From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 3D2AF1FF186 for ; Fri, 1 Aug 2025 16:09:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3A12C1B832; Fri, 1 Aug 2025 16:11:14 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Fri, 1 Aug 2025 16:10:23 +0200 Message-ID: <20250801141024.626365-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250801141024.626365-1-c.ebner@proxmox.com> References: <20250801141024.626365-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754057427073 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.043 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 1/2] tools: lru cache: allow to dynamically increase the cache capacity X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" 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 --- 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 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 LruCache { } } + /// 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(&mut self, key: K, value: V, removed: F) -> Result -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel