From nobody Sun Dec 7 20:02:23 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 457DB2DC79D for ; Mon, 6 Oct 2025 20:03:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780990; cv=none; b=P/GNpudiw1PRr306BzAPKks0qJMfySR9vveB1cLimEb/88iHlAe0oe4OiTBstdx/KCjjye1zz2AEjBnNn3+MELJV2/S2q4b096P2AiXMN66TaQhXbtHE/mnH81URPIez8WCBgBdN7bKYckFhzoyWdyTfn2T+wuTrEvj/jm9nZCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780990; c=relaxed/simple; bh=Sq9BZkzhI30LkCNbkX6MyuInjbp5KHwDN549JuJlWgw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NiZ20zI7DsIr1X5hmaquXReTR+YX6VrcptCzFaEsk5m9r/oF57t5n4XViPnf+C8hQ5uoMkp2moKu8Y39fArfikwGZIBlXays87OXbA5jiFz2YNNUxkqtXi5F8BODtNKzeEQ2I7tJ4aK+y6bmo0kZ+sZb8z4xfDHJXw50z7Ev+8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=izBSrTzq; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="izBSrTzq" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-3306d93e562so5885937a91.1 for ; Mon, 06 Oct 2025 13:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759780988; x=1760385788; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/FfTKpzDhNY44hq6VBsPjCO9xlzMvi5CioCxjggBxGo=; b=izBSrTzqIrbOb2CvT1BZWhYTSG7nRvyhBYL0g/pNXtOiZmqGbYMYXU4QHXjXbFVfq5 kanMiwI1tLAbM0XAvST0kmBcVlpAxVvE+gd13ZQwhkzm8tn9GPW7El/GI9grq2+Rcm35 nIEZoNgALAQ71f2SWfNHqSUw8mIifmmzKcqCrEUIZO8gK5I+UHfenqHzusd+ohNPtOom +RdJxth/baoTYapNYGrQkLmUEb/XCzywL06CAc4lwn6R+tnvYpnY7qWd/H6pKDZKF2v5 gV0430vQD6QCFqYO6ht7eA3qTNOiWTr71fogrrHNsBK0h1B8MYbwrgRQlnGW9hBwlUSz F+jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759780988; x=1760385788; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/FfTKpzDhNY44hq6VBsPjCO9xlzMvi5CioCxjggBxGo=; b=LFQ2XPpl1NmtiKIFzS+Poo1gL2/PL/CZD7A9dHQ4F7R6Kt9DGAt/Bi+yfZOE39mtH6 nqXEH+JuZ1qqyKvv+RKdyHsz+IbwqQL8HE8rwFDbnrq5Ei1lMNhv0bTCVveI1rlhDcZI X2AKJin4M99aWvwOfJ/poi6FPx64+2XE0cYvkqo11E62FDZEoGZ7X9L6nP2w8RdA5pvd vnD5UooAqoPClw4eEBXsq3mCAfs1VpRVw+RJaic1oHyz71FxUVy3fYmD2qFQ8UENPcBD mlbVjfW6Q/d8HW/8znLHR4EfZq00slwicjbW5LZNijci3ncjDGOdsiirQcjWHhfOrr6p A0fg== X-Forwarded-Encrypted: i=1; AJvYcCWwk06YCaRET7ZiX1e0pBYhkattWMcf7chPbjymYln7tIeUKnbvOlT0QKlFVdgnalkN+oh0oF85Lp/bOq0=@vger.kernel.org X-Gm-Message-State: AOJu0Yy8pZ2W6o3UMXFu4G9izdEGFHWbr0gXSvd6eAh8/1dFw4e7Xatd OYyqm5hEyfOwbYRQtuthOBSDha0hUBc56NK/1LKplIEZyZGj1OTlmc7H X-Gm-Gg: ASbGncu/C+kItRuxOihmeoTkH4alY+ES+NEYe9hBLxM9sHwvCI6MrVVm4HqsRhcVIW5 X6FfiaIcnD5xL69Qy8KzYmYuyNXaPaIqlunC8GaJ3j3hrQmELDcLsyZ796OiDeBqueIWm22jY4I e8BYCJImb3Up/mu6oc/YXc16Bw01KZ/x/BsStSJVih7Yf553lpSuOwTG7LrYHye9POzxqE4xURY 9wX13JYFA3h/rpVBDJ2Y+wJpdQUCCFqjvqYSCbshd7B17Jb08XL9v7TBNtQDPQz5019HhMphhf5 QggT8OOEMfcE3G9yX2DJeZ5Y6/Xm2dMZLSAb/RUJjF9K0JGKsxxA3XB/F4mXOKCYCdmyZ8QwXWu pE/ZgjQ2e8RZMQ2WYkkuMH+SR+v4uBFTi7rIdBRyWuzNk2xtKirwNxasOWvu926g= X-Google-Smtp-Source: AGHT+IGKgvoWh2AlA1gEXZJS741XwWofagS2eT43KDPpL42IYIXONw/GpTUsn2xjQoYVEGK0eUrkbg== X-Received: by 2002:a17:90b:5807:b0:339:dcc3:82ca with SMTP id 98e67ed59e1d1-339dcc38971mr8109209a91.6.1759780988397; Mon, 06 Oct 2025 13:03:08 -0700 (PDT) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-339ee0ba20asm163148a91.4.2025.10.06.13.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Oct 2025 13:03:07 -0700 (PDT) From: Kairui Song Date: Tue, 07 Oct 2025 04:02:33 +0800 Subject: [PATCH 1/4] mm, swap: do not perform synchronous discard during allocation Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251007-swap-clean-after-swap-table-p1-v1-1-74860ef8ba74@tencent.com> References: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> In-Reply-To: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , Chris Li , Baolin Wang , David Hildenbrand , "Matthew Wilcox (Oracle)" , Ying Huang , Kairui Song , linux-kernel@vger.kernel.org, stable@vger.kernel.org X-Mailer: b4 0.14.3 From: Kairui Song Since commit 1b7e90020eb77 ("mm, swap: use percpu cluster as allocation fast path"), swap allocation is protected by a local lock, which means we can't do any sleeping calls during allocation. However, the discard routine is not taken well care of. When the swap allocator failed to find any usable cluster, it would look at the pending discard cluster and try to issue some blocking discards. It may not necessarily sleep, but the cond_resched at the bio layer indicates this is wrong when combined with a local lock. And the bio GFP flag used for discard bio is also wrong (not atomic). It's arguable whether this synchronous discard is helpful at all. In most cases, the async discard is good enough. And the swap allocator is doing very differently at organizing the clusters since the recent change, so it is very rare to see discard clusters piling up. So far, no issues have been observed or reported with typical SSD setups under months of high pressure. This issue was found during my code review. But by hacking the kernel a bit: adding a mdelay(100) in the async discard path, this issue will be observable with WARNING triggered by the wrong GFP and cond_resched in the bio layer. So let's fix this issue in a safe way: remove the synchronous discard in the swap allocation path. And when order 0 is failing with all cluster list drained on all swap devices, try to do a discard following the swap device priority list. If any discards released some cluster, try the allocation again. This way, we can still avoid OOM due to swap failure if the hardware is very slow and memory pressure is extremely high. Cc: Fixes: 1b7e90020eb77 ("mm, swap: use percpu cluster as allocation fast path= ") Signed-off-by: Kairui Song Acked-by: Nhat Pham --- mm/swapfile.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index cb2392ed8e0e..0d1924f6f495 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1101,13 +1101,6 @@ static unsigned long cluster_alloc_swap_entry(struct= swap_info_struct *si, int o goto done; } =20 - /* - * We don't have free cluster but have some clusters in discarding, - * do discard now and reclaim them. - */ - if ((si->flags & SWP_PAGE_DISCARD) && swap_do_scheduled_discard(si)) - goto new_cluster; - if (order) goto done; =20 @@ -1394,6 +1387,33 @@ static bool swap_alloc_slow(swp_entry_t *entry, return false; } =20 +/* + * Discard pending clusters in a synchronized way when under high pressure. + * Return: true if any cluster is discarded. + */ +static bool swap_sync_discard(void) +{ + bool ret =3D false; + int nid =3D numa_node_id(); + struct swap_info_struct *si, *next; + + spin_lock(&swap_avail_lock); + plist_for_each_entry_safe(si, next, &swap_avail_heads[nid], avail_lists[n= id]) { + spin_unlock(&swap_avail_lock); + if (get_swap_device_info(si)) { + if (si->flags & SWP_PAGE_DISCARD) + ret =3D swap_do_scheduled_discard(si); + put_swap_device(si); + } + if (ret) + break; + spin_lock(&swap_avail_lock); + } + spin_unlock(&swap_avail_lock); + + return ret; +} + /** * folio_alloc_swap - allocate swap space for a folio * @folio: folio we want to move to swap @@ -1432,11 +1452,17 @@ int folio_alloc_swap(struct folio *folio, gfp_t gfp) } } =20 +again: local_lock(&percpu_swap_cluster.lock); if (!swap_alloc_fast(&entry, order)) swap_alloc_slow(&entry, order); local_unlock(&percpu_swap_cluster.lock); =20 + if (unlikely(!order && !entry.val)) { + if (swap_sync_discard()) + goto again; + } + /* Need to call this even if allocation failed, for MEMCG_SWAP_FAIL. */ if (mem_cgroup_try_charge_swap(folio, entry)) goto out_free; --=20 2.51.0 From nobody Sun Dec 7 20:02:23 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8782A2DE1F0 for ; Mon, 6 Oct 2025 20:03:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780995; cv=none; b=rz1Jze6yrCFNpx+yzOeNR5s3OL6Hq5wGSnUWjfvE5fPIBzGF3DFpsy0UVJtwCJXBvvUbNZYBZbcoGtUflF5Oggt4lDg329yZ+nUZm4u/jB/cSW6jyS42+8qgMxdOlmmPlsunalKL0iH2lJRm8gj6vc81fHifGYi2L7U+mO+JIwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780995; c=relaxed/simple; bh=9q7atItYA1TlcduEE3c+VIaxBOMZXl/TTmoi3n+8OJ8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D1b7fsFOlZFDadyjMdRikpP1412H5yOeNn/CK9GSEEkp2zfEO24u5xjLcOTLPC50KaMVeKdS94d4oHCXh+SiJEXdmmQcXP2fQkzS9X8rQiCeMKtqxa4JWS7LFkWlKGWQxUBaG85n7uPBO4Z5VaLAVoHmYqDu1vY1gk/Ywt5LrEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ndopRxne; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ndopRxne" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-336b9473529so4998540a91.1 for ; Mon, 06 Oct 2025 13:03:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759780993; x=1760385793; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=VextjEGcnlm32GGbyDeUjgrLV8IU5CS7mWQhtH32SsI=; b=ndopRxnexzdJTQ85qNNwCSjDhYCIK0cscoxLcsG7TOQb+CR+AolnzX/j+r7IF6uPCj 0fk64S4rAoYeqcDEQlXNZrNkrN4z2s14QCTv/K+SoiSBVPCqwK+pTh6fZjA9TT2Fh2+N VSPvxXEFU4UImIFT5fB80j6YdkSz/B0QaiVnHbZ76k16x3AqbW//ZCc/jnnXRR7hy/fR XFTSdrDHlVX0wfi6HcfAj0/k5ZLHtogDnETP0z23YhalD5WEYiOzLKYE9i2A3zLiI+Wh 6NYvKbJeiQUqju/4ShJscG7Usy+G/j5K8Cxx85lFAPtN9/Oq4Pg6UMvQX94d/NOmMf8B BTRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759780993; x=1760385793; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VextjEGcnlm32GGbyDeUjgrLV8IU5CS7mWQhtH32SsI=; b=vj+41mP3idUsbZ27WfKTOj1/N9dG9WO/od7sO+u8+OoW4RzFo+510enGPyR2mvded7 ae26DRCYvr2gJUsWJZcOX1mR9abDzoeo+3XotnSAHtRvF+nQYr+LTi4WKNM2gbMSIr7y MfESg5UneGWgDikRW5/hm8FqVKDmerPwMQBmi+ls1f6JjUxtEff3tsdAPzJgwVg8GyrO MusrgxlHOHwPqQCHjvvkykGz8PL29aAexb9Ki7FhxWoGXK/oxTDYNFG4iPy+bcu8TJ25 SByNKPsoumMU6d5bgLDV9xEHsPU+Wa70qzKPhN7cRf2gM0GT37hp/O1D2LkuqfqV82Tj gi1w== X-Forwarded-Encrypted: i=1; AJvYcCXvquTDVI6H6fA2OeEX8kO8rBflLisIwSFC6kv8GDQAZ+Qpvn8bcBvjlKLH3ga7WTI/U2RshP65ThruncA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmj7rAPew66Ui8PzmD8BLv8ObXckd+1GquyU59jgmxxOnb79K3 pYod1He++jGCRNPC0HTlhbCF/ZvQUwcTV9kgT8J0mR7rS0Cvytt3B14W X-Gm-Gg: ASbGncsLfjmbFxFmI9fMPr8F84hwO3cg7HpFPKElPIT4iWFvYYvajNEsTE+fC6TfHzS Eo7jv+0iRI7U2MX3yr0zyPDVpvmw7y5ww/R1EY64BlPQ4dyzcn3JKRRsbX2nRErG3sb1QTPXiTy EeUeY5JQ0vzATHvYp+RkGol9aG5HutIlkZf/G+AE17A1XR1k47K7vP2tGndkYg9dtVCXU/RxSmg S6XeH4ZsLWsFhi6BxjojSWEOMbYm6p/YsSZoE6qStEVqCTQ4spJGg0+DkUiTyB80u7QfhH/SINu GhuBYhb9qdzqPPKN2LFp3PK6gEG8Vj6f1FNv4I9hqPiAj8YBxFRn2klbMDYk4VhhWMEVuad0oOW PObyESlUAoinvhwi1ZasFz0I+Tzr+oqqhx3SBVdLCW2YPAyMIBAS40D5jnhFzD4E= X-Google-Smtp-Source: AGHT+IEEC/OlDJjYylUZwXM70t8C4JnPOT0aE/22j79CrAET4Rb6cfD67kwfl+/Yi6S6WmLn1QYf+g== X-Received: by 2002:a17:90b:58ec:b0:330:a1ee:e119 with SMTP id 98e67ed59e1d1-339edaae564mr1057063a91.9.1759780992601; Mon, 06 Oct 2025 13:03:12 -0700 (PDT) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-339ee0ba20asm163148a91.4.2025.10.06.13.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Oct 2025 13:03:12 -0700 (PDT) From: Kairui Song Date: Tue, 07 Oct 2025 04:02:34 +0800 Subject: [PATCH 2/4] mm, swap: rename helper for setup bad slots Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251007-swap-clean-after-swap-table-p1-v1-2-74860ef8ba74@tencent.com> References: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> In-Reply-To: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , Chris Li , Baolin Wang , David Hildenbrand , "Matthew Wilcox (Oracle)" , Ying Huang , Kairui Song , linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 From: Kairui Song The name inc_cluster_info_page is very confusing, as this helper is only used during swapon to mark bad slots. Rename it properly and turn the VM_BUG_ON in it into WARN_ON to expose more potential issues. Swapon is a cold path, so adding more checks should be a good idea. No feature change except new WARN_ON. Signed-off-by: Kairui Song Acked-by: Chris Li Acked-by: Nhat Pham Reviewed-by: David Hildenbrand --- mm/swapfile.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 0d1924f6f495..732e07c70ce9 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -751,14 +751,14 @@ static void relocate_cluster(struct swap_info_struct = *si, } =20 /* - * The cluster corresponding to page_nr will be used. The cluster will not= be - * added to free cluster list and its usage counter will be increased by 1. - * Only used for initialization. + * The cluster corresponding to @offset will be accounted as having one bad + * slot. The cluster will not be added to the free cluster list, and its + * usage counter will be increased by 1. Only used for initialization. */ -static int inc_cluster_info_page(struct swap_info_struct *si, - struct swap_cluster_info *cluster_info, unsigned long page_nr) +static int swap_cluster_setup_bad_slot(struct swap_cluster_info *cluster_i= nfo, + unsigned long offset) { - unsigned long idx =3D page_nr / SWAPFILE_CLUSTER; + unsigned long idx =3D offset / SWAPFILE_CLUSTER; struct swap_table *table; struct swap_cluster_info *ci; =20 @@ -772,8 +772,8 @@ static int inc_cluster_info_page(struct swap_info_struc= t *si, =20 ci->count++; =20 - VM_BUG_ON(ci->count > SWAPFILE_CLUSTER); - VM_BUG_ON(ci->flags); + WARN_ON(ci->count > SWAPFILE_CLUSTER); + WARN_ON(ci->flags); =20 return 0; } @@ -3396,7 +3396,7 @@ static struct swap_cluster_info *setup_clusters(struc= t swap_info_struct *si, * See setup_swap_map(): header page, bad pages, * and the EOF part of the last cluster. */ - err =3D inc_cluster_info_page(si, cluster_info, 0); + err =3D swap_cluster_setup_bad_slot(cluster_info, 0); if (err) goto err; for (i =3D 0; i < swap_header->info.nr_badpages; i++) { @@ -3404,12 +3404,12 @@ static struct swap_cluster_info *setup_clusters(str= uct swap_info_struct *si, =20 if (page_nr >=3D maxpages) continue; - err =3D inc_cluster_info_page(si, cluster_info, page_nr); + err =3D swap_cluster_setup_bad_slot(cluster_info, page_nr); if (err) goto err; } for (i =3D maxpages; i < round_up(maxpages, SWAPFILE_CLUSTER); i++) { - err =3D inc_cluster_info_page(si, cluster_info, i); + err =3D swap_cluster_setup_bad_slot(cluster_info, i); if (err) goto err; } --=20 2.51.0 From nobody Sun Dec 7 20:02:23 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A7CA2DCBEB for ; Mon, 6 Oct 2025 20:03:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780999; cv=none; b=YEz9JFJFgfbyo2/wNXfDjDDHhT9gNdMCHWLAEPGbeX2XVbfXVfBTtvdy620NoLt/2KqGh9w3nqNvB51yxwRvg8xFKFVSOuSyQ91wnn9tLsC/OLE3K6rYEcoi8X6oJsohwFNlslkhKjw0RMsaFmHlkND2ltkMgQI4vHWgyb4QWLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759780999; c=relaxed/simple; bh=BI23GMC9t6RGb9fZd+kNiyuir60KlSVll6HSYgnUNwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LAju84tQx0uq/6s7/xNWblLtVpyzv8M2smvkrD9y+fmQhmdx4reDoVgUxYT9iOqNvBSRKnT6VA4WY/bl9wyye3/aOJS1kncpSJDlgEabRfyZrRn+WIUnzHp9C0IKBtzXh8VZcuZEBUS9e6cmIzCF7YyN6FN+BShbR/U7qfqXso8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b8gkG1q5; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b8gkG1q5" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-339c9bf3492so4313442a91.2 for ; Mon, 06 Oct 2025 13:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759780997; x=1760385797; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=JOUsOsGJd3wfEZwhNSB4DJHpM3wcqaShHziJPPLEM9s=; b=b8gkG1q5DsWlmQXXFpdAyTAIZZtLD19F8HXSLdhKwESRRuzmB166EwUP7/GaeOVTXA sJphax2vgn68vkQlg/qGglFRpAKVGjXkODaxDnZbUm10KJXLCFwEEbLslO8NV8uehwZb M4fQdLi5MzcXCt4MZpXHS9NLAo/P0KLDYUBewIzTMzXmAhtw6GVgpCYadtTJeWQtCCYI nGsepIOJ0oF3b3pnTPTW5TLjaQ1pqLkfcofXh5yqKFw0RaUsCFHOiYRYxSP3HZjiXW9L tVFW9Niw3KQWDYd/chAoNYfcSVCQs+dtDfrd3cDhADIJgCSlfLmBzssCQYyPtWWElhJ4 L2jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759780997; x=1760385797; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JOUsOsGJd3wfEZwhNSB4DJHpM3wcqaShHziJPPLEM9s=; b=ji5E20MeohHWSaCcCsTMusur1d/WHBSQCuAG7s31FScIBJjjbCX5P2iNFchyHPQyp4 csC5C1Ya6LAXAIgJLa9HHQ0XBJ1yz732FUfM3R274rRb8co3E2GO869b1oFjQhjSjZOb sG3h/XHeLdVnGG6xoCpCUaH6sMag367/WijTilAnSEgtDer3ukCR8+/4EjCLCmS097eK pTAM+m9o8c9MIUAItRwxxu8z92AN3AZxtsUfw0gfNgXgHvxTM4n+vwrvcvP6erzJTRpF qwu3EbEpCyV3MGKtHyvqKL5mGqgR0SSnA4rTsMv4AJrGvuPJDPoqTVJr5csWjdr55Tr6 /WKw== X-Forwarded-Encrypted: i=1; AJvYcCWLic0YYMjY5j8Dryc7yhTMWovCXxgRwJZBxS6c2l2KCRLL3xkk0u5T6fXxjYkg9PkRltSKhl6n/2CmwIw=@vger.kernel.org X-Gm-Message-State: AOJu0YyKkmIBzO1h7sjxEmwipegUu+g89TVjRknxMvN+dosgGXlVwFhO RSBhIkDarZPYtqzSdN1Vr8jDrbVW5iqDt/bUqXe2HMhUHQERGfUXoigf X-Gm-Gg: ASbGncv4qmiDI/uxiJ2S+zw9WGz+l2RfXOnzfmPkgQWRP9ZJFUpeAZ1ObQJDQ7ayv9Q PjHJoIS1eWKzhJ9RHZiDAiBqgsY3C3I+Ugj/fNfnXuk5iVJuGCOjBZfTNOKubyZD6k6aoUHI0aa J0ZcpAW9CildelNtNSmznWgf5f7q8OIUAeZb3N3BIdFFYwyrSJUzBMycj/asEiM9dBw5M8Fd6CB bWbey8H9c2oBDmC66up+1E0LnUB5VzMamBHb87+pMLQJGgggcIuSCWnalVsMs2FoQHGB4zJ4snf TJ0gIKcpnF/97ZIXDncbw3G25PcOtS4nwc8ieWNe/3JgT21LSUjxWq9BC8O6dDDM96KPEXNfS7f rIwnByFuoRmEF6KH1PyHltp+0LRpc9HHij2FPLws1ZgJRM6BzyT5Ko7VX9xEm9O4= X-Google-Smtp-Source: AGHT+IGtlcgIQ18cOW4NX8p8Ae8A6QlZc0kl78+mT+F6McwCAq86Egqg4BpOisoBrQ9R2ia0C29Faw== X-Received: by 2002:a17:90b:1d10:b0:332:793e:c2d1 with SMTP id 98e67ed59e1d1-339c27d7865mr16524955a91.36.1759780996556; Mon, 06 Oct 2025 13:03:16 -0700 (PDT) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-339ee0ba20asm163148a91.4.2025.10.06.13.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Oct 2025 13:03:16 -0700 (PDT) From: Kairui Song Date: Tue, 07 Oct 2025 04:02:35 +0800 Subject: [PATCH 3/4] mm, swap: cleanup swap entry allocation parameter Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251007-swap-clean-after-swap-table-p1-v1-3-74860ef8ba74@tencent.com> References: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> In-Reply-To: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , Chris Li , Baolin Wang , David Hildenbrand , "Matthew Wilcox (Oracle)" , Ying Huang , Kairui Song , linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 From: Kairui Song We no longer need this GFP parameter after commit 8578e0c00dcf ("mm, swap: use the swap table for the swap cache and switch API"). Before that commit the GFP parameter is already almost identical for all callers, so nothing changed by that commit. Swap table just moved the GFP to lower layer and make it more defined and changes depend on atomic or sleep allocation. Now this parameter is no longer used, just remove it. No behavior change. Signed-off-by: Kairui Song Acked-by: Chris Li Acked-by: Nhat Pham Reviewed-by: Baolin Wang Reviewed-by: David Hildenbrand --- include/linux/swap.h | 4 ++-- mm/shmem.c | 2 +- mm/swapfile.c | 2 +- mm/vmscan.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index e818fbade1e2..a4b264817735 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -462,7 +462,7 @@ static inline long get_nr_swap_pages(void) } =20 extern void si_swapinfo(struct sysinfo *); -int folio_alloc_swap(struct folio *folio, gfp_t gfp_mask); +int folio_alloc_swap(struct folio *folio); bool folio_free_swap(struct folio *folio); void put_swap_folio(struct folio *folio, swp_entry_t entry); extern swp_entry_t get_swap_page_of_type(int); @@ -560,7 +560,7 @@ static inline int swp_swapcount(swp_entry_t entry) return 0; } =20 -static inline int folio_alloc_swap(struct folio *folio, gfp_t gfp_mask) +static inline int folio_alloc_swap(struct folio *folio) { return -EINVAL; } diff --git a/mm/shmem.c b/mm/shmem.c index 45f51745ad88..63092cc0b141 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1617,7 +1617,7 @@ int shmem_writeout(struct folio *folio, struct swap_i= ocb **plug, folio_mark_uptodate(folio); } =20 - if (!folio_alloc_swap(folio, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN= )) { + if (!folio_alloc_swap(folio)) { bool first_swapped =3D shmem_recalc_inode(inode, 0, nr_pages); int error; =20 diff --git a/mm/swapfile.c b/mm/swapfile.c index 732e07c70ce9..534b21aeef5a 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1425,7 +1425,7 @@ static bool swap_sync_discard(void) * Context: Caller needs to hold the folio lock. * Return: Whether the folio was added to the swap cache. */ -int folio_alloc_swap(struct folio *folio, gfp_t gfp) +int folio_alloc_swap(struct folio *folio) { unsigned int order =3D folio_order(folio); unsigned int size =3D 1 << order; diff --git a/mm/vmscan.c b/mm/vmscan.c index aadbee50a851..c99f7d6d5dd9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1296,7 +1296,7 @@ static unsigned int shrink_folio_list(struct list_hea= d *folio_list, split_folio_to_list(folio, folio_list)) goto activate_locked; } - if (folio_alloc_swap(folio, __GFP_HIGH | __GFP_NOWARN)) { + if (folio_alloc_swap(folio)) { int __maybe_unused order =3D folio_order(folio); =20 if (!folio_test_large(folio)) @@ -1312,7 +1312,7 @@ static unsigned int shrink_folio_list(struct list_hea= d *folio_list, } #endif count_mthp_stat(order, MTHP_STAT_SWPOUT_FALLBACK); - if (folio_alloc_swap(folio, __GFP_HIGH | __GFP_NOWARN)) + if (folio_alloc_swap(folio)) goto activate_locked_split; } /* --=20 2.51.0 From nobody Sun Dec 7 20:02:23 2025 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA0052DCC17 for ; Mon, 6 Oct 2025 20:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759781003; cv=none; b=WlCJuJwHxyft/59BifG5VrAommHasQJ3VhVL7RyTLWwSeEZrdPMQzEiKbhIPQtOji4n3RV/Fw499FEqZrjjXztJVE5DzMiw/SzsVudkCToPDp5ke6kN/yrhAM9saF/WlB6ZwvT9Z+2kRFrPlCK6rFTFJgTgVBsHsGLrzDVMRh/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759781003; c=relaxed/simple; bh=NLExQZtlq7X/64T+L9WPZw2dv47A0FwtKkMlbNC7OO0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m9kYTjmh67qNMm8jBrkKH2ZDq+mldXwOro8LxlonS+ZPegvWvdKWGH9SyNdaqHYLwoIdkLQwIwr038MxkabttjSD4Qz1QgBnP+H7So9/t5a3zJcLKzgOoe8Z6ZsThVjXHbuUI8ilQHroeTakoP7B52ClCJ6WtVJKBz02o7KVHHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NBxL/+Lq; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NBxL/+Lq" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-330631e534eso5912078a91.0 for ; Mon, 06 Oct 2025 13:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759781001; x=1760385801; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tT3gHG08BkG90c6MiUPgy6uFcKswLyMsm2cO/8LgJ2w=; b=NBxL/+LqouzSaDUMB7VaPXVhZPewW9r4ybphkcafpfbQOHozRhjingLomidI3Iw5Dr G5AX8sicxlsTjGmqcdbgmRgb60uyPp63xt87i6kOeJdTlYjZKPVLfUiPUbjTyOXd5ucd Uk+RkPA5oCakOw3bPHXJI2DFcH0GLOEb9qE4428jc0nKyQYAlDy8qod4KUOGDDJzTGB4 OQed45Mv7klyCht7xiAiW8M1S6rBWsvR+AatdPslpXRoU+ZUp95qv7EjwAtlzyxOHuBb OvLycNQB3aDdMyoeDTQzQKglAnX4PDzAW7FYN2t4BVWITFIM79mnu9C+aK61BhYujZ8D F/3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759781001; x=1760385801; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tT3gHG08BkG90c6MiUPgy6uFcKswLyMsm2cO/8LgJ2w=; b=OyqgpITk0Oh0I2HFIvKtP3r2Y9X9LoZ604sTy7OdvPBAeOA9kkUFACErnv1IOO2okG 61Du2OhOxeGkR0VRK6xUcshGbAvlrXMriPfRoH29+NRIU3uN2Zc+tF2F+mCaYCx/4T/E bkmsxl/TaqcTYGjHOV3rlC7Qj6pli5JK2pILAo/euNF5snHmDfrmejHAGVZuY/wR0g9Z pP9wyhClad81qDDlfMthWQngee29UVfqpYRD15bRZh8KubnAf/EwStMoeTfXLsvB/24v E/mIRWeLQChEI1HBLGrJ3BUYWq3tN7Rdg48CCjWvLy2pv6h+OalAkuU9t1JeHY5VxkU6 R2aA== X-Forwarded-Encrypted: i=1; AJvYcCXIOVg5kVL5ljr61zxc6yeSinHrcRBDSlKZECW+n3JG+p/c9ptURe7z3yuNgUIiIpSks/Q1thNB4K8Xn1Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxO0IScBuZdmeO7jXDIdUyYmbZzrPVnKnxiC4ZBQ3v4BZ75lNPA 0zBJVIMZFUe9/WPT+PRMV61P/SBfLDIWbObKuzwbEiHM85LI+ANUkOxG X-Gm-Gg: ASbGnct4Sl1eGgDuU+A2cCvAY4pWWAe0ky4ZlG8VB3FkX1/P0s/NIGFn5frptMk2UHz OqE01j0kwVRowZEN+miP6o4E+CULgudCo71H4Hqf0Cy7MlN9YAwP2HVIbY+X5E13kqXIfkwxTDG TFppPZj6FcZqeLndf8qr8tJRYA7rvQjHc52xVYi8xcRJy9E9TysY5/yvp+xmnZ68Sh35D9ZDMaX 0Ahh5jGEaK0/JPOsYgsP2I/JIUkyIWwmNCNIzr0bfbwe4I/NbA02qqAbnFCwK6a0qzDtmq3sZGB G1ncSZz6fb9t9h0Yqlrk92ZCcOC4Nc/SioQ4wYLp5iECnQ4jmCjC2t7yZp3es1YKpm7uxGX9cwv K2arYpMF3IyVJS1NOqGa/mPiMEJ4g/asye3xGsaFr21LlfIjh9I0Z X-Google-Smtp-Source: AGHT+IHDTaQdL9Cg+WLyZqqSRaiz6Hdnze5SC5rU4ka3LeHNo2UnGttYWx4/NzTemH9+GPk3hGm4Ew== X-Received: by 2002:a17:90b:17c3:b0:32e:7bbc:bf13 with SMTP id 98e67ed59e1d1-339c27d306fmr16089364a91.34.1759781001066; Mon, 06 Oct 2025 13:03:21 -0700 (PDT) Received: from [127.0.0.1] ([101.32.222.185]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-339ee0ba20asm163148a91.4.2025.10.06.13.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Oct 2025 13:03:20 -0700 (PDT) From: Kairui Song Date: Tue, 07 Oct 2025 04:02:36 +0800 Subject: [PATCH 4/4] mm/migrate, swap: drop usage of folio_index Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251007-swap-clean-after-swap-table-p1-v1-4-74860ef8ba74@tencent.com> References: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> In-Reply-To: <20251007-swap-clean-after-swap-table-p1-v1-0-74860ef8ba74@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , Chris Li , Baolin Wang , David Hildenbrand , "Matthew Wilcox (Oracle)" , Ying Huang , Kairui Song , linux-kernel@vger.kernel.org X-Mailer: b4 0.14.3 From: Kairui Song This helper was used when swap cache was mixed with swap cache. Now they are completely separate from each other, access to the swap cache is all wrapped by the swap_cache_* helpers, which expect the folio's swap entry as a parameter. This helper is no longer used, remove the last redundant user and drop it. Signed-off-by: Kairui Song Acked-by: Chris Li Acked-by: Nhat Pham Reviewed-by: Baolin Wang --- mm/migrate.c | 4 ++-- mm/swap.h | 21 --------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index e3065c9edb55..97c931b31940 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -561,7 +561,7 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd= _t *pmd) static int __folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int expected_count) { - XA_STATE(xas, &mapping->i_pages, folio_index(folio)); + XA_STATE(xas, &mapping->i_pages, folio->index); struct swap_cluster_info *ci =3D NULL; struct zone *oldzone, *newzone; int dirty; @@ -714,7 +714,7 @@ EXPORT_SYMBOL(folio_migrate_mapping); int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src) { - XA_STATE(xas, &mapping->i_pages, folio_index(src)); + XA_STATE(xas, &mapping->i_pages, src->index); int rc, expected_count =3D folio_expected_ref_count(src) + 1; =20 if (folio_ref_count(src) !=3D expected_count) diff --git a/mm/swap.h b/mm/swap.h index 8d8efdf1297a..d034c13d8dd2 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -445,25 +445,4 @@ static inline int non_swapcache_batch(swp_entry_t entr= y, int max_nr) return 0; } #endif /* CONFIG_SWAP */ - -/** - * folio_index - File index of a folio. - * @folio: The folio. - * - * For a folio which is either in the page cache or the swap cache, - * return its index within the address_space it belongs to. If you know - * the folio is definitely in the page cache, you can look at the folio's - * index directly. - * - * Return: The index (offset in units of pages) of a folio in its file. - */ -static inline pgoff_t folio_index(struct folio *folio) -{ -#ifdef CONFIG_SWAP - if (unlikely(folio_test_swapcache(folio))) - return swp_offset(folio->swap); -#endif - return folio->index; -} - #endif /* _MM_SWAP_H */ --=20 2.51.0