From 94a6b248ca502456f46d31ccf3a4ad7fdf38a2ad Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Nov 2019 16:22:29 +0100 Subject: [PATCH] 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(). --- Kernel/FileSystem/Ext2FileSystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index ff162d7192..c1e8892ed7 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -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);