Re: [RFC PATCH] mm/swap: fix swap table count encoding for empty slots

From: Youngjun Park

Date: Fri Sep 04 2026 - 02:16:31 EST


On Fri, Sep 04, 2026 at 10:54:11AM +0800, gaoguixing wrote:
....
> mm/swapfile.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index d6c5c25755be..02fd5ad94185 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -163,16 +163,16 @@ static void __swap_table_update_count(struct swap_cluster_info *ci,
> unsigned char count)
> {
> unsigned long swp_tb = __swap_table_get(ci, ci_off);
> - unsigned char flags = swap_table_count(count);
> + unsigned char tb_count = swap_table_count(count);
>
> if (WARN_ON_ONCE(swp_tb_is_bad(swp_tb)))
> return;
> - if (!flags && swp_tb_is_null(swp_tb))
> + if (!tb_count && swp_tb_is_null(swp_tb))
> return;
> - if (flags && swp_tb_is_null(swp_tb))
> - swp_tb = shadow_to_swp_tb(NULL, flags);
> - else
> - swp_tb = __swp_tb_mk_count(swp_tb, flags);
> + if (tb_count && swp_tb_is_null(swp_tb))
> + swp_tb = shadow_to_swp_tb(NULL, 0);
> +
> + swp_tb = __swp_tb_mk_count(swp_tb, tb_count);
> __swap_table_set(ci, ci_off, swp_tb);
> }
>
Hello,

If I understand correctly, this function was added during a custom
kernel adaptation, and since the flags field mixes the count and the
Z flag, you'd like to split out a dedicated helper for updating the
swap count?

To me the layout and helpers in swap_table.h and swapfile.c already
read well enough. A mistake is possible, but following how the flags
field is used across swap_table.h and its callers was not hard.

I can't quite see where this would apply or what it buys us from this
diff alone. Could you progress & share the rationale and an actual patch on top
of the upstream series?

Thanks,
Youngjun