From patchwork Thu Aug 30 17:42:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10582459 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 6BF751805 for ; Thu, 30 Aug 2018 17:43:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57690284DA for ; Thu, 30 Aug 2018 17:43:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B04728681; Thu, 30 Aug 2018 17:43:03 +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 DD2B4284DA for ; Thu, 30 Aug 2018 17:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727599AbeH3VqQ (ORCPT ); Thu, 30 Aug 2018 17:46:16 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:38128 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbeH3VqQ (ORCPT ); Thu, 30 Aug 2018 17:46:16 -0400 Received: by mail-qt0-f195.google.com with SMTP id x7-v6so11304534qtk.5 for ; Thu, 30 Aug 2018 10:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gRjtR9nbMSjYn5Z9+dN2dXdWyVc7PQdwC8wJ+EjtSOY=; b=iT2lfRWhpt52s4EGsinqTUo5VtmmOTbBPjONwZEoSm37JU7VXEbHabh8yW8uZ70Xbs pswY548dhx/0Y423KgCr5anaNf4QQQOqg2HD/d9tpF9EtU+S6L351lW6C//abrsaGqso 85s67JeX1QhqyY4Ggk25GWj8ZPQNvIhwjjAYeuy8YHpFfrKOF/iC4rMy5EFod+TIsSGz FGmGkMYCRYp45x98KSFdc9qkplNvN3dkYjkF+UK5BGQbZaiCain3Hnpa3XbaEYwJPd2m 2n5JNWNcVgbQGfOS3fELigufsIr/m+0GUJrcngqdcoz7PaNBg3ynTuU50drk7oaiIG9U GK+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gRjtR9nbMSjYn5Z9+dN2dXdWyVc7PQdwC8wJ+EjtSOY=; b=qIQEhyHcgyRHtp/ybg1OHfw8CmkkkwfosVIuoBV/87Zab1qG101RyxKtji9ccarHlH ESJHraIAUnHjXrNsGa2F21LTlo3umFdQcDULtb075k08itoQ69fZKj9h/EKeWeWlIobi rQXU5bmdmcsEh1lRTznHtTm/COIkN34fvkEmr8FVCac2zfifxXbGpAbDbvyKiZAT90cJ yMaoSkVaZ6chILFaCRoRa+pp+L558FU+wH6bbcwjKmKir9Kiy8vxHghciFQPwZLd95Nt FRK5+9vEnMcSBHI2bWJUbwcuQWtXKkuWyp/fV6sFk3hLPfd5umU1pR/yYdYpFyP6Xzzj +cew== X-Gm-Message-State: APzg51AI23OnXAikwJja8FHdGywbdVh8V//cCElJ/WMHWHDxbnU/Imzo bPLmA9yh4N2jwkmlekvZPc7jvwEvPTcPXQ== X-Google-Smtp-Source: ANB0Vda809aEaEo9qVu8eTZOEK4hk91F/LGTsIlsYAmwYDTguIrxXYQbH4g2Fir3RHoukisbFIHfVw== X-Received: by 2002:ac8:24d0:: with SMTP id t16-v6mr12893874qtt.116.1535650980708; Thu, 30 Aug 2018 10:43:00 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id p4-v6sm4907810qkl.41.2018.08.30.10.42.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Aug 2018 10:42:59 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 18/35] btrfs: set max_extent_size properly Date: Thu, 30 Aug 2018 13:42:08 -0400 Message-Id: <20180830174225.2200-19-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180830174225.2200-1-josef@toxicpanda.com> References: <20180830174225.2200-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 From: Josef Bacik We can't use entry->bytes if our entry is a bitmap entry, we need to use entry->max_extent_size in that case. Fix up all the logic to make this consistent. Signed-off-by: Josef Bacik --- fs/btrfs/free-space-cache.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index db93a5f035a0..53521027dd78 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1766,6 +1766,18 @@ static int search_bitmap(struct btrfs_free_space_ctl *ctl, return -1; } +static void set_max_extent_size(struct btrfs_free_space *entry, + u64 *max_extent_size) +{ + if (entry->bitmap) { + if (entry->max_extent_size > *max_extent_size) + *max_extent_size = entry->max_extent_size; + } else { + if (entry->bytes > *max_extent_size) + *max_extent_size = entry->bytes; + } +} + /* Cache the size of the max extent in bytes */ static struct btrfs_free_space * find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, @@ -1787,8 +1799,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, for (node = &entry->offset_index; node; node = rb_next(node)) { entry = rb_entry(node, struct btrfs_free_space, offset_index); if (entry->bytes < *bytes) { - if (entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + set_max_extent_size(entry, max_extent_size); continue; } @@ -1806,8 +1817,7 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, } if (entry->bytes < *bytes + align_off) { - if (entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + set_max_extent_size(entry, max_extent_size); continue; } @@ -1819,8 +1829,8 @@ find_free_space(struct btrfs_free_space_ctl *ctl, u64 *offset, u64 *bytes, *offset = tmp; *bytes = size; return entry; - } else if (size > *max_extent_size) { - *max_extent_size = size; + } else { + set_max_extent_size(entry, max_extent_size); } continue; } @@ -2680,8 +2690,7 @@ static u64 btrfs_alloc_from_bitmap(struct btrfs_block_group_cache *block_group, err = search_bitmap(ctl, entry, &search_start, &search_bytes, true); if (err) { - if (search_bytes > *max_extent_size) - *max_extent_size = search_bytes; + set_max_extent_size(entry, max_extent_size); return 0; } @@ -2718,8 +2727,8 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group, entry = rb_entry(node, struct btrfs_free_space, offset_index); while (1) { - if (entry->bytes < bytes && entry->bytes > *max_extent_size) - *max_extent_size = entry->bytes; + if (entry->bytes < bytes) + set_max_extent_size(entry, max_extent_size); if (entry->bytes < bytes || (!entry->bitmap && entry->offset < min_start)) {