From patchwork Tue Sep 11 17:57:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596095 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 439D914E5 for ; Tue, 11 Sep 2018 17:58:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EE3729B9F for ; Tue, 11 Sep 2018 17:58:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 237D229BA1; Tue, 11 Sep 2018 17:58:53 +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 BC63C29B9F for ; Tue, 11 Sep 2018 17:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbeIKW7R (ORCPT ); Tue, 11 Sep 2018 18:59:17 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:40537 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728113AbeIKW7Q (ORCPT ); Tue, 11 Sep 2018 18:59:16 -0400 Received: by mail-qt0-f193.google.com with SMTP id h4-v6so29190588qtj.7 for ; Tue, 11 Sep 2018 10:58:51 -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=vfQB1tHlwUhp446i68IaYEtvkGVFvtWut8g/b3eBAlk=; b=oCh5lm26H43scP0FTomA27AKg0ZoxVn5eHSLkEgpOzwwRqe2C6cWo5IOBWJtzARtv6 5IhbPfeAa0Cb6JK+zXo/Gon96XCX6VULvlJQDO7cp+FXCRIPRc8qjVs2g6Vc6ywZb4wZ 8znV8Ar0H+A6dC/kADTIcbIfuE4IC056/EuieZya/RMotohz9htXxmbnnLFYoXTPlIZC HeXgS0tXPy+slkaS8VNRGAJhDWF76KqydAip5B16MOrFg7IBJ5E/LeaUgzWNMcrmCEI9 C8nOqadLa01T97KD9LqKMWSJINqkLxnj0nRrRvn4i0V8QlyzZInru6VrOb+C/t9YeWaS QfwQ== 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=vfQB1tHlwUhp446i68IaYEtvkGVFvtWut8g/b3eBAlk=; b=eDD0dpo5M92aK6Gc0SgiGvg/iVayPkKgW1qP86wFQc8JL4jYxe5kiuAlR1FEb1Zu/X AKdekkjwRBuTppyKfOA1FcAG6VElL6bCekgeh9novyhYGfU2VuzoPtkKaD6C51Pm4QE3 5CNa4ibWMntKKC7V/JAc2cQEFr+W+89gb6tS8G1TY8WsEZ7S+Gonv+ZYA0+Jr6ZDDHh0 CirVX1HhRnbcdGQbdfhRGOI9gECdR5aC8hrMXQYtpLSSmLs9Fealn475ddPa4KTzhp97 fI4nahIScGt0qc76XQ7VqbqIfwJ0N1iSMnrhVSQUFRYJl0/K/dxeljyRsy/z31HIrdWC aNvA== X-Gm-Message-State: APzg51CBCDr4a2vMDSMp7tVGZyZGYa3mmGfIkhkx8/UrCDmSiiRRUH1Y ZGniYbKgaK81mfPoKJqhv0qwfg== X-Google-Smtp-Source: ANB0VdaSL7f1TFEehPH5Vu+DrsqkZlQTMS1dZMcZ8gN20ZP3pcoH8ZsQAMCD4jkWw2QnTh9sRdUdew== X-Received: by 2002:ac8:39e1:: with SMTP id v88-v6mr20677848qte.273.1536688730817; Tue, 11 Sep 2018 10:58:50 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id v129-v6sm10552151qkd.86.2018.09.11.10.58.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:49 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 22/36] btrfs: only run delayed refs if we're committing Date: Tue, 11 Sep 2018 13:57:53 -0400 Message-Id: <20180911175807.26181-23-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 I noticed in a giant dbench run that we spent a lot of time on lock contention while running transaction commit. This is because dbench results in a lot of fsync()'s that do a btrfs_transaction_commit(), and they all run the delayed refs first thing, so they all contend with each other. This leads to seconds of 0 throughput. Change this to only run the delayed refs if we're the ones committing the transaction. This makes the latency go away and we get no more lock contention. Reviewed-by: Omar Sandoval Signed-off-by: Josef Bacik --- fs/btrfs/transaction.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index a0f19ca0bd6c..39a2bddb0b29 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -1925,15 +1925,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) btrfs_trans_release_metadata(trans); trans->block_rsv = NULL; - /* make a pass through all the delayed refs we have so far - * any runnings procs may add more while we are here - */ - ret = btrfs_run_delayed_refs(trans, 0); - if (ret) { - btrfs_end_transaction(trans); - return ret; - } - cur_trans = trans->transaction; /* @@ -1946,12 +1937,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) if (!list_empty(&trans->new_bgs)) btrfs_create_pending_block_groups(trans); - ret = btrfs_run_delayed_refs(trans, 0); - if (ret) { - btrfs_end_transaction(trans); - return ret; - } - if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) { int run_it = 0; @@ -2022,6 +2007,15 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) spin_unlock(&fs_info->trans_lock); } + /* + * We are now the only one in the commit area, we can run delayed refs + * without hitting a bunch of lock contention from a lot of people + * trying to commit the transaction at once. + */ + ret = btrfs_run_delayed_refs(trans, 0); + if (ret) + goto cleanup_transaction; + extwriter_counter_dec(cur_trans, trans->type); ret = btrfs_start_delalloc_flush(fs_info);