Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: add __GFP_NOFAIL to the kvmalloc in split_item
@ 2026-12-03 23:36 Boris Burkov
  2026-12-04  0:00 ` Qu Wenruo
  2026-12-04 11:33 ` Harry Yoo
  0 siblings, 2 replies; 4+ messages in thread
From: Boris Burkov @ 2026-12-03 23:36 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Shakeel Butt, Kiryl Shutsemau, Harry Yoo

The recent patch
b2ba99cf6f7b ("btrfs: use kvmalloc() for b-tree split_item()")

improved the behavior of the split_item() allocation for allocations of
order >= 4. However, we have observed that it seems to regress the
allocations of order 2 that are more typical for btrfs with 4k page
size, 16k nodesize and crc32c checksums (split_item gets called from
btrfs_del_csums only currently)

I believe that this is caused by kvmalloc having a path for failing
allocations (regardless of order) when fatal_signal_pending() is true on
the task as checked by vm_area_alloc_pages():

if (!(gfp & __GFP_NOFAIL) && fatal_signal_pending(current))
        break;

reached by the following callchain:
kvmalloc(item_size, GFP_NOFS)
  __kvmalloc_node_noprof()
    __do_kmalloc_node()
    __vmalloc_node_range_noprof()
      __vmalloc_area_node()
        vm_area_alloc_pages()

This results in the same signature of an ENOMEM abort observed in the
original patch:

BTRFS: error (device dm-3 state A) in btrfs_del_csums:1053: errno=-12 Out of memory
Link: https://lore.kernel.org/linux-btrfs/2ab022c5c7e07345a9fc91915836cbd4ab2d25ef.1788819456.git.wqu@suse.com/

I believe we could attempt to also fix this by having a mempool for this
csum deletion temporary item buffer, but save that for a follow-up since
this is a narrow fix for an immediate problem.

Fixes: b2ba99cf6f7b ("btrfs: use kvmalloc() for b-tree split_item()")
Signed-off-by: Boris Burkov <boris@bur.io>
---
 fs/btrfs/ctree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index a70860bfd109..b05fc297ebea 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -3943,7 +3943,7 @@ static noinline int split_item(struct btrfs_trans_handle *trans,
 	orig_offset = btrfs_item_offset(leaf, path->slots[0]);
 	item_size = btrfs_item_size(leaf, path->slots[0]);
 
-	buf = kvmalloc(item_size, GFP_NOFS);
+	buf = kvmalloc(item_size, GFP_NOFS | __GFP_NOFAIL);
 	if (!buf)
 		return -ENOMEM;
 
-- 
2.56.0


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

end of thread, other threads:[~2026-12-04 11:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 23:36 [PATCH] btrfs: add __GFP_NOFAIL to the kvmalloc in split_item Boris Burkov
2026-12-04  0:00 ` Qu Wenruo
2026-12-04  4:41   ` Qu Wenruo
2026-12-04 11:33 ` Harry Yoo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox