From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0008627F754 for ; Mon, 9 Mar 2026 08:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773044278; cv=none; b=NofLS878FOv9f+dzrPmcUpmBtIn0uLWRNHqgQFInt68aVcV+TP4mWSvT28WJ6BKJDXbkJdllu+QR+J+WG+ew9MM/xgC3zjj+DFnBkb9OYbszPvzltZVb3R165xv1WUUJlMUEjDnrjuoeyEyRBxXxsM+fBjj4TJxhjq1Iddzxq8M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773044278; c=relaxed/simple; bh=Hxlyr94vhT6tceNWkfUX7FnAnLC5MO+FeAUWHj402F0=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=XSpJ0db/9eUDsl22KvHwYCiOK88yNsOJPcMMAFWOlTZJXy7C451GawZpkisxuqIXIcXQ6M+Te2X5dIRNpBi2sBA/Isb7NlHW6mil8Atc3SJJ46MfODKtQgB9D0LTWn9Mf1xcAgVaAvCnfE/CodgEFeUEgjeTnOBoTGCal4e1F6s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AycKyglm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AycKyglm" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9426EC2BC87; Mon, 9 Mar 2026 08:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773044277; bh=Hxlyr94vhT6tceNWkfUX7FnAnLC5MO+FeAUWHj402F0=; h=From:Subject:Date:To:Cc:Reply-To:From; b=AycKyglm0somIajLRn1PB2ivxqYlWEQNxYn5fFpwOAdqhapuUZjCcc7d/KBg22Moq o2C927nqYNReytwY+IvYZ2Xk5KIh1vcjFMVBYvurof/EVcn2099iWn5Kd3VY6VTnkG kQyQzHxXcSKqKn0urVRLzs3NyIcSTgTgTpFoNIG8cK08ldboviMr90OV0WTHJkgO/f spmU1CR3dD6U0xze3K5xkroZhaF2uJ82r5U0Fgnl0e1vieOa1XhAERPmxkYy+JSmkm 4v2hYKyws0Q/CHskqm1EkFIrK894lrzczp7RFurpJ0+L78szuBTEyQ1Ppybm0SdS8v F0gdhxzC7T+sg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A109EF370C; Mon, 9 Mar 2026 08:17:57 +0000 (UTC) From: Zhang Peng via B4 Relay Subject: [PATCH 0/2] mm: batch TLB flushing for dirty folios in vmscan Date: Mon, 09 Mar 2026 16:17:40 +0800 Message-Id: <20260309-batch-tlb-flush-v1-0-eb8fed7d1a9e@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=H4sIACSCrmkC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIzMDYwNL3aTEkuQM3ZKcJN20nNLiDF0LS+M0g1RTsyQTSzMloK6CotS0zAq widGxtbUADrHzlGEAAAA= 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=1773044270; l=3059; i=zippermonkey@icloud.com; s=20260309; h=from:subject:message-id; bh=Hxlyr94vhT6tceNWkfUX7FnAnLC5MO+FeAUWHj402F0=; b=sxFReAs8wK3VKflfARWnWgk7f6wn4fNFW99rIJrAv5x9OfnVaMTXYyL4a3bY+wRiQydi+yVgG mEgfk97EZfFAx4YusLrPnkMyYxiSThIU+eO6DqO9mz6vCP33ltXCVv6 X-Developer-Key: i=zippermonkey@icloud.com; a=ed25519; pk=tPCLpFnBfIyHsp0k7eaUTUREEa36bQNW/69X+NS8wBU= X-Endpoint-Received: by B4 Relay for zippermonkey@icloud.com/20260309 with auth_id=671 X-Original-From: Zhang Peng Reply-To: zippermonkey@icloud.com 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: Refactor shrink_folio_list() to improve code readability and maintainability by extracting common logic into helper functions: - folio_active_bounce(): Handle folio activation logic - folio_free(): Handle folio freeing logic - pageout_one(): Handle single folio pageout logic Patch 2: 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 --- bruzzhang (2): mm/vmscan: refactor shrink_folio_list for readability and maintainability mm, vmscan: flush TLB for every 31 folios evictions include/linux/vmstat.h | 1 + mm/vmscan.c | 387 +++++++++++++++++++++++++++++++------------------ 2 files changed, 245 insertions(+), 143 deletions(-) --- base-commit: 49cb736d092aaa856283e33b78ec3afb3964d82f change-id: 20260309-batch-tlb-flush-893f0e56b496 Best regards, -- Zhang Peng