From patchwork Tue Mar 8 16:33:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1603081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kPNd71QY; 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCgrC3vtmz9sGD for ; Wed, 9 Mar 2022 03:33:47 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4KCgr75X5Dz4xxt for ; Wed, 9 Mar 2022 03:33:43 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4KCgr75V5wz4xxx; Wed, 9 Mar 2022 03:33:43 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org 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 (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=kPNd71QY; 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 4KCgr75JMvz4xxt for ; Wed, 9 Mar 2022 03:33:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348345AbiCHQei (ORCPT ); Tue, 8 Mar 2022 11:34:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348353AbiCHQeg (ORCPT ); Tue, 8 Mar 2022 11:34:36 -0500 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3311B50479 for ; Tue, 8 Mar 2022 08:33:36 -0800 (PST) Received: by mail-pf1-x42a.google.com with SMTP id d17so8935785pfv.6 for ; Tue, 08 Mar 2022 08:33:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z3g8xwiafbXVjM4nIfugn8PU3H0lmTrt8i93qpTMpsU=; b=kPNd71QY8yX0JZH7dwltpUDI1Bc94mo4aoewcV034X5bFXqXjzt7Qsb2ga357Dadln RWd2oSRGnLFKcgHlvDBXtmqwln9UadXDgc7kEhSYK3xv+0ktpwe6jZcvhws+7Yh6KXzO rUZytw71w6Q5k6pE7UYYnMcMkXhy9+StgEKUQsrfnkUm/HVRTVdX2lKKuud/RKaNpyq7 Uj6Qah2XGzX55GojS2iyeM6rBw6VcSmmCIBef9SSHhSTqNxJU7vyNxBHDgZu5akjH1Lk qMgVQd9y4R0Smv2pkaOR93W0SAuZW9Dr08D3st5i0kqJBp8HFX/dzO+LxYM85oTjZoNU EmKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z3g8xwiafbXVjM4nIfugn8PU3H0lmTrt8i93qpTMpsU=; b=Ezj7lpwzywAayxisfuUj9Rj6rwyAiXZ9CK4Lj6LB+oPaGC5N5IOay3qezPBmO6IvCX 27LPaGcUtAdRNQWfva/dcM/hDpl9TuufB3e1hSpGfyprZnYXEz8C+CCTJ1+vob1jUP8+ +T0Tf4+PfLIJoXb40Y1mcWw8ZhYdZgE+f5tF/5YfWzi/Uq6DICr5HtZY6RYW69l4wmYH DhyYh27OR5UAC5nYG5B/gQFQjEdhN8qMAh5LjLN3RR8QJFy9wBZVGgZP0cKOAjRMlnaX 4XRDOTFYsQX8XhCUYLwRk9zGpJgrnkJDwgHlVV0D+om5sSYghgJu9qC+/7dR6EI77dgK 64Vw== X-Gm-Message-State: AOAM5301bIdHAmwn1TonDwZyaYkLiuCUVYKh4XBs6NBrcDpfBivALhwz Zuga1AndV9yJMrP+eGvYDyRu7oZfPAbJBGdO X-Google-Smtp-Source: ABdhPJxgpbk9QXAAUrNCxtjN9ENLaGrETZQA1eDUZfo0T9DNLWrniAH95ZKs6MBcwDf4qaA88vZtYw== X-Received: by 2002:a62:8ccb:0:b0:4f6:ee14:9c1e with SMTP id m194-20020a628ccb000000b004f6ee149c1emr14367038pfd.19.1646757215098; Tue, 08 Mar 2022 08:33:35 -0800 (PST) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:c24c:d8e5:a9be:227]) by smtp.googlemail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm4517720pja.3.2022.03.08.08.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:33:34 -0800 (PST) From: Harshad Shirwadkar X-Google-Original-From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu, Harshad Shirwadkar Subject: [PATCH v2 1/5] ext4: convert i_fc_lock to spinlock Date: Tue, 8 Mar 2022 08:33:15 -0800 Message-Id: <20220308163319.1183625-2-harshads@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308163319.1183625-1-harshads@google.com> References: <20220308163319.1183625-1-harshads@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Harshad Shirwadkar Convert ext4_inode_info->i_fc_lock to spinlock to avoid sleeping in invalid contexts. Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 7 +++++-- fs/ext4/fast_commit.c | 28 +++++++++++++++------------- fs/ext4/super.c | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 3f87cca49f0c..fb6d65f1176f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1065,8 +1065,11 @@ struct ext4_inode_info { /* Fast commit wait queue for this inode */ wait_queue_head_t i_fc_wait; - /* Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len */ - struct mutex i_fc_lock; + /* + * Protect concurrent accesses on i_fc_lblk_start, i_fc_lblk_len + * and inode's EXT4_FC_STATE_COMMITTING state bit. + */ + spinlock_t i_fc_lock; /* * i_disksize keeps track of what the inode size is ON DISK, not diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 5ac594e03402..9913de655b61 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -387,7 +387,7 @@ static int ext4_fc_track_template( return -EINVAL; tid = handle->h_transaction->t_tid; - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); if (tid == ei->i_sync_tid) { update = true; } else { @@ -395,7 +395,7 @@ static int ext4_fc_track_template( ei->i_sync_tid = tid; } ret = __fc_track_fn(inode, args, update); - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); if (!enqueue) return ret; @@ -427,11 +427,11 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) struct dentry *dentry = dentry_update->dentry; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); node = kmem_cache_alloc(ext4_fc_dentry_cachep, GFP_NOFS); if (!node) { ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -ENOMEM; } @@ -444,7 +444,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) kmem_cache_free(ext4_fc_dentry_cachep, node); ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return -ENOMEM; } memcpy((u8 *)node->fcd_name.name, dentry->d_name.name, @@ -478,7 +478,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) list_add_tail(&node->fcd_dilist, &ei->i_fc_dilist); } spin_unlock(&sbi->s_fc_lock); - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); return 0; } @@ -580,10 +580,8 @@ static int __track_range(struct inode *inode, void *arg, bool update) struct __track_range_args *__arg = (struct __track_range_args *)arg; - if (inode->i_ino < EXT4_FIRST_INO(inode->i_sb)) { - ext4_debug("Special inode %ld being modified\n", inode->i_ino); + if (inode->i_ino < EXT4_FIRST_INO(inode->i_sb)) return -ECANCELED; - } oldstart = ei->i_fc_lblk_start; @@ -867,15 +865,15 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) struct ext4_extent *ex; int ret; - mutex_lock(&ei->i_fc_lock); + spin_lock(&ei->i_fc_lock); if (ei->i_fc_lblk_len == 0) { - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); return 0; } old_blk_size = ei->i_fc_lblk_start; new_blk_size = ei->i_fc_lblk_start + ei->i_fc_lblk_len - 1; ei->i_fc_lblk_len = 0; - mutex_unlock(&ei->i_fc_lock); + spin_unlock(&ei->i_fc_lock); cur_lblk_off = old_blk_size; jbd_debug(1, "%s: will try writing %d to %d for inode %ld\n", @@ -972,9 +970,13 @@ static int ext4_fc_wait_inode_data_all(journal_t *journal) spin_lock(&sbi->s_fc_lock); list_for_each_entry_safe(pos, n, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + spin_lock(&pos->i_fc_lock); if (!ext4_test_inode_state(&pos->vfs_inode, - EXT4_STATE_FC_COMMITTING)) + EXT4_STATE_FC_COMMITTING)) { + spin_unlock(&pos->i_fc_lock); continue; + } + spin_unlock(&pos->i_fc_lock); spin_unlock(&sbi->s_fc_lock); ret = jbd2_wait_inode_data(journal, pos->jinode); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 1e5f4994fe57..38d63113c383 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1346,7 +1346,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) atomic_set(&ei->i_unwritten, 0); INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); ext4_fc_init_inode(&ei->vfs_inode); - mutex_init(&ei->i_fc_lock); + spin_lock_init(&ei->i_fc_lock); return &ei->vfs_inode; } From patchwork Tue Mar 8 16:33:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1603083 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qaVXWhvJ; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCgrF2kNwz9sG9 for ; Wed, 9 Mar 2022 03:33:49 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4KCgrD41gfz4xcd for ; Wed, 9 Mar 2022 03:33:48 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4KCgrD3zkXz4xv3; Wed, 9 Mar 2022 03:33:48 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org 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 (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qaVXWhvJ; 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 4KCgrD3tPPz4xcd for ; Wed, 9 Mar 2022 03:33:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348357AbiCHQen (ORCPT ); Tue, 8 Mar 2022 11:34:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348358AbiCHQej (ORCPT ); Tue, 8 Mar 2022 11:34:39 -0500 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B88C050E09 for ; Tue, 8 Mar 2022 08:33:37 -0800 (PST) Received: by mail-pl1-x62d.google.com with SMTP id z3so9070824plg.8 for ; Tue, 08 Mar 2022 08:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IhGSBme3jnSuRV07Q4H/MQOgwQep++URNvm38wnCKNQ=; b=qaVXWhvJyxoJzb2pQj2u3B5GdBEZLXBtEJRVjcJ6Q4B+8WAVtbN63IIqBVurfbCNcX RqSQmd63oFZbH+bG5Ux7Fs5Ri9/LH/uitxAYkMlEd8WtTkjcI/vpwtQ9Ktam1uwCz2IZ 2Y/Nn10JSKUskjPDU3hKv/mkdT2+p46crD5oNYAQcCPTo8p0Mk+EJJbN9Ba2asVDMRw2 DCsvOQu/mdKy8GOhqdOpQeAuP2pkf2Aq1tIq8UOiaeD/pPIdjXOh9GQLUuf1JMFQjMAG gYpySp0uKdMW+zsVjTGjTp7K1SrOQMBuAS8+nJsXUAZKyhMBHikc2MZaJgMPgV/p0lBH cucA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IhGSBme3jnSuRV07Q4H/MQOgwQep++URNvm38wnCKNQ=; b=d8d1O0jUVHN9KElG+tgRhleJTowWkgpi9Q0iXiTa9j61Pmt9idlCkrrGfFWqsg4ur0 xEmXbjMyRpYmdiN9s60f4J2d5FaMxKfkIgVsO4EXUfiAXPAq7rrN9fG+eJnakP0Y0+dm 9WC6BCMxb/WACLNx2n4zX3CbMrYjWnNxEDdpXM0o+ucc+P0hrWGtZXWvXV1qs+IJVFbC ihOa1aEkdx7aTG6hwBFottWHGvUeuP4+zTYM+hDFbPzknGlUBBD2anBk4xy++qz++pNV yHIBm5CJB3Dw0gqLKEZdcywvZqQ6U0kNd7khXz1X3LyZWKPeK4GwvXrVK0489BVEeN45 10uA== X-Gm-Message-State: AOAM533ow3Z0Tx/yzakGlI/RNC66y6PZHlJKOuuTRHz+WNi+5nyRKOaN CTkZOYAvPuD7u/kX8T87EA0WvpPm4c+80whG X-Google-Smtp-Source: ABdhPJy+TfHh5i31QWUypBwpHu0zhtGmwajbAy0IcUdCVmnAvjHah3DkX4Ksvycrx2MW/j9WYG9VKA== X-Received: by 2002:a17:902:cf03:b0:14d:880d:75b5 with SMTP id i3-20020a170902cf0300b0014d880d75b5mr18464870plg.129.1646757216519; Tue, 08 Mar 2022 08:33:36 -0800 (PST) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:c24c:d8e5:a9be:227]) by smtp.googlemail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm4517720pja.3.2022.03.08.08.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:33:35 -0800 (PST) From: Harshad Shirwadkar X-Google-Original-From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu, Harshad Shirwadkar Subject: [PATCH v2 2/5] ext4: for committing inode, make ext4_fc_track_inode wait Date: Tue, 8 Mar 2022 08:33:16 -0800 Message-Id: <20220308163319.1183625-3-harshads@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308163319.1183625-1-harshads@google.com> References: <20220308163319.1183625-1-harshads@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Harshad Shirwadkar If the inode that's being requested to track using ext4_fc_track_inode is being committed, then wait until the inode finishes the commit. Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4_jbd2.c | 12 ++++++++++++ fs/ext4/ext4_jbd2.h | 13 ++++--------- fs/ext4/fast_commit.c | 28 ++++++++++++++++++++++++++++ fs/ext4/inode.c | 3 ++- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 3477a16d08ae..7fa301b0a35a 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -106,6 +106,18 @@ handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line, GFP_NOFS, type, line); } +handle_t *__ext4_journal_start(struct inode *inode, unsigned int line, + int type, int blocks, int rsv_blocks, + int revoke_creds) +{ + handle_t *handle = __ext4_journal_start_sb(inode->i_sb, line, + type, blocks, rsv_blocks, + revoke_creds); + if (ext4_handle_valid(handle) && !IS_ERR(handle)) + ext4_fc_track_inode(handle, inode); + return handle; +} + int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle) { struct super_block *sb; diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index db2ae4a2b38d..e408622fe896 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -302,6 +302,10 @@ static inline int ext4_trans_default_revoke_credits(struct super_block *sb) return ext4_free_metadata_revoke_credits(sb, 8); } +handle_t *__ext4_journal_start(struct inode *inode, unsigned int line, + int type, int blocks, int rsv_blocks, + int revoke_creds); + #define ext4_journal_start_sb(sb, type, nblocks) \ __ext4_journal_start_sb((sb), __LINE__, (type), (nblocks), 0, \ ext4_trans_default_revoke_credits(sb)) @@ -318,15 +322,6 @@ static inline int ext4_trans_default_revoke_credits(struct super_block *sb) __ext4_journal_start((inode), __LINE__, (type), (blocks), 0, \ (revoke_creds)) -static inline handle_t *__ext4_journal_start(struct inode *inode, - unsigned int line, int type, - int blocks, int rsv_blocks, - int revoke_creds) -{ - return __ext4_journal_start_sb(inode->i_sb, line, type, blocks, - rsv_blocks, revoke_creds); -} - #define ext4_journal_stop(handle) \ __ext4_journal_stop(__func__, __LINE__, (handle)) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 9913de655b61..be8c5b3456ec 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -551,8 +551,14 @@ static int __track_inode(struct inode *inode, void *arg, bool update) return 0; } +/* + * Track inode as part of the next fast commit. If the inode is being + * committed, this function will wait for the commit to finish. + */ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) { + struct ext4_inode_info *ei = EXT4_I(inode); + wait_queue_head_t *wq; int ret; if (S_ISDIR(inode->i_mode)) @@ -564,6 +570,28 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) return; } + if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || + (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)) + return; + + while (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { +#if (BITS_PER_LONG < 64) + DEFINE_WAIT_BIT(wait, &ei->i_state_flags, + EXT4_STATE_FC_COMMITTING); + wq = bit_waitqueue(&ei->i_state_flags, + EXT4_STATE_FC_COMMITTING); +#else + DEFINE_WAIT_BIT(wait, &ei->i_flags, + EXT4_STATE_FC_COMMITTING); + wq = bit_waitqueue(&ei->i_flags, + EXT4_STATE_FC_COMMITTING); +#endif + prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); + if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) + schedule(); + finish_wait(wq, &wait.wq_entry); + } + ret = ext4_fc_track_template(handle, inode, __track_inode, NULL, 1); trace_ext4_fc_track_inode(inode, ret); } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 531a94f48637..7a01f5bd377c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -629,6 +629,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, * with create == 1 flag. */ down_write(&EXT4_I(inode)->i_data_sem); + ext4_fc_track_inode(handle, inode); /* * We need to check for EXT4 here because migrate @@ -5690,7 +5691,6 @@ int ext4_mark_iloc_dirty(handle_t *handle, put_bh(iloc->bh); return -EIO; } - ext4_fc_track_inode(handle, inode); if (IS_I_VERSION(inode)) inode_inc_iversion(inode); @@ -5727,6 +5727,7 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode, brelse(iloc->bh); iloc->bh = NULL; } + ext4_fc_track_inode(handle, inode); } ext4_std_error(inode->i_sb, err); return err; From patchwork Tue Mar 8 16:33:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1603085 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=KrYwhZRo; 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCgrG5hbpz9sGD for ; Wed, 9 Mar 2022 03:33: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 4KCgrG522Jz4xcd for ; Wed, 9 Mar 2022 03:33:50 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4KCgrG4Vr4z4xv3; Wed, 9 Mar 2022 03:33:50 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org 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 (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=KrYwhZRo; 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 4KCgrG4RZBz4xcd for ; Wed, 9 Mar 2022 03:33:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348354AbiCHQep (ORCPT ); Tue, 8 Mar 2022 11:34:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348365AbiCHQem (ORCPT ); Tue, 8 Mar 2022 11:34:42 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3042F50E0B for ; Tue, 8 Mar 2022 08:33:39 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id c11so4524993pgu.11 for ; Tue, 08 Mar 2022 08:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hkBFK5UIhzAU2q83FdXV4SDp4KTiJVRQe1MMt7tEGKE=; b=KrYwhZRoWC/yYQXwBjPcxK3/fRYkfhNbJ87NtTHlSwHK8jCO0QroDNtj3XQ4pAwgwX qETm08mp7Uj6SlK2/MIWb7cQRnvWygNk6/BP+GQY5zsuhPvwNeV7sa4bqFfSU7H+A4Yj YgC9CQc84M4FTJ8cNuJWVTP0JkfC0hk+m5f14op/X+/kc9l9vT9GxxJxPx30gcQ2tLja KBAmxP3xHyzgZkOZ8eOxmKmESeRfliewZM5NJr/7Ueznz32dd3MFxZZRenMV7h+PCFop fdD0+i1NBM/92mZqTZp5+L7iHqjw7r6LlLpc+Rr4N7AqpF/R7bGYt5epxoc4gdWdKVYD v5jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hkBFK5UIhzAU2q83FdXV4SDp4KTiJVRQe1MMt7tEGKE=; b=vwB5HlTKPOp4NU3b1URiJpYijg5cnZ/BXf91e/yNI7QnGbiTk6Yx5qFtPIfygxo5ol XBZHsltAePfjjX/jFBaM8aPFsZM9KlcilKqVXjHKV9+SvbWLKXGtiq0HGIqvlPJLxpFf DVpFeEMypVCD5b0Wgf0Pmnc0lNJn9Z5AoZhO53MHIG9Ahx+dnOsBTuRyeB5gm8WFN8oR ECLlvPLyCnbsH1UNQTWC1qQs/7cxw3TVttUeyrwxBnJDYiA6eXYVcbX2kyLQkHjYE48q PkaUVuoUTs6vPPWLhnOs10hVgYbfP1j7rho0BKPJk7x47ZzuSsMc+oGKYDLw2MRhQo2n h2uw== X-Gm-Message-State: AOAM530cdlsCUdD6yj1fFUw2VEaBSMCo2RS9v5CA5HLdp11TqIRALdz3 mF3BPi+z7WmoM+jIsTmNmxdid95IhZQEsIW4 X-Google-Smtp-Source: ABdhPJyIgxKXoUtmR3sWMWpj42TJAcr+WtuaMr7KI3qd3KbL355F8OSd2Iwyta2UoUke58CTrXpCjQ== X-Received: by 2002:a05:6a00:1146:b0:4c9:ede0:725a with SMTP id b6-20020a056a00114600b004c9ede0725amr19420303pfm.35.1646757218072; Tue, 08 Mar 2022 08:33:38 -0800 (PST) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:c24c:d8e5:a9be:227]) by smtp.googlemail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm4517720pja.3.2022.03.08.08.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:33:36 -0800 (PST) From: Harshad Shirwadkar X-Google-Original-From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu, Harshad Shirwadkar Subject: [PATCH v2 3/5] ext4: rework fast commit commit path Date: Tue, 8 Mar 2022 08:33:17 -0800 Message-Id: <20220308163319.1183625-4-harshads@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308163319.1183625-1-harshads@google.com> References: <20220308163319.1183625-1-harshads@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Harshad Shirwadkar This patch reworks fast commit's commit path to remove locking the journal for the entire duration of a fast commit. Instead, we only lock the journal while marking all the eligible inodes as "committing". This allows handles to make progress in parallel with the fast commit. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/fast_commit.c | 77 ++++++++++++++++++++++++++----------------- fs/jbd2/journal.c | 2 -- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index be8c5b3456ec..eedcf8b4d47b 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -287,20 +287,30 @@ void ext4_fc_del(struct inode *inode) (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)) return; -restart: spin_lock(&EXT4_SB(inode->i_sb)->s_fc_lock); if (list_empty(&ei->i_fc_list) && list_empty(&ei->i_fc_dilist)) { spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); return; } - if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { - ext4_fc_wait_committing_inode(inode); - goto restart; - } - - if (!list_empty(&ei->i_fc_list)) - list_del_init(&ei->i_fc_list); + /* + * Since ext4_fc_del is called from ext4_evict_inode while having a + * handle open, there is no need for us to wait here even if a fast + * commit is going on. That is because, if this inode is being + * committed, ext4_mark_inode_dirty would have waited for inode commit + * operation to finish before we come here. So, by the time we come + * here, inode's EXT4_STATE_FC_COMMITTING would have been cleared. So, + * we shouldn't see EXT4_STATE_FC_COMMITTING to be set on this inode + * here. + * + * We may come here without any handles open in the "no_delete" case of + * ext4_evict_inode as well. However, if that happens, we first mark the + * file system as fast commit ineligible anyway. So, even in that case, + * it is okay to remove the inode from the fc list. + */ + WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING) + && !ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)); + list_del_init(&ei->i_fc_list); /* * Since this inode is getting removed, let's also remove all FC @@ -323,8 +333,6 @@ void ext4_fc_del(struct inode *inode) fc_dentry->fcd_name.len > DNAME_INLINE_LEN) kfree(fc_dentry->fcd_name.name); kmem_cache_free(ext4_fc_dentry_cachep, fc_dentry); - - return; } /* @@ -964,19 +972,6 @@ static int ext4_fc_submit_inode_data_all(journal_t *journal) spin_lock(&sbi->s_fc_lock); list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - ext4_set_inode_state(&ei->vfs_inode, EXT4_STATE_FC_COMMITTING); - while (atomic_read(&ei->i_fc_updates)) { - DEFINE_WAIT(wait); - - prepare_to_wait(&ei->i_fc_wait, &wait, - TASK_UNINTERRUPTIBLE); - if (atomic_read(&ei->i_fc_updates)) { - spin_unlock(&sbi->s_fc_lock); - schedule(); - spin_lock(&sbi->s_fc_lock); - } - finish_wait(&ei->i_fc_wait, &wait); - } spin_unlock(&sbi->s_fc_lock); ret = jbd2_submit_inode_data(ei->jinode); if (ret) @@ -998,13 +993,9 @@ static int ext4_fc_wait_inode_data_all(journal_t *journal) spin_lock(&sbi->s_fc_lock); list_for_each_entry_safe(pos, n, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - spin_lock(&pos->i_fc_lock); if (!ext4_test_inode_state(&pos->vfs_inode, - EXT4_STATE_FC_COMMITTING)) { - spin_unlock(&pos->i_fc_lock); + EXT4_STATE_FC_COMMITTING)) continue; - } - spin_unlock(&pos->i_fc_lock); spin_unlock(&sbi->s_fc_lock); ret = jbd2_wait_inode_data(journal, pos->jinode); @@ -1093,6 +1084,16 @@ static int ext4_fc_perform_commit(journal_t *journal) int ret = 0; u32 crc = 0; + /* Lock the journal */ + jbd2_journal_lock_updates(journal); + spin_lock(&sbi->s_fc_lock); + list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + ext4_set_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_COMMITTING); + } + spin_unlock(&sbi->s_fc_lock); + jbd2_journal_unlock_updates(journal); + ret = ext4_fc_submit_inode_data_all(journal); if (ret) return ret; @@ -1143,6 +1144,18 @@ static int ext4_fc_perform_commit(journal_t *journal) ret = ext4_fc_write_inode(inode, &crc); if (ret) goto out; + ext4_clear_inode_state(inode, EXT4_STATE_FC_COMMITTING); + /* + * Make sure clearing of EXT4_STATE_FC_COMMITTING is + * visible before we send the wakeup. Pairs with implicit + * barrier in prepare_to_wait() in ext4_fc_track_inode(). + */ + smp_mb(); +#if (BITS_PER_LONG < 64) + wake_up_bit(&iter->i_state_flags, EXT4_STATE_FC_COMMITTING); +#else + wake_up_bit(&iter->i_flags, EXT4_STATE_FC_COMMITTING); +#endif spin_lock(&sbi->s_fc_lock); } spin_unlock(&sbi->s_fc_lock); @@ -1276,13 +1289,17 @@ static void ext4_fc_cleanup(journal_t *journal, int full, tid_t tid) spin_lock(&sbi->s_fc_lock); list_for_each_entry_safe(iter, iter_n, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - list_del_init(&iter->i_fc_list); ext4_clear_inode_state(&iter->vfs_inode, EXT4_STATE_FC_COMMITTING); if (iter->i_sync_tid <= tid) ext4_fc_reset_inode(&iter->vfs_inode); - /* Make sure EXT4_STATE_FC_COMMITTING bit is clear */ + /* + * Make sure clearing of EXT4_STATE_FC_COMMITTING is + * visible before we send the wakeup. Pairs with implicit + * barrier in prepare_to_wait() in ext4_fc_track_inode(). + */ smp_mb(); + list_del_init(&iter->i_fc_list); #if (BITS_PER_LONG < 64) wake_up_bit(&iter->i_state_flags, EXT4_STATE_FC_COMMITTING); #else diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index c2cf74b01ddb..06b885628b1c 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -757,7 +757,6 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid) } journal->j_flags |= JBD2_FAST_COMMIT_ONGOING; write_unlock(&journal->j_state_lock); - jbd2_journal_lock_updates(journal); return 0; } @@ -769,7 +768,6 @@ EXPORT_SYMBOL(jbd2_fc_begin_commit); */ static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback) { - jbd2_journal_unlock_updates(journal); if (journal->j_fc_cleanup_callback) journal->j_fc_cleanup_callback(journal, 0, tid); write_lock(&journal->j_state_lock); From patchwork Tue Mar 8 16:33:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1603087 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BmOJ4Bh/; 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCgrK4gRcz9sG9 for ; Wed, 9 Mar 2022 03:33:53 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4KCgrK41FKz4xcd for ; Wed, 9 Mar 2022 03:33:53 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4KCgrK3zf4z4xv3; Wed, 9 Mar 2022 03:33:53 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org 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 (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BmOJ4Bh/; 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 4KCgrK3wWBz4xcd for ; Wed, 9 Mar 2022 03:33:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348368AbiCHQeq (ORCPT ); Tue, 8 Mar 2022 11:34:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348364AbiCHQem (ORCPT ); Tue, 8 Mar 2022 11:34:42 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89E7033890 for ; Tue, 8 Mar 2022 08:33:40 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id c16-20020a17090aa61000b001befad2bfaaso2906325pjq.1 for ; Tue, 08 Mar 2022 08:33:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kPll1P7V9GBIOrJxOdF6hEwzL3wAJVuFpTywJr8/a3g=; b=BmOJ4Bh/pmOC6MzAQi/MFdX085SkkoDLAJ7XhMTZQDlsfmud9sr/BzoS9xG2/MIz6Y 1Qz2qUI0dT8O/xvLvWma1Sq21X3Pl2aFiXnKTXCtPkagjZzm1rsuKG2mgmovRs8wMmao vrIUsvdMGUEnpHXBDkS84l9jpRygXzm4rAPiOUAqRPfZVW59ohg1xOCcpolGcdQWZnwm 4aJ1X2busQIdq1Ugh2jsAcCPrkUwiuSz+doEQngDbJKsb5ipklciJqnvWnyWQO2rmbWn xFyMflPzeepCNH214uNl00dQbFcisPHVBAfQARCRdfdfj3CXB4Fl5l9RatY3rTY4iuqd V25Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kPll1P7V9GBIOrJxOdF6hEwzL3wAJVuFpTywJr8/a3g=; b=7+agyOLCJzF3eWAar9Dul3rDB0ebMkwLt7vJyu7bToiQ2NaxCh/9vT+m6Gl8vRetn9 vYKmdhIoXCMH9xPktHQ2IzzOEp1FhFylYHo6fUBQBf8n9H4F2Z6bgvz99HPBA+X1A599 fB6AghzELvi6qE/Lclukmhq8UQa3yIheT8SFMmEScFIiJYkHvADT+cEJUydT8wX8znYA s7AmRE9DOAdApov6xmE6w3p2c/1pdgE+pgAyycoKDeQZgN5197iQxAaaQIZ9vkwBtwtV RhRGph0TREh9D8LAPfzMBJ7vVZ6+J7i3fWx4PQNpzt6bymH6s1YkNko9CZVTWueQ5X8R T/aw== X-Gm-Message-State: AOAM533ibGaHD4fSyXJmC5HQw/54d4lxK9za0fwlJ2sWZZTorlkyMKpl 6y4+ovql7Fphi/a9kuwJb2VNBogDnWrU99Cc X-Google-Smtp-Source: ABdhPJy5v2C/nV8LTZveqZywnla5y/zoVWLDDZkbauEXXvbsRH0uXQJ+QB9roQ1wkPccyx8u6PUP2g== X-Received: by 2002:a17:903:228a:b0:151:ed55:39c8 with SMTP id b10-20020a170903228a00b00151ed5539c8mr10555071plh.53.1646757219470; Tue, 08 Mar 2022 08:33:39 -0800 (PST) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:c24c:d8e5:a9be:227]) by smtp.googlemail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm4517720pja.3.2022.03.08.08.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:33:38 -0800 (PST) From: Harshad Shirwadkar X-Google-Original-From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu, Harshad Shirwadkar Subject: [PATCH v2 4/5] ext4: drop i_fc_updates from inode fc info Date: Tue, 8 Mar 2022 08:33:18 -0800 Message-Id: <20220308163319.1183625-5-harshads@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308163319.1183625-1-harshads@google.com> References: <20220308163319.1183625-1-harshads@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Harshad Shirwadkar The new logic introduced in this series does not require tracking number of active handles open on an inode. So, drop it. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 5 ---- fs/ext4/fast_commit.c | 70 ------------------------------------------- 2 files changed, 75 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index fb6d65f1176f..6861a3127a42 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1059,9 +1059,6 @@ struct ext4_inode_info { /* End of lblk range that needs to be committed in this fast commit */ ext4_lblk_t i_fc_lblk_len; - /* Number of ongoing updates on this inode */ - atomic_t i_fc_updates; - /* Fast commit wait queue for this inode */ wait_queue_head_t i_fc_wait; @@ -2930,8 +2927,6 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode, void ext4_fc_track_create(handle_t *handle, struct dentry *dentry); void ext4_fc_track_inode(handle_t *handle, struct inode *inode); void ext4_fc_mark_ineligible(struct super_block *sb, int reason, handle_t *handle); -void ext4_fc_start_update(struct inode *inode); -void ext4_fc_stop_update(struct inode *inode); void ext4_fc_del(struct inode *inode); bool ext4_fc_replay_check_excluded(struct super_block *sb, ext4_fsblk_t block); void ext4_fc_replay_cleanup(struct super_block *sb); diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index eedcf8b4d47b..eea19e3ea9ba 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -201,76 +201,6 @@ void ext4_fc_init_inode(struct inode *inode) INIT_LIST_HEAD(&ei->i_fc_list); INIT_LIST_HEAD(&ei->i_fc_dilist); init_waitqueue_head(&ei->i_fc_wait); - atomic_set(&ei->i_fc_updates, 0); -} - -/* This function must be called with sbi->s_fc_lock held. */ -static void ext4_fc_wait_committing_inode(struct inode *inode) -__releases(&EXT4_SB(inode->i_sb)->s_fc_lock) -{ - wait_queue_head_t *wq; - struct ext4_inode_info *ei = EXT4_I(inode); - -#if (BITS_PER_LONG < 64) - DEFINE_WAIT_BIT(wait, &ei->i_state_flags, - EXT4_STATE_FC_COMMITTING); - wq = bit_waitqueue(&ei->i_state_flags, - EXT4_STATE_FC_COMMITTING); -#else - DEFINE_WAIT_BIT(wait, &ei->i_flags, - EXT4_STATE_FC_COMMITTING); - wq = bit_waitqueue(&ei->i_flags, - EXT4_STATE_FC_COMMITTING); -#endif - lockdep_assert_held(&EXT4_SB(inode->i_sb)->s_fc_lock); - prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); - spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); - schedule(); - finish_wait(wq, &wait.wq_entry); -} - -/* - * Inform Ext4's fast about start of an inode update - * - * This function is called by the high level call VFS callbacks before - * performing any inode update. This function blocks if there's an ongoing - * fast commit on the inode in question. - */ -void ext4_fc_start_update(struct inode *inode) -{ - struct ext4_inode_info *ei = EXT4_I(inode); - - if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || - (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)) - return; - -restart: - spin_lock(&EXT4_SB(inode->i_sb)->s_fc_lock); - if (list_empty(&ei->i_fc_list)) - goto out; - - if (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { - ext4_fc_wait_committing_inode(inode); - goto restart; - } -out: - atomic_inc(&ei->i_fc_updates); - spin_unlock(&EXT4_SB(inode->i_sb)->s_fc_lock); -} - -/* - * Stop inode update and wake up waiting fast commits if any. - */ -void ext4_fc_stop_update(struct inode *inode) -{ - struct ext4_inode_info *ei = EXT4_I(inode); - - if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || - (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY)) - return; - - if (atomic_dec_and_test(&ei->i_fc_updates)) - wake_up_all(&ei->i_fc_wait); } /* From patchwork Tue Mar 8 16:33:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1603084 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=MR90+yIp; 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 RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KCgrF6dZNz9sGD for ; Wed, 9 Mar 2022 03:33:49 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4KCgrF5ty1z4xcd for ; Wed, 9 Mar 2022 03:33:49 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4KCgrF5rgsz4xv3; Wed, 9 Mar 2022 03:33:49 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org 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 (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=MR90+yIp; 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 4KCgrF4d18z4xcd for ; Wed, 9 Mar 2022 03:33:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348359AbiCHQeo (ORCPT ); Tue, 8 Mar 2022 11:34:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348368AbiCHQem (ORCPT ); Tue, 8 Mar 2022 11:34:42 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26AEA427E9 for ; Tue, 8 Mar 2022 08:33:42 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id g1so17792963pfv.1 for ; Tue, 08 Mar 2022 08:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pbuYz6YiXIlLZzGmxXWhYRCymgIoYaOBHIs/RHlGFUU=; b=MR90+yIpeyeMBPzb3Zwqfw3IrbPmquz7FmHvIr4nSAMAs2+LKs94TXtnRfUeoZQxSB jMfJJ2znHLbVivjNV6QqcrfLuyXLzcsvDg1mUlCZskfDS6tV7l2vrEKwq0pz3q8QDVpH CgOU9gOxOYeLegahb6dmL5Vq1Hc8Wq9tUXpmizrQwrGoG2DfQPkexw9gZwx/kqo2h/DF AHhMoNQN9jKuUrvCKFqtrh43jmYsT/rqfsZMQF259ce+igvz9QhqJPN4QA2g00wJK4L/ HOazZYKC6WhfQ+vmmilZd8tI/guQqt82CveeQBqvZbyYh4flokrIQOQ9JdJmeWJ2DuBF Pw6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pbuYz6YiXIlLZzGmxXWhYRCymgIoYaOBHIs/RHlGFUU=; b=yj/B/h0k+vgL7nvU/ICLNTNRglcgLzlVxGpAVUHBijhcIDIQhTepgK+r7g+xeuUQDz rxTZlCEUPbD5Cf3SoPnBf0jDdORVv437Jij7wnVEexyTxPEbU7WZ/B3f0PpHBUYRBMDX 4lue+sCGku5pXTWR7zFDqzP7HwZtu1gycSJM/HKub+toB6inKFr1HJXWt+69AUV6WYmo fFcsf9cH4tJIWvdJMVbiDBb9OXnoiYWmNkyM5yC1smr3PRHXULv2kp8GFLeLz73MYo0J Nz/Fg1XeGiyhOK/PhRS8ZBvj/jS8HWrqmzt7pZtSLfNyWVRER9HbEu9o+0IYm49Hp9yX wZSA== X-Gm-Message-State: AOAM532zaIIA3+MAjx30Qry0fwUUeDdKJ7u+CPeSH07qJGEP8s5LzVoh mOEZ8Ezkix5iV8UhbMiVtLv9nM+pRHtLsCDJ X-Google-Smtp-Source: ABdhPJxFsd9TLxFY3Ezyg5P3vp4T8fSgHQlKj4uECK8tlxEw8vDmaXdOIxHKQEzJKtmfpxy9tdu/WA== X-Received: by 2002:a63:b21:0:b0:372:f0e9:50b9 with SMTP id 33-20020a630b21000000b00372f0e950b9mr14572250pgl.566.1646757221002; Tue, 08 Mar 2022 08:33:41 -0800 (PST) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:c24c:d8e5:a9be:227]) by smtp.googlemail.com with ESMTPSA id m8-20020a17090a158800b001bf2cec0377sm4517720pja.3.2022.03.08.08.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 08:33:39 -0800 (PST) From: Harshad Shirwadkar X-Google-Original-From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: riteshh@linux.ibm.com, jack@suse.cz, tytso@mit.edu, Harshad Shirwadkar Subject: [PATCH v2 5/5] ext4: update code documentation Date: Tue, 8 Mar 2022 08:33:19 -0800 Message-Id: <20220308163319.1183625-6-harshads@google.com> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220308163319.1183625-1-harshads@google.com> References: <20220308163319.1183625-1-harshads@google.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Harshad Shirwadkar This patch updates code documentation to reflect the commit path changes made in this series. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/fast_commit.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index eea19e3ea9ba..c14e6d34d552 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -49,14 +49,21 @@ * that need to be committed during a fast commit in another in memory queue of * inodes. During the commit operation, we commit in the following order: * - * [1] Lock inodes for any further data updates by setting COMMITTING state - * [2] Submit data buffers of all the inodes - * [3] Wait for [2] to complete - * [4] Commit all the directory entry updates in the fast commit space - * [5] Commit all the changed inode structures - * [6] Write tail tag (this tag ensures the atomicity, please read the following + * [1] Lock the journal by calling jbd2_journal_lock_updates. This ensures that + * all the exsiting handles finish and no new handles can start. + * [2] Mark all the fast commit eligible inodes as undergoing fast commit + * by setting "EXT4_STATE_FC_COMMITTING" state. + * [3] Unlock the journal by calling jbd2_journal_unlock_updates. This allows + * starting of new handles. If new handles try to start an update on + * any of the inodes that are being committed, ext4_fc_track_inode() + * will block until those inodes have finished the fast commit. + * [4] Submit data buffers of all the committing inodes. + * [5] Wait for [4] to complete. + * [6] Commit all the directory entry updates in the fast commit space. + * [7] Commit all the changed inodes in the fast commit space and clear + * "EXT4_STATE_FC_COMMITTING" for these inodes. + * [8] Write tail tag (this tag ensures the atomicity, please read the following * section for more details). - * [7] Wait for [4], [5] and [6] to complete. * * All the inode updates must call ext4_fc_start_update() before starting an * update. If such an ongoing update is present, fast commit waits for it to @@ -142,6 +149,13 @@ * similarly. Thus, by converting a non-idempotent procedure into a series of * idempotent outcomes, fast commits ensured idempotence during the replay. * + * Locking + * ------- + * sbi->s_fc_lock protects the fast commit inodes queue and the fast commit + * dentry queue. ei->i_fc_lock protects the fast commit related info in a given + * inode. Most of the code avoids acquiring both the locks, but if one must do + * that then sbi->s_fc_lock must be acquired before ei->i_fc_lock. + * * TODOs * ----- * @@ -156,13 +170,7 @@ * fast commit recovery even if that area is invalidated by later full * commits. * - * 1) Fast commit's commit path locks the entire file system during fast - * commit. This has significant performance penalty. Instead of that, we - * should use ext4_fc_start/stop_update functions to start inode level - * updates from ext4_journal_start/stop. Once we do that we can drop file - * system locking during commit path. - * - * 2) Handle more ineligible cases. + * 1) Handle more ineligible cases. */ #include