mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
MDEV-12534 Use atomic operations whenever available
Define UNIV_WORD_SIZE as a simple alias to SIZEOF_SIZE_T. In MariaDB 10.0 and 10.1, it was incorrectly defined as 4 on 64-bit Windows. MONITOR_OS_PENDING_READS, MONITOR_OS_PENDING_WRITES: Enable by default. os_n_pending_reads, os_n_pending_writes: Remove. Use the monitor counters instead.
This commit is contained in:
parent
8bbeac0171
commit
039a299b92
7 changed files with 53 additions and 58 deletions
|
@ -52,11 +52,6 @@ struct fil_space_t;
|
|||
extern bool os_has_said_disk_full;
|
||||
extern my_bool srv_use_trim;
|
||||
|
||||
/** Number of pending read operations */
|
||||
extern ulint os_n_pending_reads;
|
||||
/** Number of pending write operations */
|
||||
extern ulint os_n_pending_writes;
|
||||
|
||||
/** File offset in bytes */
|
||||
typedef ib_uint64_t os_offset_t;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Copyright (c) 2010, 2015, Oracle and/or its affiliates. All Rights Reserved.
|
||||
Copyright (c) 2012, Facebook Inc.
|
||||
Copyright (c) 2013, 2016, MariaDB Corporation.
|
||||
Copyright (c) 2013, 2017, 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
|
||||
|
@ -603,9 +603,10 @@ on the counters */
|
|||
|
||||
/** Atomically increment a monitor counter.
|
||||
Use MONITOR_INC if appropriate mutex protection exists.
|
||||
@param monitor monitor to be incremented by 1 */
|
||||
# define MONITOR_ATOMIC_INC(monitor) \
|
||||
if (MONITOR_IS_ON(monitor)) { \
|
||||
@param monitor monitor to be incremented by 1
|
||||
@param enabled whether the monitor is enabled */
|
||||
#define MONITOR_ATOMIC_INC_LOW(monitor, enabled) \
|
||||
if (enabled) { \
|
||||
ib_uint64_t value; \
|
||||
value = my_atomic_add64( \
|
||||
(int64*) &MONITOR_VALUE(monitor), 1) + 1; \
|
||||
|
@ -618,9 +619,10 @@ Use MONITOR_INC if appropriate mutex protection exists.
|
|||
|
||||
/** Atomically decrement a monitor counter.
|
||||
Use MONITOR_DEC if appropriate mutex protection exists.
|
||||
@param monitor monitor to be decremented by 1 */
|
||||
# define MONITOR_ATOMIC_DEC(monitor) \
|
||||
if (MONITOR_IS_ON(monitor)) { \
|
||||
@param monitor monitor to be decremented by 1
|
||||
@param enabled whether the monitor is enabled */
|
||||
#define MONITOR_ATOMIC_DEC_LOW(monitor, enabled) \
|
||||
if (enabled) { \
|
||||
ib_uint64_t value; \
|
||||
value = my_atomic_add64( \
|
||||
(int64*) &MONITOR_VALUE(monitor), -1) - 1; \
|
||||
|
@ -631,6 +633,17 @@ Use MONITOR_DEC if appropriate mutex protection exists.
|
|||
} \
|
||||
}
|
||||
|
||||
/** Atomically increment a monitor counter if it is enabled.
|
||||
Use MONITOR_INC if appropriate mutex protection exists.
|
||||
@param monitor monitor to be incremented by 1 */
|
||||
#define MONITOR_ATOMIC_INC(monitor) \
|
||||
MONITOR_ATOMIC_INC_LOW(monitor, MONITOR_IS_ON(monitor))
|
||||
/** Atomically decrement a monitor counter if it is enabled.
|
||||
Use MONITOR_DEC if appropriate mutex protection exists.
|
||||
@param monitor monitor to be decremented by 1 */
|
||||
#define MONITOR_ATOMIC_DEC(monitor) \
|
||||
MONITOR_ATOMIC_DEC_LOW(monitor, MONITOR_IS_ON(monitor))
|
||||
|
||||
#define MONITOR_DEC(monitor) \
|
||||
if (MONITOR_IS_ON(monitor)) { \
|
||||
MONITOR_VALUE(monitor)--; \
|
||||
|
|
|
@ -282,16 +282,7 @@ rarely invoked function for size instead for speed. */
|
|||
|
||||
#define UNIV_INLINE static inline
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _WIN64
|
||||
# define UNIV_WORD_SIZE 8
|
||||
# else
|
||||
# define UNIV_WORD_SIZE 4
|
||||
# endif
|
||||
#else /* !_WIN32 */
|
||||
/** MySQL config.h generated by CMake will define SIZEOF_LONG in Posix */
|
||||
#define UNIV_WORD_SIZE SIZEOF_LONG
|
||||
#endif /* _WIN32 */
|
||||
#define UNIV_WORD_SIZE SIZEOF_SIZE_T
|
||||
|
||||
/** The following alignment is used in memory allocations in memory heap
|
||||
management to ensure correct alignment for doubles etc. */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
||||
Copyright (c) 2009, Percona Inc.
|
||||
Copyright (c) 2012, 2017, MariaDB Corporation.
|
||||
Copyright (c) 2013, 2017, MariaDB Corporation.
|
||||
|
||||
Portions of this file contain modifications contributed and copyrighted
|
||||
by Percona Inc.. Those modifications are
|
||||
|
@ -687,10 +687,6 @@ ulint os_n_fsyncs;
|
|||
static ulint os_n_file_reads_old;
|
||||
static ulint os_n_file_writes_old;
|
||||
static ulint os_n_fsyncs_old;
|
||||
/** Number of pending write operations */
|
||||
ulint os_n_pending_writes;
|
||||
/** Number of pending read operations */
|
||||
ulint os_n_pending_reads;
|
||||
|
||||
static time_t os_last_printout;
|
||||
bool os_has_said_disk_full;
|
||||
|
@ -4945,14 +4941,11 @@ os_file_pwrite(
|
|||
|
||||
++os_n_file_writes;
|
||||
|
||||
(void) my_atomic_addlint(&os_n_pending_writes, 1);
|
||||
MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_WRITES);
|
||||
|
||||
const bool monitor = MONITOR_IS_ON(MONITOR_OS_PENDING_WRITES);
|
||||
MONITOR_ATOMIC_INC_LOW(MONITOR_OS_PENDING_WRITES, monitor);
|
||||
ssize_t n_bytes = os_file_io(type, file, const_cast<byte*>(buf),
|
||||
n, offset, err);
|
||||
|
||||
(void) my_atomic_addlint(&os_n_pending_writes, -1);
|
||||
MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_WRITES);
|
||||
MONITOR_ATOMIC_DEC_LOW(MONITOR_OS_PENDING_WRITES, monitor);
|
||||
|
||||
return(n_bytes);
|
||||
}
|
||||
|
@ -5032,13 +5025,10 @@ os_file_pread(
|
|||
{
|
||||
++os_n_file_reads;
|
||||
|
||||
(void) my_atomic_addlint(&os_n_pending_reads, 1);
|
||||
MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_READS);
|
||||
|
||||
const bool monitor = MONITOR_IS_ON(MONITOR_OS_PENDING_READS);
|
||||
MONITOR_ATOMIC_INC_LOW(MONITOR_OS_PENDING_READS, monitor);
|
||||
ssize_t n_bytes = os_file_io(type, file, buf, n, offset, err);
|
||||
|
||||
(void) my_atomic_addlint(&os_n_pending_reads, -1);
|
||||
MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_READS);
|
||||
MONITOR_ATOMIC_DEC_LOW(MONITOR_OS_PENDING_READS, monitor);
|
||||
|
||||
return(n_bytes);
|
||||
}
|
||||
|
@ -7467,19 +7457,24 @@ os_aio_print(FILE* file)
|
|||
time_elapsed = 0.001 + difftime(current_time, os_last_printout);
|
||||
|
||||
fprintf(file,
|
||||
"Pending flushes (fsync) log: %lu; buffer pool: %lu\n"
|
||||
"%lu OS file reads, %lu OS file writes, %lu OS fsyncs\n",
|
||||
(ulint) fil_n_pending_log_flushes,
|
||||
(ulint) fil_n_pending_tablespace_flushes,
|
||||
(ulint) os_n_file_reads,
|
||||
(ulint) os_n_file_writes,
|
||||
(ulint) os_n_fsyncs);
|
||||
"Pending flushes (fsync) log: " ULINTPF
|
||||
"; buffer pool: " ULINTPF "\n"
|
||||
ULINTPF " OS file reads, "
|
||||
ULINTPF " OS file writes, "
|
||||
ULINTPF " OS fsyncs\n",
|
||||
fil_n_pending_log_flushes,
|
||||
fil_n_pending_tablespace_flushes,
|
||||
os_n_file_reads,
|
||||
os_n_file_writes,
|
||||
os_n_fsyncs);
|
||||
|
||||
if (os_n_pending_writes != 0 || os_n_pending_reads != 0) {
|
||||
const ulint n_reads = ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
|
||||
const ulint n_writes = ulint(MONITOR_VALUE(MONITOR_OS_PENDING_WRITES));
|
||||
|
||||
if (n_reads != 0 || n_writes != 0) {
|
||||
fprintf(file,
|
||||
"%lu pending preads, %lu pending pwrites\n",
|
||||
(ulint) os_n_pending_reads,
|
||||
(ulint) os_n_pending_writes);
|
||||
ULINTPF " pending reads, " ULINTPF " pending writes\n",
|
||||
n_reads, n_writes);
|
||||
}
|
||||
|
||||
if (os_n_file_reads == os_n_file_reads_old) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
||||
Copyright (c) 2012, Facebook Inc.
|
||||
Copyright (c) 2013, 2016, MariaDB Corporation
|
||||
Copyright (c) 2013, 2017, 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
|
||||
|
@ -739,11 +739,11 @@ static monitor_info_t innodb_counter_info[] =
|
|||
MONITOR_DEFAULT_START, MONITOR_OVLD_OS_FSYNC},
|
||||
|
||||
{"os_pending_reads", "os", "Number of reads pending",
|
||||
MONITOR_NONE,
|
||||
MONITOR_DEFAULT_ON,
|
||||
MONITOR_DEFAULT_START, MONITOR_OS_PENDING_READS},
|
||||
|
||||
{"os_pending_writes", "os", "Number of writes pending",
|
||||
MONITOR_NONE,
|
||||
MONITOR_DEFAULT_ON,
|
||||
MONITOR_DEFAULT_START, MONITOR_OS_PENDING_WRITES},
|
||||
|
||||
{"os_log_bytes_written", "os",
|
||||
|
|
|
@ -1482,10 +1482,10 @@ srv_export_innodb_status(void)
|
|||
mutex_enter(&srv_innodb_monitor_mutex);
|
||||
|
||||
export_vars.innodb_data_pending_reads =
|
||||
os_n_pending_reads;
|
||||
ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
|
||||
|
||||
export_vars.innodb_data_pending_writes =
|
||||
os_n_pending_writes;
|
||||
ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
|
||||
|
||||
export_vars.innodb_data_pending_fsyncs =
|
||||
fil_n_pending_log_flushes
|
||||
|
|
|
@ -1093,9 +1093,10 @@ sync_array_print_long_waits(
|
|||
now the values of pending calls of these. */
|
||||
|
||||
fprintf(stderr,
|
||||
"InnoDB: Pending preads %lu, pwrites %lu\n",
|
||||
(ulong) os_n_pending_reads,
|
||||
(ulong) os_n_pending_writes);
|
||||
"InnoDB: Pending reads " UINT64PF
|
||||
", writes " UINT64PF "\n",
|
||||
MONITOR_VALUE(MONITOR_OS_PENDING_READS),
|
||||
MONITOR_VALUE(MONITOR_OS_PENDING_WRITES));
|
||||
|
||||
srv_print_innodb_monitor = TRUE;
|
||||
|
||||
|
|
Loading…
Reference in a new issue