From patchwork Mon Jul 24 13:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DE42C0015E for ; Mon, 24 Jul 2023 13:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231342AbjGXN1U (ORCPT ); Mon, 24 Jul 2023 09:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 383A6E66 for ; Mon, 24 Jul 2023 06:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=8iPjpqgcm59PytEKER0uUQye3TSfrtezfdMzci1iUQo=; b=coFfqR/+ubYREyXhR3bA2LXlkS mmDUdXy1ZktilqKOZihspcD8F3m7UpNWgmv8PEBioeYkGwnIfQStfQJdUoFsWmsgAoFjnppUIaEaX S96AEVJ6x/TDFQmwieZmI7xNuYvVJZSfMiG2FudoRGazlwH4Kyq3X0kwmCqAfvXHcvWCXdzbTQEog fwZ84Z8WKWoab/6yVw1/JY9e1pD8R5WR+vTuZE9PDateuJnUNgCTfjRiVW/amR1Q4yBCfOKH8CrsI hJZOgf0mPAr7Xv3wdIHFy8sMdQ3bYDDScRxqctZKtKu/jSxkv3kLeioSBxjOFO/QptyKRQy0kV2hN qdWmi2Jg==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaX-004RLX-39; Mon, 24 Jul 2023 13:27:01 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 1/9] btrfs: don't stop integrity writeback too early Date: Mon, 24 Jul 2023 06:26:53 -0700 Message-Id: <20230724132701.816771-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org extent_write_cache_pages stops writing pages as soon as nr_to_write hits zero. That is the right thing for opportunistic writeback, but incorrect for data integrity writeback, which needs to ensure that no dirty pages are left in the range. Thus only stop the writeback for WB_SYNC_NONE if nr_to_write hits 0. This is a port of write_cache_pages changes in commit 05fe478dd04e ("mm: write_cache_pages integrity fix"). Note that I've only trigger the problem with other changes to the btrfs writeback code, but this condition seems worthwhile fixing anyway. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/extent_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c0440a0988c9a8..231e620e6c497d 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2098,7 +2098,8 @@ static int extent_write_cache_pages(struct address_space *mapping, * We have to make sure to honor the new nr_to_write * at any time */ - nr_to_write_done = wbc->nr_to_write <= 0; + nr_to_write_done = wbc->sync_mode == WB_SYNC_NONE && + wbc->nr_to_write <= 0; } folio_batch_release(&fbatch); cond_resched(); From patchwork Mon Jul 24 13:26:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C37C0C001E0 for ; Mon, 24 Jul 2023 13:27:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbjGXN10 (ORCPT ); Mon, 24 Jul 2023 09:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231225AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C17E77 for ; Mon, 24 Jul 2023 06:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UYsvTds/y/Om/943qxrj8Wf0OVOAcYDC60XUQ941K7o=; b=3s2ML+l04xerF5KHR4BgCmpAPn nkrNwPwlU+QnvD/s04GXkJmn9/1FByITXkKcTlAuWeldBZ8aava3auvwh8jrxMe7pad0szz6aNini 2g3OGbgjNGvNDaFJU/jlfZCQNfoowPN9VC8HUbU6ZGeAkC+6gV91bisgPhee7mxvrVkp8c+ubo2F0 3aSRFS+Ps4Ai1nt4XNzNVa35XISfeN6Z/RTkZoyYh3j7az9dYKgDqJL+FWDCvdtFRi3+4GUlf9+i+ KQMKpyW9Ukj16TT5nDUNDX5x8LT7n7ArGPVCbMES+oLit2S/oM3hdDw7OvCCj/o7774PXMMDVXCam H/8kaaww==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaY-004RLa-0Y; Mon, 24 Jul 2023 13:27:02 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/9] btrfs: don't wait for writeback on clean pages in extent_write_cache_pages Date: Mon, 24 Jul 2023 06:26:54 -0700 Message-Id: <20230724132701.816771-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org __extent_writepage can have started on more pages than the one it was called for. This happens regularly for zoned file systems, and in theory could happen for compressed I/O if the worker thread was executed very quicky. For such pages extent_write_cache_pages waits for writeback to complete before moving on to the next page, which is highly inefficient as it blocks the flusher thread Port over the PageDirty check that was added to write_cache_pages in commit 515f4a037fb ("mm: write_cache_pages optimise page cleaning") to fix this. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/extent_io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 231e620e6c497d..1cc46bbbd888cd 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2075,6 +2075,12 @@ static int extent_write_cache_pages(struct address_space *mapping, continue; } + if (!folio_test_dirty(folio)) { + /* someone wrote it for us */ + folio_unlock(folio); + continue; + } + if (wbc->sync_mode != WB_SYNC_NONE) { if (folio_test_writeback(folio)) submit_write_bio(bio_ctrl, 0); From patchwork Mon Jul 24 13:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74F99C001E0 for ; Mon, 24 Jul 2023 13:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231169AbjGXN1W (ORCPT ); Mon, 24 Jul 2023 09:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88C0BE73 for ; Mon, 24 Jul 2023 06:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=PbB1bHaHc9RUosOldd9EfGcBQTtI4MTE+lOImgL0IDY=; b=uUV3nMbAlZett0+hKUIKXwwkRR nBdlzpVY8VDcxKHmwQBLwjNoMqn7SW/br4iNhcQm2etHXjhpfpBUbGcwDXOUugHw9ALaxe0rQ8bxw ItOJzhcUCYDSz97Wzl4W9O+TpED+gTjMk1o/Gcs46rUwwnxbNZ6GVPnGxhIS1a7gUsY+GtLY/Aq6d VLh4RA3UMyErQre+spZEn9UKYTCvMEC20gjiIiiaAOCn1I5wlDaB+wyCMzPefvwsUiD7C3R6zMk/Y ABijkmgFPMteRyu1vmxBspnlk7Gx6Je6MpAelo17eQpVZC73lUaCheqtR2xAIcWOxZIAcng61Ror8 mIwSl8qQ==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaY-004RLl-18; Mon, 24 Jul 2023 13:27:02 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 3/9] btrfs: fix an error handling corner case in cow_file_range Date: Mon, 24 Jul 2023 06:26:55 -0700 Message-Id: <20230724132701.816771-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When the call to btrfs_reloc_clone_csums in cow_file_range returns an error, we jump to the out_unlock label with the extent_reserved variable set to false. The cleanup at the label will then call extent_clear_unlock_delalloc on the range from start to end. But we've already added cur_alloc_size to start, so there might no range be left from the newly increment start to end. Move the check for start < end so that it is reached by also for the !extent_reserved case. Fixes: a315e68f6e8b ("Btrfs: fix invalid attempt to free reserved space on failure to cow range") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/inode.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 640e7dd26f6132..84c8c51e20478c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1550,8 +1550,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, clear_bits, page_ops); start += cur_alloc_size; - if (start >= end) - return ret; } /* @@ -1560,9 +1558,11 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * space_info's bytes_may_use counter, reserved in * btrfs_check_data_free_space(). */ - extent_clear_unlock_delalloc(inode, start, end, locked_page, - clear_bits | EXTENT_CLEAR_DATA_RESV, - page_ops); + if (start < end) { + clear_bits |= EXTENT_CLEAR_DATA_RESV; + extent_clear_unlock_delalloc(inode, start, end, locked_page, + clear_bits, page_ops); + } return ret; } From patchwork Mon Jul 24 13:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8981DC41513 for ; Mon, 24 Jul 2023 13:27:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231288AbjGXN1V (ORCPT ); Mon, 24 Jul 2023 09:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88C87E74 for ; Mon, 24 Jul 2023 06:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GlnKXO6nPoeWxB3BS+pZw+G1cJTsCwIsw4aw/brRaRw=; b=Km25EaLmbzkXx0g/NmhT0bJfqw nJD0esea0PjcjesuavyOH0iOtqpsp+EV1NtPeP+u7Dynia6g8PgE0j0dyAe9g0U1Vnsa/MKUfUHLM GbbTY9qoWssZ8oILJxH/Q+bTyfgsnvpfyiW3pAC3ch7Yi0kixCV8SDrF3SKdikVU+fuGW+toEkVMA XfXRoXOKQBsDx8pvMnmtY8EpW3iZ6/EavOy54Twpl9lm4Air6eR/MSZ3eIatrxxE/7lMv/+gFPx+e IsxwMvV6yGylWL0a8CjjWr0MDVnR/A97OmUh4PXgQqDuJ8RzJhY0wyQ5tdi7i9Dyr2eWUHXvRUg8N Om7LAqNg==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaY-004RLp-1r; Mon, 24 Jul 2023 13:27:02 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 4/9] btrfs: move the cow_fixup earlier in writepages handling Date: Mon, 24 Jul 2023 06:26:56 -0700 Message-Id: <20230724132701.816771-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs has a special fixup for pages that are marked dirty without having space reserved for them. But the place where is is run means it can't work for I/O that isn't kicked off inline from __extent_writepage, most notable compressed I/O and I/O to zoned file systems. Move the fixup earlier based on not findining any delalloc range in the I/O tree to cover this case as well instead of relying on the fairly obscure fallthrough behavior that calls __extent_write_page_io even when no delalloc space was found. Fixes: c8b978188c9a ("Btrfs: Add zlib compression support") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/extent_io.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 1cc46bbbd888cd..cc258bddd88eab 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1153,6 +1153,7 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode, u64 delalloc_start = page_start; u64 delalloc_end = page_end; u64 delalloc_to_write = 0; + bool found_delalloc = false; int ret = 0; while (delalloc_start < page_end) { @@ -1169,6 +1170,22 @@ static noinline_for_stack int writepage_delalloc(struct btrfs_inode *inode, return ret; delalloc_start = delalloc_end + 1; + found_delalloc = true; + } + + /* + * If we did not find any delalloc range in the io_tree, this must be + * the rare case of dirtying pages through get_user_pages without + * calling into ->page_mkwrite. + * While these are in the process of being fixed by switching to + * pin_user_pages, some are still around and need to be worked around + * by creating a delalloc reservation in a fixup worker, and waiting + * us to be called again with that reservation. + */ + if (!found_delalloc && btrfs_writepage_cow_fixup(page)) { + redirty_page_for_writepage(wbc, page); + unlock_page(page); + return 1; } /* @@ -1274,14 +1291,6 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, int ret = 0; int nr = 0; - ret = btrfs_writepage_cow_fixup(page); - if (ret) { - /* Fixup worker will requeue */ - redirty_page_for_writepage(bio_ctrl->wbc, page); - unlock_page(page); - return 1; - } - bio_ctrl->end_io_func = end_bio_extent_writepage; while (cur <= end) { u32 len = end - cur + 1; @@ -1421,9 +1430,6 @@ static int __extent_writepage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl goto done; ret = __extent_writepage_io(BTRFS_I(inode), page, bio_ctrl, i_size, &nr); - if (ret == 1) - return 0; - bio_ctrl->wbc->nr_to_write--; done: @@ -2176,8 +2182,6 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, ret = __extent_writepage_io(BTRFS_I(inode), page, &bio_ctrl, i_size, &nr); - if (ret == 1) - goto next_page; /* Make sure the mapping tag for page dirty gets cleared. */ if (nr == 0) { @@ -2193,7 +2197,6 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, btrfs_page_unlock_writer(fs_info, page, cur, cur_len); if (ret < 0) found_error = true; -next_page: put_page(page); cur = cur_end + 1; } From patchwork Mon Jul 24 13:26:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5EA4C001DF for ; Mon, 24 Jul 2023 13:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231236AbjGXN1U (ORCPT ); Mon, 24 Jul 2023 09:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87DA6E0 for ; Mon, 24 Jul 2023 06:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=zgDaWnU4/sWy2l2rpkYjh54sNjeBhBMa+7bmT5ho/kE=; b=PrWP72y0q9FDadlH8+GA4xaZB9 1b2cckXYxkLpG1GG1k1aWIV3X2g/FxUcFwHxPqCr4MO2NTBkn2vL0olvvIVLoiFfTWrGLQFd30Lcb HJHW22MZZw8Pmjjj4gC245nHLqUQjxB4KO4AaRqIjt4FtzhBUBKij5SBQwrhQ/iyR1Adjc7oYmlrX URnnnPoLWdTzG+kzoDiN6WOE49C3DpRFHgw54W4n4KIuiwOCeQbEYB6h5driHssLJpWwe2FPVkrnZ KYxOmxgk+lxbBrQjdTZomoPx3/JZDZLtY5KDLQPydVxbnLhKOThDTbes8wyGPAuqhx5tfatFjO2hM WLUzobcw==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaY-004RLt-2S; Mon, 24 Jul 2023 13:27:02 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 5/9] btrfs: fix handling of errors from __extent_writepage_io Date: Mon, 24 Jul 2023 06:26:57 -0700 Message-Id: <20230724132701.816771-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When __extent_writepage_io fails, the callers complete the ordered range for the entire page, including the range for which bios have been submitted already, leading to a double completion for those ranges. Fix this by pulling the error handling into __extent_writepage_io, and only apply it to the ranges not submitted yet. This also means that the remaining error handling in __extent_writepage never needs to complete the ordered extent, as there won't be one before writepage_delalloc is called, or when writepage_delalloc returns an error. Fixes: 61391d562229 ("Btrfs: fix hang on error (such as ENOSPC) when writing extent pages") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/extent_io.c | 78 +++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index cc258bddd88eab..85d7a219040d07 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1278,12 +1278,11 @@ static void find_next_dirty_byte(struct btrfs_fs_info *fs_info, */ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, struct page *page, - struct btrfs_bio_ctrl *bio_ctrl, - loff_t i_size, - int *nr_ret) + struct btrfs_bio_ctrl *bio_ctrl, loff_t i_size) { struct btrfs_fs_info *fs_info = inode->root->fs_info; - u64 cur = page_offset(page); + u64 start = page_offset(page); + u64 cur = start; u64 end = cur + PAGE_SIZE - 1; u64 extent_offset; u64 block_start; @@ -1325,7 +1324,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, em = btrfs_get_extent(inode, NULL, 0, cur, len); if (IS_ERR(em)) { ret = PTR_ERR_OR_ZERO(em); - goto out_error; + goto out; } extent_offset = cur - em->start; @@ -1372,15 +1371,21 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, } btrfs_page_assert_not_dirty(fs_info, page); - *nr_ret = nr; - return 0; + ret = 0; +out: + /* Make sure the mapping tag for page dirty gets cleared. */ + if (nr == 0) { + set_page_writeback(page); + end_page_writeback(page); + } + if (ret) { + u32 remaining = end + 1 - cur; -out_error: - /* - * If we finish without problem, we should not only clear page dirty, - * but also empty subpage dirty bits - */ - *nr_ret = nr; + btrfs_mark_ordered_io_finished(inode, page, cur, remaining, + false); + btrfs_page_clear_uptodate(fs_info, page, cur, remaining); + mapping_set_error(page->mapping, ret); + } return ret; } @@ -1399,7 +1404,6 @@ static int __extent_writepage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl struct inode *inode = page->mapping->host; const u64 page_start = page_offset(page); int ret; - int nr = 0; size_t pg_offset; loff_t i_size = i_size_read(inode); unsigned long end_index = i_size >> PAGE_SHIFT; @@ -1421,30 +1425,27 @@ static int __extent_writepage(struct page *page, struct btrfs_bio_ctrl *bio_ctrl ret = set_page_extent_mapped(page); if (ret < 0) - goto done; + goto error; ret = writepage_delalloc(BTRFS_I(inode), page, bio_ctrl->wbc); if (ret == 1) return 0; if (ret) - goto done; + goto error; - ret = __extent_writepage_io(BTRFS_I(inode), page, bio_ctrl, i_size, &nr); + ret = __extent_writepage_io(BTRFS_I(inode), page, bio_ctrl, i_size); + /* __extent_writepage_io cleans up by itself on error. */ bio_ctrl->wbc->nr_to_write--; - -done: - if (nr == 0) { - /* make sure the mapping tag for page dirty gets cleared */ - set_page_writeback(page); - end_page_writeback(page); - } - if (ret) { - btrfs_mark_ordered_io_finished(BTRFS_I(inode), page, page_start, - PAGE_SIZE, !ret); - btrfs_page_clear_uptodate(btrfs_sb(inode->i_sb), page, - page_start, PAGE_SIZE); - mapping_set_error(page->mapping, ret); - } + goto unlock_page; + +error: + /* Make sure the mapping tag for page dirty gets cleared. */ + set_page_writeback(page); + end_page_writeback(page); + btrfs_page_clear_uptodate(btrfs_sb(inode->i_sb), page, + page_start, PAGE_SIZE); + mapping_set_error(page->mapping, ret); +unlock_page: unlock_page(page); ASSERT(ret <= 0); return ret; @@ -2171,7 +2172,6 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, u64 cur_end = min(round_down(cur, PAGE_SIZE) + PAGE_SIZE - 1, end); u32 cur_len = cur_end + 1 - cur; struct page *page; - int nr = 0; page = find_get_page(mapping, cur >> PAGE_SHIFT); ASSERT(PageLocked(page)); @@ -2181,19 +2181,7 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, } ret = __extent_writepage_io(BTRFS_I(inode), page, &bio_ctrl, - i_size, &nr); - - /* Make sure the mapping tag for page dirty gets cleared. */ - if (nr == 0) { - set_page_writeback(page); - end_page_writeback(page); - } - if (ret) { - btrfs_mark_ordered_io_finished(BTRFS_I(inode), page, - cur, cur_len, !ret); - btrfs_page_clear_uptodate(fs_info, page, cur, cur_len); - mapping_set_error(page->mapping, ret); - } + i_size); btrfs_page_unlock_writer(fs_info, page, cur, cur_len); if (ret < 0) found_error = true; From patchwork Mon Jul 24 13:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A68CC04A94 for ; Mon, 24 Jul 2023 13:27:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231392AbjGXN1X (ORCPT ); Mon, 24 Jul 2023 09:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231179AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B36E76 for ; Mon, 24 Jul 2023 06:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=0mSf0Ipf+aqxpUxauetCwQTKn4svJk6yPriL/Z2IadY=; b=jAreCxouKNKveLD107eKSggOh1 b5Qr24+GxO0MyJPw38FAlG5diAywKj+A6moGNtxYNoN/1bth3LY4QV9M234war8AaDEqjxUxD4GQR OCX17+guIZxfwFcv5CPpUl2HbELpRabY5qvmhvzCTVx1o4ifr7au7EVIqJZ7MCSKnZfm8kTvz1hSZ 406llFg1mu5RanReTKZM43aEn2hblfz6CFCj2lMc9WMeDNitKxW3hefGVfnfMgO8jIeMurhgrLAec nYureFzmcGUh0fUr0NP1YJEi9ySYJhFcM5FP1pJYqnB39T92JBG+j4e+k0M/2PJMeXbYUJ6rTrK5E LIk4WBHg==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaZ-004RLy-01; Mon, 24 Jul 2023 13:27:03 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 6/9] btrfs: stop submitting I/O after an error in extent_write_locked_range Date: Mon, 24 Jul 2023 06:26:58 -0700 Message-Id: <20230724132701.816771-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As soon a __extent_writepage_io returns an error we know that the extent_map is corrupted or we're out of memory, and there is no point in continuing to submit I/O. Follow the behavior in extent_write_cache pages and stop submitting I/O, and instead just unlock all pages. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik Reviewed-by: Boris Burkov --- fs/btrfs/extent_io.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 85d7a219040d07..fada7a1931b130 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2151,7 +2151,6 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, u64 start, u64 end, struct writeback_control *wbc, bool pages_dirty) { - bool found_error = false; int ret = 0; struct address_space *mapping = inode->i_mapping; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); @@ -2180,16 +2179,29 @@ void extent_write_locked_range(struct inode *inode, struct page *locked_page, clear_page_dirty_for_io(page); } - ret = __extent_writepage_io(BTRFS_I(inode), page, &bio_ctrl, - i_size); + /* + * The entire page range that we were called on is locked and + * covered by an ordered_extent. Make sure we continue the + * loop after an initial writeback error to unwind these as well + * as clearing the dirty bit on the page by starting and ending + * writeback. + */ + if (ret) { + btrfs_mark_ordered_io_finished(BTRFS_I(inode), page, + cur, cur_len, false); + btrfs_page_clear_uptodate(fs_info, page, cur, cur_len); + set_page_writeback(page); + end_page_writeback(page); + } else { + ret = __extent_writepage_io(BTRFS_I(inode), page, + &bio_ctrl, i_size); + } btrfs_page_unlock_writer(fs_info, page, cur, cur_len); - if (ret < 0) - found_error = true; put_page(page); cur = cur_end + 1; } - submit_write_bio(&bio_ctrl, found_error ? ret : 0); + submit_write_bio(&bio_ctrl, ret); } int extent_writepages(struct address_space *mapping, From patchwork Mon Jul 24 13:26:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324798 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDB69C0015E for ; Mon, 24 Jul 2023 13:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbjGXN11 (ORCPT ); Mon, 24 Jul 2023 09:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbjGXN1T (ORCPT ); Mon, 24 Jul 2023 09:27:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02ACF188 for ; Mon, 24 Jul 2023 06:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=vr90lnDriW/R2EKnp/6tlr92hiSFQal6c/cwWDPPJmM=; b=es/B40Kb6rk6qCVMq0fKaNtmmi G+Y3KTOjgGmiBk9jjTKxslYs5+kZ77cNs6cIgQVqiS4n/2Hf+RO3tcJ95N4Ea/58gslLqg1857Atp sNqhLxXFIXqYZJuIhITIV3jseOeq8/EQWd5Tbc7679y62zlHWbOUqigTP7v0FvJzxKtYU5Tyg/8Y7 yYJOuIe3iQgqDpzmi31VEGbvQPeAwp0cmV3P4p0mlFFqvAaiGkDak4+b9fppXUlWkJomiNSakKDmm mEjENNz7bktZg/Rp+rGwofhwWkKyE6Llr3dlBe6qirwRvPyyf7WkWPRLdL9c/BMoB1ccpwU0oLLUW R0vEKb9g==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaZ-004RM9-0f; Mon, 24 Jul 2023 13:27:03 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 7/9] btrfs: fix a race in clearing the writeback bit for sub-page I/O Date: Mon, 24 Jul 2023 06:26:59 -0700 Message-Id: <20230724132701.816771-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org For sub-page I/O, a fast I/O completion can clear the page writeback bit in the I/O completion handler before subsequent bios were submitted. Use a trick from iomap and defer submission of bios until we're reached the end of the page to avoid this race. Fixes: c5ef5c6c733a ("btrfs: make __extent_writepage_io() only submit dirty range for subpage") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/extent_io.c | 54 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index fada7a1931b130..48a49c57daa6fd 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -105,7 +105,8 @@ struct btrfs_bio_ctrl { struct writeback_control *wbc; }; -static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) +static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl, + struct bio_list *bio_list) { struct btrfs_bio *bbio = bio_ctrl->bbio; @@ -118,6 +119,8 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) if (btrfs_op(&bbio->bio) == BTRFS_MAP_READ && bio_ctrl->compress_type != BTRFS_COMPRESS_NONE) btrfs_submit_compressed_read(bbio); + else if (bio_list) + bio_list_add(bio_list, &bbio->bio); else btrfs_submit_bio(bbio, 0); @@ -141,7 +144,22 @@ static void submit_write_bio(struct btrfs_bio_ctrl *bio_ctrl, int ret) /* The bio is owned by the end_io handler now */ bio_ctrl->bbio = NULL; } else { - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, NULL); + } +} + +static void btrfs_submit_pending_bios(struct bio_list *bio_list, int ret) +{ + struct bio *bio; + + if (ret) { + blk_status_t status = errno_to_blk_status(ret); + + while ((bio = bio_list_pop(bio_list))) + btrfs_bio_end_io(btrfs_bio(bio), status); + } else { + while ((bio = bio_list_pop(bio_list))) + btrfs_submit_bio(btrfs_bio(bio), 0); } } @@ -791,7 +809,8 @@ static void alloc_new_bio(struct btrfs_inode *inode, */ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, u64 disk_bytenr, struct page *page, - size_t size, unsigned long pg_offset) + size_t size, unsigned long pg_offset, + struct bio_list *bio_list) { struct btrfs_inode *inode = BTRFS_I(page->mapping->host); @@ -800,7 +819,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, if (bio_ctrl->bbio && !btrfs_bio_is_contig(bio_ctrl, page, disk_bytenr, pg_offset)) - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, bio_list); do { u32 len = size; @@ -820,7 +839,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, if (bio_add_page(&bio_ctrl->bbio->bio, page, len, pg_offset) != len) { /* bio full: move on to a new one */ - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, bio_list); continue; } @@ -834,7 +853,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl, /* Ordered extent boundary: move on to a new bio. */ if (bio_ctrl->len_to_oe_boundary == 0) - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, bio_list); } while (size); } @@ -1082,14 +1101,14 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, } if (bio_ctrl->compress_type != compress_type) { - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, NULL); bio_ctrl->compress_type = compress_type; } if (force_bio_submit) - submit_one_bio(bio_ctrl); + submit_one_bio(bio_ctrl, NULL); submit_extent_page(bio_ctrl, disk_bytenr, page, iosize, - pg_offset); + pg_offset, NULL); cur = cur + iosize; pg_offset += iosize; } @@ -1113,7 +1132,7 @@ int btrfs_read_folio(struct file *file, struct folio *folio) * If btrfs_do_readpage() failed we will want to submit the assembled * bio to do the cleanup. */ - submit_one_bio(&bio_ctrl); + submit_one_bio(&bio_ctrl, NULL); return ret; } @@ -1287,6 +1306,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, u64 extent_offset; u64 block_start; struct extent_map *em; + struct bio_list bio_list = BIO_EMPTY_LIST; int ret = 0; int nr = 0; @@ -1365,7 +1385,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, btrfs_page_clear_dirty(fs_info, page, cur, iosize); submit_extent_page(bio_ctrl, disk_bytenr, page, iosize, - cur - page_offset(page)); + cur - page_offset(page), &bio_list); cur += iosize; nr++; } @@ -1378,6 +1398,16 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode, set_page_writeback(page); end_page_writeback(page); } + + /* + * Submit all bios we queued up for this page. + * + * The bios are not submitted directly after building them as otherwise + * a very fast I/O completion on an earlier bio could clear the page + * writeback bit before the subsequent bios are even submitted. + */ + btrfs_submit_pending_bios(&bio_list, ret); + if (ret) { u32 remaining = end + 1 - cur; @@ -2243,7 +2273,7 @@ void extent_readahead(struct readahead_control *rac) if (em_cached) free_extent_map(em_cached); - submit_one_bio(&bio_ctrl); + submit_one_bio(&bio_ctrl, NULL); } /* From patchwork Mon Jul 24 13:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D6B7C001DE for ; Mon, 24 Jul 2023 13:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231371AbjGXN1Z (ORCPT ); Mon, 24 Jul 2023 09:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbjGXN1T (ORCPT ); Mon, 24 Jul 2023 09:27:19 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CAB8FE for ; Mon, 24 Jul 2023 06:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GwjONCJn3D5Zd2JMFVM7WYrxTZJ2bfVUbOKNfPUMpzE=; b=bapi2nk5WhTpnfadRxtDOp6jWd W3RscPHiS8myVXKexb4EqsEIHUYJ4jkaxbk1ei5zeJpHF9gFEsaCbrPcnumTPqbmTIJ6U218XAw1q fnstPXpAbmFco+tiLULyIOcI1IfE4NY23n4zFY0B7WwOrIfK//BF3TPKejjNQWlpZNZl3SSvMtl2u wR9RQjw9zzk5nmcx0WOSGvUWEaxZr1ZENgF9MvUIZSGyj1YLirhvgNjGAZrVtgHbsvh9lmWMamj8f WqL41K9yZZhFGkoQuhY1W0rsTS3w71f+XPi71kHcoOfo9psSC42JEHO6C6Rgyhy93qSDbTndbouv/ XaQTwqVA==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaZ-004RMJ-1H; Mon, 24 Jul 2023 13:27:03 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 8/9] btrfs: remove the call to btrfs_mark_ordered_io_finished in btrfs_writepage_fixup_worker Date: Mon, 24 Jul 2023 06:27:00 -0700 Message-Id: <20230724132701.816771-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If btrfs_writepage_fixup_worker is called for a range that is covered by and ordered_extent, but which doesn't have the PageOrdered bit set, that means the ordered_extent is either for a pending direct I/O, or for a buffered writeback in the final stages of I/O completion. In either case it is now owned by the calling context, and should never be completed by it. Fixes: 87826df0ec36 ("btrfs: delalloc for page dirtied out-of-band in fixup worker") Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 84c8c51e20478c..0d33bff5ca176f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2798,8 +2798,6 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) * to reflect the errors and clean the page. */ mapping_set_error(page->mapping, ret); - btrfs_mark_ordered_io_finished(inode, page, page_start, - PAGE_SIZE, !ret); btrfs_page_clear_uptodate(fs_info, page, page_start, PAGE_SIZE); clear_page_dirty_for_io(page); } From patchwork Mon Jul 24 13:27:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13324795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F2C3C0015E for ; Mon, 24 Jul 2023 13:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbjGXN1Y (ORCPT ); Mon, 24 Jul 2023 09:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjGXN1S (ORCPT ); Mon, 24 Jul 2023 09:27:18 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01AFF106 for ; Mon, 24 Jul 2023 06:27:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=3nNvfzNF93rFxsmZklRHmKc5CAnVSqAcDlcgaG/Rczo=; b=xpd0Fj5ogWsRLBCjiHSGZwzFMi bw+CmyPVAtTeWdVOsPOLTaUNhQVVFIAmMiYMgs9HV00u2055lj0ujEkidsiF4Kq33sBhgP2igFens 8AvmRD2toTvB7YOc1D08trllV2OxLGU19l5IzgVkCgeI9wrvn3xJoO8hpDXW9zRAr7+O2imKsUoaE HaZm4LkZCV/RF/TZZPItBdVdyMb7PNSOVRfn9ERfqFmWmkL2+ygNLz51cx1My4lFutFOlwMYv0ZeY fZ1SgXJx5x8DC+dGjTRImdahAEPJEJUQZaMHP1+un9cdhhQC3e/6ElDrwtKambpLsIqKXye4AQWGc zGk3Uc9w==; Received: from 67-207-104-238.static.wiline.com ([67.207.104.238] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qNvaZ-004RMO-1r; Mon, 24 Jul 2023 13:27:03 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 9/9] btrfs: lift the call to mapping_set_error out of cow_file_range Date: Mon, 24 Jul 2023 06:27:01 -0700 Message-Id: <20230724132701.816771-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724132701.816771-1-hch@lst.de> References: <20230724132701.816771-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of calling mapping_set_error in cow_file_range for the !locked_page case, make the submit_uncompressed_range call mapping_set_error also for the !locked_page as that is the only caller that might pass a NULL locked_page. Signed-off-by: Christoph Hellwig Reviewed-by: Josef Bacik --- fs/btrfs/inode.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0d33bff5ca176f..b04eacc0fed44e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1077,6 +1077,7 @@ static void submit_uncompressed_range(struct btrfs_inode *inode, wbc_detach_inode(&wbc); if (ret < 0) { btrfs_cleanup_ordered_extents(inode, locked_page, start, end - start + 1); + mapping_set_error(inode->vfs_inode.i_mapping, ret); if (locked_page) { const u64 page_start = page_offset(locked_page); @@ -1088,7 +1089,6 @@ static void submit_uncompressed_range(struct btrfs_inode *inode, btrfs_page_clear_uptodate(inode->root->fs_info, locked_page, page_start, PAGE_SIZE); - mapping_set_error(locked_page->mapping, ret); unlock_page(locked_page); } } @@ -1526,12 +1526,9 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * However, in case of @keep_locked, we still need to unlock the pages * (except @locked_page) to ensure all the pages are unlocked. */ - if (keep_locked && orig_start < start) { - if (!locked_page) - mapping_set_error(inode->vfs_inode.i_mapping, ret); + if (keep_locked && orig_start < start) extent_clear_unlock_delalloc(inode, orig_start, start - 1, locked_page, 0, page_ops); - } /* * For the range (2). If we reserved an extent for our delalloc range