summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorKrunal Bauskar <mysqlonarm@gmail.com>2021-09-15 16:18:39 +0800
committerMarko Mäkelä <marko.makela@mariadb.com>2021-09-17 11:58:49 +0300
commit48bbc447335a0b3ec698e975d48ad49145780624 (patch)
tree80cde62c24d5bd868d106b3f44e6cb27d2f8b365 /storage
parent106b16a5af7a8e29889e0ef8930bd2901a9ad00e (diff)
downloadmariadb-git-48bbc447335a0b3ec698e975d48ad49145780624.tar.gz
MDEV-26609 : Avoid deriving ELEMENT_PER_LATCH from cacheline
* buffer pool has latches that protect access to pages. * there is a latch per N pages.   (check page_hash_table for more details) * N is calculated based on the cacheline size. * for example: if cacheline size is   : 64 then 7 pages pointers + 1 latch can be hosted on the same cacheline   : 128 then 15 pages pointers + 1 latch can be hosted on the same cacheline * arm generally have wider cacheline so with arm 1 latch is used   to access 15 pages vs with x86 1 latch is used to access 7 pages.   Naturally, the contention is more with arm case. * said patch help relax this contention by limiting the elements per cacheline to 7 (+ 1 latch slot).   for wider-cacheline (say 128), the remaining 8 slots are kept empty.   this ensures there are no 2 latches on the same cacheline to avoid latch level contention. Based on suggestion from Marko, the same logic is now extended to lock_sys_t::hash_table.
Diffstat (limited to 'storage')
-rw-r--r--storage/innobase/include/buf0buf.h16
-rw-r--r--storage/innobase/include/lock0lock.h13
2 files changed, 23 insertions, 6 deletions
diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
index 2ad731e7b94..3f922708ef1 100644
--- a/storage/innobase/include/buf0buf.h
+++ b/storage/innobase/include/buf0buf.h
@@ -1726,10 +1726,15 @@ public:
/** Hash table with singly-linked overflow lists. @see hash_table_t */
struct page_hash_table
{
+ static_assert(CPU_LEVEL1_DCACHE_LINESIZE >= 64, "less than 64 bytes");
+ static_assert(!(CPU_LEVEL1_DCACHE_LINESIZE & 63),
+ "not a multiple of 64 bytes");
+
/** Number of array[] elements per page_hash_latch.
Must be one less than a power of 2. */
- static constexpr size_t ELEMENTS_PER_LATCH= CPU_LEVEL1_DCACHE_LINESIZE /
- sizeof(void*) - 1;
+ static constexpr size_t ELEMENTS_PER_LATCH= 64 / sizeof(void*) - 1;
+ static constexpr size_t EMPTY_SLOTS_PER_LATCH=
+ ((CPU_LEVEL1_DCACHE_LINESIZE / 64) - 1) * (64 / sizeof(void*));
/** number of payload elements in array[] */
Atomic_relaxed<ulint> n_cells;
@@ -1746,7 +1751,12 @@ public:
/** @return the index of an array element */
ulint calc_hash(ulint fold) const { return calc_hash(fold, n_cells); }
/** @return raw array index converted to padded index */
- static ulint pad(ulint h) { return 1 + (h / ELEMENTS_PER_LATCH) + h; }
+ static ulint pad(ulint h)
+ {
+ ulint latches= h / ELEMENTS_PER_LATCH;
+ ulint empty_slots= latches * EMPTY_SLOTS_PER_LATCH;
+ return 1 + latches + empty_slots + h;
+ }
private:
/** @return the hash value before any ELEMENTS_PER_LATCH padding */
static ulint hash(ulint fold, ulint n) { return ut_hash_ulint(fold, n); }
diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h
index 859441afcc0..c2fef3baaac 100644
--- a/storage/innobase/include/lock0lock.h
+++ b/storage/innobase/include/lock0lock.h
@@ -609,8 +609,9 @@ public:
/** Number of array[] elements per hash_latch.
Must be LATCH less than a power of 2. */
- static constexpr size_t ELEMENTS_PER_LATCH= CPU_LEVEL1_DCACHE_LINESIZE /
- sizeof(void*) - LATCH;
+ static constexpr size_t ELEMENTS_PER_LATCH= (64 / sizeof(void*)) - LATCH;
+ static constexpr size_t EMPTY_SLOTS_PER_LATCH=
+ ((CPU_LEVEL1_DCACHE_LINESIZE / 64) - 1) * (64 / sizeof(void*));
/** number of payload elements in array[]. Protected by lock_sys.latch. */
ulint n_cells;
@@ -632,9 +633,15 @@ public:
/** @return the index of an array element */
inline ulint calc_hash(ulint fold) const;
+
/** @return raw array index converted to padded index */
static ulint pad(ulint h)
- { return LATCH + LATCH * (h / ELEMENTS_PER_LATCH) + h; }
+ {
+ ulint latches= LATCH * (h / ELEMENTS_PER_LATCH);
+ ulint empty_slots= (h / ELEMENTS_PER_LATCH) * EMPTY_SLOTS_PER_LATCH;
+ return LATCH + latches + empty_slots + h;
+ }
+
/** Get a latch. */
static hash_latch *latch(hash_cell_t *cell)
{