From patchwork Mon Apr 22 07:46:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 10910763 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 5FEB11880 for ; Mon, 22 Apr 2019 07:47:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5016F28708 for ; Mon, 22 Apr 2019 07:47:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44A3D286D6; Mon, 22 Apr 2019 07:47:07 +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,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 CF9F128708 for ; Mon, 22 Apr 2019 07:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726759AbfDVHq6 (ORCPT ); Mon, 22 Apr 2019 03:46:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:39704 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726475AbfDVHq5 (ORCPT ); Mon, 22 Apr 2019 03:46:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 26323ADDC for ; Mon, 22 Apr 2019 07:46:56 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 3/3] btrfs: Always use a cached extent_state in btrfs_lock_and_flush_ordered_range Date: Mon, 22 Apr 2019 10:46:53 +0300 Message-Id: <20190422074653.13075-4-nborisov@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190422074653.13075-1-nborisov@suse.com> References: <20190422074653.13075-1-nborisov@suse.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 In case no cached_state argument is passed to btrfs_lock_and_flush_ordered_range use one locally in the function. This optimises the case when an ordered extent is found since the unlock function will be able to unlock that state directly without searching for it again. Signed-off-by: Nikolay Borisov --- fs/btrfs/ordered-data.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 65f6409c1c9f..5da2abe320b6 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -973,14 +973,26 @@ void btrfs_lock_and_flush_ordered_range(struct extent_io_tree *tree, struct extent_state **cached_state) { struct btrfs_ordered_extent *ordered; + struct extent_state *cachedp = NULL; + + if (cached_state) + cachedp = *cached_state; while (1) { - lock_extent_bits(tree, start, end, cached_state); + lock_extent_bits(tree, start, end, &cachedp); ordered = btrfs_lookup_ordered_range(BTRFS_I(inode), start, end - start + 1); - if (!ordered) + if (!ordered) { + /* + * If no external cached_state has been passed then + * decrement the extra ref taken for cachedp since we + * aren't exposing it outside of this function + */ + if (!cached_state) + refcount_dec(&cachedp->refs); break; - unlock_extent_cached(tree, start, end, cached_state); + } + unlock_extent_cached(tree, start, end, &cachedp); btrfs_start_ordered_extent(inode, ordered, 1); btrfs_put_ordered_extent(ordered); }