mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Youngjun Park <youngjun.park@lge.com>
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: Johannes Weiner <hannes@cmpxchg.org>,
	Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
	Kemeng Shi <shikemeng@huaweicloud.com>,
	Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
	Barry Song <baohua@kernel.org>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Yosry Ahmed <yosry.ahmed@linux.dev>, Lian <lianux.mm@gmail.com>,
	Youngjun Park <youngjun.park@lge.com>,
	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	[thread overview]
Message-ID: <20261202084826.2131931-1-youngjun.park@lge.com> (raw)

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:<id>] 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:<id>], 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


             reply	other threads:[~2026-12-02  8:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:48 Youngjun Park [this message]
2026-12-02  8:48 ` [PATCH v12 1/3] mm: swap: introduce the swap tier as a swap priority Youngjun Park
2026-12-02  8:48 ` [PATCH v12 2/3] mm: swap: skip swap tiers above the memcg max tier Youngjun Park
2026-12-02  8:48 ` [PATCH v12 3/3] mm: swap: add debugfs to set memcg max swap tier Youngjun Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202084826.2131931-1-youngjun.park@lge.com \
    --to=youngjun.park@lge.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=lianux.mm@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shakeel.butt@linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=yosry.ahmed@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®