f2fs: support data flush in checkpoint
PATCH 5/8 f2fs: support data flush in checkpoint
Previously, when finishing a checkpoint, we only keep consistency of all fs meta info including meta inode, node inode, dentry page of directory inode, so, after a sudden power cut, f2fs can recover from last checkpoint with full directory structure.
But during checkpoint, we didn't flush dirty pages of regular and symlink inode, so such dirty datas still in memory will be lost in that moment of power off.
In order to reduce the chance of lost data, this patch tries to flush user data before starting a checkpoint. So user's data written between two checkpoint which may not be fsynced could be saved.
--- fs/f2fs/checkpoint.c | 11 +++++++++++ fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 16 insertions(+)
fs/f2fs/checkpoint.c +11 -0
@@ -849,6 +849,17 @@ static int block_operations(struct f2fs_sb_info *sbi)blk_start_plug (&plug); +retry_flush_datas: +/* write all the dirty data pages */ +if (get_pages (sbi,F2FS_DIRTY_DATAS )) { +sync_dirty_inodes (sbi,FILE_INODE ); +if (unlikely (f2fs_cp_error (sbi))) { + err = -EIO ; + goto out; + } + goto retry_flush_datas; + } + retry_flush_dents:f2fs_lock_all (sbi);/* write all the dirty dentry pages */
fs/f2fs/f2fs.h +5 -0
@@ -648,6 +648,7 @@ struct f2fs_sm_info {enum count_type {F2FS_WRITEBACK ,F2FS_DIRTY_DENTS , +F2FS_DIRTY_DATAS ,F2FS_DIRTY_NODES ,F2FS_DIRTY_META ,F2FS_INMEM_PAGES ,
@@ -1068,6 +1069,8 @@ static inline void inode_inc_dirty_pages(struct inode *inode)atomic_inc (&F2FS_I (inode)->dirty_pages);if (S_ISDIR (inode->i_mode))inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS ); }static inline void dec_page_count (struct f2fs_sb_info *sbi,int count_type)
@@ -1085,6 +1088,8 @@ static inline void inode_dec_dirty_pages(struct inode *inode)if (S_ISDIR (inode->i_mode))dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS ); }static inline int get_pages (struct f2fs_sb_info *sbi,int count_type)
Signature · 1 line
2.6.3
Jaegeuk Kim
maintainerHi Chao,
Quoted 28 lines · Chao Yu
Previously, when finishing a checkpoint, we only keep consistency of all fs meta info including meta inode, node inode, dentry page of directory inode, so, after a sudden power cut, f2fs can recover from last checkpoint with full directory structure.
But during checkpoint, we didn't flush dirty pages of regular and symlink inode, so such dirty datas still in memory will be lost in that moment of power off.
In order to reduce the chance of lost data, this patch tries to flush user data before starting a checkpoint. So user's data written between two checkpoint which may not be fsynced could be saved.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/checkpoint.c | 11 +++++++++++ fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 16 insertions(+)fs/f2fs/checkpoint.c +1
-0@@ -849,6 +849,17 @@ static int block_operations(struct f2fs_sb_info *sbi)blk_start_plug (&plug); +retry_flush_datas:
fs/f2fs/checkpoint.c static int block_operations(struct f2fs_sb_info *sbi) · line 862
Quoted 10 lines
fs/f2fs/checkpoint.c +10
-0+/* write all the dirty data pages */ +if (get_pages (sbi,F2FS_DIRTY_DATAS )) { +sync_dirty_inodes (sbi,FILE_INODE ); +if (unlikely (f2fs_cp_error (sbi))) { + err = -EIO ; + goto out; + } + goto retry_flush_datas; + } +
Please don't do like this; our checkpoint should be different from system sync. I don't want to increase the checkpoint latency at all even in f2fs_gc as well.
I think that something like this would be better.
In f2fs_balance_fs_bg(),
if (!avaliable_free_memory() || ...) {
if (test_opt(DATA_FLUSH))
sync_dirty_inodes(FILE_INODE);
f2fs_sync_fs();
}Please add its mount option with a disabled one first.
fs/f2fs/f2fs.h struct f2fs_sm_info { · line 651
Quoted 12 lines
fs/f2fs/checkpoint.c +0
-0retry_flush_dents:f2fs_lock_all (sbi);/* write all the dirty dentry pages */ fs/f2fs/f2fs.h +1
-0@@ -648,6 +648,7 @@ struct f2fs_sm_info {enum count_type {F2FS_WRITEBACK ,F2FS_DIRTY_DENTS , +F2FS_DIRTY_DATAS ,
This should be F2FS_DIRTY_DATA.
And, it'd better to merge this part into your previous patch:
"f2fs: record dirty status of regular/symlink inodes"
I'll do that, so please check it out later from dev-test.
fs/f2fs/f2fs.h static inline void inode_inc_dirty_pages(struct inode *inode) · line 1073
Quoted 9 lines
fs/f2fs/f2fs.h +2
-0F2FS_DIRTY_NODES ,F2FS_DIRTY_META , F2FS_INMEM_PAGES,@@ -1068,6 +1069,8 @@ static inline void inode_inc_dirty_pages(struct inode *inode)atomic_inc (&F2FS_I (inode)->dirty_pages);if (S_ISDIR (inode->i_mode))inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS );
ditto.
fs/f2fs/f2fs.h static inline void inode_dec_dirty_pages(struct inode *inode) · line 1092
Quoted 9 lines
fs/f2fs/f2fs.h +2
-0}static inline void dec_page_count (struct f2fs_sb_info *sbi,int count_type)@@ -1085,6 +1088,8 @@ static inline void inode_dec_dirty_pages(struct inode *inode)if (S_ISDIR (inode->i_mode))dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS );
ditto.
Quoted 6 lines
fs/f2fs/f2fs.h +0
-0}static inline int get_pages (struct f2fs_sb_info *sbi,int count_type)Signature · 1 line
2.6.3
Hi Jaegeuk,
Quoted 37 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Wednesday, December 16, 2015 5:59 AM
To: Chao Yu
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 5/8] f2fs: support data flush in checkpointHi Chao,
Quoted 27 lines · Chao Yu
Previously, when finishing a checkpoint, we only keep consistency of all fs meta info including meta inode, node inode, dentry page of directory inode, so, after a sudden power cut, f2fs can recover from last checkpoint with full directory structure.
But during checkpoint, we didn't flush dirty pages of regular and symlink inode, so such dirty datas still in memory will be lost in that moment of power off.
In order to reduce the chance of lost data, this patch tries to flush user data before starting a checkpoint. So user's data written between two checkpoint which may not be fsynced could be saved.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/checkpoint.c | 11 +++++++++++ fs/f2fs/f2fs.h | 5 +++++ 2 files changed, 16 insertions(+)fs/f2fs/checkpoint.c +0
-0@@ -849,6 +849,17 @@ static int block_operations(struct f2fs_sb_info *sbi)blk_start_plug (&plug);
Quoted 14 lines
fs/f2fs/checkpoint.c static int block_operations(struct f2fs_sb_info *sbi) · line 862
Quoted 11 lines
fs/f2fs/checkpoint.c +11
-0+retry_flush_datas: +/* write all the dirty data pages */ +if (get_pages (sbi,F2FS_DIRTY_DATAS )) { +sync_dirty_inodes (sbi,FILE_INODE ); +if (unlikely (f2fs_cp_error (sbi))) { + err = -EIO ; + goto out; + } + goto retry_flush_datas; + } +Please don't do like this; our checkpoint should be different from system sync. I don't want to increase the checkpoint latency at all even in
f2fs_gcas well.
Alright.
Since flushing dirty data definitely increasing our latency of the interface, so what I thought was that let user take responsibility for risk of potential longer latency once user choose to mount with data_flush option.
Now, look into this implementation, it seems that adding flushing operation into checkpoint looks advancing rashly, it spreads random potential long latency everywhere.
Quoted 2 lines
I think that something like this would be better.
I will follow that currently. :)
Quoted 9 lines
In
f2fs_balance_fs_bg(),if (!avaliable_free_memory() || ...) { if (test_opt(DATA_FLUSH)) sync_dirty_inodes(FILE_INODE); f2fs_sync_fs(); }Please add its mount option with a disabled one first.
OK, I will do that.
Quoted 16 lines
fs/f2fs/f2fs.h struct f2fs_sm_info { · line 651
Quoted 13 lines
fs/f2fs/checkpoint.c +0
-0retry_flush_dents:f2fs_lock_all (sbi);/* write all the dirty dentry pages */ fs/f2fs/f2fs.h +1
-0@@ -648,6 +648,7 @@ struct f2fs_sm_info {enum count_type {F2FS_WRITEBACK ,F2FS_DIRTY_DENTS , +F2FS_DIRTY_DATAS ,This should be
F2FS_DIRTY_DATA.
Quoted 4 lines
And, it'd better to merge this part into your previous patch:
"f2fs: record dirty status of regular/symlink inodes"I'll do that, so please check it out later from dev-test.
Thanks for doing this, still I will resend the patches for the people who wants to comment on them.
Thanks,
Quoted 31 lines
fs/f2fs/f2fs.h static inline void inode_inc_dirty_pages(struct inode *inode) · line 1073
Quoted 10 lines
fs/f2fs/f2fs.h +2
-0F2FS_DIRTY_NODES ,F2FS_DIRTY_META , F2FS_INMEM_PAGES,@@ -1068,6 +1069,8 @@ static inline void inode_inc_dirty_pages(struct inode *inode)atomic_inc (&F2FS_I (inode)->dirty_pages);if (S_ISDIR (inode->i_mode))inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +inc_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS );ditto.
fs/f2fs/f2fs.h static inline void inode_dec_dirty_pages(struct inode *inode) · line 1092
Quoted 9 lines
fs/f2fs/f2fs.h +2
-0}static inline void dec_page_count (struct f2fs_sb_info *sbi,int count_type)@@ -1085,6 +1088,8 @@ static inline void inode_dec_dirty_pages(struct inode *inode)if (S_ISDIR (inode->i_mode))dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DENTS ); +else +dec_page_count (F2FS_I_SB (inode),F2FS_DIRTY_DATAS );ditto.
Quoted 6 lines
fs/f2fs/f2fs.h +0
-1}static inline int get_pages (struct f2fs_sb_info *sbi,int count_type) --2.6.3