* [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division
@ 2026-09-05 17:10 David Timber
2026-09-05 17:10 ` [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags David Timber
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: David Timber @ 2026-09-05 17:10 UTC (permalink / raw)
To: Namjae Jeon, Sungjong Seo, Yuezhang Mo
Cc: exfat, Hyunchul Lee, linux-kernel, David Timber
Changes from RFC v0:
- use mul_u64_u32_div() for 32-bit arch without 64-bit integer
division
mul_u64_u32_div() isn't so popular API, so I'm not sure it's available
on all arch.
I don't have a beefy machine to test my patches for all arch... If you'd
like to apply, I suggest waiting for the CI bots to finish testing. I
believe all submitted patches that apply to the master branch are tested
by the bots. I'll ping when the patches get a pass.
David Timber (2):
exfat: update percent_in_use field when updating volume flags
exfat: remove runtime integer division
fs/exfat/dir.c | 3 ++-
fs/exfat/exfat_fs.h | 1 +
fs/exfat/namei.c | 4 ++--
fs/exfat/super.c | 20 +++++++++++++++++---
4 files changed, 22 insertions(+), 6 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division David Timber
@ 2026-09-05 17:10 ` David Timber
2026-09-05 17:10 ` [PATCH v1 2/2] exfat: remove runtime integer division David Timber
2026-09-07 14:42 ` [PATCH v1 0/2] exfat: update percent_in_use, " Namjae Jeon
2 siblings, 0 replies; 4+ messages in thread
From: David Timber @ 2026-09-05 17:10 UTC (permalink / raw)
To: Namjae Jeon, Sungjong Seo, Yuezhang Mo
Cc: exfat, Hyunchul Lee, linux-kernel, David Timber
Currently, the exfat fs implementation does not modify the
percent_in_use in the boot sector header at all. Although the field is
only an advisory field for situations where bit counting is not
feasible, not updating the field at all can cause confusion if the
the value is actually exposed to the user.
Calculate the value using integer arithmetic only when the dirty flag is
cleared. If the dirty flag is set, set to 0xFF.
It is set to 0xFF when mounting under the assumption that the number of
used clusters will change - this is basically what is recommended in the
SD Association's specs.
When clearing the dirty flag, if overridden by
sbi->vol_flags_persistent, set to 0xFF. This is intentional because if
there are orphan clusters, the calculated value would be incorrect and
correcting the fs error is fsck.exfat's job.
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
fs/exfat/super.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index a9ea36ba2693..2409e57e7370 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -18,6 +18,7 @@
#include <linux/nls.h>
#include <linux/buffer_head.h>
#include <linux/magic.h>
+#include <linux/math.h>
#include "exfat_raw.h"
#include "exfat_fs.h"
@@ -69,16 +70,28 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0;
}
+static inline __u8 exfat_calc_perc_in_use(const struct exfat_sb_info *sbi)
+{
+ return (__u8)mul_u64_u32_div(sbi->used_clusters, 100,
+ EXFAT_DATA_CLUSTER_COUNT(sbi));
+}
+
static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags)
{
struct exfat_sb_info *sbi = EXFAT_SB(sb);
struct boot_sector *p_boot = (struct boot_sector *)sbi->boot_bh->b_data;
+ __u8 new_piu;
/* retain persistent-flags */
new_flags |= sbi->vol_flags_persistent;
+ if (new_flags & VOLUME_DIRTY)
+ new_piu = 0xFF;
+ else
+ new_piu = exfat_calc_perc_in_use(sbi);
+
/* flags are not changed */
- if (sbi->vol_flags == new_flags)
+ if (sbi->vol_flags == new_flags && new_piu == p_boot->percent_in_use)
return 0;
sbi->vol_flags = new_flags;
@@ -90,6 +103,7 @@ static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags)
return 0;
p_boot->vol_flags = cpu_to_le16(new_flags);
+ p_boot->percent_in_use = new_piu;
set_buffer_uptodate(sbi->boot_bh);
mark_buffer_dirty(sbi->boot_bh);
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1 2/2] exfat: remove runtime integer division
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division David Timber
2026-09-05 17:10 ` [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags David Timber
@ 2026-09-05 17:10 ` David Timber
2026-09-07 14:42 ` [PATCH v1 0/2] exfat: update percent_in_use, " Namjae Jeon
2 siblings, 0 replies; 4+ messages in thread
From: David Timber @ 2026-09-05 17:10 UTC (permalink / raw)
To: Namjae Jeon, Sungjong Seo, Yuezhang Mo
Cc: exfat, Hyunchul Lee, linux-kernel, David Timber
Replace the arithmetic ops that compiles to the use of actual integer
division with bitwise ops. As the divisors involved are all power of
two, integer division is not necessary.
No functional change.
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
fs/exfat/dir.c | 3 ++-
fs/exfat/exfat_fs.h | 1 +
fs/exfat/namei.c | 4 ++--
fs/exfat/super.c | 4 ++--
4 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index fa9abedf4d84..46514b13bebd 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -1309,7 +1309,8 @@ static int exfat_get_volume_label_dentry(struct super_block *sb,
es->bh = es->__bh;
es->bh[0] = bh;
es->num_bh = 1;
- es->start_off = exfat_dentries_to_bytes(i) % sb->s_blocksize;
+ es->start_off = exfat_dentries_to_bytes(i) &
+ ((u32)sb->s_blocksize - 1);
return 0;
}
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index a9131fe03302..41a2c7dfc479 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -232,6 +232,7 @@ struct exfat_sb_info {
unsigned int num_FAT_sectors; /* num of FAT sectors */
unsigned int root_dir; /* root dir cluster */
unsigned int dentries_per_clu; /* num of dentries per cluster */
+ unsigned int dentries_per_clu_bits;
unsigned int vol_flags; /* volume flags */
unsigned int vol_flags_persistent; /* volume flags to retain */
struct buffer_head *boot_bh; /* buffer_head of BOOT sector */
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 80f60e80786e..3c5746fc57d9 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -386,7 +386,7 @@ int exfat_find_empty_entry(struct inode *inode,
}
p_dir->dir = exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr);
- p_dir->size -= dentry / sbi->dentries_per_clu;
+ p_dir->size -= dentry >> sbi->dentries_per_clu_bits;
return dentry & (sbi->dentries_per_clu - 1);
}
@@ -638,7 +638,7 @@ static int exfat_find(struct inode *dir, const struct qstr *qname,
/* 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;
+ cdir.size -= dentry >> sbi->dentries_per_clu_bits;
dentry = hint_opt.eidx;
info->dir = cdir;
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index 2409e57e7370..217d150652cf 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -519,8 +519,8 @@ static int exfat_read_boot_sector(struct super_block *sb)
EXFAT_RESERVED_CLUSTERS;
sbi->root_dir = le32_to_cpu(p_boot->root_cluster);
- sbi->dentries_per_clu = 1 <<
- (sbi->cluster_size_bits - DENTRY_SIZE_BITS);
+ sbi->dentries_per_clu_bits = sbi->cluster_size_bits - DENTRY_SIZE_BITS;
+ sbi->dentries_per_clu = 1 << sbi->dentries_per_clu_bits;
sbi->vol_flags = le16_to_cpu(p_boot->vol_flags);
sbi->vol_flags_persistent = sbi->vol_flags & (VOLUME_DIRTY | MEDIA_FAILURE);
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division David Timber
2026-09-05 17:10 ` [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags David Timber
2026-09-05 17:10 ` [PATCH v1 2/2] exfat: remove runtime integer division David Timber
@ 2026-09-07 14:42 ` Namjae Jeon
2 siblings, 0 replies; 4+ messages in thread
From: Namjae Jeon @ 2026-09-07 14:42 UTC (permalink / raw)
To: David Timber; +Cc: Sungjong Seo, Yuezhang Mo, exfat, Hyunchul Lee, linux-kernel
On Sun, Sep 6, 2026 at 2:11 AM David Timber <dxdt@dev.snart.me> wrote:
>
> Changes from RFC v0:
>
> - use mul_u64_u32_div() for 32-bit arch without 64-bit integer
> division
>
> mul_u64_u32_div() isn't so popular API, so I'm not sure it's available
> on all arch.
>
> I don't have a beefy machine to test my patches for all arch... If you'd
> like to apply, I suggest waiting for the CI bots to finish testing. I
> believe all submitted patches that apply to the master branch are tested
> by the bots. I'll ping when the patches get a pass.
>
>
> David Timber (2):
> exfat: update percent_in_use field when updating volume flags
> exfat: remove runtime integer division
Applied them to #dev.
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-07 14:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division David Timber
2026-09-05 17:10 ` [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags David Timber
2026-09-05 17:10 ` [PATCH v1 2/2] exfat: remove runtime integer division David Timber
2026-09-07 14:42 ` [PATCH v1 0/2] exfat: update percent_in_use, " Namjae Jeon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®