* [PATCH] exfat: optimize allocation bitmap loading time
@ 2025-08-01 0:14 Namjae Jeon
2025-08-01 8:02 ` Yuezhang.Mo
0 siblings, 1 reply; 5+ messages in thread
From: Namjae Jeon @ 2025-08-01 0:14 UTC (permalink / raw)
To: sj1557.seo, Yuezhang.Mo; +Cc: linux-fsdevel, Namjae Jeon
Loading the allocation bitmap is very slow if user set the small cluster
size on large partition.
For optimizing it, This patch uses sb_breadahead() read the allocation
bitmap. It will improve the mount time.
The following is the result of about 4TB partition(2KB cluster size)
on my target.
without patch:
real 0m41.746s
user 0m0.011s
sys 0m0.000s
with patch:
real 0m2.525s
user 0m0.008s
sys 0m0.008s
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
fs/exfat/balloc.c | 12 +++++++++++-
fs/exfat/dir.c | 1 -
fs/exfat/exfat_fs.h | 1 +
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
index cc01556c9d9b..c40b73701941 100644
--- a/fs/exfat/balloc.c
+++ b/fs/exfat/balloc.c
@@ -30,9 +30,11 @@ static int exfat_allocate_bitmap(struct super_block *sb,
struct exfat_dentry *ep)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
+ struct blk_plug plug;
long long map_size;
- unsigned int i, need_map_size;
+ unsigned int i, j, need_map_size;
sector_t sector;
+ unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
sbi->map_clu = le32_to_cpu(ep->dentry.bitmap.start_clu);
map_size = le64_to_cpu(ep->dentry.bitmap.size);
@@ -57,6 +59,14 @@ static int exfat_allocate_bitmap(struct super_block *sb,
sector = exfat_cluster_to_sector(sbi, sbi->map_clu);
for (i = 0; i < sbi->map_sectors; i++) {
+ /* Trigger the next readahead in advance. */
+ if (0 == (i % max_ra_count)) {
+ blk_start_plug(&plug);
+ for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
+ sb_breadahead(sb, sector + j);
+ blk_finish_plug(&plug);
+ }
+
sbi->vol_amap[i] = sb_bread(sb, sector + i);
if (!sbi->vol_amap[i]) {
/* release all buffers and free vol_amap */
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index ee060e26f51d..e7a8550c0346 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -616,7 +616,6 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
return 0;
}
-#define EXFAT_MAX_RA_SIZE (128*1024)
static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index f8ead4d47ef0..d1792d5c9eed 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -13,6 +13,7 @@
#include <uapi/linux/exfat.h>
#define EXFAT_ROOT_INO 1
+#define EXFAT_MAX_RA_SIZE (128*1024)
/*
* exfat error flags
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] exfat: optimize allocation bitmap loading time
2025-08-01 0:14 [PATCH] exfat: optimize allocation bitmap loading time Namjae Jeon
@ 2025-08-01 8:02 ` Yuezhang.Mo
2025-08-03 23:04 ` Namjae Jeon
0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang.Mo @ 2025-08-01 8:02 UTC (permalink / raw)
To: Namjae Jeon, sj1557.seo@samsung.com; +Cc: linux-fsdevel@vger.kernel.org
> Loading the allocation bitmap is very slow if user set the small cluster
> size on large partition.
>
> For optimizing it, This patch uses sb_breadahead() read the allocation
> bitmap. It will improve the mount time.
>
> The following is the result of about 4TB partition(2KB cluster size)
> on my target.
>
> without patch:
> real 0m41.746s
> user 0m0.011s
> sys 0m0.000s
>
> with patch:
> real 0m2.525s
> user 0m0.008s
> sys 0m0.008s
>
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> ---
> fs/exfat/balloc.c | 12 +++++++++++-
> fs/exfat/dir.c | 1 -
> fs/exfat/exfat_fs.h | 1 +
> 3 files changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
> index cc01556c9d9b..c40b73701941 100644
> --- a/fs/exfat/balloc.c
> +++ b/fs/exfat/balloc.c
> @@ -30,9 +30,11 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> struct exfat_dentry *ep)
> {
> struct exfat_sb_info *sbi = EXFAT_SB(sb);
> + struct blk_plug plug;
> long long map_size;
> - unsigned int i, need_map_size;
> + unsigned int i, j, need_map_size;
> sector_t sector;
> + unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
>
> sbi->map_clu = le32_to_cpu(ep->dentry.bitmap.start_clu);
> map_size = le64_to_cpu(ep->dentry.bitmap.size);
> @@ -57,6 +59,14 @@ static int exfat_allocate_bitmap(struct super_block *sb,
>
> sector = exfat_cluster_to_sector(sbi, sbi->map_clu);
> for (i = 0; i < sbi->map_sectors; i++) {
> + /* Trigger the next readahead in advance. */
> + if (0 == (i % max_ra_count)) {
> + blk_start_plug(&plug);
> + for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
> + sb_breadahead(sb, sector + j);
> + blk_finish_plug(&plug);
> + }
> +
> sbi->vol_amap[i] = sb_bread(sb, sector + i);
> if (!sbi->vol_amap[i]) {
> /* release all buffers and free vol_amap */
> diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
> index ee060e26f51d..e7a8550c0346 100644
> --- a/fs/exfat/dir.c
> +++ b/fs/exfat/dir.c
> @@ -616,7 +616,6 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
> return 0;
> }
>
> -#define EXFAT_MAX_RA_SIZE (128*1024)
> static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
> {
> struct exfat_sb_info *sbi = EXFAT_SB(sb);
> diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> index f8ead4d47ef0..d1792d5c9eed 100644
> --- a/fs/exfat/exfat_fs.h
> +++ b/fs/exfat/exfat_fs.h
> @@ -13,6 +13,7 @@
> #include <uapi/linux/exfat.h>
>
> #define EXFAT_ROOT_INO 1
> +#define EXFAT_MAX_RA_SIZE (128*1024)
Why is the max readahead size 128KiB?
If the limit is changed to max_sectors_kb, so that a read request reads as much
data as possible, will the performance be better?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exfat: optimize allocation bitmap loading time
2025-08-01 8:02 ` Yuezhang.Mo
@ 2025-08-03 23:04 ` Namjae Jeon
2025-08-04 8:56 ` Yuezhang.Mo
0 siblings, 1 reply; 5+ messages in thread
From: Namjae Jeon @ 2025-08-03 23:04 UTC (permalink / raw)
To: Yuezhang.Mo@sony.com
Cc: sj1557.seo@samsung.com, linux-fsdevel@vger.kernel.org
On Fri, Aug 1, 2025 at 5:03 PM Yuezhang.Mo@sony.com
<Yuezhang.Mo@sony.com> wrote:
>
> > Loading the allocation bitmap is very slow if user set the small cluster
> > size on large partition.
> >
> > For optimizing it, This patch uses sb_breadahead() read the allocation
> > bitmap. It will improve the mount time.
> >
> > The following is the result of about 4TB partition(2KB cluster size)
> > on my target.
> >
> > without patch:
> > real 0m41.746s
> > user 0m0.011s
> > sys 0m0.000s
> >
> > with patch:
> > real 0m2.525s
> > user 0m0.008s
> > sys 0m0.008s
> >
> > Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> > Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> > ---
> > fs/exfat/balloc.c | 12 +++++++++++-
> > fs/exfat/dir.c | 1 -
> > fs/exfat/exfat_fs.h | 1 +
> > 3 files changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
> > index cc01556c9d9b..c40b73701941 100644
> > --- a/fs/exfat/balloc.c
> > +++ b/fs/exfat/balloc.c
> > @@ -30,9 +30,11 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> > struct exfat_dentry *ep)
> > {
> > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > + struct blk_plug plug;
> > long long map_size;
> > - unsigned int i, need_map_size;
> > + unsigned int i, j, need_map_size;
> > sector_t sector;
> > + unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
> >
> > sbi->map_clu = le32_to_cpu(ep->dentry.bitmap.start_clu);
> > map_size = le64_to_cpu(ep->dentry.bitmap.size);
> > @@ -57,6 +59,14 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> >
> > sector = exfat_cluster_to_sector(sbi, sbi->map_clu);
> > for (i = 0; i < sbi->map_sectors; i++) {
> > + /* Trigger the next readahead in advance. */
> > + if (0 == (i % max_ra_count)) {
> > + blk_start_plug(&plug);
> > + for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
> > + sb_breadahead(sb, sector + j);
> > + blk_finish_plug(&plug);
> > + }
> > +
> > sbi->vol_amap[i] = sb_bread(sb, sector + i);
> > if (!sbi->vol_amap[i]) {
> > /* release all buffers and free vol_amap */
> > diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
> > index ee060e26f51d..e7a8550c0346 100644
> > --- a/fs/exfat/dir.c
> > +++ b/fs/exfat/dir.c
> > @@ -616,7 +616,6 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
> > return 0;
> > }
> >
> > -#define EXFAT_MAX_RA_SIZE (128*1024)
> > static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
> > {
> > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> > index f8ead4d47ef0..d1792d5c9eed 100644
> > --- a/fs/exfat/exfat_fs.h
> > +++ b/fs/exfat/exfat_fs.h
> > @@ -13,6 +13,7 @@
> > #include <uapi/linux/exfat.h>
> >
> > #define EXFAT_ROOT_INO 1
> > +#define EXFAT_MAX_RA_SIZE (128*1024)
>
> Why is the max readahead size 128KiB?
> If the limit is changed to max_sectors_kb, so that a read request reads as much
> data as possible, will the performance be better?
This sets an appropriate readahead size for exfat. It's already used
elsewhere in exfat.
Getting ->max_sectors_kb from the block layer will result in a layer violation.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exfat: optimize allocation bitmap loading time
2025-08-03 23:04 ` Namjae Jeon
@ 2025-08-04 8:56 ` Yuezhang.Mo
2025-08-05 1:06 ` Namjae Jeon
0 siblings, 1 reply; 5+ messages in thread
From: Yuezhang.Mo @ 2025-08-04 8:56 UTC (permalink / raw)
To: Namjae Jeon; +Cc: sj1557.seo@samsung.com, linux-fsdevel@vger.kernel.org
> On Fri, Aug 1, 2025 at 5:03 PM Yuezhang.Mo@sony.com
> <Yuezhang.Mo@sony.com> wrote:
> >
> > > Loading the allocation bitmap is very slow if user set the small cluster
> > > size on large partition.
> > >
> > > For optimizing it, This patch uses sb_breadahead() read the allocation
> > > bitmap. It will improve the mount time.
> > >
> > > The following is the result of about 4TB partition(2KB cluster size)
> > > on my target.
> > >
> > > without patch:
> > > real 0m41.746s
> > > user 0m0.011s
> > > sys 0m0.000s
> > >
> > > with patch:
> > > real 0m2.525s
> > > user 0m0.008s
> > > sys 0m0.008s
> > >
> > > Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> > > Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> > > ---
> > > fs/exfat/balloc.c | 12 +++++++++++-
> > > fs/exfat/dir.c | 1 -
> > > fs/exfat/exfat_fs.h | 1 +
> > > 3 files changed, 12 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
> > > index cc01556c9d9b..c40b73701941 100644
> > > --- a/fs/exfat/balloc.c
> > > +++ b/fs/exfat/balloc.c
> > > @@ -30,9 +30,11 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> > > struct exfat_dentry *ep)
> > > {
> > > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > > + struct blk_plug plug;
> > > long long map_size;
> > > - unsigned int i, need_map_size;
> > > + unsigned int i, j, need_map_size;
> > > sector_t sector;
> > > + unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
> > >
> > > sbi->map_clu = le32_to_cpu(ep->dentry.bitmap.start_clu);
> > > map_size = le64_to_cpu(ep->dentry.bitmap.size);
> > > @@ -57,6 +59,14 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> > >
> > > sector = exfat_cluster_to_sector(sbi, sbi->map_clu);
> > > for (i = 0; i < sbi->map_sectors; i++) {
> > > + /* Trigger the next readahead in advance. */
> > > + if (0 == (i % max_ra_count)) {
> > > + blk_start_plug(&plug);
> > > + for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
> > > + sb_breadahead(sb, sector + j);
> > > + blk_finish_plug(&plug);
> > > + }
> > > +
> > > sbi->vol_amap[i] = sb_bread(sb, sector + i);
> > > if (!sbi->vol_amap[i]) {
> > > /* release all buffers and free vol_amap */
> > > diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
> > > index ee060e26f51d..e7a8550c0346 100644
> > > --- a/fs/exfat/dir.c
> > > +++ b/fs/exfat/dir.c
> > > @@ -616,7 +616,6 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
> > > return 0;
> > > }
> > >
> > > -#define EXFAT_MAX_RA_SIZE (128*1024)
> > > static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
> > > {
> > > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > > diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> > > index f8ead4d47ef0..d1792d5c9eed 100644
> > > --- a/fs/exfat/exfat_fs.h
> > > +++ b/fs/exfat/exfat_fs.h
> > > @@ -13,6 +13,7 @@
> > > #include <uapi/linux/exfat.h>
> > >
> > > #define EXFAT_ROOT_INO 1
> > > +#define EXFAT_MAX_RA_SIZE (128*1024)
> >
> > Why is the max readahead size 128KiB?
> > If the limit is changed to max_sectors_kb, so that a read request reads as much
> > data as possible, will the performance be better?
> This sets an appropriate readahead size for exfat. It's already used
> elsewhere in exfat.
> Getting ->max_sectors_kb from the block layer will result in a layer violation.
I checked the code of read ahead, EXFAT_MAX_RA_SIZE is consistent with the
default value(VM_READAHEAD_PAGES) of sb->s_bdi->ra_pages.
Is it better to use sb->s_bdi->ra_pages instead?
If so, users can set different values via 'blockdev --setra'.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] exfat: optimize allocation bitmap loading time
2025-08-04 8:56 ` Yuezhang.Mo
@ 2025-08-05 1:06 ` Namjae Jeon
0 siblings, 0 replies; 5+ messages in thread
From: Namjae Jeon @ 2025-08-05 1:06 UTC (permalink / raw)
To: Yuezhang.Mo@sony.com
Cc: sj1557.seo@samsung.com, linux-fsdevel@vger.kernel.org
On Mon, Aug 4, 2025 at 5:57 PM Yuezhang.Mo@sony.com
<Yuezhang.Mo@sony.com> wrote:
>
> > On Fri, Aug 1, 2025 at 5:03 PM Yuezhang.Mo@sony.com
> > <Yuezhang.Mo@sony.com> wrote:
> > >
> > > > Loading the allocation bitmap is very slow if user set the small cluster
> > > > size on large partition.
> > > >
> > > > For optimizing it, This patch uses sb_breadahead() read the allocation
> > > > bitmap. It will improve the mount time.
> > > >
> > > > The following is the result of about 4TB partition(2KB cluster size)
> > > > on my target.
> > > >
> > > > without patch:
> > > > real 0m41.746s
> > > > user 0m0.011s
> > > > sys 0m0.000s
> > > >
> > > > with patch:
> > > > real 0m2.525s
> > > > user 0m0.008s
> > > > sys 0m0.008s
> > > >
> > > > Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> > > > Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
> > > > ---
> > > > fs/exfat/balloc.c | 12 +++++++++++-
> > > > fs/exfat/dir.c | 1 -
> > > > fs/exfat/exfat_fs.h | 1 +
> > > > 3 files changed, 12 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
> > > > index cc01556c9d9b..c40b73701941 100644
> > > > --- a/fs/exfat/balloc.c
> > > > +++ b/fs/exfat/balloc.c
> > > > @@ -30,9 +30,11 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> > > > struct exfat_dentry *ep)
> > > > {
> > > > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > > > + struct blk_plug plug;
> > > > long long map_size;
> > > > - unsigned int i, need_map_size;
> > > > + unsigned int i, j, need_map_size;
> > > > sector_t sector;
> > > > + unsigned int max_ra_count = EXFAT_MAX_RA_SIZE >> sb->s_blocksize_bits;
> > > >
> > > > sbi->map_clu = le32_to_cpu(ep->dentry.bitmap.start_clu);
> > > > map_size = le64_to_cpu(ep->dentry.bitmap.size);
> > > > @@ -57,6 +59,14 @@ static int exfat_allocate_bitmap(struct super_block *sb,
> > > >
> > > > sector = exfat_cluster_to_sector(sbi, sbi->map_clu);
> > > > for (i = 0; i < sbi->map_sectors; i++) {
> > > > + /* Trigger the next readahead in advance. */
> > > > + if (0 == (i % max_ra_count)) {
> > > > + blk_start_plug(&plug);
> > > > + for (j = i; j < min(max_ra_count, sbi->map_sectors - i) + i; j++)
> > > > + sb_breadahead(sb, sector + j);
> > > > + blk_finish_plug(&plug);
> > > > + }
> > > > +
> > > > sbi->vol_amap[i] = sb_bread(sb, sector + i);
> > > > if (!sbi->vol_amap[i]) {
> > > > /* release all buffers and free vol_amap */
> > > > diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
> > > > index ee060e26f51d..e7a8550c0346 100644
> > > > --- a/fs/exfat/dir.c
> > > > +++ b/fs/exfat/dir.c
> > > > @@ -616,7 +616,6 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
> > > > return 0;
> > > > }
> > > >
> > > > -#define EXFAT_MAX_RA_SIZE (128*1024)
> > > > static int exfat_dir_readahead(struct super_block *sb, sector_t sec)
> > > > {
> > > > struct exfat_sb_info *sbi = EXFAT_SB(sb);
> > > > diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
> > > > index f8ead4d47ef0..d1792d5c9eed 100644
> > > > --- a/fs/exfat/exfat_fs.h
> > > > +++ b/fs/exfat/exfat_fs.h
> > > > @@ -13,6 +13,7 @@
> > > > #include <uapi/linux/exfat.h>
> > > >
> > > > #define EXFAT_ROOT_INO 1
> > > > +#define EXFAT_MAX_RA_SIZE (128*1024)
> > >
> > > Why is the max readahead size 128KiB?
> > > If the limit is changed to max_sectors_kb, so that a read request reads as much
> > > data as possible, will the performance be better?
> > This sets an appropriate readahead size for exfat. It's already used
> > elsewhere in exfat.
> > Getting ->max_sectors_kb from the block layer will result in a layer violation.
>
> I checked the code of read ahead, EXFAT_MAX_RA_SIZE is consistent with the
> default value(VM_READAHEAD_PAGES) of sb->s_bdi->ra_pages.
>
> Is it better to use sb->s_bdi->ra_pages instead?
> If so, users can set different values via 'blockdev --setra'.
I will change max_ra_count as follows:
max_ra_count = min(sb->s_bdi->ra_pages, sb->s_bdi->io_pages)
<< (PAGE_SHIFT - sb->s_blocksize_bits);
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-05 1:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-01 0:14 [PATCH] exfat: optimize allocation bitmap loading time Namjae Jeon
2025-08-01 8:02 ` Yuezhang.Mo
2025-08-03 23:04 ` Namjae Jeon
2025-08-04 8:56 ` Yuezhang.Mo
2025-08-05 1:06 ` 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).