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 2/3] mm: swap: skip swap tiers above the memcg max tier
Date: Wed,  2 Dec 2026 17:48:25 +0900	[thread overview]
Message-ID: <20261202084826.2131931-3-youngjun.park@lge.com> (raw)
In-Reply-To: <20261202084826.2131931-1-youngjun.park@lge.com>

To allow per-cgroup swap device selection, make the allocation paths
skip swap tiers above a per-memcg maximum. The per-CPU cached cluster is
shared by all memcgs, so the fast path is skipped for a memcg with a
limit.

No limit can be set yet, so there is no functional change. The next
patch adds the interface to set it.

Signed-off-by: Youngjun Park <youngjun.park@lge.com>
---
 mm/swapfile.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 95928d9f85da..d30ee41f8217 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1439,6 +1439,15 @@ static inline short swap_tier(struct swap_info_struct *si)
 	return si->prio;
 }
 
+/*
+ * Highest swap tier the memcg of @folio may allocate from. No limit
+ * can be set yet.
+ */
+static inline short swap_memcg_max_tier(struct folio *folio)
+{
+	return SWAP_TIER_MAX;
+}
+
 /*
  * Fast path try to get swap entries with specified order from current
  * CPU's swap entry pool (a cluster).
@@ -1456,7 +1465,12 @@ static bool swap_alloc_fast(struct folio *folio)
 	 */
 	si = this_cpu_read(percpu_swap_cluster.si[order]);
 	offset = this_cpu_read(percpu_swap_cluster.offset[order]);
-	if (!si || !offset || !get_swap_device_info(si))
+	if (!si || !offset)
+		return false;
+	/* The per-CPU cluster is shared by all memcgs, so skip it if limited. */
+	if (swap_memcg_max_tier(folio) != SWAP_TIER_MAX)
+		return false;
+	if (!get_swap_device_info(si))
 		return false;
 
 	ci = swap_cluster_lock(si, offset);
@@ -1476,10 +1490,14 @@ static bool swap_alloc_fast(struct folio *folio)
 static void swap_alloc_slow(struct folio *folio)
 {
 	struct swap_info_struct *si, *next;
+	short max = swap_memcg_max_tier(folio);
 
 	spin_lock(&swap_avail_lock);
 start_over:
 	plist_for_each_entry_safe(si, next, &swap_avail_head, avail_list) {
+		/* Skip tiers above the memcg limit. */
+		if (swap_tier(si) > max)
+			continue;
 		/* Rotate the device and switch to a new cluster */
 		plist_requeue(&si->avail_list, &swap_avail_head);
 		spin_unlock(&swap_avail_lock);
-- 
2.34.1


  parent 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 [PATCH v12 0/3] mm/swap: swap tier phase 1: priority as tier, per-cgroup via debugfs Youngjun Park
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 ` Youngjun Park [this message]
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-3-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®