Ext2FS: Resizing an Inode to its current size should do nothing

We were writing out the full block list whenever Ext2FSInode::resize()
was called, even if the old and new sizes were identical.

This patch makes it a no-op, which drastically improves "cp" speed
since we now take full advantage of the up-front call to ftruncate().
This commit is contained in:
Andreas Kling 2019-11-02 16:22:29 +01:00
parent 5835569527
commit 94a6b248ca

View file

@ -668,8 +668,11 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, u8* buffer, FileDes
KResult Ext2FSInode::resize(u64 new_size)
{
u64 block_size = fs().block_size();
u64 old_size = size();
if (old_size == new_size)
return KSuccess;
u64 block_size = fs().block_size();
int blocks_needed_before = ceil_div(old_size, block_size);
int blocks_needed_after = ceil_div(new_size, block_size);