summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2023-08-25 13:26:41 +0200
committerGitHub <noreply@github.com>2023-08-25 13:26:41 +0200
commit9e954b1e789794aa1d6b2fcdd802a14e1799101f (patch)
treef86cd21446703a2a4696c9e092fbd5982007ea45
parent66b009fc2f83f3bf50f2ed23919b92f8bf154e1a (diff)
parentb68af3da57a9a860697184ef678171a06b1ba27b (diff)
Merge pull request #28151 from vespa-engine/toregge/use-128-bytes-alignment-for-small-allocations-in-mmap-file-allocator
Use 128 bytes alignment for small allocations in MmapFileAllocator.
-rw-r--r--vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp16
-rw-r--r--vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp2
2 files changed, 9 insertions, 9 deletions
diff --git a/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp b/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp
index 61faf4e5168..c6971c0d803 100644
--- a/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp
+++ b/vespalib/src/tests/util/mmap_file_allocator/mmap_file_allocator_test.cpp
@@ -86,17 +86,17 @@ TEST_P(MmapFileAllocatorTest, zero_sized_allocation_is_handled)
TEST_P(MmapFileAllocatorTest, mmap_file_allocator_works)
{
- MyAlloc buf(_allocator, _allocator.alloc(400));
- EXPECT_LE(400u, buf.size);
+ MyAlloc buf(_allocator, _allocator.alloc(300));
+ EXPECT_LE(300u, buf.size);
EXPECT_TRUE(buf.data != nullptr);
memcpy(buf.data, "1st", 4);
MyAlloc buf2(_allocator, _allocator.alloc(600));
- EXPECT_LE(5u, buf2.size);
+ EXPECT_LE(600u, buf2.size);
EXPECT_TRUE(buf2.data != nullptr);
EXPECT_TRUE(buf.data != buf2.data);
memcpy(buf2.data, "fine", 5);
EXPECT_EQ(0u, _allocator.resize_inplace(buf.asPair(), 500));
- EXPECT_EQ(0u, _allocator.resize_inplace(buf.asPair(), 300));
+ EXPECT_EQ(0u, _allocator.resize_inplace(buf.asPair(), 200));
EXPECT_NE(0u, _allocator.get_end_offset());
if (GetParam().small_limit == 0) {
int result = msync(buf.data, buf.size, MS_SYNC);
@@ -108,16 +108,16 @@ TEST_P(MmapFileAllocatorTest, mmap_file_allocator_works)
TEST_P(MmapFileAllocatorTest, reuse_file_offset_works)
{
- constexpr size_t size_400 = 400;
+ constexpr size_t size_300 = 300;
constexpr size_t size_600 = 600;
- assert(hello.size() + 1 <= size_400);
+ assert(hello.size() + 1 <= size_300);
assert(world.size() + 1 <= size_600);
{
- MyAlloc buf(_allocator, _allocator.alloc(size_400));
+ MyAlloc buf(_allocator, _allocator.alloc(size_300));
memcpy(buf.data, hello.c_str(), hello.size() + 1);
}
{
- MyAlloc buf(_allocator, _allocator.alloc(size_400));
+ MyAlloc buf(_allocator, _allocator.alloc(size_300));
EXPECT_EQ(0, memcmp(buf.data, hello.c_str(), hello.size() + 1));
}
{
diff --git a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
index f1ea0034474..198294b3770 100644
--- a/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
+++ b/vespalib/src/vespa/vespalib/util/mmap_file_allocator.cpp
@@ -77,7 +77,7 @@ MmapFileAllocator::alloc(size_t sz) const
if (sz == 0) {
return PtrAndSize(); // empty allocation
}
- static constexpr size_t alignment = 64;
+ static constexpr size_t alignment = 128;
sz = (sz + alignment - 1) & -alignment; // round sz to a multiple of alignment
if (sz >= _small_limit) {
return alloc_large(sz);