From patchwork Wed Feb 5 20:15:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Mamedov X-Patchwork-Id: 3589711 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D33D8C02DC for ; Wed, 5 Feb 2014 20:16:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36CDE20163 for ; Wed, 5 Feb 2014 20:16:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B22D20114 for ; Wed, 5 Feb 2014 20:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755629AbaBEUPa (ORCPT ); Wed, 5 Feb 2014 15:15:30 -0500 Received: from luka.romanrm.net ([213.163.64.74]:53330 "EHLO luka.romanrm.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754354AbaBEUP0 (ORCPT ); Wed, 5 Feb 2014 15:15:26 -0500 Received: from natsu (unknown [IPv6:fd39::a60:6eff:fef3:b5b3]) by luka.romanrm.net (Postfix) with ESMTPS id 28D3D40074 for ; Wed, 5 Feb 2014 20:15:23 +0000 (UTC) Date: Thu, 6 Feb 2014 02:15:16 +0600 From: Roman Mamedov To: linux-btrfs@vger.kernel.org Subject: Provide a better free space estimate on RAID1 Message-ID: <20140206021516.304732cd@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 Hello, On a freshly-created RAID1 filesystem of two 1TB disks: # df -h /mnt/p2/ Filesystem Size Used Avail Use% Mounted on /dev/sda2 1.8T 1.1M 1.8T 1% /mnt/p2 I cannot write 2TB of user data to that RAID1, so this estimate is clearly misleading. I got tired of looking at the bogus disk free space on all my RAID1 btrfs systems, so today I decided to do something about this: After: # df -h /mnt/p2/ Filesystem Size Used Avail Use% Mounted on /dev/sda2 1.8T 1.1M 912G 1% /mnt/p2 Until per-subvolume RAID profiles are implemented, this estimate will be correct, and even after, it should be closer to the truth than assuming the user will fill their RAID1 FS only with subvolumes of single or raid0 profiles. If anyone likes feel free to reimplement my PoC patch in a better way, e.g. integrate this into the calculation 'while' block of that function immediately before it (logic of which I couldn't yet grasp due to it lacking comments), and not just tacked onto the tail of it. --- fs/btrfs/super.c.orig 2014-02-06 01:28:36.636164982 +0600 +++ fs/btrfs/super.c 2014-02-06 01:28:58.304164370 +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; }