cvs commit: src/sys/vm vm_page.c

Alan Cox alc at
Fri Jun 6 18:38:56 UTC 2008

alc         2008-06-06 18:38:43 UTC

  FreeBSD src repository

  Modified files:
    sys/vm               vm_page.c 
  SVN rev 179623 on 2008-06-06 18:38:43Z by alc
  Essentially, neither madvise(..., MADV_DONTNEED) nor madvise(..., MADV_FREE)
  work.  (Moreover, I don't believe that they have ever worked as intended.)
  The explanation is fairly simple.  Both MADV_DONTNEED and MADV_FREE perform
  vm_page_dontneed() on each page within the range given to madvise().  This
  function moves the page to the inactive queue.  Specifically, if the page is
  clean, it is moved to the head of the inactive queue where it is first in
  line for processing by the page daemon.  On the other hand, if it is dirty,
  it is placed at the tail.  Let's further examine the case in which the page
  is clean.  Recall that the page is at the head of the line for processing by
  the page daemon.  The expectation of vm_page_dontneed()'s author was that
  the page would be transferred from the inactive queue to the cache queue by
  the page daemon.  (Once the page is in the cache queue, it is, in effect,
  free, that is, it can be reallocated to a new vm object by vm_page_alloc()
  if it isn't reactivated quickly enough by a user of the old vm object.)  The
  trouble is that nowhere in the execution of either MADV_DONTNEED or
  MADV_FREE is either the machine-independent reference flag (PG_REFERENCED)
  or the reference bit in any page table entry (PTE) mapping the page cleared.
  Consequently, the immediate reaction of the page daemon is to reactivate the
  page because it is referenced.  In effect, the madvise() was for naught.
  The case in which the page was dirty is not too different.  Instead of being
  laundered, the page is reactivated.
  Note: The essential difference between MADV_DONTNEED and MADV_FREE is
  that MADV_FREE clears a page's dirty field.  So, MADV_FREE is always
  executing the clean case above.
  This revision changes vm_page_dontneed() to clear both the machine-
  independent reference flag (PG_REFERENCED) and the reference bit in all PTEs
  mapping the page.
  MFC after:      6 weeks
  Revision  Changes    Path
  1.371     +7 -0      src/sys/vm/vm_page.c

More information about the cvs-src mailing list