From: Kairui Song <ryncsn@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: kasong@tencent.com,
Kairui Song via B4 Relay <devnull+kasong.tencent.com@kernel.org>,
linux-mm@kvack.org, David Hildenbrand <david@kernel.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Barry Song <baohua@kernel.org>, Hugh Dickins <hughd@google.com>,
Chris Li <chrisl@kernel.org>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Nhat Pham <nphamcs@gmail.com>, Baoquan He <bhe@redhat.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Youngjun Park <youngjun.park@lge.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
Lorenzo Stoakes <ljs@kernel.org>, Yosry Ahmed <yosry@kernel.org>,
Qi Zheng <qi.zheng@linux.dev>
Subject: Re: [PATCH v5 12/12] mm, swap: merge zeromap into swap table
Date: Fri, 22 May 2026 10:39:59 +0800 [thread overview]
Message-ID: <ag_Bt1MpdF4IIXc9@KASONG-MC4> (raw)
In-Reply-To: <20260521185204.a109bfcd1e0e8f52135c5ed5@linux-foundation.org>
On Thu, May 21, 2026 at 06:52:04PM +0800, Andrew Morton wrote:
> On Sun, 17 May 2026 23:39:51 +0800 Kairui Song via B4 Relay <devnull+kasong.tencent.com@kernel.org> wrote:
>
> > From: Kairui Song <kasong@tencent.com>
> >
> > By allocating one additional bit in the swap table entry's flags field
> > alongside the count, we can store the zeromap inline
> >
> > For 64 bit systems, zeromap will store in the swap table, avoiding zeromap
> > allocation. It reduces the allocated memory. That is the happy path.
> >
> > For certain 32-bit archs, there might not be enough bits in the swap
> > table to contain both PFN and flags. Therefore, conditionally let each
> > cluster have a zeromap field at build time, and use that instead.
> > If the swapfile cluster is not fully used, it will still save memory for
> > zeromap. The empty cluster does not allocate a zeromap. In the worst case,
> > all cluster are fully populated. We will use memory similar to the
> > previous zeromap implementation.
> >
> > A few macros were moved to different headers for build time struct
> > definition.
> >
> > ...
> >
> > @@ -469,13 +474,21 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
> > VM_WARN_ON_ONCE(ci->memcg_table);
> > ci->memcg_table = kzalloc_obj(*ci->memcg_table, gfp);
> > if (!ci->memcg_table)
> > - ret = -ENOMEM;
> > + goto err_free;
> > }
> > #endif
> > - if (ret)
> > - swap_cluster_free_table(ci);
> >
> > - return ret;
> > +#if !SWAP_TABLE_HAS_ZEROFLAG
> > + VM_WARN_ON_ONCE(ci->zero_bitmap);
> > + ci->zero_bitmap = bitmap_zalloc(SWAPFILE_CLUSTER, gfp);
> > + if (!ci->zero_bitmap)
> > + goto err_free;
> > +#endif
> > + return 0;
> > +
> > +err_free:
> > + swap_cluster_free_table(ci);
> > + return -ENOMEM;
> > }
>
> My m68k defconfig warned. I'll do the below, which looks good enough.
> Please check.
>
> Perhaps a custom guard() handler would clean things up here.
>
>
> From: Andrew Morton <akpm@linux-foundation.org>
> Subject: mm-swap-merge-zeromap-into-swap-table-fix-2
> Date: Thu May 21 06:39:20 PM PDT 2026
>
> mm/swapfile.c: In function 'swap_cluster_alloc_table':
> mm/swapfile.c:488:1: warning: label 'err_free' defined but not used [-Wunused-label]
> 488 | err_free:
> | ^~~~~~~~
>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: Baoquan He <bhe@redhat.com>
> Cc: Barry Song <baohua@kernel.org>
> Cc: Chengming Zhou <chengming.zhou@linux.dev>
> Cc: Chris Li <chrisl@kernel.org>
> Cc: David Hildenbrand <david@kernel.org>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Kairui Song <kasong@tencent.com>
> Cc: Kemeng Shi <shikemeng@huaweicloud.com>
> Cc: Lorenzo Stoakes <ljs@kernel.org>
> Cc: Muchun Song <muchun.song@linux.dev>
> Cc: Nhat Pham <nphamcs@gmail.com>
> Cc: Roman Gushchin <roman.gushchin@linux.dev>
> Cc: Shakeel Butt <shakeel.butt@linux.dev>
> Cc: Youngjun Park <youngjun.park@lge.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> mm/swapfile.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> --- a/mm/swapfile.c~mm-swap-merge-zeromap-into-swap-table-fix-2
> +++ a/mm/swapfile.c
> @@ -472,22 +472,22 @@ static int swap_cluster_alloc_table(stru
> if (!mem_cgroup_disabled()) {
> VM_WARN_ON_ONCE(ci->memcg_table);
> ci->memcg_table = kzalloc_obj(*ci->memcg_table, gfp);
> - if (!ci->memcg_table)
> - goto err_free;
> + if (!ci->memcg_table) {
> + swap_cluster_free_table(ci);
> + return -ENOMEM;
> + }
> }
> #endif
>
> #if !SWAP_TABLE_HAS_ZEROFLAG
> VM_WARN_ON_ONCE(ci->zero_bitmap);
> ci->zero_bitmap = bitmap_zalloc(SWAPFILE_CLUSTER, gfp);
> - if (!ci->zero_bitmap)
> - goto err_free;
> + if (!ci->zero_bitmap) {
> + swap_cluster_free_table(ci);
> + return -ENOMEM;
> + }
> #endif
> return 0;
> -
> -err_free:
> - swap_cluster_free_table(ci);
> - return -ENOMEM;
> }
>
> /*
> _
>
Looks good, thank you. The error path is still simple and
straight at the moment.
It will be even better if we also remove the now unused ret
variable as well (this isn't triggering warning yet since Kbuild
don't set unused-but-set-variable by default):
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 9712cc862c9c..615d90867111 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -450,7 +450,6 @@ static int swap_cluster_alloc_table(struct swap_cluster_info *ci, gfp_t gfp)
{
struct swap_table *table = NULL;
struct folio *folio;
- int ret = 0;
/* The cluster must be empty and not on any list during allocation. */
VM_WARN_ON_ONCE(ci->flags || !cluster_is_empty(ci));
next prev parent reply other threads:[~2026-05-22 2:40 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-17 15:39 [PATCH v5 00/12] mm, swap: swap table phase IV: unify allocation and reduce static metadata Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 01/12] mm, swap: simplify swap cache allocation helper Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 02/12] mm, swap: move common swap cache operations into standalone helpers Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 03/12] mm/huge_memory: move THP gfp limit helper into header Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 04/12] mm, swap: add support for stable large allocation in swap cache directly Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 05/12] mm, swap: unify large folio allocation Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 06/12] mm/memcg, swap: tidy up cgroup v1 memsw swap helpers Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 07/12] mm, swap: support flexible batch freeing of slots in different memcgs Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 08/12] mm, swap: delay and unify memcg lookup and charging for swapin Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 09/12] mm, swap: consolidate cluster allocation helpers Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 10/12] mm/memcg, swap: store cgroup id in cluster table directly Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 11/12] mm/memcg: remove no longer used swap cgroup array Kairui Song via B4 Relay
2026-05-17 15:39 ` [PATCH v5 12/12] mm, swap: merge zeromap into swap table Kairui Song via B4 Relay
2026-05-22 1:52 ` Andrew Morton
2026-05-22 2:39 ` Kairui Song [this message]
2026-05-18 18:11 ` [PATCH v5 00/12] mm, swap: swap table phase IV: unify allocation and reduce static metadata Kairui Song
2026-05-18 21:51 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ag_Bt1MpdF4IIXc9@KASONG-MC4 \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bhe@redhat.com \
--cc=cgroups@vger.kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=david@kernel.org \
--cc=devnull+kasong.tencent.com@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=qi.zheng@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=usama.arif@linux.dev \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox