-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
btrfs allocation issue #1473
Comments
Hello @tormath1, I will try to reproduce the issue in my env too, to take a better look. |
Hello, I have reproduced the behaviour in my environment using the Flatcar SDK to build a Flatcar image ~ 50% chance after running build_image and image_to_vm.sh. #!/bin/bash
set -xe
umount /mnt || true
losetup -d /dev/loop6 || true
# create a loopback file of ~2GB
dd of=test.loop if=/dev/zero bs=1MB count=2048
losetup /dev/loop6 test.loop
# use the exact values from Flatcar layout
mkfs.btrfs --mixed -m single -d single --byte-count 1065345024 --label USR-A /dev/loop6
# mount the btrfs partition
mount -o relatime,seclabel,space_cache=v2,subvolid=5,subvol=/ /dev/loop6 /mnt
btrfs fi usage /mnt
# set the zstd compression
btrfs property set /mnt compression zstd
# write a ~690MB file
dd if=/dev/zero of=/mnt/test_file bs=1KB count=682490 && sync
# replace the ~690MB file with a ~459MB file
dd if=/dev/zero of=/mnt/test_file bs=1KB count=459490 && sync
# df / usage shows correctly
btrfs fi usage /mnt
# try to rebalance and remove the unused btrfs space
btrfs balance start -v -dusage=5 -musage=5 /mnt
# df / usage shows correctly again, no disparity between Free estimated and Free statsfs/df
btrfs fi usage /mnt
I think this issue is practically a non-issue, as from what I understood in the case of btrfs, the Linux syscalls used by df/statsfs are not properly showing in some conditions the actual correct values. I will try to reproduce the disparity, but wanted to share this starting point if anyone else is also investigating. |
I have tried a few times to create the image using this small fix and the sizes are converging:
@tormath1 I could not find the actual cause of this issue or reproduce it in isolation yet, but this patch should not do any harm, as the balance gets done right before making the partition readonly and the verity signing. |
Rebalance the /usr btrfs allocation to the maximum possible, in order to increase the chance of having the btrfs `Free (statfs, df)` similar to `Free (estimated)`. Note that /usr is also a zstd compressed btrfs partition, so the output of `df` free size and the actual free size after a file write for example, will be very different, because the data in that file write has a compression rate only definable after the file sync. Unfortunately, there is no determinism in the btrfs file system case, because even if you could in theory pre-compress with zstd the file before, and have an idea about the size to be used, you still cannot really predict also the metadata size for that file write. See: flatcar/Flatcar#1473 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
Adding the commit flatcar/scripts@95d8361 notes here for visibility:
|
While checking the journalctl output on the latest main, I observed that this warning appears @jepio do you have an idea from where the warning might come? I checked flatcar init / bootengine repos, but those also look fine. /usr mount log :
|
Rebalance the /usr btrfs allocation to the maximum possible, in order to increase the chance of having the btrfs `Free (statfs, df)` similar to `Free (estimated)`. Note that /usr is also a zstd compressed btrfs partition, so the output of `df` free size and the actual free size after a file write for example, will be very different, because the data in that file write has a compression rate only definable after the file sync. Unfortunately, there is no determinism in the btrfs file system case, because even if you could in theory pre-compress with zstd the file before, and have an idea about the size to be used, you still cannot really predict also the metadata size for that file write. See: flatcar/Flatcar#1473 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
I could actually obtain some really weird results during my experiments:
How I managed to obtain those results -> added a Actual command used in the disk_util: |
Made some progress and there might be a way to solve the problem, will make a PR with it.
Flatcar Results:
|
Rebalance the /usr btrfs allocation to the maximum possible, in order to increase the chance of having the btrfs `Free (statfs, df)` similar to `Free (estimated)`. Note that /usr is also a zstd compressed btrfs partition, so the output of `df` free size and the actual free size after a file write for example, will be very different, because the data in that file write has a compression rate only definable after the file sync. Unfortunately, there is no determinism in the btrfs file system case, because even if you could in theory pre-compress with zstd the file before, and have an idea about the size to be used, you still cannot really predict also the metadata size for that file write. See: flatcar/Flatcar#1473 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
Came up with a script to get the closest reproduction
Output:
|
Opened an issue upstream: https://bugzilla.kernel.org/show_bug.cgi?id=219167 |
Rebalance the /usr btrfs allocation to the maximum possible, in order to increase the chance of having the btrfs `Free (statfs, df)` similar to `Free (estimated)`. Note that /usr is also a zstd compressed btrfs partition, so the output of `df` free size and the actual free size after a file write for example, will be very different, because the data in that file write has a compression rate only definable after the file sync. Unfortunately, there is no determinism in the btrfs file system case, because even if you could in theory pre-compress with zstd the file before, and have an idea about the size to be used, you still cannot really predict also the metadata size for that file write. See: flatcar/Flatcar#1473 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
We are using read-only btrfs compressed for the /usr partition, and sometimes the free space shown by `btrfs fi usage` and the `df` IS diverging, with `df` showing the free space from the `btrfs fi usage`'s `Device unallocated`. I have found to fix the allocation, by decreasing the size to more than the btrfs file system allows, but curiosly the allocation is getting reset during the failed attempt and the issue is fixed. This is of course, a _HACK_, and can at any time produce unwanted behaviours. Note that the issue cannot be reliably reproduced. See Flatcar issue: flatcar/Flatcar#1473 See issue upstream: https://bugzilla.kernel.org/show_bug.cgi?id=219167 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
We are using read-only btrfs compressed for the /usr partition, and sometimes the free space shown by `btrfs fi usage` and the `df` IS diverging, with `df` showing the free space from the `btrfs fi usage`'s `Device unallocated. I have found a way to fix the allocation, by decreasing the size to more than the btrfs filesystem allows, but curiosly the allocation is getting reset during the failed attempt and the issue is fixed. This is of course, a _HACK_, and can at any time produce unwanted behaviours. Note that the issue cannot be reliably reproduced. See Flatcar issue: flatcar/Flatcar#1473 See issue upstream: https://bugzilla.kernel.org/show_bug.cgi?id=219167 Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
Description
Recently noticed and I'm not sure really since when it is around but BTRFS allocation looks variable from one build to the other (at least on current Alpha and Beta):
Example on Beta-3941.1.0 (good behavior):
While on a
main
build:Allocated space is different.
Impact
The impact is that the filesystem appears to be more used than in reality:
Random behavior example with the last alpha (4012.0.0) release:
Similar thing can be observed after rerunning a Beta build.
The text was updated successfully, but these errors were encountered: