Back to home page

OSCL-LXR

 
 

    


0001 .. _soft_dirty:
0002 
0003 ===============
0004 Soft-Dirty PTEs
0005 ===============
0006 
0007 The soft-dirty is a bit on a PTE which helps to track which pages a task
0008 writes to. In order to do this tracking one should
0009 
0010   1. Clear soft-dirty bits from the task's PTEs.
0011 
0012      This is done by writing "4" into the ``/proc/PID/clear_refs`` file of the
0013      task in question.
0014 
0015   2. Wait some time.
0016 
0017   3. Read soft-dirty bits from the PTEs.
0018 
0019      This is done by reading from the ``/proc/PID/pagemap``. The bit 55 of the
0020      64-bit qword is the soft-dirty one. If set, the respective PTE was
0021      written to since step 1.
0022 
0023 
0024 Internally, to do this tracking, the writable bit is cleared from PTEs
0025 when the soft-dirty bit is cleared. So, after this, when the task tries to
0026 modify a page at some virtual address the #PF occurs and the kernel sets
0027 the soft-dirty bit on the respective PTE.
0028 
0029 Note, that although all the task's address space is marked as r/o after the
0030 soft-dirty bits clear, the #PF-s that occur after that are processed fast.
0031 This is so, since the pages are still mapped to physical memory, and thus all
0032 the kernel does is finds this fact out and puts both writable and soft-dirty
0033 bits on the PTE.
0034 
0035 While in most cases tracking memory changes by #PF-s is more than enough
0036 there is still a scenario when we can lose soft dirty bits -- a task
0037 unmaps a previously mapped memory region and then maps a new one at exactly
0038 the same place. When unmap is called, the kernel internally clears PTE values
0039 including soft dirty bits. To notify user space application about such
0040 memory region renewal the kernel always marks new memory regions (and
0041 expanded regions) as soft dirty.
0042 
0043 This feature is actively used by the checkpoint-restore project. You
0044 can find more details about it on http://criu.org
0045 
0046 
0047 -- Pavel Emelyanov, Apr 9, 2013