ext4: add fast commits feature
v8 cover ext4: add fast commits feature
This patch series adds support for fast commits which is a simplified version of the scheme proposed by Park and Shin, in their paper, "iJournaling: Fine-Grained Journaling for Improving the Latency of Fsync System Call"[1]. The basic idea of fast commits is to make JBD2 give the client file system an opportunity to perform a faster commit. Only if the file system cannot perform such a commit operation, then JBD2 should fall back to traditional commits.
Because JBD2 operates at block granularity, for every file system metadata update it commits all the changed blocks are written to the journal at commit time. This is inefficient because updates to some blocks that JBD2 commits are derivable from some other blocks. For example, if a new extent is added to an inode, then corresponding updates to the inode table, the block bitmap, the group descriptor and the superblock can be derived based on just the extent information and the corresponding inode information. So, if we take this relationship between blocks into account and replay the journalled blocks smartly, we could increase performance of file system commits significantly.
Fast commits introduced in this patch have two main contributions:
(1) Making JBD2 fast commit aware, so that clients of JBD2 can implement fast commits
(2) Add support in ext4 to use JBD2's new interfaces and implement fast commits
Fast commit operation
---------------------
The new fast commit operation works by tracking file system deltas since last commit in memory and committing these deltas to disk during fsync(). Ext4 maintains directory entry updates in an in-memory queue. Also, the inodes that have changed since last commit are maintained in an in-memory queue. These queues are flushed to disk during the commit time in a log-structured way. Fast commit area is organized as a log of TAG-LENGTH-VALUE tuples with a special "tail" tag marking the end of a commit. If certain operation prevents fast commit from happening, the commit code falls back to JBD2 full commit operation and thus invalidating all the fast commits since last full commit. JBD2 provides new jbd2_fc_start() and jbd2_fc_stop() functions to co-ordinate between JBD2's full commits and client file system's fast commits.
Recovery operation
------------------
During recovery, JBD2 lets the client file system handle fast commit blocks as it wants. After performing transaction replay, JBD2 invokes client file system's recovery path handler. During the scan phase, Ext4's recovery path handler determines the validity of fast commit log by making sure CRC and TID of fast commits are valid. During the replay phase, the recovery handler replays tags one by one. These replay handlers are idempotent. Thus, if we crash in the middle of recovery, Ext4 can restart the log replay and reach the identical final state.
Testing
-------
e2fsprogs was updated to set fast commit feature flag and to ignore fast commit blocks during e2fsck.
https://github.com/harshadjs/e2fsprogs.git
No regressions were introduced in smoke tests.
Performance Evaluation
----------------------
Ext4 performance was compared with and without fast commits using fsmark, dbench and filebench benchmarks with local file system and over NFS. This is the summary of results:
|-----------+-------------------+----------------+----------------+------------| | Benchmark | Config | No FC | FC | % increase | |-----------+-------------------+----------------+----------------+------------| | Fsmark | Local, 8 threads | 1475.1 files/s | 4309.8 files/s | 192.2 | | Fsmark | NFS, 4 threads | 299.4 files/s | 409.45 files/s | 36.8 | |-----------+-------------------+----------------+----------------+------------| | Dbench | Local, 2 procs | 33.32 MB/s | 70.87 MB/s | 112.7 | | Dbench | NFS, 2 procs | 8.84 MB/s | 11.88 MB/s | 34.4 | |-----------+-------------------+----------------+----------------+------------| | Dbench | Local, 10 procs | 90.48 MB/s | 110.12 MB/s | 21.7 | | Dbench | NFS, 10 procs | 34.62 MB/s | 52.83 MB/s | 52.6 | |-----------+-------------------+----------------+----------------+------------| | FileBench | Local, 16 threads | 10442.3 ops/s | 18617.8 ops/s | 78.3 | | | (Varmail) | | | | | FileBench | NFS, 16 threads | 1531.3 ops/s | 2681.5 ops/s | 75.1 | | | (Varmail) | | | | |-----------+-------------------+----------------+----------------+------------|
---
Changes since V7:
- Fixed compilation errors for (patch 5/7) "ext4: main fast-commit commit path"
Changes since V6:
- Rebased on top of v5.7
- Re-designed the on-disk format
- Handled extent tree splitting during recovery (by adding a simple allocator)
- Handled inode deletion case in fast commits
- Added more documentation in the code
Harshad Shirwadkar (7):
doc: update ext4 and journalling docs to include fast commit feature
ext4: add fast_commit feature and handling for extended mount options ext4 / jbd2: add fast commit initialization
jbd2: add fast commit machinery
ext4: main fast-commit commit path
jbd2: fast commit recovery path
ext4: fast commit recovery path
Documentation/filesystems/ext4/journal.rst | 66 + Documentation/filesystems/journalling.rst | 28 + fs/ext4/Makefile | 3 +- fs/ext4/acl.c | 2 + fs/ext4/balloc.c | 7 +- fs/ext4/ext4.h | 88 ++ fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/extents.c | 258 +++- fs/ext4/extents_status.c | 24 + fs/ext4/fast_commit.c | 2064 ++++++++++++++++++++++++++++ fs/ext4/fast_commit.h | 159 +++ fs/ext4/file.c | 10 +- fs/ext4/fsync.c | 2 +- fs/ext4/ialloc.c | 165 ++- fs/ext4/inode.c | 130 +- fs/ext4/ioctl.c | 22 +- fs/ext4/mballoc.c | 225 ++- fs/ext4/mballoc.h | 2 + fs/ext4/namei.c | 179 ++- fs/ext4/super.c | 73 +- fs/ext4/xattr.c | 3 + fs/jbd2/commit.c | 60 + fs/jbd2/journal.c | 238 +++- fs/jbd2/recovery.c | 56 +- include/linux/jbd2.h | 91 +- include/trace/events/ext4.h | 228 ++-
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 1/7 doc: update ext4 and journalling docs to include fast commit feature
This patch adds necessary documentation for fast commits.
--- Documentation/filesystems/ext4/journal.rst | 66 ++++++++++++++++++++++ Documentation/filesystems/journalling.rst | 28 +++++++++ 2 files changed, 94 insertions(+)
Documentation/filesystems/ext4/journal.rst +66 -0
@@ -28,6 +28,17 @@ metadata are written to disk through the journal. This is slower but safest. If ``data=writeback``, dirty data blocks are not flushed to the disk before the metadata are written to disk through the journal. +In case of ``data=ordered`` mode, Ext4 also supports fast commits which +help reduce commit latency significantly. The default ``data=ordered`` +mode works by logging metadata blocks tothe journal. In fast commit +mode, Ext4 only stores the minimal delta needed to recreate the +affected metadata in fast commit space that is shared with JBD2. +Once the fast commit area fills in or if fast commit is not possible +or if JBD2 commit timer goes off, Ext4 performs a traditional full commit. +A full commit invalidates all the fast commits that happened before +it and thus it makes the fast commit area empty for further fast +commits. This feature needs to be enabled at compile time. + The journal inode is typically inode 8. The first 68 bytes of the journal inode are replicated in the ext4 superblock. The journal itself is normal (but hidden) file within the filesystem. The file usually
@@ -609,3 +620,58 @@ bytes long (but uses a full block): - h\_commit\_nsec - Nanoseconds component of the above timestamp. +Fast commits +~~~~~~~~~~~~ + +Fast commit area is organized as a log of tag tag length values. Each TLV has +a ``struct ext4_fc_tl`` in the beginning which stores the tag and the length +of the entire field. It is followed by variable length tag specific value. +Here is the list of supported tags and their meanings: + +.. list-table:: + :widths: 8 20 20 32 + :header-rows: 1 + + * - Tag + - Meaning + - Value struct + - Description + * - EXT4_FC_TAG_HEAD + - Fast commit area header + - ``struct ext4_fc_head`` + - Stores the TID of the transaction after which these fast commits should + be applied. + * - EXT4_FC_TAG_ADD_RANGE + - Add extent to inode + - ``struct ext4_fc_add_range`` + - Stores the inode number and extent to be added in this inode + * - EXT4_FC_TAG_DEL_RANGE + - Remove logical offsets to inode + - ``struct ext4_fc_del_range`` + - Stores the inode number and the logical offset range that needs to be + removed + * - EXT4_FC_TAG_CREAT + - Create directory entry for a newly created file + - ``struct ext4_fc_dentry_info`` + - Stores the parent inode numer, inode number and directory entry of the + newly created file + * - EXT4_FC_TAG_LINK + - Link a directory entry to an inode + - ``struct ext4_fc_dentry_info`` + - Stores the parent inode numer, inode number and directory entry + * - EXT4_FC_TAG_UNLINK + - Unink a directory entry of an inode + - ``struct ext4_fc_dentry_info`` + - Stores the parent inode numer, inode number and directory entry + + * - EXT4_FC_TAG_PAD + - Padding (unused area) + - None + - Unused bytes in the fast commit area. + + * - EXT4_FC_TAG_TAIL + - Mark the end of a fast commit + - ``struct ext4_fc_tail`` + - Stores the TID of the commit, CRC of the fast commit of which this tag + represents the end of +
Documentation/filesystems/journalling.rst +28 -0
@@ -132,6 +132,34 @@ The opportunities for abuse and DOS attacks with this should be obvious, if you allow unprivileged userspace to trigger codepaths containing these calls. +Fast commits +~~~~~~~~~~~~ + +JBD2 to also allows you to perform file-system specific delta commits known as +fast commits. In order to use fast commits, you first need to call +:c:func:`jbd2_fc_init` and tell how many blocks at the end of journal +area should be reserved for fast commits. Along with that, you will also need +to set following callbacks that perform correspodning work: + +`journal->j_fc_cleanup_cb`: Cleanup function called after every full commit and +fast commit. + +`journal->j_fc_replay_cb`: Replay function called for replay of fast commit +blocks. + +File system is free to perform fast commits as and when it wants as long as it +gets permission from JBD2 to do so by calling the function +:c:func:`jbd2_fc_start()`. Once a fast commit is done, the client +file system should tell JBD2 about it by calling :c:func:`jbd2_fc_stop()`. +If file system wants JBD2 to perform a full commit immediately after stopping +the fast commit it can do so by calling :c:func:`jbd2_fc_stop_do_commit()`. +This is useful if fast commit operation fails for some reason and the only way +to guarantee consistency is for JBD2 to perform the full traditional commit. + +JBD2 helper functions to manage fast commit buffers. File system can use +:c:func:`jbd2_fc_get_buf()` and :c:func:`jbd2_fc_wait_bufs()` to allocate +and wait on IO completion of fast commit buffers. + Summary ~~~~~~~
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 2/7 ext4: add fast_commit feature and handling for extended mount options
In reply to Harshad ShirwadkarWe are running out of mount option bits. Add handling for using s_mount_opt2. Add ext4 and jbd2 fast commit feature flag and also add ability to turn on / off the fast commit feature in Ext4.
--- fs/ext4/ext4.h | 4 ++++ fs/ext4/super.c | 23 +++++++++++++++++++---- include/linux/jbd2.h | 5 ++++- 3 files changed, 27 insertions(+), 5 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -1172,6 +1172,8 @@ struct ext4_inode_info {#define EXT4_MOUNT2_EXPLICIT_JOURNAL_CHECKSUM 0x00000008/* User explicitly specified journal checksum */ +#define EXT4_MOUNT2_JOURNAL_FAST_COMMIT 0x00000010/* Journal fast commit */ +#define clear_opt (sb, opt) EXT4_SB(sb)->s_mount_opt &= \ ~EXT4_MOUNT_##opt#define set_opt (sb, opt) EXT4_SB(sb)->s_mount_opt |= \
@@ -1763,6 +1765,7 @@ static inline bool ext4_verity_in_progress(struct inode *inode)#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020#define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200 +#define EXT4_FEATURE_COMPAT_FAST_COMMIT 0x0400#define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
@@ -1865,6 +1868,7 @@ EXT4_FEATURE_COMPAT_FUNCS(xattr, EXT_ATTR) EXT4_FEATURE_COMPAT_FUNCS(resize_inode, RESIZE_INODE) EXT4_FEATURE_COMPAT_FUNCS(dir_index, DIR_INDEX) EXT4_FEATURE_COMPAT_FUNCS(sparse_super2, SPARSE_SUPER2) +EXT4_FEATURE_COMPAT_FUNCS(fast_commit, FAST_COMMIT) EXT4_FEATURE_COMPAT_FUNCS(stable_inodes, STABLE_INODES)EXT4_FEATURE_RO_COMPAT_FUNCS (sparse_super,SPARSE_SUPER )
fs/ext4/super.c +19 -4
@@ -1521,6 +1521,7 @@ enum { Opt_dioread_nolock, Opt_dioread_lock, Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache, + Opt_no_fc, }; static const match_table_t tokens = {
@@ -1604,6 +1605,7 @@ static const match_table_t tokens = { {Opt_init_itable, "init_itable=%u"}, {Opt_init_itable, "init_itable"}, {Opt_noinit_itable, "noinit_itable"}, + {Opt_no_fc, "no_fc"}, {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, {Opt_nombcache, "nombcache"},
@@ -1726,6 +1728,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)#define MOPT_NO_EXT3 0x0200#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)#define MOPT_STRING 0x0400 +#define MOPT_2 0x0800 static const struct mount_opts { int token;
@@ -1818,6 +1821,8 @@ static const struct mount_opts { {Opt_max_dir_size_kb, 0, MOPT_GTE0}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, + {Opt_no_fc, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, + MOPT_CLEAR | MOPT_2 | MOPT_EXT4_ONLY}, {Opt_err, 0, 0} };
@@ -2108,10 +2113,17 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,WARN_ON (1 );return -1 ; } -if (arg !=0 ) - sbi->s_mount_opt |= m->mount_opt; -else - sbi->s_mount_opt &= ~m->mount_opt; +if (m->flags &MOPT_2 ) { +if (arg !=0 ) + sbi->s_mount_opt2 |= m->mount_opt; +else + sbi->s_mount_opt2 &= ~m->mount_opt; + }else { +if (arg !=0 ) + sbi->s_mount_opt |= m->mount_opt; +else + sbi->s_mount_opt &= ~m->mount_opt; + } }return 1 ; }
@@ -3792,6 +3804,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)#ifdef CONFIG_EXT4_FS_POSIX_ACL set_opt (sb,POSIX_ACL );#endif +if (ext4_has_feature_fast_commit (sb)) +set_opt2 (sb,JOURNAL_FAST_COMMIT );/* don't forget to enable journal_csum when metadata_csum is enabled. */ if (ext4_has_metadata_csum (sb))set_opt (sb,JOURNAL_CHECKSUM );
@@ -4446,6 +4460,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_def_mount_opt &= ~EXT4_MOUNT_JOURNAL_CHECKSUM ;clear_opt (sb,JOURNAL_CHECKSUM );clear_opt (sb,DATA_FLAGS ); +clear_opt2 (sb,JOURNAL_FAST_COMMIT ); sbi->s_journal =NULL ; needs_recovery =0 ; goto no_journal;
include/linux/jbd2.h +4 -1
@@ -288,6 +288,7 @@ typedef struct journal_superblock_s#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004#define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008#define JBD2_FEATURE_INCOMPAT_CSUM_V3 0x00000010 +#define JBD2_FEATURE_INCOMPAT_FAST_COMMIT 0x00000020/* See "journal feature predicate functions" below */
@@ -298,7 +299,8 @@ typedef struct journal_superblock_sJBD2_FEATURE_INCOMPAT_64BIT | \JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT | \JBD2_FEATURE_INCOMPAT_CSUM_V2 | \ - JBD2_FEATURE_INCOMPAT_CSUM_V3) +JBD2_FEATURE_INCOMPAT_CSUM_V3 | \ + JBD2_FEATURE_INCOMPAT_FAST_COMMIT) #ifdef __KERNEL__
@@ -1234,6 +1236,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(64bit, 64BIT) JBD2_FEATURE_INCOMPAT_FUNCS(async_commit, ASYNC_COMMIT) JBD2_FEATURE_INCOMPAT_FUNCS(csum2, CSUM_V2) JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3) +JBD2_FEATURE_INCOMPAT_FUNCS (fast_commit,FAST_COMMIT )/* * Journal flag definitions
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 3/7 ext4 / jbd2: add fast commit initialization
In reply to Harshad ShirwadkarThis patch adds fast commit area trackers in the journal_t structure. These are initialized via the jbd2_fc_init() routine that this patch adds. This patch also adds ext4/fast_commit.c and ext4/fast_commit.h files for fast commit code that will be added in subsequent patches in this series.
--- fs/ext4/Makefile | 3 ++- fs/ext4/ext4.h | 4 ++++ fs/ext4/fast_commit.c | 20 +++++++++++++++++ fs/ext4/fast_commit.h | 9 ++++++++ fs/ext4/super.c | 1 + fs/jbd2/journal.c | 52 ++++++++++++++++++++++++++++++++++++++----- include/linux/jbd2.h | 39 ++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 fs/ext4/fast_commit.c create mode 100644 fs/ext4/fast_commit.h
fs/ext4/Makefile +2 -1
@@ -9,7 +9,8 @@ ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ extents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \ indirect.o inline.o inode.o ioctl.o mballoc.o migrate.o \ mmp.o move_extent.o namei.o page-io.o readpage.o resize.o \ - super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o + super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o \ + fast_commit.o ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o ext4-$(CONFIG_EXT4_FS_SECURITY) += xattr_security.o
fs/ext4/ext4.h +4 -0
@@ -926,6 +926,7 @@ do { \#endif /* defined(__KERNEL__) || defined(__linux__) */ #include "extents_status.h" +#include "fast_commit.h" /* * Lock subclasses for i_data_sem in the ext4_inode_info structure.
@@ -2620,6 +2621,9 @@ extern int ext4_init_inode_table(struct super_block *sb, ext4_group_t group, int barrier);extern void ext4_end_bitmap_read (struct buffer_head *bh,int uptodate); +/* fast_commit.c */ + +void ext4_fc_init (struct super_block *sb,journal_t *journal);/* mballoc.c */ extern const struct seq_operations ext4_mb_seq_groups_ops;extern long ext4_mb_stats;
fs/ext4/fast_commit.c new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* fs/ext4/fast_commit.c +* +* Written by Harshad Shirwadkar <[email protected]> +* +* Ext4 fast commits routines. +*/ +#include "ext4_jbd2.h" + +void ext4_fc_init (struct super_block *sb,journal_t *journal) +{ +if (!test_opt2 (sb,JOURNAL_FAST_COMMIT )) +return ; +if (jbd2_fc_init (journal,EXT4_NUM_FC_BLKS )) { +pr_warn ("Error while enabling fast commits, turning off." ); +ext4_clear_feature_fast_commit (sb); + } +}
fs/ext4/fast_commit.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __FAST_COMMIT_H__ +#define __FAST_COMMIT_H__ + +/* Number of blocks in journal area to allocate for fast commits */ +#define EXT4_NUM_FC_BLKS 256 + +#endif /* __FAST_COMMIT_H__ */
fs/ext4/super.c +1 -0
@@ -4819,6 +4819,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal) journal->j_commit_interval = sbi->s_commit_interval; journal->j_min_batch_time = sbi->s_min_batch_time; journal->j_max_batch_time = sbi->s_max_batch_time; +ext4_fc_init (sb, journal);write_lock (&journal->j_state_lock);if (test_opt (sb,BARRIER ))
fs/jbd2/journal.c +47 -5
96 lines not on this page · raw message
include/linux/jbd2.h +39 -0
@@ -910,6 +910,30 @@ struct journal_s*/ unsigned long j_last; +/** +* @j_first_fc: +* +* The block number of the first fast commit block in the journal +* [j_state_lock]. +*/ +unsigned long j_first_fc; + +/** +* @j_fc_off: +* +* Number of fast commit blocks currently allocated. +* [j_state_lock]. +*/ +unsigned long j_fc_off; + +/** +* @j_last_fc: +* +* The block number one beyond the last fast commit block in the journal +* [j_state_lock]. +*/ +unsigned long j_last_fc; +/** * @j_dev: Device where we store the journal. */
@@ -1060,6 +1084,12 @@ struct journal_s*/ struct buffer_head **j_wbuf; +/** +* @j_fc_wbuf: Array of fast commit bhs for +* jbd2_journal_commit_transaction. +*/ +struct buffer_head **j_fc_wbuf; +/** * @j_wbufsize: *
@@ -1067,6 +1097,13 @@ struct journal_s*/ int j_wbufsize; +/** +* @j_fc_wbufsize: +* +* Size of @j_fc_wbuf array. +*/ +int j_fc_wbufsize; +/** * @j_last_sync_writer: *
@@ -1503,6 +1540,8 @@ void __jbd2_log_wait_for_space(journal_t *journal);extern void __jbd2_journal_drop_transaction (journal_t *,transaction_t *);extern int jbd2_cleanup_journal_tail (journal_t *); +/* Fast commit related APIs */ +int jbd2_fc_init (journal_t *journal,int num_fc_blks);/* * is_journal_abort *
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 4/7 jbd2: add fast commit machinery
In reply to Harshad ShirwadkarThis patch implements following APIs in JBD2 to allow for fast commits:
jbd2_fc_start(): Start a new fast commit. This function waits for any existing fast commit or full commit to complete.
jbd2_fc_stop(): Stop fast commit. This function ends current fast commit and wakes up either the journal thread or the other fast commit waiting for current fast commit to complete.
jbd2_fc_stop_do_commit(): Stop fast commit and perform a full commit. This is same as above but also performs a full commit.
This patch also adds a cleanup handler in journal_t that is called after every full and fast commit.
--- fs/ext4/fast_commit.c | 8 ++++++ fs/jbd2/commit.c | 19 ++++++++++++ fs/jbd2/journal.c | 67 +++++++++++++++++++++++++++++++++++++++++++ include/linux/jbd2.h | 21 ++++++++++++++ 4 files changed, 115 insertions(+)
fs/ext4/fast_commit.c +8 -0
@@ -8,11 +8,19 @@* Ext4 fast commits routines. */ #include "ext4_jbd2.h" +/* +* Fast commit cleanup routine. This is called after every fast commit and +* full commit. full is true if we are called after a full commit. +*/ +static void ext4_fc_cleanup (journal_t *journal,int full) +{ +}void ext4_fc_init (struct super_block *sb,journal_t *journal) {if (!test_opt2 (sb,JOURNAL_FAST_COMMIT ))return ; + journal->j_fc_cleanup_callback = ext4_fc_cleanup;if (jbd2_fc_init (journal,EXT4_NUM_FC_BLKS )) {pr_warn ("Error while enabling fast commits, turning off." );ext4_clear_feature_fast_commit (sb);
fs/jbd2/commit.c +19 -0
@@ -413,6 +413,20 @@ void jbd2_journal_commit_transaction(journal_t *journal)J_ASSERT (journal->j_running_transaction !=NULL );J_ASSERT (journal->j_committing_transaction ==NULL ); +write_lock (&journal->j_state_lock); + journal->j_flags |=JBD2_FULL_COMMIT_ONGOING ; +while (journal->j_flags &JBD2_FAST_COMMIT_ONGOING ) { +DEFINE_WAIT (wait); + +prepare_to_wait (&journal->j_wait_fc, &wait, +TASK_UNINTERRUPTIBLE ); +write_unlock (&journal->j_state_lock); +schedule (); +write_lock (&journal->j_state_lock); +finish_wait (&journal->j_wait_fc, &wait); + } +write_unlock (&journal->j_state_lock); + commit_transaction = journal->j_running_transaction;trace_jbd2_start_commit (journal, commit_transaction);
@@ -1119,12 +1133,16 @@ void jbd2_journal_commit_transaction(journal_t *journal)if (journal->j_commit_callback) journal->j_commit_callback (journal, commit_transaction); +if (journal->j_fc_cleanup_callback) + journal->j_fc_cleanup_callback (journal,1 );trace_jbd2_end_commit (journal, commit_transaction);jbd_debug (1 ,"JBD2: commit %d complete, head %d\n" , journal->j_commit_sequence, journal->j_tail_sequence);write_lock (&journal->j_state_lock); + journal->j_flags &= ~JBD2_FULL_COMMIT_ONGOING ; + journal->j_flags &= ~JBD2_FAST_COMMIT_ONGOING ;spin_lock (&journal->j_list_lock); commit_transaction->t_state =T_FINISHED ;/* Check if the transaction can be dropped now that we are finished */
@@ -1136,6 +1154,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)spin_unlock (&journal->j_list_lock);write_unlock (&journal->j_state_lock);wake_up (&journal->j_wait_done_commit); +wake_up (&journal->j_wait_fc);/* * Calculate overall stats
fs/jbd2/journal.c +67 -0
79 lines not on this page · raw message
include/linux/jbd2.h +21 -0
@@ -853,6 +853,13 @@ struct journal_s*/ wait_queue_head_t j_wait_reserved; +/** +* @j_wait_fc: +* +* Wait queue to wait for completion of async fast commits. +*/ +wait_queue_head_t j_wait_fc; +/** * @j_checkpoint_mutex: *
@@ -1203,6 +1210,15 @@ struct journal_s*/ struct lockdep_map j_trans_commit_map;#endif + +/** +* @j_fc_cleanup_callback: +* +* Clean-up after fast commit or full commit. JBD2 calls this function +* after every commit operation. +*/ +void (*j_fc_cleanup_callback)(struct journal_s *journal,int ); + };#define jbd2_might_wait_for_commit (j) \
@@ -1288,6 +1304,8 @@ JBD2_FEATURE_INCOMPAT_FUNCS(fast_commit, FAST_COMMIT)* data write error in ordered * mode */ #define JBD2_REC_ERR 0x080/* The errno in the sb has been recorded */ +#define JBD2_FAST_COMMIT_ONGOING 0x100/* Fast commit is ongoing */ +#define JBD2_FULL_COMMIT_ONGOING 0x200/* Full commit is ongoing */ /* * Function declarations for the journaling transaction and buffer
@@ -1542,6 +1560,9 @@ extern int jbd2_cleanup_journal_tail(journal_t *);/* Fast commit related APIs */ int jbd2_fc_init (journal_t *journal,int num_fc_blks); +int jbd2_fc_start (journal_t *journal,tid_t tid); +int jbd2_fc_stop (journal_t *journal); +int jbd2_fc_stop_do_commit (journal_t *journal,tid_t tid);/* * is_journal_abort *
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 5/7 ext4: main fast-commit commit path
In reply to Harshad ShirwadkarThis patch adds main fast commit commit path handlers. The overall patch can be divided into two inter-related parts:
(A) Metadata updates tracking
This part consists of helper functions to track changes that need to be committed during a commit operation. These updates are maintained by Ext4 in different in-memory queues. Following are the APIs and their short description that are implemented in this patch:
- ext4_fc_track_link/unlink/creat() - Track unlink. link and creat operations
- ext4_fc_track_range() - Track changed logical block offsets inodes
- ext4_fc_track_inode() - Track inodes
- ext4_fc_mark_ineligible() - Mark file system fast commit ineligible()
- ext4_fc_start_update() / ext4_fc_stop_update() / ext4_fc_start_ineligible() / ext4_fc_stop_ineligible() These functions are useful for co-ordinating inode updates with commits.
(B) Main commit Path
This part consists of functions to convert updates tracked in in-memory data structures into on-disk commits. Function ext4_fc_commit() is the main entry point to commit path.
--- fs/ext4/acl.c | 2 + fs/ext4/ext4.h | 57 ++ fs/ext4/extents.c | 46 +- fs/ext4/fast_commit.c | 1183 +++++++++++++++++++++++++++++++++++ fs/ext4/fast_commit.h | 110 ++++ fs/ext4/file.c | 10 +- fs/ext4/fsync.c | 2 +- fs/ext4/inode.c | 41 +- fs/ext4/ioctl.c | 16 +- fs/ext4/namei.c | 35 +- fs/ext4/super.c | 31 + fs/ext4/xattr.c | 3 + fs/jbd2/commit.c | 41 ++ fs/jbd2/journal.c | 119 +++- include/linux/jbd2.h | 6 + include/trace/events/ext4.h | 172 +++++ 16 files changed, 1850 insertions(+), 24 deletions(-)
fs/ext4/acl.c +2 -0
@@ -243,6 +243,7 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type) handle =ext4_journal_start (inode,EXT4_HT_XATTR , credits);if (IS_ERR (handle))return PTR_ERR (handle); +ext4_fc_start_update (inode);if ((type ==ACL_TYPE_ACCESS ) && acl) { error =posix_acl_update_mode (inode, &mode, &acl);
@@ -260,6 +261,7 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type) } out_stop:ext4_journal_stop (handle); +ext4_fc_stop_update (inode);if (error == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry;return error;
fs/ext4/ext4.h +57 -0
87 lines not on this page · raw message
fs/ext4/extents.c +34 -12
117 lines not on this page · raw message
fs/ext4/fast_commit.c +1183 -0
1,199 lines not on this page · raw message
fs/ext4/fast_commit.h +110 -0
114 lines not on this page · raw message
fs/ext4/file.c +8 -2
@@ -261,6 +261,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,if (iocb->ki_flags &IOCB_NOWAIT )return -EOPNOTSUPP ; +ext4_fc_start_update (inode);inode_lock (inode); ret =ext4_write_checks (iocb, from);if (ret <=0 )
@@ -272,6 +273,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb, out:inode_unlock (inode); +ext4_fc_stop_update (inode);if (likely (ret >0 )) { iocb->ki_pos += ret; ret =generic_write_sync (iocb, ret);
@@ -511,6 +513,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)if (unaligned_io)inode_dio_wait (inode); +ext4_fc_start_update (inode);if (extend) { handle =ext4_journal_start (inode,EXT4_HT_INODE ,2 );if (IS_ERR (handle)) {
@@ -540,6 +543,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)inode_unlock_shared (inode); elseinode_unlock (inode ); +ext4_fc_stop_update (inode);if (ret >=0 &&iov_iter_count (from)) {ssize_t err;
@@ -638,8 +642,8 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)#endif if (iocb->ki_flags &IOCB_DIRECT )return ext4_dio_write_iter (iocb, from); - -return ext4_buffered_write_iter (iocb, from); +else +return ext4_buffered_write_iter (iocb, from); }#ifdef CONFIG_FS_DAX
@@ -739,6 +743,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)if (!daxdev_mapping_supported (vma, dax_dev))return -EOPNOTSUPP ; +ext4_fc_start_update (inode);file_accessed (file);if (IS_DAX (file_inode (file))) { vma->vm_ops = &ext4_dax_vm_ops;
@@ -746,6 +751,7 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) }else { vma->vm_ops = &ext4_file_vm_ops; } +ext4_fc_stop_update (inode);return 0 ; }
fs/ext4/fsync.c +1 -1
@@ -114,7 +114,7 @@ static int ext4_fsync_journal(struct inode *inode, bool datasync, !jbd2_trans_will_send_data_barrier(journal, commit_tid)) *needs_barrier = true; -return jbd2_complete_transaction (journal, commit_tid); +return ext4_fc_commit (journal, commit_tid); }/*
fs/ext4/inode.c +36 -5
118 lines not on this page · raw message
fs/ext4/ioctl.c +15 -1
@@ -165,6 +165,7 @@ static long swap_inode_boot_loader(struct super_block *sb, err = -EINVAL ; goto err_out; } +ext4_fc_start_ineligible (sb,EXT4_FC_REASON_SWAP_BOOT );/* Protect extent tree against block allocations via delalloc */ ext4_double_down_write_data_sem (inode, inode_bl);
@@ -247,6 +248,7 @@ static long swap_inode_boot_loader(struct super_block *sb, err_out1:ext4_journal_stop (handle); +ext4_fc_stop_ineligible (sb);ext4_double_up_write_data_sem (inode, inode_bl); err_out:
@@ -772,7 +774,7 @@ static int ext4_ioctl_get_es_cache(struct file *filp, unsigned long arg)return error; } -long ext4_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +static long __ext4_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct inode *inode =file_inode (filp);struct super_block *sb = inode->i_sb;
@@ -1039,6 +1041,7 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) err =ext4_resize_fs (sb, n_blocks_count);if (EXT4_SB (sb)->s_journal) { +ext4_fc_mark_ineligible (sb,EXT4_FC_REASON_RESIZE );jbd2_journal_lock_updates (EXT4_SB (sb)->s_journal); err2 =jbd2_journal_flush (EXT4_SB (sb)->s_journal);jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal);
@@ -1273,6 +1276,17 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } } +long ext4_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) +{ +long ret; + +ext4_fc_start_update (file_inode (filp)); + ret =__ext4_ioctl (filp, cmd, arg); +ext4_fc_stop_update (file_inode (filp)); + +return ret; +} +#ifdef CONFIG_COMPAT long ext4_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
fs/ext4/namei.c +33 -2
@@ -2601,7 +2601,7 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) {handle_t *handle; -struct inode *inode; +struct inode *inode, *inode_save;int err, credits, retries =0 ; err =dquot_initialize (dir);
@@ -2619,7 +2619,11 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, umode_t mode, inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations;ext4_set_aops (inode); + inode_save = inode; +ihold (inode_save); err =ext4_add_nondir (handle, dentry, &inode); +ext4_fc_track_create (inode_save, dentry); +iput (inode_save); }if (handle)ext4_journal_stop (handle);
@@ -2634,7 +2638,7 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev) {handle_t *handle; -struct inode *inode; +struct inode *inode, *inode_save;int err, credits, retries =0 ; err =dquot_initialize (dir);
@@ -2651,7 +2655,12 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,if (!IS_ERR (inode)) {init_special_inode (inode, inode->i_mode, rdev); inode->i_op = &ext4_special_inode_operations; + inode_save = inode; +ihold (inode_save); err =ext4_add_nondir (handle, dentry, &inode); +if (!err) +ext4_fc_track_create (inode_save, dentry); +iput (inode_save); }if (handle)ext4_journal_stop (handle);
@@ -2813,6 +2822,7 @@ static int ext4_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)iput (inode); goto out_retry; } +ext4_fc_track_create (inode, dentry);ext4_inc_count (handle, dir);ext4_update_dx_flag (dir); err =ext4_mark_inode_dirty (handle, dir);
@@ -3151,6 +3161,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)ext4_mark_inode_dirty (handle, inode);ext4_dec_count (handle, dir);ext4_update_dx_flag (dir); +ext4_fc_track_unlink (inode, dentry);ext4_mark_inode_dirty (handle, dir);#ifdef CONFIG_UNICODE
@@ -3232,6 +3243,8 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) inode->i_ctime =current_time (inode);ext4_mark_inode_dirty (handle, inode); +if (!retval) +ext4_fc_track_unlink (d_inode (dentry), dentry);#ifdef CONFIG_UNICODE /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid
@@ -3843,6 +3856,22 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,ext4_mark_inode_dirty (handle, new.dir); } } + +if (S_ISDIR (old.inode->i_mode)) { +/* +* We disable fast commits here that's because the +* replay code is not yet capable of changing dot dot +* dirents in directories. +*/ +ext4_fc_mark_ineligible (old.inode->i_sb, +EXT4_FC_REASON_RENAME_DIR ); + }else { +if (new.inode) +ext4_fc_track_unlink (new.inode, new.dentry); +ext4_fc_track_link (old.inode, new.dentry); +ext4_fc_track_unlink (old.inode, old.dentry); + } +ext4_mark_inode_dirty (handle, old.dir);if (new.inode) {ext4_mark_inode_dirty (handle, new.inode);
@@ -3980,6 +4009,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, old.inode->i_ctime = ctime; new.inode->i_ctime = ctime;ext4_mark_inode_dirty (handle, old.inode); +ext4_fc_mark_ineligible (new.inode->i_sb, +EXT4_FC_REASON_CROSS_RENAME );ext4_mark_inode_dirty (handle, new.inode);if (old.dir_bh) {
fs/ext4/super.c +31 -0
@@ -1149,6 +1149,8 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_datasync_tid =0 ;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);return &ei->vfs_inode; }
@@ -1166,6 +1168,10 @@ static int ext4_drop_inode(struct inode *inode)static void ext4_free_in_core_inode (struct inode *inode) {fscrypt_free_inode (inode); +if (!list_empty (&(EXT4_I (inode)->i_fc_list))) { +pr_warn ("%s: inode %ld still in fc list" , + __func__, inode->i_ino); + }kmem_cache_free (ext4_inode_cachep,EXT4_I (inode)); }
@@ -1191,6 +1197,7 @@ static void init_once(void *foo)init_rwsem (&ei->i_data_sem);init_rwsem (&ei->i_mmap_sem);inode_init_once (&ei->vfs_inode); +ext4_fc_init_inode (&ei->vfs_inode); }static int __init init_inodecache (void )
@@ -1219,6 +1226,7 @@ static void destroy_inodecache(void)void ext4_clear_inode (struct inode *inode) { +ext4_fc_del (inode);invalidate_inode_buffers (inode);clear_inode (inode);ext4_discard_preallocations (inode);
@@ -4411,6 +4419,19 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)INIT_LIST_HEAD (&sbi->s_orphan);/* unlinked but open files */ mutex_init (&sbi->s_orphan_lock); +/* Initialize fast commit stuff */ +atomic_set (&sbi->s_fc_subtid,0 ); +atomic_set (&sbi->s_fc_ineligible_updates,0 ); +INIT_LIST_HEAD (&sbi->s_fc_q); +INIT_LIST_HEAD (&sbi->s_fc_staging_q); +INIT_LIST_HEAD (&sbi->s_fc_dentry_q); +INIT_LIST_HEAD (&sbi->s_fc_staging_dentry_q); + sbi->s_fc_bytes =0 ; + sbi->s_mount_state &= ~EXT4_FC_INELIGIBLE ; + sbi->s_mount_state &= ~EXT4_FC_COMMITTING ; +spin_lock_init (&sbi->s_fc_lock); +memset (&sbi->s_fc_stats,0 ,sizeof (sbi->s_fc_stats)); + sb->s_root =NULL ; needs_recovery = (es->s_last_orphan != 0 ||
@@ -6112,6 +6133,10 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,brelse (bh); out:if (inode->i_size < off + len) { +ext4_fc_track_range (inode, + (inode->i_size >0 ? inode->i_size -1 :0 ) + >> inode->i_sb->s_blocksize_bits, + (off + len) >> inode->i_sb->s_blocksize_bits);i_size_write (inode, off + len);EXT4_I (inode)->i_disksize = inode->i_size;ext4_mark_inode_dirty (handle, inode);
@@ -6238,6 +6263,11 @@ static int __init ext4_init_fs(void) err =init_inodecache ();if (err) goto out1; + + err =ext4_fc_init_dentry_cache (); +if (err) + goto out05; +register_as_ext3 ();register_as_ext2 (); err =register_filesystem (&ext4_fs_type);
@@ -6248,6 +6278,7 @@ static int __init ext4_init_fs(void) out:unregister_as_ext2 ();unregister_as_ext3 (); +out05:destroy_inodecache (); out1:ext4_exit_mballoc ();
fs/ext4/xattr.c +3 -0
@@ -2413,6 +2413,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,if (IS_SYNC (inode))ext4_handle_sync (handle); } +ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_XATTR ); cleanup:brelse (is.iloc.bh);
@@ -2490,6 +2491,7 @@ ext4_xattr_set(struct inode *inode, int name_index, const char *name,if (error ==0 ) error = error2; } +ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_XATTR );return error; }
@@ -2922,6 +2924,7 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode, error); goto cleanup; } +ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_XATTR ); } error =0 ; cleanup:
fs/jbd2/commit.c +41 -0
53 lines not on this page · raw message
fs/jbd2/journal.c +118 -1
146 lines not on this page · raw message
include/linux/jbd2.h +6 -0
@@ -1563,6 +1563,12 @@ int jbd2_fc_init(journal_t *journal, int num_fc_blks);int jbd2_fc_start (journal_t *journal,tid_t tid);int jbd2_fc_stop (journal_t *journal);int jbd2_fc_stop_do_commit (journal_t *journal,tid_t tid); +int jbd2_fc_get_buf (journal_t *journal,struct buffer_head **bh_out); +int jbd2_fc_wait_bufs (journal_t *journal,int num_blks); +int jbd2_fc_release_bufs (journal_t *journal); +int jbd2_submit_inode_data (journal_t *journal,struct jbd2_inode *jinode); +int jbd2_wait_inode_data (journal_t *journal,struct jbd2_inode *jinode); +/* * is_journal_abort *
include/trace/events/ext4.h +172 -0
184 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 6/7 jbd2: fast commit recovery path
In reply to Harshad ShirwadkarThis patch adds fast commit recovery support in JBD2.
--- fs/ext4/fast_commit.c | 15 ++++++++++++ fs/jbd2/recovery.c | 56 +++++++++++++++++++++++++++++++++++++++---- include/linux/jbd2.h | 20 ++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-)
fs/ext4/fast_commit.c +15 -0
@@ -1188,8 +1188,23 @@ static void ext4_fc_cleanup(journal_t *journal, int full)trace_ext4_fc_stats (sb); } +/* +* Main recovery path entry point. +*/ +static int ext4_fc_replay (journal_t *journal,struct buffer_head *bh, +enum passtype pass,int off,tid_t expected_tid) +{ +return 0 ; +} +void ext4_fc_init (struct super_block *sb,journal_t *journal) { +/* +* We set replay callback even if fast commit disabled because we may +* could still have fast commit blocks that need to be replayed even if +* fast commit has now been turned off. +*/ + journal->j_fc_replay_callback = ext4_fc_replay;if (!test_opt2 (sb,JOURNAL_FAST_COMMIT ))return ; journal->j_fc_cleanup_callback = ext4_fc_cleanup;
fs/jbd2/recovery.c +52 -4
82 lines not on this page · raw message
include/linux/jbd2.h +20 -0
@@ -748,6 +748,11 @@ jbd2_time_diff(unsigned long start, unsigned long end)#define JBD2_NR_BATCH 64 +enum passtype {PASS_SCAN ,PASS_REVOKE ,PASS_REPLAY }; + +#define JBD2_FC_REPLAY_STOP 0 +#define JBD2_FC_REPLAY_CONTINUE 1 +/** * struct journal_s - The journal_s type is the concrete type associated with * journal_t.
@@ -1219,6 +1224,21 @@ struct journal_s*/ void (*j_fc_cleanup_callback)(struct journal_s *journal,int ); +/* +* @j_fc_replay_callback: +* +* File-system specific function that performs replay of a fast +* commit. JBD2 calls this function for each fast commit block found in +* the journal. This function should return JBD2_FC_REPLAY_CONTINUE +* to indicate that the block was processed correctly and more fast +* commit replay should continue. Return value of JBD2_FC_REPLAY_STOP +* indicates the end of replay (no more blocks remaining). A negative +* return value indicates error. +*/ +int (*j_fc_replay_callback)(struct journal_s *journal, +struct buffer_head *bh, +enum passtype pass,int off, +tid_t expected_commit_id); };#define jbd2_might_wait_for_commit (j) \
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v8 7/7 ext4: fast commit recovery path
In reply to Harshad ShirwadkarThis patch adds fast commit recovery path support for Ext4 file system. We add several helper functions that are similar in spirit to e2fsprogs journal recovery path handlers. Example of such functions include - a simple block allocator, idempotent block bitmap update function etc. Using these routines and the fast commit log in the fast commit area, the recovery path (ext4_fc_replay()) performs fast commit log recovery.
--- fs/ext4/balloc.c | 7 +- fs/ext4/ext4.h | 23 + fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/extents.c | 212 +++++++++ fs/ext4/extents_status.c | 24 + fs/ext4/fast_commit.c | 851 +++++++++++++++++++++++++++++++++++- fs/ext4/fast_commit.h | 40 ++ fs/ext4/ialloc.c | 165 ++++++- fs/ext4/inode.c | 89 ++-- fs/ext4/ioctl.c | 6 +- fs/ext4/mballoc.c | 225 +++++++++- fs/ext4/mballoc.h | 2 + fs/ext4/namei.c | 144 +++--- fs/ext4/super.c | 20 +- include/trace/events/ext4.h | 56 ++- 15 files changed, 1740 insertions(+), 126 deletions(-)
fs/ext4/balloc.c +6 -1
@@ -368,7 +368,12 @@ static int ext4_validate_block_bitmap(struct super_block *sb, struct buffer_head *bh) {ext4_fsblk_t blk; -struct ext4_group_info *grp =ext4_get_group_info (sb, block_group); +struct ext4_group_info *grp; + +if (EXT4_SB (sb)->s_mount_state &EXT4_FC_REPLAY ) +return 0 ; + + grp =ext4_get_group_info (sb, block_group);if (buffer_verified (bh))return 0 ;
fs/ext4/ext4.h +23 -0
@@ -1128,6 +1128,7 @@ struct ext4_inode_info {#define EXT4_FC_COMMITTING 0x0010/* File system underoing a fast * commit. */ +#define EXT4_FC_REPLAY 0x0020/* Fast commit replay ongoing */ /* * Misc. filesystem flags
@@ -1603,6 +1604,10 @@ struct ext4_sb_info {spinlock_t s_fc_lock;struct buffer_head *s_fc_bh;struct ext4_fc_stats s_fc_stats; +#ifdef CONFIG_EXT4_DEBUG +int s_fc_debug_max_replay; +#endif +struct ext4_fc_replay_state s_fc_replay_state; };static inline struct ext4_sb_info *EXT4_SB (struct super_block *sb)
@@ -2637,6 +2642,7 @@ extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len, struct dx_hash_info *hinfo);/* ialloc.c */ +extern int ext4_mark_inode_used (struct super_block *sb,int ino); extern struct inode *__ext4_new_inode(handle_t *, struct inode *, umode_t, const struct qstr *qstr, __u32 goal, uid_t *owner, __u32 i_flags,
@@ -2678,6 +2684,8 @@ void ext4_fc_stop_ineligible(struct super_block *sb);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);int ext4_fc_commit (journal_t *journal,tid_t commit_tid);int __init ext4_fc_init_dentry_cache (void );
@@ -2706,6 +2714,8 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);extern void ext4_process_freed_data (struct super_block *sb,tid_t commit_tid);/* inode.c */ +void ext4_inode_csum_set (struct inode *inode,struct ext4_inode *raw, +struct ext4_inode_info *ei);int ext4_inode_is_fast_symlink (struct inode *inode);struct buffer_head *ext4_getblk (handle_t *,struct inode *,ext4_lblk_t ,int );struct buffer_head *ext4_bread (handle_t *,struct inode *,ext4_lblk_t ,int );
@@ -2752,6 +2762,8 @@ extern int ext4_sync_inode(handle_t *, struct inode *);extern void ext4_dirty_inode (struct inode *,int );extern int ext4_change_inode_journal_flag (struct inode *,int );extern int ext4_get_inode_loc (struct inode *,struct ext4_iloc *); +extern int ext4_get_fc_inode_loc (struct super_block *sb,unsigned long ino, +struct ext4_iloc *iloc);extern int ext4_inode_attach_jinode (struct inode *inode);extern int ext4_can_truncate (struct inode *inode);extern int ext4_truncate (struct inode *);
@@ -2785,12 +2797,15 @@ extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode,/* ioctl.c */ extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long ); +extern void ext4_reset_inode_seed (struct inode *inode);/* migrate.c */ extern int ext4_ext_migrate (struct inode *);extern int ext4_ind_migrate (struct inode *inode);/* namei.c */ +extern int ext4_init_new_dir (handle_t *handle,struct inode *dir, +struct inode *inode);extern int ext4_dirblock_csum_verify (struct inode *inode,struct buffer_head *bh);extern int ext4_orphan_add (handle_t *,struct inode *);
@@ -3361,6 +3376,10 @@ extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,extern int ext4_ci_compare (const struct inode *parent,const struct qstr *fname,const struct qstr *entry,bool quick); +extern int __ext4_unlink (struct inode *dir,const struct qstr *d_name, +struct inode *inode); +extern int __ext4_link (struct inode *dir,struct inode *inode, +struct dentry *dentry);#define S_SHIFT 12static const unsigned char ext4_type_by_mode[(S_IFMT >>S_SHIFT ) +1 ] = {
@@ -3462,6 +3481,10 @@ extern int ext4_clu_mapped(struct inode *inode, ext4_lblk_t lclu);extern int ext4_datasem_ensure_credits (handle_t *handle,struct inode *inode,int check_cred,int restart_cred,int revoke_cred); +extern void ext4_ext_replay_shrink_inode (struct inode *inode,ext4_lblk_t end); +extern int ext4_ext_replay_set_iblocks (struct inode *inode); +extern int ext4_ext_replay_update_ex (struct inode *inode,ext4_lblk_t start, +int len,int unwritten,ext4_fsblk_t pblk);/* move_extent.c */
fs/ext4/ext4_jbd2.c +1 -1
@@ -100,7 +100,7 @@ handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,return ERR_PTR (err); journal =EXT4_SB (sb)->s_journal; -if (!journal) +if (!journal || (EXT4_SB (sb)->s_mount_state &EXT4_FC_REPLAY ))return ext4_get_nojournal ();return jbd2__journal_start (journal, blocks, rsv_blocks, revoke_creds,GFP_NOFS , type, line);
fs/ext4/extents.c +212 -0
215 lines not on this page · raw message
fs/ext4/extents_status.c +24 -0
@@ -311,6 +311,9 @@ void ext4_es_find_extent_range(struct inode *inode, ext4_lblk_t lblk, ext4_lblk_t end, struct extent_status *es) { + if (EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) + return; +trace_ext4_es_find_extent_range_enter (inode ,lblk );read_lock (&EXT4_I (inode)->i_es_lock);
@@ -361,6 +364,9 @@ bool ext4_es_scan_range(struct inode *inode, {bool ret; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return false; +read_lock (&EXT4_I (inode)->i_es_lock); ret =__es_scan_range (inode, matching_fn, lblk, end);read_unlock (&EXT4_I (inode)->i_es_lock);
@@ -404,6 +410,9 @@ bool ext4_es_scan_clu(struct inode *inode, {bool ret; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return false; +read_lock (&EXT4_I (inode)->i_es_lock); ret =__es_scan_clu (inode, matching_fn, lblk);read_unlock (&EXT4_I (inode)->i_es_lock);
@@ -812,6 +821,9 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,int err =0 ;struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return 0 ; +es_debug ("add [%u/%u) %llu %x to extent status tree of inode %lu\n" , lblk, len, pblk, status, inode->i_ino);
@@ -873,6 +885,9 @@ void ext4_es_cache_extent(struct inode *inode, ext4_lblk_t lblk,struct extent_status newes;ext4_lblk_t end = lblk + len -1 ; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return ; + newes.es_lblk = lblk; newes.es_len = len;ext4_es_store_pblock_status (&newes, pblk, status);
@@ -908,6 +923,9 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,struct rb_node *node;int found =0 ; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return 0 ; +trace_ext4_es_lookup_extent_enter (inode, lblk);es_debug ("lookup extent in block %u\n" , lblk);
@@ -1419,6 +1437,9 @@ int ext4_es_remove_extent(struct inode *inode, ext4_lblk_t lblk,int err =0 ;int reserved =0 ; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return 0 ; +trace_ext4_es_remove_extent (inode, lblk, len);es_debug ("remove [%u/%u) from extent status tree of inode %lu\n" , lblk, len, inode->i_ino);
@@ -1969,6 +1990,9 @@ int ext4_es_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk,struct extent_status newes;int err =0 ; +if (EXT4_SB (inode->i_sb)->s_mount_state &EXT4_FC_REPLAY ) +return 0 ; +es_debug ("add [%u/1) delayed to extent status tree of inode %lu\n" , lblk, inode->i_ino);
fs/ext4/fast_commit.c +842 -9
887 lines not on this page · raw message
fs/ext4/fast_commit.h +40 -0
@@ -116,4 +116,44 @@ struct ext4_fc_stats { int fc_numblks; }; +#define EXT4_FC_REPLAY_REALLOC_INCREMENT 4 + +/* +* Physical block regions added to different inodes due to fast commit +* recovery. These are set during the SCAN phase. During the replay phase, +* our allocator excludes these from its allocation. This ensures that +* we don't accidentally allocating a block that is going to be used by +* another inode. +*/ +struct ext4_fc_alloc_region { +ext4_lblk_t lblk; +ext4_fsblk_t pblk; +int ino, len; +}; + +/* +* Fast commit replay state. +*/ +struct ext4_fc_replay_state { +int fc_replay_num_tags; +int fc_replay_expected_off; +int fc_current_pass; +int fc_cur_tag; +int fc_crc; +struct ext4_fc_alloc_region *fc_regions; +int fc_regions_size, fc_regions_used, fc_regions_valid; +int *fc_modified_inodes; +int fc_modified_inodes_used, fc_modified_inodes_size; +}; + +#define region_last (__region) (((__region)->lblk) + ((__region)->len) - 1) + +#define fc_for_each_tl (__start, __end, __tl) \ + for (tl = (struct ext4_fc_tl *)start; \ + (u8 *)tl < (u8 *)end; \ + tl = (struct ext4_fc_tl *)((u8 *)tl + \ + sizeof(struct ext4_fc_tl) + \ + + le16_to_cpu(tl->fc_len))) + +#endif /* __FAST_COMMIT_H__ */
fs/ext4/ialloc.c +149 -16
222 lines not on this page · raw message
fs/ext4/inode.c +63 -26
180 lines not on this page · raw message
fs/ext4/ioctl.c +3 -3
@@ -86,7 +86,7 @@ static void swap_inode_data(struct inode *inode1, struct inode *inode2)i_size_write (inode2, isize); } -static void reset_inode_seed (struct inode *inode) +void ext4_reset_inode_seed (struct inode *inode) {struct ext4_inode_info *ei =EXT4_I (inode);struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb);
@@ -200,8 +200,8 @@ static long swap_inode_boot_loader(struct super_block *sb, inode->i_generation =prandom_u32 (); inode_bl->i_generation =prandom_u32 (); -reset_inode_seed (inode); -reset_inode_seed (inode_bl); +ext4_reset_inode_seed (inode); +ext4_reset_inode_seed (inode_bl);ext4_discard_preallocations (inode);
fs/ext4/mballoc.c +217 -8
274 lines not on this page · raw message
fs/ext4/mballoc.h +2 -0
@@ -215,4 +215,6 @@ ext4_mballoc_query_range(ext4_mballoc_query_range_fn formatter, void *priv); +void ext4_mb_mark_bb (struct super_block *sb,ext4_fsblk_t block, +int len,int state);#endif
fs/ext4/namei.c +87 -57
213 lines not on this page · raw message
fs/ext4/super.c +19 -1
@@ -1529,7 +1529,7 @@ enum { Opt_dioread_nolock, Opt_dioread_lock, Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache, - Opt_no_fc, + Opt_no_fc, Opt_fc_debug_max_replay }; static const match_table_t tokens = {
@@ -1614,6 +1614,9 @@ static const match_table_t tokens = { {Opt_init_itable, "init_itable"}, {Opt_noinit_itable, "noinit_itable"}, {Opt_no_fc, "no_fc"}, +#ifdef CONFIG_EXT4_DEBUG + {Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"}, +#endif {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, {Opt_nombcache, "nombcache"},
@@ -1831,6 +1834,9 @@ static const struct mount_opts { {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, {Opt_no_fc, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, MOPT_CLEAR | MOPT_2 | MOPT_EXT4_ONLY}, +#ifdef CONFIG_EXT4_DEBUG + {Opt_fc_debug_max_replay, 0, MOPT_GTE0}, +#endif {Opt_err, 0, 0} };
@@ -1990,6 +1996,10 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, sbi->s_li_wait_mult = arg; }else if (token == Opt_max_dir_size_kb) { sbi->s_max_dir_size_kb = arg; +#ifdef CONFIG_EXT4_DEBUG + }else if (token == Opt_fc_debug_max_replay) { + sbi->s_fc_debug_max_replay = arg; +#endif }else if (token == Opt_stripe) { sbi->s_stripe = arg; }else if (token == Opt_resuid) {
@@ -4431,6 +4441,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_mount_state &= ~EXT4_FC_COMMITTING ;spin_lock_init (&sbi->s_fc_lock);memset (&sbi->s_fc_stats,0 ,sizeof (sbi->s_fc_stats)); + sbi->s_fc_replay_state.fc_regions =NULL ; + sbi->s_fc_replay_state.fc_regions_size =0 ; + sbi->s_fc_replay_state.fc_regions_used =0 ; + sbi->s_fc_replay_state.fc_regions_valid =0 ; + sbi->s_fc_replay_state.fc_modified_inodes =NULL ; + sbi->s_fc_replay_state.fc_modified_inodes_size =0 ; + sbi->s_fc_replay_state.fc_modified_inodes_used =0 ; sb->s_root =NULL ;
@@ -4640,6 +4657,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) "zone (%d)", err); goto failed_mount4a; } +ext4_fc_replay_cleanup (sb);ext4_ext_init (sb); err =ext4_mb_init (sb);
include/trace/events/ext4.h +52 -4
75 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog