[kernel] Remove page_table's cache counter

The `s_cache_count` counter had the potential to get out of sync with
the cache itself. Since we only call `fill_table_page_cache()` when the
cache is empty, the counter was not useful. After chasing the bug for
hours to figure out how they were getting out of sync, I just ripped it
out.
This commit is contained in:
Justin C. Miller
2023-02-14 20:29:40 -08:00
parent 2c2398b549
commit dc30437ce7
2 changed files with 14 additions and 22 deletions

View File

@@ -11,7 +11,6 @@ using mem::linear_offset;
using level = page_table::level;
free_page_header * page_table::s_page_cache = nullptr;
size_t page_table::s_cache_count = 0;
util::spinlock page_table::s_lock;
constexpr size_t page_table::entry_sizes[4];
@@ -182,14 +181,13 @@ page_table::get_table_page()
{
util::scoped_lock lock(s_lock);
if (!s_cache_count)
if (!s_page_cache)
fill_table_page_cache();
kassert(s_page_cache, "Somehow the page cache pointer is null");
page = s_page_cache;
s_page_cache = s_page_cache->next;
--s_cache_count;
}
memset(page, 0, frame_size);
@@ -204,34 +202,29 @@ page_table::free_table_page(page_table *pt)
reinterpret_cast<free_page_header*>(pt);
page->next = s_page_cache;
s_page_cache = page;
++s_cache_count;
}
void
page_table::fill_table_page_cache()
{
constexpr size_t min_pages = 32;
static constexpr size_t request_pages = 32;
frame_allocator &fa = frame_allocator::get();
while (s_cache_count < min_pages) {
uintptr_t phys = 0;
size_t n = fa.allocate(min_pages - s_cache_count, &phys);
kassert(phys, "Got physical page 0 as a page table");
free_page_header *start =
mem::to_virtual<free_page_header>(phys);
uintptr_t phys = 0;
size_t n = fa.allocate(request_pages, &phys);
for (int i = 0; i < n - 1; ++i)
util::offset_pointer(start, i * frame_size)
->next = util::offset_pointer(start, (i+1) * frame_size);
free_page_header *start =
mem::to_virtual<free_page_header>(phys);
free_page_header *end =
util::offset_pointer(start, (n-1) * frame_size);
for (int i = 0; i < n - 1; ++i)
util::offset_pointer(start, i * frame_size)
->next = util::offset_pointer(start, (i+1) * frame_size);
end->next = s_page_cache;
s_page_cache = start;
s_cache_count += n;
}
free_page_header *end =
util::offset_pointer(start, (n-1) * frame_size);
end->next = s_page_cache;
s_page_cache = start;
}
void

View File

@@ -141,7 +141,6 @@ struct page_table
static void fill_table_page_cache();
static free_page_header *s_page_cache; ///< Cache of free pages to use for tables
static size_t s_cache_count; ///< Number of pages in s_page_cache
static util::spinlock s_lock; ///< Lock for shared page cache
/// Get an entry in the page table as a page_table pointer