1

I'm trying to learn more about the swapping system of the linux kernel.

I figured out that if a r/o or a code part of a binary in memory needs to get swapped, it shouldn't be moved to the swap file/partition, because it is already backed by a file in the disk.

Does it actually works that way? pages from r/o or rx allocations backed by a file gets swapped to the dedicated file? If so, can someone please point me to the code that handles this? I can't seem to find it

1 Answer 1

1

Yes, it works that way. Pages whose content is available on disk are discarded, they don’t even need to be swapped to “the dedicated file”. Dirty pages with a non-swap backing store (e.g., memory-mapped files) are written out to that backing store. Swap is only used for evictable pages with no backing store.

Most of the time this is handled by kswapd, doing what is known as reclaim:

It will asynchronously scan memory pages and either just free them if the data they contain is available elsewhere, or evict to the backing storage device (remember those dirty pages?).

See mm/vmscan.c for the implementation.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .