From patchwork Tue Sep 11 17:57:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42AE214BD for ; Tue, 11 Sep 2018 17:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3095E29B9D for ; Tue, 11 Sep 2018 17:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2555229BA0; Tue, 11 Sep 2018 17:58:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD58A29B9D for ; Tue, 11 Sep 2018 17:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbeIKW7C (ORCPT ); Tue, 11 Sep 2018 18:59:02 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:44548 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbeIKW7C (ORCPT ); Tue, 11 Sep 2018 18:59:02 -0400 Received: by mail-qt0-f196.google.com with SMTP id k38-v6so29173610qtk.11 for ; Tue, 11 Sep 2018 10:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=Jq3SGl04mzgCqgy3tL5veCHtOWx8lnR+Uw62q9CFJl8=; b=IWIXxsfz24jsuqGJwlnl3r1vCqBU4O+zjlMINyUh/sZ8UTe/aGLOaLSMXdkOga3v+k Z/m+fs005wCGFXHY+Ps2TkpQiC4xklAX5Q4j+nXKnmfaOKMRR2V92RuIWbSh/H+XDtYF lKbZms2GBL7bozo7YhtBl5eLZobadwB4pNVSdFxRgtwNQy0UOWVIj7nPkv0R4wGU8/dT 5JcArf5AVQe4MR4Hn5CuqCpOKnZkA34Ta/WXQ0W15V9NKP9NeB5sjvRXI1el4Df0b40Y xNhbwrRkgqu/6J0zDPgOlXBHaJ2uuzkiImQ/ZPFkigK6ZiG2/vPc4/V239xCR/5YOxUO w4nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Jq3SGl04mzgCqgy3tL5veCHtOWx8lnR+Uw62q9CFJl8=; b=Ayqp+VgrRgoTQsMzo9dOPSVPZF33y++Tv6xi+bofu3opTJvH4imNAHDPB0TqE339C8 Z3hVKTushoUSqlt6yxfrY8RlAMpWo1xRi0fjUvqUAgA3UFAyBLYofxEaGCaCQUEQB/3v FKXBWa5V7RtJ2zCmceikvsqxJa3UV+AzvqZbRYgpqXllHtP/u+dLWwJmEA3if2VYnVbR ASojoem8j6zXdzmLa4MN7cwPeRmmtbqTHbwlRFdb4D3oVYXUglf1A0ZLCu8qyJDY9KCA AyNzwqjRyF+zXFewnJqSEW8UM4/Wj2HFGRMVwxcxzGP7nPr4bc489iqmQSWbH/ijvLOB mkOg== X-Gm-Message-State: APzg51C+H/5HU/A0u5IJ3RkHsseoN8Qt2AI4ECpDG6RdN4jnvqYo2lco 2rhgiMbh8K4LRknkQjzh3wNKSq0eTW9M4w== X-Google-Smtp-Source: ANB0VdZKD6+sdhAGET287bRw5/s4wHVoqRTF8gRaHPifwSt20x/sAbcbYaCpcK7UCBdW3vq3n4Oiig== X-Received: by 2002:ac8:3110:: with SMTP id g16-v6mr21323656qtb.312.1536688716647; Tue, 11 Sep 2018 10:58:36 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id e29-v6sm13522138qte.47.2018.09.11.10.58.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:35 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 14/36] btrfs: reset max_extent_size properly Date: Tue, 11 Sep 2018 13:57:45 -0400 Message-Id: <20180911175807.26181-15-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-1-josef@toxicpanda.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we use up our block group before allocating a new one we'll easily get a max_extent_size that's set really really low, which will result in a lot of fragmentation. We need to make sure we're resetting the max_extent_size when we add a new chunk or add new space. Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 13441a293c73..44d59bee6e5e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4573,6 +4573,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, goto out; } else { ret = 1; + space_info->max_extent_size = 0; } space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; @@ -8084,11 +8085,17 @@ static int __btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, if (pin) pin_down_extent(fs_info, cache, start, len, 1); else { + struct btrfs_space_info *space_info = cache->space_info; + if (btrfs_test_opt(fs_info, DISCARD)) ret = btrfs_discard_extent(fs_info, start, len, NULL, BTRFS_CLEAR_OP_DISCARD); btrfs_add_free_space(cache, start, len); btrfs_free_reserved_bytes(cache, len, delalloc); + + spin_lock(&space_info->lock); + space_info->max_extent_size = 0; + spin_unlock(&space_info->lock); trace_btrfs_reserved_extent_free(fs_info, start, len); }