From 936b33f7243fa1e54c8f4f2febd3472cc00e66fd Mon Sep 17 00:00:00 2001
From: Mikulas Patocka <mpatocka@redhat.com>
Date: Thu, 9 May 2019 12:51:27 -0600
Subject: [PATCH] brd: add cond_resched to brd_free_pages

The loop that frees all the pages can take unbounded amount of time, so
add cond_resched() to it.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 drivers/block/brd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 17defbf4f332c..2da615b45b314 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -152,6 +152,12 @@ static void brd_free_pages(struct brd_device *brd)
 
 		pos++;
 
+		/*
+		 * It takes 3.4 seconds to remove 80GiB ramdisk.
+		 * So, we need cond_resched to avoid stalling the CPU.
+		 */
+		cond_resched();
+
 		/*
 		 * This assumes radix_tree_gang_lookup always returns as
 		 * many pages as possible. If the radix-tree code changes,
-- 
GitLab