← Documents Documentation/admin-guide/mm/soft-dirty.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Memory Management

Soft-Dirty PTEs

PTE soft-dirty bit를 초기화·관찰·판독하는 절차와 page fault 기반 구현, remap 예외를 설명합니다.

Source pathDocumentation/admin-guide/mm/soft-dirty.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

운영 핵심

soft-dirty.rst:1-45

Soft-dirty 추적은 `clear_refs`에 `4`를 기록한 시점 이후 어느 page가 write되었는지 `pagemap` bit 55로 판별합니다. Writable bit를 임시로 지워 최초 write를 #PF로 포착하며, 같은 주소의 unmap/remap도 새 region을 soft-dirty로 표시해 놓치지 않습니다.

관점핵심
목적task가 write한 page를 PTE 단위로 추적
초기화`/proc/PID/clear_refs`에 `4` 기록
판독`/proc/PID/pagemap`의 64-bit entry 중 bit 55 확인
예외 보완unmap 뒤 같은 주소에 새 mapping이 생기면 새 region을 soft-dirty로 표시

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Soft-dirty PTE의 목적

1-6

Soft-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-31

Kernel은 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를 함께 설정하면 됩니다.

Soft-dirty write 추적 흐름
사용자 공간 / taskPTE / kernel
01 `clear_refs`에 `4` 기록soft-dirty=0, writable=0
02 task가 page에 write#PF 발생
03 write 재개physical mapping 확인 후 writable=1, soft-dirty=1
04 `pagemap` bit 55 판독변경된 PTE 식별

초기화 뒤 최초 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일.