{"id":459,"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-292","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=459","title":{"rendered":"Swapping Out System V Shared Memory Pages"},"content":{"rendered":"\n<title>Swapping Out System V Shared Memory Pages<\/title>\n<p>\nSystem V shared memory is an inter-process communication mechanism which allows two or more\nprocesses to share virtual memory in order to pass information amongst themselves.\nHow  processes share memory in this way is described in more detail in\nthe <site id=\"288\">section on inter-process communication<\/site>.\nFor now it is enough to say that each area of System V shared memory is described by\na <tt>shmid_ds<\/tt> data structure.\nThis contains a pointer to a list of <tt>vm_area_struct<\/tt> data structures, one for each process\nsharing this area of virtual memory.\nThe <tt>vm_area_struct<\/tt> data structures describe where in each processes virtual memory this area\nof System V shared memory goes.\nEach <tt>vm_area_struct<\/tt> data structure  for this System V shared memory is linked together using\nthe <tt>vm_next_shared<\/tt> and <tt>vm_prev_shared<\/tt> pointers.\nEach <tt>shmid_ds<\/tt> data structure also contains a list of page table entries each of which describes the\nphysical page that a shared virtual page maps to.\n<p>\nThe kernel swap daemon also uses a <em>clock<\/em> algorithm when swapping out\nSystem V shared memory pages.\nEach time it runs it remembers which page of which shared virtual memory area it last\nswapped out.It does this by keeping two indices, the first is an index into the set\nof <tt>shmid_ds<\/tt> data structures, the second into the list of page table entries\nfor this area of System V shared memory. This makes\nsure that it fairly &#8220;victimizes&#8221; the areas of System V shared memory.\n<p>\nThe kernel swap daemon must modify the page table of every process sharing an area\nof virtual memory to reflect that a page has been moved from memory to the swap file\nbecause the physical page frame number for any given virtual page of System V shared\nmemory is contained in the page tables of all of the processes sharing this area of\nvirtual memory.\nFor each shared page it is swapping out, the kernel swap daemon finds the page table\nentry in each of the sharing process&#8217; page tables (by following a pointer from each <tt>vm_area_struct<\/tt> data structure).\nIf this process&#8217; page table entry for this page of System V shared memory is valid, it converts it into\nan invalid but swapped out page table entry and reduces this (shared) page&#8217;s count of users by one.\nThe format of a swapped out System V shared page table entry contains an index into the set of  <tt>shmid_ds<\/tt>\ndata structures and an index into the page table entries for this area of System V shared memory.\n<p>\nIf the page&#8217;s count is zero after the page tables of the sharing processes have all been modified, the\nshared page can be written out to the swap file.\nThe page table entry in the list pointed at by the\n<tt>shmid_ds<\/tt> data structure for this area of System V shared memory is replaced by a swapped out page\ntable entry.\nA swapped out page table entry is invalid but contains an index into the set of open swap files and the offset\nin that file where the swapped out page can be found.\nThis information will be used when the page has to be brought back into physical memory.\n","protected":false},"excerpt":{"rendered":"<p>Swapping Out System V Shared Memory Pages System V shared memory is an inter-process communication mechanism which allows two or more processes to share virtual memory in order to pass information amongst themselves. How processes share memory in this way &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=459\">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-459","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/459","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=459"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/459\/revisions"}],"predecessor-version":[{"id":717,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/459\/revisions\/717"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}