home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / bsd / 11691 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  3.0 KB

  1. Path: sparky!uunet!munnari.oz.au!manuel.anu.edu.au!dubhe.anu.edu.au!sirius.anu.edu.au!not-for-mail
  2. From: paulus@cs.anu.edu.au (Paul Mackerras)
  3. Newsgroups: comp.unix.bsd
  4. Subject: Bug + fix: page leak in VM system
  5. Date: 22 Jan 1993 15:19:37 +1100
  6. Organization: Computer Science Department, ANU, Australia
  7. Lines: 74
  8. Message-ID: <1jnskpINN2a0@sirius.anu.edu.au>
  9. NNTP-Posting-Host: sirius.anu.edu.au
  10. Keywords: VM system, bug, memory leak
  11.  
  12. I have found a bug in the new Mach-derived VM system in BSD Unix (as
  13. in the NET/2 release and 386BSD) which causes it to lose physical
  14. pages, resulting in less memory for running programs and increased
  15. likelihood of thrashing.
  16.  
  17. The bug is that the call to vm_page_deactivate() at line 531 of
  18. vm_fault.c does not put the (now no longer needed) page back on the
  19. inactive list, because vm_page_deactivate() only does anything with
  20. active pages.  Consequently, the page is then not on the active,
  21. inactive or free lists and is effectively not available for use.  (It
  22. is not lost forever, though, because it is still on its object's page
  23. queue.)
  24.  
  25. The situation where this occurs is basically the following:
  26.     1. A process has a copy-on-write mapping, e.g. to the data
  27.        segment of an executable file.
  28.     2. The process reads a page in the copy-on-write region.
  29.        The VM system allocates a page and reads in the data from
  30.        the file.
  31.     3. The process writes to the page.  The VM system allocates
  32.        a second page, copies the first page to it, and then
  33.        loses the first page :-(.
  34.  
  35. The following patch corrects the problem.
  36.  
  37. Paul Mackerras
  38. Dept. Computer Science,
  39. Australian National University.
  40. paulus@cs.anu.edu.au
  41.  
  42. -----------------------------------------------------------------------------
  43. *** vm_page-orig.c    Fri Jan 22 09:54:01 1993
  44. --- vm_page.c    Fri Jan 22 09:52:51 1993
  45. ***************
  46. *** 687,701 ****
  47.       /*
  48.        *    Only move active pages -- ignore locked or already
  49.        *    inactive ones.
  50.        */
  51.   
  52. !     if (m->active) {
  53.           pmap_clear_reference(VM_PAGE_TO_PHYS(m));
  54. !         queue_remove(&vm_page_queue_active, m, vm_page_t, pageq);
  55.           queue_enter(&vm_page_queue_inactive, m, vm_page_t, pageq);
  56. -         m->active = FALSE;
  57.           m->inactive = TRUE;
  58. -         vm_page_active_count--;
  59.           vm_page_inactive_count++;
  60.           if (pmap_is_modified(VM_PAGE_TO_PHYS(m)))
  61.               m->clean = FALSE;
  62. --- 687,708 ----
  63.       /*
  64.        *    Only move active pages -- ignore locked or already
  65.        *    inactive ones.
  66. +      *
  67. +      *    XXX: sometimes we get pages which aren't wired down
  68. +      *    or on any queue - we need to put them on the inactive
  69. +      *    queue also, otherwise we lose track of them.
  70. +      *    Paul Mackerras (paulus@cs.anu.edu.au) 9-Jan-93.
  71.        */
  72.   
  73. !     if (!m->inactive && m->wire_count == 0) {
  74.           pmap_clear_reference(VM_PAGE_TO_PHYS(m));
  75. !         if (m->active) {
  76. !             queue_remove(&vm_page_queue_active, m, vm_page_t, pageq);
  77. !             m->active = FALSE;
  78. !             vm_page_active_count--;
  79. !         }
  80.           queue_enter(&vm_page_queue_inactive, m, vm_page_t, pageq);
  81.           m->inactive = TRUE;
  82.           vm_page_inactive_count++;
  83.           if (pmap_is_modified(VM_PAGE_TO_PHYS(m)))
  84.               m->clean = FALSE;
  85.  
  86.