From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=57.103.70.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794834029; b=WUmmteMIfXeEv3lvCHXrrhHIXiNJVcPWl8X10fY34lqH0UJ+hoita2Q+ZcS2UQo74vpr gSZqRCtMUUA3GK1E4fc1QOYceYIaTBNskxTfy3E6vSBM7XsxrSBxp+77e5mWJa4hlSgHC zD3WTvKqn5Vu0j1qHOimZWZwLW/mAd8bls9YmpfkkXjm6QdNEyMv3w4HNcLi4hq9JnsgP Q1aTADKSJ638RZGddv/xMQw1Io3SfJGkVaLc4fkYBqVRw+1Ysa4BXHX24GxSU+FuzwO0W IFh497vVSgEV5hyPHKORmRanx8A4JbbecNzqJYXTVBVuI9FQVRV0mGQVLs0hzMLYHNw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794834029; h=DMARC-Filter:Received:X-ICL-RepId:Dkim-Signature:Received:Date:From: To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Authority-Info-Out:X-Proofpoint-GUID:X-JNJ; bh=N2VrZwSXFQpePhWr6QR5jf0LaY6vYKdX0ikOoiKW4E4=; b=C92hUMuiKE+eMQ7Huz7bL76fnRAWTNBKeXnfJxq5dqB0hHJzOZNOqQiig22g+8EcWOOi vUwW+b9Twz0QU80i29XRa+f+ujas6J2HrAo6xtMCiCihBGgT3oYOIvkUO1uXNmae2HWfK 9x4vFXkibyUWbpyS/QTJfrJ2EYsm0rvp536Ja6vdAb7ufyxlHviVhaWaU0WoybRkBpN6e U60G38REpY9wy9HFtc6jb1AEspyo+hqWpDa3jw9wCLgPDHL1QMwAogYJqTCveefoAJBU0 HMUOVmpFGc1pl8o04p/pCO0A8vhlmj7oNA7+FLjHl072kLdbi5ItrtDmJnWQYq5NRYA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass header.d=icloud.com header.i=@icloud.com header.a=rsa-sha256 header.s=1a1hai header.b=zinPx+gC; arc=none smtp.remote-ip=57.103.70.43 Received: from outbound.mr.icloud.com (mr-2006f-snip4-11.eps.apple.com [57.103.70.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C2AB606A323 for ; Mon, 16 Nov 2026 13:00:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C2AB606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.a=rsa-sha256 header.s=1a1hai header.b=zinPx+gC Received: from outbound.mr.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-2a-20-percent-1 (Postfix) with ESMTPS id F3DA81801B22; Mon, 16 Nov 2026 13:00:24 +0000 (UTC) X-ICL-RepId: 01a1e471-c9d5-7b88-80ae-0d52a32e5e96 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1794834028; x=1826370028; bh=N2VrZwSXFQpePhWr6QR5jf0LaY6vYKdX0ikOoiKW4E4=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:x-icloud-hme; b=zinPx+gC8U4DU363yssCEHGI1pb41ifQK1L+0LqSHG5RzKgO7aB3YrlK5kQfgdRCbutdgH42F0rBxbFc3bQV6gc0ut2coKmW/tEPBtvebBUMZxE9WW2JgAUtUPmVVxrxxO0NpQGzyU3PFXmpaISHT0SCpmGqPoNFhejJB5o35gBCPRXgUJpGm/1gxqM+cgtaq6GOdAhr9pKaYbsMVsUGkHEONg77r/NIzSUb//5DOQ0ujOhBGR44ousbKWRkM7I9OQvqwrIb/sgd/7pef7oTYVG4dwlDaQHqgvJ9wsvim7mSnC2nAgqvOVjxzK1Jx3tXjTJ9y5f7dNp3tjkM/dJ3cg== Received: from lima-kernel-dev (unknown [17.156.200.36]) by p00-icloudmta-asmtp-us-west-2a-20-percent-1 (Postfix) with ESMTPSA id B36D01801540; Mon, 16 Nov 2026 13:00:20 +0000 (UTC) Date: Mon, 16 Nov 2026 21:00:15 +0800 From: Zhang Peng To: "Barry Song (Xiaomi)" Cc: akpm@linux-foundation.org, axelrasmussen@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, bruzzhang@tencent.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, weixugc@google.com, yuanchu@google.com Subject: Re: [PATCH v6 0/5] mm: batch TLB flushing for dirty folios in vmscan Message-ID: References: <20261031-batch-tlb-flush-v6-0-190539839eec@tencent.com> <20261115230231.21194-1-baohua@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261115230231.21194-1-baohua@kernel.org> X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE2MDA1MSBTYWx0ZWRfXwpZDbepw2hpM HU1CTTwM0zxmzB11fhPuB1UzVZHlDsxfBOU/Etbi9k82hfPYmJ0+G1dDmLWXTE7wke4UZBPmA4X 8MRKZd0Bob0h1iJE/l4EcPpfTKfFefUJD7x7dyw9vE1r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E k4ohrYjwHi5xdFztyjAQFa64L73YquGEJnVJxvthpWmhXOXGYdXuNcVcGAOptk5Q== On Mon, Nov 16, 2026 at 07:02:31AM +0800, Barry Song (Xiaomi) wrote: > On Sat, Oct 31, 2026 at 6:35 PM Zhang Peng wrote: > > > > This series introduces batch TLB flushing optimization for dirty folios > > during memory reclaim, aiming to reduce IPI overhead on multi-core systems. > > > > Background > > ---------- > > Reclaim calls try_to_unmap_flush_dirty() before writing out each dirty > > folio. When writable TLB entries are pending, this triggers a flush. > > On systems that use IPIs for TLB shootdowns, frequent flushes can add > > significant overhead. > > > > Approach > > -------- > > Collect dirty folios into a folio_batch, releasing their locks while > > collecting the batch so swap faults can progress. Before writeout, try > > locking each folio again and recheck writeback, mappings and DMA pins. > > Keep eligible folios locked, flush pending writable TLB entries once, > > then page them out. Process a final partial batch at the end of the scan. > > > > Changes > > ------- > > Patch 1: Extract the folio activation block at activate_locked into > > folio_activate_locked(). > > Patch 2: Extract the folio-freeing path (buffer release, lazyfree, > > __remove_mapping, folio_batch drain) into folio_try_reclaim_free(). > > Group retained folios, deferred frees and the reclaimed count > > in reclaim_folio_state, local to each shrink_folio_list() call. > > Patch 3: Extract the pageout() dispatch state machine into folio_try_pageout(). > > Patch 4: Extract the TTU setup and try_to_unmap() block into folio_try_unmap(). > > Patch 5: Implement batch TLB flushing logic. Dirty folios are accumulated in > > batches and a single TLB flush is performed for each batch before > > calling pageout. > > > > Testing > > ------- > > The benchmark script uses stress-ng to compare TLB shootdown behavior before and > > after this patch. It constrains a stress-ng workload via memcg to force reclaim > > through shrink_folio_list(), reporting TLB shootdowns and IPIs. > > > > Core benchmark command: stress-ng --vm 16 --vm-bytes 2G --vm-keep --timeout 60 > > > > ========================================================================== > > batch_dirty_tlb_flush Benchmark Results > > ========================================================================== > > Kernel: 7.0.0-rc1+ CPUs: 16 > > MemTotal: 31834M SwapTotal: 8191M > > memcg limit: 512M alloc: 2G workers: 16 duration: 60s > > -------------------------------------------------------------------------- > > Metric Before After Delta (abs / %) > > -------------------------------------------------------------------------- > > bogo ops/s 28238.63 35833.97 +7595.34 (+26.9%) > > TLB shootdowns 55428953 17621697 -37807256 (-68.2%) > > Function call IPIs 34073695 14498768 -19574927 (-57.4%) > > pgscan_anon (pages) 52856224 60252894 7396670 (+14.0%) > > pgsteal_anon (pages) 29004962 34054753 5049791 (+17.4%) > > -------------------------------------------------------------------------- > > > > Suggested-by: Kairui Song > > Signed-off-by: Zhang Peng > > --- > > Hi Peng, > > Just a quick update: this patch is still on my radar. I ran a > quick perf test while building the kernel. Without your patch, > try_to_unmap_flush_dirty() accounted for 1.75% of CPU cycles. > > I guess there could be workloads where try_to_unmap_flush_dirty() > accounts for an even larger share of CPU cycles. > > # Children Self Command Shared Object Symbol > # ........ ........ ....... ................. ............................ > # > > 1.75% 0.01% cc1 [kernel.kallsyms] [.] try_to_unmap_flush_dirty > | > --1.74%--try_to_unmap_flush_dirty > try_to_unmap_flush (inlined) > | > --1.73%--arch_tlbbatch_flush > | > --1.70%--flush_tlb_multi (inlined) > __flush_tlb_multi (inlined) > | > --1.69%--native_flush_tlb_multi > | > --1.68%--on_each_cpu_cond_mask > | > --1.62%--smp_call_function_many_cond > | > --1.23%--csd_lock_wait (inlined) > > > With your patch, the CPU overhead drops by roughly 7x: > > > # Children Self Command Shared Object Symbol > # ........ ........ ....... ................. ............................ > # > 0.25% 0.00% cc1 [kernel.kallsyms] [.] try_to_unmap_flush_dirty > | > --0.24%--try_to_unmap_flush_dirty > try_to_unmap_flush (inlined) > | > --0.24%--arch_tlbbatch_flush > | > --0.24%--flush_tlb_multi (inlined) > __flush_tlb_multi (inlined) > | > --0.24%--native_flush_tlb_multi > | > --0.23%--on_each_cpu_cond_mask > | > --0.21%--smp_call_function_many_cond > | > --0.14%--csd_lock_wait (inlined) > > 0.00% 0.00% fixdep [kernel.kallsyms] [.] try_to_unmap_flush_dirty > > > Overall, I think this is a good approach. I'll be traveling soon > and will return to this patchset for more testing and a thorough > review in about two and a half weeks. > > Thanks > Barry > Hi Barry, Thanks for the update and for taking the time to run the perf test. The breakdown is helpful, and it's encouraging to see that try_to_unmap_flush_dirty() accounts for a significant share of the cycles in shrink_folio_list(). Safe travels! Thanks, Peng