From: Goffredo Baroncelli <kreijack@libero.it>
To: linux-btrfs@vger.kernel.org
Cc: Roman Mamedov <rm@romanrm.net>, Brendan Hide <brendan@swiftspirit.co.za>
Subject: [PATCH][V3] Provide a better free space estimate [was]Re: Provide a better free space estimate on RAID1
Date: Sun, 09 Feb 2014 18:20:57 +0100 [thread overview]
Message-ID: <52F7B8F9.6040004@libero.it> (raw)
In-Reply-To: <20140207104005.7bd1438a@natsu>
On 02/07/2014 05:40 AM, Roman Mamedov wrote:
> On Thu, 06 Feb 2014 20:54:19 +0100
> Goffredo Baroncelli <kreijack@libero.it> wrote:
>
[...]
As Roman pointed out, df show the "raw" space available. However
when a RAID level is used, the space available to the user is
less.
This patch try to address this estimation correcting the value
on the basis of the RAID level.
This is my third revision of this patch. In this last issue, I
addressed the bugs related to an uncorrected evaluation of the
free space in case of RAID1 [1] and DUP.
I have to point out that the free space estimation is quite
approximative, because it assumes:
a) all the new files are allocated in data "chunk"
b) the free space will not consumed by metadata
c) the already allocated chunk are not evaluated for the free
space estimation
Both these assumptions are unrelated to my patch.
I performed some tests with a filesystem composed by 7 51GB disks.
Here my "df" results:
Profile: single
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 351G 512K 348G 1% /mnt/btrfs1
Profile: raid1
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 351G 1.3M 175G 1% /mnt/btrfs1
Profile: raid10
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 351G 2.3M 177G 1% /mnt/btrfs1
Profile: raid5
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 351G 2.0M 298G 1% /mnt/btrfs1
Profile: raid6
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 351G 1.8M 248G 1% /mnt/btrfs1
Profile: DUP (only one 50GB disk was used)
Filesystem Size Used Avail Use% Mounted on
/dev/vdc 51G 576K 26G 1% /mnt/btrfs1
Below my patch.
BR
G.Baroncelli
[1] the bug is before my patch; try to see what happens when you
create a RAID1 filesystem with three disks.
Changes history:
V1 First issue
V2 Correct a (old) bug when in RAID10 the disks aren't
a multiple of 4
V3 Correct the free space estimation in RAID1 (when the
number of disks are odd) and DUP
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index d71a11d..4064a5f 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1481,10 +1481,16 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
num_stripes = nr_devices;
} else if (type & BTRFS_BLOCK_GROUP_RAID1) {
min_stripes = 2;
- num_stripes = 2;
+ num_stripes = nr_devices;
} else if (type & BTRFS_BLOCK_GROUP_RAID10) {
min_stripes = 4;
- num_stripes = 4;
+ num_stripes = nr_devices;
+ } else if (type & BTRFS_BLOCK_GROUP_RAID5) {
+ min_stripes = 3;
+ num_stripes = nr_devices;
+ } else if (type & BTRFS_BLOCK_GROUP_RAID6) {
+ min_stripes = 4;
+ num_stripes = nr_devices;
}
if (type & BTRFS_BLOCK_GROUP_DUP)
@@ -1560,9 +1566,44 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
if (devices_info[i].max_avail >= min_stripe_size) {
int j;
- u64 alloc_size;
+ u64 alloc_size, delta;
+ int k, div;
+
+ /*
+ * Depending by the RAID profile, we use some
+ * disk space as redundancy:
+ * RAID1, RAID10, DUP -> half of space used as redundancy
+ * RAID5 -> 1 stripe used as redundancy
+ * RAID6 -> 2 stripes used as redundancy
+ * RAID0,LINEAR -> no redundancy
+ */
+ if (type & BTRFS_BLOCK_GROUP_RAID1) {
+ k = num_stripes;
+ div = 2;
+ } else if (type & BTRFS_BLOCK_GROUP_DUP) {
+ k = num_stripes;
+ div = 2;
+ } else if (type & BTRFS_BLOCK_GROUP_RAID10) {
+ k = num_stripes;
+ div = 2;
+ } else if (type & BTRFS_BLOCK_GROUP_RAID5) {
+ k = num_stripes-1;
+ div = 1;
+ } else if (type & BTRFS_BLOCK_GROUP_RAID6) {
+ k = num_stripes-2;
+ div = 1;
+ } else { /* RAID0/LINEAR */
+ k = num_stripes;
+ div = 1;
+ }
+
+ delta = devices_info[i].max_avail*k;
+ if (div==2)
+ delta >>= 1;
+ else if (div>2)
+ do_div(delta, div);
+ avail_space += delta;
- 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;
--
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5
next prev parent reply other threads:[~2014-02-09 17:21 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-05 20:15 Provide a better free space estimate on RAID1 Roman Mamedov
2014-02-06 7:38 ` Brendan Hide
2014-02-06 12:45 ` Roman Mamedov
2014-02-06 19:54 ` Goffredo Baroncelli
2014-02-07 4:40 ` Roman Mamedov
2014-02-07 5:30 ` Chris Murphy
2014-02-07 6:08 ` Roman Mamedov
2014-02-07 18:44 ` Chris Murphy
2014-02-08 21:46 ` Kai Krakow
2014-02-08 11:21 ` Roman Mamedov
2014-02-07 10:02 ` Martin Steigerwald
2014-02-08 21:50 ` Kai Krakow
2014-02-08 15:46 ` Goffredo Baroncelli
2014-02-08 16:36 ` [PATCH][V2] " Goffredo Baroncelli
2014-02-09 17:20 ` Goffredo Baroncelli [this message]
2014-02-07 14:05 ` Frank Kingswood
2014-02-06 20:21 ` Josef Bacik
2014-02-07 20:32 ` Kai Krakow
2014-02-08 11:33 ` Roman Mamedov
2014-02-08 11:46 ` Hugo Mills
2014-02-08 21:35 ` Kai Krakow
2014-02-08 22:10 ` Roman Mamedov
2014-02-08 22:45 ` cwillu
2014-02-08 23:27 ` Kai Krakow
2014-02-08 23:32 ` Kai Krakow
2014-02-09 1:08 ` Roman Mamedov
2014-02-09 9:39 ` Kai Krakow
2014-02-09 6:38 ` Duncan
2014-02-09 9:20 ` Roman Mamedov
2014-02-10 0:02 ` Duncan
2014-02-10 9:14 ` Roman Mamedov
2014-02-09 9:37 ` Kai Krakow
2014-02-08 23:17 ` Kai Krakow
2014-02-09 1:55 ` Roman Mamedov
2014-02-09 2:21 ` Chris Murphy
2014-02-09 2:29 ` Chris Murphy
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=52F7B8F9.6040004@libero.it \
--to=kreijack@libero.it \
--cc=brendan@swiftspirit.co.za \
--cc=kreijack@inwind.it \
--cc=linux-btrfs@vger.kernel.org \
--cc=rm@romanrm.net \
/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;
as well as URLs for NNTP newsgroup(s).