ソースを参照

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().
Andreas Kling 5 年 前
コミット
94a6b248ca
1 ファイル変更4 行追加1 行削除
  1. 4 1
      Kernel/FileSystem/Ext2FileSystem.cpp

+ 4 - 1
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)
 KResult Ext2FSInode::resize(u64 new_size)
 {
 {
-    u64 block_size = fs().block_size();
     u64 old_size = 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_before = ceil_div(old_size, block_size);
     int blocks_needed_after = ceil_div(new_size, block_size);
     int blocks_needed_after = ceil_div(new_size, block_size);