From patchwork Wed Jan 11 15:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=x9RcRNLh; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tLPbO6dL; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX8c0FDYz23fY for ; Thu, 12 Jan 2023 02:46:07 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8X5HVcz4xwp for ; Thu, 12 Jan 2023 02:46:04 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX8X5Dj2z4xyF; Thu, 12 Jan 2023 02:46:04 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=x9RcRNLh; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=tLPbO6dL; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8X58D7z4xwp for ; Thu, 12 Jan 2023 02:46:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239272AbjAKPqD (ORCPT ); Wed, 11 Jan 2023 10:46:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239246AbjAKPpc (ORCPT ); Wed, 11 Jan 2023 10:45:32 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0340739FA5 for ; Wed, 11 Jan 2023 07:43:42 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 456918B8D2; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451819; 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=52itqBs8IMZtBoJrtv/loJtQZkbIh02hK584OTuk6n4=; b=x9RcRNLhgw+6fIFdUH5wootU4VHuCbtV28FW/u/Ne+g8i0g7Kqx7xba4nDgG5g8Td4Elgu ufoR8/r2aRD1d/veJ4b9cB9cansQcw8X8RLDR9REVppddcJQdFoHLszcsYGLC7qjSsVXUJ rH+ttL+GVXtf0mml9MG7shT3g19PGq4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451819; 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=52itqBs8IMZtBoJrtv/loJtQZkbIh02hK584OTuk6n4=; b=tLPbO6dLawQ1Hwbf6NgC3vX5jiQt4helZSh3kSdwKMPtqXos1SUmk3QCGA2L9KAsSSSKEc wq9T9UzJNw74o3BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2F3B713595; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5YotCyvZvmO3OwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1818CA0745; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 1/7] ext4: Update stale comment about write constraints Date: Wed, 11 Jan 2023 16:43:25 +0100 Message-Id: <20230111154338.392-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2737; i=jack@suse.cz; h=from:subject; bh=CIyzQqdP55rWTUKA4pnB3wd3eEgA6ZuDKeMzISlJGRU=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkdBAaI3HkXn92jd0cdwZT3hZfluriqz2N6txYH fpsXs/6JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZHQAKCRCcnaoHP2RA2XYJB/ wOYanaiGNvPyYw+noHzrgwim0nM/xAmsf2qaQ6ZGG9ER4O09BbRFfITRFYpkRQaFspJG0mWSM2Bqaa DKEHCyAb2yau7xJkX3RFinZmsUWSgE99ssI6T0CB3oCoOLAE+6SQtIuJO6pCu1GU7Gbl0ggDoTxMzT /2XeVatn5azFztKOOTEGEeeRiyuCd6jHF+uNGqk2mMYhJTJcYjqkjEwGffksmQzf5CIh0O9CUknegD 1bZEXCNhAAI+wGzcqLX8eL1hp+dHmKVAk6lfWjdtcjVb5JmY7s9+l9EqU/FaL5iBnYY1KIvHub/ZLI Yc0zLui3dExipHstvCKfHeXLkL/poS X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The comment above do_journal_get_write_access() is very stale. Most of it just does not refer to what the function does today or how jbd2 works. The bit about transaction handling during write(2) is still correct so just update the function names in that part and move the comment to a more appropriate place. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9d9f414f99fe..f9201c7d61ad 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1005,30 +1005,6 @@ int ext4_walk_page_buffers(handle_t *handle, struct inode *inode, return ret; } -/* - * To preserve ordering, it is essential that the hole instantiation and - * the data write be encapsulated in a single transaction. We cannot - * close off a transaction and start a new one between the ext4_get_block() - * and the commit_write(). So doing the jbd2_journal_start at the start of - * prepare_write() is the right place. - * - * Also, this function can nest inside ext4_writepage(). In that case, we - * *know* that ext4_writepage() has generated enough buffer credits to do the - * whole page. So we won't block on the journal in that case, which is good, - * because the caller may be PF_MEMALLOC. - * - * By accident, ext4 can be reentered when a transaction is open via - * quota file writes. If we were to commit the transaction while thus - * reentered, there can be a deadlock - we would be holding a quota - * lock, and the commit would never complete if another thread had a - * transaction open and was blocking on the quota lock - a ranking - * violation. - * - * So what we do is to rely on the fact that jbd2_journal_stop/journal_start - * will _not_ run commit under these circumstances because handle->h_ref - * is elevated. We'll still have enough credits for the tiny quotafile - * write. - */ int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh) { @@ -1149,6 +1125,13 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, } #endif +/* + * To preserve ordering, it is essential that the hole instantiation and + * the data write be encapsulated in a single transaction. We cannot + * close off a transaction and start a new one between the ext4_get_block() + * and the ext4_write_end(). So doing the jbd2_journal_start at the start of + * ext4_write_begin() is the right place. + */ static int ext4_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, struct page **pagep, void **fsdata) From patchwork Wed Jan 11 15:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724725 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=pC4qTwbt; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=yU9n5ZFc; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX9l01CZz23fY for ; Thu, 12 Jan 2023 02:47:06 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9k6h9fz4x1G for ; Thu, 12 Jan 2023 02:47:06 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX9k6cMnz4xwp; Thu, 12 Jan 2023 02:47:06 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=pC4qTwbt; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=yU9n5ZFc; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9k6TD2z4x1G for ; Thu, 12 Jan 2023 02:47:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239423AbjAKPrG (ORCPT ); Wed, 11 Jan 2023 10:47:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238851AbjAKPq1 (ORCPT ); Wed, 11 Jan 2023 10:46:27 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 648BA3B925 for ; Wed, 11 Jan 2023 07:44:10 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 384774CDB; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451819; 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=hCzZtTCPysU8XKeIuyFBJEo6DrpX6FUzU7+1VRauqHo=; b=pC4qTwbtiEtUzPpIRPnvP4DwVYWlf7nzNl161ntx3qWRpLmE6cOjFIp1bnFiQVmdm6DHC2 nYEsgMRiFJy9AirZhzsRUsSsqzl5LYJt4yBXtYzsPrH4FJpzfAOWSvQ7wM/9g5o4VcHvRH Yotnd0ZPe8iXZ8wxg47gTzJdxjt6pUA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451819; 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=hCzZtTCPysU8XKeIuyFBJEo6DrpX6FUzU7+1VRauqHo=; b=yU9n5ZFcxfzaC/oI2s344cKtzds9F2ZNOVMh8g4aK6U8CnND8IVrli4YzWCrKtssXalpX/ jbZdK1lMdTCJoQCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2449F13594; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5xjTCCvZvmO1OwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1C6D3A0746; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 2/7] ext4: Use nr_to_write directly in mpage_prepare_extent_to_map() Date: Wed, 11 Jan 2023 16:43:26 +0100 Message-Id: <20230111154338.392-2-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1590; i=jack@suse.cz; h=from:subject; bh=sdcU1RNfO+GxuvDAPMRPuPWdH7mDyZSmSkAT9wazJqc=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkeFYDjx0MiVWWsphGGp4qcJpvhUNW7kxPszOCG zGU1jzuJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZHgAKCRCcnaoHP2RA2XzmB/ 9l9jR+yXL9Maubb9Edl4l/kNkuuz+BF8U2Vby4PMf/K/xIqIaZxLlUOtFmrvud0u8MDi7fX7FxKH/N p0+pJBLUl6aitQns67lJzkW13nMEK8WF/ACdOQelFJqUP75HS//V7oCx9lB9KlOd6OibJYPz63XmNh ZYwRH1CKtkQ6QFhdxhSxIlZ2bBRTUmkmNuBQGl9Dgi//OHJV9lfCIOuxLR2hQ80b7blywUU5rdy0WJ EhIwWWYOWZHsifVQyyehrqXAiF7KvtG+OzkYucGUVtmb7yYHd4xQW/NdPXHZApSFz31QB+2W3tDs2c DcSke99CYdejk4Iy3bfmlTO1BOJ8nR X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When looking up extent of pages to map in mpage_prepare_extent_to_map() we count how many pages we still need to find in a copy of wbc->nr_to_write counter. With more complex page handling for data=journal mode, it will be easier to use wbc->nr_to_write directly so that we don't forget to carry over changes back to nr_to_write counter. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index f9201c7d61ad..13cab2a47f99 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2580,7 +2580,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) struct address_space *mapping = mpd->inode->i_mapping; struct pagevec pvec; unsigned int nr_pages; - long left = mpd->wbc->nr_to_write; pgoff_t index = mpd->first_page; pgoff_t end = mpd->last_page; xa_mark_t tag; @@ -2614,7 +2613,9 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) * newly appeared dirty pages, but have not synced all * of the old dirty pages. */ - if (mpd->wbc->sync_mode == WB_SYNC_NONE && left <= 0) + if (mpd->wbc->sync_mode == WB_SYNC_NONE && + mpd->wbc->nr_to_write <= + mpd->map.m_len >> (PAGE_SHIFT - blkbits)) goto out; /* If we can't merge this page, we are done. */ @@ -2683,7 +2684,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) goto out; err = 0; } - left--; } pagevec_release(&pvec); cond_resched(); From patchwork Wed Jan 11 15:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=jM5omugW; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Wxkp2+bJ; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX8c0K3Pz23fj for ; Thu, 12 Jan 2023 02:46:07 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8Z666Dz4x1G for ; Thu, 12 Jan 2023 02:46:06 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX8Z63Ccz4xyF; Thu, 12 Jan 2023 02:46:06 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=jM5omugW; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Wxkp2+bJ; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8Z5yMBz4x1G for ; Thu, 12 Jan 2023 02:46:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239408AbjAKPqF (ORCPT ); Wed, 11 Jan 2023 10:46:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235186AbjAKPpe (ORCPT ); Wed, 11 Jan 2023 10:45:34 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8161BB43 for ; Wed, 11 Jan 2023 07:43:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 344A08B8CF; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451819; 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=H9Y3Ug2d9PxV/z1Yd+PN2GAKUVsib+KNAWTAz2ds8Bc=; b=jM5omugWJM8fc8v2JVwu7HVfB+x/Q9zYYl+EkJrMq6+kpi2bHddAHK24xz4Imd3iNEJ1jI s0o5/gUIWKy1tKBOit776Bsj/jxn34CFe4I6HTf5fLy78TvSraldWj1YYMxrNPgCSHo3eF WBUcmeLGg63EaxHOArcAWauReUlKCmw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451819; 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=H9Y3Ug2d9PxV/z1Yd+PN2GAKUVsib+KNAWTAz2ds8Bc=; b=Wxkp2+bJ8oZvDOvVzyMGiubIymqMbC+872iuBmaJq7zNFhbR8AQRqSqDCnj97wAXNi3KbF wWkT5VPSv3YCQODA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1F23B1358A; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YrymByvZvmOzOwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 22C72A0749; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 3/7] ext4: Mark page for delayed dirtying only if it is pinned Date: Wed, 11 Jan 2023 16:43:27 +0100 Message-Id: <20230111154338.392-3-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3033; i=jack@suse.cz; h=from:subject; bh=0gbqwrLZ82QItIKg9QqxNzvnP9BHqzEl1X5/Ky10LFQ=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkfPwmMmwNe5QpgEUhINfTekEKiaCdIcWLLueSn acDWyOGJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZHwAKCRCcnaoHP2RA2QiiB/ 4mUTEYooyueI0NTiBJR4QAJ83bqBTaDfkSp5CuHEWFEJm8CzltXAEXJYwAnfXX19qjOs6pUWwk+Nve lzH8KV/tiFSH3/jdWJPJ9lvrWgldUEhcKfupJLUSL2jhp3smi1y2e2tPu+VPdxPTRZmu7XmZtiX8/G bHMC4IlksdlOEikuaXPiDNZLslCt6h+a2wXpgo3IbHpivcStgnAwJrqpKtkV9otkaKGokvMK8U1U12 2QDJN+PUZ8+MrPw/vKdCY8l0ebD0EvwTiCXs/vIU5efS3o4cHxrUVERt84QqTPiv2weffz5Gyc7lko KUA1s0DrQ6SLHMBPFqHoAdffNfcXkN X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In data=journal mode, page should be dirtied only when it has buffers for checkpoint or it is writeably mapped. In the first case, we don't need to do anything special. In the second case, page was already added to the journal by ext4_page_mkwrite() and since transaction commit writeprotects mapped pages again, page should be writeable (and thus dirtied) only while it is part of the running transaction. So nothing needs to be done either. The only special case is when someone pins the page and uses this pin for modifying page data. So recognize this special case and only then mark the page as having data that needs adding to the journal. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 13cab2a47f99..4c14aa1b9152 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3670,24 +3670,26 @@ const struct iomap_ops ext4_iomap_report_ops = { }; /* - * Whenever the folio is being dirtied, corresponding buffers should already - * be attached to the transaction (we take care of this in ext4_page_mkwrite() - * and ext4_write_begin()). However we cannot move buffers to dirty transaction - * lists here because ->dirty_folio is called under VFS locks and the folio - * is not necessarily locked. - * - * We cannot just dirty the folio and leave attached buffers clean, because the - * buffers' dirty state is "definitive". We cannot just set the buffers dirty - * or jbddirty because all the journalling code will explode. - * - * So what we do is to mark the folio "pending dirty" and next time writepage - * is called, propagate that into the buffers appropriately. + * For data=journal mode, folio should be marked dirty only when it was + * writeably mapped. When that happens, it was already attached to the + * transaction and marked as jbddirty (we take care of this in + * ext4_page_mkwrite()). On transaction commit, we writeprotect page mappings + * so we should have nothing to do here, except for the case when someone + * had the page pinned and dirtied the page through this pin (e.g. by doing + * direct IO to it). In that case we'd need to attach buffers here to the + * transaction but we cannot due to lock ordering. We cannot just dirty the + * folio and leave attached buffers clean, because the buffers' dirty state is + * "definitive". We cannot just set the buffers dirty or jbddirty because all + * the journalling code will explode. So what we do is to mark the folio + * "pending dirty" and next time ext4_writepages() is called, attach buffers + * to the transaction appropriately. */ static bool ext4_journalled_dirty_folio(struct address_space *mapping, struct folio *folio) { WARN_ON_ONCE(!folio_buffers(folio)); - folio_set_checked(folio); + if (folio_may_be_dma_pinned(folio)) + folio_set_checked(folio); return filemap_dirty_folio(mapping, folio); } From patchwork Wed Jan 11 15:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=bSecToR5; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+R9eCOzZ; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX9T2mXBz23fY for ; Thu, 12 Jan 2023 02:46:53 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9T2L5jz4x1G for ; Thu, 12 Jan 2023 02:46:53 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX9T2HkPz4xwp; Thu, 12 Jan 2023 02:46:53 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=bSecToR5; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+R9eCOzZ; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9T2Bjmz4x1G for ; Thu, 12 Jan 2023 02:46:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239482AbjAKPqv (ORCPT ); Wed, 11 Jan 2023 10:46:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238827AbjAKPq1 (ORCPT ); Wed, 11 Jan 2023 10:46:27 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F6603B920 for ; Wed, 11 Jan 2023 07:44:10 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 47D644CDC; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451819; 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=6vKk+UjtaYyTgUG5kRPuE6Dux62abObV4tz4J0MHgHc=; b=bSecToR501v6G84ByahV5p/clH4tFTdAd0yjpsPG7c0xYmLbcUalpfhrSUWBsM7K3hD5Ow DD6qbqqMFBtmE3H+e/eh4rM7avN6C1Uij+uc01nH62KCdlALgj3DNMFkVPJxM9xdxugXa4 Db5VnPOLjdr7hQ5DkZPfw6f7Vk0JB+M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451819; 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=6vKk+UjtaYyTgUG5kRPuE6Dux62abObV4tz4J0MHgHc=; b=+R9eCOzZMSuRHVA3D0clEyras8YQkq6kwCegJf+K0zZTRpJXbGO5Qy61zcaXw2xKt8UPYX KtA/Ve9qehBmUMBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3434013677; Wed, 11 Jan 2023 15:43:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +ES1DCvZvmO6OwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 28001A074D; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 4/7] ext4: Don't unlock page in ext4_bio_write_page() Date: Wed, 11 Jan 2023 16:43:28 +0100 Message-Id: <20230111154338.392-4-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1887; i=jack@suse.cz; h=from:subject; bh=J/YYy9kOGvXtlg3KxCeHOp+Rgo+fGGYk65kMXfU15NM=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkgAAryq3r3xYhzCIPiQrIy00tr8a95O6b5WPBg p5euuk+JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZIAAKCRCcnaoHP2RA2TTFB/ wOPDZH85o/u8fJmbEsVA3swMNB4M8a9jyo6FGc92VgqFfpv407392OO/1RrS4JJf1wADH14eC03QLm SflxdDZgNTfANF/TquH2XdEmZUep6CqBsed14N9S8IIWTpmt/N/CNM+1XEFpQAVG7pbXv7uWj3RIWR JoiJjN0bc7Cbn4QILshHf407E5swF/FcEbdK/K2HjFhQ/IIlQyx+VN/lM4go0pPpP1jOZD/5dBtj87 1vl+f4E4mjCm8Cj2T8zAqfLgG6MYS2AUOjMl9Q39nEmtTp1SyzOEENn9opwLKF1plw3iWNo+F2Lg1c zZcCmoe8Wn7YpHzIjuIwrO6G8CywlR X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Do not unlock the written page in ext4_bio_write_page(). Instead leave the page locked and unlock it in the callers. We'll need to keep the page locked for data=journal writeback for a bit longer. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 2 ++ fs/ext4/page-io.c | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4c14aa1b9152..237880f0d406 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2076,6 +2076,7 @@ static int ext4_writepage(struct page *page, return -ENOMEM; } ret = ext4_bio_write_page(&io_submit, page, len); + unlock_page(page); ext4_io_submit(&io_submit); /* Drop io_end reference we got from init */ ext4_put_io_end_defer(io_submit.io_end); @@ -2110,6 +2111,7 @@ static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page) else len = PAGE_SIZE; err = ext4_bio_write_page(&mpd->io_submit, page, len); + unlock_page(page); if (!err) mpd->wbc->nr_to_write--; mpd->first_page++; diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index beaec6d81074..3bc7c7c5b99d 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -500,7 +500,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io, /* Nothing to submit? Just unlock the page... */ if (!nr_to_submit) - goto unlock; + return 0; bh = head = page_buffers(page); @@ -548,7 +548,8 @@ int ext4_bio_write_page(struct ext4_io_submit *io, } bh = bh->b_this_page; } while (bh != head); - goto unlock; + + return ret; } } @@ -564,7 +565,6 @@ int ext4_bio_write_page(struct ext4_io_submit *io, io_submit_add_bh(io, inode, bounce_page ? bounce_page : page, bh); } while ((bh = bh->b_this_page) != head); -unlock: - unlock_page(page); - return ret; + + return 0; } From patchwork Wed Jan 11 15:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=vZfqua1J; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=B0eQZJ0h; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX9g6gKQz23fY for ; Thu, 12 Jan 2023 02:47:03 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9g69gNz4x1G for ; Thu, 12 Jan 2023 02:47:03 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX9g5Ss7z4xwp; Thu, 12 Jan 2023 02:47:03 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=vZfqua1J; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=B0eQZJ0h; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9g5My8z4x1G for ; Thu, 12 Jan 2023 02:47:03 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239465AbjAKPrC (ORCPT ); Wed, 11 Jan 2023 10:47:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbjAKPq1 (ORCPT ); Wed, 11 Jan 2023 10:46:27 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646583B924 for ; Wed, 11 Jan 2023 07:44:10 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1C41D4CDF; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451820; 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=qwczy+UDYj18TbxkAMvC7qrXX4CX2pJuDg23rlJQdPM=; b=vZfqua1J1aB7UkB1vojCo5+vp/U3fS6KbIXcHo6QSY4ksAEFO1g1NuEdEiV7JbL1mtyGPE F0Bb6XuwfT7uq241EsmLfxYmmFXYofsszaNRUUNFfX/tCKesf/y+oMcp4w3Ee+/qrOVpoZ 0gdwGXUw/zkUIFEVastbem3DP4psAi0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451820; 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=qwczy+UDYj18TbxkAMvC7qrXX4CX2pJuDg23rlJQdPM=; b=B0eQZJ0h1jlu7KRyoHORKamEm/jio9g8Zp7LBnShw37L2RMVpU8gxdpRcDh4tAmzMZU46z RvU9j4Rw3yb0egBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 035531358A; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sS3NACzZvmPOOwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:40 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 2D404A074F; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 5/7] ext4: Move page unlocking out of mpage_submit_page() Date: Wed, 11 Jan 2023 16:43:29 +0100 Message-Id: <20230111154338.392-5-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2463; i=jack@suse.cz; h=from:subject; bh=TIislCEYm8JsMX39PpjQA05elqHdpeu+/dFa5UWEXA8=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkhWeIvTZ+1zwsmoYXQLVOIZDuOo5IAGspUmIXx uGcdK52JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZIQAKCRCcnaoHP2RA2bSXCA Dlsmcj//cGTZzfF74CXFY1jhKOp/H4J8Kov2fYQ+hL8uQV3J3yk04jNNgg2ihR7OTnlJgBbkOst1WO bkeuNPuS2098qXxnTEVzpamHfBQKd0/hlfODnU8OX2GIC2XfHtDIkWzrOV7eKRIcpXGA91EhuMN2A8 k2NthuW4YooV7/gCRmIxkE+037OXtM/vuVL/z8SBl0M2hUWZSEtjRuVV4RCOMY510XpOgzYLzuqnJD RaG8MQSZGOCGZcqozIdMn2GsAdeq6AKu2pmPdeSyqb25mAyA1UQtTYnp/PurQC1eUD8CRcCTtmBVPQ 6pQkut2zP8znepRgrjn4xCuKufSqf2 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Move page unlocking during page writeback out of mpage_submit_page() into the callers. This will allow writeback in data=journal mode to keep the page locked for a bit longer. Since page unlocking it tightly connected to increment of mpd->first_page (as that determines cleanup of locked but unwritten pages), move page unlocking as well as mpd->first_page handling into a helper function. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 237880f0d406..28b59e078a1d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2083,6 +2083,12 @@ static int ext4_writepage(struct page *page, return ret; } +static void mpage_page_done(struct mpage_da_data *mpd, struct page *page) +{ + mpd->first_page++; + unlock_page(page); +} + static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page) { int len; @@ -2111,10 +2117,8 @@ static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page) else len = PAGE_SIZE; err = ext4_bio_write_page(&mpd->io_submit, page, len); - unlock_page(page); if (!err) mpd->wbc->nr_to_write--; - mpd->first_page++; return err; } @@ -2226,6 +2230,7 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, /* So far everything mapped? Submit the page for IO. */ if (mpd->map.m_len == 0) { err = mpage_submit_page(mpd, head->b_page); + mpage_page_done(mpd, head->b_page); if (err < 0) return err; } @@ -2357,6 +2362,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd) goto out; /* Page fully mapped - let IO run! */ err = mpage_submit_page(mpd, page); + mpage_page_done(mpd, page); if (err < 0) goto out; } @@ -2667,14 +2673,11 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) * modify metadata is simple. Just submit the page. */ if (!mpd->can_map) { - if (ext4_page_nomap_can_writeout(page)) { + if (ext4_page_nomap_can_writeout(page)) err = mpage_submit_page(mpd, page); - if (err < 0) - goto out; - } else { - unlock_page(page); - mpd->first_page++; - } + mpage_page_done(mpd, page); + if (err < 0) + goto out; } else { /* Add all dirty buffers to mpd */ lblk = ((ext4_lblk_t)page->index) << From patchwork Wed Jan 11 15:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=YyeYZkD7; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=l9l47LUK; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX8s3gRhz23fY for ; Thu, 12 Jan 2023 02:46:21 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8s3LNFz4xwp for ; Thu, 12 Jan 2023 02:46:21 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX8s3HgRz4xyF; Thu, 12 Jan 2023 02:46:21 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=YyeYZkD7; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=l9l47LUK; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX8s34Xqz4xwp for ; Thu, 12 Jan 2023 02:46:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235388AbjAKPqT (ORCPT ); Wed, 11 Jan 2023 10:46:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239479AbjAKPpm (ORCPT ); Wed, 11 Jan 2023 10:45:42 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0EF939FB6 for ; Wed, 11 Jan 2023 07:43:46 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 20FEE8B8D3; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451820; 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=/eDpHMFOwJ7Imien0QpSOQ3X4KMxSthjAjrPjJ/A2yw=; b=YyeYZkD7n5nSD58tK8w1PGsAiWyqYR2sorp6bweXNQwp5/6axd3vAVSCz+35OahwToKmDf wnuNj39+XPRrUrMTLpfqXA0GDVIiObI95W7Ld+JJANDR9T/HRyhouM5Nk2wy9NfnTOz+Jv pEwjGM0Nksp+7uRc8VBTlQhnPrx1w1s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451820; 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=/eDpHMFOwJ7Imien0QpSOQ3X4KMxSthjAjrPjJ/A2yw=; b=l9l47LUKAse16ObMufLnouCOE7p2hp2Op5gB78y5/0XAhYVFxTAwdKvQkqJTefoNLh/4ZD l4z9C5RmiG+JUTDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 06E8313594; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nV6jASzZvmPPOwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:40 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 32E2BA0752; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 6/7] ext4: Move mpage_page_done() calls after error handling Date: Wed, 11 Jan 2023 16:43:30 +0100 Message-Id: <20230111154338.392-6-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1987; i=jack@suse.cz; h=from:subject; bh=TTp6BPUOiVSDwO9eHBxXU6rfjaCY0QsiMMuLhfjClZ8=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkhpwZfI0H6Jz4ybZBzDI0gKM8BzgSWBcWS87ax zKzdMC+JATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZIQAKCRCcnaoHP2RA2aFACA CBqQfuJvLMZhMlayyZR8ApJF0iumvB3LKzxl1YwmHWBtRQHeE0LAQ9Y2ZpNujTuKhAPNzEWTCvFadM VAOkjPLF1p031gP/S0sNznDqWRjptO31vxvMu0fPt8k47G7sqevEnnGGEAauy6GDsqwLWumo4lditI RHfxtZWXl0xRPpEhlQimfcqtvJez7Jv/JLFqyF3lIso4UnjR1awjAnEPeGU0DBdooXjX1OJw/Twv1s Is1n+typtcmjonzjGB9k8Ram0N1C0fouPvNOQpcuNzg6LgK0pWoJJuE8M2hJMdB0YJamfGUXsdtKkl Q5rGFZX467qV42Du0jlrItaSA+m3t8 X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In case mpage_submit_page() returns error, it doesn't really matter whether we call mpage_page_done() and then return error or whether we return directly because in that case page cleanup will be done by mpage_release_unused_pages() instead. Logically, it makes more sense to leave the cleanup to mpage_release_unused_pages() because we didn't succeed in writing the page. So move mpage_page_done() calls after the error handling. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 28b59e078a1d..d0102b1c6b27 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2230,9 +2230,9 @@ static int mpage_process_page_bufs(struct mpage_da_data *mpd, /* So far everything mapped? Submit the page for IO. */ if (mpd->map.m_len == 0) { err = mpage_submit_page(mpd, head->b_page); - mpage_page_done(mpd, head->b_page); if (err < 0) return err; + mpage_page_done(mpd, head->b_page); } if (lblk >= blocks) { mpd->scanned_until_end = 1; @@ -2362,9 +2362,9 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd) goto out; /* Page fully mapped - let IO run! */ err = mpage_submit_page(mpd, page); - mpage_page_done(mpd, page); if (err < 0) goto out; + mpage_page_done(mpd, page); } folio_batch_release(&fbatch); } @@ -2673,11 +2673,12 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) * modify metadata is simple. Just submit the page. */ if (!mpd->can_map) { - if (ext4_page_nomap_can_writeout(page)) + if (ext4_page_nomap_can_writeout(page)) { err = mpage_submit_page(mpd, page); + if (err < 0) + goto out; + } mpage_page_done(mpd, page); - if (err < 0) - goto out; } else { /* Add all dirty buffers to mpd */ lblk = ((ext4_lblk_t)page->index) << From patchwork Wed Jan 11 15:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1724721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=h0bi=5i=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=RtxdyTgF; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=b/dT4Tnp; dkim-atps=neutral Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NsX9Q1k13z23fY for ; Thu, 12 Jan 2023 02:46:50 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9Q10myz4x1G for ; Thu, 12 Jan 2023 02:46:50 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4NsX9Q0y73z4xwp; Thu, 12 Jan 2023 02:46:50 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=RtxdyTgF; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=b/dT4Tnp; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NsX9P6YCCz4x1G for ; Thu, 12 Jan 2023 02:46:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233325AbjAKPqp (ORCPT ); Wed, 11 Jan 2023 10:46:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239479AbjAKPqV (ORCPT ); Wed, 11 Jan 2023 10:46:21 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2F8634D64 for ; Wed, 11 Jan 2023 07:44:02 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3919B4CE0; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1673451820; 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=qj0L5J96bfiQVal5kFTwhXukoOAkBQrSqdeQFL1mUEA=; b=RtxdyTgFw1W6dMGBYgXgwEdTlA/5CXoySyjJ26HfY3ztWMAu6zjHnbukAB/vh/NwXlgsI5 YxPBSeB5bD3NsGQlFEo7t4EKDH+u65SBz8ZOKvCpWW8Fg8M9xYAnrfc8Nfnx16uo49LgdY JtXR4B1bSyNbNv2XCiXjKWb/6rW7C60= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1673451820; 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=qj0L5J96bfiQVal5kFTwhXukoOAkBQrSqdeQFL1mUEA=; b=b/dT4TnpFfMhhXcrYn0Lvt75EBfK4o/jjAGLMB4qRQyYtZ0hOlhpNRWrK7ZbQkV57IAc0u mKakRd+GNg8+vVCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0B76B13595; Wed, 11 Jan 2023 15:43:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QijjAizZvmPQOwAAMHmgww (envelope-from ); Wed, 11 Jan 2023 15:43:40 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 39F0EA0754; Wed, 11 Jan 2023 16:43:38 +0100 (CET) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH 7/7] ext4: Convert data=journal writeback to use ext4_writepages() Date: Wed, 11 Jan 2023 16:43:31 +0100 Message-Id: <20230111154338.392-7-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230111152736.9608-1-jack@suse.cz> References: <20230111152736.9608-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=17128; i=jack@suse.cz; h=from:subject; bh=9Ztx3hvPLsY7OeD26m5+kSFK9FcSlJvM9/QRNPXZn68=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjvtkiTJovsCGMnhBjTqg6VfTuRIVKrZt9RWDkL3xR /z5mo6SJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCY77ZIgAKCRCcnaoHP2RA2RJeB/ 9jap3XQGaMDqGxfxq6+LfG2HCYXoXn20r2wxMzBlCRFGkgj68Z65fSO1nY80u5+eplK8BbCCJT8wbN ViSvOA/XEsru+kkNcwi7w1u/lzzgiLUOKT9+OGbjPEGhDO+ocT7zlWeIkq5esalp4PoNVbTtCna9Ce tv9TVF4GZnDy4WIu5JNGC7kYswpZPyzorU8K2X5ziqQZJ3sij8Z5dYQpxJWOxB+au8MsXHuVkuAbzX /SVRP33ES8j1/+hqn+DRg89wtRrh6jrx5YP1ipTw5DhPPMEoQf4r0Fr4oDQU4ZUSOgLhvoQFWaQmwL uwJn5vwJAvjknbSCEsX3toLv4YzO/U X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add support for writeback of journalled data directly into ext4_writepages() instead of offloading it to write_cache_pages(). This actually significantly simplifies the code and reduces code duplication. For checkpointing of committed data we can use ext4_writepages() rightaway the same way as writeback of ordered data uses it on transaction commit. For journalling of dirty mapped pages, we need to add a special case to mpage_prepare_extent_to_map() to add all page buffers to the journal. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 340 ++++++++++-------------------------- include/trace/events/ext4.h | 7 - 2 files changed, 90 insertions(+), 257 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d0102b1c6b27..b1bc4e8db6d8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -136,7 +136,6 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode, new_size); } -static int __ext4_journalled_writepage(struct page *page, unsigned int len); static int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents); @@ -1632,12 +1631,6 @@ static void ext4_print_free_blocks(struct inode *inode) return; } -static int ext4_bh_delay_or_unwritten(handle_t *handle, struct inode *inode, - struct buffer_head *bh) -{ - return (buffer_delay(bh) || buffer_unwritten(bh)) && buffer_dirty(bh); -} - /* * ext4_insert_delayed_block - adds a delayed block to the extents status * tree, incrementing the reserved cluster/block @@ -1870,219 +1863,6 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, return 0; } -static int __ext4_journalled_writepage(struct page *page, - unsigned int len) -{ - struct address_space *mapping = page->mapping; - struct inode *inode = mapping->host; - handle_t *handle = NULL; - int ret = 0, err = 0; - int inline_data = ext4_has_inline_data(inode); - struct buffer_head *inode_bh = NULL; - loff_t size; - - ClearPageChecked(page); - - if (inline_data) { - BUG_ON(page->index != 0); - BUG_ON(len > ext4_get_max_inline_size(inode)); - inode_bh = ext4_journalled_write_inline_data(inode, len, page); - if (inode_bh == NULL) - goto out; - } - /* - * We need to release the page lock before we start the - * journal, so grab a reference so the page won't disappear - * out from under us. - */ - get_page(page); - unlock_page(page); - - handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, - ext4_writepage_trans_blocks(inode)); - if (IS_ERR(handle)) { - ret = PTR_ERR(handle); - put_page(page); - goto out_no_pagelock; - } - BUG_ON(!ext4_handle_valid(handle)); - - lock_page(page); - put_page(page); - size = i_size_read(inode); - if (page->mapping != mapping || page_offset(page) > size) { - /* The page got truncated from under us */ - ext4_journal_stop(handle); - ret = 0; - goto out; - } - - if (inline_data) { - ret = ext4_mark_inode_dirty(handle, inode); - } else { - struct buffer_head *page_bufs = page_buffers(page); - - if (page->index == size >> PAGE_SHIFT) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; - - ret = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, - NULL, do_journal_get_write_access); - - err = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, - NULL, write_end_fn); - } - if (ret == 0) - ret = err; - err = ext4_jbd2_inode_add_write(handle, inode, page_offset(page), len); - if (ret == 0) - ret = err; - EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; - err = ext4_journal_stop(handle); - if (!ret) - ret = err; - - ext4_set_inode_state(inode, EXT4_STATE_JDATA); -out: - unlock_page(page); -out_no_pagelock: - brelse(inode_bh); - return ret; -} - -/* - * Note that we don't need to start a transaction unless we're journaling data - * because we should have holes filled from ext4_page_mkwrite(). We even don't - * need to file the inode to the transaction's list in ordered mode because if - * we are writing back data added by write(), the inode is already there and if - * we are writing back data modified via mmap(), no one guarantees in which - * transaction the data will hit the disk. In case we are journaling data, we - * cannot start transaction directly because transaction start ranks above page - * lock so we have to do some magic. - * - * This function can get called via... - * - ext4_writepages after taking page lock (have journal handle) - * - journal_submit_inode_data_buffers (no journal handle) - * - shrink_page_list via the kswapd/direct reclaim (no journal handle) - * - grab_page_cache when doing write_begin (have journal handle) - * - * We don't do any block allocation in this function. If we have page with - * multiple blocks we need to write those buffer_heads that are mapped. This - * is important for mmaped based write. So if we do with blocksize 1K - * truncate(f, 1024); - * a = mmap(f, 0, 4096); - * a[0] = 'a'; - * truncate(f, 4096); - * we have in the page first buffer_head mapped via page_mkwrite call back - * but other buffer_heads would be unmapped but dirty (dirty done via the - * do_wp_page). So writepage should write the first block. If we modify - * the mmap area beyond 1024 we will again get a page_fault and the - * page_mkwrite callback will do the block allocation and mark the - * buffer_heads mapped. - * - * We redirty the page if we have any buffer_heads that is either delay or - * unwritten in the page. - * - * We can get recursively called as show below. - * - * ext4_writepage() -> kmalloc() -> __alloc_pages() -> page_launder() -> - * ext4_writepage() - * - * But since we don't do any block allocation we should not deadlock. - * Page also have the dirty flag cleared so we don't get recurive page_lock. - */ -static int ext4_writepage(struct page *page, - struct writeback_control *wbc) -{ - struct folio *folio = page_folio(page); - int ret = 0; - loff_t size; - unsigned int len; - struct buffer_head *page_bufs = NULL; - struct inode *inode = page->mapping->host; - struct ext4_io_submit io_submit; - - if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) { - folio_invalidate(folio, 0, folio_size(folio)); - folio_unlock(folio); - return -EIO; - } - - trace_ext4_writepage(page); - size = i_size_read(inode); - if (page->index == size >> PAGE_SHIFT && - !ext4_verity_in_progress(inode)) - len = size & ~PAGE_MASK; - else - len = PAGE_SIZE; - - /* Should never happen but for bugs in other kernel subsystems */ - if (!page_has_buffers(page)) { - ext4_warning_inode(inode, - "page %lu does not have buffers attached", page->index); - ClearPageDirty(page); - unlock_page(page); - return 0; - } - - page_bufs = page_buffers(page); - /* - * We cannot do block allocation or other extent handling in this - * function. If there are buffers needing that, we have to redirty - * the page. But we may reach here when we do a journal commit via - * journal_submit_inode_data_buffers() and in that case we must write - * allocated buffers to achieve data=ordered mode guarantees. - * - * Also, if there is only one buffer per page (the fs block - * size == the page size), if one buffer needs block - * allocation or needs to modify the extent tree to clear the - * unwritten flag, we know that the page can't be written at - * all, so we might as well refuse the write immediately. - * Unfortunately if the block size != page size, we can't as - * easily detect this case using ext4_walk_page_buffers(), but - * for the extremely common case, this is an optimization that - * skips a useless round trip through ext4_bio_write_page(). - */ - if (ext4_walk_page_buffers(NULL, inode, page_bufs, 0, len, NULL, - ext4_bh_delay_or_unwritten)) { - redirty_page_for_writepage(wbc, page); - if ((current->flags & PF_MEMALLOC) || - (inode->i_sb->s_blocksize == PAGE_SIZE)) { - /* - * For memory cleaning there's no point in writing only - * some buffers. So just bail out. Warn if we came here - * from direct reclaim. - */ - WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD)) - == PF_MEMALLOC); - unlock_page(page); - return 0; - } - } - - if (PageChecked(page) && ext4_should_journal_data(inode)) - /* - * It's mmapped pagecache. Add buffers and journal it. There - * doesn't seem much point in redirtying the page here. - */ - return __ext4_journalled_writepage(page, len); - - ext4_io_submit_init(&io_submit, wbc); - io_submit.io_end = ext4_init_io_end(inode, GFP_NOFS); - if (!io_submit.io_end) { - redirty_page_for_writepage(wbc, page); - unlock_page(page); - return -ENOMEM; - } - ret = ext4_bio_write_page(&io_submit, page, len); - unlock_page(page); - ext4_io_submit(&io_submit); - /* Drop io_end reference we got from init */ - ext4_put_io_end_defer(io_submit.io_end); - return ret; -} - static void mpage_page_done(struct mpage_da_data *mpd, struct page *page) { mpd->first_page++; @@ -2563,6 +2343,50 @@ static bool ext4_page_nomap_can_writeout(struct page *page) return false; } +static int ext4_journal_page_buffers(handle_t *handle, struct page *page, + int len) +{ + struct buffer_head *page_bufs = page_buffers(page); + struct inode *inode = page->mapping->host; + int ret, err; + + ret = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, + NULL, do_journal_get_write_access); + err = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, + NULL, write_end_fn); + if (ret == 0) + ret = err; + err = ext4_jbd2_inode_add_write(handle, inode, page_offset(page), len); + if (ret == 0) + ret = err; + EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; + + ext4_set_inode_state(inode, EXT4_STATE_JDATA); + + return ret; +} + +static int mpage_journal_page_buffers(handle_t *handle, + struct mpage_da_data *mpd, + struct page *page) +{ + struct inode *inode = mpd->inode; + loff_t size = i_size_read(inode); + int len; + + ClearPageChecked(page); + clear_page_dirty_for_io(page); + mpd->wbc->nr_to_write--; + + if (page->index == size >> PAGE_SHIFT && + !ext4_verity_in_progress(inode)) + len = size & ~PAGE_MASK; + else + len = PAGE_SIZE; + + return ext4_journal_page_buffers(handle, page, len); +} + /* * mpage_prepare_extent_to_map - find & lock contiguous range of dirty pages * needing mapping, submit mapped pages @@ -2595,12 +2419,20 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) int blkbits = mpd->inode->i_blkbits; ext4_lblk_t lblk; struct buffer_head *head; + handle_t *handle = NULL; + int bpp = ext4_journal_blocks_per_page(mpd->inode); if (mpd->wbc->sync_mode == WB_SYNC_ALL || mpd->wbc->tagged_writepages) tag = PAGECACHE_TAG_TOWRITE; else tag = PAGECACHE_TAG_DIRTY; + if (ext4_should_journal_data(mpd->inode)) { + handle = ext4_journal_start(mpd->inode, EXT4_HT_WRITE_PAGE, + bpp); + if (IS_ERR(handle)) + return PTR_ERR(handle); + } pagevec_init(&pvec); mpd->map.m_len = 0; mpd->next_page = index; @@ -2630,6 +2462,13 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) if (mpd->map.m_len > 0 && mpd->next_page != page->index) goto out; + if (handle) { + err = ext4_journal_ensure_credits(handle, bpp, + 0); + if (err < 0) + goto out; + } + lock_page(page); /* * If the page is no longer dirty, or its mapping no @@ -2669,8 +2508,15 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) mpd->first_page = page->index; mpd->next_page = page->index + 1; /* - * Writeout for transaction commit where we cannot - * modify metadata is simple. Just submit the page. + * Writeout when we cannot modify metadata is simple. + * Just submit the page. For data=journal mode we + * first handle writeout of the page for checkpoint and + * only after that handle delayed page dirtying. This + * is crutial so that forcing a transaction commit and + * then calling filemap_write_and_wait() guarantees + * current state of data is in its final location. Such + * sequence is used for example by insert/collapse + * range operations before discarding the page cache. */ if (!mpd->can_map) { if (ext4_page_nomap_can_writeout(page)) { @@ -2678,6 +2524,13 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) if (err < 0) goto out; } + /* Pending dirtying of journalled data? */ + if (PageChecked(page)) { + err = mpage_journal_page_buffers(handle, + mpd, page); + if (err < 0) + goto out; + } mpage_page_done(mpd, page); } else { /* Add all dirty buffers to mpd */ @@ -2695,18 +2548,16 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) cond_resched(); } mpd->scanned_until_end = 1; + if (handle) + ext4_journal_stop(handle); return 0; out: pagevec_release(&pvec); + if (handle) + ext4_journal_stop(handle); return err; } -static int ext4_writepage_cb(struct page *page, struct writeback_control *wbc, - void *data) -{ - return ext4_writepage(page, wbc); -} - static int ext4_do_writepages(struct mpage_da_data *mpd) { struct writeback_control *wbc = mpd->wbc; @@ -2732,13 +2583,6 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) goto out_writepages; - if (ext4_should_journal_data(inode)) { - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, ext4_writepage_cb, NULL); - blk_finish_plug(&plug); - goto out_writepages; - } - /* * If the filesystem has aborted, it is read-only, so return * right away instead of dumping stack traces later on that @@ -2773,6 +2617,13 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) ext4_journal_stop(handle); } + /* + * data=journal mode does not do delalloc so we just need to writeout / + * journal already mapped buffers + */ + if (ext4_should_journal_data(inode)) + mpd->can_map = 0; + if (ext4_should_dioread_nolock(inode)) { /* * We may need to convert up to one extent per block in @@ -3149,9 +3000,8 @@ static int ext4_da_write_end(struct file *file, * i_disksize since writeback will push i_disksize upto i_size * eventually. If the end of the current write is > i_size and * inside an allocated block (ext4_da_should_update_i_disksize() - * check), we need to update i_disksize here as neither - * ext4_writepage() nor certain ext4_writepages() paths not - * allocating blocks update i_disksize. + * check), we need to update i_disksize here as certain + * ext4_writepages() paths not allocating blocks update i_disksize. * * Note that we defer inode dirtying to generic_write_end() / * ext4_da_write_inline_data_end(). @@ -5373,7 +5223,7 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode) * If the folio is fully truncated, we don't need to wait for any commit * (and we even should not as __ext4_journalled_invalidate_folio() may * strip all buffers from the folio but keep the folio dirty which can then - * confuse e.g. concurrent ext4_writepage() seeing dirty folio without + * confuse e.g. concurrent ext4_writepages() seeing dirty folio without * buffers). Also we don't need to wait for any commit if all buffers in * the folio remain valid. This is most beneficial for the common case of * blocksize == PAGESIZE. @@ -6311,18 +6161,8 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) err = __block_write_begin(page, 0, len, ext4_get_block); if (!err) { ret = VM_FAULT_SIGBUS; - if (ext4_walk_page_buffers(handle, inode, - page_buffers(page), 0, len, NULL, - do_journal_get_write_access)) - goto out_error; - if (ext4_walk_page_buffers(handle, inode, - page_buffers(page), 0, len, NULL, - write_end_fn)) - goto out_error; - if (ext4_jbd2_inode_add_write(handle, inode, - page_offset(page), len)) + if (ext4_journal_page_buffers(handle, page, len)) goto out_error; - ext4_set_inode_state(inode, EXT4_STATE_JDATA); } else { unlock_page(page); } diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h index 77b426ae0064..ebccf6a6aa1b 100644 --- a/include/trace/events/ext4.h +++ b/include/trace/events/ext4.h @@ -584,13 +584,6 @@ DECLARE_EVENT_CLASS(ext4__page_op, (unsigned long) __entry->index) ); -DEFINE_EVENT(ext4__page_op, ext4_writepage, - - TP_PROTO(struct page *page), - - TP_ARGS(page) -); - DEFINE_EVENT(ext4__page_op, ext4_readpage, TP_PROTO(struct page *page),