From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (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 A523435AC1D for ; Fri, 15 May 2026 05:51:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778824318; cv=none; b=p/3Evz2mr3aln/BvNI/lWF7KWTbeIxaqPQ+uJMq7BqDgPTaHLD5qReCMamtAnc7UI5fTwY47KW/QgNuyGTCmFtqjAmQykdbKGfiWN+xHQ/TPLrW9SCv8hRLhP5sPqwl2P6NUWfYDE6hCMJYNgx328NqWSZHBETlBnJKd5tA9PYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778824318; c=relaxed/simple; bh=fNv3W7ZimHG0yC3sLHwP9dIhiv24isjiJmPOWAflc5c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PCvp7JqzAWPivjmi7OG8YyOifz0LEcmFQom3c+AcqcOrnoxhIXDXDKPhBT8vfYIRXl3EEttScjnA8Wi+jzM68XpYObvntM+sqyWK804u9L1jPYGMfv9/bVuIA0H9jldbQYXBPdiV52H20TH41PACwh/09f7ALu9nYob+c98q1jQ= 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=h7UaCRrV; arc=none smtp.client-ip=91.218.175.174 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="h7UaCRrV" Date: Fri, 15 May 2026 13:51:49 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778824314; 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=UIOk2al9Vt/sBz7YJF+EdQDyWvBFeXp9LuduC5T9qX4=; b=h7UaCRrVzqm5T4YnE+NWwhgpv3YQM+ORdMqOcFKf2tbIlbSOZ35B+sa4KfC/nG4Xv0t3KL kim4NK36cJGGFpsLWyQsvsPpBESL6J3OrWckyKDWH6Bx5YNyKBDrTz68VEQo/uqZs6qKsc 6ZLBGf6CHNHMNuuOzd9Ew/5hoWl2F+8= 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? Well, I just double checked it, the "sis->ops" check in init_swap_ops is a embeded pointer in struct swap_info_struct. While here it's checking pointer embeded inside struct swap_iocb, it's different thing, isn't it? > > +int init_swap_ops(struct swap_info_struct *sis) > +{ > + ... > + > + if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio) > + return -EINVAL; > + > + return 0; > +}