From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outbound.ci.icloud.com (ci-2001b-snip4-3.eps.apple.com [57.103.91.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3864623183F for ; Thu, 26 Mar 2026 08:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.103.91.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774514155; cv=none; b=J73wCrtaTOAW2ky+hFOdsf0Fw2uVRFK2ERCJq+OOmoFsA27vw1hkmeY6EtqCTFHTzXp0ahYGJx8rdi0m8XwbIDdPqR1pSk21vx/Qy1NlTC+3B7Abxu9wpkTwmh35/6d3QrVx31M5Fx42R8e4HUtGP0HNRVXcdZs7q56tvjTKppQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774514155; c=relaxed/simple; bh=1S4mtwiSgiEXK9RkHO0cUF3Km1aYqH6AUACfPgCXzzs=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=lMdO292T1/+qa5vh3FaILisoup3FdgS8X8gixUWXLV+8iX535t3F4zmhbfL7IGiWhGABlIUoeGcPzVZyxRNHY7ZhY4+CP+JbPWC3ByShAvci1+m/izvCYeP69Wxu4CZeMQDqG/6OmFhAIzISvfRGu7hKn20OB70FTbIFtz7Plyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=vfLk1hpJ; arc=none smtp.client-ip=57.103.91.16 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.b="vfLk1hpJ" Received: from outbound.ci.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-central-1k-60-percent-5 (Postfix) with ESMTPS id 5A8311800099; Thu, 26 Mar 2026 08:35:51 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1774514153; x=1777106153; bh=TnFacVqdLEOdPbeqUWCs+TzIAEb2KkAj5Z3+qb/+C44=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:x-icloud-hme; b=vfLk1hpJx5drEyisk2Axujy+9Qp9RrOGShXp4nusuC0UeiLSxyKUYTcFpvet6W4gNsG91qG9isbEc53Ef1HnbkESdl20wUYBMJs2FiOn77Ujoz7VtgT+tVY3x99aTC+hH6aZyyRN1xbemLvjKQGXo1QU36hFkN2LLr+pzAyAu6y+gavk1t6VBLnEgCOGWz6b2C71zm7hcPXKEGbyFXyRXx1fHutXNhTAQCkxF+UJHOG4mMBuslwbmUG/8BGsBq6wtUYOIsskJmaFQ2Yu+H1Hc+XTMsHxYZTkYR17OvRv40bWO7sO3TvfyuE/i3eT9gGJ690V0eBW1+VGeTyFF68Kxw== Received: from [21.6.122.162] (unknown [17.57.156.36]) by p00-icloudmta-asmtp-us-central-1k-60-percent-5 (Postfix) with ESMTPSA id 4FC981800167; Thu, 26 Mar 2026 08:35:46 +0000 (UTC) From: Zhang Peng Subject: [PATCH v2 0/5] mm: batch TLB flushing for dirty folios in vmscan Date: Thu, 26 Mar 2026 16:35:33 +0800 Message-Id: <20260326-batch-tlb-flush-v2-0-989ba60f970d@icloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIANXvxGkC/3WNQQ6CMBBFr0Jm7ZgCWqkr72FY0HZqJ0FqWmg0h Ltb2bt8L/nvr5AoMiW4VitEypw4TAWaQwXGD9ODkG1haEQjRSsU6mE2HudRoxuX5LFTrRN0lvq kJJTVK5Lj916894U9pznEz36Q65/938o1CiTdObIXWw+KbmzGsNijCU/ot237AjSbtcCvAAAA X-Change-ID: 20260309-batch-tlb-flush-893f0e56b496 To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Qi Zheng , Shakeel Butt , Axel Rasmussen , Yuanchu Xie , Wei Xu , Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kairui Song , Zhang Peng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1774514145; l=3652; i=zippermonkey@icloud.com; s=20260309; h=from:subject:message-id; bh=1S4mtwiSgiEXK9RkHO0cUF3Km1aYqH6AUACfPgCXzzs=; b=7lJx20nI1Zoi+8Zmcww8Z4JTuVwbzT44J4i57tORiO/vubcR3diXcmV6vIfFhftrgxB2unYtY YzzLQ/G+I3IC7X4rqCPgA20eeWTjOXva/E0nheAByNk2gsChrKmPxbz X-Developer-Key: i=zippermonkey@icloud.com; a=ed25519; pk=tPCLpFnBfIyHsp0k7eaUTUREEa36bQNW/69X+NS8wBU= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzI2MDA2MiBTYWx0ZWRfXwXwMgcvl3dZR BdR8pwlZJsiPXtLtoMsgDBlj+/gOHVMCfFPttgEn4xuHOfr9sWED42rVsQNPLPVSGZZ+v81HiIp Jz5sxT5nrL97mqeVPFpl1Zz4a1sUN6lf03TBNZNjTtaR4i2qWX0fnKEB5yVqKUJsftpj6W1j+eu LKUm3iDwmnqTt9LF+QKG+XxvaXg0E9+ou+blc++xXQgzBOlzWI8Lsb/K72V1YaeW94243MenOhx dXj4AvTSyWMnJtNVP6REMDeG546/vkywrEUi/rKnrpq7vNxn2/Ht4J1b9FLDSu3/SsDG8iIpanN ZA8pczipRaaWumwE9KVjMsb3avHGedBbgeqQuo8bu/P4SEiPKQ4QWw1+7OYq0U= X-Authority-Info-Out: v=2.4 cv=deWNHHXe c=1 sm=1 tr=0 ts=69c4efe8 cx=c_apl:c_pps:t_out a=2G65uMN5HjSv0sBfM2Yj2w==:117 a=2G65uMN5HjSv0sBfM2Yj2w==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=x7bEGLp0ZPQA:10 a=YE32fvk_ji8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=v3ZZPjhaAAAA:8 a=GvQkQWPkAAAA:8 a=0nsp5VSLLG1NfpzbPScA:9 a=QEXdDO2ut3YA:10 a=J82S1U87d15UFHHUFZS8:22 a=yLjSXO_LiVxs9JEHLWbQ:22 X-Proofpoint-GUID: Rs6VvbBLaY2M1IFXpa2SMfafmOye5Ufk X-Proofpoint-ORIG-GUID: Rs6VvbBLaY2M1IFXpa2SMfafmOye5Ufk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-26_02,2026-03-24_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2603260062 This series introduces batch TLB flushing optimization for dirty folios during memory reclaim, aiming to reduce IPI overhead on multi-core systems. Background ---------- Currently, when performing pageout in memory reclaim, try_to_unmap_flush_dirty() is called for each dirty folio individually. On multi-core systems, this causes frequent IPIs which can significantly impact performance. Approach -------- This patch series accumulates dirty folios into batches and performs a single TLB flush for the entire batch, rather than flushing for each individual folio. Changes ------- Patch 1: Add nr_reclaimed to reclaim_stat so shrink_folio_list() can be changed to void, giving a consistent interface where all per-pass statistics are reported through reclaim_stat. Patch 2: Extract the folio activation block at activate_locked into folio_active_bounce(). Patch 3: Extract the pageout() dispatch state machine and the folio-freeing path into pageout_one() and folio_free() respectively. 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 --- Changes in v2: - Fix incorrect comment about page_ref_freeze - Add folio_maybe_dma_pinned() check in pageout_batch() - Link to v1: https://lore.kernel.org/r/20260309-batch-tlb-flush-v1-0-eb8fed7d1a9e@icloud.com --- Zhang Peng (5): mm/vmscan: track reclaimed pages in reclaim_stat mm/vmscan: extract folio activation into folio_active_bounce() mm/vmscan: extract folio_free() and pageout_one() mm/vmscan: extract folio unmap logic into folio_try_unmap() mm/vmscan: flush TLB for every 31 folios evictions include/linux/vmstat.h | 1 + mm/vmscan.c | 456 +++++++++++++++++++++++++++++++------------------ 2 files changed, 287 insertions(+), 170 deletions(-) --- base-commit: 7c5507fca017a80ece36f34e36c77e2bee267517 change-id: 20260309-batch-tlb-flush-893f0e56b496 Best regards, -- Zhang Peng