From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67C22606A32D for ; Thu, 3 Dec 2026 08:48:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HCoM1zkk Received: by kanga.kvack.org (Postfix) id 8211E6B05BA; Thu, 3 Dec 2026 03:48:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F94B6B05BB; Thu, 3 Dec 2026 03:48:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 734AE6B05BC; Thu, 3 Dec 2026 03:48:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2A3896B05BA for ; Thu, 3 Dec 2026 03:48:48 -0500 (EST) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A52DD120603 for ; Thu, 3 Dec 2026 08:48:47 +0000 (UTC) X-FDA: 85502046294.03.818A452 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf07.hostedemail.com (Postfix) with ESMTP id 1B2F840006 for ; Thu, 3 Dec 2026 08:48:45 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=HCoM1zkk; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796287726; b=w/szr8hw+QrvXh5C7t9dsnAPeLqTm8Est8SpVtRVSo/oBP3obUw83/GvoR5GOB9kJF5jGr ZhMFcLpd1U6CNiSyZ8ymi9g2LcHfCT/McggfLVktB28uo4UJXbcdZsRYM8K0SqhaZjm+XS fy3PXzRiyISl4xr9aU+N9Q4sStaV/yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796287726; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2b6WuG01cO3LON0WlYn7FFNjl9N5dULbnoCO833Ew0k=; b=wPd2fp1Iq22F5WtSGvbWXccTcn7VNHPjMh3Dlg5DRCA6h4TkJtJSWywIbPAYL/YdR3/6Hz IM80jxqkwU5+cIe0zhX89b+KC7Hi7jccVN4l0+QY3snd+T1ECC5naFB3/lm2R1PxiLBZe0 PWuUkQqKUdjXPFm3UF8srAOMj3eZVe8= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=HCoM1zkk; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id A729A6203B; Thu, 3 Dec 2026 08:48:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D35461F00893; Thu, 3 Dec 2026 08:48:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796287725; bh=2b6WuG01cO3LON0WlYn7FFNjl9N5dULbnoCO833Ew0k=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HCoM1zkkSJ3waFLrgQt/eQwnhQLda2WdbX3b+4l6uDD2tn6CsMOPQIBSQ03H4A4oB EcltgCzR6Rt9Y+PD6L5vPTSJuK1ErQkDs0Tu/AN+f1GIOJgeBpq/XGBJe3/bdTFAV6 2JNEACLaJtlmBUAW6/le6fE830TcEnJspmgFCFD9lhRrVkEjIImTQICXWVlrfwWxJs VRLBXyYOelNiX4793+2gm+nyFtJmywcTiKJq79JjMpeG8ljtGUUWf4LaOvGvUNgHpK Ci2yFk7chkD19KmVI2nhHXvgDe9hS2DKvJBjWUd+o5axYYzXgOBMGBcANNqL/2yEAc GA34kzVIgSS1w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v12 2/3] mm: swap: skip swap tiers above the memcg max tier Reply-To: sashiko-reviews@lists.linux.dev To: "Youngjun Park" , "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 In-Reply-To: <20261202084826.2131931-3-youngjun.park@lge.com> References: <20261202084826.2131931-1-youngjun.park@lge.com> <20261202084826.2131931-3-youngjun.park@lge.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 08:48:44 +0000 X-Rspamd-Queue-Id: 1B2F840006 X-Rspam-User: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspamd-Server: rspam03 X-Stat-Signature: jp3gbx35a1d6mou43gdi7yxutm4pxhrd X-HE-Tag: 1796287725-212791 X-HE-Meta: U2FsdGVkX1+J3lrQe4mRnQ2e9RSoC3UmcT2Oyh4o8IQuhkMYNwdqgkdwnvUHFf60KS+CX5zJAnjpR/1cRwQXvcjQ93mEL6IsYhSUgtCRe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KlXKvylAJsxCMniL0bRd3pzLKxR6mprw3coJaXrAuy8HbAuMkUWm8iGZsN30ELIMJa6YGQkjc2zeLFAWf8oV0FHevQkcWyX7YYvD16rZlsDvd7rva27SVj54PuSe4KL17p+uPMOkZJ49UnnW58tnRtLW+lZSJ5vg6TCTT5ZSK+zAgk4vDk2YWh2gOzD/pIVTk9RIh66owPv0DUwUTz8TvvFLi2ZF7UBoXigMAawNd0tpeVPrZdPQl2/OYwDw2Rzu01iycyNyr6XMIgHuTY2YLowtfTMw5XzzBJehZJ2diua4OKva3NS9b3gLbN0mULlvKdw90L2Jof+iXM53XvevAdt3eihsEf/hi55mJ5ZqqFvqJOpMg2W7wMYoLW0uHrv9ZZmJk9/tjBC7rOV9hZ1zqLLwMN7o0P2Wt9S7WYDAShCvrupCHc0eD58zjYahHTqwHkhHqnh7qx6kIDB4eYyBOYxs1Deox+rqIrmbSFlqeNuSpdRfuY98G7z61u7M/HG/Zu1GsrJV/NY27AYg95NJjHj97fGjjPtJQxaDHs9SinxbDHr0tYUuolXVJPpwucayAlue5eX0rqK2DhsXmpJcM1oGo26yA3VEEiMEPiGcY1r97yn4MzG1+21gE1VU7u5Z34SHZFo1b6ZJbDPDCsK1mLBeG2hmbsoJdiWUBWrCIlR8uJcfqk1xKUHCCTs91WH7hFZM= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] mm: swap: broken percpu_swap_cluster handling in swap_alloc_fast() - [Medium] mm: swap: unfiltered discard and -E2BIG return in folio_alloc_swap() -- commit c316a03b87811115cdd04e1144bda00848de29fa Author: Youngjun Park mm: swap: skip swap tiers above the memcg max tier This commit introduces a swap_memcg_max_tier() helper and skips the per-CPU cluster fast path for tier-limited memcgs while filtering out swap devices above the memcg's maximum tier in swap_alloc_slow(). > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 95928d9f85da0..d30ee41f82176 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1439,6 +1439,15 @@ static inline short swap_tier(struct swap_info_str= uct *si) > return si->prio; > } > =20 > +/* > + * 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 =3D this_cpu_read(percpu_swap_cluster.si[order]); > offset =3D 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) !=3D SWAP_TIER_MAX) > + return false; > + if (!get_swap_device_info(si)) > return false; [Severity: High] Does skipping swap_alloc_fast() whenever swap_memcg_max_tier(folio) !=3D SWAP_TIER_MAX cause every allocation on a SWP_SOLIDSTATE device to isolate a new cluster from si->free_clusters while still installing the lower-tier cluster into percpu_swap_cluster? When swap_alloc_fast() returns false, swap_alloc_slow() calls cluster_alloc_swap_entry(si, folio). On SWP_SOLIDSTATE devices, cluster_alloc_swap_entry() does not use si->global_cluster; it jumps to new_cluster: and pulls a fresh cluster from si->free_clusters via alloc_swap_scan_list() -> alloc_swap_scan_cluster(): mm/swapfile.c:alloc_swap_scan_cluster() { ... out: relocate_cluster(si, ci); swap_cluster_unlock(ci); if (si->flags & SWP_SOLIDSTATE) { this_cpu_write(percpu_swap_cluster.offset[order], next); this_cpu_write(percpu_swap_cluster.si[order], si); } else { si->global_cluster->next[order] =3D next; } return found; } After allocating a single folio, relocate_cluster() moves the cluster with its remaining free slots onto si->frag_clusters[order] and caches the rest of the cluster in percpu_swap_cluster. Because a limited memcg never uses swap_alloc_fast(), its next allocation isolates yet another cluster from si->free_clusters instead of consuming the remaining 511 slots, draining si->free_clusters after 1/512th of the device is used and starving large folio allocations. At the same time, an unlimited memcg running on the same CPU passes the check in swap_alloc_fast() and allocates from the lower-tier device left in percpu_swap_cluster. > =20 > ci =3D 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 =3D swap_memcg_max_tier(folio); > =20 > 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); [Severity: Medium] When all swap devices with swap_tier(si) <=3D max are full while higher-tier devices still have free space or pending discards, how does folio_alloc_swap() handle the failed allocation? mm/swapfile.c:folio_alloc_swap() { ... if (!order && unlikely(!folio_test_swapcache(folio))) { if (swap_sync_discard()) goto again; } ... failed: if (get_nr_swap_pages() <=3D 0) return -ENOSPC; if (mem_cgroup_get_folio_swap_margin(folio) <=3D 0) return -ENOMEM; return order ? -E2BIG : -ENOMEM; } For a large folio (order > 0), get_nr_swap_pages() is still positive because the higher-tier devices have free pages, so folio_alloc_swap() returns -E2BIG instead of -ENOMEM and causes shrink_folio_list() and shmem_writeout() to split the folio and retry order-0 allocations that also cannot use the higher tier. For order-0 folios, swap_sync_discard() walks swap_active_head without checking swap_tier(si) <=3D max, so it synchronously discards clusters on disallowed higher-tier devices and loops back to again: even though swap_alloc_slow() will skip those devices. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202084826.2131= 931-1-youngjun.park@lge.com?part=3D2