public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: Chris Murphy <lists@colorremedies.com>,
	Jorge Bastos <jorge.mrbastos@gmail.com>
Cc: Btrfs BTRFS <linux-btrfs@vger.kernel.org>
Subject: Re: df free space not correct with raid1 pools with an odd number of devices
Date: Sat, 25 Jul 2020 10:43:45 +0300	[thread overview]
Message-ID: <446adc05-b03b-488a-c8a3-6c31cabdb3d0@gmail.com> (raw)
In-Reply-To: <dd11313f-3b9c-c743-257c-71ba1da4dde0@gmail.com>

25.07.2020 10:30, Andrei Borzenkov пишет:
> 24.07.2020 23:46, Chris Murphy пишет:
>> On Fri, Jul 24, 2020 at 2:16 AM Jorge Bastos <jorge.mrbastos@gmail.com> wrote:
>>>
>>>>> Filesystem      Size  Used Avail Use% Mounted on
>>>>> /dev/sdd1       1.2T  3.4M  931G   1% /mnt/cache
>>
>> Oh yeah Avail is clearly goofy.
>>
>>
>>> Filesystem      Size  Used Avail Use% Mounted on
>>> /dev/sdd1       699G  3.4M  466G   1% /mnt/cache
>>
>>
>> Anybody know what's up?
>>
>>
> 
> df "Used" and "Avail" are totally independent values.
> 
> "Used" is computed as (total - free), both of which are reported by
> statfs. By default df does not show "Free", you need to use --output=
> option (at least using coreutils df).
> 
> "Avail" is computed by filesystem. Originally the difference comes from
> "available to root" and "available to user" .
> 
> btrfs computes "Avail" by simulating chunk allocations on devices. See
> super.c:btrfs_calc_avail_data_space(), the final chunk:
> 
>         btrfs_descending_sort_devices(devices_info, nr_devices);
> 
>         i = nr_devices - 1;
>         avail_space = 0;
>         while (nr_devices >= rattr->devs_min) {
>                 num_stripes = min(num_stripes, nr_devices);
> 
>                 if (devices_info[i].max_avail >= min_stripe_size) {
>                         int j;
>                         u64 alloc_size;
> 
>                         avail_space += devices_info[i].max_avail *
> num_stripes;
>                         alloc_size = devices_info[i].max_avail;
>                         for (j = i + 1 - num_stripes; j <= i; j++)
>                                 devices_info[j].max_avail -= alloc_size;
>                 }
>                 i--;
>                 nr_devices--;
>         }
> 
>         kfree(devices_info);
>         *free_bytes = avail_space;
> 
> devices_info holds device list sorted by unallocated space. We start
> with device with smallest available space and add its full available
> space (adjusted by allocation profile), then move to the previous device
> with more free space.
> 
> The problem is that if we have three equal sized devices and RAID1
> profile, the first iteration consumes two full devices, thus third
> device cannot be used anymore (we need two of them for raid1). Real
> allocator will evaluate free space every time and so alternate between
> all three devices.
> 
> 

OTOH, this is the correct if the most pessimistic estimation either. If
you have three 250G RAID1 devices and you allocate 250G data in one file
you consume two full devices and won't be able to allocate new data at
all (or for that matter no new metadata either).


So whatever value btrfs returns will be wrong for some allocation pattern.

  reply	other threads:[~2020-07-25  7:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23 10:24 df free space not correct with raid1 pools with an odd number of devices Jorge Bastos
2020-07-24  4:40 ` Chris Murphy
2020-07-24  6:53   ` Rolf Wald
2020-07-24  8:16   ` Jorge Bastos
2020-07-24 20:46     ` Chris Murphy
2020-07-25  2:19       ` Chris Murphy
2020-07-25  7:30       ` Andrei Borzenkov
2020-07-25  7:43         ` Andrei Borzenkov [this message]
2020-07-25 10:04           ` Jorge Bastos
2020-07-25 10:21             ` Andrei Borzenkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=446adc05-b03b-488a-c8a3-6c31cabdb3d0@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=jorge.mrbastos@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lists@colorremedies.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox