Skip to content

Commit

Permalink
Merge pull request eBay#415 from hkadayam/bitset_fix
Browse files Browse the repository at this point in the history
Fixed the number of chunks issue
  • Loading branch information
raakella1 authored Aug 14, 2024
2 parents 2fa025e + d1ac41d commit 0a59691
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "6.4.43"
version = "6.4.44"
homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
topics = ("ebay", "nublox")
Expand Down
15 changes: 7 additions & 8 deletions src/lib/device/hs_super_blk.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ class hs_super_blk {
static uint64_t chunk_super_block_size(const dev_info& dinfo);
static uint64_t chunk_info_bitmap_size(const dev_info& dinfo) {
// Chunk bitmap area has bitmap of max_chunks rounded off to 4k page
return sisl::round_up(std::max(1u, hs_super_blk::max_chunks_in_pdev(dinfo) / 8), 4096);
// add 4KB headroom for bitmap serialized header
auto bytes = sisl::round_up(hs_super_blk::max_chunks_in_pdev(dinfo), 8) / 8 + 4096;
return sisl::round_up(bytes, 4096);
}

static uint64_t total_size(const dev_info& dinfo) { return total_used_size(dinfo) + future_padding_size(dinfo); }
Expand All @@ -197,13 +199,10 @@ class hs_super_blk {
return (dinfo.dev_type == HSDevType::Fast) ? EXTRA_SB_SIZE_FOR_FAST_DEVICE : EXTRA_SB_SIZE_FOR_DATA_DEVICE;
}
static uint32_t max_chunks_in_pdev(const dev_info& dinfo) {
uint64_t min_chunk_size =
(dinfo.dev_type == HSDevType::Fast) ? MIN_CHUNK_SIZE_FAST_DEVICE : MIN_CHUNK_SIZE_DATA_DEVICE;
#ifdef _PRERELEASE
auto chunk_size = iomgr_flip::instance()->get_test_flip< long >("set_minimum_chunk_size");
if (chunk_size) { min_chunk_size = chunk_size.get(); }
#endif
return (dinfo.dev_size - 1) / min_chunk_size + 1;
uint64_t min_c_size = min_chunk_size(dinfo.dev_type);
// Do not round up , for a device with 128MB and min_chunk_size = 16MB, we should get 8 chunks
// for a device with 100MB and min_chunk_size = 16MB, we should get 6 chunks, not 7.
return dinfo.dev_size / min_c_size;
}
static uint32_t min_chunk_size(HSDevType dtype) {
uint64_t min_chunk_size = (dtype == HSDevType::Fast) ? MIN_CHUNK_SIZE_FAST_DEVICE : MIN_CHUNK_SIZE_DATA_DEVICE;
Expand Down
9 changes: 6 additions & 3 deletions src/lib/device/physical_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ void PhysicalDev::submit_batch() { m_drive_iface->submit_batch(); }

//////////////////////////// Chunk Creation/Load related methods /////////////////////////////////////////
void PhysicalDev::format_chunks() {
m_chunk_info_slots = std::make_unique< sisl::Bitset >(hs_super_blk::chunk_info_bitmap_size(m_dev_info));
auto bitmap_mem = m_chunk_info_slots->serialize(m_pdev_info.dev_attr.align_size);
m_chunk_info_slots = std::make_unique< sisl::Bitset >(std::max(1u, hs_super_blk::max_chunks_in_pdev(m_dev_info)),
/* align size */ 4096);
auto bitmap_mem = m_chunk_info_slots->serialize(/* align size */ 4096);
HS_REL_ASSERT_LE(bitmap_mem->size(), hs_super_blk::chunk_info_bitmap_size(m_dev_info),
"Chunk info serialized bitmap mismatch with expected size");
write_super_block(bitmap_mem->cbytes(), bitmap_mem->size(), hs_super_blk::chunk_sb_offset());
}

Expand All @@ -235,7 +238,7 @@ std::vector< shared< Chunk > > PhysicalDev::create_chunks(const std::vector< uin

try {
while (chunks_remaining > 0) {
auto b = m_chunk_info_slots->get_next_contiguous_n_reset_bits(0u, chunks_remaining);
auto b = m_chunk_info_slots->get_next_contiguous_n_reset_bits(0u, std::nullopt, 1u, chunks_remaining);
if (b.nbits == 0) { throw std::out_of_range("System has no room for additional chunk"); }

buf = hs_utils::iobuf_alloc(chunk_info::size * b.nbits, sisl::buftag::superblk,
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_pdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ SISL_OPTION_GROUP(test_pdev,
::cxxopts::value< uint32_t >()->default_value("2"), "number"),
(data_dev_size_mb, "", "data_dev_size_mb", "size of each data device in MB",
::cxxopts::value< uint64_t >()->default_value("1024"), "number"),
// in OrderlyChunkOpsWithRestart UT, we need to create 10 chunks on fast drive
// ensure fast dev has > min_chunk_size_fast(32M) * 10 capacity.
(fast_dev_size_mb, "", "fast_dev_size_mb", "size of each fast device in MB",
::cxxopts::value< uint64_t >()->default_value("100"), "number"),
::cxxopts::value< uint64_t >()->default_value("400"), "number"),
(spdk, "", "spdk", "spdk", ::cxxopts::value< bool >()->default_value("false"), "true or false"));

std::vector< std::string > g_data_dev_names;
Expand Down

0 comments on commit 0a59691

Please sign in to comment.