Ext2FS: Uncache unused Inodes after flushing contents to disk

Don't keep Inodes around in memory forever after we've interacted with
them once. This is a slight performance pessimization when accessing
the same file repeatedly, but closing it for a while in between.

Longer term we should find a way to keep a limited number of unused
Inodes cached, whichever ones we think are likely to be used again.
This commit is contained in:
Andreas Kling 2019-11-04 12:23:19 +01:00
parent 19398cd7d5
commit c538648465
Notes: sideshowbarker 2024-07-19 11:25:57 +09:00

View File

@ -503,7 +503,21 @@ void Ext2FS::flush_writes()
#endif
}
}
DiskBackedFS::flush_writes();
// Uncache Inodes that are only kept alive by the index-to-inode lookup cache.
// FIXME: It would be better to keep a capped number of Inodes around.
// The problem is that they are quite heavy objects, and use a lot of heap memory
// for their (child name lookup) and (block list) caches.
Vector<InodeIndex> unused_inodes;
for (auto& it : m_inode_cache) {
if (it.value->ref_count() != 1)
continue;
unused_inodes.append(it.key);
}
for (auto index : unused_inodes)
uncache_inode(index);
}
Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index)