From patchwork Mon Mar 22 03:21:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jim owens X-Patchwork-Id: 87336 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o2M3LvcJ017481 for ; Mon, 22 Mar 2010 03:21:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753960Ab0CVDV5 (ORCPT ); Sun, 21 Mar 2010 23:21:57 -0400 Received: from qw-out-2122.google.com ([74.125.92.25]:63542 "EHLO qw-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753726Ab0CVDV4 (ORCPT ); Sun, 21 Mar 2010 23:21:56 -0400 Received: by qw-out-2122.google.com with SMTP id 8so1062375qwh.37 for ; Sun, 21 Mar 2010 20:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=aNN6Q1i/k+mf/wayjMfONC2IzD5rEmKMO4scPOv24gY=; b=Xg1SLgiKsihzSJLslQw4kNLXpen2e0nCX53N61QqYHrWxD/HdD/e+eYZufbOxcH+u8 Rap8kreboFAUM3ZwMWW9CItsFWgs2Qy20rkn4jDwzxK2SQrPZ/ppm2cF2RtKCSG+4aLE wD1NPIzKjUhSknYXelOSlmEVuhOdbS1v/ycJg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=hvsu6OpNjgQ5bT5q7s1WrkpVIUaxilhvqBVtzL5THQBmXgGcMME+AE+TSlUDpMopoL MHA1A8UB2ZUgyTVCbxIBVG2Wpjg2Rj1j+lY8sIylGF2PKqNIjrVfv7xguY/NjZ1UVD3K /PMbapCcUuhHFNmc/M/fujJQj4Ti3VxTGdnxY= Received: by 10.224.50.15 with SMTP id x15mr976107qaf.232.1269228115592; Sun, 21 Mar 2010 20:21:55 -0700 (PDT) Received: from [192.168.0.97] (c-24-147-40-65.hsd1.nh.comcast.net [24.147.40.65]) by mx.google.com with ESMTPS id 7sm7917672qwf.44.2010.03.21.20.21.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 21 Mar 2010 20:21:55 -0700 (PDT) Message-ID: <4BA6E252.2000805@gmail.com> Date: Sun, 21 Mar 2010 23:21:54 -0400 From: jim owens User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: linux-btrfs Subject: [PATCH V3 04/18] 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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 22 Mar 2010 03:21:58 +0000 (UTC) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 0e6c173..39c3299 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2637,26 +2637,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); @@ -2677,27 +2663,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 @@ -2725,6 +2690,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) { @@ -2769,6 +2746,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; @@ -2788,11 +2776,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;