Skip to content

Commit

Permalink
Add get_freeable_nblks and get_defrag_nblks api to Vchunk (#216)
Browse files Browse the repository at this point in the history
the two apis will be used by HeapChunkSelector to select a best
candidate chunk for GC

Signed-off-by: Jie Yao <[email protected]>
  • Loading branch information
JacksonYao287 authored Oct 29, 2023
1 parent fcb47c0 commit ddff069
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/include/homestore/vchunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/blkalloc/blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/lib/blkalloc/fixed_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/blkalloc/varsize_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/lib/blkalloc/varsize_blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/device/vchunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down

0 comments on commit ddff069

Please sign in to comment.