soft-dirty.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. .. _soft_dirty:
  2. ===============
  3. Soft-Dirty PTEs
  4. ===============
  5. The soft-dirty is a bit on a PTE which helps to track which pages a task
  6. writes to. In order to do this tracking one should
  7. 1. Clear soft-dirty bits from the task's PTEs.
  8. This is done by writing "4" into the ``/proc/PID/clear_refs`` file of the
  9. task in question.
  10. 2. Wait some time.
  11. 3. Read soft-dirty bits from the PTEs.
  12. This is done by reading from the ``/proc/PID/pagemap``. The bit 55 of the
  13. 64-bit qword is the soft-dirty one. If set, the respective PTE was
  14. written to since step 1.
  15. Internally, to do this tracking, the writable bit is cleared from PTEs
  16. when the soft-dirty bit is cleared. So, after this, when the task tries to
  17. modify a page at some virtual address the #PF occurs and the kernel sets
  18. the soft-dirty bit on the respective PTE.
  19. Note, that although all the task's address space is marked as r/o after the
  20. soft-dirty bits clear, the #PF-s that occur after that are processed fast.
  21. This is so, since the pages are still mapped to physical memory, and thus all
  22. the kernel does is finds this fact out and puts both writable and soft-dirty
  23. bits on the PTE.
  24. While in most cases tracking memory changes by #PF-s is more than enough
  25. there is still a scenario when we can lose soft dirty bits -- a task
  26. unmaps a previously mapped memory region and then maps a new one at exactly
  27. the same place. When unmap is called, the kernel internally clears PTE values
  28. including soft dirty bits. To notify user space application about such
  29. memory region renewal the kernel always marks new memory regions (and
  30. expanded regions) as soft dirty.
  31. This feature is actively used by the checkpoint-restore project. You
  32. can find more details about it on http://criu.org
  33. -- Pavel Emelyanov, Apr 9, 2013