Received: from outbound.st.icloud.com (p-east2-cluster5-host4-snip4-2.eps.apple.com [57.103.79.55]) (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 95430CA4E for ; Fri, 10 Apr 2026 12:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.103.79.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775825057; cv=none; b=eC3thJ68/hMp054lYS1IB6qsFfMNXfWkvarX7XmIEypkDuZP+IrWPHwf1oSQq82MThvM21SA4u+PiyfMeuqB/QNE59C0+PmlTUTnZvjhWEom9q95hEw0pdcQszPHeyxdusjN2p/8p0f+Vq1h3wOGyoS2iZU8sHXOspJzmsAXcSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775825057; c=relaxed/simple; bh=O5ktmk+TLv9rz1J+bLjEiohACE86R8x9048z8wYN4I4=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=rrb/zDDGFa/mS4Wy5jXmPzTORRA548HiOmGiez++jLGHpIWEpAMo/oumMVipCtmh0mAaUVl9O8MGCuLa2VGCUzbtkONm40aj70KjERvWpqNc9zREBWuXRxW6unys5VZagYmHQ6FZ3qsYJZ9nqzGRcbgQL2NosmjWvGjPe9dFar0= 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=VZHJ1nQa; arc=none smtp.client-ip=57.103.79.55 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="VZHJ1nQa" Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-100-percent-0 (Postfix) with ESMTPS id 35938180035C; Fri, 10 Apr 2026 12:44:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1775825055; x=1778417055; bh=8zAKW7TKIdYtRCrdMYYdB7ruxsvi8/ixARgZcc3HuzY=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:x-icloud-hme; b=VZHJ1nQaGwER5pdoNL+xnmFDpR3bOrZqlvLOO0URIDF3FxXV7vhizUaWMLFY5KSPURPta++qCyMig0+wL77mym3e3kdxaSJy8uPbheD14KYoiwQl15BGqvs4w7ecIBqqW3QZkQsIw4GE+rnd5cPKF9wI37d/WULHO37Dg4zcSmzCIIZEXLfLvQSEX1TmSNk2DL85zIk2sGKAfeIkIsTk/Hme21pliENaT07+fii1VS1os2iGIgKOhxN0Q8JvXuiYXT8VNBqjHkv3c26lA4lmxnxuiYFDb3DanDg+PV1QkfJaqG3D6jTTHGJjZbIabD1B9uDCmBh4m7QnLOe8aj0hEw== Received: from [21.6.122.162] (unknown [17.42.251.67]) by p00-icloudmta-asmtp-us-east-1a-100-percent-0 (Postfix) with ESMTPSA id 0B5CE1800181; Fri, 10 Apr 2026 12:44:04 +0000 (UTC) From: Zhang Peng Subject: [PATCH v3 0/5] mm: batch TLB flushing for dirty folios in vmscan Date: Fri, 10 Apr 2026 20:43:58 +0800 Message-Id: <20260410-batch-tlb-flush-v3-0-ff0b9d3a351a@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=H4sIAI7w2GkC/3XNQQ7CIBCF4asY1mIotFhceQ/josAgk9RioCWap neXdqUxLv+XzDczSRAREjntZhIhY8IwlBD7HTG+G25A0ZYmnHHJBFNUd6PxdOw1df2UPG2VcAw aqWslSbl6RHD43MTLtbTHNIb42h7kal3/W7mijIJuHdijrToFZzR9mOzBhDtZscw/AC5/AV6Am glouBC8MfUXsCzLG4ad4xrwAAAA 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=1775825044; l=4105; i=zippermonkey@icloud.com; s=20260309; h=from:subject:message-id; bh=O5ktmk+TLv9rz1J+bLjEiohACE86R8x9048z8wYN4I4=; b=Qe5FdIHImhiR0XAGDGfa72dcBPU/IRjGupJlQzoAdyNjl6fbz6o7UCJ7Tke1VwRcua/u9ZO8T nfMGX6o+L/GCSCkEHHQGaX64jkW56N66CXZUsjkJ29mygcZBvrR1i/H X-Developer-Key: i=zippermonkey@icloud.com; a=ed25519; pk=tPCLpFnBfIyHsp0k7eaUTUREEa36bQNW/69X+NS8wBU= X-Proofpoint-GUID: LVApXZZHrRNHwHEbxJLFoAMXamTelL-e X-Authority-Info-Out: v=2.4 cv=VKfQXtPX c=1 sm=1 tr=0 ts=69d8f09d cx=c_apl:c_pps:t_out a=YrL12D//S6tul8v/L+6tKg==:117 a=YrL12D//S6tul8v/L+6tKg==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=x7bEGLp0ZPQA:10 a=YE32fvk_ji8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=v3ZZPjhaAAAA:8 a=GvQkQWPkAAAA:8 a=k3ryPfxwKlxrfAMZny4A:9 a=QEXdDO2ut3YA:10 a=J82S1U87d15UFHHUFZS8:22 a=yLjSXO_LiVxs9JEHLWbQ:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDEwMDExOCBTYWx0ZWRfX4qGg5eeMrMwc cDBxlZvO2WD/E54nkqzd18+4ITfbqAnWgoeJvA9g7LDu0EvuLH4KfBr41H2zeu/WsKXAVFL2Xtc WIIi1SaTgL5dh1pi2A/Ik+MU9QLpzn/QQnNEOCehUYyw6snXXoi8YCVwrqT3OPHvGfTDY/qdPEQ rOFmwFqroNn5HLOHZElNlA9NnfuTE470Nqom7xBfm5COABoK39wH/ThDxo3xZX+HD4VZQxXTrdH r2drVc66qy1/dwFobGtGbr60stcBsy9GrfsidizmleQEpz4Kep4AYrHBLoYnp7iZjoshiSk70is z7j+QZodZvHWWEUW9B+60FrEQBiOkiPCR6N6nx95EB6zx5/V2OwLo9urUhWN20= X-Proofpoint-ORIG-GUID: LVApXZZHrRNHwHEbxJLFoAMXamTelL-e 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-04-10_03,2026-04-09_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1015 phishscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2604100118 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 v3: - Patch 5: Replace folio_test_lru() condition check with VM_WARN_ON_FOLIO assertion, as PG_lru should never be set for isolated folios - Patch 5: Add comment explaining folio_batch reuse-in-place technique in pageout_batch() - Patch 5: Rewrite comment above folio_unlock() to explain why the folio is unlocked while batching - Link to v2: https://lore.kernel.org/r/20260326-batch-tlb-flush-v2-0-403e523325c4@icloud.com 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 | 462 +++++++++++++++++++++++++++++++------------------ 2 files changed, 293 insertions(+), 170 deletions(-) --- base-commit: 7c5507fca017a80ece36f34e36c77e2bee267517 change-id: 20260309-batch-tlb-flush-893f0e56b496 Best regards, -- Zhang Peng