From badbdcedefad1088a80279d80cb217d918259f5b Mon Sep 17 00:00:00 2001 From: Marc Fiuczynski Date: Mon, 13 Sep 2004 03:07:20 +0000 Subject: [PATCH] ckrm_E15-io-controller --- arch/i386/kernel/entry.S | 2 + arch/ppc/kernel/misc.S | 2 + drivers/block/Makefile | 3 +- drivers/block/cfq-iosched.c | 1014 ++++++++++++++++++++++++++++++----- drivers/block/elevator.c | 10 +- drivers/block/ll_rw_blk.c | 45 +- fs/exec.c | 13 - include/asm-i386/unistd.h | 4 +- include/asm-ppc/unistd.h | 4 +- include/asm-x86_64/unistd.h | 6 +- include/linux/ckrm_rc.h | 12 +- include/linux/elevator.h | 5 + include/linux/fs.h | 12 + include/linux/init_task.h | 1 + include/linux/mm.h | 3 - include/linux/mm_inline.h | 7 - include/linux/sched.h | 11 +- init/Kconfig | 29 +- kernel/ckrm/Makefile | 1 - kernel/ckrm/ckrmutils.c | 19 + kernel/ckrm/rbce/rbcemod.c | 1 + kernel/exit.c | 7 - kernel/fork.c | 21 +- mm/fremap.c | 2 - mm/memory.c | 2 - mm/page_alloc.c | 7 - mm/rmap.c | 2 - mm/vmscan.c | 148 +---- 28 files changed, 986 insertions(+), 407 deletions(-) diff --git a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S index 7b6856363..d66058134 100644 --- a/arch/i386/kernel/entry.S +++ b/arch/i386/kernel/entry.S @@ -886,5 +886,7 @@ ENTRY(sys_call_table) .long sys_mq_notify .long sys_mq_getsetattr .long sys_ni_syscall /* reserved for kexec */ + .long sys_ioprio_set + .long sys_ioprio_get /* 285 */ syscall_table_size=(.-sys_call_table) diff --git a/arch/ppc/kernel/misc.S b/arch/ppc/kernel/misc.S index c3ed5ed1d..433996927 100644 --- a/arch/ppc/kernel/misc.S +++ b/arch/ppc/kernel/misc.S @@ -1398,3 +1398,5 @@ _GLOBAL(sys_call_table) .long sys_mq_notify .long sys_mq_getsetattr .long sys_ni_syscall /* 268 reserved for sys_kexec_load */ + .long sys_ioprio_set + .long sys_ioprio_get diff --git a/drivers/block/Makefile b/drivers/block/Makefile index 33b14e84c..40293f417 100644 --- a/drivers/block/Makefile +++ b/drivers/block/Makefile @@ -13,12 +13,13 @@ # kblockd threads # -obj-y := elevator.o ll_rw_blk.o ioctl.o genhd.o scsi_ioctl.o +obj-y := elevator.o ll_rw_blk.o ioctl.o genhd.o scsi_ioctl.o ckrm-iostub.o obj-$(CONFIG_IOSCHED_NOOP) += noop-iosched.o obj-$(CONFIG_IOSCHED_AS) += as-iosched.o obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o +obj-$(CONFIG_CKRM_RES_BLKIO) += ckrm-io.o obj-$(CONFIG_MAC_FLOPPY) += swim3.o obj-$(CONFIG_BLK_DEV_FD) += floppy.o obj-$(CONFIG_BLK_DEV_FD98) += floppy98.o diff --git a/drivers/block/cfq-iosched.c b/drivers/block/cfq-iosched.c index 977d32ddd..d37911a64 100644 --- a/drivers/block/cfq-iosched.c +++ b/drivers/block/cfq-iosched.c @@ -6,6 +6,18 @@ * Based on ideas from a previously unfinished io * scheduler (round robin per-process disk scheduling) and Andrea Arcangeli. * + * IO priorities are supported, from 0% to 100% in 5% increments. Both of + * those values have special meaning - 0% class is allowed to do io if + * noone else wants to use the disk. 100% is considered real-time io, and + * always get priority. Default process io rate is 95%. In absence of other + * io, a class may consume 100% disk bandwidth regardless. Withing a class, + * bandwidth is distributed equally among the citizens. + * + * TODO: + * - cfq_select_requests() needs some work for 5-95% io + * - barriers not supported + * - export grace periods in ms, not jiffies + * * Copyright (C) 2003 Jens Axboe */ #include @@ -22,69 +34,160 @@ #include #include +#if IOPRIO_NR > BITS_PER_LONG +#error Cannot support this many io priority levels +#endif + /* * tunables */ -static int cfq_quantum = 4; -static int cfq_queued = 8; +static int cfq_quantum = 6; +static int cfq_quantum_io = 256; +static int cfq_idle_quantum = 1; +static int cfq_idle_quantum_io = 64; +static int cfq_queued = 4; +static int cfq_grace_rt = HZ / 100 ?: 1; +static int cfq_grace_idle = HZ / 10; #define CFQ_QHASH_SHIFT 6 #define CFQ_QHASH_ENTRIES (1 << CFQ_QHASH_SHIFT) -#define list_entry_qhash(entry) list_entry((entry), struct cfq_queue, cfq_hash) +#define list_entry_qhash(entry) hlist_entry((entry), struct cfq_queue, cfq_hash) #define CFQ_MHASH_SHIFT 8 #define CFQ_MHASH_BLOCK(sec) ((sec) >> 3) #define CFQ_MHASH_ENTRIES (1 << CFQ_MHASH_SHIFT) #define CFQ_MHASH_FN(sec) (hash_long(CFQ_MHASH_BLOCK((sec)),CFQ_MHASH_SHIFT)) -#define ON_MHASH(crq) !list_empty(&(crq)->hash) #define rq_hash_key(rq) ((rq)->sector + (rq)->nr_sectors) -#define list_entry_hash(ptr) list_entry((ptr), struct cfq_rq, hash) +#define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash) #define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list) +#define list_entry_prio(ptr) list_entry((ptr), struct cfq_rq, prio_list) + +#define cfq_account_io(crq) \ + ((crq)->ioprio != IOPRIO_IDLE && (crq)->ioprio != IOPRIO_RT) + +/* + * defines how we distribute bandwidth (can be tgid, uid, etc) + */ -#define RQ_DATA(rq) ((struct cfq_rq *) (rq)->elevator_private) +/* FIXME: change hash_key to be sizeof(void *) rather than sizeof(int) + * otherwise the cast of cki_tsk_icls will not work reliably on 64-bit arches. + * OR, change cki_tsk_icls to return ints (will need another id space to be + * managed) + */ + +#if defined(CONFIG_CKRM_RES_BLKIO) || defined(CONFIG_CKRM_RES_BLKIO_MODULE) +extern inline void *cki_hash_key(struct task_struct *tsk); +extern inline int cki_ioprio(struct task_struct *tsk); +#define cfq_hash_key(current) ((int)cki_hash_key((current))) +#define cfq_ioprio(current) (cki_ioprio((current))) + +#else +#define cfq_hash_key(current) ((current)->tgid) +/* + * move to io_context + */ +#define cfq_ioprio(current) ((current)->ioprio) +#endif + +#define CFQ_WAIT_RT 0 +#define CFQ_WAIT_NORM 1 static kmem_cache_t *crq_pool; static kmem_cache_t *cfq_pool; static mempool_t *cfq_mpool; -struct cfq_data { +/* + * defines an io priority level + */ +struct io_prio_data { struct list_head rr_list; + int busy_queues; + int busy_rq; + unsigned long busy_sectors; + + /* Statistics on requests, sectors and queues + * added to (in) and dispatched from (out) + * this priority level. Reinsertion of previously + * dispatched crq's into cfq's results in double counting + * which is ignored for now as in-out should + * still be accurate. + */ + atomic_t cum_rq_in,cum_rq_out; + atomic_t cum_sectors_in,cum_sectors_out; + atomic_t cum_queues_in,cum_queues_out; + + struct list_head prio_list; + int last_rq; + int last_sectors; +}; + +/* + * per-request queue structure + */ +struct cfq_data { struct list_head *dispatch; - struct list_head *cfq_hash; + struct hlist_head *cfq_hash; + struct hlist_head *crq_hash; + mempool_t *crq_pool; - struct list_head *crq_hash; + struct io_prio_data cid[IOPRIO_NR]; - unsigned int busy_queues; - unsigned int max_queued; + /* + * total number of busy queues and requests + */ + int busy_rq; + int busy_queues; + unsigned long busy_sectors; - mempool_t *crq_pool; + unsigned long rq_starved_mask; + + /* + * grace period handling + */ + struct timer_list timer; + unsigned long wait_end; + unsigned long flags; + struct work_struct work; + + /* + * tunables + */ + unsigned int cfq_quantum; + unsigned int cfq_quantum_io; + unsigned int cfq_idle_quantum; + unsigned int cfq_idle_quantum_io; + unsigned int cfq_queued; + unsigned int cfq_grace_rt; + unsigned int cfq_grace_idle; }; +/* + * per-class structure + */ struct cfq_queue { - struct list_head cfq_hash; struct list_head cfq_list; + struct hlist_node cfq_hash; + int hash_key; struct rb_root sort_list; - int pid; int queued[2]; -#if 0 - /* - * with a simple addition like this, we can do io priorities. almost. - * does need a split request free list, too. - */ - int io_prio -#endif + int ioprio; }; +/* + * per-request structure + */ struct cfq_rq { + struct cfq_queue *cfq_queue; struct rb_node rb_node; + struct hlist_node hash; sector_t rb_key; struct request *request; - struct cfq_queue *cfq_queue; - - struct list_head hash; + struct list_head prio_list; + unsigned long nr_sectors; + int ioprio; }; static void cfq_put_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq); @@ -94,18 +197,13 @@ static void cfq_dispatch_sort(struct list_head *head, struct cfq_rq *crq); /* * lots of deadline iosched dupes, can be abstracted later... */ -static inline void __cfq_del_crq_hash(struct cfq_rq *crq) -{ - list_del_init(&crq->hash); -} - static inline void cfq_del_crq_hash(struct cfq_rq *crq) { - if (ON_MHASH(crq)) - __cfq_del_crq_hash(crq); + hlist_del_init(&crq->hash); } -static void cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq) +static inline void +cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq) { cfq_del_crq_hash(crq); @@ -116,27 +214,26 @@ static void cfq_remove_merge_hints(request_queue_t *q, struct cfq_rq *crq) static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq) { struct request *rq = crq->request; + const int hash_idx = CFQ_MHASH_FN(rq_hash_key(rq)); - BUG_ON(ON_MHASH(crq)); + BUG_ON(!hlist_unhashed(&crq->hash)); - list_add(&crq->hash, &cfqd->crq_hash[CFQ_MHASH_FN(rq_hash_key(rq))]); + hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]); } static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset) { - struct list_head *hash_list = &cfqd->crq_hash[CFQ_MHASH_FN(offset)]; - struct list_head *entry, *next = hash_list->next; + struct hlist_head *hash_list = &cfqd->crq_hash[CFQ_MHASH_FN(offset)]; + struct hlist_node *entry, *next; - while ((entry = next) != hash_list) { + hlist_for_each_safe(entry, next, hash_list) { struct cfq_rq *crq = list_entry_hash(entry); struct request *__rq = crq->request; - next = entry->next; - - BUG_ON(!ON_MHASH(crq)); + BUG_ON(hlist_unhashed(&crq->hash)); if (!rq_mergeable(__rq)) { - __cfq_del_crq_hash(crq); + cfq_del_crq_hash(crq); continue; } @@ -150,20 +247,27 @@ static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset) /* * rb tree support functions */ -#define RB_NONE (2) -#define RB_EMPTY(node) ((node)->rb_node == NULL) -#define RB_CLEAR(node) ((node)->rb_color = RB_NONE) -#define RB_CLEAR_ROOT(root) ((root)->rb_node = NULL) -#define ON_RB(node) ((node)->rb_color != RB_NONE) +#define RB_EMPTY(node) ((node)->rb_node == NULL) #define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) #define rq_rb_key(rq) (rq)->sector -static inline void cfq_del_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq) +static void +cfq_del_crq_rb(struct cfq_data *cfqd, struct cfq_queue *cfqq,struct cfq_rq *crq) { - if (ON_RB(&crq->rb_node)) { + if (crq->cfq_queue) { + crq->cfq_queue = NULL; + + if (cfq_account_io(crq)) { + cfqd->busy_rq--; + cfqd->busy_sectors -= crq->nr_sectors; + cfqd->cid[crq->ioprio].busy_rq--; + atomic_inc(&(cfqd->cid[crq->ioprio].cum_rq_out)); + cfqd->cid[crq->ioprio].busy_sectors -= crq->nr_sectors; + atomic_add(crq->nr_sectors,&(cfqd->cid[crq->ioprio].cum_sectors_out)); + } + cfqq->queued[rq_data_dir(crq->request)]--; rb_erase(&crq->rb_node, &cfqq->sort_list); - crq->cfq_queue = NULL; } } @@ -196,17 +300,25 @@ cfq_add_crq_rb(struct cfq_data *cfqd, struct cfq_queue *cfqq,struct cfq_rq *crq) struct request *rq = crq->request; struct cfq_rq *__alias; - crq->rb_key = rq_rb_key(rq); cfqq->queued[rq_data_dir(rq)]++; + if (cfq_account_io(crq)) { + cfqd->busy_rq++; + cfqd->busy_sectors += crq->nr_sectors; + cfqd->cid[crq->ioprio].busy_rq++; + atomic_inc(&(cfqd->cid[crq->ioprio].cum_rq_in)); + cfqd->cid[crq->ioprio].busy_sectors += crq->nr_sectors; + atomic_add(crq->nr_sectors,&(cfqd->cid[crq->ioprio].cum_sectors_in)); + } retry: __alias = __cfq_add_crq_rb(cfqq, crq); if (!__alias) { rb_insert_color(&crq->rb_node, &cfqq->sort_list); + crq->rb_key = rq_rb_key(rq); crq->cfq_queue = cfqq; return; } - cfq_del_crq_rb(cfqq, __alias); + cfq_del_crq_rb(cfqd, cfqq, __alias); cfq_dispatch_sort(cfqd->dispatch, __alias); goto retry; } @@ -214,7 +326,7 @@ retry: static struct request * cfq_find_rq_rb(struct cfq_data *cfqd, sector_t sector) { - struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, current->tgid); + struct cfq_queue *cfqq = cfq_find_cfq_hash(cfqd, cfq_hash_key(current)); struct rb_node *n; if (!cfqq) @@ -239,16 +351,30 @@ out: static void cfq_remove_request(request_queue_t *q, struct request *rq) { struct cfq_data *cfqd = q->elevator.elevator_data; - struct cfq_rq *crq = RQ_DATA(rq); + struct cfq_rq *crq = RQ_ELV_DATA(rq); if (crq) { - struct cfq_queue *cfqq = crq->cfq_queue; - cfq_remove_merge_hints(q, crq); + list_del_init(&crq->prio_list); list_del_init(&rq->queuelist); - if (cfqq) { - cfq_del_crq_rb(cfqq, crq); + /* + * set a grace period timer to allow realtime io to make real + * progress, if we release an rt request. for normal request, + * set timer so idle io doesn't interfere with other io + */ + if (crq->ioprio == IOPRIO_RT) { + set_bit(CFQ_WAIT_RT, &cfqd->flags); + cfqd->wait_end = jiffies + cfqd->cfq_grace_rt; + } else if (crq->ioprio != IOPRIO_IDLE) { + set_bit(CFQ_WAIT_NORM, &cfqd->flags); + cfqd->wait_end = jiffies + cfqd->cfq_grace_idle; + } + + if (crq->cfq_queue) { + struct cfq_queue *cfqq = crq->cfq_queue; + + cfq_del_crq_rb(cfqd, cfqq, crq); if (RB_EMPTY(&cfqq->sort_list)) cfq_put_queue(cfqd, cfqq); @@ -298,18 +424,22 @@ out_insert: static void cfq_merged_request(request_queue_t *q, struct request *req) { struct cfq_data *cfqd = q->elevator.elevator_data; - struct cfq_rq *crq = RQ_DATA(req); + struct cfq_rq *crq = RQ_ELV_DATA(req); cfq_del_crq_hash(crq); cfq_add_crq_hash(cfqd, crq); - if (ON_RB(&crq->rb_node) && (rq_rb_key(req) != crq->rb_key)) { + if (crq->cfq_queue && (rq_rb_key(req) != crq->rb_key)) { struct cfq_queue *cfqq = crq->cfq_queue; - cfq_del_crq_rb(cfqq, crq); + cfq_del_crq_rb(cfqd, cfqq, crq); cfq_add_crq_rb(cfqd, cfqq, crq); } + cfqd->busy_sectors += req->hard_nr_sectors - crq->nr_sectors; + cfqd->cid[crq->ioprio].busy_sectors += req->hard_nr_sectors - crq->nr_sectors; + crq->nr_sectors = req->hard_nr_sectors; + q->last_merge = req; } @@ -321,6 +451,9 @@ cfq_merged_requests(request_queue_t *q, struct request *req, cfq_remove_request(q, next); } +/* + * sort into dispatch list, in optimal ascending order + */ static void cfq_dispatch_sort(struct list_head *head, struct cfq_rq *crq) { struct list_head *entry = head; @@ -346,49 +479,164 @@ link: list_add_tail(&crq->request->queuelist, entry); } -static inline void +/* + * remove from io scheduler core and put on dispatch list for service + */ +static inline int __cfq_dispatch_requests(request_queue_t *q, struct cfq_data *cfqd, struct cfq_queue *cfqq) { - struct cfq_rq *crq = rb_entry_crq(rb_first(&cfqq->sort_list)); + struct cfq_rq *crq; + + crq = rb_entry_crq(rb_first(&cfqq->sort_list)); - cfq_del_crq_rb(cfqq, crq); + cfq_del_crq_rb(cfqd, cfqq, crq); cfq_remove_merge_hints(q, crq); cfq_dispatch_sort(cfqd->dispatch, crq); + + /* + * technically, for IOPRIO_RT we don't need to add it to the list. + */ + list_add_tail(&crq->prio_list, &cfqd->cid[cfqq->ioprio].prio_list); + return crq->nr_sectors; } -static int cfq_dispatch_requests(request_queue_t *q, struct cfq_data *cfqd) +static int +cfq_dispatch_requests(request_queue_t *q, int prio, int max_rq, int max_sectors) { - struct cfq_queue *cfqq; - struct list_head *entry, *tmp; - int ret, queued, good_queues; - - if (list_empty(&cfqd->rr_list)) - return 0; + struct cfq_data *cfqd = q->elevator.elevator_data; + struct list_head *plist = &cfqd->cid[prio].rr_list; + struct list_head *entry, *nxt; + int q_rq, q_io; - queued = ret = 0; -restart: - good_queues = 0; - list_for_each_safe(entry, tmp, &cfqd->rr_list) { - cfqq = list_entry_cfqq(cfqd->rr_list.next); + /* + * for each queue at this prio level, dispatch a request + */ + q_rq = q_io = 0; + list_for_each_safe(entry, nxt, plist) { + struct cfq_queue *cfqq = list_entry_cfqq(entry); BUG_ON(RB_EMPTY(&cfqq->sort_list)); - __cfq_dispatch_requests(q, cfqd, cfqq); + q_io += __cfq_dispatch_requests(q, cfqd, cfqq); + q_rq++; if (RB_EMPTY(&cfqq->sort_list)) cfq_put_queue(cfqd, cfqq); - else - good_queues++; - queued++; - ret = 1; + /* + * if we hit the queue limit, put the string of serviced + * queues at the back of the pending list + */ + if (q_io >= max_sectors || q_rq >= max_rq) { + struct list_head *prv = nxt->prev; + + if (prv != plist) { + list_del(plist); + list_add(plist, prv); + } + break; + } } - if ((queued < cfq_quantum) && good_queues) - goto restart; + cfqd->cid[prio].last_rq = q_rq; + cfqd->cid[prio].last_sectors = q_io; + return q_rq; +} - return ret; +/* + * try to move some requests to the dispatch list. return 0 on success + */ +static int cfq_select_requests(request_queue_t *q, struct cfq_data *cfqd) +{ + int queued, busy_rq, busy_sectors, i; + + /* + * if there's any realtime io, only schedule that + */ + if (cfq_dispatch_requests(q, IOPRIO_RT, cfqd->cfq_quantum, cfqd->cfq_quantum_io)) + return 1; + + /* + * if RT io was last serviced and grace time hasn't expired, + * arm the timer to restart queueing if no other RT io has been + * submitted in the mean time + */ + if (test_bit(CFQ_WAIT_RT, &cfqd->flags)) { + if (time_before(jiffies, cfqd->wait_end)) { + mod_timer(&cfqd->timer, cfqd->wait_end); + return 0; + } + clear_bit(CFQ_WAIT_RT, &cfqd->flags); + } + + /* + * for each priority level, calculate number of requests we + * are allowed to put into service. + */ + queued = 0; + busy_rq = cfqd->busy_rq; + busy_sectors = cfqd->busy_sectors; + for (i = IOPRIO_RT - 1; i > IOPRIO_IDLE; i--) { + const int o_rq = busy_rq - cfqd->cid[i].busy_rq; + const int o_sectors = busy_sectors - cfqd->cid[i].busy_sectors; + int q_rq = cfqd->cfq_quantum * (i + 1) / IOPRIO_NR; + int q_io = cfqd->cfq_quantum_io * (i + 1) / IOPRIO_NR; + + /* + * no need to keep iterating the list, if there are no + * requests pending anymore + */ + if (!cfqd->busy_rq) + break; + + /* + * find out how many requests and sectors we are allowed to + * service + */ + if (o_rq) + q_rq = o_sectors * (i + 1) / IOPRIO_NR; + if (q_rq > cfqd->cfq_quantum) + q_rq = cfqd->cfq_quantum; + + if (o_sectors) + q_io = o_sectors * (i + 1) / IOPRIO_NR; + if (q_io > cfqd->cfq_quantum_io) + q_io = cfqd->cfq_quantum_io; + + /* + * average with last dispatched for fairness + */ + if (cfqd->cid[i].last_rq != -1) + q_rq = (cfqd->cid[i].last_rq + q_rq) / 2; + if (cfqd->cid[i].last_sectors != -1) + q_io = (cfqd->cid[i].last_sectors + q_io) / 2; + + queued += cfq_dispatch_requests(q, i, q_rq, q_io); + } + + if (queued) + return 1; + + /* + * only allow dispatch of idle io, if the queue has been idle from + * servicing RT or normal io for the grace period + */ + if (test_bit(CFQ_WAIT_NORM, &cfqd->flags)) { + if (time_before(jiffies, cfqd->wait_end)) { + mod_timer(&cfqd->timer, cfqd->wait_end); + return 0; + } + clear_bit(CFQ_WAIT_NORM, &cfqd->flags); + } + + /* + * if we found nothing to do, allow idle io to be serviced + */ + if (cfq_dispatch_requests(q, IOPRIO_IDLE, cfqd->cfq_idle_quantum, cfqd->cfq_idle_quantum_io)) + return 1; + + return 0; } static struct request *cfq_next_request(request_queue_t *q) @@ -399,96 +647,185 @@ static struct request *cfq_next_request(request_queue_t *q) if (!list_empty(cfqd->dispatch)) { struct cfq_rq *crq; dispatch: + /* + * end grace period, we are servicing a request + */ + del_timer(&cfqd->timer); + clear_bit(CFQ_WAIT_RT, &cfqd->flags); + clear_bit(CFQ_WAIT_NORM, &cfqd->flags); + + BUG_ON(list_empty(cfqd->dispatch)); rq = list_entry_rq(cfqd->dispatch->next); - crq = RQ_DATA(rq); - if (crq) - cfq_remove_merge_hints(q, crq); + BUG_ON(q->last_merge == rq); + crq = RQ_ELV_DATA(rq); + if (crq) { + BUG_ON(!hlist_unhashed(&crq->hash)); + list_del_init(&crq->prio_list); + } return rq; } - if (cfq_dispatch_requests(q, cfqd)) + /* + * we moved requests to dispatch list, go back end serve one + */ + if (cfq_select_requests(q, cfqd)) goto dispatch; return NULL; } static inline struct cfq_queue * -__cfq_find_cfq_hash(struct cfq_data *cfqd, int pid, const int hashval) +__cfq_find_cfq_hash(struct cfq_data *cfqd, int hashkey, const int hashval) { - struct list_head *hash_list = &cfqd->cfq_hash[hashval]; - struct list_head *entry; + struct hlist_head *hash_list = &cfqd->cfq_hash[hashval]; + struct hlist_node *entry; - list_for_each(entry, hash_list) { + hlist_for_each(entry, hash_list) { struct cfq_queue *__cfqq = list_entry_qhash(entry); - if (__cfqq->pid == pid) + if (__cfqq->hash_key == hashkey) return __cfqq; } return NULL; } -static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *cfqd, int pid) +static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *cfqd, int hashkey) { - const int hashval = hash_long(current->tgid, CFQ_QHASH_SHIFT); + const int hashval = hash_long(hashkey, CFQ_QHASH_SHIFT); - return __cfq_find_cfq_hash(cfqd, pid, hashval); + return __cfq_find_cfq_hash(cfqd, hashkey, hashval); } static void cfq_put_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) { cfqd->busy_queues--; + WARN_ON(cfqd->busy_queues < 0); + + cfqd->cid[cfqq->ioprio].busy_queues--; + WARN_ON(cfqd->cid[cfqq->ioprio].busy_queues < 0); + atomic_inc(&(cfqd->cid[cfqq->ioprio].cum_queues_out)); + list_del(&cfqq->cfq_list); - list_del(&cfqq->cfq_hash); + hlist_del(&cfqq->cfq_hash); mempool_free(cfqq, cfq_mpool); } -static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, int pid) +static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, int hashkey) { - const int hashval = hash_long(current->tgid, CFQ_QHASH_SHIFT); - struct cfq_queue *cfqq = __cfq_find_cfq_hash(cfqd, pid, hashval); + const int hashval = hash_long(hashkey, CFQ_QHASH_SHIFT); + struct cfq_queue *cfqq = __cfq_find_cfq_hash(cfqd, hashkey, hashval); if (!cfqq) { cfqq = mempool_alloc(cfq_mpool, GFP_NOIO); - INIT_LIST_HEAD(&cfqq->cfq_hash); + memset(cfqq, 0, sizeof(*cfqq)); + INIT_HLIST_NODE(&cfqq->cfq_hash); INIT_LIST_HEAD(&cfqq->cfq_list); - RB_CLEAR_ROOT(&cfqq->sort_list); - cfqq->pid = pid; - cfqq->queued[0] = cfqq->queued[1] = 0; - list_add(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); + cfqq->hash_key = cfq_hash_key(current); + cfqq->ioprio = cfq_ioprio(current); + hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); } return cfqq; } -static void cfq_enqueue(struct cfq_data *cfqd, struct cfq_rq *crq) +static void +__cfq_enqueue(request_queue_t *q, struct cfq_data *cfqd, struct cfq_rq *crq) { + const int prio = crq->ioprio; struct cfq_queue *cfqq; - cfqq = cfq_get_queue(cfqd, current->tgid); + cfqq = cfq_get_queue(cfqd, cfq_hash_key(current)); + + /* + * not too good... + */ + if (prio > cfqq->ioprio) { + printk("prio hash collision %d %d\n", prio, cfqq->ioprio); + if (!list_empty(&cfqq->cfq_list)) { + cfqd->cid[cfqq->ioprio].busy_queues--; + WARN_ON(cfqd->cid[cfqq->ioprio].busy_queues < 0); + atomic_inc(&(cfqd->cid[cfqq->ioprio].cum_queues_out)); + cfqd->cid[prio].busy_queues++; + atomic_inc(&(cfqd->cid[prio].cum_queues_in)); + list_move_tail(&cfqq->cfq_list, &cfqd->cid[prio].rr_list); + } + cfqq->ioprio = prio; + } cfq_add_crq_rb(cfqd, cfqq, crq); if (list_empty(&cfqq->cfq_list)) { - list_add(&cfqq->cfq_list, &cfqd->rr_list); + list_add_tail(&cfqq->cfq_list, &cfqd->cid[prio].rr_list); + cfqd->cid[prio].busy_queues++; + atomic_inc(&(cfqd->cid[prio].cum_queues_in)); cfqd->busy_queues++; } + + if (rq_mergeable(crq->request)) { + cfq_add_crq_hash(cfqd, crq); + + if (!q->last_merge) + q->last_merge = crq->request; + } + +} + +static void cfq_reenqueue(request_queue_t *q, struct cfq_data *cfqd, int prio) +{ + struct list_head *prio_list = &cfqd->cid[prio].prio_list; + struct list_head *entry, *tmp; + + list_for_each_safe(entry, tmp, prio_list) { + struct cfq_rq *crq = list_entry_prio(entry); + + list_del_init(entry); + list_del_init(&crq->request->queuelist); + __cfq_enqueue(q, cfqd, crq); + } +} + +static void +cfq_enqueue(request_queue_t *q, struct cfq_data *cfqd, struct cfq_rq *crq) +{ + const int prio = cfq_ioprio(current); + + crq->ioprio = prio; + crq->nr_sectors = crq->request->hard_nr_sectors; + __cfq_enqueue(q, cfqd, crq); + + if (prio == IOPRIO_RT) { + int i; + + /* + * realtime io gets priority, move all other io back + */ + for (i = IOPRIO_IDLE; i < IOPRIO_RT; i++) + cfq_reenqueue(q, cfqd, i); + } else if (prio != IOPRIO_IDLE) { + /* + * check if we need to move idle io back into queue + */ + cfq_reenqueue(q, cfqd, IOPRIO_IDLE); + } } static void cfq_insert_request(request_queue_t *q, struct request *rq, int where) { struct cfq_data *cfqd = q->elevator.elevator_data; - struct cfq_rq *crq = RQ_DATA(rq); + struct cfq_rq *crq = RQ_ELV_DATA(rq); switch (where) { case ELEVATOR_INSERT_BACK: +#if 0 while (cfq_dispatch_requests(q, cfqd)) ; +#endif list_add_tail(&rq->queuelist, cfqd->dispatch); break; case ELEVATOR_INSERT_FRONT: @@ -496,26 +833,19 @@ cfq_insert_request(request_queue_t *q, struct request *rq, int where) break; case ELEVATOR_INSERT_SORT: BUG_ON(!blk_fs_request(rq)); - cfq_enqueue(cfqd, crq); + cfq_enqueue(q, cfqd, crq); break; default: printk("%s: bad insert point %d\n", __FUNCTION__,where); return; } - - if (rq_mergeable(rq)) { - cfq_add_crq_hash(cfqd, crq); - - if (!q->last_merge) - q->last_merge = rq; - } } static int cfq_queue_empty(request_queue_t *q) { struct cfq_data *cfqd = q->elevator.elevator_data; - if (list_empty(cfqd->dispatch) && list_empty(&cfqd->rr_list)) + if (list_empty(cfqd->dispatch) && !cfqd->busy_queues) return 1; return 0; @@ -524,7 +854,7 @@ static int cfq_queue_empty(request_queue_t *q) static struct request * cfq_former_request(request_queue_t *q, struct request *rq) { - struct cfq_rq *crq = RQ_DATA(rq); + struct cfq_rq *crq = RQ_ELV_DATA(rq); struct rb_node *rbprev = rb_prev(&crq->rb_node); if (rbprev) @@ -536,7 +866,7 @@ cfq_former_request(request_queue_t *q, struct request *rq) static struct request * cfq_latter_request(request_queue_t *q, struct request *rq) { - struct cfq_rq *crq = RQ_DATA(rq); + struct cfq_rq *crq = RQ_ELV_DATA(rq); struct rb_node *rbnext = rb_next(&crq->rb_node); if (rbnext) @@ -545,27 +875,47 @@ cfq_latter_request(request_queue_t *q, struct request *rq) return NULL; } +static void cfq_queue_congested(request_queue_t *q) +{ + struct cfq_data *cfqd = q->elevator.elevator_data; + + set_bit(cfq_ioprio(current), &cfqd->rq_starved_mask); +} + static int cfq_may_queue(request_queue_t *q, int rw) { struct cfq_data *cfqd = q->elevator.elevator_data; struct cfq_queue *cfqq; - int ret = 1; + const int prio = cfq_ioprio(current); + int limit, ret = 1; if (!cfqd->busy_queues) goto out; - cfqq = cfq_find_cfq_hash(cfqd, current->tgid); - if (cfqq) { - int limit = (q->nr_requests - cfq_queued) / cfqd->busy_queues; + cfqq = cfq_find_cfq_hash(cfqd, cfq_hash_key(current)); + if (!cfqq) + goto out; - if (limit < 3) - limit = 3; - else if (limit > cfqd->max_queued) - limit = cfqd->max_queued; + cfqq = cfq_find_cfq_hash(cfqd, cfq_hash_key(current)); + if (!cfqq) + goto out; + + /* + * if higher or equal prio io is sleeping waiting for a request, don't + * allow this one to allocate one. as long as ll_rw_blk does fifo + * waitqueue wakeups this should work... + */ + if (cfqd->rq_starved_mask & ~((1 << prio) - 1)) + goto out; + + if (cfqq->queued[rw] < cfqd->cfq_queued || !cfqd->cid[prio].busy_queues) + goto out; + + limit = q->nr_requests * (prio + 1) / IOPRIO_NR; + limit /= cfqd->cid[prio].busy_queues; + if (cfqq->queued[rw] > limit) + ret = 0; - if (cfqq->queued[rw] > limit) - ret = 0; - } out: return ret; } @@ -573,11 +923,11 @@ out: static void cfq_put_request(request_queue_t *q, struct request *rq) { struct cfq_data *cfqd = q->elevator.elevator_data; - struct cfq_rq *crq = RQ_DATA(rq); + struct cfq_rq *crq = RQ_ELV_DATA(rq); if (crq) { BUG_ON(q->last_merge == rq); - BUG_ON(ON_MHASH(crq)); + BUG_ON(!hlist_unhashed(&crq->hash)); mempool_free(crq, cfqd->crq_pool); rq->elevator_private = NULL; @@ -590,10 +940,15 @@ static int cfq_set_request(request_queue_t *q, struct request *rq, int gfp_mask) struct cfq_rq *crq = mempool_alloc(cfqd->crq_pool, gfp_mask); if (crq) { - RB_CLEAR(&crq->rb_node); + /* + * process now has one request + */ + clear_bit(cfq_ioprio(current), &cfqd->rq_starved_mask); + + memset(crq, 0, sizeof(*crq)); crq->request = rq; - crq->cfq_queue = NULL; - INIT_LIST_HEAD(&crq->hash); + INIT_HLIST_NODE(&crq->hash); + INIT_LIST_HEAD(&crq->prio_list); rq->elevator_private = crq; return 0; } @@ -612,6 +967,26 @@ static void cfq_exit(request_queue_t *q, elevator_t *e) kfree(cfqd); } +static void cfq_timer(unsigned long data) +{ + struct cfq_data *cfqd = (struct cfq_data *) data; + + clear_bit(CFQ_WAIT_RT, &cfqd->flags); + clear_bit(CFQ_WAIT_NORM, &cfqd->flags); + kblockd_schedule_work(&cfqd->work); +} + +static void cfq_work(void *data) +{ + request_queue_t *q = data; + unsigned long flags; + + spin_lock_irqsave(q->queue_lock, flags); + if (cfq_next_request(q)) + q->request_fn(q); + spin_unlock_irqrestore(q->queue_lock, flags); +} + static int cfq_init(request_queue_t *q, elevator_t *e) { struct cfq_data *cfqd; @@ -622,13 +997,34 @@ static int cfq_init(request_queue_t *q, elevator_t *e) return -ENOMEM; memset(cfqd, 0, sizeof(*cfqd)); - INIT_LIST_HEAD(&cfqd->rr_list); - cfqd->crq_hash = kmalloc(sizeof(struct list_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL); + init_timer(&cfqd->timer); + cfqd->timer.function = cfq_timer; + cfqd->timer.data = (unsigned long) cfqd; + + INIT_WORK(&cfqd->work, cfq_work, q); + + for (i = 0; i < IOPRIO_NR; i++) { + struct io_prio_data *cid = &cfqd->cid[i]; + + INIT_LIST_HEAD(&cid->rr_list); + INIT_LIST_HEAD(&cid->prio_list); + cid->last_rq = -1; + cid->last_sectors = -1; + + atomic_set(&cid->cum_rq_in,0); + atomic_set(&cid->cum_rq_out,0); + atomic_set(&cid->cum_sectors_in,0); + atomic_set(&cid->cum_sectors_out,0); + atomic_set(&cid->cum_queues_in,0); + atomic_set(&cid->cum_queues_out,0); + } + + cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL); if (!cfqd->crq_hash) goto out_crqhash; - cfqd->cfq_hash = kmalloc(sizeof(struct list_head) * CFQ_QHASH_ENTRIES, GFP_KERNEL); + cfqd->cfq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_QHASH_ENTRIES, GFP_KERNEL); if (!cfqd->cfq_hash) goto out_cfqhash; @@ -637,20 +1033,23 @@ static int cfq_init(request_queue_t *q, elevator_t *e) goto out_crqpool; for (i = 0; i < CFQ_MHASH_ENTRIES; i++) - INIT_LIST_HEAD(&cfqd->crq_hash[i]); + INIT_HLIST_HEAD(&cfqd->crq_hash[i]); for (i = 0; i < CFQ_QHASH_ENTRIES; i++) - INIT_LIST_HEAD(&cfqd->cfq_hash[i]); + INIT_HLIST_HEAD(&cfqd->cfq_hash[i]); + + cfqd->cfq_queued = cfq_queued; + cfqd->cfq_quantum = cfq_quantum; + cfqd->cfq_quantum_io = cfq_quantum_io; + cfqd->cfq_idle_quantum = cfq_idle_quantum; + cfqd->cfq_idle_quantum_io = cfq_idle_quantum_io; + cfqd->cfq_grace_rt = cfq_grace_rt; + cfqd->cfq_grace_idle = cfq_grace_idle; + + q->nr_requests <<= 2; cfqd->dispatch = &q->queue_head; e->elevator_data = cfqd; - /* - * just set it to some high value, we want anyone to be able to queue - * some requests. fairness is handled differently - */ - cfqd->max_queued = q->nr_requests; - q->nr_requests = 8192; - return 0; out_crqpool: kfree(cfqd->cfq_hash); @@ -685,8 +1084,328 @@ static int __init cfq_slab_setup(void) subsys_initcall(cfq_slab_setup); +/* + * sysfs parts below --> + */ +struct cfq_fs_entry { + struct attribute attr; + ssize_t (*show)(struct cfq_data *, char *); + ssize_t (*store)(struct cfq_data *, const char *, size_t); +}; + +static ssize_t +cfq_var_show(unsigned int var, char *page) +{ + return sprintf(page, "%d\n", var); +} + +static ssize_t +cfq_var_store(unsigned int *var, const char *page, size_t count) +{ + char *p = (char *) page; + + *var = simple_strtoul(p, &p, 10); + return count; +} + +#define SHOW_FUNCTION(__FUNC, __VAR) \ +static ssize_t __FUNC(struct cfq_data *cfqd, char *page) \ +{ \ + return cfq_var_show(__VAR, (page)); \ +} +SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum); +SHOW_FUNCTION(cfq_quantum_io_show, cfqd->cfq_quantum_io); +SHOW_FUNCTION(cfq_idle_quantum_show, cfqd->cfq_idle_quantum); +SHOW_FUNCTION(cfq_idle_quantum_io_show, cfqd->cfq_idle_quantum_io); +SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued); +SHOW_FUNCTION(cfq_grace_rt_show, cfqd->cfq_grace_rt); +SHOW_FUNCTION(cfq_grace_idle_show, cfqd->cfq_grace_idle); +#undef SHOW_FUNCTION + +#define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX) \ +static ssize_t __FUNC(struct cfq_data *cfqd, const char *page, size_t count) \ +{ \ + int ret = cfq_var_store(__PTR, (page), count); \ + if (*(__PTR) < (MIN)) \ + *(__PTR) = (MIN); \ + else if (*(__PTR) > (MAX)) \ + *(__PTR) = (MAX); \ + return ret; \ +} +STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, INT_MAX); +STORE_FUNCTION(cfq_quantum_io_store, &cfqd->cfq_quantum_io, 4, INT_MAX); +STORE_FUNCTION(cfq_idle_quantum_store, &cfqd->cfq_idle_quantum, 1, INT_MAX); +STORE_FUNCTION(cfq_idle_quantum_io_store, &cfqd->cfq_idle_quantum_io, 4, INT_MAX); +STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, INT_MAX); +STORE_FUNCTION(cfq_grace_rt_store, &cfqd->cfq_grace_rt, 0, INT_MAX); +STORE_FUNCTION(cfq_grace_idle_store, &cfqd->cfq_grace_idle, 0, INT_MAX); +#undef STORE_FUNCTION + + +/* Additional entries to get priority level data */ +static ssize_t +cfq_prio_show(struct cfq_data *cfqd, char *page, unsigned int priolvl) +{ + int r1,r2,s1,s2,q1,q2; + + if (!(priolvl >= IOPRIO_IDLE && priolvl <= IOPRIO_RT)) + return 0; + + r1 = (int)atomic_read(&(cfqd->cid[priolvl].cum_rq_in)); + r2 = (int)atomic_read(&(cfqd->cid[priolvl].cum_rq_out)); + s1 = (int)atomic_read(&(cfqd->cid[priolvl].cum_sectors_in)); + s2 = (int)atomic_read(&(cfqd->cid[priolvl].cum_sectors_out)); + q1 = (int)atomic_read(&(cfqd->cid[priolvl].cum_queues_in)); + q2 = (int)atomic_read(&(cfqd->cid[priolvl].cum_queues_out)); + + + /* + return sprintf(page,"rq %d (%d,%d) sec %d (%d,%d) q %d (%d,%d)\n", + r1-r2,r1,r2, + s1-s2,s1,s2, + q1-q2,q1,q2); + */ + + return sprintf(page,"rq (%d,%d) sec (%d,%d) q (%d,%d)\n", + r1,r2, + s1,s2, + q1,q2); + +} + +#define SHOW_PRIO_DATA(__PRIOLVL) \ +static ssize_t cfq_prio_##__PRIOLVL##_show(struct cfq_data *cfqd, char *page) \ +{ \ + return cfq_prio_show(cfqd,page,__PRIOLVL); \ +} +SHOW_PRIO_DATA(0); +SHOW_PRIO_DATA(1); +SHOW_PRIO_DATA(2); +SHOW_PRIO_DATA(3); +SHOW_PRIO_DATA(4); +SHOW_PRIO_DATA(5); +SHOW_PRIO_DATA(6); +SHOW_PRIO_DATA(7); +SHOW_PRIO_DATA(8); +SHOW_PRIO_DATA(9); +SHOW_PRIO_DATA(10); +SHOW_PRIO_DATA(11); +SHOW_PRIO_DATA(12); +SHOW_PRIO_DATA(13); +SHOW_PRIO_DATA(14); +SHOW_PRIO_DATA(15); +SHOW_PRIO_DATA(16); +SHOW_PRIO_DATA(17); +SHOW_PRIO_DATA(18); +SHOW_PRIO_DATA(19); +SHOW_PRIO_DATA(20); +#undef SHOW_PRIO_DATA + + +static ssize_t cfq_prio_store(struct cfq_data *cfqd, const char *page, size_t count, int priolvl) +{ + atomic_set(&(cfqd->cid[priolvl].cum_rq_in),0); + atomic_set(&(cfqd->cid[priolvl].cum_rq_out),0); + atomic_set(&(cfqd->cid[priolvl].cum_sectors_in),0); + atomic_set(&(cfqd->cid[priolvl].cum_sectors_out),0); + atomic_set(&(cfqd->cid[priolvl].cum_queues_in),0); + atomic_set(&(cfqd->cid[priolvl].cum_queues_out),0); + + return count; +} + + +#define STORE_PRIO_DATA(__PRIOLVL) \ +static ssize_t cfq_prio_##__PRIOLVL##_store(struct cfq_data *cfqd, const char *page, size_t count) \ +{ \ + return cfq_prio_store(cfqd,page,count,__PRIOLVL); \ +} +STORE_PRIO_DATA(0); +STORE_PRIO_DATA(1); +STORE_PRIO_DATA(2); +STORE_PRIO_DATA(3); +STORE_PRIO_DATA(4); +STORE_PRIO_DATA(5); +STORE_PRIO_DATA(6); +STORE_PRIO_DATA(7); +STORE_PRIO_DATA(8); +STORE_PRIO_DATA(9); +STORE_PRIO_DATA(10); +STORE_PRIO_DATA(11); +STORE_PRIO_DATA(12); +STORE_PRIO_DATA(13); +STORE_PRIO_DATA(14); +STORE_PRIO_DATA(15); +STORE_PRIO_DATA(16); +STORE_PRIO_DATA(17); +STORE_PRIO_DATA(18); +STORE_PRIO_DATA(19); +STORE_PRIO_DATA(20); +#undef STORE_PRIO_DATA + + + +static struct cfq_fs_entry cfq_quantum_entry = { + .attr = {.name = "quantum", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_quantum_show, + .store = cfq_quantum_store, +}; +static struct cfq_fs_entry cfq_quantum_io_entry = { + .attr = {.name = "quantum_io", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_quantum_io_show, + .store = cfq_quantum_io_store, +}; +static struct cfq_fs_entry cfq_idle_quantum_entry = { + .attr = {.name = "idle_quantum", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_idle_quantum_show, + .store = cfq_idle_quantum_store, +}; +static struct cfq_fs_entry cfq_idle_quantum_io_entry = { + .attr = {.name = "idle_quantum_io", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_idle_quantum_io_show, + .store = cfq_idle_quantum_io_store, +}; +static struct cfq_fs_entry cfq_queued_entry = { + .attr = {.name = "queued", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_queued_show, + .store = cfq_queued_store, +}; +static struct cfq_fs_entry cfq_grace_rt_entry = { + .attr = {.name = "grace_rt", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_grace_rt_show, + .store = cfq_grace_rt_store, +}; +static struct cfq_fs_entry cfq_grace_idle_entry = { + .attr = {.name = "grace_idle", .mode = S_IRUGO | S_IWUSR }, + .show = cfq_grace_idle_show, + .store = cfq_grace_idle_store, +}; + +#define P_0_STR "p0" +#define P_1_STR "p1" +#define P_2_STR "p2" +#define P_3_STR "p3" +#define P_4_STR "p4" +#define P_5_STR "p5" +#define P_6_STR "p6" +#define P_7_STR "p7" +#define P_8_STR "p8" +#define P_9_STR "p9" +#define P_10_STR "p10" +#define P_11_STR "p11" +#define P_12_STR "p12" +#define P_13_STR "p13" +#define P_14_STR "p14" +#define P_15_STR "p15" +#define P_16_STR "p16" +#define P_17_STR "p17" +#define P_18_STR "p18" +#define P_19_STR "p19" +#define P_20_STR "p20" + + +#define CFQ_PRIO_SYSFS_ENTRY(__PRIOLVL) \ +static struct cfq_fs_entry cfq_prio_##__PRIOLVL##_entry = { \ + .attr = {.name = P_##__PRIOLVL##_STR, .mode = S_IRUGO | S_IWUSR }, \ + .show = cfq_prio_##__PRIOLVL##_show, \ + .store = cfq_prio_##__PRIOLVL##_store, \ +}; +CFQ_PRIO_SYSFS_ENTRY(0); +CFQ_PRIO_SYSFS_ENTRY(1); +CFQ_PRIO_SYSFS_ENTRY(2); +CFQ_PRIO_SYSFS_ENTRY(3); +CFQ_PRIO_SYSFS_ENTRY(4); +CFQ_PRIO_SYSFS_ENTRY(5); +CFQ_PRIO_SYSFS_ENTRY(6); +CFQ_PRIO_SYSFS_ENTRY(7); +CFQ_PRIO_SYSFS_ENTRY(8); +CFQ_PRIO_SYSFS_ENTRY(9); +CFQ_PRIO_SYSFS_ENTRY(10); +CFQ_PRIO_SYSFS_ENTRY(11); +CFQ_PRIO_SYSFS_ENTRY(12); +CFQ_PRIO_SYSFS_ENTRY(13); +CFQ_PRIO_SYSFS_ENTRY(14); +CFQ_PRIO_SYSFS_ENTRY(15); +CFQ_PRIO_SYSFS_ENTRY(16); +CFQ_PRIO_SYSFS_ENTRY(17); +CFQ_PRIO_SYSFS_ENTRY(18); +CFQ_PRIO_SYSFS_ENTRY(19); +CFQ_PRIO_SYSFS_ENTRY(20); +#undef CFQ_PRIO_SYSFS_ENTRY + + +static struct attribute *default_attrs[] = { + &cfq_quantum_entry.attr, + &cfq_quantum_io_entry.attr, + &cfq_idle_quantum_entry.attr, + &cfq_idle_quantum_io_entry.attr, + &cfq_queued_entry.attr, + &cfq_grace_rt_entry.attr, + &cfq_grace_idle_entry.attr, + &cfq_prio_0_entry.attr, + &cfq_prio_1_entry.attr, + &cfq_prio_2_entry.attr, + &cfq_prio_3_entry.attr, + &cfq_prio_4_entry.attr, + &cfq_prio_5_entry.attr, + &cfq_prio_6_entry.attr, + &cfq_prio_7_entry.attr, + &cfq_prio_8_entry.attr, + &cfq_prio_9_entry.attr, + &cfq_prio_10_entry.attr, + &cfq_prio_11_entry.attr, + &cfq_prio_12_entry.attr, + &cfq_prio_13_entry.attr, + &cfq_prio_14_entry.attr, + &cfq_prio_15_entry.attr, + &cfq_prio_16_entry.attr, + &cfq_prio_17_entry.attr, + &cfq_prio_18_entry.attr, + &cfq_prio_19_entry.attr, + &cfq_prio_20_entry.attr, + NULL, +}; + +#define to_cfq(atr) container_of((atr), struct cfq_fs_entry, attr) + +static ssize_t +cfq_attr_show(struct kobject *kobj, struct attribute *attr, char *page) +{ + elevator_t *e = container_of(kobj, elevator_t, kobj); + struct cfq_fs_entry *entry = to_cfq(attr); + + if (!entry->show) + return 0; + + return entry->show(e->elevator_data, page); +} + +static ssize_t +cfq_attr_store(struct kobject *kobj, struct attribute *attr, + const char *page, size_t length) +{ + elevator_t *e = container_of(kobj, elevator_t, kobj); + struct cfq_fs_entry *entry = to_cfq(attr); + + if (!entry->store) + return -EINVAL; + + return entry->store(e->elevator_data, page, length); +} + +static struct sysfs_ops cfq_sysfs_ops = { + .show = cfq_attr_show, + .store = cfq_attr_store, +}; + +struct kobj_type cfq_ktype = { + .sysfs_ops = &cfq_sysfs_ops, + .default_attrs = default_attrs, +}; + elevator_t iosched_cfq = { .elevator_name = "cfq", + .elevator_ktype = &cfq_ktype, .elevator_merge_fn = cfq_merge, .elevator_merged_fn = cfq_merged_request, .elevator_merge_req_fn = cfq_merged_requests, @@ -699,6 +1418,7 @@ elevator_t iosched_cfq = { .elevator_set_req_fn = cfq_set_request, .elevator_put_req_fn = cfq_put_request, .elevator_may_queue_fn = cfq_may_queue, + .elevator_set_congested_fn = cfq_queue_congested, .elevator_init_fn = cfq_init, .elevator_exit_fn = cfq_exit, }; diff --git a/drivers/block/elevator.c b/drivers/block/elevator.c index 4ce5ca130..b01dd4e4e 100644 --- a/drivers/block/elevator.c +++ b/drivers/block/elevator.c @@ -331,6 +331,14 @@ void elv_put_request(request_queue_t *q, struct request *rq) e->elevator_put_req_fn(q, rq); } +void elv_set_congested(request_queue_t *q) +{ + elevator_t *e = &q->elevator; + + if (e->elevator_set_congested_fn) + e->elevator_set_congested_fn(q); +} + int elv_may_queue(request_queue_t *q, int rw) { elevator_t *e = &q->elevator; @@ -338,7 +346,7 @@ int elv_may_queue(request_queue_t *q, int rw) if (e->elevator_may_queue_fn) return e->elevator_may_queue_fn(q, rw); - return 0; + return 1; } void elv_completed_request(request_queue_t *q, struct request *rq) diff --git a/drivers/block/ll_rw_blk.c b/drivers/block/ll_rw_blk.c index 5baa11da0..ea286ebf4 100644 --- a/drivers/block/ll_rw_blk.c +++ b/drivers/block/ll_rw_blk.c @@ -1537,6 +1537,10 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) struct io_context *ioc = get_io_context(gfp_mask); spin_lock_irq(q->queue_lock); + + if (!elv_may_queue(q, rw)) + goto out_lock; + if (rl->count[rw]+1 >= q->nr_requests) { /* * The queue will fill after this allocation, so set it as @@ -1550,15 +1554,12 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) } } - if (blk_queue_full(q, rw) - && !ioc_batching(ioc) && !elv_may_queue(q, rw)) { - /* - * The queue is full and the allocating process is not a - * "batcher", and not exempted by the IO scheduler - */ - spin_unlock_irq(q->queue_lock); - goto out; - } + /* + * The queue is full and the allocating process is not a + * "batcher", and not exempted by the IO scheduler + */ + if (blk_queue_full(q, rw) && !ioc_batching(ioc)) + goto out_lock; rl->count[rw]++; if (rl->count[rw] >= queue_congestion_on_threshold(q)) @@ -1576,8 +1577,7 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) */ spin_lock_irq(q->queue_lock); freed_request(q, rw); - spin_unlock_irq(q->queue_lock); - goto out; + goto out_lock; } if (ioc_batching(ioc)) @@ -1607,6 +1607,11 @@ static struct request *get_request(request_queue_t *q, int rw, int gfp_mask) out: put_io_context(ioc); return rq; +out_lock: + if (!rq) + elv_set_congested(q); + spin_unlock_irq(q->queue_lock); + goto out; } /* @@ -3109,3 +3114,21 @@ void blk_unregister_queue(struct gendisk *disk) kobject_put(&disk->kobj); } } + +asmlinkage int sys_ioprio_set(int ioprio) +{ + if (ioprio < IOPRIO_IDLE || ioprio > IOPRIO_RT) + return -EINVAL; + if (ioprio == IOPRIO_RT && !capable(CAP_SYS_ADMIN)) + return -EACCES; + + printk("%s: set ioprio %d\n", current->comm, ioprio); + current->ioprio = ioprio; + return 0; +} + +asmlinkage int sys_ioprio_get(void) +{ + return current->ioprio; +} + diff --git a/fs/exec.c b/fs/exec.c index ba44671ed..61fba8f37 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -548,18 +547,6 @@ static int exec_mmap(struct mm_struct *mm) tsk->active_mm = mm; activate_mm(active_mm, mm); task_unlock(tsk); -#ifdef CONFIG_CKRM_RES_MEM - if (old_mm) { - spin_lock(&old_mm->peertask_lock); - list_del(&tsk->mm_peers); - ckrm_mem_evaluate_mm(old_mm); - spin_unlock(&old_mm->peertask_lock); - } - spin_lock(&mm->peertask_lock); - list_add_tail(&tsk->mm_peers, &mm->tasklist); - ckrm_mem_evaluate_mm(mm); - spin_unlock(&mm->peertask_lock); -#endif if (old_mm) { if (active_mm != old_mm) BUG(); mmput(old_mm); diff --git a/include/asm-i386/unistd.h b/include/asm-i386/unistd.h index 0df3f9b0a..b76af2f93 100644 --- a/include/asm-i386/unistd.h +++ b/include/asm-i386/unistd.h @@ -289,8 +289,10 @@ #define __NR_mq_notify (__NR_mq_open+4) #define __NR_mq_getsetattr (__NR_mq_open+5) #define __NR_sys_kexec_load 283 +#define __NR_ioprio_set 284 +#define __NR_ioprio_get 285 -#define NR_syscalls 284 +#define NR_syscalls 286 /* user-visible error numbers are in the range -1 - -124: see */ diff --git a/include/asm-ppc/unistd.h b/include/asm-ppc/unistd.h index 57fb02c6c..bdf4ebe9b 100644 --- a/include/asm-ppc/unistd.h +++ b/include/asm-ppc/unistd.h @@ -273,8 +273,10 @@ #define __NR_mq_notify 266 #define __NR_mq_getsetattr 267 #define __NR_kexec_load 268 +#define __NR_ioprio_set 269 +#define __NR_ioprio_get 270 -#define __NR_syscalls 269 +#define __NR_syscalls 271 #define __NR(n) #n diff --git a/include/asm-x86_64/unistd.h b/include/asm-x86_64/unistd.h index 26e0aa30b..0b0a6a10d 100644 --- a/include/asm-x86_64/unistd.h +++ b/include/asm-x86_64/unistd.h @@ -554,8 +554,12 @@ __SYSCALL(__NR_mq_notify, sys_mq_notify) __SYSCALL(__NR_mq_getsetattr, sys_mq_getsetattr) #define __NR_kexec_load 246 __SYSCALL(__NR_kexec_load, sys_ni_syscall) +#define __NR_ioprio_set 247 +__SYSCALL(__NR_ioprio_set, sys_ioprio_set); +#define __NR_ioprio_get 248 +__SYSCALL(__NR_ioprio_get, sys_ioprio_get); -#define __NR_syscall_max __NR_kexec_load +#define __NR_syscall_max __NR_ioprio_get #ifndef __NO_STUBS /* user-visible error numbers are in the range -1 - -4095 */ diff --git a/include/linux/ckrm_rc.h b/include/linux/ckrm_rc.h index f4031671e..b46cfd9f3 100644 --- a/include/linux/ckrm_rc.h +++ b/include/linux/ckrm_rc.h @@ -223,17 +223,7 @@ typedef struct ckrm_core_class { * OTHER ******************************************************************************/ -#define ckrm_get_res_class(rescls, resid, type) \ - ((type*) (((resid != -1) && ((rescls) != NULL) \ - && ((rescls) != (void *)-1)) ? \ - ((struct ckrm_core_class *)(rescls))->res_class[resid] : NULL)) - -#define ckrm_set_res_class(rescls, resid, value) \ -do { \ - if ((resid != -1) && ((rescls) != NULL)) { \ - ((struct ckrm_core_class *)(rescls))->res_class[resid] = value; \ - } \ -} while (0) +#define ckrm_get_res_class(rescls,resid,type) ((type*)((rescls)->res_class[resid])) extern int ckrm_register_res_ctlr(struct ckrm_classtype *, ckrm_res_ctlr_t *); extern int ckrm_unregister_res_ctlr(ckrm_res_ctlr_t *); diff --git a/include/linux/elevator.h b/include/linux/elevator.h index 27e8183f4..b42a9c4e2 100644 --- a/include/linux/elevator.h +++ b/include/linux/elevator.h @@ -17,6 +17,7 @@ typedef void (elevator_requeue_req_fn) (request_queue_t *, struct request *); typedef struct request *(elevator_request_list_fn) (request_queue_t *, struct request *); typedef void (elevator_completed_req_fn) (request_queue_t *, struct request *); typedef int (elevator_may_queue_fn) (request_queue_t *, int); +typedef void (elevator_set_congested_fn) (request_queue_t *); typedef int (elevator_set_req_fn) (request_queue_t *, struct request *, int); typedef void (elevator_put_req_fn) (request_queue_t *, struct request *); @@ -45,6 +46,7 @@ struct elevator_s elevator_put_req_fn *elevator_put_req_fn; elevator_may_queue_fn *elevator_may_queue_fn; + elevator_set_congested_fn *elevator_set_congested_fn; elevator_init_fn *elevator_init_fn; elevator_exit_fn *elevator_exit_fn; @@ -74,6 +76,7 @@ extern struct request *elv_latter_request(request_queue_t *, struct request *); extern int elv_register_queue(request_queue_t *q); extern void elv_unregister_queue(request_queue_t *q); extern int elv_may_queue(request_queue_t *, int); +extern void elv_set_congested(request_queue_t *); extern void elv_completed_request(request_queue_t *, struct request *); extern int elv_set_request(request_queue_t *, struct request *, int); extern void elv_put_request(request_queue_t *, struct request *); @@ -119,4 +122,6 @@ extern int elv_try_last_merge(request_queue_t *, struct bio *); #define ELEVATOR_INSERT_BACK 2 #define ELEVATOR_INSERT_SORT 3 +#define RQ_ELV_DATA(rq) (rq)->elevator_private + #endif diff --git a/include/linux/fs.h b/include/linux/fs.h index 10a69a544..3573884fe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1548,5 +1548,17 @@ static inline void free_secdata(void *secdata) { } #endif /* CONFIG_SECURITY */ +/* io priorities */ + +#define IOPRIO_NR 21 + +#define IOPRIO_IDLE 0 +#define IOPRIO_NORM 10 +#define IOPRIO_RT 20 + +asmlinkage int sys_ioprio_set(int ioprio); +asmlinkage int sys_ioprio_get(void); + + #endif /* __KERNEL__ */ #endif /* _LINUX_FS_H */ diff --git a/include/linux/init_task.h b/include/linux/init_task.h index 29189706e..98b6ca6de 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h @@ -112,6 +112,7 @@ extern struct group_info init_groups; .proc_lock = SPIN_LOCK_UNLOCKED, \ .switch_lock = SPIN_LOCK_UNLOCKED, \ .journal_info = NULL, \ + .ioprio = IOPRIO_NORM, \ } diff --git a/include/linux/mm.h b/include/linux/mm.h index a2bd104b7..8f8a8a3a3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -228,9 +228,6 @@ struct page { void *virtual; /* Kernel virtual address (NULL if not kmapped, ie. highmem) */ #endif /* WANT_PAGE_VIRTUAL */ -#ifdef CONFIG_CKRM_RES_MEM - void *memclass; -#endif // CONFIG_CKRM_RES_MEM }; /* diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 5edb739b4..47762ca69 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -1,11 +1,9 @@ -#include static inline void add_page_to_active_list(struct zone *zone, struct page *page) { list_add(&page->lru, &zone->active_list); zone->nr_active++; - ckrm_mem_inc_active(page); } static inline void @@ -13,7 +11,6 @@ add_page_to_inactive_list(struct zone *zone, struct page *page) { list_add(&page->lru, &zone->inactive_list); zone->nr_inactive++; - ckrm_mem_inc_inactive(page); } static inline void @@ -21,7 +18,6 @@ del_page_from_active_list(struct zone *zone, struct page *page) { list_del(&page->lru); zone->nr_active--; - ckrm_mem_dec_active(page); } static inline void @@ -29,7 +25,6 @@ del_page_from_inactive_list(struct zone *zone, struct page *page) { list_del(&page->lru); zone->nr_inactive--; - ckrm_mem_dec_inactive(page); } static inline void @@ -39,9 +34,7 @@ del_page_from_lru(struct zone *zone, struct page *page) if (PageActive(page)) { ClearPageActive(page); zone->nr_active--; - ckrm_mem_dec_active(page); } else { zone->nr_inactive--; - ckrm_mem_dec_inactive(page); } } diff --git a/include/linux/sched.h b/include/linux/sched.h index a5a1d8ed9..99037de05 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -235,11 +235,6 @@ struct mm_struct { struct kioctx *ioctx_list; struct kioctx default_kioctx; -#ifdef CONFIG_CKRM_RES_MEM - struct ckrm_mem_res *memclass; - struct list_head tasklist; /* list of all tasks sharing this address space */ - spinlock_t peertask_lock; /* protect above tasklist */ -#endif }; extern int mmlist_nr; @@ -512,6 +507,8 @@ struct task_struct { struct io_context *io_context; + int ioprio; + unsigned long ptrace_message; siginfo_t *last_siginfo; /* For ptrace use. */ @@ -528,10 +525,8 @@ struct task_struct { struct ckrm_task_class *taskclass; struct list_head taskclass_link; #endif // CONFIG_CKRM_TYPE_TASKCLASS -#ifdef CONFIG_CKRM_RES_MEM - struct list_head mm_peers; // list of tasks using same mm_struct -#endif // CONFIG_CKRM_RES_MEM #endif // CONFIG_CKRM + struct task_delay_info delays; }; diff --git a/init/Kconfig b/init/Kconfig index c6888dbea..12c6ab9ab 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -168,25 +168,18 @@ config CKRM_RES_NUMTASKS Say N if unsure, Y to use the feature. -config CKRM_RES_MEM - bool "Class based physical memory controller" - default y - depends on CKRM - help - Provide the basic support for collecting physical memory usage information - among classes. Say Y if you want to know the memory usage of each class. - -config CKRM_MEM_LRUORDER_CHANGE - bool "Change the LRU ordering of scanned pages" - default n - depends on CKRM_RES_MEM +config CKRM_RES_BLKIO + tristate " Disk I/O Resource Controller" + depends on CKRM_TYPE_TASKCLASS && IOSCHED_CFQ + default m help - While trying to free pages, by default(n), scanned pages are left were they - are found if they belong to relatively under-used class. In this case the - LRU ordering of the memory subsystemis left intact. If this option is chosen, - then the scanned pages are moved to the tail of the list(active or inactive). - Changing this to yes reduces the checking overhead but violates the approximate - LRU order that is maintained by the paging subsystem. + Provides a resource controller for best-effort block I/O + bandwidth control. The controller attempts this by proportional + servicing of requests in the I/O scheduler. However, seek + optimizations and reordering by device drivers/disk controllers may + alter the actual bandwidth delivered to a class. + + Say N if unsure, Y to use the feature. config CKRM_TYPE_SOCKETCLASS bool "Class Manager for socket groups" diff --git a/kernel/ckrm/Makefile b/kernel/ckrm/Makefile index 0ff956a92..4ace47acd 100644 --- a/kernel/ckrm/Makefile +++ b/kernel/ckrm/Makefile @@ -7,6 +7,5 @@ ifeq ($(CONFIG_CKRM),y) endif obj-$(CONFIG_CKRM_TYPE_TASKCLASS) += ckrm_tc.o obj-$(CONFIG_CKRM_RES_NUMTASKS) += ckrm_tasks.o - obj-$(CONFIG_CKRM_RES_MEM) += ckrm_mem.o obj-$(CONFIG_CKRM_TYPE_SOCKETCLASS) += ckrm_sockc.o obj-$(CONFIG_CKRM_RES_LISTENAQ) += ckrm_listenaq.o diff --git a/kernel/ckrm/ckrmutils.c b/kernel/ckrm/ckrmutils.c index d54e7b563..c56a2ae1c 100644 --- a/kernel/ckrm/ckrmutils.c +++ b/kernel/ckrm/ckrmutils.c @@ -96,6 +96,7 @@ void child_maxlimit_changed(struct ckrm_shares *parent, int new_limit) return; } + /* * Caller is responsible for holding any lock to protect the data * structures passed to this function @@ -110,18 +111,26 @@ set_shares(struct ckrm_shares *new, struct ckrm_shares *cur, // Check total_guarantee for correctness if (new->total_guarantee <= CKRM_SHARE_DONTCARE) { + printk(KERN_ERR "new->total_guarantee %d <= CKRM_SHARE_DONTCARE\n", + new->total_guarantee); goto set_share_err; } else if (new->total_guarantee == CKRM_SHARE_UNCHANGED) { ; // do nothing } else if (cur_usage_guar > new->total_guarantee) { + printk(KERN_ERR "cur_usage_guar %d > new->total_guarantee %d\n", + cur_usage_guar,new->total_guarantee); goto set_share_err; } // Check max_limit for correctness if (new->max_limit <= CKRM_SHARE_DONTCARE) { + printk(KERN_ERR "new->max_limit %d <= CKRM_SHARE_DONTCARE\n", + new->max_limit); goto set_share_err; } else if (new->max_limit == CKRM_SHARE_UNCHANGED) { ; // do nothing } else if (cur->cur_max_limit > new->max_limit) { + printk(KERN_ERR "cur->cur_max_limit %d > new->max_limit %d\n", + cur->cur_max_limit, new->max_limit); goto set_share_err; } // Check my_guarantee for correctness @@ -130,6 +139,8 @@ set_shares(struct ckrm_shares *new, struct ckrm_shares *cur, } else if (new->my_guarantee == CKRM_SHARE_DONTCARE) { ; // do nothing } else if (par && increase_by > par->unused_guarantee) { + printk(KERN_ERR "increase_by %d > par->unused_guarantee %d\n", + increase_by, par->unused_guarantee); goto set_share_err; } // Check my_limit for correctness @@ -139,6 +150,8 @@ set_shares(struct ckrm_shares *new, struct ckrm_shares *cur, ; // do nothing } else if (par && new->my_limit > par->max_limit) { // I can't get more limit than my parent's limit + printk(KERN_ERR "new->my_limit %d > par->max_limit %d\n", + new->my_limit,par->max_limit); goto set_share_err; } @@ -152,6 +165,8 @@ set_shares(struct ckrm_shares *new, struct ckrm_shares *cur, ; // do nothing earlier setting would've // taken care of it } else if (new->my_guarantee > cur->my_limit) { + printk(KERN_ERR "new->my_guarantee %d > cur->my_limit %d\n", + new->my_guarantee,par->max_limit); goto set_share_err; } } else { // new->my_limit has a valid value @@ -159,9 +174,13 @@ set_shares(struct ckrm_shares *new, struct ckrm_shares *cur, ; // do nothing } else if (new->my_guarantee == CKRM_SHARE_UNCHANGED) { if (cur->my_guarantee > new->my_limit) { + printk(KERN_ERR "cur->my_guarantee %d > new->my_limit %d\n", + cur->my_guarantee,new->my_limit); goto set_share_err; } } else if (new->my_guarantee > new->my_limit) { + printk(KERN_ERR "new->my_guarantee %d > new->my_limit %d\n", + new->my_guarantee,new->my_limit); goto set_share_err; } } diff --git a/kernel/ckrm/rbce/rbcemod.c b/kernel/ckrm/rbce/rbcemod.c index fffa9ad1f..f61d0879c 100644 --- a/kernel/ckrm/rbce/rbcemod.c +++ b/kernel/ckrm/rbce/rbcemod.c @@ -497,6 +497,7 @@ rbce_class_deletecb(const char *classname, void *classobj, int classtype) } } } + put_class(cls); if ((cls = find_class_name(classname)) != NULL) { printk(KERN_ERR "rbce ERROR: class %s exists in rbce after " diff --git a/kernel/exit.c b/kernel/exit.c index 333f8003e..f53583e2b 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -514,12 +513,6 @@ static inline void __exit_mm(struct task_struct * tsk) task_lock(tsk); tsk->mm = NULL; up_read(&mm->mmap_sem); -#ifdef CONFIG_CKRM_RES_MEM - spin_lock(&mm->peertask_lock); - list_del_init(&tsk->mm_peers); - ckrm_mem_evaluate_mm(mm); - spin_unlock(&mm->peertask_lock); -#endif enter_lazy_tlb(mm, current); task_unlock(tsk); mmput(mm); diff --git a/kernel/fork.c b/kernel/fork.c index deb264307..7de2f3bcd 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -266,9 +265,6 @@ static struct task_struct *dup_task_struct(struct task_struct *orig) ckrm_cb_newtask(tsk); /* One for us, one for whoever does the "release_task()" (usually parent) */ atomic_set(&tsk->usage,2); -#ifdef CONFIG_CKRM_RES_MEM - INIT_LIST_HEAD(&tsk->mm_peers); -#endif return tsk; } @@ -421,10 +417,6 @@ static struct mm_struct * mm_init(struct mm_struct * mm) mm->ioctx_list = NULL; mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm); mm->free_area_cache = TASK_UNMAPPED_BASE; -#ifdef CONFIG_CKRM_RES_MEM - INIT_LIST_HEAD(&mm->tasklist); - mm->peertask_lock = SPIN_LOCK_UNLOCKED; -#endif if (likely(!mm_alloc_pgd(mm))) { mm->def_flags = 0; @@ -445,10 +437,6 @@ struct mm_struct * mm_alloc(void) if (mm) { memset(mm, 0, sizeof(*mm)); mm = mm_init(mm); -#ifdef CONFIG_CKRM_RES_MEM - mm->memclass = GET_MEM_CLASS(current); - mem_class_get(mm->memclass); -#endif } return mm; } @@ -463,13 +451,6 @@ void fastcall __mmdrop(struct mm_struct *mm) BUG_ON(mm == &init_mm); mm_free_pgd(mm); destroy_context(mm); -#ifdef CONFIG_CKRM_RES_MEM - /* class can be null and mm's tasklist can be empty here */ - if (mm->memclass) { - mem_class_put(mm->memclass); - mm->memclass = NULL; - } -#endif free_mm(mm); } @@ -597,7 +578,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct * tsk) good_mm: tsk->mm = mm; tsk->active_mm = mm; - ckrm_init_mm_to_task(mm, tsk); return 0; free_pt: @@ -1117,6 +1097,7 @@ struct task_struct *copy_process(unsigned long clone_flags, } else link_pid(p, p->pids + PIDTYPE_TGID, &p->group_leader->pids[PIDTYPE_TGID].pid); + p->ioprio = current->ioprio; nr_threads++; write_unlock_irq(&tasklist_lock); retval = 0; diff --git a/mm/fremap.c b/mm/fremap.c index 5cbe6779a..eb056db90 100644 --- a/mm/fremap.c +++ b/mm/fremap.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -84,7 +83,6 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma, mm->rss++; flush_icache_page(vma, page); set_pte(pte, mk_pte(page, prot)); - ckrm_mem_evaluate_page_byadd(page, mm); page_add_file_rmap(page); pte_val = *pte; pte_unmap(pte); diff --git a/mm/memory.c b/mm/memory.c index 75d75a38b..ddf7049ff 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -55,7 +55,6 @@ #include #include -#include #ifndef CONFIG_DISCONTIGMEM /* use the per-pgdat data instead for discontigmem - mbligh */ @@ -1535,7 +1534,6 @@ retry: if (write_access) entry = maybe_mkwrite(pte_mkdirty(entry), vma); set_pte(page_table, entry); - ckrm_mem_evaluate_page_byadd(new_page, mm); if (anon) { lru_cache_add_active(new_page); page_add_anon_rmap(new_page, vma, address); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ea8ec23e8..3dbbeb2f3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -31,7 +31,6 @@ #include #include #include -#include #include @@ -268,7 +267,6 @@ free_pages_bulk(struct zone *zone, int count, page = list_entry(list->prev, struct page, lru); /* have to delete it as __free_pages_bulk list manipulates */ list_del(&page->lru); - ckrm_clear_page_class(page); __free_pages_bulk(page, base, zone, area, mask, order); ret++; } @@ -600,10 +598,6 @@ __alloc_pages(unsigned int gfp_mask, unsigned int order, might_sleep_if(wait); - if (!ckrm_class_limit_ok((GET_MEM_CLASS(current)))) { - return NULL; - } - zones = zonelist->zones; /* the list of zones suitable for gfp_mask */ if (zones[0] == NULL) /* no zones in the zonelist */ return NULL; @@ -733,7 +727,6 @@ nopage: return NULL; got_pg: kernel_map_pages(page, 1 << order, 1); - ckrm_set_pages_class(page, 1 << order, GET_MEM_CLASS(current)); return page; } diff --git a/mm/rmap.c b/mm/rmap.c index 59c1fc120..1f3c84f8c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -33,7 +33,6 @@ #include #include #include -#include #include @@ -361,7 +360,6 @@ void page_add_anon_rmap(struct page *page, */ page_map_lock(page); if (!page->mapcount) { - ckrm_mem_evaluate_page_byadd(page, vma->vm_mm); BUG_ON(PageAnon(page)); BUG_ON(page->mapping); SetPageAnon(page); diff --git a/mm/vmscan.c b/mm/vmscan.c index 0908b4e15..e5f0b0919 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -38,7 +38,6 @@ #include #include -#include /* * From 0 .. 100. Higher means more swappy. @@ -330,9 +329,6 @@ struct scan_control { /* This context's GFP mask */ unsigned int gfp_mask; - /* Flag used by CKRM */ - unsigned int ckrm_flags; - int may_writepage; }; @@ -543,23 +539,19 @@ static void shrink_cache(struct zone *zone, struct scan_control *sc) { LIST_HEAD(page_list); struct pagevec pvec; - int max_scan = sc->nr_to_scan, nr_pass; - unsigned int ckrm_flags = sc->ckrm_flags, bit_flag; + int max_scan = sc->nr_to_scan; pagevec_init(&pvec, 1); lru_add_drain(); spin_lock_irq(&zone->lru_lock); -redo: - ckrm_get_reclaim_bits(&ckrm_flags, &bit_flag); - nr_pass = zone->nr_inactive; while (max_scan > 0) { struct page *page; int nr_taken = 0; int nr_scan = 0; int nr_freed; - while (nr_pass-- && nr_scan++ < SWAP_CLUSTER_MAX && + while (nr_scan++ < SWAP_CLUSTER_MAX && !list_empty(&zone->inactive_list)) { page = lru_to_page(&zone->inactive_list); @@ -577,25 +569,15 @@ redo: SetPageLRU(page); list_add(&page->lru, &zone->inactive_list); continue; - } else if (bit_flag && !ckrm_kick_page(page, bit_flag)) { - __put_page(page); - SetPageLRU(page); -#ifdef CONFIG_CKRM_MEM_LRUORDER_CHANGE - list_add_tail(&page->lru, &zone->inactive_list); -#else - list_add(&page->lru, &zone->inactive_list); -#endif - continue; } list_add(&page->lru, &page_list); - ckrm_mem_dec_inactive(page); nr_taken++; } zone->nr_inactive -= nr_taken; zone->pages_scanned += nr_taken; spin_unlock_irq(&zone->lru_lock); - if ((bit_flag == 0) && (nr_taken == 0)) + if (nr_taken == 0) goto done; max_scan -= nr_scan; @@ -627,9 +609,6 @@ redo: spin_lock_irq(&zone->lru_lock); } } - if (ckrm_flags && (nr_pass <= 0)) { - goto redo; - } } spin_unlock_irq(&zone->lru_lock); done: @@ -669,15 +648,10 @@ refill_inactive_zone(struct zone *zone, struct scan_control *sc) long mapped_ratio; long distress; long swap_tendency; - unsigned int ckrm_flags = sc->ckrm_flags, bit_flag; - int nr_pass; lru_add_drain(); pgmoved = 0; spin_lock_irq(&zone->lru_lock); -redo: - ckrm_get_reclaim_bits(&ckrm_flags, &bit_flag); - nr_pass = zone->nr_active; while (pgscanned < nr_pages && !list_empty(&zone->active_list)) { page = lru_to_page(&zone->active_list); prefetchw_prev_lru_page(page, &zone->active_list, flags); @@ -694,24 +668,11 @@ redo: __put_page(page); SetPageLRU(page); list_add(&page->lru, &zone->active_list); - pgscanned++; - } else if (bit_flag && !ckrm_kick_page(page, bit_flag)) { - __put_page(page); - SetPageLRU(page); -#ifdef CONFIG_CKRM_MEM_LRUORDER_CHANGE - list_add_tail(&page->lru, &zone->active_list); -#else - list_add(&page->lru, &zone->active_list); -#endif } else { list_add(&page->lru, &l_hold); - ckrm_mem_dec_active(page); pgmoved++; - pgscanned++; - } - if (ckrm_flags && !--nr_pass) { - goto redo; } + pgscanned++; } zone->nr_active -= pgmoved; spin_unlock_irq(&zone->lru_lock); @@ -785,7 +746,6 @@ redo: if (!TestClearPageActive(page)) BUG(); list_move(&page->lru, &zone->inactive_list); - ckrm_mem_inc_inactive(page); pgmoved++; if (!pagevec_add(&pvec, page)) { zone->nr_inactive += pgmoved; @@ -814,7 +774,6 @@ redo: BUG(); BUG_ON(!PageActive(page)); list_move(&page->lru, &zone->active_list); - ckrm_mem_inc_active(page); pgmoved++; if (!pagevec_add(&pvec, page)) { zone->nr_active += pgmoved; @@ -867,7 +826,6 @@ shrink_zone(struct zone *zone, struct scan_control *sc) scan_active = (unsigned long)tmp; } - sc->ckrm_flags = ckrm_setup_reclamation(); atomic_add(scan_active + 1, &zone->nr_scan_active); count = atomic_read(&zone->nr_scan_active); if (count >= SWAP_CLUSTER_MAX) { @@ -883,101 +841,8 @@ shrink_zone(struct zone *zone, struct scan_control *sc) sc->nr_to_scan = count; shrink_cache(zone, sc); } - ckrm_teardown_reclamation(); } -#ifdef CONFIG_CKRM_RES_MEM -// This function needs to be given more thought. -static void -ckrm_shrink_class(ckrm_mem_res_t *cls) -{ - struct scan_control sc; - struct zone *zone; - int zindex = 0, active_credit = 0, inactive_credit = 0; - - if (ckrm_test_set_shrink(cls)) { // set the SHRINK bit atomically - // if it is already set somebody is working on it. so... leave - return; - } - sc.nr_mapped = read_page_state(nr_mapped); - sc.nr_scanned = 0; - sc.ckrm_flags = ckrm_get_reclaim_flags(cls); - sc.nr_reclaimed = 0; - sc.priority = 0; // always very high priority - - for_each_zone(zone) { - int zone_total, zone_limit, active_limit, inactive_limit; - int active_over, inactive_over, count; - u64 temp; - - zone->temp_priority = zone->prev_priority; - zone->prev_priority = sc.priority; - - zone_total = zone->nr_active + zone->nr_inactive + zone->free_pages; - - temp = (u64) cls->pg_limit * zone_total; - do_div(temp, ckrm_tot_lru_pages); - zone_limit = (int) temp; - active_limit = (6 * zone_limit) / 10; // 2/3rd in active list - inactive_limit = (3 * zone_limit) / 10; // 1/3rd in inactive list - - active_over = cls->nr_active[zindex] - active_limit + active_credit; - inactive_over = active_over + - (cls->nr_inactive[zindex] - inactive_limit) + inactive_credit; - - if (active_over > 0) { - atomic_add(active_over + 1, &zone->nr_scan_active); - count = atomic_read(&zone->nr_scan_active); - if (count >= SWAP_CLUSTER_MAX) { - atomic_set(&zone->nr_scan_active, 0); - sc.nr_to_scan = count; - refill_inactive_zone(zone, &sc); - } - active_credit = 0; - } else { - active_credit = active_over; - } - - if (inactive_over > 0) { - atomic_add(inactive_over, &zone->nr_scan_inactive); - count = atomic_read(&zone->nr_scan_inactive); - if (count >= SWAP_CLUSTER_MAX) { - atomic_set(&zone->nr_scan_inactive, 0); - sc.nr_to_scan = count; - shrink_cache(zone, &sc); - } - inactive_credit = 0; - } else { - inactive_credit = inactive_over; - } - zone->prev_priority = zone->temp_priority; - zindex++; - } - ckrm_clear_shrink(cls); -} - -static void -ckrm_shrink_classes(void) -{ - ckrm_mem_res_t *cls; - - spin_lock(&ckrm_mem_lock); - while (!ckrm_shrink_list_empty()) { - cls = list_entry(ckrm_shrink_list.next, ckrm_mem_res_t, - shrink_list); - spin_unlock(&ckrm_mem_lock); - ckrm_shrink_class(cls); - spin_lock(&ckrm_mem_lock); - list_del(&cls->shrink_list); - cls->flags &= ~MEM_NEAR_LIMIT; - } - spin_unlock(&ckrm_mem_lock); -} - -#else -#define ckrm_shrink_classes() do { } while(0) -#endif - /* * This is the direct reclaim path, for page-allocating processes. We only * try to reclaim pages from zones which will satisfy the caller's allocation @@ -1272,9 +1137,6 @@ int kswapd(void *p) schedule(); finish_wait(&pgdat->kswapd_wait, &wait); - if (!ckrm_shrink_list_empty()) - ckrm_shrink_classes(); - else balance_pgdat(pgdat, 0); } } @@ -1284,7 +1146,7 @@ int kswapd(void *p) */ void wakeup_kswapd(struct zone *zone) { - if ((zone->free_pages > zone->pages_low) && ckrm_shrink_list_empty()) + if (zone->free_pages > zone->pages_low) return; if (!waitqueue_active(&zone->zone_pgdat->kswapd_wait)) return; -- 2.43.0