aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/mballoc.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2009-09-18 13:34:02 -0400
committerTheodore Ts'o <tytso@mit.edu>2009-09-18 13:34:02 -0400
commit50797481a7bdee548589506d7d7b48b08bc14dcd (patch)
tree19989d27e3a69c6c2c507f798f55a2d9a47a5d27 /fs/ext4/mballoc.c
parent4ba74d00a20256e22f159cb288ff34b587608917 (diff)
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>
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r--fs/ext4/mballoc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 90a30ce822fc..faf5bd056a93 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4191,9 +4191,17 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
4191 return; 4191 return;
4192 4192
4193 size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len; 4193 size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len;
4194 isize = i_size_read(ac->ac_inode) >> bsbits; 4194 isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1)
4195 >> bsbits;
4195 size = max(size, isize); 4196 size = max(size, isize);
4196 4197
4198 if ((size == isize) &&
4199 !ext4_fs_is_busy(sbi) &&
4200 (atomic_read(&ac->ac_inode->i_writecount) == 0)) {
4201 ac->ac_flags |= EXT4_MB_HINT_NOPREALLOC;
4202 return;
4203 }
4204
4197 /* don't use group allocation for large files */ 4205 /* don't use group allocation for large files */
4198 if (size >= sbi->s_mb_stream_request) { 4206 if (size >= sbi->s_mb_stream_request) {
4199 ac->ac_flags |= EXT4_MB_STREAM_ALLOC; 4207 ac->ac_flags |= EXT4_MB_STREAM_ALLOC;