Go to file
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
.github fix udev rules path 2023-12-06 15:41:05 -05:00
ccan Update bcachefs sources to f638850417 bcachefs: bch2_trans_log_msg() 2022-03-30 17:40:37 -04:00
debian fsck: add a service to schedule and run bcachefsck@ services 2023-12-07 11:57:36 -05:00
doc Add additional information about encryption 2023-07-10 16:03:30 -04:00
fsck Update .gitignore for new service files 2023-12-07 11:57:36 -05:00
include bcachefs-tools: Use sysinfo(2) directly to implement si_meminfo() 2023-12-09 23:26:29 -05:00
initramfs Replaced mkdir -p with install -D in make install 2019-01-13 19:31:04 -08:00
libbcachefs Update bcachefs sources to 6d44812757dd bcachefs: BCH_IOCTL_FSCK_ONLINE 2023-12-07 11:57:36 -05:00
linux bcachefs-tools: Avoid glibc-specific mallinfo() in shrinker 2023-12-09 23:28:01 -05:00
packaging fix udev rules path 2023-12-06 15:41:05 -05:00
raid snapraid 2018-11-23 02:10:44 -05:00
rust-src rust: fix MSRV build 2023-11-23 19:29:43 +01:00
tests Add valgrind suppressions: 2022-03-24 11:41:10 -06:00
udev fix udev rules path 2023-12-06 15:41:05 -05:00
.bcachefs_revision Update bcachefs sources to 6d44812757dd bcachefs: BCH_IOCTL_FSCK_ONLINE 2023-12-07 11:57:36 -05:00
.editorconfig nix: overhaul build system. 2023-01-03 16:58:55 +13:00
.gitignore .gitignore: replace travis with github-ci config 2023-07-20 22:27:56 +02:00
bcachefs.8 man: Fix cmd-option format 2023-11-27 21:04:03 -05:00
bcachefs.c improve kmalloc performance 2023-11-24 19:54:11 -05:00
build.nix nix: add bcachefs-fuse package 2023-11-20 15:13:17 -05:00
cmd_assemble.c Update bcachefs sources to 0906b1fb49 bcachefs: fixes for 32 bit/big endian machines 2018-05-17 02:36:19 -04:00
cmd_attr.c Update email address 2022-05-26 15:40:08 -04:00
cmd_data.c Update bcachefs sources to 783085c3cc44 kbuild: Allow gcov to be enabled on the command line 2023-11-22 16:55:06 -05:00
cmd_device.c Convert to BCH_IOCTL_DEV_USAGE_V2 2023-11-27 21:04:03 -05:00
cmd_dump.c Update bcachefs sources to f9c612bbf82d bcachefs: Fixes for building in userspace 2023-09-23 20:03:23 -04:00
cmd_format.c cmd_format: Check for device options after device arguments 2023-11-06 19:02:40 -05:00
cmd_fs.c cmd_fs: calculate size based on bucket count for data types BCH_DATA_free, BCH_DATA_need_discard and BCH_DATA_need_inc_gens 2023-12-07 20:47:09 +01:00
cmd_fsck.c Online fsck 2023-12-07 12:04:24 -05:00
cmd_fusemount.c Multiple small fuse fixes for write, api, and hardlink 2023-12-07 15:17:34 +02:00
cmd_key.c Update bcachefs sources to a180af9dd349 bcachefs: Refactor memcpy into direct assignment 2023-10-18 22:14:53 -04:00
cmd_kill_btree_node.c Update bcachefs sources to 24bdb6fed91c bcachefs: bch2_btree_id_str() 2023-10-19 22:56:59 -04:00
cmd_list_journal.c cmd_list_journal: Apply star_start_of_lines() correctly 2023-11-27 21:04:03 -05:00
cmd_migrate.c Avoiding picking different bucket sizes for different devices 2023-11-06 20:47:48 -05:00
cmd_option.c Use bch2_err_str() instead of strerror() 2022-12-19 16:05:54 -05:00
cmd_run.c Update bcachefs sources to 0906b1fb49 bcachefs: fixes for 32 bit/big endian machines 2018-05-17 02:36:19 -04:00
cmd_subvolume.c Add more specific subcommand usage messages 2021-11-01 08:12:35 -06:00
cmd_version.c Version is now specified in the makefile 2023-11-16 15:24:22 -05:00
cmds.h delete dead code 2023-11-16 17:54:06 -05:00
config.h Redo lots of stuff 2016-03-11 21:18:42 -09:00
COPYING bcache-tools are GPL 2013-07-17 13:13:31 -07:00
crypto.c Update bcachefs sources to a180af9dd349 bcachefs: Refactor memcpy into direct assignment 2023-10-18 22:14:53 -04:00
crypto.h cmd_unlock: Add -k argument to specify keyring 2022-05-19 16:01:51 -04:00
default.nix nix: fix build add overlay and formatter to flake 2023-11-09 22:09:33 +01:00
flake.lock nix: fix build add overlay and formatter to flake 2023-11-09 22:09:33 +01:00
flake.nix nix: add bcachefs-fuse package 2023-11-20 15:13:17 -05:00
INSTALL.md fix udev rules path 2023-12-06 15:41:05 -05:00
libbcachefs.c bcachefs-tools: Use basename(3) from <libgen.h> 2023-12-09 23:25:00 -05:00
libbcachefs.h Convert to BCH_IOCTL_DEV_USAGE_V2 2023-11-27 21:04:03 -05:00
make-release-tarball.sh Create COPYING.rust-dependencies in release tarballs 2023-11-16 17:54:06 -05:00
Makefile bcachefs-tools: make 'all' the default Makefile goal 2023-12-08 15:07:32 -05:00
Makefile.compiler Update bcachefs sources to f9c612bbf82d bcachefs: Fixes for building in userspace 2023-09-23 20:03:23 -04:00
mount.bcachefs.sh Add a shell script version of mount.bcachefs 2020-08-24 23:17:17 -04:00
qcow2.c deleted unused path to device in get_size, get_blocksize 2023-10-08 21:06:07 -04:00
qcow2.h cmd_migrate 2017-03-09 09:14:11 -09:00
README.md Update docs 2023-03-07 12:46:53 -05:00
tools-util.c bcachefs-tools: don't skip stale superblock wipe in force mode 2023-11-27 21:04:03 -05:00
tools-util.h Change open_for_format to the block io api 2023-10-08 21:06:07 -04:00

bcachefs-tools

Userspace tools and docs for bcachefs

Bcachefs is an advanced new filesystem for Linux, with an emphasis on reliability and robustness and the complete set of features one would expect from a modern filesystem.

This repo primarily consists of the following:

  • bcachefs tool, the reason this repo exists.
  • {mkfs,mount,fsck}.bcachefs utils, which is just wrappers calling the corresponding subcommands in the main tool
  • docs in the form of man-pages and a user manual

Please refer to the main site for getting started An in-depth user manual is (also) found on the official website

Build and install

Refer to INSTALL.md

Bug reports and contributions