Skip to content

Commit 131d9a5

Browse files
svojdr-m
authored andcommitted
Allocate lock_sys statically
There is only one lock_sys. Allocate it statically in order to avoid dereferencing a pointer whenever accessing it. Also, align some members to their own cache line in order to avoid false sharing. lock_sys_t::create(): The deferred constructor. lock_sys_t::close(): The early destructor.
1 parent 59dd046 commit 131d9a5

File tree

21 files changed

+248
-240
lines changed

21 files changed

+248
-240
lines changed

extra/mariabackup/xtrabackup.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,8 +3672,6 @@ xtrabackup_backup_func()
36723672
"innodb_redo_log", SRV_LOG_SPACE_FIRST_ID, 0,
36733673
FIL_TYPE_LOG, NULL);
36743674

3675-
lock_sys_create(srv_lock_table_size);
3676-
36773675
for (i = 0; i < srv_n_log_files; i++) {
36783676
err = open_or_create_log_file(space, &log_file_created, i);
36793677
if (err != DB_SUCCESS) {

storage/innobase/btr/btr0btr.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3675,7 +3675,7 @@ btr_lift_page_up(
36753675
if (dict_index_is_spatial(index)) {
36763676
lock_mutex_enter();
36773677
lock_prdt_page_free_from_discard(
3678-
block, lock_sys->prdt_page_hash);
3678+
block, lock_sys.prdt_page_hash);
36793679
lock_mutex_exit();
36803680
}
36813681
lock_update_copy_and_discard(father_block, block);
@@ -3968,7 +3968,7 @@ btr_compress(
39683968
/* No GAP lock needs to be worrying about */
39693969
lock_mutex_enter();
39703970
lock_prdt_page_free_from_discard(
3971-
block, lock_sys->prdt_page_hash);
3971+
block, lock_sys.prdt_page_hash);
39723972
lock_rec_free_all_from_discard_page(block);
39733973
lock_mutex_exit();
39743974
} else {
@@ -4126,7 +4126,7 @@ btr_compress(
41264126
}
41274127
lock_mutex_enter();
41284128
lock_prdt_page_free_from_discard(
4129-
block, lock_sys->prdt_page_hash);
4129+
block, lock_sys.prdt_page_hash);
41304130
lock_rec_free_all_from_discard_page(block);
41314131
lock_mutex_exit();
41324132
} else {

storage/innobase/buf/buf0buf.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,7 @@ buf_pool_resize()
30583058

30593059
/* normalize lock_sys */
30603060
srv_lock_table_size = 5 * (srv_buf_pool_size / UNIV_PAGE_SIZE);
3061-
lock_sys_resize(srv_lock_table_size);
3061+
lock_sys.resize(srv_lock_table_size);
30623062

30633063
/* normalize btr_search_sys */
30643064
btr_search_sys_resize(

storage/innobase/gis/gis0sea.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ rtr_check_discard_page(
12551255
mutex_exit(&index->rtr_track->rtr_active_mutex);
12561256

12571257
lock_mutex_enter();
1258-
lock_prdt_page_free_from_discard(block, lock_sys->prdt_hash);
1259-
lock_prdt_page_free_from_discard(block, lock_sys->prdt_page_hash);
1258+
lock_prdt_page_free_from_discard(block, lock_sys.prdt_hash);
1259+
lock_prdt_page_free_from_discard(block, lock_sys.prdt_page_hash);
12601260
lock_mutex_exit();
12611261
}
12621262

storage/innobase/include/dict0mem.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ struct dict_table_t {
19081908
ulong n_waiting_or_granted_auto_inc_locks;
19091909

19101910
/** The transaction that currently holds the the AUTOINC lock on this
1911-
table. Protected by lock_sys->mutex. */
1911+
table. Protected by lock_sys.mutex. */
19121912
const trx_t* autoinc_trx;
19131913

19141914
/* @} */
@@ -1923,7 +1923,7 @@ struct dict_table_t {
19231923

19241924
/** Count of the number of record locks on this table. We use this to
19251925
determine whether we can evict the table from the dictionary cache.
1926-
It is protected by lock_sys->mutex. */
1926+
It is protected by lock_sys.mutex. */
19271927
ulint n_rec_locks;
19281928

19291929
#ifndef DBUG_ASSERT_EXISTS
@@ -1935,7 +1935,7 @@ struct dict_table_t {
19351935
ulint n_ref_count;
19361936

19371937
public:
1938-
/** List of locks on the table. Protected by lock_sys->mutex. */
1938+
/** List of locks on the table. Protected by lock_sys.mutex. */
19391939
table_lock_list_tlocks;
19401940

19411941
/** Timestamp of the last modification of this table. */

storage/innobase/include/lock0lock.h

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,6 @@ ulint
6565
lock_get_size(void);
6666
/*===============*/
6767
/*********************************************************************//**
68-
Creates the lock system at database start. */
69-
void
70-
lock_sys_create(
71-
/*============*/
72-
ulint n_cells);/*!< in: number of slots in lock hash table */
73-
/** Resize the lock hash table.
74-
@param[in] n_cells number of slots in lock hash table */
75-
void
76-
lock_sys_resize(
77-
ulint n_cells);
78-
79-
/*********************************************************************//**
80-
Closes the lock system at database shutdown. */
81-
void
82-
lock_sys_close(void);
83-
/*================*/
84-
/*********************************************************************//**
8568
Gets the heap_no of the smallest user record on a page.
8669
@return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */
8770
UNIV_INLINE
@@ -605,7 +588,7 @@ lock_print_info_all_transactions(
605588
Return approximate number or record locks (bits set in the bitmap) for
606589
this transaction. Since delete-marked records may be removed, the
607590
record count will not be precise.
608-
The caller must be holding lock_sys->mutex. */
591+
The caller must be holding lock_sys.mutex. */
609592
ulint
610593
lock_number_of_rows_locked(
611594
/*=======================*/
@@ -614,7 +597,7 @@ lock_number_of_rows_locked(
614597

615598
/*********************************************************************//**
616599
Return the number of table locks for a transaction.
617-
The caller must be holding lock_sys->mutex. */
600+
The caller must be holding lock_sys.mutex. */
618601
ulint
619602
lock_number_of_tables_locked(
620603
/*=========================*/
@@ -897,11 +880,12 @@ struct lock_op_t{
897880
typedef ib_mutex_t LockMutex;
898881

899882
/** The lock system struct */
900-
struct lock_sys_t{
901-
charpad1[CACHE_LINE_SIZE];/*!< padding to prevent other
902-
memory update hotspots from
903-
residing on the same memory
904-
cache line */
883+
class lock_sys_t
884+
{
885+
bool m_initialised;
886+
887+
public:
888+
MY_ALIGNED(CACHE_LINE_SIZE)
905889
LockMutex mutex;/*!< Mutex protecting the
906890
locks */
907891
hash_table_t* rec_hash;/*!< hash table of the record
@@ -911,13 +895,13 @@ struct lock_sys_t{
911895
hash_table_t* prdt_page_hash;/*!< hash table of the page
912896
lock */
913897

914-
charpad2[CACHE_LINE_SIZE];/*!< Padding */
898+
MY_ALIGNED(CACHE_LINE_SIZE)
915899
LockMutex wait_mutex;/*!< Mutex protecting the
916900
next two fields */
917901
srv_slot_t* waiting_threads;/*!< Array of user threads
918902
suspended while waiting for
919903
locks within InnoDB, protected
920-
by the lock_sys->wait_mutex;
904+
by the lock_sys.wait_mutex;
921905
os_event_set() and
922906
os_event_reset() on
923907
waiting_threads[]->event
@@ -926,7 +910,7 @@ struct lock_sys_t{
926910
srv_slot_t* last_slot;/*!< highest slot ever used
927911
in the waiting_threads array,
928912
protected by
929-
lock_sys->wait_mutex */
913+
lock_sys.wait_mutex */
930914

931915
ulint n_lock_max_wait_time;/*!< Max wait time */
932916

@@ -938,6 +922,38 @@ struct lock_sys_t{
938922

939923
booltimeout_thread_active;/*!< True if the timeout thread
940924
is running */
925+
926+
927+
/**
928+
Constructor.
929+
930+
Some members may require late initialisation, thus we just mark object as
931+
uninitialised. Real initialisation happens in create().
932+
*/
933+
lock_sys_t(): m_initialised(false) {}
934+
935+
936+
bool is_initialised() { return m_initialised; }
937+
938+
939+
/**
940+
Creates the lock system at database start.
941+
942+
@param[in] n_cells number of slots in lock hash table
943+
*/
944+
void create(ulint n_cells);
945+
946+
947+
/**
948+
Resize the lock hash table.
949+
950+
@param[in] n_cells number of slots in lock hash table
951+
*/
952+
void resize(ulint n_cells);
953+
954+
955+
/** Closes the lock system at database shutdown. */
956+
void close();
941957
};
942958

943959
/*************************************************************//**
@@ -982,36 +998,36 @@ lock_rec_trx_wait(
982998
ulint type);
983999

9841000
/** The lock system */
985-
extern lock_sys_t*lock_sys;
1001+
extern lock_sys_t lock_sys;
9861002

987-
/** Test if lock_sys->mutex can be acquired without waiting. */
1003+
/** Test if lock_sys.mutex can be acquired without waiting. */
9881004
#define lock_mutex_enter_nowait() \
989-
(lock_sys->mutex.trylock(__FILE__, __LINE__))
1005+
(lock_sys.mutex.trylock(__FILE__, __LINE__))
9901006

991-
/** Test if lock_sys->mutex is owned. */
992-
#define lock_mutex_own() (lock_sys->mutex.is_owned())
1007+
/** Test if lock_sys.mutex is owned. */
1008+
#define lock_mutex_own() (lock_sys.mutex.is_owned())
9931009

994-
/** Acquire the lock_sys->mutex. */
1010+
/** Acquire the lock_sys.mutex. */
9951011
#define lock_mutex_enter() do { \
996-
mutex_enter(&lock_sys->mutex); \
1012+
mutex_enter(&lock_sys.mutex); \
9971013
} while (0)
9981014

999-
/** Release the lock_sys->mutex. */
1015+
/** Release the lock_sys.mutex. */
10001016
#define lock_mutex_exit() do { \
1001-
lock_sys->mutex.exit(); \
1017+
lock_sys.mutex.exit(); \
10021018
} while (0)
10031019

1004-
/** Test if lock_sys->wait_mutex is owned. */
1005-
#define lock_wait_mutex_own() (lock_sys->wait_mutex.is_owned())
1020+
/** Test if lock_sys.wait_mutex is owned. */
1021+
#define lock_wait_mutex_own() (lock_sys.wait_mutex.is_owned())
10061022

1007-
/** Acquire the lock_sys->wait_mutex. */
1023+
/** Acquire the lock_sys.wait_mutex. */
10081024
#define lock_wait_mutex_enter() do { \
1009-
mutex_enter(&lock_sys->wait_mutex); \
1025+
mutex_enter(&lock_sys.wait_mutex); \
10101026
} while (0)
10111027

1012-
/** Release the lock_sys->wait_mutex. */
1028+
/** Release the lock_sys.wait_mutex. */
10131029
#define lock_wait_mutex_exit() do { \
1014-
lock_sys->wait_mutex.exit(); \
1030+
lock_sys.wait_mutex.exit(); \
10151031
} while (0)
10161032

10171033
#ifdef WITH_WSREP

storage/innobase/include/lock0lock.ic

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ lock_rec_hash(
6363
ulint page_no)/*!< in: page number */
6464
{
6565
return(unsigned(hash_calc_hash(lock_rec_fold(space, page_no),
66-
lock_sys->rec_hash)));
66+
lock_sys.rec_hash)));
6767
}
6868

6969
/*********************************************************************//**
@@ -99,11 +99,11 @@ lock_hash_get(
9999
ulint mode) /*!< in: lock mode */
100100
{
101101
if (mode & LOCK_PREDICATE) {
102-
return(lock_sys->prdt_hash);
102+
return(lock_sys.prdt_hash);
103103
} else if (mode & LOCK_PRDT_PAGE) {
104-
return(lock_sys->prdt_page_hash);
104+
return(lock_sys.prdt_page_hash);
105105
} else {
106-
return(lock_sys->rec_hash);
106+
return(lock_sys.rec_hash);
107107
}
108108
}
109109

storage/innobase/include/lock0priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ operator<<(std::ostream& out, const lock_rec_t& lock)
111111
return(lock.print(out));
112112
}
113113

114-
/** Lock struct; protected by lock_sys->mutex */
114+
/** Lock struct; protected by lock_sys.mutex */
115115
struct lock_t {
116116
trx_t* trx;/*!< transaction owning the
117117
lock */

storage/innobase/include/lock0types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Created 5/7/1996 Heikki Tuuri
3131
#define lock_t ib_lock_t
3232

3333
struct lock_t;
34-
struct lock_sys_t;
3534
struct lock_table_t;
3635

3736
/* Basic lock modes */

storage/innobase/include/trx0sys.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,10 @@ class rw_trx_hash_t
590590
the transaction may get committed before this method returns.
591591
592592
With do_ref_count == false the caller may dereference returned trx pointer
593-
only if lock_sys->mutex was acquired before calling find().
593+
only if lock_sys.mutex was acquired before calling find().
594594
595595
With do_ref_count == true caller may dereference trx even if it is not
596-
holding lock_sys->mutex. Caller is responsible for calling
596+
holding lock_sys.mutex. Caller is responsible for calling
597597
trx->release_reference() when it is done playing with trx.
598598
599599
Ideally this method should get caller rw_trx_hash_pins along with trx

0 commit comments

Comments
 (0)