diff --git a/src/v/bytes/details/io_allocation_size.h b/src/v/bytes/details/io_allocation_size.h index d46d6f5cf82c4..c7cd938f956cb 100644 --- a/src/v/bytes/details/io_allocation_size.h +++ b/src/v/bytes/details/io_allocation_size.h @@ -29,28 +29,46 @@ class io_allocation_size { static constexpr size_t ss_max_small_allocation = 16384; public: - // >>> x=512 - // >>> while x < int((1024*128)): - // ... print(x) - // ... x=int(((x*3)+1)/2) - // ... x=int(min(1024*128,x)) - // print(1024*128) + // This script computes the table immediately below, which are "ideal" + // allocation sizes: rounded up to the next true size supported by + // the seastar allocator. At <= 16K we apply the small pool indexing + // logic, and above we use powers of 2 since we are in the buddy allocator + // which only supports power-of-two sizes. + // + // We scale the target size by 1.47, i.e., 1.5 tweaked slightly to ensure + // we hit 16K at the small<->big pool boundary. + // + // def lg2(size: int): + // return size.bit_length() - 1 + // def p(v: object): + // print(f"{v},") + // s = 512 + // fb = 2 # idx_frac_bits + // while s <= 2**14: + // # The size calculation below is doing idx_to_size(size_to_idx(s)), + // # i.e., figuring out which small point index the allocation falls in + // # then seeing what the size of that small pool is, i.e., the size of + // # the smallest small pool that can fix this allocation. + // # See the corresponding routines in src/core/memory.cc: + // #https://github.com/scylladb/seastar/blob/f840b860432e7e716e3cfc004690897b50dc122c/src/core/memory.cc#L478-L499 + // idx = ((lg2(s) << fb) - ((1 << fb) - 1)) + ((s - 1) >> (lg2(s) - fb)) + // p((((1 << fb) | (idx & ((1 << fb) - 1))) << (idx >> fb)) >> fb) + // s = int(s * 1.47) + // for e in [15, 16, 17]: + // p(2**e) static constexpr auto alloc_table = std::to_array( - // computed from a python script above {512, 768, - 1152, - 1728, - 2592, - 3888, - 5832, - 8748, - 13122, - 19683, - 29525, - 44288, - 66432, - 99648, + 1280, + 1792, + 2560, + 3584, + 6144, + 8192, + 12288, + 16384, + 32768, + 65536, 131072}); static size_t next_allocation_size(size_t data_size); diff --git a/src/v/bytes/tests/iobuf_tests.cc b/src/v/bytes/tests/iobuf_tests.cc index 4ebfee7f2e129..47dcc1a267bcb 100644 --- a/src/v/bytes/tests/iobuf_tests.cc +++ b/src/v/bytes/tests/iobuf_tests.cc @@ -396,38 +396,36 @@ SEASTAR_THREAD_TEST_CASE(iobuf_as_ostream) { } SEASTAR_THREAD_TEST_CASE(alloctor_forward_progress) { - static constexpr std::array src = {{ + static constexpr auto src = std::to_array({ 512, 768, - 1152, - 1728, - 2592, - 3888, - 5832, - 8748, - 13122, - 19683, - 29525, - 44288, - 66432, - 99648, - }}; - static constexpr std::array expected = {{ + 1280, + 1792, + 2560, + 3584, + 6144, + 8192, + 12288, + 16384, + 32768, + 65536, + 131072, + }); + static constexpr auto expected = std::to_array({ 768, - 1152, - 1728, - 2592, - 3888, - 5832, - 8748, - 13122, - 19683, - 29525, - 44288, - 66432, - 99648, + 1280, + 1792, + 2560, + 3584, + 6144, + 8192, + 12288, + 16384, + 32768, + 65536, + 131072, 131072, - }}; + }); BOOST_REQUIRE_EQUAL(src.size(), expected.size()); for (size_t i = 0; i < src.size(); ++i) { BOOST_REQUIRE_EQUAL( @@ -446,7 +444,7 @@ SEASTAR_THREAD_TEST_CASE(test_next_chunk_allocation_append_temp_buf) { } // slow but tha'ts life. auto distance = std::distance(buf.begin(), buf.end()); - BOOST_REQUIRE_EQUAL(distance, 324); + BOOST_REQUIRE_EQUAL(distance, 323); constexpr size_t sz = 40000 * 1024; auto msg = iobuf_as_scattered(std::move(buf)); BOOST_REQUIRE_EQUAL(msg.size(), sz); @@ -462,7 +460,7 @@ SEASTAR_THREAD_TEST_CASE(test_next_chunk_allocation_append_iobuf) { } // slow but tha'ts life. auto distance = std::distance(buf.begin(), buf.end()); - BOOST_REQUIRE_EQUAL(distance, 324); + BOOST_REQUIRE_EQUAL(distance, 323); constexpr size_t sz = 40000 * 1024; auto msg = iobuf_as_scattered(std::move(buf)); BOOST_REQUIRE_EQUAL(msg.size(), sz);