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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

VERSIONS

88       These system calls have been available on Linux since kernel 2.6.13.
89

CONFORMING TO

91       These system calls are Linux-specific.
92

NOTES

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

BUGS

180       Glibc does not yet provide a suitable header file defining the function
181       prototypes and macros described on this page.  Suitable definitions can
182       be found in linux/ioprio.h.
183

SEE ALSO

185       getpriority(2), open(2), capabilities(7)
186
187       Documentation/block/ioprio.txt in the kernel source tree.
188

COLOPHON

190       This  page  is  part of release 3.22 of the Linux man-pages project.  A
191       description of the project, and information about reporting  bugs,  can
192       be found at http://www.kernel.org/doc/man-pages/.
193
194
195
196Linux                             2008-07-09                     IOPRIO_SET(2)
Impressum