Open daiaji opened 2 years ago
btrfs is fairly CPU-heavy in the kernel, and this CPU usage can bypass normal process priority control mechanisms. Also there is much less isolation between processes for IO requests in btrfs than in other filesystems, so that limiting IO in any cgroup will slow down all processes on the system.
Your best bet is to reduce the number of worker threads in bees using the -c
or -g
options to reduce the load at the source. This will also reduce the memory requirement--libc will add about 128MB per CPU for malloc arenas alone.
sudo beesd -c=6 /run/bees/mnt/df6d2459-8f5a-4585-a2ff-5461bf494be4
uuidparse: invalid option -- 'c'
Try 'uuidparse --help' for more information.
ERROR: No config for -c=6
That's strange.
btrfs is fairly CPU-heavy in the kernel, and this CPU usage can bypass normal process priority control mechanisms.
I think there's also a lot of unrelated lock contention which affects the VM performance. Maybe it helps to put the VM onto a separate file system. OTOH, using chattr +m
on the VM image directory (before creating the image), moving it to a dedicated subvolume and throwing lots of RAM at the system (32 GB+) helped my use cases.
Also there is much less isolation between processes for IO requests in btrfs than in other filesystems, so that limiting IO in any cgroup will slow down all processes on the system.
I think I already noticed that and removed cgroup priority and bandwidth settings. Thanks for confirming.
I have two NVME SSDs, one of which has been passed through to the VM.
I have two NVME SSDs, one of which has been passed through to the VM.
So it affects even completely isolated IO?
sudo beesd -c=6 /run/bees/mnt/df6d2459-8f5a-4585-a2ff-5461bf494be4 uuidparse: invalid option -- 'c' Try 'uuidparse --help' for more information. ERROR: No config for -c=6
That's expected. If you're using bees directly with a mount point, do not use the beesd
but use /usr/libexec/bees
directly (or /usr/lib/bees
or similar depending on distribution). Also, it's probably -c6
or --thread-count=6
. I'm not sure if the arg parser groks -c=6
well.
Basically I use systemd service, is there any way to load tune a running systemd service?
Basically, I'm using this:
# /etc/systemd/system/bees.service
[Unit]
Description=Bees
Documentation=https://github.com/Zygo/bees
After=local-fs.target
RequiresMountsFor=/mnt/btrfs-pool
[Service]
Type=simple
Environment=BEESSTATUS=%t/bees/bees.status
ExecStart=/usr/libexec/bees --no-timestamps --strip-paths --thread-count=3 --loadavg-target=5 --verbose=5 /mnt/btrfs-pool
CPUAccounting=true
CPUWeight=12
IOSchedulingClass=idle
IOSchedulingPriority=7
KillMode=control-group
KillSignal=SIGTERM
MemoryAccounting=true
Nice=19
Restart=on-abnormal
ReadWritePaths=/mnt/btrfs-pool
RuntimeDirectory=bees
StartupCPUWeight=25
WorkingDirectory=/run/bees
# Hide other users' process in /proc/
ProtectProc=invisible
# Mount / as read-only
ProtectSystem=strict
# Forbidden access to /home, /root and /run/user
ProtectHome=true
# Mount tmpfs on /tmp/ and /var/tmp/.
# Cannot mount at /run/ or /var/run/ for they are used by systemd.
PrivateTmp=true
# Disable network access
PrivateNetwork=true
# Use private IPC namespace, utc namespace
PrivateIPC=true
ProtectHostname=true
# Disable write access to kernel variables throug /proc
ProtectKernelTunables=true
# Disable access to control groups
ProtectControlGroups=true
# Set capabilities of the new program
# The first three are required for accessing any file on the mounted filesystem.
# The last one is required for mounting the filesystem.
AmbientCapabilities=CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_SYS_ADMIN
# With NoNewPrivileges, running sudo cannot gain any new privilege
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/bees.service.d/override.conf
[Service]
Slice=maintenance.slice
IOWeight=10
StartupIOWeight=25
# /etc/systemd/system/maintenance.slice
[Unit]
Description=Limit maintenance tasks resource usage
[Slice]
AllowedCPUs=16-19
CPUWeight=20
IOWeight=10
Adjust for your needs. I'm running on i7-12700K, CPU 16-19 are the e-cores. My subvolid=0
is mounted at /mnt/btrfs-pool
.
If the kernel leaks IO priorities into other process contexts, you may want to remove these:
IOSchedulingClass=idle
IOSchedulingPriority=7
Tuning the services while running may partially work using systemctl edit [--full] {bees.service|maintenance.slice}
, or some of the property commands of systemctl.
It looks like I should use libvirt hooks to stop the bees service after the VM is running.
If the kernel leaks IO priorities into other process contexts,
How does one find out for sure whether their kernel does or does not do that? For example mine (NixOS 6.2.11, i.e. the latest and presumably mostly-vanilla) apparently does, judging by system behavior with and without the IOSchedulingClass=idle
setting in the bees service (local audio playback stutters with it, works fine without it).
And if the norm is that the kernel does leak IO priorities, then maybe those lines should be removed from beesd@.service.in
, or at least commented out with the explanation?
There seem to be a lot of issues coming into play here:
IOSchedulingClass
leaks into other processes IO, maybe due to tree updates affecting multiple processes, I don't know but it seems to be a thing (thanks @cmm, interesting observation)/proc/buddyinfo
as huge amounts of order 1 and 2 free memory blocks, essentially causing memory fragmentation, which in turn discards caches early due to memory pressure, it leads to IO stutter, IO stalls and affects even unrelated processes and filesystems, this behavior seems to occur in short bursts, using transparent hugepages magnifies the issue exponentially, increasing vm.min_free_kb
can somewhat mitigate the problem
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/resource_management_guide/sec-modifying_control_groups https://wiki.archlinux.org/title/PCI_passthrough_via_OVMF#Dynamically_isolating_CPUs Basically, I am using a VM with GPU passthrough to run win10 to play some games, but the excessive resource utilization rate of bees in the background makes it impossible for me to play games when bees is enabled.
I tried these commands, but they didn't seem to help much.
I tried the following command again.
But there seems to be no improvement. Does this mean that I need to limit the memory and block IO utilization of bees?
And I use looking glass. This is my CPU topology.