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

BUGS

192       Glibc does not yet provide a suitable header file defining the function
193       prototypes and macros described on this page.  Suitable definitions can
194       be found in linux/ioprio.h.
195

SEE ALSO

197       ionice(1), getpriority(2), open(2), capabilities(7)
198
199       Documentation/block/ioprio.txt in the Linux kernel source tree
200

COLOPHON

202       This  page  is  part of release 3.53 of the Linux man-pages project.  A
203       description of the project, and information about reporting  bugs,  can
204       be found at http://www.kernel.org/doc/man-pages/.
205
206
207
208Linux                             2013-02-12                     IOPRIO_SET(2)
Impressum