Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/mmu_gather: replace IPI with synchronize_rcu() when batch allocation fails

When freeing page tables, we try to batch them. If batch allocation fails
(GFP_NOWAIT), __tlb_remove_table_one() immediately frees the one without
batching.

On !CONFIG_PT_RECLAIM, the fallback sends an IPI to all CPUs via
tlb_remove_table_sync_one(). It disrupts all CPUs even when only a single
process is unmapping memory. IPI broadcast was reported to hurt RT
workloads[1].

tlb_remove_table_sync_one() synchronizes with lockless page-table walkers
(e.g. GUP-fast) that rely on IRQ disabling. These walkers use
local_irq_disable(), which is also an RCU read-side critical section.

This patch introduces tlb_remove_table_sync_rcu() which uses RCU grace
period (synchronize_rcu()) instead of IPI broadcast. This provides the
same guarantee as IPI but without disrupting all CPUs. Since batch
allocation already failed, we are in a slow path where sleeping is
acceptable - we are in process context (unmap_region, exit_mmap) with only
mmap_lock held.

tlb_remove_table_sync_one() is retained for other callers (e.g.,
khugepaged after pmdp_collapse_flush(), tlb_finish_mmu() when
tlb->fully_unshared_tables) that are not slow paths. Converting those may
require different approaches such as targeted IPIs.

Link: https://lore.kernel.org/linux-mm/1b27a3fa-359a-43d0-bdeb-c31341749367@kernel.org/ [1]
Link: https://lore.kernel.org/linux-mm/20260202150957.GD1282955@noisy.programming.kicks-ass.net/
Link: https://lore.kernel.org/linux-mm/dfdfeac9-5cd5-46fc-a5c1-9ccf9bd3502a@intel.com/
Link: https://lore.kernel.org/linux-mm/bc489455-bb18-44dc-8518-ae75abda6bec@kernel.org/
Link: https://lkml.kernel.org/r/20260224142101.20500-1-lance.yang@linux.dev
Signed-off-by: Lance Yang <lance.yang@linux.dev>
Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Suggested-by: Dave Hansen <dave.hansen@intel.com>
Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Nick Piggin <npiggin@gmail.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lance Yang and committed by
Andrew Morton
1fb3d8c2 77a9c445

+24 -1
+4
include/asm-generic/tlb.h
··· 251 251 252 252 void tlb_remove_table_sync_one(void); 253 253 254 + void tlb_remove_table_sync_rcu(void); 255 + 254 256 #else 255 257 256 258 #ifdef tlb_needs_table_invalidate ··· 260 258 #endif 261 259 262 260 static inline void tlb_remove_table_sync_one(void) { } 261 + 262 + static inline void tlb_remove_table_sync_rcu(void) { } 263 263 264 264 #endif /* CONFIG_MMU_GATHER_RCU_TABLE_FREE */ 265 265
+20 -1
mm/mmu_gather.c
··· 296 296 call_rcu(&batch->rcu, tlb_remove_table_rcu); 297 297 } 298 298 299 + /** 300 + * tlb_remove_table_sync_rcu - synchronize with software page-table walkers 301 + * 302 + * Like tlb_remove_table_sync_one() but uses RCU grace period instead of IPI 303 + * broadcast. Use in slow paths where sleeping is acceptable. 304 + * 305 + * Software/Lockless page-table walkers use local_irq_disable(), which is also 306 + * an RCU read-side critical section. synchronize_rcu() waits for all such 307 + * sections, providing the same guarantee as tlb_remove_table_sync_one() but 308 + * without disrupting all CPUs with IPIs. 309 + * 310 + * Do not use for freeing memory. Use RCU callbacks instead to avoid latency 311 + * spikes. 312 + */ 313 + void tlb_remove_table_sync_rcu(void) 314 + { 315 + synchronize_rcu(); 316 + } 317 + 299 318 #else /* !CONFIG_MMU_GATHER_RCU_TABLE_FREE */ 300 319 301 320 static void tlb_remove_table_free(struct mmu_table_batch *batch) ··· 358 339 #else 359 340 static inline void __tlb_remove_table_one(void *table) 360 341 { 361 - tlb_remove_table_sync_one(); 342 + tlb_remove_table_sync_rcu(); 362 343 __tlb_remove_table(table); 363 344 } 364 345 #endif /* CONFIG_PT_RECLAIM */