Skip to contentSkip to conversation

fs/buffer: adjust the order of might_sleep() in __getblk_gfp()

PATCH In review [email protected] 2 participants 3 messages Mar 23, 2023 – Mar 24, 2023 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/buffer: adjust the order of might_sleep() in __getblk_gfp()

From: Gou Hao <[email protected]>

If 'bh' is found in cache, just return directly.
might_sleep() is only required on slow paths.

---
 fs/buffer.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
fs/buffer.c +4 -3
index 9e1e2add541e..e13eff504fb5 100644
@@ -1371,10 +1371,11 @@ __getblk_gfp(struct block_device *bdev, sector_t block,
 {
 	struct buffer_head *bh = __find_get_block(bdev, block, size);
 
+	if (bh)
+		return bh;
+
 	might_sleep();
-	if (bh == NULL)
-		bh = __getblk_slow(bdev, block, size, gfp);
-	return bh;
+	return __getblk_slow(bdev, block, size, gfp);
 }
 EXPORT_SYMBOL(__getblk_gfp);
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 4 lines · On Thu, Mar 23, 2023 at 05:37:52PM +0800, [email protected] wrote:

From: Gou Hao <[email protected]>

If 'bh' is found in cache, just return directly.
might_sleep() is only required on slow paths.

You're missing the point. The caller can't know whether the slow or fast path will be taken. So it must _never_ call this function if it cannot sleep.

#2 lore raw
Quoted 9 lines · On Thu, Mar 23, 2023 at 05:37:52PM +0800, [email protected] wrote:
Quoted 4 lines

From: Gou Hao <[email protected]>

If 'bh' is found in cache, just return directly.
might_sleep() is only required on slow paths.

You're missing the point. The caller can't know whether the slow or fast path will be taken. So it must _never_ call this function if it cannot sleep.

I see. Thank you for your explanation! :)