[kernel] Fix some page allocation bugs

Fixing two page allocation issues I came across while debugging:

- Added a spinlock to the page_table static page cache, to avoid
  multiple CPUs grabbing the same page. This cache should probably
  just be made into per-CPU caches.
- Fixed a bitwise math issue ("1" instead of "1ull" when working with
  64-bit numbers) that made it so that pages were never marked as
  allocated when allocating 32 or more.
This commit is contained in:
Justin C. Miller
2021-12-31 20:35:11 -08:00
parent 348b64ebb0
commit 99de8454cd
3 changed files with 23 additions and 10 deletions

View File

@@ -59,16 +59,16 @@ frame_allocator::allocate(size_t count, uintptr_t *address)
*address = block.base + frame * frame_size;
// Clear the bits to mark these pages allocated
m3 &= ~(((1 << n) - 1) << o3);
m3 &= ~(((1ull << n) - 1) << o3);
block.bitmap[(o1 << 6) + o2] = m3;
if (!m3) {
// if that was it for this group, clear the next level bit
m2 &= ~(1 << o2);
m2 &= ~(1ull << o2);
block.map2[o1] = m2;
if (!m2) {
// if that was cleared too, update the top level
block.map1 &= ~(1 << o1);
block.map1 &= ~(1ull << o1);
}
}