← Documents Documentation/virt/kvm/halt-polling.rst GitHub 원문 ↗

Linux 6.18.37 · 가상화 / KVM

KVM halt polling system

게스트 halt 직후의 호스트 폴링, 자동 구간 조정, 모듈 매개변수와 전력·지연 절충을 설명합니다.

Source pathDocumentation/virt/kvm/halt-polling.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

halt-polling.rst:1-153

게스트 halt 직후의 호스트 폴링, 자동 구간 조정, 모듈 매개변수와 전력·지연 절충을 설명합니다.

원문 기호, 함수명, 경로, 레지스터와 줄 좌표를 유지하면서 동작 순서와 경쟁 조건을 한국어로 풀어 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===========================
4 The KVM halt polling system
5 ===========================
6
7 The KVM halt polling system provides a feature within KVM whereby the latency
8 of a guest can, under some circumstances, be reduced by polling in the host
9 for some time period after the guest has elected to no longer run by cedeing.
10 That is, when a guest vcpu has ceded, or in the case of powerpc when all of the
11 vcpus of a single vcore have ceded, the host kernel polls for wakeup conditions
12 before giving up the cpu to the scheduler in order to let something else run.
13
14 Polling provides a latency advantage in cases where the guest can be run again
15 very quickly by at least saving us a trip through the scheduler, normally on
16 the order of a few micro-seconds, although performance benefits are workload
17 dependent. In the event that no wakeup source arrives during the polling
18 interval or some other task on the runqueue is runnable the scheduler is
19 invoked. Thus halt polling is especially useful on workloads with very short
20 wakeup periods where the time spent halt polling is minimised and the time
21 savings of not invoking the scheduler are distinguishable.
22
23 The generic halt polling code is implemented in:
24
25 virt/kvm/kvm_main.c: kvm_vcpu_block()
26
27 The powerpc kvm-hv specific case is implemented in:
28
29 arch/powerpc/kvm/book3s_hv.c: kvmppc_vcore_blocked()
30
31 Halt Polling Interval
32 =====================
33
34 The maximum time for which to poll before invoking the scheduler, referred to
35 as the halt polling interval, is increased and decreased based on the perceived
36 effectiveness of the polling in an attempt to limit pointless polling.
37 This value is stored in either the vcpu struct:
38
39 kvm_vcpu->halt_poll_ns
40
41 or in the case of powerpc kvm-hv, in the vcore struct:
42
43 kvmppc_vcore->halt_poll_ns
44
45 Thus this is a per vcpu (or vcore) value.
46
47 During polling if a wakeup source is received within the halt polling interval,
48 the interval is left unchanged. In the event that a wakeup source isn't
49 received during the polling interval (and thus schedule is invoked) there are
50 two options, either the polling interval and total block time[0] were less than
51 the global max polling interval (see module params below), or the total block
52 time was greater than the global max polling interval.
53
54 In the event that both the polling interval and total block time were less than
55 the global max polling interval then the polling interval can be increased in
56 the hope that next time during the longer polling interval the wake up source
57 will be received while the host is polling and the latency benefits will be
58 received. The polling interval is grown in the function grow_halt_poll_ns() and
59 is multiplied by the module parameters halt_poll_ns_grow and
60 halt_poll_ns_grow_start.
61
62 In the event that the total block time was greater than the global max polling
63 interval then the host will never poll for long enough (limited by the global
64 max) to wakeup during the polling interval so it may as well be shrunk in order
65 to avoid pointless polling. The polling interval is shrunk in the function
66 shrink_halt_poll_ns() and is divided by the module parameter
67 halt_poll_ns_shrink, or set to 0 iff halt_poll_ns_shrink == 0.
68
69 It is worth noting that this adjustment process attempts to hone in on some
70 steady state polling interval but will only really do a good job for wakeups
71 which come at an approximately constant rate, otherwise there will be constant
72 adjustment of the polling interval.
73
74 [0] total block time:
75 the time between when the halt polling function is
76 invoked and a wakeup source received (irrespective of
77 whether the scheduler is invoked within that function).
78
79 Module Parameters
80 =================
81
82 The kvm module has 4 tunable module parameters to adjust the global max polling
83 interval, the initial value (to grow from 0), and the rate at which the polling
84 interval is grown and shrunk. These variables are defined in
85 include/linux/kvm_host.h and as module parameters in virt/kvm/kvm_main.c, or
86 arch/powerpc/kvm/book3s_hv.c in the powerpc kvm-hv case.
87
88 +-----------------------+---------------------------+-------------------------+
89 |Module Parameter | Description | Default Value |
90 +-----------------------+---------------------------+-------------------------+
91 |halt_poll_ns | The global max polling | KVM_HALT_POLL_NS_DEFAULT|
92 | | interval which defines | |
93 | | the ceiling value of the | |
94 | | polling interval for | (per arch value) |
95 | | each vcpu. | |
96 +-----------------------+---------------------------+-------------------------+
97 |halt_poll_ns_grow | The value by which the | 2 |
98 | | halt polling interval is | |
99 | | multiplied in the | |
100 | | grow_halt_poll_ns() | |
101 | | function. | |
102 +-----------------------+---------------------------+-------------------------+
103 |halt_poll_ns_grow_start| The initial value to grow | 10000 |
104 | | to from zero in the | |
105 | | grow_halt_poll_ns() | |
106 | | function. | |
107 +-----------------------+---------------------------+-------------------------+
108 |halt_poll_ns_shrink | The value by which the | 2 |
109 | | halt polling interval is | |
110 | | divided in the | |
111 | | shrink_halt_poll_ns() | |
112 | | function. | |
113 +-----------------------+---------------------------+-------------------------+
114
115 These module parameters can be set from the sysfs files in:
116
117 /sys/module/kvm/parameters/
118
119 Note: these module parameters are system-wide values and are not able to
120 be tuned on a per vm basis.
121
122 Any changes to these parameters will be picked up by new and existing vCPUs the
123 next time they halt, with the notable exception of VMs using KVM_CAP_HALT_POLL
124 (see next section).
125
126 KVM_CAP_HALT_POLL
127 =================
128
129 KVM_CAP_HALT_POLL is a VM capability that allows userspace to override halt_poll_ns
130 on a per-VM basis. VMs using KVM_CAP_HALT_POLL ignore halt_poll_ns completely (but
131 still obey halt_poll_ns_grow, halt_poll_ns_grow_start, and halt_poll_ns_shrink).
132
133 See Documentation/virt/kvm/api.rst for more information on this capability.
134
135 Further Notes
136 =============
137
138 - Care should be taken when setting the halt_poll_ns module parameter as a large value
139 has the potential to drive the cpu usage to 100% on a machine which would be almost
140 entirely idle otherwise. This is because even if a guest has wakeups during which very
141 little work is done and which are quite far apart, if the period is shorter than the
142 global max polling interval (halt_poll_ns) then the host will always poll for the
143 entire block time and thus cpu utilisation will go to 100%.
144
145 - Halt polling essentially presents a trade-off between power usage and latency and
146 the module parameters should be used to tune the affinity for this. Idle cpu time is
147 essentially converted to host kernel time with the aim of decreasing latency when
148 entering the guest.
149
150 - Halt polling will only be conducted by the host when no other tasks are runnable on
151 that cpu, otherwise the polling will cease immediately and schedule will be invoked to
152 allow that other task to run. Thus this doesn't allow a guest to cause denial of service
153 of the cpu.
154

3. 한국어 전문 번역

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

동작 원리와 구현 위치

1-31

KVM halt polling은 게스트 vCPU가 실행권을 양보해 멈춘 직후 호스트가 곧바로 스케줄러를 호출하지 않고 일정 시간 깨우기 조건을 폴링하는 기능입니다. PowerPC KVM-HV에서는 단일 vcore의 모든 vCPU가 양보한 경우에 같은 원리를 적용합니다.

게스트가 수 마이크로초 안에 다시 실행될 수 있는 작업에서는 스케줄러 왕복을 피하므로 지연 시간이 줄어듭니다. 반대로 폴링 구간 안에 깨우기 원인이 없거나 실행 큐에 다른 태스크가 있으면 즉시 스케줄러를 호출합니다. 따라서 짧고 비교적 규칙적인 깨우기 주기를 가진 작업에 특히 유리합니다.

halt polling 구현 지점
범위소스와 함수
일반 KVM`virt/kvm/kvm_main.c`: `kvm_vcpu_block()`
PowerPC KVM-HV`arch/powerpc/kvm/book3s_hv.c`: `kvmppc_vcore_blocked()`

일반 KVM과 PowerPC KVM-HV가 사용하는 차단 함수입니다.

.. SPDX-License-Identifier: GPL-2.0

===========================
The KVM halt polling system
===========================

The KVM halt polling system provides a feature within KVM whereby the latency
of a guest can, under some circumstances, be reduced by polling in the host
for some time period after the guest has elected to no longer run by cedeing.
That is, when a guest vcpu has ceded, or in the case of powerpc when all of the
vcpus of a single vcore have ceded, the host kernel polls for wakeup conditions
before giving up the cpu to the scheduler in order to let something else run.

Polling provides a latency advantage in cases where the guest can be run again
very quickly by at least saving us a trip through the scheduler, normally on
the order of a few micro-seconds, although performance benefits are workload
dependent. In the event that no wakeup source arrives during the polling
interval or some other task on the runqueue is runnable the scheduler is
invoked. Thus halt polling is especially useful on workloads with very short
wakeup periods where the time spent halt polling is minimised and the time
savings of not invoking the scheduler are distinguishable.

The generic halt polling code is implemented in:

	virt/kvm/kvm_main.c: kvm_vcpu_block()

The powerpc kvm-hv specific case is implemented in:

	arch/powerpc/kvm/book3s_hv.c: kvmppc_vcore_blocked()

Halt Polling Interval

폴링 구간의 자동 조정

32-79

스케줄러를 부르기 전까지 폴링하는 최대 시간을 halt polling interval이라고 합니다. 이 값은 일반 KVM에서는 `kvm_vcpu->halt_poll_ns`, PowerPC KVM-HV에서는 `kvmppc_vcore->halt_poll_ns`에 저장되므로 vCPU 또는 vcore별 상태입니다.

폴링 구간 안에 깨우기 원인이 도착하면 현재 구간을 유지합니다. 도착하지 않아 스케줄러를 호출한 경우에는 현재 구간과 전체 차단 시간이 전역 최대값보다 작은지, 전체 차단 시간이 전역 최대값보다 큰지를 기준으로 다음 값을 조정합니다.

halt polling interval 조정
구간 안에서 깨움: 현재 halt_poll_ns 유지폴링 구간과 전체 차단 시간이 모두 전역 최대보다 작음: grow_halt_poll_ns()로 증가전체 차단 시간이 전역 최대보다 큼: shrink_halt_poll_ns()로 감소halt_poll_ns_shrink가 0이면 감소 대신 구간을 0으로 설정

관측된 전체 차단 시간에 따라 다음 폴링 구간을 바꿉니다.

증가 함수는 `halt_poll_ns_grow`와 `halt_poll_ns_grow_start`를 사용하고 감소 함수는 `halt_poll_ns_shrink`로 나눕니다. 이 적응 방식은 일정한 깨우기 주기에는 안정 상태를 찾지만 주기가 계속 변하면 구간도 계속 조정됩니다.

전체 차단 시간은 halt polling 함수가 호출된 때부터 깨우기 원인이 도착할 때까지의 시간이며, 그 사이 실제로 스케줄러를 호출했는지는 관계없습니다.

=====================

The maximum time for which to poll before invoking the scheduler, referred to
as the halt polling interval, is increased and decreased based on the perceived
effectiveness of the polling in an attempt to limit pointless polling.
This value is stored in either the vcpu struct:

	kvm_vcpu->halt_poll_ns

or in the case of powerpc kvm-hv, in the vcore struct:

	kvmppc_vcore->halt_poll_ns

Thus this is a per vcpu (or vcore) value.

During polling if a wakeup source is received within the halt polling interval,
the interval is left unchanged. In the event that a wakeup source isn't
received during the polling interval (and thus schedule is invoked) there are
two options, either the polling interval and total block time[0] were less than
the global max polling interval (see module params below), or the total block
time was greater than the global max polling interval.

In the event that both the polling interval and total block time were less than
the global max polling interval then the polling interval can be increased in
the hope that next time during the longer polling interval the wake up source
will be received while the host is polling and the latency benefits will be
received. The polling interval is grown in the function grow_halt_poll_ns() and
is multiplied by the module parameters halt_poll_ns_grow and
halt_poll_ns_grow_start.

In the event that the total block time was greater than the global max polling
interval then the host will never poll for long enough (limited by the global
max) to wakeup during the polling interval so it may as well be shrunk in order
to avoid pointless polling. The polling interval is shrunk in the function
shrink_halt_poll_ns() and is divided by the module parameter
halt_poll_ns_shrink, or set to 0 iff halt_poll_ns_shrink == 0.

It is worth noting that this adjustment process attempts to hone in on some
steady state polling interval but will only really do a good job for wakeups
which come at an approximately constant rate, otherwise there will be constant
adjustment of the polling interval.

[0] total block time:
		      the time between when the halt polling function is
		      invoked and a wakeup source received (irrespective of
		      whether the scheduler is invoked within that function).

Module Parameters

모듈 매개변수

80-126

KVM 모듈은 전역 최대 구간, 0에서 시작할 초기값, 증가율과 감소율을 조정하는 네 매개변수를 제공합니다. 일반 구현은 `include/linux/kvm_host.h`와 `virt/kvm/kvm_main.c`에, PowerPC KVM-HV 구현은 `arch/powerpc/kvm/book3s_hv.c`에 정의됩니다.

halt polling 모듈 매개변수
매개변수의미기본값
`halt_poll_ns`각 vCPU 폴링 구간의 상한인 전역 최대값`KVM_HALT_POLL_NS_DEFAULT`(아키텍처별)
`halt_poll_ns_grow``grow_halt_poll_ns()`에서 곱하는 증가 배수2
`halt_poll_ns_grow_start`0에서 처음 증가할 때 사용하는 값10000
`halt_poll_ns_shrink``shrink_halt_poll_ns()`에서 나누는 감소 배수2

모든 VM에 적용되는 시스템 전역 조정값입니다.

매개변수는 `/sys/module/kvm/parameters/` 아래 sysfs 파일에서 설정합니다. VM별로 조정할 수 없는 시스템 전역 값이며, 새 vCPU와 기존 vCPU 모두 다음 halt 시 변경값을 읽습니다. 단, `KVM_CAP_HALT_POLL`을 사용하는 VM은 예외입니다.

=================

The kvm module has 4 tunable module parameters to adjust the global max polling
interval, the initial value (to grow from 0), and the rate at which the polling
interval is grown and shrunk. These variables are defined in
include/linux/kvm_host.h and as module parameters in virt/kvm/kvm_main.c, or
arch/powerpc/kvm/book3s_hv.c in the powerpc kvm-hv case.

+-----------------------+---------------------------+-------------------------+
|Module Parameter	|   Description		    |	     Default Value    |
+-----------------------+---------------------------+-------------------------+
|halt_poll_ns		| The global max polling    | KVM_HALT_POLL_NS_DEFAULT|
|			| interval which defines    |			      |
|			| the ceiling value of the  |			      |
|			| polling interval for      | (per arch value)	      |
|			| each vcpu.		    |			      |
+-----------------------+---------------------------+-------------------------+
|halt_poll_ns_grow	| The value by which the    | 2			      |
|			| halt polling interval is  |			      |
|			| multiplied in the	    |			      |
|			| grow_halt_poll_ns()	    |			      |
|			| function.		    |			      |
+-----------------------+---------------------------+-------------------------+
|halt_poll_ns_grow_start| The initial value to grow | 10000		      |
|			| to from zero in the	    |			      |
|			| grow_halt_poll_ns()	    |			      |
|			| function.		    |			      |
+-----------------------+---------------------------+-------------------------+
|halt_poll_ns_shrink	| The value by which the    | 2			      |
|			| halt polling interval is  |			      |
|			| divided in the	    |			      |
|			| shrink_halt_poll_ns()	    |			      |
|			| function.		    |			      |
+-----------------------+---------------------------+-------------------------+

These module parameters can be set from the sysfs files in:

	/sys/module/kvm/parameters/

Note: these module parameters are system-wide values and are not able to
      be tuned on a per vm basis.

Any changes to these parameters will be picked up by new and existing vCPUs the
next time they halt, with the notable exception of VMs using KVM_CAP_HALT_POLL
(see next section).

KVM_CAP_HALT_POLL

KVM_CAP_HALT_POLL

127-135

`KVM_CAP_HALT_POLL`은 userspace가 VM별로 `halt_poll_ns`를 덮어쓰게 하는 VM capability입니다. 이 capability를 쓰는 VM은 전역 `halt_poll_ns`를 완전히 무시하지만 `halt_poll_ns_grow`, `halt_poll_ns_grow_start`, `halt_poll_ns_shrink`는 계속 따릅니다.

capability의 세부 ABI와 설정 방법은 `Documentation/virt/kvm/api.rst`를 참조합니다.

=================

KVM_CAP_HALT_POLL is a VM capability that allows userspace to override halt_poll_ns
on a per-VM basis. VMs using KVM_CAP_HALT_POLL ignore halt_poll_ns completely (but
still obey halt_poll_ns_grow, halt_poll_ns_grow_start, and halt_poll_ns_shrink).

See Documentation/virt/kvm/api.rst for more information on this capability.

Further Notes

운영 시 주의사항

136-153

`halt_poll_ns`를 크게 잡으면 원래 거의 유휴 상태일 시스템에서도 CPU 사용률이 100%에 이를 수 있습니다. 게스트의 짧은 작업이 드물게 깨어나더라도 깨우기 간격이 전역 최대 구간보다 짧으면 호스트가 전체 차단 시간 동안 계속 폴링하기 때문입니다.

halt polling은 전력 소비와 지연 시간 사이의 명시적인 절충입니다. 유휴 CPU 시간을 호스트 커널 시간으로 바꾸어 게스트 재진입 지연을 줄이므로 모듈 매개변수는 워크로드 목표에 맞춰 조정해야 합니다.

해당 CPU에서 다른 태스크가 실행 가능해지면 호스트는 폴링을 즉시 끝내고 스케줄러를 호출합니다. 따라서 게스트가 halt polling을 이용해 다른 태스크의 CPU 실행을 거부할 수는 없습니다.

=============

- Care should be taken when setting the halt_poll_ns module parameter as a large value
  has the potential to drive the cpu usage to 100% on a machine which would be almost
  entirely idle otherwise. This is because even if a guest has wakeups during which very
  little work is done and which are quite far apart, if the period is shorter than the
  global max polling interval (halt_poll_ns) then the host will always poll for the
  entire block time and thus cpu utilisation will go to 100%.

- Halt polling essentially presents a trade-off between power usage and latency and
  the module parameters should be used to tune the affinity for this. Idle cpu time is
  essentially converted to host kernel time with the aim of decreasing latency when
  entering the guest.

- Halt polling will only be conducted by the host when no other tasks are runnable on
  that cpu, otherwise the polling will cease immediately and schedule will be invoked to
  allow that other task to run. Thus this doesn't allow a guest to cause denial of service
  of the cpu.