Skip to contentSkip to conversation

exfat: reduce unnecessary writes during mmap write

PATCH Applied [email protected] 2 participants 2 messages Jan 15 – Jan 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 exfat: reduce unnecessary writes during mmap write

From: Yuling Dong <[email protected]>

During mmap write, exfat_page_mkwrite() currently extends valid_size to the end of the VMA range. For a large mapping, this can push valid_size far beyond the page that actually triggered the fault, resulting in unnecessary writes.

valid_size only needs to extend to the end of the page being written.

---
 fs/exfat/file.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
fs/exfat/file.c +6 -9
index 536c8078f0c1..2977524beaf4 100644
@@ -707,21 +707,18 @@ static ssize_t exfat_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
 static vm_fault_t exfat_page_mkwrite(struct vm_fault *vmf)
 {
 	int err;
-	struct vm_area_struct *vma = vmf->vma;
-	struct file *file = vma->vm_file;
-	struct inode *inode = file_inode(file);
+	struct inode *inode = file_inode(vmf->vma->vm_file);
 	struct exfat_inode_info *ei = EXFAT_I(inode);
-	loff_t start, end;
+	loff_t new_valid_size;
 
 	if (!inode_trylock(inode))
 		return VM_FAULT_RETRY;
 
-	start = ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
-	end = min_t(loff_t, i_size_read(inode),
-			start + vma->vm_end - vma->vm_start);
+	new_valid_size = ((loff_t)vmf->pgoff + 1) << PAGE_SHIFT;
+	new_valid_size = min(new_valid_size, i_size_read(inode));
 
-	if (ei->valid_size < end) {
-		err = exfat_extend_valid_size(inode, end);
+	if (ei->valid_size < new_valid_size) {
+		err = exfat_extend_valid_size(inode, new_valid_size);
 		if (err < 0) {
 			inode_unlock(inode);
 			return vmf_fs_error(err);
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 8 lines · On Thu, Jan 15, 2026 at 2:07 PM <[email protected]> wrote:

From: Yuling Dong <[email protected]>

During mmap write, exfat_page_mkwrite() currently extends valid_size to the end of the VMA range. For a large mapping, this can push valid_size far beyond the page that actually triggered the fault, resulting in unnecessary writes.

Quoted 4 lines

valid_size only needs to extend to the end of the page being written.

Applied it to #dev.
Thanks!