linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/buffer: adjust the order of might_sleep() in __getblk_gfp()
@ 2023-03-23  9:37 gouhao
  2023-03-23 12:23 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: gouhao @ 2023-03-23  9:37 UTC (permalink / raw)
  To: viro, brauner; +Cc: linux-fsdevel, linux-kernel

From: Gou Hao <gouhao@uniontech.com>

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

Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 fs/buffer.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 9e1e2add541e..e13eff504fb5 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -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);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/buffer: adjust the order of might_sleep() in __getblk_gfp()
  2023-03-23  9:37 [PATCH] fs/buffer: adjust the order of might_sleep() in __getblk_gfp() gouhao
@ 2023-03-23 12:23 ` Matthew Wilcox
  2023-03-24  1:52   ` gouhao
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2023-03-23 12:23 UTC (permalink / raw)
  To: gouhao; +Cc: viro, brauner, linux-fsdevel, linux-kernel

On Thu, Mar 23, 2023 at 05:37:52PM +0800, gouhao@uniontech.com wrote:
> From: Gou Hao <gouhao@uniontech.com>
> 
> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/buffer: adjust the order of might_sleep() in __getblk_gfp()
  2023-03-23 12:23 ` Matthew Wilcox
@ 2023-03-24  1:52   ` gouhao
  0 siblings, 0 replies; 3+ messages in thread
From: gouhao @ 2023-03-24  1:52 UTC (permalink / raw)
  To: willy; +Cc: brauner, gouhao, linux-fsdevel, linux-kernel, viro

>On Thu, Mar 23, 2023 at 05:37:52PM +0800, gouhao@uniontech.com wrote:
>> From: Gou Hao <gouhao@uniontech.com>
>> 
>> 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! :)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-24  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-23  9:37 [PATCH] fs/buffer: adjust the order of might_sleep() in __getblk_gfp() gouhao
2023-03-23 12:23 ` Matthew Wilcox
2023-03-24  1:52   ` gouhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).