From: Uladzislau Rezki <urezki@gmail.com>
To: "Linus Lüssing" <linus.luessing@c0d3.blue>,
"Vlastimil Babka" <vbabka@suse.cz>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
b.a.t.m.a.n@lists.open-mesh.org,
Dmitry Antipov <dmantipov@yandex.ru>,
netdev@vger.kernel.org, rcu@vger.kernel.org,
Matthew Wilcox <willy@infradead.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH] Revert "batman-adv: prefer kfree_rcu() over call_rcu() with free-only callbacks"
Date: Wed, 12 Jun 2024 18:25:06 +0200 [thread overview]
Message-ID: <ZmnL4jkhJLIW924W@pc636> (raw)
In-Reply-To: <ZmmzE6Przj0pCHek@sellars>
+ Vlastimil Babka
+ Matthew Wilcox
> On Wed, Jun 12, 2024 at 07:06:04AM -0700, Paul E. McKenney wrote:
> > Let me make sure that I understand...
> >
> > You need rcu_barrier() to wait for any memory passed to kfree_rcu()
> > to actually be freed? If so, please explain why you need this, as
> > in what bad thing happens if the actual kfree() happens later.
> >
> > (I could imagine something involving OOM avoidance, but I need to
> > hear your code's needs rather than my imaginations.)
> >
> > Thanx, Paul
>
> We have allocated a kmem-cache for some objects, which are like
> batman-adv's version of a bridge's FDB entry.
>
> The very last thing we do before unloading the module is
> free'ing/destroying this kmem-cache with a call to
> kmem_cache_destroy().
>
> As far as I understand before calling kmem_cache_destroy()
> we need to ensure that all previously allocated objects on this
> kmem-cache were free'd. At least we get this kernel splat
> (from Slub?) otherwise. I'm not quite sure if any other bad things
> other than this noise in dmesg would occur though. Other than a
> stale, zero objects entry remaining in /proc/slabinfo maybe. Which
> gets duplicated everytime we repeat loading+unloading the module.
> At least these entries would be a memory leak I suppose?
>
> ```
> # after insmod/rmmod'ing batman-adv 6 times:
> $ cat /proc/slabinfo | grep batadv_tl_cache
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> batadv_tl_cache 0 16 256 16 1 : tunables 0 0 0 : slabdata 1 1 0
> ```
>
> That's why we added this rcu_barrier() call on module
> shutdown in the batman-adv module __exit function right before the
> kmem_cache_destroy() calls. Hoping that this would wait for all
> call_rcu() / kfree_rcu() callbacks and their final kfree() to finish.
> This worked when we were using call_rcu() with our own callback
> with a kfree(). However for kfree_rcu() this somehow does not seem
> to be the case anymore (- or more likely I'm missing something else,
> some other bug within the batman-adv code?).
>
Some background:
Before kfree_rcu() could deal only with "internal system slab caches" which
are static and live forever. After removing SLAB allocator it become possible
to free a memory over RCU using kfree_rcu() without specifying a kmem-cache
an object belongs to because two remaining allocators are capable of convert
an object to its cache internally.
So, now, kfree_rcu() does not need to be aware of any cache and this is
something new.
In your scenario the cache is destroyed and after that kfree_rcu()
started to free objects into non-existing cache which is a problem.
I have a question to Vlastimil. Is kmem_cached_destroy() removes the
cache right away even though there are allocated objects which have
not yet been freed? If so, is that possible to destroy the cache only
when usage counter becomes zero? i.e. when all objects were returned
back to the cache.
Thank you!
--
Uladzislau Rezki
parent reply other threads:[~2024-06-12 16:25 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <ZmmzE6Przj0pCHek@sellars>]
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=ZmnL4jkhJLIW924W@pc636 \
--to=urezki@gmail.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=dmantipov@yandex.ru \
--cc=linus.luessing@c0d3.blue \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox