After this documentation was released in July 2003, I was approached
by Prentice Hall and asked to write a book on the Linux VM under the Bruce Peren's Open Book Series.
The book is available and called simply "Understanding The Linux Virtual
Memory Manager". There is a lot of additional material in the book that is
not available here, including details on later 2.4 kernels, introductions
to 2.6, a whole new chapter on the shared memory filesystem, coverage of TLB
management, a lot more code commentary, countless other additions and
clarifications and a CD with lots of cool stuff on it. This material (although
now dated and lacking in comparison to the book) will remain available
although I obviously encourge you to buy the book from your favourite book
store :-) . As the book is under the Bruce Perens Open Book Series, it will
be available 90 days after appearing on the book shelves which means it
is not available right now. When it is available, it will be downloadable
from http://www.phptr.com/perens
so check there for more information.
To be fully clear, this webpage is not the actual book.
Next: 8.3 Freeing A Non-Contiguous
Up: 8. Non-Contiguous Memory Allocation
Previous: 8.1 Describing Virtual Memory
  Contents
  Index
The functions vmalloc(), vmalloc_dma() and
vmalloc_32() are provided to allocate a memory area that
is contiguous in virtual address space. They all take a single parameter
size which is rounded up to the next page alignment. They all
return a linear address for the new allocated area.
Figure 8.2:
Call Graph: vmalloc()
|
As is clear from the call graph shown in Figure 8.2, there
are two steps to allocating the area.
The first step with get_vm_area() finds a region large
enough to store the request. It searches through a linear linked list of
vm_structs and returns a new struct describing the allocated
region.
The second step is to allocate the necessary PGD entries with
vmalloc_area_pages(), PMD entries with alloc_area_pmd()
and PTE entries with alloc_area_pte() before finally allocating
the page with alloc_page().
The page table updated by vmalloc() is not the current process but
the master page table referenced by init_mmpgd. This
means that a process accessing the vmalloc area will cause a page fault
exception as its page tables are not pointing to the correct area. There is
a special case in the page fault handling code which knows that the fault
occured in the vmalloc area and updates the current process page tables
using information from the master page table.
Table 8.1:
Non-Contiguous Memory Allocation API
|
Table 8.2:
Non-Contiguous Memory Free API
|
Next: 8.3 Freeing A Non-Contiguous
Up: 8. Non-Contiguous Memory Allocation
Previous: 8.1 Describing Virtual Memory
  Contents
  Index
Mel
2004-02-15