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 9F936606A322 for ; Fri, 4 Dec 2026 16:49:02 +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=DCv56AxD Received: by kanga.kvack.org (Postfix) id A9B9F6B05B9; Fri, 4 Dec 2026 11:48:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A26386B05BF; Fri, 4 Dec 2026 11:48:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 962136B05C0; Fri, 4 Dec 2026 11:48:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6FBAA6B05B9 for ; Fri, 4 Dec 2026 11:48:30 -0500 (EST) Received: from smtpin01.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EEBF7C011A for ; Fri, 4 Dec 2026 16:48:29 +0000 (UTC) X-FDA: 85506883938.01.2185969 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf28.hostedemail.com (Postfix) with ESMTP id 5E6FBC000C for ; Fri, 4 Dec 2026 16:48:28 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=DCv56AxD; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796402908; b=p9zUIopdYnEEfvBnfEeCP00blI+TKEaa48XuGoEDGsQEKOqZKxX3fRP4mmlUc5Am//PCod iFWEa8lwgagoktVc7QlQBW3Gr3Y8c52Osrcy88kuwXnsFVQklkZKoQ8rG29ieCwYdlR5dV EAQEcb54btPsiiFhY/ydtHT5PowE5c8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796402908; 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=QVMp5iGIkL5O3Ohmnkss7+/73m0xgjifwuSizj2G3fM=; b=AGQW1NjWmm+wxv+EeS4KpQfZ6uoUg6eHvG1ExRA/MWdMqxov0uDhh2XFq8ljnqLK9THWHB DGksXey0vrFlKNxpX1Bj5GSiynWuZABsS5Bm0zIbHBDucEXFyed20XKq+/guHsfDqTYDC4 VBad+UZmuu97UvpnZSXyRCXwXLSXG6w= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=DCv56AxD; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id DABE8602D4; Fri, 4 Dec 2026 16:48:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F7B51F00936; Fri, 4 Dec 2026 16:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796402907; bh=QVMp5iGIkL5O3Ohmnkss7+/73m0xgjifwuSizj2G3fM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=DCv56AxDjoUj8eCd8iqIp+SrlhzLbd7q2gGJP7M7fWZuPrYwH8niItRwuocACoZ3M 9RiU8d+uvasyTdOz4PrGX+dN/gJ7BqIieaKWgMlL8bnTVg3EIp0YlatAkC6a0smJyc FF7wah35QB0oxRxM9L63Z3c9fGJjmPXO7yNbqLqejaXQAqGwQBUiMpDxpF4tCVBiLS XaT1EqdLuzXF9CyPzWFFNghSyHNxoaBkIGO8jQfQ+0UFaglxJkzJq7UWCk9DOAkGmO 6ATcDuG4zXMVEFp53Q+7FUV4ifphcYCMc9XCK8skoF/Dy6iLWV7Ky8O5GecX5JiERb hKtKW4ti320XQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v8 11/14] mm, swap: add xswap grow trigger on cluster allocation Reply-To: sashiko-reviews@lists.linux.dev To: "Baoquan He" , linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, corbet@lwn.net, chrisl@kernel.org, kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, baohua@kernel.org, youngjun.park@lge.com, kunwu.chan@gmail.com, klarasmodin@gmail.com, "Baoquan He" In-Reply-To: <20261203164336.864691-12-baoquan.he@linux.dev> References: <20261203164336.864691-1-baoquan.he@linux.dev> <20261203164336.864691-12-baoquan.he@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:48:24 +0000 X-Stat-Signature: 7acgx9ghd3p69kn1bsritqnqdsu7ne6n X-Rspam-User: X-Spam-Status: No, score=-11.2 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-Queue-Id: 5E6FBC000C X-Rspamd-Server: rspam01 X-HE-Tag: 1796402908-612897 X-HE-Meta: U2FsdGVkX1/w6ai1FXq638l4xeuVWVsdwEJxDQGP2S3/Z95MvpewSNZhL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fDVS3+7bHpocgj7S9/sXkqxIc8LMNvYAUpxHyCYdrGOyGKzY3oH87j+ttlOnbQr1Tt4S72gPv9RjRDOOzYwJiwH8h3t6RaDUFA4qkCYvYLp9VSFLKP3OtWuHPxZSma2lsPEeNEXF08I59w5cCsoaEIEZNU2tRjCxcKQXNPzgMp3vZId3QzBh+7oW9N1z/CUX7cJRyb9SUBRHyMGFNrKotIKnm6tC3ANkEof7Zy9xwoNNZW+Nt7GMkboM+61MGoKABoOTjts2j9cauUIjGPvDluInv0TgW3u0qm2UU0/mIlIALl7qqY4/BfmqSCW1Jkfl3vrIfbjx7QcRkO6A1/edrBJzEu6SEsFzbzbSTSSaB7mwzKLxQMPtKRjOMvRMmfEpM2vssUPU3K5swrvqzTQ/9rEhXyCOaohlA+QruM3KaN2Qczbd1JI8CxGkYLoxpL/PYb9cPCYKQrU2QP3ZqIRGXXaJ/KU81ZSmt/v7XGGN9aB6jNqmIK2aLGZVMXdvmeexlMFQTZwwERkcIjhVHUFPBTO2ljPgvu1JdGao6v0+YPpoxjSbgL+YgXzrmd4KzCUFF3vr6Xrqi94m6nZx8uzf7f9jmgroFbn3Yta9Z6eqOvpYQWPA13vrPSfomSLN4zbhsXXOY2R9ykNVdA7pmbsk/RqRiBolOmgRXi79lY3KAM1yyNJvxkyfKf+Ilzzs/wQ9nUtt6KKlA6v7//6ENokPY= 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 5 potential issues to consider: - [Medium] mm: xswap_grow() requests multiple chunks when force is true - [Medium] mm: xswap forced grow fails prematurely on concurrent bursts - [Medium] mm: proactive xswap_grow() stalls concurrent allocators on xswap_lock - [Medium] mm: cluster_alloc_swap_entry() rescans lists even when xswap did not grow - [Medium] mm: cluster_alloc_swap_entry() grows xswap when free_clusters is non-empty -- commit b0a141260a703566349e90f3c0ef3c0714bd6db0 Author: Baoquan He mm, swap: add xswap grow trigger on cluster allocation This patch adds proactive and fallback growth of the mapped xswap cluster_info range in cluster_alloc_swap_entry(), growing toward 65% usage in bounded chunks once mapped usage reaches 85% and retrying after a forced grow when no cluster is found. > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 074c5114d129a..4d6a46346b935 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c [ ... ] > @@ -1325,6 +1345,13 @@ static unsigned long cluster_alloc_swap_entry(stru= ct swap_info_struct *si, > if (order && !(si->flags & SWP_BLKDEV)) > return 0; > =20 > +#ifdef CONFIG_XSWAP > + /* Grow before allocating: mapping pages can sleep. */ > + if ((si->flags & SWP_XSWAP) && (si->flags & SWP_WRITEOK) && > + xswap_should_grow(si)) > + xswap_grow(si, false); > +#endif [Severity: Medium] Does this stall concurrent allocators on si->xswap_lock once usage reaches 85%? Since si->nr_clusters_mapped is only updated at the end of xswap_publish_clusters(), other CPUs entering cluster_alloc_swap_entry() while a grow sleeps in vm_area_grow_pages() also call xswap_grow() and block on mutex_lock(&si->xswap_lock) in xswap_map_clusters(). Those waiters then wake up serially just to fail the stale start_idx check with -EAGAIN, instead of allocating from the remaining 15% free clusters. Using mutex_trylock(&si->xswap_lock) for non-forced grows would let them proceed while one grow is already in flight. [ ... ] > @@ -1397,6 +1424,22 @@ static unsigned long cluster_alloc_swap_entry(stru= ct swap_info_struct *si, > if (found) > goto done; > } > + > +#ifdef CONFIG_XSWAP > + /* > + * A burst of allocators can hold every mapped cluster while usage is > + * still below the growth threshold. Grow and rescan all lists: a > + * cluster published by another grower may already be on a frag list. > + */ > + if (!found && (si->flags & SWP_XSWAP) && > + (READ_ONCE(si->flags) & SWP_WRITEOK) && !retried) { > + retried =3D true; > + if (READ_ONCE(si->nr_clusters_mapped) < > + READ_ONCE(si->nr_clusters_max)) > + xswap_grow(si, true); > + goto new_cluster; > + } > +#endif [Severity: Medium] Can a concurrent burst still fail allocation here while unmapped clusters remain below si->nr_clusters_max? Because xswap_grow() collapses -EAGAIN from xswap_map_clusters() to 0 and retried caps the fallback to a single attempt, excess threads in a burst (more than XSWAP_GROW_CLUSTERS) or a thread racing with an in-flight grow can lose the newly published clusters and return 0: CPU0 CPU1 cluster_alloc_swap_entry() cluster_alloc_swap_entry() !found, retried =3D true !found, retried =3D true xswap_grow(si, true) xswap_grow(si, true) mapped =3D N mapped =3D N xswap_map_clusters(N, ...) mutex_lock(&si->xswap_lock) mutex_lock(&si->xswap_lock) publish N + chunk mutex_unlock(&si->xswap_lock) start_idx !=3D nr_clusters_mapped return -EAGAIN (returned as 0) goto new_cluster isolate new clusters goto new_cluster lists empty, retried =3D=3D true return 0 <-- premature -ENOMEM Once another thread isolates the new clusters (which stay off-list while swap_cluster_populate() can sleep), CPU1 cannot retry a forced grow and folio_alloc_swap() fails with -ENOMEM despite unmapped clusters remaining. [Severity: Medium] Should goto new_cluster be skipped when si->nr_clusters_mapped did not advance? When nr_clusters_mapped has already reached nr_clusters_max, or when xswap_grow(si, true) fails with -ENOMEM, this still jumps back to new_cluster and repeats the entire scan across all cluster lists and swap_reclaim_full_clusters() on every failed allocation. Snapshotting nr_clusters_mapped before new_cluster and retrying only if xswap_grow() succeeded or nr_clusters_mapped increased would avoid the redundant pass while still catching clusters published by another grower. [Severity: Medium] Can this grow xswap even when si->free_clusters is not empty? If swap_cluster_populate() fails (for example with -ENOMEM in swap_cluster_alloc_table() or -EAGAIN), it returns the cluster to si->free_clusters and returns NULL, which makes alloc_swap_scan_list() break out and return 0 while free clusters remain on the list. When nonfull and frag lists have no slots, cluster_alloc_swap_entry() then calls xswap_grow(si, true) without checking list_empty() on si->free_clusters, mapping additional permanent vmalloc pages for cluster_info even though free clusters are already available. [ ... ] > +static unsigned long xswap_grow(struct swap_info_struct *si, bool force) > +{ > + unsigned long mapped =3D READ_ONCE(si->nr_clusters_mapped); > + unsigned long nr_new, want; > + int ret; > + > + lockdep_assert_held(&this_cpu_ptr(&percpu_swap_cluster)->lock); > + > + want =3D DIV_ROUND_UP(swap_usage_in_pages(si) * 100, > + XSWAP_GROW_UNTIL * SWAPFILE_CLUSTER); > + if (want <=3D mapped) { > + if (!force) > + return 0; > + nr_new =3D XSWAP_GROW_CLUSTERS; > + } else { > + nr_new =3D rounddown(want - mapped, XSWAP_GROW_CLUSTERS); > + } > + if (!nr_new) > + nr_new =3D XSWAP_GROW_CLUSTERS; > + if (nr_new > XSWAP_GROW_CHUNKS * XSWAP_GROW_CLUSTERS) > + nr_new =3D XSWAP_GROW_CHUNKS * XSWAP_GROW_CLUSTERS; [Severity: Medium] Should xswap_grow() cap nr_new to a single XSWAP_GROW_CLUSTERS chunk when force is true? Here force is only checked in the want <=3D mapped branch. Whenever usage exceeds 65% (XSWAP_GROW_UNTIL), want > mapped holds and a forced grow takes the else branch, requesting up to XSWAP_GROW_CHUNKS (4) chunks instead of the single chunk described in the commit message. Because vm_area_grow_pages() is all-or-nothing under memalloc_noreclaim_save() and __GFP_NOMEMALLOC, if the proactive 4-chunk grow fails with -ENOMEM under memory pressure, the fallback xswap_grow(si, true) repeats the exact same 4-chunk request and starves swap allocation even when a single page is available. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203164336.8646= 91-1-baoquan.he@linux.dev?part=3D11