From c538648465d1a35f1eb6d059245537e186a7e855 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Nov 2019 12:23:19 +0100 Subject: [PATCH] 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. --- Kernel/FileSystem/Ext2FileSystem.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 096d444223..9d428b4c13 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -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 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)