From: Kairui Song <ryncsn@gmail.com>
To: Klara Modin <klarasmodin@gmail.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Hugh Dickins <hughd@google.com>, Chris Li <chrisl@kernel.org>,
Barry Song <baohua@kernel.org>, Baoquan He <bhe@redhat.com>,
Nhat Pham <nphamcs@gmail.com>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Ying Huang <ying.huang@linux.alibaba.com>,
Johannes Weiner <hannes@cmpxchg.org>,
David Hildenbrand <david@redhat.com>,
Yosry Ahmed <yosryahmed@google.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Zi Yan <ziy@nvidia.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 11/15] mm, swap: use the swap table for the swap cache and switch API
Date: Mon, 8 Sep 2025 23:10:05 +0800 [thread overview]
Message-ID: <CAMgjq7AHZ+X83pOUiOfhXWkV158uAvv=NQE6ibh33BQVgPJ5iA@mail.gmail.com> (raw)
In-Reply-To: <eu3s6hqfcbkymjqk2rrngzx7qxjzpivfty2dr4lrduxohxuuuv@g63qihvder5d>
On Mon, Sep 8, 2025 at 11:01 PM Klara Modin <klarasmodin@gmail.com> wrote:
>
> On 2025-09-08 22:34:04 +0800, Kairui Song wrote:
> > On Sun, Sep 7, 2025 at 8:59 PM Klara Modin <klarasmodin@gmail.com> wrote:
> > >
> > > On 2025-09-06 03:13:53 +0800, Kairui Song wrote:
> > > > From: Kairui Song <kasong@tencent.com>
> > > >
> > > > Introduce basic swap table infrastructures, which are now just a
> > > > fixed-sized flat array inside each swap cluster, with access wrappers.
> > > >
> > > > Each cluster contains a swap table of 512 entries. Each table entry is
> > > > an opaque atomic long. It could be in 3 types: a shadow type (XA_VALUE),
> > > > a folio type (pointer), or NULL.
> > > >
> > > > In this first step, it only supports storing a folio or shadow, and it
> > > > is a drop-in replacement for the current swap cache. Convert all swap
> > > > cache users to use the new sets of APIs. Chris Li has been suggesting
> > > > using a new infrastructure for swap cache for better performance, and
> > > > that idea combined well with the swap table as the new backing
> > > > structure. Now the lock contention range is reduced to 2M clusters,
> > > > which is much smaller than the 64M address_space. And we can also drop
> > > > the multiple address_space design.
> > > >
> > > > All the internal works are done with swap_cache_get_* helpers. Swap
> > > > cache lookup is still lock-less like before, and the helper's contexts
> > > > are same with original swap cache helpers. They still require a pin
> > > > on the swap device to prevent the backing data from being freed.
> > > >
> > > > Swap cache updates are now protected by the swap cluster lock
> > > > instead of the Xarray lock. This is mostly handled internally, but new
> > > > __swap_cache_* helpers require the caller to lock the cluster. So, a
> > > > few new cluster access and locking helpers are also introduced.
> > > >
> > > > A fully cluster-based unified swap table can be implemented on top
> > > > of this to take care of all count tracking and synchronization work,
> > > > with dynamic allocation. It should reduce the memory usage while
> > > > making the performance even better.
> > > >
> > > > Co-developed-by: Chris Li <chrisl@kernel.org>
> > > > Signed-off-by: Chris Li <chrisl@kernel.org>
> > > > Signed-off-by: Kairui Song <kasong@tencent.com>
> > > > ---
> > > > MAINTAINERS | 1 +
> > > > include/linux/swap.h | 2 -
> > > > mm/huge_memory.c | 13 +-
> > > > mm/migrate.c | 19 ++-
> > > > mm/shmem.c | 8 +-
> > > > mm/swap.h | 157 +++++++++++++++++------
> > > > mm/swap_state.c | 289 +++++++++++++++++++------------------------
> > > > mm/swap_table.h | 97 +++++++++++++++
> > > > mm/swapfile.c | 100 +++++++++++----
> > > > mm/vmscan.c | 20 ++-
> > > > 10 files changed, 458 insertions(+), 248 deletions(-)
> > > > create mode 100644 mm/swap_table.h
> > > >
> > > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > > index 1c8292c0318d..de402ca91a80 100644
> > > > --- a/MAINTAINERS
> > > > +++ b/MAINTAINERS
> > > > @@ -16226,6 +16226,7 @@ F: include/linux/swapops.h
> > > > F: mm/page_io.c
> > > > F: mm/swap.c
> > > > F: mm/swap.h
> > > > +F: mm/swap_table.h
> > > > F: mm/swap_state.c
> > > > F: mm/swapfile.c
> > > >
> > >
> > > ...
> > >
> > > > #include <linux/swapops.h> /* for swp_offset */
> > >
> > > Now that swp_offset() is used in folio_index(), should this perhaps also be
> > > included for !CONFIG_SWAP?
> >
> > Hi, Thanks for looking at this series.
> >
> > >
> > > > #include <linux/blk_types.h> /* for bio_end_io_t */
> > > >
> > ...
> >
> > > > if (unlikely(folio_test_swapcache(folio)))
> > >
> > > > - return swap_cache_index(folio->swap);
> > > > + return swp_offset(folio->swap);
> > >
> > > This is outside CONFIG_SWAP.
> >
> > Right, but there are users of folio_index that are outside of
> > CONFIG_SWAP (mm/migrate.c), and swp_offset is also outside of SWAP so
> > that's OK.
> >
> > If we wrap it, the CONFIG_SWAP build will fail. I've test !CONFIG_SWAP
> > build on this patch and after the whole series, it works fine.
> >
> > We should drop the usage of folio_index in migrate.c, that's not
> > really related to this series though.
>
> Interesting that it works for you. I have a config with !CONFIG_SWAP which
> fails with:
>
> In file included from mm/shmem.c:44:
> mm/swap.h: In function ‘folio_index’:
> mm/swap.h:461:24: error: implicit declaration of function ‘swp_offset’; did you mean ‘pmd_offset’? [-Wimplicit-function-declaration]
> 461 | return swp_offset(folio->swap);
> | ^~~~~~~~~~
> | pmd_offset
>
> (though it's possible I have misapplied the series somehow).
> If I just move the linux/swapops.h include outside the CONFIG_SWAP ifdef:
>
> diff --git a/mm/swap.h b/mm/swap.h
> index caff4fe30fc5..12dd7d6478ff 100644
> --- a/mm/swap.h
> +++ b/mm/swap.h
> @@ -3,6 +3,7 @@
> #define _MM_SWAP_H
>
> #include <linux/atomic.h> /* for atomic_long_t */
> +#include <linux/swapops.h> /* for swp_offset */
> struct mempolicy;
> struct swap_iocb;
>
> @@ -54,7 +55,6 @@ enum swap_cluster_flags {
> };
>
> #ifdef CONFIG_SWAP
> -#include <linux/swapops.h> /* for swp_offset */
Oh, I think I know what the problem is here. You disabled SHMEM too.
Most users of swap.h includes linux/swapops.h already. But for
shmem.c, it doesn't include linux/swapops.h when !CONFIG_SHMEM
so swp_offset is undefined.
It's true that the problem is in swap.h, it should include swapops.h
for !SWAP too to avoid build error like this. Thanks for the report!
> #include <linux/blk_types.h> /* for bio_end_io_t */
>
> static inline unsigned int swp_cluster_offset(swp_entry_t entry)
>
> it fixes that issue for me, and my other CONFIG_SWAP builds do not seem
> to be impacted. I attached the config in case it's useful.
>
> >
> > >
> > > > return folio->index;
> > > > }
> > >
> > > ...
> > >
> > > Regards,
> > > Klara Modin
> > >
next prev parent reply other threads:[~2025-09-08 15:10 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 19:13 [PATCH v2 00/15] mm, swap: introduce swap table as swap cache (phase I) Kairui Song
2025-09-05 19:13 ` [PATCH v2 01/15] docs/mm: add document for swap table Kairui Song
2025-09-05 23:58 ` Chris Li
2025-09-06 13:31 ` Kairui Song
2025-09-08 12:35 ` Baoquan He
2025-09-08 14:27 ` Kairui Song
2025-09-08 15:06 ` Baoquan He
2025-09-08 15:01 ` Chris Li
2025-09-08 15:09 ` Baoquan He
2025-09-08 15:52 ` Chris Li
2025-09-05 19:13 ` [PATCH v2 02/15] mm, swap: use unified helper for swap cache look up Kairui Song
2025-09-05 23:59 ` Chris Li
2025-09-08 11:43 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 03/15] mm, swap: fix swap cahe index error when retrying reclaim Kairui Song
2025-09-05 22:40 ` Nhat Pham
2025-09-06 6:30 ` Kairui Song
2025-09-06 1:51 ` Chris Li
2025-09-06 6:28 ` Kairui Song
2025-09-06 11:58 ` Chris Li
2025-09-08 3:08 ` Baolin Wang
2025-09-08 11:45 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 04/15] mm, swap: check page poison flag after locking it Kairui Song
2025-09-06 2:00 ` Chris Li
2025-09-08 12:11 ` David Hildenbrand
2025-09-09 14:54 ` Kairui Song
2025-09-09 15:18 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 05/15] mm, swap: always lock and check the swap cache folio before use Kairui Song
2025-09-06 2:12 ` Chris Li
2025-09-06 6:32 ` Kairui Song
2025-09-08 12:18 ` David Hildenbrand
2025-09-09 14:58 ` Kairui Song
2025-09-09 15:19 ` David Hildenbrand
2025-09-10 12:56 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 06/15] mm, swap: rename and move some swap cluster definition and helpers Kairui Song
2025-09-06 2:13 ` Chris Li
2025-09-08 3:03 ` Baolin Wang
2025-09-05 19:13 ` [PATCH v2 07/15] mm, swap: tidy up swap device and cluster info helpers Kairui Song
2025-09-06 2:14 ` Chris Li
2025-09-08 12:21 ` David Hildenbrand
2025-09-08 15:01 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 08/15] mm/shmem, swap: remove redundant error handling for replacing folio Kairui Song
2025-09-08 3:17 ` Baolin Wang
2025-09-08 9:28 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 09/15] mm, swap: cleanup swap cache API and add kerneldoc Kairui Song
2025-09-06 5:45 ` Chris Li
2025-09-08 0:11 ` Barry Song
2025-09-08 3:23 ` Baolin Wang
2025-09-08 12:23 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 10/15] mm, swap: wrap swap cache replacement with a helper Kairui Song
2025-09-06 7:09 ` Chris Li
2025-09-08 3:41 ` Baolin Wang
2025-09-08 10:44 ` Kairui Song
2025-09-09 1:18 ` Baolin Wang
2025-09-08 12:30 ` David Hildenbrand
2025-09-08 14:20 ` Kairui Song
2025-09-08 14:39 ` David Hildenbrand
2025-09-08 14:49 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 11/15] mm, swap: use the swap table for the swap cache and switch API Kairui Song
2025-09-06 15:28 ` Chris Li
2025-09-08 15:38 ` Kairui Song
2025-09-07 12:55 ` Klara Modin
2025-09-08 14:34 ` Kairui Song
2025-09-08 15:00 ` Klara Modin
2025-09-08 15:10 ` Kairui Song [this message]
2025-09-08 13:45 ` David Hildenbrand
2025-09-08 15:14 ` Kairui Song
2025-09-08 15:32 ` Kairui Song
2025-09-10 2:53 ` SeongJae Park
2025-09-10 2:56 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 12/15] mm, swap: mark swap address space ro and add context debug check Kairui Song
2025-09-06 15:35 ` Chris Li
2025-09-08 13:10 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 13/15] mm, swap: remove contention workaround for swap cache Kairui Song
2025-09-06 15:30 ` Chris Li
2025-09-08 13:12 ` David Hildenbrand
2025-09-05 19:13 ` [PATCH v2 14/15] mm, swap: implement dynamic allocation of swap table Kairui Song
2025-09-06 15:45 ` Chris Li
2025-09-08 14:58 ` Kairui Song
2025-09-05 19:13 ` [PATCH v2 15/15] mm, swap: use a single page for swap table when the size fits Kairui Song
2025-09-06 15:48 ` Chris Li
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='CAMgjq7AHZ+X83pOUiOfhXWkV158uAvv=NQE6ibh33BQVgPJ5iA@mail.gmail.com' \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=klarasmodin@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=nphamcs@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--cc=yosryahmed@google.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