Commit e9f33b77 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-24142: Avoid block_lock alignment loss on 64-bit systems

sux_lock::recursive: Move right after the 32-bit sux_lock::lock.
This will reduce sizeof(block_lock) from 24 to 16 bytes on
64-bit systems with CMAKE_BUILD_TYPE=RelWithDebInfo. This may be
significant, because there will be one buf_block_t::lock for each
buffer pool page descriptor.

We still have some potential for savings, with sizeof(buf_page_t)==112
and sizeof(buf_block_t)==184 on a GNU/Linux AMD64 system.

Note: On GNU/Linux AMD64, sizeof(index_lock) remains 32 bytes
(16 with PLUGIN_PERFSCHEMA=NO) even tough it would fit in 24 bytes.
This is because sizeof(srw_lock) includes 4 bytes of padding
(to 16 bytes) that index_lock_t::recursive cannot reuse. So,
in total 4+4 bytes will be lost to padding. This is rather
insignificant compared to sizeof(dict_index_t)==400.
parent ba2d45dc
...@@ -114,8 +114,8 @@ typedef srw_lock_low srw_lock; ...@@ -114,8 +114,8 @@ typedef srw_lock_low srw_lock;
/** Slim reader-writer lock with PERFORMANCE_SCHEMA instrumentation */ /** Slim reader-writer lock with PERFORMANCE_SCHEMA instrumentation */
class srw_lock class srw_lock
{ {
srw_lock_low lock;
PSI_rwlock *pfs_psi; PSI_rwlock *pfs_psi;
srw_lock_low lock;
template<bool support_u_lock> template<bool support_u_lock>
ATTRIBUTE_NOINLINE void psi_rd_lock(const char *file, unsigned line); ATTRIBUTE_NOINLINE void psi_rd_lock(const char *file, unsigned line);
...@@ -126,8 +126,8 @@ class srw_lock ...@@ -126,8 +126,8 @@ class srw_lock
public: public:
void init(mysql_pfs_key_t key) void init(mysql_pfs_key_t key)
{ {
lock.init();
pfs_psi= PSI_RWLOCK_CALL(init_rwlock)(key, this); pfs_psi= PSI_RWLOCK_CALL(init_rwlock)(key, this);
lock.init();
} }
void destroy() void destroy()
{ {
......
...@@ -33,6 +33,8 @@ class sux_lock final ...@@ -33,6 +33,8 @@ class sux_lock final
{ {
/** The underlying non-recursive lock */ /** The underlying non-recursive lock */
srw lock; srw lock;
/** Numbers of U and X locks. Protected by lock. */
uint32_t recursive;
/** The owner of the U or X lock (0 if none); protected by lock */ /** The owner of the U or X lock (0 if none); protected by lock */
std::atomic<os_thread_id_t> writer; std::atomic<os_thread_id_t> writer;
/** Special writer!=0 value to indicate that the lock is non-recursive /** Special writer!=0 value to indicate that the lock is non-recursive
...@@ -42,8 +44,6 @@ class sux_lock final ...@@ -42,8 +44,6 @@ class sux_lock final
#else #else
# define FOR_IO ((os_thread_id_t) ~0UL) /* it could be a pointer */ # define FOR_IO ((os_thread_id_t) ~0UL) /* it could be a pointer */
#endif #endif
/** Numbers of U and X locks. Protected by lock. */
uint32_t recursive;
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
/** Protects readers */ /** Protects readers */
mutable srw_mutex readers_lock; mutable srw_mutex readers_lock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment