From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1D09378839 for ; Mon, 11 May 2026 12:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778501838; cv=none; b=rfObFPlOodkJaDu4BULD4vVJIp8N0TeaVeK9sudQZlrH0y37jcRCEf48URw4oaYJiu96wWJn11r4EWrB8FFyo5PxOCFJ6ubHiVZEFANeYMbCH+jBEA3wWbgStuanPWIZn2AuNSMbDWx0NYYaG2SLXbbYMTjlGttP4dSuzeS8bmQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778501838; c=relaxed/simple; bh=TMY9gszTFTVr/JN5GDYu3nRdNkOqAixroNQnQU9coEA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pWXpc3BkTAC/kP1ADy3k+FENMBCggd3gUoh495qkx2umz7yNlAeu6+cbYiBQFFmiVM8PEYFfqMaVkRVRMErp2732Ljtlqmi8K5+iiiDsyMSU2aUcH7y0Z+URftuT+AJVU6mTVwNir+6dJEZvm+pblzZrYskVuLKWvoSdibKlOlo= 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=cl9hhl9W; arc=none smtp.client-ip=91.218.175.188 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="cl9hhl9W" Date: Mon, 11 May 2026 20:17:00 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778501832; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v1Xtp8ucmwoascdJlTfCMmSV9tphy+hPG1tbhbr9z9U=; b=cl9hhl9WX0F98pNQ5NWV5bfqT4tkm9/T2whpttx3jOkdzKxo0+X4UaferwfKdYD7MtUH7c Mj2H6Ox9046KWDIPYwPgc+/f8hoJXB/HkCDG0jzIgovKQuf9kOBuqfJkaMYV0e3oZ2HcKf lrDUKdDNIoPx72mrTRKSFvQPXHLyyyc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: Kairui Song Cc: linux-mm@kvack.org, akpm@linux-foundation.org, usama.arif@linux.dev, chrisl@kernel.org, baohua@kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260511073334.635682-1-baoquan.he@linux.dev> <20260511073334.635682-3-baoquan.he@linux.dev> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT On 05/11/26 at 04:37pm, Kairui Song wrote: > On Mon, May 11, 2026 at 3:43 PM Baoquan He wrote: > > > > This simplifies codes and makes logic clearer. And also makes later any > > new swap device type being added easier to handle. > > > > Currently there are three types of swap devices: bdev_fs, bdev_sync > > and bdev_async, and only operations read_folio and write_folio are > > included. In the future, there could be more swap device types added > > and more appropriate opeations adapted into swap_ops. > > Hi Baoquan, > > Thanks for the patch. Sorry I was busy with travel and a few other > series and didn't got a chance to look at a few previous versions. > > > +struct swap_ops { > > + void (*read_folio)(struct swap_info_struct *sis, > > + struct folio *folio, > > + struct swap_iocb **plug); > > + void (*write_folio)(struct swap_info_struct *sis, > > + struct folio *folio, > > + struct swap_iocb **plug); > > +}; > > Overall, I really like this idea, we can have a cleaner interface > starting there. > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 9174f1eeffb0..82d2c9b35b11 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3518,6 +3518,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) > > goto bad_swap_unlock_inode; > > } > > > > + error = init_swap_ops(si); > > + if (error) > > + goto bad_swap_unlock_inode; > > + > > But this part seems wrong? init_swap_ops is called before > setup_swap_extents -> swap_activate sets SWP_FS_OPS, or > SWP_SYNCHRONOUS_IO is set below, so the branches in init_swap_ops > never take effect, am I right? You need to move this someplace after > these flags are set. Maybe right before swapon_mutex so the mutex is a > clean barrier that the swap device will be used and all things before > that will be seen by users, with some comments. Speaking of comments, do you think below sentences are OK to you? diff --git a/mm/swapfile.c b/mm/swapfile.c index 82d2c9b35b11..8012e5e334f9 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3518,10 +3518,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) goto bad_swap_unlock_inode; } - error = init_swap_ops(si); - if (error) - goto bad_swap_unlock_inode; - si->max = maxpages; si->pages = maxpages - 1; nr_extents = setup_swap_extents(si, swap_file, &span); @@ -3616,6 +3612,15 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) goto free_swap_zswap; } + /* + * init_swap_ops() sets si->ops based on flags. It does not need + * swapon_mutex, and must complete before enable_swap_info() + * exposes the device. + */ + error = init_swap_ops(si); + if (error) + goto bad_swap_unlock_inode; + mutex_lock(&swapon_mutex); prio = DEF_SWAP_PRIO; if (swap_flags & SWAP_FLAG_PREFER)