summaryrefslogtreecommitdiff
path: root/linux/shrinker.c
AgeCommit message (Collapse)Author
2024-01-16Move c_src dirs back to toplevelKent Overstreet
We just wanted c sourcefiles out of the top level, not c source directories. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-01-16move Rust sources to top level, C sources into c_srcThomas Bertschinger
This moves the Rust sources out of rust_src/ and into the top level. Running the bcachefs executable out of the development tree is now: $ ./target/release/bcachefs command or $ cargo run --profile release -- command instead of "./bcachefs command". Building and installing is still: $ make && make install Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-19fix shrinker_free()Kent Overstreet
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-10bcachefs-tools: Fix typo in 872cd43Chris Webb
6% of physical RAM is info.totalram >> 4 not info.totalram << 4. Signed-off-by: Chris Webb <chris@arachsys.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-09bcachefs-tools: Avoid glibc-specific mallinfo() in shrinkerChris Webb
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-09bcachefs-tools: Use sysinfo(2) directly to implement si_meminfo()Chris Webb
Use a single sysinfo(2) call to fill out struct sysinfo instead of multiple libc sysconf(3) requests, which will only make sysinfo(2) calls internally anyway. This also enables us to access other struct sysinfo fields, not just the three filled-out previously. As we provide our own definition of struct sysinfo in include/linux/mm.h to match the kernel, which is not guaranteed to align with the definition libc provides in <sys/sysinfo.h>, use syscall(SYS_sysinfo, ...) directly instead of the libc wrapper. Signed-off-by: Chris Webb <chris@arachsys.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-12-07fix build for glibc prior to 2.33Alexander Fougner
Signed-off-by: Alexander Fougner <fougner89@gmail.com>
2023-12-05Disable shrinker thread shutdownKent Overstreet
We seem to be hitting a rare crash in the exit path of fsck - when shutting down the shrinker thread. Disable exiting the shrinker thread as a workaround. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-11-24improve kmalloc performanceDaniel Hill
Reading from /proc/meminfo is really slow We don't want to start swapping to disk. Deceptively, memory available goes up when we start to swap to disk making performance even worse. To mitigate this: 1. replace reading from meminfo with proper system calls. 2. attempt to lock allocations in physical memory space. 3. check our own allocated memory instead of available memory. 4. still check available memory in the off chance we're trying to play nice with other apps. Signed-off-by: Daniel Hill <daniel@gluo.nz> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-11-22Update bcachefs sources to 783085c3cc44 kbuild: Allow gcov to be enabled on ↵Kent Overstreet
the command line Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-09-01Fix one second delay when exitingTorge Matthies
Signed-off-by: Torge Matthies <openglfreak@googlemail.com>
2022-12-19Change memory reclaimKent Overstreet
- Spin up a background thread to call the shrinkers every 1 second - Memory allocations will only call reclaim after a failed allocation, not every single time This will be a major performance boost on allocation intensive workloads. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2022-10-11Update bcachefs sources to 6dc2a699c6 bcachefs: bch2_path_put_nokeep()Kent Overstreet
2022-10-11Don't run shrinkers without GFP_KERNELKent Overstreet
This would correspond to GFP_RECLAIM in the kernel - but we don't distinguish between different types of reclaim here. This solves a deadlock in the btree node memory allocation path - we allocate with the btree node cache lock held but without GFP_KERNEL set. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2022-10-10Update bcachefs sources to 47ffed9fad bcachefs: ↵Kent Overstreet
bch2_btree_delete_range_trans() now uses peek_upto()
2022-10-09Update bcachefs sources to cbccc6d869 bcachefs: Ratelimit ec error messageKent Overstreet
2022-03-21Shrinker improvementsKent Overstreet
After memory allocation failure, don't rely on /proc/meminfo to figure out how much memory we should free - instead unconditionally free 1/8th of each cache. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
2021-03-31If we failed to read /proc/meminfo, just run the shrinkers.Kent Overstreet
2018-11-04Don't read meminfo if there are no shrinkersTim Schlueter
2017-11-12Simple stupid memory reclaim codeKent Overstreet