From patchwork Thu Aug 30 17:41:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10582427 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 316AD17DE for ; Thu, 30 Aug 2018 17:42:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F79E2C342 for ; Thu, 30 Aug 2018 17:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 141452C35E; Thu, 30 Aug 2018 17:42:35 +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 98D7C2C342 for ; Thu, 30 Aug 2018 17:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727404AbeH3Vps (ORCPT ); Thu, 30 Aug 2018 17:45:48 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:44025 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727205AbeH3Vpr (ORCPT ); Thu, 30 Aug 2018 17:45:47 -0400 Received: by mail-qk1-f195.google.com with SMTP id 130-v6so22816qkd.10 for ; Thu, 30 Aug 2018 10:42:32 -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=6KgmwomWpLZEcbjWD03lwUSb4bv1/MZXNAiN0EJMH3g=; b=yS4vQKhtDs3fCtunKcBQY5tJAj/JFAjMFqx9Hvj41uhxi7fau8Emxz8Ju9/bzTV9pw 5zI0zR0uqr73iQcYOl7olxz8JvHEkNpkWtF+YEvgT414aXMYOpPD/sPUQck+5GjLLgqj SoUTw8TK6nKCC2xLVNQKSKdPxUz2q2IE9dq8lOsw7L2NnBwSzkRfzic1hm8AMJ1E34m1 3MsDqnyUjAbDTGySsjXeE3E0LwNOi2w2+MCEUC0rlgKfN6lp9Py5AJimzBlefioEC2z5 Zj33yMvJ4hCbLyvKPIfMNZmfS/+H57rmiiKpZkcZBdk4IdwtF/sC4ZBpx/JCg6IsoO9Q tHpw== 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=6KgmwomWpLZEcbjWD03lwUSb4bv1/MZXNAiN0EJMH3g=; b=jA5SRaEWoJXfPd9oyj4tWKoYfSFVTLr9PK4bbsuxAyY8EKZagOsHQwgc0mNXbzPVkE XwjIy6OwJfMpkf+K83zsgaj260JY+MreSuECDk6VINsp/pu7+jh7LSOZzvFfOMGOD/eu f7RkEIBPCtTdAvqAXjnDXOLBBw+Lye8BKhIAKqgOSOUvNLEKh5sO8OUHoh9dtevzUbU8 a3cYtlUaowwR0DKNR8OsXFGWGwgOu5CvYNBSaiFQGi7S+lgNP7VdhBIz3LjOl4iGcMqP ULIBumAQNyQbG5BWrhn6WejRsni5J4XOa7LUEib7brp8/7sdfqoZcxWV6ITf9hQ73e5I rJ3g== X-Gm-Message-State: APzg51DmEkj1wmffzdRRS9lbMpXbJStQ9KONCzSuHnZBXoGGLjmGob0K yq4gfCSQQkHqMsxfyfRliRU9oHMO8+pJDg== X-Google-Smtp-Source: ANB0VdYlTOqyUoU/Vdw4ZECuIYZGeApID6UwxSweyBYKx/Rc3ArvVpl//TU6lCPNyc4YbF8c77JN5g== X-Received: by 2002:a37:132a:: with SMTP id d42-v6mr11831047qkh.343.1535650952037; Thu, 30 Aug 2018 10:42:32 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id o68-v6sm4147551qkf.9.2018.08.30.10.42.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Aug 2018 10:42:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 02/35] btrfs: add cleanup_ref_head_accounting helper Date: Thu, 30 Aug 2018 13:41:52 -0400 Message-Id: <20180830174225.2200-3-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 were missing some quota cleanups in check_ref_cleanup, so break the ref head accounting cleanup into a helper and call that from both check_ref_cleanup and cleanup_ref_head. This will hopefully ensure that we don't screw up accounting in the future for other things that we add. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: Liu Bo --- fs/btrfs/extent-tree.c | 67 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 6799950fa057..4c9fd35bca07 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2461,6 +2461,41 @@ static int cleanup_extent_op(struct btrfs_trans_handle *trans, return ret ? ret : 1; } +static void cleanup_ref_head_accounting(struct btrfs_trans_handle *trans, + struct btrfs_delayed_ref_head *head) +{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_delayed_ref_root *delayed_refs = + &trans->transaction->delayed_refs; + + if (head->total_ref_mod < 0) { + struct btrfs_space_info *space_info; + u64 flags; + + if (head->is_data) + flags = BTRFS_BLOCK_GROUP_DATA; + else if (head->is_system) + flags = BTRFS_BLOCK_GROUP_SYSTEM; + else + flags = BTRFS_BLOCK_GROUP_METADATA; + space_info = __find_space_info(fs_info, flags); + ASSERT(space_info); + percpu_counter_add_batch(&space_info->total_bytes_pinned, + -head->num_bytes, + BTRFS_TOTAL_BYTES_PINNED_BATCH); + + if (head->is_data) { + spin_lock(&delayed_refs->lock); + delayed_refs->pending_csums -= head->num_bytes; + spin_unlock(&delayed_refs->lock); + } + } + + /* Also free its reserved qgroup space */ + btrfs_qgroup_free_delayed_ref(fs_info, head->qgroup_ref_root, + head->qgroup_reserved); +} + static int cleanup_ref_head(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *head) { @@ -2496,31 +2531,6 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, spin_unlock(&delayed_refs->lock); spin_unlock(&head->lock); - trace_run_delayed_ref_head(fs_info, head, 0); - - if (head->total_ref_mod < 0) { - struct btrfs_space_info *space_info; - u64 flags; - - if (head->is_data) - flags = BTRFS_BLOCK_GROUP_DATA; - else if (head->is_system) - flags = BTRFS_BLOCK_GROUP_SYSTEM; - else - flags = BTRFS_BLOCK_GROUP_METADATA; - space_info = __find_space_info(fs_info, flags); - ASSERT(space_info); - percpu_counter_add_batch(&space_info->total_bytes_pinned, - -head->num_bytes, - BTRFS_TOTAL_BYTES_PINNED_BATCH); - - if (head->is_data) { - spin_lock(&delayed_refs->lock); - delayed_refs->pending_csums -= head->num_bytes; - spin_unlock(&delayed_refs->lock); - } - } - if (head->must_insert_reserved) { btrfs_pin_extent(fs_info, head->bytenr, head->num_bytes, 1); @@ -2530,9 +2540,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, } } - /* Also free its reserved qgroup space */ - btrfs_qgroup_free_delayed_ref(fs_info, head->qgroup_ref_root, - head->qgroup_reserved); + cleanup_ref_head_accounting(trans, head); + + trace_run_delayed_ref_head(fs_info, head, 0); btrfs_delayed_ref_unlock(head); btrfs_put_delayed_ref_head(head); return 0; @@ -6991,6 +7001,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (head->must_insert_reserved) ret = 1; + cleanup_ref_head_accounting(trans, head); mutex_unlock(&head->mutex); btrfs_put_delayed_ref_head(head); return ret;