]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit - fs/ext4/mballoc.c
ext4: Avoid group preallocation for closed files
authorTheodore Ts'o <tytso@mit.edu>
Fri, 18 Sep 2009 17:34:02 +0000 (13:34 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 18 Sep 2009 17:34:02 +0000 (13:34 -0400)
commit50797481a7bdee548589506d7d7b48b08bc14dcd
tree19989d27e3a69c6c2c507f798f55a2d9a47a5d27
parent4ba74d00a20256e22f159cb288ff34b587608917
ext4: Avoid group preallocation for closed files

Currently the group preallocation code tries to find a large (512)
free block from which to do per-cpu group allocation for small files.
The problem with this scheme is that it leaves the filesystem horribly
fragmented.  In the worst case, if the filesystem is unmounted and
remounted (after a system shutdown, for example) we forget the fact
that wee were using a particular (now-partially filled) 512 block
extent.  So the next time we try to allocate space for a small file,
we will find *another* completely free 512 block chunk to allocate
small files.  Given that there are 32,768 blocks in a block group,
after 64 iterations of "mount, write one 4k file in a directory,
unmount", the block group will have 64 files, each separated by 511
blocks, and the block group will no longer have any free 512
completely free chunks of blocks for group preallocation space.

So if we try to allocate blocks for a file that has been closed, such
that we know the final size of the file, and the filesystem is not
busy, avoid using group preallocation.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/ext4.h
fs/ext4/mballoc.c