From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 1/2] tools: lru cache: allow to dynamically increase the cache capacity
Date: Fri, 1 Aug 2025 16:10:23 +0200 [thread overview]
Message-ID: <20250801141024.626365-2-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250801141024.626365-1-c.ebner@proxmox.com>
Currently, the capacity of the LRU cache is set at instantiation, not
allowing to change it afterwards. In some situations, e.g. when more
space/memory is available, dynamically increasing it is required.
Therefore, add the methods which allow to increase the capacity by a
given increment, for the lru cache, async lru cache and the local
datastore lru caches, respectively.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
pbs-datastore/src/local_datastore_lru_cache.rs | 7 +++++++
pbs-tools/src/async_lru_cache.rs | 8 ++++++++
pbs-tools/src/lru_cache.rs | 6 ++++++
3 files changed, 21 insertions(+)
diff --git a/pbs-datastore/src/local_datastore_lru_cache.rs b/pbs-datastore/src/local_datastore_lru_cache.rs
index c0edd3619..00cce94d6 100644
--- a/pbs-datastore/src/local_datastore_lru_cache.rs
+++ b/pbs-datastore/src/local_datastore_lru_cache.rs
@@ -177,4 +177,11 @@ impl LocalDatastoreLruCache {
pub fn contains(&self, digest: &[u8; 32]) -> bool {
self.cache.contains(*digest)
}
+
+ /// Increases the capacity of the cache by given increment.
+ ///
+ /// Returns the new cache capacity.
+ pub fn increase_capacity(&self, increment: usize) -> usize {
+ self.cache.increase_capacity(increment)
+ }
}
diff --git a/pbs-tools/src/async_lru_cache.rs b/pbs-tools/src/async_lru_cache.rs
index 3a975de32..dbfa1e21d 100644
--- a/pbs-tools/src/async_lru_cache.rs
+++ b/pbs-tools/src/async_lru_cache.rs
@@ -39,6 +39,14 @@ impl<K: std::cmp::Eq + std::hash::Hash + Copy, V: Clone + Send + 'static> AsyncL
}
}
+ /// Increment the LRU cache capacity by given increment, saturating at MAX value for usize
+ ///
+ /// Returns the new capacity.
+ pub fn increase_capacity(&self, increment: usize) -> usize {
+ let mut maps = self.maps.lock().unwrap();
+ maps.0.increase_capacity(increment)
+ }
+
/// Access an item either via the cache or by calling cacher.fetch. A return value of Ok(None)
/// means the item requested has no representation, Err(_) means a call to fetch() failed,
/// regardless of whether it was initiated by this call or a previous one.
diff --git a/pbs-tools/src/lru_cache.rs b/pbs-tools/src/lru_cache.rs
index a7aea6528..d12d0675e 100644
--- a/pbs-tools/src/lru_cache.rs
+++ b/pbs-tools/src/lru_cache.rs
@@ -133,6 +133,12 @@ impl<K: std::cmp::Eq + std::hash::Hash + Copy, V> LruCache<K, V> {
}
}
+ /// Increments the cache capacity by given `increment`, saturating at MAX value for usize
+ pub fn increase_capacity(&mut self, increment: usize) -> usize {
+ self.capacity = self.capacity.saturating_add(increment);
+ self.capacity
+ }
+
/// Insert or update an entry identified by `key` with the given `value`.
/// This entry is placed as the most recently used node at the head.
pub fn insert<F>(&mut self, key: K, value: V, removed: F) -> Result<bool, anyhow::Error>
--
2.47.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-08-01 14:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 14:10 [pbs-devel] [PATCH proxmox-backup 0/2] rewarm local datastore chunk cache on datastore instantiation Christian Ebner
2025-08-01 14:10 ` Christian Ebner [this message]
2025-08-01 14:10 ` [pbs-devel] [PATCH proxmox-backup 2/2] datastore: reinsert unused chunks into cache during instantiation Christian Ebner
2025-08-04 20:42 ` Thomas Lamprecht
2025-08-05 6:15 ` Christian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250801141024.626365-2-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.