From patchwork Thu Jul 21 06:02:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658865 X-Patchwork-Delegate: tytso@mit.edu 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=kPB8fWON; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMS53ykFz9sFk for ; Thu, 21 Jul 2022 16:03:01 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMS265mZz4xD9 for ; Thu, 21 Jul 2022 16:02:58 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMS2634fz4xG0; Thu, 21 Jul 2022 16:02:58 +1000 (AEST) 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=kPB8fWON; 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 4LpMS25ynZz4xD9 for ; Thu, 21 Jul 2022 16:02:58 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbiGUGC5 (ORCPT ); Thu, 21 Jul 2022 02:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231707AbiGUGC4 (ORCPT ); Thu, 21 Jul 2022 02:02:56 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CF437A536 for ; Wed, 20 Jul 2022 23:02:55 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id go3so684837pjb.0 for ; Wed, 20 Jul 2022 23:02:55 -0700 (PDT) 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=15ANQp0dwnsCHTF03pUt3yxdPH7n6txqP2v/xxtddnc=; b=kPB8fWONO8F8QzDLidnwEWAXYm4XPbTfALoAWHIJzS3ogycNUg3itIgRDQ46PDQ63f /F7LlhP3Twbpki5I1vArlQewmHzzoxnOjUtynmAC4ysWX9mjz6pSha4kiYVr3ro5h4/S UdrvB3amqiaW5AMB+eMawQ6n27wHc6jUOPEFLsGKVEiPolg+ONy7h5jraXQgxAZNUAPF tq0ZmxbeCfqHoNfA4K3KDM2IxPOLeZd1DAH1lsa0Ct33a2CaXxA+abqxJ0FWtoL+GtZH 8vP81Rs7z+NYjd49eIKgGP6WiJu32cNj2jT7nXS1+NtBLLEexOgXDjJFyaIoVmslEWbZ 27pA== 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=15ANQp0dwnsCHTF03pUt3yxdPH7n6txqP2v/xxtddnc=; b=u9VIJ21WsjDqHl+WjPo+NnfiqoFsS/dUkr8L4gcFmL5URPqUH9V3TIMQnfAhuPWCEq g7tQd0/SjDaYXgJ59NAteTAJKfIZQSBthb/lye2VKIr4UJSmgBO5irWQqcZP0MpuzYiX /h474wEHg5cO1xY7nd9ZHvOOFp2nGBRNm3mMWtHuXBfoYEOXxtzyek23OmuRi5bdgzOD 6LUCMtbRR4xzBEoBRPUTjKn506C+wjQ0fAR5lmTtb4ojiSPUXOTojEeInNWrFCs8RTfv /3uscH6lrYtg6z2Sfiq/0V6httVHPEn4HOWIj3Up0WwxVRzEEUjlyb0yaoLOYFIVuX0m AxsQ== X-Gm-Message-State: AJIora9zLL7TGAeIjdnufUbfulDIKFP7NftGne+TRW+wfid3x16JbbH5 sR8uHO307AhAIWqDSc6NOUKFrwr4/QhIEQ== X-Google-Smtp-Source: AGRyM1v4phghZLcK1n4NGB2onC9yEdOHcrEuecOikp5hf4rSP6519PR+L62gUzAe8jz6rUoH+/vwQA== X-Received: by 2002:a17:902:8ec9:b0:16b:d5bf:c465 with SMTP id x9-20020a1709028ec900b0016bd5bfc465mr19934960plo.128.1658383374530; Wed, 20 Jul 2022 23:02:54 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:53 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar , Jan Kara Subject: [RFC PATCH v4 1/8] ext4: convert i_fc_lock to spinlock Date: Thu, 21 Jul 2022 06:02:39 +0000 Message-Id: <20220721060246.1696852-2-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 Convert ext4_inode_info->i_fc_lock to spinlock to avoid sleeping in invalid contexts. Signed-off-by: Harshad Shirwadkar Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 7 +++++-- fs/ext4/fast_commit.c | 22 ++++++++++------------ fs/ext4/super.c | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 75b8d81b2469..12c8691f08d3 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1067,8 +1067,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 795a60ad1897..8d6d5155a646 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -380,7 +380,7 @@ static int ext4_fc_track_template( int ret; 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 { @@ -388,7 +388,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; @@ -420,11 +420,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; } @@ -437,7 +437,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, @@ -471,7 +471,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; } @@ -611,10 +611,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; @@ -906,15 +904,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", diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 845f2f8aee5f..307871359e23 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1354,7 +1354,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 Thu Jul 21 06:02:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658866 X-Patchwork-Delegate: tytso@mit.edu 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=WGm8o0lP; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMS85b3tz9sFk for ; Thu, 21 Jul 2022 16:03:04 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMS84rSvz4xD9 for ; Thu, 21 Jul 2022 16:03:04 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMS84pFSz4xG0; Thu, 21 Jul 2022 16:03:04 +1000 (AEST) 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=WGm8o0lP; 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 4LpMS84kjNz4xD9 for ; Thu, 21 Jul 2022 16:03:04 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbiGUGDD (ORCPT ); Thu, 21 Jul 2022 02:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiGUGC5 (ORCPT ); Thu, 21 Jul 2022 02:02:57 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BFD47A536 for ; Wed, 20 Jul 2022 23:02:57 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id h132so707481pgc.10 for ; Wed, 20 Jul 2022 23:02:57 -0700 (PDT) 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=9zgv8W9ohloZRX9vqO+xpKxAioSV1XlBjrfd2i4B79U=; b=WGm8o0lPCZhvf8pYzYirB8Wyg/NR/KU3v8XmFbMj8D3VInjpq0Ips264ipxlIjCw/n 9MNSrA7GyT5F68hBvn8n+ujoTuVYxmI0lOQ/DWMYGjatuC2EeicFOJ40YMD58gTIrURS OjENq+JG+Nbuq1OkYQhCVRVdhJGYLjFFqYliWvRCWc7TczuW8KTiGgQLE+tSrZKNmJc3 6APxW36nTJotd1ABSsq6bJ9ygENQOcPFbKXaMTIg8cmER7R0Ca2adWGO1zSf0TRy4hIG Cp5WUhOpAEsmM4knmzQIzLI/de0MJxm8m5DNVvILNTUdDUx6MX8FQSZ+SfR33JD9SvxP inCw== 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=9zgv8W9ohloZRX9vqO+xpKxAioSV1XlBjrfd2i4B79U=; b=n+ui+kLbpVleS/BH8f+QOboyYXqVfZD8OnzSLrCbJwj81oNpiS41eUhUbuVgLm2wLT bl0k5dDonspNqIoLnNXxVkCeoqexwg13bmfqLGv7mh19eDAgHajaJ02P1+Y7s1fjehgl BEhppNg1CfjC7oM0blzUZ/9JHJzmjgvJjugIVefcnAXW5kwXLQz/QHWG0Rb2x9hOKQhQ YsYjnGD3hBENF8ZMwoK1psCPDLg9v+RbRL+IJgXMa2Hm0Hv1Df/JmzkAy+eqR20qHxq7 VhdGadqXSrxQOTBt+QqAdsRhop1Tums2zGWW6/UdR7TCHusc3aJoonSeRmAQzLvEdn9m UOeQ== X-Gm-Message-State: AJIora8nVOUKM8MZLxqS7eHutoFLdo8dzevNP+rgdZpVdPyZu6fKCi0x noQ+ClV/veBVV7IvvfA+2pQ/xwaCX7ww0A== X-Google-Smtp-Source: AGRyM1v1KRYf7EuZxHhI9+MWLLyNIFvZCtHWuPvOXpJEc6RUEjubqs1DzfdWPBR4MbPwfWffgvCDqg== X-Received: by 2002:aa7:8318:0:b0:528:c331:e576 with SMTP id bk24-20020aa78318000000b00528c331e576mr43040947pfb.58.1658383375707; Wed, 20 Jul 2022 23:02:55 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:54 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar Subject: [RFC PATCH v4 2/8] ext4: for committing inode, make ext4_fc_track_inode wait Date: Thu, 21 Jul 2022 06:02:40 +0000 Message-Id: <20220721060246.1696852-3-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 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. Also, add calls to ext4_fc_track_inode at the right places. With this patch, now calling ext4_reserve_inode_write() results in inode being tracked for next fast commit. A subtle lock ordering requirement with i_data_sem (which is documented in the code) requires that ext4_fc_track_inode() be called before grabbing i_data_sem. So, this patch also adds explicit ext4_fc_track_inode() calls in places where i_data_sem grabbed. Signed-off-by: Harshad Shirwadkar --- fs/ext4/fast_commit.c | 30 ++++++++++++++++++++++++++++++ fs/ext4/inline.c | 3 +++ fs/ext4/inode.c | 5 ++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 8d6d5155a646..4d2384adcbb0 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -574,8 +574,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; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); int ret; @@ -595,6 +601,30 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) if (ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)) return; + if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || + (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) || + ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE) || + !list_empty(&ei->i_fc_list)) + 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(handle, inode, ret); } diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index cff52ff6549d..7f5edfb34095 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -586,6 +586,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; } + ext4_fc_track_inode(handle, inode); ret = ext4_destroy_inline_data_nolock(handle, inode); if (ret) goto out; @@ -686,6 +687,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, goto convert; } + ext4_fc_track_inode(handle, inode); ret = ext4_journal_get_write_access(handle, inode->i_sb, iloc.bh, EXT4_JTR_NONE); if (ret) @@ -964,6 +966,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, if (ret < 0) goto out_release_page; } + ext4_fc_track_inode(handle, inode); ret = ext4_journal_get_write_access(handle, inode->i_sb, iloc.bh, EXT4_JTR_NONE); if (ret) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 84c0eb55071d..f3de6748a96b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -627,6 +627,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, */ map->m_flags &= ~EXT4_MAP_FLAGS; + ext4_fc_track_inode(handle, inode); /* * New blocks allocate and/or writing to unwritten extent * will possibly result in updating i_data, so we take @@ -4076,7 +4077,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) /* If there are blocks to remove, do it */ if (stop_block > first_block) { - + ext4_fc_track_inode(handle, inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode, 0); @@ -4232,6 +4233,7 @@ int ext4_truncate(struct inode *inode) if (err) goto out_stop; + ext4_fc_track_inode(handle, inode); down_write(&EXT4_I(inode)->i_data_sem); ext4_discard_preallocations(inode, 0); @@ -5752,6 +5754,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 Thu Jul 21 06:02:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658867 X-Patchwork-Delegate: tytso@mit.edu 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=feeVCLN7; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMS923g6z9sFs for ; Thu, 21 Jul 2022 16:03:05 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMS91NLnz4xD9 for ; Thu, 21 Jul 2022 16:03:05 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMS91Kljz4xG0; Thu, 21 Jul 2022 16:03:05 +1000 (AEST) 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=feeVCLN7; 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 4LpMS91Fvnz4xD9 for ; Thu, 21 Jul 2022 16:03:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231920AbiGUGDE (ORCPT ); Thu, 21 Jul 2022 02:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231842AbiGUGC6 (ORCPT ); Thu, 21 Jul 2022 02:02:58 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5157AB00 for ; Wed, 20 Jul 2022 23:02:57 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d10so823672pfd.9 for ; Wed, 20 Jul 2022 23:02:57 -0700 (PDT) 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=WnygQSSP2aOqCpGFs0AW4rqi/kwZHcwdU9jLes7G+zo=; b=feeVCLN7Z9AjuQFIQR/jsGFMqWc2mncPmgmhgz3N5FDwryrKSHnsD3+hUOxBqqKi0W wi8xi8iLpji5dl05j7Br4Ds/sSIPXIjarYBEVoamuXz8hKl2G5/hkhKu+fh+69XkkPLj /Q3PcbKwUps+R0Bjg5g96VIUsNsfgEJuPSF54ad/B4xH6KzvwbAuut1KvUAH+ObuzEps EH6WkswwIDZ5K6ZnO6AxfGQ4/a9o/7Diwhb11hBwbH3C3Qcb7PVPyE3Sb/d/KclQFrN+ RR0yRQ+E6WdjeutHmZpjTeBG83nTnINGM2lQf/ANcumpd/OuRq58Tdkbs5mzQvPJqXle EfnQ== 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=WnygQSSP2aOqCpGFs0AW4rqi/kwZHcwdU9jLes7G+zo=; b=a6yRbjFsVLxUb8Ve7qpYDALaXO7KPPVyHPf16f8tR+f5snao7JxK24241VO4MLdCrk 1hIXPZj7Q/mZNTw/nN0qcWOygWfDqOiXZM9X4wVwqwA2JIDuXEswBdsE7JTP8GsK6sZg E46kmq3iDjxcjFJR6Sf1eSZZmxO9gH9JgQESVb+78xarWiEGmHB9N+lEhsI2KHueQYPA gZuTI7iapO9iaKMGxLAHW8ZNWrCuT+9tFfRSPCUNwnCdLEhBr76QSNEiLm47basx8v+s oAw7H80NFnSl5a3fVuul98o/eTUUbHvbkFUg7sdWuLH5BCoqIxdxgt38gGG9ezVv2CFs iv7g== X-Gm-Message-State: AJIora+s1C7cDMc0Y4FjGrqJs8H67Psd01aV23SpnqLj9TdZUlv9F4DJ tMdMMmsa5I3KIyK3D6SZxrW95HuxEZBckA== X-Google-Smtp-Source: AGRyM1uExJxv3C8i0jWmTZPjo1R8upvj8ijwT67rgSXvSsuExU6teEGT0yitnrtqLJ1C/9AUGtZqJw== X-Received: by 2002:a05:6a00:10ca:b0:4f7:5af4:47b6 with SMTP id d10-20020a056a0010ca00b004f75af447b6mr42869771pfu.6.1658383376526; Wed, 20 Jul 2022 23:02:56 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:55 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar Subject: [RFC PATCH v4 3/8] ext4: use extent status tree in fast commit path Date: Thu, 21 Jul 2022 06:02:41 +0000 Message-Id: <20220721060246.1696852-4-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 This patch moves fc commit path to use extent status tree to lookup logical to physical mappings. In order to preserve the uncommitted entries in the es cache, this patch makes all the inodes on fast commit list as shrinker ineligible. Making the uncommitted entries in es cache to stick around is left as a future enhancement. Signed-off-by: Harshad Shirwadkar --- fs/ext4/extents_status.c | 3 ++- fs/ext4/fast_commit.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 9a3a8996aacf..07fb86746534 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1500,7 +1500,8 @@ static int __es_shrink(struct ext4_sb_info *sbi, int nr_to_scan, continue; } - if (ei == locked_ei || !write_trylock(&ei->i_es_lock)) { + if (!list_empty(&ei->i_fc_list) || ei == locked_ei || + !write_trylock(&ei->i_es_lock)) { nr_skipped++; continue; } diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 4d2384adcbb0..916f62cfa7f7 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -951,7 +951,8 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc) while (cur_lblk_off <= new_blk_size) { map.m_lblk = cur_lblk_off; map.m_len = new_blk_size - cur_lblk_off + 1; - ret = ext4_map_blocks(NULL, inode, &map, 0); + ret = ext4_map_blocks(NULL, inode, &map, + EXT4_GET_BLOCKS_CACHED_NOWAIT); if (ret < 0) return -ECANCELED; From patchwork Thu Jul 21 06:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658868 X-Patchwork-Delegate: tytso@mit.edu 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=nCb28GiV; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMSB4mfbz9sFk for ; Thu, 21 Jul 2022 16:03:06 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMSB41k0z4xD9 for ; Thu, 21 Jul 2022 16:03:06 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMSB3zblz4xG0; Thu, 21 Jul 2022 16:03:06 +1000 (AEST) 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=nCb28GiV; 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 4LpMSB3vP6z4xD9 for ; Thu, 21 Jul 2022 16:03:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiGUGDF (ORCPT ); Thu, 21 Jul 2022 02:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231708AbiGUGDC (ORCPT ); Thu, 21 Jul 2022 02:03:02 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0529C7AB16 for ; Wed, 20 Jul 2022 23:02:59 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id s206so738741pgs.3 for ; Wed, 20 Jul 2022 23:02:59 -0700 (PDT) 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=gw1tvgmsX9USbUcdfOLPUt99Xa2Ep6XpIu5vjIGEUvo=; b=nCb28GiVKxZCIe7IIj0IF27PzIkSbJF7/pLTWMD/RL50OURnTVn3SFxGMIBqngVZ8Q gMBLW+X07ent8Scqm/NM7itoFSBBAViyuxjgwZSjm2n7JCh89deSsiUIUrFioYOS254x BpXrDWFJ5b6mN9URSsj5rfzNwusksWCxvflknrQyNGswIVD1mzLY+Dw84iLYuBFJf3T2 yVm7R2Pgzb/VLUKVBq57bHJcgzvOaSEtBO5Tcd3RIMtKXW4dI2IuUbD+AQuI1V9uRAHK 4mxfMtf/jnxtvjVdcnoXDjUCxsDnzlhQYC5iOwtvRGz5IYs5ECfDdMG7uMYGjKyFDmh1 YRcQ== 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=gw1tvgmsX9USbUcdfOLPUt99Xa2Ep6XpIu5vjIGEUvo=; b=O+CoszHa+3VXHuRNApSLSWn63FEKOwcljt4eku/aD5Ybc4CNTuWbrh5t64geiSU42G 06gWXevWqES5MrWpltjb3rUvFwyyHXEyl/u64Y9CUMlF4j6ZVj9QBtVixKOyvCkSsYm6 leB21QHG97JVMVfxDIKwGAWjGegLY8FS4sM5FGe8rX2mAEnei5ehuTVubX3kcvLfgyUA 2TljL62+1bnKmOq04ciaTYGhPuYcb9qzfcX6tJ7rX7O6QsqrO/vxtGTtCyLkhtxOnk5F dAzL/4f5id/0W096Onqi8cRWmhZP4uZK7Uo0H7CcUDZ0aQJyrjelb49GBBZ40wb2BkhV OZhA== X-Gm-Message-State: AJIora+0gdx8rInXfopwkHUDjj7zbA7T/IB7ah2wKFXxaX93VumdqK+r eTQpR9UbGs34PR8sJ4A9hHuC+NwFr4Y0EczL X-Google-Smtp-Source: AGRyM1vgncA7xegLkUWultJwUPcGnKYK1p9uDt7aHxEsetgPH5/UOHZIw7JZHzS6vOq558i+VKxxeg== X-Received: by 2002:a05:6a00:174f:b0:525:518e:71d6 with SMTP id j15-20020a056a00174f00b00525518e71d6mr43458840pfc.68.1658383377897; Wed, 20 Jul 2022 23:02:57 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:57 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar , Jan Kara Subject: [RFC PATCH v4 4/8] ext4: rework fast commit commit path Date: Thu, 21 Jul 2022 06:02:42 +0000 Message-Id: <20220721060246.1696852-5-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 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 | 73 ++++++++++++++++++++++++++++--------------- fs/jbd2/journal.c | 2 -- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 916f62cfa7f7..608ae16afcd6 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; } /* @@ -1006,19 +1014,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) @@ -1131,6 +1126,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; @@ -1183,6 +1188,20 @@ static int ext4_fc_perform_commit(journal_t *journal) goto out; spin_lock(&sbi->s_fc_lock); } + list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { + 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_unlock(&sbi->s_fc_lock); ret = ext4_fc_write_tail(sb, crc); @@ -1318,13 +1337,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 c0cbeeaec2d1..64b56bf02c52 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 Thu Jul 21 06:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658869 X-Patchwork-Delegate: tytso@mit.edu 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=q5MOXOfA; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMSC5JjVz9sFk for ; Thu, 21 Jul 2022 16:03:07 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMSC4Yq9z4xG0 for ; Thu, 21 Jul 2022 16:03:07 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMSC4Wlvz4xG6; Thu, 21 Jul 2022 16:03:07 +1000 (AEST) 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=q5MOXOfA; 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 4LpMSC4RGxz4xG0 for ; Thu, 21 Jul 2022 16:03:07 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231886AbiGUGDH (ORCPT ); Thu, 21 Jul 2022 02:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231883AbiGUGDD (ORCPT ); Thu, 21 Jul 2022 02:03:03 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE1E7A539 for ; Wed, 20 Jul 2022 23:03:00 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id x24-20020a17090ab01800b001f21556cf48so4210343pjq.4 for ; Wed, 20 Jul 2022 23:03:00 -0700 (PDT) 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=fNljEoovjwlVcxzjjsT9XVt70W1NHTNB2v0mAFC2T40=; b=q5MOXOfAO1VDPfxXwVeEi9RorbFccWyUjIWyA/dogeiQC2k9pxWXEPSaeJtw8Jy6Gb JhkpVBQoxyModQVz4aIsV/g3Be2mehlkqwUWKw6/FNJpg6+rqsjqV5oQYsDU9PLSHZdh Ngw2NXCMFH5edBycmFQt5dSjpe7nLXf8e7mxdEPUxXPYBYLgyiNmTRFSG3Wf8nqGjGHs 9/msype5n6eVJOnx5XEHVc4IYds7FYvRW5C6APa960mEIXP4AEeCJSXBWu+w17ExQ/l5 xYbEkyC+4dCS3BKzuyuXBfrj/idNsVsd1PNnCzkc28sqxQFIdcLtdLMPgv6FI49apV44 2Lfw== 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=fNljEoovjwlVcxzjjsT9XVt70W1NHTNB2v0mAFC2T40=; b=ptg+wlRWJm7byzhAaf9b2SbW/7AYuApUxn2bTpEa7TxIUA1Nh6E0DUFqVXCFrer4Pn o0x1OXvzzh3+1B7fxr/c8vM3suG2jxujEEGq4RNr0lMx54eEEbPC0StlGH+gQIlHd7j6 ihq/UQ/7ezMCLezpWjzlCqARhDSiUEp6QvSkkfyPsGd9EpNrMfJ2CmKMGrugNOLdgBKk 1BJi2LGbZdPCrrk+mof1c7D47tYSQ0PVgATJrV9qSypeJL0aCdTSNLZIJegyhlfdJaHZ gGQK+dcRtr7r246JCb/eiYM+p3X8F+7/GoAhLDh6uVRnCWwbXD4cVEuM4dOHUTt5m/Jo URYg== X-Gm-Message-State: AJIora/TMBADMiJKsBOtATBxdJvQhyhl9bhzQqyJuaBJo6F8ZY0Vc5X3 E5OFn47/TLmyehzxu0nUMV3wkpXwwm/xjqaj X-Google-Smtp-Source: AGRyM1u7e8n4dKE6BXK/TbheJ4mDSIMYeZrQ1oEIIUwDxoClx+wyFiYVOh1swMklrSTizdFZJmGxOg== X-Received: by 2002:a17:902:ce0e:b0:16c:7977:9d74 with SMTP id k14-20020a170902ce0e00b0016c79779d74mr42761036plg.92.1658383379052; Wed, 20 Jul 2022 23:02:59 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:58 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar Subject: [RFC PATCH v4 5/8] ext4: ext4_fc_track_inode() bug fix Date: Thu, 21 Jul 2022 06:02:43 +0000 Message-Id: <20220721060246.1696852-6-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 This patch fixes a bug in ext4_fc_track_inode() where we should not immediately return from ext4_fc_track_inode() if the inode is on fast commit list. It is possible that the inode is on fast commit list and then somebody calls ext4_fc_track_inode(). If we immediately return if the inode is on fc list, we will let the caller modify the inode while it is being committed. Signed-off-by: Harshad Shirwadkar --- fs/ext4/fast_commit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 608ae16afcd6..0307e21e5b29 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -611,8 +611,7 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode) if (!test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT) || (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) || - ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE) || - !list_empty(&ei->i_fc_list)) + ext4_test_mount_flag(inode->i_sb, EXT4_MF_FC_INELIGIBLE)) return; while (ext4_test_inode_state(inode, EXT4_STATE_FC_COMMITTING)) { From patchwork Thu Jul 21 06:02:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658870 X-Patchwork-Delegate: tytso@mit.edu 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=Cdvhy/MK; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMSQ2vD8z9sFk for ; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMSQ28b6z4xD9 for ; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMSQ260Dz4xG0; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) 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=Cdvhy/MK; 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 4LpMSQ21qMz4xD9 for ; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231707AbiGUGDR (ORCPT ); Thu, 21 Jul 2022 02:03:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiGUGDD (ORCPT ); Thu, 21 Jul 2022 02:03:03 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AF6E7AB07 for ; Wed, 20 Jul 2022 23:03:01 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id f11so875374plr.4 for ; Wed, 20 Jul 2022 23:03:01 -0700 (PDT) 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=OV09mUR7NPB7eGHDljRTvkjtRaYH2nALEITwnc5n28w=; b=Cdvhy/MKGUII3/qU50EOdqfATcKIX5hwsL8GfpvabwZKOI3h/UGcwXqDFplnvvBePa EFGkFIuxsmicr0QJvRC00IhNotbRHPrCgPpXHriCEk6Z/VO/XzaK9SDQSomI3TRGy65j ZZh4olytMlgiFWAHKfqRo30kFzp2XGTFRAP5DXAfYbZXG1nGzMwymjuyzqNLG/069y+f 9qhfa6WkyMq/dCT5O+uLK0lxMbHXs0ZrCd72fFMnE1+deivJhs3mLf9M2VLiR/jC2LKt evcdbFtqK4ux594+qEPO6wEWXGkdacMlCgXwC9UHicT4p2/L3m2D8xJ1mFWj44c1LjnQ H4GQ== 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=OV09mUR7NPB7eGHDljRTvkjtRaYH2nALEITwnc5n28w=; b=OiGiTT8+MAOGQl9SM1feEoOdjyZ7hEFRxPZ/B2XgIfQhWpIPRPC7zA2X6FKSEBg82r fPmZwHgayklc2udAQCYO0bXPffgHnJCtKvze9XMdJ4IowL/nJvKHe0pQQfpb8bsPieiV +ws2x+0XkSol54LOES00cxyD4ioVIDn/wSpffFf8lVm5qkxndT3h7/1u2xeolFzu26fb R/jQ27UFmt4SWTUqGnIRa3OelBFeISpb5Vi0HL+nHzcxKrZ5H5Uhzgc0RmcwS6EwGU+K GKCcn+M6UrN6TLTtQzMGCJS2zyb5KjE1rXrDW/Kpp5Ndq2iWrHfEL7EG0R7atuYd/Q0+ 7F/g== X-Gm-Message-State: AJIora9z853yQ2GhS989t1SW7Zg53fNMRO3r6ihWo0qM3sY2pZOpJ3W5 8MkNA//+xpSX0UCTxPHnsHhcShaFf8P4tYyg X-Google-Smtp-Source: AGRyM1v6kgGK3stYDp48C/tb2eTC4mYRQ1q9IdgakJ+nrgbLLpt8YTQBAFvnXWchXh6QZYdrW1aM2Q== X-Received: by 2002:a17:90b:4b8f:b0:1f0:7c99:10fd with SMTP id lr15-20020a17090b4b8f00b001f07c9910fdmr9509618pjb.86.1658383380329; Wed, 20 Jul 2022 23:03:00 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:02:59 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar , Jan Kara Subject: [RFC PATCH v4 6/8] ext4: drop i_fc_updates from inode fc info Date: Thu, 21 Jul 2022 06:02:44 +0000 Message-Id: <20220721060246.1696852-7-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 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 12c8691f08d3..51ed372faff0 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1061,9 +1061,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; @@ -2882,8 +2879,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 0307e21e5b29..a9cac460de26 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 Thu Jul 21 06:02:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658871 X-Patchwork-Delegate: tytso@mit.edu 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=ePiII6fq; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMSR0LyMz9sFk for ; Thu, 21 Jul 2022 16:03:19 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMSQ6mvZz4xD9 for ; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMSQ6kGRz4xG0; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) 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=ePiII6fq; 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 4LpMSQ6fRWz4xD9 for ; Thu, 21 Jul 2022 16:03:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbiGUGDS (ORCPT ); Thu, 21 Jul 2022 02:03:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231908AbiGUGDE (ORCPT ); Thu, 21 Jul 2022 02:03:04 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720287AB00 for ; Wed, 20 Jul 2022 23:03:02 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id e16so817993pfm.11 for ; Wed, 20 Jul 2022 23:03:02 -0700 (PDT) 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=PGAGNpawL/u7W8Xz6zunSJw4vTxtsiclV0M76QUq9aE=; b=ePiII6fqRq4HLP2bz2zP0693CqxfQQ6qgkVrqvEd0zDlET2JsD/Rwq0wvlllPBXsjZ TwbRzW4SrlDbqb6hs5Zc0/HI3/xk3pOET6ta0e50RZGiMr/bVgAmlnQjJSw0wjlCDY10 i3QLURY4WafdJLJd8R2d37fU2r0nqE+d50LZr9IwS0cOXXZm6bn3y9jBCcVjJKEixQSN FtFTyPkJ/VXYAdVDY7RtgTWoUYDOQtox6maWojTRBO5P5twbF2qxM89PRTC+nxpW3UVV 9VlGeDE9YriX3T2A+W28ExVgCLAoYihM7CPcG9SZ7avx9Ur98F92+Ot0oywrdmUwPB24 V/mw== 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=PGAGNpawL/u7W8Xz6zunSJw4vTxtsiclV0M76QUq9aE=; b=RTXXZFtmxxLluoE488hPlGK1/WsW+rsfVhLqT+QZRgZU/IaNu3uVQ6JXzlhYfxi7Br giNmYY9ccATMNwjIQd2QkFmjZKVtHYzNYIvr06m/Y0hNKaaNfDY9ykRZ9Tm9xd5Q6jGX XoPENM9RRvtvXIOuFd23BfZ+pPtAVG8FJBQtOQulttaNkDSJvlUeBgHNsJbTUSCHidWL B8K1lRJT+3zB6bN8OxIrJIoC5KgVGKckA8PN+mfRnushVUDIjmNxyXK3dggi9L5Sqkve Oh3bX6jpOkNsvdreVhq7/iRqnfxrWP60kqk4h6vU80e6Z1v5QDJqh+5DuXvS59ZAzC2j UBcw== X-Gm-Message-State: AJIora8vW0WRNdQ99pk3VqRcNmvr2Qp4u5VR5kblwF55TVDRrPwxVCyw 7calDKebKqvUGMihsNWEKdvTninRfDA+xCzy X-Google-Smtp-Source: AGRyM1uTIZn8Ctj6tmUHxi2UdsYSKxvznxBQuQkrt8ZDXz81/gbYt4DP449GpBsDVCTt1ZtFY3RSfw== X-Received: by 2002:a05:6a00:84e:b0:52b:a5fd:f0bc with SMTP id q14-20020a056a00084e00b0052ba5fdf0bcmr7066611pfk.86.1658383381460; Wed, 20 Jul 2022 23:03:01 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:03:00 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar Subject: [RFC PATCH v4 7/8] ext4: add lockdep annotation in fc commit path Date: Thu, 21 Jul 2022 06:02:45 +0000 Message-Id: <20220721060246.1696852-8-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 This patch adds lockdep annotation in fast commit commit path. Signed-off-by: Harshad Shirwadkar --- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/fast_commit.c | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 51ed372faff0..eabf0c9a3765 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1070,6 +1070,15 @@ struct ext4_inode_info { */ spinlock_t i_fc_lock; +#ifdef CONFIG_DEBUG_LOCK_ALLOC + /* + * Lockdep entity to track fast commit waiting dependencies. Any caller + * who sets / resets EXT4_STATE_FC_COMMITTING flag should let lockdep + * know that they are doing so by locking / unlocking fc_commit_map. + */ + struct lockdep_map i_fc_commit_map; + struct lock_class_key i_fc_commit_key; +#endif /* * i_disksize keeps track of what the inode size is ON DISK, not * in memory. During truncate, i_size is set to the new size by diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index a9cac460de26..727a87073e6a 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -201,6 +201,8 @@ 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); + lockdep_init_map(&ei->i_fc_commit_map, "i_fc_commit", + &ei->i_fc_commit_key, 0); } /* @@ -1061,6 +1063,7 @@ static int ext4_fc_perform_commit(journal_t *journal) 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); + mutex_acquire(&iter->i_fc_commit_map, 0, 0, _THIS_IP_); } spin_unlock(&sbi->s_fc_lock); jbd2_journal_unlock_updates(journal); @@ -1119,6 +1122,7 @@ static int ext4_fc_perform_commit(journal_t *journal) } list_for_each_entry(iter, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { ext4_clear_inode_state(inode, EXT4_STATE_FC_COMMITTING); + mutex_release(&iter->i_fc_commit_map, _THIS_IP_); /* * Make sure clearing of EXT4_STATE_FC_COMMITTING is * visible before we send the wakeup. Pairs with implicit @@ -1266,8 +1270,12 @@ 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) { - ext4_clear_inode_state(&iter->vfs_inode, - EXT4_STATE_FC_COMMITTING); + if (ext4_test_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_COMMITTING)) { + ext4_clear_inode_state(&iter->vfs_inode, + EXT4_STATE_FC_COMMITTING); + mutex_release(&iter->i_fc_commit_map, _THIS_IP_); + } if (iter->i_sync_tid <= tid) ext4_fc_reset_inode(&iter->vfs_inode); /* From patchwork Thu Jul 21 06:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: harshad shirwadkar X-Patchwork-Id: 1658872 X-Patchwork-Delegate: tytso@mit.edu 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=l49nNg/R; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LpMSR3TbPz9sFs for ; Thu, 21 Jul 2022 16:03:19 +1000 (AEST) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4LpMSR2n4fz4xD9 for ; Thu, 21 Jul 2022 16:03:19 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4LpMSR2kh8z4xG0; Thu, 21 Jul 2022 16:03:19 +1000 (AEST) 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=l49nNg/R; 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 4LpMSR2fK6z4xD9 for ; Thu, 21 Jul 2022 16:03:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231855AbiGUGDT (ORCPT ); Thu, 21 Jul 2022 02:03:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231883AbiGUGDO (ORCPT ); Thu, 21 Jul 2022 02:03:14 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA14D7AB35 for ; Wed, 20 Jul 2022 23:03:03 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id k16so858616pls.8 for ; Wed, 20 Jul 2022 23:03:03 -0700 (PDT) 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=RyJ/2ovef+Q1/jKxQ9/xhbRuIU47cSBso2MBQ15p+0w=; b=l49nNg/RxE+hO9L4OR1icl2zJRiDb4bdPpvAWun/lbU7AfZw62J02Y0/q7yRj0EPua 3s+SNLH1/18ZLbHaC3v2KXV5IkBhsslfKX3miJhTk/jsuvB6Zelw6ISQ5u/5xgXQ81rG spWMr8P5aJesK1V3CrgVFIdNdxcB7PahnOUmyiatTgbfuENzkki3plhC4rfty2VRUIzr bph8AAqbEWGv2jE50KnIkWFJsk0hy3pjQDWyhGffMrExhXlb1lLwY/TTdAKEAS6699YQ VaJgKbtZnInS06LozxvbHTLJL9G6qLyHum7WuyhkuILomDzsgZtI/EU5v2GSlIJaHQpx rAHw== 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=RyJ/2ovef+Q1/jKxQ9/xhbRuIU47cSBso2MBQ15p+0w=; b=Jha7JhRpgzkTovnPj0qsiaA8BvRzi2TaaWqMSlErWKSLidQA0Rj6b0CFor89SJsxBT nE0WCPY5V/1DLf+MBgktgUOMHHDMqi1WnDHGNOZ1b6LJ+gW997apIhBtWWI4FHQRKkU7 bQRCoMxgOeE6Av2dPKI/OcQ2qaKUvuQgUL2tTp/iPGCPNp8oO8hcTmSNBKwr9l0AO2sn mlItSzUkLyxwrfUnyRuVwFOEUOJLTFZ1Nk0FGT1UVUCmLpQA85R+t7tmo9EfKrtEV2RG jTyQmY5FBgCvyp0wOqBE0d9D6/mqreSMXwGCo+cZc31tyOWpdGFaRYC3kdy45cSlHa+G HO7w== X-Gm-Message-State: AJIora/LUExogSCYyi27oNfsbbJWSdxWmA+La6gTTd+x/MuvBqXnZknR p6SO9d6ikzb6tg3H3OYUNVzHW6+GkNPrWRjQ X-Google-Smtp-Source: AGRyM1sBHDiKBI1dl8yBUUuCG22gijD+vRo3KaYHJzx66WMiwILq+GLi6Kh9Vye/v35BkAzdAyGEbw== X-Received: by 2002:a17:90a:4e0f:b0:1f2:10b0:2f60 with SMTP id n15-20020a17090a4e0f00b001f210b02f60mr9567190pjh.161.1658383382577; Wed, 20 Jul 2022 23:03:02 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.133.83.34.bc.googleusercontent.com. [34.83.133.34]) by smtp.googlemail.com with ESMTPSA id rm10-20020a17090b3eca00b001ed27d132c1sm9105377pjb.2.2022.07.20.23.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:03:01 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Harshad Shirwadkar , Jan Kara Subject: [RFC PATCH v4 8/8] ext4: update code documentation Date: Thu, 21 Jul 2022 06:02:46 +0000 Message-Id: <20220721060246.1696852-9-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220721060246.1696852-1-harshadshirwadkar@gmail.com> References: <20220721060246.1696852-1-harshadshirwadkar@gmail.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 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 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 | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 727a87073e6a..7a7bb540904f 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,12 @@ * 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. + * 1) Handle more ineligible cases. * - * 2) Handle more ineligible cases. + * 2) Change ext4_fc_commit() to lookup logical to physical mapping using extent + * status tree. This would get rid of the need to call ext4_fc_track_inode() + * before acquiring i_data_sem. To do that we would need to ensure that + * modified extents from the extent status tree are not evicted from memory. */ #include