[PATCH 3/5] x86/mm: Extract the TLB range flush threshold check
From: Chuyi Zhou
Date: Mon Sep 21 2026 - 06:27:17 EST
The decision to replace a range flush with a full flush is embedded in
init_flush_tlb_info(). Both mm and kernel flushes use this policy, but
the kernel path only needs the range and the decision, without the
mm-specific descriptor initialization.
Extract the threshold predicate into tlb_range_exceeds_ceiling()
and use it in init_flush_tlb_info(). Preserve the unsigned range
arithmetic, right-shift rounding and strict greater-than comparison.
Descriptor initialization and both flush paths remain unchanged.
Signed-off-by: Chuyi Zhou <zhouchuyi@xxxxxxxxxxxxx>
---
arch/x86/mm/tlb.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index 5e9d1689f605..f0dfeb271c66 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -1373,6 +1373,12 @@ void flush_tlb_multi(const struct cpumask *cpumask,
*/
unsigned long tlb_single_page_flush_ceiling __read_mostly = 33;
+static bool tlb_range_exceeds_ceiling(unsigned long start, unsigned long end,
+ unsigned int stride_shift)
+{
+ return ((end - start) >> stride_shift) > tlb_single_page_flush_ceiling;
+}
+
static void init_flush_tlb_info(struct flush_tlb_info *info,
struct mm_struct *mm,
unsigned long start, unsigned long end,
@@ -1383,7 +1389,7 @@ static void init_flush_tlb_info(struct flush_tlb_info *info,
* If the number of flushes is so large that a full flush
* would be faster, do a full flush.
*/
- if ((end - start) >> stride_shift > tlb_single_page_flush_ceiling) {
+ if (tlb_range_exceeds_ceiling(start, end, stride_shift)) {
start = 0;
end = TLB_FLUSH_ALL;
}
--
2.20.1