Re: Understanding "Used" in df

Hugo Mills
2020-07-27T20:47:40Z

On Mon, Jul 27, 2020 at 10:48:18PM +0300, Andrei Borzenkov wrote:
> 27.07.2020 22:30, Chris Murphy пишет:
> > On Mon, Jul 27, 2020 at 10:43 AM Andrei Borzenkov <arvidjaar@gmail.com> wrote:
> >>
> >> Unfortunately, "df" does not display "free" (I was wrong in other post).
> >> But using stat ...
> >>
> >>
> >> $ LANGUAGE=en stat -f .
> >> ...
> >> Block size: 4096 Fundamental block size: 4096
> >> Blocks: Total: 115164174 Free: 49153062 Available: 43297293
> >>
> >> $ LANGUAGE=en df -B 4K .
> >> Filesystem 4K-blocks Used Available Use% Mounted on
> >> /dev/sda4 115164174 66011112 43297293 61% /
> >>
> >> 115164174 - 49153062 == 66011112
> >>
> >> But there is no way you can compute Available from other values - it is
> >> whatever filesystem returns.
> >>
> >
> > It's definitely goofy in the odd device raid1 case.
>
> Well, I already explained why it happens. Yes, it looks like a bug, the
> question is how to do better estimation without performing exhaustive
> single-chunk allocation every time. Three equal size devices looks
> simple, but consider general case of multiple devices of different size
> or different amount of free space.

There's an O(n^2) algorithm in the number of devices. It's what I
used to implement the online space checker[1]. I've put up a write up
of the process at [2]. Without proof -- I wasn't able to work it out
-- but nobody's been able to catch it out yet.

Hugo.

[1] https://carfax.org.uk/btrfs-usage/
[2] https://carfax.org.uk/files/temp/btrfs-allocator.pdf

--
Hugo Mills | >squeek< *POP*
hugo@... carfax.org.uk | gluglugluglug
http://carfax.org.uk/ | <pause>
PGP: E2AB1DE4 | gluglugluglug!