From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 057B53D522F for ; Wed, 15 Apr 2026 15:24:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776266696; cv=none; b=CQXGQxy5qIjDZ3c88Shzp5gA+MQW/J7FP6w0hbh7RzOPfkasVsQ/pGKvuJaOR3dTQTR2qWJna7Y9/xJFLeieVQp+jcKjRttx5+pDmkbb3dH8ung/OGYiLRw4oQxTxagASuTFzwsoptGuFzg3a3qaeTHQlV8G2SaAbKejp0HzlXg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776266696; c=relaxed/simple; bh=wTdie6TVDLjJ7LQWz04Teg+47CnFBlMTxKfJAcevP3U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SNNkFNpQUnDDWAQWqQOv63tsPNVincKuO3Z//1MRJBbMGXYFWPjMPV8Wp3hQFMoHF3uK9Vm9LAXarCp1p/SkOFESPA9dvCPBG0MHPNHuNFGjw3zUaZsNtWy4pNiXeIg8W8Ld/iorP6UytdZFxas0qzO5HJ5hNHzpr5XSqBTuR5Y= 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=kcGyWJCT; arc=none smtp.client-ip=95.215.58.176 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="kcGyWJCT" Date: Wed, 15 Apr 2026 23:24:43 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776266691; 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: in-reply-to:in-reply-to:references:references; bh=zRMRmyy9EWk8CIIPpL2LFE86JxkN0Rgl8uTe98Wyi+g=; b=kcGyWJCTD2OLfde0AeTZ55okox+Pnkciu73MjFRJ1zIV5E2AwF6UEHJ9ZYIEbAtmrc0g8L SH3hcXYZoNhWkjsAcsmqxjgu0slt/o/s4WqiqcjS7tpcLOiHOHIbMhmzTNbf3dUd/eoMjo 58m34J5LjDMs/5UYneSKpzAZOJ36RZ4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: Usama Arif Cc: linux-mm@kvack.org, akpm@linux-foundation.org, baohua@kernel.org, chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/3] mm/swap: use swap_ops to register swap device's methods Message-ID: References: <20260415085658.993859-3-baoquan.he@linux.dev> <20260415150550.3616172-1-usama.arif@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=us-ascii Content-Disposition: inline In-Reply-To: <20260415150550.3616172-1-usama.arif@linux.dev> X-Migadu-Flow: FLOW_OUT On 04/15/26 at 08:05am, Usama Arif wrote: > On Wed, 15 Apr 2026 16:56:57 +0800 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. > > s/opeations/operations/ Good catch, thanks. > > > > > Suggested-by: Chris Li > > Co-developed-by: Barry Song > > Signed-off-by: Barry Song > > Signed-off-by: Baoquan He > > --- > > include/linux/swap.h | 2 + > > mm/swap.h | 10 ++++- > > mm/swap_io.c | 102 +++++++++++++++++++++++++------------------ > > mm/swapfile.c | 5 +++ > > mm/zswap.c | 2 +- > > 5 files changed, 76 insertions(+), 45 deletions(-) > > ...snip... > > diff --git a/mm/swap_io.c b/mm/swap_io.c > > index 4bf210bd677e..602e9b871b30 100644 > > --- a/mm/swap_io.c > > +++ b/mm/swap_io.c ...snip... > > @@ -604,6 +588,44 @@ static void swap_read_folio_bdev_async(struct folio *folio, > > submit_bio(bio); > > } > > > > +static const struct swap_ops bdev_fs_swap_ops = { > > + .read_folio = swap_read_folio_fs, > > + .write_folio = swap_writepage_fs, > > +}; > > + > > +static const struct swap_ops bdev_sync_swap_ops = { > > + .read_folio = swap_read_folio_bdev_sync, > > + .write_folio = swap_writepage_bdev_sync, > > +}; > > + > > +static const struct swap_ops bdev_async_swap_ops = { > > + .read_folio = swap_read_folio_bdev_async, > > + .write_folio = swap_writepage_bdev_async, > > +}; > > + > > +int init_swap_ops(struct swap_info_struct *sis) > > +{ > > + /* > > + * ->flags can be updated non-atomically, but that will > > + * never affect SWP_FS_OPS, so the data_race is safe. > > + */ > > + if (data_race(sis->flags & SWP_FS_OPS)) > > + sis->ops = &bdev_fs_swap_ops; > > + /* > > + * ->flags can be updated non-atomically, but that will > > + * never affect SWP_SYNCHRONOUS_IO, so the data_race is safe. > > + */ > > + else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO)) > > + sis->ops = &bdev_sync_swap_ops; > > + else > > + sis->ops = &bdev_async_swap_ops; > > + > > + if (sis->ops || sis->ops->read_folio || sis->ops->write_folio) > > + return -1; > > sis->ops is always non-NULL, and you will return -1 here and > swapon will always fail with -EINVAL. > > You probably wanted? > > if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > return -1; You are right. Think one thing, write another. Will fix it in v4. Thanks a lot for your careful reviewing. > > > + > > + return 0; > > +} > > + > > void swap_read_folio(struct folio *folio, struct swap_iocb **plug) > > { > > struct swap_info_struct *sis = __swap_entry_to_info(folio->swap);