1ioprio_set(2) System Calls Manual ioprio_set(2)
2
3
4
6 ioprio_get, ioprio_set - get/set I/O scheduling class and priority
7
9 Standard C library (libc, -lc)
10
12 #include <linux/ioprio.h> /* Definition of IOPRIO_* constants */
13 #include <sys/syscall.h> /* Definition of SYS_* constants */
14 #include <unistd.h>
15
16 int syscall(SYS_ioprio_get, int which, int who);
17 int syscall(SYS_ioprio_set, int which, int who, int ioprio);
18
19 Note: glibc provides no wrappers for these system calls, necessitating
20 the use of syscall(2).
21
23 The ioprio_get() and ioprio_set() system calls get and set the I/O
24 scheduling class and priority of one or more threads.
25
26 The which and who arguments identify the thread(s) on which the system
27 calls operate. The which argument determines how who is interpreted,
28 and has one of the following values:
29
30 IOPRIO_WHO_PROCESS
31 who is a process ID or thread ID identifying a single process or
32 thread. If who is 0, then operate on the calling thread.
33
34 IOPRIO_WHO_PGRP
35 who is a process group ID identifying all the members of a
36 process group. If who is 0, then operate on the process group
37 of which the caller is a member.
38
39 IOPRIO_WHO_USER
40 who is a user ID identifying all of the processes that have a
41 matching real UID.
42
43 If which is specified as IOPRIO_WHO_PGRP or IOPRIO_WHO_USER when call‐
44 ing ioprio_get(), and more than one process matches who, then the re‐
45 turned priority will be the highest one found among all of the matching
46 processes. One priority is said to be higher than another one if it
47 belongs to a higher priority class (IOPRIO_CLASS_RT is the highest pri‐
48 ority class; IOPRIO_CLASS_IDLE is the lowest) or if it belongs to the
49 same priority class as the other process but has a higher priority
50 level (a lower priority number means a higher priority level).
51
52 The ioprio argument given to ioprio_set() is a bit mask that specifies
53 both the scheduling class and the priority to be assigned to the target
54 process(es). The following macros are used for assembling and dissect‐
55 ing ioprio values:
56
57 IOPRIO_PRIO_VALUE(class, data)
58 Given a scheduling class and priority (data), this macro com‐
59 bines the two values to produce an ioprio value, which is re‐
60 turned as the result of the macro.
61
62 IOPRIO_PRIO_CLASS(mask)
63 Given mask (an ioprio value), this macro returns its I/O class
64 component, that is, one of the values IOPRIO_CLASS_RT, IO‐
65 PRIO_CLASS_BE, or IOPRIO_CLASS_IDLE.
66
67 IOPRIO_PRIO_DATA(mask)
68 Given mask (an ioprio value), this macro returns its priority
69 (data) component.
70
71 See the NOTES section for more information on scheduling classes and
72 priorities, as well as the meaning of specifying ioprio as 0.
73
74 I/O priorities are supported for reads and for synchronous (O_DIRECT,
75 O_SYNC) writes. I/O priorities are not supported for asynchronous
76 writes because they are issued outside the context of the program
77 dirtying the memory, and thus program-specific priorities do not apply.
78
80 On success, ioprio_get() returns the ioprio value of the process with
81 highest I/O priority of any of the processes that match the criteria
82 specified in which and who. On error, -1 is returned, and errno is set
83 to indicate the error.
84
85 On success, ioprio_set() returns 0. On error, -1 is returned, and er‐
86 rno is set to indicate the error.
87
89 EINVAL Invalid value for which or ioprio. Refer to the NOTES section
90 for available scheduler classes and priority levels for ioprio.
91
92 EPERM The calling process does not have the privilege needed to assign
93 this ioprio to the specified process(es). See the NOTES section
94 for more information on required privileges for ioprio_set().
95
96 ESRCH No process(es) could be found that matched the specification in
97 which and who.
98
100 Linux.
101
103 Linux 2.6.13.
104
106 Two or more processes or threads can share an I/O context. This will
107 be the case when clone(2) was called with the CLONE_IO flag. However,
108 by default, the distinct threads of a process will not share the same
109 I/O context. This means that if you want to change the I/O priority of
110 all threads in a process, you may need to call ioprio_set() on each of
111 the threads. The thread ID that you would need for this operation is
112 the one that is returned by gettid(2) or clone(2).
113
114 These system calls have an effect only when used in conjunction with an
115 I/O scheduler that supports I/O priorities. As at kernel 2.6.17 the
116 only such scheduler is the Completely Fair Queuing (CFQ) I/O scheduler.
117
118 If no I/O scheduler has been set for a thread, then by default the I/O
119 priority will follow the CPU nice value (setpriority(2)). Before Linux
120 2.6.24, once an I/O priority had been set using ioprio_set(), there was
121 no way to reset the I/O scheduling behavior to the default. Since
122 Linux 2.6.24, specifying ioprio as 0 can be used to reset to the de‐
123 fault I/O scheduling behavior.
124
125 Selecting an I/O scheduler
126 I/O schedulers are selected on a per-device basis via the special file
127 /sys/block/device/queue/scheduler.
128
129 One can view the current I/O scheduler via the /sys filesystem. For
130 example, the following command displays a list of all schedulers cur‐
131 rently loaded in the kernel:
132
133 $ cat /sys/block/sda/queue/scheduler
134 noop anticipatory deadline [cfq]
135
136 The scheduler surrounded by brackets is the one actually in use for the
137 device (sda in the example). Setting another scheduler is done by
138 writing the name of the new scheduler to this file. For example, the
139 following command will set the scheduler for the sda device to cfq:
140
141 $ su
142 Password:
143 # echo cfq > /sys/block/sda/queue/scheduler
144
145 The Completely Fair Queuing (CFQ) I/O scheduler
146 Since version 3 (also known as CFQ Time Sliced), CFQ implements I/O
147 nice levels similar to those of CPU scheduling. These nice levels are
148 grouped into three scheduling classes, each one containing one or more
149 priority levels:
150
151 IOPRIO_CLASS_RT (1)
152 This is the real-time I/O class. This scheduling class is given
153 higher priority than any other class: processes from this class
154 are given first access to the disk every time. Thus, this I/O
155 class needs to be used with some care: one I/O real-time process
156 can starve the entire system. Within the real-time class, there
157 are 8 levels of class data (priority) that determine exactly how
158 much time this process needs the disk for on each service. The
159 highest real-time priority level is 0; the lowest is 7. In the
160 future, this might change to be more directly mappable to per‐
161 formance, by passing in a desired data rate instead.
162
163 IOPRIO_CLASS_BE (2)
164 This is the best-effort scheduling class, which is the default
165 for any process that hasn't set a specific I/O priority. The
166 class data (priority) determines how much I/O bandwidth the
167 process will get. Best-effort priority levels are analogous to
168 CPU nice values (see getpriority(2)). The priority level deter‐
169 mines a priority relative to other processes in the best-effort
170 scheduling class. Priority levels range from 0 (highest) to 7
171 (lowest).
172
173 IOPRIO_CLASS_IDLE (3)
174 This is the idle scheduling class. Processes running at this
175 level get I/O time only when no one else needs the disk. The
176 idle class has no class data. Attention is required when as‐
177 signing this priority class to a process, since it may become
178 starved if higher priority processes are constantly accessing
179 the disk.
180
181 Refer to the kernel source file Documentation/block/ioprio.txt for more
182 information on the CFQ I/O Scheduler and an example program.
183
184 Required permissions to set I/O priorities
185 Permission to change a process's priority is granted or denied based on
186 two criteria:
187
188 Process ownership
189 An unprivileged process may set the I/O priority only for a
190 process whose real UID matches the real or effective UID of the
191 calling process. A process which has the CAP_SYS_NICE capabil‐
192 ity can change the priority of any process.
193
194 What is the desired priority
195 Attempts to set very high priorities (IOPRIO_CLASS_RT) require
196 the CAP_SYS_ADMIN capability. Up to Linux 2.6.24 also required
197 CAP_SYS_ADMIN to set a very low priority (IOPRIO_CLASS_IDLE),
198 but since Linux 2.6.25, this is no longer required.
199
200 A call to ioprio_set() must follow both rules, or the call will fail
201 with the error EPERM.
202
204 glibc does not yet provide a suitable header file defining the function
205 prototypes and macros described on this page. Suitable definitions can
206 be found in linux/ioprio.h.
207
209 ionice(1), getpriority(2), open(2), capabilities(7), cgroups(7)
210
211 Documentation/block/ioprio.txt in the Linux kernel source tree
212
213
214
215Linux man-pages 6.05 2023-04-03 ioprio_set(2)