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 220CBC61DA4 for ; Wed, 15 Mar 2023 13:38:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97EF46B0075; Wed, 15 Mar 2023 09:38:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92F8F6B0078; Wed, 15 Mar 2023 09:38:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F6F46B007B; Wed, 15 Mar 2023 09:38:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6F6B96B0075 for ; Wed, 15 Mar 2023 09:38:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1A4FBAAF03 for ; Wed, 15 Mar 2023 13:38:53 +0000 (UTC) X-FDA: 80571238146.10.4CEF96F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf18.hostedemail.com (Postfix) with ESMTP id 0F7821C0020 for ; Wed, 15 Mar 2023 13:38:49 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cqxP2two; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="w6coZ/Uw"; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678887530; a=rsa-sha256; cv=none; b=a1dFmYOt3ZuQsBrcBUO3LOvXa0mYNRgULDJWxw2MDzz25MyhHtbXTAGK6kfUkDev+vnh0n orsvWYAPbLp94jb9p3+AhbU56a/BtPcVihHJdYCo1wuT+1QJA+2VeREByNtIwHHKcqjIOn tP6ryCR6sA6pCLcT4t07fQLCDInXCBI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=cqxP2two; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="w6coZ/Uw"; spf=pass (imf18.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678887530; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wQFuKBaF6WvGk6vzttY4i4tA7syyP5hs6IrhdtonffA=; b=m0p8vrxaR1kllI0D0V+3OXmnwtThl2VSXKFVyXcYsSN47Ym1W2iqnvke+/7aad9nBWzsEG v8h31jex4S1RoZHeGiKUmWBJ0Zhq5YkJAclMOKVbWOKMbQaWir+tT0p16gDNtPYVp+hjgw HPrE297wQHeWcen3C5xqBl1la0xfLME= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 5D8B31FD76; Wed, 15 Mar 2023 13:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1678887528; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQFuKBaF6WvGk6vzttY4i4tA7syyP5hs6IrhdtonffA=; b=cqxP2twoRj+fcrs/+8lehtiDgnL4jr0LNZ6a5rdur0lBr0tEWrBncWCbZJ6/bK8EyWpU4x gZ0F+4c+4+XXRkr56WDNiSySqXnP6VfvK3ui99h+DhlZDvTySsKKDiEo77yQOun5YA6Xyt sgYbKyd2dOq4T+lsVt4cYW7F2JRPFGk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1678887528; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wQFuKBaF6WvGk6vzttY4i4tA7syyP5hs6IrhdtonffA=; b=w6coZ/Uw88fhU8aHcGl6eDCI1gHVg0UOGUkVaXsHulRwjbstUIgG9UCupGjq6fQNmDKLo6 x/lC0q/mxOCeVZCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0211513A2F; Wed, 15 Mar 2023 13:38:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id e+dPO2fKEWQSLwAAMHmgww (envelope-from ); Wed, 15 Mar 2023 13:38:47 +0000 Message-ID: <14043bee-af7d-38f3-5a46-f63940e56c1e@suse.cz> Date: Wed, 15 Mar 2023 14:38:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH 7/7] mm/slab: document kfree() as allowed for kmem_cache_alloc() objects Content-Language: en-US To: Mike Rapoport Cc: 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, Mike Rapoport , Jonathan Corbet , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes References: <20230310103210.22372-1-vbabka@suse.cz> <20230310103210.22372-8-vbabka@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 0F7821C0020 X-Rspamd-Server: rspam01 X-Stat-Signature: s1ie5bo13hrxmwcqzmy1w9qrzqyo4csf X-HE-Tag: 1678887529-409896 X-HE-Meta: U2FsdGVkX1+WXTfeQTGxv7fS1Qy3E5Q2U2d998yVMfef/VGiKfPAeMvOAb2K7aakPLwB+E0Np9k1/dYgziSvGLlQQ+Io8w28f7yA1RcI0mhWp99vfgGv1NEMW22ZUwtsMkgsehU/bmEeY6VOa1z7wFBARkmZ3q2/rc0NAE78FjA4IU2E5FMbBLsfs9bh5KIUV6rCf5/aSnnSnKD1tzBiVlw79hn0uqazmsGEwXHpDUuv2E2RSR8UDkk+qUdayVKzQ5fHIJUn38ydDGhl1SSEHfyjYKnCZVJaUsL9TWLNIj9c9KkvLBrFAqAkq2aP/Cp8d9JFOwX1tWeFifSYXWWgDwmuJQB2qugKmWWUkmY+AlHfbS44mglcJ2xBuiCmEVipidhF9RzQ+odpyPoK+134apxc99GM8uMkCoH/6P/a2obLbYft9Nj9S/TnrWs0sqO6Z1omr+1phk8NNrmEVuO/ETS2/AxvJRxWHt9Ze+mFuOmjdZCQdIWQYd2eHEhLKVrQrU62GSVfEYfP1BwnDtWOyXJQsEVlm7qoAMzECQvLXhOkjS1TR403nl/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UBNlO9/L6mKSA5tPVso/0HdQdD4Kdne86/6+XNQfVHmczGHpVbC2Zvpy2fsDzXTosolizuY5S6bmOnwM9+t9QuGsbRTRRo= 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 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? > >> +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. + +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`.