From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Dominik Csapak <d.csapak@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] applied: [PATCH proxmox-backup] pbs-tools: LruCache: implement Drop
Date: Thu, 20 Jan 2022 11:30:04 +0100 [thread overview]
Message-ID: <20220120103004.va2fqclwvb3gzuju@olga.proxmox.com> (raw)
In-Reply-To: <20220120101608.1062152-1-d.csapak@proxmox.com>
applied, thanks
On Thu, Jan 20, 2022 at 11:16:08AM +0100, Dominik Csapak wrote:
> this fixes the leaked memory for the cache, as we had only pointers
> in the map/list which were freed, not the underlying chunks
>
> moves the 'clear' implementation out of the trait bounds so that
> Drop can reuse it
>
> this is used e.g. for file download from a pxar
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> pbs-tools/src/lru_cache.rs | 24 ++++++++++++++++--------
> 1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/pbs-tools/src/lru_cache.rs b/pbs-tools/src/lru_cache.rs
> index b1c0c6ac..fbd7673a 100644
> --- a/pbs-tools/src/lru_cache.rs
> +++ b/pbs-tools/src/lru_cache.rs
> @@ -100,9 +100,25 @@ pub struct LruCache<K, V> {
> _marker: PhantomData<Box<CacheNode<K, V>>>,
> }
>
> +impl<K, V> Drop for LruCache<K, V> {
> + fn drop (&mut self) {
> + self.clear();
> + }
> +}
> +
> // trivial: if our contents are Send, the whole cache is Send
> unsafe impl<K: Send, V: Send> Send for LruCache<K, V> {}
>
> +impl<K, V> LruCache<K, V> {
> + /// Clear all the entries from the cache.
> + pub fn clear(&mut self) {
> + // This frees only the HashMap with the node pointers.
> + self.map.clear();
> + // This frees the actual nodes and resets the list head and tail.
> + self.list.clear();
> + }
> +}
> +
> impl<K: std::cmp::Eq + std::hash::Hash + Copy, V> LruCache<K, V> {
> /// Create LRU cache instance which holds up to `capacity` nodes at once.
> pub fn new(capacity: usize) -> Self {
> @@ -115,14 +131,6 @@ impl<K: std::cmp::Eq + std::hash::Hash + Copy, V> LruCache<K, V> {
> }
> }
>
> - /// Clear all the entries from the cache.
> - pub fn clear(&mut self) {
> - // This frees only the HashMap with the node pointers.
> - self.map.clear();
> - // This frees the actual nodes and resets the list head and tail.
> - self.list.clear();
> - }
> -
> /// 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) {
> --
> 2.30.2
prev parent reply other threads:[~2022-01-20 10:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 10:16 [pbs-devel] " Dominik Csapak
2022-01-20 10:30 ` Wolfgang Bumiller [this message]
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=20220120103004.va2fqclwvb3gzuju@olga.proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=d.csapak@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.