diff mbox series

[08/16] block: optimise blk_flush_plug_list

Message ID a9127996b15a859a0041245b4a9507f97f155f7f.1634676157.git.asml.silence@gmail.com (mailing list archive)
State New, archived
Headers show
Series block optimisation round | expand

Commit Message

Pavel Begunkov Oct. 19, 2021, 9:24 p.m. UTC
First, don't init a callback list if there are no plug callbacks. Also,
replace internals of the function with do-while.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 block/blk-mq.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig Oct. 20, 2021, 6:29 a.m. UTC | #1
On Tue, Oct 19, 2021 at 10:24:17PM +0100, Pavel Begunkov wrote:
> First, don't init a callback list if there are no plug callbacks. Also,
> replace internals of the function with do-while.

So the check to not call into the callback code when there are none,
which is the usual case, totally makes sense.  But what is the point of
the rest?
Pavel Begunkov Oct. 20, 2021, 12:26 p.m. UTC | #2
On 10/20/21 07:29, Christoph Hellwig wrote:
> On Tue, Oct 19, 2021 at 10:24:17PM +0100, Pavel Begunkov wrote:
>> First, don't init a callback list if there are no plug callbacks. Also,
>> replace internals of the function with do-while.
> 
> So the check to not call into the callback code when there are none,
> which is the usual case, totally makes sense.  But what is the point of
> the rest?

I don't care much about that part, can leave it alone, especially if
blk_flush_plug_list() stays in blk-core.c. I'll likely squash this
patch into the previous one.
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 6bdbaa838030..6627ea76f7c6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2251,22 +2251,24 @@  static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
 {
 	LIST_HEAD(callbacks);
 
-	while (!list_empty(&plug->cb_list)) {
+	do {
 		list_splice_init(&plug->cb_list, &callbacks);
 
-		while (!list_empty(&callbacks)) {
+		do {
 			struct blk_plug_cb *cb = list_first_entry(&callbacks,
 							  struct blk_plug_cb,
 							  list);
+
 			list_del(&cb->list);
 			cb->callback(cb, from_schedule);
-		}
-	}
+		} while (!list_empty(&callbacks));
+	} while (!list_empty(&plug->cb_list));
 }
 
 void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 {
-	flush_plug_callbacks(plug, from_schedule);
+	if (!list_empty(&plug->cb_list))
+		flush_plug_callbacks(plug, from_schedule);
 
 	if (!rq_list_empty(plug->mq_list))
 		blk_mq_flush_plug_list(plug, from_schedule);