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=1796201324; b=ozjGfKj3eOVgpN/JVVYLQeFdiah5+3FeYKNDtlvp5KvZLKADnAySU9uCdcURYh4aQr42 6iHXayzG1UH6gHwzmFA4CV3/mh5X3CUnItqrGiteLsgtlNe/3H0abpOFRYWEVQ038qZlT nonNixZ7PosN/rFQJyGG/Qsfo89x6qOnZgkxE5axiHTvw6mEVavreQvW+zp2QQGf4UTMX kvaCApJmhdT/Q0AaqSf4BLf/h23xmbYhHy1HwHLuGPauEC3NlGNm0u3Ul3SLhad9rFrpF ZLVzOoqvyRMptF2Qr9HJOSV06A12nUGwvGw64OpCSVi9u4ipLJftNrUM6dL8NCdzn/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796201324; h=DMARC-Filter:Received:X-Original-SENDERIP:X-Original-MAILFROM:From: To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=i4JTu0YnlAibI2/elNiz/zd4H9e1qBJlGViIyCn6jTQ=; b=y7ai4/Bv01FyCFKSqcw4NIv+DFR4r+56hTXK2E3x7vjXyUlCW4I3HCYwlQcqRjXiYgxQ V6HhsHBTVkBO+rd4LX9J15ySbaNEN1B1jk1AF0MpwpD9e4z4HRtjJTWOfUrC99cVXnAk7 mbVWr793riVKLeFEnbEhWFs+CsXUpTTuGEoo1WAIFC61u6m+GqANsk+kDvlCstvVqVyxI hCb/zEqC5zz2cb4rBAOAQ2gW2MrfPchI9C77LWIrb2bHnvoQkVR6RO3jwYIavhSvMQWl+ Fdz63w5FfYI+CGl//HEYJXiUo3VzZqizgV2c3CmQ1y5uUvFKFZfWWFEPW8W8+lNwu8g== 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 47F1B606A6AF for ; Wed, 2 Dec 2026 08:48:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 47F1B606A6AF 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:30 +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 2/3] mm: swap: skip swap tiers above the memcg max tier Date: Wed, 2 Dec 2026 17:48:25 +0900 Message-Id: <20261202084826.2131931-3-youngjun.park@lge.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202084826.2131931-1-youngjun.park@lge.com> References: <20261202084826.2131931-1-youngjun.park@lge.com> 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 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 --- 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