From patchwork Fri Nov 30 06:30:14 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: 1823781 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 6DE2ADF264 for ; Fri, 30 Nov 2012 06:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755912Ab2K3Ga1 (ORCPT ); Fri, 30 Nov 2012 01:30:27 -0500 Received: from mail-ia0-f174.google.com ([209.85.210.174]:34739 "EHLO mail-ia0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755770Ab2K3Ga0 (ORCPT ); Fri, 30 Nov 2012 01:30:26 -0500 Received: by mail-ia0-f174.google.com with SMTP id y25so109872iay.19 for ; Thu, 29 Nov 2012 22:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=Kf5lsbTLsopVs94umK1tkzjtc7HbMGS77SC2MOSPkl0=; b=b9gzb7zvLnclWn08j3+zSVkyhX3XSgPC9PUQmkgFsOuMVn7R12wMm+KsP009Mtj5rz KqJh5HnJhiqHyOuM71dP/fRePyvi8Y+scDit/XFyveq2bJGFH7U/AkVswuRolpsbuuuk QhicFLZIitAJ4SlDemuZxE6h6TwPfyfxp4u91roaLBCQq60drEgHDgeOJgCSmt4DzwEf BSY5MFC4t/1OdplHG/bXihqngs80SuEG1NcstB14VBDiqPPpM1h3KMzLpxgIk8AwKxBn RE02w3zI3eEM9FSEQ2YHeFkx4byq56Ag2bw7Xwc3Ie+/35d3D04/l8KJfp8qVtQ7EyuG ykzA== Received: by 10.50.13.133 with SMTP id h5mr231991igc.2.1354257026157; Thu, 29 Nov 2012 22:30:26 -0800 (PST) Received: from crossover.org ([202.108.130.138]) by mx.google.com with ESMTPS id xn10sm9384275igb.4.2012.11.29.22.30.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 29 Nov 2012 22:30:25 -0800 (PST) Message-ID: <50B85276.60003@gmail.com> Date: Fri, 30 Nov 2012 14:30:14 +0800 From: Wang Sheng-Hui User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: chris.mason@fusionio.com, Josef Bacik , linux-btrfs@vger.kernel.org Subject: [PATCH][RESEND] Btrfs: use ctl->unit for free space calculation instead of block_group->sectorsize Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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; }