From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 0/3] btrfs: use kvmalloc() for allocations that can be larger than page size
Date: Tue, 8 Sep 2026 16:45:38 +0930 [thread overview]
Message-ID: <cover.1788851649.git.wqu@suse.com> (raw)
With the experimental bs > ps support, btrfs can hit several kmalloc()
call sites requesting physically contiguous memory that are larger
than a page, sometimes such allocation can be as large as 64K.
This means those kmalloc() has a much higher chance to fail if the
system's available memory is very fragmented on 4K page sized systems.
And there is already a report that with 64K nodesize, even bs == ps we
can still hit such kmalloc() failure.
(https://lore.kernel.org/linux-btrfs/250decb0-d940-4fe6-9b54-d06e1b293a1b@suse.com/)
But we do not really require any physically contiguous memory for a lot
of kmalloc() call sites, we just want a buffer to save some data
temporarily.
So change those possible larger than page size kmalloc() to kvmalloc()
to reduce the chance of memory allocation failure.
And since kvmalloc() falls back to kmalloc() if the allocation is not
larger than a page, it means for most cases it's still calling
kmalloc(), not affecting the most common cases anyway.
The first patch is a special case that affects the existing bs == ps
cases already.
The second one only affects bs > ps cases.
The third one mostly affects bs > ps cases, but can still improve S390's
hardware accelerated path with 4K page size.
Qu Wenruo (3):
btrfs: use kvmalloc() for overwrite_item()
btrfs: use kvmalloc() for uncompress_inline()
btrfs: use kvmalloc() to allocate compression workspace buffer
fs/btrfs/inode.c | 4 ++--
fs/btrfs/tree-log.c | 4 ++--
fs/btrfs/zlib.c | 10 +++++-----
fs/btrfs/zstd.c | 4 ++--
4 files changed, 11 insertions(+), 11 deletions(-)
--
2.55.0
next reply other threads:[~2026-09-08 7:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 7:15 Qu Wenruo [this message]
2026-09-08 7:15 ` [PATCH 1/3] btrfs: use kvmalloc() for overwrite_item() Qu Wenruo
2026-09-08 7:32 ` Daniel Vacek
2026-09-08 7:15 ` [PATCH 2/3] btrfs: use kvmalloc() for uncompress_inline() Qu Wenruo
2026-09-08 7:34 ` Daniel Vacek
2026-09-08 7:15 ` [PATCH 3/3] btrfs: use kvmalloc() to allocate compression workspace buffer Qu Wenruo
2026-09-08 7:38 ` Daniel Vacek
2026-09-08 7:58 ` [PATCH 0/3] btrfs: use kvmalloc() for allocations that can be larger than page size Johannes Thumshirn
2026-09-08 15:40 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1788851649.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.