fs/writeback: only calculate dirtied_before when b_io is empty
authorKemeng Shi <shikemeng@huaweicloud.com>
Wed, 28 Feb 2024 09:19:56 +0000 (17:19 +0800)
committerChristian Brauner <brauner@kernel.org>
Fri, 5 Apr 2024 13:53:45 +0000 (15:53 +0200)
The dirtied_before is only used when b_io is not empty, so only calculate
when b_io is not empty.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Link: https://lore.kernel.org/r/20240228091958.288260-5-shikemeng@huaweicloud.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/fs-writeback.c

index a754eb25453576921533504121878d50b69d2e50..cbfb3e05e1206ac5f237ece6453824ebacc8356a 100644 (file)
@@ -2105,20 +2105,21 @@ static long wb_writeback(struct bdi_writeback *wb,
 
                spin_lock(&wb->list_lock);
 
-               /*
-                * Kupdate and background works are special and we want to
-                * include all inodes that need writing. Livelock avoidance is
-                * handled by these works yielding to any other work so we are
-                * safe.
-                */
-               if (work->for_kupdate) {
-                       dirtied_before = jiffies -
-                               msecs_to_jiffies(dirty_expire_interval * 10);
-               } else if (work->for_background)
-                       dirtied_before = jiffies;
-
                trace_writeback_start(wb, work);
                if (list_empty(&wb->b_io)) {
+                       /*
+                        * Kupdate and background works are special and we want
+                        * to include all inodes that need writing. Livelock
+                        * avoidance is handled by these works yielding to any
+                        * other work so we are safe.
+                        */
+                       if (work->for_kupdate) {
+                               dirtied_before = jiffies -
+                                       msecs_to_jiffies(dirty_expire_interval *
+                                                        10);
+                       } else if (work->for_background)
+                               dirtied_before = jiffies;
+
                        queue_io(wb, work, dirtied_before);
                        queued = true;
                }