Since the thread in which I first raised the problem has now been closed (because it may have been solved), I am reopening the same topic here, since the same problem occurs again and again.
I now have the current kernel 6.1.7. The problem is the following: I have a swapfile from Calamares during the installation with exclusive root rights. But every few reboots I get error messages that the swapfile could not be activated. Remedy is every time I recreate the swapfile and activate it again:
OK, that could be the case with me, too, if I think about it carefully. I have done this manually from time to time. So I should also turn off the automated balance function in the Btrfs Assistant again? Stupid …
I’m just reporting that if I run sudo btrfs balance start --bg /, I get the same errors as you.
So I suppose that could be the balance procedure affecting your swap, just like it was happening with me before.
Note that this is just an assumption based on my previously problems with balance and swap and I could be wrong.
I’m not sure… Probably we will need someone with more skills in BTRFS like Dalto to help us to answer that…
Balance and/or convert (change allocation profile of) chunks that
passed all filters in a comma-separated list of filters for a
particular chunk type. If filter list is not given balance all
chunks of that type. In case none of the -d, -m or -s options is
given balance all chunks in a filesystem. This is potentially
long operation and the user is warned before this start, with
a delay to stop it.
This means that if you run the command for balance found in the arch wiki, which has no filters, it would balance all chunks in a filesystem.
btrfsmaintenace is using filters, 10% for data and 5% for metadata, so they are different it seems…
https://github.com/kdave/btrfsmaintenance
btrfsmaintenance is also using 5% but you can tune it editing the file /etc/default/btrfsmaintenance
Edit: btrfsmaintenace is using filters, 10% for data and 5% for metadata
In the article that @anon50380917 linked to, the author issues a warning against running balance on metadata though in some cases it seems to be legit.
WARNING: Do not run balance on Metadata chunks as this can increase the risk for ENOSPC errors. Only run Metadata balance when converting between RAID profiles or when changing the number of devices in the filesystem.
I’m trying to understand the code but I’m not a programmer.
Inside this file: /etc/default/btrfsmaintenance
We have this:
# The usage percent for balancing data block groups.
#
# Note: default values should not disturb normal work but may not reclaim
# enough block groups. If you observe that, add higher values but beware that
# this will increase IO load on the system.
BTRFS_BALANCE_DUSAGE="5 10"
## Path: System/File systems/btrfs
## Type: string
## Default: "5"
#
# The usage percent for balancing metadata block groups. The values are also
# used in case the filesystem has mixed blockgroups.
#
# Note: default values should not disturb normal work but may not reclaim
# enough block groups. If you observe that, add higher values but beware that
# this will increase IO load on the system.
BTRFS_BALANCE_MUSAGE="5"
Inside this file /usr/share/btrfsmaintenance/btrfs-balance.sh, we have this:
#!/bin/bash
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
umask 022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
if [ -f /etc/sysconfig/btrfsmaintenance ] ; then
. /etc/sysconfig/btrfsmaintenance
fi
if [ -f /etc/default/btrfsmaintenance ] ; then
. /etc/default/btrfsmaintenance
fi
LOGIDENTIFIER='btrfs-balance'
. $(dirname $(realpath "$0"))/btrfsmaintenance-functions
{
BTRFS_BALANCE_MOUNTPOINTS=$(expand_auto_mountpoint "$BTRFS_BALANCE_MOUNTPOINTS")
OIFS="$IFS"
IFS=:
exec 2>&1 # redirect stderr to stdout to catch all output to log destination
for MM in $BTRFS_BALANCE_MOUNTPOINTS; do
IFS="$OIFS"
if ! is_btrfs "$MM"; then
echo "Path $MM is not btrfs, skipping"
continue
fi
echo "Before balance of $MM"
btrfs filesystem df "$MM"
df -H "$MM"
if detect_mixed_bg "$MM"; then
run_task btrfs balance start -musage=0 -dusage=0 "$MM"
# we use the MUSAGE values for both, supposedly less aggressive
# values, but as the data and metadata space is shared on
# mixed-bg this does not lead to the situations we want to
# prevent when the blockgroups are split (ie. underused
# blockgroups)
for BB in $BTRFS_BALANCE_MUSAGE; do
# quick round to clean up the unused block groups
run_task btrfs balance start -v -musage=$BB -dusage=$BB "$MM"
done
else
run_task btrfs balance start -dusage=0 "$MM"
for BB in $BTRFS_BALANCE_DUSAGE; do
# quick round to clean up the unused block groups
run_task btrfs balance start -v -dusage=$BB "$MM"
done
run_task btrfs balance start -musage=0 "$MM"
for BB in $BTRFS_BALANCE_MUSAGE; do
# quick round to clean up the unused block groups
run_task btrfs balance start -v -musage="$BB" "$MM"
done
fi
echo "After balance of $MM"
btrfs filesystem df "$MM"
df -H "$MM"
done
} | \
case "$BTRFS_LOG_OUTPUT" in
stdout) cat;;
journal) systemd-cat -t "$LOGIDENTIFIER";;
syslog) logger -t "$LOGIDENTIFIER";;
none) cat >/dev/null;;
*) cat;;
esac
exit 0
So, it seems that there is a condition to run, ifs and elses .
Not sure if the metadata part of the code runs every time…
Edit: I suppose BB is BTRFS_BALANCE_DUSAGE and MM is BTRFS_BALANCE_MUSAGE ?
But only when mixed_bg MM is found ? What this means?
Now it’s as good as confirmed that at least running Balance manually on the Btrfs Assistant start page will cripple the swapfile. Balance => restart => swapfile broken …
Did you kick off the balance and then restart? A swapfile can’t be activated while a balance is running. So if you started a balance and restarted right away, that would leave the balance in a paused state and may stop swap activation.
If that is the case, you could resume the balance, let it finish and then activate the swapfile.
Update: I now have the LTS kernel in use again (5.15.90) and the balancing of the swapfile doesn’t seem to matter. But after I rebooted into 6.18, the swapfile was broken again. Am curious what happens when the 6.1 then LTS has become …