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 0437BC6FD1C for ; Sun, 12 Mar 2023 09:59:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A8DE8E0003; Sun, 12 Mar 2023 05:59:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 759068E0001; Sun, 12 Mar 2023 05:59:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F96A8E0003; Sun, 12 Mar 2023 05:59:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4F42C8E0001 for ; Sun, 12 Mar 2023 05:59:24 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 20A2612028D for ; Sun, 12 Mar 2023 09:59:24 +0000 (UTC) X-FDA: 80559798648.05.20F18CD Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf10.hostedemail.com (Postfix) with ESMTP id 300EFC0012 for ; Sun, 12 Mar 2023 09:59:20 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mQjD7qOx; spf=pass (imf10.hostedemail.com: domain of mike.rapoport@gmail.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=mike.rapoport@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678615161; 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=F/eUf+U6VJsU72zpkAHAR/G+9W+06JthKevGiP5LF44=; b=iwUKtDEO+ZQHehS4aWCMvZJdYPzN5M77fdIY/VpZXiG3pW6LdJmg5hU2+IPKMEkgOOLDCP XhoHamXaX/8C9mfqZAoDgIhPF5B/vSJJXxra2KSScQC3jVwKNg9OhwpHeLwXAQbJqekQAX zvcsBh3t5pKj3+HsrKzpWKy0p/UX7AI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mQjD7qOx; spf=pass (imf10.hostedemail.com: domain of mike.rapoport@gmail.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=mike.rapoport@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678615161; a=rsa-sha256; cv=none; b=KAfk9YOKZA/EzxM/J4vpWFghvj9lco6G46+s99+EU4VKbluvC5zjbpxCbqGjyWl+Lm1Iuv k3i9edXjY7v30Abwynu9tXGsBpeLY2HiYjyreSAo/kwow+/9PZ/ucjYzrIim8EAzUP0ZEc PQWi5H9uTldkjMnKAym0L/VupWCQZ8U= Received: by mail-wr1-f41.google.com with SMTP id h14so8778402wru.4 for ; Sun, 12 Mar 2023 01:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678615160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=F/eUf+U6VJsU72zpkAHAR/G+9W+06JthKevGiP5LF44=; b=mQjD7qOx7ex1pHGWyQeUg0YqTmCHy1WTTDhdvfcblgD/O1BEmOllQOhb+WykNhIjZJ 8fABaAKSlHCX8WjL7ecmWEiu0afJm49LiQgrU5P3uvtEvjGEpPvoO7j8dghtH9yB888L HCvBJoyz+jBZK/OH4h0rkBdLpQgxskFHjLxJKzZvU/LYcoYJYRGamZUo6R8rp+kaw/P5 9Sr9zUgOhCFMx8UDPSwTM1pnHDgf60/Et0uMd8VCzatob3+VhJvJcfqal/9xtFZQM0C+ ptVF/C9NDptX9W5XaKpi5Qjssag5XtJADn60tuPiS9xen4hjcQy9fJnpldX5GgdwflXP 3vAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678615160; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=F/eUf+U6VJsU72zpkAHAR/G+9W+06JthKevGiP5LF44=; b=K4ru00tMKH1zh1ULKrlsa8qk6S5P6tiGGxudthqFT8/OtKhCu+eNtg5szhwvcmmngb YsIj3His8Uj4TyY5rPIeUKFY5Edvwwu1UEVMNGSnGmu6PNSDyyLZXMXuWNTpSoeDGHrH FMstHvO8mQdivgD+sDuAHiQXGmjNvIh96griilJ1kEVUhcdlkvFM5x/8PSQvRYPX7qFO wsaqN3Im2C0TgZXSkJ1CAM25bESCS/i4RZrB7G4iKwbGfPSXtrad0rTw+wiUwZry53GQ ZO7wZ6s9Uk42FJCgC9ejcFDl+y386wC/zVi8b0FBxUoKfBmmSnHh+KJmqd+rTe01X26i SV5w== X-Gm-Message-State: AO0yUKWPR75dnRRGxOwv5yh9RRPyXGr35CnTRRSLVJKcHd+ra/hpxCkU DWLLrbvIqwT3iYe/Sre6cik= X-Google-Smtp-Source: AK7set8l8/lXKE5CTcpAn0qTvK8Gp5PAdyHglSBceQJL8ZQLKfrUOQl3w3Kww9Ks9mqp+kEuNQe/1Q== X-Received: by 2002:a05:6000:181:b0:2ce:aa2e:b864 with SMTP id p1-20020a056000018100b002ceaa2eb864mr1211615wrx.27.1678615159553; Sun, 12 Mar 2023 01:59:19 -0800 (PST) Received: from kernel.org ([46.120.23.99]) by smtp.gmail.com with ESMTPSA id z10-20020a5d654a000000b002ceaa0e6aa5sm1753461wrv.73.2023.03.12.01.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Mar 2023 01:59:19 -0800 (PST) Date: Sun, 12 Mar 2023 11:59:15 +0200 From: Mike Rapoport To: Vlastimil Babka 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 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230310103210.22372-8-vbabka@suse.cz> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 300EFC0012 X-Stat-Signature: 5hzmz78shsrq8im7bsg4xapr4pqqh7kj X-Rspam-User: X-HE-Tag: 1678615160-613074 X-HE-Meta: U2FsdGVkX1/8XtKsoOTuXOUHS4er1JpQU+NFYTImtq8DlwJhJlKWtask0OujWdpOcvKyz8v3qk7rVgph84fwEoyyZ+1QF+yT063bSO3T0jqopWlQuuImUVthIGDoSTXgJHZsQX8JHRRHBWaBmz27zujDHB8yxL+dkweugnBVrXDtFaI5Mu4TCYpXb/2RCx+FJL0qheIw9iMza1lqHSnvMREtWKISAAfa7V+qKs69bXIhnTkBjx5RN8QYbElpTIW0didexGzXLVi4CjLu40oYtRJ9KseBm2Ci/2f1QPrl2tMZR3hYU7YDGNVNUmoGD/otTpIziZyXvjGFbpu02j6TqTzEhawR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tbXQCD91TunTAsIjjawrcxxKzZc+7fL1mPA/gnTulLGHfwmA4DUNJ0LHExs7Bg1ZgaJuH+40AFsGOhpW3OvTSnF9vq74jva7UHtIgwn19EmUI0H3YyG9kMPasbpyN1Twn0tMT8qg/mP4v8OnC/NZqlEOLy/DUceeoqjYsMwtj5x9qcFbTL57Kj4CqWT5eTvSNp7YYE67kQVOetU1PkHyv+X5QqVw7WqttqRXT7wQ7RcEEJqK/oS9+5Ksu+IqRt5qPTNdXvdw9HYu/2U6ExQE1PO4lBCyXR7lpql084IVtRqI5gQyezdUH/g7lSvVRsj+AMeI437YnlahuRwdU68LbZSlg/OtM8shpUZ4eYIn4MS4X8S8Oku/a4EXrhr/wU1aSl1Kgx3HNAr62kG5QruBXNvp37D4tmlUqTm5Z+0zzllJhV8sd1cUv+pnlXh23o9b7SlSU5BjQCo5yVLoxQuJvTX06BX6lH1ZpkdJtbrHqNxuQJoBKwS6V6UTqJ7QEjMmC2uh1oyzR3xzmhB1IozQLseMuSK0tFpw8ypN3AWOM+eaPHJMABpjOL5ymoa ljYpmeIP qArBrJ4AFxACQg2XBKIbcQ== 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 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 > +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. > + > +Memory allocated by `vmalloc` can be freed with `vfree` or `kvfree`. > +Memory allocated by `kvmalloc` can be freed with `kvfree`. > +Caches created by `kmem_cache_create` should be freed with > +`kmem_cache_destroy` only after freeing all the allocated objects first. > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index 094321c17e48..dcd2cf1e8326 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -976,8 +976,10 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) > * either fall back to use of call_rcu() or rearrange the structure to > * position the rcu_head structure into the first 4096 bytes. > * > - * Note that the allowable offset might decrease in the future, for example, > - * to allow something like kmem_cache_free_rcu(). > + * The object to be freed can be allocated either by kmalloc() or > + * kmem_cache_alloc(). > + * > + * Note that the allowable offset might decrease in the future. > * > * The BUILD_BUG_ON check must not involve any function calls, hence the > * checks are done in macros here. > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 1522693295f5..607249785c07 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -989,12 +989,9 @@ EXPORT_SYMBOL(__kmalloc_node_track_caller); > > /** > * kfree - free previously allocated memory > - * @object: pointer returned by kmalloc. > + * @object: pointer returned by kmalloc() or kmem_cache_alloc() > * > * If @object is NULL, no operation is performed. > - * > - * Don't free memory not originally allocated by kmalloc() > - * or you will run into trouble. > */ > void kfree(const void *object) > { > -- > 2.39.2 > -- Sincerely yours, Mike.