1IOPRIO_SET(2)              Linux Programmer's Manual             IOPRIO_SET(2)
2
3
4

NAME

6       ioprio_get, ioprio_set - get/set I/O scheduling class and priority
7

SYNOPSIS

9       int ioprio_get(int which, int who);
10       int ioprio_set(int which, int who, int ioprio);
11
12       Note: There are no glibc wrappers for these system calls; see NOTES.
13

DESCRIPTION

15       The  ioprio_get()  and  ioprio_set()  system  calls get and set the I/O
16       scheduling class and priority of one or more threads.
17
18       The which and who arguments identify the thread(s) on which the  system
19       calls  operate.   The which argument determines how who is interpreted,
20       and has one of the following values:
21
22       IOPRIO_WHO_PROCESS
23              who is a process ID or thread ID identifying a single process or
24              thread.  If who is 0, then operate on the calling thread.
25
26       IOPRIO_WHO_PGRP
27              who  is  a  process  group  ID  identifying all the members of a
28              process group.  If who is 0, then operate on the  process  group
29              of which the caller is a member.
30
31       IOPRIO_WHO_USER
32              who  is  a  user ID identifying all of the processes that have a
33              matching real UID.
34
35       If which is specified as IOPRIO_WHO_PGRP or IOPRIO_WHO_USER when  call‐
36       ing  ioprio_get(),  and  more  than  one  process matches who, then the
37       returned priority will be the highest one found among all of the match‐
38       ing  processes.   One priority is said to be higher than another one if
39       it belongs to a higher priority class (IOPRIO_CLASS_RT is  the  highest
40       priority  class;  IOPRIO_CLASS_IDLE  is the lowest) or if it belongs to
41       the same priority class as the other process but has a higher  priority
42       level (a lower priority number means a higher priority level).
43
44       The  ioprio argument given to ioprio_set() is a bit mask that specifies
45       both the scheduling class and the priority to be assigned to the target
46       process(es).  The following macros are used for assembling and dissect‐
47       ing ioprio values:
48
49       IOPRIO_PRIO_VALUE(class, data)
50              Given a scheduling class and priority (data),  this  macro  com‐
51              bines  the  two  values  to  produce  an  ioprio value, which is
52              returned as the result of the macro.
53
54       IOPRIO_PRIO_CLASS(mask)
55              Given mask (an ioprio value), this macro returns its  I/O  class
56              component,   that   is,   one  of  the  values  IOPRIO_CLASS_RT,
57              IOPRIO_CLASS_BE, or IOPRIO_CLASS_IDLE.
58
59       IOPRIO_PRIO_DATA(mask)
60              Given mask (an ioprio value), this macro  returns  its  priority
61              (data) component.
62
63       See  the  NOTES  section for more information on scheduling classes and
64       priorities, as well as the meaning of specifying ioprio as 0.
65
66       I/O priorities are supported for reads and for  synchronous  (O_DIRECT,
67       O_SYNC)  writes.   I/O  priorities  are  not supported for asynchronous
68       writes because they are issued  outside  the  context  of  the  program
69       dirtying the memory, and thus program-specific priorities do not apply.
70

RETURN VALUE

72       On  success,  ioprio_get() returns the ioprio value of the process with
73       highest I/O priority of any of the processes that  match  the  criteria
74       specified in which and who.  On error, -1 is returned, and errno is set
75       to indicate the error.
76
77       On success, ioprio_set() returns 0.  On  error,  -1  is  returned,  and
78       errno is set to indicate the error.
79

ERRORS

81       EINVAL Invalid  value  for which or ioprio.  Refer to the NOTES section
82              for available scheduler classes and priority levels for ioprio.
83
84       EPERM  The calling process does not have the privilege needed to assign
85              this ioprio to the specified process(es).  See the NOTES section
86              for more information on required privileges for ioprio_set().
87
88       ESRCH  No process(es) could be found that matched the specification  in
89              which and who.
90

VERSIONS

92       These system calls have been available on Linux since kernel 2.6.13.
93

CONFORMING TO

95       These system calls are Linux-specific.
96

NOTES

98       Glibc  does  not  provide  a  wrapper for these system calls; call them
99       using syscall(2).
100
101       Two or more processes or threads can share an I/O context.   This  will
102       be  the case when clone(2) was called with the CLONE_IO flag.  However,
103       by default, the distinct threads of a process will not share  the  same
104       I/O context.  This means that if you want to change the I/O priority of
105       all threads in a process, you may need to call ioprio_set() on each  of
106       the  threads.   The thread ID that you would need for this operation is
107       the one that is returned by gettid(2) or clone(2).
108
109       These system calls have an effect only when used in conjunction with an
110       I/O  scheduler  that  supports I/O priorities.  As at kernel 2.6.17 the
111       only such scheduler is the Completely Fair Queuing (CFQ) I/O scheduler.
112
113       If no I/O scheduler has been set for a thread, then by default the  I/O
114       priority  will  follow  the  CPU nice value (setpriority(2)).  In Linux
115       kernels before version 2.6.24, once an I/O priority had been set  using
116       ioprio_set(),  there was no way to reset the I/O scheduling behavior to
117       the default.  Since Linux 2.6.24, specifying ioprio as 0 can be used to
118       reset to the default I/O scheduling behavior.
119
120   Selecting an I/O scheduler
121       I/O  schedulers are selected on a per-device basis via the special file
122       /sys/block/<device>/queue/scheduler.
123
124       One can view the current I/O scheduler via the  /sys  filesystem.   For
125       example,  the  following command displays a list of all schedulers cur‐
126       rently loaded in the kernel:
127
128           $ cat /sys/block/sda/queue/scheduler
129           noop anticipatory deadline [cfq]
130
131       The scheduler surrounded by brackets is the one actually in use for the
132       device  (sda  in  the  example).   Setting another scheduler is done by
133       writing the name of the new scheduler to this file.  For  example,  the
134       following command will set the scheduler for the sda device to cfq:
135
136           $ su
137           Password:
138           # echo cfq > /sys/block/sda/queue/scheduler
139
140   The Completely Fair Queuing (CFQ) I/O scheduler
141       Since  version  3  (also  known as CFQ Time Sliced), CFQ implements I/O
142       nice levels similar to those of CPU scheduling.  These nice levels  are
143       grouped  into three scheduling classes, each one containing one or more
144       priority levels:
145
146       IOPRIO_CLASS_RT (1)
147              This is the real-time I/O class.  This scheduling class is given
148              higher  priority than any other class: processes from this class
149              are given first access to the disk every time.  Thus,  this  I/O
150              class needs to be used with some care: one I/O real-time process
151              can starve the entire system.  Within the real-time class, there
152              are 8 levels of class data (priority) that determine exactly how
153              much time this process needs the disk for on each service.   The
154              highest  real-time priority level is 0; the lowest is 7.  In the
155              future, this might change to be more directly mappable  to  per‐
156              formance, by passing in a desired data rate instead.
157
158       IOPRIO_CLASS_BE (2)
159              This  is  the best-effort scheduling class, which is the default
160              for any process that hasn't set a specific  I/O  priority.   The
161              class  data  (priority)  determines  how  much I/O bandwidth the
162              process will get.  Best-effort priority levels are analogous  to
163              CPU nice values (see getpriority(2)).  The priority level deter‐
164              mines a priority relative to other processes in the  best-effort
165              scheduling  class.   Priority levels range from 0 (highest) to 7
166              (lowest).
167
168       IOPRIO_CLASS_IDLE (3)
169              This is the idle scheduling class.  Processes  running  at  this
170              level  get  I/O  time only when no one else needs the disk.  The
171              idle class has  no  class  data.   Attention  is  required  when
172              assigning  this priority class to a process, since it may become
173              starved if higher priority processes  are  constantly  accessing
174              the disk.
175
176       Refer to the kernel source file Documentation/block/ioprio.txt for more
177       information on the CFQ I/O Scheduler and an example program.
178
179   Required permissions to set I/O priorities
180       Permission to change a process's priority is granted or denied based on
181       two criteria:
182
183       Process ownership
184              An  unprivileged  process  may  set  the I/O priority only for a
185              process whose real UID matches the real or effective UID of  the
186              calling  process.  A process which has the CAP_SYS_NICE capabil‐
187              ity can change the priority of any process.
188
189       What is the desired priority
190              Attempts to set very high priorities  (IOPRIO_CLASS_RT)  require
191              the CAP_SYS_ADMIN capability.  Kernel versions up to 2.6.24 also
192              required   CAP_SYS_ADMIN   to   set   a   very   low    priority
193              (IOPRIO_CLASS_IDLE),  but  since Linux 2.6.25, this is no longer
194              required.
195
196       A call to ioprio_set() must follow both rules, or the  call  will  fail
197       with the error EPERM.
198

BUGS

200       Glibc does not yet provide a suitable header file defining the function
201       prototypes and macros described on this page.  Suitable definitions can
202       be found in linux/ioprio.h.
203

SEE ALSO

205       ionice(1), getpriority(2), open(2), capabilities(7), cgroups(7)
206
207       Documentation/block/ioprio.txt in the Linux kernel source tree
208

COLOPHON

210       This  page  is  part of release 5.07 of the Linux man-pages project.  A
211       description of the project, information about reporting bugs,  and  the
212       latest     version     of     this    page,    can    be    found    at
213       https://www.kernel.org/doc/man-pages/.
214
215
216
217Linux                             2019-03-06                     IOPRIO_SET(2)
Impressum