1 .\" This is _*_ nroff _*_ source. Emacs, gimme all those colors :)
3 .\" Copyright (c) International Business Machines orp., 2006
5 .\" This program is free software; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
10 .\" This program is distributed in the hope that it will be useful,
11 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
12 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 .\" the GNU General Public License for more details.
15 .\" You should have received a copy of the GNU General Public License
16 .\" along with this program; if not, write to the Free Software
17 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 .\" 2006-04-27, created by Eduardo M. Fleury <efleury@br.ibm.com>
22 .\" with various additions by Michael Kerrisk <mtk.manpages@gmail.com>
25 .TH IOPRIO_SET 2 2013-02-12 "Linux" "Linux Programmer's Manual"
27 ioprio_get, ioprio_set \- get/set I/O scheduling class and priority
30 .BI "int ioprio_get(int " which ", int " who );
31 .BI "int ioprio_set(int " which ", int " who ", int " ioprio );
35 There are no glibc wrappers for these system calls; see NOTES.
41 system calls respectively get and set the I/O scheduling class and
42 priority of one or more threads.
48 arguments identify the thread(s) on which the system
52 argument determines how
54 is interpreted, and has one of the following values:
58 is a process ID or thread ID identifying a single process or thread.
61 is 0, then operate on the calling thread.
65 is a process group ID identifying all the members of a process group.
68 is 0, then operate on the process group of which the caller is a member.
72 is a user ID identifying all of the processes that
73 have a matching real UID.
74 .\" FIXME who==0 needs to be documented,
75 .\" See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=652443
85 and more than one process matches
87 then the returned priority will be the highest one found among
88 all of the matching processes.
89 One priority is said to be
90 higher than another one if it belongs to a higher priority
93 is the highest priority class;
96 or if it belongs to the same priority class as the other process but
97 has a higher priority level (a lower priority number means a
98 higher priority level).
104 is a bit mask that specifies both the scheduling class and the
105 priority to be assigned to the target process(es).
106 The following macros are used for assembling and dissecting
110 .BI IOPRIO_PRIO_VALUE( class ", " data )
115 this macro combines the two values to produce an
117 value, which is returned as the result of the macro.
119 .BI IOPRIO_PRIO_CLASS( mask )
124 value), this macro returns its I/O class component, that is,
126 .BR IOPRIO_CLASS_RT ,
127 .BR IOPRIO_CLASS_BE ,
129 .BR IOPRIO_CLASS_IDLE .
131 .BI IOPRIO_PRIO_DATA( mask )
136 value), this macro returns its priority
140 See the NOTES section for more
141 information on scheduling classes and priorities.
143 I/O priorities are supported for reads and for synchronous
147 I/O priorities are not supported for asynchronous
148 writes because they are issued outside the context of the program
149 dirtying the memory, and thus program-specific priorities do not apply.
155 value of the process with highest I/O priority of any of the processes
156 that match the criteria specified in
160 On error, \-1 is returned, and
162 is set to indicate the error.
167 On error, \-1 is returned, and
169 is set to indicate the error.
177 Refer to the NOTES section for available scheduler
178 classes and priority levels for
182 The calling process does not have the privilege needed to assign this
184 to the specified process(es).
185 See the NOTES section for more information on required
190 No process(es) could be found that matched the specification in
195 These system calls have been available on Linux since
198 These system calls are Linux-specific.
200 Glibc does not provide a wrapper for these system calls; call them using
203 Two or more processes or threads can share an I/O context.
204 This will be the case when
209 However, by default, the distinct threads of a process will
211 share the same I/O context.
212 This means that if you want to change the I/O
213 priority of all threads in a process, you may need to call
215 on each of the threads.
216 The thread ID that you would need for this operation
217 is the one that is returned by
222 These system calls only have an effect when used
223 in conjunction with an I/O scheduler that supports I/O priorities.
224 As at kernel 2.6.17 the only such scheduler is the Completely Fair Queuing
226 .SS Selecting an I/O scheduler
227 I/O Schedulers are selected on a per-device basis via the special
229 .IR /sys/block/<device>/queue/scheduler .
231 One can view the current I/O scheduler via the
234 For example, the following command
235 displays a list of all schedulers currently loaded in the kernel:
239 .RB "$" " cat /sys/block/hda/queue/scheduler"
240 noop anticipatory deadline [cfq]
244 The scheduler surrounded by brackets is the one actually
245 in use for the device
248 Setting another scheduler is done by writing the name of the
249 new scheduler to this file.
250 For example, the following command will set the
260 .RB "#" " echo cfq > /sys/block/hda/queue/scheduler"
263 .SS The Completely Fair Queuing (CFQ) I/O scheduler
264 Since v3 (aka CFQ Time Sliced) CFQ implements
265 I/O nice levels similar to those
267 These nice levels are grouped in three scheduling classes
268 each one containing one or more priority levels:
270 .BR IOPRIO_CLASS_RT " (1)"
271 This is the real-time I/O class.
272 This scheduling class is given
273 higher priority than any other class:
274 processes from this class are
275 given first access to the disk every time.
276 Thus this I/O class needs to be used with some
277 care: one I/O real-time process can starve the entire system.
278 Within the real-time class,
279 there are 8 levels of class data (priority) that determine exactly
280 how much time this process needs the disk for on each service.
281 The highest real-time priority level is 0; the lowest is 7.
282 In the future this might change to be more directly mappable to
283 performance, by passing in a desired data rate instead.
285 .BR IOPRIO_CLASS_BE " (2)"
286 This is the best-effort scheduling class,
287 which is the default for any process
288 that hasn't set a specific I/O priority.
289 The class data (priority) determines how much
290 I/O bandwidth the process will get.
291 Best-effort priority levels are analogous to CPU nice values
293 .BR getpriority (2)).
294 The priority level determines a priority relative
295 to other processes in the best-effort scheduling class.
296 Priority levels range from 0 (highest) to 7 (lowest).
298 .BR IOPRIO_CLASS_IDLE " (3)"
299 This is the idle scheduling class.
300 Processes running at this level only get I/O
301 time when no-one else needs the disk.
302 The idle class has no class data.
303 Attention is required when assigning this priority class to a process,
304 since it may become starved if higher priority processes are
305 constantly accessing the disk.
308 .I Documentation/block/ioprio.txt
309 for more information on the CFQ I/O Scheduler and an example program.
310 .SS Required permissions to set I/O priorities
311 Permission to change a process's priority is granted or denied based
314 .B "Process ownership"
315 An unprivileged process may only set the I/O priority of a process
317 matches the real or effective UID of the calling process.
318 A process which has the
320 capability can change the priority of any process.
322 .B "What is the desired priority"
323 Attempts to set very high priorities
324 .RB ( IOPRIO_CLASS_RT )
328 Kernel versions up to 2.6.24 also required
330 to set a very low priority
331 .RB ( IOPRIO_CLASS_IDLE ),
332 but since Linux 2.6.25, this is no longer required.
336 must follow both rules, or the call will fail with the error
339 .\" 6 May 07: Bug report raised:
340 .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=4464
341 .\" Ulrich Drepper replied that he wasn't going to add these
343 Glibc does not yet provide a suitable header file defining
344 the function prototypes and macros described on this page.
345 Suitable definitions can be found in
353 .I Documentation/block/ioprio.txt
354 in the Linux kernel source tree