From 41849210e9acaba9a0d5bf842cf321f9328a212b Mon Sep 17 00:00:00 2001 From: Peter Dillinger Date: Mon, 26 Feb 2024 16:08:21 -0800 Subject: [PATCH] Fix ArenaTest.UnmappedAllocation in some cases (#12378) Summary: Fix compatibility with transparent huge pages by allocating in increments (1MiB) smaller than the typical smallest huge page size of 2MiB. Also, bypass the test when jemalloc config.fill is used, which means the allocator is explicitly configured to write to memory before we get it, which is not what this test expects. Fixes https://github.com/facebook/rocksdb/issues/12351 Pull Request resolved: https://github.com/facebook/rocksdb/pull/12378 Test Plan: ``` sudo bash -c 'echo "always" > /sys/kernel/mm/transparent_hugepage/enabled' ``` And see unit test fails before this change, passes after this change Also tested internal buck build with dbg mode (previously failing). Reviewed By: jaykorean, hx235 Differential Revision: D54139634 Pulled By: pdillinger fbshipit-source-id: 179accebe918d8eecd46a979fcf21d356f9b5519 --- memory/arena_test.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/memory/arena_test.cc b/memory/arena_test.cc index 8db761f68f..1547a86d5d 100644 --- a/memory/arena_test.cc +++ b/memory/arena_test.cc @@ -12,6 +12,7 @@ #ifndef OS_WIN #include #endif +#include "port/jemalloc_helper.h" #include "port/port.h" #include "test_util/testharness.h" #include "util/random.h" @@ -267,7 +268,21 @@ TEST_F(ArenaTest, UnmappedAllocation) { // Verify that it's possible to get unmapped pages in large allocations, // for memory efficiency and to ensure we don't accidentally waste time & // space initializing the memory. - constexpr size_t kBlockSize = 2U << 20; + +#ifdef ROCKSDB_JEMALLOC + // With Jemalloc config.fill, the pages are written to before we get them + uint8_t fill = 0; + size_t fill_sz = sizeof(fill); + mallctl("config.fill", &fill, &fill_sz, nullptr, 0); + if (fill) { + ROCKSDB_GTEST_BYPASS("Test skipped because of config.fill==true"); + return; + } +#endif // ROCKSDB_JEMALLOC + + // This block size value is smaller than the smallest x86 huge page size, + // so should not be fulfilled by a transparent huge page mapping. + constexpr size_t kBlockSize = 1U << 20; Arena arena(kBlockSize); // The allocator might give us back recycled memory for a while, but