Skip to content

Commit

Permalink
Fix ArenaTest.UnmappedAllocation in some cases (#12378)
Browse files Browse the repository at this point in the history
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 #12351

Pull Request resolved: #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
  • Loading branch information
pdillinger authored and facebook-github-bot committed Feb 27, 2024
1 parent a4ff83d commit 4184921
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion memory/arena_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef OS_WIN
#include <sys/resource.h>
#endif
#include "port/jemalloc_helper.h"
#include "port/port.h"
#include "test_util/testharness.h"
#include "util/random.h"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4184921

Please sign in to comment.