Skip to content
Permalink
Browse files

MYSQL-16: Augment mysqld_safe to flush caches and set numa policy.

Add a mysqld_safe option to flush (sync and drop) caches, specially
the page cache, before starting a mysqld server. This is useful for
establishing a consistent and predictable behavior for normal usage
and/or benchmarking.

Also, add an option to set an memory interleave policy. This causes
mysqld memory allocations to be interleaved in round-robing fashion
over the available nodes.
  • Loading branch information...
Davi Arnaut
Davi Arnaut committed Nov 15, 2011
1 parent 03f9d2b commit 19cf63c596c0146a72583998d138190cc285df5c
Showing with 67 additions and 0 deletions.
  1. +67 −0 scripts/mysqld_safe.sh
@@ -17,6 +17,8 @@ MYSQLD=
niceness=0
mysqld_ld_preload=
mysqld_ld_library_path=
flush_caches=0
numa_interleave=0

# Initial logging status: error log is not open, and not using syslog
logging=init
@@ -60,6 +62,9 @@ Usage: $0 [OPTIONS]
--syslog Log messages to syslog with 'logger'
--skip-syslog Log messages to error log (default)
--syslog-tag=TAG Pass -t "mysqld-TAG" to 'logger'
--flush-caches Flush and purge buffers/caches
--numa-interleave Run mysqld with its memory interleaved
on all CPUs
All other options are passed to the mysqld program.
@@ -205,6 +210,8 @@ parse_arguments() {
--skip-syslog) want_syslog=0 ;;
--syslog-tag=*) syslog_tag="$val" ;;
--timezone=*) TZ="$val"; export TZ; ;;
--flush-caches) flush_caches=1 ;;
--numa-interleave) numa_interleave=1 ;;

--help) usage ;;

@@ -707,6 +714,41 @@ mysqld daemon not started"
fi
fi

#
# Flush and purge buffers/caches.
#

if @TARGET_LINUX@ && test $flush_caches -eq 1
then
# Locate sync, ensure it exists.
if ! my_which sync > /dev/null 2>&1
then
log_error "sync command not found, required for --flush-caches"
exit 1
# Flush file system buffers.
elif ! sync
then
# Huh, the sync() function is always successful...
log_error "sync failed, check if sync is properly installed"
fi

# Locate sysctl, ensure it exists.
if ! my_which sysctl > /dev/null 2>&1
then
log_error "sysctl command not found, required for --flush-caches"
exit 1
# Purge page cache, dentries and inodes.
elif ! sysctl -q -w vm.drop_caches=3
then
log_error "sysctl failed, check the error message for details"
exit 1
fi
elif test $flush_caches -eq 1
then
log_error "--flush-caches is not supported on this platform"
exit 1
fi

#
# Uncomment the following lines if you want all tables to be automatically
# checked and repaired during startup. You should add sensible key_buffer
@@ -727,6 +769,31 @@ fi

cmd="`mysqld_ld_preload_text`$NOHUP_NICENESS"

#
# Set mysqld's memory interleave policy.
#

if @TARGET_LINUX@ && test $numa_interleave -eq 1
then
# Locate numactl, ensure it exists.
if ! my_which numactl > /dev/null 2>&1
then
log_error "numactl command not found, required for --numa-interleave"
exit 1
# Attempt to run a command, ensure it works.
elif ! numactl --interleave=all true
then
log_error "numactl failed, check if numactl is properly installed"
fi

# Launch mysqld with numactl.
cmd="$cmd numactl --interleave=all"
elif test $numa_interleave -eq 1
then
log_error "--numa-interleave is not supported on this platform"
exit 1
fi

for i in "$ledir/$MYSQLD" "$defaults" "--basedir=$MY_BASEDIR_VERSION" \
"--datadir=$DATADIR" "--plugin-dir=$plugin_dir" "$USER_OPTION"
do

0 comments on commit 19cf63c

Please sign in to comment.
You can’t perform that action at this time.