mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: Klara Modin <klarasmodin@gmail.com>
Cc: Baoquan He <hebaoquan@kylinos.cn>,
	linux-mm@kvack.org, chrisl@kernel.org, nphamcs@gmail.com,
	kasong@tencent.com, baohua@kernel.org, youngjun.park@lge.com,
	hannes@cmpxchg.org, yosry@kernel.org, shikemeng@huaweicloud.com,
	chengming.zhou@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC v3 05/15] mm, swap: add xswap cluster grow via VM_SPARSE vmalloc
Date: Mon, 17 Aug 2026 08:46:41 +0800	[thread overview]
Message-ID: <aoJZ8QKMhFgwgUFz@MiWiFi-R3L-srv> (raw)
In-Reply-To: <an-dmyT37Cq-aYUF@soda.int.kasm.eu>

On 08/15/26 at 01:09am, Klara Modin wrote:
> Hi,
> 
> On 2026-08-13 18:48:44 +0800, Baoquan He wrote:
> > Implement dynamic cluster_info array growth for xswap devices using a
> > VM_SPARSE vmalloc area:
> > 
......snip....
> > @@ -3562,6 +3757,64 @@ static int setup_swap_clusters_info(struct swap_info_struct *si,
> >  	int err = -ENOMEM;
> >  	unsigned long i;
> >  
> > +#ifdef CONFIG_XSWAP
> > +	if (si->flags & SWP_XSWAP) {
> > +		unsigned long size = PAGE_ALIGN(nr_clusters * sizeof(*cluster_info));
> > +		struct vm_struct *vm;
> > +
> > +		vm = get_vm_area(size, VM_SPARSE);
> > +		if (!vm)
> > +			goto err;
> > +
> > +		cluster_info = vm->addr;
> > +		si->cluster_vm = vm;
> > +		si->nr_clusters = nr_clusters;
> > +		si->cluster_info = cluster_info;
> 
> Should probably initialise the mutex here instead since
> xswap_map_clusters() uses it?

Many thanks for reviewing, and you are absolutely right. A real bug is
caught, I will wrap up the fix in the next version as you suggested.

Thanks
Baoquan
> 
> > +
> > +		/* Map the initial chunk (at least cluster 0) */
> > +		if (xswap_map_clusters(si, 0, min_t(unsigned long,
> > +					XSWAP_GROW_CLUSTERS, nr_clusters)))
> > +			goto err_free_vm;
> 
> > +
> > +		/* xswap: only cluster 0 slot 0 is bad */
> > +		err = swap_cluster_setup_bad_slot(si, cluster_info, 0, false);
> > +		if (err)
> > +			goto err_unmap;
> > +
> > +		INIT_LIST_HEAD(&si->free_clusters);
> > +		INIT_LIST_HEAD(&si->full_clusters);
> > +		INIT_LIST_HEAD(&si->discard_clusters);
> > +		for (i = 0; i < SWAP_NR_ORDERS; i++) {
> > +			INIT_LIST_HEAD(&si->nonfull_clusters[i]);
> > +			INIT_LIST_HEAD(&si->frag_clusters[i]);
> > +		}
> > +
> > +		/* Mark mapped clusters: cluster 0 has 1 bad slot, rest free */
> > +		for (i = 0; i < si->nr_clusters_mapped; i++) {
> > +			struct swap_cluster_info *ci = &cluster_info[i];
> > +
> > +			if (i == 0) {
> > +				ci->flags = CLUSTER_FLAG_NONFULL;
> > +				list_add_tail(&ci->list, &si->nonfull_clusters[0]);
> > +			} else {
> > +				ci->flags = CLUSTER_FLAG_FREE;
> > +				list_add_tail(&ci->list, &si->free_clusters);
> > +			}
> > +		}
> > +
> > +		mutex_init(&si->xswap_lock);
> > +		return 0;
> > +
> > +err_unmap:
> > +		xswap_unmap_clusters(si, 0, si->nr_clusters_mapped);
> > +err_free_vm:
> > +		free_vm_area(si->cluster_vm);
> > +		si->cluster_vm = NULL;
> > +		si->cluster_info = NULL;
> > +		return err;
> > +	}
> > +#endif /* CONFIG_XSWAP */
> > +
> >  	cluster_info = kvzalloc_objs(*cluster_info, nr_clusters);
> >  	if (!cluster_info)
> >  		goto err;
> > -- 
> > 2.54.0
> > 
> 
> Regards,
> Klara Modin

  reply	other threads:[~2026-08-17  0:46 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 10:48 [RFC v3 00/15] xswap: extendable (virtual) swap device backed by zswap Baoquan He
2026-08-13 10:48 ` [RFC v3 01/15] mm: zswap: return -ENOENT when the swap device is gone Baoquan He
2026-08-13 10:48 ` [RFC v3 02/15] mm: xswap support for zswap Baoquan He
2026-08-13 10:48 ` [RFC v3 03/15] mm, swap: add CONFIG_XSWAP and xswap fields to swap_info_struct Baoquan He
2026-08-13 10:48 ` [RFC v3 04/15] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-08-13 10:48 ` [RFC v3 05/15] mm, swap: add xswap cluster grow via VM_SPARSE vmalloc Baoquan He
2026-08-14 23:09   ` Klara Modin
2026-08-17  0:46     ` Baoquan He [this message]
2026-08-13 10:48 ` [RFC v3 06/15] mm, swap: add sysfs create interface for xswap Baoquan He
2026-08-13 10:48 ` [RFC v3 07/15] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-08-13 10:48 ` [RFC v3 08/15] mm, swap: add xswap_try_shrink and shrink trigger on cluster free Baoquan He
2026-08-13 10:48 ` [RFC v3 09/15] mm, swap: free backing pages in xswap_unmap_clusters Baoquan He
2026-08-13 10:48 ` [RFC v3 10/15] mm, swap: add nr_free_tail for O(1) xswap shrink detection Baoquan He
2026-08-13 10:48 ` [RFC v3 11/15] mm, swap: add adjustable runtime ceiling (nr_clusters) for xswap Baoquan He
2026-08-13 10:48 ` [RFC v3 12/15] mm, swap: add debugfs knob for xswap per-device cluster limit Baoquan He
2026-08-13 10:48 ` [RFC v3 13/15] mm, swap: defer xswap shrink to workqueue to avoid lock recursion Baoquan He
2026-08-13 10:48 ` [RFC v3 14/15] mm, swap: refactor swapoff + add xswap_destroy Baoquan He
2026-08-13 10:48 ` [RFC v3 15/15] mm, swap: require zswap for xswap devices Baoquan He
2026-09-02 14:22 ` [RFC v3 00/15] xswap: extendable (virtual) swap device backed by zswap Nhat Pham

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=aoJZ8QKMhFgwgUFz@MiWiFi-R3L-srv \
    --to=baoquan.he@linux.dev \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hebaoquan@kylinos.cn \
    --cc=kasong@tencent.com \
    --cc=klarasmodin@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=yosry@kernel.org \
    --cc=youngjun.park@lge.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

all inboxes | Powered by JetHome®