From 6aa34d9bcd7f8ee601ac90054006b8ee86a24923 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Tue, 11 Jan 2022 10:08:49 +0100 Subject: [PATCH] block: remove blk_needs_flush_plug blk_needs_flush_plug forgets to check the callbacks list and is one of a few reasons why blkdev.h needs to pull in sched.h. Remove it and just make blk_flush_plug check if there is a plug before calling out of line, which gets us 90% of the advantages without poking into details in the header. Signed-off-by: Christoph Hellwig --- block/blk-core.c | 7 +++---- fs/fs-writeback.c | 6 ++---- include/linux/blkdev.h | 18 ++++-------------- kernel/exit.c | 2 +- kernel/sched/core.c | 6 ++---- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 97f8bc8d3a79..f5f0d45841a4 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -991,8 +991,7 @@ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags) !test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) return 0; - if (current->plug) - blk_flush_plug(current->plug, false); + blk_flush_plug(current->plug, false); if (blk_queue_enter(q, BLK_MQ_REQ_NOWAIT)) return 0; @@ -1261,7 +1260,7 @@ struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data, } EXPORT_SYMBOL(blk_check_plugged); -void blk_flush_plug(struct blk_plug *plug, bool from_schedule) +void __blk_flush_plug(struct blk_plug *plug, bool from_schedule) { if (!list_empty(&plug->cb_list)) flush_plug_callbacks(plug, from_schedule); @@ -1290,7 +1289,7 @@ void blk_flush_plug(struct blk_plug *plug, bool from_schedule) void blk_finish_plug(struct blk_plug *plug) { if (plug == current->plug) { - blk_flush_plug(plug, false); + __blk_flush_plug(plug, false); current->plug = NULL; } } diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 67f0e88eed01..148b5a40c003 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1893,8 +1893,7 @@ static long writeback_sb_inodes(struct super_block *sb, * unplug, so get our IOs out the door before we * give up the CPU. */ - if (current->plug) - blk_flush_plug(current->plug, false); + blk_flush_plug(current->plug, false); cond_resched(); } @@ -2291,8 +2290,7 @@ void wakeup_flusher_threads(enum wb_reason reason) /* * If we are expecting writeback progress we must submit plugged IO. */ - if (blk_needs_flush_plug(current)) - blk_flush_plug(current->plug, true); + blk_flush_plug(current->plug, true); rcu_read_lock(); list_for_each_entry_rcu(bdi, &bdi_list, bdi_list) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9c95df26fc26..56351ac48909 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -2,7 +2,6 @@ #ifndef _LINUX_BLKDEV_H #define _LINUX_BLKDEV_H -#include #include #include #include @@ -790,15 +789,11 @@ extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, 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 bool blk_needs_flush_plug(struct task_struct *tsk) +void __blk_flush_plug(struct blk_plug *plug, bool from_schedule); +static inline void blk_flush_plug(struct blk_plug *plug, bool from_schedule) { - struct blk_plug *plug = tsk->plug; - - return plug && - (plug->mq_list || !list_empty(&plug->cb_list)); + if (plug) + __blk_flush_plug(plug, from_schedule); } int blkdev_issue_flush(struct block_device *bdev); @@ -824,11 +819,6 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async) { } -static inline bool blk_needs_flush_plug(struct task_struct *tsk) -{ - return false; -} - static inline int blkdev_issue_flush(struct block_device *bdev) { return 0; diff --git a/kernel/exit.c b/kernel/exit.c index f702a6a63686..a1e073254e14 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -742,7 +742,7 @@ void __noreturn do_exit(long code) * Then do everything else. */ - WARN_ON(blk_needs_flush_plug(tsk)); + WARN_ON(tsk->plug); if (unlikely(in_interrupt())) panic("Aiee, killing interrupt handler!"); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 76f9deeaa942..a99eb2d016ab 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6302,8 +6302,7 @@ static inline void sched_submit_work(struct task_struct *tsk) * If we are going to sleep and we have plugged IO queued, * make sure to submit it to avoid deadlocks. */ - if (blk_needs_flush_plug(tsk)) - blk_flush_plug(tsk->plug, true); + blk_flush_plug(tsk->plug, true); } static void sched_update_worker(struct task_struct *tsk) @@ -8335,8 +8334,7 @@ int io_schedule_prepare(void) int old_iowait = current->in_iowait; current->in_iowait = 1; - if (current->plug) - blk_flush_plug(current->plug, true); + blk_flush_plug(current->plug, true); return old_iowait; } -- 2.50.1