Question

Are .text pages in a process' memory swapped-out, or is it just the pages containing data (heap) that are swapped-out?

Here by "swapped-out" I refer to 'being swapped to the swap area' and not 'mere eviction from primary memory'. My doubt is whether the .text pages are merely evicted and then read from the HDD as they are never to be modified (unlike data pages), or are they swapped to swap area.

So also, is a page belonging to stack swapped-out?

Can anyone please provide more clarity on what pages in the virtual memory of a process are considered for swapping, and which ones are never?

Was it helpful?

Solution

All pages in the end are considered for being swapped out. In Linux it starts by swapping out freeing cache pages followed by clean non-recently used pages (which just requires unmapping rather than a write to the swap device). After this it will try to flush dirty file backed pages in memory to their respective backing device before finally reaching the point where it must starts swapping anonymously backed process pages (includes stack, data that can be edited, heap, etc....). Any non-kernel page is always a candidate for being swapped out it just depends on the memory pressure on the system.

Pages that already have a backing store are simply unmapped or if they are dirty are flushed to their backing store. They are not written to swap for obvious reasons.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top