Kernel Memory
Kernel
memory is memory which is allocated by kernel at run time. Kernel should use
Heap library to allocate/free memory. However there is a problem in that
because Heap library calls VirtualSpaceAllocate() calls which in turns calls Heap library again.
To
avoid this problem, kernel reserves some memory at boot time. This reserved
memory can be used by Heap to allocate memory in byte granularity to kernel
during boot time.
kmem_reserved_mem_size is a kernel
variable/parameter which holds the number of bytes should reserved to the
kernel during boot. If this variable is not set to any value, a default value
is calculated. The default value is some percentage of system total memory.
(The percentage is configured through the following macro -KMEM_RESERVED_MEM_PERCENTAGE.
The current value is 5).
kmem_page_alloc(),kmem_page_free()
are internal functions used to allocate memory pages to the heap subsystem.
These functions are static and not visible to other subsystems. The
implementation of these functions are very simple, it just calls the VM to
allocate pages and free pages after some sanity checks. In future, these
functions can also log all the activities for debugging purpose.
kmalloc() and kfree() are the only functions exported. These function is
similar to malloc() and free() and need no
introduction.