-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioprio_set.html
405 lines (313 loc) · 13.4 KB
/
ioprio_set.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:25:44 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>IOPRIO_SET</title>
</head>
<body>
<h1 align="center">IOPRIO_SET</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">ioprio_get,
ioprio_set - get/set I/O scheduling class and priority</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>int
ioprio_get(int</b> <i>which</i><b>, int</b> <i>who</i><b>);
<br>
int ioprio_set(int</b> <i>which</i><b>, int</b>
<i>who</i><b>, int</b> <i>ioprio</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em"><i>Note</i>:
There are no glibc wrappers for these system calls; see
NOTES.</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">The
<b>ioprio_get</b>() and <b>ioprio_set</b>() system calls get
and set the I/O scheduling class and priority of one or more
threads.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>which</i> and <i>who</i> arguments identify the thread(s)
on which the system calls operate. The <i>which</i> argument
determines how <i>who</i> is interpreted, and has one of the
following values: <b><br>
IOPRIO_WHO_PROCESS</b></p>
<p style="margin-left:22%;"><i>who</i> is a process ID or
thread ID identifying a single process or thread. If
<i>who</i> is 0, then operate on the calling thread.</p>
<p style="margin-left:11%;"><b>IOPRIO_WHO_PGRP</b></p>
<p style="margin-left:22%;"><i>who</i> is a process group
ID identifying all the members of a process group. If
<i>who</i> is 0, then operate on the process group of which
the caller is a member.</p>
<p style="margin-left:11%;"><b>IOPRIO_WHO_USER</b></p>
<p style="margin-left:22%;"><i>who</i> is a user ID
identifying all of the processes that have a matching real
UID.</p>
<p style="margin-left:11%; margin-top: 1em">If <i>which</i>
is specified as <b>IOPRIO_WHO_PGRP</b> or
<b>IOPRIO_WHO_USER</b> when calling <b>ioprio_get</b>(), and
more than one process matches <i>who</i>, then the returned
priority will be the highest one found among all of the
matching processes. One priority is said to be higher than
another one if it belongs to a higher priority class
(<b>IOPRIO_CLASS_RT</b> is the highest priority class;
<b>IOPRIO_CLASS_IDLE</b> is the lowest) or if it belongs to
the same priority class as the other process but has a
higher priority level (a lower priority number means a
higher priority level).</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>ioprio</i> argument given to <b>ioprio_set</b>() is a bit
mask that specifies both the scheduling class and the
priority to be assigned to the target process(es). The
following macros are used for assembling and dissecting
<i>ioprio</i> values: <b><br>
IOPRIO_PRIO_VALUE(</b><i>class</i><b>,</b>
<i>data</i><b>)</b></p>
<p style="margin-left:22%;">Given a scheduling <i>class</i>
and priority (<i>data</i>), this macro combines the two
values to produce an <i>ioprio</i> value, which is returned
as the result of the macro.</p>
<p style="margin-left:11%;"><b>IOPRIO_PRIO_CLASS(</b><i>mask</i><b>)</b></p>
<p style="margin-left:22%;">Given <i>mask</i> (an
<i>ioprio</i> value), this macro returns its I/O class
component, that is, one of the values
<b>IOPRIO_CLASS_RT</b>, <b>IOPRIO_CLASS_BE</b>, or
<b>IOPRIO_CLASS_IDLE</b>.</p>
<p style="margin-left:11%;"><b>IOPRIO_PRIO_DATA(</b><i>mask</i><b>)</b></p>
<p style="margin-left:22%;">Given <i>mask</i> (an
<i>ioprio</i> value), this macro returns its priority
(<i>data</i>) component.</p>
<p style="margin-left:11%; margin-top: 1em">See the NOTES
section for more information on scheduling classes and
priorities, as well as the meaning of specifying
<i>ioprio</i> as 0.</p>
<p style="margin-left:11%; margin-top: 1em">I/O priorities
are supported for reads and for synchronous
(<b>O_DIRECT</b>, <b>O_SYNC</b>) writes. I/O priorities are
not supported for asynchronous writes because they are
issued outside the context of the program dirtying the
memory, and thus program-specific priorities do not
apply.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>ioprio_get</b>() returns the <i>ioprio</i> value of the
process with highest I/O priority of any of the processes
that match the criteria specified in <i>which</i> and
<i>who</i>. On error, -1 is returned, and <i>errno</i> is
set to indicate the error.</p>
<p style="margin-left:11%; margin-top: 1em">On success,
<b>ioprio_set</b>() returns 0. On error, -1 is returned, and
<i>errno</i> is set to indicate the error.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">Invalid value for <i>which</i>
or <i>ioprio</i>. Refer to the NOTES section for available
scheduler classes and priority levels for <i>ioprio</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EPERM</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The calling process does not have the privilege needed
to assign this <i>ioprio</i> to the specified process(es).
See the NOTES section for more information on required
privileges for <b>ioprio_set</b>().</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ESRCH</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>No process(es) could be found that matched the
specification in <i>which</i> and <i>who</i>.</p></td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls have been available on Linux since kernel 2.6.13.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">These system
calls are Linux-specific.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Glibc does not
provide a wrapper for these system calls; call them using
<b>syscall</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">Two or more
processes or threads can share an I/O context. This will be
the case when <b>clone</b>(2) was called with the
<b>CLONE_IO</b> flag. However, by default, the distinct
threads of a process will <b>not</b> share the same I/O
context. This means that if you want to change the I/O
priority of all threads in a process, you may need to call
<b>ioprio_set</b>() on each of the threads. The thread ID
that you would need for this operation is the one that is
returned by <b>gettid</b>(2) or <b>clone</b>(2).</p>
<p style="margin-left:11%; margin-top: 1em">These system
calls have an effect only when used in conjunction with an
I/O scheduler that supports I/O priorities. As at kernel
2.6.17 the only such scheduler is the Completely Fair
Queuing (CFQ) I/O scheduler.</p>
<p style="margin-left:11%; margin-top: 1em">If no I/O
scheduler has been set for a thread, then by default the I/O
priority will follow the CPU nice value
(<b>setpriority</b>(2)). In Linux kernels before version
2.6.24, once an I/O priority had been set using
<b>ioprio_set</b>(), there was no way to reset the I/O
scheduling behavior to the default. Since Linux 2.6.24,
specifying <i>ioprio</i> as 0 can be used to reset to the
default I/O scheduling behavior.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Selecting an
I/O scheduler</b> <br>
I/O schedulers are selected on a per-device basis via the
special file
<i>/sys/block/<device>/queue/scheduler</i>.</p>
<p style="margin-left:11%; margin-top: 1em">One can view
the current I/O scheduler via the <i>/sys</i> filesystem.
For example, the following command displays a list of all
schedulers currently loaded in the kernel:</p>
<p style="margin-left:17%; margin-top: 1em">$ <b>cat
/sys/block/sda/queue/scheduler</b> <br>
noop anticipatory deadline [cfq]</p>
<p style="margin-left:11%; margin-top: 1em">The scheduler
surrounded by brackets is the one actually in use for the
device (<i>sda</i> in the example). Setting another
scheduler is done by writing the name of the new scheduler
to this file. For example, the following command will set
the scheduler for the <i>sda</i> device to <i>cfq</i>:</p>
<p style="margin-left:17%; margin-top: 1em">$ <b>su</b>
<br>
Password: <br>
# <b>echo cfq > /sys/block/sda/queue/scheduler</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>The
Completely Fair Queuing (CFQ) I/O scheduler</b> <br>
Since version 3 (also known as CFQ Time Sliced), CFQ
implements I/O nice levels similar to those of CPU
scheduling. These nice levels are grouped into three
scheduling classes, each one containing one or more priority
levels: <b><br>
IOPRIO_CLASS_RT</b> (1)</p>
<p style="margin-left:22%;">This is the real-time I/O
class. This scheduling class is given higher priority than
any other class: processes from this class are given first
access to the disk every time. Thus, this I/O class needs to
be used with some care: one I/O real-time process can starve
the entire system. Within the real-time class, there are 8
levels of class data (priority) that determine exactly how
much time this process needs the disk for on each service.
The highest real-time priority level is 0; the lowest is 7.
In the future, this might change to be more directly
mappable to performance, by passing in a desired data rate
instead.</p>
<p style="margin-left:11%;"><b>IOPRIO_CLASS_BE</b> (2)</p>
<p style="margin-left:22%;">This is the best-effort
scheduling class, which is the default for any process that
hasn’t set a specific I/O priority. The class data
(priority) determines how much I/O bandwidth the process
will get. Best-effort priority levels are analogous to CPU
nice values (see <b>getpriority</b>(2)). The priority level
determines a priority relative to other processes in the
best-effort scheduling class. Priority levels range from 0
(highest) to 7 (lowest).</p>
<p style="margin-left:11%;"><b>IOPRIO_CLASS_IDLE</b>
(3)</p>
<p style="margin-left:22%;">This is the idle scheduling
class. Processes running at this level get I/O time only
when no one else needs the disk. The idle class has no class
data. Attention is required when assigning this priority
class to a process, since it may become starved if higher
priority processes are constantly accessing the disk.</p>
<p style="margin-left:11%; margin-top: 1em">Refer to the
kernel source file <i>Documentation/block/ioprio.txt</i> for
more information on the CFQ I/O Scheduler and an example
program.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Required
permissions to set I/O priorities</b> <br>
Permission to change a process’s priority is granted
or denied based on two criteria: <b><br>
Process ownership</b></p>
<p style="margin-left:22%;">An unprivileged process may set
the I/O priority only for a process whose real UID matches
the real or effective UID of the calling process. A process
which has the <b>CAP_SYS_NICE</b> capability can change the
priority of any process.</p>
<p style="margin-left:11%;"><b>What is the desired
priority</b></p>
<p style="margin-left:22%;">Attempts to set very high
priorities (<b>IOPRIO_CLASS_RT</b>) require the
<b>CAP_SYS_ADMIN</b> capability. Kernel versions up to
2.6.24 also required <b>CAP_SYS_ADMIN</b> to set a very low
priority (<b>IOPRIO_CLASS_IDLE</b>), but since Linux 2.6.25,
this is no longer required.</p>
<p style="margin-left:11%; margin-top: 1em">A call to
<b>ioprio_set</b>() must follow both rules, or the call will
fail with the error <b>EPERM</b>.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Glibc does not
yet provide a suitable header file defining the function
prototypes and macros described on this page. Suitable
definitions can be found in <i>linux/ioprio.h</i>.</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>ionice</b>(1),
<b>getpriority</b>(2), <b>open</b>(2),
<b>capabilities</b>(7), <b>cgroups</b>(7)</p>
<p style="margin-left:11%; margin-top: 1em"><i>Documentation/block/ioprio.txt</i>
in the Linux kernel source tree</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>