From patchwork Mon Jan 4 21:12:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 70740 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o04LDM6K024937 for ; Mon, 4 Jan 2010 21:13:23 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754102Ab0ADVNE (ORCPT ); Mon, 4 Jan 2010 16:13:04 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754120Ab0ADVNA (ORCPT ); Mon, 4 Jan 2010 16:13:00 -0500 Received: from g1t0029.austin.hp.com ([15.216.28.36]:24769 "EHLO g1t0029.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753955Ab0ADVM6 (ORCPT ); Mon, 4 Jan 2010 16:12:58 -0500 Received: from g1t0039.austin.hp.com (g1t0039.austin.hp.com [16.236.32.45]) by g1t0029.austin.hp.com (Postfix) with ESMTP id 0F017383EB for ; Mon, 4 Jan 2010 21:12:58 +0000 (UTC) Received: from ldl (ldl.fc.hp.com [15.11.146.30]) by g1t0039.austin.hp.com (Postfix) with ESMTP id 0208C34018 for ; Mon, 4 Jan 2010 21:12:57 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id C7FD5CF0011; Mon, 4 Jan 2010 14:12:57 -0700 (MST) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yB9aKf9O2fOW; Mon, 4 Jan 2010 14:12:57 -0700 (MST) Received: from [192.168.0.99] (squirrel.fc.hp.com [15.11.146.57]) (Authenticated sender: owens@fc.hp.com) by ldl (Postfix) with ESMTPA id 572A3CF000E; Mon, 4 Jan 2010 14:12:57 -0700 (MST) Message-ID: <4B4259D7.3000701@hp.com> Date: Mon, 04 Jan 2010 16:12:55 -0500 From: jim owens User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: linux-btrfs Subject: [RFC 03/12 RESEND PATCH] Btrfs: Reorder __btrfs_map_block to make code more efficient. Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5af76fc..e6599ef 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2625,26 +2625,12 @@ static int __btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, u64 offset; u64 stripe_offset; u64 stripe_nr; - int stripes_allocated = 8; - int stripes_required = 1; int stripe_index; int i; int num_stripes; - int max_errors = 0; + int max_errors; struct btrfs_multi_bio *multi = NULL; - if (multi_ret && !(rw & (1 << BIO_RW))) - stripes_allocated = 1; -again: - if (multi_ret) { - multi = kzalloc(btrfs_multi_bio_size(stripes_allocated), - GFP_NOFS); - if (!multi) - return -ENOMEM; - - atomic_set(&multi->error, 0); - } - read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, logical, *length); read_unlock(&em_tree->lock); @@ -2663,27 +2649,6 @@ again: map = (struct map_lookup *)em->bdev; offset = logical - em->start; - if (mirror_num > map->num_stripes) - mirror_num = 0; - - /* if our multi bio struct is too small, back off and try again */ - if (rw & (1 << BIO_RW)) { - if (map->type & (BTRFS_BLOCK_GROUP_RAID1 | - BTRFS_BLOCK_GROUP_DUP)) { - stripes_required = map->num_stripes; - max_errors = 1; - } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { - stripes_required = map->sub_stripes; - max_errors = 1; - } - } - if (multi_ret && (rw & (1 << BIO_RW)) && - stripes_allocated < stripes_required) { - stripes_allocated = map->num_stripes; - free_extent_map(em); - kfree(multi); - goto again; - } stripe_nr = offset; /* * stripe_nr counts the total number of stripes we have to stride @@ -2711,6 +2676,18 @@ again: if (!multi_ret && !unplug_page) goto out; + if (mirror_num > map->num_stripes) + mirror_num = 0; + + max_errors = 0; + if (rw & (1 << BIO_RW)) { + if (map->type & (BTRFS_BLOCK_GROUP_RAID1 | + BTRFS_BLOCK_GROUP_DUP)) + max_errors = 1; + else if (map->type & BTRFS_BLOCK_GROUP_RAID10) + max_errors = 1; + } + num_stripes = 1; stripe_index = 0; if (map->type & BTRFS_BLOCK_GROUP_RAID1) { @@ -2755,6 +2732,17 @@ again: } BUG_ON(stripe_index >= map->num_stripes); + if (multi_ret) { + multi = kzalloc(btrfs_multi_bio_size(num_stripes), GFP_NOFS); + if (!multi) + return -ENOMEM; + *multi_ret = multi; + + atomic_set(&multi->error, 0); + multi->num_stripes = num_stripes; + multi->max_errors = max_errors; + } + for (i = 0; i < num_stripes; i++) { if (unplug_page) { struct btrfs_device *device; @@ -2774,11 +2762,6 @@ again: } stripe_index++; } - if (multi_ret) { - *multi_ret = multi; - multi->num_stripes = num_stripes; - multi->max_errors = max_errors; - } out: free_extent_map(em); return 0;