Hi,

I'm currently trying out f2fs safe resize / shrink on Android.
(Size: 98 GiB used out of 221 GiB, 501,313 nodes, resize to 180 GiB)

It seems to work surprisingly well, the only improvement that can be
made seems to be updating quota.

After resize, fsck complains:
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 4 corrupted: file
size 73728 does not match page offset 19
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 5 corrupted: file
size 120832 does not match page offset 30
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 6 corrupted: file
size 27648 does not match page offset 7

The resize.f2fs process was stuck at 100% CPU usage the whole time.
Maybe this can be improved with a more efficient algorithm or
parallelizing, but that's another discussion.
The whole process took about 5 minutes, when the resize.f2fs was
pinned at cpu7 (Cortex-X1).

I've also confirmed that the files are exactly the same before and
after the shrink (checked via rsync -c). This took 25 minutes.
All in all, I'm glad to find out that shrinking works on f2fs well. No
error logs on dmesg either.

Also, I believe man/resize.f2fs.8 needs to be updated:
`Current version only supports expanding the prebuilt filesystem.`

Used versions:
f2fs-tools 1.15.0
Linux v5.4.197 with 5.19-rc1-5.4 merged

Here's the full commands & outputs that I've used:
---- Snapshot creation ----
# echo 10G > /sys/block/zram0/disksize
# dmsetup create snap --table "0 464059800 snapshot
/dev/block/bootdevice/by-name/userdata /dev/block/zram0 N 256"

---- Initial fsck before resize ----
# fsck.f2fs -y -f /dev/block/mapper/snap
Info: Force to fix corruption
Info: Force to fix corruption
Info: MKFS version
  "5.4.179-arter97-gbc35154ef66c"
Info: FSCK version
  from "5.4-arter97"
    to "Linux version 5.4.197-arter97-r21b2-69720-g84bf16de46b9
(arter97@arter97-dgist) (Android (8508608, based on r450784e) clang
version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project
4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.7) #"
Info: superblock features = 1499 :  encrypt verity extra_attr
project_quota quota_ino casefold
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: Segments per section = 1
Info: Sections per zone = 1
Info: total FS sectors = 58007475 (226591 MB)
Info: CKPT version = 6b90089a
Info: checkpoint state = 44 :  crc compacted_summary sudden-power-off
[FSCK] Check node 1 / 501313 (0.00%)
[FSCK] Check node 50132 / 501313 (10.00%)
[FSCK] Check node 100263 / 501313 (20.00%)
[FSCK] Check node 150394 / 501313 (30.00%)
[FSCK] Check node 200525 / 501313 (40.00%)
[FSCK] Check node 250656 / 501313 (50.00%)
[FSCK] Check node 300787 / 501313 (60.00%)
[FSCK] Check node 350918 / 501313 (70.00%)
[FSCK] Check node 401049 / 501313 (80.00%)
[FSCK] Check node 451180 / 501313 (90.00%)
[FSCK] Check node 501311 / 501313 (100.00%)
[fsck_chk_quota_files:2035] Fixing Quota file ([  0] ino [0x4])
[fsck_chk_quota_files:2035] Fixing Quota file ([  1] ino [0x5])
[fsck_chk_quota_files:2035] Fixing Quota file ([  2] ino [0x6])

[FSCK] Max image size: 206671 MB, Free space: 126217 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0xa]
[FSCK] valid_block_count matching with CP             [Ok..] [0x17deab6]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x7a641]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x7a641]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x76cec]
[FSCK] free segment_count matched with CP             [Ok..] [0xfa30]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]
Info: Duplicate valid checkpoint to mirror position 1024 -> 512
Info: Write valid nat_bits in checkpoint
Info: Write valid nat_bits in checkpoint

Done: 0.000000 secs

---- Resize ----
# resize.f2fs -s -t 47185920 /dev/block/mapper/snap
Info: MKFS version
  "5.4.179-arter97-gbc35154ef66c"
Info: FSCK version
  from "5.4-arter97"
    to "Linux version 5.4.197-arter97-r21b2-69720-g84bf16de46b9
(arter97@arter97-dgist) (Android (8508608, based on r450784e) clang
version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project
4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.7) #"
Info: superblock features = 1499 :  encrypt verity extra_attr
project_quota quota_ino casefold
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: Segments per section = 1
Info: Sections per zone = 1
Info: total FS sectors = 58007475 (226591 MB)
Info: CKPT version = 6b90089a
[FIX] (move_one_curseg_info:2857)  --> Move curseg[0] 70 -> 161cc after 2d00000

[FIX] (move_one_curseg_info:2857)  --> Move curseg[1] 890 -> 161cb after 2d00000

[FIX] (move_one_curseg_info:2857)  --> Move curseg[2] 8af -> 161cd after 2d00000

[FIX] (move_one_curseg_info:2857)  --> Move curseg[3] a8 -> 161ca after 2d00000

[FIX] (move_one_curseg_info:2857)  --> Move curseg[4] 117 -> 161c9 after 2d00000

[FIX] (move_one_curseg_info:2857)  --> Move curseg[5] 16d9 -> 161c8
after 2d00000

Info: Write valid nat_bits in checkpoint
Try to do defragement: Done
[update_superblock: 701] Info: Done to update superblock
Info: Write valid nat_bits in checkpoint
[rebuild_checkpoint: 591] Info: Done to rebuild checkpoint blocks

Done: 0.000000 secs

---- 1st fsck after resize ----
# fsck.f2fs -y -f /dev/block/mapper/snap
Info: Force to fix corruption
Info: Force to fix corruption
Info: MKFS version
  "5.4.179-arter97-gbc35154ef66c"
Info: FSCK version
  from "5.4-arter97"
    to "Linux version 5.4.197-arter97-r21b2-69720-g84bf16de46b9
(arter97@arter97-dgist) (Android (8508608, based on r450784e) clang
version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project
4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.7) #"
Info: superblock features = 1499 :  encrypt verity extra_attr
project_quota quota_ino casefold
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: Segments per section = 1
Info: Sections per zone = 1
Info: total FS sectors = 47185920 (184320 MB)
Invalid CP CRC offset: 0
Info: CKPT version = 6b90089b
Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = 81 :  nat_bits unmount
[FSCK] Check node 1 / 501313 (0.00%)
[FSCK] Check node 50132 / 501313 (10.00%)
[FSCK] Check node 100263 / 501313 (20.00%)
[FSCK] Check node 150394 / 501313 (30.00%)
[FSCK] Check node 200525 / 501313 (40.00%)
[FSCK] Check node 250656 / 501313 (50.00%)
[FSCK] Check node 300787 / 501313 (60.00%)
[FSCK] Check node 350918 / 501313 (70.00%)
[FSCK] Check node 401049 / 501313 (80.00%)
[FSCK] Check node 451180 / 501313 (90.00%)
[FSCK] Check node 501311 / 501313 (100.00%)
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 4 corrupted: file
size 73728 does not match page offset 19
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 5 corrupted: file
size 120832 does not match page offset 30
[ERROR] quotaio_v2.c:201:v2_init_io:: Quota inode 6 corrupted: file
size 27648 does not match page offset 7

[FSCK] Max image size: 184108 MB, Free space: 84135 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0xa]
[FSCK] valid_block_count matching with CP             [Ok..] [0x17deab6]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x7a641]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x7a641]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x76cec]
[FSCK] free segment_count matched with CP             [Ok..] [0xa79c]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]

Done: 0.000000 secs

---- 2nd fsck after resize ----
# fsck.f2fs -y -f /dev/block/mapper/snap
Info: Force to fix corruption
Info: Force to fix corruption
Info: MKFS version
  "5.4.179-arter97-gbc35154ef66c"
Info: FSCK version
  from "5.4-arter97"
    to "Linux version 5.4.197-arter97-r21b2-69720-g84bf16de46b9
(arter97@arter97-dgist) (Android (8508608, based on r450784e) clang
version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project
4c603efb0cca074e9238af8b4106c30add4418f6), LLD 14.0.7) #"
Info: superblock features = 1499 :  encrypt verity extra_attr
project_quota quota_ino casefold
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: Segments per section = 1
Info: Sections per zone = 1
Info: total FS sectors = 47185920 (184320 MB)
Invalid CP CRC offset: 0
Info: CKPT version = 6b90089b
Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = 81 :  nat_bits unmount
[FSCK] Check node 1 / 501313 (0.00%)
[FSCK] Check node 50132 / 501313 (10.00%)
[FSCK] Check node 100263 / 501313 (20.00%)
[FSCK] Check node 150394 / 501313 (30.00%)
[FSCK] Check node 200525 / 501313 (40.00%)
[FSCK] Check node 250656 / 501313 (50.00%)
[FSCK] Check node 300787 / 501313 (60.00%)
[FSCK] Check node 350918 / 501313 (70.00%)
[FSCK] Check node 401049 / 501313 (80.00%)
[FSCK] Check node 451180 / 501313 (90.00%)
[FSCK] Check node 501311 / 501313 (100.00%)

[FSCK] Max image size: 184108 MB, Free space: 84135 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0xa]
[FSCK] valid_block_count matching with CP             [Ok..] [0x17deab6]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x7a641]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x7a641]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x76cec]
[FSCK] free segment_count matched with CP             [Ok..] [0xa79c]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]

Done: 0.000000 secs

---- Before & after check ----
# mkdir /tmp/1 /tmp/2
# losetup -f -r /dev/block/by-name/userdata
# mount -t f2fs -o ro /dev/block/loop0 /tmp/1
# mount -t f2fs -o ro /dev/block/mapper/snap /tmp/2
# rsync -ahxvc --info=progress2 1/ 2/
sending incremental file list
              0   0%    0.00kB/s    0:00:00 (xfr#0, to-chk=0/486687)

sent 25.22M bytes  received 90.17K bytes  16.92K bytes/sec
total size is 101.04G  speedup is 3,991.40
# dmesg | grep -i f2fs
[ 2462.787850] F2FS-fs (loop0): Using encoding defined by superblock:
utf8-12.1.0 with flags 0x0
[ 2462.929670] F2FS-fs (loop0): recover fsync data on readonly fs
[ 2462.976133] F2FS-fs (loop0): write access unavailable, skipping recovery
[ 2462.976135] F2FS-fs (loop0): Mounted with checkpoint version = 6b90089a
[ 2475.857335] F2FS-fs (dm-0): Using encoding defined by superblock:
utf8-12.1.0 with flags 0x0
[ 2475.876950] F2FS-fs (dm-0): Found nat_bits in checkpoint
[ 2475.913980] F2FS-fs (dm-0): recover fsync data on readonly fs
[ 2475.940111] F2FS-fs (dm-0): Mounted with checkpoint version = 6b9009b7

After the whole operation, zram0 usage was 3 GiB (uncompressed size).


_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to