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

NAME

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

SYNOPSIS

9       #include <errno.h>
10       #include <linux/unistd.h>
11
12       _syscall2(int, ioprio_get, int, which, int, who);
13       _syscall3(int, ioprio_set, int, which, int, who, int, ioprio);
14               /* Using syscall(2) might be preferable; see intro(2) */
15
16       int ioprio_get(int which, int who);
17       int ioprio_set(int which, int who, int ioprio);
18

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

NOTES

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

BUGS

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

VERSIONS

182       These system calls have been available on Linux since kernel 2.6.13.
183

CONFORMING TO

185       These system calls are Linux specific.
186

SEE ALSO

188       getpriority(2), open(2), capabilities(7)
189
190       Documentation/block/ioprio.txt in the kernel source tree.
191
192
193
1942.6.13                            2006-04-27                     IOPRIO_GET(2)
Impressum