When a process accesses a page not in the main memory but in the swap space, a page fault happens, and the pager reads a page from swap space to main memory.

Is the read a move or copy? In other words, is there still a copy of the page in the swap space?

If it is a copy, does it mean that the pager has to update the copy in the swap space whenever there is a change to the copy of the page in the main space?


Operating System Concepts says:

  1. We find a free frame (by taking one from the free-frame list, for example).

  2. We schedule a disk operation to read the desired page into the newly allocated frame.

and this figure also shows copies of some pages (A, C and F) are in both swap space and main memory, and no page only exists in main memory but not in swap space:

enter image description here

1 Answer 1


It copies the page. That way should the page need to be discarded (i.e. the system needs to free up memory for other pages) and the page has not been modified, it doesn't need to be rewritten again to swap before discarding it.

Conceptually it's fine to think of the page as being moved back and forth, just recognize that the kernel is doing things like caching behind the scenes to minimize the amount of actual disk I/O being done.

  • Thanks. Could you provide some reference to back up your reply? Is it a disadvantage that you have to update the copy in the swap space? How is the advantage you gave weighed against the disadvantage?
    – Tim
    Oct 10, 2018 at 19:27
  • 2
    @Tim The best reference I could find is thegeekstuff.com/2012/02/linux-memory-swap-cache-shared-vm (see the section titled 'Linux Swap Cache') Disk I/O is a relatively slow operation (even with SSDs) compared to memory from the CPU's perspective so any unnecessary disk reads or writes are to be avoided. This is especially true with swap space (see en.wikipedia.org/wiki/Paging#Swap_death)
    – blihp
    Oct 10, 2018 at 21:03
  • @Tim the link given above also addresses your concern about updating copies of pages in swap: that doesn’t happen, if a page is modified then its copy in swap is discarded (which doesn’t involve writing to disk). Oct 11, 2018 at 5:27
  • @StephenKitt "if a page is modified then its copy in swap is discarded". Is a modified page written to swap, if and only if it is selected by the page replacement algorithm to handle a page fault?
    – Tim
    Oct 12, 2018 at 2:49

You must log in to answer this question.

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