linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Dave Hansen <dave.hansen@intel.com>
Cc: akpm@linux-foundation.org, aneesh.kumar@kernel.org,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, npiggin@gmail.com, peterz@infradead.org,
	will@kernel.org, david@kernel.org
Subject: Re: [PATCH 1/1] mm/mmu_gather: replace IPI with synchronize_rcu() when batch allocation fails
Date: Tue, 24 Feb 2026 00:29:29 +0800	[thread overview]
Message-ID: <1373db93-3977-425f-ad59-5970e7e50b48@linux.dev> (raw)
In-Reply-To: <a0c434c4-ec65-4a37-9422-5614249124bc@intel.com>



On 2026/2/23 23:31, Dave Hansen wrote:
> On 2/23/26 04:58, Lance Yang wrote:
> ...
>> +/**
>> + * tlb_remove_table_sync_rcu() - synchronize with software page-table walkers
>> + *
>> + * Like tlb_remove_table_sync_one() but uses RCU grace period instead of IPI
>> + * broadcast. Should be used in slow paths where sleeping is acceptable.
> 
> Just a nit on comments: Use imperative voice:
> 
> 	... Use in slow paths where sleeping is acceptable.

Okay, thanks.

>> + * Software/Lockless page-table walkers use local_irq_disable(), which is also
>> + * an RCU read-side critical section. synchronize_rcu() waits for all such
>> + * sections, providing the same guarantee as tlb_remove_table_sync_one() but
>> + * without disrupting all CPUs with IPIs.
> 
> Yep, synchronize_rcu() is likely slower (longer wall clock time) but
> less disruptive to other CPUs.
> 
> Is it worth explaining here that this should be used when code really
> needs to _wait_ and *not* for freeing memory? Freeing memory should use
> RCU callbacks that don't cause latency spikes in this thread, not this.

Good point! Worth clarifying. Something like:

Note: Use this when code really needs to wait for synchronization,
*not* for freeing memory. Memory freeing should use RCU callbacks
that don't cause latency spikes in this thread.

>> + * Context: Can sleep/block. Cannot be called from any atomic context.
> 
> As a general rule, expressing constraints like this is best done in
> code, not comments, so:
> 
> 	might_sleep();
> or
> 	WARN_ON_ONCE(!in_atomic());
> 
> seem appropriate.
> 
> I didn't see any obvious warning like that in the top levels of
> synchronize_rcu().

Yep, synchronize_rcu() does call might_sleep() internally:

synchronize_rcu()
   -> synchronize_rcu_normal()
     -> wait_rcu_gp()      -> __wait_rcu_gp()
         -> might_sleep()
But adding an explicit might_sleep() here makes the constraint
more obvious. I'll add it :)

>> +static void tlb_remove_table_sync_rcu(void)
>> +{
>> +	synchronize_rcu();
>> +}
>> +
>>   #else /* !CONFIG_MMU_GATHER_RCU_TABLE_FREE */
>>
>>   static void tlb_remove_table_free(struct mmu_table_batch *batch)
>> @@ -303,6 +321,10 @@ static void tlb_remove_table_free(struct mmu_table_batch *batch)
>>   	__tlb_remove_table_free(batch);
>>   }
>>
>> +static void tlb_remove_table_sync_rcu(void)
>> +{
>> +}
>> +
>>   #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */
> This seems a _little_ dangerous to even define. We don't want this
> sneaking into use when it doesn't do anything.

This follows the same pattern as tlb_remove_table_sync_one(), which
also has an empty stub in the !CONFIG_MMU_GATHER_RCU_TABLE_FREE path.

It should be in tlb.h like tlb_remove_table_sync_one(). Will put
it there.


Thanks,
Lance


  reply	other threads:[~2026-02-23 16:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-23  3:36 Lance Yang
2026-02-23  9:29 ` David Hildenbrand (Arm)
2026-02-23 12:58   ` Lance Yang
2026-02-23 13:02     ` David Hildenbrand (Arm)
2026-02-23 15:31     ` Dave Hansen
2026-02-23 16:29       ` Lance Yang [this message]
2026-02-23 16:35         ` Dave Hansen

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=1373db93-3977-425f-ad59-5970e7e50b48@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=dave.hansen@intel.com \
    --cc=david@kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox