Skip to content
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

BUG: Naive df's test_use_percentage can fail on some machines #5531

Closed
pawelngei opened this issue Nov 14, 2023 · 1 comment · Fixed by #5532
Closed

BUG: Naive df's test_use_percentage can fail on some machines #5531

pawelngei opened this issue Nov 14, 2023 · 1 comment · Fixed by #5532
Labels

Comments

@pawelngei
Copy link
Contributor

tests/by-util/test_df.rs uses a very naive way of calculating computed_percentage, essentially adding the reported_used to reported_avail to get the total memory to calculate the percentage used.

This leads to this particular test failing on some machines depending on their settings / disk space usage, like:

$ df --total --block-size=1
Filesystem                    1B-blocks         Used    Available Use% Mounted on
efivarfs                         253852       164372        84360  67% /sys/firmware/efi/efivars

We can plainly see that this would give us ~64.75%, not 67%.

As explained in Coreutils FAQ, the tool is not intended to work this way (thanks to @cakebaker for pointing this out!):

The most natural thing in the world is to add the values of Used plus Available and expect to have a result that equals Size. But as we see here 35847132 plus 2651768 is not equal to 40559188 and is missing aproximately 2G of disk. Where did it go?

This data is in the minfree percentage of reserved filesystem disk blocks. A typical filesystem value for minfree is 5% reserved to superuser processes. Root can make use of all of the disk space but non-root processes will be restricted by the minfree value. If a user or user process fills up a partition the root user can still create files within the provided space.

We will need to rewrite this test to account for the minfree behavior. I should be able to do that either today or tomorrow.

@pawelngei
Copy link
Contributor Author

Seeing the comment in https://github.com/uutils/coreutils/blob/main/src/uu/df/src/table.rs#L118-L121 , I can see that it might be done on purpose: so the failing test might be caused by a rounding error somewhere else. I'm investigating it further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants