Skip to content

Commit d6e6215

Browse files
Julian Sunbrauner
authored andcommitted
writeback: Add logging for slow writeback (exceeds sysctl_hung_task_timeout_secs)
When a writeback work lasts for sysctl_hung_task_timeout_secs, we want to identify that there are tasks waiting for a long time-this helps us pinpoint potential issues. Additionally, recording the starting jiffies is useful when debugging a crashed vmcore. Signed-off-by: Julian Sun <sunjunchao@bytedance.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 1888635 commit d6e6215

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

fs/fs-writeback.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ static void wb_queue_work(struct bdi_writeback *wb,
201201
spin_unlock_irq(&wb->work_lock);
202202
}
203203

204+
static bool wb_wait_for_completion_cb(struct wb_completion *done)
205+
{
206+
unsigned long waited_secs = (jiffies - done->wait_start) / HZ;
207+
208+
done->progress_stamp = jiffies;
209+
if (waited_secs > sysctl_hung_task_timeout_secs)
210+
pr_info("INFO: The task %s:%d has been waiting for writeback "
211+
"completion for more than %lu seconds.",
212+
current->comm, current->pid, waited_secs);
213+
214+
return !atomic_read(&done->cnt);
215+
}
216+
204217
/**
205218
* wb_wait_for_completion - wait for completion of bdi_writeback_works
206219
* @done: target wb_completion
@@ -213,9 +226,9 @@ static void wb_queue_work(struct bdi_writeback *wb,
213226
*/
214227
void wb_wait_for_completion(struct wb_completion *done)
215228
{
229+
done->wait_start = jiffies;
216230
atomic_dec(&done->cnt); /* put down the initial count */
217-
wait_event(*done->waitq,
218-
({ done->progress_stamp = jiffies; !atomic_read(&done->cnt); }));
231+
wait_event(*done->waitq, wb_wait_for_completion_cb(done));
219232
}
220233

221234
#ifdef CONFIG_CGROUP_WRITEBACK

include/linux/backing-dev-defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct wb_completion {
6464
atomic_t cnt;
6565
wait_queue_head_t *waitq;
6666
unsigned long progress_stamp; /* The jiffies when slow progress is detected */
67+
unsigned long wait_start; /* The jiffies when waiting for the writeback work to finish */
6768
};
6869

6970
#define __WB_COMPLETION_INIT(_waitq) \

0 commit comments

Comments
 (0)