Entnommen aus /usr/src/linux/Documentation/block/ioprio.txt von Jens Axboe axboe@suse.de (March 11 2005) und für syscall umgeschrieben.
read: ionice -p $PID set: ionice -n $IOPRIO -p $PID ionice -c $IOPRIOCLASS -p $PID execute: ionice -n $IOPRIO $COMMAND ionice -c $IOPRIOCLASS $COMMAND IOPRIO = 0..7 (0: höchste Priorität/real time, 7: niedrigest Prio./idle) IOCLASS = 1..3 (1: -n0, 2: -n4, 3: -n7)
Hier die Ergebnisse eines kleinen Performancetests:
Während relativ wenig Last vorliegt (kaum HDD-Aktivität)
spot bin # ionice -n7 hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 778 MB in 2.00 seconds = 388.71 MB/sec Timing buffered disk reads: 70 MB in 3.07 seconds = 22.79 MB/sec spot bin # hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 596 MB in 2.00 seconds = 297.43 MB/sec Timing buffered disk reads: 62 MB in 3.02 seconds = 20.55 MB/sec spot bin # ionice -n0 hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 772 MB in 2.00 seconds = 385.24 MB/sec Timing buffered disk reads: 66 MB in 3.09 seconds = 21.36 MB/sec
Während bei mir “find / -name ‘asdf’” lief (HDD-LED ständig am leuchten)
spot bin # ionice -n7 hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 760 MB in 2.00 seconds = 379.51 MB/sec Timing buffered disk reads: 28 MB in 3.38 seconds = 8.28 MB/sec spot bin # hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 756 MB in 2.00 seconds = 377.37 MB/sec Timing buffered disk reads: 46 MB in 3.12 seconds = 14.73 MB/sec spot bin # ionice -n0 hdparm -T -t /dev/hda /dev/hda: Timing cached reads: 782 MB in 2.00 seconds = 390.84 MB/sec Timing buffered disk reads: 54 MB in 3.03 seconds = 17.80 MB/sec
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <getopt.h> #include <unistd.h> #include <sys/ptrace.h> #include <asm/unistd.h> #include <sys/syscall.h> #if defined(__i386__) #define __NR_ioprio_set 289 #define __NR_ioprio_get 290 #elif defined(__ppc__) #define __NR_ioprio_set 273 #define __NR_ioprio_get 274 #elif defined(__x86_64__) #define __NR_ioprio_set 251 #define __NR_ioprio_get 252 #elif defined(__ia64__) #define __NR_ioprio_set 1274 #define __NR_ioprio_get 1275 #else #error "Unsupported arch" #endif enum { IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE, }; enum { IOPRIO_WHO_PROCESS = 1, IOPRIO_WHO_PGRP, IOPRIO_WHO_USER, }; #define IOPRIO_CLASS_SHIFT 13 const char *to_prio[] = { "none", "realtime", "best-effort", "idle", }; int main(int argc, char *argv[]) { int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE; int c, pid = 0; while ((c = getopt(argc, argv, "+n:c:p:")) != EOF) { switch (c) { case 'n': ioprio = strtol(optarg, NULL, 10); set = 1; break; case 'c': ioprio_class = strtol(optarg, NULL, 10); set = 1; break; case 'p': pid = strtol(optarg, NULL, 10); break; } } switch (ioprio_class) { case IOPRIO_CLASS_NONE: ioprio_class = IOPRIO_CLASS_BE; break; case IOPRIO_CLASS_RT: case IOPRIO_CLASS_BE: break; case IOPRIO_CLASS_IDLE: ioprio = 7; break; default: printf("bad prio class %d\n", ioprio_class); return 1; } if (!set) { if (!pid && argv[optind]) pid = strtol(argv[optind], NULL, 10); ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid); printf("pid=%d, %d\n", pid, ioprio); if (ioprio == -1) perror("ioprio_get"); else { ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT; ioprio = ioprio & 0xff; printf("%s: prio %d\n", to_prio[ioprio_class], ioprio); } } else { if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { perror("ioprio_set"); return 1; } if (argv[optind]) execvp(argv[optind], &argv[optind]); } return 0; }
7a8 > #include <sys/syscall.h> 9,10d9 < extern int sys_ioprio_set(int, int, int); < extern int sys_ioprio_get(int, int); 28,30d26 < _syscall3(int, ioprio_set, int, which, int, who, int, ioprio); < _syscall2(int, ioprio_get, int, which, int, who); < 88c84 < ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid); --- > ioprio = syscall(SYS_ioprio_get, IOPRIO_WHO_PROCESS, pid); 100c96 < if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) { --- > if (syscall(SYS_ioprio_set, IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {