From d3b383005d81dc439c329c685a134957e3c0b5f7 Mon Sep 17 00:00:00 2001 From: mckusick Date: Fri, 14 Dec 2001 05:50:44 +0000 Subject: Add disk I/O scheduling for positively niced processes. When a positively niced process requests a disk I/O, make it wait for its nice value of ticks before scheduling its I/O request if there are any other processes with I/O requests in the disk queue. For all the gory details, see the ``Running fsck in the Background'' paper in the Usenix BSDCon 2002 Conference Proceedings, pages 55-64. --- sys/kern/subr_disklabel.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'sys/kern/subr_disklabel.c') diff --git a/sys/kern/subr_disklabel.c b/sys/kern/subr_disklabel.c index 1dc0ece..2924c55 100644 --- a/sys/kern/subr_disklabel.c +++ b/sys/kern/subr_disklabel.c @@ -44,12 +44,25 @@ #include #include #include +#include #include #include #include #include /* + * Mutex to use when delaying niced I/O bound processes in bioqdisksort(). + */ +static struct mtx dksort_mtx; +static void +dksort_init(void) +{ + + mtx_init(&dksort_mtx, "dksort", MTX_DEF); +} +SYSINIT(dksort, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dksort_init, NULL) + +/* * Seek sort for disks. * * The buf_queue keep two queues, sorted in ascending block order. The first @@ -72,7 +85,19 @@ bioqdisksort(bioq, bp) struct bio *bq; struct bio *bn; struct bio *be; + struct thread *td = curthread; + if (td && td->td_ksegrp->kg_nice > 0) { + TAILQ_FOREACH(bn, &bioq->queue, bio_queue) + if (BIOTOBUF(bn)->b_vp != BIOTOBUF(bn)->b_vp) + break; + if (bn != NULL) { + mtx_lock(&dksort_mtx); + msleep((caddr_t)&dksort_mtx, &dksort_mtx, + PPAUSE | PCATCH | PDROP, "ioslow", + td->td_ksegrp->kg_nice); + } + } if (!atomic_cmpset_int(&bioq->busy, 0, 1)) panic("Recursing in bioqdisksort()"); be = TAILQ_LAST(&bioq->queue, bio_queue); -- cgit v1.1