From patchwork Thu Jul 19 14:49:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10534689 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 791E0600D0 for ; Thu, 19 Jul 2018 14:50:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8031029CB7 for ; Thu, 19 Jul 2018 14:50:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74ED129CC6; Thu, 19 Jul 2018 14:50:28 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 1066029CB7 for ; Thu, 19 Jul 2018 14:50:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731983AbeGSPd5 (ORCPT ); Thu, 19 Jul 2018 11:33:57 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34263 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731656AbeGSPd5 (ORCPT ); Thu, 19 Jul 2018 11:33:57 -0400 Received: by mail-qk0-f196.google.com with SMTP id b66-v6so4410987qkj.1 for ; Thu, 19 Jul 2018 07:50:26 -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=YRhHfYvcxk5JpWY5c7kjM/LCCCXthk/+kL7hgjXlx0g=; b=aKb8WHWc3tLaH2YtTPVJrhrshvU6naeFf7WuigocumzY/BHSAFNhV709RQZgEvp1BP exbLEHgqUR6OGO49WEynTlE4aVivo0p+gind75PLiNcNreiyxDRBYHFwIp0H9qPyQAsy QOMCsR0A9tzw8mYFC6VMDtN7q7PLPEhULEk0z6HCwvurt5xffs8ibExamjrZ8IqApgG8 H79065yv2R7x684Du3YvAwYKe69fKiBjNF5HEE+sw89wB/C6/JNEH+TPWkwxUgR4QYMz SyvbNGK4Rz2l1fyRzaUvdansrTb5B4r6PP0Uud9z0ozcUlQEDBi2KMJKcsijhGgI08tr OfdA== 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=YRhHfYvcxk5JpWY5c7kjM/LCCCXthk/+kL7hgjXlx0g=; b=mTz6ba3VXlzR7NNgXY4NSHhh52G/Qmc3m2+0zBCDVpZ7r0WvWC0W87m5oSHL8gtdZC z/7OCzyxxhy/BJCo2j3RBlGutNkRrHmM6M2BUK9jpjY6LjBRQWbfI7HtzaqikbMFH59G /OWZW7+1mD5zBg6GDLC2AXl4toUw5I2AQhFoRfYdjN9QjGZQZNvvcAbAY6phIuyX1v90 cg1ieicLLM6NgI79qmWQ8zt3R3axpmtAgFvnlfHAIjhhEL+vLCqg2oD/B4fYPVBx7pun cndfzTacZJgD4rMt36b1tKPcff888VESUgTLQn/9LB71nGBtdyPEw3O9Fu9XekYlmr5k qKwg== X-Gm-Message-State: AOUpUlGxOIjs0vi84Tud+7vFAlCxfLL32tmo6Hm9/xci0sCaPgQVfd55 AXm61S7giNXtN2sZQFhW3Bon/9eJ+oc= X-Google-Smtp-Source: AAOMgpeog9eFAVtmoe8nkkW8C9jgxpLCWeN4YjpQ26geKbupQ8PNi4as/TBKt2CnyEAjbxt4BRJR2w== X-Received: by 2002:a37:5285:: with SMTP id g127-v6mr8941555qkb.377.1532011825545; Thu, 19 Jul 2018 07:50:25 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id j20-v6sm6054397qtc.71.2018.07.19.07.50.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 07:50:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/22] btrfs: reset max_extent_size properly Date: Thu, 19 Jul 2018 10:49:57 -0400 Message-Id: <20180719145006.17532-13-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180719145006.17532-1-josef@toxicpanda.com> References: <20180719145006.17532-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 c20675c265c5..e057d9b2d959 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4657,6 +4657,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, goto out; } else { ret = 1; + space_info->max_extent_size = 0; } space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; @@ -8199,10 +8200,16 @@ 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_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); }