From patchwork Thu Jul 19 14:50:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10534699 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 D5094601D2 for ; Thu, 19 Jul 2018 14:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA08C29CB7 for ; Thu, 19 Jul 2018 14:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE91529CC6; Thu, 19 Jul 2018 14:50:37 +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 6DAA829CB7 for ; Thu, 19 Jul 2018 14:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731985AbeGSPeG (ORCPT ); Thu, 19 Jul 2018 11:34:06 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:34276 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731977AbeGSPeG (ORCPT ); Thu, 19 Jul 2018 11:34:06 -0400 Received: by mail-qk0-f196.google.com with SMTP id b66-v6so4411324qkj.1 for ; Thu, 19 Jul 2018 07:50:34 -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=StGRMfm4ovmcuRtLQBEdH/x+r6G6dwGSJNOEruL4AT0=; b=DxLAn2fu5UZ1gzvbJp06YJOWnrICxCLYT+vUPLdG6HZzKZrjGVZlZ1S6m5IDi3LDil 5Mhm71jSTyEMQxZ96foOxBMWsb16Z97nqD0n0WVSNFyOa4ZteJ4f2C0LOne/sMByeovb lYUgV7AN4tGptwnMWv+qQGOBCZ/fk+ZNO/j3/JYzvKy/x2a+72qjJ+o1Iuxx2nI2kclG 4YNjxtzhqv/CxqK6ke6IALW4yg/yGhR5ROTTFmV2tR3EVKRcM2CuG29EMyKN5fcrtUg7 UuheBW7YgT1gU6sMMKlNsgr05DHd4KoTcKFgtkRaXZ007TRNgy/ovBMKXRK+dztyVJep Qw4A== 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=StGRMfm4ovmcuRtLQBEdH/x+r6G6dwGSJNOEruL4AT0=; b=tTW+w1YUekJpvPUDpymFfxzUMM9IpPw0I7rMtiFJuRnDqKNL/Mtk7fUhgR0zDZRsLx 5nnuLrmAEvCw34zxyIcP0A3ToKRnNHFcnd/zjmfwp1oij0g1i1CEx/dIRbeNd1iKfUTw LcYBkKoNiQSrawNcEtzjIKjvuLeptLHC/bmNAHO3JGyIIvL/q7G16X9GQ+qTJBDMvPIm cUcB44+R2RqEdF6eyjTVnW0QaeCQORdMR5KzcHYrIjy/ZPir54xApViGY0BGDsiRlsxl tXHdY+yxZMqjD8hUI8+R6nZZujTw0lgH5pvLMP6AgXeO8SLcFMICh6s2G3DFxG6hV41Z QNPQ== X-Gm-Message-State: AOUpUlHrtQTaz5hNJfT29ZD6u6d9a4UqHP9qXeQZMXYAGvlPTojL0w+Q QTUm7z2LgqbHx4dcEIPhzVZKxxJTZa4= X-Google-Smtp-Source: AAOMgpfAwIXSfBiZiMouIBUPb4xN1VK37vl9s2IxxENv3P48GXjKE1mvxUz25ePhq84LQnrSeu9Qwg== X-Received: by 2002:a37:b91:: with SMTP id 139-v6mr9417871qkl.429.1532011833605; Thu, 19 Jul 2018 07:50:33 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id d39-v6sm6653171qta.60.2018.07.19.07.50.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jul 2018 07:50:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH 19/22] btrfs: set max_extent_size properly Date: Thu, 19 Jul 2018 10:50:03 -0400 Message-Id: <20180719145006.17532-19-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 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 13bc514e4e16..92e1c30356b9 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -1774,6 +1774,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, @@ -1795,8 +1807,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; } @@ -1814,8 +1825,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; } @@ -1827,8 +1837,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; } @@ -2688,8 +2698,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; } @@ -2726,8 +2735,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)) {