Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1260930pxa; Thu, 20 Aug 2020 07:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP0Nw3DhvILQVGEWJC+5sdU2xRcoquh+MbHzWruY6Cx4j7DjagZLV0kH8s3UdqDeLhcUmN X-Received: by 2002:a17:906:6055:: with SMTP id p21mr3553356ejj.173.1597932106839; Thu, 20 Aug 2020 07:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597932106; cv=none; d=google.com; s=arc-20160816; b=wKOPTCzK1CbxvSBr0TS9WPighachz0TuWx3CT5IZJrFIIU4wOMc6reoT4tOUprbuoO ZQQi0vHRGEaupkZosL7t+h06keLAvW15F7udKrrK8o/fja4ONKtDN1MvBdQbE5zwN9e/ uEE8nMLfjXJ6XtwuV2gz1Kq4lxE42GaQvuh3huYP1bbKnwr59ocbj/O2MMHtJQ43Nd8q 67fLQaKBS7eQ2AUUfzF9DSldnmYy1Re1D0mgA8oLTQwxYfNa/qkyG8yTflMBh/AI6OU4 NpJRezojKuL6+kBwQ621CNRmlnAGWWUS6oM1/0Zt2LL0B2XyX02wKyzu1l05XVWcSRAC DWDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8TF0Ar1WiSmniC0tqAG1ItFGdoC/C2yekhjkwhRQFC4=; b=SR3QaeBhDntPZ1sAtxZ5DMbtroOX8hUNy4hTBvKS+9G7RTDR59H9eLzWKrGF7/4ywW hQoi8G+1kUkxun4KD6kiHyKs1XHQdoUGveYWHlehyRW2DSMorBv+cLsuGnLGG8UnS72O cMFttjoyHFI4MHj0FwtT9ADjmPi9bwyHRXIWncnh7Bp8+mbQmlI0sLRaJGykWxtTn5MY bxKLdlYTNo7W7GTiu663ExCXcNNxTH2I3LnVzGqZuLM0wykBTcUGro6uQBWA2IpX2jkI 1w2hWro6AJ8q0BWAEqS0D9xibisPuzvTkEa+lB2LVRs8qM2ptxSp/RjcVifyfnHwuFH0 6q4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FBaNdzMt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si1217484ejx.196.2020.08.20.07.01.22; Thu, 20 Aug 2020 07:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FBaNdzMt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727990AbgHTN70 (ORCPT + 99 others); Thu, 20 Aug 2020 09:59:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:60240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726948AbgHTJYW (ORCPT ); Thu, 20 Aug 2020 05:24:22 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4F4CA22CA1; Thu, 20 Aug 2020 09:24:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915461; bh=2zNQvTpp5k7RZuk30s8XlS+dyW8wMKyqVTDGMrdR33E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FBaNdzMt0QgXEbuZRvOVck65hi1qjXYMfHcVPRBia/GBPSWx82XnNOlQX7c9rYqeJ N2F4lTb8E4Y+O/naDc5YVYYZOb6ZacQk7T1auKHJoG9LPnL270b0uCHsVXDwESFxHu SMc6O26YAX/YR799jd/V6n5l6hYC6wqUhCMFydRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Filipe Manana , David Sterba Subject: [PATCH 5.8 021/232] btrfs: remove no longer needed use of log_writers for the log root tree Date: Thu, 20 Aug 2020 11:17:52 +0200 Message-Id: <20200820091613.767414822@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana commit a93e01682e283f6de09d6ce8f805dc52a2e942fb upstream. When syncing the log, we used to update the log root tree without holding neither the log_mutex of the subvolume root nor the log_mutex of log root tree. We used to have two critical sections delimited by the log_mutex of the log root tree, so in the first one we incremented the log_writers of the log root tree and on the second one we decremented it and waited for the log_writers counter to go down to zero. This was because the update of the log root tree happened between the two critical sections. The use of two critical sections allowed a little bit more of parallelism and required the use of the log_writers counter, necessary to make sure we didn't miss any log root tree update when we have multiple tasks trying to sync the log in parallel. However after commit 06989c799f0481 ("Btrfs: fix race updating log root item during fsync") the log root tree update was moved into a critical section delimited by the subvolume's log_mutex. Later another commit moved the log tree update from that critical section into the second critical section delimited by the log_mutex of the log root tree. Both commits addressed different bugs. The end result is that the first critical section delimited by the log_mutex of the log root tree became pointless, since there's nothing done between it and the second critical section, we just have an unlock of the log_mutex followed by a lock operation. This means we can merge both critical sections, as the first one does almost nothing now, and we can stop using the log_writers counter of the log root tree, which was incremented in the first critical section and decremented in the second criticial section, used to make sure no one in the second critical section started writeback of the log root tree before some other task updated it. So just remove the mutex_unlock() followed by mutex_lock() of the log root tree, as well as the use of the log_writers counter for the log root tree. This patch is part of a series that has the following patches: 1/4 btrfs: only commit the delayed inode when doing a full fsync 2/4 btrfs: only commit delayed items at fsync if we are logging a directory 3/4 btrfs: stop incremening log_batch for the log root tree when syncing log 4/4 btrfs: remove no longer needed use of log_writers for the log root tree After the entire patchset applied I saw about 12% decrease on max latency reported by dbench. The test was done on a qemu vm, with 8 cores, 16Gb of ram, using kvm and using a raw NVMe device directly (no intermediary fs on the host). The test was invoked like the following: mkfs.btrfs -f /dev/sdk mount -o ssd -o nospace_cache /dev/sdk /mnt/sdk dbench -D /mnt/sdk -t 300 8 umount /mnt/dsk CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Josef Bacik Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ctree.h | 1 + fs/btrfs/tree-log.c | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1059,6 +1059,7 @@ struct btrfs_root { wait_queue_head_t log_writer_wait; wait_queue_head_t log_commit_wait[2]; struct list_head log_ctxs[2]; + /* Used only for log trees of subvolumes, not for the log root tree */ atomic_t log_writers; atomic_t log_commit[2]; /* Used only for log trees of subvolumes, not for the log root tree */ --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -3116,28 +3116,17 @@ int btrfs_sync_log(struct btrfs_trans_ha btrfs_init_log_ctx(&root_log_ctx, NULL); mutex_lock(&log_root_tree->log_mutex); - atomic_inc(&log_root_tree->log_writers); index2 = log_root_tree->log_transid % 2; list_add_tail(&root_log_ctx.list, &log_root_tree->log_ctxs[index2]); root_log_ctx.log_transid = log_root_tree->log_transid; - mutex_unlock(&log_root_tree->log_mutex); - - mutex_lock(&log_root_tree->log_mutex); - /* * Now we are safe to update the log_root_tree because we're under the * log_mutex, and we're a current writer so we're holding the commit * open until we drop the log_mutex. */ ret = update_log_root(trans, log, &new_root_item); - - if (atomic_dec_and_test(&log_root_tree->log_writers)) { - /* atomic_dec_and_test implies a barrier */ - cond_wake_up_nomb(&log_root_tree->log_writer_wait); - } - if (ret) { if (!list_empty(&root_log_ctx.list)) list_del_init(&root_log_ctx.list); @@ -3183,8 +3172,6 @@ int btrfs_sync_log(struct btrfs_trans_ha root_log_ctx.log_transid - 1); } - wait_for_writer(log_root_tree); - /* * now that we've moved on to the tree of log tree roots, * check the full commit flag again