From patchwork Fri Nov 30 06:02:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Sheng-Hui X-Patchwork-Id: 1823701 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 46FDA3FC23 for ; Fri, 30 Nov 2012 06:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754897Ab2K3GCm (ORCPT ); Fri, 30 Nov 2012 01:02:42 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:62017 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752356Ab2K3GCl (ORCPT ); Fri, 30 Nov 2012 01:02:41 -0500 Received: by mail-pa0-f46.google.com with SMTP id bh2so109595pad.19 for ; Thu, 29 Nov 2012 22:02:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=hJowHiGh1YvBN1MEHVIRvvh/zOhijfUb8TZy8nG2g+Q=; b=s9pDah4HjXBMGXpuBAQwr+peLPoKUq7iMZEiZEBKqmu9vhzmAnKEg8mQ1HBh93tkqe e6NA6oH8S9+7/rSvlzjeNNBorTOWhY/w5rMGnwvsaGgfH8aFDKTIhwmXoP9GVnPsTQlD 3NWRi2zik7tLbO1R0bQb/om7vEb13xg5S87SW3e0D8micLTAjcCzUdWcS4s17jsSGi/+ VoGpX8t6a1XsdDO+d4w2fbp2ySLF1YXp+PVVyU7La9EtLKbvJbGLO8nrv/HG44h3q3do jmg6kgCG+FXytR3lPzFp2HtazBOt6Epa8HOL4LHNI4DkENLXa7eGIMLkMc8TgSFqg9fZ kATA== Received: by 10.68.247.134 with SMTP id ye6mr2717983pbc.69.1354255360760; Thu, 29 Nov 2012 22:02:40 -0800 (PST) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPS id s7sm2348281paz.7.2012.11.29.22.02.35 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 29 Nov 2012 22:02:39 -0800 (PST) From: shhuiw@gmail.com To: chris.mason@fusionio.com, jbacik@fusionio.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: use ctl->unit for free space calculation instead of block_group->sectorsize Date: Fri, 30 Nov 2012 14:02:25 +0800 Message-Id: <50b84bff.e756420a.16c1.ffffc35a@mx.google.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Wang Sheng-Hui We should use ctl->unit for free space calculation instead of block_group->sectorsize even though for free space use_bitmap or free space cluster we only have sectorsize assigned to ctl->unit currently. Also, we can keep it consisten in code style. Signed-off-by: Wang Sheng-Hui --- fs/btrfs/free-space-cache.c | 20 +++++++++----------- 1 files changed, 9 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 1027b85..c3318cb 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1364,7 +1364,7 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl) u64 bitmap_bytes; u64 extent_bytes; u64 size = block_group->key.offset; - u64 bytes_per_bg = BITS_PER_BITMAP * block_group->sectorsize; + u64 bytes_per_bg = BITS_PER_BITMAP * ctl->unit; int max_bitmaps = div64_u64(size + bytes_per_bg - 1, bytes_per_bg); BUG_ON(ctl->total_bitmaps > max_bitmaps); @@ -1650,8 +1650,7 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl, * some block groups are so tiny they can't be enveloped by a bitmap, so * don't even bother to create a bitmap for this */ - if (BITS_PER_BITMAP * block_group->sectorsize > - block_group->key.offset) + if (BITS_PER_BITMAP * ctl->unit > block_group->key.offset) return false; return true; @@ -2298,10 +2297,10 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, unsigned long total_found = 0; int ret; - i = offset_to_bit(entry->offset, block_group->sectorsize, + i = offset_to_bit(entry->offset, ctl->unit, max_t(u64, offset, entry->offset)); - want_bits = bytes_to_bits(bytes, block_group->sectorsize); - min_bits = bytes_to_bits(min_bytes, block_group->sectorsize); + want_bits = bytes_to_bits(bytes, ctl->unit); + min_bits = bytes_to_bits(min_bytes, ctl->unit); again: found_bits = 0; @@ -2325,23 +2324,22 @@ again: total_found += found_bits; - if (cluster->max_size < found_bits * block_group->sectorsize) - cluster->max_size = found_bits * block_group->sectorsize; + if (cluster->max_size < found_bits * ctl->unit) + cluster->max_size = found_bits * ctl->unit; if (total_found < want_bits || cluster->max_size < cont1_bytes) { i = next_zero + 1; goto again; } - cluster->window_start = start * block_group->sectorsize + - entry->offset; + cluster->window_start = start * ctl->unit + entry->offset; rb_erase(&entry->offset_index, &ctl->free_space_offset); ret = tree_insert_offset(&cluster->root, entry->offset, &entry->offset_index, 1); BUG_ON(ret); /* -EEXIST; Logic error */ trace_btrfs_setup_cluster(block_group, cluster, - total_found * block_group->sectorsize, 1); + total_found * ctl->unit, 1); return 0; }