Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VarsizeBlkAllocator crash when running with smaller chunk size. #383

Open
xiaoxichen opened this issue Apr 17, 2024 · 1 comment
Open

VarsizeBlkAllocator crash when running with smaller chunk size. #383

xiaoxichen opened this issue Apr 17, 2024 · 1 comment

Comments

@xiaoxichen
Copy link
Contributor

    for (const auto& slab_cfg : cfg.m_per_slab_cfg) {
        std::vector< blk_num_t > level_limits;
        level_limits.reserve(slab_cfg.m_level_distribution_pct.size());
#ifndef NDEBUG
        HS_DBG_ASSERT_EQ(slab_cfg.slab_size, slab_size, "Slab config size is not contiguous power of 2");
        slab_size *= 2;
#endif

        blk_num_t sum{0};
        for (const auto& p : slab_cfg.m_level_distribution_pct) {
            const blk_num_t limit{static_cast< blk_num_t >((static_cast< double >(slab_cfg.max_entries) * p) / 100.0)};
            sum += limit;
            level_limits.push_back(limit);
        }
        HS_DBG_ASSERT_GE(slab_cfg.max_entries, sum, "Slab config distribution does not add to 100%");
        if (sum < slab_cfg.max_entries) {
            level_limits[0] += slab_cfg.max_entries - sum; // Put the remaining to the first priority
        }

        auto ptr{std::make_unique< SlabCacheQueue >(slab_cfg.slab_size, level_limits, slab_cfg.refill_threshold_pct,
                                                    metrics)};
        m_slab_queues.push_back(std::move(ptr));

It is possible we have a level with 0 limit, which will crash in constructing SlabCacheQueue

unknown file: Failure
C++ exception with description "MPMCQueue with explicit capacity 0 is impossible" thrown in the test body.
$43 = std::vector of length 2, capacity 2 = {2, 0}
(gdb) p slab_cfg.m_level_distribution_pct
$44 = std::vector of length 2, capacity 2 = {70, 30}
(gdb) p slab_cfg.max_entries
$45 = 2
(gdb) p slab_cfg.max_entries
$46 = 2
(gdb) p slab_cfg
$47 = (const homestore::SlabCacheConfig::_slab_config &) @0x617000069cf8: {slab_size = 128, max_entries = 2, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}
(gdb) p cfg.m_per_slab_cfg
$48 = std::vector of length 9, capacity 9 = {{slab_size = 1, max_entries = 707, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 2, max_entries = 118, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 4, max_entries = 59,
    refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 8, max_entries = 25, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 16, max_entries = 21, refill_threshold_pct = 60,
    m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 32, max_entries = 10, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 64, max_entries = 5, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30},
    m_name = "varsize_chunk_0"}, {slab_size = 128, max_entries = 2, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 256, max_entries = 3, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}}
@xiaoxichen
Copy link
Contributor Author

Thread 1 "homestore_test" hit Breakpoint 1, homestore::VarsizeBlkAllocator::VarsizeBlkAllocator (this=0x61500005d290, cfg=..., is_fresh=true, chunk_id=0) at /var/home/centos/.conan/data/homestore/6.2.3-49/oss/master/build/98a6c2ddffe4d1fb00eb495a8407dc88f8f61572/src/lib/blkalloc/varsize_blk_allocator.cpp:53
53	VarsizeBlkAllocator::VarsizeBlkAllocator(VarsizeBlkAllocConfig const& cfg, bool is_fresh, chunk_num_t chunk_id) :
(gdb) p cfg
$1 = (const homestore::VarsizeBlkAllocConfig &) @0x7fffffff9480: {<homestore::BlkAllocConfig> = {_vptr.BlkAllocConfig = 0x55555e0080c0 <vtable for homestore::VarsizeBlkAllocConfig+16>, m_blk_size = 4096, m_align_size = 512, m_capacity = 4224, m_blks_per_portion = 4224, m_persistent = false, m_unique_name = "varsize_chunk_0"}, m_phys_page_size = 4096, m_nsegments = 1, m_blks_per_temp_group = 4224,
  m_max_cache_blks = 3379, m_slab_config = {m_name = "varsize_chunk_0", m_per_slab_cfg = std::vector of length 9, capacity 16 = {{slab_size = 1, max_entries = 707, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 2, max_entries = 118, refill_threshold_pct = 60,
        m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 4, max_entries = 59, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 8, max_entries = 25, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30},
        m_name = "varsize_chunk_0"}, {slab_size = 16, max_entries = 21, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 32, max_entries = 10, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 64, max_entries = 5,
        refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 128, max_entries = 2, refill_threshold_pct = 60, m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}, {slab_size = 256, max_entries = 3, refill_threshold_pct = 60,
        m_level_distribution_pct = std::vector of length 2, capacity 2 = {70, 30}, m_name = "varsize_chunk_0"}}}, m_use_slabs = true}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant