1 |
commit: 353c61912b134b326da5ac16ef1d4bc74b8967d1 |
2 |
Author: KARBOWSKI Piotr <slashbeast <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Aug 1 20:55:41 2022 +0000 |
4 |
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Aug 3 15:57:38 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=353c6191 |
7 |
|
8 |
Scheduling policy switching |
9 |
|
10 |
Adds ability to control the scheduler policy that is used for emerge and |
11 |
all child processes. Mainly to interface the ability to switch to |
12 |
SCHED_IDLE as the solution to keep interactive tasks unaffected by |
13 |
building process happening in the background. |
14 |
|
15 |
On a test sample N=1 with AMD Ryzen 5950x and 64 GB of ram building |
16 |
sys-devel/gcc with lto enabled significantly reduces responsiveness of |
17 |
the system, even with CONFIG_SCHED_AUTOGROUP and PREEMPT enabled. Using |
18 |
a web browser result in visible lags, video playback in web browser, |
19 |
when using CPU decoding, also suffers greatly. |
20 |
|
21 |
Switching Portage to SCHED_IDLE (PORTAGE_SCHEDULING_POLICY="idle") |
22 |
results in no visible slowdowns and responsiveness is as if nothing in |
23 |
the background was happening. |
24 |
|
25 |
This is especially worthy feature when running on powerful CPUs, where |
26 |
users often opt in to build not only with parallel build jobs, but also |
27 |
with multiple packages at once. Anyone running with PORTAGE_NICENESS="19" will |
28 |
undoubtedly want to use this feature to force SCHED_IDLE policy. |
29 |
|
30 |
Closes: https://github.com/gentoo/portage/pull/861 |
31 |
Signed-off-by: KARBOWSKI Piotr <slashbeast <AT> gentoo.org> |
32 |
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org> |
33 |
|
34 |
cnf/make.conf.example | 17 +++++++++++++++++ |
35 |
lib/_emerge/actions.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ |
36 |
man/make.conf.5 | 16 ++++++++++++++++ |
37 |
3 files changed, 78 insertions(+) |
38 |
|
39 |
diff --git a/cnf/make.conf.example b/cnf/make.conf.example |
40 |
index 5b2229465..2e33a6e50 100644 |
41 |
--- a/cnf/make.conf.example |
42 |
+++ b/cnf/make.conf.example |
43 |
@@ -291,6 +291,23 @@ |
44 |
# unset. |
45 |
#PORTAGE_IONICE_COMMAND="ionice -c 3 -p \${PID}" |
46 |
# |
47 |
+# PORTAGE_SCHEDULING_POLICY allows changing the current scheduling policy. The |
48 |
+# supported options are 'other', 'batch', 'idle', 'fifo' and 'round-robin'. When |
49 |
+# unset, the scheduling policy remains unchanged, by default Linux uses 'other' |
50 |
+# policy. Users that wish to minimize the Portage's impact on system |
51 |
+# responsiveness should set scheduling policy to 'idle' which significantly |
52 |
+# reduces the disruption to the rest of the system by scheduling Portage as |
53 |
+# extremely low priority processes. |
54 |
+# |
55 |
+#PORTAGE_SCHEDULING_POLICY="idle" |
56 |
+# |
57 |
+# PORTAGE_SCHEDULING_PRIORITY allows changing the priority (1-99) of the current |
58 |
+# scheduling policy, only applies if PORTAGE_SCHEDULING_POLICY is set to 'fifo' |
59 |
+# or 'round-robin', for others the only supported priority is 0, If unset, |
60 |
+# defaults to lowest priority of the selected scheduling policy. |
61 |
+# |
62 |
+#PORTAGE_SCHEDULING_PRIORITY="99" |
63 |
+# |
64 |
# AUTOCLEAN enables portage to automatically clean out older or overlapping |
65 |
# packages from the system after every successful merge. This is the |
66 |
# same as running 'emerge -c' after every merge. Set with: "yes" or "no". |
67 |
|
68 |
diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py |
69 |
index e2f3f2ccf..e79bb30c0 100644 |
70 |
--- a/lib/_emerge/actions.py |
71 |
+++ b/lib/_emerge/actions.py |
72 |
@@ -3054,6 +3054,7 @@ def config_protect_check(trees): |
73 |
def apply_priorities(settings): |
74 |
ionice(settings) |
75 |
nice(settings) |
76 |
+ set_scheduling_policy(settings) |
77 |
|
78 |
|
79 |
def nice(settings): |
80 |
@@ -3094,6 +3095,50 @@ def ionice(settings): |
81 |
) |
82 |
|
83 |
|
84 |
+def set_scheduling_policy(settings): |
85 |
+ scheduling_policy = settings.get("PORTAGE_SCHEDULING_POLICY") |
86 |
+ scheduling_priority = settings.get("PORTAGE_SCHEDULING_PRIORITY") |
87 |
+ |
88 |
+ if platform.system() != "Linux" or not scheduling_policy: |
89 |
+ return os.EX_OK |
90 |
+ |
91 |
+ policies = { |
92 |
+ "other": os.SCHED_OTHER, |
93 |
+ "batch": os.SCHED_BATCH, |
94 |
+ "idle": os.SCHED_IDLE, |
95 |
+ "fifo": os.SCHED_FIFO, |
96 |
+ "round-robin": os.SCHED_RR, |
97 |
+ } |
98 |
+ |
99 |
+ out = portage.output.EOutput() |
100 |
+ |
101 |
+ if scheduling_policy in policies: |
102 |
+ policy = policies[scheduling_policy] |
103 |
+ else: |
104 |
+ out.eerror("Invalid policy in PORTAGE_SCHEDULING_POLICY.") |
105 |
+ out.eerror( |
106 |
+ "See the make.conf(5) man page for PORTAGE_SCHEDULING_POLICY usage instructions." |
107 |
+ ) |
108 |
+ return os.EX_USAGE |
109 |
+ |
110 |
+ if not scheduling_priority: |
111 |
+ scheduling_priority = os.sched_get_priority_min(policy) |
112 |
+ else: |
113 |
+ scheduling_priority = int(scheduling_priority) |
114 |
+ if scheduling_priority not in range( |
115 |
+ os.sched_get_priority_min(policy), os.sched_get_priority_max(policy) + 1 |
116 |
+ ): |
117 |
+ out.eerror("Invalid priority in PORTAGE_SCHEDULING_PRIORITY.") |
118 |
+ out.eerror( |
119 |
+ "See the make.conf(5) man page for PORTAGE_SCHEDULING_PRIORITY usage instructions." |
120 |
+ ) |
121 |
+ return os.EX_USAGE |
122 |
+ |
123 |
+ os.sched_setscheduler(portage.getpid(), policy, os.sched_param(scheduling_priority)) |
124 |
+ |
125 |
+ return os.EX_OK |
126 |
+ |
127 |
+ |
128 |
def setconfig_fallback(root_config): |
129 |
setconfig = root_config.setconfig |
130 |
setconfig._create_default_config() |
131 |
|
132 |
diff --git a/man/make.conf.5 b/man/make.conf.5 |
133 |
index bde92af1a..a527a3f74 100644 |
134 |
--- a/man/make.conf.5 |
135 |
+++ b/man/make.conf.5 |
136 |
@@ -1080,6 +1080,22 @@ will set idle io priority. For more information about ionice, see |
137 |
Portage will also set the autogroup-nice value (see fBsched\fR(7))), if |
138 |
FEATURES="pid\-sandbox" is enabled. |
139 |
.TP |
140 |
+\fBPORTAGE_SCHEDULING_POLICY\fR = \fI[policy name]\fR |
141 |
+Allows changing the current scheduling policy. The supported options are |
142 |
+\fBother\fR, \fBbatch\fR, \fBidle\fR, \fBfifo\fR, and \fBround-robin\fR. When |
143 |
+unset, the scheduling policy remains unchanged, by default Linux uses 'other' |
144 |
+policy. Users that wish to minimize the Portage's impact on system |
145 |
+responsiveness should set scheduling policy to \fBidle\fR, which significantly |
146 |
+reduces the disruption to the rest of the system by scheduling Portage as |
147 |
+extremely low priority processes. see \fBsched\fR(7) for more information. |
148 |
+.TP |
149 |
+\fBPORTAGE_SCHEDULING_PRIORITY\fR = \fI[priority]\fR |
150 |
+Allows changing the priority (1-99) of the current scheduling policy, only |
151 |
+applies if PORTAGE _SCHEDULING_POLICY is set to 'fifo' or 'round-robin', |
152 |
+for others the only supported priority is 0, If unset, defaults to lowest |
153 |
+priority of the selected scheduling policy. For more information about |
154 |
+scheduler, see \fBsched\fR(7). This variable is unset by default. |
155 |
+.TP |
156 |
.B PORTAGE_LOG_FILTER_FILE_CMD |
157 |
This variable specifies a command that filters build log output to a |
158 |
log file. In order to filter ANSI escape codes from build logs, |