From 5615a78a69a596099d5f515dd03424b402c7fd17 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 8 Apr 2022 10:37:17 +0200 Subject: [PATCH 1/7] MDEV-28266 Crash in Field_string::type_handler when calling procedures on_table_fill_finished() should always be done at the end of open() even if result is not Select_materialize but (for example) Select_fetch_into_spvars. --- mysql-test/main/sp-cursor.result | 12 ++++++++++++ mysql-test/main/sp-cursor.test | 21 +++++++++++++++++++++ sql/sql_cursor.cc | 16 +++------------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/mysql-test/main/sp-cursor.result b/mysql-test/main/sp-cursor.result index b1c2b335ea4..230bf8c66ef 100644 --- a/mysql-test/main/sp-cursor.result +++ b/mysql-test/main/sp-cursor.result @@ -800,3 +800,15 @@ drop procedure test_proc; drop view v1; drop function get_name; drop table t1; +# +# MDEV-28266: Crash in Field_string::type_handler when calling procedures +# +CREATE TABLE t (f INT); +CREATE TRIGGER tr AFTER INSERT ON t FOR EACH ROW +FOR x IN (SELECT * FROM json_table(NULL, '$' COLUMNS(a CHAR(1) path '$.*')) tmp) +DO set @a=1; END FOR $ +INSERT INTO t () values (); +DROP TABLE t; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/sp-cursor.test b/mysql-test/main/sp-cursor.test index 9794815c784..c95d59b1d3b 100644 --- a/mysql-test/main/sp-cursor.test +++ b/mysql-test/main/sp-cursor.test @@ -800,3 +800,24 @@ drop procedure test_proc; drop view v1; drop function get_name; drop table t1; + +--echo # +--echo # MDEV-28266: Crash in Field_string::type_handler when calling procedures +--echo # + +CREATE TABLE t (f INT); + +--delimiter $ +CREATE TRIGGER tr AFTER INSERT ON t FOR EACH ROW + FOR x IN (SELECT * FROM json_table(NULL, '$' COLUMNS(a CHAR(1) path '$.*')) tmp) + DO set @a=1; END FOR $ +--delimiter ; + +INSERT INTO t () values (); + +# Cleanup +DROP TABLE t; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc index 0add5845558..d45f2ac8777 100644 --- a/sql/sql_cursor.cc +++ b/sql/sql_cursor.cc @@ -80,19 +80,7 @@ public: Select_materialize(THD *thd_arg, select_result *result_arg): select_unit(thd_arg), result(result_arg), materialized_cursor(0) {} virtual bool send_result_set_metadata(List &list, uint flags); - bool send_eof() - { - if (materialized_cursor) - materialized_cursor->on_table_fill_finished(); - return false; - } - - void abort_result_set() - { - if (materialized_cursor) - materialized_cursor->on_table_fill_finished(); - } - + bool send_eof() { return false; } bool view_structure_only() const { return result->view_structure_only(); @@ -333,6 +321,8 @@ int Materialized_cursor::open(JOIN *join __attribute__((unused))) result->abort_result_set(); } + on_table_fill_finished(); + return rc; } From fc8396448c44517b891adaaeda17370ba5eeae54 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 13 Apr 2022 00:49:22 +0200 Subject: [PATCH 2/7] MDEV-27767 poor scaling with InnoDB and utf8mb3 because of charset stats Access the all_charsets[] array directly in a hot loop. This avoids get_charset() that increments a shared counter via my_collation_statistics_inc_use_count(), causing a scalability issue. Instead, call get_charset() when a table is opened (and InnoDB fills in dtype_t values) - this is enough, as charset is marked ready (MY_CS_READY) only once, on the first get_charset() call, after that it can be accessed directly. This also fixes a potential bug in InnoDB. It used to access charsets directly when filling dtype_t values. This wasn't preceded by any get_charset() call inside InnoDB. Normally the server would call get_charset() on reading the frm, but if the table was first opened from a purge thread InnoDB could, theoretically, access a not-ready charset in innobase_get_cset_width(). --- storage/innobase/handler/ha_innodb.cc | 2 +- storage/innobase/rem/rem0cmp.cc | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 29c391060d6..528f810bf8d 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2418,7 +2418,7 @@ innobase_get_cset_width( ut_ad(mbminlen); ut_ad(mbmaxlen); - cs = all_charsets[cset]; + cs = cset ? get_charset((uint)cset, MYF(MY_WME)) : NULL; if (cs) { *mbminlen = cs->mbminlen; *mbmaxlen = cs->mbmaxlen; diff --git a/storage/innobase/rem/rem0cmp.cc b/storage/innobase/rem/rem0cmp.cc index 6c42aaa0f38..7fb6fdac1ba 100644 --- a/storage/innobase/rem/rem0cmp.cc +++ b/storage/innobase/rem/rem0cmp.cc @@ -281,15 +281,13 @@ static int cmp_data(ulint mtype, ulint prtype, const byte *data1, ulint len1, /* fall through */ case DATA_VARMYSQL: DBUG_ASSERT(is_strnncoll_compatible(prtype & DATA_MYSQL_TYPE_MASK)); - if (CHARSET_INFO *cs= get_charset(dtype_get_charset_coll(prtype), - MYF(MY_WME))) + if (CHARSET_INFO *cs= all_charsets[dtype_get_charset_coll(prtype)]) return cs->coll->strnncollsp(cs, data1, len1, data2, len2); no_collation: ib::fatal() << "Unable to find charset-collation for " << prtype; case DATA_MYSQL: DBUG_ASSERT(is_strnncoll_compatible(prtype & DATA_MYSQL_TYPE_MASK)); - if (CHARSET_INFO *cs= get_charset(dtype_get_charset_coll(prtype), - MYF(MY_WME))) + if (CHARSET_INFO *cs= all_charsets[dtype_get_charset_coll(prtype)]) return cs->coll->strnncollsp_nchars(cs, data1, len1, data2, len2, std::max(len1, len2)); goto no_collation; From f7f0bc748e88f911b957d3dbf3bc0828a33675fb Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 13 Apr 2022 13:16:49 +0200 Subject: [PATCH 3/7] cleanup: un-inline dtype_get_mblen() per Marko request --- storage/innobase/handler/ha_innodb.cc | 25 ++++++++++++++++- storage/innobase/include/data0type.h | 1 - storage/innobase/include/data0type.inl | 34 ------------------------ storage/innobase/include/ha_prototypes.h | 9 ------- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 528f810bf8d..cec7fe3c615 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2406,7 +2406,7 @@ innobase_mysql_print_thd( /******************************************************************//** Get the variable length bounds of the given character set. */ -void +static void innobase_get_cset_width( /*====================*/ ulint cset, /*!< in: MySQL charset-collation code */ @@ -2446,6 +2446,29 @@ innobase_get_cset_width( } } +/*********************************************************************//** +Compute the mbminlen and mbmaxlen members of a data type structure. */ +void +dtype_get_mblen( +/*============*/ + ulint mtype, /*!< in: main type */ + ulint prtype, /*!< in: precise type (and collation) */ + unsigned*mbminlen, /*!< out: minimum length of a + multi-byte character */ + unsigned*mbmaxlen) /*!< out: maximum length of a + multi-byte character */ +{ + if (dtype_is_string_type(mtype)) { + innobase_get_cset_width(dtype_get_charset_coll(prtype), + mbminlen, mbmaxlen); + ut_ad(*mbminlen <= *mbmaxlen); + ut_ad(*mbminlen < DATA_MBMAX); + ut_ad(*mbmaxlen < DATA_MBMAX); + } else { + *mbminlen = *mbmaxlen = 0; + } +} + /******************************************************************//** Converts an identifier to a table name. */ void diff --git a/storage/innobase/include/data0type.h b/storage/innobase/include/data0type.h index 5c79458e5a9..40d9412d27f 100644 --- a/storage/innobase/include/data0type.h +++ b/storage/innobase/include/data0type.h @@ -325,7 +325,6 @@ dtype_get_prtype( /*********************************************************************//** Compute the mbminlen and mbmaxlen members of a data type structure. */ -UNIV_INLINE void dtype_get_mblen( /*============*/ diff --git a/storage/innobase/include/data0type.inl b/storage/innobase/include/data0type.inl index 06d90959855..329cee5d190 100644 --- a/storage/innobase/include/data0type.inl +++ b/storage/innobase/include/data0type.inl @@ -64,30 +64,6 @@ dtype_get_mysql_type( return(type->prtype & 0xFFUL); } -/*********************************************************************//** -Compute the mbminlen and mbmaxlen members of a data type structure. */ -UNIV_INLINE -void -dtype_get_mblen( -/*============*/ - ulint mtype, /*!< in: main type */ - ulint prtype, /*!< in: precise type (and collation) */ - unsigned*mbminlen, /*!< out: minimum length of a - multi-byte character */ - unsigned*mbmaxlen) /*!< out: maximum length of a - multi-byte character */ -{ - if (dtype_is_string_type(mtype)) { - innobase_get_cset_width(dtype_get_charset_coll(prtype), - mbminlen, mbmaxlen); - ut_ad(*mbminlen <= *mbmaxlen); - ut_ad(*mbminlen < DATA_MBMAX); - ut_ad(*mbmaxlen < DATA_MBMAX); - } else { - *mbminlen = *mbmaxlen = 0; - } -} - /*********************************************************************//** Compute the mbminlen and mbmaxlen members of a data type structure. */ UNIV_INLINE @@ -374,16 +350,6 @@ dtype_get_fixed_size_low( } else if (!comp) { return static_cast(len); } else { -#ifdef UNIV_DEBUG - unsigned i_mbminlen, i_mbmaxlen; - - innobase_get_cset_width( - dtype_get_charset_coll(prtype), - &i_mbminlen, &i_mbmaxlen); - - ut_ad(i_mbminlen == mbminlen); - ut_ad(i_mbmaxlen == mbmaxlen); -#endif /* UNIV_DEBUG */ if (mbminlen == mbmaxlen) { return static_cast(len); } diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index 2dd7c571386..3d217dc3243 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -139,15 +139,6 @@ at least ENUM and SET, and unsigned integer types are 'unsigned types' uint8_t get_innobase_type_from_mysql_type(unsigned *unsigned_flag, const Field *field); -/******************************************************************//** -Get the variable length bounds of the given character set. */ -void -innobase_get_cset_width( -/*====================*/ - ulint cset, /*!< in: MySQL charset-collation code */ - unsigned*mbminlen, /*!< out: minimum length of a char (in bytes) */ - unsigned*mbmaxlen); /*!< out: maximum length of a char (in bytes) */ - /******************************************************************//** Compares NUL-terminated UTF-8 strings case insensitively. @return 0 if a=b, <0 if a1 if a>b */ From 0cd2e6c61478baf91235a66f0357974a26f02ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 14 Apr 2022 10:06:34 +0300 Subject: [PATCH 4/7] MDEV-28313: InnoDB transactions are not aligned at cache lines trx_lock_t: Remove byte pad[256] and use alignas(CPU_LEVEL1_DCACHE_LINESIZE) instead. trx_t: Declare n_ref (the first member) aligned at cache line. Pool: Assert that the sizes are multiples of CPU_LEVEL1_DCACHE_LINESIZE, and invoke an aligned allocator. --- storage/innobase/include/trx0sys.h | 2 +- storage/innobase/include/trx0trx.h | 15 ++++++++------- storage/innobase/include/ut0pool.h | 25 ++++++++++++++++++------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index cbac3fd3a94..aa3cdd6a24b 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2021, MariaDB Corporation. +Copyright (c) 2017, 2022, 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 diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 6b9ffdc6374..2fd04353a2b 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -387,13 +387,13 @@ struct trx_lock_t only be modified by the thread that is serving the running transaction. */ - /** Pre-allocated record locks */ - struct { - ib_lock_t lock; byte pad[256]; - } rec_pool[8]; + /** Pre-allocated record locks */ + struct { + alignas(CPU_LEVEL1_DCACHE_LINESIZE) ib_lock_t lock; + } rec_pool[8]; - /** Pre-allocated table locks */ - ib_lock_t table_pool[8]; + /** Pre-allocated table locks */ + ib_lock_t table_pool[8]; /** Memory heap for trx_locks. Protected by lock_sys.assert_locked() and lock_sys.is_writer() || trx->mutex_is_owner(). */ @@ -583,6 +583,7 @@ private: that it is no longer "active". */ + alignas(CPU_LEVEL1_DCACHE_LINESIZE) Atomic_counter n_ref; @@ -698,7 +699,7 @@ public: /** The locks of the transaction. Protected by lock_sys.latch (insertions also by trx_t::mutex). */ - trx_lock_t lock; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) trx_lock_t lock; #ifdef WITH_WSREP /** whether wsrep_on(mysql_thd) held at the start of transaction */ diff --git a/storage/innobase/include/ut0pool.h b/storage/innobase/include/ut0pool.h index 41b02e0a985..ccea69fe549 100644 --- a/storage/innobase/include/ut0pool.h +++ b/storage/innobase/include/ut0pool.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2013, 2014, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2020, MariaDB Corporation. +Copyright (c) 2018, 2022, 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 @@ -31,7 +31,7 @@ Created 2012-Feb-26 Sunny Bains #include #include -#include "ut0new.h" +#include /** Allocate the memory for the object in blocks. We keep the objects sorted on pointer so that they are closer together in case they have to be iterated @@ -41,8 +41,6 @@ struct Pool { typedef Type value_type; - // FIXME: Add an assertion to check alignment and offset is - // as we expect it. Also, sizeof(void*) can be 8, can we impove on this. struct Element { Pool* m_pool; value_type m_type; @@ -57,17 +55,30 @@ struct Pool { m_size(size), m_last() { + ut_ad(ut_is_2pow(size)); ut_a(size >= sizeof(Element)); + static_assert(!(sizeof(Element) % CPU_LEVEL1_DCACHE_LINESIZE), + "alignment"); m_lock_strategy.create(); ut_a(m_start == 0); - m_start = reinterpret_cast(ut_zalloc_nokey(m_size)); +#ifdef _MSC_VER + m_start = static_cast( + _aligned_malloc(m_size, CPU_LEVEL1_DCACHE_LINESIZE)); +#else + void* start; + ut_a(!posix_memalign(&start, CPU_LEVEL1_DCACHE_LINESIZE, + m_size)); + m_start = static_cast(start); +#endif + memset_aligned( + m_start, 0, m_size); m_last = m_start; - m_end = &m_start[m_size / sizeof(*m_start)]; + m_end = &m_start[m_size / sizeof *m_start]; /* Note: Initialise only a small subset, even though we have allocated all the memory. This is required only because PFS @@ -90,7 +101,7 @@ struct Pool { Factory::destroy(&elem->m_type); } - ut_free(m_start); + IF_WIN(_aligned_free,free)(m_start); m_end = m_last = m_start = 0; m_size = 0; } From 8074ab57843234198a711dda101d2b2690c41df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 14 Apr 2022 10:10:44 +0300 Subject: [PATCH 5/7] MDEV-28313: Shrink rw_trx_hash_element_t::mutex The element mutex is unnecessarily large. The PERFORMANCE_SCHEMA instrumentation was not even enabled. --- storage/innobase/handler/ha_innodb.cc | 1 - storage/innobase/include/trx0sys.h | 35 ++++++++++++--------------- storage/innobase/lock/lock0lock.cc | 12 ++++----- storage/innobase/trx/trx0roll.cc | 10 ++++---- storage/innobase/trx/trx0trx.cc | 14 +++++------ 5 files changed, 34 insertions(+), 38 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index cec7fe3c615..625093e25f4 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -546,7 +546,6 @@ mysql_pfs_key_t trx_sys_mutex_key; mysql_pfs_key_t srv_threads_mutex_key; mysql_pfs_key_t thread_mutex_key; mysql_pfs_key_t row_drop_list_mutex_key; -mysql_pfs_key_t rw_trx_hash_element_mutex_key; mysql_pfs_key_t read_view_mutex_key; /* all_innodb_mutexes array contains mutexes that are diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index aa3cdd6a24b..16414f2841f 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -40,7 +40,6 @@ Created 3/26/1996 Heikki Tuuri #ifdef UNIV_PFS_MUTEX extern mysql_pfs_key_t trx_sys_mutex_key; -extern mysql_pfs_key_t rw_trx_hash_element_mutex_key; #endif /** Checks if a page address is the trx sys header page. @@ -335,16 +334,14 @@ trx_t* current_trx(); struct rw_trx_hash_element_t { - rw_trx_hash_element_t(): trx(0) + rw_trx_hash_element_t() { - mysql_mutex_init(rw_trx_hash_element_mutex_key, &mutex, nullptr); + memset(reinterpret_cast(this), 0, sizeof *this); + mutex.init(); } - ~rw_trx_hash_element_t() - { - mysql_mutex_destroy(&mutex); - } + ~rw_trx_hash_element_t() { mutex.destroy(); } trx_id_t id; /* lf_hash_init() relies on this to be first in the struct */ @@ -357,7 +354,7 @@ struct rw_trx_hash_element_t */ Atomic_counter no; trx_t *trx; - mysql_mutex_t mutex; + srw_mutex mutex; }; @@ -526,10 +523,10 @@ class rw_trx_hash_t static my_bool debug_iterator(rw_trx_hash_element_t *element, debug_iterator_arg *arg) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (element->trx) validate_element(element->trx); - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return arg->action(element, arg->argument); } #endif @@ -631,7 +628,7 @@ public: sizeof(trx_id_t))); if (element) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); lf_hash_search_unpin(pins); if ((trx= element->trx)) { DBUG_ASSERT(trx_id == trx->id); @@ -652,7 +649,7 @@ public: trx->reference(); } } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); } if (!caller_trx) lf_hash_put_pins(pins); @@ -686,9 +683,9 @@ public: void erase(trx_t *trx) { ut_d(validate_element(trx)); - mysql_mutex_lock(&trx->rw_trx_hash_element->mutex); - trx->rw_trx_hash_element->trx= 0; - mysql_mutex_unlock(&trx->rw_trx_hash_element->mutex); + trx->rw_trx_hash_element->mutex.wr_lock(); + trx->rw_trx_hash_element->trx= nullptr; + trx->rw_trx_hash_element->mutex.wr_unlock(); int res= lf_hash_delete(&hash, get_pins(trx), reinterpret_cast(&trx->id), sizeof(trx_id_t)); @@ -722,12 +719,12 @@ public: May return element with committed transaction. If caller doesn't like to see committed transactions, it has to skip those under element mutex: - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t trx= element->trx) { // trx is protected against commit in this branch } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); May miss concurrently inserted transactions. @@ -1180,11 +1177,11 @@ private: { if (element->id < *id) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); /* We don't care about read-only transactions here. */ if (element->trx && element->trx->rsegs.m_redo.rseg) *id= element->id; - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); } return 0; } diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index f920ac1ac95..05fdf9b3efe 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -4868,7 +4868,7 @@ static void lock_rec_block_validate(const page_id_t page_id) static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*) { lock_sys.assert_locked(); - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (element->trx) { check_trx_state(element->trx); @@ -4878,7 +4878,7 @@ static my_bool lock_validate_table_locks(rw_trx_hash_element_t *element, void*) if (lock->is_table()) lock_table_queue_validate(lock->un_member.tab_lock.table); } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return 0; } @@ -5075,7 +5075,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback( rw_trx_hash_element_t *element, lock_rec_other_trx_holds_expl_arg *arg) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (element->trx) { element->trx->mutex_lock(); @@ -5091,7 +5091,7 @@ static my_bool lock_rec_other_trx_holds_expl_callback( ut_ad(!expl_lock || expl_lock->trx == &arg->impl_trx); element->trx->mutex_unlock(); } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return 0; } @@ -5835,7 +5835,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element, const dict_table_t *table) { lock_sys.assert_locked(); - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (element->trx) { element->trx->mutex_lock(); @@ -5859,7 +5859,7 @@ static my_bool lock_table_locks_lookup(rw_trx_hash_element_t *element, } element->trx->mutex_unlock(); } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return 0; } #endif /* UNIV_DEBUG */ diff --git a/storage/innobase/trx/trx0roll.cc b/storage/innobase/trx/trx0roll.cc index 8fd9f93909c..ddad699ead4 100644 --- a/storage/innobase/trx/trx0roll.cc +++ b/storage/innobase/trx/trx0roll.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2021, MariaDB Corporation. +Copyright (c) 2016, 2022, 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 @@ -631,7 +631,7 @@ struct trx_roll_count_callback_arg static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element, trx_roll_count_callback_arg *arg) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t *trx= element->trx) { if (trx->is_recovered && trx_state_eq(trx, TRX_STATE_ACTIVE)) @@ -640,7 +640,7 @@ static my_bool trx_roll_count_callback(rw_trx_hash_element_t *element, arg->n_rows+= trx->undo_no; } } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return 0; } @@ -678,7 +678,7 @@ void trx_roll_report_progress() static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element, std::vector *trx_list) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t *trx= element->trx) { trx->mutex_lock(); @@ -686,7 +686,7 @@ static my_bool trx_rollback_recovered_callback(rw_trx_hash_element_t *element, trx_list->push_back(trx); trx->mutex_unlock(); } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return 0; } diff --git a/storage/innobase/trx/trx0trx.cc b/storage/innobase/trx/trx0trx.cc index 7b070a605f4..3c3c4db2b3e 100644 --- a/storage/innobase/trx/trx0trx.cc +++ b/storage/innobase/trx/trx0trx.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2021, MariaDB Corporation. +Copyright (c) 2015, 2022, 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 @@ -1914,7 +1914,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, trx_recover_for_mysql_callback_arg *arg) { DBUG_ASSERT(arg->len > 0); - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t *trx= element->trx) { /* @@ -1940,7 +1940,7 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, } } } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); /* Do not terminate upon reaching arg->len; count all transactions */ return false; } @@ -1949,13 +1949,13 @@ static my_bool trx_recover_for_mysql_callback(rw_trx_hash_element_t *element, static my_bool trx_recover_reset_callback(rw_trx_hash_element_t *element, void*) { - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t *trx= element->trx) { if (trx_state_eq(trx, TRX_STATE_PREPARED_RECOVERED)) trx->state= TRX_STATE_PREPARED; } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return false; } @@ -2004,7 +2004,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element, trx_get_trx_by_xid_callback_arg *arg) { my_bool found= 0; - mysql_mutex_lock(&element->mutex); + element->mutex.wr_lock(); if (trx_t *trx= element->trx) { trx->mutex_lock(); @@ -2026,7 +2026,7 @@ static my_bool trx_get_trx_by_xid_callback(rw_trx_hash_element_t *element, } trx->mutex_unlock(); } - mysql_mutex_unlock(&element->mutex); + element->mutex.wr_unlock(); return found; } From 03f9bb8c902a7ff25952e214b7b832ac86cc9783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 14 Apr 2022 10:21:43 +0300 Subject: [PATCH 6/7] MDEV-28313: Shrink ReadView::m_mutex A few PERFORMANCE_SCHEMA instrumentation keys were not exposed in all_innodb_mutexes[]. Let us remove them. The keys fts_pll_tokenize_mutex_key and read_view_mutex_key were internally used. Let us make ReadView::m_mutex use the simpler and smaller srw_mutex, hoping to improve memory access patterns. --- storage/innobase/handler/ha_innodb.cc | 4 ---- storage/innobase/include/read0types.h | 31 ++++++++++++--------------- storage/innobase/include/univ.i | 3 --- storage/innobase/read/read0read.cc | 6 +++--- storage/innobase/row/row0ftsort.cc | 5 ++--- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 625093e25f4..3090d93c6e8 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -522,7 +522,6 @@ mysql_pfs_key_t fts_cache_mutex_key; mysql_pfs_key_t fts_cache_init_mutex_key; mysql_pfs_key_t fts_delete_mutex_key; mysql_pfs_key_t fts_doc_id_mutex_key; -mysql_pfs_key_t fts_pll_tokenize_mutex_key; mysql_pfs_key_t ibuf_bitmap_mutex_key; mysql_pfs_key_t ibuf_mutex_key; mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key; @@ -544,9 +543,6 @@ mysql_pfs_key_t trx_pool_manager_mutex_key; mysql_pfs_key_t lock_wait_mutex_key; mysql_pfs_key_t trx_sys_mutex_key; mysql_pfs_key_t srv_threads_mutex_key; -mysql_pfs_key_t thread_mutex_key; -mysql_pfs_key_t row_drop_list_mutex_key; -mysql_pfs_key_t read_view_mutex_key; /* all_innodb_mutexes array contains mutexes that are performance schema instrumented if "UNIV_PFS_MUTEX" diff --git a/storage/innobase/include/read0types.h b/storage/innobase/include/read0types.h index 37d97ebcaac..bc02fc065f5 100644 --- a/storage/innobase/include/read0types.h +++ b/storage/innobase/include/read0types.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2021, MariaDB Corporation. +Copyright (c) 2018, 2022, 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 @@ -28,12 +28,9 @@ Created 2/16/1997 Heikki Tuuri #include "dict0mem.h" #include "trx0types.h" +#include "srw_lock.h" #include -#ifdef UNIV_PFS_MUTEX -extern mysql_pfs_key_t read_view_mutex_key; -#endif - /** Read view lists the trx ids of those transactions for which a consistent read should not see the modifications to the database. @@ -44,7 +41,7 @@ class ReadViewBase The read should not see any transaction with trx id >= this value. In other words, this is the "high water mark". */ - trx_id_t m_low_limit_id; + trx_id_t m_low_limit_id= 0; /** The read should see all trx ids which are strictly @@ -70,9 +67,6 @@ protected: trx_id_t up_limit_id() const { return m_up_limit_id; } public: - ReadViewBase(): m_low_limit_id(0) {} - - /** Append state from another view. @@ -206,7 +200,7 @@ class ReadView: public ReadViewBase std::atomic m_open; /** For synchronisation with purge coordinator. */ - mutable mysql_mutex_t m_mutex; + mutable srw_mutex m_mutex; /** trx id of creating transaction. @@ -215,9 +209,12 @@ class ReadView: public ReadViewBase trx_id_t m_creator_trx_id; public: - ReadView(): m_open(false) - { mysql_mutex_init(read_view_mutex_key, &m_mutex, nullptr); } - ~ReadView() { mysql_mutex_destroy(&m_mutex); } + ReadView() + { + memset(reinterpret_cast(this), 0, sizeof *this); + m_mutex.init(); + } + ~ReadView() { m_mutex.destroy(); } /** @@ -265,12 +262,12 @@ public: */ void print_limits(FILE *file) const { - mysql_mutex_lock(&m_mutex); + m_mutex.wr_lock(); if (is_open()) fprintf(file, "Trx read view will not see trx with" " id >= " TRX_ID_FMT ", sees < " TRX_ID_FMT "\n", low_limit_id(), up_limit_id()); - mysql_mutex_unlock(&m_mutex); + m_mutex.wr_unlock(); } @@ -289,10 +286,10 @@ public: */ void append_to(ReadViewBase *to) const { - mysql_mutex_lock(&m_mutex); + m_mutex.wr_lock(); if (is_open()) to->append(*this); - mysql_mutex_unlock(&m_mutex); + m_mutex.wr_unlock(); } /** diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index a5ad43a58ae..ced26762ff7 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -540,7 +540,6 @@ extern mysql_pfs_key_t fts_cache_mutex_key; extern mysql_pfs_key_t fts_cache_init_mutex_key; extern mysql_pfs_key_t fts_delete_mutex_key; extern mysql_pfs_key_t fts_doc_id_mutex_key; -extern mysql_pfs_key_t fts_pll_tokenize_mutex_key; extern mysql_pfs_key_t ibuf_bitmap_mutex_key; extern mysql_pfs_key_t ibuf_mutex_key; extern mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key; @@ -561,8 +560,6 @@ extern mysql_pfs_key_t trx_pool_mutex_key; extern mysql_pfs_key_t trx_pool_manager_mutex_key; extern mysql_pfs_key_t lock_wait_mutex_key; extern mysql_pfs_key_t srv_threads_mutex_key; -extern mysql_pfs_key_t thread_mutex_key; -extern mysql_pfs_key_t row_drop_list_mutex_key; # endif /* UNIV_PFS_MUTEX */ # ifdef UNIV_PFS_RWLOCK diff --git a/storage/innobase/read/read0read.cc b/storage/innobase/read/read0read.cc index ff34765244e..05d12fa7f21 100644 --- a/storage/innobase/read/read0read.cc +++ b/storage/innobase/read/read0read.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2018, 2021, MariaDB Corporation. +Copyright (c) 2018, 2022, 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 @@ -226,10 +226,10 @@ void ReadView::open(trx_t *trx) m_open.store(true, std::memory_order_relaxed); else { - mysql_mutex_lock(&m_mutex); + m_mutex.wr_lock(); snapshot(trx); m_open.store(true, std::memory_order_relaxed); - mysql_mutex_unlock(&m_mutex); + m_mutex.wr_unlock(); } } } diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index 81cf283c5e0..cc8844c3bd4 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2021, MariaDB Corporation. +Copyright (c) 2015, 2022, 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 @@ -285,8 +285,7 @@ row_fts_psort_info_init( psort_info[j].psort_common = common_info; psort_info[j].error = DB_SUCCESS; psort_info[j].memory_used = 0; - mysql_mutex_init(fts_pll_tokenize_mutex_key, - &psort_info[j].mutex, nullptr); + mysql_mutex_init(0, &psort_info[j].mutex, nullptr); } /* Initialize merge_info structures parallel merge and insert From 2aed566d2267a824158025c09830bc6353ec88a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 14 Apr 2022 10:40:26 +0300 Subject: [PATCH 7/7] Cleanup: alignas(CPU_LEVEL1_DCACHE_LINESIZE) Let us replace all use of MY_ALIGNED in InnoDB with C++11 alignas. CACHE_LINE_SIZE: Replaced with CPU_LEVEL1_DCACHE_LINESIZE. --- storage/innobase/handler/ha_innodb.cc | 2 +- storage/innobase/include/buf0buf.h | 4 ++-- storage/innobase/include/dict0dict.h | 2 +- storage/innobase/include/lock0lock.h | 4 ++-- storage/innobase/include/log0log.h | 6 +++--- storage/innobase/include/srv0srv.h | 2 +- storage/innobase/include/trx0purge.h | 2 +- storage/innobase/include/trx0rseg.h | 2 +- storage/innobase/include/trx0sys.h | 11 ++++++----- storage/innobase/include/ut0counter.h | 20 ++++++-------------- tpool/tpool_generic.cc | 4 ++-- 11 files changed, 26 insertions(+), 33 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3090d93c6e8..3f11061258c 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -1229,7 +1229,7 @@ struct log_flush_request }; /** Buffer of pending innodb_log_flush_request() */ -MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) static +alignas(CPU_LEVEL1_DCACHE_LINESIZE) static struct { /** first request */ diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 9e341546c6a..a1b4ea53c3e 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1585,7 +1585,7 @@ public: static constexpr uint32_t READ_AHEAD_PAGES= 64; /** Buffer pool mutex */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t mutex; /** Number of pending LRU flush; protected by mutex. */ ulint n_flush_LRU_; /** broadcast when n_flush_LRU reaches 0; protected by mutex */ @@ -1767,7 +1767,7 @@ public: /** mutex protecting flush_list, buf_page_t::set_oldest_modification() and buf_page_t::list pointers when !oldest_modification() */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t flush_list_mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t flush_list_mutex; /** "hazard pointer" for flush_list scans; protected by flush_list_mutex */ FlushHp flush_hp; /** modified blocks (a subset of LRU) */ diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index d84c737b0f5..f3a00a81f6b 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -1354,7 +1354,7 @@ class dict_sys_t std::atomic latch_ex_wait_start; /** the rw-latch protecting the data dictionary cache */ - MY_ALIGNED(CACHE_LINE_SIZE) srw_lock latch; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) srw_lock latch; #ifdef UNIV_DEBUG /** whether latch is being held in exclusive mode (by any thread) */ bool latch_ex; diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index e4ceff6dec2..e711bf03444 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -684,7 +684,7 @@ private: bool m_initialised; /** mutex proteting the locks */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) srw_spin_lock latch; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) srw_spin_lock latch; #ifdef UNIV_DEBUG /** The owner of exclusive latch (0 if none); protected by latch */ std::atomic writer{0}; @@ -707,7 +707,7 @@ public: hash_table prdt_page_hash; /** mutex covering lock waits; @see trx_lock_t::wait_lock */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t wait_mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t wait_mutex; private: /** The increment of wait_count for a wait. Anything smaller is a pending wait count. */ diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index 0d24d4a4e4f..629ddacdf1b 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -451,7 +451,7 @@ struct log_t{ private: /** The log sequence number of the last change of durable InnoDB files */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) + alignas(CPU_LEVEL1_DCACHE_LINESIZE) std::atomic lsn; /** the first guaranteed-durable log sequence number */ std::atomic flushed_to_disk_lsn; @@ -461,7 +461,7 @@ private: std::atomic check_flush_or_checkpoint_; public: /** mutex protecting the log */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t mutex; /** first free offset within the log buffer in use */ size_t buf_free; /** recommended maximum size of buf, after which the buffer is flushed */ @@ -470,7 +470,7 @@ public: dirty blocks in the list. The idea behind this mutex is to be able to release log_sys.mutex during mtr_commit and still ensure that insertions in the flush_list happen in the LSN order. */ - MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t flush_order_mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t flush_order_mutex; /** log_buffer, append data here */ byte *buf; /** log_buffer, writing data to file from this buffer. diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index b045885034e..2749e8e53b6 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -55,7 +55,7 @@ Created 10/10/1995 Heikki Tuuri /** Simple non-atomic counter @tparam Type the integer type of the counter */ template -struct MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) simple_counter +struct alignas(CPU_LEVEL1_DCACHE_LINESIZE) simple_counter { /** Increment the counter */ Type inc() { return add(1); } diff --git a/storage/innobase/include/trx0purge.h b/storage/innobase/include/trx0purge.h index b3f2fbeedf3..ef9111845a6 100644 --- a/storage/innobase/include/trx0purge.h +++ b/storage/innobase/include/trx0purge.h @@ -125,7 +125,7 @@ class purge_sys_t { public: /** latch protecting view, m_enabled */ - MY_ALIGNED(CACHE_LINE_SIZE) mutable srw_spin_lock latch; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mutable srw_spin_lock latch; private: /** The purge will not remove undo logs which are >= this view */ ReadViewBase view; diff --git a/storage/innobase/include/trx0rseg.h b/storage/innobase/include/trx0rseg.h index 8662dd18e61..f03e33db6f3 100644 --- a/storage/innobase/include/trx0rseg.h +++ b/storage/innobase/include/trx0rseg.h @@ -81,7 +81,7 @@ void trx_temp_rseg_create(); #define TRX_RSEG_MAX_N_TRXS (TRX_RSEG_N_SLOTS / 2) /** The rollback segment memory object */ -struct MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) trx_rseg_t +struct alignas(CPU_LEVEL1_DCACHE_LINESIZE) trx_rseg_t { /** tablespace containing the rollback segment; constant after init() */ fil_space_t *space; diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index 16414f2841f..1f33a9db091 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -830,8 +830,8 @@ public: void unfreeze() const { mysql_mutex_unlock(&mutex); } private: - alignas(CACHE_LINE_SIZE) mutable mysql_mutex_t mutex; - alignas(CACHE_LINE_SIZE) ilist trx_list; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) mutable mysql_mutex_t mutex; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) ilist trx_list; }; /** The transaction system central memory data structure. */ @@ -841,7 +841,7 @@ class trx_sys_t The smallest number not yet assigned as a transaction id or transaction number. Accessed and updated with atomic operations. */ - MY_ALIGNED(CACHE_LINE_SIZE) Atomic_counter m_max_trx_id; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) Atomic_counter m_max_trx_id; /** @@ -852,7 +852,8 @@ class trx_sys_t @sa assign_new_trx_no() @sa snapshot_ids() */ - MY_ALIGNED(CACHE_LINE_SIZE) std::atomic m_rw_trx_hash_version; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) + std::atomic m_rw_trx_hash_version; bool m_initialised; @@ -872,7 +873,7 @@ public: Works faster when it is on it's own cache line (tested). */ - MY_ALIGNED(CACHE_LINE_SIZE) rw_trx_hash_t rw_trx_hash; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) rw_trx_hash_t rw_trx_hash; #ifdef WITH_WSREP diff --git a/storage/innobase/include/ut0counter.h b/storage/innobase/include/ut0counter.h index 448768ec29a..94a674b2c32 100644 --- a/storage/innobase/include/ut0counter.h +++ b/storage/innobase/include/ut0counter.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2012, 2015, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, 2019, MariaDB Corporation. +Copyright (c) 2017, 2022, 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 @@ -31,13 +31,6 @@ Created 2012/04/12 by Sunny Bains #include "os0thread.h" #include "my_rdtsc.h" -/** CPU cache line size */ -#ifdef CPU_LEVEL1_DCACHE_LINESIZE -# define CACHE_LINE_SIZE CPU_LEVEL1_DCACHE_LINESIZE -#else -# error CPU_LEVEL1_DCACHE_LINESIZE is undefined -#endif /* CPU_LEVEL1_DCACHE_LINESIZE */ - /** Use the result of my_timer_cycles(), which mainly uses RDTSC for cycles as a random value. See the comments for my_timer_cycles() */ /** @return result from RDTSC or similar functions. */ @@ -71,19 +64,18 @@ be zero-initialized by the run-time environment. @see srv_stats */ template struct ib_atomic_counter_element_t { - MY_ALIGNED(CACHE_LINE_SIZE) Atomic_relaxed value; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) Atomic_relaxed value; }; template struct ib_counter_element_t { - MY_ALIGNED(CACHE_LINE_SIZE) Type value; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) Type value; }; /** Class for using fuzzy counters. The counter is multi-instance relaxed atomic so the results are not guaranteed to be 100% accurate but close -enough. Creates an array of counters and separates each element by the -CACHE_LINE_SIZE bytes */ +enough. */ template class Element = ib_atomic_counter_element_t, int N = 128 > @@ -123,9 +115,9 @@ struct ib_counter_t { } private: - static_assert(sizeof(Element) == CACHE_LINE_SIZE, ""); + static_assert(sizeof(Element) == CPU_LEVEL1_DCACHE_LINESIZE, ""); /** Array of counter elements */ - MY_ALIGNED(CACHE_LINE_SIZE) Element m_counter[N]; + alignas(CPU_LEVEL1_DCACHE_LINESIZE) Element m_counter[N]; }; #endif /* ut0counter_h */ diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index 5720c5b48aa..22d29d6400b 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2019, 2021, MariaDB Corporation. +/* Copyright (C) 2019, 2022, MariaDB Corporation. This program is free software; you can redistribute itand /or modify it under the terms of the GNU General Public License as published by @@ -128,7 +128,7 @@ enum worker_wake_reason /* A per-worker thread structure.*/ -struct MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) worker_data +struct alignas(CPU_LEVEL1_DCACHE_LINESIZE) worker_data { /** Condition variable to wakeup this worker.*/ std::condition_variable m_cv;