Библиотека сайта rus-linux.net
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: 12.6 Deactivating a Swap Up: 12. Swap Management Previous: 12.4 Swap Cache   Contents   Index
As it has now been covered what swap areas are, how they are represented and
how pages are tracked, it is time to see how they all tie together to activate
an area. Activating an area is conceptually quite simple; Open the file, load
the header information from disk, populate a
and add it to the swap list.
The function responsible for the activation of a swap area is
sys_swapon() and it takes two parameters, the path to the special
file for the swap area and a set of flags. While swap is been activated, the
Big Kernel Lock (BKL) is held which prevents any application
entering kernel space while this operation is been performed. The function
is quite large but can be broken down into the following simple steps;
- Find a free
swap_infoarray an initialise it with default values
user_path_walk()which traverses the directory tree for the supplied
specialfileand populates a
namidatastructure with the available data on the file, such as the
dentryand the filesystem information for where it is stored (
swap_info_structfields pertaining to the dimensions of the swap area and how to find it. If the swap area is a partition, the block size will be configured to the
PAGE_SIZEbefore calculating the size. If it is a file, the information is obtained directly from the
- Ensure the area is not already activated. If not, allocate a page from
memory and read the first page sized slot from the swap area. This page
contains information such as the number of good slots and how to populate
swap_mapwith the bad entries
- Allocate memory with
swap_mapand initialise each entry with 0 for good slots and
SWAP_MAP_BADotherwise. Ideally the header information will be a version 2 file format as version 1 was limited to swap areas of just under 128MiB for architectures with 4KiB page sizes like the x8612.3
- After ensuring the information indicated in the header
matches the actual swap area, fill in the remaining information in the
swap_info_structsuch as the maximum number of pages and the available good pages. Update the global statistics for
- The swap area is now fully active and initialised and so it is inserted
into the swap list in the correct position based on priority of the newly
At the end of the function, the BKL is released and the system now has a new swap area available for paging to.
Next: 12.6 Deactivating a Swap Up: 12. Swap Management Previous: 12.4 Swap Cache   Contents   Index Mel 2004-02-15
Только зарегистрированные пользователи могут оценивать и комментировать статьи.