MDEV-22186 : Add innodb_buffer_pool_in_core_file to control buffer pool in core#4651
MDEV-22186 : Add innodb_buffer_pool_in_core_file to control buffer pool in core#4651mariadb-TafzeelShams wants to merge 1 commit into10.11from
Conversation
0034625 to
9b91138
Compare
…l in cores Problem: There is no control to include or exclude the InnoDB buffer pool from core files, which can lead to unnecessarily large core dumps or prevent capturing useful memory state. Solution: Introduce a dynamic global system variable innodb_buffer_pool_in_core_file. When set to OFF (or via --skip-innodb-buffer-pool-in-core-file), the server attempts to exclude the buffer pool from core dumps using madvise(MADV_DONTDUMP) where supported. If exclusion cannot be guaranteed, @@core_file is automatically disabled and a warning is emitted to respect the user’s intention. - innodb_buffer_pool_in_core_file Determines whether the buffer pool should be included in core files when @@core_file=ON. No effect if @@core_file=OFF. Default: OFF on non-debug builds with MADV_DONTDUMP support, ON otherwise. - innobase_should_madvise_buf_pool() Evaluates @@core_file and @@innodb_buffer_pool_in_core_file to determine if MADV_DONTDUMP should be applied. - innobase_disable_core_dump() Clears TEST_CORE_ON_SIGNAL, disabling @@core_file when buffer pool exclusion cannot be guaranteed. - buf_pool_t::madvise_dont_dump() Applies MADV_DONTDUMP to buffer pool memory. Emits warning and returns false if unsupported or fails. - buf_pool_t::madvise_dump() Applies MADV_DODUMP to re-include buffer pool in core dumps. Returns false if unsupported or fails. - buf_pool_t::madvise_update_dump() Reevaluates and updates madvise state. If exclusion fails, invokes innobase_disable_core_dump(). - buf_pool_t::buf_pool_should_madvise_dont_dump Tracks current dump state, protected by buf_pool_t::mutex. - buf_pool_t::create() Initializes buf_pool_should_madvise_dont_dump and conditionally applies MADV_DONTDUMP after allocation; disables core dumps on failure. - buf_pool_t::close() Calls madvise_dump() before releasing memory if MADV_DONTDUMP was applied. - buf_pool_t::resize() Invokes madvise_update_dump(true) to reapply correct madvise state after resizing. - innodb_srv_buffer_pool_in_core_file_update() Update hook that updates srv_buffer_pool_in_core_file and calls buf_pool.madvise_update_dump(). - srv_buffer_pool_in_core_file Global variable backing @@innodb_buffer_pool_in_core_file. Inspired from mysql commit@891460995137598a6e0ae3684ba1cc6ccd0c3ca3
9b91138 to
b881bdc
Compare
| # madvise MADV_DONTDUMP is non-posix extension available in Linux 3.4 | ||
| --let $minimum_required_linux_version = 3.4 | ||
| --source include/linux-version.inc |
There was a problem hiding this comment.
In b600f30 #364, @grooverdan introduced the madvise() calls, and there never was an issue reported with any GNU/Linux distribution in all these years. I see that Linux kernel 3.4 was released in 2012. MariaDB Server 10.4 switched the code base to C++11 (ISO/IEC 14882:2011), which bumped the compiler requirement to GCC 4.8.5. This was available in Red Hat Enterprise Linux 7, which has meanwhile reached its End of Maintenance support on 2024-06-30. According to https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux the kernel major version number should be reported as 3.10 by that dated system, which had originally been introduced in 2014.
I checked the environment details on https://buildbot.mariadb.org/#/builders/222 but unfortunately it’s running in a container on a much newer kernel (6.x).
Please remove this check as well as the entire file.
| --echo # Shutdown server | ||
| --source include/shutdown_mysqld.inc | ||
|
|
||
| --echo # Restart server with --log-error | ||
| --exec echo "restart:--log-error=$MYSQLTEST_VARDIR/log/core_dump.err" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect | ||
| --enable_reconnect | ||
| --source include/wait_until_connected_again.inc |
There was a problem hiding this comment.
Why do we need this restart? Other tests use the following pattern just fine:
let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN= InnoDB: foo;
-- source include/search_pattern_in_file.inc
| --enable_reconnect | ||
| --source include/wait_until_connected_again.inc | ||
|
|
||
| SHOW VARIABLES LIKE '%core%'; |
There was a problem hiding this comment.
Why such a broad pattern that could break when someone adds a variable that happens to match it, such as optimizer_plan_score_for_something_funny?
| # Embedded mode doesn't support restart | ||
| --source include/not_embedded.inc | ||
|
|
||
| --echo # Shutdown server | ||
| --source include/shutdown_mysqld.inc | ||
|
|
||
| --echo # Restart server with --log-error | ||
| --exec echo "restart:--log-error=$MYSQLTEST_VARDIR/log/core_dump.err" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect | ||
| --enable_reconnect | ||
| --source include/wait_until_connected_again.inc |
There was a problem hiding this comment.
There does not seem to be any reason for any restart in this test.
| # Kill mysqld to dump a core | ||
| system("kill", "-s", "SIGABRT", "$pid"); | ||
| print "# Perl: Sent a SIGABRT to mysqld to dump a core.\n"; | ||
|
|
||
| $core_dir = $ENV{'MYSQLTEST_VARDIR'} . '/mysqld.1/data/'; | ||
|
|
||
| $found_core = 0; | ||
| $core_size = 0; | ||
| $core_size_good = 0; | ||
|
|
||
| # Check the files in the core file directory | ||
| $wait_sec = 60; | ||
| while ($wait_sec > 0) { | ||
| opendir(my $dir, $core_dir) or die "Failed to open dir $core_dir: $!\n"; |
There was a problem hiding this comment.
I think that there is a much less intrusive ways to check what would included in a core dump. man gcore informs me that /proc/$pid/coredump_filter can be consulted. There is also /proc/$pid/maps. I think that you should experiment with those and identify the impact of the madvise() calls. There is no need to significantly increase the load on https://buildbot.mariadb.org workers by generating potentially huge core dumps. It can lead to significant interference with other concurrently running workload. Keep in mind that the data directory is usually stored in /dev/shm, and we don’t want to trigger any swapping.
Description
MDEV-22186: Add
innodb_buffer_pool_in_core_fileto control buffer pool in coresProblem:
There is no control to include or exclude the InnoDB buffer pool from core files,
which can lead to unnecessarily large core dumps or prevent capturing useful
memory state.
Solution:
Introduce a dynamic global system variable
innodb_buffer_pool_in_core_file.When set to
OFF(or via--skip-innodb-buffer-pool-in-core-file),the server attempts to exclude the buffer pool from core dumps using
madvise(MADV_DONTDUMP)where supported. If exclusion cannot be guaranteed,@@core_fileis automatically disabled and a warning is emitted to respect theuser’s intention.
Inspired from mysql commit@891460995137598a6e0ae3684ba1cc6ccd0c3ca3
How can this PR be tested?
Added
mysql-test/suite/innodb/t/mysqld_core_dump_without_buffer_pool.test
mysql-test/suite/innodb/t/mysqld_core_dump_without_buffer_pool_dynamic.test
mysql-test/suite/innodb/t/mysqld_core_dump_without_buffer_pool_with_resizing.test
Basing the PR against the correct MariaDB version
Backward compatibility
The default value of
innodb_buffer_pool_in_core_filepreserves existing behavior:This ensures the new variable behaves the same way as previous versions by default.