From f1a711c830be195bee49776609e379e03ab96b9a Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Fri, 4 Apr 2025 15:07:11 +0200 Subject: [PATCH] garbage collection: set phase1 LRU cache capacity by tuning option Allow to control the capacity of the cache used to track recently touched chunks via the configured value in the datastore tuning options. Log the configured value to the task log, if an explicit value is set, allowing the user to confirm the setting and debug. Signed-off-by: Christian Ebner Link: https://lore.proxmox.com/pbs-devel/20250404130713.376630-2-c.ebner@proxmox.com --- pbs-datastore/src/datastore.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs index ef534f42..fbd9eddb 100644 --- a/pbs-datastore/src/datastore.rs +++ b/pbs-datastore/src/datastore.rs @@ -1115,6 +1115,7 @@ impl DataStore { &self, status: &mut GarbageCollectionStatus, worker: &dyn WorkerTaskContext, + cache_capacity: usize, ) -> Result<(), Error> { // Iterate twice over the datastore to fetch index files, even if this comes with an // additional runtime cost: @@ -1130,7 +1131,7 @@ impl DataStore { let mut unprocessed_index_list = self.list_index_files()?; let index_count = unprocessed_index_list.len(); - let mut chunk_lru_cache = LruCache::new(1024 * 1024); + let mut chunk_lru_cache = LruCache::new(cache_capacity); let mut processed_index_files = 0; let mut last_percentage: usize = 0; @@ -1274,9 +1275,20 @@ impl DataStore { ); } + let tuning: DatastoreTuning = serde_json::from_value( + DatastoreTuning::API_SCHEMA + .parse_property_string(gc_store_config.tuning.as_deref().unwrap_or(""))?, + )?; + let gc_cache_capacity = if let Some(capacity) = tuning.gc_cache_capacity { + info!("Using chunk digest cache capacity of {capacity}."); + capacity + } else { + 1024 * 1024 + }; + info!("Start GC phase1 (mark used chunks)"); - self.mark_used_chunks(&mut gc_status, worker) + self.mark_used_chunks(&mut gc_status, worker, gc_cache_capacity) .context("marking used chunks failed")?; info!("Start GC phase2 (sweep unused chunks)");