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 12997606A32E for ; Mon, 30 Nov 2026 15:10:06 +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=jRI5bySn Received: by kanga.kvack.org (Postfix) id A8E536B05B8; Mon, 30 Nov 2026 10:09:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A66126B05B9; Mon, 30 Nov 2026 10:09:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92D926B05BA; Mon, 30 Nov 2026 10:09:54 -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 0A85C6B05B8 for ; Mon, 30 Nov 2026 10:09:54 -0500 (EST) Received: from smtpin16.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E9FF9120AE2 for ; Mon, 30 Nov 2026 15:09:49 +0000 (UTC) X-FDA: 85492120098.16.85AADAF Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf14.hostedemail.com (Postfix) with ESMTP id 30FAF10001A for ; Mon, 30 Nov 2026 15:09:48 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=jRI5bySn; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.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=1796051388; b=wo5C9vkvsqwUiKBRqQSsNWBEIoYi9cxD6QuBplzFmBbuAKplS0xtQMhxlNz+yCQcmXmVUS TrLsTonAM3jBVIfrXeXDasSCrI3vlb0212+a0f+d2xCVCKizxQQ+hsjF8xfTtnH533cTxc 1KueuOV0br4lQBIIIK2iThIp+t2Shu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796051388; 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=7mhpHzgfpnxKFVUGMpf1CFipe7f7TC4bR+HJj4lqSpE=; b=lDM2H5WcNCRyXo73kXTeygUtLrQ+6rWF/iLyA8yrAy+XfJZaFMTp31c8xjdyO8fPJXAosm /Bz+cTc16dzLQn0EnOdpIehbzlLks2FOVy9eNO+/hVIdrEqKpe4TyAawh+s7Ym5vQvil7S rPqrlauyQx8imwzN+m6PrEWP1G35hZk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=jRI5bySn; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf14.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 5FF4B61CCF; Mon, 30 Nov 2026 15:09:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E57091F0089A; Mon, 30 Nov 2026 15:09:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796051386; bh=7mhpHzgfpnxKFVUGMpf1CFipe7f7TC4bR+HJj4lqSpE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=jRI5bySnYWnUy0tKJUEKCan5iA+hQjycjxwqGCgP1948i53ptfExgFtUcGgPhw6ao AGfxPOb6a40ozkWWUJ6UQeQk3Av6XHA35qvWrELcfrp/iyH4nKV5P2PNQnbqfJt8ub 5BIkUABI33hcCXt7SIInCG6m0y9Mu5+8+AGHX8eCNp3vutL1mrBXFEgumppzHBLQT9 vxMoImx5XUlY4/IRnKAajsLtR4OQN6XOlzESfdODLDY4NtlEUoPmjOJ7dxaX7uHHyB YfgTb+NHns8vNgD8FIdy2uP9xP2EeHSdnx3I5xHJTB5fBwuE6ZY74CX3nft48FfCed I+YWzGm484P0w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org, corbet@lwn.net, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, shikemeng@huaweicloud.com, yosry@kernel.org, chengming.zhou@linux.dev, kunwu.chan@gmail.com, klarasmodin@gmail.com, "Baoquan He" In-Reply-To: <20261129150755.191662-14-baoquan.he@linux.dev> References: <20261129150755.191662-1-baoquan.he@linux.dev> <20261129150755.191662-14-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 15:09:45 +0000 X-Stat-Signature: bo9b4y9yhyzdzi8i7ck4o4k45o6z1jt8 X-Rspamd-Queue-Id: 30FAF10001A X-Rspam-User: X-Rspamd-Server: rspam03 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-HE-Tag: 1796051388-398292 X-HE-Meta: U2FsdGVkX1+URIGPFItc2mL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sxf3mwBMtgYjLFUR8CgnNIKczklvHBrO3lgMW8Ggkosmf/9O0DUtZAP+DfKhDO00JzH2dcFlauFfnNYzO4m9uJ9j+zuP4ga8E7fbOiERXej/nr+1rNc9kUnYXgZelZRacnkWyCMowrbWfbuDseIGpLwh3I0rAU1Uq70hSJ+z6b+/9ABciC568wGT1SSoJUUBsFSO1SRoYP52y8Awmx0mgdb1KOCgsU+pz8dASL2fXXbyLhz0RFYuczyHLSReo4979iPRVhE2qghdCJnA5y7vqiWte4/XUuQTnxXWvNBug8f/qMGkaI7g8sg2JiwIFeS3Vru7AZI8BBuX1AesMMuG7YOL1hPzRyv0iltq/vXJrgF8lZFCqNhB+uHsLzrc/b2hKyse8qnCzoAff9kL6CLSc7aMHEd2Rgg24QL4PsUemxGYHZKAjeaNIT0DDYTnfem+A9phjfclKZsWQcqx1YeS8WhHXLRM8Wuxk6hdwRNuOFAspKKmyTfPDCHpa/nBnd2JlQDDkKxFaqQRwoL/cJis88Nnnn1QdOj4S1p/FdqMmelI7ycro9zX75EJHKL91Dt+CAw0SBzwr4UKluSYEgizInck9hKjb0gmvwNOzGDMhVWL1J1BT7mKXBUaW7xmNE6HOoUnVP7uM+2BjMYk4JuAdE3B2ge/Zsqpkac1cPgjkzzcMDVo6LujcxmJWiEwfL7Aeir0tOtljQaAgiIZdCPDxAmHEy6TLXnArAFazXwxzb1tO9YcWEjw/iW+EgE8iwNJZCuzw4= 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 3 potential issues to consider: - [High] mm, swap: no_cache in alloc_swap_scan_cluster() fragments SSD free clusters - [Medium] mm, swap: early goto failed in folio_alloc_swap() skips MEMCG_SWAP_FAIL - [Medium] mm, swap: folio_alloc_swap() returns -E2BIG when real swapfiles are full -- commit 635affe850d5047e3d0a27127b5b71819aadffb6 Author: Baoquan He mm, swap: do not give an xswap slot to a cgroup that cannot zswap This commit skips xswap devices during swap slot allocation when the folio's cgroup cannot accept another zswap page, falling back to physical swap devices instead. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 8b2082bdac082..3a84dbd7a54c6 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -1197,7 +1199,7 @@ static bool swap_prefer_free_cluster(struct swap_in= fo_struct *si) > static unsigned long alloc_swap_scan_cluster(struct swap_info_struct *si, > struct swap_cluster_info *ci, > struct folio *folio, > - unsigned long offset) > + unsigned long offset, bool no_cache) > { > unsigned long next =3D SWAP_ENTRY_INVALID, found =3D SWAP_ENTRY_INVALID; > unsigned long start =3D ALIGN_DOWN(offset, SWAPFILE_CLUSTER); > @@ -1238,6 +1240,9 @@ static unsigned long alloc_swap_scan_cluster(struct= swap_info_struct *si, > relocate_cluster(si, ci); > swap_cluster_unlock(ci); > if (si->flags & SWP_SOLIDSTATE) { > + if (no_cache && > + this_cpu_read(percpu_swap_cluster.si[order]) !=3D si) > + return found; > this_cpu_write(percpu_swap_cluster.offset[order], next); > this_cpu_write(percpu_swap_cluster.si[order], si); > } else { [Severity: High] Does skipping the percpu_swap_cluster update when no_cache is true fragment si->free_clusters on SWP_SOLIDSTATE physical swap devices? For SWP_SOLIDSTATE devices, relocate_cluster() moves a newly allocated, partially used cluster straight to si->frag_clusters[ci->order], relying on percpu_swap_cluster to retain the cursor for the remaining free slots. When a cgroup with !may_zswap falls back to a physical SSD while percpu_swap_cluster.si[order] is NULL or points to the higher-priority xswap device, returning early discards next. The next !may_zswap allocation on that CPU misses swap_alloc_fast() and re-enters cluster_alloc_swap_entry(), which drains another fresh cluster from si->free_clusters before consulting si->frag_clusters[order]. Each order-0 allocation therefore strands a 2 MiB free cluster on si->frag_clusters[0] with only 1 of 512 slots used, exhausting free clusters for large folio allocations. Conversely, if percpu_swap_cluster.si[order] already equals the physical device si (for example, left over with offset =3D=3D 0 after a previous cluster filled up), this check is false and caches next on the physical device, causing subsequent may_zswap allocations on this CPU to use the lower-priority physical device instead of xswap. [ ... ] > @@ -2017,10 +2063,17 @@ int folio_alloc_swap(struct folio *folio) > } > } > =20 > + /* > + * Only xswap devices exist and this folio cannot use them; there is > + * no slot to find. > + */ > + if (!may_zswap && !atomic_read(&nr_real_swapfiles)) > + goto failed; > + > again: > local_lock(&percpu_swap_cluster.lock); > - if (!swap_alloc_fast(folio)) > - swap_alloc_slow(folio); > + if (!swap_alloc_fast(folio, may_zswap)) > + swap_alloc_slow(folio, may_zswap); > local_unlock(&percpu_swap_cluster.lock); > =20 > if (!order && unlikely(!folio_test_swapcache(folio))) { > @@ -2028,6 +2081,20 @@ int folio_alloc_swap(struct folio *folio) > goto again; > } > =20 > + /* > + * The gate was skipped when there was no device; one may have > + * appeared since, so ask the slot itself. > + */ > + if (unlikely(!zswap_checked && folio_test_swapcache(folio) && > + (__swap_entry_to_info(folio->swap)->flags & SWP_XSWAP))) { > + zswap_checked =3D true; > + may_zswap =3D folio_may_zswap(folio); > + if (!may_zswap) { > + swap_cache_del_folio(folio); > + goto again; > + } > + } > + > /* Need to call this even if allocation failed, for MEMCG_SWAP_FAIL. */ > if (unlikely(mem_cgroup_try_charge_swap(folio))) { > swap_cache_del_folio(folio); [Severity: Medium] Does jumping directly to failed when !may_zswap && !nr_real_swapfiles skip MEMCG_SWAP_FAIL accounting in mem_cgroup_try_charge_swap()? In addition, because again is placed after that check, if the post-allocati= on !zswap_checked path detects !may_zswap after racing with xswap activation, goto again bypasses the !nr_real_swapfiles shortcut and scans the swap lists even when no real swapfiles exist. > @@ -2045,6 +2112,13 @@ int folio_alloc_swap(struct folio *folio) > if (mem_cgroup_get_folio_swap_margin(folio) <=3D 0) > return -ENOMEM; > =20 > + /* > + * Only xswap devices exist and the folio cannot use them; splitting > + * cannot help. > + */ > + if (!may_zswap && !atomic_read(&nr_real_swapfiles)) > + return -ENOMEM; > + > return order ? -E2BIG : -ENOMEM; > } [Severity: Medium] Can folio_alloc_swap() still return -E2BIG for a !may_zswap large folio when all real swapfiles are full? del_from_avail_list() only decrements nr_real_swapfiles on swapoff, not when a real swap device fills up, while get_nr_swap_pages() includes free pages on xswap devices. If real swapfiles are active but full and xswap still has free pages, both get_nr_swap_pages() <=3D 0 and !nr_real_swapfiles are false, so folio_alloc_swap() returns -E2BIG and causes callers to split the large folio even though order-0 swap allocation cannot succeed either. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129150755.1916= 62-1-baoquan.he@linux.dev?part=3D13