From patchwork Thu Jul 13 13:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312158 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 E7B2DC001E0 for ; Thu, 13 Jul 2023 13:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235178AbjGMNGD (ORCPT ); Thu, 13 Jul 2023 09:06:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235177AbjGMNFd (ORCPT ); Thu, 13 Jul 2023 09:05:33 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7901F35B6; Thu, 13 Jul 2023 06:04:48 -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=NR1Dsao3xHvpRuOa6WrdSfFOOH1XFxhO6DoGpCB/hxQ=; b=uw1V40UDPYkBQTmHG0WIrooo3q +OPM9EiFADzduSwVJMeTSCoZCDOmRvg+LMCiBBAkblgjdS/Q/MsMLVZ+CrLiAMwqb9hGO+HlR0ZjX 6A1TR/w+pm87fX0fuZ9kXEu4AhJA+RwAWwqycWqOSYxkXz+GrSsdQhfIIYiR0Ymiv+4H7c7CjbCBq UysPU3ArFYUrk3wCJ5yHVtd1WJEFQ4HGObCF8YWcO+zY82NWQ+atx3xbnjc+H9Y0odS6oFih1kuzj pkSxfX4/kgxmlfv3+zsQporSbBiKpov9BiuDPL5S/JWcMm+nngeDZiYgNUhT6b8iD0pn+vIxvA/u6 t4Bq2OJw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJvzp-003LQh-1s; Thu, 13 Jul 2023 13:04:37 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/9] btrfs: don't stop integrity writeback too early Date: Thu, 13 Jul 2023 15:04:23 +0200 Message-Id: <20230713130431.4798-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 f2b9c72ea0c104..cb8c5d06fe2304 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 Thu Jul 13 13:04:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312159 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 63B8CC001DD for ; Thu, 13 Jul 2023 13:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235208AbjGMNGO (ORCPT ); Thu, 13 Jul 2023 09:06:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234133AbjGMNFv (ORCPT ); Thu, 13 Jul 2023 09:05:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3513A8D; Thu, 13 Jul 2023 06:04:55 -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=jJH67TsCbAy/M81eao+hE7f2jfjbJTpCc7Wu7+KlLQ4=; b=pJznxCPQ1Kxg1MFAnXOcYYXtPB vGBFi2/fjZl+fC+RbBF/bRL2IPQkjh8uiJ/gH17r+y8vmHv9g4NH0OH0EJ8f5SINzoiY00obZdbT9 9nPcZB91Ef7iNXXwMr9jnTcjg7bzjLBS4kJ6s8EY+n0quGAh7TzPsMVh/hOqEjqidIiIk3wgaZKMC fralsoSp4ZgvNGyk06hjZOquZoTGcWVcDhG9tW/g9oicr1aO2ORZT0Re/+jkVJ6hM7v5eOKrcPntj goDolu4nQTwf0tbryH5xd+oKQ+TLQVB/FBVw9xaeFn2nAXuJEZwrcOBwJ1ocVs6KlCnYUYPVZi1R8 JshwB0oQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJvzr-003LTW-34; Thu, 13 Jul 2023 13:04:40 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/9] btrfs: don't wait for writeback on clean pages in extent_write_cache_pages Date: Thu, 13 Jul 2023 15:04:24 +0200 Message-Id: <20230713130431.4798-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 cb8c5d06fe2304..2ae3badaf36df6 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 Thu Jul 13 13:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312160 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 69537C0015E for ; Thu, 13 Jul 2023 13:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235191AbjGMNGO (ORCPT ); Thu, 13 Jul 2023 09:06:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234372AbjGMNFw (ORCPT ); Thu, 13 Jul 2023 09:05:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 617263A8E; Thu, 13 Jul 2023 06:04:55 -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=ZOkQVTJJYdXe/u2csdGqahKYBWo+lvzD5ymfs7yQGIc=; b=3bUjfMwEEHlLAcqaJRpRhI2RUn ScmA+KKqf2RUCTbmcrRDpO7nltbKGTKMD+CQZisIlPz+xqgajGzilCbQQ30tOdK9D7Ll9oRcEJf7c V+imnDA8VIKtY43fHmPz3HaABn19EzokCx0/1BpgHS7Gh9SQKd+zN51dkN46wBZOavoCWMkjZAuNA J1EphwDGup6OozQjRojShLJ9WYaZiq/NAqgKEiJMmA7uek9fFO2cdTyw8TBP9HDgaCvdmUq4aLVra e5Fv1Rut/ZDZzUt41aUuO23+eFh5PHyG2sMaat1BeAyx+4HhJHI2PgLGv07idXlw2zsH+d3HSPwab LvYBPoDQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJvzu-003LVX-1B; Thu, 13 Jul 2023 13:04:42 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 3/9] btrfs: fix an error handling corner case in cow_file_range Date: Thu, 13 Jul 2023 15:04:25 +0200 Message-Id: <20230713130431.4798-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 ae1bda58004b26..20bee7f8dae01c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1548,8 +1548,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, clear_bits, page_ops); start += cur_alloc_size; - if (start >= end) - return ret; } /* @@ -1558,9 +1556,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 Thu Jul 13 13:04:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312161 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 D6A7CC00528 for ; Thu, 13 Jul 2023 13:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235214AbjGMNGP (ORCPT ); Thu, 13 Jul 2023 09:06:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234454AbjGMNFx (ORCPT ); Thu, 13 Jul 2023 09:05:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84D512D69; Thu, 13 Jul 2023 06:04:55 -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=KiumRusWz96B87ESESC631Rxm43rrn0KaIEpbGiF1MQ=; b=faiY4qzc/kzVE4hBHuyUM2oBxc GrhfMGIuBQ4HitF4AdK32QBCQSUXlXKlGtIZHdPA0Gu4Lyx+dZgISpKWV6i4JYe/SLNkgXcTSVM3Y AHsoJMQuahqG8SFnR3C5J7kJPGgr/glJ/M8SCqosauo/qVg73AKaScevAEkdDwdeBBRZpOl7464yP nGo1b6RpRmh7GJd6LH3DkSyu/TnBFAV4eaqQGnqKAtsmCESu6XBoPdyt5ms6bRoanfLJJjjsrDkTk RBAQCX8BuSRGbN5VkGcfDyca7CC2AOxP6MLQ/1DEOd5Ii5qszz5ggEQqn7SfdSYXk4JTQyxcwugpq ftT59pjw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJvzw-003LY2-28; Thu, 13 Jul 2023 13:04:45 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 4/9] btrfs: move the cow_fixup earlier in writepages handling Date: Thu, 13 Jul 2023 15:04:26 +0200 Message-Id: <20230713130431.4798-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 2ae3badaf36df6..d8185582b9f4b0 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 Thu Jul 13 13:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312162 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 C741AC04A94 for ; Thu, 13 Jul 2023 13:06:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235164AbjGMNGR (ORCPT ); Thu, 13 Jul 2023 09:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235113AbjGMNFx (ORCPT ); Thu, 13 Jul 2023 09:05:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF6E3A91; Thu, 13 Jul 2023 06:04:56 -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=F/VojWwpMX68AyePR5SCL18Oq3RJWNWzyJlzVpGjdsA=; b=p73ZwbZsGYOfpfT+wt+Plw806e KZmv9DhYnzt2Dau4Ipy1peLCSDGT05pTi3Gd3PR8YcEqumwoSYmgXouPitKWVvjEmAbIUeaeNnbwf OZDldiBIE7QHO373+Aj13s3FaXWLuQVuya8Tsz7AzSg+0aWfDnIfaC4h/GBT2zddQo2M4glzrXLiT z1JLQ0ZSIJOgz6GzM6MyKDk6IJ5sAg2CCwdqaiLowHEYqBvmYNOTduif0ayoc1blbGYHww5K+hgd8 /53+B3zeN0mMwSfRyXzb0f+4aRairi4/1L4tGWUL4ZuNI4TtmR1l7s4iDJzTwKr1L/ZC8734debvz 0qyrVIZA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJvzy-003LZH-30; Thu, 13 Jul 2023 13:04:47 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 5/9] btrfs: fix handling of errors from __extent_writepage_io Date: Thu, 13 Jul 2023 15:04:27 +0200 Message-Id: <20230713130431.4798-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 d8185582b9f4b0..0c5e540eb2ebea 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 Thu Jul 13 13:04:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312163 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 C590CC001DD for ; Thu, 13 Jul 2023 13:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235217AbjGMNGT (ORCPT ); Thu, 13 Jul 2023 09:06:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234989AbjGMNFy (ORCPT ); Thu, 13 Jul 2023 09:05:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF23E3A97; Thu, 13 Jul 2023 06:04:59 -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=dIOSe9C7Eta5xFws/YXktNlrD1JACTeSAMCGDk/3k7w=; b=XhbZXlZtAes91JgrFyQ65CY1zn orIxGitW6f/Khv5OmuAUjPHr6FHVJfUNzC3Af0rVFRG0sSkk0hst7me3LT7cqVn5DJpRyjTNxqAO3 1icKxPRWBWyqsTwpSYa8NMzmisCYyzFNMVH3Poou2aXhXnxfVJhBgmfsUPDZklOO5+W3uUDGHkICB N+sef8+FzMgGgm/G4+2Kn+2GpyjfjRT6azXoTKDRMOKdAnj/dXoPtRqpte7PYtYsyzOwZel72XKSY ZXA8i6fKhS/CjVcew/gpL60gmq1FrMKWXwa6nhzn6Jms9NzIv5ouq/+e5duiYYT+A9PBn2OZL1i/Q odqTvMFw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJw01-003Lb6-0x; Thu, 13 Jul 2023 13:04:49 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 6/9] btrfs: stop submitting I/O after an error in extent_write_locked_range Date: Thu, 13 Jul 2023 15:04:28 +0200 Message-Id: <20230713130431.4798-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 0c5e540eb2ebea..035f49de024887 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 Thu Jul 13 13:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312164 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 8A38AC0015E for ; Thu, 13 Jul 2023 13:06:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235198AbjGMNGd (ORCPT ); Thu, 13 Jul 2023 09:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235127AbjGMNF6 (ORCPT ); Thu, 13 Jul 2023 09:05:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 379F53AA5; Thu, 13 Jul 2023 06:05: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=HYE9SE2+4Y8hVncAzaPtb5LiXtR8HZODCvq/2+j8w/o=; b=3R+CL5VuedWM9EYCohR4wbe/rs IqLeoy7Y0Qmlb8C/2j/yn4oITqbqTV09wzySSkuCJglheoQtMiMDjkA02ymsMfUTLqjuSXeLRJhdu 0pGlDnVNCtbNdK/G7z5kzqlOOzbhINzWve1L37n8uNL+T2o3mdx+n8tzbORP2kn1Kte6WIcUa4y5g sepYHU547MddRTt73BEmaCuWvYi8ozxMwR/yDavZ30xN9IeVIDt9e3Y1XgTKlFKSoOqSAV2jmGfC8 +SPmhZXkE9tblDHOtrC4/MSRAVk5YIop+7rhOnr0OrDynvwwk3q1BglZeFihb/KdvRsyOAorSSjB3 VgKD1xmw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJw03-003LdE-22; Thu, 13 Jul 2023 13:04:51 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 7/9] btrfs: fix a race in clearing the writeback bit for sub-page I/O Date: Thu, 13 Jul 2023 15:04:29 +0200 Message-Id: <20230713130431.4798-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- 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 035f49de024887..994d38f59cbed4 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 Thu Jul 13 13:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312165 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 5DA99C0015E for ; Thu, 13 Jul 2023 13:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234631AbjGMNGk (ORCPT ); Thu, 13 Jul 2023 09:06:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235170AbjGMNGB (ORCPT ); Thu, 13 Jul 2023 09:06:01 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB4D32729; Thu, 13 Jul 2023 06:05:09 -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=DIN7jTQKiX0fYn4tpLMYTRoJ4jczECHpji7D+MGfhMg=; b=1KrgdpvryGijkjmqsauXv1e/ZZ O8NLuXCmD1qpSczsF8QHb3i3MA0ahdWKLQJVnqEK83qSoMPJi37n4r65qTfeS/L+478eAWSb5zoNr YmaImsg2f5OAHPd0NtQcRyt/9IcnR/dE45qbFdVd00n+TdMFxFpqQf2iU41fmp8T6XIDE5eMuB59C O1OkwuP/GTYC8oBW8WyiDpCXAphlaGN9GLlasEo/JPHcodnMZoXx/YChJvSrqv2idQiwoSHzB759d yhMInMuD16YbUHP+5ZIsFdXGHIGKuNShlh1+QfgPbKvNNNaalXlwAFSd80vVh9cgJM0nr8yYYd2Ql NHEicvFw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJw06-003Lfz-0F; Thu, 13 Jul 2023 13:04:54 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 8/9] btrfs: remove the call to btrfs_mark_ordered_io_finished in btrfs_writepage_fixup_worker Date: Thu, 13 Jul 2023 15:04:30 +0200 Message-Id: <20230713130431.4798-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- fs/btrfs/inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 20bee7f8dae01c..46d04803d76f13 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2796,8 +2796,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 Thu Jul 13 13:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13312166 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 C79FCC001DF for ; Thu, 13 Jul 2023 13:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235206AbjGMNGm (ORCPT ); Thu, 13 Jul 2023 09:06:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235203AbjGMNGC (ORCPT ); Thu, 13 Jul 2023 09:06:02 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26E6B3AB6; Thu, 13 Jul 2023 06:05:11 -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=jmJ5pZs1+tC3MnsnYQCRaWDiepQvfSm8uolE2IagJ2s=; b=n7nN05pFq8qPRJMRugNvgnjDsv UwBetNkAsTPjQPXKxtI1YM0cDu1WY8KrM2pN2/Uz8RJZTUl3d2gGS+UfAQtoOWTMGMKQcXX+Pqoll 0sQebfuYxXM+7tAkN0qK8syfMzzLIhTBwxMxyHQSlxHYidZBio1ZO/6hrzfvk9SrVRJyQys8kXw54 Io3kp2U8wxKjUy7Knl2wPlpjHL3IfCryZu3CF9XBkdV2AIz56bhh/p0pkvBLJqJP3uLjRc4X+72Cp a6C1+JMXJOA8t2BcJzdajDG4wvVYHSeEVtw705z3rzpUoVPnTvZEihLof4cn0smvZSECGtPa0GhVM 9T9gKNRA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJw08-003Lih-18; Thu, 13 Jul 2023 13:04:56 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 9/9] btrfs: lift the call to mapping_set_error out of cow_file_range Date: Thu, 13 Jul 2023 15:04:31 +0200 Message-Id: <20230713130431.4798-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230713130431.4798-1-hch@lst.de> References: <20230713130431.4798-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 --- fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 46d04803d76f13..9305a100b5f809 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1074,6 +1074,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); @@ -1085,7 +1086,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); } } @@ -1525,8 +1525,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * pages (except @locked_page) to ensure all the pages are unlocked. */ if ((flags & CFR_KEEP_LOCKED) && orig_start < start) { - if (!locked_page) - mapping_set_error(inode->vfs_inode.i_mapping, ret); extent_clear_unlock_delalloc(inode, orig_start, start - 1, locked_page, 0, page_ops); }