From: Mike Rapoport <rppt@kernel.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Mike Rapoport <mike.rapoport@gmail.com>,
Christoph Lameter <cl@linux.com>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Pekka Enberg <penberg@kernel.org>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, rcu@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev, netdev@vger.kernel.org,
linux-doc@vger.kernel.org, Jonathan Corbet <corbet@lwn.net>,
"Paul E. McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Josh Triplett <josh@joshtriplett.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>
Subject: Re: [PATCH 7/7] mm/slab: document kfree() as allowed for kmem_cache_alloc() objects
Date: Wed, 15 Mar 2023 16:50:34 +0200 [thread overview]
Message-ID: <ZBHbOrk3P3TXSkK8@kernel.org> (raw)
In-Reply-To: <14043bee-af7d-38f3-5a46-f63940e56c1e@suse.cz>
On Wed, Mar 15, 2023 at 02:38:47PM +0100, Vlastimil Babka wrote:
> On 3/12/23 10:59, Mike Rapoport wrote:
> > On Fri, Mar 10, 2023 at 11:32:09AM +0100, Vlastimil Babka wrote:
> >> This will make it easier to free objects in situations when they can
> >> come from either kmalloc() or kmem_cache_alloc(), and also allow
> >> kfree_rcu() for freeing objects from kmem_cache_alloc().
> >>
> >> For the SLAB and SLUB allocators this was always possible so with SLOB
> >> gone, we can document it as supported.
> >>
> >> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> >> Cc: Mike Rapoport <rppt@kernel.org>
> >> Cc: Jonathan Corbet <corbet@lwn.net>
> >> Cc: "Paul E. McKenney" <paulmck@kernel.org>
> >> Cc: Frederic Weisbecker <frederic@kernel.org>
> >> Cc: Neeraj Upadhyay <quic_neeraju@quicinc.com>
> >> Cc: Josh Triplett <josh@joshtriplett.org>
> >> Cc: Steven Rostedt <rostedt@goodmis.org>
> >> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> >> Cc: Lai Jiangshan <jiangshanlai@gmail.com>
> >> Cc: Joel Fernandes <joel@joelfernandes.org>
> >> ---
> >> Documentation/core-api/memory-allocation.rst | 15 +++++++++++----
> >> include/linux/rcupdate.h | 6 ++++--
> >> mm/slab_common.c | 5 +----
> >> 3 files changed, 16 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> >> index 5954ddf6ee13..f9e8d352ed67 100644
> >> --- a/Documentation/core-api/memory-allocation.rst
> >> +++ b/Documentation/core-api/memory-allocation.rst
> >> @@ -170,7 +170,14 @@ should be used if a part of the cache might be copied to the userspace.
> >> After the cache is created kmem_cache_alloc() and its convenience
> >> wrappers can allocate memory from that cache.
> >>
> >> -When the allocated memory is no longer needed it must be freed. You can
> >> -use kvfree() for the memory allocated with `kmalloc`, `vmalloc` and
> >> -`kvmalloc`. The slab caches should be freed with kmem_cache_free(). And
> >> -don't forget to destroy the cache with kmem_cache_destroy().
> >> +When the allocated memory is no longer needed it must be freed. Objects
> >
> > I'd add a line break before Objects ^
> >
> >> +allocated by `kmalloc` can be freed by `kfree` or `kvfree`.
> >> +Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`
> >> +or also by `kfree` or `kvfree`, which can be more convenient as it does
> >
> > Maybe replace 'or also by' with a coma:
> >
> > Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`,
> > `kfree` or `kvfree`, which can be more convenient as it does
>
> But then I need to clarify what the "which" applies to?
Yeah, I kinda missed that...
> >
> >> +not require the kmem_cache pointed.
> >
> > ^ pointer.
> >
> >> +The rules for _bulk and _rcu flavors of freeing functions are analogical.
> >
> > Maybe
> >
> > The same rules apply to _bulk and _rcu flavors of freeing functions.
>
> So like this incremental diff?
> diff --git a/Documentation/core-api/memory-allocation.rst b/Documentation/core-api/memory-allocation.rst
> index f9e8d352ed67..1c58d883b273 100644
> --- a/Documentation/core-api/memory-allocation.rst
> +++ b/Documentation/core-api/memory-allocation.rst
> @@ -170,12 +170,14 @@ should be used if a part of the cache might be copied to the userspace.
> After the cache is created kmem_cache_alloc() and its convenience
> wrappers can allocate memory from that cache.
>
> -When the allocated memory is no longer needed it must be freed. Objects
> -allocated by `kmalloc` can be freed by `kfree` or `kvfree`.
> -Objects allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`
> -or also by `kfree` or `kvfree`, which can be more convenient as it does
> -not require the kmem_cache pointed.
> -The rules for _bulk and _rcu flavors of freeing functions are analogical.
> +When the allocated memory is no longer needed it must be freed.
> +
> +Objects allocated by `kmalloc` can be freed by `kfree` or `kvfree`. Objects
> +allocated by `kmem_cache_alloc` can be freed with `kmem_cache_free`, `kfree`
> +or `kvfree`, where the latter two might be more convenient thanks to not
> +needing the kmem_cache pointer.
... but this way it's more explicit that kfree and kvfree don't need
kmem_cache pointer.
> +
> +The same rules apply to _bulk and _rcu flavors of freeing functions.
>
> Memory allocated by `vmalloc` can be freed with `vfree` or `kvfree`.
> Memory allocated by `kvmalloc` can be freed with `kvfree`.
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2023-03-15 14:51 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 10:32 [PATCH 0/7] remove SLOB and allow kfree() with kmem_cache_alloc() Vlastimil Babka
2023-03-10 10:32 ` [PATCH 1/7] mm/slob: remove CONFIG_SLOB Vlastimil Babka
2023-03-14 7:18 ` Hyeonggon Yoo
2023-03-14 22:11 ` Lorenzo Stoakes
2023-03-10 10:32 ` [PATCH 2/7] net: skbuff: remove SLOB-specific ifdefs Vlastimil Babka
2023-03-10 10:32 ` [PATCH 3/7] mm, page_flags: remove PG_slob_free Vlastimil Babka
2023-03-14 7:25 ` Hyeonggon Yoo
2023-03-14 22:12 ` Lorenzo Stoakes
2023-03-10 10:32 ` [PATCH 4/7] mm, pagemap: remove SLOB and SLQB from comments and documentation Vlastimil Babka
2023-03-14 8:19 ` Hyeonggon Yoo
2023-03-15 11:05 ` Vlastimil Babka
2023-03-14 22:16 ` Lorenzo Stoakes
2023-03-10 10:32 ` [PATCH 5/7] mm/slab: remove CONFIG_SLOB code from slab common code Vlastimil Babka
2023-03-14 9:28 ` Hyeonggon Yoo
2023-03-14 22:16 ` Lorenzo Stoakes
2023-03-10 10:32 ` [PATCH 6/7] mm/slob: remove slob.c Vlastimil Babka
2023-03-14 9:34 ` Hyeonggon Yoo
2023-03-14 22:18 ` Lorenzo Stoakes
2023-03-15 2:54 ` Roman Gushchin
2023-03-10 10:32 ` [PATCH 7/7] mm/slab: document kfree() as allowed for kmem_cache_alloc() objects Vlastimil Babka
2023-03-12 9:59 ` Mike Rapoport
2023-03-15 13:38 ` Vlastimil Babka
2023-03-15 14:50 ` Mike Rapoport [this message]
2023-03-11 1:00 ` [PATCH 0/7] remove SLOB and allow kfree() with kmem_cache_alloc() Jakub Kicinski
2023-03-12 9:51 ` Mike Rapoport
2023-03-13 16:31 ` Steven Rostedt
2023-03-13 18:00 ` Mike Rapoport
2023-03-15 13:53 ` Vlastimil Babka
2023-03-15 14:20 ` Steven Rostedt
2023-03-15 14:22 ` Vlastimil Babka
2023-03-13 16:36 ` Vlastimil Babka
2023-03-14 22:10 ` Lorenzo Stoakes
2023-03-15 13:40 ` Vlastimil Babka
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=ZBHbOrk3P3TXSkK8@kernel.org \
--to=rppt@kernel.org \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=corbet@lwn.net \
--cc=frederic@kernel.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mike.rapoport@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=paulmck@kernel.org \
--cc=penberg@kernel.org \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=vbabka@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).