soft-dirty.txt 1.7 KB

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