Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1232466pxa; Thu, 20 Aug 2020 06:18:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7L4kehFO/sKX4uOGfwufI2ikQBLN4YDtDfbQvI2JSUXcR+7/tdDmn7QRMW0OxhEK+WLPU X-Received: by 2002:a17:906:4e4f:: with SMTP id g15mr3120753ejw.443.1597929528375; Thu, 20 Aug 2020 06:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597929528; cv=none; d=google.com; s=arc-20160816; b=Pyk9ZU91TAhAOui6RCqIJm1pVhL3H/DJUcod3o8IXLhTBvppLaw1n7lbeICrf8RsPn Djjfs7rPK4BV6goGEdRlOFU4DNALTurFyYWcrj8VRH1Uhvkw2D64G/45CJz5ciTJWOk9 AMlmw/Cmm4OAMd/v2m67tUJ3XFMl+rCS2cZQ/3PWTYYrW1tNw8kh54Hj4VUxsi5VjjBg jkmR46+KvnogtneaZqrnYTcaSWIAa4RmVK1/j3vzXxENSeP0UP2l3JPODUygP4ciKxuz 3jdNgLXYQf0vzSVrh2fV8mbAzFwEDnxVJFbJmaK2FrLLqemitxyyFNxAa0hGB3YImPmM 9Jlg== 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=v9tBlQIHxYX4SIu7a+DAhuIELcLE2i7+E53JIoRIFwQ=; b=PzJ7BnZEz2yTSlIE+sIGHuUQ5RLkygfleRv/+nMRrs5jLzTbnjVYPHE2dZIqneIjaB HMYMk4HoJcsAuFq0wF24fJaaX/jo0XmgytnfPWzPOlqM+lIyPgDz1fjBNSeHHHy8i4I6 pvpLSNIYXgZJqa34xCITdoioKPqdyIy0P04bWtzKVjw7u0sgKRfcJwnGZfIk+d1tfcAr Afzr9JcmlGv5+xhy+VjEPfbf2P3Xzq2U6y7sG+vQ6t0/bOtjlKGavuBv1qcEIoAVWMdc 1byF/XcirpeAogGL/j3HVky9WSUV6bwC99tvOehxOEqhWumUkkmr38fjUwh3/tHWNl02 yk0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I5CeannI; 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 di7si1427202edb.220.2020.08.20.06.18.23; Thu, 20 Aug 2020 06:18:48 -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=I5CeannI; 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 S1728785AbgHTNRS (ORCPT + 99 others); Thu, 20 Aug 2020 09:17:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728382AbgHTJfH (ORCPT ); Thu, 20 Aug 2020 05:35:07 -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 DE95920724; Thu, 20 Aug 2020 09:35:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597916107; bh=Td9RkfrIsHF2byBHdEUoYltcoXv/ZlGRTo56IMl7h+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5CeannIEbrmMDjPNp8sOiG0OlpavNL1rarPQz3btw0Ctlk2ccDA1UZPF18aOM55Z GAsk1OSUEs6uF3ifuGeAW05qaSfBqUWLXa0saibOkYicjSfyalYJeEnWFbxtukwqQX fFwBJGrMyzq3oSKqOD9zcVjmAieon/4oxPXasqSk= 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.7 014/204] btrfs: only commit the delayed inode when doing a full fsync Date: Thu, 20 Aug 2020 11:18:31 +0200 Message-Id: <20200820091606.929702327@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091606.194320503@linuxfoundation.org> References: <20200820091606.194320503@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 8c8648dd1f6d62aeb912deeb788b6ac33cb782e7 upstream. Commit 2c2c452b0cafdc ("Btrfs: fix fsync when extend references are added to an inode") forced a commit of the delayed inode when logging an inode in order to ensure we would end up logging the inode item during a full fsync. By committing the delayed inode, we updated the inode item in the fs/subvolume tree and then later when copying items from leafs modified in the current transaction into the log tree (with copy_inode_items_to_log()) we ended up copying the inode item from the fs/subvolume tree into the log tree. Logging an up to date version of the inode item is required to make sure at log replay time we get the link count fixup triggered among other things (replay xattr deletes, etc). The test case generic/040 from fstests exercises the bug which that commit fixed. However for a fast fsync we don't need to commit the delayed inode because we always log an up to date version of the inode item based on the struct btrfs_inode we have in-memory. We started doing this for fast fsyncs since commit e4545de5b035c7 ("Btrfs: fix fsync data loss after append write"). So just stop committing the delayed inode if we are doing a fast fsync, we are only wasting time and adding contention on fs/subvolume 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/tree-log.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -5158,7 +5158,7 @@ static int btrfs_log_inode(struct btrfs_ struct btrfs_key max_key; struct btrfs_root *log = root->log_root; int err = 0; - int ret; + int ret = 0; bool fast_search = false; u64 ino = btrfs_ino(inode); struct extent_map_tree *em_tree = &inode->extent_tree; @@ -5195,14 +5195,16 @@ static int btrfs_log_inode(struct btrfs_ /* * Only run delayed items if we are a dir or a new file. - * Otherwise commit the delayed inode only, which is needed in - * order for the log replay code to mark inodes for link count - * fixup (create temporary BTRFS_TREE_LOG_FIXUP_OBJECTID items). + * Otherwise commit the delayed inode only if the full sync flag is set, + * as we want to make sure an up to date version is in the subvolume + * tree so copy_inode_items_to_log() / copy_items() can find it and copy + * it to the log tree. For a non full sync, we always log the inode item + * based on the in-memory struct btrfs_inode which is always up to date. */ if (S_ISDIR(inode->vfs_inode.i_mode) || inode->generation > fs_info->last_trans_committed) ret = btrfs_commit_inode_delayed_items(trans, inode); - else + else if (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags)) ret = btrfs_commit_inode_delayed_inode(inode); if (ret) {