From: Kairui Song <kasong@tencent.com>
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 <kasong@tencent.com>
---
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,
}
/*
- * 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_info,
+ unsigned long offset)
{
- unsigned long idx = page_nr / SWAPFILE_CLUSTER;
+ unsigned long idx = offset / SWAPFILE_CLUSTER;
struct swap_table *table;
struct swap_cluster_info *ci;
@@ -772,8 +772,8 @@ static int inc_cluster_info_page(struct swap_info_struct *si,
ci->count++;
- VM_BUG_ON(ci->count > SWAPFILE_CLUSTER);
- VM_BUG_ON(ci->flags);
+ WARN_ON(ci->count > SWAPFILE_CLUSTER);
+ WARN_ON(ci->flags);
return 0;
}
@@ -3396,7 +3396,7 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
* See setup_swap_map(): header page, bad pages,
* and the EOF part of the last cluster.
*/
- err = inc_cluster_info_page(si, cluster_info, 0);
+ err = swap_cluster_setup_bad_slot(cluster_info, 0);
if (err)
goto err;
for (i = 0; i < swap_header->info.nr_badpages; i++) {
@@ -3404,12 +3404,12 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
if (page_nr >= maxpages)
continue;
- err = inc_cluster_info_page(si, cluster_info, page_nr);
+ err = swap_cluster_setup_bad_slot(cluster_info, page_nr);
if (err)
goto err;
}
for (i = maxpages; i < round_up(maxpages, SWAPFILE_CLUSTER); i++) {
- err = inc_cluster_info_page(si, cluster_info, i);
+ err = swap_cluster_setup_bad_slot(cluster_info, i);
if (err)
goto err;
}
--
2.51.0
Acked-by: Chris Li <chrisl@kernel.org>
Chris
On Mon, Oct 6, 2025 at 1:03 PM Kairui Song <ryncsn@gmail.com> wrote:
>
> From: Kairui Song <kasong@tencent.com>
>
> 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 <kasong@tencent.com>
> ---
> 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,
> }
>
> /*
> - * 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_info,
> + unsigned long offset)
> {
> - unsigned long idx = page_nr / SWAPFILE_CLUSTER;
> + unsigned long idx = offset / SWAPFILE_CLUSTER;
> struct swap_table *table;
> struct swap_cluster_info *ci;
>
> @@ -772,8 +772,8 @@ static int inc_cluster_info_page(struct swap_info_struct *si,
>
> ci->count++;
>
> - VM_BUG_ON(ci->count > SWAPFILE_CLUSTER);
> - VM_BUG_ON(ci->flags);
> + WARN_ON(ci->count > SWAPFILE_CLUSTER);
> + WARN_ON(ci->flags);
>
> return 0;
> }
> @@ -3396,7 +3396,7 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
> * See setup_swap_map(): header page, bad pages,
> * and the EOF part of the last cluster.
> */
> - err = inc_cluster_info_page(si, cluster_info, 0);
> + err = swap_cluster_setup_bad_slot(cluster_info, 0);
> if (err)
> goto err;
> for (i = 0; i < swap_header->info.nr_badpages; i++) {
> @@ -3404,12 +3404,12 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
>
> if (page_nr >= maxpages)
> continue;
> - err = inc_cluster_info_page(si, cluster_info, page_nr);
> + err = swap_cluster_setup_bad_slot(cluster_info, page_nr);
> if (err)
> goto err;
> }
> for (i = maxpages; i < round_up(maxpages, SWAPFILE_CLUSTER); i++) {
> - err = inc_cluster_info_page(si, cluster_info, i);
> + err = swap_cluster_setup_bad_slot(cluster_info, i);
> if (err)
> goto err;
> }
>
> --
> 2.51.0
>
On 06.10.25 22:02, Kairui Song wrote: > From: Kairui Song <kasong@tencent.com> > > 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 <kasong@tencent.com> > --- Reviewed-by: David Hildenbrand <david@redhat.com> -- Cheers David / dhildenb
On Mon, Oct 6, 2025 at 1:03 PM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > 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 <kasong@tencent.com> Acked-by: Nhat Pham <nphamcs@gmail.com>
© 2016 - 2025 Red Hat, Inc.