Results 1 to 1 of 1
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Jun 2010
Questions about Linux Kernel Memory Management
I find the memory management the hardest to understand and I have some questions that someone in this forum might be able to answer for me? I have tried reading more books and articles and can just not find answers that I'm happy with.
(note all these questions assume 32-bit system with no PAE support)
1. I understand that a process has a 4GB virtual address space, and when the OS switches processes it switches the page table that its referencing so that a particular virtual address points to the right physical address. I also know that the top 1GB of virtual address space is reserved for the kernel that can only be accessed when the process is in kernel mode.
Why is this necessary to have? Why can't the OS just have a separate page table for itself so that the OS can address 4GB of memory?
All addresses must be virtual when running in protected mode, I guess I'm confused on how the OS manages its own virtual memory space.
2. I understand that the first 16MB of physical memory is in the DMA zone, then from 16-896MB is the normal zones, and higher than 896 is the high memory zone.
Why 896MB? is this arbitrary?
3. I have read that the kernel itself is not "pageable" or "swappable" i.e. it will never be swapped out of physical RAM to the swap space on the disk. This makes sense to me because the kernel had code for dealing with swapping in and out and if that code is on the disk that makes sort of a difficult situation. I have read the kernel code itself is about 3MB? And its in the very low region of physical memory. Is the fact that the kernel is not swappable refer to just the code part of the Linux kernel or all data structures?
This confuses me because I understand that there is the kernel can address up to 1GB of memory, but it cannot possibly make 1GB of memory "not swappable" because many PCs don't even have that much memory, so other processes memory could never be moved into physical RAM.
4. I understand that the kernel virtual address space a subset of those virtual addresses are known as "kernel logical addresses" and they have the property of always being mapped to physically contiguous frames in memory. Is the "kernel logical addresses" that first 896MB? Or am I confused? Also, many PCs have less than 896MB of memory, so how does this work? kernel logical address at 750MB cannot be possibly mapped to physical address 750MB in that case.
5. I'm having a hard time understand the relationship between kmalloc, vmalloc, get_free_page , and the slab allocator. I get that kmaloc returns "kernel logical addresses" so that the memory it allocates are physically contiguous in memory. So that means it returns memory in the first 896MB of physical memory only correct? D
and vmalloc returns a kernel virtual address but the block of memory it reserves are not necessarily contiguous in physical memory right. Is this returned in the 896MB-1GB region of physical memory?
Do kmalloc and vmalloc return memory that is ALWAYS currently in physical memory? Or could it be on the disk in the swap space?
Are these two functions only used for data structures for the OS and not user space processes? If so, I'm confused on how a process grows its stack space or uses malloc, how does the OS handle that internally?
I know that there is get_free_page function that gets a free page, what is this doing exactly? Allocating a page frame? (ie. reserving a frame in physical memory to put a page of data) How does this relate to kmalloc and vmalloc? Do kmalloc and vmalloc use this internally?
Sorry, I know this is a lot of questions, if you only want to answer 1 or 2 that is fine as well of course! Thanks for any help you can give me.