user31986
user31986

Reputation: 1656

Are .text pages swapped-out?

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?

Upvotes: 1

Views: 497

Answers (2)

stevea
stevea

Reputation: 236

No. Linux does not write pages to swap if that same page exists in storage. ".text" pages, are the program and library code pages that are generally read-only and change on disk infrequently.

When the kernel is recouping dram, it examine LRU pages. If the page exists on disk it merely 'evicts' the page - it marks the page as not present in dram in the MMU, and then re-uses that dram page for other purposes. If the evicted page is later accessed, it will page-fault in from disk.

Upvotes: 0

Jesus Ramos
Jesus Ramos

Reputation: 23266

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.

Upvotes: 1

Related Questions