From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88F0BC07E95 for ; Sun, 4 Jul 2021 23:21:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7351E61364 for ; Sun, 4 Jul 2021 23:21:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbhGDXX7 (ORCPT ); Sun, 4 Jul 2021 19:23:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:56968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234240AbhGDXO6 (ORCPT ); Sun, 4 Jul 2021 19:14:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D547A61970; Sun, 4 Jul 2021 23:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625440312; bh=qtOcQ47kKf3f54/I83iYhNOALL5tgTnwC9HF82KQ0ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bBaauEM0oT9+Unx3bDkZ5rjj9vhGr3qmHoqGkcJjMLFtazUPGGnWxPO1CY1xyr/nW nHk4ZUK2fKl9oJ93184JcKai/3d6g410AaxEj34pdjZC4PcfmPo4vGu+luhRWPxYti G3DTNSG9GnbW+sNQXqkR00y8uczUu42SW+OPlRDbSQafrRQt5gdAPm6v2hggRbUn+H KjUR7c32QBBbM05VJLnOo9+7GI2tEoF94R4OcI7irJbkl5MMVqA+TM1B7ztZn/0wos 4JSqEpO7WprChh4E+2NfdlH6+cylg/0UEZX+hUPLVHm4Psb+FNVcOLVS02wuiyTLRr VDAznQjKYmW1A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Qu Wenruo , Josef Bacik , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 23/25] btrfs: make Private2 lifespan more consistent Date: Sun, 4 Jul 2021 19:11:21 -0400 Message-Id: <20210704231123.1491517-23-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704231123.1491517-1-sashal@kernel.org> References: <20210704231123.1491517-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo [ Upstream commit 87b4d86baae219a9a79f6b0a1434b2a42fd40d09 ] Currently we use page Private2 bit to indicate that we have ordered extent for the page range. But the lifespan of it is not consistent, during regular writeback path, there are two locations to clear the same PagePrivate2: T ----- Page marked Dirty | + ----- Page marked Private2, through btrfs_run_dealloc_range() | + ----- Page cleared Private2, through btrfs_writepage_cow_fixup() | in __extent_writepage_io() | ^^^ Private2 cleared for the first time | + ----- Page marked Writeback, through btrfs_set_range_writeback() | in __extent_writepage_io(). | + ----- Page cleared Private2, through | btrfs_writepage_endio_finish_ordered() | ^^^ Private2 cleared for the second time. | + ----- Page cleared Writeback, through btrfs_writepage_endio_finish_ordered() Currently PagePrivate2 is mostly to prevent ordered extent accounting being executed for both endio and invalidatepage. Thus only the one who cleared page Private2 is responsible for ordered extent accounting. But the fact is, in btrfs_writepage_endio_finish_ordered(), page Private2 is cleared and ordered extent accounting is executed unconditionally. The race prevention only happens through btrfs_invalidatepage(), where we wait for the page writeback first, before checking the Private2 bit. This means, Private2 is also protected by Writeback bit, and there is no need for btrfs_writepage_cow_fixup() to clear Priavte2. This patch will change btrfs_writepage_cow_fixup() to just check PagePrivate2, not to clear it. The clearing will happen in either btrfs_invalidatepage() or btrfs_writepage_endio_finish_ordered(). This makes the Private2 bit easier to understand, just meaning the page has unfinished ordered extent attached to it. And this patch is a hard requirement for the incoming refactoring for how we finished ordered IO for endio context, as the coming patch will check Private2 to determine if we need to do the ordered extent accounting. Thus this patch is definitely needed or we will hang due to unfinished ordered extent. Reviewed-by: Josef Bacik Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9769a5db7d5e..d7317936b45c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2204,7 +2204,7 @@ static int btrfs_writepage_start_hook(struct page *page, u64 start, u64 end) struct btrfs_writepage_fixup *fixup; /* this page is properly in the ordered list */ - if (TestClearPagePrivate2(page)) + if (PagePrivate2(page)) return 0; if (PageChecked(page)) -- 2.30.2