Skip to content

Commit

Permalink
MDEV-12534 Use atomic operations whenever available
Browse files Browse the repository at this point in the history
Allow 64-bit atomic operations on 32-bit systems,
only relying on HAVE_ATOMIC_BUILTINS_64, disregarding
the width of the register file.

Define UNIV_WORD_SIZE correctly on all systems, including Windows.
In MariaDB 10.0 and 10.1, it was incorrectly defined as 4 on
64-bit Windows.

Define HAVE_ATOMIC_BUILTINS_64 on Windows
(64-bit atomics are available on both 32-bit and 64-bit Windows
platforms; the operations were unnecessarily disabled even on
64-bit Windows).

MONITOR_OS_PENDING_READS, MONITOR_OS_PENDING_WRITES: Enable by default.

os_file_n_pending_preads, os_file_n_pending_pwrites,
os_n_pending_reads, os_n_pending_writes: Remove.
Use the monitor counters instead.

os_file_count_mutex: Remove. On a system that does not support
64-bit atomics, monitor_mutex will be used instead.
  • Loading branch information
dr-m committed Apr 20, 2017
1 parent 88613e1 commit d34a67b
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 407 deletions.
14 changes: 5 additions & 9 deletions storage/innobase/buf/buf0rea.cc
Expand Up @@ -881,15 +881,11 @@ buf_read_recv_pages(
count++;

if (count > 1000) {
fprintf(stderr,
"InnoDB: Error: InnoDB has waited for"
" 10 seconds for pending\n"
"InnoDB: reads to the buffer pool to"
" be finished.\n"
"InnoDB: Number of pending reads %lu,"
" pending pread calls %lu\n",
(ulong) buf_pool->n_pend_reads,
(ulong) os_file_n_pending_preads);
ib_logf(IB_LOG_LEVEL_ERROR,
"waited for 10 seconds for " ULINTPF
" pending reads to the buffer pool to"
" be finished",
buf_pool->n_pend_reads);

os_aio_print_debug = TRUE;
}
Expand Down
12 changes: 1 addition & 11 deletions storage/innobase/include/os0file.h
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2009, Percona Inc.
Copyright (c) 2017, MariaDB Corporation. All Rights Reserved.
Copyright (c) 2013, 2017, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are
Expand Down Expand Up @@ -51,16 +51,6 @@ extern ibool os_has_said_disk_full;
/** Flag: enable debug printout for asynchronous i/o */
extern ibool os_aio_print_debug;

/** Number of pending os_file_pread() operations */
extern ulint os_file_n_pending_preads;
/** Number of pending os_file_pwrite() operations */
extern ulint os_file_n_pending_pwrites;

/** Number of pending read operations */
extern ulint os_n_pending_reads;
/** Number of pending write operations */
extern ulint os_n_pending_writes;

#ifdef __WIN__

/** We define always WIN_ASYNC_IO, and check at run-time whether
Expand Down
5 changes: 1 addition & 4 deletions storage/innobase/include/os0sync.h
Expand Up @@ -667,10 +667,7 @@ os_atomic_clear(volatile lock_word_t* ptr)

# define HAVE_ATOMIC_BUILTINS
# define HAVE_ATOMIC_BUILTINS_BYTE

# ifndef _WIN32
# define HAVE_ATOMIC_BUILTINS_64
# endif
# define HAVE_ATOMIC_BUILTINS_64

/**********************************************************//**
Atomic compare and exchange of signed integers (both 32 and 64 bit).
Expand Down
62 changes: 47 additions & 15 deletions storage/innobase/include/srv0mon.h
Expand Up @@ -2,6 +2,7 @@
Copyright (c) 2010, 2013, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
Copyright (c) 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
Expand Down Expand Up @@ -541,22 +542,30 @@ on the counters */

/** Increment a monitor counter under mutex protection.
Use MONITOR_INC if appropriate mutex protection already exists.
@param mutex mutex to acquire and release
@param monitor monitor to be incremented by 1
@param mutex mutex to acquire and relese */
# define MONITOR_MUTEX_INC(mutex, monitor) \
@param enabled whether the monitor is enabled */
#define MONITOR_MUTEX_INC_LOW(mutex, monitor, enabled) \
ut_ad(!mutex_own(mutex)); \
if (MONITOR_IS_ON(monitor)) { \
if (enabled) { \
mutex_enter(mutex); \
if (++MONITOR_VALUE(monitor) > MONITOR_MAX_VALUE(monitor)) { \
MONITOR_MAX_VALUE(monitor) = MONITOR_VALUE(monitor); \
} \
mutex_exit(mutex); \
}
/** Increment a monitor counter under mutex protection.
Use MONITOR_INC if appropriate mutex protection already exists.
@param mutex mutex to acquire and release
@param monitor monitor to be incremented by 1 */
#define MONITOR_MUTEX_INC(mutex, monitor) \
MONITOR_MUTEX_INC_LOW(mutex, monitor, MONITOR_IS_ON(monitor))
/** Decrement a monitor counter under mutex protection.
Use MONITOR_DEC if appropriate mutex protection already exists.
@param mutex mutex to acquire and release
@param monitor monitor to be decremented by 1
@param mutex mutex to acquire and relese */
# define MONITOR_MUTEX_DEC(mutex, monitor) \
@param enabled whether the monitor is enabled */
#define MONITOR_MUTEX_DEC_LOW(mutex, monitor, enabled) \
ut_ad(!mutex_own(mutex)); \
if (MONITOR_IS_ON(monitor)) { \
mutex_enter(mutex); \
Expand All @@ -565,13 +574,20 @@ Use MONITOR_DEC if appropriate mutex protection already exists.
} \
mutex_exit(mutex); \
}
/** Decrement a monitor counter under mutex protection.
Use MONITOR_DEC if appropriate mutex protection already exists.
@param mutex mutex to acquire and release
@param monitor monitor to be decremented by 1 */
#define MONITOR_MUTEX_DEC(mutex, monitor) \
MONITOR_MUTEX_DEC_LOW(mutex, monitor, MONITOR_IS_ON(monitor))

#if defined HAVE_ATOMIC_BUILTINS_64
/** 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 = os_atomic_increment_uint64( \
(ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
Expand All @@ -584,9 +600,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 = os_atomic_decrement_uint64( \
(ib_uint64_t*) &MONITOR_VALUE(monitor), 1); \
Expand Down Expand Up @@ -617,14 +634,29 @@ srv_mon_free(void);

/** 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) MONITOR_MUTEX_INC(&monitor_mutex, monitor)
@param monitor monitor to be incremented by 1
@param enabled whether the monitor is enabled */
# define MONITOR_ATOMIC_INC_LOW(monitor, enabled) \
MONITOR_MUTEX_INC_LOW(&monitor_mutex, monitor, enabled)
/** 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) MONITOR_MUTEX_DEC(&monitor_mutex, monitor)
@param monitor monitor to be decremented by 1
@param enabled whether the monitor is enabled */
# define MONITOR_ATOMIC_DEC_LOW(monitor, enabled) \
MONITOR_MUTEX_DEC_LOW(&monitor_mutex, monitor, enabled)
#endif /* HAVE_ATOMIC_BUILTINS_64 */

/** 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)--; \
Expand Down
12 changes: 1 addition & 11 deletions storage/innobase/include/univ.i
Expand Up @@ -285,22 +285,12 @@ definitions: */

#endif /* !UNIV_MUST_NOT_INLINE */

#ifdef _WIN32
#define UNIV_WORD_SIZE 4
#elif defined(_WIN64)
#define UNIV_WORD_SIZE 8
#else
/** MySQL config.h generated by GNU autoconf will define SIZEOF_LONG in Posix */
#define UNIV_WORD_SIZE SIZEOF_LONG
#endif
#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. */
#define UNIV_MEM_ALIGNMENT 8

/** The following alignment is used in aligning lints etc. */
#define UNIV_WORD_ALIGNMENT UNIV_WORD_SIZE

/*
DATABASE VERSION CONTROL
========================
Expand Down

0 comments on commit d34a67b

Please sign in to comment.