Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2256306lqo; Sun, 19 May 2024 22:52:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBYN+ttAjWQdEdoYQvM0MaZll8F5vpP9epFVhU38OhkyvGRwEuUZa+7WRmJdeefG+DdPbAPraLYrX5mvI2dFD3Q33g8v3yqaTux8UI9A== X-Google-Smtp-Source: AGHT+IE3JDAxfGbIPrwETPfMEjQ2se+u1ZeZJ3lWMeAW9SM1azfvPtv9/rerj+q1hz0cqS/IWC/3 X-Received: by 2002:a05:6a00:13a6:b0:6ed:5f64:2fef with SMTP id d2e1a72fcca58-6f4e02cec14mr32584872b3a.17.1716184344803; Sun, 19 May 2024 22:52:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716184344; cv=pass; d=google.com; s=arc-20160816; b=fEmNzIJZ2fzX+3yqBjrP4R/wgOkt5qF0Yrg15iuNKbQXR8CPDLeQf12yfcQgmUgQgx yxFoEvJDFUhguZ3+sERqod2Xuxv4cQdtaEX1jnwW8MY1XgIgmk8LyUK1b9mBWp3EEa2x YRKzhQidzJjKj6yRNCtup/7v8YEvOTAG9pAF3b6hdcqCmP4MXrYwMv91tINy/Atyn4uV CWH5T/PwaJPrjC7+HkJcrdlm4s6vACwJRGwVB37IiP6RdJaXI9jTKfO9WsOz5Be0BfuE /foTa1TronhOKEzH0CQ+B2tahM4YFexN444hEKrBZnedLeadBwYYHPVI9k7CzLtTuB/u PsIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YRCrYTwwFVDixnXXAD5H33jtqfwfso/HwA9nJ4FRhxI=; fh=UlOqzFGIERK+QMf/CPOKlq/OPxKMX/nridyXfPastG8=; b=MjPauDfOMEPbAbLxO3ps0jI6sMU6MoyDSYu5mI2pgy/chLg1u7eLLqMp0CEydjI5vF N61OD5ArIlYJERcfmh4jiFOfSYFEHdBw/RV+7vr05OnmukRfnq8hghgif19eA19RpKnd WqlBc0P7GCZBxXbYdQN7rccVz5fo0hpC0O/UNcxV2B6eNTxwjYWIwRHSZJbzazWM+ae2 cG5+EU2lAJjF42PyBQP85q4JddOz2vjf4JMrBpqGxDJ3us47BflElU4nYprdtE7MUJ/q 6FZgXsysI+uAxtHZ6bGsZFVxDdHnGzV789VoY1vqmYFUoxBcdf4Q0X2lsB6UN9Vwq2MU 3v+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LJgJ2wPm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-ext4+bounces-2585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2aeee59si1963592b3a.187.2024.05.19.22.52.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 22:52:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LJgJ2wPm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-ext4+bounces-2585-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2585-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6A0EC282162 for ; Mon, 20 May 2024 05:52:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F9A217C73; Mon, 20 May 2024 05:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LJgJ2wPm" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E65214AB2 for ; Mon, 20 May 2024 05:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716184334; cv=none; b=SHar2Ph/wVXv2OvNWdOu98UoGUTtw/dnQ2I8BoDlUhWcp7G3a69PUG1X/B0+N1lG1z9fqwtT/ns4gzGhyNKQ+6BDcbAfRMeq51L+dFMJhJL+65Kfy1dTPRpJOycF+E9ZR0wwDi2qgOmRudABhBt/z5v5xBQDPH4xlCvaRDY+EXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716184334; c=relaxed/simple; bh=egkFtAgshc186tNo3bCFe97o/987CsuRW0JAveq6c9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u+vccLfT6mjri0ZQFe6jElPGactkH+qUisadWsSDEPuo7jrCEaYaFbTQKxTvLXK/mw4kOT+wi5SGHCoWaupcefQpCdp0agkMRv019A/RxPuGe/l5Pz8JKyGwlBxSYBhp+AiuI0+GnqyoMQap7OGWauumceY6zm1x53wVRPRxSgU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LJgJ2wPm; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-23ee34c33ceso1021029fac.3 for ; Sun, 19 May 2024 22:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716184331; x=1716789131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YRCrYTwwFVDixnXXAD5H33jtqfwfso/HwA9nJ4FRhxI=; b=LJgJ2wPm5KlVGIlX3f60hlp5bUXJ6BaYQdMB/huMNC+N6WlYZoDf/hqTIf+FKTmwwv V0QpL30pUv/MaGDmJMlAe86+uIAGRzxZN7IO5pbJF6Njz+O4mDrx0N8FCYwbTyQ3G3pc yHUWGm1gnMikUGY/yIYOEuInZSctK73vhkMr8L5XNC9NFbQ08uFHpz8YkX2HUem4c8J+ yJvzldbr0/VxmMpo14tGGMq5tjLEOk+JrrytaFcEotFI+L/ISj4ZKI7CyolG7dmpLhKE xB+gNUoW6mEoReFYtfFv5NHboDsUqzDakrkQyn/axUT66Emdqx3FPWz7XXqnNk/qzJWI jATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716184331; x=1716789131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YRCrYTwwFVDixnXXAD5H33jtqfwfso/HwA9nJ4FRhxI=; b=MCfSvBnCogwp0xfIJlFBTVS5c7Z8WD9eFT9WaK7C/BCFpkyWnQcZckUI4JnfhmQVcp SZa+r8b3kETx78MWaIs3ZNu+E0M+tpgIVzxxKMwv9Ah7VbtRXTF8d5SE5USpv2LDUA70 HmI1VSJjzvchp6a29ib3RUW5Tbdg9MATl2+WJKy+OTxIffmdPC5t4GNDUMgFr2S10jrr IeWb/8Hdl5iN5lCILRvl93X0oYkfK56DQdmEaRWgytGc9xuR5AyprF7GCoeCe7tyF9Ix 33D8JpPjdfLMkHnIA3E1LkgwZUGabdnW/0vEIhv5/oztoA5u1EN433VRJ4AB923Dt7iO PWEw== X-Gm-Message-State: AOJu0YyjvTKQd4QH1VfrOjR/VZA52YLfW1AlH2ZIAuwsfhpA/rhVEqtY MVmB6oEJV0iQ2IshEjmn0IwN8Nmh4JysRrrTK9HbWxGBSeYk33leg0KkeSEp X-Received: by 2002:a05:6870:944f:b0:23f:ba54:5f41 with SMTP id 586e51a60fabf-24172a3f4d5mr31884950fac.1.1716184331204; Sun, 19 May 2024 22:52:11 -0700 (PDT) Received: from harshads.c.googlers.com.com (34.85.168.34.bc.googleusercontent.com. [34.168.85.34]) by smtp.googlemail.com with ESMTPSA id 41be03b00d2f7-659f66bf18csm6769297a12.46.2024.05.19.22.52.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 22:52:10 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, saukad@google.com, harshads@google.com, Harshad Shirwadkar Subject: [PATCH 04/10] ext4: rework fast commit commit path Date: Mon, 20 May 2024 05:51:47 +0000 Message-ID: <20240520055153.136091-5-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240520055153.136091-1-harshadshirwadkar@gmail.com> References: <20240520055153.136091-1-harshadshirwadkar@gmail.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- fs/ext4/fast_commit.c | 75 ++++++++++++++++++++++++++++--------------- fs/jbd2/journal.c | 2 -- fs/jbd2/transaction.c | 41 +++++++++++++++-------- include/linux/jbd2.h | 1 + 4 files changed, 79 insertions(+), 40 deletions(-) diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index fa93ce399440..3aca5b20aac5 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -290,20 +290,30 @@ void ext4_fc_del(struct inode *inode) if (ext4_fc_disabled(inode->i_sb)) 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 @@ -326,8 +336,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; } /* @@ -999,19 +1007,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(journal, ei->jinode); if (ret) @@ -1124,6 +1119,20 @@ static int ext4_fc_perform_commit(journal_t *journal) int ret = 0; u32 crc = 0; + /* + * Wait for all the handles of the current transaction to complete + * and then lock the journal. Since this is essentially the commit + * path, we don't need to wait for reserved handles. + */ + jbd2_journal_lock_updates_no_rsv(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; @@ -1174,6 +1183,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); @@ -1311,13 +1332,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 b6c114c11b97..f243552eadad 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -742,7 +742,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; } @@ -754,7 +753,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); diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index cb0b8d6fc0c6..4361e5c56490 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -865,25 +865,15 @@ void jbd2_journal_wait_updates(journal_t *journal) } } -/** - * jbd2_journal_lock_updates () - establish a transaction barrier. - * @journal: Journal to establish a barrier on. - * - * This locks out any further updates from being started, and blocks - * until all existing updates have completed, returning only once the - * journal is in a quiescent state with no updates running. - * - * The journal lock should not be held on entry. - */ -void jbd2_journal_lock_updates(journal_t *journal) +static void __jbd2_journal_lock_updates(journal_t *journal, bool wait_on_rsv) { jbd2_might_wait_for_commit(journal); write_lock(&journal->j_state_lock); ++journal->j_barrier_count; - /* Wait until there are no reserved handles */ - if (atomic_read(&journal->j_reserved_credits)) { + if (wait_on_rsv && atomic_read(&journal->j_reserved_credits)) { + /* Wait until there are no reserved handles */ write_unlock(&journal->j_state_lock); wait_event(journal->j_wait_reserved, atomic_read(&journal->j_reserved_credits) == 0); @@ -904,6 +894,31 @@ void jbd2_journal_lock_updates(journal_t *journal) mutex_lock(&journal->j_barrier); } +/** + * jbd2_journal_lock_updates () - establish a transaction barrier. + * @journal: Journal to establish a barrier on. + * + * This locks out any further updates from being started, and blocks + * until all existing updates have completed, returning only once the + * journal is in a quiescent state with no updates running. + * + * The journal lock should not be held on entry. + */ +void jbd2_journal_lock_updates(journal_t *journal) +{ + __jbd2_journal_lock_updates(journal, true); +} + +/** + * jbd2_journal_lock_updates_no_rsv - same as above, but doesn't + * wait for reserved handles to finish. + * @journal: Journal to establish barrier on. + */ +void jbd2_journal_lock_updates_no_rsv(journal_t *journal) +{ + __jbd2_journal_lock_updates(journal, false); +} + /** * jbd2_journal_unlock_updates () - release barrier * @journal: Journal to release the barrier on. diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 7479f64c0939..cfac287c0ad4 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -1531,6 +1531,7 @@ bool jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio); extern int jbd2_journal_stop(handle_t *); extern int jbd2_journal_flush(journal_t *journal, unsigned int flags); extern void jbd2_journal_lock_updates (journal_t *); +extern void jbd2_journal_lock_updates_no_rsv(journal_t *journal); extern void jbd2_journal_unlock_updates (journal_t *); void jbd2_journal_wait_updates(journal_t *); -- 2.45.0.rc1.225.g2a3ae87e7f-goog