Просмотр исходного кода

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.
Pankaj Raghav 2 лет назад
Родитель
Сommit
ac9d60bb13
1 измененных файлов с 4 добавлено и 0 удалено
  1. 4 0
      Kernel/FileSystem/BlockBasedFileSystem.cpp

+ 4 - 0
Kernel/FileSystem/BlockBasedFileSystem.cpp

@@ -60,6 +60,10 @@ public:
             return nullptr;
             return nullptr;
         auto& entry = const_cast<CacheEntry&>(*it->value);
         auto& entry = const_cast<CacheEntry&>(*it->value);
         VERIFY(entry.block_index == block_index);
         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;
         return &entry;
     }
     }