From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 DAEDC3A9D9B; Mon, 6 Jul 2026 04:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783311101; cv=none; b=PgVka6nsw2n+3Rd8cdV7h0pJGgkRaP6MV6kdGPTncQXiqyJIUBSR+94sKK9/9ewEY9nkd7HMVUVzuPGOv73+RQRlnRaRRei+UwWPmXdeMD3TCa78r7Q9DN4KepMcjtUMA7PSLKwAcAOA8OgRKIRoj+bzVgTDQD0X5Y2PvH84kic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783311101; c=relaxed/simple; bh=7EIfSD4zUKwCTq6mQcB3QWDCPD/HmMaJ0wtRe12KHHs=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=msls82wgjsAW9XXQUTOujC/FQYUS3py2/jasAxwOYTwhw/HBvicTKeNGFjY1LdlXkxI7Tc4tqJOY5Kko9pU84UZYJZF9C00BxvHhKTglzo8YOTc3MP0YWqzy/sh5aq/yWLUazbXAvsUP6RH1n20dGJvJEPnqZBm/MdDifrvCJz0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ArKOzEqt; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ArKOzEqt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=qgSk7nCZFkI9gf+sjMVY+BqFP42Rck99sMffUrmwwfg=; b=ArKOzEqtp6QZoSPinq7HOSwi5m w4LqP2g0XqjGd9BI9gPUJl8+zoEmIaecaA5ejxvaXM60J4JumdgUwo++7cabDl4jUYwSzj3nG5JsI n3GF5DvNL18gKpHRfpn4sgoRGxWsV07kzrOFyZBjw9+FZ7ECrJCUcOd7OrV4l1cYk9zIsMHjhsEAt lXjoVem7E6PvMc96WjCaNby+tzbjab9gErQxkwn+9hSk7mk4eW5AhteQmMLe6EmJJ+S66QdE6f8+B 81wSemkMPL2l1qGf/FVTo/MWeuRjPIoU8EbVsSq64g2b3Aio1uCaLu70kHeZlmI4UnzULgeh0oRxm w/B0VRGg==; Received: from 85-127-110-197.dsl.dynamic.surfer.at ([85.127.110.197] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wgag6-0000000BUGu-0PkE; Mon, 06 Jul 2026 04:11:30 +0000 From: Christoph Hellwig To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] block: split out a new blk_plug.h helper Date: Mon, 6 Jul 2026 06:11:25 +0200 Message-ID: <20260706041125.642097-1-hch@lst.de> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html blkdev.h gets included in various places outside the block layer just for struct blk_plug and related plugging functions. Split blk_plug into a separate helper to reduce the amount of code that needs to get rebuilt when blkdev.h changes and to slightly reduce compile times. In io_uring this requires pulling in a few other headers explicitly that previously were implicitly included through blkdev.h. Signed-off-by: Christoph Hellwig --- fs/aio.c | 2 +- fs/fs-writeback.c | 2 +- include/linux/blk_plug.h | 95 ++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 86 +----------------------------- include/linux/io_uring_types.h | 2 +- io_uring/io_uring.h | 1 + io_uring/kbuf.c | 1 + io_uring/rsrc.h | 2 + io_uring/rw.h | 1 + kernel/exit.c | 1 - kernel/sched/core.c | 1 - mm/madvise.c | 2 +- mm/page-writeback.c | 1 - mm/readahead.c | 2 +- mm/swap_state.c | 2 +- mm/vmscan.c | 2 +- 16 files changed, 108 insertions(+), 95 deletions(-) create mode 100644 include/linux/blk_plug.h diff --git a/fs/aio.c b/fs/aio.c index f57fa21a2503..ebdb0e5b95fd 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index fdb8766d275a..d064072284f4 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/linux/blk_plug.h b/include/linux/blk_plug.h new file mode 100644 index 000000000000..2ac1265662ad --- /dev/null +++ b/include/linux/blk_plug.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_BLK_PLUG_H +#define _LINUX_BLK_PLUG_H + +#include + +struct blk_plug_cb; +typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *cb, bool from_schedule); + +struct rq_list { + struct request *head; + struct request *tail; +}; + +#ifdef CONFIG_BLOCK +/* + * blk_plug permits building a queue of related requests by holding the I/O + * fragments for a short period. This allows merging of sequential requests + * into single larger request. As the requests are moved from a per-task list to + * the device's request_queue in a batch, this results in improved scalability + * as the lock contention for request_queue lock is reduced. + * + * It is ok not to disable preemption when adding the request to the plug list + * or when attempting a merge. For details, please see schedule() where + * blk_flush_plug() is called. + */ +struct blk_plug { + struct rq_list mq_list; /* blk-mq requests */ + + /* if ios_left is > 1, we can batch tag/rq allocations */ + struct rq_list cached_rqs; + u64 cur_ktime; + unsigned short nr_ios; + + unsigned short rq_count; + + bool multiple_queues; + bool has_elevator; + + struct list_head cb_list; /* md requires an unplug callback */ +}; + +void blk_start_plug(struct blk_plug *); +void blk_start_plug_nr_ios(struct blk_plug *, unsigned short); +void blk_finish_plug(struct blk_plug *); + +void __blk_flush_plug(struct blk_plug *plug, bool from_schedule); +static inline void blk_flush_plug(struct blk_plug *plug, bool async) +{ + if (plug) + __blk_flush_plug(plug, async); +} + +static __always_inline void blk_plug_invalidate_ts(void) +{ + if (unlikely(current->flags & PF_BLOCK_TS)) { + current->plug->cur_ktime = 0; + current->flags &= ~PF_BLOCK_TS; + } +} + +struct blk_plug_cb { + struct list_head list; + blk_plug_cb_fn callback; + void *data; +}; + +struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data, + int size); +#else /* CONFIG_BLOCK */ +struct blk_plug { +}; + +static inline void blk_start_plug(struct blk_plug *plug) +{ +} + +static inline void blk_start_plug_nr_ios(struct blk_plug *plug, + unsigned short nr_ios) +{ +} + +static inline void blk_finish_plug(struct blk_plug *plug) +{ +} + +static inline void blk_flush_plug(struct blk_plug *plug, bool async) +{ +} + +static inline void blk_plug_invalidate_ts(void) +{ +} +#endif /* CONFIG_BLOCK */ +#endif /* _LINUX_BLK_PLUG_H */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9213a5716f95..20cb8ed7d987 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -1169,94 +1169,10 @@ extern void blk_put_queue(struct request_queue *); void blk_mark_disk_dead(struct gendisk *disk); -struct rq_list { - struct request *head; - struct request *tail; -}; - #ifdef CONFIG_BLOCK -/* - * blk_plug permits building a queue of related requests by holding the I/O - * fragments for a short period. This allows merging of sequential requests - * into single larger request. As the requests are moved from a per-task list to - * the device's request_queue in a batch, this results in improved scalability - * as the lock contention for request_queue lock is reduced. - * - * It is ok not to disable preemption when adding the request to the plug list - * or when attempting a merge. For details, please see schedule() where - * blk_flush_plug() is called. - */ -struct blk_plug { - struct rq_list mq_list; /* blk-mq requests */ - - /* if ios_left is > 1, we can batch tag/rq allocations */ - struct rq_list cached_rqs; - u64 cur_ktime; - unsigned short nr_ios; - - unsigned short rq_count; - - bool multiple_queues; - bool has_elevator; - - struct list_head cb_list; /* md requires an unplug callback */ -}; - -struct blk_plug_cb; -typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); -struct blk_plug_cb { - struct list_head list; - blk_plug_cb_fn callback; - void *data; -}; -extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, - void *data, int size); -extern void blk_start_plug(struct blk_plug *); -extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short); -extern void blk_finish_plug(struct blk_plug *); - -void __blk_flush_plug(struct blk_plug *plug, bool from_schedule); -static inline void blk_flush_plug(struct blk_plug *plug, bool async) -{ - if (plug) - __blk_flush_plug(plug, async); -} - -static __always_inline void blk_plug_invalidate_ts(void) -{ - if (unlikely(current->flags & PF_BLOCK_TS)) { - current->plug->cur_ktime = 0; - current->flags &= ~PF_BLOCK_TS; - } -} - int blkdev_issue_flush(struct block_device *bdev); long nr_blockdev_pages(void); #else /* CONFIG_BLOCK */ -struct blk_plug { -}; - -static inline void blk_start_plug_nr_ios(struct blk_plug *plug, - unsigned short nr_ios) -{ -} - -static inline void blk_start_plug(struct blk_plug *plug) -{ -} - -static inline void blk_finish_plug(struct blk_plug *plug) -{ -} - -static inline void blk_flush_plug(struct blk_plug *plug, bool async) -{ -} - -static inline void blk_plug_invalidate_ts(void) -{ -} - static inline int blkdev_issue_flush(struct block_device *bdev) { return 0; diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index a2c623a67a25..f302bb3fcf8e 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -1,7 +1,7 @@ #ifndef IO_URING_TYPES_H #define IO_URING_TYPES_H -#include +#include #include #include #include diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index cb736b815422..9771d4557ed3 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -3,6 +3,7 @@ #define IOU_CORE_H #include +#include #include #include #include diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index 3cd29477fff2..e58bff9037f1 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index 98ae8ef51009..eacfdb70f203 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -2,8 +2,10 @@ #ifndef IOU_RSRC_H #define IOU_RSRC_H +#include #include #include +#include #define IO_VEC_CACHE_SOFT_CAP 256 diff --git a/io_uring/rw.h b/io_uring/rw.h index 9bd7fbf70ea9..1179506f929f 100644 --- a/io_uring/rw.h +++ b/io_uring/rw.h @@ -2,6 +2,7 @@ #include #include +#include struct io_meta_state { u32 seed; diff --git a/kernel/exit.c b/kernel/exit.c index 1056422bc101..2140d0515f9e 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -48,7 +48,6 @@ #include /* for audit_free() */ #include #include -#include #include #include #include diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 96226707c2f6..616774777dea 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -40,7 +40,6 @@ #include #include -#include #include #include #include diff --git a/mm/madvise.c b/mm/madvise.c index cd9bb077072c..f6b7ef0f8b1b 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/mm/page-writeback.c b/mm/page-writeback.c index e98748112d1e..d1fd6ba58ae5 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/mm/readahead.c b/mm/readahead.c index 558c92957518..6e5563290287 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -113,7 +113,7 @@ * ->read_folio() which may be less efficient. */ -#include +#include #include #include #include diff --git a/mm/swap_state.c b/mm/swap_state.c index 9c3a5cf99778..727a17ee7821 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/mm/vmscan.c b/mm/vmscan.c index 35c3bb15ae96..b957664abb26 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include /* for buffer_heads_over_limit */ #include #include -- 2.53.0