From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 BBEFB30CD85 for ; Fri, 15 May 2026 01:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778810297; cv=none; b=ZamzT9oLe3qhc6DYbfxMU+wnDRmoY5AJJQUjGw2rHTtbBAk+E8xn0xQ/9FBjkeXxTjNI74ry6RNAqUzxwIoo2FrSJeTf0ShGbNXbixncEZmTeiOCGECDxxcn2giu/QS5B4n3nURkVTdfvC3KswUasc82/MewalsLSChm3uLFQhI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778810297; c=relaxed/simple; bh=bMPjdzt1HQb1JHVWTPu4arI9X39DTCXQlIN//QLm8Nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=lM6xeWAcCoUjAQj5rJn3Rzh3h7PhTx4f9Qviuj7L3jDWGwiSRuoIr1cx/kshBdozY0igeua8bvtXyEVdaOdBBis0/G6uk3pgeHRWSQrRrqezz+zfWg+x2KyEyIrZEnSNV6zaMW836YYhEF/K18JHus2VSVq4S1m95e402XIX66E= 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=LntZuY8Q; arc=none smtp.client-ip=95.215.58.172 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="LntZuY8Q" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778810294; 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=oIPP5FhKMUzrX3A0EHFrIdCr5xrbmrEmKzfzM6TrS4c=; b=LntZuY8QFuRihoIjhUQTi0DBnkEvRf1icssDkm1b4W/Vp3zQZia9jEe+VYIBH1vMUs91bC l5FCfgeJ3t/4Tc2CyZPVJjzJIM5Esi3xhDadY9ApwsQGpcWEgeCbv1hD/IvsdaAFeFqYUs ySG9l1eDWBYUbDcgch5zYFOkXEk/UeU= From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, chrisl@kernel.org, usama.arif@linux.dev, baohua@kernel.org, kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com, youngjun.park@lge.com, hch@infradead.org, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v7 3/3] mm/swap: add unplug callback to swap_ops to fix leaky abstraction Date: Fri, 15 May 2026 09:57:37 +0800 Message-ID: <20260515015737.890994-4-baoquan.he@linux.dev> In-Reply-To: <20260515015737.890994-1-baoquan.he@linux.dev> References: <20260515015737.890994-1-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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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); +} + static void sio_read_complete(struct kiocb *iocb, long ret) { struct swap_iocb *sio = container_of(iocb, struct swap_iocb, iocb); @@ -599,6 +607,7 @@ static void swap_bdev_async_read_folio(struct swap_info_struct *sis, static const struct swap_ops bdev_fs_swap_ops = { .read_folio = swap_fs_read_folio, .write_folio = swap_fs_write_folio, + .unplug = swap_fs_write_folio_unplug, }; static const struct swap_ops bdev_sync_swap_ops = { diff --git a/mm/swap.h b/mm/swap.h index 8d4375f91632..67e3b1617146 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -224,6 +224,7 @@ struct swap_ops { void (*write_folio)(struct swap_info_struct *sis, struct folio *folio, struct swap_iocb **plug); + void (*unplug)(struct swap_iocb *sio); }; int init_swap_ops(struct swap_info_struct *sis); void swap_read_folio(struct folio *folio, struct swap_iocb **plug); -- 2.52.0