]> Git Repo - linux.git/commit
btrfs: do not wait for short bulk allocation
authorQu Wenruo <[email protected]>
Mon, 25 Mar 2024 22:46:46 +0000 (09:16 +1030)
committerDavid Sterba <[email protected]>
Tue, 9 Apr 2024 21:20:32 +0000 (23:20 +0200)
commit1db7959aacd905e6487d0478ac01d89f86eb1e51
treed784ed0b25cc830a22c77d0fbb385acf9f5bad97
parent073bda7a541731f41ed08f32d286394236c74005
btrfs: do not wait for short bulk allocation

[BUG]
There is a recent report that when memory pressure is high (including
cached pages), btrfs can spend most of its time on memory allocation in
btrfs_alloc_page_array() for compressed read/write.

[CAUSE]
For btrfs_alloc_page_array() we always go alloc_pages_bulk_array(), and
even if the bulk allocation failed (fell back to single page
allocation) we still retry but with extra memalloc_retry_wait().

If the bulk alloc only returned one page a time, we would spend a lot of
time on the retry wait.

The behavior was introduced in commit 395cb57e8560 ("btrfs: wait between
incomplete batch memory allocations").

[FIX]
Although the commit mentioned that other filesystems do the wait, it's
not the case at least nowadays.

All the mainlined filesystems only call memalloc_retry_wait() if they
failed to allocate any page (not only for bulk allocation).
If there is any progress, they won't call memalloc_retry_wait() at all.

For example, xfs_buf_alloc_pages() would only call memalloc_retry_wait()
if there is no allocation progress at all, and the call is not for
metadata readahead.

So I don't believe we should call memalloc_retry_wait() unconditionally
for short allocation.

Call memalloc_retry_wait() if it fails to allocate any page for tree
block allocation (which goes with __GFP_NOFAIL and may not need the
special handling anyway), and reduce the latency for
btrfs_alloc_page_array().

Reported-by: Julian Taylor <[email protected]>
Tested-by: Julian Taylor <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Fixes: 395cb57e8560 ("btrfs: wait between incomplete batch memory allocations")
CC: [email protected] # 6.1+
Reviewed-by: Sweet Tea Dorminy <[email protected]>
Reviewed-by: Filipe Manana <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
fs/btrfs/extent_io.c
This page took 0.057449 seconds and 4 git commands to generate.