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

add reclaim api to append_blk_allocator for GC #366

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/lib/blkalloc/append_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ BlkAllocStatus AppendBlkAllocator::mark_blk_allocated(BlkId const&) { return Blk

void AppendBlkAllocator::free_on_disk(BlkId const&) {}

// note that this function will force to reclaim nblks from the tail, so make sure the nblks at tail are not in use
// or have been copied to another chunk for later access;
void AppendBlkAllocator::reclaim_tail_nblks(blk_count_t nblks) {
std::unique_lock lk(m_mtx);
auto cur_cp = hs()->cp_mgr().cp_guard();
m_last_append_offset -= nblks;
m_freeable_nblks += nblks;
set_dirty_offset(cur_cp->id() % MAX_CP_COUNT);

COUNTER_INCREMENT(m_metrics, num_reclaimed, nblks);
}

bool AppendBlkAllocator::is_blk_alloced_on_disk(BlkId const&, bool) const { return false; }

//
Expand Down
2 changes: 2 additions & 0 deletions src/lib/blkalloc/append_blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AppendBlkAllocMetrics : public sisl::MetricsGroup {
explicit AppendBlkAllocMetrics(const char* inst_name) : sisl::MetricsGroup("AppendBlkAlloc", inst_name) {
REGISTER_COUNTER(num_alloc, "Number of blks alloc attempts");
REGISTER_COUNTER(num_alloc_failure, "Number of blk alloc failures");
REGISTER_COUNTER(num_reclaimed, "Number of blk reclaimed from tail");

register_me_to_farm();
}
Expand Down Expand Up @@ -87,6 +88,7 @@ class AppendBlkAllocator : public BlkAllocator {
BlkAllocStatus mark_blk_allocated(BlkId const& b) override;

void free_on_disk(BlkId const& b) override;
void reclaim_tail_nblks(blk_count_t nblks) override;
bool is_blk_alloced_on_disk(BlkId const& b, bool use_lock = false) const override;

/**
Expand Down
1 change: 1 addition & 0 deletions src/lib/blkalloc/bitmap_blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class BitmapBlkAllocator : public BlkAllocator {
virtual void load() = 0;
BlkAllocStatus alloc_on_disk(BlkId const& in_bid) override;
void free_on_disk(BlkId const& b) override;
void reclaim_tail_nblks(blk_count_t nblks) override{};
bool is_blk_alloced_on_disk(BlkId const& b, bool use_lock = false) const override;
void cp_flush(CP* cp) override;

Expand Down
3 changes: 3 additions & 0 deletions src/lib/blkalloc/blk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class BlkAllocator {
virtual void free(BlkId const& id) = 0;
virtual void free_on_disk(BlkId const& bid) = 0;

// Reclaim nblks from the tail of the chunk
virtual void reclaim_tail_nblks(blk_count_t nblks) = 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;
Expand Down