Skip to content

Instantly share code, notes, and snippets.

@iankronquist
Last active September 2, 2016 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iankronquist/8012875d42d7a586d77767fbee2b6a61 to your computer and use it in GitHub Desktop.
Save iankronquist/8012875d42d7a586d77767fbee2b6a61 to your computer and use it in GitHub Desktop.
Design of the Kernel of Truth Memory System

Design of the Kernel of Truth Memory System

  • Uses PAE paging.
  • Higher half memory model.

Initialized in this order:

  1. Bootstrap PAE paging.
  2. Kernel heap.
  3. Physical allocator.
  4. Init process PAE paging.
  5. Higher half virtual allocator.
  6. Per process lower half virtual allocator.

Kernel Heap

  • Initialized first.
  • Initially a fixed sized heap at a fixed location. 1 Page, at the page after the end of the kernel binary.
  • Later we will find a large enough region by parsing the multiboot memory map.
  • First fit block allocator where each the region metadata is a prefix of the allocation.
  • Not currently kept in sorted order, or in 'binned' lists (regions of < 32 words, 128 words, 512 words, 1 page, more than a page)
  • May later grow after virtual memory allocator is initialized.
  • Depends on: physical memory allocator (after it is initialized).
  • Currently tested.

PAE Paging

  • Each process has its own page table structure.
  • Three levels: Page Directory Pointer Table, Page Directory, Page Table.
  • PDPT is allocated on kernel heap. Physical address calculated by subtraction.
  • All four slots in the PDPT are reserved at initialization time.
  • A cache of higher half virtual address pointers to the PDPT is kept in the page table structure.
  • All of the higher half PD are initialized and mapped into all process page tables at initialization time.
  • The kernel and kernel heap are mapped into higher half and thus their PDs are shared by all page tables.
  • PD are mapped using the physical allocator. If they are to be manipulated, they must first be mapped into the current page table.
  • PT are mapped using the physical allocator. If they are to be manipulated they must first be mapped into the current page table.
  • New process page tables get: new aligned PDPT, four new PDPT entries, and the higher half mapped (including kernel binary and kernel heap).
  • Depends on: kernel heap, physical memory allocator.

Region Allocator

  • Used to keep track of the physical memory allocator, higher half memory allocator, and lower half memory allocators.
  • Initially a sorted linked list of [address, size] pairs. Not binned. Later may be an RB tree.
  • Data structure lives on the kernel heap.
  • Currently tested.

Physical Memory Allocator

  • Uses the Region Allocator.
  • Initialized using the multiboot memory map.
  • Has the kernel's physical memory addresses, the kernel heap's bootstrap physical address, and the VGA buffer's physical address all pruned from its memory space.
  • Since this is shared among all processes it is protected by a singly spinlock.
  • Depends on: Kernel heap.

Higher Half Virtual Memory Allocator

  • Uses the Region Allocator.
  • Has the kernel's virtual memory addresses, the kernel heap's bootstrap virtual address, and the VGA buffer's virtual address all pruned from its memory space.
  • Since this is shared among all processes it is protected by a singly spinlock.
  • Depends on: Kernel heap, physical memory allocator, PAE paging.

Lower Half Virtual Memory Allocator

  • Uses the Region Allocator.
  • Per process.
  • Nothing is pruned.
  • Not locked since it should only be manipulated by the process which owns it.
  • Depends on: Kernel heap, physical memory allocator, PAE paging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment