I have a requirement to use more inodes than normally available on most file systems. Therefore, I create and mount a ext4 filesystem with a custom inode setting:
dd if=/dev/zero of=loop0.img bs=1MB count=5000
losetup --find --show `pwd`/loop0.img
mkfs -t ext4 -i 1024 /dev/loop0
mount /dev/loop0 /mnt
This will create a 5000MB file on the disk (via ls /mnt
), but when I check using df
it shows as the disk is not occupied (disk space does not go up by 5000MB ). I suspect because it's zeroed out on the disk and looks like unused space.
As the disk gets full, I have a program that tries to delete least-recently-used files until the disk space pressure is removed. Well it turns out that despite deleting the files in /mnt
, it still registers as taking up space on my disk, at least according to df
and other disk free system calls.
So is there a special way I need to rm
the files on this virtual disk in order to register that the space is free? or do I need to inquire about free space in a non-standard way?
Edit: The full command and output, notice that the disk usage for /dev/vda1
does not increase 5000MB.
root@localhost:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 490064 0 490064 0% /dev
tmpfs 101092 3188 97904 4% /run
/dev/vda1 19343152 2699088 15660656 15% /
tmpfs 505448 0 505448 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 505448 0 505448 0% /sys/fs/cgroup
tmpfs 101088 0 101088 0% /run/user/0
root@localhost:~# dd if=/dev/zero of=loop0.img bs=1MB count=5000
5000+0 records in
5000+0 records out
5000000000 bytes (5.0 GB, 4.7 GiB) copied, 6.20117 s, 806 MB/s
root@localhost:~# losetup --find --show `pwd`/loop0.img
/dev/loop0
root@localhost:~# mkfs -t ext4 -i 1024 /dev/loop0
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done
Creating filesystem with 1220703 4k blocks and 4884000 inodes
Filesystem UUID: 4f308a54-6ddd-4ef6-b685-c193dfec8b84
Superblock backups stored on blocks:
8176, 24528, 40880, 57232, 73584, 204400, 220752, 400624, 662256,
1022000
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@localhost:~# mount /dev/loop0 /mnt
root@localhost:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 490064 0 490064 0% /dev
tmpfs 101092 3216 97876 4% /run
/dev/vda1 19343152 2769404 15590340 16% /
tmpfs 505448 0 505448 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 505448 0 505448 0% /sys/fs/cgroup
tmpfs 101088 0 101088 0% /run/user/0
/dev/loop0 3594900 45080 3289556 2% /mnt