Henrique de Moraes Holschuh wrote: > Bob Proulx wrote: > > Henrique de Moraes Holschuh wrote: > > > 2. unmount filesystem and run e2fsck -D on it every so often. > > > > Every so often? That phrase roused my interest. Wouldn't exactly > > once be enough? > > Yes, as long as nobody ever creates a massive number of entries in a > directory that is not going to be rmdir'd again after you did the > e2fsck -D... > > So, "every so often"...
But I think it doesn't actually work to shrink directories. :-( > > I think there are two issues under discussion. One is if dir_index > > has been applied. For that once would be enough. > > Yes. But dir_index is about locating files fast for open() or > stat() in massive directories, not shrinking a very sparse one. Right. That is why I said there were two issues under discussion. :-) > > # fsck -D /dev/v1/test > > fsck from util-linux 2.25.2 > > e2fsck 1.42.12 (29-Aug-2014) > > /dev/mapper/v1-test: clean, 13/25688 files, 9121/102400 blocks > > > > This produced no change in that directory size. It does not appear to > > me that e2fsck -D compacts existing empty directories. > > Hmm, you could try "e2fsck -D", not "fsck -D". Of course we know that fsck simply passed through to the appropriate underlying driver fsck, e2fsck in this case. The output says say. But this is trivially easy for me to do too so here it is. (It really is the same.) root@havoc:~# lvcreate -L100M -ntest v1 Logical volume "test" created root@havoc:~# mkfs -t ext4 /dev/v1/test mke2fs 1.42.12 (29-Aug-2014) Creating filesystem with 102400 1k blocks and 25688 inodes Filesystem UUID: 47bf1774-75b9-4783-958c-7cbcab2e219b Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done root@havoc:~# mount /dev/v1/test /mnt root@havoc:~# mkdir -p /mnt/junk/junk root@havoc:~# cd /mnt/junk/junk root@havoc:/mnt/junk/junk# for i in $(seq -w 1 10000); do touch $i;done root@havoc:/mnt/junk/junk# for i in $(seq -w 1 10000); do rm -f $i;done root@havoc:/mnt/junk/junk# cd root@havoc:~# \ls -ld /mnt/junk/junk drwxr-xr-x 2 root root 227328 Apr 15 14:35 /mnt/junk/junk root@havoc:~# umount /mnt root@havoc:~# e2fsck -D /dev/v1/test e2fsck 1.42.12 (29-Aug-2014) /dev/v1/test: clean, 13/25688 files, 9119/102400 blocks root@havoc:~# mount /dev/v1/test /mnt root@havoc:~# \ls -ld /mnt/junk/junk drwxr-xr-x 2 root root 227328 Apr 15 14:35 /mnt/junk/junk Using 'e2fsck -D' by itself isn't shrinking the size of the empty directory. > If e2fsck also refuses to do anything, try "e2fsck -D -f" to force > it to check a clean filesystem. Ah! That was the secret! root@havoc:~# umount /mnt root@havoc:~# e2fsck -D -f /dev/v1/test e2fsck 1.42.12 (29-Aug-2014) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 3A: Optimizing directories Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/v1/test: ***** FILE SYSTEM WAS MODIFIED ***** /dev/v1/test: 14/25688 files (0.0% non-contiguous), 8899/102400 blocks root@havoc:~# \ls -ld /mnt/junk/junk drwxr-xr-x 2 root root 1024 Apr 15 14:35 /mnt/junk/junk It was necessary to -f force the fsck. So 'e2fsck -D -f' is required. Bob
signature.asc
Description: Digital signature