From ddff069df74d935d10ac8cb9abc5c7ece790c8f0 Mon Sep 17 00:00:00 2001 From: Jie Yao Date: Sun, 29 Oct 2023 18:18:46 +0800 Subject: [PATCH] Add `get_freeable_nblks` and `get_defrag_nblks` api to Vchunk (#216) the two apis will be used by HeapChunkSelector to select a best candidate chunk for GC Signed-off-by: Jie Yao --- conanfile.py | 2 +- src/include/homestore/vchunk.h | 2 ++ src/lib/blkalloc/blk_allocator.h | 4 ++++ src/lib/blkalloc/fixed_blk_allocator.cpp | 13 +++++++++++++ src/lib/blkalloc/varsize_blk_allocator.cpp | 13 +++++++++++++ src/lib/blkalloc/varsize_blk_allocator.h | 2 ++ src/lib/device/vchunk.cpp | 4 ++++ 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 7d4a73a3a..a2c858e77 100644 --- a/conanfile.py +++ b/conanfile.py @@ -5,7 +5,7 @@ class HomestoreConan(ConanFile): name = "homestore" - version = "4.5.8" + version = "4.5.9" homepage = "https://github.com/eBay/Homestore" description = "HomeStore Storage Engine" diff --git a/src/include/homestore/vchunk.h b/src/include/homestore/vchunk.h index f34ed0f4a..a88f17361 100644 --- a/src/include/homestore/vchunk.h +++ b/src/include/homestore/vchunk.h @@ -30,6 +30,8 @@ class VChunk { void set_user_private(const sisl::blob& data); const uint8_t* get_user_private() const; blk_num_t available_blks() const; + blk_num_t get_freeable_nblks() const; + blk_num_t get_defrag_nblks() const; uint32_t get_pdev_id() const; uint16_t get_chunk_id() const; cshared< Chunk > get_internal_chunk() const; diff --git a/src/lib/blkalloc/blk_allocator.h b/src/lib/blkalloc/blk_allocator.h index fb75bc0f4..0166ec5e1 100644 --- a/src/lib/blkalloc/blk_allocator.h +++ b/src/lib/blkalloc/blk_allocator.h @@ -186,6 +186,8 @@ class BlkAllocator { virtual BlkAllocStatus alloc(blk_count_t nblks, blk_alloc_hints const& hints, BlkId& out_blkid) = 0; virtual void free(BlkId const& id) = 0; virtual blk_num_t available_blks() const = 0; + virtual blk_num_t get_freeable_nblks() const = 0; + virtual blk_num_t get_defrag_nblks() const = 0; virtual blk_num_t get_used_blks() const = 0; virtual bool is_blk_alloced(BlkId const& b, bool use_lock = false) const = 0; virtual std::string to_string() const = 0; @@ -319,6 +321,8 @@ class FixedBlkAllocator : public BlkAllocator { void inited() override; blk_num_t available_blks() const override; + blk_num_t get_freeable_nblks() const override; + blk_num_t get_defrag_nblks() const override; blk_num_t get_used_blks() const override; bool is_blk_alloced(BlkId const& in_bid, bool use_lock = false) const override; std::string to_string() const override; diff --git a/src/lib/blkalloc/fixed_blk_allocator.cpp b/src/lib/blkalloc/fixed_blk_allocator.cpp index d922edf03..b3437ae1e 100644 --- a/src/lib/blkalloc/fixed_blk_allocator.cpp +++ b/src/lib/blkalloc/fixed_blk_allocator.cpp @@ -85,6 +85,19 @@ void FixedBlkAllocator::free(BlkId const& b) { } blk_num_t FixedBlkAllocator::available_blks() const { return m_blk_q.sizeGuess(); } + +blk_num_t FixedBlkAllocator::get_freeable_nblks() const { + // TODO: implement this + HS_DBG_ASSERT_EQ(false, true, "FixedBlkAllocator get_freeable_nblks Not implemented"); + return 0; +} + +blk_num_t FixedBlkAllocator::get_defrag_nblks() const { + // TODO: implement this + HS_DBG_ASSERT_EQ(false, true, "FixedBlkAllocator get_defrag_nblks Not implemented"); + return 0; +} + blk_num_t FixedBlkAllocator::get_used_blks() const { return get_total_blks() - available_blks(); } std::string FixedBlkAllocator::to_string() const { diff --git a/src/lib/blkalloc/varsize_blk_allocator.cpp b/src/lib/blkalloc/varsize_blk_allocator.cpp index 34d2e6dab..6b30d4e2b 100644 --- a/src/lib/blkalloc/varsize_blk_allocator.cpp +++ b/src/lib/blkalloc/varsize_blk_allocator.cpp @@ -731,6 +731,19 @@ bool VarsizeBlkAllocator::is_blk_alloced(BlkId const& bid, bool use_lock) const } blk_num_t VarsizeBlkAllocator::available_blks() const { return get_total_blks() - get_used_blks(); } + +blk_num_t VarsizeBlkAllocator::get_freeable_nblks() const { + // TODO: implement this + BLKALLOC_REL_ASSERT(false, "VarsizeBlkAllocator get_freeable_nblks Not implemented") + return 0; +} + +blk_num_t VarsizeBlkAllocator::get_defrag_nblks() const { + // TODO: implement this + BLKALLOC_REL_ASSERT(false, "VarsizeBlkAllocator get_defrag_nblks Not implemented") + return 0; +} + blk_num_t VarsizeBlkAllocator::get_used_blks() const { return get_alloced_blk_count(); } #ifdef _PRERELEASE diff --git a/src/lib/blkalloc/varsize_blk_allocator.h b/src/lib/blkalloc/varsize_blk_allocator.h index 7e23597fd..f0fab8c96 100644 --- a/src/lib/blkalloc/varsize_blk_allocator.h +++ b/src/lib/blkalloc/varsize_blk_allocator.h @@ -216,6 +216,8 @@ class VarsizeBlkAllocator : public BlkAllocator { void inited() override; blk_num_t available_blks() const override; + blk_num_t get_freeable_nblks() const override; + blk_num_t get_defrag_nblks() const override; blk_num_t get_used_blks() const override; bool is_blk_alloced(BlkId const& in_bid, bool use_lock = false) const override; std::string to_string() const override; diff --git a/src/lib/device/vchunk.cpp b/src/lib/device/vchunk.cpp index 54dc54604..a154f39a9 100644 --- a/src/lib/device/vchunk.cpp +++ b/src/lib/device/vchunk.cpp @@ -25,6 +25,10 @@ const uint8_t* VChunk::get_user_private() const { return m_internal_chunk->user_ blk_num_t VChunk::available_blks() const { return m_internal_chunk->blk_allocator()->available_blks(); } +blk_num_t VChunk::get_freeable_nblks() const { return m_internal_chunk->blk_allocator()->get_freeable_nblks(); } + +blk_num_t VChunk::get_defrag_nblks() const { return m_internal_chunk->blk_allocator()->get_defrag_nblks(); } + uint32_t VChunk::get_pdev_id() const { return m_internal_chunk->physical_dev()->pdev_id(); } uint16_t VChunk::get_chunk_id() const { return m_internal_chunk->chunk_id(); }