From patchwork Sun Jun 13 13:39:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 495B6C48BCF for ; Sun, 13 Jun 2021 13:40:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C19A61285 for ; Sun, 13 Jun 2021 13:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbhFMNmQ (ORCPT ); Sun, 13 Jun 2021 09:42:16 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34492 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231738AbhFMNmP (ORCPT ); Sun, 13 Jun 2021 09:42:15 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DF54F21972; Sun, 13 Jun 2021 13:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kF9mUTKWAgird3A2WvETQdl4IQRcEa9mc2Hk3dPUiUc=; b=hs9/Iy46YvQMyuJcZnETN8CVdq1P4YXl1d6KRScezKajdV2+dIYBDs2Jpe4VRL2xp3orCr 56Lu+DC0tr2hFasR7KDF9qgyyMaCfRyfFoSvbz9LxujfcPnKiMcjOoXE4iwhEN98ZyAaeG +bUV8d0drvCN/3bPnzCadnKRkI3C1ew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kF9mUTKWAgird3A2WvETQdl4IQRcEa9mc2Hk3dPUiUc=; b=AC/6Co1bKEFys5YjlOORGZfXrF02CR8PZTJIT/yxf7Ju2cUeAvMGNNMNBVTONjhokdDOqt O/5LvDuOlKfy9mDQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 8827D118DD; Sun, 13 Jun 2021 13:40:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kF9mUTKWAgird3A2WvETQdl4IQRcEa9mc2Hk3dPUiUc=; b=hs9/Iy46YvQMyuJcZnETN8CVdq1P4YXl1d6KRScezKajdV2+dIYBDs2Jpe4VRL2xp3orCr 56Lu+DC0tr2hFasR7KDF9qgyyMaCfRyfFoSvbz9LxujfcPnKiMcjOoXE4iwhEN98ZyAaeG +bUV8d0drvCN/3bPnzCadnKRkI3C1ew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591612; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kF9mUTKWAgird3A2WvETQdl4IQRcEa9mc2Hk3dPUiUc=; b=AC/6Co1bKEFys5YjlOORGZfXrF02CR8PZTJIT/yxf7Ju2cUeAvMGNNMNBVTONjhokdDOqt O/5LvDuOlKfy9mDQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id omzkGLwKxmAtJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:12 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 01/31] iomap: Check if blocksize == PAGE_SIZE in to_iomap_page() Date: Sun, 13 Jun 2021 08:39:29 -0500 Message-Id: <79781ca99470475ff33382e67571eeb914edac63.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues btrfs requires page->private set to get a callback to releasepage(). So, for normal circumstances of blocksize==PAGE_SIZE, btrfs will have page->private set to 1. In order to avoid a crash, check for the blocksize==PAGE_SIZE in to_iomap_page(). --- fs/iomap/buffered-io.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 9023717c5188..d30683734d01 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -41,9 +41,11 @@ static inline struct iomap_page *to_iomap_page(struct page *page) */ VM_BUG_ON_PGFLAGS(PageTail(page), page); - if (page_has_private(page)) - return (struct iomap_page *)page_private(page); - return NULL; + if (i_blocksize(page->mapping->host) == PAGE_SIZE) + return NULL; + if (!page_has_private(page)) + return NULL; + return (struct iomap_page *)page_private(page); } static struct bio_set iomap_ioend_bioset; @@ -163,7 +165,7 @@ iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len) if (PageError(page)) return; - if (page_has_private(page)) + if (i_blocksize(page->mapping->host) != PAGE_SIZE) iomap_iop_set_range_uptodate(page, off, len); else SetPageUptodate(page); From patchwork Sun Jun 13 13:39:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53E43C49360 for ; Sun, 13 Jun 2021 13:40:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 321C961284 for ; Sun, 13 Jun 2021 13:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231793AbhFMNmR (ORCPT ); Sun, 13 Jun 2021 09:42:17 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34502 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmQ (ORCPT ); Sun, 13 Jun 2021 09:42:16 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F3E2621973; Sun, 13 Jun 2021 13:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591614; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSEaLkVpkKswEMClQZajPDa8Ztrho6+KzaxTdXhJHkc=; b=12erQFm2dI14QpGCBFVVW6Q+OiVgDww8lx7D/HMzcjH52ob/mO9ds+ywEBVKLadZ4I+rb+ VHL+fKIlvpwnODaApNzwAq3nudLxqf9dYQeVH59JSrdvDoY3xFNDqNgxJBtCzE75MZQSgC z6oYUTswLodupEtQ7sNq0B6QEiaFUu8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591614; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSEaLkVpkKswEMClQZajPDa8Ztrho6+KzaxTdXhJHkc=; b=SR52TwsqXC1ucvVp4SpcvGamM7kbRp1xM69nQOuMmXgJ7VugjQY3Dp1jKDgKpLFVDSwJQu JUnH9iOFzocjboDw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 9D421118DD; Sun, 13 Jun 2021 13:40:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591614; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSEaLkVpkKswEMClQZajPDa8Ztrho6+KzaxTdXhJHkc=; b=12erQFm2dI14QpGCBFVVW6Q+OiVgDww8lx7D/HMzcjH52ob/mO9ds+ywEBVKLadZ4I+rb+ VHL+fKIlvpwnODaApNzwAq3nudLxqf9dYQeVH59JSrdvDoY3xFNDqNgxJBtCzE75MZQSgC z6oYUTswLodupEtQ7sNq0B6QEiaFUu8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591614; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mSEaLkVpkKswEMClQZajPDa8Ztrho6+KzaxTdXhJHkc=; b=SR52TwsqXC1ucvVp4SpcvGamM7kbRp1xM69nQOuMmXgJ7VugjQY3Dp1jKDgKpLFVDSwJQu JUnH9iOFzocjboDw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 0XYyGr4KxmAzJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:14 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 02/31] iomap: Add submit_io to writepage_ops Date: Sun, 13 Jun 2021 08:39:30 -0500 Message-Id: <999c273a4d4fd73ecd9fe80a20e7008eb1124b35.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Filesystems such as btrfs need to perform pre and post bio operations such as csum calculations, device mapping etc. Add a submit_io() function to writepage_ops so filesystems can control how the bio is submitted. Signed-off-by: Goldwyn Rodrigues --- fs/iomap/buffered-io.c | 11 ++++++++++- include/linux/iomap.h | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index d30683734d01..b6fd6d6118a6 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1209,7 +1209,11 @@ iomap_submit_ioend(struct iomap_writepage_ctx *wpc, struct iomap_ioend *ioend, return error; } - submit_bio(ioend->io_bio); + if (wpc->ops->submit_io) + wpc->ops->submit_io(ioend->io_inode, ioend->io_bio); + else + submit_bio(ioend->io_bio); + return 0; } @@ -1305,8 +1309,13 @@ iomap_add_to_ioend(struct inode *inode, loff_t offset, struct page *page, if (!merged) { if (bio_full(wpc->ioend->io_bio, len)) { + struct bio *bio = wpc->ioend->io_bio; wpc->ioend->io_bio = iomap_chain_bio(wpc->ioend->io_bio); + if (wpc->ops->submit_io) + wpc->ops->submit_io(inode, bio); + else + submit_bio(bio); } bio_add_page(wpc->ioend->io_bio, page, len, poff); } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index c87d0cb0de6d..689d799b1915 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -223,6 +223,12 @@ struct iomap_writeback_ops { * we failed to submit any I/O. */ void (*discard_page)(struct page *page, loff_t fileoff); + + /* + * Optional, allows the filesystem to perform a custom submission of + * bio, such as csum calculations or multi-device bio split + */ + void (*submit_io)(struct inode *inode, struct bio *bio); }; struct iomap_writepage_ctx { From patchwork Sun Jun 13 13:39:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47123C48BCF for ; Sun, 13 Jun 2021 13:40:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A76E6128B for ; Sun, 13 Jun 2021 13:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbhFMNmU (ORCPT ); Sun, 13 Jun 2021 09:42:20 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34508 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmT (ORCPT ); Sun, 13 Jun 2021 09:42:19 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4398921972; Sun, 13 Jun 2021 13:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591617; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m9iQJIqAvP3oBb21ZwYbBOg6Zz8z0z73yHx102nYx7c=; b=jLcJcjEEZoo9WE6/hGBR4tCmvRVXFEiSoUrzlthLxWSKjLKQ9D8jVyNGmQMGLVl24gVj/K liUB+Z9G9/Bc4lmbyNL0EIwMfTe69tGfBMw3J1AOImlGf+OhtZYmHMmLwHbeT0WUt7URpl fNn+vr+2fz0wp3rZdOQeTyzuwX1faNg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591617; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m9iQJIqAvP3oBb21ZwYbBOg6Zz8z0z73yHx102nYx7c=; b=3KS8/47n58RZNbPKnwzwQXWKjv8UYga9mSknb0vl3LUO9WAxXo2NB3zRN5IRxNfv4iunew 5O69l/qrtFwxaMBQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id CEB1D118DD; Sun, 13 Jun 2021 13:40:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591617; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m9iQJIqAvP3oBb21ZwYbBOg6Zz8z0z73yHx102nYx7c=; b=jLcJcjEEZoo9WE6/hGBR4tCmvRVXFEiSoUrzlthLxWSKjLKQ9D8jVyNGmQMGLVl24gVj/K liUB+Z9G9/Bc4lmbyNL0EIwMfTe69tGfBMw3J1AOImlGf+OhtZYmHMmLwHbeT0WUt7URpl fNn+vr+2fz0wp3rZdOQeTyzuwX1faNg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591617; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m9iQJIqAvP3oBb21ZwYbBOg6Zz8z0z73yHx102nYx7c=; b=3KS8/47n58RZNbPKnwzwQXWKjv8UYga9mSknb0vl3LUO9WAxXo2NB3zRN5IRxNfv4iunew 5O69l/qrtFwxaMBQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id a+pdKsAKxmA3JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:16 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 03/31] iomap: Export iomap_writepage_end_bio() Date: Sun, 13 Jun 2021 08:39:31 -0500 Message-Id: <5c4a9997996d39e80e647278a546c28e0ce124ed.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues BTRFS marks ordered extents as uptodate clearing bits such as delalloc after the bio is deemed complete. After marking the extents, btrfs needs to call iomap_writepage_end_bio() to perform housekeeping on the pages: end of writeback. Signed-off-by: Goldwyn Rodrigues --- fs/iomap/buffered-io.c | 3 ++- include/linux/iomap.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index b6fd6d6118a6..f88f058cdefb 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1173,12 +1173,13 @@ iomap_sort_ioends(struct list_head *ioend_list) } EXPORT_SYMBOL_GPL(iomap_sort_ioends); -static void iomap_writepage_end_bio(struct bio *bio) +void iomap_writepage_end_bio(struct bio *bio) { struct iomap_ioend *ioend = bio->bi_private; iomap_finish_ioend(ioend, blk_status_to_errno(bio->bi_status)); } +EXPORT_SYMBOL_GPL(iomap_writepage_end_bio); /* * Submit the final bio for an ioend. diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 689d799b1915..8944711aa92e 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -238,6 +238,7 @@ struct iomap_writepage_ctx { }; void iomap_finish_ioends(struct iomap_ioend *ioend, int error); +void iomap_writepage_end_bio(struct bio *bio); void iomap_ioend_try_merge(struct iomap_ioend *ioend, struct list_head *more_ioends); void iomap_sort_ioends(struct list_head *ioend_list); From patchwork Sun Jun 13 13:39:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD40CC48BE8 for ; Sun, 13 Jun 2021 13:40:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADE8E61284 for ; Sun, 13 Jun 2021 13:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbhFMNmV (ORCPT ); Sun, 13 Jun 2021 09:42:21 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55388 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmV (ORCPT ); Sun, 13 Jun 2021 09:42:21 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 60E481FD2D; Sun, 13 Jun 2021 13:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0SwFOdjmv+BwHEcQT6xR2AV/iXoKaxQAfg5HNaGaPc=; b=FC1Qck7+6PgQ6kxHSOmLHuaZuI1MXYDL2np5FGslDZ+sBkAGdB9s/gzc1bLymgkKQ7BXgl dRmwgK9glMtl1IHTP9AM/4xt9etkuVJcLXwPPwjLSfQkRrHH89lcxZCAqHpniuDKk95zSI RwpUzULmBVqtfmKvHOrbgehruKlElDM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0SwFOdjmv+BwHEcQT6xR2AV/iXoKaxQAfg5HNaGaPc=; b=lt/Rkg2eX9aGZ8Wg7y4xzPw0Tc7cvKFTsf6ywp8H2uUWTIahZnyKelxGo93Bb9yKCmuPEt A8wnodEy/01kDTAg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 0A3F6118DD; Sun, 13 Jun 2021 13:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0SwFOdjmv+BwHEcQT6xR2AV/iXoKaxQAfg5HNaGaPc=; b=FC1Qck7+6PgQ6kxHSOmLHuaZuI1MXYDL2np5FGslDZ+sBkAGdB9s/gzc1bLymgkKQ7BXgl dRmwgK9glMtl1IHTP9AM/4xt9etkuVJcLXwPPwjLSfQkRrHH89lcxZCAqHpniuDKk95zSI RwpUzULmBVqtfmKvHOrbgehruKlElDM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591619; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0SwFOdjmv+BwHEcQT6xR2AV/iXoKaxQAfg5HNaGaPc=; b=lt/Rkg2eX9aGZ8Wg7y4xzPw0Tc7cvKFTsf6ywp8H2uUWTIahZnyKelxGo93Bb9yKCmuPEt A8wnodEy/01kDTAg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id ic5EMMIKxmA7JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:18 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 04/31] iomap: Introduce iomap_readpage_ops Date: Sun, 13 Jun 2021 08:39:32 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues iomap_readpage_ops provide additional functions to allocate or submit the bio. alloc_bio() is used to allocate bio from the filesystem, in case of btrfs: to allocate btrfs_io_bio. submit_io() similar to the one introduced with direct I/O, submits the bio. Signed-off-by: Goldwyn Rodrigues --- fs/gfs2/aops.c | 4 +-- fs/iomap/buffered-io.c | 56 +++++++++++++++++++++++++++++++----------- fs/xfs/xfs_aops.c | 4 +-- fs/zonefs/super.c | 4 +-- include/linux/iomap.h | 19 ++++++++++++-- 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 23b5be3db044..f5bd7d0dab90 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c @@ -474,7 +474,7 @@ static int __gfs2_readpage(void *file, struct page *page) if (!gfs2_is_jdata(ip) || (i_blocksize(inode) == PAGE_SIZE && !page_has_buffers(page))) { - error = iomap_readpage(page, &gfs2_iomap_ops); + error = iomap_readpage(page, &gfs2_iomap_ops, NULL); } else if (gfs2_is_stuffed(ip)) { error = stuffed_readpage(ip, page); unlock_page(page); @@ -563,7 +563,7 @@ static void gfs2_readahead(struct readahead_control *rac) else if (gfs2_is_jdata(ip)) mpage_readahead(rac, gfs2_block_map); else - iomap_readahead(rac, &gfs2_iomap_ops); + iomap_readahead(rac, &gfs2_iomap_ops, NULL); } /** diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f88f058cdefb..ec2304eea51a 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -201,10 +201,11 @@ iomap_read_end_io(struct bio *bio) } struct iomap_readpage_ctx { - struct page *cur_page; - bool cur_page_in_bio; - struct bio *bio; - struct readahead_control *rac; + struct page *cur_page; + bool cur_page_in_bio; + struct bio *bio; + struct readahead_control *rac; + const struct iomap_readpage_ops *ops; }; static void @@ -282,19 +283,31 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, gfp_t orig_gfp = gfp; unsigned int nr_vecs = DIV_ROUND_UP(length, PAGE_SIZE); - if (ctx->bio) - submit_bio(ctx->bio); + if (ctx->bio) { + if (ctx->ops && ctx->ops->submit_io) + ctx->ops->submit_io(inode, ctx->bio); + else + submit_bio(ctx->bio); + } if (ctx->rac) /* same as readahead_gfp_mask */ gfp |= __GFP_NORETRY | __GFP_NOWARN; - ctx->bio = bio_alloc(gfp, bio_max_segs(nr_vecs)); + if (ctx->ops->alloc_bio) + ctx->bio = ctx->ops->alloc_bio(gfp, + bio_max_segs(nr_vecs)); + else + ctx->bio = bio_alloc(gfp, bio_max_segs(nr_vecs)); /* * If the bio_alloc fails, try it again for a single page to * avoid having to deal with partial page reads. This emulates * what do_mpage_readpage does. */ - if (!ctx->bio) - ctx->bio = bio_alloc(orig_gfp, 1); + if (!ctx->bio) { + if (ctx->ops->alloc_bio) + ctx->bio = ctx->ops->alloc_bio(orig_gfp, 1); + else + ctx->bio = bio_alloc(orig_gfp, 1); + } ctx->bio->bi_opf = REQ_OP_READ; if (ctx->rac) ctx->bio->bi_opf |= REQ_RAHEAD; @@ -315,9 +328,13 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, } int -iomap_readpage(struct page *page, const struct iomap_ops *ops) +iomap_readpage(struct page *page, const struct iomap_ops *ops, + const struct iomap_readpage_ops *readpage_ops) { - struct iomap_readpage_ctx ctx = { .cur_page = page }; + struct iomap_readpage_ctx ctx = { + .cur_page = page, + .ops = readpage_ops, + }; struct inode *inode = page->mapping->host; unsigned poff; loff_t ret; @@ -336,7 +353,10 @@ iomap_readpage(struct page *page, const struct iomap_ops *ops) } if (ctx.bio) { - submit_bio(ctx.bio); + if (ctx.ops->submit_io) + ctx.ops->submit_io(inode, ctx.bio); + else + submit_bio(ctx.bio); WARN_ON_ONCE(!ctx.cur_page_in_bio); } else { WARN_ON_ONCE(ctx.cur_page_in_bio); @@ -392,13 +412,15 @@ iomap_readahead_actor(struct inode *inode, loff_t pos, loff_t length, * function is called with memalloc_nofs set, so allocations will not cause * the filesystem to be reentered. */ -void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops) +void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops, + const struct iomap_readpage_ops *readpage_ops) { struct inode *inode = rac->mapping->host; loff_t pos = readahead_pos(rac); size_t length = readahead_length(rac); struct iomap_readpage_ctx ctx = { .rac = rac, + .ops = readpage_ops, }; trace_iomap_readahead(inode, readahead_count(rac)); @@ -414,8 +436,12 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops) length -= ret; } - if (ctx.bio) - submit_bio(ctx.bio); + if (ctx.bio) { + if (ctx.ops && ctx.ops->submit_io) + ctx.ops->submit_io(inode, ctx.bio); + else + submit_bio(ctx.bio); + } if (ctx.cur_page) { if (!ctx.cur_page_in_bio) unlock_page(ctx.cur_page); diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 826caa6b4a5a..7f49bbf325a1 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -535,14 +535,14 @@ xfs_vm_readpage( struct file *unused, struct page *page) { - return iomap_readpage(page, &xfs_read_iomap_ops); + return iomap_readpage(page, &xfs_read_iomap_ops, NULL); } STATIC void xfs_vm_readahead( struct readahead_control *rac) { - iomap_readahead(rac, &xfs_read_iomap_ops); + iomap_readahead(rac, &xfs_read_iomap_ops, NULL); } static int diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index cd145d318b17..f8157f91b8b1 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -115,12 +115,12 @@ static const struct iomap_ops zonefs_iomap_ops = { static int zonefs_readpage(struct file *unused, struct page *page) { - return iomap_readpage(page, &zonefs_iomap_ops); + return iomap_readpage(page, &zonefs_iomap_ops, NULL); } static void zonefs_readahead(struct readahead_control *rac) { - iomap_readahead(rac, &zonefs_iomap_ops); + iomap_readahead(rac, &zonefs_iomap_ops, NULL); } /* diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 8944711aa92e..cc8c00026edb 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -157,8 +157,6 @@ loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, const struct iomap_ops *ops); -int iomap_readpage(struct page *page, const struct iomap_ops *ops); -void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops); int iomap_set_page_dirty(struct page *page); int iomap_is_partially_uptodate(struct page *page, unsigned long from, unsigned long count); @@ -188,6 +186,23 @@ loff_t iomap_seek_data(struct inode *inode, loff_t offset, sector_t iomap_bmap(struct address_space *mapping, sector_t bno, const struct iomap_ops *ops); +struct iomap_readpage_ops { + + /* allow the filesystem to allocate custom struct bio */ + struct bio *(*alloc_bio)(gfp_t gfp_mask, unsigned short nr_iovecs); + + /* + * Optional, allows the filesystem to perform a custom submission of + * bio, such as csum calculations or multi-device bio split + */ + void (*submit_io)(struct inode *inode, struct bio *bio); +}; + +int iomap_readpage(struct page *page, const struct iomap_ops *ops, + const struct iomap_readpage_ops *readpage_ops); +void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops, + const struct iomap_readpage_ops *readpage_ops); + /* * Structure for writeback I/O completions. */ From patchwork Sun Jun 13 13:39:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8AE3C48BCF for ; Sun, 13 Jun 2021 13:40:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EAD161284 for ; Sun, 13 Jun 2021 13:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231821AbhFMNmX (ORCPT ); Sun, 13 Jun 2021 09:42:23 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34516 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmX (ORCPT ); Sun, 13 Jun 2021 09:42:23 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 71A9621972; Sun, 13 Jun 2021 13:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QaWqpBXHLJh12ZyzW3RVu6eaJSWxCUfEnSj+SOEakZI=; b=Ta9g42fVk0R+1hLlW1+v6W2AF0/Ti7diOD1IhbdQQK794Wwtq9uUdBTSJ/j5aPCzbzb1ud BRAWzLZ0PmD2vmHFb+DJ90AsWdWPwzYA5iUKtplqGXMd/x55Lcrt8vHZ2+afVPSQK2a999 dHsoM5jWBS3NjO1lOEp35E6lcf65VG8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QaWqpBXHLJh12ZyzW3RVu6eaJSWxCUfEnSj+SOEakZI=; b=TRwPehKM29qyqbCh1PhUOvyD+ojnkgX9/574ISGUKt6fgtU4oiIWmytTkx94tJuq6DUZZA JQdxIxpLALoDpLAw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 15ABE118DD; Sun, 13 Jun 2021 13:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QaWqpBXHLJh12ZyzW3RVu6eaJSWxCUfEnSj+SOEakZI=; b=Ta9g42fVk0R+1hLlW1+v6W2AF0/Ti7diOD1IhbdQQK794Wwtq9uUdBTSJ/j5aPCzbzb1ud BRAWzLZ0PmD2vmHFb+DJ90AsWdWPwzYA5iUKtplqGXMd/x55Lcrt8vHZ2+afVPSQK2a999 dHsoM5jWBS3NjO1lOEp35E6lcf65VG8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591621; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QaWqpBXHLJh12ZyzW3RVu6eaJSWxCUfEnSj+SOEakZI=; b=TRwPehKM29qyqbCh1PhUOvyD+ojnkgX9/574ISGUKt6fgtU4oiIWmytTkx94tJuq6DUZZA JQdxIxpLALoDpLAw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id D6gLNcQKxmA/JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:20 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 05/31] btrfs: writepage() lock extent before pages Date: Sun, 13 Jun 2021 08:39:33 -0500 Message-Id: <412df27129a676f4bca6724960350569573a3791.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Lock Order change: Extent locks before page locks writepage() is called with the page locked. So make an attempt to lock the extents and proceed only if successful. The new function best_effort_lock_extent() attempts to lock the range provided. If the entire range was not locked, but it still covers the locked page, work with the reduced range by resetting delalloc_end() Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 66 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 9e81d25dea70..75ad809e8c86 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -1488,6 +1488,47 @@ int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end) return 1; } +/* + * best_effort_lock_extent() - locks the extent to the best of effort + * making sure the minimum range is locked and the + * delalloc bits are set. If the full requested range is not locked, + * delalloc_end shifts to until the range that can be locked. + */ +static bool best_effort_lock_extent(struct extent_io_tree *tree, u64 start, + u64 *delalloc_end, u64 min_end, struct extent_state **cached_state) +{ + u64 failed_start; + u64 end = *delalloc_end; + int ret; + + ret = set_extent_bit(tree, start, end, EXTENT_LOCKED, EXTENT_LOCKED, + &failed_start, cached_state, GFP_NOFS, NULL); + + if (!ret) + return false; + + if (failed_start < min_end) { + /* Could not lock the whole range */ + if (failed_start > start) + unlock_extent_cached(tree, start, + failed_start - 1, cached_state); + return false; + } else if (end > failed_start) { + /* Work with what could be locked */ + end = failed_start - 1; + } + + /* Check if delalloc bits are set */ + ret = test_range_bit(tree, start, end, + EXTENT_DELALLOC, 1, *cached_state); + if (!ret) { + unlock_extent_cached(tree, start, end - 1, cached_state); + return false; + } + *delalloc_end = end; + return true; +} + void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) { unsigned long index = start >> PAGE_SHIFT; @@ -2018,7 +2059,16 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, if (delalloc_end + 1 - delalloc_start > max_bytes) delalloc_end = delalloc_start + max_bytes - 1; - /* step two, lock all the pages after the page that has start */ + /* step two, lock the state bits for the range */ + found = best_effort_lock_extent(tree, delalloc_start, &delalloc_end, + ((page_index(locked_page) + 1) << PAGE_SHIFT), + &cached_state); + if (!found) { + free_extent_state(cached_state); + goto out_failed; + } + + /* step three, lock all the pages after the page that has start */ ret = lock_delalloc_pages(inode, locked_page, delalloc_start, delalloc_end); ASSERT(!ret || ret == -EAGAIN); @@ -2038,20 +2088,6 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, } } - /* step three, lock the state bits for the whole range */ - lock_extent_bits(tree, delalloc_start, delalloc_end, &cached_state); - - /* then test to make sure it is all still delalloc */ - ret = test_range_bit(tree, delalloc_start, delalloc_end, - EXTENT_DELALLOC, 1, cached_state); - if (!ret) { - unlock_extent_cached(tree, delalloc_start, delalloc_end, - &cached_state); - __unlock_for_delalloc(inode, locked_page, - delalloc_start, delalloc_end); - cond_resched(); - goto again; - } free_extent_state(cached_state); *start = delalloc_start; *end = delalloc_end; From patchwork Sun Jun 13 13:39:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 613DAC48BDF for ; Sun, 13 Jun 2021 13:40:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44AE161285 for ; Sun, 13 Jun 2021 13:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbhFMNm0 (ORCPT ); Sun, 13 Jun 2021 09:42:26 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34524 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmZ (ORCPT ); Sun, 13 Jun 2021 09:42:25 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CB04021972; Sun, 13 Jun 2021 13:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2EAeWBzr1ttQBkU0x0lfWsOiWyFSVZOO+2WRdGTAZQ=; b=NRnYpGL0dwQ4kzlHYkQ8BqqfUJGnddGU0tm6TxuAc4aZ8coSgMkfXXbDfYx37/Eyp2nXj0 aSOwTgLKbUZ6/pDZx/SfqsQGHJdxLbCxcjym20524+qb2zl1h4JI/sym+P/duBT7v44fvi 0Miv1qGrSZv+ATOvCxFOCtT6La7wBeM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2EAeWBzr1ttQBkU0x0lfWsOiWyFSVZOO+2WRdGTAZQ=; b=wM7UUlCKihW/fSaYDUBrsLFl/0OZjYTpQfgp9dbxlnZc1S4ZXBeLh7EZ3SEAPfLSzoahji qJNTIKrLeKqno2Bw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 5574C118DD; Sun, 13 Jun 2021 13:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2EAeWBzr1ttQBkU0x0lfWsOiWyFSVZOO+2WRdGTAZQ=; b=NRnYpGL0dwQ4kzlHYkQ8BqqfUJGnddGU0tm6TxuAc4aZ8coSgMkfXXbDfYx37/Eyp2nXj0 aSOwTgLKbUZ6/pDZx/SfqsQGHJdxLbCxcjym20524+qb2zl1h4JI/sym+P/duBT7v44fvi 0Miv1qGrSZv+ATOvCxFOCtT6La7wBeM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591623; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w2EAeWBzr1ttQBkU0x0lfWsOiWyFSVZOO+2WRdGTAZQ=; b=wM7UUlCKihW/fSaYDUBrsLFl/0OZjYTpQfgp9dbxlnZc1S4ZXBeLh7EZ3SEAPfLSzoahji qJNTIKrLeKqno2Bw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id iSQqCccKxmBGJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:23 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 06/31] btrfs: lock extents while truncating Date: Sun, 13 Jun 2021 08:39:34 -0500 Message-Id: <6a65ad8036c65f0d484dc98ee30ba21d4c4812fc.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Lock order change: Lock extents before pages. This removes extent locking in invalidatepages(). invalidatepage() is either called during truncating or while evicting inode. Inode eviction does not require locking. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 794d906cba6c..7761a60788d0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5201,6 +5201,9 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) btrfs_end_transaction(trans); } else { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + u64 start = round_down(oldsize, fs_info->sectorsize); + u64 end = round_up(newsize, fs_info->sectorsize) - 1; + struct extent_state **cached = NULL; if (btrfs_is_zoned(fs_info)) { ret = btrfs_wait_ordered_range(inode, @@ -5219,7 +5222,10 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) set_bit(BTRFS_INODE_FLUSH_ON_CLOSE, &BTRFS_I(inode)->runtime_flags); + lock_extent_bits(&BTRFS_I(inode)->io_tree, start, end, cached); truncate_setsize(inode, newsize); + unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, end, + cached); inode_dio_wait(inode); @@ -8322,9 +8328,23 @@ static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags) static int btrfs_releasepage(struct page *page, gfp_t gfp_flags) { + struct btrfs_inode *inode = BTRFS_I(page->mapping->host); + struct extent_map *em; + int ret; + if (PageWriteback(page) || PageDirty(page)) return 0; - return __btrfs_releasepage(page, gfp_flags); + + em = lookup_extent_mapping(&inode->extent_tree, page_offset(page), + PAGE_SIZE - 1); + if (!em) + return 0; + if (!try_lock_extent(&inode->io_tree, em->start, extent_map_end(em) - 1)) + return 0; + ret = __btrfs_releasepage(page, gfp_flags); + unlock_extent(&inode->io_tree, em->start, extent_map_end(em)); + free_extent_map(em); + return ret; } #ifdef CONFIG_MIGRATION @@ -8398,9 +8418,6 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, return; } - if (!inode_evicting) - lock_extent_bits(tree, page_start, page_end, &cached_state); - cur = page_start; while (cur < page_end) { struct btrfs_ordered_extent *ordered; @@ -8458,7 +8475,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, if (!inode_evicting) clear_extent_bit(tree, cur, range_end, EXTENT_DELALLOC | - EXTENT_LOCKED | EXTENT_DO_ACCOUNTING | + EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, 0, &cached_state); spin_lock_irq(&inode->ordered_tree.lock); @@ -8503,7 +8520,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset, */ btrfs_qgroup_free_data(inode, NULL, cur, range_end + 1 - cur); if (!inode_evicting) { - clear_extent_bit(tree, cur, range_end, EXTENT_LOCKED | + clear_extent_bit(tree, cur, range_end, EXTENT_DELALLOC | EXTENT_UPTODATE | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, 1, delete_states, &cached_state); From patchwork Sun Jun 13 13:39:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4709FC48BE8 for ; Sun, 13 Jun 2021 13:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E5B36128B for ; Sun, 13 Jun 2021 13:40:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbhFMNm2 (ORCPT ); Sun, 13 Jun 2021 09:42:28 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34532 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNm1 (ORCPT ); Sun, 13 Jun 2021 09:42:27 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D59E821972; Sun, 13 Jun 2021 13:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591625; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5e10Lqu1nbYMdX1ZgSSgLB6GXzx9FvCEgtMOqZao1vQ=; b=VVD1SY1q3rO4MkVrgXenmEAXh/80EfQ799eenbQTx8HygykWV0CzYtQbOOUHqlsDBlwH/M C3OTTodqGCFpT1PtDeVjYFu8sYclHgAYp16LRyDID7f8a7kehghEb/mM1QUwPoctOMc5Nx Yja3Ig69mzdq2Dn8KanuR4B1KkpNhQk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591625; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5e10Lqu1nbYMdX1ZgSSgLB6GXzx9FvCEgtMOqZao1vQ=; b=mnZ5qhSKUSJtszWLw3Y05AyHMuZcIlTu2cjQb91o6sE5P27psibVdvGItLd9W7GTgk+aw5 XVqpldY6r91fxhDg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 7F73D118DD; Sun, 13 Jun 2021 13:40:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591625; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5e10Lqu1nbYMdX1ZgSSgLB6GXzx9FvCEgtMOqZao1vQ=; b=VVD1SY1q3rO4MkVrgXenmEAXh/80EfQ799eenbQTx8HygykWV0CzYtQbOOUHqlsDBlwH/M C3OTTodqGCFpT1PtDeVjYFu8sYclHgAYp16LRyDID7f8a7kehghEb/mM1QUwPoctOMc5Nx Yja3Ig69mzdq2Dn8KanuR4B1KkpNhQk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591625; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5e10Lqu1nbYMdX1ZgSSgLB6GXzx9FvCEgtMOqZao1vQ=; b=mnZ5qhSKUSJtszWLw3Y05AyHMuZcIlTu2cjQb91o6sE5P27psibVdvGItLd9W7GTgk+aw5 XVqpldY6r91fxhDg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id O4vwFskKxmBOJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:25 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 07/31] btrfs: write() perform extent locks before locking page Date: Sun, 13 Jun 2021 08:39:35 -0500 Message-Id: <499b1e04baf4e035aeb9a03784b148ec97974787.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Lock order change: Extent locks before page locks. While performing writes, lock the extents before locking the pages. Since pages will no longer involved, lock_and_cleanup_extent_if_need() can be deleted and btrfs_lock_and_flush_ordered_range() is used instead. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 95 +++++++++---------------------------------------- 1 file changed, 16 insertions(+), 79 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 28a05ba47060..e7d33c8177a0 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1407,70 +1407,6 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages, } -/* - * This function locks the extent and properly waits for data=ordered extents - * to finish before allowing the pages to be modified if need. - * - * The return value: - * 1 - the extent is locked - * 0 - the extent is not locked, and everything is OK - * -EAGAIN - need re-prepare the pages - * the other < 0 number - Something wrong happens - */ -static noinline int -lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages, - size_t num_pages, loff_t pos, - size_t write_bytes, - u64 *lockstart, u64 *lockend, - struct extent_state **cached_state) -{ - struct btrfs_fs_info *fs_info = inode->root->fs_info; - u64 start_pos; - u64 last_pos; - int i; - int ret = 0; - - start_pos = round_down(pos, fs_info->sectorsize); - last_pos = round_up(pos + write_bytes, fs_info->sectorsize) - 1; - - if (start_pos < inode->vfs_inode.i_size) { - struct btrfs_ordered_extent *ordered; - - lock_extent_bits(&inode->io_tree, start_pos, last_pos, - cached_state); - ordered = btrfs_lookup_ordered_range(inode, start_pos, - last_pos - start_pos + 1); - if (ordered && - ordered->file_offset + ordered->num_bytes > start_pos && - ordered->file_offset <= last_pos) { - unlock_extent_cached(&inode->io_tree, start_pos, - last_pos, cached_state); - for (i = 0; i < num_pages; i++) { - unlock_page(pages[i]); - put_page(pages[i]); - } - btrfs_start_ordered_extent(ordered, 1); - btrfs_put_ordered_extent(ordered); - return -EAGAIN; - } - if (ordered) - btrfs_put_ordered_extent(ordered); - - *lockstart = start_pos; - *lockend = last_pos; - ret = 1; - } - - /* - * We should be called after prepare_pages() which should have locked - * all pages in the range. - */ - for (i = 0; i < num_pages; i++) - WARN_ON(!PageLocked(pages[i])); - - return ret; -} - static int check_can_nocow(struct btrfs_inode *inode, loff_t pos, size_t *write_bytes, bool nowait) { @@ -1693,7 +1629,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, size_t copied; size_t dirty_sectors; size_t num_sectors; - int extents_locked; + int extents_locked = false; /* * Fault pages before locking them in prepare_pages @@ -1742,7 +1678,15 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, } release_bytes = reserve_bytes; -again: + + if (pos < inode->i_size) { + lockstart = round_down(pos, fs_info->sectorsize); + lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; + btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), + lockstart, lockend, &cached_state); + extents_locked = true; + } + /* * This is going to setup the pages array with the number of * pages we want, so we don't really need to worry about the @@ -1754,19 +1698,11 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); - break; - } - - extents_locked = lock_and_cleanup_extent_if_need( - BTRFS_I(inode), pages, - num_pages, pos, write_bytes, &lockstart, - &lockend, &cached_state); - if (extents_locked < 0) { - if (extents_locked == -EAGAIN) - goto again; - btrfs_delalloc_release_extents(BTRFS_I(inode), - reserve_bytes); - ret = extents_locked; + if (extents_locked) + unlock_extent_cached(&BTRFS_I(inode)->io_tree, + lockstart, lockend, &cached_state); + else + free_extent_state(cached_state); break; } @@ -1831,6 +1767,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, lockstart, lockend, &cached_state); else free_extent_state(cached_state); + extents_locked = false; btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); if (ret) { From patchwork Sun Jun 13 13:39:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F20FC48BCF for ; Sun, 13 Jun 2021 13:40:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 532B361284 for ; Sun, 13 Jun 2021 13:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231834AbhFMNma (ORCPT ); Sun, 13 Jun 2021 09:42:30 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55394 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNm3 (ORCPT ); Sun, 13 Jun 2021 09:42:29 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1F45E1FD2D; Sun, 13 Jun 2021 13:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmYg5B27pnVNot470a/jdEU0j59AEPxgiFKN7pm7uuY=; b=bpF1tBVWBR2k3Qhg5ztrGbH7bXjj3YXfN3sBjXb7CIGqqKkC86G0yLQIU4zASnbwuAS9b5 RH5jEWV5ov7IqRzMU+Sj0DAEO7WsZ+bnWbXTnh127Zfd136++Gn53Le222v/wJFgXVynae 6BPeEqYyHoFMMCYBfmes0A60F4Bmoa4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmYg5B27pnVNot470a/jdEU0j59AEPxgiFKN7pm7uuY=; b=nwHZZhuf0TNHGgA7BbQ23CZ8khLGj6iWqJpv2HebKNG7ko8B0KGASuOQzFJE5wFyfnTh24 Bt2BbDesajHyn8Dg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id B6069118DD; Sun, 13 Jun 2021 13:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmYg5B27pnVNot470a/jdEU0j59AEPxgiFKN7pm7uuY=; b=bpF1tBVWBR2k3Qhg5ztrGbH7bXjj3YXfN3sBjXb7CIGqqKkC86G0yLQIU4zASnbwuAS9b5 RH5jEWV5ov7IqRzMU+Sj0DAEO7WsZ+bnWbXTnh127Zfd136++Gn53Le222v/wJFgXVynae 6BPeEqYyHoFMMCYBfmes0A60F4Bmoa4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591628; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmYg5B27pnVNot470a/jdEU0j59AEPxgiFKN7pm7uuY=; b=nwHZZhuf0TNHGgA7BbQ23CZ8khLGj6iWqJpv2HebKNG7ko8B0KGASuOQzFJE5wFyfnTh24 Bt2BbDesajHyn8Dg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 39o6IcsKxmBQJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:27 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 08/31] btrfs: btrfs_em_to_iomap () to convert em to iomap Date: Sun, 13 Jun 2021 08:39:36 -0500 Message-Id: <87e85bcd1f50533b3a18c09cff5bd88cc3c6f923.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues btrfs_em_to_iomap() converts and extent map into passed argument struct iomap. It makes sure the information is set close to sectorsize block. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/ctree.h | 2 ++ fs/btrfs/file.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index c9256f862085..d4567c7a93cb 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3267,6 +3267,8 @@ int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end); int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos, size_t *write_bytes); void btrfs_check_nocow_unlock(struct btrfs_inode *inode); +void btrfs_em_to_iomap(struct inode *inode, struct extent_map *em, + struct iomap *iomap, loff_t pos); /* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index e7d33c8177a0..cb9471e7224a 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1570,6 +1570,28 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, return 0; } +void btrfs_em_to_iomap(struct inode *inode, + struct extent_map *em, struct iomap *iomap, + loff_t sector_pos) +{ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + loff_t diff = sector_pos - em->start; + + if (em->block_start == EXTENT_MAP_HOLE) { + iomap->addr = IOMAP_NULL_ADDR; + iomap->type = IOMAP_HOLE; + } else if (em->block_start == EXTENT_MAP_INLINE) { + iomap->addr = IOMAP_NULL_ADDR; + iomap->type = IOMAP_INLINE; + } else { + iomap->addr = em->block_start + diff; + iomap->type = IOMAP_MAPPED; + } + iomap->offset = em->start + diff; + iomap->bdev = fs_info->fs_devices->latest_bdev; + iomap->length = em->len - diff; +} + static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) { From patchwork Sun Jun 13 13:39:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1918C48BCF for ; Sun, 13 Jun 2021 13:40:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD6C66128B for ; Sun, 13 Jun 2021 13:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbhFMNme (ORCPT ); Sun, 13 Jun 2021 09:42:34 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34540 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231785AbhFMNmc (ORCPT ); Sun, 13 Jun 2021 09:42:32 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A029D21972; Sun, 13 Jun 2021 13:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l64Lba1V7WJAKv4Fw6fS8eIAElGUf9K5xGDxUIIzbaw=; b=drwsgh2tG3v7xmZEcAq33z4zpoQCLhYO3Vuuq+UY/wIGEWN5jkTpZnCy3UvP++blTbj8+D P65wEuu3t+5cyQeaPAq1IjUlQmZGp4YqNfviBt2sdq+jm+gbDziXCVtfZaxuklyUVWv49Q WsvQbGLmSM8D25vuo/GxTjCWb6dbP1o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l64Lba1V7WJAKv4Fw6fS8eIAElGUf9K5xGDxUIIzbaw=; b=Yo2U5qaoQWNQ60+Zyl5MV6J5+rlmm1/NOYZ5EH7J/n9a44Hof/0sLdy43qMkZfJ3P46QOb NHTWnp7kXeNvLpAA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 4A64A118DD; Sun, 13 Jun 2021 13:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l64Lba1V7WJAKv4Fw6fS8eIAElGUf9K5xGDxUIIzbaw=; b=drwsgh2tG3v7xmZEcAq33z4zpoQCLhYO3Vuuq+UY/wIGEWN5jkTpZnCy3UvP++blTbj8+D P65wEuu3t+5cyQeaPAq1IjUlQmZGp4YqNfviBt2sdq+jm+gbDziXCVtfZaxuklyUVWv49Q WsvQbGLmSM8D25vuo/GxTjCWb6dbP1o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591630; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l64Lba1V7WJAKv4Fw6fS8eIAElGUf9K5xGDxUIIzbaw=; b=Yo2U5qaoQWNQ60+Zyl5MV6J5+rlmm1/NOYZ5EH7J/n9a44Hof/0sLdy43qMkZfJ3P46QOb NHTWnp7kXeNvLpAA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 5A1ABs4KxmBcJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:30 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 09/31] btrfs: Don't process pages if locked_page is NULL Date: Sun, 13 Jun 2021 08:39:37 -0500 Message-Id: <4d69749390822e1241158412dd5c94d70dfab7a0.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues This is an ugly hack so we don't process pages since all page processing is performed in iomap. Ideally, we would want to change this to remove locked_page argument from the run_delalloc_range()->cow_file_range() calls. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 3 +++ fs/btrfs/inode.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 75ad809e8c86..71a59fbeffe1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2101,6 +2101,9 @@ void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, { clear_extent_bit(&inode->io_tree, start, end, clear_bits, 1, 0, NULL); + if (!locked_page) + return; + __process_pages_contig(inode->vfs_inode.i_mapping, locked_page, start, end, page_ops, NULL); } diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7761a60788d0..5491d0e5600f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1112,7 +1112,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * can't use page_started to determine if it's an * inline extent or a compressed extent. */ - unlock_page(locked_page); + if (locked_page) + unlock_page(locked_page); goto out; } else if (ret < 0) { goto out_unlock; From patchwork Sun Jun 13 13:39:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A53C48BE8 for ; Sun, 13 Jun 2021 13:40:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D2CF61284 for ; Sun, 13 Jun 2021 13:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231841AbhFMNmf (ORCPT ); Sun, 13 Jun 2021 09:42:35 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34548 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231838AbhFMNme (ORCPT ); Sun, 13 Jun 2021 09:42:34 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B6D3A21973; Sun, 13 Jun 2021 13:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33EPwHwzBIXafkpmpclsPvxySz1Fq/J7myQK+g42hTk=; b=fj0iio22CqauRbqeg0/w+l+KtaSYXkdOrWrKr9Lm5fotflUzMXY4Ub1zyQHO6nfFlW7Ns1 2xGIqhIGPi6UscH5r54er02kwAXaQnyFI/FjQRXi6JrzzFlJlKygydDIl0ahIiMRIOcHQN aVWKieoHab6INjhRWTiBEwFfpTkszJ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33EPwHwzBIXafkpmpclsPvxySz1Fq/J7myQK+g42hTk=; b=Y8v0VM0bMYeyzU7DjsvZxGRTr5Gx5cGVYkB0Po6uh9q4D3oyzUeyki+JY2GclkyWtl5aSC nYX4MZuwbgtoYJCw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 56C10118DD; Sun, 13 Jun 2021 13:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33EPwHwzBIXafkpmpclsPvxySz1Fq/J7myQK+g42hTk=; b=fj0iio22CqauRbqeg0/w+l+KtaSYXkdOrWrKr9Lm5fotflUzMXY4Ub1zyQHO6nfFlW7Ns1 2xGIqhIGPi6UscH5r54er02kwAXaQnyFI/FjQRXi6JrzzFlJlKygydDIl0ahIiMRIOcHQN aVWKieoHab6INjhRWTiBEwFfpTkszJ4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591632; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=33EPwHwzBIXafkpmpclsPvxySz1Fq/J7myQK+g42hTk=; b=Y8v0VM0bMYeyzU7DjsvZxGRTr5Gx5cGVYkB0Po6uh9q4D3oyzUeyki+JY2GclkyWtl5aSC nYX4MZuwbgtoYJCw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id g9IdCdAKxmBeJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:32 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 10/31] btrfs: Add btrfs_map_blocks to for iomap_writeback_ops Date: Sun, 13 Jun 2021 08:39:38 -0500 Message-Id: <5a0fbde3961d867e810a22d240882a91f4f81bba.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues btrfs_map_blocks() runs delayed allocation range to allcate new CoW space if required and returns the io_map associated with the location to write. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5491d0e5600f..eff4ec44fecd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8283,6 +8283,77 @@ int btrfs_readpage(struct file *file, struct page *page) return ret; } +static int find_delalloc_range(struct inode *inode, u64 *start, u64 *end) +{ + struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree; + bool found; + int ret; + struct extent_state *cached = NULL; + + /* Find the range */ + found = btrfs_find_delalloc_range(tree, start, end, + BTRFS_MAX_EXTENT_SIZE, &cached); + if (!found) + return -EIO; + + lock_extent(tree, *start, *end); + + /* Verify it is set to delalloc */ + ret = test_range_bit(tree, *start, *end, + EXTENT_DELALLOC, 1, cached); + return ret; +} + +static int btrfs_set_iomap(struct inode *inode, loff_t pos, + loff_t length, struct iomap *srcmap) +{ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + loff_t sector_start = round_down(pos, fs_info->sectorsize); + struct extent_map *em; + + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, sector_start, length); + if (IS_ERR(em)) + return PTR_ERR(em); + + btrfs_em_to_iomap(inode, em, srcmap, sector_start); + + free_extent_map(em); + return 0; +} + +static int btrfs_map_blocks(struct iomap_writepage_ctx *wpc, + struct inode *inode, loff_t offset) +{ + int ret; + unsigned long nr_written; /* unused */ + int page_started; /* unused */ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + u64 start = round_down(offset, fs_info->sectorsize); + u64 end = 0; + + /* Check if iomap is valid */ + if (offset >= wpc->iomap.offset && + offset < wpc->iomap.offset + wpc->iomap.length) + return 0; + + ret = find_delalloc_range(inode, &start, &end); + if (ret < 0) + return ret; + + ret = btrfs_run_delalloc_range(BTRFS_I(inode), NULL, + start, end, &page_started, &nr_written, NULL); + if (ret < 0) + return ret; + + /* TODO: handle compressed extents */ + return btrfs_set_iomap(inode, offset, end - offset, &wpc->iomap); +} + +static const struct iomap_writeback_ops btrfs_writeback_ops = { + .map_blocks = btrfs_map_blocks, +}; + + static int btrfs_writepage(struct page *page, struct writeback_control *wbc) { struct inode *inode = page->mapping->host; From patchwork Sun Jun 13 13:39:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F6AFC48BCF for ; Sun, 13 Jun 2021 13:40:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5940C61284 for ; Sun, 13 Jun 2021 13:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbhFMNmh (ORCPT ); Sun, 13 Jun 2021 09:42:37 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34556 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231838AbhFMNmh (ORCPT ); Sun, 13 Jun 2021 09:42:37 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2E5C121972; Sun, 13 Jun 2021 13:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591635; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z9FXmnKCi1B4iOtWVu8/g8/D4h2jusWPmEMhnU+OBdI=; b=jQ6+OXs4d+bm6BSXVoid6d2t0hA3pby/iprtwqvdGFTfF3mfgFK5jzvA/1Pt3/1uUiY75G USXjNNt5CvYHSWurfseD6NutdaMBPQb6p5WcpoNm2prr/1MPTf7poySSml1mnwvtJQj1MD XIKcZl2DjpGdERRLW8NdaLL7k9AGmBc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591635; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z9FXmnKCi1B4iOtWVu8/g8/D4h2jusWPmEMhnU+OBdI=; b=ycKMpAmgK1XKwjBr908UfGet7X0ReDDdj3QO593PSuUdGBu1L9+CmRrCLkVKeLkSu6JmeZ sgx8Ta04liPM7xAg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id C66ED118DD; Sun, 13 Jun 2021 13:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591635; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z9FXmnKCi1B4iOtWVu8/g8/D4h2jusWPmEMhnU+OBdI=; b=jQ6+OXs4d+bm6BSXVoid6d2t0hA3pby/iprtwqvdGFTfF3mfgFK5jzvA/1Pt3/1uUiY75G USXjNNt5CvYHSWurfseD6NutdaMBPQb6p5WcpoNm2prr/1MPTf7poySSml1mnwvtJQj1MD XIKcZl2DjpGdERRLW8NdaLL7k9AGmBc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591635; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z9FXmnKCi1B4iOtWVu8/g8/D4h2jusWPmEMhnU+OBdI=; b=ycKMpAmgK1XKwjBr908UfGet7X0ReDDdj3QO593PSuUdGBu1L9+CmRrCLkVKeLkSu6JmeZ sgx8Ta04liPM7xAg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 15M5J9IKxmBgJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:34 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 11/31] btrfs: Use submit_io to submit btrfs writeback bios Date: Sun, 13 Jun 2021 08:39:39 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues The submit_io sequence calls set_page_extent_mapped() for data inodes to make sure that page->private is set. Depending on the type of inode: metadata or data, the respective submit_bio function is called. This will also be used for readpage() sequence. --- fs/btrfs/inode.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index eff4ec44fecd..87d0730f59d8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8349,11 +8349,26 @@ static int btrfs_map_blocks(struct iomap_writepage_ctx *wpc, return btrfs_set_iomap(inode, offset, end - offset, &wpc->iomap); } +static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) +{ + struct bio_vec *bvec; + struct bvec_iter_all iter_all; + + if (is_data_inode(inode)) + bio_for_each_segment_all(bvec, bio, iter_all) + set_page_extent_mapped(bvec->bv_page); + + if (is_data_inode(inode)) + btrfs_submit_data_bio(inode, bio, 0, 0); + else + btrfs_submit_metadata_bio(inode, bio, 0, 0); +} + static const struct iomap_writeback_ops btrfs_writeback_ops = { .map_blocks = btrfs_map_blocks, + .submit_io = btrfs_buffered_submit_io, }; - static int btrfs_writepage(struct page *page, struct writeback_control *wbc) { struct inode *inode = page->mapping->host; From patchwork Sun Jun 13 13:39:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AC13C48BDF for ; Sun, 13 Jun 2021 13:40:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1106B61285 for ; Sun, 13 Jun 2021 13:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbhFMNmk (ORCPT ); Sun, 13 Jun 2021 09:42:40 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55402 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmj (ORCPT ); Sun, 13 Jun 2021 09:42:39 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B85861FD2D; Sun, 13 Jun 2021 13:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmnkcrX6Ieqz0c3J0QPXJe4jqVvUe93ZisuNxNlg03o=; b=CnjQ4PPHK8Pdhe2XjcJjgzXS3H3Iwm/jJdKy4SYRIIxngFqRTqeKUiQUfKBiLjmTztna8v xxYE0GPmMrO0s4KspNgjliGVZiWIGq0nLO2sBx/31khgQTZ4xpkmQPqV93C2dI11TWgcc9 qTTcSg1RmorI4cEmTK6hwF+kns2eanc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmnkcrX6Ieqz0c3J0QPXJe4jqVvUe93ZisuNxNlg03o=; b=lx4WnwyrkYm1IL4VY2KiOFy4e5Jf99x93Q9hnuiYg6YbPcNrztQQ4GSTffoiNczSuUKtVq c+zRLt9LCH2nZ/Bw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 5AFE9118DD; Sun, 13 Jun 2021 13:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmnkcrX6Ieqz0c3J0QPXJe4jqVvUe93ZisuNxNlg03o=; b=CnjQ4PPHK8Pdhe2XjcJjgzXS3H3Iwm/jJdKy4SYRIIxngFqRTqeKUiQUfKBiLjmTztna8v xxYE0GPmMrO0s4KspNgjliGVZiWIGq0nLO2sBx/31khgQTZ4xpkmQPqV93C2dI11TWgcc9 qTTcSg1RmorI4cEmTK6hwF+kns2eanc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kmnkcrX6Ieqz0c3J0QPXJe4jqVvUe93ZisuNxNlg03o=; b=lx4WnwyrkYm1IL4VY2KiOFy4e5Jf99x93Q9hnuiYg6YbPcNrztQQ4GSTffoiNczSuUKtVq c+zRLt9LCH2nZ/Bw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id mjIbCtUKxmBoJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:37 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 12/31] btrfs: endio sequence for writepage Date: Sun, 13 Jun 2021 08:39:40 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Perform extent housekeeping after completion of bio. This calls iomap_writepage_end_bio() to perform end of write sequence for the pages. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 87d0730f59d8..b8fcf9102eb2 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8349,6 +8349,23 @@ static int btrfs_map_blocks(struct iomap_writepage_ctx *wpc, return btrfs_set_iomap(inode, offset, end - offset, &wpc->iomap); } +static void btrfs_writepage_endio(struct bio *bio) +{ + int error = blk_status_to_errno(bio->bi_status); + struct iomap_ioend *ioend = bio->bi_private; + struct btrfs_inode *inode = BTRFS_I(ioend->io_inode); + struct btrfs_fs_info *fs_info = btrfs_sb(ioend->io_inode->i_sb); + struct btrfs_ordered_extent *ordered = NULL; + + if (!btrfs_dec_test_ordered_pending(inode, &ordered, ioend->io_offset, + ioend->io_size, !error)) + return; + + btrfs_init_work(&ordered->work, finish_ordered_fn, NULL, NULL); + btrfs_queue_work(fs_info->endio_write_workers, &ordered->work); + iomap_writepage_end_bio(bio); +} + static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) { struct bio_vec *bvec; @@ -8358,6 +8375,7 @@ static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) bio_for_each_segment_all(bvec, bio, iter_all) set_page_extent_mapped(bvec->bv_page); + bio->bi_end_io = btrfs_writepage_endio; if (is_data_inode(inode)) btrfs_submit_data_bio(inode, bio, 0, 0); else From patchwork Sun Jun 13 13:39:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A441C48BCF for ; Sun, 13 Jun 2021 13:40:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 799AF6128B for ; Sun, 13 Jun 2021 13:40:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbhFMNmm (ORCPT ); Sun, 13 Jun 2021 09:42:42 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55410 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmm (ORCPT ); Sun, 13 Jun 2021 09:42:42 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4B43C1FD2D; Sun, 13 Jun 2021 13:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uw+CueK/k+SjCPoe3p3Dw3pqHof/UVQBmzfjw9hxgs0=; b=Je4Ob1RyOf04aUwG7P0DM6tB/XkB4HiXrB5ZYEP1xxdfnjbk8vHZ8PnJLnWeJox539jKzn MLbiAlo8Cbx6O5Tu/sZeLe39X8pcpZdRj2MKSdn16v0UoVw6jouYneoz77hML+xiinqOxV kF3v0GhP+aXglau6hAIBtbwcNB9k+bI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uw+CueK/k+SjCPoe3p3Dw3pqHof/UVQBmzfjw9hxgs0=; b=zFFydXdMWoQmnVJxSVp1Nx6AA9SIxLEO5+DQkjTPspLuUP8r9U86kXL3JyVu48CLE5KvYw mSI+iVZTpBR72bBQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id E423B118DD; Sun, 13 Jun 2021 13:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uw+CueK/k+SjCPoe3p3Dw3pqHof/UVQBmzfjw9hxgs0=; b=Je4Ob1RyOf04aUwG7P0DM6tB/XkB4HiXrB5ZYEP1xxdfnjbk8vHZ8PnJLnWeJox539jKzn MLbiAlo8Cbx6O5Tu/sZeLe39X8pcpZdRj2MKSdn16v0UoVw6jouYneoz77hML+xiinqOxV kF3v0GhP+aXglau6hAIBtbwcNB9k+bI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591640; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uw+CueK/k+SjCPoe3p3Dw3pqHof/UVQBmzfjw9hxgs0=; b=zFFydXdMWoQmnVJxSVp1Nx6AA9SIxLEO5+DQkjTPspLuUP8r9U86kXL3JyVu48CLE5KvYw mSI+iVZTpBR72bBQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id VORKLNcKxmBrJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:39 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 13/31] btrfs: do not checksum for free space inode Date: Sun, 13 Jun 2021 08:39:41 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Free space inode writes should not be checksummed. Q: Now sure why this is required now (as opposed to earlier), but it would fail on writing free_space_inode. How is this avoided in the existing code? Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/disk-io.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d1d5091a8385..3af505ec22dc 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -946,9 +946,12 @@ blk_status_t btrfs_submit_metadata_bio(struct inode *inode, struct bio *bio, goto out_w_error; ret = btrfs_map_bio(fs_info, bio, mirror_num); } else if (!should_async_write(fs_info, BTRFS_I(inode))) { - ret = btree_csum_one_bio(bio); - if (ret) - goto out_w_error; + /* Do not checksum free space inode */ + if (!btrfs_is_free_space_inode(BTRFS_I(inode))) { + ret = btree_csum_one_bio(bio); + if (ret) + goto out_w_error; + } ret = btrfs_map_bio(fs_info, bio, mirror_num); } else { /* From patchwork Sun Jun 13 13:39:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33B1BC48BDF for ; Sun, 13 Jun 2021 13:40:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1421161285 for ; Sun, 13 Jun 2021 13:40:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231855AbhFMNmp (ORCPT ); Sun, 13 Jun 2021 09:42:45 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55418 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmo (ORCPT ); Sun, 13 Jun 2021 09:42:44 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A33B41FD2D; Sun, 13 Jun 2021 13:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khznnwgj7wHuTmt9TmWpJgaRjU/UBMcYdj9n6fBdBQQ=; b=m4Bm7cFUdEv9SOORiUGt6cXlxqnrH6ysL9Tyym5fX0zKesDgxJdapyZOOFooEiWpR5y/8Q gq0oB0ItWQKD/FJ4KK/dvA5thNFQGyrF6O4TStH3nkDqI8601wFYxlvaq9d+SbV40DFS2u lOzu3bierOrKLXbTgd5xpB/vagiTayQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khznnwgj7wHuTmt9TmWpJgaRjU/UBMcYdj9n6fBdBQQ=; b=bJNl6F3vtOAc/m4/XlMAaXjDzy8qpZIaL7dO4IzxVo/vm25JHaKRLKIR8P11c3JQqYIEhj g5aekyEW9tVI58DA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 46134118DD; Sun, 13 Jun 2021 13:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khznnwgj7wHuTmt9TmWpJgaRjU/UBMcYdj9n6fBdBQQ=; b=m4Bm7cFUdEv9SOORiUGt6cXlxqnrH6ysL9Tyym5fX0zKesDgxJdapyZOOFooEiWpR5y/8Q gq0oB0ItWQKD/FJ4KK/dvA5thNFQGyrF6O4TStH3nkDqI8601wFYxlvaq9d+SbV40DFS2u lOzu3bierOrKLXbTgd5xpB/vagiTayQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591642; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=khznnwgj7wHuTmt9TmWpJgaRjU/UBMcYdj9n6fBdBQQ=; b=bJNl6F3vtOAc/m4/XlMAaXjDzy8qpZIaL7dO4IzxVo/vm25JHaKRLKIR8P11c3JQqYIEhj g5aekyEW9tVI58DA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id jsxaB9oKxmBtJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:42 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 14/31] btrfs: end EXTENT_MAP_INLINE writeback early Date: Sun, 13 Jun 2021 08:39:42 -0500 Message-Id: <6a5603135d159456d68a566900306cb86b5bbcb1.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues writes to inline extent maps are finished immediately and does not go through the entire writeback cycle of creation or submission of bios. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b8fcf9102eb2..0601cf375b9c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8346,7 +8346,22 @@ static int btrfs_map_blocks(struct iomap_writepage_ctx *wpc, return ret; /* TODO: handle compressed extents */ - return btrfs_set_iomap(inode, offset, end - offset, &wpc->iomap); + ret = btrfs_set_iomap(inode, offset, end - offset, &wpc->iomap); + if (ret < 0) { + __endio_write_update_ordered(BTRFS_I(inode), start, end, false); + return ret; + } + + if (wpc->iomap.type == IOMAP_INLINE) { + /* + * In case of EXTENT_MAP_INLINE, call endio function + * and reset type to IOMAP_HOLE, so iomap code does not + * perform any action + */ + __endio_write_update_ordered(BTRFS_I(inode), start, end, true); + wpc->iomap.type = IOMAP_HOLE; + } + return 0; } static void btrfs_writepage_endio(struct bio *bio) From patchwork Sun Jun 13 13:39:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C0B2C48BDF for ; Sun, 13 Jun 2021 13:40:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35CFF61284 for ; Sun, 13 Jun 2021 13:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231858AbhFMNmr (ORCPT ); Sun, 13 Jun 2021 09:42:47 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55426 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmr (ORCPT ); Sun, 13 Jun 2021 09:42:47 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 365411FD2D; Sun, 13 Jun 2021 13:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591645; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PvVASk6wKeg8uiU+9eR/xYZBw7gAnOw+H/nxmFlyzrU=; b=QL8CUyw0Ouk3fzA5dgi3XKcROPnr0Th9xlr95jn7wfHwTIj1vfOq1Dm5xPq9yDdcoLCjm+ 1KarhgnzOtr0oQ6sOe+np87Eml50GV9zT1rgKN/8YZ8+zl1sZTK+UkbgdXtu9v9fPuJHSM I//UtnJVJpw3YxyPOtykI3zgL17ky68= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591645; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PvVASk6wKeg8uiU+9eR/xYZBw7gAnOw+H/nxmFlyzrU=; b=ANj/FsJUkPpcPaGTvpzD2JAFxsq/Ouab/dIpVaDiS1iNmnI+/l58sQH3wxLgmmyttCHM/5 lcw7uePnVihkqmCg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id CEC63118DD; Sun, 13 Jun 2021 13:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591645; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PvVASk6wKeg8uiU+9eR/xYZBw7gAnOw+H/nxmFlyzrU=; b=QL8CUyw0Ouk3fzA5dgi3XKcROPnr0Th9xlr95jn7wfHwTIj1vfOq1Dm5xPq9yDdcoLCjm+ 1KarhgnzOtr0oQ6sOe+np87Eml50GV9zT1rgKN/8YZ8+zl1sZTK+UkbgdXtu9v9fPuJHSM I//UtnJVJpw3YxyPOtykI3zgL17ky68= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591645; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PvVASk6wKeg8uiU+9eR/xYZBw7gAnOw+H/nxmFlyzrU=; b=ANj/FsJUkPpcPaGTvpzD2JAFxsq/Ouab/dIpVaDiS1iNmnI+/l58sQH3wxLgmmyttCHM/5 lcw7uePnVihkqmCg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id SuctKdwKxmB0JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:44 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 15/31] btrfs: Switch to iomap_writepages() Date: Sun, 13 Jun 2021 08:39:43 -0500 Message-Id: <75b4c003edceca1866a5abfda2c1bb496ee048f1.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Switch to iomap_writepages() Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0601cf375b9c..be0caf3a11f9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8430,7 +8430,9 @@ static int btrfs_writepage(struct page *page, struct writeback_control *wbc) static int btrfs_writepages(struct address_space *mapping, struct writeback_control *wbc) { - return extent_writepages(mapping, wbc); + struct iomap_writepage_ctx wpc = {0}; + + return iomap_writepages(mapping, wbc, &wpc, &btrfs_writeback_ops); } static void btrfs_readahead(struct readahead_control *rac) From patchwork Sun Jun 13 13:39:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40D71C48BDF for ; Sun, 13 Jun 2021 13:40:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ACC561285 for ; Sun, 13 Jun 2021 13:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbhFMNmu (ORCPT ); Sun, 13 Jun 2021 09:42:50 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34564 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmt (ORCPT ); Sun, 13 Jun 2021 09:42:49 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9165221972; Sun, 13 Jun 2021 13:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpiHcbL4IqLdQsBTQDMj/YwHVGU/FHsxPaSfLi/SADY=; b=Jph8tp4nHPG/7cVDr+Zo6F0aHHNAJpJUkH3gyZF070+Y6RXg4pbArfa1mWnXCo9FEamuya IME7YAuqe5oXiB1/bNq2+NZeKKVRHq3Q8GhM8hvfthi2DZu78aZ4I9AnlsX/djV+v8msQc oee8MQYmbRfeaGv47S8DGuv5WtjCQzM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpiHcbL4IqLdQsBTQDMj/YwHVGU/FHsxPaSfLi/SADY=; b=BmqCH3/eMLrMpRN2zvKByUoHDo6ypfduT6slJ/43HexVZCVDBAaLWFrzHt5bKKvpZYrfZR Ia4/0nIHpb9JVQCQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 3A733118DD; Sun, 13 Jun 2021 13:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpiHcbL4IqLdQsBTQDMj/YwHVGU/FHsxPaSfLi/SADY=; b=Jph8tp4nHPG/7cVDr+Zo6F0aHHNAJpJUkH3gyZF070+Y6RXg4pbArfa1mWnXCo9FEamuya IME7YAuqe5oXiB1/bNq2+NZeKKVRHq3Q8GhM8hvfthi2DZu78aZ4I9AnlsX/djV+v8msQc oee8MQYmbRfeaGv47S8DGuv5WtjCQzM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpiHcbL4IqLdQsBTQDMj/YwHVGU/FHsxPaSfLi/SADY=; b=BmqCH3/eMLrMpRN2zvKByUoHDo6ypfduT6slJ/43HexVZCVDBAaLWFrzHt5bKKvpZYrfZR Ia4/0nIHpb9JVQCQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 2jkOBt8KxmB6JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:47 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 16/31] btrfs: remove force_page_uptodate Date: Sun, 13 Jun 2021 08:39:44 -0500 Message-Id: <20379b412dcebaf588f73fd5ac7411ff9781238c.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues iomap handles short writes well. Removing force_page_uptodate eases out porting. Note, this change is not that important because these functions are deleted down the line. This is performed to make the switch easier. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index cb9471e7224a..a94ab3c8da1d 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1326,13 +1326,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, * on success we return a locked page and 0 */ static int prepare_uptodate_page(struct inode *inode, - struct page *page, u64 pos, - bool force_uptodate) + struct page *page, u64 pos) { int ret = 0; - if (((pos & (PAGE_SIZE - 1)) || force_uptodate) && - !PageUptodate(page)) { + if ((pos & (PAGE_SIZE - 1)) && !PageUptodate(page)) { ret = btrfs_readpage(NULL, page); if (ret) return ret; @@ -1354,7 +1352,7 @@ static int prepare_uptodate_page(struct inode *inode, */ static noinline int prepare_pages(struct inode *inode, struct page **pages, size_t num_pages, loff_t pos, - size_t write_bytes, bool force_uptodate) + size_t write_bytes) { int i; unsigned long index = pos >> PAGE_SHIFT; @@ -1379,11 +1377,10 @@ static noinline int prepare_pages(struct inode *inode, struct page **pages, } if (i == 0) - err = prepare_uptodate_page(inode, pages[i], pos, - force_uptodate); + err = prepare_uptodate_page(inode, pages[i], pos); if (!err && i == num_pages - 1) err = prepare_uptodate_page(inode, pages[i], - pos + write_bytes, false); + pos + write_bytes); if (err) { put_page(pages[i]); if (err == -EAGAIN) { @@ -1608,7 +1605,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, int nrptrs; ssize_t ret; bool only_release_metadata = false; - bool force_page_uptodate = false; loff_t old_isize = i_size_read(inode); unsigned int ilock_flags = 0; @@ -1715,8 +1711,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, * contents of pages from loop to loop */ ret = prepare_pages(inode, pages, num_pages, - pos, write_bytes, - force_page_uptodate); + pos, write_bytes); if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); @@ -1743,11 +1738,9 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, nrptrs = 1; if (copied == 0) { - force_page_uptodate = true; dirty_sectors = 0; dirty_pages = 0; } else { - force_page_uptodate = false; dirty_pages = DIV_ROUND_UP(copied + offset, PAGE_SIZE); } From patchwork Sun Jun 13 13:39:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C7F2C48BCF for ; Sun, 13 Jun 2021 13:40:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06B956128A for ; Sun, 13 Jun 2021 13:40:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbhFMNmv (ORCPT ); Sun, 13 Jun 2021 09:42:51 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55434 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmv (ORCPT ); Sun, 13 Jun 2021 09:42:51 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 968741FD2D; Sun, 13 Jun 2021 13:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591649; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=817jSEC+Ks6fELKz59lWJQgVXpski9/T9iIR9yuHxSM=; b=B39gS6OtqZGHGVf9u0kag8BShGB83aOFlxrHGvLRG2Oy+MLdg04Bv7IE2hcW4aEHeqWg/E JF3ry8a1IawiH60G5oU93ZDccpJL05+PiEpEq7iHrWqKDXpwzvdR8VmrTh92VI+nGUiRaR 3g1WZVy0yeuLLWSCI6QBXxZHs1htNAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591649; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=817jSEC+Ks6fELKz59lWJQgVXpski9/T9iIR9yuHxSM=; b=sMt4DpmdNdbUMgHwBgSjq7p5PZh/EIGtzH2ttwLefImgumZEaNKIoIgtBFc3sRXWijcqBZ TBeN+5WPNLd83VDg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 3F2A6118DD; Sun, 13 Jun 2021 13:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591649; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=817jSEC+Ks6fELKz59lWJQgVXpski9/T9iIR9yuHxSM=; b=B39gS6OtqZGHGVf9u0kag8BShGB83aOFlxrHGvLRG2Oy+MLdg04Bv7IE2hcW4aEHeqWg/E JF3ry8a1IawiH60G5oU93ZDccpJL05+PiEpEq7iHrWqKDXpwzvdR8VmrTh92VI+nGUiRaR 3g1WZVy0yeuLLWSCI6QBXxZHs1htNAI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591649; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=817jSEC+Ks6fELKz59lWJQgVXpski9/T9iIR9yuHxSM=; b=sMt4DpmdNdbUMgHwBgSjq7p5PZh/EIGtzH2ttwLefImgumZEaNKIoIgtBFc3sRXWijcqBZ TBeN+5WPNLd83VDg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id hfhHB+EKxmB+JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:49 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 17/31] btrfs: Introduce btrfs_iomap Date: Sun, 13 Jun 2021 08:39:45 -0500 Message-Id: <23b8bc9426ff2de7cf4345c21df8d0c9c36dffa6.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues A structure which will be used to transfer information from iomap_begin() to iomap_end(). Move all locking information into btrfs_iomap. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a94ab3c8da1d..a28435a6bb7e 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -56,6 +56,15 @@ struct inode_defrag { int cycled; }; +struct btrfs_iomap { + + /* Locking */ + u64 lockstart; + u64 lockend; + struct extent_state *cached_state; + int extents_locked; +}; + static int __compare_inode_defrag(struct inode_defrag *defrag1, struct inode_defrag *defrag2) { @@ -1599,14 +1608,13 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct page **pages = NULL; struct extent_changeset *data_reserved = NULL; u64 release_bytes = 0; - u64 lockstart; - u64 lockend; size_t num_written = 0; int nrptrs; ssize_t ret; bool only_release_metadata = false; loff_t old_isize = i_size_read(inode); unsigned int ilock_flags = 0; + struct btrfs_iomap *bi = NULL; if (iocb->ki_flags & IOCB_NOWAIT) ilock_flags |= BTRFS_ILOCK_TRY; @@ -1634,6 +1642,12 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, goto out; } + bi = kzalloc(sizeof(struct btrfs_iomap), GFP_NOFS); + if (!bi) { + ret = -ENOMEM; + goto out; + } + while (iov_iter_count(i) > 0) { struct extent_state *cached_state = NULL; size_t offset = offset_in_page(pos); @@ -1647,7 +1661,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, size_t copied; size_t dirty_sectors; size_t num_sectors; - int extents_locked = false; /* * Fault pages before locking them in prepare_pages @@ -1658,6 +1671,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, break; } + bi->extents_locked = false; only_release_metadata = false; sector_offset = pos & (fs_info->sectorsize - 1); @@ -1698,11 +1712,12 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, release_bytes = reserve_bytes; if (pos < inode->i_size) { - lockstart = round_down(pos, fs_info->sectorsize); - lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; + bi->lockstart = round_down(pos, fs_info->sectorsize); + bi->lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), - lockstart, lockend, &cached_state); - extents_locked = true; + bi->lockstart, bi->lockend, + &cached_state); + bi->extents_locked = true; } /* @@ -1715,11 +1730,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); - if (extents_locked) - unlock_extent_cached(&BTRFS_I(inode)->io_tree, - lockstart, lockend, &cached_state); - else - free_extent_state(cached_state); break; } @@ -1777,12 +1787,13 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, * as delalloc through btrfs_dirty_pages(). Therefore free any * possible cached extent state to avoid a memory leak. */ - if (extents_locked) + if (bi->extents_locked) unlock_extent_cached(&BTRFS_I(inode)->io_tree, - lockstart, lockend, &cached_state); + bi->lockstart, bi->lockend, + &bi->cached_state); else - free_extent_state(cached_state); - extents_locked = false; + free_extent_state(bi->cached_state); + bi->extents_locked = false; btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); if (ret) { @@ -1825,6 +1836,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, iocb->ki_pos += num_written; } out: + kfree(bi); btrfs_inode_unlock(inode, ilock_flags); return num_written ? num_written : ret; } From patchwork Sun Jun 13 13:39:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0CFDC48BE8 for ; Sun, 13 Jun 2021 13:40:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBCD86128B for ; Sun, 13 Jun 2021 13:40:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbhFMNmy (ORCPT ); Sun, 13 Jun 2021 09:42:54 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55442 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmx (ORCPT ); Sun, 13 Jun 2021 09:42:53 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C23FB1FD2D; Sun, 13 Jun 2021 13:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZE0FtYlgl8ev2sxWtgXXJjO7FApdkFhMALSqMYUM8Iw=; b=hQm0YlmaWz49yU82yR3Qa22329SQLw/5zIWJ5ZaRlmRut5PCx71SOucrWMaixWlZLLpCuO rEGyOPtALT/gJd8WKMIfuLd5R5yo9RHyYpPsdwOYTUP0AKRzwYvvSZDtRkgM/L/D2T8bGl sPWGLjg8G37nzPRTydMf22y27XtxRds= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZE0FtYlgl8ev2sxWtgXXJjO7FApdkFhMALSqMYUM8Iw=; b=bg9C3zzv41253kqtp5b066vULdQ6b6g+24bUBH1++7bFBdbl/ZeE1LgH4c+ztVT/AltsK1 5RkRgfAxd+uOpSBg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 6BB21118DD; Sun, 13 Jun 2021 13:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZE0FtYlgl8ev2sxWtgXXJjO7FApdkFhMALSqMYUM8Iw=; b=hQm0YlmaWz49yU82yR3Qa22329SQLw/5zIWJ5ZaRlmRut5PCx71SOucrWMaixWlZLLpCuO rEGyOPtALT/gJd8WKMIfuLd5R5yo9RHyYpPsdwOYTUP0AKRzwYvvSZDtRkgM/L/D2T8bGl sPWGLjg8G37nzPRTydMf22y27XtxRds= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591651; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZE0FtYlgl8ev2sxWtgXXJjO7FApdkFhMALSqMYUM8Iw=; b=bg9C3zzv41253kqtp5b066vULdQ6b6g+24bUBH1++7bFBdbl/ZeE1LgH4c+ztVT/AltsK1 5RkRgfAxd+uOpSBg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id Xa0kEuMKxmCCJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:51 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 18/31] btrfs: Add btrfs_iomap_release() Date: Sun, 13 Jun 2021 08:39:46 -0500 Message-Id: <481e176481ae788109087bb0817ee7d589d933a9.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Function to release allocated btrfs_iomap resources. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index a28435a6bb7e..3d4b8fde47f4 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1598,6 +1598,30 @@ void btrfs_em_to_iomap(struct inode *inode, iomap->length = em->len - diff; } +/* + * btrfs_iomap_release - release reservation passed as length and free + * the btrfs_iomap structure + */ +static void btrfs_iomap_release(struct inode *inode, + loff_t pos, size_t length, struct btrfs_iomap *bi) +{ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + + if (length) { + if (bi->metadata_only) { + btrfs_delalloc_release_metadata(BTRFS_I(inode), + length, true); + } else { + btrfs_delalloc_release_space(BTRFS_I(inode), + bi->data_reserved, + round_down(pos, fs_info->sectorsize), + length, true); + } + } + extent_changeset_free(bi->data_reserved); + kfree(bi); +} + static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) { @@ -1817,24 +1841,14 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, kfree(pages); - if (release_bytes) { - if (only_release_metadata) { - btrfs_check_nocow_unlock(BTRFS_I(inode)); - btrfs_delalloc_release_metadata(BTRFS_I(inode), - release_bytes, true); - } else { - btrfs_delalloc_release_space(BTRFS_I(inode), - data_reserved, - round_down(pos, fs_info->sectorsize), - release_bytes, true); - } - } - - extent_changeset_free(data_reserved); if (num_written > 0) { pagecache_isize_extended(inode, old_isize, iocb->ki_pos); iocb->ki_pos += num_written; } + + if (release_bytes && bi->metadata_only) + btrfs_check_nocow_unlock(BTRFS_I(inode)); + btrfs_iomap_release(inode, pos, release_bytes, bi); out: kfree(bi); btrfs_inode_unlock(inode, ilock_flags); From patchwork Sun Jun 13 13:39:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA795C48BCF for ; Sun, 13 Jun 2021 13:40:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A76CE6128B for ; Sun, 13 Jun 2021 13:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231873AbhFMNm4 (ORCPT ); Sun, 13 Jun 2021 09:42:56 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34572 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNmz (ORCPT ); Sun, 13 Jun 2021 09:42:55 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 22FC921972; Sun, 13 Jun 2021 13:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591654; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8BQUYBVQ/UYTbG0b/GxopWsB0aWx2Aoyv/KPIamnS/g=; b=qaYXaW7TgIyV22GjU2drkZE7psLE9n0CBMgRz0qV55nCiTmmZn8GlPwtkBM+VIOgjAVqw4 5sjRztpCCDpmkKCkRrXs0Jok9rKyW88SYob2qBt+f3jgW0OdsmtrWqkAkXPePjm0DKjYfu 3U+pDGJWGUN661ZWQKQK4qT0kh7T8qA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591654; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8BQUYBVQ/UYTbG0b/GxopWsB0aWx2Aoyv/KPIamnS/g=; b=6cP0FydpyqqRu3iabGW7jaeeCqTuoSdDyK4hN+SwVGs3bWP8+o5hfkRRPeMH/5ZPTwhr17 m9ag0sSz8mFC+XAQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id BA5F4118DD; Sun, 13 Jun 2021 13:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591654; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8BQUYBVQ/UYTbG0b/GxopWsB0aWx2Aoyv/KPIamnS/g=; b=qaYXaW7TgIyV22GjU2drkZE7psLE9n0CBMgRz0qV55nCiTmmZn8GlPwtkBM+VIOgjAVqw4 5sjRztpCCDpmkKCkRrXs0Jok9rKyW88SYob2qBt+f3jgW0OdsmtrWqkAkXPePjm0DKjYfu 3U+pDGJWGUN661ZWQKQK4qT0kh7T8qA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591654; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8BQUYBVQ/UYTbG0b/GxopWsB0aWx2Aoyv/KPIamnS/g=; b=6cP0FydpyqqRu3iabGW7jaeeCqTuoSdDyK4hN+SwVGs3bWP8+o5hfkRRPeMH/5ZPTwhr17 m9ag0sSz8mFC+XAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 4RtTIeUKxmCGJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:53 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 19/31] btrfs: Add reservation information to btrfs_iomap Date: Sun, 13 Jun 2021 08:39:47 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Move reservation information into btrfs_iomap. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 3d4b8fde47f4..ccae8ce7ec4f 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -63,6 +63,11 @@ struct btrfs_iomap { u64 lockend; struct extent_state *cached_state; int extents_locked; + + /* Reservation */ + bool metadata_only; + struct extent_changeset *data_reserved; + size_t reserved_bytes; }; static int __compare_inode_defrag(struct inode_defrag *defrag1, @@ -1630,12 +1635,10 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct inode *inode = file_inode(file); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct page **pages = NULL; - struct extent_changeset *data_reserved = NULL; u64 release_bytes = 0; size_t num_written = 0; int nrptrs; - ssize_t ret; - bool only_release_metadata = false; + int ret; loff_t old_isize = i_size_read(inode); unsigned int ilock_flags = 0; struct btrfs_iomap *bi = NULL; @@ -1673,14 +1676,12 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, } while (iov_iter_count(i) > 0) { - struct extent_state *cached_state = NULL; size_t offset = offset_in_page(pos); size_t sector_offset; size_t write_bytes = min(iov_iter_count(i), nrptrs * (size_t)PAGE_SIZE - offset); size_t num_pages; - size_t reserve_bytes; size_t dirty_pages; size_t copied; size_t dirty_sectors; @@ -1696,12 +1697,12 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, } bi->extents_locked = false; - only_release_metadata = false; + bi->metadata_only = false; sector_offset = pos & (fs_info->sectorsize - 1); - extent_changeset_release(data_reserved); + extent_changeset_release(bi->data_reserved); ret = btrfs_check_data_free_space(BTRFS_I(inode), - &data_reserved, pos, + &bi->data_reserved, pos, write_bytes); if (ret < 0) { /* @@ -1711,36 +1712,36 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, */ if (btrfs_check_nocow_lock(BTRFS_I(inode), pos, &write_bytes) > 0) - only_release_metadata = true; + bi->metadata_only = true; else break; } num_pages = DIV_ROUND_UP(write_bytes + offset, PAGE_SIZE); WARN_ON(num_pages > nrptrs); - reserve_bytes = round_up(write_bytes + sector_offset, + bi->reserved_bytes = round_up(write_bytes + sector_offset, fs_info->sectorsize); - WARN_ON(reserve_bytes == 0); + WARN_ON(bi->reserved_bytes == 0); ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode), - reserve_bytes); + bi->reserved_bytes); if (ret) { - if (!only_release_metadata) + if (!bi->metadata_only) btrfs_free_reserved_data_space(BTRFS_I(inode), - data_reserved, pos, + bi->data_reserved, pos, write_bytes); else btrfs_check_nocow_unlock(BTRFS_I(inode)); break; } - release_bytes = reserve_bytes; + release_bytes = bi->reserved_bytes; if (pos < inode->i_size) { bi->lockstart = round_down(pos, fs_info->sectorsize); bi->lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), bi->lockstart, bi->lockend, - &cached_state); + &bi->cached_state); bi->extents_locked = true; } @@ -1753,13 +1754,13 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, pos, write_bytes); if (ret) { btrfs_delalloc_release_extents(BTRFS_I(inode), - reserve_bytes); + bi->reserved_bytes); break; } copied = btrfs_copy_from_user(pos, write_bytes, pages, i); - num_sectors = BTRFS_BYTES_TO_BLKS(fs_info, reserve_bytes); + num_sectors = BTRFS_BYTES_TO_BLKS(fs_info, bi->reserved_bytes); dirty_sectors = round_up(copied + sector_offset, fs_info->sectorsize); dirty_sectors = BTRFS_BYTES_TO_BLKS(fs_info, dirty_sectors); @@ -1782,7 +1783,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, if (num_sectors > dirty_sectors) { /* release everything except the sectors we dirtied */ release_bytes -= dirty_sectors << fs_info->sectorsize_bits; - if (only_release_metadata) { + if (bi->metadata_only) { btrfs_delalloc_release_metadata(BTRFS_I(inode), release_bytes, true); } else { @@ -1792,7 +1793,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, fs_info->sectorsize) + (dirty_pages << PAGE_SHIFT); btrfs_delalloc_release_space(BTRFS_I(inode), - data_reserved, __pos, + bi->data_reserved, __pos, release_bytes, true); } } @@ -1802,7 +1803,8 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, ret = btrfs_dirty_pages(BTRFS_I(inode), pages, dirty_pages, pos, copied, - &cached_state, only_release_metadata); + &bi->cached_state, + bi->metadata_only); /* * If we have not locked the extent range, because the range's @@ -1819,14 +1821,14 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, free_extent_state(bi->cached_state); bi->extents_locked = false; - btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes); + btrfs_delalloc_release_extents(BTRFS_I(inode), bi->reserved_bytes); if (ret) { btrfs_drop_pages(pages, num_pages); break; } release_bytes = 0; - if (only_release_metadata) + if (bi->metadata_only) btrfs_check_nocow_unlock(BTRFS_I(inode)); btrfs_drop_pages(pages, num_pages); @@ -1850,7 +1852,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, btrfs_check_nocow_unlock(BTRFS_I(inode)); btrfs_iomap_release(inode, pos, release_bytes, bi); out: - kfree(bi); btrfs_inode_unlock(inode, ilock_flags); return num_written ? num_written : ret; } From patchwork Sun Jun 13 13:39:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15367C48BCF for ; Sun, 13 Jun 2021 13:40:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ECDA36128B for ; Sun, 13 Jun 2021 13:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231876AbhFMNm7 (ORCPT ); Sun, 13 Jun 2021 09:42:59 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34580 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNm6 (ORCPT ); Sun, 13 Jun 2021 09:42:58 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AA23D21972; Sun, 13 Jun 2021 13:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D+/hZrO15Vf4vY/d/brckWzoWlmW2Z5wUX3vyyNhiWo=; b=2VYk/JXOXD5WsYHucmi0wGjG4CYc9UmWYlLuXiAjxtLroa+a17XvmWL6OIsFSbeB22AQXO h7nk2OT0DEsN6vISvK9ecXr7sSn5x7/Fp98P3S+5GEwfgHZVuuwRcBs0O/sIyATe/LcinB OuzB3RhvL4z29tKuA/jG/t0s4mIVmVk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D+/hZrO15Vf4vY/d/brckWzoWlmW2Z5wUX3vyyNhiWo=; b=DKv5PZxzF2s/uJafic7iy6Cu8WKpDj3FkM4h6fqwYm2k8Jl8N8urKElLGV7uYehWqfvcIP nvNSYtvtUSkrb4CA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 34AB7118DD; Sun, 13 Jun 2021 13:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D+/hZrO15Vf4vY/d/brckWzoWlmW2Z5wUX3vyyNhiWo=; b=2VYk/JXOXD5WsYHucmi0wGjG4CYc9UmWYlLuXiAjxtLroa+a17XvmWL6OIsFSbeB22AQXO h7nk2OT0DEsN6vISvK9ecXr7sSn5x7/Fp98P3S+5GEwfgHZVuuwRcBs0O/sIyATe/LcinB OuzB3RhvL4z29tKuA/jG/t0s4mIVmVk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591656; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D+/hZrO15Vf4vY/d/brckWzoWlmW2Z5wUX3vyyNhiWo=; b=DKv5PZxzF2s/uJafic7iy6Cu8WKpDj3FkM4h6fqwYm2k8Jl8N8urKElLGV7uYehWqfvcIP nvNSYtvtUSkrb4CA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id uBu7AOgKxmCKJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:56 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 20/31] btrfs: Carve out btrfs_buffered_iomap_begin() from write path Date: Sun, 13 Jun 2021 08:39:48 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Carve out reservation and locking from bufferd write sequence in btrfs_buffered_iomap_begin(). Shortcomings: page handling with respect to nrptrs is messed up. However, since we will be passing the responsibility of pages to iomap, this will not be problem. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 100 ++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index ccae8ce7ec4f..5751bb5e0656 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1627,6 +1627,57 @@ static void btrfs_iomap_release(struct inode *inode, kfree(bi); } +static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, + size_t length, struct btrfs_iomap *bi) +{ + int ret; + size_t write_bytes = length; + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + size_t sector_offset = pos & (fs_info->sectorsize - 1); + + ret = btrfs_check_data_free_space(BTRFS_I(inode), + &bi->data_reserved, pos, write_bytes); + if (ret < 0) { + /* + * If we don't have to COW at the offset, reserve + * metadata only. write_bytes may get smaller than + * requested here. + */ + if (btrfs_check_nocow_lock(BTRFS_I(inode), pos, + &write_bytes) > 0) + bi->metadata_only = true; + else + return ret; + } + + bi->reserved_bytes = round_up(write_bytes + sector_offset, + fs_info->sectorsize); + WARN_ON(bi->reserved_bytes == 0); + ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode), + bi->reserved_bytes); + if (ret) { + if (!bi->metadata_only) + btrfs_free_reserved_data_space(BTRFS_I(inode), + bi->data_reserved, pos, + write_bytes); + else + btrfs_check_nocow_unlock(BTRFS_I(inode)); + return ret; + } + + if (pos < inode->i_size) { + bi->lockstart = round_down(pos, fs_info->sectorsize); + bi->lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; + btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), + bi->lockstart, bi->lockend, + &bi->cached_state); + bi->extents_locked = true; + } + + return 0; + +} + static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) { @@ -1701,50 +1752,15 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, sector_offset = pos & (fs_info->sectorsize - 1); extent_changeset_release(bi->data_reserved); - ret = btrfs_check_data_free_space(BTRFS_I(inode), - &bi->data_reserved, pos, - write_bytes); - if (ret < 0) { - /* - * If we don't have to COW at the offset, reserve - * metadata only. write_bytes may get smaller than - * requested here. - */ - if (btrfs_check_nocow_lock(BTRFS_I(inode), pos, - &write_bytes) > 0) - bi->metadata_only = true; - else - break; - } - num_pages = DIV_ROUND_UP(write_bytes + offset, PAGE_SIZE); - WARN_ON(num_pages > nrptrs); - bi->reserved_bytes = round_up(write_bytes + sector_offset, - fs_info->sectorsize); - WARN_ON(bi->reserved_bytes == 0); - ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode), - bi->reserved_bytes); - if (ret) { - if (!bi->metadata_only) - btrfs_free_reserved_data_space(BTRFS_I(inode), - bi->data_reserved, pos, - write_bytes); - else - btrfs_check_nocow_unlock(BTRFS_I(inode)); - break; - } - - release_bytes = bi->reserved_bytes; + ret = btrfs_buffered_iomap_begin(inode, pos, write_bytes, + bi); - if (pos < inode->i_size) { - bi->lockstart = round_down(pos, fs_info->sectorsize); - bi->lockend = round_up(pos + write_bytes, fs_info->sectorsize) - 1; - btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), - bi->lockstart, bi->lockend, - &bi->cached_state); - bi->extents_locked = true; - } + if (ret < 0) + goto out; + num_pages = DIV_ROUND_UP(write_bytes + offset, PAGE_SIZE); + WARN_ON(num_pages > nrptrs); /* * This is going to setup the pages array with the number of * pages we want, so we don't really need to worry about the @@ -1780,6 +1796,8 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, PAGE_SIZE); } + release_bytes = bi->reserved_bytes; + if (num_sectors > dirty_sectors) { /* release everything except the sectors we dirtied */ release_bytes -= dirty_sectors << fs_info->sectorsize_bits; From patchwork Sun Jun 13 13:39:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11EA0C48BCF for ; Sun, 13 Jun 2021 13:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA3D661284 for ; Sun, 13 Jun 2021 13:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbhFMNnB (ORCPT ); Sun, 13 Jun 2021 09:43:01 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55450 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNnA (ORCPT ); Sun, 13 Jun 2021 09:43:00 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 06ACF1FD2D; Sun, 13 Jun 2021 13:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tPw2ZLv+IdPIxBZFMpyvUX/Ud1VcKuHnz0GAwJFF0zs=; b=pCtHEsE+EhVW9KRNXYTFfJphkD1BUwkngMn6jY0lIpvITgrGY5JC/NAXWXjXP0iTx6MviF vZ8G9aMLDOwXioehhLYjKCfyFcWsfA7/U2co+HwsE5m0ULPVfToaB64iEoNEGre2mew/6W ln05q6+yBJac+KyB0nAmUlFdfEsn6WI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tPw2ZLv+IdPIxBZFMpyvUX/Ud1VcKuHnz0GAwJFF0zs=; b=vrDpEEQiIvlALCo4j8OSPvJbDFG+LbYjB3zmZkuBvJ+OAJ4znD+atrA4y8dSBV0BAgyDZc 1f8HZrS6X/FlJCBw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id A5320118DD; Sun, 13 Jun 2021 13:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tPw2ZLv+IdPIxBZFMpyvUX/Ud1VcKuHnz0GAwJFF0zs=; b=pCtHEsE+EhVW9KRNXYTFfJphkD1BUwkngMn6jY0lIpvITgrGY5JC/NAXWXjXP0iTx6MviF vZ8G9aMLDOwXioehhLYjKCfyFcWsfA7/U2co+HwsE5m0ULPVfToaB64iEoNEGre2mew/6W ln05q6+yBJac+KyB0nAmUlFdfEsn6WI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591659; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tPw2ZLv+IdPIxBZFMpyvUX/Ud1VcKuHnz0GAwJFF0zs=; b=vrDpEEQiIvlALCo4j8OSPvJbDFG+LbYjB3zmZkuBvJ+OAJ4znD+atrA4y8dSBV0BAgyDZc 1f8HZrS6X/FlJCBw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id qGIZH+oKxmCQJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:40:58 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 21/31] btrfs: Carve out btrfs_buffered_iomap_end from the write path Date: Sun, 13 Jun 2021 08:39:49 -0500 Message-Id: <9719e5a213073fe0e49370906a76a76f1b85629e.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Carve out btrfs_buffered_iomap_end() from the write path to form iomap_end() function for writes. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 97 ++++++++++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 5751bb5e0656..ab2b1790e0bb 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1678,6 +1678,63 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, } +static int btrfs_buffered_iomap_end(struct inode *inode, loff_t pos, + loff_t length, ssize_t written, struct btrfs_iomap *bi) +{ + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + size_t num_sectors = BTRFS_BYTES_TO_BLKS(fs_info, bi->reserved_bytes); + size_t dirty_sectors = 0; + int dirty_pages = 0; + int sector_offset = pos & (fs_info->sectorsize - 1); + + if (written) { + dirty_sectors = round_up(written + sector_offset, + fs_info->sectorsize); + dirty_sectors = BTRFS_BYTES_TO_BLKS(fs_info, dirty_sectors); + dirty_pages = DIV_ROUND_UP(written + offset_in_page(pos), + PAGE_SIZE); + } + + /* Release excess reservations */ + if (num_sectors > dirty_sectors) { + size_t release_bytes = bi->reserved_bytes - + (dirty_sectors << fs_info->sb->s_blocksize_bits); + if (bi->metadata_only) { + btrfs_delalloc_release_metadata(BTRFS_I(inode), + release_bytes, true); + } else { + u64 p; + + p = round_down(pos, + fs_info->sectorsize) + + (dirty_pages << PAGE_SHIFT); + btrfs_delalloc_release_space(BTRFS_I(inode), + bi->data_reserved, p, + release_bytes, true); + } + } + + /* + * If we have not locked the extent range, because the range's + * start offset is >= i_size, we might still have a non-NULL + * cached extent state, acquired while marking the extent range + * as delalloc through btrfs_dirty_pages(). Therefore free any + * possible cached extent state to avoid a memory leak. + */ + if (bi->extents_locked) + unlock_extent_cached(&BTRFS_I(inode)->io_tree, + bi->lockstart, bi->lockend, + &bi->cached_state); + else + free_extent_state(bi->cached_state); + + btrfs_delalloc_release_extents(BTRFS_I(inode), bi->reserved_bytes); + if (bi->metadata_only) + btrfs_check_nocow_unlock(BTRFS_I(inode)); + + return 0; +} + static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) { @@ -1736,7 +1793,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, size_t dirty_pages; size_t copied; size_t dirty_sectors; - size_t num_sectors; /* * Fault pages before locking them in prepare_pages @@ -1776,7 +1832,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, copied = btrfs_copy_from_user(pos, write_bytes, pages, i); - num_sectors = BTRFS_BYTES_TO_BLKS(fs_info, bi->reserved_bytes); dirty_sectors = round_up(copied + sector_offset, fs_info->sectorsize); dirty_sectors = BTRFS_BYTES_TO_BLKS(fs_info, dirty_sectors); @@ -1796,26 +1851,6 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, PAGE_SIZE); } - release_bytes = bi->reserved_bytes; - - if (num_sectors > dirty_sectors) { - /* release everything except the sectors we dirtied */ - release_bytes -= dirty_sectors << fs_info->sectorsize_bits; - if (bi->metadata_only) { - btrfs_delalloc_release_metadata(BTRFS_I(inode), - release_bytes, true); - } else { - u64 __pos; - - __pos = round_down(pos, - fs_info->sectorsize) + - (dirty_pages << PAGE_SHIFT); - btrfs_delalloc_release_space(BTRFS_I(inode), - bi->data_reserved, __pos, - release_bytes, true); - } - } - release_bytes = round_up(copied + sector_offset, fs_info->sectorsize); @@ -1824,27 +1859,13 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, &bi->cached_state, bi->metadata_only); - /* - * If we have not locked the extent range, because the range's - * start offset is >= i_size, we might still have a non-NULL - * cached extent state, acquired while marking the extent range - * as delalloc through btrfs_dirty_pages(). Therefore free any - * possible cached extent state to avoid a memory leak. - */ - if (bi->extents_locked) - unlock_extent_cached(&BTRFS_I(inode)->io_tree, - bi->lockstart, bi->lockend, - &bi->cached_state); - else - free_extent_state(bi->cached_state); - bi->extents_locked = false; - - btrfs_delalloc_release_extents(BTRFS_I(inode), bi->reserved_bytes); if (ret) { btrfs_drop_pages(pages, num_pages); break; } + btrfs_buffered_iomap_end(inode, pos, write_bytes, copied, bi); + release_bytes = 0; if (bi->metadata_only) btrfs_check_nocow_unlock(BTRFS_I(inode)); From patchwork Sun Jun 13 13:39:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 122D7C48BDF for ; Sun, 13 Jun 2021 13:41:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1A576128A for ; Sun, 13 Jun 2021 13:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231882AbhFMNnD (ORCPT ); Sun, 13 Jun 2021 09:43:03 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34588 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNnD (ORCPT ); Sun, 13 Jun 2021 09:43:03 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3FCB121972; Sun, 13 Jun 2021 13:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=znXXNpFAe+aq+YAsUkY0lqM2azAuju2wzEFWUnhjD8E=; b=rAi/2znaRQsOtnopGHiIRzzyUQgevCBwNL1b0yoy/lj8xfBy5rZcWKRU5JkXL36MntQhUY ixbz8VifzyQOCIPwOVa21MfwFeXL4MDe7wyBLYFadzKwLYV/ow1ZEqDzMNsjxc9uWz4EvL qXVrA6+dQ4Gls8aGN0p6NNU3j8rmbzc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=znXXNpFAe+aq+YAsUkY0lqM2azAuju2wzEFWUnhjD8E=; b=X86wekEHyPOGI0QCifbh+5SHVMQmYoM4A8iQVpr4T213ko5J6y+FRvcT4W+8lIzz0nl7aM qP4+kMsUZimQujAQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id DCF7B118DD; Sun, 13 Jun 2021 13:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=znXXNpFAe+aq+YAsUkY0lqM2azAuju2wzEFWUnhjD8E=; b=rAi/2znaRQsOtnopGHiIRzzyUQgevCBwNL1b0yoy/lj8xfBy5rZcWKRU5JkXL36MntQhUY ixbz8VifzyQOCIPwOVa21MfwFeXL4MDe7wyBLYFadzKwLYV/ow1ZEqDzMNsjxc9uWz4EvL qXVrA6+dQ4Gls8aGN0p6NNU3j8rmbzc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591661; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=znXXNpFAe+aq+YAsUkY0lqM2azAuju2wzEFWUnhjD8E=; b=X86wekEHyPOGI0QCifbh+5SHVMQmYoM4A8iQVpr4T213ko5J6y+FRvcT4W+8lIzz0nl7aM qP4+kMsUZimQujAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id YT+nLewKxmCSJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:00 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 22/31] btrfs: Set extents delalloc in iomap_end Date: Sun, 13 Jun 2021 08:39:50 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Since the new code path would not be calling btrfs_dirty_pages(), set extent delalloc for the extent just written. In order to make the flow easier, modify btrfs_buffered_iomap_end() to use written_block_end and block_end to calculate respective written and length sectorsize boundaries. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 58 +++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index ab2b1790e0bb..d311b01a2b71 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1682,44 +1682,38 @@ static int btrfs_buffered_iomap_end(struct inode *inode, loff_t pos, loff_t length, ssize_t written, struct btrfs_iomap *bi) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - size_t num_sectors = BTRFS_BYTES_TO_BLKS(fs_info, bi->reserved_bytes); - size_t dirty_sectors = 0; - int dirty_pages = 0; - int sector_offset = pos & (fs_info->sectorsize - 1); - - if (written) { - dirty_sectors = round_up(written + sector_offset, - fs_info->sectorsize); - dirty_sectors = BTRFS_BYTES_TO_BLKS(fs_info, dirty_sectors); - dirty_pages = DIV_ROUND_UP(written + offset_in_page(pos), - PAGE_SIZE); - } + int ret = 0; + size_t release_bytes = 0; + u64 start = round_down(pos, fs_info->sectorsize); + u64 written_block_end = round_up(pos + written, fs_info->sectorsize) - 1; + u64 block_end = round_up(pos + length, fs_info->sectorsize) - 1; + int extra_bits = 0; - /* Release excess reservations */ - if (num_sectors > dirty_sectors) { - size_t release_bytes = bi->reserved_bytes - - (dirty_sectors << fs_info->sb->s_blocksize_bits); - if (bi->metadata_only) { - btrfs_delalloc_release_metadata(BTRFS_I(inode), - release_bytes, true); - } else { - u64 p; + if (written == 0) + release_bytes = bi->reserved_bytes; + else if (written < length) + release_bytes = block_end - written_block_end + 1; - p = round_down(pos, - fs_info->sectorsize) + - (dirty_pages << PAGE_SHIFT); - btrfs_delalloc_release_space(BTRFS_I(inode), - bi->data_reserved, p, - release_bytes, true); - } - } + if (bi->metadata_only) + extra_bits |= EXTENT_NORESERVE; + + clear_extent_bit(&BTRFS_I(inode)->io_tree, start, written_block_end, + EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING | EXTENT_DEFRAG, + 0, 0, &bi->cached_state); + + ret = btrfs_set_extent_delalloc(BTRFS_I(inode), start, + written_block_end, extra_bits, &bi->cached_state); + + /* In case of error, release everything in btrfs_iomap_release() */ + if (ret < 0) + release_bytes = bi->reserved_bytes; /* * If we have not locked the extent range, because the range's * start offset is >= i_size, we might still have a non-NULL * cached extent state, acquired while marking the extent range - * as delalloc through btrfs_dirty_pages(). Therefore free any - * possible cached extent state to avoid a memory leak. + * as delalloc. Therefore free any possible cached extent state + * to avoid a memory leak. */ if (bi->extents_locked) unlock_extent_cached(&BTRFS_I(inode)->io_tree, @@ -1732,6 +1726,8 @@ static int btrfs_buffered_iomap_end(struct inode *inode, loff_t pos, if (bi->metadata_only) btrfs_check_nocow_unlock(BTRFS_I(inode)); + btrfs_iomap_release(inode, pos, release_bytes, bi); + return 0; } From patchwork Sun Jun 13 13:39:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47CA5C48BDF for ; Sun, 13 Jun 2021 13:41:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32FD261285 for ; Sun, 13 Jun 2021 13:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231887AbhFMNnH (ORCPT ); Sun, 13 Jun 2021 09:43:07 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34596 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhFMNnF (ORCPT ); Sun, 13 Jun 2021 09:43:05 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6F05E21972; Sun, 13 Jun 2021 13:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsIJK/Xhj43RCQxVzm3n65e3ZnHxsC5vOFgMkRLxiIQ=; b=lXUoF6v1wdnjlPHqyJIPNH4UTGTd0wxG6Rhdyxjn+b6QTXuzswhRF0w9wB9PXgCLm+XCB+ LobnipDVqkthvOxezM9mJJGIb0o1wJdDj2tp3DGpXr6YVIFZqFirz4zKN3ZlSHoB5xG0en GpW2k5LgiKgBIDTvoU3yvMV3I1s3l8M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsIJK/Xhj43RCQxVzm3n65e3ZnHxsC5vOFgMkRLxiIQ=; b=VPJcX25rJUisx+RLcrgsbRrK4yGK+1eUajDeZOV7on6wOYwItRn/OCyiuzOaS+9CAtCoT2 lpKcRP68GlDi5bAQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id ED478118DD; Sun, 13 Jun 2021 13:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsIJK/Xhj43RCQxVzm3n65e3ZnHxsC5vOFgMkRLxiIQ=; b=lXUoF6v1wdnjlPHqyJIPNH4UTGTd0wxG6Rhdyxjn+b6QTXuzswhRF0w9wB9PXgCLm+XCB+ LobnipDVqkthvOxezM9mJJGIb0o1wJdDj2tp3DGpXr6YVIFZqFirz4zKN3ZlSHoB5xG0en GpW2k5LgiKgBIDTvoU3yvMV3I1s3l8M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591663; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UsIJK/Xhj43RCQxVzm3n65e3ZnHxsC5vOFgMkRLxiIQ=; b=VPJcX25rJUisx+RLcrgsbRrK4yGK+1eUajDeZOV7on6wOYwItRn/OCyiuzOaS+9CAtCoT2 lpKcRP68GlDi5bAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 3UK9Lu4KxmCUJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:02 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 23/31] btrfs: define iomap_page_ops Date: Sun, 13 Jun 2021 08:39:51 -0500 Message-Id: <4421b14055294a07710ab1ec4ec3795f8d056bc2.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues The page_done() sets page->private to EXTENT_PAGE_PRIVATE if not already set. The check is in set_page_extent_mapped(). Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index d311b01a2b71..fe6d24c6f7bf 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -467,6 +467,17 @@ static void btrfs_drop_pages(struct page **pages, size_t num_pages) } } +static void btrfs_page_done(struct inode *inode, loff_t pos, + unsigned int copied, struct page *page, + struct iomap *iomap) +{ + set_page_extent_mapped(page); +} + +static const struct iomap_page_ops btrfs_iomap_page_ops = { + .page_done = btrfs_page_done, +}; + /* * After btrfs_copy_from_user(), update the following things for delalloc: * - Mark newly dirtied pages as DELALLOC in the io tree. From patchwork Sun Jun 13 13:39:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50CDBC48BCF for ; Sun, 13 Jun 2021 13:41:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3AF2361284 for ; Sun, 13 Jun 2021 13:41:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbhFMNnI (ORCPT ); Sun, 13 Jun 2021 09:43:08 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55458 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnH (ORCPT ); Sun, 13 Jun 2021 09:43:07 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 016641FD2D; Sun, 13 Jun 2021 13:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591666; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=woGRyD6YcRWiTazf5LzYH7OlMQ3bppkqFLYFo8OVpZY=; b=gKp+qI7Cnzc6dEH/NsQdawjtKbl6yeFo0gKA1pkwhdIq0245twIg5/CzuMn/5tnsYGrEZA ogwr7ALii/vEHCtgfsLLnRHG4aVXqmtNMonX7cJbJZoNv5KGoidK9tfRqbpigQoug5JCBM iBSnoxXdpiOv7ft2SvtzTOcxVRmTyWY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591666; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=woGRyD6YcRWiTazf5LzYH7OlMQ3bppkqFLYFo8OVpZY=; b=dJ3+2Y/08JboD825YQns5ClcTKwF0Bvkrm1ihL4p6kuB2x0RvvfFFNk+6pHnSqF74LUeWy CJsaEXKcvBchLmDg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 50319118DD; Sun, 13 Jun 2021 13:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591665; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=woGRyD6YcRWiTazf5LzYH7OlMQ3bppkqFLYFo8OVpZY=; b=KhFOPUfPmFagBzCPtA1pemsyqM4AgvXdyZH87tqcP9yNxOxkL1akFc0NUZvG39W1x8pcN0 8DSZHt8oGPUqH31MzarkpDXKJ/8VCdY+gKBIkeRsUKggrbiP1Ydth6yz1rb9sjFVqU4ZiG YrkgpSS9SbbPInTnQhx9BIeQmPvnMDM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591665; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=woGRyD6YcRWiTazf5LzYH7OlMQ3bppkqFLYFo8OVpZY=; b=NCGAhcgDBlI6c15cyFuofpJ1Cn1wnY3ltJ5FkYW2kABShpTiGbeHPB8XFgCD4MfKQdmdz1 1NNKzRPg0k1hUnBA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id wjFAB/EKxmCWJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:05 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 24/31] btrfs: Switch to iomap_file_buffered_write() Date: Sun, 13 Jun 2021 08:39:52 -0500 Message-Id: <5f7bdc2dd24fd6a2e5b3b73b43c867463a5277a7.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Move allocation of btrfs_iomap into iomap_begin(). Change begin()/end() functions to fill iomap data structure. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 157 +++++++++--------------------------------------- 1 file changed, 27 insertions(+), 130 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index fe6d24c6f7bf..6c6e3343bf37 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1639,12 +1639,18 @@ static void btrfs_iomap_release(struct inode *inode, } static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, - size_t length, struct btrfs_iomap *bi) + loff_t length, unsigned int flags, struct iomap *iomap, + struct iomap *srcmap) { int ret; size_t write_bytes = length; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); size_t sector_offset = pos & (fs_info->sectorsize - 1); + struct btrfs_iomap *bi; + + bi = kzalloc(sizeof(struct btrfs_iomap), GFP_NOFS); + if (!bi) + return -ENOMEM; ret = btrfs_check_data_free_space(BTRFS_I(inode), &bi->data_reserved, pos, write_bytes); @@ -1685,14 +1691,25 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, bi->extents_locked = true; } + iomap->private = bi; + iomap->length = round_up(write_bytes + sector_offset, + fs_info->sectorsize); + iomap->offset = round_down(pos, fs_info->sectorsize); + iomap->addr = IOMAP_NULL_ADDR; + iomap->type = IOMAP_DELALLOC; + iomap->bdev = fs_info->fs_devices->latest_bdev; + iomap->page_ops = &btrfs_iomap_page_ops; + return 0; } static int btrfs_buffered_iomap_end(struct inode *inode, loff_t pos, - loff_t length, ssize_t written, struct btrfs_iomap *bi) + loff_t length, ssize_t written, unsigned flags, + struct iomap *iomap) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + struct btrfs_iomap *bi = iomap->private; int ret = 0; size_t release_bytes = 0; u64 start = round_down(pos, fs_info->sectorsize); @@ -1742,21 +1759,19 @@ static int btrfs_buffered_iomap_end(struct inode *inode, loff_t pos, return 0; } +const struct iomap_ops btrfs_buffered_iomap_ops = { + .iomap_begin = btrfs_buffered_iomap_begin, + .iomap_end = btrfs_buffered_iomap_end, +}; + static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, struct iov_iter *i) { struct file *file = iocb->ki_filp; - loff_t pos; struct inode *inode = file_inode(file); - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - struct page **pages = NULL; - u64 release_bytes = 0; size_t num_written = 0; - int nrptrs; int ret; - loff_t old_isize = i_size_read(inode); unsigned int ilock_flags = 0; - struct btrfs_iomap *bi = NULL; if (iocb->ki_flags & IOCB_NOWAIT) ilock_flags |= BTRFS_ILOCK_TRY; @@ -1773,130 +1788,12 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb, if (ret < 0) goto out; - pos = iocb->ki_pos; - nrptrs = min(DIV_ROUND_UP(iov_iter_count(i), PAGE_SIZE), - PAGE_SIZE / (sizeof(struct page *))); - nrptrs = min(nrptrs, current->nr_dirtied_pause - current->nr_dirtied); - nrptrs = max(nrptrs, 8); - pages = kmalloc_array(nrptrs, sizeof(struct page *), GFP_KERNEL); - if (!pages) { - ret = -ENOMEM; - goto out; - } + num_written = iomap_file_buffered_write(iocb, i, + &btrfs_buffered_iomap_ops); - bi = kzalloc(sizeof(struct btrfs_iomap), GFP_NOFS); - if (!bi) { - ret = -ENOMEM; - goto out; - } - - while (iov_iter_count(i) > 0) { - size_t offset = offset_in_page(pos); - size_t sector_offset; - size_t write_bytes = min(iov_iter_count(i), - nrptrs * (size_t)PAGE_SIZE - - offset); - size_t num_pages; - size_t dirty_pages; - size_t copied; - size_t dirty_sectors; - - /* - * Fault pages before locking them in prepare_pages - * to avoid recursive lock - */ - if (unlikely(iov_iter_fault_in_readable(i, write_bytes))) { - ret = -EFAULT; - break; - } - - bi->extents_locked = false; - bi->metadata_only = false; - sector_offset = pos & (fs_info->sectorsize - 1); - - extent_changeset_release(bi->data_reserved); - - ret = btrfs_buffered_iomap_begin(inode, pos, write_bytes, - bi); - - if (ret < 0) - goto out; - - num_pages = DIV_ROUND_UP(write_bytes + offset, PAGE_SIZE); - WARN_ON(num_pages > nrptrs); - /* - * This is going to setup the pages array with the number of - * pages we want, so we don't really need to worry about the - * contents of pages from loop to loop - */ - ret = prepare_pages(inode, pages, num_pages, - pos, write_bytes); - if (ret) { - btrfs_delalloc_release_extents(BTRFS_I(inode), - bi->reserved_bytes); - break; - } - - copied = btrfs_copy_from_user(pos, write_bytes, pages, i); - - dirty_sectors = round_up(copied + sector_offset, - fs_info->sectorsize); - dirty_sectors = BTRFS_BYTES_TO_BLKS(fs_info, dirty_sectors); - - /* - * if we have trouble faulting in the pages, fall - * back to one page at a time - */ - if (copied < write_bytes) - nrptrs = 1; - - if (copied == 0) { - dirty_sectors = 0; - dirty_pages = 0; - } else { - dirty_pages = DIV_ROUND_UP(copied + offset, - PAGE_SIZE); - } - - release_bytes = round_up(copied + sector_offset, - fs_info->sectorsize); - - ret = btrfs_dirty_pages(BTRFS_I(inode), pages, - dirty_pages, pos, copied, - &bi->cached_state, - bi->metadata_only); - - if (ret) { - btrfs_drop_pages(pages, num_pages); - break; - } - - btrfs_buffered_iomap_end(inode, pos, write_bytes, copied, bi); - - release_bytes = 0; - if (bi->metadata_only) - btrfs_check_nocow_unlock(BTRFS_I(inode)); - - btrfs_drop_pages(pages, num_pages); - - cond_resched(); - - balance_dirty_pages_ratelimited(inode->i_mapping); - - pos += copied; - num_written += copied; - } - - kfree(pages); - - if (num_written > 0) { - pagecache_isize_extended(inode, old_isize, iocb->ki_pos); + if (num_written > 0) iocb->ki_pos += num_written; - } - if (release_bytes && bi->metadata_only) - btrfs_check_nocow_unlock(BTRFS_I(inode)); - btrfs_iomap_release(inode, pos, release_bytes, bi); out: btrfs_inode_unlock(inode, ilock_flags); return num_written ? num_written : ret; From patchwork Sun Jun 13 13:39:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C86D6C48BDF for ; Sun, 13 Jun 2021 13:41:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B53816128A for ; Sun, 13 Jun 2021 13:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231893AbhFMNnK (ORCPT ); Sun, 13 Jun 2021 09:43:10 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55466 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnK (ORCPT ); Sun, 13 Jun 2021 09:43:10 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8D2601FD2D; Sun, 13 Jun 2021 13:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591668; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sHt7LK1ESoWdj42G+riEG2/YtmTweWopKxvGb9XqrI=; b=vNELV5+Hv6izPSdEcN9JIw3NDMXWsivXHroMabIzeXp9bHLZ1mXEDGMv7iVtqurtsCzznn QAdo5uF/t7MsMyLBNPpamXBqBHhl1+hxWDn3E8aPbeIO6qMD/HZYLZm4/32xECr0ON6c5+ 0kJaJMyX9Ty/8mXauiyZPThkyRxJ/y8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591668; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sHt7LK1ESoWdj42G+riEG2/YtmTweWopKxvGb9XqrI=; b=ONluyri5V2+0iExL4uvrjsYBVJwlg7NplEM9eQBbIZQ2oSB9bbd6xHMsJgpUUaEc4b1drA mV4NXuMEMtsC/BAw== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 3083A118DD; Sun, 13 Jun 2021 13:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591668; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sHt7LK1ESoWdj42G+riEG2/YtmTweWopKxvGb9XqrI=; b=vNELV5+Hv6izPSdEcN9JIw3NDMXWsivXHroMabIzeXp9bHLZ1mXEDGMv7iVtqurtsCzznn QAdo5uF/t7MsMyLBNPpamXBqBHhl1+hxWDn3E8aPbeIO6qMD/HZYLZm4/32xECr0ON6c5+ 0kJaJMyX9Ty/8mXauiyZPThkyRxJ/y8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591668; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9sHt7LK1ESoWdj42G+riEG2/YtmTweWopKxvGb9XqrI=; b=ONluyri5V2+0iExL4uvrjsYBVJwlg7NplEM9eQBbIZQ2oSB9bbd6xHMsJgpUUaEc4b1drA mV4NXuMEMtsC/BAw== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id 2C86APQKxmCcJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:08 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 25/31] btrfs: remove all page related functions Date: Sun, 13 Jun 2021 08:39:53 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Cleanup after switching to iomap writes. Remove all page handling functions. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 156 ------------------------------------------------ 1 file changed, 156 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 6c6e3343bf37..b3e48bfd75df 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -394,79 +394,6 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info) return 0; } -/* simple helper to fault in pages and copy. This should go away - * and be replaced with calls into generic code. - */ -static noinline int btrfs_copy_from_user(loff_t pos, size_t write_bytes, - struct page **prepared_pages, - struct iov_iter *i) -{ - size_t copied = 0; - size_t total_copied = 0; - int pg = 0; - int offset = offset_in_page(pos); - - while (write_bytes > 0) { - size_t count = min_t(size_t, - PAGE_SIZE - offset, write_bytes); - struct page *page = prepared_pages[pg]; - /* - * Copy data from userspace to the current page - */ - copied = iov_iter_copy_from_user_atomic(page, i, offset, count); - - /* Flush processor's dcache for this page */ - flush_dcache_page(page); - - /* - * if we get a partial write, we can end up with - * partially up to date pages. These add - * a lot of complexity, so make sure they don't - * happen by forcing this copy to be retried. - * - * The rest of the btrfs_file_write code will fall - * back to page at a time copies after we return 0. - */ - if (!PageUptodate(page) && copied < count) - copied = 0; - - iov_iter_advance(i, copied); - write_bytes -= copied; - total_copied += copied; - - /* Return to btrfs_file_write_iter to fault page */ - if (unlikely(copied == 0)) - break; - - if (copied < PAGE_SIZE - offset) { - offset += copied; - } else { - pg++; - offset = 0; - } - } - return total_copied; -} - -/* - * unlocks pages after btrfs_file_write is done with them - */ -static void btrfs_drop_pages(struct page **pages, size_t num_pages) -{ - size_t i; - for (i = 0; i < num_pages; i++) { - /* page checked is some magic around finding pages that - * have been modified without going through btrfs_set_page_dirty - * clear it here. There should be no need to mark the pages - * accessed as prepare_pages should have marked them accessed - * in prepare_pages via find_or_create_page() - */ - ClearPageChecked(pages[i]); - unlock_page(pages[i]); - put_page(pages[i]); - } -} - static void btrfs_page_done(struct inode *inode, loff_t pos, unsigned int copied, struct page *page, struct iomap *iomap) @@ -1346,89 +1273,6 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, return ret; } -/* - * on error we return an unlocked page and the error value - * on success we return a locked page and 0 - */ -static int prepare_uptodate_page(struct inode *inode, - struct page *page, u64 pos) -{ - int ret = 0; - - if ((pos & (PAGE_SIZE - 1)) && !PageUptodate(page)) { - ret = btrfs_readpage(NULL, page); - if (ret) - return ret; - lock_page(page); - if (!PageUptodate(page)) { - unlock_page(page); - return -EIO; - } - if (page->mapping != inode->i_mapping) { - unlock_page(page); - return -EAGAIN; - } - } - return 0; -} - -/* - * this just gets pages into the page cache and locks them down. - */ -static noinline int prepare_pages(struct inode *inode, struct page **pages, - size_t num_pages, loff_t pos, - size_t write_bytes) -{ - int i; - unsigned long index = pos >> PAGE_SHIFT; - gfp_t mask = btrfs_alloc_write_mask(inode->i_mapping); - int err = 0; - int faili; - - for (i = 0; i < num_pages; i++) { -again: - pages[i] = find_or_create_page(inode->i_mapping, index + i, - mask | __GFP_WRITE); - if (!pages[i]) { - faili = i - 1; - err = -ENOMEM; - goto fail; - } - - err = set_page_extent_mapped(pages[i]); - if (err < 0) { - faili = i; - goto fail; - } - - if (i == 0) - err = prepare_uptodate_page(inode, pages[i], pos); - if (!err && i == num_pages - 1) - err = prepare_uptodate_page(inode, pages[i], - pos + write_bytes); - if (err) { - put_page(pages[i]); - if (err == -EAGAIN) { - err = 0; - goto again; - } - faili = i - 1; - goto fail; - } - wait_on_page_writeback(pages[i]); - } - - return 0; -fail: - while (faili >= 0) { - unlock_page(pages[faili]); - put_page(pages[faili]); - faili--; - } - return err; - -} - static int check_can_nocow(struct btrfs_inode *inode, loff_t pos, size_t *write_bytes, bool nowait) { From patchwork Sun Jun 13 13:39:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 123D1C48BCF for ; Sun, 13 Jun 2021 13:41:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE93461284 for ; Sun, 13 Jun 2021 13:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbhFMNnN (ORCPT ); Sun, 13 Jun 2021 09:43:13 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34604 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnM (ORCPT ); Sun, 13 Jun 2021 09:43:12 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 20ABC21970; Sun, 13 Jun 2021 13:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591671; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9nFwya3HpVdIReFAFEOI0CgYeJmvPV3+ZZPtBBolb3c=; b=cSPbNqQTU4O1aKBQU2C2TtIdGYl8h6VcPvw8BxiJH6LOJdLwLeJtx4el3reYkGgmhmPmlZ JIS+gYPrUHVtuOItBcibqhn+ebR+f+pX1QfQ38XN2s49Scrpy4LakWlk5Xt6WRwQV3YVW5 FFOQMFpHmtbmfCj8lXu8s/1zg2EIrHg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591671; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9nFwya3HpVdIReFAFEOI0CgYeJmvPV3+ZZPtBBolb3c=; b=2CXsLoq7m8sP73Yb41QUd9/3cbcUk0YwuN27eJxBUZz9zC8YLE87egQdvHU+HqUH/NEOF+ MKQ1MLhauoqJaOAQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id B8DEA118DD; Sun, 13 Jun 2021 13:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591671; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9nFwya3HpVdIReFAFEOI0CgYeJmvPV3+ZZPtBBolb3c=; b=cSPbNqQTU4O1aKBQU2C2TtIdGYl8h6VcPvw8BxiJH6LOJdLwLeJtx4el3reYkGgmhmPmlZ JIS+gYPrUHVtuOItBcibqhn+ebR+f+pX1QfQ38XN2s49Scrpy4LakWlk5Xt6WRwQV3YVW5 FFOQMFpHmtbmfCj8lXu8s/1zg2EIrHg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591671; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9nFwya3HpVdIReFAFEOI0CgYeJmvPV3+ZZPtBBolb3c=; b=2CXsLoq7m8sP73Yb41QUd9/3cbcUk0YwuN27eJxBUZz9zC8YLE87egQdvHU+HqUH/NEOF+ MKQ1MLhauoqJaOAQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id YbfHIfYKxmCgJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:10 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 26/31] btrfs: use srcmap for read-before-write cases Date: Sun, 13 Jun 2021 08:39:54 -0500 Message-Id: <9d48e1e7fce37455cb6e1a39ae2f2427ae13cebe.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues srcmap supplies the iomap structure to read from in case the write is not aligned to blocksize boundaries. Note, range is already locked, so no extent locking is required. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/file.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index b3e48bfd75df..b10252d93462 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -64,6 +64,9 @@ struct btrfs_iomap { struct extent_state *cached_state; int extents_locked; + /* Source extent-map in order to read from in case not sector aligned */ + struct extent_map *em; + /* Reservation */ bool metadata_only; struct extent_changeset *data_reserved; @@ -1479,6 +1482,7 @@ static void btrfs_iomap_release(struct inode *inode, } } extent_changeset_free(bi->data_reserved); + free_extent_map(bi->em); kfree(bi); } @@ -1491,11 +1495,37 @@ static int btrfs_buffered_iomap_begin(struct inode *inode, loff_t pos, struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); size_t sector_offset = pos & (fs_info->sectorsize - 1); struct btrfs_iomap *bi; + loff_t end = pos + length; bi = kzalloc(sizeof(struct btrfs_iomap), GFP_NOFS); if (!bi) return -ENOMEM; + if ((pos & (PAGE_SIZE - 1) || end & (PAGE_SIZE - 1))) { + loff_t isize = i_size_read(inode); + + if (pos >= isize) { + srcmap->addr = IOMAP_NULL_ADDR; + srcmap->type = IOMAP_HOLE; + srcmap->offset = isize; + srcmap->length = end - isize; + } else { + bi->em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, + pos - sector_offset, length); + if (IS_ERR(bi->em)) { + kfree(bi); + return PTR_ERR(bi->em); + } + btrfs_em_to_iomap(inode, bi->em, srcmap, + pos - sector_offset); + } + } + + if ((srcmap->type != IOMAP_HOLE) && + (end > srcmap->offset + srcmap->length)) + write_bytes = srcmap->offset + srcmap->length - pos; + + ret = btrfs_check_data_free_space(BTRFS_I(inode), &bi->data_reserved, pos, write_bytes); if (ret < 0) { From patchwork Sun Jun 13 13:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A86FC48BDF for ; Sun, 13 Jun 2021 13:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E220561285 for ; Sun, 13 Jun 2021 13:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231898AbhFMNnR (ORCPT ); Sun, 13 Jun 2021 09:43:17 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55474 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnP (ORCPT ); Sun, 13 Jun 2021 09:43:15 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 907581FD32; Sun, 13 Jun 2021 13:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HfZshoc5LhmJs51ERO/QjKdagzVSJhmIg8h3TlxejE=; b=awfbiFCnTmYBhYFb7SRrzPnHwop65b7T4x/4EyGlHLNBD9TJPmlz6jz668vuOHVTrB1wfz 8l8WdFz9uGQ3B672J1TvIi5X0bY6JYtrDLDd7LUQOt2iYZYpxGbGXlodJBMIo3LAWYRR3L WkmGddYBOnKbGueiVCbvleFMm4JoHug= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HfZshoc5LhmJs51ERO/QjKdagzVSJhmIg8h3TlxejE=; b=gEtDOImmM/VEQrylLonFrunctZzzTBfEIkc5OdqMbf8PBNgdFv48sM2370GpgJpLQrMJAC pZs0zWjJyYPibpCA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 33DA0118DD; Sun, 13 Jun 2021 13:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HfZshoc5LhmJs51ERO/QjKdagzVSJhmIg8h3TlxejE=; b=awfbiFCnTmYBhYFb7SRrzPnHwop65b7T4x/4EyGlHLNBD9TJPmlz6jz668vuOHVTrB1wfz 8l8WdFz9uGQ3B672J1TvIi5X0bY6JYtrDLDd7LUQOt2iYZYpxGbGXlodJBMIo3LAWYRR3L WkmGddYBOnKbGueiVCbvleFMm4JoHug= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591673; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3HfZshoc5LhmJs51ERO/QjKdagzVSJhmIg8h3TlxejE=; b=gEtDOImmM/VEQrylLonFrunctZzzTBfEIkc5OdqMbf8PBNgdFv48sM2370GpgJpLQrMJAC pZs0zWjJyYPibpCA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id jS1nAfkKxmCkJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:13 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 27/31] btrfs: Rename end_bio_extent_readpage to btrfs_readpage_endio Date: Sun, 13 Jun 2021 08:39:55 -0500 Message-Id: <44c8d4d3345eeef03be7ed7c9e78e22f6c827dab.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Also, declare it in extent_io.h so it may be used by bio submission function. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 12 ++++++------ fs/btrfs/extent_io.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 71a59fbeffe1..b0a01e3e4e7f 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2970,7 +2970,7 @@ static void begin_page_read(struct btrfs_fs_info *fs_info, struct page *page) /* * Find extent buffer for a givne bytenr. * - * This is for end_bio_extent_readpage(), thus we can't do any unsafe locking + * This is for btrfs_readpage_endio(), thus we can't do any unsafe locking * in endio context. */ static struct extent_buffer *find_extent_buffer_readpage( @@ -3007,7 +3007,7 @@ static struct extent_buffer *find_extent_buffer_readpage( * Scheduling is not allowed, so the extent state tree is expected * to have one and only one object corresponding to this IO. */ -static void end_bio_extent_readpage(struct bio *bio) +void btrfs_readpage_endio(struct bio *bio) { struct bio_vec *bvec; struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); @@ -3035,7 +3035,7 @@ static void end_bio_extent_readpage(struct bio *bio) u32 len; btrfs_debug(fs_info, - "end_bio_extent_readpage: bi_sector=%llu, err=%d, mirror=%u", + "btrfs_readpage_endio: bi_sector=%llu, err=%d, mirror=%u", bio->bi_iter.bi_sector, bio->bi_status, io_bio->mirror_num); tree = &BTRFS_I(inode)->io_tree; @@ -3687,7 +3687,7 @@ int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, ret = submit_extent_page(REQ_OP_READ | read_flags, NULL, bio_ctrl, page, disk_bytenr, iosize, pg_offset, - end_bio_extent_readpage, 0, + btrfs_readpage_endio, 0, this_bio_flag, force_bio_submit); if (!ret) { @@ -6411,7 +6411,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait, ret = submit_extent_page(REQ_OP_READ | REQ_META, NULL, &bio_ctrl, page, eb->start, eb->len, eb->start - page_offset(page), - end_bio_extent_readpage, mirror_num, 0, + btrfs_readpage_endio, mirror_num, 0, true); if (ret) { /* @@ -6513,7 +6513,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num) ClearPageError(page); err = submit_extent_page(REQ_OP_READ | REQ_META, NULL, &bio_ctrl, page, page_offset(page), - PAGE_SIZE, 0, end_bio_extent_readpage, + PAGE_SIZE, 0, btrfs_readpage_endio, mirror_num, 0, false); if (err) { /* diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index 62027f551b44..e3685b071eba 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -287,6 +287,7 @@ int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, unsigned int pg_offset, int mirror_num); void end_extent_writepage(struct page *page, int err, u64 start, u64 end); int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num); +void btrfs_readpage_endio(struct bio *bio); /* * When IO fails, either with EIO or csum verification fails, we From patchwork Sun Jun 13 13:39:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0070EC48BE8 for ; Sun, 13 Jun 2021 13:41:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2CD76128A for ; Sun, 13 Jun 2021 13:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231902AbhFMNnS (ORCPT ); Sun, 13 Jun 2021 09:43:18 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34612 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnR (ORCPT ); Sun, 13 Jun 2021 09:43:17 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0C32921970; Sun, 13 Jun 2021 13:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uGXS7gxOb+12aVOmu+jitXQx/RU1aR6UUDQhT8W6LUQ=; b=KSAC2gRfKJ3fdzRyBoDf8DO5NPcDCK0ZBofnF8xXjHYoM8RQ/RXYcPt4tinxyU2tYLAE/7 kJTMEjFgk3hwuAhXZ736vQHb7t8gTY699jgV3ah+u/CYc4QmLoUGxjmom8E02xo9PdahKt ihLGQwvTOOPyD520xSDpbMprW4txNgQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uGXS7gxOb+12aVOmu+jitXQx/RU1aR6UUDQhT8W6LUQ=; b=nBymWOz5BFipOr133y9TQb3F2rxvmyMO5PVMro5bDLkVl4EuhF+eAEPpPeLtB6cZ3uGNme wvIkUZMOrH4qn0AQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 8B081118DD; Sun, 13 Jun 2021 13:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uGXS7gxOb+12aVOmu+jitXQx/RU1aR6UUDQhT8W6LUQ=; b=KSAC2gRfKJ3fdzRyBoDf8DO5NPcDCK0ZBofnF8xXjHYoM8RQ/RXYcPt4tinxyU2tYLAE/7 kJTMEjFgk3hwuAhXZ736vQHb7t8gTY699jgV3ah+u/CYc4QmLoUGxjmom8E02xo9PdahKt ihLGQwvTOOPyD520xSDpbMprW4txNgQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591676; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uGXS7gxOb+12aVOmu+jitXQx/RU1aR6UUDQhT8W6LUQ=; b=nBymWOz5BFipOr133y9TQb3F2rxvmyMO5PVMro5bDLkVl4EuhF+eAEPpPeLtB6cZ3uGNme wvIkUZMOrH4qn0AQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id NispFvsKxmCoJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:15 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 28/31] btrfs: iomap_begin() for buffered read Date: Sun, 13 Jun 2021 08:39:56 -0500 Message-Id: <55e7d9c0cb329323d11f7782da1e69bb7ca9ccff.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Lock the extents before performing a read. Convert the offset/length to iomap by calling btrfs_em_to_iomap(). If reading from a hole, unlock the extent because iomap provides page with zeros set. Lock only the range on which iomap I/O can be performed. If iomap is lesser than requested range, unlock extents beyond iomap range. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index be0caf3a11f9..6b9b238837b8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8267,6 +8267,56 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, return extent_fiemap(BTRFS_I(inode), fieinfo, start, len); } + +static int btrfs_read_iomap_begin(struct inode *inode, loff_t pos, + loff_t length, unsigned int flags, struct iomap *iomap, + struct iomap *srcmap) +{ + struct extent_state *cached_state = NULL; + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + struct extent_map *em; + u64 start = round_down(pos, fs_info->sectorsize); + u64 end = round_up(pos + length, fs_info->sectorsize) - 1; + + /* Lock the extent */ + btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), + start, end, &cached_state); + + em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, start, end - start + 1); + if (IS_ERR(em)) + return PTR_ERR(em); + + btrfs_em_to_iomap(inode, em, iomap, start); + iomap->private = em; + + if (iomap->type == IOMAP_HOLE) { + unlock_extent_cached(&BTRFS_I(inode)->io_tree, + start, end, &cached_state); + } else if (end > iomap->offset + iomap->length) { + /* Unlock part beyond iomap */ + unlock_extent_cached(&BTRFS_I(inode)->io_tree, + iomap->offset + iomap->length, + end, &cached_state); + } + + return 0; +} + +static int btrfs_read_iomap_end(struct inode *inode, loff_t pos, + loff_t length, ssize_t written, unsigned int flags, + struct iomap *iomap) +{ + struct extent_map *em = iomap->private; + + free_extent_map(em); + return 0; +} + +const struct iomap_ops btrfs_buffered_read_iomap_ops = { + .iomap_begin = btrfs_read_iomap_begin, + .iomap_end = btrfs_read_iomap_end, +}; + int btrfs_readpage(struct file *file, struct page *page) { struct btrfs_inode *inode = BTRFS_I(page->mapping->host); From patchwork Sun Jun 13 13:39:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCBAEC48BDF for ; Sun, 13 Jun 2021 13:41:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1BF26128B for ; Sun, 13 Jun 2021 13:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231905AbhFMNnV (ORCPT ); Sun, 13 Jun 2021 09:43:21 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34620 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnU (ORCPT ); Sun, 13 Jun 2021 09:43:20 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9617C21970; Sun, 13 Jun 2021 13:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNZG1TTDQhR2kz38dZlRJEd5iHoYePtsFIpo634A8Wc=; b=kKjwRfwJ2s5tkRXu7yGfDXvV4qhbw9EMPOYQD5Dt6UxpnOQdn0MeOCUF1xagRAvkwJgfU5 VBuqjPBd8acZb89mTJN6EER3GYuHP779GD5DX/4D3C3CTwHm5ajMFvyYiO/yqZxANPOYrA QOHuqM6XybmeuxUMTK1AXhAGgyKExaI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNZG1TTDQhR2kz38dZlRJEd5iHoYePtsFIpo634A8Wc=; b=pnMdmsIr8yGl3NQiKT9k0lskHhI0kc9gEQ58wMifG343TslZWv7y5uF3J8Fjs2eAamyHvM 8X4P4zbInP28vLBQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 38961118DD; Sun, 13 Jun 2021 13:41:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNZG1TTDQhR2kz38dZlRJEd5iHoYePtsFIpo634A8Wc=; b=kKjwRfwJ2s5tkRXu7yGfDXvV4qhbw9EMPOYQD5Dt6UxpnOQdn0MeOCUF1xagRAvkwJgfU5 VBuqjPBd8acZb89mTJN6EER3GYuHP779GD5DX/4D3C3CTwHm5ajMFvyYiO/yqZxANPOYrA QOHuqM6XybmeuxUMTK1AXhAGgyKExaI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591678; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HNZG1TTDQhR2kz38dZlRJEd5iHoYePtsFIpo634A8Wc=; b=pnMdmsIr8yGl3NQiKT9k0lskHhI0kc9gEQ58wMifG343TslZWv7y5uF3J8Fjs2eAamyHvM 8X4P4zbInP28vLBQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id cLMfAv4KxmCrJAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:18 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 29/31] btrfs: Use iomap_readpage_ops to allocate and submit bio Date: Sun, 13 Jun 2021 08:39:57 -0500 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Set the alloc_io() and submit_io() functions of iomap_readpage_ops While performing readpage, the an btrfs_io_bio is allocated to fill csums and check data csums. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/ctree.h | 1 + fs/btrfs/extent_io.c | 10 ++++++++++ fs/btrfs/extent_io.h | 3 +++ fs/btrfs/inode.c | 9 +++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index d4567c7a93cb..5826933ba4d2 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3214,6 +3214,7 @@ void btrfs_inode_unlock(struct inode *inode, unsigned int ilock_flags); void btrfs_update_inode_bytes(struct btrfs_inode *inode, const u64 add_bytes, const u64 del_bytes); +void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio); /* ioctl.c */ long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index b0a01e3e4e7f..88a8fbf467b0 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -7284,3 +7284,13 @@ void btrfs_readahead_node_child(struct extent_buffer *node, int slot) btrfs_node_ptr_generation(node, slot), btrfs_header_level(node) - 1); } + +static struct bio *btrfs_readpage_alloc_bio(gfp_t gfp_mask, unsigned short nr) +{ + return btrfs_io_bio_alloc(nr); +} + +const struct iomap_readpage_ops btrfs_iomap_readpage_ops = { + .alloc_bio = btrfs_readpage_alloc_bio, + .submit_io = btrfs_buffered_submit_io, +}; diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index e3685b071eba..8cb79f8d1af8 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "ulist.h" /* @@ -313,6 +314,8 @@ int btrfs_repair_one_sector(struct inode *inode, u64 start, int failed_mirror, submit_bio_hook_t *submit_bio_hook); +extern const struct iomap_readpage_ops btrfs_iomap_readpage_ops; + #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS bool find_lock_delalloc_range(struct inode *inode, struct page *locked_page, u64 *start, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6b9b238837b8..1ca83c11e8b9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -35,6 +35,7 @@ #include "misc.h" #include "ctree.h" #include "disk-io.h" +#include "extent_io.h" #include "transaction.h" #include "btrfs_inode.h" #include "print-tree.h" @@ -8431,7 +8432,7 @@ static void btrfs_writepage_endio(struct bio *bio) iomap_writepage_end_bio(bio); } -static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) +void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) { struct bio_vec *bvec; struct bvec_iter_all iter_all; @@ -8440,7 +8441,11 @@ static void btrfs_buffered_submit_io(struct inode *inode, struct bio *bio) bio_for_each_segment_all(bvec, bio, iter_all) set_page_extent_mapped(bvec->bv_page); - bio->bi_end_io = btrfs_writepage_endio; + if (bio_op(bio) == REQ_OP_WRITE) + bio->bi_end_io = btrfs_writepage_endio; + else + bio->bi_end_io = btrfs_readpage_endio; + if (is_data_inode(inode)) btrfs_submit_data_bio(inode, bio, 0, 0); else From patchwork Sun Jun 13 13:39:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F4FC48BDF for ; Sun, 13 Jun 2021 13:41:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0CF7C61285 for ; Sun, 13 Jun 2021 13:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231908AbhFMNnX (ORCPT ); Sun, 13 Jun 2021 09:43:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55482 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnX (ORCPT ); Sun, 13 Jun 2021 09:43:23 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 422F91FD32; Sun, 13 Jun 2021 13:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e3SwlmhUCiFoc8JrUC/yOudxgsveSdq0yYwhSQ7MXDc=; b=IcK0C74f96KZTpPCFFTt35Q5U13Yxwf8Fzaac7y+4xzLMtMNpkm9GAKicp9FQnrRXoALit 4oHYgrKSrIQZyzne5x2thb6g1vYBYXE7AIGpIU0szT50hJdT4ytgX5g4zg4gvSmGP+yRQo rMvXZgfAlk9oCJLcb1Um+btljpkkV9w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e3SwlmhUCiFoc8JrUC/yOudxgsveSdq0yYwhSQ7MXDc=; b=GFb34SC2Y52nq6uZjYixYClnYUvia0pj1S0wwSC/KIIX+09LTM4bUGp994EB26/jHCZU+d jkKnwoFjLTwI5YCQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id C16A0118DD; Sun, 13 Jun 2021 13:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e3SwlmhUCiFoc8JrUC/yOudxgsveSdq0yYwhSQ7MXDc=; b=IcK0C74f96KZTpPCFFTt35Q5U13Yxwf8Fzaac7y+4xzLMtMNpkm9GAKicp9FQnrRXoALit 4oHYgrKSrIQZyzne5x2thb6g1vYBYXE7AIGpIU0szT50hJdT4ytgX5g4zg4gvSmGP+yRQo rMvXZgfAlk9oCJLcb1Um+btljpkkV9w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e3SwlmhUCiFoc8JrUC/yOudxgsveSdq0yYwhSQ7MXDc=; b=GFb34SC2Y52nq6uZjYixYClnYUvia0pj1S0wwSC/KIIX+09LTM4bUGp994EB26/jHCZU+d jkKnwoFjLTwI5YCQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id afa+HQALxmC1JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:20 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 30/31] btrfs: Do not call btrfs_io_bio_free_csum() if BTRFS_INODE_NODATASUM is not set Date: Sun, 13 Jun 2021 08:39:58 -0500 Message-Id: <2a2dc9b5feedd92839f1f835f02235b2539bbcfd.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Q: Not sure why this patch is required. But there are cases when I received a would fail at kfree(io_bio->csum). io_bio->csum_inline would be set to some random value. What would cause this? Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 88a8fbf467b0..a9e8217c0935 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -3013,6 +3013,7 @@ void btrfs_readpage_endio(struct bio *bio) struct btrfs_io_bio *io_bio = btrfs_io_bio(bio); struct extent_io_tree *tree, *failure_tree; struct processed_extent processed = { 0 }; + struct inode *inode; /* * The offset to the beginning of a bio, since one bio can never be * larger than UINT_MAX, u32 here is enough. @@ -3026,14 +3027,16 @@ void btrfs_readpage_endio(struct bio *bio) bio_for_each_segment_all(bvec, bio, iter_all) { bool uptodate = !bio->bi_status; struct page *page = bvec->bv_page; - struct inode *inode = page->mapping->host; - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); - const u32 sectorsize = fs_info->sectorsize; + struct btrfs_fs_info *fs_info; + u32 sectorsize; unsigned int error_bitmap = (unsigned int)-1; u64 start; u64 end; u32 len; + inode = page->mapping->host; + fs_info = btrfs_sb(inode->i_sb); + sectorsize = fs_info->sectorsize; btrfs_debug(fs_info, "btrfs_readpage_endio: bi_sector=%llu, err=%d, mirror=%u", bio->bi_iter.bi_sector, bio->bi_status, @@ -3140,7 +3143,8 @@ void btrfs_readpage_endio(struct bio *bio) } /* Release the last extent */ endio_readpage_release_extent(&processed, NULL, 0, 0, false); - btrfs_io_bio_free_csum(io_bio); + if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) + btrfs_io_bio_free_csum(io_bio); bio_put(bio); } From patchwork Sun Jun 13 13:39:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 12317687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5613C48BCF for ; Sun, 13 Jun 2021 13:41:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB11761284 for ; Sun, 13 Jun 2021 13:41:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231911AbhFMNn0 (ORCPT ); Sun, 13 Jun 2021 09:43:26 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:55494 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231888AbhFMNnZ (ORCPT ); Sun, 13 Jun 2021 09:43:25 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B19CC1FD32; Sun, 13 Jun 2021 13:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591683; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGS+rAwO6W5XC4k4/elnYe/7UK77wwj8LLNNxM0l86c=; b=dznH0irWlm9RXBLlBfzTLHg8E0gbRbcnGAZq4gLpCsQs4hKa6Q3JMbtDclHveslfAgtTMm eH79FoX7qpI4xilhkwBrCIQa/ZDa2wx07p5j556U1HansQkh7YUdW+JBOwwuXE3CGiNJ2l Dc5O92qtiZGJ/pAB4KMbjWRdgjIU3lc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591683; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGS+rAwO6W5XC4k4/elnYe/7UK77wwj8LLNNxM0l86c=; b=ctKZR8q0fCGOy69SQGNK4URuxxCBgTSq8sZLiIlhjzep456JrnatZQEd6Rhh1I93KshE8q +jR4c1Fsmyuzl0AQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 55395118DD; Sun, 13 Jun 2021 13:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623591683; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGS+rAwO6W5XC4k4/elnYe/7UK77wwj8LLNNxM0l86c=; b=dznH0irWlm9RXBLlBfzTLHg8E0gbRbcnGAZq4gLpCsQs4hKa6Q3JMbtDclHveslfAgtTMm eH79FoX7qpI4xilhkwBrCIQa/ZDa2wx07p5j556U1HansQkh7YUdW+JBOwwuXE3CGiNJ2l Dc5O92qtiZGJ/pAB4KMbjWRdgjIU3lc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623591683; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DGS+rAwO6W5XC4k4/elnYe/7UK77wwj8LLNNxM0l86c=; b=ctKZR8q0fCGOy69SQGNK4URuxxCBgTSq8sZLiIlhjzep456JrnatZQEd6Rhh1I93KshE8q +jR4c1Fsmyuzl0AQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id E5ChCAMLxmC/JAAALh3uQQ (envelope-from ); Sun, 13 Jun 2021 13:41:23 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues Subject: [RFC PATCH 31/31] btrfs: Switch to iomap_readpage() and iomap_readahead() Date: Sun, 13 Jun 2021 08:39:59 -0500 Message-Id: <92c58a2ffd31c6538fe3b1a50d5c38556631cbae.1623567940.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goldwyn Rodrigues Use iomap readpage and readahead sequences. Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1ca83c11e8b9..56d9cbeb151d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8320,18 +8320,8 @@ const struct iomap_ops btrfs_buffered_read_iomap_ops = { int btrfs_readpage(struct file *file, struct page *page) { - struct btrfs_inode *inode = BTRFS_I(page->mapping->host); - u64 start = page_offset(page); - u64 end = start + PAGE_SIZE - 1; - struct btrfs_bio_ctrl bio_ctrl = { 0 }; - int ret; - - btrfs_lock_and_flush_ordered_range(inode, start, end, NULL); - - ret = btrfs_do_readpage(page, NULL, &bio_ctrl, 0, NULL); - if (bio_ctrl.bio) - ret = submit_one_bio(bio_ctrl.bio, 0, bio_ctrl.bio_flags); - return ret; + return iomap_readpage(page, &btrfs_buffered_read_iomap_ops, + &btrfs_iomap_readpage_ops); } static int find_delalloc_range(struct inode *inode, u64 *start, u64 *end) @@ -8492,7 +8482,8 @@ static int btrfs_writepages(struct address_space *mapping, static void btrfs_readahead(struct readahead_control *rac) { - extent_readahead(rac); + iomap_readahead(rac, &btrfs_buffered_read_iomap_ops, + &btrfs_iomap_readpage_ops); } static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags)