0
votes

The discussion below applies to 32-bit ARM Linux.

  1. Suppose there are 512MB physical RAM in my system. For common configurations, all these 512MB physical RAM will be mapped via direct mapping by kernel(0xC000 0000 to 0xE000 0000). Question is: kernel itself only uses part of these RAM; most of these RAM would be allocated to user space. Why bother mapping all these 512MB physical RAM in kernel's virtual space(0xC000 0000 to 0xE000 0000)? Why doesn't kernel just map part of these RAM for its only usage(say 64MB RAM)?

  2. If physical RAM is greater than 1GB, things get a little complicated. Let's say directly-mapped area is 768MB in size. The result would be 768MB out of 1GB being directly mapped to kernel's virtual space. I guess the rest of the RAM(256MB) goes to two places: either high memory area or allocated by kernel to user space. But I still don't see any advantage of mapping so many physical RAM into kernel's virtual space.

1

1 Answers

3
votes

Actually this question can be reduced to: what are the drawbacks if kernel only directly maps a small part of physical RAM(say 64MB out of 512MB)?

Before further discussion, it is beneficial to know that

  • After MMU is turned on, every address issued by CPU is virtual address.
  • If kernel wants to access ANY address in RAM, a mapping must be set up before the actual access happens.

If kernel only directly maps a small part of physical RAM, the cost is that every time kernel needs to access other parts of RAM, it needs to set up a temporary mapping before accessing that address and torn down that mapping after the access, which is very tedious and low efficiency.

If that mapping is set up in advance and is always there, it saves quite a lot of trouble for kernel.