add patch create-function-to-read-journal-inode
[ext4-patch-queue.git] / only-call-ext4_truncate-if-there-is-data-to-truncate
blob56ac69ff580b232c77136067f65d365f75b746ba
1 ext4: in ext4_setattr(), only call ext4_truncate() if there is no data to drop
3 If there are no blocks associated with the inode (and no inline data),
4 there's no point calling ext4_truncate().  This avoids setting the
5 replace-via-truncate hueristic if there is an attempt to truncate a
6 file which is already zero-length --- which is something that happens
7 in the core dumping code, in case there is an already existing core
8 file.  In the comon case, there is not a previous core file, so by not
9 enabling the replace-via-truncate hueristic, we can speed up core
10 dumps.
12 Reported-by: Omar Sandoval <osandov@fb.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 ---
15  fs/ext4/inode.c | 2 +-
16  1 file changed, 1 insertion(+), 1 deletion(-)
18 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
19 index 44ee5d9..cd757f8 100644
20 --- a/fs/ext4/inode.c
21 +++ b/fs/ext4/inode.c
22 @@ -5171,7 +5171,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
23                  * in data=journal mode to make pages freeable.
24                  */
25                 truncate_pagecache(inode, inode->i_size);
26 -               if (shrink)
27 +               if (shrink && (inode->i_blocks || ext4_has_inline_data(inode)))
28                         ext4_truncate(inode);
29                 up_write(&EXT4_I(inode)->i_mmap_sem);
30         }