From 7f9543c11f1d7d81162f93b996a6f95656cc1a01 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Wed, 20 Mar 2019 21:10:04 +0300 Subject: [PATCH] os/bluestore: unconditionally cap chunks returned by allocator to 2^31 Signed-off-by: Igor Fedotov (cherry picked from commit 1337443e37ffbfcaf494bdb2bb80db4cf41b97f9) --- src/os/bluestore/fastbmap_allocator_impl.h | 6 ++++- .../objectstore/fastbmap_allocator_test.cc | 22 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/fastbmap_allocator_impl.h b/src/os/bluestore/fastbmap_allocator_impl.h index 1c9cd3af080e..98a78d4b0ca9 100755 --- a/src/os/bluestore/fastbmap_allocator_impl.h +++ b/src/os/bluestore/fastbmap_allocator_impl.h @@ -156,7 +156,6 @@ class AllocatorLevel01Loose : public AllocatorLevel01 interval_vector_t* res) { auto it = res->rbegin(); - if (max_length) { if (it != res->rend() && it->offset + it->length == offset) { auto l = max_length - it->length; @@ -638,6 +637,11 @@ protected: ceph_assert(length >= min_length); ceph_assert((length % min_length) == 0); + uint64_t cap = 1ull << 31; + if (max_length == 0 || max_length >= cap) { + max_length = cap; + } + uint64_t l1_w = slotset_width * l1._children_per_slot(); std::lock_guard l(lock); diff --git a/src/test/objectstore/fastbmap_allocator_test.cc b/src/test/objectstore/fastbmap_allocator_test.cc index 650a452c0005..14752422b29b 100755 --- a/src/test/objectstore/fastbmap_allocator_test.cc +++ b/src/test/objectstore/fastbmap_allocator_test.cc @@ -900,8 +900,6 @@ TEST(TestAllocatorLevel01, test_4G_alloc_bug2) std::map bins_overall; al2.collect_stats(bins_overall); - std::cout << "!!!!!!!!!!!!!!" << std::endl; - uint64_t allocated4 = 0; interval_vector_t a4; al2.allocate_l2(0x3e000000, _1m, &allocated4, &a4); @@ -913,3 +911,23 @@ TEST(TestAllocatorLevel01, test_4G_alloc_bug2) ASSERT_EQ(a4[1].length, 0x3cd00000u); } } + +TEST(TestAllocatorLevel01, test_4G_alloc_bug3) +{ + { + TestAllocatorLevel02 al2; + uint64_t capacity = 0x8000 * _1m; // = 32GB + al2.init(capacity, 0x10000); + std::cout << "Init L2 cont aligned" << std::endl; + + uint64_t allocated4 = 0; + interval_vector_t a4; + al2.allocate_l2(4096ull * _1m, _1m, &allocated4, &a4); + ASSERT_EQ(a4.size(), 2u); // allocator has to split into 2 allocations + ASSERT_EQ(allocated4, 4096ull * _1m); + ASSERT_EQ(a4[0].offset, 0u); + ASSERT_EQ(a4[0].length, 2048ull * _1m); + ASSERT_EQ(a4[1].offset, 2048ull * _1m); + ASSERT_EQ(a4[1].length, 2048ull * _1m); + } +} -- 2.47.3