summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-05-11 14:23:37 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-05-11 14:23:37 +0300
commitba3d58ad4cf4e152bc3854c1526ea72bbcb31ed6 (patch)
tree1322ba71091f914e1a56b94a2e719ad516eb5573
parent4ae778bbec4514bdfe08baddd7630446276fa9c6 (diff)
downloadmariadb-git-ba3d58ad4cf4e152bc3854c1526ea72bbcb31ed6.tar.gz
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.
-rw-r--r--storage/innobase/btr/btr0cur.cc7
-rw-r--r--storage/innobase/dict/dict0mem.cc2
-rw-r--r--storage/innobase/handler/ha_innodb.cc1
-rw-r--r--storage/innobase/include/dict0mem.h5
-rw-r--r--storage/innobase/include/gis0rtree.ic20
-rw-r--r--storage/innobase/include/gis0type.h8
-rw-r--r--storage/innobase/include/sync0sync.h2
-rw-r--r--storage/innobase/include/sync0types.h3
-rw-r--r--storage/innobase/sync/sync0debug.cc7
-rw-r--r--storage/innobase/sync/sync0sync.cc2
10 files changed, 17 insertions, 40 deletions
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index c282d864543..a187402328f 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -1475,10 +1475,9 @@ retry_page_get:
node_seq_t root_seq_no;
root_seq_no = page_get_ssn_id(page);
-
- mutex_enter(&(index->rtr_ssn.mutex));
- index->rtr_ssn.seq_no = root_seq_no + 1;
- mutex_exit(&(index->rtr_ssn.mutex));
+ my_atomic_store32_explicit(
+ &index->rtr_ssn, root_seq_no + 1,
+ MY_MEMORY_ORDER_RELAXED);
}
/* Save the MBR */
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc
index 02ab1d77eb3..21a3c743f52 100644
--- a/storage/innobase/dict/dict0mem.cc
+++ b/storage/innobase/dict/dict0mem.cc
@@ -741,7 +741,6 @@ dict_mem_index_create(
dict_index_zip_pad_mutex_create_lazy(index);
if (type & DICT_SPATIAL) {
- mutex_create(LATCH_ID_RTR_SSN_MUTEX, &index->rtr_ssn.mutex);
index->rtr_track = static_cast<rtr_info_track_t*>(
mem_heap_alloc(
heap,
@@ -1067,7 +1066,6 @@ dict_mem_index_free(
rtr_info->index = NULL;
}
- mutex_destroy(&index->rtr_ssn.mutex);
mutex_destroy(&index->rtr_track->rtr_active_mutex);
UT_DELETE(index->rtr_track->rtr_active);
}
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 25304b82d64..32f7c6460e2 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -626,7 +626,6 @@ static PSI_mutex_info all_innodb_mutexes[] = {
PSI_KEY(rtr_active_mutex),
PSI_KEY(rtr_match_mutex),
PSI_KEY(rtr_path_mutex),
- PSI_KEY(rtr_ssn_mutex),
PSI_KEY(trx_sys_mutex),
PSI_KEY(zip_pad_mutex)
};
diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
index ed4bf073061..b259d2fb2ad 100644
--- a/storage/innobase/include/dict0mem.h
+++ b/storage/innobase/include/dict0mem.h
@@ -2,7 +2,7 @@
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2013, 2019, MariaDB Corporation.
+Copyright (c) 2013, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -964,7 +964,8 @@ struct dict_index_t{
/* in which slot the next sample should be
saved. */
/* @} */
- rtr_ssn_t rtr_ssn;/*!< Node sequence number for RTree */
+ /** R-tree split sequence number */
+ volatile int32 rtr_ssn;
rtr_info_track_t*
rtr_track;/*!< tracking all R-Tree search cursors */
trx_id_t trx_id; /*!< id of the transaction that created this
diff --git a/storage/innobase/include/gis0rtree.ic b/storage/innobase/include/gis0rtree.ic
index 0d346051f00..696aa1e2f5f 100644
--- a/storage/innobase/include/gis0rtree.ic
+++ b/storage/innobase/include/gis0rtree.ic
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, MariaDB Corporation.
+Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -132,13 +132,9 @@ rtr_get_new_ssn_id(
/*===============*/
dict_index_t* index) /*!< in/out: the index struct */
{
- node_seq_t ssn;
-
- mutex_enter(&(index->rtr_ssn.mutex));
- ssn = ++index->rtr_ssn.seq_no;
- mutex_exit(&(index->rtr_ssn.mutex));
-
- return(ssn);
+ node_seq_t ssn= my_atomic_add32_explicit(&index->rtr_ssn, 1,
+ MY_MEMORY_ORDER_RELAXED);
+ return ssn + 1;
}
/*****************************************************************//**
Get the current Split Sequence Number.
@@ -149,13 +145,7 @@ rtr_get_current_ssn_id(
/*===================*/
dict_index_t* index) /*!< in: index struct */
{
- node_seq_t ssn;
-
- mutex_enter(&(index->rtr_ssn.mutex));
- ssn = index->rtr_ssn.seq_no;
- mutex_exit(&(index->rtr_ssn.mutex));
-
- return(ssn);
+ return my_atomic_load32_explicit(&index->rtr_ssn, MY_MEMORY_ORDER_RELAXED);
}
/*********************************************************************//**
diff --git a/storage/innobase/include/gis0type.h b/storage/innobase/include/gis0type.h
index ee350ea56ce..c5ea817c6bf 100644
--- a/storage/innobase/include/gis0type.h
+++ b/storage/innobase/include/gis0type.h
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2018, MariaDB Corporation.
+Copyright (c) 2018, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -143,12 +143,6 @@ typedef struct rtr_info_track {
rtr_active */
} rtr_info_track_t;
-/* Node Sequence Number and mutex protects it. */
-typedef struct rtree_ssn {
- ib_mutex_t mutex; /*!< mutex protect the seq num */
- node_seq_t seq_no; /*!< the SSN (node sequence number) */
-} rtr_ssn_t;
-
/* This is to record the record movement between pages. Used for corresponding
lock movement */
typedef struct rtr_rec_move {
diff --git a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h
index 0d8bd0a4509..e250307fa28 100644
--- a/storage/innobase/include/sync0sync.h
+++ b/storage/innobase/include/sync0sync.h
@@ -3,6 +3,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc.
Copyright (c) 2012, Facebook Inc.
+Copyright (c) 2020, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -81,7 +82,6 @@ extern mysql_pfs_key_t recv_writer_mutex_key;
extern mysql_pfs_key_t rtr_active_mutex_key;
extern mysql_pfs_key_t rtr_match_mutex_key;
extern mysql_pfs_key_t rtr_path_mutex_key;
-extern mysql_pfs_key_t rtr_ssn_mutex_key;
extern mysql_pfs_key_t redo_rseg_mutex_key;
extern mysql_pfs_key_t noredo_rseg_mutex_key;
extern mysql_pfs_key_t page_zip_stat_per_index_mutex_key;
diff --git a/storage/innobase/include/sync0types.h b/storage/innobase/include/sync0types.h
index 9b1443523c7..c21f3bbf853 100644
--- a/storage/innobase/include/sync0types.h
+++ b/storage/innobase/include/sync0types.h
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2018, MariaDB Corporation.
+Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -327,7 +327,6 @@ enum latch_id_t {
LATCH_ID_REDO_RSEG,
LATCH_ID_NOREDO_RSEG,
LATCH_ID_RW_LOCK_DEBUG,
- LATCH_ID_RTR_SSN_MUTEX,
LATCH_ID_RTR_ACTIVE_MUTEX,
LATCH_ID_RTR_MATCH_MUTEX,
LATCH_ID_RTR_PATH_MUTEX,
diff --git a/storage/innobase/sync/sync0debug.cc b/storage/innobase/sync/sync0debug.cc
index c4a2fd90b37..78c3058573f 100644
--- a/storage/innobase/sync/sync0debug.cc
+++ b/storage/innobase/sync/sync0debug.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2018, MariaDB Corporation.
+Copyright (c) 2017, 2020, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -383,8 +383,7 @@ private:
{
return(latch->get_id() == LATCH_ID_RTR_ACTIVE_MUTEX
|| latch->get_id() == LATCH_ID_RTR_PATH_MUTEX
- || latch->get_id() == LATCH_ID_RTR_MATCH_MUTEX
- || latch->get_id() == LATCH_ID_RTR_SSN_MUTEX);
+ || latch->get_id() == LATCH_ID_RTR_MATCH_MUTEX);
}
private:
@@ -1375,8 +1374,6 @@ sync_latch_meta_init()
rw_lock_debug_mutex_key);
#endif /* UNIV_DEBUG */
- LATCH_ADD_MUTEX(RTR_SSN_MUTEX, SYNC_ANY_LATCH, rtr_ssn_mutex_key);
-
LATCH_ADD_MUTEX(RTR_ACTIVE_MUTEX, SYNC_ANY_LATCH,
rtr_active_mutex_key);
diff --git a/storage/innobase/sync/sync0sync.cc b/storage/innobase/sync/sync0sync.cc
index 0a81f9c00e7..22bd9f823ec 100644
--- a/storage/innobase/sync/sync0sync.cc
+++ b/storage/innobase/sync/sync0sync.cc
@@ -2,6 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc.
+Copyright (c) 2020, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -73,7 +74,6 @@ mysql_pfs_key_t rw_lock_debug_mutex_key;
mysql_pfs_key_t rtr_active_mutex_key;
mysql_pfs_key_t rtr_match_mutex_key;
mysql_pfs_key_t rtr_path_mutex_key;
-mysql_pfs_key_t rtr_ssn_mutex_key;
mysql_pfs_key_t rw_lock_list_mutex_key;
mysql_pfs_key_t rw_lock_mutex_key;
mysql_pfs_key_t srv_innodb_monitor_mutex_key;