{"id":460,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:38","modified_gmt":"2020-08-22T20:26:38","slug":"this-is-the-page-title-toplevel-293","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=460","title":{"rendered":"Swapping Pages In"},"content":{"rendered":"\n<title>Swapping Pages In<\/title>\n<p>\nThe dirty pages saved in the swap files may be needed again, for example when an application\nwrites to an area of virtual memory whose contents are held in a swapped out physical page.\nAccessing a page of virtual memory that is not held in physical memory causes a page fault to occur.\nThe page fault is the processor signalling the operating system that it cannot translate\na virtual address into a physical one.\nIn this case this is because the page table entry describing this page of virtual memory was\nmarked as invalid when the page was swapped out.\nThe processor cannot handle the virtual to physical address translation and so hands control\nback to the operating system describing as it does so the virtual address that\nfaulted and the reason for the fault.\nThe format of this information and how the processor passes control to the operating system\nis processor specific.\n<p>\nThe processor specific page fault handling code must locate the <tt>vm_area_struct<\/tt> data structure\nthat describes the area of virtual memory that contains the faulting virtual address.\nIt does this by searching the  <tt>vm_area_struct<\/tt> data structures for this process until it finds the\none containing the faulting virtual address.\nThis is very time critical code and a processes <tt>vm_area_struct<\/tt> data structures are so arranged\nas to make this search take as little time as possible.\n<p>\nHaving carried out the appropriate processor specific actions and found that the faulting virtual\naddress is for a valid area of virtual memory, the page fault processing becomes generic and applicable\nto all processors that Linux runs on.\n<p>\nThe generic page fault handling code looks for the page table entry for the faulting virtual address.\nIf the page table entry it finds is for a swapped out page, Linux must swap the page back into\nphysical memory.\nThe format of the page table entry for a  swapped out page is processor specific but all processors\nmark these pages as invalid and put the information neccessary to locate the page within the swap file\ninto the page table entry.\nLinux needs this information in order to bring the page back into physical memory.\n<p>\nAt this point,\n Linux knows the faulting virtual address and has a page table entry containing\ninformation about where this page has been swapped to.\nThe <tt>vm_area_struct<\/tt> data structure may contain a pointer to a routine which will swap any page\nof the area of virtual memory that it describes back into physical memory.\nThis is its <em>swapin<\/em> operation.\nIf there is a <em>swapin<\/em> operation for this area of virtual memory then Linux will use it.\nThis\n is, in fact, how swapped out System V shared memory pages are\nhandled as it requires special handling because the format of a swapped out System V shared page is a little different\nfrom that of an ordinairy swapped out page.\nThere may not be a <em>swapin<\/em> operation, in which case Linux will assume that this is an\nordinairy page that does not need to be specially handled.\n<p>\nIt allocates a free physical page and reads the swapped out page back from the swap file.\nInformation telling it where in the swap file (and which swap file) is taken from the\nthe invalid page table entry.\n<p>\nIf the access that caused the page fault was not a write access then the page is left in the swap\ncache and its page table entry is not marked as writable.\nIf the page is subsequently written to, another page fault will occur and, at that point, the page is\nmarked as dirty and its entry is removed from the swap cache.\nIf the page is not written to and it needs to be swapped out again, Linux can avoid the write\nof the page to its swap file because the page is already in the swap file.\n<p>\nIf the access that caused the page to be brought in from\nthe swap file was a write operation, this page is removed from the swap cache and its page\ntable entry is marked as both dirty and writable.\n","protected":false},"excerpt":{"rendered":"<p>Swapping Pages In The dirty pages saved in the swap files may be needed again, for example when an application writes to an area of virtual memory whose contents are held in a swapped out physical page. Accessing a page &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=460\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-460","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=460"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/460\/revisions"}],"predecessor-version":[{"id":718,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/460\/revisions\/718"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}