ext4 fast commit fixes
Subsystems (5)
v2 cover ext4 fast commit fixes
ext4: fast commit fixes
This patch series adds several code-only (no on disk format changes) fixes for the fast commit code. I verified that there were no regressions introduced by this patch series in xfstests auto and log groups in fast_commit and 4k configurations.
Changes since V1:
- Broke couple of misc patches into separate patches
- Added a few new fixes:
- atomic update of mount flags
- no fast commits on aborted journal
- Dropped confusing fast commit mount options
- Dropped jbd2_fc_init()
Harshad Shirwadkar (22):
ext4: describe fast_commit feature flags
ext4: mark fc ineligible if inode gets evictied due to mem pressure
ext4: drop redundant calls ext4_fc_track_range
ext4: fixup ext4_fc_track_* functions' signature
jbd2: rename j_maxlen to j_total_len and add jbd2_journal_max_txn_bufs
ext4: clean up the JBD2 API that initializes fast commits
jbd2: drop jbd2_fc_init documentation
jbd2: don't use state lock during commit path
jbd2: don't pass tid to jbd2_fc_end_commit_fallback()
jbd2: add todo for a fast commit performance optimization
jbd2: don't touch buffer state until it is filled
jbd2: don't read journal->j_commit_sequence without taking a lock
ext4: dedpulicate the code to wait on inode that's being committed
ext4: fix code documentatioon
ext4: mark buf dirty before submitting fast commit buffer
ext4: remove unnecessary fast commit calls from ext4_file_mmap
ext4: fix inode dirty check in case of fast commits
ext4: disable fast commit with data journalling
ext4: issue fsdev cache flush before starting fast commit
ext4: make s_mount_flags modifications atomic
jbd2: don't start fast commit on aborted journal
ext4: cleanup fast commit mount options
Documentation/filesystems/ext4/journal.rst | 6 + Documentation/filesystems/ext4/super.rst | 7 + Documentation/filesystems/journalling.rst | 6 +- fs/ext4/ext4.h | 66 +++++--- fs/ext4/extents.c | 7 +- fs/ext4/fast_commit.c | 169 +++++++++++---------- fs/ext4/fast_commit.h | 6 +- fs/ext4/file.c | 6 +- fs/ext4/fsmap.c | 2 +- fs/ext4/fsync.c | 2 +- fs/ext4/inode.c | 19 +-- fs/ext4/mballoc.c | 4 +- fs/ext4/namei.c | 61 ++++---- fs/ext4/super.c | 43 +++--- fs/jbd2/commit.c | 11 +- fs/jbd2/journal.c | 138 +++++++++-------- fs/jbd2/recovery.c | 6 +- fs/ocfs2/journal.c | 2 +- include/linux/jbd2.h | 23 ++- include/trace/events/ext4.h | 10 +- 20 files changed, 328 insertions(+), 266 deletions(-)
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 1/22 ext4: describe fast_commit feature flags
Fast commit feature has flags in the file system as well in JBD2. The meaning of fast commit feature flags can get confusing. Update docs and code to add more documentation about it.
--- Documentation/filesystems/ext4/journal.rst | 6 ++++++ Documentation/filesystems/ext4/super.rst | 7 +++++++ fs/ext4/ext4.h | 7 +++++++ 3 files changed, 20 insertions(+)
Documentation/filesystems/ext4/journal.rst +6 -0
@@ -256,6 +256,10 @@ which is 1024 bytes long: - s\_padding2 - * - 0x54 + - \_\_be32 + - s\_num\_fc\_blocks + - Number of fast commit blocks in the journal. + * - 0x58 - \_\_u32 - s\_padding[42] -
@@ -310,6 +314,8 @@ The journal incompat features are any combination of the following: - This journal uses v3 of the checksum on-disk format. This is the same as v2, but the journal block tag size is fixed regardless of the size of block numbers. (JBD2\_FEATURE\_INCOMPAT\_CSUM\_V3) + * - 0x20 + - Journal has fast commit blocks. (JBD2\_FEATURE\_INCOMPAT\_FAST\_COMMIT) .. _jbd2_checksum_type:
Documentation/filesystems/ext4/super.rst +7 -0
@@ -596,6 +596,13 @@ following: - Sparse Super Block, v2. If this flag is set, the SB field s\_backup\_bgs points to the two block groups that contain backup superblocks (COMPAT\_SPARSE\_SUPER2). + * - 0x400 + - Fast commits supported. Although fast commits blocks are + backward incompatible, fast commit blocks are not always + present in the journal. If fast commit blocks are present in + the journal, JBD2 incompat feature + (JBD2\_FEATURE\_INCOMPAT\_FAST\_COMMIT) gets + set (COMPAT\_FAST\_COMMIT). .. _super_incompat:
fs/ext4/ext4.h +7 -0
@@ -1875,6 +1875,13 @@ 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 +/* +* The reason why "FAST_COMMIT" is a compat feature is that, FS becomes +* incompatible only if fast commit blocks are present in the FS. Since we +* clear the journal (and thus the fast commit blocks), we don't mark FS as +* incompatible. We also have a JBD2 incompat feature, which gets set when +* there are fast commit blocks present in the journal. +*/ #define EXT4_FEATURE_COMPAT_FAST_COMMIT 0x0400#define EXT4_FEATURE_COMPAT_STABLE_INODES 0x0800
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 2/22 ext4: mark fc ineligible if inode gets evictied due to mem pressure
In reply to Harshad ShirwadkarIf inode gets evicted due to memory pressure, we have to remove it from the fast commit list. However, that inode may have uncommitted changes that fast commits will lose. So, just fall back to full commits in this case. Also, rename the fast commit ineligiblity reason from "EXT4_FC_REASON_MEM" to "EXT4_FC_REASON_MEM_NOMEM" for better expression.
--- fs/ext4/fast_commit.c | 4 ++-- fs/ext4/fast_commit.h | 2 +- fs/ext4/inode.c | 2 ++ include/trace/events/ext4.h | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-)
fs/ext4/fast_commit.c +2 -2
@@ -384,7 +384,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)mutex_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_MEM ); +ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_NOMEM );mutex_lock (&ei->i_fc_lock);return -ENOMEM ; }
@@ -397,7 +397,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update)if (!node->fcd_name.name) {kmem_cache_free (ext4_fc_dentry_cachep, node);ext4_fc_mark_ineligible (inode->i_sb, -EXT4_FC_REASON_MEM ); +EXT4_FC_REASON_NOMEM );mutex_lock (&ei->i_fc_lock);return -ENOMEM ; }
fs/ext4/fast_commit.h +1 -1
@@ -100,7 +100,7 @@ enum {EXT4_FC_REASON_XATTR =0 ,EXT4_FC_REASON_CROSS_RENAME ,EXT4_FC_REASON_JOURNAL_FLAG_CHANGE , -EXT4_FC_REASON_MEM , +EXT4_FC_REASON_NOMEM ,EXT4_FC_REASON_SWAP_BOOT ,EXT4_FC_REASON_RESIZE , EXT4_FC_REASON_RENAME_DIR,
fs/ext4/inode.c +2 -0
@@ -327,6 +327,8 @@ void ext4_evict_inode(struct inode *inode)ext4_xattr_inode_array_free (ea_inode_array);return ; no_delete: +if (!list_empty (&EXT4_I (inode)->i_fc_list)) +ext4_fc_mark_ineligible (inode->i_sb,EXT4_FC_REASON_NOMEM );ext4_clear_inode (inode);/* We must guarantee clearing of inode... */ }
include/trace/events/ext4.h +3 -3
@@ -100,7 +100,7 @@ TRACE_DEFINE_ENUM(ES_REFERENCED_B); { EXT4_FC_REASON_XATTR, "XATTR"}, \ { EXT4_FC_REASON_CROSS_RENAME, "CROSS_RENAME"}, \ { EXT4_FC_REASON_JOURNAL_FLAG_CHANGE, "JOURNAL_FLAG_CHANGE"}, \ - { EXT4_FC_REASON_MEM, "NO_MEM"}, \ + { EXT4_FC_REASON_NOMEM, "NO_MEM"}, \ { EXT4_FC_REASON_SWAP_BOOT, "SWAP_BOOT"}, \ { EXT4_FC_REASON_RESIZE, "RESIZE"}, \ { EXT4_FC_REASON_RENAME_DIR, "RENAME_DIR"}, \
@@ -2917,13 +2917,13 @@ TRACE_EVENT(ext4_fc_stats, ), TP_printk("dev %d:%d fc ineligible reasons:\n" - "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s,%d; " + "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d; " "num_commits:%ld, ineligible: %ld, numblks: %ld", MAJOR(__entry->dev), MINOR(__entry->dev), FC_REASON_NAME_STAT(EXT4_FC_REASON_XATTR), FC_REASON_NAME_STAT(EXT4_FC_REASON_CROSS_RENAME), FC_REASON_NAME_STAT(EXT4_FC_REASON_JOURNAL_FLAG_CHANGE), - FC_REASON_NAME_STAT(EXT4_FC_REASON_MEM), + FC_REASON_NAME_STAT(EXT4_FC_REASON_NOMEM), FC_REASON_NAME_STAT(EXT4_FC_REASON_SWAP_BOOT), FC_REASON_NAME_STAT(EXT4_FC_REASON_RESIZE), FC_REASON_NAME_STAT(EXT4_FC_REASON_RENAME_DIR),
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 3/22 ext4: drop redundant calls ext4_fc_track_range
In reply to Harshad Shirwadkarext4_fc_track_range() should only be called when blocks are added or removed from an inode. So, the only places from where we need to call this function are ext4_map_blocks(), punch hole, collapse / zero range, truncate. Remove all the other redundant calls to ths function.
--- fs/ext4/extents.c | 5 ----- fs/ext4/super.c | 4 ---- 2 files changed, 9 deletions(-)
fs/ext4/extents.c +0 -5
@@ -3723,7 +3723,6 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle, err =ext4_ext_dirty (handle, inode, path + path->p_depth); out:ext4_ext_show_leaf (inode, path); -ext4_fc_track_range (inode, ee_block, ee_block + ee_len -1 );return err; }
@@ -3795,7 +3794,6 @@ convert_initialized_extent(handle_t *handle, struct inode *inode,if (*allocated > map->m_len) *allocated = map->m_len; map->m_len = *allocated; -ext4_fc_track_range (inode, ee_block, ee_block + ee_len -1 );return 0 ; }
@@ -4329,7 +4327,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, map->m_len = ar.len; allocated = map->m_len;ext4_ext_show_leaf (inode, path); -ext4_fc_track_range (inode, map->m_lblk, map->m_lblk + map->m_len -1 ); out:ext4_ext_drop_refs (path);kfree (path);
@@ -4651,8 +4648,6 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)FALLOC_FL_COLLAPSE_RANGE |FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)) return -EOPNOTSUPP; -ext4_fc_track_range (inode, offset >> blkbits, - (offset + len -1 ) >> blkbits);ext4_fc_start_update (inode);
fs/ext4/super.c +0 -4
@@ -6561,10 +6561,6 @@ 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; err2 =ext4_mark_inode_dirty (handle, inode);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 4/22 ext4: fixup ext4_fc_track_* functions' signature
In reply to Harshad ShirwadkarFirstly, pass handle to all ext4_fc_track_* functions and use transaction id found in handle->h_transaction->h_tid for tracking fast commit updates. Secondly, don't pass inode to ext4_fc_track_link/create/unlink functions. inode can be found inside these functions as d_inode(dentry). However, rename path is an exeception. That's because in that case, we need inode that's not same as d_inode(dentry). To handle that, add a couple of low-level wrapper functions that take inode and dentry as arguments.
--- fs/ext4/ext4.h | 16 +++++++----- fs/ext4/extents.c | 2 +- fs/ext4/fast_commit.c | 48 +++++++++++++++++++++------------- fs/ext4/inode.c | 10 +++---- fs/ext4/namei.c | 61 ++++++++++++++++++++----------------------- 5 files changed, 74 insertions(+), 63 deletions(-)
fs/ext4/ext4.h +10 -6
@@ -2750,12 +2750,16 @@ extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);int ext4_fc_info_show (struct seq_file *seq,void *v);void ext4_fc_init (struct super_block *sb,journal_t *journal);void ext4_fc_init_inode (struct inode *inode); -void ext4_fc_track_range (struct inode *inode,ext4_lblk_t start, +void ext4_fc_track_range (handle_t *handle,struct inode *inode,ext4_lblk_t start,ext4_lblk_t end); -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); -void ext4_fc_track_inode (struct inode *inode); +void __ext4_fc_track_unlink (handle_t *handle,struct inode *inode, +struct dentry *dentry); +void __ext4_fc_track_link (handle_t *handle,struct inode *inode, +struct dentry *dentry); +void ext4_fc_track_unlink (handle_t *handle,struct dentry *dentry); +void ext4_fc_track_link (handle_t *handle,struct dentry *dentry); +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);void ext4_fc_start_ineligible (struct super_block *sb,int reason);void ext4_fc_stop_ineligible (struct super_block *sb);
@@ -3471,7 +3475,7 @@ 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, +extern int __ext4_unlink (handle_t *handle,struct inode *dir,const struct qstr *d_name,struct inode *inode);extern int __ext4_link (struct inode *dir,struct inode *inode,struct dentry *dentry);
fs/ext4/extents.c +1 -1
@@ -4599,7 +4599,7 @@ static long ext4_zero_range(struct file *file, loff_t offset, ret =ext4_mark_inode_dirty (handle, inode);if (unlikely (ret)) goto out_handle; -ext4_fc_track_range (inode, offset >> inode->i_sb->s_blocksize_bits, +ext4_fc_track_range (handle, inode, offset >> inode->i_sb->s_blocksize_bits, (offset + len -1 ) >> inode->i_sb->s_blocksize_bits);/* Zero out partial block at the edges of the range */ ret =ext4_zero_partial_blocks (handle, inode, offset, len);
fs/ext4/fast_commit.c +30 -18
132 lines not on this page · raw message
fs/ext4/inode.c +5 -5
@@ -732,7 +732,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,if (ret)return ret; } -ext4_fc_track_range (inode, map->m_lblk, +ext4_fc_track_range (handle, inode, map->m_lblk, map->m_lblk + map->m_len -1 ); }
@@ -4111,7 +4111,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)up_write (&EXT4_I (inode)->i_data_sem); } -ext4_fc_track_range (inode, first_block, stop_block); +ext4_fc_track_range (handle, inode, first_block, stop_block);if (IS_SYNC (inode))ext4_handle_sync (handle);
@@ -5444,14 +5444,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) }if (shrink) -ext4_fc_track_range (inode, +ext4_fc_track_range (handle, inode, (attr->ia_size >0 ? attr->ia_size -1 :0 ) >> inode->i_sb->s_blocksize_bits, (oldsize >0 ? oldsize -1 :0 ) >> inode->i_sb->s_blocksize_bits);else ext4_fc_track_range( - inode, + handle, inode, (oldsize > 0 ? oldsize - 1 : oldsize) >> inode->i_sb->s_blocksize_bits, (attr->ia_size > 0 ? attr->ia_size - 1 : 0) >>
@@ -5701,7 +5701,7 @@ int ext4_mark_iloc_dirty(handle_t *handle,put_bh (iloc->bh);return -EIO ; } -ext4_fc_track_inode (inode); +ext4_fc_track_inode (handle, inode);if (IS_I_VERSION (inode))inode_inc_iversion (inode);
fs/ext4/namei.c +28 -33
176 lines not on this page · raw message
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 5/22 jbd2: rename j_maxlen to j_total_len and add jbd2_journal_max_txn_bufs
In reply to Harshad ShirwadkarThe on-disk superblock field sb->s_maxlen represents the total size of the journal including the fast commit area and is no more the max number of blocks available for a transaction. The maximum number of blocks available to a transaction is reduced by the number of fast commit blocks. So, this patch renames j_maxlen to j_total_len to better represent its intent. Also, it adds a function to calculate max number of bufs available for a transaction.
--- fs/ext4/fsmap.c | 2 +- fs/ext4/super.c | 2 +- fs/jbd2/commit.c | 2 +- fs/jbd2/journal.c | 12 ++++++------ fs/jbd2/recovery.c | 6 +++--- fs/ocfs2/journal.c | 2 +- include/linux/jbd2.h | 9 +++++++-- 7 files changed, 20 insertions(+), 15 deletions(-)
fs/ext4/fsmap.c +1 -1
@@ -280,7 +280,7 @@ static int ext4_getfsmap_logdev(struct super_block *sb, struct ext4_fsmap *keys,/* Fabricate an rmap entry for the external log device. */ irec.fmr_physical = journal->j_blk_offset; - irec.fmr_length = journal->j_maxlen; + irec.fmr_length = journal->j_total_len; irec.fmr_owner =EXT4_FMR_OWN_LOG ; irec.fmr_flags =0 ;
fs/ext4/super.c +1 -1
@@ -3976,7 +3976,7 @@ int ext4_calculate_overhead(struct super_block *sb)* loaded or not */ if (sbi->s_journal && !sbi->s_journal_bdev) - overhead +=EXT4_NUM_B2C (sbi, sbi->s_journal->j_maxlen); + overhead +=EXT4_NUM_B2C (sbi, sbi->s_journal->j_total_len);else if (ext4_has_feature_journal (sb) && !sbi->s_journal && j_inum) {/* j_inum for internal journal is non-zero */ j_inode =ext4_get_journal_inode (sb, j_inum);
fs/jbd2/commit.c +1 -1
@@ -801,7 +801,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)if (first_block < journal->j_tail) freed += journal->j_last - journal->j_first;/* Update tail only if we free significant amount of space */ -if (freed < journal->j_maxlen /4 ) +if (freed <jbd2_journal_get_max_txn_bufs (journal)) update_tail =0 ; }J_ASSERT (commit_transaction->t_state ==T_COMMIT );
fs/jbd2/journal.c +6 -6
@@ -1348,7 +1348,7 @@ static journal_t *journal_init_common(struct block_device *bdev, journal->j_dev = bdev; journal->j_fs_dev = fs_dev; journal->j_blk_offset = start; - journal->j_maxlen = len; + journal->j_total_len = len;/* We need enough buffers to write out full descriptor block. */ n = journal->j_blocksize /jbd2_min_tag_size (); journal->j_wbufsize = n;
@@ -1531,7 +1531,7 @@ static int journal_reset(journal_t *journal) journal->j_commit_sequence = journal->j_transaction_sequence -1 ; journal->j_commit_request = journal->j_commit_sequence; - journal->j_max_transaction_buffers = journal->j_maxlen /4 ; + journal->j_max_transaction_buffers =jbd2_journal_get_max_txn_bufs (journal);/* * As a special case, if the on-disk copy is already marked as needing
@@ -1792,15 +1792,15 @@ static int journal_get_superblock(journal_t *journal) goto out; } -if (be32_to_cpu (sb->s_maxlen) < journal->j_maxlen) - journal->j_maxlen =be32_to_cpu (sb->s_maxlen); -else if (be32_to_cpu (sb->s_maxlen) > journal->j_maxlen) { +if (be32_to_cpu (sb->s_maxlen) < journal->j_total_len) + journal->j_total_len =be32_to_cpu (sb->s_maxlen); +else if (be32_to_cpu (sb->s_maxlen) > journal->j_total_len) {printk (KERN_WARNING "JBD2: journal file too short\n" ); goto out; }if (be32_to_cpu (sb->s_first) ==0 || -be32_to_cpu (sb->s_first) >= journal->j_maxlen) { +be32_to_cpu (sb->s_first) >= journal->j_total_len) {printk (KERN_WARNING "JBD2: Invalid start block of journal: %u\n" ,be32_to_cpu (sb->s_first));
fs/jbd2/recovery.c +3 -3
@@ -74,8 +74,8 @@ static int do_readahead(journal_t *journal, unsigned int start)/* Do up to 128K of readahead */ max = start + (128 *1024 / journal->j_blocksize); -if (max > journal->j_maxlen) - max = journal->j_maxlen; +if (max > journal->j_total_len) + max = journal->j_total_len;/* Do the readahead itself. We'll submit MAXBUF buffer_heads at * a time to the block device IO layer. */
@@ -134,7 +134,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal, *bhp =NULL ; -if (offset >= journal->j_maxlen) { +if (offset >= journal->j_total_len) {printk (KERN_ERR "JBD2: corrupted journal superblock\n" );return -EFSCORRUPTED ; }
fs/ocfs2/journal.c +1 -1
@@ -877,7 +877,7 @@ int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty) goto done; } -trace_ocfs2_journal_init_maxlen (j_journal->j_maxlen); +trace_ocfs2_journal_init_maxlen (j_journal->j_total_len); *dirty = (le32_to_cpu (di->id1.journal1.ij_flags) &OCFS2_JOURNAL_DIRTY_FL );
include/linux/jbd2.h +7 -2
@@ -988,9 +988,9 @@ struct journal_sstruct block_device *j_fs_dev;/** -* @j_maxlen: Total maximum capacity of the journal region on disk. +* @j_total_len: Total maximum capacity of the journal region on disk. */ -unsigned int j_maxlen; +unsigned int j_total_len;/** * @j_reserved_credits:
@@ -1624,6 +1624,11 @@ int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);int jbd2_fc_wait_bufs (journal_t *journal,int num_blks);int jbd2_fc_release_bufs (journal_t *journal); +static inline int jbd2_journal_get_max_txn_bufs (journal_t *journal) +{ +return (journal->j_total_len - journal->j_fc_wbufsize) /4 ; +} +/* * is_journal_abort *
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 6/22 ext4: clean up the JBD2 API that initializes fast commits
In reply to Harshad ShirwadkarThis patch removes jbd2_fc_init() API and its related functions to simplify enabling fast commits. With this change, the number of fast commit blocks to use is solely determined by the JBD2 layer. So, we move the default value for minimum number of fast commit blocks from ext4/fast_commit.h to include/linux/jbd2.h. However, whether or not to use fast commits is determined by the file system. The file system just sets the fast commit feature using jbd2_journal_set_features(). JBD2 layer then determines how many blocks to use for fast commits (based on the value found in the JBD2 superblock).
Note that the JBD2 feature flag of fast commits is just an indication that there are fast commit blocks present on disk. It doesn't tell JBD2 layer about the intent of the file system of whether to it wants to use fast commit or not. That's why, we blindly clear the fast commit flag in journal_reset() after the recovery is done.
--- fs/ext4/fast_commit.c | 14 ------- fs/ext4/fast_commit.h | 3 -- fs/ext4/super.c | 8 ++++ fs/jbd2/journal.c | 96 +++++++++++++++++++++++++------------------ include/linux/jbd2.h | 2 +- 5 files changed, 65 insertions(+), 58 deletions(-)
fs/ext4/fast_commit.c +0 -14
@@ -2091,8 +2091,6 @@ static int ext4_fc_replay(journal_t *journal, struct buffer_head *bh,void ext4_fc_init (struct super_block *sb,journal_t *journal) { -int num_fc_blocks; -/* * 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
@@ -2102,18 +2100,6 @@ 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 (!buffer_uptodate (journal->j_sb_buffer) - &&ext4_read_bh_lock (journal->j_sb_buffer,REQ_META |REQ_PRIO , - true)) { -ext4_msg (sb,KERN_ERR ,"I/O error on journal" ); -return ; - } - num_fc_blocks =be32_to_cpu (journal->j_superblock->s_num_fc_blks); -if (jbd2_fc_init (journal, num_fc_blocks ? num_fc_blocks : -EXT4_NUM_FC_BLKS )) { -pr_warn ("Error while enabling fast commits, turning off." ); -ext4_clear_feature_fast_commit (sb); - } }const char *fc_ineligible_reasons[] = {
fs/ext4/fast_commit.h +0 -3
@@ -3,9 +3,6 @@#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 -/* Fast commit tags */ #define EXT4_FC_TAG_ADD_RANGE 0x0001#define EXT4_FC_TAG_DEL_RANGE 0x0002
fs/ext4/super.c +8 -0
@@ -4857,6 +4857,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount_wq; } +if (test_opt2 (sb,JOURNAL_FAST_COMMIT ) && + !jbd2_journal_set_features (EXT4_SB (sb)->s_journal,0 ,0 , +JBD2_FEATURE_INCOMPAT_FAST_COMMIT )) { +ext4_msg (sb,KERN_ERR , +"Failed to set fast commit journal feature" ); + goto failed_mount_wq; + } +/* We have now updated the journal if required, so we can * validate the data journaling mode. */ switch (test_opt (sb,DATA_FLAGS )) {
fs/jbd2/journal.c +56 -40
170 lines not on this page · raw message
include/linux/jbd2.h +1 -1
@@ -68,6 +68,7 @@ extern void *jbd2_alloc(size_t size, gfp_t flags);extern void jbd2_free (void *ptr,size_t size);#define JBD2_MIN_JOURNAL_BLOCKS 1024 +#define JBD2_MIN_FC_BLOCKS 256#ifdef __KERNEL__
@@ -1614,7 +1615,6 @@ 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);int jbd2_fc_begin_commit (journal_t *journal,tid_t tid);int jbd2_fc_end_commit (journal_t *journal);int jbd2_fc_end_commit_fallback (journal_t *journal,tid_t tid);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 7/22 jbd2: drop jbd2_fc_init documentation
In reply to Harshad ShirwadkarNow that jbd2_fc_init is dropped, drop its docs too.
--- Documentation/filesystems/journalling.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Documentation/filesystems/journalling.rst +2 -4
@@ -136,10 +136,8 @@ 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: +fast commits. In order to use fast commits, you will need to set following +callbacks that perform correspodning work: `journal->j_fc_cleanup_cb`: Cleanup function called after every full commit and fast commit.
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 8/22 jbd2: don't use state lock during commit path
In reply to Harshad ShirwadkarVariables journal->j_fc_off, journal->j_fc_wbuf are accessed during commit path. Since today we allow only one process to perform a fast commit, there is no need take state lock before accessing these variables. This patch removes these locks and adds comments to describe this.
--- fs/jbd2/journal.c | 6 ------ include/linux/jbd2.h | 10 ++++++---- 2 files changed, 6 insertions(+), 10 deletions(-)
fs/jbd2/journal.c +0 -6
@@ -865,7 +865,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)int fc_off; *bh_out =NULL ; -write_lock (&journal->j_state_lock);if (journal->j_fc_off + journal->j_fc_first < journal->j_fc_last) { fc_off = journal->j_fc_off;
@@ -874,7 +873,6 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) }else { ret = -EINVAL ; } -write_unlock (&journal->j_state_lock);if (ret)return ret;
@@ -909,9 +907,7 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)struct buffer_head *bh;int i, j_fc_off; -read_lock (&journal->j_state_lock); j_fc_off = journal->j_fc_off; -read_unlock (&journal->j_state_lock);/* * Wait in reverse order to minimize chances of us being woken up before
@@ -939,9 +935,7 @@ int jbd2_fc_release_bufs(journal_t *journal)struct buffer_head *bh;int i, j_fc_off; -read_lock (&journal->j_state_lock); j_fc_off = journal->j_fc_off; -read_unlock (&journal->j_state_lock);/* * Wait in reverse order to minimize chances of us being woken up before
include/linux/jbd2.h +6 -4
@@ -945,8 +945,9 @@ struct journal_s/** * @j_fc_off: * -* Number of fast commit blocks currently allocated. -* [j_state_lock]. +* Number of fast commit blocks currently allocated. Accessed only +* during fast commit. Currently only process can do fast commit, so +* this field is not protected by any lock. */ unsigned long j_fc_off;
@@ -1109,8 +1110,9 @@ struct journal_sstruct buffer_head **j_wbuf;/** -* @j_fc_wbuf: Array of fast commit bhs for -* jbd2_journal_commit_transaction. +* @j_fc_wbuf: Array of fast commit bhs for fast commit. Accessed only +* during a fast commit. Currently only process can do fast commit, so +* this field is not protected by any lock. */ struct buffer_head **j_fc_wbuf;
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 9/22 jbd2: don't pass tid to jbd2_fc_end_commit_fallback()
In reply to Harshad ShirwadkarIn jbd2_fc_end_commit_fallback(), we know which tid to commit. There's no need for caller to pass it.
--- fs/ext4/fast_commit.c | 2 +- fs/jbd2/journal.c | 12 +++++++++--- include/linux/jbd2.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)
fs/ext4/fast_commit.c +1 -1
@@ -1143,7 +1143,7 @@ int ext4_fc_commit(journal_t *journal, tid_t commit_tid)"Fast commit ended with blks = %d, reason = %d, subtid - %d" , nblks, reason, subtid);if (reason ==EXT4_FC_REASON_FC_FAILED ) -return jbd2_fc_end_commit_fallback (journal, commit_tid); +return jbd2_fc_end_commit_fallback (journal);if (reason ==EXT4_FC_REASON_FC_START_FAILED || reason ==EXT4_FC_REASON_INELIGIBLE )return jbd2_complete_transaction (journal, commit_tid);
fs/jbd2/journal.c +9 -3
@@ -777,13 +777,19 @@ static int __jbd2_fc_end_commit(journal_t *journal, tid_t tid, bool fallback)int jbd2_fc_end_commit (journal_t *journal) { -return __jbd2_fc_end_commit (journal,0 ,0 ); +return __jbd2_fc_end_commit (journal,0 , false); }EXPORT_SYMBOL (jbd2_fc_end_commit); -int jbd2_fc_end_commit_fallback (journal_t *journal,tid_t tid) +int jbd2_fc_end_commit_fallback (journal_t *journal) { -return __jbd2_fc_end_commit (journal, tid,1 ); +tid_t tid; + +read_lock (&journal->j_state_lock); + tid = journal->j_running_transaction ? + journal->j_running_transaction->t_tid :0 ; +read_unlock (&journal->j_state_lock); +return __jbd2_fc_end_commit (journal, tid, true); }EXPORT_SYMBOL (jbd2_fc_end_commit_fallback);
include/linux/jbd2.h +1 -1
@@ -1619,7 +1619,7 @@ extern int jbd2_cleanup_journal_tail(journal_t *);/* Fast commit related APIs */ int jbd2_fc_begin_commit (journal_t *journal,tid_t tid);int jbd2_fc_end_commit (journal_t *journal); -int jbd2_fc_end_commit_fallback (journal_t *journal,tid_t tid); +int jbd2_fc_end_commit_fallback (journal_t *journal);int jbd2_fc_get_buf (journal_t *journal,struct buffer_head **bh_out);int jbd2_submit_inode_data (struct jbd2_inode *jinode);int jbd2_wait_inode_data (journal_t *journal,struct jbd2_inode *jinode);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 10/22 jbd2: add todo for a fast commit performance optimization
In reply to Harshad ShirwadkarFast commit performance can be optimized if commit thread doesn't wait for ongoing fast commits to complete until the transaction enters T_FLUSH state. Document this optimization.
--- fs/jbd2/commit.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/jbd2/commit.c +9 -0
@@ -450,6 +450,15 @@ void jbd2_journal_commit_transaction(journal_t *journal)schedule ();write_lock (&journal->j_state_lock);finish_wait (&journal->j_fc_wait, &wait); +/* +* TODO: by blocking fast commits here, we are increasing +* fsync() latency slightly. Strictly speaking, we don't need +* to block fast commits until the transaction enters T_FLUSH +* state. So an optimization is possible where we block new fast +* commits here and wait for existing ones to complete +* just before we enter T_FLUSH. That way, the existing fast +* commits and this full commit can proceed parallely. +*/ }write_unlock (&journal->j_state_lock);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 11/22 jbd2: don't touch buffer state until it is filled
In reply to Harshad ShirwadkarFast commit buffers should be filled in before toucing their state. Remove code that sets buffer state as dirty before the buffer is passed to the file system.
--- fs/jbd2/journal.c | 4 ---- 1 file changed, 4 deletions(-)
fs/jbd2/journal.c +0 -4
@@ -891,11 +891,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)if (!bh)return -ENOMEM ; -lock_buffer (bh); -clear_buffer_uptodate (bh); -set_buffer_dirty (bh); -unlock_buffer (bh); journal->j_fc_wbuf[fc_off] = bh; *bh_out = bh;
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 12/22 jbd2: don't read journal->j_commit_sequence without taking a lock
In reply to Harshad ShirwadkarTake journal state lock before reading journal->j_commit_sequence.
--- fs/jbd2/journal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/jbd2/journal.c +4 -2
@@ -734,10 +734,12 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)if (!journal->j_stats.ts_tid)return -EINVAL ; -if (tid <= journal->j_commit_sequence) +write_lock (&journal->j_state_lock); +if (tid <= journal->j_commit_sequence) { +write_unlock (&journal->j_state_lock);return -EALREADY ; + } -write_lock (&journal->j_state_lock);if (journal->j_flags &JBD2_FULL_COMMIT_ONGOING || (journal->j_flags &JBD2_FAST_COMMIT_ONGOING )) {DEFINE_WAIT (wait);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 13/22 ext4: dedpulicate the code to wait on inode that's being committed
In reply to Harshad ShirwadkarThis patch removes the deduplicates the code that implements waiting on inode that's being committed. That code is moved into a new function.
--- fs/ext4/fast_commit.c | 61 +++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 34 deletions(-)
fs/ext4/fast_commit.c +27 -34
@@ -155,6 +155,30 @@ void ext4_fc_init_inode(struct inode *inode) ei->i_fc_committed_subtid =0 ; } +/* This function must be called with sbi->s_fc_lock held. */ +static void ext4_fc_wait_committing_inode (struct inode *inode) +{ +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 *
@@ -176,22 +200,7 @@ void ext4_fc_start_update(struct inode *inode) goto out;if (ext4_test_inode_state (inode,EXT4_STATE_FC_COMMITTING )) { -wait_queue_head_t *wq; -#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 ); -spin_unlock (&EXT4_SB (inode->i_sb)->s_fc_lock); -schedule (); -finish_wait (wq, &wait.wq_entry); +ext4_fc_wait_committing_inode (inode); goto restart; } out:
@@ -234,26 +243,10 @@ void ext4_fc_del(struct inode *inode) }if (ext4_test_inode_state (inode,EXT4_STATE_FC_COMMITTING )) { -wait_queue_head_t *wq; -#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 ); -spin_unlock (&EXT4_SB (inode->i_sb)->s_fc_lock); -schedule (); -finish_wait (wq, &wait.wq_entry); +ext4_fc_wait_committing_inode (inode); goto restart; } -if (!list_empty (&ei->i_fc_list)) -list_del_init (&ei->i_fc_list); +list_del_init (&ei->i_fc_list);spin_unlock (&EXT4_SB (inode->i_sb)->s_fc_lock); }
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 14/22 ext4: fix code documentatioon
In reply to Harshad ShirwadkarAdd a TODO to remember fixing REQ_FUA | REQ_PREFLUSH for fast commit buffers. Also, fix a typo in top level comment in fast_commit.c
--- fs/ext4/fast_commit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/fast_commit.c +2 -1
@@ -83,7 +83,7 @@* * Atomicity of commits * -------------------- -* In order to gaurantee atomicity during the commit operation, fast commit +* In order to guarantee atomicity during the commit operation, fast commit * uses "EXT4_FC_TAG_TAIL" tag that marks a fast commit as complete. Tail * tag contains CRC of the contents and TID of the transaction after which * this fast commit should be applied. Recovery code replays fast commit
@@ -542,6 +542,7 @@ static void ext4_fc_submit_bh(struct super_block *sb)int write_flags =REQ_SYNC ;struct buffer_head *bh =EXT4_SB (sb)->s_fc_bh; +/* TODO: REQ_FUA | REQ_PREFLUSH is unnecessarily expensive. */ if (test_opt (sb,BARRIER )) write_flags |=REQ_FUA |REQ_PREFLUSH ;lock_buffer (bh);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 15/22 ext4: mark buf dirty before submitting fast commit buffer
In reply to Harshad ShirwadkarMark the fast commit buffer as dirty before submission.
--- fs/ext4/fast_commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/fast_commit.c +1 -1
@@ -546,7 +546,7 @@ static void ext4_fc_submit_bh(struct super_block *sb)if (test_opt (sb,BARRIER )) write_flags |=REQ_FUA |REQ_PREFLUSH ;lock_buffer (bh); -clear_buffer_dirty (bh); +set_buffer_dirty (bh);set_buffer_uptodate (bh); bh->b_end_io = ext4_end_buffer_io_sync;submit_bh (REQ_OP_WRITE , write_flags, bh);
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 16/22 ext4: remove unnecessary fast commit calls from ext4_file_mmap
In reply to Harshad ShirwadkarRemove unnecessary calls to ext4_fc_start_update() and ext4_fc_stop_update() from ext4_file_mmap().
--- fs/ext4/file.c | 2 -- 1 file changed, 2 deletions(-)
fs/ext4/file.c +0 -2
@@ -761,7 +761,6 @@ 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;
@@ -769,7 +768,6 @@ 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 ; }
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 17/22 ext4: fix inode dirty check in case of fast commits
In reply to Harshad ShirwadkarIn case of fast commits, determine if the inode is dirty by checking if the inode is on fast commit list. This also helps us get rid of ext4_inode_info.i_fc_committed_subtid field.
--- fs/ext4/ext4.h | 3 --- fs/ext4/fast_commit.c | 3 --- fs/ext4/inode.c | 3 +-- 3 files changed, 1 insertion(+), 8 deletions(-)
fs/ext4/ext4.h +0 -3
@@ -1028,9 +1028,6 @@ struct ext4_inode_info {* protected by sbi->s_fc_lock. */ -/* Fast commit subtid when this inode was committed */ -unsigned int i_fc_committed_subtid; -/* Start of lblk range that needs to be committed in this fast commit */ ext4_lblk_t i_fc_lblk_start;
fs/ext4/fast_commit.c +0 -3
@@ -152,7 +152,6 @@ void ext4_fc_init_inode(struct inode *inode)INIT_LIST_HEAD (&ei->i_fc_list);init_waitqueue_head (&ei->i_fc_wait);atomic_set (&ei->i_fc_updates,0 ); - ei->i_fc_committed_subtid =0 ; }/* This function must be called with sbi->s_fc_lock held. */
@@ -1037,8 +1036,6 @@ static int ext4_fc_perform_commit(journal_t *journal)if (ret) goto out;spin_lock (&sbi->s_fc_lock); -EXT4_I (inode)->i_fc_committed_subtid = -atomic_read (&sbi->s_fc_subtid); }spin_unlock (&sbi->s_fc_lock);
fs/ext4/inode.c +1 -2
@@ -3312,8 +3312,7 @@ static bool ext4_inode_datasync_dirty(struct inode *inode) EXT4_I(inode)->i_datasync_tid))return false;if (test_opt2 (inode->i_sb,JOURNAL_FAST_COMMIT )) -return atomic_read (&EXT4_SB (inode->i_sb)->s_fc_subtid) < -EXT4_I (inode)->i_fc_committed_subtid; +return !list_empty (&EXT4_I (inode)->i_fc_list);return true; }
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 18/22 ext4: disable fast commit with data journalling
In reply to Harshad ShirwadkarFast commits don't work with data journalling. This patch disables the fast commit support when data journalling is turned on.
--- fs/ext4/fast_commit.c | 7 +++++++ fs/ext4/fast_commit.h | 1 + fs/ext4/super.c | 3 ++- include/trace/events/ext4.h | 6 ++++-- 4 files changed, 14 insertions(+), 3 deletions(-)
fs/ext4/fast_commit.c +7 -0
@@ -483,6 +483,12 @@ void ext4_fc_track_inode(handle_t *handle, struct inode *inode)if (S_ISDIR (inode->i_mode))return ; +if (ext4_should_journal_data (inode)) { +ext4_fc_mark_ineligible (inode->i_sb, +EXT4_FC_REASON_INODE_JOURNAL_DATA ); +return ; + } + ret =ext4_fc_track_template (handle, inode, __track_inode,NULL ,1 );trace_ext4_fc_track_inode (inode, ret); }
@@ -2102,6 +2108,7 @@ const char *fc_ineligible_reasons[] = {"Resize" ,"Dir renamed" ,"Falloc range op" , +"Data journalling" , "FC Commit Failed" };
fs/ext4/fast_commit.h +1 -0
@@ -102,6 +102,7 @@ enum {EXT4_FC_REASON_RESIZE ,EXT4_FC_REASON_RENAME_DIR ,EXT4_FC_REASON_FALLOC_RANGE , +EXT4_FC_REASON_INODE_JOURNAL_DATA ,EXT4_FC_COMMIT_FAILED , EXT4_FC_REASON_MAX };
fs/ext4/super.c +2 -1
@@ -4340,9 +4340,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)#endif if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA ) { -printk_once (KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, and O_DIRECT support!\n" ); +printk_once (KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n" );/* can't mount with both data=journal and dioread_nolock. */ clear_opt (sb,DIOREAD_NOLOCK ); +clear_opt2 (sb,JOURNAL_FAST_COMMIT );if (test_opt2 (sb,EXPLICIT_DELALLOC )) {ext4_msg (sb,KERN_ERR ,"can't mount with " "both data=journal and delalloc" );
include/trace/events/ext4.h +4 -2
@@ -104,7 +104,8 @@ TRACE_DEFINE_ENUM(ES_REFERENCED_B); { EXT4_FC_REASON_SWAP_BOOT, "SWAP_BOOT"}, \ { EXT4_FC_REASON_RESIZE, "RESIZE"}, \ { EXT4_FC_REASON_RENAME_DIR, "RENAME_DIR"}, \ - { EXT4_FC_REASON_FALLOC_RANGE, "FALLOC_RANGE"}) + { EXT4_FC_REASON_FALLOC_RANGE, "FALLOC_RANGE"}, \ + { EXT4_FC_REASON_INODE_JOURNAL_DATA, "INODE_JOURNAL_DATA"}) TRACE_EVENT(ext4_other_inode_update_time, TP_PROTO(struct inode *inode, ino_t orig_ino),
@@ -2917,7 +2918,7 @@ TRACE_EVENT(ext4_fc_stats, ), TP_printk("dev %d:%d fc ineligible reasons:\n" - "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d; " + "%s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d, %s:%d; " "num_commits:%ld, ineligible: %ld, numblks: %ld", MAJOR(__entry->dev), MINOR(__entry->dev), FC_REASON_NAME_STAT(EXT4_FC_REASON_XATTR),
@@ -2928,6 +2929,7 @@ TRACE_EVENT(ext4_fc_stats,FC_REASON_NAME_STAT (EXT4_FC_REASON_RESIZE ),FC_REASON_NAME_STAT (EXT4_FC_REASON_RENAME_DIR ),FC_REASON_NAME_STAT (EXT4_FC_REASON_FALLOC_RANGE ), +FC_REASON_NAME_STAT (EXT4_FC_REASON_INODE_JOURNAL_DATA ), __entry->sbi->s_fc_stats.fc_num_commits, __entry->sbi->s_fc_stats.fc_ineligible_commits, __entry->sbi->s_fc_stats.fc_numblks)
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 19/22 ext4: issue fsdev cache flush before starting fast commit
In reply to Harshad ShirwadkarIf the journal dev is different from fsdev, issue a cache flush before committing fast commit blocks to disk.
--- fs/ext4/fast_commit.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/ext4/fast_commit.c +7 -0
@@ -1007,6 +1007,13 @@ static int ext4_fc_perform_commit(journal_t *journal)if (ret)return ret; +/* +* If file system device is different from journal device, issue a cache +* flush before we start writing fast commit blocks. +*/ +if (journal->j_fs_dev != journal->j_dev) +blkdev_issue_flush (journal->j_fs_dev,GFP_NOFS ); +blk_start_plug (&plug);if (sbi->s_fc_bytes ==0 ) {/*
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 20/22 ext4: make s_mount_flags modifications atomic
In reply to Harshad ShirwadkarFast commit file system states are recorded in sbi->s_mount_flags. Fast commit expects these bit manipulations to be atomic. This patch adds helpers to make those modifications atomic.
--- fs/ext4/ext4.h | 40 +++++++++++++++++++++++++++++----------- fs/ext4/fast_commit.c | 18 +++++++++--------- fs/ext4/file.c | 4 ++-- fs/ext4/fsync.c | 2 +- fs/ext4/inode.c | 4 ++-- fs/ext4/mballoc.c | 4 ++-- fs/ext4/super.c | 14 +++++++------- 7 files changed, 52 insertions(+), 34 deletions(-)
fs/ext4/ext4.h +29 -11
@@ -1419,16 +1419,6 @@ struct ext4_super_block {#ifdef __KERNEL__ -/* -* run-time mount flags -*/ -#define EXT4_MF_MNTDIR_SAMPLED 0x0001 -#define EXT4_MF_FS_ABORTED 0x0002/* Fatal error detected */ -#define EXT4_MF_FC_INELIGIBLE 0x0004/* Fast commit ineligible */ -#define EXT4_MF_FC_COMMITTING 0x0008/* File system underoing a fast -* commit. -*/ -#ifdef CONFIG_FS_ENCRYPTION #define DUMMY_ENCRYPTION_ENABLED (sbi) ((sbi)->s_dummy_enc_policy.policy != NULL)#else
@@ -1471,7 +1461,7 @@ struct ext4_sb_info {struct buffer_head *__rcu *s_group_desc;unsigned int s_mount_opt;unsigned int s_mount_opt2; -unsigned int s_mount_flags; +unsigned long s_mount_flags;unsigned int s_def_mount_opt;ext4_fsblk_t s_sb_block;atomic64_t s_resv_clusters;
@@ -1703,6 +1693,34 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) _v; \ }) +/* +* run-time mount flags +*/ +enum { +EXT4_MF_MNTDIR_SAMPLED , +EXT4_MF_FS_ABORTED ,/* Fatal error detected */ +EXT4_MF_FC_INELIGIBLE ,/* Fast commit ineligible */ +EXT4_MF_FC_COMMITTING /* File system underoing a fast +* commit. +*/ +}; + +static inline void ext4_set_mount_flag (struct super_block *sb,int bit) +{ +set_bit (bit, &EXT4_SB (sb)->s_mount_flags); +} + +static inline void ext4_clear_mount_flag (struct super_block *sb,int bit) +{ +clear_bit (bit, &EXT4_SB (sb)->s_mount_flags); +} + +static inline int ext4_test_mount_flag (struct super_block *sb,int bit) +{ +return test_bit (bit, &EXT4_SB (sb)->s_mount_flags); +} + +/* * Simulate_fail codes */
fs/ext4/fast_commit.c +9 -9
@@ -261,7 +261,7 @@ void ext4_fc_mark_ineligible(struct super_block *sb, int reason) (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) return; - sbi->s_mount_flags |=EXT4_MF_FC_INELIGIBLE ; +ext4_set_mount_flag (sb,EXT4_MF_FC_INELIGIBLE );WARN_ON (reason >=EXT4_FC_REASON_MAX ); sbi->s_fc_stats.fc_ineligible_reason_count[reason]++; }
@@ -294,14 +294,14 @@ void ext4_fc_stop_ineligible(struct super_block *sb) (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) return; -EXT4_SB (sb)->s_mount_flags |=EXT4_MF_FC_INELIGIBLE ; +ext4_set_mount_flag (sb,EXT4_MF_FC_INELIGIBLE );atomic_dec (&EXT4_SB (sb)->s_fc_ineligible_updates); }static inline int ext4_fc_is_ineligible (struct super_block *sb) { -return (EXT4_SB (sb)->s_mount_flags &EXT4_MF_FC_INELIGIBLE ) || -atomic_read (&EXT4_SB (sb)->s_fc_ineligible_updates); +return (ext4_test_mount_flag (sb,EXT4_MF_FC_INELIGIBLE ) || +atomic_read (&EXT4_SB (sb)->s_fc_ineligible_updates)); }/*
@@ -349,7 +349,7 @@ static int ext4_fc_track_template(spin_lock (&sbi->s_fc_lock);if (list_empty (&EXT4_I (inode)->i_fc_list))list_add_tail (&EXT4_I (inode)->i_fc_list, - (sbi->s_mount_flags &EXT4_MF_FC_COMMITTING ) ? + (ext4_test_mount_flag (inode->i_sb,EXT4_MF_FC_COMMITTING )) ? &sbi->s_fc_q[FC_Q_STAGING ] : &sbi->s_fc_q[FC_Q_MAIN ]);spin_unlock (&sbi->s_fc_lock);
@@ -402,7 +402,7 @@ static int __track_dentry_update(struct inode *inode, void *arg, bool update) node->fcd_name.len = dentry->d_name.len;spin_lock (&sbi->s_fc_lock); -if (sbi->s_mount_flags &EXT4_MF_FC_COMMITTING ) +if (ext4_test_mount_flag (inode->i_sb,EXT4_MF_FC_COMMITTING ))list_add_tail (&node->fcd_list, &sbi->s_fc_dentry_q[FC_Q_STAGING ]);else
@@ -857,7 +857,7 @@ static int ext4_fc_submit_inode_data_all(journal_t *journal)int ret =0 ;spin_lock (&sbi->s_fc_lock); - sbi->s_mount_flags |=EXT4_MF_FC_COMMITTING ; +ext4_set_mount_flag (sb,EXT4_MF_FC_COMMITTING );list_for_each (pos, &sbi->s_fc_q[FC_Q_MAIN ]) { ei = list_entry(pos, struct ext4_inode_info, i_fc_list);ext4_set_inode_state (&ei->vfs_inode,EXT4_STATE_FC_COMMITTING );
@@ -1206,8 +1206,8 @@ static void ext4_fc_cleanup(journal_t *journal, int full)list_splice_init (&sbi->s_fc_q[FC_Q_STAGING ], &sbi->s_fc_q[FC_Q_STAGING ]); - sbi->s_mount_flags &= ~EXT4_MF_FC_COMMITTING ; - sbi->s_mount_flags &= ~EXT4_MF_FC_INELIGIBLE ; +ext4_clear_mount_flag (sb,EXT4_MF_FC_COMMITTING ); +ext4_clear_mount_flag (sb,EXT4_MF_FC_INELIGIBLE );if (full) sbi->s_fc_bytes =0 ;
fs/ext4/file.c +2 -2
@@ -780,13 +780,13 @@ static int ext4_sample_last_mounted(struct super_block *sb,handle_t *handle;int err; -if (likely (sbi->s_mount_flags &EXT4_MF_MNTDIR_SAMPLED )) +if (likely (ext4_test_mount_flag (sb,EXT4_MF_MNTDIR_SAMPLED )))return 0 ;if (sb_rdonly (sb) || !sb_start_intwrite_trylock (sb))return 0 ; - sbi->s_mount_flags |=EXT4_MF_MNTDIR_SAMPLED ; +ext4_set_mount_flag (sb,EXT4_MF_MNTDIR_SAMPLED );/* * Sample where the filesystem has been mounted and * store it in the superblock for sysadmin convenience
fs/ext4/fsync.c +1 -1
@@ -143,7 +143,7 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)if (sb_rdonly (inode->i_sb)) {/* Make sure that we read updated s_mount_flags value */ smp_rmb (); -if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED ) +if (ext4_test_mount_flag (inode->i_sb,EXT4_MF_FS_ABORTED )) ret = -EROFS ; goto out; }
fs/ext4/inode.c +2 -2
@@ -2442,7 +2442,7 @@ static int mpage_map_and_submit_extent(handle_t *handle,struct super_block *sb = inode->i_sb;if (ext4_forced_shutdown (EXT4_SB (sb)) || -EXT4_SB (sb)->s_mount_flags &EXT4_MF_FS_ABORTED ) +ext4_test_mount_flag (sb,EXT4_MF_FS_ABORTED )) goto invalidate_dirty_pages;/* * Let the uper layers retry transient errors.
@@ -2676,7 +2676,7 @@ static int ext4_writepages(struct address_space *mapping,* the stack trace. */ if (unlikely (ext4_forced_shutdown (EXT4_SB (mapping->host->i_sb)) || - sbi->s_mount_flags &EXT4_MF_FS_ABORTED )) { +ext4_test_mount_flag (inode->i_sb,EXT4_MF_FS_ABORTED ))) { ret = -EROFS ; goto out_writepages; }
fs/ext4/mballoc.c +2 -2
@@ -4477,7 +4477,7 @@ static inline void ext4_mb_show_pa(struct super_block *sb) {ext4_group_t i, ngroups; -if (EXT4_SB (sb)->s_mount_flags &EXT4_MF_FS_ABORTED ) +if (ext4_test_mount_flag (sb,EXT4_MF_FS_ABORTED ))return ; ngroups =ext4_get_groups_count (sb);
@@ -4508,7 +4508,7 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac) {struct super_block *sb = ac->ac_sb; -if (EXT4_SB (sb)->s_mount_flags &EXT4_MF_FS_ABORTED ) +if (ext4_test_mount_flag (sb,EXT4_MF_FS_ABORTED ))return ; mb_debug(sb, "Can't allocate:"
fs/ext4/super.c +7 -7
@@ -686,7 +686,7 @@ static void ext4_handle_error(struct super_block *sb)if (!test_opt (sb,ERRORS_CONT )) {journal_t *journal =EXT4_SB (sb)->s_journal; -EXT4_SB (sb)->s_mount_flags |=EXT4_MF_FS_ABORTED ; +ext4_set_mount_flag (sb,EXT4_MF_FS_ABORTED );if (journal)jbd2_journal_abort (journal, -EIO ); }
@@ -904,7 +904,7 @@ void __ext4_abort(struct super_block *sb, const char *function,va_end (args);if (sb_rdonly (sb) ==0 ) { -EXT4_SB (sb)->s_mount_flags |=EXT4_MF_FS_ABORTED ; +ext4_set_mount_flag (sb,EXT4_MF_FS_ABORTED );if (EXT4_SB (sb)->s_journal)jbd2_journal_abort (EXT4_SB (sb)->s_journal, -EIO );
@@ -2153,7 +2153,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,ext4_msg (sb,KERN_WARNING ,"Ignoring removed %s option" , opt);return 1 ;case Opt_abort: - sbi->s_mount_flags |=EXT4_MF_FS_ABORTED ; +ext4_set_mount_flag (sb,EXT4_MF_FS_ABORTED );return 1 ;case Opt_i_version: sb->s_flags |=SB_I_VERSION ;
@@ -4778,8 +4778,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)INIT_LIST_HEAD (&sbi->s_fc_dentry_q[FC_Q_MAIN ]);INIT_LIST_HEAD (&sbi->s_fc_dentry_q[FC_Q_STAGING ]); sbi->s_fc_bytes =0 ; - sbi->s_mount_flags &= ~EXT4_MF_FC_INELIGIBLE ; - sbi->s_mount_flags &= ~EXT4_MF_FC_COMMITTING ; +ext4_clear_mount_flag (sb,EXT4_MF_FC_INELIGIBLE ); +ext4_clear_mount_flag (sb,EXT4_MF_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 ;
@@ -5881,7 +5881,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) goto restore_opts; } -if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED ) +if (ext4_test_mount_flag (sb,EXT4_MF_FS_ABORTED ))ext4_abort (sb,EXT4_ERR_ESHUTDOWN ,"Abort forced by user" ); sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
@@ -5895,7 +5895,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) }if ((bool )(*flags &SB_RDONLY ) !=sb_rdonly (sb)) { -if (sbi->s_mount_flags &EXT4_MF_FS_ABORTED ) { +if (ext4_test_mount_flag (sb,EXT4_MF_FS_ABORTED )) { err = -EROFS ; goto restore_opts; }
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 21/22 jbd2: don't start fast commit on aborted journal
In reply to Harshad ShirwadkarFast commit should not be started if the journal is aborted.
--- fs/jbd2/journal.c | 2 ++ 1 file changed, 2 insertions(+)
fs/jbd2/journal.c +2 -0
@@ -727,6 +727,8 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)*/ int jbd2_fc_begin_commit (journal_t *journal,tid_t tid) { +if (unlikely (is_journal_aborted (journal))) +return -EIO ;/* * Fast commits only allowed if at least one full commit has * been processed.
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog
PATCH v2 22/22 ext4: cleanup fast commit mount options
In reply to Harshad ShirwadkarDrop no_fc mount option that disable fast commit even if it was enabled at mkfs time. Move fc_debug_force mount option under ifdef EXT4_DEBUG to annotate that this is strictly for debugging and testing purposes and should not be used in production.
--- fs/ext4/super.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
fs/ext4/super.c +4 -8
@@ -1716,11 +1716,10 @@ 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_prefetch_block_bitmaps, Opt_no_fc, + Opt_prefetch_block_bitmaps, #ifdef CONFIG_EXT4_DEBUG - Opt_fc_debug_max_replay, + Opt_fc_debug_max_replay, Opt_fc_debug_force #endif - Opt_fc_debug_force }; static const match_table_t tokens = {
@@ -1807,9 +1806,8 @@ 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_fc_debug_force, "fc_debug_force"}, #ifdef CONFIG_EXT4_DEBUG + {Opt_fc_debug_force, "fc_debug_force"}, {Opt_fc_debug_max_replay, "fc_debug_max_replay=%u"}, #endif {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
@@ -2039,11 +2037,9 @@ static const struct mount_opts { {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET}, {Opt_prefetch_block_bitmaps, EXT4_MOUNT_PREFETCH_BLOCK_BITMAPS, MOPT_SET}, - {Opt_no_fc, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, - MOPT_CLEAR | MOPT_2 | MOPT_EXT4_ONLY}, +#ifdef CONFIG_EXT4_DEBUG {Opt_fc_debug_force, EXT4_MOUNT2_JOURNAL_FAST_COMMIT, MOPT_SET | MOPT_2 | MOPT_EXT4_ONLY}, -#ifdef CONFIG_EXT4_DEBUG {Opt_fc_debug_max_replay, 0, MOPT_GTE0}, #endif {Opt_err, 0, 0}
Signature · 1 line
2.29.1.341.ge80a0c044ae-goog