{"id":453,"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:00","modified_gmt":"2020-08-22T20:26:00","slug":"this-is-the-page-title-toplevel-286","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=453","title":{"rendered":"Demand Paging"},"content":{"rendered":"\n<title>Demand Paging<\/title>\n<p>\nOnce an executable image has been memory mapped into a process&#8217; virtual memory it\ncan start to execute.\nAs only the very start of the image is physically pulled into memory it will soon access an area\nof virtual memory that is not yet in physical memory.\nWhen a process accesses a virtual address that does not have a valid page table\nentry, the processor will report a page fault to Linux.\n<p>\nThe page fault describes the virtual address where the page fault occurred and the type\nof memory  access that caused the fault.\nLinux must find the area of memory in which the page fault occurred in. This is\ndone through the <tt>vm_area_struct<\/tt> kernel data structure.\nAs searching through the <tt>vm_area_struct<\/tt> data structures is critical to the efficient\nhandling of page faults, these are linked together in an AVL\n(Adelson-Velskii and Landis) tree structure.\n(An AVL tree structure is a balanced binary search tree where the height of the two\nsubtrees (children) of a node differs by at most one, thus optimizing searches.)\nIf there is no <tt>vm_area_struct<\/tt> data structure for this faulting virtual address,\nthis process has accessed an illegal virtual address.\nLinux will signal the process, sending a <tt>SIGSEGV<\/tt> signal and if the process does not\nhave a handler for that signal it will be terminated.\n<p>\nLinux next checks the type of page fault that occurred against the types of accesses\nallowed for this area of virtual memory.\nIf the process is accessing the memory in an illegal way, say writing to an area that it\nis only allowed to read from, it is also signalled with a memory error.\n<p>\nNow that Linux has determined that the page fault is legal, it must deal with it.\n<p>\nLinux must differentiate between pages that are in the swap file and those that are part\nof an executable image on a disk somewhere.\nIt does this by using the page table entry for this faulting virtual address.\n<p>\nIf the page&#8217;s page table entry is invalid but not empty, the page fault is for a page\ncurrently being held in the swap file.\nFor Alpha AXP&nbsp;page table entries, these are entries which do not have their valid bit set\nbut which have a non-zero value in their PFN field.\nIn this case the PFN field holds information about where in the swap (and which swap\nfile) the page is being held.\nHow pages in the swap file are handled is described later in this chapter.\n<p>\nNot all <tt>vm_area_struct<\/tt> data structures have a set of virtual memory operations and even\nthose that do may not have a <em>nopage<\/em> operation.\nThis is because by default Linux will fix up the access by allocating a new physical page and\ncreating a valid page table entry for it.\nIf there is a <em>nopage<\/em> operation for this area of virtual memory, Linux will use it.\n<p>\nThe generic Linux <em>nopage<\/em> operation\n is used for\nmemory mapped executable images and it uses the page cache to bring the required image\npage into physical memory.\n<p>\nHowever the required page is brought into physical memory, the process&#8217; page tables are updated.\nIt may be necessary for hardware specific actions to update those entries, particularly if\nthe processor uses translation look aside buffers.\nNow that the page fault has been handled it can be dismissed and the process is restarted\nat the instruction that made the faulting virtual memory access.\n<p>\n","protected":false},"excerpt":{"rendered":"<p>Demand Paging Once an executable image has been memory mapped into a process&#8217; virtual memory it can start to execute. As only the very start of the image is physically pulled into memory it will soon access an area of &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=453\">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-453","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/453","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=453"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/453\/revisions"}],"predecessor-version":[{"id":536,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/453\/revisions\/536"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}