For example, the executable instructions of an image will never be modified by the image and so will never be written to the swap file. Once the process to swap has been located, the swap daemon looks through all of its virtual memory regions looking for areas which are not shared or locked. The swap algorithm uses page aging. The default action when a page is first allocated, is to give it an initial age of 3. Each time the Kernel swap daemon runs it ages pages, decrementing their age by 1.
Dirty pages are pages which can be swapped out.
However, not all dirty pages are neccessarily written to the swap file. Otherwise, the swap daemon will allocate a page in the swap file and write the page out to that device. If the swap file is used, the page's Page Table Entry is replaced by one which is marked as invalid but which contains information about where the page is in the swap file. The PTEs for these pages are made invalid. These pages will be re-read from the executable image running when the process attempts to access them.