From 5dffc19f2d20308226d11c5b4bc876ca41f7d72f Mon Sep 17 00:00:00 2001 From: Lakshmi Narayanan Sreethar Date: Tue, 17 Dec 2024 14:52:26 +0530 Subject: [PATCH] sstables_manager: introduce reclaim_memory_and_stop_tracking_sstable() When an sstable is unlinked or deactivated, it should be removed from the component memory tracking metrics and any further reload/reclaim should be disabled. This patch adds a new method that implements the above mentioned functionality. This patch also updates the deactivate() to use the new method. Next patch will use it to disable tracking when an sstable is unlinked. Signed-off-by: Lakshmi Narayanan Sreethar --- sstables/sstables_manager.cc | 18 ++++++++++++++---- sstables/sstables_manager.hh | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sstables/sstables_manager.cc b/sstables/sstables_manager.cc index 06fd44d639..cd6d4d5a63 100644 --- a/sstables/sstables_manager.cc +++ b/sstables/sstables_manager.cc @@ -227,15 +227,25 @@ future<> sstables_manager::components_reloader_fiber() { } } +void sstables_manager::reclaim_memory_and_stop_tracking_sstable(sstable* sst) { + // remove the sstable from the memory tracking metrics + _total_reclaimable_memory -= sst->total_reclaimable_memory_size(); + _total_memory_reclaimed -= sst->total_memory_reclaimed(); + // reclaim any remaining memory from the sstable + sst->reclaim_memory_from_components(); + // disable further reload of components + _reclaimed.erase(*sst); + sst->disable_component_memory_reload(); +} + void sstables_manager::add(sstable* sst) { _active.push_back(*sst); } void sstables_manager::deactivate(sstable* sst) { - // Remove SSTable from the reclaimable memory tracking - _total_reclaimable_memory -= sst->total_reclaimable_memory_size(); - _total_memory_reclaimed -= sst->total_memory_reclaimed(); - _reclaimed.erase(*sst); + // Drop reclaimable components if they are still in memory + // and remove SSTable from the reclaimable memory tracking + reclaim_memory_and_stop_tracking_sstable(sst); // At this point, sst has a reference count of zero, since we got here from // lw_shared_ptr_deleter::dispose(). diff --git a/sstables/sstables_manager.hh b/sstables/sstables_manager.hh index e792f7e2a9..d861b9240d 100644 --- a/sstables/sstables_manager.hh +++ b/sstables/sstables_manager.hh @@ -219,6 +219,10 @@ private: // Fiber to reload reclaimed components back into memory when memory becomes available. future<> components_reloader_fiber(); size_t get_memory_available_for_reclaimable_components(); + // Reclaim memory from the SSTable and remove it from the memory tracking metrics. + // The method is idempotent and for an sstable that is deleted, it is called both + // during unlink and during deactivation. + void reclaim_memory_and_stop_tracking_sstable(sstable* sst); private: db::large_data_handler& get_large_data_handler() const { return _large_data_handler;