Re: Totally confused about kmap, highmem, and VM in general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Patrick Toomey wrote:
Hello all,
 This is my first post to the kernelnewbie list, so here we go....

You've got some good questions.  Let me try to answer them :)

I am failing to understand why all the physical memory is mapped into
the kernel space up to the highmem mark and the highmem area is then
used to temporarily map additional memory into kernel space.  Is this
done so that the kernel can then use memory that it controls to hand
out to user processes?

The kernel also uses memory for its own data structures, and
often has to access memory to construct network packets, etc...

If so, why does the kernel need these areas of memory mapped into its
virtual address space? It seems like the kernel could keep a list of
all page frames that are available and then use this to map in page frames for userspace memory without ever having it mapped into kernel
memory space.

Besides the "kernel's own data structures" argument, there are
security reasons why the kernel has to clear out a page's data
before mapping the page into user space.

This is more efficiently done if the page is already mapped into
kernel address space, and does not have to be mapped in especially
for the purpose.

The kernel will leave the memory mapped into kernel address space
after it has been given to a user process.  This makes it easier
to process the page in the future, eg. after the process has stopped
using the page.

Then, lets say we have a machine with 1.5GB of memory. The kernel linearly maps 896MB of space into kernel space and the leaves teh remaning 128MB for temporary mappings. When are these temporary mappings done, and for what purpose. Would these temporary mappings take place when user processes require space?

The temporary mappings are done when the kernel needs to access
memory above the 896MB boundary.  The kernel needs to do accesses
when it has to clear out the data in a page before it is given to
userspace, or when userspace calls sendfile(2) and the kernel has
to copy data into or out of the page.  There probably are other
occasions too.

I've got some more documentation on your questions at this URL:

http://linux-mm.org/HighMemory

--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it." - Brian W. Kernighan

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux