[PATCH v1 0/3] exfat: remove duplicate write directory entries

From: Yuezhang.Mo@xxxxxxxx
Date: Tue Jul 05 2022 - 22:35:13 EST


These patches simplifie the code, and removes unnecessary writes for the
following operations.

1. Write data to an empty file
* Preparation
```
mkdir /mnt/dir;touch /mnt/dir/file;sync
```
* Capture the blktrace log of the following command
```
dd if=/dev/zero of=/mnt/dir/file bs=${cluster_size} count=1 oflag=append conv=notrunc
```
* blktrace log
* Before
```
179,3 0 1 0.000000000 84 C WS 2623488 + 1 [0] BootArea
179,3 2 1 30.259435003 189 C W 2628864 + 256 [0] /dir/file
179,3 0 2 30.264066003 84 C W 2627584 + 1 [0] BitMap
179,3 2 2 30.261749337 189 C W 2628608 + 1 [0] /dir/
179,3 0 3 60.479159007 84 C W 2628608 + 1 [0] /dir/
```
* After
```
179,3 0 1 0.000000000 84 C WS 2623488 + 1 [0] BootArea
179,3 3 1 30.185383337 87 C W 2629888 + 256 [0] /dir/file
179,3 0 2 30.246422004 84 C W 2627584 + 1 [0] BitMap
179,3 0 3 60.466497674 84 C W 2628352 + 1 [0] /dir/
```

2. Allocate a new cluster for a directory
* Preparation
```
mkdir /mnt/dir
for ((i=1; i<cluster_size/96; i++)); do > /mnt/dir/file$i; done
mkdir /mnt/dir/dir1; sync
```
* Capture the blktrace log of the following command
```
> /mnt/dir/file
```
* blktrace log
- Before
```
179,3 0 1 0.000000000 84 C WS 2623488 + 1 [0] BootArea
179,3 2 1 30.263762003 189 C W 2629504 + 128 [0] /dir/
179,3 2 2 30.275596670 189 C W 2629376 + 128 [0] /dir/
179,3 2 3 30.290174003 189 C W 2629119 + 1 [0] /dir/
179,3 2 4 30.292362670 189 C W 2628096 + 1 [0] /
179,3 2 5 30.294547337 189 C W 2627584 + 1 [0] BitMap
179,3 0 2 30.296661337 84 C W 2625536 + 1 [0] FatArea
179,3 0 3 60.478775007 84 C W 2628096 + 1 [0] /
```
- After
```
179,3 0 1 0.000000000 84 C WS 2623488 + 1 [0] BootArea
179,3 3 1 30.288114670 87 C W 2631552 + 128 [0] /dir/
179,3 3 2 30.303518003 87 C W 2631424 + 128 [0] /dir/
179,3 3 3 30.324212337 87 C W 2631167 + 1 [0] /dir/
179,3 3 4 30.326579003 87 C W 2627584 + 1 [0] BitMap
179,3 0 2 30.328892670 84 C W 2625536 + 1 [0] FatArea
179,3 0 3 60.503128674 84 C W 2628096 + 1 [0] /
```

3. Truncate and release cluster from the file
* Preparation
```
mkdir /mnt/dir
dd if=/dev/zero of=/mnt/dir/file bs=${cluster_size} count=2
sync
```
* Capture the blktrace log of the following command
```
truncate -s ${cluster_size} /mnt/dir/file
```

* blktrace log
* Before
```
179,3 0 1 0.000000000 84 C WS 2623488 + 1 [0] BootArea
179,3 1 1 5.048452334 49 C W 2629120 + 1 [0] /dir/
179,3 0 2 5.062994334 84 C W 2627584 + 1 [0] BitMap
179,3 0 3 10.031253002 84 C W 2629120 + 1 [0] /dir/
```

* After
```
179,3 0 1 0.000000000 9143 C WS 2623488 + 1 [0] BootArea
179,3 0 2 14.839244001 9143 C W 2629888 + 1 [0] /dir/
179,3 0 3 14.841562335 9143 C W 2627584 + 1 [0] BitMap
```

Yuezhang Mo (3):
exfat: reuse __exfat_write_inode() to update directory entry
exfat: remove duplicate write inode for truncating file
exfat: remove duplicate write inode for extending dir/file

fs/exfat/exfat_fs.h | 1 +
fs/exfat/file.c | 82 ++++++++++++++-------------------------------
fs/exfat/inode.c | 41 ++++++-----------------
fs/exfat/namei.c | 20 -----------
4 files changed, 37 insertions(+), 107 deletions(-)

--
2.25.1