bcachefs-tools/linux
Chris Webb 872cd437e7 bcachefs-tools: Avoid glibc-specific mallinfo() in shrinker
Before 326d7c1, the shrinker used freeram and totalram from a struct
sysinfo (constructed from /proc/meminfo) to target 25% free physical
memory. As well as the slowness of repeatedly reading /proc/meminfo,
this was a problem as freeram rises when the system starts to swap.
We don't want swapping to reduce our estimate of memory pressure.

To work around this, in 326d7c1 the shrinker started to use the total
allocated heap from a glibc-specific interface mallinfo2(), aiming to
shrink such that our heap is less than 80% of physical memory, unless
overall free memory is less than 6% so that becomes the determining factor.

Unfortunately, a sign error in the calculation means this heuristic
never worked. It would shrink aggressively when the process was small,
and not at all when the process grew beyond 80% of physical RAM. Only the
fallback test ensuring the free physical RAM doesn't fall below 6% would
actually kick in under memory pressure. It also breaks portability to
anything other than recent glibc.

Later, in 2440469 the mallinfo2() was replaced with the older mallinfo()
to improve compatibility with older glibc. This is even more problematic:
it's still not portable but also struct mallinfo has (signed) int fields
which overflow for large processes on 32-bit machines with a 3G/1G split.

Rather than trying to use libc-specific debug interfaces and our own heap
to inform the shrinker, use the information about free and total swap
we already have from sysinfo(2) to explicitly compensate for swapping
in our estimate of free physical memory. Target free memory of 6% of
physical RAM adjusted for zero swap use when calculating the pressure
on the shrinker, based on the effective behaviour of 326d7c1 in practice
given the sign error.

As well as fixing portability to non-glibc systems, this loosens the
assumption that we are the only process using significant memory when
setting the shrinker target. It wouldn't be unreasonable to run two
fsck jobs against independent devices on a large RAM machine and want to
balance physical RAM between them.

Signed-off-by: Chris Webb <chris@arachsys.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-09 23:28:01 -05:00
..
crypto
atomic64.c
bio.c Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into multiple functions 2023-06-27 19:38:18 -04:00
blkdev.c Handle -EAGAIN from io_submit() 2023-09-29 01:27:59 -04:00
closure.c Update bcachefs sources to 783085c3cc44 kbuild: Allow gcov to be enabled on the command line 2023-11-22 16:55:06 -05:00
crc64.c
crc64table.h
fs.c Update bcachefs sources to 84f132d569 bcachefs: fsck: Break walk_inode() up into multiple functions 2023-06-27 19:38:18 -04:00
generic-radix-tree.c Update bcachefs sources to 6ddf061e68 bcachefs: Use a genradix for reading journal entries 2022-04-08 19:26:30 -04:00
int_sqrt.c Update bcachefs sources to 3e93567c51 bcachefs: Switch to local_clock() for fastpath time source 2022-10-15 01:04:30 -04:00
kstrtox.c
kstrtox.h
kthread.c Run shrinkers when pthread_create fails 2023-07-20 21:28:03 -04:00
llist.c Update llist code 2019-08-28 11:35:00 -04:00
mempool.c Add a real mempool implementation 2021-04-24 01:36:43 -04:00
preempt.c Fix building on musl 2020-05-05 10:29:31 +01:00
ratelimit.c Fix printk_ratelimited() 2022-06-22 22:05:39 -04:00
rhashtable.c Update bcachefs sources to 18686af684 bcachefs: Inode backpointers 2021-03-29 00:22:38 -04:00
sched.c Don't use mlockall() 2021-01-12 16:36:45 -05:00
semaphore.c Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree 2020-06-15 16:27:19 -04:00
seq_buf.c Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
shrinker.c bcachefs-tools: Avoid glibc-specific mallinfo() in shrinker 2023-12-09 23:28:01 -05:00
siphash.c Update bcachefs sources to ba398d2906 bcachefs: Fix reflink repair code 2022-02-13 04:08:33 -05:00
string_helpers.c Update bcachefs sources to ea93c26e98 fixup! bcachefs: We can handle missing btree roots for all alloc btrees 2023-02-09 18:36:24 -05:00
string.c Update bcachefs sources to cd779e0cc5 bcachefs: Skip inode unpack/pack in bch2_extent_update() 2022-10-22 14:41:54 -04:00
timer.c Heap code fix 2022-03-28 12:39:12 -04:00
wait.c Update bcachefs sources to 8d3fc97ca3 bcachefs: Fixes for building in userspace 2022-11-13 20:07:22 -05:00
workqueue.c Update bcachefs sources to c9b4a210f9 fixup! bcachefs: Fixes for going RO 2020-06-03 19:56:33 -04:00
xxhash.c Update bcachefs sources to dbee44d5ab bcachefs: add bcachefs xxhash support 2021-07-07 20:30:53 -04:00
zstd_compress_module.c Update bcachefs sources to e48731a188 bcachefs: Fix BTREE_TRIGGER_WANTS_OLD_AND_NEW 2022-03-13 19:20:59 -04:00
zstd_decompress_module.c Update bcachefs sources to e48731a188 bcachefs: Fix BTREE_TRIGGER_WANTS_OLD_AND_NEW 2022-03-13 19:20:59 -04:00