Skip to content

Commit

Permalink
MDEV-28313: Shrink ReadView::m_mutex
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Apr 14, 2022
1 parent 8074ab5 commit 03f9bb8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
4 changes: 0 additions & 4 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down
31 changes: 14 additions & 17 deletions storage/innobase/include/read0types.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,12 +28,9 @@ Created 2/16/1997 Heikki Tuuri

#include "dict0mem.h"
#include "trx0types.h"
#include "srw_lock.h"
#include <algorithm>

#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.
Expand All @@ -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
Expand All @@ -70,9 +67,6 @@ class ReadViewBase
trx_id_t up_limit_id() const { return m_up_limit_id; }

public:
ReadViewBase(): m_low_limit_id(0) {}


/**
Append state from another view.
Expand Down Expand Up @@ -206,7 +200,7 @@ class ReadView: public ReadViewBase
std::atomic<bool> m_open;

/** For synchronisation with purge coordinator. */
mutable mysql_mutex_t m_mutex;
mutable srw_mutex m_mutex;

/**
trx id of creating transaction.
Expand All @@ -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<void*>(this), 0, sizeof *this);
m_mutex.init();
}
~ReadView() { m_mutex.destroy(); }


/**
Expand Down Expand Up @@ -265,12 +262,12 @@ class ReadView: public ReadViewBase
*/
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();
}


Expand All @@ -289,10 +286,10 @@ class ReadView: public ReadViewBase
*/
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();
}

/**
Expand Down
3 changes: 0 additions & 3 deletions storage/innobase/include/univ.i
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/read/read0read.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions storage/innobase/row/row0ftsort.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 03f9bb8

Please sign in to comment.