ext4: make data=journal support large block size

Currently, ext4_set_inode_mapping_order() does not set max folio order
for files with the data journalling flag. For files that already have
large folios enabled, ext4_inode_journal_mode() ignores the data
journalling flag once max folio order is set.

This is not because data journalling cannot work with large folios, but
because credit estimates will go through the roof if there are too many
blocks per folio.

Since the real constraint is blocks-per-folio, to support data=journal
under LBS, we now set max folio order to be equal to min folio order for
files with the journalling flag. When LBS is disabled, the max folio order
remains unset as before.

Therefore, before ext4_change_inode_journal_flag() switches the journalling
mode, we call truncate_pagecache() to drop all page cache for that inode,
and filemap_write_and_wait() is called unconditionally.

After that, once the journalling mode has been switched, we can safely
reset the inode mapping order, and the mapping_large_folio_support() check
in ext4_inode_journal_mode() can be removed.

Suggested-by: Jan Kara <jack@suse.cz>
Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Message-ID: <20251121090654.631996-22-libaokun@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
Baokun Li 2025-11-21 17:06:51 +08:00 committed by Theodore Ts'o
parent c00a6292d0
commit 58fd191f99
2 changed files with 20 additions and 16 deletions

View File

@ -16,8 +16,7 @@ int ext4_inode_journal_mode(struct inode *inode)
ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) ||
test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA || test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
(ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
!test_opt(inode->i_sb, DELALLOC) && !test_opt(inode->i_sb, DELALLOC))) {
!mapping_large_folio_support(inode->i_mapping))) {
/* We do not support data journalling for encrypted data */ /* We do not support data journalling for encrypted data */
if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */

View File

@ -5154,9 +5154,6 @@ static bool ext4_should_enable_large_folio(struct inode *inode)
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return false; return false;
if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA))
return false;
if (ext4_has_feature_verity(sb)) if (ext4_has_feature_verity(sb))
return false; return false;
if (ext4_has_feature_encrypt(sb)) if (ext4_has_feature_encrypt(sb))
@ -5174,12 +5171,20 @@ static bool ext4_should_enable_large_folio(struct inode *inode)
umin(MAX_PAGECACHE_ORDER, (11 + (i)->i_blkbits - PAGE_SHIFT)) umin(MAX_PAGECACHE_ORDER, (11 + (i)->i_blkbits - PAGE_SHIFT))
void ext4_set_inode_mapping_order(struct inode *inode) void ext4_set_inode_mapping_order(struct inode *inode)
{ {
u32 max_order;
if (!ext4_should_enable_large_folio(inode)) if (!ext4_should_enable_large_folio(inode))
return; return;
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA))
max_order = EXT4_SB(inode->i_sb)->s_min_folio_order;
else
max_order = EXT4_MAX_PAGECACHE_ORDER(inode);
mapping_set_folio_order_range(inode->i_mapping, mapping_set_folio_order_range(inode->i_mapping,
EXT4_SB(inode->i_sb)->s_min_folio_order, EXT4_SB(inode->i_sb)->s_min_folio_order,
EXT4_MAX_PAGECACHE_ORDER(inode)); max_order);
} }
struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
@ -6554,14 +6559,14 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
* dirty data which can be converted only after flushing the dirty * dirty data which can be converted only after flushing the dirty
* data (and journalled aops don't know how to handle these cases). * data (and journalled aops don't know how to handle these cases).
*/ */
if (val) {
filemap_invalidate_lock(inode->i_mapping); filemap_invalidate_lock(inode->i_mapping);
err = filemap_write_and_wait(inode->i_mapping); err = filemap_write_and_wait(inode->i_mapping);
if (err < 0) { if (err < 0) {
filemap_invalidate_unlock(inode->i_mapping); filemap_invalidate_unlock(inode->i_mapping);
return err; return err;
} }
} /* Before switch the inode journalling mode evict all the page cache. */
truncate_pagecache(inode, 0);
alloc_ctx = ext4_writepages_down_write(inode->i_sb); alloc_ctx = ext4_writepages_down_write(inode->i_sb);
jbd2_journal_lock_updates(journal); jbd2_journal_lock_updates(journal);
@ -6581,16 +6586,16 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
if (err < 0) { if (err < 0) {
jbd2_journal_unlock_updates(journal); jbd2_journal_unlock_updates(journal);
ext4_writepages_up_write(inode->i_sb, alloc_ctx); ext4_writepages_up_write(inode->i_sb, alloc_ctx);
filemap_invalidate_unlock(inode->i_mapping);
return err; return err;
} }
ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);
} }
ext4_set_aops(inode); ext4_set_aops(inode);
ext4_set_inode_mapping_order(inode);
jbd2_journal_unlock_updates(journal); jbd2_journal_unlock_updates(journal);
ext4_writepages_up_write(inode->i_sb, alloc_ctx); ext4_writepages_up_write(inode->i_sb, alloc_ctx);
if (val)
filemap_invalidate_unlock(inode->i_mapping); filemap_invalidate_unlock(inode->i_mapping);
/* Finally we can mark the inode as dirty. */ /* Finally we can mark the inode as dirty. */