Skip to content

Commit

Permalink
Ext2FS: Avoid a kmallocation every time we fetch an inode from disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Feb 3, 2019
1 parent db2422d commit 3a9c016
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions Kernel/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Ext2FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Ext2FSInode final : public Inode {

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;
Expand Down

0 comments on commit 3a9c016

Please sign in to comment.