Kernel memory management: where do I begin? -


i'm bit of noob when comes kernel programming, , wondering if point me in right direction beginning implementation of memory management in kernel setting. working on toy kernel , doing lot of research on subject i'm bit confused on topic of memory management. there many different aspects paging , virtual memory mapping. there specific order should implement things or do's , dont's? i'm not looking code or anything, need pointed in right direction. appreciated.

there multiple aspects should consider separately:

  • managing available physical memory.
  • managing memory required kernel , it's data structures.
  • managing virtual memory (space) of every process.
  • managing memory required process, i.e. malloc , free.

to able manage of other memory demands need know how physical memory have available , parts of available use. assuming kernel loaded multiboot compatible boot loader you'll find information in multiboot header passed (in eax on x86 if remember correctly) boot loader. header contains structure describing memory areas used , free use.

you need store information somehow, , keep track of memory allocated , freed. easy method maintain bitmap, bit n indicates whether (fixed size s) memory area n * s (n + 1) * s - 1 used or free. of course want use more sophisticated methods multilevel bitmaps or free lists kernel advances, simple bitmap above can started.

this memory manager provides "large" sized memory chunks, multiples of 4kb. of course of no use dynamic memory allocation in style of malloc , free you're used applications programming.

since dynamic memory allocation ease implementing advanced features of kernel (multitasking, inter process communication, ...) write memory manager kernel. provides means allocation (kalloc) , deallocation (kfree) of arbitrary sized memory chunks. memory pool(s) allocated using physical memory manager above.

all of above happening inside kernel. want provide applications means dynamic memory allocation. implementing similar in concept management of physical memory done above:

a process sees own virtual address space. parts of unusable process (for example area kernel memory mapped into), of "free use" (that is, no physical memory associated it). minimum kernel needs provide applications means allocate , free single pages of memory address space. allocating page results (under hood, invisible application) in call physical memory manager, , in mapping requested page newly allocated memory.

note though many kernels provide processes either more sophisticated access own address space or directly implement of following tasks in kernel.

being able allocate , free pages (4kb mostly) before doesn't dynamic memory management, before handled other memory manager using these large memory chunks pool provide smaller chunks application. prominent example doug lea's allocator. memory managers these implemented library (part of standard library likely) linked every application.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -