From patchwork Fri Oct 15 21:28:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 257961 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9FLYA5R010541 for ; Fri, 15 Oct 2010 21:34:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751262Ab0JOVeE (ORCPT ); Fri, 15 Oct 2010 17:34:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35761 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983Ab0JOVeB (ORCPT ); Fri, 15 Oct 2010 17:34:01 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9FLY1Ou008821 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 15 Oct 2010 17:34:01 -0400 Received: from localhost.localdomain (test1244.test.redhat.com [10.10.10.244]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9FLY0vO003011 for ; Fri, 15 Oct 2010 17:34:01 -0400 From: Josef Bacik To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] Btrfs: don't allocate chunks as aggressively Date: Fri, 15 Oct 2010 17:28:34 -0400 Message-Id: <1287178115-18229-4-git-send-email-josef@redhat.com> In-Reply-To: <1287178115-18229-1-git-send-email-josef@redhat.com> References: <1287178115-18229-1-git-send-email-josef@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 (demeter1.kernel.org [140.211.167.41]); Fri, 15 Oct 2010 21:34:16 +0000 (UTC) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 14a52dd..265d8e0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3224,7 +3224,8 @@ static void force_metadata_allocation(struct btrfs_fs_info *info) rcu_read_unlock(); } -static int should_alloc_chunk(struct btrfs_space_info *sinfo, +static int should_alloc_chunk(struct btrfs_fs_info *info, + struct btrfs_space_info *sinfo, u64 alloc_bytes) { u64 num_bytes = sinfo->total_bytes - sinfo->bytes_readonly; @@ -3237,6 +3238,9 @@ static int should_alloc_chunk(struct btrfs_space_info *sinfo, alloc_bytes < div_factor(num_bytes, 8)) return 0; + if (sinfo->bytes_used < div_factor(num_bytes, 3)) + return 0; + return 1; } @@ -3268,7 +3272,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, goto out; } - if (!force && !should_alloc_chunk(space_info, alloc_bytes)) { + if (!force && !should_alloc_chunk(fs_info, space_info, alloc_bytes)) { spin_unlock(&space_info->lock); goto out; } @@ -3317,7 +3321,8 @@ static int maybe_allocate_chunk(struct btrfs_trans_handle *trans, return 0; spin_lock(&sinfo->lock); - ret = should_alloc_chunk(sinfo, num_bytes + 2 * 1024 * 1024); + ret = should_alloc_chunk(root->fs_info, sinfo, + num_bytes + 2 * 1024 * 1024); spin_unlock(&sinfo->lock); if (!ret) return 0;