From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-81.mta0.migadu.com [91.218.175.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DF7414A8B for ; Mon, 17 Aug 2026 00:46:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786927614; cv=none; b=RebnkUJIwsRmQO66BCltDpMJG8tAC5lJI6Z5prWLu3ATZT4wX/DzySuoPJFY4j9Okwm1+rJsy+3yjBxXLnPcWN5pGJMbdPlzVVjj02gV+aNPK1YDGaVbJfph9WdT+ZIjYCup8gn28MjQwc3dggCISDa4szaZOavj+KW/54U8BpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786927614; c=relaxed/simple; bh=RmRDd0T1DmftRn82bVM/bMZ1+VjMHGBKK/DFk8gJdq8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bk6tZt84XD9KihOt8DvptKpNfktw8DgeBSdbOtQ1Ovtr/7nSGpQdePew02VhmGIK/0DO+17GEJ/sSP5d/tJCs9492/x7D+f1DPDKTDKh+yXu40subYq3uc75NWM1M4g/QpD49WJ9KDmaDzgR/PCyqT5lOzgGOMoskn5ZBji4DbI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=rBGMiwVR; arc=none smtp.client-ip=91.218.175.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rBGMiwVR" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RmRDd0T1DmftRn82bVM/bMZ1+VjMHGBKK/DFk8gJdq8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786927609; v=1; x=1787532409; b=rBGMiwVRPa6FNwY2Xcmct96xlWkXLN4nI5I6bEg5MeMcXms8EPI43kC1UKF/OKAs4MPtNr78 ShwtqRdd8ddL8X5jTrbNcEZL3OBG3BMLHsI4z3PNf8iZSk+1y0Ij9fwi1OjCvquU0C5yOxKsq+S vwBCR80WTQRuhK34UZ/P42HU= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (3.112.29.171) by mta12.migadu.com with ESMTPS id 35c9ec350a8c0870; Mon, 17 Aug 2026 00:46:49 +0000 X-Migadu-Flow: FLOW_OUT Date: Mon, 17 Aug 2026 08:46:41 +0800 From: Baoquan He To: Klara Modin Cc: Baoquan He , 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 Message-ID: References: <20260813104857.3450386-1-hebaoquan@kylinos.cn> <20260813104857.3450386-6-hebaoquan@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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