WL#14452: InnoDB: Add configuration variable to switch between fdatasync() and fsync()
Affects: Server-8.0
—
Status: Complete
On platforms where fdatasync() is available we should allow the user to switch to using fdatasync() from fsync(). Which is basically Linux.
Proposed configuration parameter: --innodb-use-fdatasync := bool
FR1 - On platforms that have fdatasync defined, setting --innodb-use-fdatasync
will make InnoDB use fdatasync instead of the default fsync for os buffer flushes.
Introduce a new MySQL variable indicating whether InnoDB should use fdatasync
instead of fsync for os flushes.This is a dynamic global variable.
Usage:
[1] ./bin/mysqld --innodb-use-fdatasync=1
When using this flag, InnoDB will use the fdatasync system call which will not
flush the metadata of accessed files on each flush. This should allow for some
performance gains in certain scenarios.
1) Declare the new MYSQL_SYSVAR_BOOL in ha_innodb.cc - use_fdatasync:
static MYSQL_SYSVAR_BOOL(use_fdatasync, srv_use_fdatasync, PLUGIN_VAR_NOCMDARG,
"Use fdatasync() instead of the default fsync().",
nullptr, nullptr, false);
2) Declare the underlying bool (srv_use_fdatasync) in srv0srv.h and
define in srv0srv.cc:
/** Use fdatasync() instead of fsync(). */
bool srv_use_fdatasync = false;
3) In os0file.cc, static int os_file_fsync_posix(os_file_t file) add the fdatasync
call if available:
#if defined(HAVE_FDATASYNC) && defined(HAVE_DECL_FDATASYNC)
const auto ret = srv_use_fdatasync ? fdatasync(file) : fsync(file);
#else
const auto ret = fsync(file);
#endif
Copyright (c) 2000, 2025, Oracle Corporation and/or its affiliates. All rights reserved.