IO Priorities
Subsystems (3)
Hello all,
About a week ago, I said I would try to implement IO priorities.
I tried. I got the whole thing done, but there is one major problem - it doesn't work the way it is supposed to. For example, I wrote a little shell script that calls:
time dd if=/dev/zero of=dump bs=4096 count=200000
It calls it twice, once as the highest priority (0) and once as the lowest priority (39). The only difference (besides the output file) is the io priority. Nice values are _not_ connected with io prio (at least not yet.) The only thing that the io_prio affects is the coefficient in front of the cfq time slice length (see patch). The interesting thing that happens is that sometimes the lower priority process finishes before the higher priority one - even though the time slices are WAY way different in size (1ms and 223ms). Con Kolivas told me that he experienced the same odd behaviour when he implemented io priorities on top of deadline.
I know the priorities do change the duration of the time slice since I see that at times certain processes get starved while others at high priority happily run. This seems to contradict the mesurements with the 4 io tests (see bottom of this email), but it does happen. I am hoping that I am overlooking something that I need to modify in CFQ, but it doesn't look that way.
The patch itself requires Jens Axboe's CFQ#4. It is still work in progress -- it needs a cleanup, and some other things, like adding the security calls to the new syscalls, and the syscalls have to be added to other architectures than i386 as well, but those are not critical.
Any ideas?
Jeff.
To call the syscalls I created a few utilities
http://shells.gnugeneration.com/~jeffpc/kernel/v2.6/ioprio_utils.tar.bz2
(b1beeb82155054e7acf5a92628c7efaa ioprio_utils.tar.bz2)
These are the 4 io tests I used in total:
# reader time cat dump > /dev/null
# writer time dd if=/dev/zero of=dump bs=4096 count=200000
# tar (dump.tar == 2 built BK kernel trees ~900MB) time tar xf dump.tar
# tiobench tiobench --size 800 --numruns 4 --dir /tmp --block 65536 --random 1000 --threads 4
arch/i386/kernel/entry.S +3 -0
@@ -864,5 +864,8 @@ .long sys_add_key .long sys_request_key .long sys_keyctl + .long sys_io_prio + .long sys_getiopriority /* 290 */ + .long sys_setiopriority syscall_table_size=(.-sys_call_table)
drivers/block/cfq-iosched.c +23 -7
@@ -33,10 +33,20 @@static int cfq_back_max =16 *1024 ;/* maximum backwards seek, in KiB */ static int cfq_back_penalty =2 ;/* penalty of a backwards seek */ -static int cfq_slice_sync =HZ /10 ; -static int cfq_slice_async =HZ /25 ; +static int cfq_slice_sync =HZ /1000 ; +static int cfq_slice_async =HZ /1000 ;static int cfq_slice_async_rq =16 ; -static int cfq_slice_idle =HZ /249 ; +static int cfq_slice_idle =HZ /1000 ; + +/* the slice scaling factors */ +static int cfq_prio_scale[] = {223 ,194 ,169 ,147 ,128 ,/* 0..4 */ +111 ,97 ,84 ,73 ,64 ,/* 5..9 */ +56 ,49 ,42 ,36 ,32 ,/* 10..14 */ +28 ,24 ,21 ,18 ,16 ,/* 15..19 */ +14 ,12 ,11 ,9 ,8 ,/* 20..24 */ +7 ,6 ,5 ,5 ,4 ,/* 25..29 */ +3 ,3 ,2 ,2 ,2 ,/* 30..34 */ +1 ,1 ,1 ,1 ,1 };/* 35..39 */ static int cfq_max_depth =4 ;
@@ -98,6 +108,9 @@*/ #define CFQ_KEY_SPARE (~0UL) +#define CFQ_MIN_IO_PRIO IOPRIO_MIN +#define CFQ_MAX_IO_PRIO IOPRIO_MAX +static kmem_cache_t *crq_pool;static kmem_cache_t *cfq_pool;static kmem_cache_t *cfq_ioc_pool;
@@ -133,6 +146,7 @@struct work_struct unplug_work;struct cfq_queue *active_queue;unsigned int dispatch_slice; +unsigned int cfq_prio_scale[(CFQ_MAX_IO_PRIO -CFQ_MIN_IO_PRIO ) +1 ];/* * tunables, see top of file
@@ -176,6 +190,7 @@unsigned long last_fifo_expire;int key_type; +int io_prio;unsigned long slice_start;unsigned long slice_end;
@@ -912,7 +927,7 @@* sync, use the sync time slice value */ if (!cfqq->slice_end) - cfqq->slice_end = cfqd->cfq_slice[!!sync] + jiffies; + cfqq->slice_end = cfqd->cfq_prio_scale[cfqq->io_prio]*cfqd->cfq_slice[!!sync] + jiffies;/* * expire an async queue immediately if it has used up its slice
@@ -946,7 +961,6 @@ {struct cfq_queue *cfqq = crq->cfq_queue;struct cfq_data *cfqd = cfqq->cfqd; -unsigned long now, elapsed;if (unlikely (!blk_fs_request (crq->request)))return ;
@@ -972,13 +986,13 @@WARN_ON (!cfqd->rq_in_driver); cfqd->rq_in_driver--; } - +/* * queue was preempted while this request was servicing */ if (cfqd->active_queue != cfqq)return ; - +/* * this is still the active queue. if we have nothing to do and no * more pending requests in flight, wait for a new sync request if
@@ -1093,6 +1107,7 @@ *cfqq = __cfqq; } + __cfqq->io_prio = current->io_prio; cic->cfqq = __cfqq;spin_unlock_irqrestore (cfqd->queue->queue_lock, flags); }
@@ -1744,6 +1759,7 @@ cfqd->cfq_slice_async_rq = cfq_slice_async_rq; cfqd->cfq_slice_idle = cfq_slice_idle; cfqd->cfq_max_depth = cfq_max_depth; +memcpy (cfqd->cfq_prio_scale, cfq_prio_scale,sizeof (cfq_prio_scale));return 0 ; out_spare:
include/asm-i386/unistd.h +4 -1
@@ -294,8 +294,11 @@#define __NR_add_key 286#define __NR_request_key 287#define __NR_keyctl 288 +#define __NR_io_prio 289 +#define __NR_getiopriority 290 +#define __NR_setiopriority 291 -#define NR_syscalls 289 +#define NR_syscalls 292/* * user-visible error numbers are in the range -1 - -128: see
include/linux/resource.h +4 -0
@@ -42,6 +42,10 @@unsigned long rlim_max; }; +#define IOPRIO_MIN 0 +#define IOPRIO_MAX 39 +#define IOPRIO_DEFAULT 20 +#define PRIO_MIN (-20)#define PRIO_MAX 20
include/linux/sched.h +5 -0
@@ -664,6 +664,9 @@struct mempolicy *mempolicy;short il_next;/* could be shared with used_math */ #endif + +/* io priority */ +short io_prio; };static inline pid_t process_group (struct task_struct *tsk)
@@ -723,8 +726,10 @@extern void sched_idle_next (void );extern void set_user_nice (task_t *p,long nice); +extern void set_user_ioprio (task_t *p,long ioprio);extern int task_prio (const task_t *p);extern int task_nice (const task_t *p); +extern int task_ioprio (const task_t *p);extern int task_curr (const task_t *p);extern int idle_cpu (int cpu);extern unsigned long task_will_schedule_at (const task_t *p);
include/linux/security.h +12 -0
@@ -1717,6 +1717,13 @@return security_ops->task_setnice (p, nice); } +static inline int security_task_setioprio (struct task_struct *p,int prio) +{ +#warn "Fixme! Add security_ops->task_setprio" +return 1 ; +//return security_ops->task_setioprio (p, prio); +} +static inline int security_task_setrlimit (unsigned int resource,struct rlimit *new_rlim) {
@@ -2353,6 +2360,11 @@ }static inline int security_task_setnice (struct task_struct *p,int nice) +{ +return 0 ; +} + +static inline int security_task_setioprio (struct task_struct *p,int prio) {return 0 ; }
init/main.c +1 -0
@@ -443,6 +443,7 @@ static void noinline rest_init(void)__releases (kernel_lock) { + current->io_prio =IOPRIO_DEFAULT ;kernel_thread (init,NULL ,CLONE_FS |CLONE_SIGHAND );numa_default_policy ();unlock_kernel ();
kernel/sched.c +52 -0
82 lines not on this page · raw message
kernel/sys.c +129 -0
141 lines not on this page · raw message
Quoted 3 lines · Jeff Sipek
Hello all,
About a week ago, I said I would try to implement IO priorities.
I tried. I got the whole thing done, but there is one major problem - it
I did too, did you see my patch?
Quoted 5 lines
doesn't work the way it is supposed to. For example, I wrote a little shell script that calls:
time dd if=/dev/zero of=dump bs=4096 count=200000
Quoted 9 lines
It calls it twice, once as the highest priority (0) and once as the lowest priority (39). The only difference (besides the output file) is the io priority. Nice values are _not_ connected with io prio (at least not yet.) The only thing that the
io_prioaffects is the coefficient in front of the cfq time slice length (see patch). The interesting thing that happens is that sometimes the lower priority process finishes before the higher priority one - even though the time slices are WAY way different in size (1ms and 223ms). Con Kolivas told me that he experienced the same odd behaviour when he implemented io priorities on top of deadline.
Well, for this specific case, I'd suggest you check out how much of the write out actually happens in context of that process. Often you end up with pdflush(es) doing the process dirty work, and the io priorities aren't inherited across that boundary.
drivers/block/cfq-iosched.c line 39
Quoted 7 lines
drivers/block/cfq-iosched.c +3
-3-static int cfq_slice_sync =HZ /10 ; -static int cfq_slice_async =HZ /25 ; +static int cfq_slice_sync =HZ /1000 ; +static int cfq_slice_async =HZ /1000 ;static int cfq_slice_async_rq =16 ; -static int cfq_slice_idle =HZ /249 ; +static int cfq_slice_idle =HZ /1000 ;
You need to be careful, on archs with HZ == 100 you just set every time slice to 0.
drivers/block/cfq-iosched.c line 49
Quoted 9 lines
drivers/block/cfq-iosched.c +9
-0+/* the slice scaling factors */ +static int cfq_prio_scale[] = {223 ,194 ,169 ,147 ,128 ,/* 0..4 */ +111 ,97 ,84 ,73 ,64 ,/* 5..9 */ +56 ,49 ,42 ,36 ,32 ,/* 10..14 */ +28 ,24 ,21 ,18 ,16 ,/* 15..19 */ +14 ,12 ,11 ,9 ,8 ,/* 20..24 */ +7 ,6 ,5 ,5 ,4 ,/* 25..29 */ +3 ,3 ,2 ,2 ,2 ,/* 30..34 */ +1 ,1 ,1 ,1 ,1 };/* 35..39 */
I think it's pointless to scale it so fine grained (see my earlier postings).
Additionally, you don't do anything with the priorities internally.
Signature · 1 line
Jens Axboe
Quoted 6 lines · Jens Axboe
Quoted 3 lines · Jeff Sipek
Hello all,
About a week ago, I said I would try to implement IO priorities.
I tried. I got the whole thing done, but there is one major problem - itI did too, did you see my patch?
I did after I sent mine. I was reading it and I noticed:
"Disable TCQ in the hardware/driver by default. Can be changed (as always) with the max_depth setting. If you do that, don't expect fairness or priorities to work as well."
Would this cause my problem?
Quoted 15 lines
Quoted 5 lines
doesn't work the way it is supposed to. For example, I wrote a little shell script that calls:
time dd if=/dev/zero of=dump bs=4096 count=200000
Quoted 9 lines
It calls it twice, once as the highest priority (0) and once as the lowest priority (39). The only difference (besides the output file) is the io priority. Nice values are _not_ connected with io prio (at least not yet.) The only thing that the
io_prioaffects is the coefficient in front of the cfq time slice length (see patch). The interesting thing that happens is that sometimes the lower priority process finishes before the higher priority one - even though the time slices are WAY way different in size (1ms and 223ms). Con Kolivas told me that he experienced the same odd behaviour when he implemented io priorities on top of deadline.
Quoted 4 lines
Well, for this specific case, I'd suggest you check out how much of the write out actually happens in context of that process. Often you end up with pdflush(es) doing the process dirty work, and the io priorities aren't inherited across that boundary.
Hmm....will do.
Quoted 10 lines
drivers/block/cfq-iosched.c line 39
Quoted 7 lines
drivers/block/cfq-iosched.c +3
-3-static int cfq_slice_sync =HZ /10 ; -static int cfq_slice_async =HZ /25 ; +static int cfq_slice_sync =HZ /1000 ; +static int cfq_slice_async =HZ /1000 ;static int cfq_slice_async_rq =16 ; -static int cfq_slice_idle =HZ /249 ; +static int cfq_slice_idle =HZ /1000 ;You need to be careful, on archs with HZ == 100 you just set every time slice to 0.
Yes, I was trying to get to work on my box first.
Quoted 4 lines
Quoted 4 lines
drivers/block/cfq-iosched.c +4
-0+/* the slice scaling factors */ +static int cfq_prio_scale[] = {223 ,194 ,169 ,147 ,128 ,/* 0..4 */ +111 ,97 ,84 ,73 ,64 ,/* 5..9 */ +56 ,49 ,42 ,36 ,32 ,/* 10..14 */
Quoted 8 lines
drivers/block/cfq-iosched.c line 49
Quoted 5 lines
drivers/block/cfq-iosched.c +5
-0+28 ,24 ,21 ,18 ,16 ,/* 15..19 */ +14 ,12 ,11 ,9 ,8 ,/* 20..24 */ +7 ,6 ,5 ,5 ,4 ,/* 25..29 */ +3 ,3 ,2 ,2 ,2 ,/* 30..34 */ + 1, 1, 1, 1, 1}; /* 35..39 */I think it's pointless to scale it so fine grained (see my earlier postings).
I guess 40 priorities is a little too much. Now that I am thinking about it more, 40 levels is way too much. I'll change it later.
Quoted 1 line
Additionally, you don't do anything with the priorities internally.
Sure I do, I multiply the slice by cfq_prio_scale[ioprio]. It did seem too simple. :-) Looking at your code right now, I kind of see some code that should have been in my implementation as well. Back to coding... :-)
Jeff.
Quoted 8 lines · Jeff Sipek
Quoted 6 lines · Jens Axboe
Quoted 3 lines · Jeff Sipek
Hello all,
About a week ago, I said I would try to implement IO priorities.
I tried. I got the whole thing done, but there is one major problem - itI did too, did you see my patch?
Quoted 7 lines
I did after I sent mine. I was reading it and I noticed:
"Disable TCQ in the hardware/driver by default. Can be changed (as always) with the
max_depthsetting. If you do that, don't expect fairness or priorities to work as well."Would this cause my problem?
Only if you test on SCSI with TCQ enabled. But I already outlined what your problems are even if you did.
Quoted 6 lines
Quoted 1 line
Additionally, you don't do anything with the priorities internally.
Sure I do, I multiply the slice by cfq_prio_scale[ioprio]. It did seem too simple. :-) Looking at your code right now, I kind of see some code that should have been in my implementation as well. Back to coding... :-)
If you would base changes on what I already did with CFQ, that would be handy. You need the CFQ bits anyways.
Updated patch here:
Signature · 1 line
Jens Axboe