]> git.ipfire.org Git - thirdparty/linux.git/commit
btrfs: use shrinker for compression page pool
authorDavid Sterba <dsterba@suse.com>
Wed, 15 Nov 2023 16:59:41 +0000 (17:59 +0100)
committerDavid Sterba <dsterba@suse.com>
Fri, 15 Dec 2023 19:27:01 +0000 (20:27 +0100)
commit4cea422a776558ccf84e918205d0c162a516502c
treecc9f5c3f623e0e9bf5990765c990bf1df5f5d134
parent9ba965dca3b13757e49f98bbea7cf48f07633ff9
btrfs: use shrinker for compression page pool

The pages are now allocated and freed centrally, so we can extend the
logic to manage the lifetime. The main idea is to keep a few recently
used pages and hand them to all writers. Ideally we won't have to go to
allocator at all (a slight performance gain) and also raise chance that
we'll have the pages available (slightly increased reliability).

In order to avoid gathering too many pages, the shrinker is attached to
the cache so we can free them on when MM demands that. The first
implementation will drain the whole cache. Further this can be refined
to keep some minimal number of pages for emergency purposes.  The
ultimate goal to avoid memory allocation failures on the write out path
from the compression.

The pool threshold is set to cover full BTRFS_MAX_COMPRESSED / PAGE_SIZE
for minimal thread pool, which is 8 (btrfs_init_fs_info()). This is 128K
/ 4K * 8 = 256 pages at maximum, which is 1MiB.

This is for all filesystems currently mounted, with heavy use of
compression IO the allocator is still needed. The cache helps for short
burst IO.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c