From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 7499236404D for ; Fri, 15 May 2026 05:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778823810; cv=none; b=P+h+8rg2g1LRJ7hqhwuqu/yehbwZt5Q84dc7ED82V2+qSQGODEKrUIgVyL7jkhoBVECixnUwNCh12QJ1Xzo6OASOMgIozHA9El3ITDKCEzXFyauYkOi+j/05L7VnXZX0STDXiXlHOmpkueY9dt6OKFCNEjOdFjwh8CtcVRrpw10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778823810; c=relaxed/simple; bh=wHCQF4sRrOJDB69u3kJnNTPgzrNjwzPLO6xvBaC3P2o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uo74C2J13szcZE23p25L44ANTbtPGw3ncwg7RitDlr6um+gSBEeuaMsm/M9M9YUCSVAvzlkXGDFXxCbfhthTdDhNywBSaQTCSvy/ZFpj7nuhJ37w+AvV+xVDKwum60aM+y3ZS5bu9daaWJiVFxO70nj6cjPNPrcXVof5e7mnR7g= 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=kxy/4Esu; arc=none smtp.client-ip=91.218.175.184 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="kxy/4Esu" Date: Fri, 15 May 2026 13:43:18 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778823805; 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=1ZV9qpUxgwNTdiW6770LA+y9TmWtjhD445HqaVmW9eQ=; b=kxy/4EsuFBleWBFg4bofQSoVwmIAGS4m+89f7JWMV1+0sUstE0dgbayPfJVB0MLhClhd7T 9Axzx0PlgcKWwQAR/6z3Xdl1hjaWiSTwCviQVH1PRlTT86f8FFmYyAe+JxyckASIy8kLV4 3ta3NBTu8ggu6OWTiFFT2uzbYZ32MeY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Baoquan He To: Barry Song Cc: linux-mm@kvack.org, akpm@linux-foundation.org, chrisl@kernel.org, usama.arif@linux.dev, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, hch@infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 3/3] mm/swap: add unplug callback to swap_ops to fix leaky abstraction Message-ID: References: <20260515015737.890994-1-baoquan.he@linux.dev> <20260515015737.890994-4-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/15/26 at 12:39pm, Barry Song wrote: > On Fri, May 15, 2026 at 9:58 AM Baoquan He wrote: > > > > When swap_ops was introduced, the FS-swap batch submission remained > > as a standalone swap_write_unplug() that directly called > > mapping->a_ops->swap_rw(). This meant callers still had implicit > > knowledge of filesystem internals rather than going through the > > swap_ops abstraction. > > > > Fix this by adding an unplug callback to struct swap_ops. > > Each ops table provides its own implementation: > > - bdev_fs_swap_ops uses the existing FS batch-submission logic > > - bdev_sync/bdev_async_swap_ops leave it NULL since block-layer > > plugging handles their I/O > > > > The swap_iocb now carries a pointer to its ops table so that > > swap_write_unplug() can dispatch through the callback without > > the caller needing to know the swap device type. > > > > Signed-off-by: Baoquan He > > --- > > mm/page_io.c | 11 ++++++++++- > > mm/swap.h | 1 + > > 2 files changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/mm/page_io.c b/mm/page_io.c > > index 38b94c560c37..2c36d261ad98 100644 > > --- a/mm/page_io.c > > +++ b/mm/page_io.c > > @@ -329,6 +329,7 @@ static void bio_associate_blkg_from_page(struct bio *bio, struct folio *folio) > > > > struct swap_iocb { > > struct kiocb iocb; > > + const struct swap_ops *ops; > > struct bio_vec bvec[SWAP_CLUSTER_MAX]; > > int pages; > > int len; > > @@ -401,6 +402,7 @@ static void swap_fs_write_folio(struct swap_info_struct *sis, > > init_sync_kiocb(&sio->iocb, swap_file); > > sio->iocb.ki_complete = sio_write_complete; > > sio->iocb.ki_pos = pos; > > + sio->ops = sis->ops; > > sio->pages = 0; > > sio->len = 0; > > } > > @@ -454,7 +456,7 @@ static void swap_bdev_async_write_folio(struct swap_info_struct *sis, > > submit_bio(bio); > > } > > > > -void swap_write_unplug(struct swap_iocb *sio) > > +static void swap_fs_write_folio_unplug(struct swap_iocb *sio) > > { > > struct iov_iter from; > > struct address_space *mapping = sio->iocb.ki_filp->f_mapping; > > @@ -466,6 +468,12 @@ void swap_write_unplug(struct swap_iocb *sio) > > sio_write_complete(&sio->iocb, ret); > > } > > > > +void swap_write_unplug(struct swap_iocb *sio) > > +{ > > + if (sio->ops && sio->ops->unplug) > > + sio->ops->unplug(sio); > > +} > > + > > Hi Baoquan, > > we have already "sis->ops" check in init_swap_ops, do we need !sis->ops > again? That's a good point, and no, I dont' think we need it. I will fix it in v8. Thanks. > > +int init_swap_ops(struct swap_info_struct *sis) > +{ > + ... > + > + if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > + return -EINVAL; > + > + return 0; > +}