요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
===============
Soft-Dirty PTEs
===============
The soft-dirty is a bit on a PTE which helps to track which pages a task
writes to. In order to do this tracking one should
1. Clear soft-dirty bits from the task's PTEs.
This is done by writing "4" into the ``/proc/PID/clear_refs`` file of the
task in question.
2. Wait some time.
3. Read soft-dirty bits from the PTEs.
This is done by reading from the ``/proc/PID/pagemap``. The bit 55 of the
64-bit qword is the soft-dirty one. If set, the respective PTE was
written to since step 1.
Internally, to do this tracking, the writable bit is cleared from PTEs
when the soft-dirty bit is cleared. So, after this, when the task tries to
modify a page at some virtual address the #PF occurs and the kernel sets
the soft-dirty bit on the respective PTE.
Note, that although all the task's address space is marked as r/o after the
soft-dirty bits clear, the #PF-s that occur after that are processed fast.
This is so, since the pages are still mapped to physical memory, and thus all
the kernel does is finds this fact out and puts both writable and soft-dirty
bits on the PTE.
While in most cases tracking memory changes by #PF-s is more than enough
there is still a scenario when we can lose soft dirty bits -- a task
unmaps a previously mapped memory region and then maps a new one at exactly
the same place. When unmap is called, the kernel internally clears PTE values
including soft dirty bits. To notify user space application about such
memory region renewal the kernel always marks new memory regions (and
expanded regions) as soft dirty.
This feature is actively used by the checkpoint-restore project. You
can find more details about it on http://criu.org
-- Pavel Emelyanov, Apr 9, 2013
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Soft-dirty PTE의 목적
1-6Soft-dirty는 task가 어느 page에 write했는지 추적하는 데 쓰이는 PTE bit입니다. 이 추적은 soft-dirty bit를 초기화하고, 관찰 시간을 둔 뒤, PTE의 bit를 다시 읽는 순서로 수행합니다.
사용자 공간 추적 절차
7-20| 단계 | 사용자 공간 동작 | 의미 |
|---|---|---|
| 1 | `/proc/PID/clear_refs`에 `4` 기록 | task의 PTE에서 soft-dirty bit를 지움 |
| 2 | 일정 시간 대기 | 관찰 구간 동안 task의 write를 허용 |
| 3 | `/proc/PID/pagemap` 판독 | 64-bit qword의 bit 55로 step 1 이후 write 여부 확인 |
1. 대상 task의 `/proc/PID/clear_refs` file에 `4`를 기록해 task의 PTE에서 soft-dirty bit를 지웁니다.
2. 변경을 관찰할 시간을 둡니다.
3. `/proc/PID/pagemap`에서 PTE의 soft-dirty bit를 읽습니다. 각 64-bit qword의 bit 55가 soft-dirty bit이며, 이 bit가 설정되어 있으면 해당 PTE는 step 1 이후 write된 것입니다.
Kernel 내부 동작
21-31Kernel은 soft-dirty bit를 지울 때 PTE의 writable bit도 함께 지웁니다. 그 뒤 task가 어떤 virtual address의 page를 수정하려 하면 #PF가 발생하고, kernel은 해당 PTE에 soft-dirty bit를 설정합니다.
Soft-dirty bit를 지운 직후에는 task의 전체 address space가 read-only로 표시되지만, 이후 발생하는 #PF는 빠르게 처리됩니다. Page가 여전히 physical memory에 mapping되어 있으므로 kernel은 그 사실만 확인한 뒤 PTE에 writable bit와 soft-dirty bit를 함께 설정하면 됩니다.
초기화 뒤 최초 write에서 발생한 page fault가 writable과 soft-dirty 상태를 복구하고, 사용자 공간은 pagemap bit 55로 변경 page를 식별합니다.
Unmap과 동일 주소 remap 예외
32-39대부분의 경우 #PF를 이용한 memory 변경 추적으로 충분하지만 soft-dirty bit를 잃을 수 있는 경우가 있습니다. Task가 기존에 mapping된 memory region을 unmap한 뒤 정확히 같은 위치에 새 region을 mapping하면, unmap 과정에서 kernel이 soft-dirty bit를 포함한 PTE 값을 내부적으로 지웁니다.
이러한 memory region 갱신을 사용자 공간 application에 알리기 위해 kernel은 새 memory region과 확장된 region을 항상 soft-dirty로 표시합니다.
Checkpoint/restore 사용처
40-45이 기능은 checkpoint-restore project에서 적극적으로 사용합니다. 자세한 내용은 `http://criu.org`에서 확인할 수 있습니다.
저자: Pavel Emelyanov, 2013년 4월 9일.
운영 핵심
soft-dirty.rst:1-45Soft-dirty 추적은 `clear_refs`에 `4`를 기록한 시점 이후 어느 page가 write되었는지 `pagemap` bit 55로 판별합니다. Writable bit를 임시로 지워 최초 write를 #PF로 포착하며, 같은 주소의 unmap/remap도 새 region을 soft-dirty로 표시해 놓치지 않습니다.