All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Puranjay Mohan <puranjay@kernel.org>,
	Amery Hung <ameryhung@gmail.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Boqun Feng <boqun@kernel.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>, Pedro Falcato <pfalcato@suse.de>,
	Suren Baghdasaryan <surenb@google.com>,
	Shengming Hu <hu.shengming@zte.com.cn>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-rt-devel@lists.linux.dev, rcu@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH slab/for-next v4 6/8] mm/slab: introduce struct kvfree_rcu_head for kvfree_rcu batching
Date: Wed, 22 Jul 2026 16:42:46 +0900	[thread overview]
Message-ID: <29fb9c96-5685-4974-afe5-c76f48eeba45@kernel.org> (raw)
In-Reply-To: <cd11b015-7c59-4ce4-8eb0-8040fbb2cdfc@kernel.org>


[-- Attachment #1.1: Type: text/plain, Size: 3075 bytes --]



On 7/21/26 8:06 PM, Vlastimil Babka (SUSE) wrote:
> On 7/20/26 14:44, Harry Yoo (Oracle) wrote:
>> rcu_head is overkill for kvfree_rcu() because the callback
>> function is always either kfree(), vfree(), or free_large_kmalloc(),
>> and thus there is no need for a function pointer.
>>
>> kvfree_rcu batching reuses the field to store the start address
>> of an object, however, this is not strictly needed because we can
>> calculate the start address in the slowpath. For the purpose of
>> kvfree_rcu batching, it is sufficient to implement a linked list using
>> a single pointer.
>>
>> Introduce a new struct called kvfree_rcu_head (the name was suggested
>> by Vlastimil Babka), which is similar to rcu_head but is only a single
>> pointer to build a linked list, without a function pointer, when
>> CONFIG_KVFREE_RCU_BATCHED=y.
>>
>> When kvfree_rcu is not batched, kvfree_rcu_head is the same size
>> as rcu_head. Note that shrinking struct kvfree_rcu_head on
>> CONFIG_KVFREE_RCU_BATCHED=n kernels would inevitably require additional
>> complexity and also some sort of batching (which defeats the purpose of
>> the config option) because it cannot fall back to call_rcu().
>>
>> For now there are no user-visible changes to the API. k[v]free_rcu()
>> simply casts rcu_head to kvfree_rcu_head. While this does not affect
>> the API, it allows kfree_rcu_nolock() to reuse kvfree_rcu batching
>> as a fallback when trylock or sheaf allocation fails.
>>
>> Stop storing the object pointer in rcu_head.func and instead calculate
>> the object's start address in kvfree_rcu_list(). Factor out the existing
>> logic to calculate the start address from kvfree_rcu_cb() to
>> kvmalloc_obj_start_addr().
>>
>> Signed-off-by: Harry Yoo (Oracle) <harry@kernel.org>
> 
> Nice.
> 
> Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

Thanks!

> Nit:
> 
>> --- a/mm/slab.h
>> +++ b/mm/slab.h
>> @@ -351,6 +351,33 @@ static inline int objs_per_slab(const struct kmem_cache *cache,
>>  	return slab->objects;
>>  }
>>  
>> +/* kvfree_rcu_head offset can be only less than page size */
>> +static inline void *kvmalloc_obj_start_addr(void *head)
>> +{
>> +	void *obj = head;
>> +
>> +	if (unlikely(is_vmalloc_addr(obj))) {
>> +		obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);
>> +	} else {
>> +		struct page *page = virt_to_page(obj);
>> +		struct slab *slab = page_slab(page);
> 
> Can use virt_to_slab().

Ah, right. We don't call free_large_kmalloc() here.

>> +
>> +		if (!slab) {
>> +			obj = (void *) PAGE_ALIGN_DOWN((unsigned long)obj);
>> +		} else if (is_kfence_address(obj)) {
>> +			obj = kfence_object_start(obj);
>> +		} else {
>> +			struct kmem_cache *s = slab->slab_cache;
>> +			unsigned int idx = __obj_to_index(s, slab_address(slab), obj);
>> +
>> +			obj = slab_address(slab) + s->size * idx;
>> +			obj = fixup_red_left(s, obj);
>> +		}
>> +	}
>> +
>> +	return obj;
>> +}
>> +
>>  /*
>>   * State of the slab allocator.
>>   *

-- 
Cheers,
Harry / Hyeonggon


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-07-22  7:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20 12:44 [PATCH slab/for-next v4 0/8] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Harry Yoo (Oracle)
2026-07-20 12:44 ` [PATCH slab/for-next v4 1/8] mm/slab, slub_kunit: register kprobe to trigger _nolock APIs Harry Yoo (Oracle)
2026-07-20 12:56   ` sashiko-bot
2026-07-22  3:27   ` hu.shengming
2026-07-22  7:16     ` Harry Yoo
2026-07-22  8:32       ` hu.shengming
2026-07-20 12:44 ` [PATCH slab/for-next v4 2/8] mm/slab: handle the !allow_spin case in kfree_rcu_sheaf() Harry Yoo (Oracle)
2026-07-20 13:11   ` sashiko-bot
2026-07-21 10:07   ` Vlastimil Babka (SUSE)
2026-07-22  7:28     ` Harry Yoo
2026-07-22  7:37       ` Vlastimil Babka (SUSE)
2026-07-22  7:39         ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 3/8] mm/slab: use call_rcu() in unknown context if irqs are enabled Harry Yoo (Oracle)
2026-07-20 13:01   ` sashiko-bot
2026-07-20 12:44 ` [PATCH slab/for-next v4 4/8] mm/slab: extend deferred free mechanism to handle rcu sheaves Harry Yoo (Oracle)
2026-07-20 13:03   ` sashiko-bot
2026-07-20 12:44 ` [PATCH slab/for-next v4 5/8] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT Harry Yoo (Oracle)
2026-07-20 12:56   ` sashiko-bot
2026-07-21 10:46   ` Vlastimil Babka (SUSE)
2026-07-22  7:41     ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 6/8] mm/slab: introduce struct kvfree_rcu_head for kvfree_rcu batching Harry Yoo (Oracle)
2026-07-20 13:09   ` sashiko-bot
2026-07-21 11:06   ` Vlastimil Babka (SUSE)
2026-07-22  7:42     ` Harry Yoo [this message]
2026-07-20 12:44 ` [PATCH slab/for-next v4 7/8] mm/slab: introduce kfree_rcu_nolock() Harry Yoo (Oracle)
2026-07-20 13:07   ` sashiko-bot
2026-07-21 13:09   ` Vlastimil Babka (SUSE)
2026-07-22  8:15     ` Harry Yoo
2026-07-22 10:05       ` Vlastimil Babka (SUSE)
2026-07-22 13:03         ` Harry Yoo
2026-07-20 12:44 ` [PATCH slab/for-next v4 8/8] slub_kunit: extend the test for kfree_rcu_nolock() Harry Yoo (Oracle)

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=29fb9c96-5685-4974-afe5-c76f48eeba45@kernel.org \
    --to=harry@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cl@gentwo.org \
    --cc=clrkwllms@kernel.org \
    --cc=frederic@kernel.org \
    --cc=hao.li@linux.dev \
    --cc=hu.shengming@zte.com.cn \
    --cc=jiangshanlai@gmail.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=pfalcato@suse.de \
    --cc=puranjay@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=urezki@gmail.com \
    --cc=vbabka@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.