From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C043C7618B for ; Wed, 15 Mar 2023 14:50:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BACF6B0072; Wed, 15 Mar 2023 10:50:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 044106B0074; Wed, 15 Mar 2023 10:50:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E268D6B0075; Wed, 15 Mar 2023 10:50:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CD96C6B0072 for ; Wed, 15 Mar 2023 10:50:57 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A0DE5AB575 for ; Wed, 15 Mar 2023 14:50:57 +0000 (UTC) X-FDA: 80571419754.19.EF077E8 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id EAFC1100016 for ; Wed, 15 Mar 2023 14:50:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="ni/Hy4a5"; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678891855; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CQdxGcPGibAt2qCmFC7DY2IpP822WbXrvBkP+TIBVfQ=; b=V7ncS38fKJwvropQgMk+8tVQ3WH88ic0QrGVUlhALOuOkPpE05haFffL1rfWtt1dS6RaPK 8Vo/6GJtYMHLGz8JDGTGaC0cmZYqOqXtuXVBk+jucLtGcKot1FFiXHDsCzZMatAThpI3aD 4EO2KujkW7fYTO8cXlMkgEoQbgTJ6ng= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="ni/Hy4a5"; spf=pass (imf05.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678891855; a=rsa-sha256; cv=none; b=MxRQhb2PmlHkvssuXEYjuoXvXoZH6jpRnoL79InkENoGq75Q5XUkFj4B0ngIhAMkSsoBFb ToptrwXeDJ9NhFKvuAL4HRx3HuJBeNCLJ1G7626ndAKlclQ0+7wp/vQgnJNK4uIaBOsZ4D AW/9Gwimm/jOqH9Bz4JMGnoO3mD59jI= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C6FB261DA5; Wed, 15 Mar 2023 14:50:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C04E0C433D2; Wed, 15 Mar 2023 14:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678891853; bh=wu9HXojxuH3AtIIT++MDX+kORwbWO7Y7OZ2upGm0F4g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ni/Hy4a5bJJNljjXzq8+c+485351OSOzfK6nHpUHJ4HBGlkidr8j4Ww1Q2RuUYgEe lM5RbzfsBlmTzMjurrLTYOKIicKITAeEXSadq2NXDNsMcKwXsyPhg3vCx7v0CyTaak Z1qShw49YNGDF0tf6+ts62FOZRD9PlrCnILgFgnC35g53MgiBu90OrC3zTB/FcmJEK PKsfzxa0MxPOdZDiIZPNF+SDQExt+L394j+lmThmbsIPDvHm+0Tf3KZO/wl52yIt2d qMM0Wh8SIAXaTwmSBaHY3xxbfGMEQcmci4HTUz6ClZ9Ais/uNviMgqBYxzb83kZopJ 6jQsgqvSec0DQ== Date: Wed, 15 Mar 2023 16:50:34 +0200 From: Mike Rapoport To: Vlastimil Babka Cc: Mike Rapoport , Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Roman Gushchin , Andrew Morton , 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 , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes Subject: Re: [PATCH 7/7] mm/slab: document kfree() as allowed for kmem_cache_alloc() objects Message-ID: References: <20230310103210.22372-1-vbabka@suse.cz> <20230310103210.22372-8-vbabka@suse.cz> <14043bee-af7d-38f3-5a46-f63940e56c1e@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14043bee-af7d-38f3-5a46-f63940e56c1e@suse.cz> X-Rspamd-Queue-Id: EAFC1100016 X-Stat-Signature: o13r5unm6zaf1mhnpmbmzo34u8a4m68t X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1678891854-179155 X-HE-Meta: U2FsdGVkX1+nyA9JpJlOHVFJOrXRr+Ez5L+IW4vGcTnfOuq0suXdDe7kAB2HXTPncpvQIXFzLRcStyZV/jup5Bk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/9csUQKKJ4qYBPxQHdDKGmAeJpFirdxLv8GMiW7jwfdCtlCArOIA6i9niFQfBCFuUU/gkd20kYOHob+tT3dq6sQal0UmvZiYvqb5VPaIIr1RfKlgEtP74BZ14ud7K3n30z2LoiKWc4HtmFL05n2f4Jd+9OpZPKceYXZLle2DVMfCf9CgsW8uIU+SYGwYZd6X5GNlvyQNCBiqIlaa+Uom0eJZN5RiaNdaye1ZSVtAD7euD+zg+MYCtJs818JhS/jgzxQgUX47KdOJEzcSh/EYcm5+v7mqKWSq26Eantpu6DK8Fekbv5TgBFhdGMC4U+zMURP8XSsPBVcJ9R8AhsKwwQnATTTBVPMKmUBKZ6oKSQWuMSQj/lpYwryAvABftUTd4P7hQPQbTZ7QOELqt7r7+21SiAiPuafJ3IuubfKtF3mAWjRTkxKEcMbLeUuTZR1HXBmbIdH3Oeh3bvP8muLu8hzqVXYmzpxlwfdB1Ia7wchNRrbP7AeAmqF/uZqCjxMM1tGV7hBCUajWkMBVJj1zlRVRKzq1pJBm9PePwOerPD6du/VGXkpwC2T1hRSz3/dtyhvCImAc7xXPIkYaNRSCHvpJlOI4QUgHk0Yn22rLDDX4gbDlScquI5tdFjbX61JGuAosBE4e14PYv4vBl9mU9sfSKAXT77mob4bHRNASa+Cn/mhGi95/peDx6TtbcSkY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 > >> Cc: Mike Rapoport > >> Cc: Jonathan Corbet > >> Cc: "Paul E. McKenney" > >> Cc: Frederic Weisbecker > >> Cc: Neeraj Upadhyay > >> Cc: Josh Triplett > >> Cc: Steven Rostedt > >> Cc: Mathieu Desnoyers > >> Cc: Lai Jiangshan > >> Cc: Joel Fernandes > >> --- > >> 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.