mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
Ext2FS: Avoid a kmallocation every time we fetch an inode from disk.
This commit is contained in:
parent
db2422d0d3
commit
3a9c01619f
Notes:
sideshowbarker
2024-07-19 15:53:12 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3a9c01619f2
2 changed files with 4 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue