diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2022-01-05 03:07:45 -0800 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-05 14:04:18 +0100 |
commit | 4b4cf060692664389b66e586a3f475f78d3cd839 (patch) | |
tree | 9e5dc34dea6b9f071541dc1f3777e5598478c565 /Kernel/FileSystem | |
parent | aa77c2ca585531023b9ed53b686200534a65e6ff (diff) | |
download | serenity-4b4cf060692664389b66e586a3f475f78d3cd839.zip |
Kernel: Remove temporary Vector from Ext2FS::flush_writes()
Previously we were using this vector to store the inodes as we iterated.
However, we don't need to store all of them, just the previous inode, as
we know it will be safe to remove it once we've iterated past that
element.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/Ext2FileSystem.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index 47a9b8b681..a30a785e8d 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -700,26 +700,34 @@ void Ext2FS::flush_writes() // Uncache Inodes that are only kept alive by the index-to-inode lookup cache. // We don't uncache Inodes that are being watched by at least one InodeWatcher. + Optional<InodeIndex> last_index {}; + auto remove_previous_entry_from_cache = [&]() { + if (last_index.has_value()) { + m_inode_cache.remove(last_index.value()); + last_index.clear(); + } + }; + // 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) { + remove_previous_entry_from_cache(); + // NOTE: If we're asked to look up an inode by number (via get_inode) and it turns out // to not exist, we remember the fact that it doesn't exist by caching a nullptr. // This seems like a reasonable time to uncache ideas about unknown inodes, so do that. if (!it.value) { - MUST(unused_inodes.try_append(it.key)); + last_index = it.key; continue; } if (it.value->ref_count() != 1) continue; if (it.value->has_watchers()) continue; - MUST(unused_inodes.try_append(it.key)); + last_index = it.key; } - for (auto index : unused_inodes) - uncache_inode(index); + remove_previous_entry_from_cache(); } BlockBasedFileSystem::flush_writes(); |