From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=156.147.51.103 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796201323; b=V5ClsOUvvZ8i9la1X/knOCwEgClXl5sBvhYbYUD4zOUYmHJXif8/+FI+ZR5PFKqiNKuu EZBR7wipnnuevOVCU01VgsgmWaevJ5jdu4vxqH9tp7A+MpYS6KjmYG+F4xCUrNJ3872ws 9p2II4E1JObKGaEkC+pMBo77dym5qxwuM+91S0XIgkgnGBc9xs51AsRlxA5ef2GDbVVOO Bz58j244heieitSaDJLWIgXRsb1lHxK0oH2QJlC9HUDoPETZ2v/wq9La2yzrl02jgGvlJ OQLDPr8EuFW0Ljr6WgpHDebLHpjA76RbxnbmGIxdRt8bFMo4Ae9CC6Gwp61AIhzBC1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796201323; h=DMARC-Filter:Received:X-Original-SENDERIP:X-Original-MAILFROM:From: To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=DH4eBl0a/dNSFap2DdsiamlpNS7uh7p1dQLYFvZwwAc=; b=yiAzKlt1lBluZXH2VzG/8c0xuIrj6C8bg9wIQO7EsjUyoEwLee5kTMQ/ggG7/8+m6YFR B1MkczIFa1tBddyCWkxi83hOAxn2DQZLbqkCno11SD3D3pi/20Gv1ykMjsreRhVggkTSY hcgZmjsSLkP3oPlc7/UIUYB2aI5ov5VcRI74uE7sejoug99rTDoaS9Hi5BK9KysdiKySA cyI5yYCRO1Y8KsqSEqPWrnOTAYmVv3r4ALkv9Pj8T8b5j55aqOOVky46VrSQW7IpJHYqD 87ceXC6rt9U/rRRNT2uKMJWn3CAxpxRWLt9qxFM/8NrJM/FywODsJOwidRQDt+58snA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=lge.com; spf=pass smtp.mailfrom=lge.com; arc=none smtp.remote-ip=156.147.51.103 Received: from lgeamrelo07.lge.com (lgeamrelo07.lge.com [156.147.51.103]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1E1C606A687 for ; Wed, 2 Dec 2026 08:48:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D1E1C606A687 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lge.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lge.com Received: from unknown (HELO yjaykim-PowerEdge-T330.lge.net) (10.177.112.156) by 156.147.51.103 with ESMTP; 2 Dec 2026 17:48:28 +0900 X-Original-SENDERIP: 10.177.112.156 X-Original-MAILFROM: youngjun.park@lge.com From: Youngjun Park To: Andrew Morton , linux-mm@kvack.org Cc: Johannes Weiner , Chris Li , Kairui Song , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Shakeel Butt , Yosry Ahmed , Lian , Youngjun Park , linux-kernel@vger.kernel.org Subject: [PATCH v12 0/3] mm/swap: swap tier phase 1: priority as tier, per-cgroup via debugfs Date: Wed, 2 Dec 2026 17:48:23 +0900 Message-Id: <20261202084826.2131931-1-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 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-Transfer-Encoding: 8bit This is v12 of the swap tier series [1], reworked after the v11 discussion [2][3]. In this phase 1, a swap priority is the tier, and a per-cgroup maximum swap priority is set through debugfs. Motivation ========== After the v10 discussion [4][5], I would like to first land the parts that do not affect users, before anything touches memcg, with two goals in mind. - Make per-cgroup swap device selection possible. - Serve as a bridge that causes no trouble when the tier interface and memcg support are introduced later. Swap priority already gives us a tier-like structure. - Devices with different priorities are used in priority order. - Devices with the same priority are used round-robin. So each distinct priority is one tier: a round-robin group, with ordering only between tiers. The existing plists are already sorted this way, so this series adds no tier list or new field. It only filters the existing allocation walk by priority for a given memory cgroup. This is phase 1. When tiers are extended later, the same view holds: a tier is simply named by (or replaces) its priority, and the debugfs limit becomes the memcg interface. The swap queue of the per-priority allocation series [6] is such a per-priority group. I think that concept could become the swap tier, if the discussion goes that way. Kairui, Chris, Lian, what do you think? Whichever lands first, I can rebase on the other. Use case ======== Interactive groups should get the fast tiers, and batch groups should be kept off them. A top-down priority limit is all this needs. Per-cgroup swap in debugfs ========================== Johannes suggested [2] trying swap priority as the tier. Based on that: - Patch 1 introduces the swap tier as a swap priority. - Patch 2 skips tiers above a memcg limit in the allocation path. - Patch 3 sets the limit per cgroup through debugfs. The effective limit is the lowest one among the cgroup and its ancestors (parent 50, child 100 gives 50). # swapon -p 100 /dev/nvme0n1p2 # swapon -p 50 /dev/sdb2 # echo "/batch 50" > /sys/kernel/debug/swap/memcg_tiers /batch now uses only sdb2. Writing "max" removes the limit. Limits are keyed by cgroup ID; a removed cgroup is shown as [removed:] until deleted by ID. Known limitations ================= - Fast path: the per-CPU cluster cache is shared by all memcgs and can hand out a device above the limit, so limited cgroups skip it. Lian's series [6] makes the cluster per device, which removes the need. - Lookup cost: limits are in a list outside struct mem_cgroup, walked on each slow path allocation. Slow only with many entries, and we set few. With the memcg interface it becomes a field check. - Reclaim: mem_cgroup_get_nr_swap_pages() ignores the limit. To be handled with the memcg interface. Future direction ================ - Add the memcg interface after virtual swap lands, as memory.swap.prio.max or memory.swap.tiers.max, whichever the discussion prefers. - Explicit tiers (naming, e.g. /sys/kernel/mm/swap/tiers), only when a concrete need appears. - Per-tier allocation policy, as a separate extension that needs its own discussion. Testing ======= QEMU (KASAN enabled) with two swap devices (priority 100 and 50) and a memcg running a 150M anonymous memory hog. - No limit / limit 100: swaps to the priority 100 device. - Limit 50: swaps only to the priority 50 device. - Limit below all devices: no swap is used and the cgroup OOMs. - Parent and child limits: the lowest one applies. - Invalid input is rejected; "max" removes the limit. - Removed cgroup shown as [removed:], recreated one starts without a limit, stale entry deleted by ID. No WARNING/BUG/KASAN reports. checkpatch.pl --strict is clean. Tool-generated content ====================== Following Documentation/process/generated-content.rst: I used GitHub Copilot CLI (Claude Sonnet 5.5) to help write the code, the commit logs and this cover letter, and to run the QEMU tests. The design is mine, and I reviewed and tested the result. Change log ========== v12 - Use a swap priority as the tier; dropped the tier list and avail list walk. - Replaced the debugfs tier mask with a per-cgroup max swap priority [2][3]; removed the tiers file. - Split into three patches. Changes up to v11 are in the v11 cover letter [1]. [1] https://lore.kernel.org/linux-mm/20260916183437.2946306-1-youngjun.park@lge.com/ [2] https://lore.kernel.org/linux-mm/20260916200434.GA5784@cmpxchg.org/ [3] https://lore.kernel.org/linux-mm/arfnkNBANl0fwrKb@gmail.com/ [4] https://lore.kernel.org/linux-mm/amDCIl51NoNPL7Op@cmpxchg.org/ [5] https://lore.kernel.org/linux-mm/amIlqHQ40baRoz3O@cmpxchg.org/ [6] https://lore.kernel.org/linux-mm/cover.1795439990.git.lianux.mm@gmail.com/ Youngjun Park (3): mm: swap: introduce the swap tier as a swap priority mm: swap: skip swap tiers above the memcg max tier mm: swap: add debugfs to set memcg max swap tier mm/swapfile.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 238 insertions(+), 1 deletion(-) base-commit: 1a7610248a3802e38124ce66b07eef12277be9a0 -- 2.34.1