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

Linux 6.18.37 · Administration / Memory Management

Idle Page Tracking

PFN bitmap으로 workload의 idle page와 working set을 측정하고 Idle·Young flag가 reclaimer와 협력하는 방식을 설명합니다.

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

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

1. 요약·해설

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

Idle page tracking 흐름

idle_page_tracking.rst:1-118

Workload page를 idle로 표시하고 실제 실행 뒤에도 idle인 page를 세어 working set 바깥의 memory를 추정합니다. PFN bitmap 정렬, huge page head flag, page type과 LRU 제약을 함께 고려해야 정확합니다.

영역interface·조건
EnableCONFIG_IDLE_PAGE_TRACKING=y
Interface/sys/kernel/mm/page_idle/bitmap
Page discovery/proc/pid/pagemap 또는 /proc/kpagecgroup
Type filtering/proc/kpageflags
Helpertools/mm/page-types

2. 영어 원문 전체

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

원문 전체 펼치기
1 ==================
2 Idle Page Tracking
3 ==================
4
5 Motivation
6 ==========
7
8 The idle page tracking feature allows to track which memory pages are being
9 accessed by a workload and which are idle. This information can be useful for
10 estimating the workload's working set size, which, in turn, can be taken into
11 account when configuring the workload parameters, setting memory cgroup limits,
12 or deciding where to place the workload within a compute cluster.
13
14 It is enabled by CONFIG_IDLE_PAGE_TRACKING=y.
15
16 .. _user_api:
17
18 User API
19 ========
20
21 The idle page tracking API is located at ``/sys/kernel/mm/page_idle``.
22 Currently, it consists of the only read-write file,
23 ``/sys/kernel/mm/page_idle/bitmap``.
24
25 The file implements a bitmap where each bit corresponds to a memory page. The
26 bitmap is represented by an array of 8-byte integers, and the page at PFN #i is
27 mapped to bit #i%64 of array element #i/64, byte order is native. When a bit is
28 set, the corresponding page is idle.
29
30 A page is considered idle if it has not been accessed since it was marked idle
31 (for more details on what "accessed" actually means see the :ref:`Implementation
32 Details <impl_details>` section).
33 To mark a page idle one has to set the bit corresponding to
34 the page by writing to the file. A value written to the file is OR-ed with the
35 current bitmap value.
36
37 Only accesses to user memory pages are tracked. These are pages mapped to a
38 process address space, page cache and buffer pages, swap cache pages. For other
39 page types (e.g. SLAB pages) an attempt to mark a page idle is silently ignored,
40 and hence such pages are never reported idle.
41
42 For huge pages the idle flag is set only on the head page, so one has to read
43 ``/proc/kpageflags`` in order to correctly count idle huge pages.
44
45 Reading from or writing to ``/sys/kernel/mm/page_idle/bitmap`` will return
46 -EINVAL if you are not starting the read/write on an 8-byte boundary, or
47 if the size of the read/write is not a multiple of 8 bytes. Writing to
48 this file beyond max PFN will return -ENXIO.
49
50 That said, in order to estimate the amount of pages that are not used by a
51 workload one should:
52
53 1. Mark all the workload's pages as idle by setting corresponding bits in
54 ``/sys/kernel/mm/page_idle/bitmap``. The pages can be found by reading
55 ``/proc/pid/pagemap`` if the workload is represented by a process, or by
56 filtering out alien pages using ``/proc/kpagecgroup`` in case the workload
57 is placed in a memory cgroup.
58
59 2. Wait until the workload accesses its working set.
60
61 3. Read ``/sys/kernel/mm/page_idle/bitmap`` and count the number of bits set.
62 If one wants to ignore certain types of pages, e.g. mlocked pages since they
63 are not reclaimable, he or she can filter them out using
64 ``/proc/kpageflags``.
65
66 The page-types tool in the tools/mm directory can be used to assist in this.
67 If the tool is run initially with the appropriate option, it will mark all the
68 queried pages as idle. Subsequent runs of the tool can then show which pages have
69 their idle flag cleared in the interim.
70
71 See Documentation/admin-guide/mm/pagemap.rst for more information about
72 ``/proc/pid/pagemap``, ``/proc/kpageflags``, and ``/proc/kpagecgroup``.
73
74 .. _impl_details:
75
76 Implementation Details
77 ======================
78
79 The kernel internally keeps track of accesses to user memory pages in order to
80 reclaim unreferenced pages first on memory shortage conditions. A page is
81 considered referenced if it has been recently accessed via a process address
82 space, in which case one or more PTEs it is mapped to will have the Accessed bit
83 set, or marked accessed explicitly by the kernel (see mark_page_accessed()). The
84 latter happens when:
85
86 - a userspace process reads or writes a page using a system call (e.g. read(2)
87 or write(2))
88
89 - a page that is used for storing filesystem buffers is read or written,
90 because a process needs filesystem metadata stored in it (e.g. lists a
91 directory tree)
92
93 - a page is accessed by a device driver using get_user_pages()
94
95 When a dirty page is written to swap or disk as a result of memory reclaim or
96 exceeding the dirty memory limit, it is not marked referenced.
97
98 The idle memory tracking feature adds a new page flag, the Idle flag. This flag
99 is set manually, by writing to ``/sys/kernel/mm/page_idle/bitmap`` (see the
100 :ref:`User API <user_api>`
101 section), and cleared automatically whenever a page is referenced as defined
102 above.
103
104 When a page is marked idle, the Accessed bit must be cleared in all PTEs it is
105 mapped to, otherwise we will not be able to detect accesses to the page coming
106 from a process address space. To avoid interference with the reclaimer, which,
107 as noted above, uses the Accessed bit to promote actively referenced pages, one
108 more page flag is introduced, the Young flag. When the PTE Accessed bit is
109 cleared as a result of setting or updating a page's Idle flag, the Young flag
110 is set on the page. The reclaimer treats the Young flag as an extra PTE
111 Accessed bit and therefore will consider such a page as referenced.
112
113 Since the idle memory tracking feature is based on the memory reclaimer logic,
114 it only works with pages that are on an LRU list, other pages are silently
115 ignored. That means it will ignore a user memory page if it is isolated, but
116 since there are usually not many of them, it should not affect the overall
117 result noticeably. In order not to stall scanning of the idle page bitmap,
118 locked pages may be skipped too.
119

3. 한국어 전문 번역

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

목적과 활성화

1-15

Idle page tracking은 workload가 접근하는 memory page와 idle 상태인 page를 구분합니다. 이 정보로 working set size를 추정하면 workload parameter, memory cgroup limit, compute cluster 배치 결정을 더 정확하게 할 수 있습니다.

Kernel은 `CONFIG_IDLE_PAGE_TRACKING=y`로 빌드해야 이 기능을 사용할 수 있습니다.

bitmap user API

16-48

User API는 `/sys/kernel/mm/page_idle`에 있으며 현재 read-write 파일은 `/sys/kernel/mm/page_idle/bitmap` 하나입니다. 각 bit가 physical page 하나에 대응하고 8-byte integer array로 표현되며 byte order는 native입니다.

항목해석
Storage8-byte integer arraynative byte order
PFN #i element#i / 64integer division
PFN #i bit#i % 64해당 element 안의 bit
Bit = 1idleidle로 표시한 뒤 아직 referenced되지 않음

PFN #i는 array element `#i/64`의 bit `#i%64`에 대응합니다. Bit가 set이면 해당 page를 idle로 표시한 뒤 아직 접근되지 않았다는 뜻입니다. 파일에 쓴 값은 현재 bitmap에 OR되므로 page를 idle로 표시하려면 그 page bit를 set해 씁니다.

Process address space에 mapping된 page, page cache와 buffer page, swap cache page 같은 user memory만 추적합니다. SLAB 같은 다른 page type은 idle 표시 요청을 조용히 무시하므로 idle로 보고되지 않습니다.

Huge page는 head page에만 Idle flag를 둡니다. Idle huge page를 정확히 셀 때는 `/proc/kpageflags`로 compound page 구조를 함께 확인해야 합니다.

`bitmap` read/write 시작 offset은 8-byte boundary여야 하고 size도 8의 배수여야 합니다. 그렇지 않으면 `-EINVAL`을 반환하며 max PFN 뒤에 쓰면 `-ENXIO`를 반환합니다.

working set 측정 절차

49-73
단계작업
1. Mark`pagemap` 또는 `kpagecgroup`으로 workload page를 찾고 bitmap bit를 set
2. Observeworkload가 working set에 접근할 시간을 기다림
3. Countbitmap에서 여전히 set인 bit를 세고 필요하면 `kpageflags`로 filter

Process workload라면 `/proc/pid/pagemap`으로 page를 찾고, memory cgroup workload라면 `/proc/kpagecgroup`으로 다른 cgroup page를 걸러서 해당 bitmap bit를 set합니다. Workload가 working set에 접근할 시간을 준 뒤 bitmap을 다시 읽어 아직 set인 bit 수를 셉니다.

mlocked page처럼 reclaim할 수 없는 type을 제외하려면 `/proc/kpageflags`로 filter합니다. `tools/mm`의 `page-types`는 첫 실행에서 query한 page를 idle로 표시하고 후속 실행에서 그 사이 Idle flag가 clear된 page를 보여 주어 이 절차를 돕습니다.

`/proc/pid/pagemap`, `/proc/kpageflags`, `/proc/kpagecgroup` 형식은 `Documentation/admin-guide/mm/pagemap.rst`를 참조합니다.

referenced page 판정

74-96

Kernel reclaimer는 memory 부족 시 unreferenced page를 먼저 회수하려고 user memory 접근을 내부적으로 추적합니다. Process address space를 통해 최근 접근해 mapping PTE의 Accessed bit가 set됐거나 kernel이 `mark_page_accessed()`를 호출한 page를 referenced로 봅니다.

Kernel은 userspace process가 `read(2)`·`write(2)` 같은 system call로 page를 읽거나 쓸 때, filesystem metadata가 든 buffer page를 읽거나 쓸 때, device driver가 `get_user_pages()`로 page에 접근할 때 명시적으로 referenced 표시를 합니다.

Memory reclaim이나 dirty memory limit 초과로 dirty page를 swap 또는 disk에 쓰는 작업 자체는 page를 referenced로 표시하지 않습니다.

Idle·Young flag 구현

97-118

Idle tracking은 새 page flag인 Idle을 사용합니다. `/sys/kernel/mm/page_idle/bitmap`에 써서 수동으로 set하고, 위에서 정의한 방식으로 page가 referenced되면 자동으로 clear합니다.

Page를 idle로 표시할 때 process address space 접근을 다시 감지하려면 모든 mapping PTE의 Accessed bit를 clear해야 합니다. 그러나 reclaimer도 Accessed bit로 active page를 승격하므로 이를 방해하지 않도록 Young page flag를 함께 사용합니다.

Idle flag set 또는 update 때문에 PTE Accessed bit를 clear하면 page의 Young flag를 set합니다. Reclaimer는 Young을 추가 PTE Accessed bit처럼 취급해 그 page를 referenced로 봅니다.

기능이 reclaimer logic에 기반하므로 LRU list에 있는 page만 추적합니다. Isolated user page는 무시되고 bitmap scan을 오래 막지 않도록 locked page도 건너뛸 수 있지만, 보통 수가 적어 전체 결과에는 큰 영향을 주지 않습니다.