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

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

 




On Aug 4, 2006, at 8:25 PM, Rik van Riel wrote:

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.

Ok, so lets say that all of the memory in ZONE_NORMAL and 128MB worth of highmem memory has been mapped by the kernel for kernel usage and user processes. So, basically all of the kernel address space is mapped to used memory. Will the kernel basically then be forced to not "leave the memory mapped into kernel space after it has been given to a user process"? In other words, what happens when another number of pages are needed to satisfy requests for user space applications? I'm guessing the highmem area is reused at the expense of being more expensive to reclaim previously mapped areas later....

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

Thanks for this...I'll take a look

--
"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/





--
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