yjxqwed wrote:I'm currently developing a simple kernel. And my current focus is the memory management (mm) subsystem. To design a mm, I read some materials about Linux. However, I'm confused

:
1. Why does Linux kernel define the NORMAL ZONE, which is directly mapped (linear address = physical address + PAGE_OFFSET)? Is it just for efficiency?
I think it's largely historical. Linux was designed in 1991, when 16MB would have been a large amount of memory for a consumer level machine, and UNIX workstations topped out at maybe 64MB or 128MB.
At the time, 896MB of memory was huge, and it seemed perfectly reasonable to map in 64MB of physical RAM its entirety in one place to make working with physical memory easier.
The Linux model is probably not a good model to emulate.
yjxqwed wrote:
2. Does Linux kernel occupy the low 896M physical memory after initialized? If not, how can the kernel guarantee that the NORMAL ZONE is directly mapped? If so, what physical memory will be used for the user processes if the machine has memory less than 896M?
Linux just maps the low 896MB of memory as a convenience. It gives nice, easy access to certain physical pages with a convenient mapping between virtual and physical addresses. It there makes code that works with physical buffers, like device drivers, a simpler time translating between virtual and physical memory addresses, allowing a simple offset to go from one to the other.
This gives a simple overview.
But all the pages in the memory can be used for any purpose, including user pages. Its just those pages will have multiple mappings (the kernel direct mapping + any user mappings.)
yjxqwed wrote:
Do you have good memory management subsystem development tutorials?
Many thanks!
NetBSD UVM is well documented.
Of course, not in the form of a tutorial, but UVM is a nice, clean, virtual memory system, and I personally prefer how UVM splits machine independent from the machine dependent parts compared to Linux's method of defining an abstract machine independent page table structure.
My own hobby kernel uses a system more like UVM than Linux's abstract page table, using what is basically a virtual-TLB like API.
But for virtual memory, I find text books tend to be better than online resources.