From patchwork Sat Feb 8 11:21:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Mamedov X-Patchwork-Id: 3610011 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7BB129F2D6 for ; Sat, 8 Feb 2014 11:22:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79FF820138 for ; Sat, 8 Feb 2014 11:22:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 043CB20125 for ; Sat, 8 Feb 2014 11:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751378AbaBHLVq (ORCPT ); Sat, 8 Feb 2014 06:21:46 -0500 Received: from luka.romanrm.net ([213.163.64.74]:42722 "EHLO luka.romanrm.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751312AbaBHLVp (ORCPT ); Sat, 8 Feb 2014 06:21:45 -0500 Received: from natsu (unknown [IPv6:fd39::a60:6eff:fef3:b5b3]) by luka.romanrm.net (Postfix) with ESMTPS id 6E41241558; Sat, 8 Feb 2014 11:21:43 +0000 (UTC) Date: Sat, 8 Feb 2014 17:21:42 +0600 From: Roman Mamedov To: Roman Mamedov Cc: Chris Murphy , kreijack@inwind.it, kreijack@libero.it, Brendan Hide , linux-btrfs@vger.kernel.org Subject: Re: Provide a better free space estimate on RAID1 Message-ID: <20140208172142.44243c67@natsu> In-Reply-To: <20140207120812.43dc7982@natsu> References: <20140206021516.304732cd@natsu> <52F33BE7.4020708@swiftspirit.co.za> <20140206184502.128b7dbe@natsu> <52F3E86B.4030805@libero.it> <20140207104005.7bd1438a@natsu> <1B8BB06F-64EA-40EC-B0D7-FB4A38928DA3@colorremedies.com> <20140207120812.43dc7982@natsu> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Fri, 7 Feb 2014 12:08:12 +0600 Roman Mamedov wrote: > > Earlier conventions would have stated Size ~900GB, and Avail ~900GB. But that's not exactly true either, is it? > > Much better, and matching the user expectations of how RAID1 should behave, > without a major "gotcha" blowing up into their face the first minute they are > trying it out. In fact next step that I planned would be finding how to adjust > also Size and Used on all my machines to show what you just mentioned. OK done; again, this is just what I will personally use from now on (and for anyone who finds this helpful). ---- ---- 2x1TB RAID1 with a 1GB file: Filesystem Size Used Avail Use% Mounted on /dev/sda2 912G 1.1G 911G 1% /mnt/p2 --- fs/btrfs/super.c.orig 2014-02-06 01:28:36.636164982 +0600 +++ fs/btrfs/super.c 2014-02-08 17:16:50.361931959 +0600 @@ -1481,6 +1481,11 @@ } kfree(devices_info); + + if (type & BTRFS_BLOCK_GROUP_RAID1) { + do_div(avail_space, min_stripes); + } + *free_bytes = avail_space; return 0; } @@ -1491,8 +1496,10 @@ struct btrfs_super_block *disk_super = fs_info->super_copy; struct list_head *head = &fs_info->space_info; struct btrfs_space_info *found; + u64 total_size; u64 total_used = 0; u64 total_free_data = 0; + u64 type; int bits = dentry->d_sb->s_blocksize_bits; __be32 *fsid = (__be32 *)fs_info->fsid; int ret; @@ -1512,7 +1519,13 @@ rcu_read_unlock(); buf->f_namelen = BTRFS_NAME_LEN; - buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; + total_size = btrfs_super_total_bytes(disk_super); + type = btrfs_get_alloc_profile(fs_info->tree_root, 1); + if (type & BTRFS_BLOCK_GROUP_RAID1) { + do_div(total_size, 2); + do_div(total_used, 2); + } + buf->f_blocks = total_size >> bits; buf->f_bfree = buf->f_blocks - (total_used >> bits); buf->f_bsize = dentry->d_sb->s_blocksize; buf->f_type = BTRFS_SUPER_MAGIC;