From nobody Sat Oct 4 22:33:07 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE5E62D8375 for ; Tue, 12 Aug 2025 07:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754982660; cv=none; b=ZBGdYsriz3j5i7U8AH9OFC4HzQUyS0H5kWPludQA2BKdAJsFjeq8aKu07ezOaTJLic2fQW45O2uHP8PoGaMWvU+mzLy/mKa5nxEx3xu+oM3FVcFDFGsFrY5zojrUuolTig2yD9EvKKnp3USUyA6pvQ5Q/SH6OOYVAhEAmLX7KT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754982660; c=relaxed/simple; bh=RS8ZN6qEMRelHHf535daIqnnsWW0kEy9YMRdf1YF2MA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PABGOGAf9Kz1hjiwZf79J9fylFnylfOySnzaykAjD2oGd/XgnxcugnpQhlF01OuXyY+PkST0nxhgj3/Tu5Jrz3HkQc1DWeur/Pn5KnxfdqP5p6O9KZ560y3rLdsdZAl676bzAGvztpC9wqbXI63D0KzLTp1BlGAQg6RJMt4XwBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B1F9CQbC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B1F9CQbC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F009C4CEF1; Tue, 12 Aug 2025 07:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754982659; bh=RS8ZN6qEMRelHHf535daIqnnsWW0kEy9YMRdf1YF2MA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B1F9CQbCHkCn4lgH11d1sPnMtbwfOGvwAeb8STBmGAEOHN9jQk/cx3veSoweGRUKu Yu4hTUW3pCVUFSUA4gvugi/5BQ0lKjKmbGEOd4mLjudgwFGme0N4RjLYjbLuwo0SUs 8zLRYBDigLRNWSMVhQJ13HKLu/e/jkO+Ikba3l1AD0DXuCL7wmWbDFuCDAluqPExbh dyws2ecYH9ucj2kApdv5b71we6VM8Ig5PGo3ZXlYGVERsrxi+t/ySzNgMnJiql1kNx 9Y0k4p1la+tCuYoVOMaBhUDUup6ShXrnztAkhuU+jsOlfpu1TJGKeDhVhTUDmJ1M62 YvpRi/7FybdCA== From: Chris Li Date: Tue, 12 Aug 2025 00:10:58 -0700 Subject: [PATCH v3 1/2] mm/swapfile.c: introduce function alloc_swap_scan_list() 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: <20250812-swap-scan-list-v3-1-6d73504d267b@kernel.org> References: <20250812-swap-scan-list-v3-0-6d73504d267b@kernel.org> In-Reply-To: <20250812-swap-scan-list-v3-0-6d73504d267b@kernel.org> To: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , "Huang, Ying" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Li X-Mailer: b4 0.13.0 alloc_swap_scan_list() will scan the whole list or the first cluster. This reduces the repeat patterns of isolating a cluster then scanning that cluster. As a result, cluster_alloc_swap_entry() is shorter and shallower. No functional change. Signed-off-by: Chris Li Acked-by: Nhat Pham Reviewed-by: Kairui Song --- mm/swapfile.c | 86 ++++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 4a0cf4fb348d..a7ffabbe65ef 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -820,6 +820,29 @@ static unsigned int alloc_swap_scan_cluster(struct swa= p_info_struct *si, return found; } =20 +static unsigned int alloc_swap_scan_list(struct swap_info_struct *si, + struct list_head *list, + unsigned int order, + unsigned char usage, + bool scan_all) +{ + unsigned int found =3D SWAP_ENTRY_INVALID; + + do { + struct swap_cluster_info *ci =3D isolate_lock_cluster(si, list); + unsigned long offset; + + if (!ci) + break; + offset =3D cluster_offset(si, ci); + found =3D alloc_swap_scan_cluster(si, ci, offset, order, usage); + if (found) + break; + } while (scan_all); + + return found; +} + static void swap_reclaim_full_clusters(struct swap_info_struct *si, bool f= orce) { long to_scan =3D 1; @@ -913,32 +936,24 @@ static unsigned long cluster_alloc_swap_entry(struct = swap_info_struct *si, int o * to spread out the writes. */ if (si->flags & SWP_PAGE_DISCARD) { - ci =3D isolate_lock_cluster(si, &si->free_clusters); - if (ci) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - order, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->free_clusters, order, usage, + false); + if (found) + goto done; } =20 if (order < PMD_ORDER) { - while ((ci =3D isolate_lock_cluster(si, &si->nonfull_clusters[order]))) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - order, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->nonfull_clusters[order], + order, usage, true); + if (found) + goto done; } =20 if (!(si->flags & SWP_PAGE_DISCARD)) { - ci =3D isolate_lock_cluster(si, &si->free_clusters); - if (ci) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - order, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->free_clusters, order, usage, + false); + if (found) + goto done; } =20 /* Try reclaim full clusters if free and nonfull lists are drained */ @@ -952,13 +967,10 @@ static unsigned long cluster_alloc_swap_entry(struct = swap_info_struct *si, int o * failure is not critical. Scanning one cluster still * keeps the list rotated and reclaimed (for HAS_CACHE). */ - ci =3D isolate_lock_cluster(si, &si->frag_clusters[order]); - if (ci) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - order, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->frag_clusters[order], order, + usage, false); + if (found) + goto done; } =20 /* @@ -977,19 +989,15 @@ static unsigned long cluster_alloc_swap_entry(struct = swap_info_struct *si, int o * Clusters here have at least one usable slots and can't fail order 0 * allocation, but reclaim may drop si->lock and race with another user. */ - while ((ci =3D isolate_lock_cluster(si, &si->frag_clusters[o]))) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - 0, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->frag_clusters[o], + 0, usage, true); + if (found) + goto done; =20 - while ((ci =3D isolate_lock_cluster(si, &si->nonfull_clusters[o]))) { - found =3D alloc_swap_scan_cluster(si, ci, cluster_offset(si, ci), - 0, usage); - if (found) - goto done; - } + found =3D alloc_swap_scan_list(si, &si->nonfull_clusters[o], + 0, usage, true); + if (found) + goto done; } done: if (!(si->flags & SWP_SOLIDSTATE)) --=20 2.43.0 From nobody Sat Oct 4 22:33:07 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02A242D8376 for ; Tue, 12 Aug 2025 07:10:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754982660; cv=none; b=lZg0NkOhtknkQMOTpZ6I4c1J27ol5+OE8InXZL31SA6sAjSMX0jWZ0Dp4LptmgZfwSJ3320RcgDtehNHc1kS3sL3fOFAK3rvBZo7CSVkKMWu1iSCEhR17uCoxexVWlUuDoBRt9u3rt2hrbYS8UUa1SYnkpqyOEQv1z7+rNdrXKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754982660; c=relaxed/simple; bh=obdOWxAf7RFXJ2IB/8yF3uqWcTZG9h0+RKS1zCQ9UP0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aojami4wPrJjm6cIlYTXEHKlU3OQbkRKp8O2VFYH0440f+CSpBk4eJ3bESJXLmY/yI5AHCu7jJLepLnLWxMGbz9ATSc2L+VAsgXlsXpdbhDeuybMnOPaq3RGwGX1XP4LTsETMw1jpqPbmLfluN7J3k8rr7ZMbJNs50JdQ2rwmBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bOP7mj6e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bOP7mj6e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93824C4CEF0; Tue, 12 Aug 2025 07:10:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754982659; bh=obdOWxAf7RFXJ2IB/8yF3uqWcTZG9h0+RKS1zCQ9UP0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bOP7mj6eg5jHCROEXjruEK4HythPameWSjzlj+oPPo0hvojrO1/WpDET+iDJD8mse KWNqhP+95GM3HcOpwiBQrg8bcqV4h0tpe33J/q+TzIeNJOve1CzVPrSSHwSyJM8aZP rD06s4wj3xZHNTOAJCdM4vQX9Nx0KTARmDerFL/6zR50yZoego+DTMzeRoKemji4XV 2bCb7oe2dq66FfEFvmgZDr0Eo87+Tbic6F1Y7+cZP3oK4DvqnAVjxIs3X+BOafmh91 RIe86BWh3X9LUkIID21z78uX4CqkNTDv0X9RC34ZmS2Tw9VHTfNa457rnxxNr2ZlRz B2l5/ACkHxiow== From: Chris Li Date: Tue, 12 Aug 2025 00:10:59 -0700 Subject: [PATCH v3 2/2] mm: swap.h: Remove deleted field from comments 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: <20250812-swap-scan-list-v3-2-6d73504d267b@kernel.org> References: <20250812-swap-scan-list-v3-0-6d73504d267b@kernel.org> In-Reply-To: <20250812-swap-scan-list-v3-0-6d73504d267b@kernel.org> To: Andrew Morton , Kemeng Shi , Kairui Song , Nhat Pham , Baoquan He , Barry Song , "Huang, Ying" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chris Li X-Mailer: b4 0.13.0 The comment for struct swap_info_struct.lock incorrectly mentions fields that have already been deleted from the structure. Updates the comments to accurately reflect the current struct swap_info_struct. There is no functional change. Signed-off-by: Chris Li Acked-by: Nhat Pham Reviewed-by: Barry Song Reviewed-by: Kairui Song --- include/linux/swap.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index a060d102e0d1..c2da85cb7fe7 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -320,11 +320,8 @@ struct swap_info_struct { struct completion comp; /* seldom referenced */ spinlock_t lock; /* * protect map scan related fields like - * swap_map, lowest_bit, highest_bit, - * inuse_pages, cluster_next, - * cluster_nr, lowest_alloc, - * highest_alloc, free/discard cluster - * list. other fields are only changed + * swap_map, inuse_pages and all cluster + * lists. other fields are only changed * at swapon/swapoff, so are protected * by swap_lock. changing flags need * hold this lock and swap_lock. If --=20 2.43.0