Skip to content

Commit aaf8c0b

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: reduce expensive checkpoint trigger frequency
We may trigger high frequent checkpoint for below case: 1. mkdir /mnt/dir1; set dir1 encrypted 2. touch /mnt/file1; fsync /mnt/file1 3. mkdir /mnt/dir2; set dir2 encrypted 4. touch /mnt/file2; fsync /mnt/file2 ... Although, newly created dir and file are not related, due to commit bbf156f ("f2fs: fix lost xattrs of directories"), we will trigger checkpoint whenever fsync() comes after a new encrypted dir created. In order to avoid such performance regression issue, let's record an entry including directory's ino in global cache whenever we update directory's xattr data, and then triggerring checkpoint() only if xattr metadata of target file's parent was updated. This patch updates to cover below no encryption case as well: 1) parent is checkpointed 2) set_xattr(dir) w/ new xnid 3) create(file) 4) fsync(file) Fixes: bbf156f ("f2fs: fix lost xattrs of directories") Reported-by: wangzijie <[email protected]> Reported-by: Zhiguo Niu <[email protected]> Tested-by: Zhiguo Niu <[email protected]> Reported-by: Yunlei He <[email protected]> Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 1a0bd28 commit aaf8c0b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

fs/f2fs/f2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ enum {
291291
APPEND_INO, /* for append ino list */
292292
UPDATE_INO, /* for update ino list */
293293
TRANS_DIR_INO, /* for transactions dir ino list */
294+
XATTR_DIR_INO, /* for xattr updated dir ino list */
294295
FLUSH_INO, /* for multiple device flushing */
295296
MAX_INO_ENTRY, /* max. list */
296297
};
@@ -1161,6 +1162,7 @@ enum cp_reason_type {
11611162
CP_FASTBOOT_MODE,
11621163
CP_SPEC_LOG_NUM,
11631164
CP_RECOVER_DIR,
1165+
CP_XATTR_DIR,
11641166
};
11651167

11661168
enum iostat_type {

fs/f2fs/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
218218
f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino,
219219
TRANS_DIR_INO))
220220
cp_reason = CP_RECOVER_DIR;
221+
else if (f2fs_exist_written_data(sbi, F2FS_I(inode)->i_pino,
222+
XATTR_DIR_INO))
223+
cp_reason = CP_XATTR_DIR;
221224

222225
return cp_reason;
223226
}

fs/f2fs/xattr.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ static int __f2fs_setxattr(struct inode *inode, int index,
629629
const char *name, const void *value, size_t size,
630630
struct page *ipage, int flags)
631631
{
632+
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
632633
struct f2fs_xattr_entry *here, *last;
633634
void *base_addr, *last_base_addr;
634635
int found, newsize;
@@ -772,9 +773,18 @@ static int __f2fs_setxattr(struct inode *inode, int index,
772773
if (index == F2FS_XATTR_INDEX_ENCRYPTION &&
773774
!strcmp(name, F2FS_XATTR_NAME_ENCRYPTION_CONTEXT))
774775
f2fs_set_encrypted_inode(inode);
775-
if (S_ISDIR(inode->i_mode))
776-
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_CP);
777776

777+
if (!S_ISDIR(inode->i_mode))
778+
goto same;
779+
/*
780+
* In restrict mode, fsync() always try to trigger checkpoint for all
781+
* metadata consistency, in other mode, it triggers checkpoint when
782+
* parent's xattr metadata was updated.
783+
*/
784+
if (F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
785+
set_sbi_flag(sbi, SBI_NEED_CP);
786+
else
787+
f2fs_add_ino_entry(sbi, inode->i_ino, XATTR_DIR_INO);
778788
same:
779789
if (is_inode_flag_set(inode, FI_ACL_MODE)) {
780790
inode->i_mode = F2FS_I(inode)->i_acl_mode;

include/trace/events/f2fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ TRACE_DEFINE_ENUM(EX_BLOCK_AGE);
139139
{ CP_NODE_NEED_CP, "node needs cp" }, \
140140
{ CP_FASTBOOT_MODE, "fastboot mode" }, \
141141
{ CP_SPEC_LOG_NUM, "log type is 2" }, \
142-
{ CP_RECOVER_DIR, "dir needs recovery" })
142+
{ CP_RECOVER_DIR, "dir needs recovery" }, \
143+
{ CP_XATTR_DIR, "dir's xattr updated" })
143144

144145
#define show_shutdown_mode(type) \
145146
__print_symbolic(type, \

0 commit comments

Comments
 (0)