Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3345489pxv; Sun, 4 Jul 2021 16:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp+WnKPLa3uf45Llwg6IIqwjB6zAZDkOZ4jeMGMT+nRYchhH2v40VOu/g6FBUg31RgR6qg X-Received: by 2002:a05:6638:d51:: with SMTP id d17mr7669022jak.109.1625440154120; Sun, 04 Jul 2021 16:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625440154; cv=none; d=google.com; s=arc-20160816; b=c+9kugwHOknqbacgEvIuO0YjnHfxgqfQm3+PSmhQ/zXFjQQF/4pNtNuGAG5Eb5zq6J oaT7G6Rc/FYBo5DrXtMdNCqegc+KK9Hh5g6nLSJU7dUv9bYhSvBol1ULlLU4d9VKRIte n5FE7v7vpO9WpBTofPPO+x0xd8LC0PznV4DBwZFLBZe0EK7sVpw56/oRkmp9VcSEhA/V TBhoYVc2iGorCcoT2RIj0ObINuXRz31YHYMXP4unlLXQWbrEiVgDJ/ncUQr7ab2bomy0 m+p0sCiPjxtDsX40JOiyP9nVa6W7RaU6EJX9WVsuXlo3rVuO3ahEThqFnJPamE/QOhXk vztg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9KNDudNVbYhVL3rTasZHfAnR8Cjd4+R74NbeFIkvR9Y=; b=FnSQcfvUL78JgQ9MQcGbMPwLhjtzQpNNzUwIchO5YHxQu1maD2W3vLjNqfykAQc/bd xTHkG6yL31M6iKFds0MMaC60K6hEyfLOUgtR8iLG6UrB7PHaWC5y7WYpjA/lS7Lmi7p/ qGjOyT89bMY3ONiRHaQyeU+pMfMrLY6rMeHJQ8ShJ5JQRY2/2RXt5QDLye+lmuuHs1VJ LD743x56TAx7r+yeOEBGQ0G0lADTOGiHbCw6LojjPulPon2SJSGBU03MnoK+Mis3fkZc eY4NFp9lsvj3RUK4ZdKg+w+VKlRZU7bMtt4lJ5PZVZHYi8H4HYyelGeMNWk+v4VIqCYM qQNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oTOzgFYN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si11882092iln.52.2021.07.04.16.09.02; Sun, 04 Jul 2021 16:09:14 -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=k20201202 header.b=oTOzgFYN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232261AbhGDXKw (ORCPT + 99 others); Sun, 4 Jul 2021 19:10:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:47378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231233AbhGDXIi (ORCPT ); Sun, 4 Jul 2021 19:08:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 79B2561474; Sun, 4 Jul 2021 23:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625439962; bh=8BhR/GIE5G1/WZhMs6amTjTnxA/3gu8Ccy5Un5sX4TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oTOzgFYNGrI+WEPTJ6CrlLZy11dMIaVb63P4o6KHOjPq6RXyPasgN7Mkp9XPZLkBs HRAo6qKfM7Bc4uTxfNHJfe0iNQi0IYRSHc0bFAV5qQoJcDJ3teKlxWwH+bauvvKh7i CB7m8ZBrcqBJq2k/L9iQOGEe524b4cmbW4E9jCBer/cpVJ1jXyBSmdvQ5pWxBnYyYh r7eMXauc99dNKWdY0Ozqk0MBy01GxThdfWThPeLM4vSCmgmkbCg1sTYp1Ys9Ze45CF D8LOuEM+jAcBvfNFoqUM7j/kOtzPcIY1NglK2JVObgxqeKfwjaC2ZHqKiECWS/sFPZ jEKEvH712F8oQ== 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 5.13 75/85] btrfs: make Private2 lifespan more consistent Date: Sun, 4 Jul 2021 19:04:10 -0400 Message-Id: <20210704230420.1488358-75-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210704230420.1488358-1-sashal@kernel.org> References: <20210704230420.1488358-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 46f392943f4d..f9942560866b 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2677,7 +2677,7 @@ int btrfs_writepage_cow_fixup(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; /* -- 2.30.2