Skip to contentSkip to conversation

f2fs: introduce sysfs readdir_ra to readahead inode block in readdir

RFC PATCH In review Sheng Yong 3 participants 8 messages Nov 22, 2017 – Jan 2, 2018 F2FS file system

lore
Share & tools
lore

Sheng Yong

author
#0 lore raw

RFC PATCH 1/3 f2fs: introduce sysfs readdir_ra to readahead inode block in readdir

This patch introduces a sysfs interface readdir_ra to enable/disable readaheading inode block in f2fs_readdir. When readdir_ra is enabled, it improves the performance of "readdir + stat".

For 300,000 files:
time find /data/test > /dev/null
disable readdir_ra: 1m25.69s real 0m01.94s user 0m50.80s system enable readdir_ra: 0m18.55s real 0m00.44s user 0m15.39s system

---
 Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
 fs/f2fs/dir.c                           | 4 ++++
 fs/f2fs/f2fs.h                          | 1 +
 fs/f2fs/sysfs.c                         | 2 ++
 4 files changed, 13 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index a7799c2fca28..d870b5514d15 100644
@@ -186,3 +186,9 @@ Date:		August 2017
 Contact:	"Jaegeuk Kim" <[email protected]>
 Description:
 		 Controls sleep time of GC urgent mode
+
+What:		/sys/fs/f2fs/<disk>/readdir_ra
+Date:		November 2017
+Contact:	"Sheng Yong" <[email protected]>
+Description:
+		 Controls readahead inode block in readdir.
fs/f2fs/dir.c +4 -0
index 2d98d877c09d..724304dc6143 100644
@@ -798,6 +798,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 	unsigned int bit_pos;
 	struct f2fs_dir_entry *de = NULL;
 	struct fscrypt_str de_name = FSTR_INIT(NULL, 0);
+	struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode);
 
 	bit_pos = ((unsigned long)ctx->pos % d->max);
 
@@ -836,6 +837,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 					le32_to_cpu(de->ino), d_type))
 			return 1;
 
+		if (sbi->readdir_ra == 1)
+			ra_node_page(sbi, le32_to_cpu(de->ino));
+
 		bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
 		ctx->pos = start_pos + bit_pos;
 	}
fs/f2fs/f2fs.h +1 -0
index ca6b0c9bc621..a269d795ba7c 100644
@@ -1095,6 +1095,7 @@ struct f2fs_sb_info {
 	int dir_level;				/* directory level */
 	int inline_xattr_size;			/* inline xattr size */
 	unsigned int trigger_ssr_threshold;	/* threshold to trigger ssr */
+	int readdir_ra;				/* readahead inode in readdir */
 
 	block_t user_block_count;		/* # of user blocks */
 	block_t total_valid_block_count;	/* # of valid blocks */
fs/f2fs/sysfs.c +2 -0
index 9835348b6e5d..93c3364250dd 100644
@@ -299,6 +299,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
@@ -346,6 +347,7 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(cp_interval),
 	ATTR_LIST(idle_interval),
 	ATTR_LIST(iostat_enable),
+	ATTR_LIST(readdir_ra),
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 	ATTR_LIST(inject_rate),
 	ATTR_LIST(inject_type),
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
author
#1 lore raw

PATCH 2/3 f2fs: still write data if preallocate only partial blocks

If there is not enough space left, f2fs_preallocate_blocks may only preallocte partial blocks. As a result, the write operation fails but i_blocks is not 0. To avoid this, f2fs should write data in non-preallocation way and write as many data as the size of i_blocks.

---
 fs/f2fs/data.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/data.c +8 -2
index b0781edc9ada..e593df628158 100644
@@ -862,8 +862,14 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
 		if (err)
 			return err;
 	}
-	if (!f2fs_has_inline_data(inode))
-		return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+	if (!f2fs_has_inline_data(inode)) {
+		err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+		if (map.m_len > 0 && err == -ENOSPC) {
+			set_inode_flag(inode, FI_NO_PREALLOC);
+			err = 0;
+		}
+		return err;
+	}
 	return err;
 }
 
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] f2fs: still write data if preallocate only partial blocks

Quoted 6 lines · Sheng Yong

If there is not enough space left, f2fs_preallocate_blocks may only preallocte partial blocks. As a result, the write operation fails but i_blocks is not 0. To avoid this, f2fs should write data in non-preallocation way and write as many data as the size of i_blocks.

Thanks,

Quoted 16 lines
---
 fs/f2fs/data.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/data.c +1 -2
index b0781edc9ada..e593df628158 100644
@@ -862,8 +862,14 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
 		if (err)
 			return err;
 	}
-	if (!f2fs_has_inline_data(inode))
-		return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+	if (!f2fs_has_inline_data(inode)) {

fs/f2fs/data.c int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) · line 875

Quoted 10 lines
fs/f2fs/data.c +7 -0
+		err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+		if (map.m_len > 0 && err == -ENOSPC) {
+			set_inode_flag(inode, FI_NO_PREALLOC);
+			err = 0;
+		}
+		return err;
+	}
 	return err;
 }
 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author
#3 lore raw

PATCH 3/3 f2fs: remove unused parameter

In reply to Sheng Yong

Commit d260081ccf37 ("f2fs: change recovery policy of xattr node block") removes the use of blkaddr, which is no longer used. So remove the parameter.

---
 fs/f2fs/f2fs.h     | 3 +--
 fs/f2fs/node.c     | 2 +-
 fs/f2fs/recovery.c | 6 +++---
 3 files changed, 5 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +1 -2
index a269d795ba7c..bab4c2287090 100644
@@ -2607,8 +2607,7 @@ void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
 void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
 int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
 void recover_inline_xattr(struct inode *inode, struct page *page);
-int recover_xattr_data(struct inode *inode, struct page *page,
-			block_t blkaddr);
+int recover_xattr_data(struct inode *inode, struct page *page);
 int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum);
fs/f2fs/node.c +1 -1
index fe1fc662af2a..ebb0d1797431 100644
@@ -2238,7 +2238,7 @@ void recover_inline_xattr(struct inode *inode, struct page *page)
 	f2fs_put_page(ipage, 1);
 }
 
-int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr)
+int recover_xattr_data(struct inode *inode, struct page *page)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid;
fs/f2fs/recovery.c +3 -3
index 92c57ace1939..7d63faf51e52 100644
@@ -404,7 +404,7 @@ static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
 }
 
 static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
-					struct page *page, block_t blkaddr)
+					struct page *page)
 {
 	struct dnode_of_data dn;
 	struct node_info ni;
@@ -415,7 +415,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 	if (IS_INODE(page)) {
 		recover_inline_xattr(inode, page);
 	} else if (f2fs_has_xattr_block(ofs_of_node(page))) {
-		err = recover_xattr_data(inode, page, blkaddr);
+		err = recover_xattr_data(inode, page);
 		if (!err)
 			recovered++;
 		goto out;
@@ -568,7 +568,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
 				break;
 			}
 		}
-		err = do_recover_data(sbi, entry->inode, page, blkaddr);
+		err = do_recover_data(sbi, entry->inode, page);
 		if (err) {
 			f2fs_put_page(page, 1);
 			break;
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer Reviewed-by on v1 3/3
#4 lore raw

Re: [PATCH 3/3] f2fs: remove unused parameter

Quoted 5 lines · Sheng Yong

Commit d260081ccf37 ("f2fs: change recovery policy of xattr node block") removes the use of blkaddr, which is no longer used. So remove the parameter.

Thanks,

Quoted 57 lines
---
 fs/f2fs/f2fs.h     | 3 +--
 fs/f2fs/node.c     | 2 +-
 fs/f2fs/recovery.c | 6 +++---
 3 files changed, 5 insertions(+), 6 deletions(-)
fs/f2fs/f2fs.h +1 -2
index a269d795ba7c..bab4c2287090 100644
@@ -2607,8 +2607,7 @@ void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
 void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
 int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
 void recover_inline_xattr(struct inode *inode, struct page *page);
-int recover_xattr_data(struct inode *inode, struct page *page,
-			block_t blkaddr);
+int recover_xattr_data(struct inode *inode, struct page *page);
 int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
 int restore_node_summary(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_summary_block *sum);
fs/f2fs/node.c +1 -1
index fe1fc662af2a..ebb0d1797431 100644
@@ -2238,7 +2238,7 @@ void recover_inline_xattr(struct inode *inode, struct page *page)
 	f2fs_put_page(ipage, 1);
 }
 
-int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr)
+int recover_xattr_data(struct inode *inode, struct page *page)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid;
fs/f2fs/recovery.c +2 -2
index 92c57ace1939..7d63faf51e52 100644
@@ -404,7 +404,7 @@ static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
 }
 
 static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
-					struct page *page, block_t blkaddr)
+					struct page *page)
 {
 	struct dnode_of_data dn;
 	struct node_info ni;
@@ -415,7 +415,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
 	if (IS_INODE(page)) {
 		recover_inline_xattr(inode, page);
 	} else if (f2fs_has_xattr_block(ofs_of_node(page))) {
-		err = recover_xattr_data(inode, page, blkaddr);
+		err = recover_xattr_data(inode, page);
 		if (!err)
 			recovered++;
 		goto out;

fs/f2fs/recovery.c static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list, · line 574

Quoted 8 lines
fs/f2fs/recovery.c +1 -1
@@ -568,7 +568,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list,
 				break;
 			}
 		}
-		err = do_recover_data(sbi, entry->inode, page, blkaddr);
+		err = do_recover_data(sbi, entry->inode, page);
 		if (err) {
 			f2fs_put_page(page, 1);
 			break;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

maintainer Reviewed-by on v1 1/3
#5 lore raw
In reply to Sheng Yong
Quoted 10 lines · Sheng Yong

This patch introduces a sysfs interface readdir_ra to enable/disable readaheading inode block in f2fs_readdir. When readdir_ra is enabled, it improves the performance of "readdir + stat".

For 300,000 files:
time find /data/test > /dev/null
disable readdir_ra: 1m25.69s real 0m01.94s user 0m50.80s system enable readdir_ra: 0m18.55s real 0m00.44s user 0m15.39s system

Thanks,

Quoted 69 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
 fs/f2fs/dir.c                           | 4 ++++
 fs/f2fs/f2fs.h                          | 1 +
 fs/f2fs/sysfs.c                         | 2 ++
 4 files changed, 13 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index a7799c2fca28..d870b5514d15 100644
@@ -186,3 +186,9 @@ Date:		August 2017
 Contact:	"Jaegeuk Kim" <[email protected]>
 Description:
 		 Controls sleep time of GC urgent mode
+
+What:		/sys/fs/f2fs/<disk>/readdir_ra
+Date:		November 2017
+Contact:	"Sheng Yong" <[email protected]>
+Description:
+		 Controls readahead inode block in readdir.
fs/f2fs/dir.c +4 -0
index 2d98d877c09d..724304dc6143 100644
@@ -798,6 +798,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 	unsigned int bit_pos;
 	struct f2fs_dir_entry *de = NULL;
 	struct fscrypt_str de_name = FSTR_INIT(NULL, 0);
+	struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode);
 
 	bit_pos = ((unsigned long)ctx->pos % d->max);
 
@@ -836,6 +837,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
 					le32_to_cpu(de->ino), d_type))
 			return 1;
 
+		if (sbi->readdir_ra == 1)
+			ra_node_page(sbi, le32_to_cpu(de->ino));
+
 		bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
 		ctx->pos = start_pos + bit_pos;
 	}
fs/f2fs/f2fs.h +1 -0
index ca6b0c9bc621..a269d795ba7c 100644
@@ -1095,6 +1095,7 @@ struct f2fs_sb_info {
 	int dir_level;				/* directory level */
 	int inline_xattr_size;			/* inline xattr size */
 	unsigned int trigger_ssr_threshold;	/* threshold to trigger ssr */
+	int readdir_ra;				/* readahead inode in readdir */
 
 	block_t user_block_count;		/* # of user blocks */
 	block_t total_valid_block_count;	/* # of valid blocks */
fs/f2fs/sysfs.c +1 -0
index 9835348b6e5d..93c3364250dd 100644
@@ -299,6 +299,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 353

Quoted 7 lines
fs/f2fs/sysfs.c +1 -0
@@ -346,6 +347,7 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(cp_interval),
 	ATTR_LIST(idle_interval),
 	ATTR_LIST(iostat_enable),
+	ATTR_LIST(readdir_ra),
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 	ATTR_LIST(inject_rate),
 	ATTR_LIST(inject_type),

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#6 lore raw

May I ask why is this disabled by default?

Quoted 93 lines · Chao Yu
Quoted 10 lines · Sheng Yong

This patch introduces a sysfs interface readdir_ra to enable/disable readaheading inode block in f2fs_readdir. When readdir_ra is enabled, it improves the performance of "readdir + stat".

For 300,000 files:
time find /data/test > /dev/null
disable readdir_ra: 1m25.69s real 0m01.94s user 0m50.80s system enable readdir_ra: 0m18.55s real 0m00.44s user 0m15.39s system

Thanks,

Quoted 69 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
 fs/f2fs/dir.c                           | 4 ++++
 fs/f2fs/f2fs.h                          | 1 +
 fs/f2fs/sysfs.c                         | 2 ++
 4 files changed, 13 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index a7799c2fca28..d870b5514d15 100644
@@ -186,3 +186,9 @@ Date:             August 2017
 Contact:     "Jaegeuk Kim" <[email protected]>
 Description:
               Controls sleep time of GC urgent mode
+
+What:                /sys/fs/f2fs/<disk>/readdir_ra
+Date:                November 2017
+Contact:     "Sheng Yong" <[email protected]>
+Description:
+              Controls readahead inode block in readdir.
fs/f2fs/dir.c +4 -0
index 2d98d877c09d..724304dc6143 100644
@@ -798,6 +798,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
      unsigned int bit_pos;
      struct f2fs_dir_entry *de = NULL;
      struct fscrypt_str de_name = FSTR_INIT(NULL, 0);
+     struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode);
 
      bit_pos = ((unsigned long)ctx->pos % d->max);
 
@@ -836,6 +837,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                                      le32_to_cpu(de->ino), d_type))
                      return 1;
 
+             if (sbi->readdir_ra == 1)
+                     ra_node_page(sbi, le32_to_cpu(de->ino));
+
              bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
              ctx->pos = start_pos + bit_pos;
      }
fs/f2fs/f2fs.h +1 -0
index ca6b0c9bc621..a269d795ba7c 100644
@@ -1095,6 +1095,7 @@ struct f2fs_sb_info {
      int dir_level;                          /* directory level */
      int inline_xattr_size;                  /* inline xattr size */
      unsigned int trigger_ssr_threshold;     /* threshold to trigger ssr */
+     int readdir_ra;                         /* readahead inode in readdir */
 
      block_t user_block_count;               /* # of user blocks */
      block_t total_valid_block_count;        /* # of valid blocks */
fs/f2fs/sysfs.c +1 -0
index 9835348b6e5d..93c3364250dd 100644
@@ -299,6 +299,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
 F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 353

Quoted 7 lines
fs/f2fs/sysfs.c +1 -0
@@ -346,6 +347,7 @@ static struct attribute *f2fs_attrs[] = {
      ATTR_LIST(cp_interval),
      ATTR_LIST(idle_interval),
      ATTR_LIST(iostat_enable),
+     ATTR_LIST(readdir_ra),
 #ifdef CONFIG_F2FS_FAULT_INJECTION
      ATTR_LIST(inject_rate),
      ATTR_LIST(inject_type),
Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author
#7 lore raw

Hi, Ju Hyung

Quoted 1 line · Ju Hyung Park

May I ask why is this disabled by default?

Since the readahead only improves "readdir + stat" scenario, and it will cause overhead if we only call a readdir, we don't know how user lookup files. So I think it's better to provide an option for user to decide if the readahead is needed.

thanks,
Sheng

Quoted 103 lines · Chao Yu
Quoted 93 lines · Sheng Yong
Quoted 10 lines

This patch introduces a sysfs interface readdir_ra to enable/disable readaheading inode block in f2fs_readdir. When readdir_ra is enabled, it improves the performance of "readdir + stat".

For 300,000 files:
time find /data/test > /dev/null
disable readdir_ra: 1m25.69s real 0m01.94s user 0m50.80s system enable readdir_ra: 0m18.55s real 0m00.44s user 0m15.39s system

Thanks,

Quoted 69 lines
---
  Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
  fs/f2fs/dir.c                           | 4 ++++
  fs/f2fs/f2fs.h                          | 1 +
  fs/f2fs/sysfs.c                         | 2 ++
  4 files changed, 13 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index a7799c2fca28..d870b5514d15 100644
@@ -186,3 +186,9 @@ Date:             August 2017
  Contact:     "Jaegeuk Kim" <[email protected]>
  Description:
                Controls sleep time of GC urgent mode
+
+What:                /sys/fs/f2fs/<disk>/readdir_ra
+Date:                November 2017
+Contact:     "Sheng Yong" <[email protected]>
+Description:
+              Controls readahead inode block in readdir.
fs/f2fs/dir.c +4 -0
index 2d98d877c09d..724304dc6143 100644
@@ -798,6 +798,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
       unsigned int bit_pos;
       struct f2fs_dir_entry *de = NULL;
       struct fscrypt_str de_name = FSTR_INIT(NULL, 0);
+     struct f2fs_sb_info *sbi = F2FS_I_SB(d->inode);
 
       bit_pos = ((unsigned long)ctx->pos % d->max);
 
@@ -836,6 +837,9 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                                       le32_to_cpu(de->ino), d_type))
                       return 1;
 
+             if (sbi->readdir_ra == 1)
+                     ra_node_page(sbi, le32_to_cpu(de->ino));
+
               bit_pos += GET_DENTRY_SLOTS(le16_to_cpu(de->name_len));
               ctx->pos = start_pos + bit_pos;
       }
fs/f2fs/f2fs.h +1 -0
index ca6b0c9bc621..a269d795ba7c 100644
@@ -1095,6 +1095,7 @@ struct f2fs_sb_info {
       int dir_level;                          /* directory level */
       int inline_xattr_size;                  /* inline xattr size */
       unsigned int trigger_ssr_threshold;     /* threshold to trigger ssr */
+     int readdir_ra;                         /* readahead inode in readdir */
 
       block_t user_block_count;               /* # of user blocks */
       block_t total_valid_block_count;        /* # of valid blocks */
fs/f2fs/sysfs.c +1 -0
index 9835348b6e5d..93c3364250dd 100644
@@ -299,6 +299,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
  F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, iostat_enable, iostat_enable);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, readdir_ra, readdir_ra);
  #ifdef CONFIG_F2FS_FAULT_INJECTION
  F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
  F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);

fs/f2fs/sysfs.c static struct attribute *f2fs_attrs[] = { · line 353

Quoted 7 lines
fs/f2fs/sysfs.c +1 -0
@@ -346,6 +347,7 @@ static struct attribute *f2fs_attrs[] = {
       ATTR_LIST(cp_interval),
       ATTR_LIST(idle_interval),
       ATTR_LIST(iostat_enable),
+     ATTR_LIST(readdir_ra),
  #ifdef CONFIG_F2FS_FAULT_INJECTION
       ATTR_LIST(inject_rate),
       ATTR_LIST(inject_type),
Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot