Skip to content

Commit ba3d58a

Browse files
committed
MDEV-22523 index->rtr_ssn.mutex is wasting memory
As part of the SPATIAL INDEX implementation in InnoDB, dict_index_t was expanded by a rtr_ssn_t field. There are only 3 operations for this field, all protected by rtr_ssn_t::mutex: * btr_cur_search_to_nth_level() stores the least significant 32 bits of the 64-bit value that is stored in the index root page. (This would better be done when the table is opened for the very first time.) * rtr_get_new_ssn_id() increments the value by 1. * rtr_get_current_ssn_id() reads the current value. All these operations can be implemented equally safely by using atomic memory access operations.
1 parent 4ae778b commit ba3d58a

File tree

10 files changed

+17
-40
lines changed

10 files changed

+17
-40
lines changed

storage/innobase/btr/btr0cur.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,10 +1475,9 @@ btr_cur_search_to_nth_level(
14751475
node_seq_t root_seq_no;
14761476

14771477
root_seq_no = page_get_ssn_id(page);
1478-
1479-
mutex_enter(&(index->rtr_ssn.mutex));
1480-
index->rtr_ssn.seq_no = root_seq_no + 1;
1481-
mutex_exit(&(index->rtr_ssn.mutex));
1478+
my_atomic_store32_explicit(
1479+
&index->rtr_ssn, root_seq_no + 1,
1480+
MY_MEMORY_ORDER_RELAXED);
14821481
}
14831482

14841483
/* Save the MBR */

storage/innobase/dict/dict0mem.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,6 @@ dict_mem_index_create(
741741
dict_index_zip_pad_mutex_create_lazy(index);
742742

743743
if (type & DICT_SPATIAL) {
744-
mutex_create(LATCH_ID_RTR_SSN_MUTEX, &index->rtr_ssn.mutex);
745744
index->rtr_track = static_cast<rtr_info_track_t*>(
746745
mem_heap_alloc(
747746
heap,
@@ -1067,7 +1066,6 @@ dict_mem_index_free(
10671066
rtr_info->index = NULL;
10681067
}
10691068

1070-
mutex_destroy(&index->rtr_ssn.mutex);
10711069
mutex_destroy(&index->rtr_track->rtr_active_mutex);
10721070
UT_DELETE(index->rtr_track->rtr_active);
10731071
}

storage/innobase/handler/ha_innodb.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ static PSI_mutex_info all_innodb_mutexes[] = {
626626
PSI_KEY(rtr_active_mutex),
627627
PSI_KEY(rtr_match_mutex),
628628
PSI_KEY(rtr_path_mutex),
629-
PSI_KEY(rtr_ssn_mutex),
630629
PSI_KEY(trx_sys_mutex),
631630
PSI_KEY(zip_pad_mutex)
632631
};

storage/innobase/include/dict0mem.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2012, Facebook Inc.
5-
Copyright (c) 2013, 2019, MariaDB Corporation.
5+
Copyright (c) 2013, 2020, MariaDB Corporation.
66
77
This program is free software; you can redistribute it and/or modify it under
88
the terms of the GNU General Public License as published by the Free Software
@@ -964,7 +964,8 @@ struct dict_index_t{
964964
/* in which slot the next sample should be
965965
saved. */
966966
/* @} */
967-
rtr_ssn_trtr_ssn;/*!< Node sequence number for RTree */
967+
/** R-tree split sequence number */
968+
volatile int32 rtr_ssn;
968969
rtr_info_track_t*
969970
rtr_track;/*!< tracking all R-Tree search cursors */
970971
trx_id_ttrx_id; /*!< id of the transaction that created this

storage/innobase/include/gis0rtree.ic

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22

33
Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, MariaDB Corporation.
4+
Copyright (c) 2017, 2020, MariaDB Corporation.
55

66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -132,13 +132,9 @@ rtr_get_new_ssn_id(
132132
/*===============*/
133133
dict_index_t* index) /*!< in/out: the index struct */
134134
{
135-
node_seq_t ssn;
136-
137-
mutex_enter(&(index->rtr_ssn.mutex));
138-
ssn = ++index->rtr_ssn.seq_no;
139-
mutex_exit(&(index->rtr_ssn.mutex));
140-
141-
return(ssn);
135+
node_seq_t ssn= my_atomic_add32_explicit(&index->rtr_ssn, 1,
136+
MY_MEMORY_ORDER_RELAXED);
137+
return ssn + 1;
142138
}
143139
/*****************************************************************//**
144140
Get the current Split Sequence Number.
@@ -149,13 +145,7 @@ rtr_get_current_ssn_id(
149145
/*===================*/
150146
dict_index_t* index) /*!< in: index struct */
151147
{
152-
node_seq_t ssn;
153-
154-
mutex_enter(&(index->rtr_ssn.mutex));
155-
ssn = index->rtr_ssn.seq_no;
156-
mutex_exit(&(index->rtr_ssn.mutex));
157-
158-
return(ssn);
148+
return my_atomic_load32_explicit(&index->rtr_ssn, MY_MEMORY_ORDER_RELAXED);
159149
}
160150

161151
/*********************************************************************//**

storage/innobase/include/gis0type.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2018, MariaDB Corporation.
4+
Copyright (c) 2018, 2020, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -143,12 +143,6 @@ typedef struct rtr_info_track {
143143
rtr_active */
144144
} rtr_info_track_t;
145145

146-
/* Node Sequence Number and mutex protects it. */
147-
typedef struct rtree_ssn {
148-
ib_mutex_t mutex; /*!< mutex protect the seq num */
149-
node_seq_t seq_no; /*!< the SSN (node sequence number) */
150-
} rtr_ssn_t;
151-
152146
/* This is to record the record movement between pages. Used for corresponding
153147
lock movement */
154148
typedef struct rtr_rec_move {

storage/innobase/include/sync0sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2008, Google Inc.
55
Copyright (c) 2012, Facebook Inc.
6+
Copyright (c) 2020, MariaDB Corporation.
67
78
Portions of this file contain modifications contributed and copyrighted by
89
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -81,7 +82,6 @@ extern mysql_pfs_key_t recv_writer_mutex_key;
8182
extern mysql_pfs_key_trtr_active_mutex_key;
8283
extern mysql_pfs_key_trtr_match_mutex_key;
8384
extern mysql_pfs_key_trtr_path_mutex_key;
84-
extern mysql_pfs_key_trtr_ssn_mutex_key;
8585
extern mysql_pfs_key_tredo_rseg_mutex_key;
8686
extern mysql_pfs_key_tnoredo_rseg_mutex_key;
8787
extern mysql_pfs_key_t page_zip_stat_per_index_mutex_key;

storage/innobase/include/sync0types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2018, MariaDB Corporation.
4+
Copyright (c) 2017, 2020, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -327,7 +327,6 @@ enum latch_id_t {
327327
LATCH_ID_REDO_RSEG,
328328
LATCH_ID_NOREDO_RSEG,
329329
LATCH_ID_RW_LOCK_DEBUG,
330-
LATCH_ID_RTR_SSN_MUTEX,
331330
LATCH_ID_RTR_ACTIVE_MUTEX,
332331
LATCH_ID_RTR_MATCH_MUTEX,
333332
LATCH_ID_RTR_PATH_MUTEX,

storage/innobase/sync/sync0debug.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2018, MariaDB Corporation.
4+
Copyright (c) 2017, 2020, MariaDB Corporation.
55
66
Portions of this file contain modifications contributed and copyrighted by
77
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -383,8 +383,7 @@ struct LatchDebug {
383383
{
384384
return(latch->get_id() == LATCH_ID_RTR_ACTIVE_MUTEX
385385
|| latch->get_id() == LATCH_ID_RTR_PATH_MUTEX
386-
|| latch->get_id() == LATCH_ID_RTR_MATCH_MUTEX
387-
|| latch->get_id() == LATCH_ID_RTR_SSN_MUTEX);
386+
|| latch->get_id() == LATCH_ID_RTR_MATCH_MUTEX);
388387
}
389388

390389
private:
@@ -1375,8 +1374,6 @@ sync_latch_meta_init()
13751374
rw_lock_debug_mutex_key);
13761375
#endif /* UNIV_DEBUG */
13771376

1378-
LATCH_ADD_MUTEX(RTR_SSN_MUTEX, SYNC_ANY_LATCH, rtr_ssn_mutex_key);
1379-
13801377
LATCH_ADD_MUTEX(RTR_ACTIVE_MUTEX, SYNC_ANY_LATCH,
13811378
rtr_active_mutex_key);
13821379

storage/innobase/sync/sync0sync.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2008, Google Inc.
5+
Copyright (c) 2020, MariaDB Corporation.
56
67
Portions of this file contain modifications contributed and copyrighted by
78
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -73,7 +74,6 @@ mysql_pfs_key_t rw_lock_debug_mutex_key;
7374
mysql_pfs_key_t rtr_active_mutex_key;
7475
mysql_pfs_key_trtr_match_mutex_key;
7576
mysql_pfs_key_trtr_path_mutex_key;
76-
mysql_pfs_key_t rtr_ssn_mutex_key;
7777
mysql_pfs_key_trw_lock_list_mutex_key;
7878
mysql_pfs_key_trw_lock_mutex_key;
7979
mysql_pfs_key_tsrv_innodb_monitor_mutex_key;

0 commit comments

Comments
 (0)