linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: [PATCH v6 09/20] ext4: add inode tracking and ineligible marking routines
Date: Wed,  8 Apr 2020 14:55:19 -0700	[thread overview]
Message-ID: <20200408215530.25649-9-harshads@google.com> (raw)
In-Reply-To: <20200408215530.25649-1-harshads@google.com>

From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

Under certain situations, such as zeroing a range, there are only data
updates and no metadata updates. We need to track such inodes for fast
commits. Also, under some situations, we need to fall back to full
commits because remembering the delta is either not yet supported or
fast commits won't be "fast" enough. In such cases, we need to mark
inodes as ineligible for fast commits. Add routines that allow
tracking just the inodes and marking inodes as well as entire file
system as fast commit ineligible.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
 fs/ext4/ext4.h              |  2 ++
 fs/ext4/ext4_jbd2.c         | 57 +++++++++++++++++++++++++++++++++++++
 fs/ext4/ext4_jbd2.h         |  4 +++
 fs/ext4/super.c             |  1 +
 include/trace/events/ext4.h | 22 ++++++++++++++
 5 files changed, 86 insertions(+)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 669ecf12d392..e9c82f555b6d 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1154,6 +1154,7 @@ struct ext4_inode_info {
 #define	EXT4_ERROR_FS			0x0002	/* Errors detected */
 #define	EXT4_ORPHAN_FS			0x0004	/* Orphans being recovered */
 #define EXT4_FC_REPLAY			0x0008	/* Fast commit replay ongoing */
+#define EXT4_FC_INELIGIBLE		0x0010	/* Fast commit ineligible */
 
 /*
  * Misc. filesystem flags
@@ -1735,6 +1736,7 @@ enum {
 	EXT4_STATE_EXT_PRECACHED,	/* extents have been precached */
 	EXT4_STATE_LUSTRE_EA_INODE,	/* Lustre-style ea_inode */
 	EXT4_STATE_VERITY_IN_PROGRESS,	/* building fs-verity Merkle tree */
+	EXT4_STATE_FC_ELIGIBLE,		/* File is Fast commit eligible */
 };
 
 #define EXT4_INODE_BIT_FNS(name, field, offset)				\
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index ccaaf1c09ba6..9f12ae2fb3ab 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -379,6 +379,7 @@ void ext4_reset_inode_fc_info(struct inode *inode)
 	ei->i_fc_lblk_start = 0;
 	ei->i_fc_lblk_end = 0;
 	ei->i_fc_mdata_update = NULL;
+	ext4_clear_inode_state(inode, EXT4_STATE_FC_ELIGIBLE);
 }
 
 void ext4_init_inode_fc_info(struct inode *inode)
@@ -410,6 +411,36 @@ static inline tid_t get_running_txn_tid(struct super_block *sb)
 	return 0;
 }
 
+bool ext4_is_inode_fc_ineligible(struct inode *inode)
+{
+	if (get_running_txn_tid(inode->i_sb) == EXT4_I(inode)->i_fc_tid)
+		return !ext4_test_inode_state(inode, EXT4_STATE_FC_ELIGIBLE);
+	return false;
+}
+
+void ext4_fc_mark_ineligible(struct inode *inode, int reason)
+{
+	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	if (!ext4_should_fast_commit(inode->i_sb) ||
+	    (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY))
+		return;
+
+	if (sbi->s_journal)
+		ei->i_fc_tid = get_running_txn_tid(inode->i_sb);
+	ext4_clear_inode_state(inode, EXT4_STATE_FC_ELIGIBLE);
+
+	ext4_fc_enqueue_inode(inode);
+}
+
+void ext4_fc_disable(struct super_block *sb, int reason)
+{
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+	sbi->s_mount_state |= EXT4_FC_INELIGIBLE;
+}
+
 /*
  * Generic fast commit tracking function. If this is the first
  * time this we are called after a full commit, we initialize
@@ -435,10 +466,15 @@ static int __ext4_fc_track_template(
 
 	write_lock(&ei->i_fc_lock);
 	if (running_txn_tid == ei->i_fc_tid) {
+		if (!ext4_test_inode_state(inode, EXT4_STATE_FC_ELIGIBLE)) {
+			write_unlock(&ei->i_fc_lock);
+			return -EINVAL;
+		}
 		update = true;
 	} else {
 		ext4_reset_inode_fc_info(inode);
 		ei->i_fc_tid = running_txn_tid;
+		ext4_set_inode_state(inode, EXT4_STATE_FC_ELIGIBLE);
 	}
 	ret = __fc_track_fn(inode, args, update);
 	write_unlock(&ei->i_fc_lock);
@@ -535,6 +571,27 @@ void ext4_fc_track_create(struct inode *inode, struct dentry *dentry)
 	trace_ext4_fc_track_create(inode, dentry, ret);
 }
 
+static int __ext4_fc_add_inode(struct inode *inode, void *arg, bool update)
+{
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	if (update)
+		return -EEXIST;
+
+	ei->i_fc_lblk_start = (i_size_read(inode) - 1) >> inode->i_blkbits;
+	ei->i_fc_lblk_end = (i_size_read(inode) - 1) >> inode->i_blkbits;
+
+	return 0;
+}
+
+void ext4_fc_track_inode(struct inode *inode)
+{
+	int ret;
+
+	ret = __ext4_fc_track_template(inode, __ext4_fc_add_inode, NULL);
+	trace_ext4_fc_track_inode(inode, ret);
+}
+
 struct __ext4_fc_track_range_args {
 	ext4_lblk_t start, end;
 };
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index 8fbd09dbfeca..b1239d6be713 100644
--- a/fs/ext4/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -538,4 +538,8 @@ void ext4_fc_track_unlink(struct inode *inode, struct dentry *dentry);
 void ext4_fc_track_link(struct inode *inode, struct dentry *dentry);
 void ext4_fc_track_create(struct inode *inode, struct dentry *dentry);
 int __init ext4_init_fc_dentry_cache(void);
+void ext4_fc_track_inode(struct inode *inode);
+void ext4_fc_mark_ineligible(struct inode *inode, int reason);
+void ext4_fc_disable(struct super_block *sb, int reason);
+
 #endif	/* _EXT4_JBD2_H */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a93dada07623..695bc43d5916 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4422,6 +4422,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 
 	INIT_LIST_HEAD(&sbi->s_fc_q);
 	INIT_LIST_HEAD(&sbi->s_fc_dentry_q);
+	sbi->s_mount_state &= ~EXT4_FC_INELIGIBLE;
 	spin_lock_init(&sbi->s_fc_lock);
 	sb->s_root = NULL;
 
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index 577c6230b23a..5d278a8082a7 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -2751,6 +2751,28 @@ DEFINE_TRACE_DENTRY_EVENT(create);
 DEFINE_TRACE_DENTRY_EVENT(link);
 DEFINE_TRACE_DENTRY_EVENT(unlink);
 
+TRACE_EVENT(ext4_fc_track_inode,
+	    TP_PROTO(struct inode *inode, int ret),
+
+	    TP_ARGS(inode, ret),
+
+	    TP_STRUCT__entry(
+		    __field(dev_t, dev)
+		    __field(int, ino)
+		    __field(int, error)
+		    ),
+
+	    TP_fast_assign(
+		    __entry->dev = inode->i_sb->s_dev;
+		    __entry->ino = inode->i_ino;
+		    __entry->error = ret;
+		    ),
+
+	    TP_printk("dev %d:%d, inode %d, error %d",
+		      MAJOR(__entry->dev), MINOR(__entry->dev),
+		      __entry->ino, __entry->error)
+	);
+
 TRACE_EVENT(ext4_fc_track_range,
 	    TP_PROTO(struct inode *inode, long start, long end, int ret),
 
-- 
2.26.0.110.g2183baf09c-goog


  parent reply	other threads:[~2020-04-08 21:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-08 21:55 [PATCH v6 01/20] ext4: update docs for fast commit feature Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 02/20] ext4: add handling for extended mount options Harshad Shirwadkar
2020-04-09 19:47   ` Andreas Dilger
2020-04-08 21:55 ` [PATCH v6 03/20] ext4, jbd2: add fast commit initialization routines Harshad Shirwadkar
2020-04-10 12:12   ` Andreas Dilger
2020-04-10 17:51     ` harshad shirwadkar
2020-04-08 21:55 ` [PATCH v6 04/20] jbd2: add fast commit block tracker variables Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 05/20] jbd2: disable fast commits if journal is empty Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 06/20] jbd2: fast commit main commit path changes Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 07/20] ext4: add generic diff tracking routines and range tracking Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 08/20] ext4: add directory entry tracking routines Harshad Shirwadkar
2020-04-08 21:55 ` Harshad Shirwadkar [this message]
2020-04-08 21:55 ` [PATCH v6 10/20] ext4: break ext4_unlink() and ext4_link() Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 11/20] ext4: add fast commit track points Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 12/20] ext4: add fast commit on-disk format structs Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 13/20] jbd2: add new APIs for commit path of fast commits Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 14/20] ext4: main commit routine for " Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 15/20] jbd2: add fast commit recovery path support Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 16/20] ext4: fast commit recovery path preparation Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 17/20] ext4: add idempotent helpers to manipulate bitmaps Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 18/20] ext4: disable certain features in replay path Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 19/20] ext4: add fast commit " Harshad Shirwadkar
2020-04-08 21:55 ` [PATCH v6 20/20] ext4: add debug mount option to test fast commit replay Harshad Shirwadkar
2020-04-09 22:01 ` [PATCH v6 01/20] ext4: update docs for fast commit feature Andreas Dilger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200408215530.25649-9-harshads@google.com \
    --to=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).