From ac9d60bb132c5cdcc8f501e7b1952a2347dacd20 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Fri, 5 May 2023 17:33:22 +0200 Subject: [PATCH] Kernel: Promote the entry to the front during a cache hit Whenever an entry is added to the cache, the last element is removed to make space for the new entry(if the cache is full). To make this an LRU cache, the entry needs to be moved to the front of the list when there is a cache hit so that the least recently used entry moves to the end to be evicted first. --- Kernel/FileSystem/BlockBasedFileSystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index 1dabaecf00d..852fb524f5d 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -60,6 +60,10 @@ public: return nullptr; auto& entry = const_cast(*it->value); VERIFY(entry.block_index == block_index); + if (!entry_is_dirty(entry) && (m_clean_list.first() != &entry)) { + // Cache hit! Promote the entry to the front of the list. + m_clean_list.prepend(entry); + } return &entry; }