Only a few kinds of pages may be swapped out to a swap area — all others have an alternative backing storage on a block device that is used instead:
□ Pages of the map_anonymous category that are not associated with a file (or are a mapping of /dev/zero); for example, a process stack or memory area mapped anonymously using mmap. (The reference manual on the GNU C standard library or the customary standard reference works on system programming provide further information on mappings of this kind.)
□ Private mappings of a process used to map files in which changes are not written to the underlying block device, as would normally be the case. As the file is no longer available as a backing store in this case, the pages must be swapped out to the swap area if RAM memory becomes scarce since the contents can no longer be restored from the file. The kernel (and therefore the C standard library) uses the map_private flag to create mappings of this type.
□ All pages that belong to the process heap and were reserved using malloc (and consequently using the brk system call or ultimately an anonymous mapping); see Chapter 3
□ Pages that are used to implement one of the interprocess communication mechanisms. These include, for instance, shared memory pages that are used to exchange data between processes.
Memory pages used by the kernel itself are never swapped out. The reasons are obvious. The complexity of the kernel code would increase dramatically. Since the kernel does not require very much memory as compared to other user applications, the potential gain is too low to justify the additional effort.
Naturally, pages used to map peripherals to memory space cannot be swapped out either. This would make no sense, especially as the pages are used only as a means of communication between the application and the device and not for actually storing data persistently.
Even though it is not possible to swap out all page types, the kernel's swapping page reclaim must still cater to page types that are based on other backing stores. The most frequent page types of this kind relate to data from files that are mapped into memory. Ultimately, it is irrelevant which pages from which category are written from RAM memory to backing store because the effect is always the same — a page frame is freed to make space for more important data that must reside in the RAM.
Continue reading here: Page Thrashing
Was this article helpful?