瀏覽代碼

Ext2FS: Avoid a kmallocation every time we fetch an inode from disk.

Andreas Kling 6 年之前
父節點
當前提交
3a9c01619f
共有 2 個文件被更改,包括 4 次插入11 次删除
  1. 3 10
      Kernel/Ext2FileSystem.cpp
  2. 1 1
      Kernel/Ext2FileSystem.h

+ 3 - 10
Kernel/Ext2FileSystem.cpp

@@ -329,9 +329,8 @@ void Ext2FS::flush_block_group_descriptor_table()
     write_blocks(first_block_of_bgdt, blocks_to_write, m_cached_group_descriptor_table);
 }
 
-Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index, const ext2_inode& raw_inode)
+Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index)
     : Inode(fs, index)
-    , m_raw_inode(raw_inode)
 {
 }
 
@@ -402,18 +401,12 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
     if (!block)
         return { };
 
-    // FIXME: Avoid this extra allocation, copy the raw inode directly into the Ext2FSInode metadata somehow.
-    auto* e2inode = reinterpret_cast<ext2_inode*>(kmalloc(inode_size()));
-    memcpy(e2inode, reinterpret_cast<ext2_inode*>(block.offset_pointer(offset)), inode_size());
-    auto raw_inode = OwnPtr<ext2_inode>(e2inode);
-    if (!raw_inode)
-        return nullptr;
-
     LOCKER(m_inode_cache_lock);
     auto it = m_inode_cache.find(inode.index());
     if (it != m_inode_cache.end())
         return (*it).value;
-    auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index(), *raw_inode));
+    auto new_inode = adopt(*new Ext2FSInode(const_cast<Ext2FS&>(*this), inode.index()));
+    memcpy(&new_inode->m_raw_inode, reinterpret_cast<ext2_inode*>(block.offset_pointer(offset)), inode_size());
     m_inode_cache.set(inode.index(), new_inode.copy_ref());
     return new_inode;
 }

+ 1 - 1
Kernel/Ext2FileSystem.h

@@ -47,7 +47,7 @@ private:
 
     Ext2FS& fs();
     const Ext2FS& fs() const;
-    Ext2FSInode(Ext2FS&, unsigned index, const ext2_inode&);
+    Ext2FSInode(Ext2FS&, unsigned index);
 
     mutable Vector<unsigned> m_block_list;
     mutable HashMap<String, unsigned> m_lookup_cache;