linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] exfat: speed up iterate/lookup by fixing start point of traversing cluster chain
@ 2021-03-22  3:53 ` Hyeongseok Kim
  2021-03-22  5:52   ` Sungjong Seo
  0 siblings, 1 reply; 3+ messages in thread
From: Hyeongseok Kim @ 2021-03-22  3:53 UTC (permalink / raw)
  To: namjae.jeon, sj1557.seo, linux-kernel, linux-fsdevel; +Cc: Hyeongseok Kim

When directory iterate and lookup is called, there's a buggy rewinding
of start point for traversing cluster chain to the parent directory
entry's first cluster. This caused repeated cluster chain traversing
from the first entry of the parent directory that would show worse
performance if huge amounts of files exist under the parent directory.
Fix not to rewind, make continue from currently referenced cluster and
dir entry.

Tested with 50,000 files under single directory / 256GB sdcard,
with command "time ls -l > /dev/null",
Before :     0m08.69s real     0m00.27s user     0m05.91s system
After  :     0m07.01s real     0m00.25s user     0m04.34s system

Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>
---
 fs/exfat/dir.c      | 19 +++++++++++++------
 fs/exfat/exfat_fs.h |  2 +-
 fs/exfat/namei.c    |  9 ++++++++-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 7efb1c6d4808..c4523648472a 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -147,7 +147,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
 					0);
 
 			*uni_name.name = 0x0;
-			exfat_get_uniname_from_ext_entry(sb, &dir, dentry,
+			exfat_get_uniname_from_ext_entry(sb, &clu, i,
 				uni_name.name);
 			exfat_utf16_to_nls(sb, &uni_name,
 				dir_entry->namebuf.lfn,
@@ -911,14 +911,19 @@ enum {
 };
 
 /*
- * return values:
- *   >= 0	: return dir entiry position with the name in dir
- *   -ENOENT	: entry with the name does not exist
- *   -EIO	: I/O error
+ * @ei:         inode info of parent directory
+ * @p_dir:      directory structure of parent directory
+ * @num_entries:entry size of p_uniname
+ * @hint_opt:   If p_uniname is found, filled with optimized dir/entry
+ *              for traversing cluster chain.
+ * @return:
+ *   >= 0:      file directory entry position where the name exists
+ *   -ENOENT:   entry with the name does not exist
+ *   -EIO:      I/O error
  */
 int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 		struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
-		int num_entries, unsigned int type)
+		int num_entries, unsigned int type, struct exfat_hint *hint_opt)
 {
 	int i, rewind = 0, dentry = 0, end_eidx = 0, num_ext = 0, len;
 	int order, step, name_len = 0;
@@ -995,6 +1000,8 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 
 			if (entry_type == TYPE_FILE || entry_type == TYPE_DIR) {
 				step = DIRENT_STEP_FILE;
+				hint_opt->clu = clu.dir;
+				hint_opt->eidx = i;
 				if (type == TYPE_ALL || type == entry_type) {
 					num_ext = ep->dentry.file.num_ext;
 					step = DIRENT_STEP_STRM;
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index e77fe2f45cf2..1d6da61157c9 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -457,7 +457,7 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es);
 int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
 int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
 		struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
-		int num_entries, unsigned int type);
+		int num_entries, unsigned int type, struct exfat_hint *hint_opt);
 int exfat_alloc_new_dir(struct inode *inode, struct exfat_chain *clu);
 int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
 		int entry, sector_t *sector, int *offset);
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 1f7b3dc66fcd..24b41103d1cc 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -596,6 +596,8 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
 	struct exfat_inode_info *ei = EXFAT_I(dir);
 	struct exfat_dentry *ep, *ep2;
 	struct exfat_entry_set_cache *es;
+	/* for optimized dir & entry to prevent long traverse of cluster chain */
+	struct exfat_hint hint_opt;
 
 	if (qname->len == 0)
 		return -ENOENT;
@@ -619,7 +621,7 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
 
 	/* search the file name for directories */
 	dentry = exfat_find_dir_entry(sb, ei, &cdir, &uni_name,
-			num_entries, TYPE_ALL);
+			num_entries, TYPE_ALL, &hint_opt);
 
 	if (dentry < 0)
 		return dentry; /* -error value */
@@ -628,6 +630,11 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
 	info->entry = dentry;
 	info->num_subdirs = 0;
 
+	/* adjust cdir to the optimized value */
+	cdir.dir = hint_opt.clu;
+	if (cdir.flags & ALLOC_NO_FAT_CHAIN)
+		cdir.size -= dentry / sbi->dentries_per_clu;
+	dentry = hint_opt.eidx;
 	es = exfat_get_dentry_set(sb, &cdir, dentry, ES_2_ENTRIES);
 	if (!es)
 		return -EIO;
-- 
2.27.0.83.g0313f36


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH v3] exfat: speed up iterate/lookup by fixing start point of traversing cluster chain
  2021-03-22  3:53 ` [PATCH v3] exfat: speed up iterate/lookup by fixing start point of traversing cluster chain Hyeongseok Kim
@ 2021-03-22  5:52   ` Sungjong Seo
  2021-03-23  8:26     ` Namjae Jeon
  0 siblings, 1 reply; 3+ messages in thread
From: Sungjong Seo @ 2021-03-22  5:52 UTC (permalink / raw)
  To: 'Hyeongseok Kim', namjae.jeon, linux-kernel, linux-fsdevel
  Cc: sj1557.seo

> When directory iterate and lookup is called, there's a buggy rewinding of
> start point for traversing cluster chain to the parent directory entry's
> first cluster. This caused repeated cluster chain traversing from the
> first entry of the parent directory that would show worse performance if
> huge amounts of files exist under the parent directory.
> Fix not to rewind, make continue from currently referenced cluster and dir
> entry.
> 
> Tested with 50,000 files under single directory / 256GB sdcard, with
> command "time ls -l > /dev/null",
> Before :     0m08.69s real     0m00.27s user     0m05.91s system
> After  :     0m07.01s real     0m00.25s user     0m04.34s system
> 
> Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>

Looks good.
Thanks for your contribution.

Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>

> ---
>  fs/exfat/dir.c      | 19 +++++++++++++------
>  fs/exfat/exfat_fs.h |  2 +-
>  fs/exfat/namei.c    |  9 ++++++++-
>  3 files changed, 22 insertions(+), 8 deletions(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH v3] exfat: speed up iterate/lookup by fixing start point of traversing cluster chain
  2021-03-22  5:52   ` Sungjong Seo
@ 2021-03-23  8:26     ` Namjae Jeon
  0 siblings, 0 replies; 3+ messages in thread
From: Namjae Jeon @ 2021-03-23  8:26 UTC (permalink / raw)
  To: 'Sungjong Seo', 'Hyeongseok Kim'
  Cc: linux-kernel, linux-fsdevel

> > When directory iterate and lookup is called, there's a buggy rewinding
> > of start point for traversing cluster chain to the parent directory
> > entry's first cluster. This caused repeated cluster chain traversing
> > from the first entry of the parent directory that would show worse
> > performance if huge amounts of files exist under the parent directory.
> > Fix not to rewind, make continue from currently referenced cluster and
> > dir entry.
> >
> > Tested with 50,000 files under single directory / 256GB sdcard, with
> > command "time ls -l > /dev/null",
> > Before :     0m08.69s real     0m00.27s user     0m05.91s system
> > After  :     0m07.01s real     0m00.25s user     0m04.34s system
> >
> > Signed-off-by: Hyeongseok Kim <hyeongseok@gmail.com>
> 
> Looks good.
> Thanks for your contribution.
> 
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Applied. Thanks!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-23  8:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210322035356epcas1p35cf4d476030f5ebaf6357c5761355605@epcas1p3.samsung.com>
2021-03-22  3:53 ` [PATCH v3] exfat: speed up iterate/lookup by fixing start point of traversing cluster chain Hyeongseok Kim
2021-03-22  5:52   ` Sungjong Seo
2021-03-23  8:26     ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).