[21.02] Wrong used/available space for F2FS @ x86

Running the official openwrt-21.02.0-rc4-x86-64-generic-squashfs-combined.img on Ubuntu 20.04 with KVM, the space available of the overlay seems wrong after the initial boot. df reported 58.2M of 98.1M was already used in /overlay, however du said /overlay only contains 50.5K data. A quick test with dd also verified the actual space available reported by df is correct.

So, this is the initial boot of the official image, how come 58.2M space on overlay got occupied? And the file occupying the space is invisible in the file system tree?

BusyBox v1.33.1 (2021-07-31 17:21:01 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 21.02.0-rc4, r16256-2d5ee43dc6
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.0M      4.0M         0 100% /rom
tmpfs                   242.8M     64.0K    242.7M   0% /tmp
/dev/loop0               98.1M     58.2M     39.8M  59% /overlay
overlayfs:/overlay       98.1M     58.2M     39.8M  59% /
/dev/sda1                15.7M      4.8M     10.7M  31% /boot
/dev/sda1                15.7M      4.8M     10.7M  31% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
root@OpenWrt:~# du -sh /rom /tmp /overlay /boot /
12.3M   /rom
64.0K   /tmp
50.5K   /overlay
4.7M    /boot
12.3M   /
root@OpenWrt:~# dd if=/dev/zero of=test bs=1024k count=100
dd: error writing 'test': No space left on device
40+0 records in
39+0 records out

Thanks!

2 Likes

The used space reported by du should be correct as it matches the Ext4 image.
It must be an F2FS-related bug since the problem persists on a separately mounted filesystem.

Tested again with with the official 21.02.0 release image (openwrt-21.02.0-x86-64-generic-squashfs-combined-efi.img.gz) and the problem persists :disappointed:

"Used" includes space that is reserved for internal use by F2FS. And for small partition sizes, that reserved space is relatively large, with the largest part being occupied by overprovision segments.

The number of overprovision segments is available at /sys/fs/f2fs/DEVICE/ovp_segments (but only with a current kernel, so this doesn't work on OpenWrt 21.02), and info about all main segments is available at /proc/fs/f2fs/DEVICE/segment_info (each segment has a size of 2 MiB).

1 Like

Is this normal for F2FS to reserve almost 60% of a 100 MB volume?

# dd if=/dev/zero of=/tmp/f2fs.img bs=1M count=100
100+0 records in
100+0 records out

# mkfs.f2fs /tmp/f2fs.img

	F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-08-24)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is enabled
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 204800 (100 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
  "Linux version 5.10.70 (builder@buildhost) (x86_64-openwrt-linux-musl-gcc (OpenWrt GCC 11.2.0 r17693-c2222f74c8) 11.2.0, GNU ld (GNU Binutils) 2.37) #0 SMP Fri Oct 8 00:09:40 2021"
Info: [/tmp/f2fs.img] Discarding device
Info: Overprovision ratio = 25.000%
Info: Overprovision segments = 22 (GC reserved = 16)
Info: format successful

# mount /tmp/f2fs.img /mnt

# df -h /mnt
Filesystem                Size      Used Available Use% Mounted on
/dev/loop0               98.0M     58.0M     40.0M  59% /mnt

# losetup
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE     DIO LOG-SEC
/dev/loop0         0      0         1  0 /tmp/f2fs.img   0     512

# cat /proc/fs/f2fs/loop0/segment_info
format: segment_type|valid_blocks
segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)
0         3|1   4|0   5|0   0|1   0|0   0|0   0|0   0|0   0|0   2|0  
10        0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0  
20        1|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0  
30        0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0   0|0  
40        0|0   0|0