mariadb/include/mysql/psi/mysql_thread.h

1357 lines
35 KiB
C
Raw Normal View History

2022-07-29 14:48:01 +02:00
/* Copyright (c) 2008, 2022, Oracle and/or its affiliates.
MDEV-23399: Performance regression with write workloads The buffer pool refactoring in MDEV-15053 and MDEV-22871 shifted the performance bottleneck to the page flushing. The configuration parameters will be changed as follows: innodb_lru_flush_size=32 (new: how many pages to flush on LRU eviction) innodb_lru_scan_depth=1536 (old: 1024) innodb_max_dirty_pages_pct=90 (old: 75) innodb_max_dirty_pages_pct_lwm=75 (old: 0) Note: The parameter innodb_lru_scan_depth will only affect LRU eviction of buffer pool pages when a new page is being allocated. The page cleaner thread will no longer evict any pages. It used to guarantee that some pages will remain free in the buffer pool. Now, we perform that eviction 'on demand' in buf_LRU_get_free_block(). The parameter innodb_lru_scan_depth(srv_LRU_scan_depth) is used as follows: * When the buffer pool is being shrunk in buf_pool_t::withdraw_blocks() * As a buf_pool.free limit in buf_LRU_list_batch() for terminating the flushing that is initiated e.g., by buf_LRU_get_free_block() The parameter also used to serve as an initial limit for unzip_LRU eviction (evicting uncompressed page frames while retaining ROW_FORMAT=COMPRESSED pages), but now we will use a hard-coded limit of 100 or unlimited for invoking buf_LRU_scan_and_free_block(). The status variables will be changed as follows: innodb_buffer_pool_pages_flushed: This includes also the count of innodb_buffer_pool_pages_LRU_flushed and should work reliably, updated one by one in buf_flush_page() to give more real-time statistics. The function buf_flush_stats(), which we are removing, was not called in every code path. For both counters, we will use regular variables that are incremented in a critical section of buf_pool.mutex. Note that show_innodb_vars() directly links to the variables, and reads of the counters will *not* be protected by buf_pool.mutex, so you cannot get a consistent snapshot of both variables. The following INFORMATION_SCHEMA.INNODB_METRICS counters will be removed, because the page cleaner no longer deals with writing or evicting least recently used pages, and because the single-page writes have been removed: * buffer_LRU_batch_flush_avg_time_slot * buffer_LRU_batch_flush_avg_time_thread * buffer_LRU_batch_flush_avg_time_est * buffer_LRU_batch_flush_avg_pass * buffer_LRU_single_flush_scanned * buffer_LRU_single_flush_num_scan * buffer_LRU_single_flush_scanned_per_call When moving to a single buffer pool instance in MDEV-15058, we missed some opportunity to simplify the buf_flush_page_cleaner thread. It was unnecessarily using a mutex and some complex data structures, even though we always have a single page cleaner thread. Furthermore, the buf_flush_page_cleaner thread had separate 'recovery' and 'shutdown' modes where it was waiting to be triggered by some other thread, adding unnecessary latency and potential for hangs in relatively rarely executed startup or shutdown code. The page cleaner was also running two kinds of batches in an interleaved fashion: "LRU flush" (writing out some least recently used pages and evicting them on write completion) and the normal batches that aim to increase the MIN(oldest_modification) in the buffer pool, to help the log checkpoint advance. The buf_pool.flush_list flushing was being blocked by buf_block_t::lock for no good reason. Furthermore, if the FIL_PAGE_LSN of a page is ahead of log_sys.get_flushed_lsn(), that is, what has been persistently written to the redo log, we would trigger a log flush and then resume the page flushing. This would unnecessarily limit the performance of the page cleaner thread and trigger the infamous messages "InnoDB: page_cleaner: 1000ms intended loop took 4450ms. The settings might not be optimal" that were suppressed in commit d1ab89037a518fcffbc50c24e4bd94e4ec33aed0 unless log_warnings>2. Our revised algorithm will make log_sys.get_flushed_lsn() advance at the start of buf_flush_lists(), and then execute a 'best effort' to write out all pages. The flush batches will skip pages that were modified since the log was written, or are are currently exclusively locked. The MDEV-13670 message "page_cleaner: 1000ms intended loop took" message will be removed, because by design, the buf_flush_page_cleaner() should not be blocked during a batch for extended periods of time. We will remove the single-page flushing altogether. Related to this, the debug parameter innodb_doublewrite_batch_size will be removed, because all of the doublewrite buffer will be used for flushing batches. If a page needs to be evicted from the buffer pool and all 100 least recently used pages in the buffer pool have unflushed changes, buf_LRU_get_free_block() will execute buf_flush_lists() to write out and evict innodb_lru_flush_size pages. At most one thread will execute buf_flush_lists() in buf_LRU_get_free_block(); other threads will wait for that LRU flushing batch to finish. To improve concurrency, we will replace the InnoDB ib_mutex_t and os_event_t native mutexes and condition variables in this area of code. Most notably, this means that the buffer pool mutex (buf_pool.mutex) is no longer instrumented via any InnoDB interfaces. It will continue to be instrumented via PERFORMANCE_SCHEMA. For now, both buf_pool.flush_list_mutex and buf_pool.mutex will be declared with MY_MUTEX_INIT_FAST (PTHREAD_MUTEX_ADAPTIVE_NP). The critical sections of buf_pool.flush_list_mutex should be shorter than those for buf_pool.mutex, because in the worst case, they cover a linear scan of buf_pool.flush_list, while the worst case of a critical section of buf_pool.mutex covers a linear scan of the potentially much longer buf_pool.LRU list. mysql_mutex_is_owner(), safe_mutex_is_owner(): New predicate, usable with SAFE_MUTEX. Some InnoDB debug assertions need this predicate instead of mysql_mutex_assert_owner() or mysql_mutex_assert_not_owner(). buf_pool_t::n_flush_LRU, buf_pool_t::n_flush_list: Replaces buf_pool_t::init_flush[] and buf_pool_t::n_flush[]. The number of active flush operations. buf_pool_t::mutex, buf_pool_t::flush_list_mutex: Use mysql_mutex_t instead of ib_mutex_t, to have native mutexes with PERFORMANCE_SCHEMA and SAFE_MUTEX instrumentation. buf_pool_t::done_flush_LRU: Condition variable for !n_flush_LRU. buf_pool_t::done_flush_list: Condition variable for !n_flush_list. buf_pool_t::do_flush_list: Condition variable to wake up the buf_flush_page_cleaner when a log checkpoint needs to be written or the server is being shut down. Replaces buf_flush_event. We will keep using timed waits (the page cleaner thread will wake _at least_ once per second), because the calculations for innodb_adaptive_flushing depend on fixed time intervals. buf_dblwr: Allocate statically, and move all code to member functions. Use a native mutex and condition variable. Remove code to deal with single-page flushing. buf_dblwr_check_block(): Make the check debug-only. We were spending a significant amount of execution time in page_simple_validate_new(). flush_counters_t::unzip_LRU_evicted: Remove. IORequest: Make more members const. FIXME: m_fil_node should be removed. buf_flush_sync_lsn: Protect by std::atomic, not page_cleaner.mutex (which we are removing). page_cleaner_slot_t, page_cleaner_t: Remove many redundant members. pc_request_flush_slot(): Replaces pc_request() and pc_flush_slot(). recv_writer_thread: Remove. Recovery works just fine without it, if we simply invoke buf_flush_sync() at the end of each batch in recv_sys_t::apply(). recv_recovery_from_checkpoint_finish(): Remove. We can simply call recv_sys.debug_free() directly. srv_started_redo: Replaces srv_start_state. SRV_SHUTDOWN_FLUSH_PHASE: Remove. logs_empty_and_mark_files_at_shutdown() can communicate with the normal page cleaner loop via the new function flush_buffer_pool(). buf_flush_remove(): Assert that the calling thread is holding buf_pool.flush_list_mutex. This removes unnecessary mutex operations from buf_flush_remove_pages() and buf_flush_dirty_pages(), which replace buf_LRU_flush_or_remove_pages(). buf_flush_lists(): Renamed from buf_flush_batch(), with simplified interface. Return the number of flushed pages. Clarified comments and renamed min_n to max_n. Identify LRU batch by lsn=0. Merge all the functions buf_flush_start(), buf_flush_batch(), buf_flush_end() directly to this function, which was their only caller, and remove 2 unnecessary buf_pool.mutex release/re-acquisition that we used to perform around the buf_flush_batch() call. At the start, if not all log has been durably written, wait for a background task to do it, or start a new task to do it. This allows the log write to run concurrently with our page flushing batch. Any pages that were skipped due to too recent FIL_PAGE_LSN or due to them being latched by a writer should be flushed during the next batch, unless there are further modifications to those pages. It is possible that a page that we must flush due to small oldest_modification also carries a recent FIL_PAGE_LSN or is being constantly modified. In the worst case, all writers would then end up waiting in log_free_check() to allow the flushing and the checkpoint to complete. buf_do_flush_list_batch(): Clarify comments, and rename min_n to max_n. Cache the last looked up tablespace. If neighbor flushing is not applicable, invoke buf_flush_page() directly, avoiding a page lookup in between. buf_flush_space(): Auxiliary function to look up a tablespace for page flushing. buf_flush_page(): Defer the computation of space->full_crc32(). Never call log_write_up_to(), but instead skip persistent pages whose latest modification (FIL_PAGE_LSN) is newer than the redo log. Also skip pages on which we cannot acquire a shared latch without waiting. buf_flush_try_neighbors(): Do not bother checking buf_fix_count because buf_flush_page() will no longer wait for the page latch. Take the tablespace as a parameter, and only execute this function when innodb_flush_neighbors>0. Avoid repeated calls of page_id_t::fold(). buf_flush_relocate_on_flush_list(): Declare as cold, and push down a condition from the callers. buf_flush_check_neighbor(): Take id.fold() as a parameter. buf_flush_sync(): Ensure that the buf_pool.flush_list is empty, because the flushing batch will skip pages whose modifications have not yet been written to the log or were latched for modification. buf_free_from_unzip_LRU_list_batch(): Remove redundant local variables. buf_flush_LRU_list_batch(): Let the caller buf_do_LRU_batch() initialize the counters, and report n->evicted. Cache the last looked up tablespace. If neighbor flushing is not applicable, invoke buf_flush_page() directly, avoiding a page lookup in between. buf_do_LRU_batch(): Return the number of pages flushed. buf_LRU_free_page(): Only release and re-acquire buf_pool.mutex if adaptive hash index entries are pointing to the block. buf_LRU_get_free_block(): Do not wake up the page cleaner, because it will no longer perform any useful work for us, and we do not want it to compete for I/O while buf_flush_lists(innodb_lru_flush_size, 0) writes out and evicts at most innodb_lru_flush_size pages. (The function buf_do_LRU_batch() may complete after writing fewer pages if more than innodb_lru_scan_depth pages end up in buf_pool.free list.) Eliminate some mutex release-acquire cycles, and wait for the LRU flush batch to complete before rescanning. buf_LRU_check_size_of_non_data_objects(): Simplify the code. buf_page_write_complete(): Remove the parameter evict, and always evict pages that were part of an LRU flush. buf_page_create(): Take a pre-allocated page as a parameter. buf_pool_t::free_block(): Free a pre-allocated block. recv_sys_t::recover_low(), recv_sys_t::apply(): Preallocate the block while not holding recv_sys.mutex. During page allocation, we may initiate a page flush, which in turn may initiate a log flush, which would require acquiring log_sys.mutex, which should always be acquired before recv_sys.mutex in order to avoid deadlocks. Therefore, we must not be holding recv_sys.mutex while allocating a buffer pool block. BtrBulk::logFreeCheck(): Skip a redundant condition. row_undo_step(): Do not invoke srv_inc_activity_count() for every row that is being rolled back. It should suffice to invoke the function in trx_flush_log_if_needed() during trx_t::commit_in_memory() when the rollback completes. sync_check_enable(): Remove. We will enable innodb_sync_debug from the very beginning. Reviewed by: Vladislav Vaintroub
2020-10-15 12:10:42 +03:00
Copyright (c) 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
2020-01-19 12:52:07 +01:00
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2020-01-19 12:52:07 +01:00
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
2010-07-08 11:04:07 -06:00
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
#ifndef MYSQL_THREAD_H
#define MYSQL_THREAD_H
/**
@file mysql/psi/mysql_thread.h
Instrumentation helpers for mysys threads, mutexes,
read write locks and conditions.
This header file provides the necessary declarations
to use the mysys thread API with the performance schema instrumentation.
In some compilers (SunStudio), 'static inline' functions, when declared
but not used, are not optimized away (because they are unused) by default,
so that including a static inline function from a header file does
create unwanted dependencies, causing unresolved symbols at link time.
Other compilers, like gcc, optimize these dependencies by default.
Since the instrumented APIs declared here are wrapper on top
of my_pthread / safemutex / etc APIs,
including mysql/psi/mysql_thread.h assumes that
the dependency on my_pthread and safemutex already exists.
*/
/*
Note: there are several orthogonal dimensions here.
Dimension 1: Instrumentation
HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in.
This may happen both in debug or production builds.
Dimension 2: Debug
SAFE_MUTEX is defined when debug is compiled in.
This may happen both with and without instrumentation.
Dimension 3: Platform
Mutexes are implemented with one of:
- the pthread library
- fast mutexes
- window apis
This is implemented by various macro definitions in my_pthread.h
This causes complexity with '#ifdef'-ery that can't be avoided.
*/
#include "mysql/psi/psi.h"
2019-12-10 15:35:00 +01:00
#ifdef MYSQL_SERVER
#ifndef MYSQL_DYNAMIC_PLUGIN
#include "pfs_thread_provider.h"
#endif
#endif
#ifndef PSI_MUTEX_CALL
#define PSI_MUTEX_CALL(M) PSI_DYNAMIC_CALL(M)
#endif
#ifndef PSI_RWLOCK_CALL
#define PSI_RWLOCK_CALL(M) PSI_DYNAMIC_CALL(M)
#endif
#ifndef PSI_COND_CALL
#define PSI_COND_CALL(M) PSI_DYNAMIC_CALL(M)
#endif
#ifndef PSI_THREAD_CALL
#define PSI_THREAD_CALL(M) PSI_DYNAMIC_CALL(M)
#endif
/**
@defgroup Thread_instrumentation Thread Instrumentation
@ingroup Instrumentation_interface
@{
*/
#ifdef HAVE_PSI_THREAD_INTERFACE
#define PSI_CALL_delete_current_thread PSI_THREAD_CALL(delete_current_thread)
#define PSI_CALL_get_thread PSI_THREAD_CALL(get_thread)
#define PSI_CALL_new_thread PSI_THREAD_CALL(new_thread)
#define PSI_CALL_register_thread PSI_THREAD_CALL(register_thread)
#define PSI_CALL_set_thread PSI_THREAD_CALL(set_thread)
#define PSI_CALL_set_thread_THD PSI_THREAD_CALL(set_thread_THD)
#define PSI_CALL_set_thread_connect_attrs PSI_THREAD_CALL(set_thread_connect_attrs)
#define PSI_CALL_set_thread_db PSI_THREAD_CALL(set_thread_db)
#define PSI_CALL_set_thread_id PSI_THREAD_CALL(set_thread_id)
#define PSI_CALL_set_thread_os_id PSI_THREAD_CALL(set_thread_os_id)
#define PSI_CALL_set_thread_info PSI_THREAD_CALL(set_thread_info)
#define PSI_CALL_set_thread_start_time PSI_THREAD_CALL(set_thread_start_time)
2019-12-10 15:35:00 +01:00
#define PSI_CALL_set_thread_account PSI_THREAD_CALL(set_thread_account)
#define PSI_CALL_spawn_thread PSI_THREAD_CALL(spawn_thread)
#define PSI_CALL_set_connection_type PSI_THREAD_CALL(set_connection_type)
#else
#define PSI_CALL_delete_current_thread() do { } while(0)
#define PSI_CALL_get_thread() NULL
#define PSI_CALL_new_thread(A1,A2,A3) NULL
#define PSI_CALL_register_thread(A1,A2,A3) do { } while(0)
#define PSI_CALL_set_thread(A1) do { } while(0)
#define PSI_CALL_set_thread_THD(A1,A2) do { } while(0)
#define PSI_CALL_set_thread_connect_attrs(A1,A2,A3) 0
#define PSI_CALL_set_thread_db(A1,A2) do { } while(0)
#define PSI_CALL_set_thread_id(A1,A2) do { } while(0)
#define PSI_CALL_set_thread_os_id(A1) do { } while(0)
#define PSI_CALL_set_thread_info(A1, A2) do { } while(0)
#define PSI_CALL_set_thread_start_time(A1) do { } while(0)
2019-12-10 15:35:00 +01:00
#define PSI_CALL_set_thread_account(A1, A2, A3, A4) do { } while(0)
#define PSI_CALL_spawn_thread(A1, A2, A3, A4, A5) 0
#define PSI_CALL_set_connection_type(A) do { } while(0)
#endif
/**
An instrumented mutex structure.
@sa mysql_mutex_t
*/
struct st_mysql_mutex
{
/** The real mutex. */
#ifdef SAFE_MUTEX
safe_mutex_t m_mutex;
#else
pthread_mutex_t m_mutex;
#endif
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_mutex_t interface.
*/
struct PSI_mutex *m_psi;
};
/**
Type of an instrumented mutex.
@c mysql_mutex_t is a drop-in replacement for @c pthread_mutex_t.
@sa mysql_mutex_assert_owner
@sa mysql_mutex_assert_not_owner
@sa mysql_mutex_init
@sa mysql_mutex_lock
@sa mysql_mutex_unlock
@sa mysql_mutex_destroy
*/
typedef struct st_mysql_mutex mysql_mutex_t;
/**
An instrumented rwlock structure.
@sa mysql_rwlock_t
*/
struct st_mysql_rwlock
{
/** The real rwlock */
rw_lock_t m_rwlock;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_rwlock_t interface.
*/
struct PSI_rwlock *m_psi;
};
/**
An instrumented prlock structure.
@sa mysql_prlock_t
*/
struct st_mysql_prlock
{
/** The real prlock */
rw_pr_lock_t m_prlock;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_rwlock_t interface.
*/
struct PSI_rwlock *m_psi;
};
/**
Type of an instrumented rwlock.
@c mysql_rwlock_t is a drop-in replacement for @c pthread_rwlock_t.
@sa mysql_rwlock_init
@sa mysql_rwlock_rdlock
@sa mysql_rwlock_tryrdlock
@sa mysql_rwlock_wrlock
@sa mysql_rwlock_trywrlock
@sa mysql_rwlock_unlock
@sa mysql_rwlock_destroy
*/
typedef struct st_mysql_rwlock mysql_rwlock_t;
/**
Type of an instrumented prlock.
A prlock is a read write lock that 'prefers readers' (pr).
@c mysql_prlock_t is a drop-in replacement for @c rw_pr_lock_t.
@sa mysql_prlock_init
@sa mysql_prlock_rdlock
@sa mysql_prlock_wrlock
@sa mysql_prlock_unlock
@sa mysql_prlock_destroy
*/
typedef struct st_mysql_prlock mysql_prlock_t;
/**
An instrumented cond structure.
@sa mysql_cond_t
*/
struct st_mysql_cond
{
/** The real condition */
pthread_cond_t m_cond;
/**
The instrumentation hook.
Note that this hook is not conditionally defined,
for binary compatibility of the @c mysql_cond_t interface.
*/
struct PSI_cond *m_psi;
};
/**
Type of an instrumented condition.
@c mysql_cond_t is a drop-in replacement for @c pthread_cond_t.
@sa mysql_cond_init
@sa mysql_cond_wait
@sa mysql_cond_timedwait
@sa mysql_cond_signal
@sa mysql_cond_broadcast
@sa mysql_cond_destroy
*/
typedef struct st_mysql_cond mysql_cond_t;
/*
Consider the following code:
static inline void foo() { bar(); }
when foo() is never called.
With gcc, foo() is a local static function, so the dependencies
are optimized away at compile time, and there is no dependency on bar().
With other compilers (HP, Sun Studio), the function foo() implementation
is compiled, and bar() needs to be present to link.
Due to the existing header dependencies in MySQL code, this header file
is sometime used when it is not needed, which in turn cause link failures
on some platforms.
The proper fix would be to cut these extra dependencies in the calling code.
DISABLE_MYSQL_THREAD_H is a work around to limit dependencies.
DISABLE_MYSQL_PRLOCK_H is similar, and is used to disable specifically
the prlock wrappers.
*/
#ifndef DISABLE_MYSQL_THREAD_H
MDEV-23399: Performance regression with write workloads The buffer pool refactoring in MDEV-15053 and MDEV-22871 shifted the performance bottleneck to the page flushing. The configuration parameters will be changed as follows: innodb_lru_flush_size=32 (new: how many pages to flush on LRU eviction) innodb_lru_scan_depth=1536 (old: 1024) innodb_max_dirty_pages_pct=90 (old: 75) innodb_max_dirty_pages_pct_lwm=75 (old: 0) Note: The parameter innodb_lru_scan_depth will only affect LRU eviction of buffer pool pages when a new page is being allocated. The page cleaner thread will no longer evict any pages. It used to guarantee that some pages will remain free in the buffer pool. Now, we perform that eviction 'on demand' in buf_LRU_get_free_block(). The parameter innodb_lru_scan_depth(srv_LRU_scan_depth) is used as follows: * When the buffer pool is being shrunk in buf_pool_t::withdraw_blocks() * As a buf_pool.free limit in buf_LRU_list_batch() for terminating the flushing that is initiated e.g., by buf_LRU_get_free_block() The parameter also used to serve as an initial limit for unzip_LRU eviction (evicting uncompressed page frames while retaining ROW_FORMAT=COMPRESSED pages), but now we will use a hard-coded limit of 100 or unlimited for invoking buf_LRU_scan_and_free_block(). The status variables will be changed as follows: innodb_buffer_pool_pages_flushed: This includes also the count of innodb_buffer_pool_pages_LRU_flushed and should work reliably, updated one by one in buf_flush_page() to give more real-time statistics. The function buf_flush_stats(), which we are removing, was not called in every code path. For both counters, we will use regular variables that are incremented in a critical section of buf_pool.mutex. Note that show_innodb_vars() directly links to the variables, and reads of the counters will *not* be protected by buf_pool.mutex, so you cannot get a consistent snapshot of both variables. The following INFORMATION_SCHEMA.INNODB_METRICS counters will be removed, because the page cleaner no longer deals with writing or evicting least recently used pages, and because the single-page writes have been removed: * buffer_LRU_batch_flush_avg_time_slot * buffer_LRU_batch_flush_avg_time_thread * buffer_LRU_batch_flush_avg_time_est * buffer_LRU_batch_flush_avg_pass * buffer_LRU_single_flush_scanned * buffer_LRU_single_flush_num_scan * buffer_LRU_single_flush_scanned_per_call When moving to a single buffer pool instance in MDEV-15058, we missed some opportunity to simplify the buf_flush_page_cleaner thread. It was unnecessarily using a mutex and some complex data structures, even though we always have a single page cleaner thread. Furthermore, the buf_flush_page_cleaner thread had separate 'recovery' and 'shutdown' modes where it was waiting to be triggered by some other thread, adding unnecessary latency and potential for hangs in relatively rarely executed startup or shutdown code. The page cleaner was also running two kinds of batches in an interleaved fashion: "LRU flush" (writing out some least recently used pages and evicting them on write completion) and the normal batches that aim to increase the MIN(oldest_modification) in the buffer pool, to help the log checkpoint advance. The buf_pool.flush_list flushing was being blocked by buf_block_t::lock for no good reason. Furthermore, if the FIL_PAGE_LSN of a page is ahead of log_sys.get_flushed_lsn(), that is, what has been persistently written to the redo log, we would trigger a log flush and then resume the page flushing. This would unnecessarily limit the performance of the page cleaner thread and trigger the infamous messages "InnoDB: page_cleaner: 1000ms intended loop took 4450ms. The settings might not be optimal" that were suppressed in commit d1ab89037a518fcffbc50c24e4bd94e4ec33aed0 unless log_warnings>2. Our revised algorithm will make log_sys.get_flushed_lsn() advance at the start of buf_flush_lists(), and then execute a 'best effort' to write out all pages. The flush batches will skip pages that were modified since the log was written, or are are currently exclusively locked. The MDEV-13670 message "page_cleaner: 1000ms intended loop took" message will be removed, because by design, the buf_flush_page_cleaner() should not be blocked during a batch for extended periods of time. We will remove the single-page flushing altogether. Related to this, the debug parameter innodb_doublewrite_batch_size will be removed, because all of the doublewrite buffer will be used for flushing batches. If a page needs to be evicted from the buffer pool and all 100 least recently used pages in the buffer pool have unflushed changes, buf_LRU_get_free_block() will execute buf_flush_lists() to write out and evict innodb_lru_flush_size pages. At most one thread will execute buf_flush_lists() in buf_LRU_get_free_block(); other threads will wait for that LRU flushing batch to finish. To improve concurrency, we will replace the InnoDB ib_mutex_t and os_event_t native mutexes and condition variables in this area of code. Most notably, this means that the buffer pool mutex (buf_pool.mutex) is no longer instrumented via any InnoDB interfaces. It will continue to be instrumented via PERFORMANCE_SCHEMA. For now, both buf_pool.flush_list_mutex and buf_pool.mutex will be declared with MY_MUTEX_INIT_FAST (PTHREAD_MUTEX_ADAPTIVE_NP). The critical sections of buf_pool.flush_list_mutex should be shorter than those for buf_pool.mutex, because in the worst case, they cover a linear scan of buf_pool.flush_list, while the worst case of a critical section of buf_pool.mutex covers a linear scan of the potentially much longer buf_pool.LRU list. mysql_mutex_is_owner(), safe_mutex_is_owner(): New predicate, usable with SAFE_MUTEX. Some InnoDB debug assertions need this predicate instead of mysql_mutex_assert_owner() or mysql_mutex_assert_not_owner(). buf_pool_t::n_flush_LRU, buf_pool_t::n_flush_list: Replaces buf_pool_t::init_flush[] and buf_pool_t::n_flush[]. The number of active flush operations. buf_pool_t::mutex, buf_pool_t::flush_list_mutex: Use mysql_mutex_t instead of ib_mutex_t, to have native mutexes with PERFORMANCE_SCHEMA and SAFE_MUTEX instrumentation. buf_pool_t::done_flush_LRU: Condition variable for !n_flush_LRU. buf_pool_t::done_flush_list: Condition variable for !n_flush_list. buf_pool_t::do_flush_list: Condition variable to wake up the buf_flush_page_cleaner when a log checkpoint needs to be written or the server is being shut down. Replaces buf_flush_event. We will keep using timed waits (the page cleaner thread will wake _at least_ once per second), because the calculations for innodb_adaptive_flushing depend on fixed time intervals. buf_dblwr: Allocate statically, and move all code to member functions. Use a native mutex and condition variable. Remove code to deal with single-page flushing. buf_dblwr_check_block(): Make the check debug-only. We were spending a significant amount of execution time in page_simple_validate_new(). flush_counters_t::unzip_LRU_evicted: Remove. IORequest: Make more members const. FIXME: m_fil_node should be removed. buf_flush_sync_lsn: Protect by std::atomic, not page_cleaner.mutex (which we are removing). page_cleaner_slot_t, page_cleaner_t: Remove many redundant members. pc_request_flush_slot(): Replaces pc_request() and pc_flush_slot(). recv_writer_thread: Remove. Recovery works just fine without it, if we simply invoke buf_flush_sync() at the end of each batch in recv_sys_t::apply(). recv_recovery_from_checkpoint_finish(): Remove. We can simply call recv_sys.debug_free() directly. srv_started_redo: Replaces srv_start_state. SRV_SHUTDOWN_FLUSH_PHASE: Remove. logs_empty_and_mark_files_at_shutdown() can communicate with the normal page cleaner loop via the new function flush_buffer_pool(). buf_flush_remove(): Assert that the calling thread is holding buf_pool.flush_list_mutex. This removes unnecessary mutex operations from buf_flush_remove_pages() and buf_flush_dirty_pages(), which replace buf_LRU_flush_or_remove_pages(). buf_flush_lists(): Renamed from buf_flush_batch(), with simplified interface. Return the number of flushed pages. Clarified comments and renamed min_n to max_n. Identify LRU batch by lsn=0. Merge all the functions buf_flush_start(), buf_flush_batch(), buf_flush_end() directly to this function, which was their only caller, and remove 2 unnecessary buf_pool.mutex release/re-acquisition that we used to perform around the buf_flush_batch() call. At the start, if not all log has been durably written, wait for a background task to do it, or start a new task to do it. This allows the log write to run concurrently with our page flushing batch. Any pages that were skipped due to too recent FIL_PAGE_LSN or due to them being latched by a writer should be flushed during the next batch, unless there are further modifications to those pages. It is possible that a page that we must flush due to small oldest_modification also carries a recent FIL_PAGE_LSN or is being constantly modified. In the worst case, all writers would then end up waiting in log_free_check() to allow the flushing and the checkpoint to complete. buf_do_flush_list_batch(): Clarify comments, and rename min_n to max_n. Cache the last looked up tablespace. If neighbor flushing is not applicable, invoke buf_flush_page() directly, avoiding a page lookup in between. buf_flush_space(): Auxiliary function to look up a tablespace for page flushing. buf_flush_page(): Defer the computation of space->full_crc32(). Never call log_write_up_to(), but instead skip persistent pages whose latest modification (FIL_PAGE_LSN) is newer than the redo log. Also skip pages on which we cannot acquire a shared latch without waiting. buf_flush_try_neighbors(): Do not bother checking buf_fix_count because buf_flush_page() will no longer wait for the page latch. Take the tablespace as a parameter, and only execute this function when innodb_flush_neighbors>0. Avoid repeated calls of page_id_t::fold(). buf_flush_relocate_on_flush_list(): Declare as cold, and push down a condition from the callers. buf_flush_check_neighbor(): Take id.fold() as a parameter. buf_flush_sync(): Ensure that the buf_pool.flush_list is empty, because the flushing batch will skip pages whose modifications have not yet been written to the log or were latched for modification. buf_free_from_unzip_LRU_list_batch(): Remove redundant local variables. buf_flush_LRU_list_batch(): Let the caller buf_do_LRU_batch() initialize the counters, and report n->evicted. Cache the last looked up tablespace. If neighbor flushing is not applicable, invoke buf_flush_page() directly, avoiding a page lookup in between. buf_do_LRU_batch(): Return the number of pages flushed. buf_LRU_free_page(): Only release and re-acquire buf_pool.mutex if adaptive hash index entries are pointing to the block. buf_LRU_get_free_block(): Do not wake up the page cleaner, because it will no longer perform any useful work for us, and we do not want it to compete for I/O while buf_flush_lists(innodb_lru_flush_size, 0) writes out and evicts at most innodb_lru_flush_size pages. (The function buf_do_LRU_batch() may complete after writing fewer pages if more than innodb_lru_scan_depth pages end up in buf_pool.free list.) Eliminate some mutex release-acquire cycles, and wait for the LRU flush batch to complete before rescanning. buf_LRU_check_size_of_non_data_objects(): Simplify the code. buf_page_write_complete(): Remove the parameter evict, and always evict pages that were part of an LRU flush. buf_page_create(): Take a pre-allocated page as a parameter. buf_pool_t::free_block(): Free a pre-allocated block. recv_sys_t::recover_low(), recv_sys_t::apply(): Preallocate the block while not holding recv_sys.mutex. During page allocation, we may initiate a page flush, which in turn may initiate a log flush, which would require acquiring log_sys.mutex, which should always be acquired before recv_sys.mutex in order to avoid deadlocks. Therefore, we must not be holding recv_sys.mutex while allocating a buffer pool block. BtrBulk::logFreeCheck(): Skip a redundant condition. row_undo_step(): Do not invoke srv_inc_activity_count() for every row that is being rolled back. It should suffice to invoke the function in trx_flush_log_if_needed() during trx_t::commit_in_memory() when the rollback completes. sync_check_enable(): Remove. We will enable innodb_sync_debug from the very beginning. Reviewed by: Vladislav Vaintroub
2020-10-15 12:10:42 +03:00
#define mysql_mutex_is_owner(M) safe_mutex_is_owner(&(M)->m_mutex)
/**
@def mysql_mutex_assert_owner(M)
Wrapper, to use safe_mutex_assert_owner with instrumented mutexes.
@c mysql_mutex_assert_owner is a drop-in replacement
for @c safe_mutex_assert_owner.
*/
#define mysql_mutex_assert_owner(M) \
safe_mutex_assert_owner(&(M)->m_mutex)
/**
@def mysql_mutex_assert_not_owner(M)
Wrapper, to use safe_mutex_assert_not_owner with instrumented mutexes.
@c mysql_mutex_assert_not_owner is a drop-in replacement
for @c safe_mutex_assert_not_owner.
*/
#define mysql_mutex_assert_not_owner(M) \
safe_mutex_assert_not_owner(&(M)->m_mutex)
#define mysql_mutex_setflags(M, F) \
safe_mutex_setflags(&(M)->m_mutex, (F))
2019-12-10 15:35:00 +01:00
/**
@def mysql_prlock_assert_write_owner(M)
Drop-in replacement
for @c rw_pr_lock_assert_write_owner.
*/
#define mysql_prlock_assert_write_owner(M) \
rw_pr_lock_assert_write_owner(&(M)->m_prlock)
2019-12-10 15:35:00 +01:00
/**
@def mysql_prlock_assert_not_write_owner(M)
Drop-in replacement
for @c rw_pr_lock_assert_not_write_owner.
*/
#define mysql_prlock_assert_not_write_owner(M) \
rw_pr_lock_assert_not_write_owner(&(M)->m_prlock)
/**
@def mysql_mutex_register(P1, P2, P3)
Mutex registration.
*/
#define mysql_mutex_register(P1, P2, P3) \
inline_mysql_mutex_register(P1, P2, P3)
/**
@def mysql_mutex_init(K, M, A)
Instrumented mutex_init.
@c mysql_mutex_init is a replacement for @c pthread_mutex_init.
@param K The PSI_mutex_key for this instrumented mutex
@param M The mutex to initialize
@param A Mutex attributes
*/
#ifdef HAVE_PSI_MUTEX_INTERFACE
#ifdef SAFE_MUTEX
#define mysql_mutex_init(K, M, A) \
2011-04-25 17:22:25 +02:00
inline_mysql_mutex_init(K, M, A, #M, __FILE__, __LINE__)
#else
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(K, M, A)
#endif
#else
#ifdef SAFE_MUTEX
#define mysql_mutex_init(K, M, A) \
2011-04-25 17:22:25 +02:00
inline_mysql_mutex_init(M, A, #M, __FILE__, __LINE__)
#else
#define mysql_mutex_init(K, M, A) \
inline_mysql_mutex_init(M, A)
#endif
#endif
/**
@def mysql_mutex_destroy(M)
Instrumented mutex_destroy.
@c mysql_mutex_destroy is a drop-in replacement
for @c pthread_mutex_destroy.
*/
#ifdef SAFE_MUTEX
#define mysql_mutex_destroy(M) \
inline_mysql_mutex_destroy(M, __FILE__, __LINE__)
#else
#define mysql_mutex_destroy(M) \
inline_mysql_mutex_destroy(M)
#endif
/**
@def mysql_mutex_lock(M)
Instrumented mutex_lock.
@c mysql_mutex_lock is a drop-in replacement for @c pthread_mutex_lock.
@param M The mutex to lock
*/
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
#define mysql_mutex_lock(M) \
inline_mysql_mutex_lock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_lock(M) \
inline_mysql_mutex_lock(M)
#endif
/**
@def mysql_mutex_trylock(M)
Instrumented mutex_lock.
@c mysql_mutex_trylock is a drop-in replacement
for @c pthread_mutex_trylock.
*/
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
#define mysql_mutex_trylock(M) \
inline_mysql_mutex_trylock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_trylock(M) \
inline_mysql_mutex_trylock(M)
#endif
/**
@def mysql_mutex_unlock(M)
Instrumented mutex_unlock.
@c mysql_mutex_unlock is a drop-in replacement for @c pthread_mutex_unlock.
*/
#ifdef SAFE_MUTEX
#define mysql_mutex_unlock(M) \
inline_mysql_mutex_unlock(M, __FILE__, __LINE__)
#else
#define mysql_mutex_unlock(M) \
inline_mysql_mutex_unlock(M)
#endif
/**
@def mysql_rwlock_register(P1, P2, P3)
Rwlock registration.
*/
#define mysql_rwlock_register(P1, P2, P3) \
inline_mysql_rwlock_register(P1, P2, P3)
/**
@def mysql_rwlock_init(K, RW)
Instrumented rwlock_init.
@c mysql_rwlock_init is a replacement for @c pthread_rwlock_init.
Note that pthread_rwlockattr_t is not supported in MySQL.
@param K The PSI_rwlock_key for this instrumented rwlock
@param RW The rwlock to initialize
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(K, RW)
#else
#define mysql_rwlock_init(K, RW) inline_mysql_rwlock_init(RW)
#endif
/**
@def mysql_prlock_init(K, RW)
Instrumented rw_pr_init.
@c mysql_prlock_init is a replacement for @c rw_pr_init.
@param K The PSI_rwlock_key for this instrumented prlock
@param RW The prlock to initialize
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_prlock_init(K, RW) inline_mysql_prlock_init(K, RW)
#else
#define mysql_prlock_init(K, RW) inline_mysql_prlock_init(RW)
#endif
/**
@def mysql_rwlock_destroy(RW)
Instrumented rwlock_destroy.
@c mysql_rwlock_destroy is a drop-in replacement
for @c pthread_rwlock_destroy.
*/
#define mysql_rwlock_destroy(RW) inline_mysql_rwlock_destroy(RW)
/**
@def mysql_prlock_destroy(RW)
Instrumented rw_pr_destroy.
@c mysql_prlock_destroy is a drop-in replacement
for @c rw_pr_destroy.
*/
#define mysql_prlock_destroy(RW) inline_mysql_prlock_destroy(RW)
/**
@def mysql_rwlock_rdlock(RW)
Instrumented rwlock_rdlock.
@c mysql_rwlock_rdlock is a drop-in replacement
for @c pthread_rwlock_rdlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_rwlock_rdlock(RW) \
inline_mysql_rwlock_rdlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_rdlock(RW) \
inline_mysql_rwlock_rdlock(RW)
#endif
/**
@def mysql_prlock_rdlock(RW)
Instrumented rw_pr_rdlock.
@c mysql_prlock_rdlock is a drop-in replacement
for @c rw_pr_rdlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_prlock_rdlock(RW) \
inline_mysql_prlock_rdlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_rdlock(RW) \
inline_mysql_prlock_rdlock(RW)
#endif
/**
@def mysql_rwlock_wrlock(RW)
Instrumented rwlock_wrlock.
@c mysql_rwlock_wrlock is a drop-in replacement
for @c pthread_rwlock_wrlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_rwlock_wrlock(RW) \
inline_mysql_rwlock_wrlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_wrlock(RW) \
inline_mysql_rwlock_wrlock(RW)
#endif
/**
@def mysql_prlock_wrlock(RW)
Instrumented rw_pr_wrlock.
@c mysql_prlock_wrlock is a drop-in replacement
for @c rw_pr_wrlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_prlock_wrlock(RW) \
inline_mysql_prlock_wrlock(RW, __FILE__, __LINE__)
#else
#define mysql_prlock_wrlock(RW) \
inline_mysql_prlock_wrlock(RW)
#endif
/**
@def mysql_rwlock_tryrdlock(RW)
Instrumented rwlock_tryrdlock.
@c mysql_rwlock_tryrdlock is a drop-in replacement
for @c pthread_rwlock_tryrdlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_rwlock_tryrdlock(RW) \
inline_mysql_rwlock_tryrdlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_tryrdlock(RW) \
inline_mysql_rwlock_tryrdlock(RW)
#endif
/**
@def mysql_rwlock_trywrlock(RW)
Instrumented rwlock_trywrlock.
@c mysql_rwlock_trywrlock is a drop-in replacement
for @c pthread_rwlock_trywrlock.
*/
#ifdef HAVE_PSI_RWLOCK_INTERFACE
#define mysql_rwlock_trywrlock(RW) \
inline_mysql_rwlock_trywrlock(RW, __FILE__, __LINE__)
#else
#define mysql_rwlock_trywrlock(RW) \
inline_mysql_rwlock_trywrlock(RW)
#endif
/**
@def mysql_rwlock_unlock(RW)
Instrumented rwlock_unlock.
@c mysql_rwlock_unlock is a drop-in replacement
for @c pthread_rwlock_unlock.
*/
#define mysql_rwlock_unlock(RW) inline_mysql_rwlock_unlock(RW)
/**
@def mysql_prlock_unlock(RW)
Instrumented rw_pr_unlock.
@c mysql_prlock_unlock is a drop-in replacement
for @c rw_pr_unlock.
*/
#define mysql_prlock_unlock(RW) inline_mysql_prlock_unlock(RW)
/**
@def mysql_cond_register(P1, P2, P3)
Cond registration.
*/
#define mysql_cond_register(P1, P2, P3) \
inline_mysql_cond_register(P1, P2, P3)
/**
@def mysql_cond_init(K, C, A)
Instrumented cond_init.
@c mysql_cond_init is a replacement for @c pthread_cond_init.
@param C The cond to initialize
@param K The PSI_cond_key for this instrumented cond
@param A Condition attributes
*/
#ifdef HAVE_PSI_COND_INTERFACE
#define mysql_cond_init(K, C, A) inline_mysql_cond_init(K, C, A)
#else
#define mysql_cond_init(K, C, A) inline_mysql_cond_init(C, A)
#endif
/**
@def mysql_cond_destroy(C)
Instrumented cond_destroy.
@c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy.
*/
#define mysql_cond_destroy(C) inline_mysql_cond_destroy(C)
/**
@def mysql_cond_wait(C)
Instrumented cond_wait.
@c mysql_cond_wait is a drop-in replacement for @c pthread_cond_wait.
*/
2019-12-10 15:35:00 +01:00
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_COND_INTERFACE)
#define mysql_cond_wait(C, M) \
inline_mysql_cond_wait(C, M, __FILE__, __LINE__)
#else
#define mysql_cond_wait(C, M) \
inline_mysql_cond_wait(C, M)
#endif
/**
@def mysql_cond_timedwait(C, M, W)
Instrumented cond_timedwait.
@c mysql_cond_timedwait is a drop-in replacement
for @c pthread_cond_timedwait.
*/
2019-12-10 15:35:00 +01:00
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_COND_INTERFACE)
#define mysql_cond_timedwait(C, M, W) \
inline_mysql_cond_timedwait(C, M, W, __FILE__, __LINE__)
#else
#define mysql_cond_timedwait(C, M, W) \
inline_mysql_cond_timedwait(C, M, W)
#endif
/**
@def mysql_cond_signal(C)
Instrumented cond_signal.
@c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal.
*/
#define mysql_cond_signal(C) inline_mysql_cond_signal(C)
/**
@def mysql_cond_broadcast(C)
Instrumented cond_broadcast.
@c mysql_cond_broadcast is a drop-in replacement
for @c pthread_cond_broadcast.
*/
#define mysql_cond_broadcast(C) inline_mysql_cond_broadcast(C)
/**
@def mysql_thread_register(P1, P2, P3)
Thread registration.
*/
#define mysql_thread_register(P1, P2, P3) \
inline_mysql_thread_register(P1, P2, P3)
/**
@def mysql_thread_create(K, P1, P2, P3, P4)
Instrumented pthread_create.
This function creates both the thread instrumentation and a thread.
@c mysql_thread_create is a replacement for @c pthread_create.
The parameter P4 (or, if it is NULL, P1) will be used as the
2022-12-19 15:08:20 -06:00
instrumented thread "identity".
Providing a P1 / P4 parameter with a different value for each call
will on average improve performances, since this thread identity value
is used internally to randomize access to data and prevent contention.
This is optional, and the improvement is not guaranteed, only statistical.
@param K The PSI_thread_key for this instrumented thread
@param P1 pthread_create parameter 1
@param P2 pthread_create parameter 2
@param P3 pthread_create parameter 3
@param P4 pthread_create parameter 4
*/
#ifdef HAVE_PSI_THREAD_INTERFACE
#define mysql_thread_create(K, P1, P2, P3, P4) \
inline_mysql_thread_create(K, P1, P2, P3, P4)
#else
#define mysql_thread_create(K, P1, P2, P3, P4) \
pthread_create(P1, P2, P3, P4)
#endif
/**
@def mysql_thread_set_psi_id(I)
Set the thread identifier for the instrumentation.
@param I The thread identifier
*/
#ifdef HAVE_PSI_THREAD_INTERFACE
#define mysql_thread_set_psi_id(I) inline_mysql_thread_set_psi_id(I)
#else
#define mysql_thread_set_psi_id(I) do {} while (0)
#endif
2019-12-10 15:35:00 +01:00
/**
@def mysql_thread_set_psi_THD(T)
Set the thread sql session for the instrumentation.
@param I The thread identifier
*/
#ifdef HAVE_PSI_THREAD_INTERFACE
#define mysql_thread_set_psi_THD(T) inline_mysql_thread_set_psi_THD(T)
#else
#define mysql_thread_set_psi_THD(T) do {} while (0)
#endif
static inline void inline_mysql_mutex_register(
#ifdef HAVE_PSI_MUTEX_INTERFACE
const char *category,
PSI_mutex_info *info,
int count
#else
const char *category __attribute__ ((unused)),
void *info __attribute__ ((unused)),
int count __attribute__ ((unused))
#endif
)
{
#ifdef HAVE_PSI_MUTEX_INTERFACE
2013-03-26 00:03:13 +02:00
PSI_MUTEX_CALL(register_mutex)(category, info, count);
#endif
}
static inline int inline_mysql_mutex_init(
#ifdef HAVE_PSI_MUTEX_INTERFACE
PSI_mutex_key key,
#endif
mysql_mutex_t *that,
const pthread_mutexattr_t *attr
#ifdef SAFE_MUTEX
2011-04-25 17:22:25 +02:00
, const char *src_name, const char *src_file, uint src_line
#endif
)
{
#ifdef HAVE_PSI_MUTEX_INTERFACE
2013-03-26 00:03:13 +02:00
that->m_psi= PSI_MUTEX_CALL(init_mutex)(key, &that->m_mutex);
#else
that->m_psi= NULL;
#endif
#ifdef SAFE_MUTEX
2011-04-25 17:22:25 +02:00
return safe_mutex_init(&that->m_mutex, attr, src_name, src_file, src_line);
#else
return pthread_mutex_init(&that->m_mutex, attr);
#endif
}
static inline int inline_mysql_mutex_destroy(
mysql_mutex_t *that
#ifdef SAFE_MUTEX
, const char *src_file, uint src_line
#endif
)
{
#ifdef HAVE_PSI_MUTEX_INTERFACE
if (that->m_psi != NULL)
{
2013-03-26 00:03:13 +02:00
PSI_MUTEX_CALL(destroy_mutex)(that->m_psi);
that->m_psi= NULL;
}
#endif
#ifdef SAFE_MUTEX
return safe_mutex_destroy(&that->m_mutex, src_file, src_line);
#else
return pthread_mutex_destroy(&that->m_mutex);
#endif
}
static inline int inline_mysql_mutex_lock(
mysql_mutex_t *that
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_MUTEX_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_mutex_locker *locker;
PSI_mutex_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
PSI_MUTEX_LOCK, src_file, src_line);
/* Instrumented code */
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
#else
result= pthread_mutex_lock(&that->m_mutex);
#endif
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, FALSE, src_file, src_line);
#else
result= pthread_mutex_lock(&that->m_mutex);
#endif
return result;
}
static inline int inline_mysql_mutex_trylock(
mysql_mutex_t *that
#if defined(SAFE_MUTEX) || defined (HAVE_PSI_MUTEX_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_MUTEX_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_mutex_locker *locker;
PSI_mutex_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_MUTEX_CALL(start_mutex_wait)(&state, that->m_psi,
PSI_MUTEX_TRYLOCK, src_file, src_line);
/* Instrumented code */
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
#else
result= pthread_mutex_trylock(&that->m_mutex);
#endif
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_MUTEX_CALL(end_mutex_wait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
#ifdef SAFE_MUTEX
result= safe_mutex_lock(&that->m_mutex, TRUE, src_file, src_line);
#else
result= pthread_mutex_trylock(&that->m_mutex);
#endif
return result;
}
static inline int inline_mysql_mutex_unlock(
mysql_mutex_t *that
#ifdef SAFE_MUTEX
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_MUTEX_INTERFACE
if (psi_likely(that->m_psi != NULL))
2013-03-26 00:03:13 +02:00
PSI_MUTEX_CALL(unlock_mutex)(that->m_psi);
#endif
#ifdef SAFE_MUTEX
result= safe_mutex_unlock(&that->m_mutex, src_file, src_line);
#else
result= pthread_mutex_unlock(&that->m_mutex);
#endif
return result;
}
static inline void inline_mysql_rwlock_register(
#ifdef HAVE_PSI_RWLOCK_INTERFACE
const char *category,
PSI_rwlock_info *info,
int count
#else
const char *category __attribute__ ((unused)),
void *info __attribute__ ((unused)),
int count __attribute__ ((unused))
#endif
)
{
#ifdef HAVE_PSI_RWLOCK_INTERFACE
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(register_rwlock)(category, info, count);
#endif
}
static inline int inline_mysql_rwlock_init(
#ifdef HAVE_PSI_RWLOCK_INTERFACE
PSI_rwlock_key key,
#endif
mysql_rwlock_t *that)
{
#ifdef HAVE_PSI_RWLOCK_INTERFACE
2013-03-26 00:03:13 +02:00
that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_rwlock);
#else
that->m_psi= NULL;
#endif
/*
pthread_rwlockattr_t is not used in MySQL.
*/
return my_rwlock_init(&that->m_rwlock, NULL);
}
#ifndef DISABLE_MYSQL_PRLOCK_H
static inline int inline_mysql_prlock_init(
#ifdef HAVE_PSI_RWLOCK_INTERFACE
PSI_rwlock_key key,
#endif
mysql_prlock_t *that)
{
#ifdef HAVE_PSI_RWLOCK_INTERFACE
2013-03-26 00:03:13 +02:00
that->m_psi= PSI_RWLOCK_CALL(init_rwlock)(key, &that->m_prlock);
#else
that->m_psi= NULL;
#endif
return rw_pr_init(&that->m_prlock);
}
#endif
static inline int inline_mysql_rwlock_destroy(
mysql_rwlock_t *that)
{
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
that->m_psi= NULL;
}
#endif
return rwlock_destroy(&that->m_rwlock);
}
#ifndef DISABLE_MYSQL_PRLOCK_H
static inline int inline_mysql_prlock_destroy(
mysql_prlock_t *that)
{
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(destroy_rwlock)(that->m_psi);
that->m_psi= NULL;
}
#endif
return rw_pr_destroy(&that->m_prlock);
}
#endif
static inline int inline_mysql_rwlock_rdlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
PSI_RWLOCK_READLOCK, src_file, src_line);
/* Instrumented code */
result= rw_rdlock(&that->m_rwlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_rdlock(&that->m_rwlock);
return result;
}
#ifndef DISABLE_MYSQL_PRLOCK_H
static inline int inline_mysql_prlock_rdlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
PSI_RWLOCK_READLOCK, src_file, src_line);
/* Instrumented code */
result= rw_pr_rdlock(&that->m_prlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_pr_rdlock(&that->m_prlock);
return result;
}
#endif
static inline int inline_mysql_rwlock_wrlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
PSI_RWLOCK_WRITELOCK, src_file, src_line);
/* Instrumented code */
result= rw_wrlock(&that->m_rwlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_wrlock(&that->m_rwlock);
return result;
}
#ifndef DISABLE_MYSQL_PRLOCK_H
static inline int inline_mysql_prlock_wrlock(
mysql_prlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
PSI_RWLOCK_WRITELOCK, src_file, src_line);
/* Instrumented code */
result= rw_pr_wrlock(&that->m_prlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_pr_wrlock(&that->m_prlock);
return result;
}
#endif
static inline int inline_mysql_rwlock_tryrdlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_rdwait)(&state, that->m_psi,
PSI_RWLOCK_TRYREADLOCK, src_file, src_line);
/* Instrumented code */
result= rw_tryrdlock(&that->m_rwlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_rdwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_tryrdlock(&that->m_rwlock);
return result;
}
static inline int inline_mysql_rwlock_trywrlock(
mysql_rwlock_t *that
#ifdef HAVE_PSI_RWLOCK_INTERFACE
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_rwlock_locker *locker;
PSI_rwlock_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_RWLOCK_CALL(start_rwlock_wrwait)(&state, that->m_psi,
PSI_RWLOCK_TRYWRITELOCK, src_file, src_line);
/* Instrumented code */
result= rw_trywrlock(&that->m_rwlock);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(end_rwlock_wrwait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= rw_trywrlock(&that->m_rwlock);
return result;
}
static inline int inline_mysql_rwlock_unlock(
mysql_rwlock_t *that)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
#endif
result= rw_unlock(&that->m_rwlock);
return result;
}
#ifndef DISABLE_MYSQL_PRLOCK_H
static inline int inline_mysql_prlock_unlock(
mysql_prlock_t *that)
{
int result;
#ifdef HAVE_PSI_RWLOCK_INTERFACE
if (psi_likely(that->m_psi != NULL))
2013-03-26 00:03:13 +02:00
PSI_RWLOCK_CALL(unlock_rwlock)(that->m_psi);
#endif
result= rw_pr_unlock(&that->m_prlock);
return result;
}
#endif
static inline void inline_mysql_cond_register(
#ifdef HAVE_PSI_COND_INTERFACE
const char *category,
PSI_cond_info *info,
int count
#else
const char *category __attribute__ ((unused)),
void *info __attribute__ ((unused)),
int count __attribute__ ((unused))
#endif
)
{
#ifdef HAVE_PSI_COND_INTERFACE
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(register_cond)(category, info, count);
#endif
}
static inline int inline_mysql_cond_init(
#ifdef HAVE_PSI_COND_INTERFACE
PSI_cond_key key,
#endif
mysql_cond_t *that,
const pthread_condattr_t *attr)
{
#ifdef HAVE_PSI_COND_INTERFACE
2013-03-26 00:03:13 +02:00
that->m_psi= PSI_COND_CALL(init_cond)(key, &that->m_cond);
#else
that->m_psi= NULL;
#endif
return pthread_cond_init(&that->m_cond, attr);
}
static inline int inline_mysql_cond_destroy(
mysql_cond_t *that)
{
#ifdef HAVE_PSI_COND_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(destroy_cond)(that->m_psi);
that->m_psi= NULL;
}
#endif
return pthread_cond_destroy(&that->m_cond);
}
static inline int inline_mysql_cond_wait(
mysql_cond_t *that,
mysql_mutex_t *mutex
2019-12-10 15:35:00 +01:00
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_COND_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_COND_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_cond_locker *locker;
PSI_cond_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
PSI_COND_WAIT, src_file, src_line);
/* Instrumented code */
result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
/* Instrumentation end */
if (locker != NULL)
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(end_cond_wait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= my_cond_wait(&that->m_cond, &mutex->m_mutex);
return result;
}
static inline int inline_mysql_cond_timedwait(
mysql_cond_t *that,
mysql_mutex_t *mutex,
const struct timespec *abstime
2019-12-10 15:35:00 +01:00
#if defined(SAFE_MUTEX) || defined(HAVE_PSI_COND_INTERFACE)
, const char *src_file, uint src_line
#endif
)
{
int result;
#ifdef HAVE_PSI_COND_INTERFACE
if (psi_likely(that->m_psi != NULL))
{
/* Instrumentation start */
PSI_cond_locker *locker;
PSI_cond_locker_state state;
2013-03-26 00:03:13 +02:00
locker= PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
PSI_COND_TIMEDWAIT, src_file, src_line);
/* Instrumented code */
result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
/* Instrumentation end */
if (psi_likely(locker != NULL))
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(end_cond_wait)(locker, result);
return result;
}
#endif
/* Non instrumented code */
result= my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime);
return result;
}
static inline int inline_mysql_cond_signal(
mysql_cond_t *that)
{
int result;
#ifdef HAVE_PSI_COND_INTERFACE
if (psi_likely(that->m_psi != NULL))
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(signal_cond)(that->m_psi);
#endif
result= pthread_cond_signal(&that->m_cond);
return result;
}
static inline int inline_mysql_cond_broadcast(
mysql_cond_t *that)
{
int result;
#ifdef HAVE_PSI_COND_INTERFACE
if (psi_likely(that->m_psi != NULL))
2013-03-26 00:03:13 +02:00
PSI_COND_CALL(broadcast_cond)(that->m_psi);
#endif
result= pthread_cond_broadcast(&that->m_cond);
return result;
}
static inline void inline_mysql_thread_register(
#ifdef HAVE_PSI_THREAD_INTERFACE
const char *category,
PSI_thread_info *info,
int count
#else
const char *category __attribute__ ((unused)),
void *info __attribute__ ((unused)),
int count __attribute__ ((unused))
#endif
)
{
#ifdef HAVE_PSI_THREAD_INTERFACE
2013-03-26 00:03:13 +02:00
PSI_THREAD_CALL(register_thread)(category, info, count);
#endif
}
#ifdef HAVE_PSI_THREAD_INTERFACE
static inline int inline_mysql_thread_create(
PSI_thread_key key,
pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg)
{
int result;
2013-03-26 00:03:13 +02:00
result= PSI_THREAD_CALL(spawn_thread)(key, thread, attr, start_routine, arg);
return result;
}
2016-02-10 00:20:23 +01:00
static inline void inline_mysql_thread_set_psi_id(my_thread_id id)
{
2013-03-26 00:03:13 +02:00
struct PSI_thread *psi= PSI_THREAD_CALL(get_thread)();
PSI_THREAD_CALL(set_thread_id)(psi, id);
}
2019-12-10 15:35:00 +01:00
#ifdef __cplusplus
class THD;
static inline void inline_mysql_thread_set_psi_THD(THD *thd)
{
struct PSI_thread *psi= PSI_THREAD_CALL(get_thread)();
PSI_THREAD_CALL(set_thread_THD)(psi, thd);
}
#endif /* __cplusplus */
static inline void mysql_thread_set_peer_port(uint port __attribute__ ((unused))) {
2022-07-29 14:48:01 +02:00
#ifdef HAVE_PSI_THREAD_INTERFACE
struct PSI_thread *psi = PSI_THREAD_CALL(get_thread)();
PSI_THREAD_CALL(set_thread_peer_port)(psi, port);
#endif
}
#endif
#endif /* DISABLE_MYSQL_THREAD_H */
/** @} (end of group Thread_instrumentation) */
#endif