From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6679D606A322 for ; Fri, 4 Dec 2026 12:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XIO0MzfE Received: by kanga.kvack.org (Postfix) id 82BF86B05BA; Fri, 4 Dec 2026 07:25:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DC9A6B05BC; Fri, 4 Dec 2026 07:25:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CBF36B05BD; Fri, 4 Dec 2026 07:25:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4537B6B05BA for ; Fri, 4 Dec 2026 07:25:46 -0500 (EST) Received: from smtpin23.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CF1D1802D4 for ; Fri, 4 Dec 2026 12:25:45 +0000 (UTC) X-FDA: 85506221850.23.BBADB8B Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf03.hostedemail.com (Postfix) with ESMTP id F202520015 for ; Fri, 4 Dec 2026 12:25:43 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=XIO0MzfE; spf=pass (imf03.hostedemail.com: domain of david@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=david@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796387144; b=Ow9zKoIkThQHP6LCebcuOlj6P6VuMolPEPn/nHcHvXOHMwSi9oJli21MPHGmfBDdRDuQFQ nyEbuCPZISTYS62nMNl8MS7Lm7IL1w8lUAFJcz2SeIZo8XECVwqpkmDlP2eS+CugxsKfRv yXNqcWdM9a8yX93Xq2zerkV2QsoAWCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796387144; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CzUT8MILrMo7SLfsm+r/YP6OIRy5vh3JaSX8ZJr1R9s=; b=mO8lqtQ2j80fK8ta+LTPtohNSwkMcEtyGDhonV7XW8ovZphGqtQXv2a7k3zqnWegzS8KlX I0jJRd1jMWfaVjp1ytcuIqcKBE904A3DxWdhjm13Nx6VoQFju/UG4iR1P2xQb57WuBx3zr P7HhUjApX6cYAUgenbKgQIco/l+CTC0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=XIO0MzfE; spf=pass (imf03.hostedemail.com: domain of david@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=david@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 197A3409EC; Fri, 4 Dec 2026 12:25:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BDE11F00897; Fri, 4 Dec 2026 12:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796387143; bh=CzUT8MILrMo7SLfsm+r/YP6OIRy5vh3JaSX8ZJr1R9s=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=XIO0MzfEHdtzC5Jh7Hwvp42P5xxdtFQzTOsAbCN91NdnqboK5677k4KpfVD/pq3nX F/1RxHkCF3IrWY/MctNWm/gOSNcFOGZkNqbjcXw3GRL8fN752ki31Npi4X34XbhOOk Xd2NQvM05LjSjDDyufPqes4ckV72rxGIgN2XaZYfEBV2He7/O357aFVXQ0B1srgvGC ID8ifDNT9smc7XDUYWPbyvLlVyFNNvh4PZaE7vgO3CerVPJiN8RjsBHyg+zkZ31smd WcvirisG6l6efHTK092HbDYrbAEdkkpvJtY91yeu7zqQOk+fyvpDl4SZWIwwsKnE/a NR/k69a2YBDaw== Message-ID: <786ba304-29b6-43ed-8bcf-aefcbaa001a9@kernel.org> Date: Fri, 4 Dec 2026 13:25:34 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] mm/migrate: don't batch the TLB flush when there is nothing to batch To: Zhiteng Qiu , Andrew Morton Cc: Ying Huang , Zi Yan , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Alistair Popple , Xin Hao , Dave Hansen , Yuan Zhong , Shifei Ge , Jianyong Wu , Shijie Huang , Yibin Liu , Fengyu Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20261203181741.2318590-1-qiuzhiteng@hygon.cn> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsa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TCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <20261203181741.2318590-1-qiuzhiteng@hygon.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: F202520015 X-Stat-Signature: xsqsd6yymm8iimork45mmurqbe9jzgjn X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796387143-298344 X-HE-Meta: U2FsdGVkX19jFsjenSa8s+jFXvwgizzvPBF8U4A5yZ7GO/h9t69k04ySvuthth55C8SujTnlfObMBtztTWJj2ointHTwBHDvEonTJHZv+U5+liWe7NgGmWH3zzDjPx9IjcImIp6fliI3CLXcIRK2O4dj1NH9rQxPYwy33K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RjgebwcaIhfiNXc41gcvXKWOnuDrMtUKTnv2x2oO+s9IFEqv8DMTAHmLUDgP9/1ggLrbuATLi+r0Hs974D3J4Fq7rlHDYkn5w7rgL4Xr2WgVlo2QkWe2oPf62teAcrrtA9t2o6pxIE1+fkRj+j3Z6YJI0+RzwA/J3SFHZ9B4axOcKAd60BewILIG9vAs6u9UA3iEw9ArS/FDf1EKg/8bn9FFGH/z3IvEe+HEoyKq8gR9oUAQCLPvS8Sq3WcAiyhw5Her3ovmxMeMbsBavumdD9dcJZ4NVWn+hJuGJSNzUGhkCBYg9L49mKVSe54R7apoYtHh3Y3YJtwtZubUKs4jrX+FDMOF8Seul+9o4= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 12/3/26 19:17, Zhiteng Qiu wrote: > NUMA balancing migrates one folio at a time, but since commit > 7e12beb8ca2a ("migrate_pages: batch flushing TLB") it still unmaps with > TTU_BATCH_FLUSH like any other MIGRATE_ASYNC migration. When the batch > holds one small folio mapped only once, there is nothing to batch, and > the batched unmap can leave mm->tlb_flush_batched pending, so the NUMA > scanner's next change_pte_range() can call flush_tlb_mm() before > changing the PTE table. With migrations running concurrently, that > state keeps being refilled, and on this workload the scanner often > flushes the whole mm as it walks the PTE tables. > > This slows scanning and keeps mm->tlb_flush_pending raised longer. On > x86, a migration that unmaps a PROT_NONE PTE while mm->tlb_flush_pending > is set gets true from pte_accessible() and needs a flush too. Without > INVLPGB, the resulting arch_tlbbatch_flush() is a full flush. The two > feed each other. In one run, 33% of the migrations overlapped a scan > pass, although passes covered only 9% of the time. > > On a two-socket Hygon 7447V (384 logical CPUs, 12 NUMA nodes), both > kernels used the same v7.4-rc4-based mm-unstable tree and the same two > Hygon die and LLC topology fixes. The benchmark combined pointer > chasing and allocations across 384 threads on a 120 GiB anonymous > working set backed by 4 KiB pages. For each seed, both kernels ran > for 180 seconds with NUMA balancing on and 180 seconds with it off. > > Throughput (million operations/s) TLB IRQs/migrated page > balancing on balancing off balancing on > seed base patched base patched base patched > 1013 17.41 27.88 26.85 26.98 207.5 29.8 > 1019 18.46 29.12 26.60 27.08 199.7 26.1 > 1021 25.57 28.33 27.08 26.85 181.0 29.1 > > With balancing on, throughput increased by 60.1%, 57.7% and 10.8% > across the three seeds. With balancing off, the changes were +0.5%, > +1.8% and -0.8%. The last two columns divide the system-wide increase > in TLB interrupts (summed over CPUs in /proc/interrupts) by the increase > in numa_pages_migrated in /proc/vmstat over the same run. > > Let migrate_pages_batch() choose the unmap flags for asynchronous > migration. If a mapped folio is selected for a batched flush, set > flush_deferred and keep it set across retry passes. This lets the tail > share any flush already queued. Otherwise, when only one small folio > remains and folio_maybe_mapped_shared() is false, omit TTU_BATCH_FLUSH > so try_to_migrate_one() uses ptep_clear_flush(). Large folios keep > their existing behavior. For PMD-mapped THPs, set_pmd_migration_entry() > flushes regardless of TTU_BATCH_FLUSH. > > Link: https://lore.kernel.org/r/20261122171706.9376E1F000C4@smtp.kernel.org > Signed-off-by: Zhiteng Qiu > --- > Changes in v5: > - Incorporated Andrew Morton's fix to v4, following David > Hildenbrand's review. Pass the current list to folio_migrate_ttu_flags() > and explain each batching condition next to its check. > - Rebased on mm-unstable e685fdf67323. migrate_pages_batch() now moves > source folios from the input list to pending_folios as it allocates > destinations. The unmap loop walks new_folios, so check that list > when deciding whether the current folio is the last one. > - Track flush_deferred throughout the batch, including retry passes. > A singular new_folios list says nothing about earlier folios. If a > mapped folio was selected for a batched flush, keep batching the > tail so it can share any flush the earlier unmap queued. Unmapped > folios do not set the flag, so the sole mapped tail of a split THP > can still take the direct path. > - The batching decision changed since v4, so please review it afresh. > > Changes in v4: > - Compute the try_to_migrate() flags in migrate_pages_batch() with a > helper and pass them to migrate_folio_unmap() instead of a bool, as > suggested by David. > - Go back to v2's check, limited to small folios, using > folio_maybe_mapped_shared() as Zi suggested. folio_mapcount() would > stop being a good hint for large folios once try_to_unmap() batches > them better (David). > - Shorter comment (Zi). > > Changes in v3: > - Use folio_mapcount() for the check, as Ying suggested. > - Cut the changelog down. > > Changes in v2: > - Pass the try_to_migrate() flags directly and use single_folio in > the VM_WARN_ON_ONCE(), as suggested by Ying. > - Rewrote the changelog after looking into why b99a342d4f11 does not > avoid the flush here. > > v4: https://lore.kernel.org/r/20261112010357.2739389-1-qiuzhiteng@hygon.cn > v3: https://lore.kernel.org/r/20261109122915.2150586-1-qiuzhiteng@hygon.cn > v2: https://lore.kernel.org/r/20261107143456.1590658-1-qiuzhiteng@hygon.cn > v1: https://lore.kernel.org/r/20261106041628.1177963-1-qiuzhiteng@hygon.cn > > Earlier measurements on v7.3, on x86 without INVLPGB, used the v4 check: > > v7.3 patched > throughput loss from balancing 13.0-16.5% 0.5-6.3% > TLB interrupts per migrated page 202-210 12.7-13.6 > average scanner mmu_gather time ~90 ms ~6.7 ms > > The mmu_gather times were measured in separate instrumented runs. > > On mm-new with v4, three balancing on/off pairs gave a 1.9-2.9% > loss and 13.2-14.6 TLB interrupts per migrated page. > > In a KVM guest with 192 vCPUs and a 60 GiB working set, throughput > with balancing on changed by -6.6%, -0.1% and +5.5% for the same > three seeds. The median change was -0.1%. In the baseline pilot, > the two runs with balancing on differed by 4.5% of their mean. > > Both kernels were also tested with identical instrumentation in an > 8-vCPU, 8 GiB KVM guest with two NUMA nodes. > > - When move_pages() migrated one private 4 KiB page, the baseline > deferred the PTE flush. Later, flush_tlb_batched_pending() flushed > the whole mm. The trace identified the mm but did not record the > caller. The patched kernel used ptep_clear_flush() on that PTE. > - After a forced 2 MiB THP split, only the last of 512 sub-folios was > still mapped. The baseline deferred its PTE flush, while the > patched kernel flushed it directly. > - Both kernels selected TTU_BATCH_FLUSH for all eight privately > mapped folios in one batch, including the last folio. > - Both kernels selected TTU_BATCH_FLUSH for an intact 2 MiB THP. > The PTE-level probe did not fire in this test. > > A 60-second CONFIG_DEBUG_VM stress test raced NUMA balancing with > fork(), MADV_DONTNEED and move_pages(). Its data checks passed on > both kernels. > > In separate two-node guest tests, all six mm migration selftests > passed on both kernels. All 14 available LTP move_pages and > migrate_pages test programs also passed on both kernels. > > No Fixes: tag, as this is a performance trade-off that has been there > since v6.3 and nobody has reported it as a regression. Happy to add > one if you think it should have one. > > mm/migrate.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 43 insertions(+), 3 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 96b66a272..731d66110 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1229,9 +1229,37 @@ static void migrate_folio_done(struct folio *src, > folio_put(src); > } > > +static enum ttu_flags folio_migrate_ttu_flags(struct folio *folio, > + enum migrate_mode mode, > + struct list_head *new_folios, > + bool flush_deferred) Two tabs please. > +{ > + if (mode != MIGRATE_ASYNC) > + return 0; > + > + /* Merge with the flush an earlier folio of this batch queued. */ > + if (flush_deferred) > + return TTU_BATCH_FLUSH; > + > + /* A batch with multiple folios can benefit from a batched flush. */ > + if (!list_is_singular(new_folios)) > + return TTU_BATCH_FLUSH; > + > + /* Keep the existing flush behavior for large folios. */ > + if (folio_test_large(folio)) > + return TTU_BATCH_FLUSH; > + > + /* A shared mapping can have more than one PTE to flush. */ > + if (folio_maybe_mapped_shared(folio)) > + return TTU_BATCH_FLUSH; > + > + return 0; > +} > + > /* Obtain the lock on page, remove all ptes. */ > static int migrate_folio_unmap(struct folio *src, struct folio *dst, > - enum migrate_mode mode, struct list_head *ret) > + enum migrate_mode mode, enum ttu_flags ttu, > + struct list_head *ret) > { > int rc = -EAGAIN; > int old_folio_state = 0; > @@ -1345,7 +1373,7 @@ static int migrate_folio_unmap(struct folio *src, struct folio *dst, > /* Establish migration ptes */ > VM_BUG_ON_FOLIO(folio_test_anon(src) && > !folio_test_ksm(src) && !anon_vma, src); > - try_to_migrate(src, mode == MIGRATE_ASYNC ? TTU_BATCH_FLUSH : 0); > + try_to_migrate(src, ttu); > old_folio_state |= FOLIO_WAS_MAPPED; > } > > @@ -1858,6 +1886,8 @@ static int migrate_pages_batch(struct list_head *from, > LIST_HEAD(unmap_folios); > LIST_HEAD(dst_folios); > bool nosplit = (reason == MR_NUMA_MISPLACED); > + bool flush_deferred = false; > + enum ttu_flags ttu; > > VM_WARN_ON_ONCE(mode != MIGRATE_ASYNC && > !list_empty(from) && !list_is_singular(from)); > @@ -2020,7 +2050,17 @@ static int migrate_pages_batch(struct list_head *from, > > cond_resched_tasks_rcu_qs(); > > - rc = migrate_folio_unmap(folio, dst, mode, ret_folios); > + ttu = folio_migrate_ttu_flags(folio, mode, > + &new_folios, flush_deferred); > + /* > + * A folio that looks mapped here may leave a flush > + * queued, which the rest of the batch can merge with. > + */ > + if (ttu == TTU_BATCH_FLUSH && folio_mapped(folio)) > + flush_deferred = true; Curious ... why do we even have to unmap if ... already unmapped? :) -- Cheers, David