f2fs: refactor flush_nat_entries codes for reducing NAT writes
Subsystems (2)
PATCH v2 1/1 f2fs: refactor flush_nat_entries codes for reducing NAT writes
Although building NAT journal in cursum reduce the read/write work for NAT block, but previous design leave us lower performance when write checkpoint frequently for these cases:
1. if journal in cursum has already full, it's a bit of waste that we flush all nat entries to page for persistence, but not to cache any entries.
2. if journal in cursum is not full, we fill nat entries to journal util journal is full, then flush the left dirty entries to disk without merge journaled entries, so these journaled entries may be flushed to disk at next checkpoint but lost chance to flushed last time.
In this patch we merge dirty entries located in same NAT block to nat entry set, and linked all set to list, sorted ascending order by entries' count of set. Later we flush entries in sparse set into journal as many as we can, and then flush merged entries to disk.
In my testing environment, it shows this patch can help to reduce NAT block writes.
1. virtual machine + hard disk:
fsstress -p 20 -n 200 -l 5
node num cp count nodes/cp
based 4599.6 1803.0 2.551
patched 2714.6 1829.6 1.483
2. virtual machine + 32g micro SD card:
fsstress -p 20 -n 200 -l 1 -w -f chown=0 -f creat=4 -f dwrite=0 -f fdatasync=4 -f fsync=4 -f link=0 -f mkdir=4 -f mknod=4 -f rename=5 -f rmdir=5 -f symlink=0 -f truncate=4 -f unlink=5 -f write=0 -S
node num cp count nodes/cp
based 84.5 43.7 1.933
patched 49.2 40.0 1.23
change log from v1:
o use list_for_each_entry_safe in add_nat_entry() to avoid potential deadloop.
--- fs/f2fs/f2fs.h | 4 + fs/f2fs/node.c | 254 +++++++++++++++++++++++++++++++++++++------------------ fs/f2fs/node.h | 7 ++ fs/f2fs/super.c | 8 +- 4 files changed, 192 insertions(+), 81 deletions(-)
fs/f2fs/f2fs.h +4 -0
@@ -256,6 +256,8 @@ struct f2fs_nm_info {unsigned int nat_cnt;/* the # of cached nat entries */ struct list_head nat_entries;/* cached nat entry list (clean) */ struct list_head dirty_nat_entries;/* cached nat entry list (dirty) */ +struct list_head nat_entry_set;/* nat entry set list */ +unsigned int dirty_nat_cnt;/* total num of nat entries in set */ /* free node ids management */ struct radix_tree_root free_nid_root;/* root of the free_nid cache */
@@ -1194,6 +1196,8 @@ int build_node_manager(struct f2fs_sb_info *);void destroy_node_manager (struct f2fs_sb_info *);int __init create_node_manager_caches (void );void destroy_node_manager_caches (void ); +int __init create_nat_set_caches (void ); +void destroy_nat_set_caches (void );/* * segment.c
fs/f2fs/node.c +174 -80
323 lines not on this page · raw message
fs/f2fs/node.h +7 -0
@@ -89,6 +89,13 @@ enum mem_type { DIRTY_DENTS /* indicates dirty dentry pages */ }; +struct nat_entry_set { +struct list_head set_list;/* link with all nat sets */ +struct list_head entry_list;/* link with dirty nat entries */ +nid_t start_nid;/* start nid of nats in set */ +unsigned int entry_cnt;/* the # of nat entries in set */ +}; +/* * For free nid mangement */
fs/f2fs/super.c +7 -1
@@ -1172,10 +1172,13 @@ static int __init init_f2fs_fs(void) err =create_checkpoint_caches ();if (err) goto free_gc_caches; + err =create_nat_set_caches (); +if (err) + goto free_checkpoint_caches; f2fs_kset =kset_create_and_add ("f2fs" ,NULL , fs_kobj);if (!f2fs_kset) { err = -ENOMEM ; - goto free_checkpoint_caches; + goto free_nat_set_caches; } err =register_filesystem (&f2fs_fs_type);if (err)
@@ -1186,6 +1189,8 @@ static int __init init_f2fs_fs(void) free_kset:kset_unregister (f2fs_kset); +free_nat_set_caches: +destroy_nat_set_caches (); free_checkpoint_caches:destroy_checkpoint_caches (); free_gc_caches:
@@ -1205,6 +1210,7 @@ static void __exit exit_f2fs_fs(void)remove_proc_entry ("fs/f2fs" ,NULL );f2fs_destroy_root_stats ();unregister_filesystem (&f2fs_fs_type); +destroy_nat_set_caches ();destroy_checkpoint_caches ();destroy_gc_caches ();destroy_segment_manager_caches ();
Signature · 10 lines
1.7.9.5 ------------------------------------------------------------------------------ HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing & Easy Data Exploration http://p.sf.net/sfu/hpccsystems