"PSA: Linux 5.16 has major regression in btrfs causing extreme IO load"

I mean the btrfs filesystem defragment command…

If I understand correctly, this all works with the current btrfs-assistant-git program.
The access is to the btrfsmaintenance.
Defrag - daily, weekly, monthly
also balance, scrub.

I looked into btrfsmaintenance recently but I haven’t figured out if it also takes nested subvolumes into account. Does it?

I have never checked if it handles nested subvolumes specifically.

btrfsmaintanence info about nested subvolumes

image

sudo systemctl status btrfs-defrag.service
○ btrfs-defrag.service - Defragment file data on a mounted filesystem
     Loaded: loaded (/usr/lib/systemd/system/btrfs-defrag.service; static)
     Active: inactive (dead) since Thu 2022-02-03 11:09:34 -03; 17min ago
TriggeredBy: ● btrfs-defrag.timer
       Docs: man:btrfs-filesystem
   Main PID: 3874 (code=exited, status=0/SUCCESS)
        CPU: 3ms

fev 03 11:09:34 eos systemd[1]: Started Defragment file data on a mounted filesystem.
fev 03 11:09:34 eos systemd[1]: btrfs-defrag.service: Deactivated successfully.

https://github.com/kdave/btrfsmaintenance

2 Likes

I just made a defrag.timer which triggers defrag.service on a weekly basis running a (clumsily made) script for defragging all the mounted subvolumes. I hope it will work.

2 Likes

I suppose you need to set the nested subvolumes here:

$ cat /etc/default/btrfsmaintenance
## Path:        System/File systems/btrfs
## Type:        string(none,stdout,journal,syslog)
## Default:     "stdout"
#
# Output target for messages. Journal and syslog messages are tagged by the task name like
# 'btrfs-scrub' etc.
BTRFS_LOG_OUTPUT="stdout"

## Path:        System/File systems/btrfs
## Type:        string
## Default:     ""
#
# Run periodic defrag on selected paths. The files from a given path do not
# cross mount points or other subvolumes/snapshots. If you want to defragment
# nested subvolumes, all have to be listed in this variable.
# (Colon separated paths)
BTRFS_DEFRAG_PATHS=""
1 Like

Thanks! So it doesn’t.

@dalto What I tested was manually entering the nested subvolumes into the btrfsmaintenance config file, but they got parsed out/overwritten when the GUI is saving its config.

1 Like

I am also going the noautodefrag option and I’m gonna use btrfsmaintenance with weekly setting. That should be good enough.

If you are talking about btrfs-assistant, that is probably a bug I need to fix. I didn’t consider nested subvolumes.

3 Likes

I guess you just need to include the subvols id=5 in this file /etc/default/btrfsmaintenance, not sure yet

BTRFS_DEFRAG_PATHS="/:/home:/var/log:/var/cache"

I am currently looking at mounted subvolumes. I also need to include nested subvolumes that are under those mounted subvolumes.

1 Like

If you run a find -xdev in /home, it shows the path .snapshots, so I guess including /home is enough and it will include /home/.snapshots automatically, or am I wrong?
Same happens if you run a find -xdev in /, it shows the path .snapshots, so I suppose this will be included in the defrag process;

I came across this video, the guy says there is a bug in the 5.16 kernel that might affect BTRFS autodefrag and you should remove it or set it to noautodefrag to mitigate the bug.

Moderation note: This comment was merged from a different post.

That is what was talked about in this thread. And this was fixed in Kernel 5.16.5

That guy in the video is talking about exactly this. Did you actually follow the thread and read anything?

Edit: nvm

Mod note: Moderation note: This comment was merged from a different post.

1 Like

I merged the comment from a different thread and probably does look out of context. Its not @anon78337273 's fault.

1 Like

yeh I just saw it, Edited my post.

1 Like

But it seems not solved fully… also on latest kernel… it seems there are new issues with BTRFS causing problems on systemload ?
https://forum.endeavouros.com/t/nvidia-510-47-03-graphics-driver-released/23521/49?u=joekamprad

It should also be used infrequently in normal use.

Do I need to run a balance regularly?
In general usage, no. A full unfiltered balance typically takes a long time, and will rewrite huge amounts of data unnecessarily. You may wish to run a balance on metadata only (see Balance_Filters) if you find you have very large amounts of metadata space allocated but unused, but this should be a last resort. At some point, this kind of clean-up will be made an automatic background process. btrfs wiki

3 Likes

Thanks for the info

1 Like