Commit ffc4e759 authored by Jens Axboe's avatar Jens Axboe

cfq-iosched: add hlist for browsing parallel to the radix tree

It's cumbersome to browse a radix tree from start to finish, especially
since we modify keys when a process exits. So add a hlist for the single
purpose of browsing over all known cfq_io_contexts, used for exit,
io prio change, etc.

This fixes http://bugzilla.kernel.org/show_bug.cgi?id=9948Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 84e9e03c
...@@ -17,17 +17,13 @@ static struct kmem_cache *iocontext_cachep; ...@@ -17,17 +17,13 @@ static struct kmem_cache *iocontext_cachep;
static void cfq_dtor(struct io_context *ioc) static void cfq_dtor(struct io_context *ioc)
{ {
struct cfq_io_context *cic[1]; if (!hlist_empty(&ioc->cic_list)) {
int r; struct cfq_io_context *cic;
/* cic = list_entry(ioc->cic_list.first, struct cfq_io_context,
* We don't have a specific key to lookup with, so use the gang cic_list);
* lookup to just retrieve the first item stored. The cfq exit cic->dtor(ioc);
* function will iterate the full tree, so any member will do. }
*/
r = radix_tree_gang_lookup(&ioc->radix_root, (void **) cic, 0, 1);
if (r > 0)
cic[0]->dtor(ioc);
} }
/* /*
...@@ -57,18 +53,16 @@ EXPORT_SYMBOL(put_io_context); ...@@ -57,18 +53,16 @@ EXPORT_SYMBOL(put_io_context);
static void cfq_exit(struct io_context *ioc) static void cfq_exit(struct io_context *ioc)
{ {
struct cfq_io_context *cic[1];
int r;
rcu_read_lock(); rcu_read_lock();
/*
* See comment for cfq_dtor()
*/
r = radix_tree_gang_lookup(&ioc->radix_root, (void **) cic, 0, 1);
rcu_read_unlock();
if (r > 0) if (!hlist_empty(&ioc->cic_list)) {
cic[0]->exit(ioc); struct cfq_io_context *cic;
cic = list_entry(ioc->cic_list.first, struct cfq_io_context,
cic_list);
cic->exit(ioc);
}
rcu_read_unlock();
} }
/* Called by the exitting task */ /* Called by the exitting task */
...@@ -105,6 +99,7 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node) ...@@ -105,6 +99,7 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
ret->nr_batch_requests = 0; /* because this is 0 */ ret->nr_batch_requests = 0; /* because this is 0 */
ret->aic = NULL; ret->aic = NULL;
INIT_RADIX_TREE(&ret->radix_root, GFP_ATOMIC | __GFP_HIGH); INIT_RADIX_TREE(&ret->radix_root, GFP_ATOMIC | __GFP_HIGH);
INIT_HLIST_HEAD(&ret->cic_list);
ret->ioc_data = NULL; ret->ioc_data = NULL;
} }
......
...@@ -1145,38 +1145,19 @@ static void cfq_put_queue(struct cfq_queue *cfqq) ...@@ -1145,38 +1145,19 @@ static void cfq_put_queue(struct cfq_queue *cfqq)
/* /*
* Call func for each cic attached to this ioc. Returns number of cic's seen. * Call func for each cic attached to this ioc. Returns number of cic's seen.
*/ */
#define CIC_GANG_NR 16
static unsigned int static unsigned int
call_for_each_cic(struct io_context *ioc, call_for_each_cic(struct io_context *ioc,
void (*func)(struct io_context *, struct cfq_io_context *)) void (*func)(struct io_context *, struct cfq_io_context *))
{ {
struct cfq_io_context *cics[CIC_GANG_NR]; struct cfq_io_context *cic;
unsigned long index = 0; struct hlist_node *n;
unsigned int called = 0; int called = 0;
int nr;
rcu_read_lock(); rcu_read_lock();
hlist_for_each_entry_rcu(cic, n, &ioc->cic_list, cic_list) {
do { func(ioc, cic);
int i; called++;
}
/*
* Perhaps there's a better way - this just gang lookups from
* 0 to the end, restarting after each CIC_GANG_NR from the
* last key + 1.
*/
nr = radix_tree_gang_lookup(&ioc->radix_root, (void **) cics,
index, CIC_GANG_NR);
if (!nr)
break;
called += nr;
index = 1 + (unsigned long) cics[nr - 1]->key;
for (i = 0; i < nr; i++)
func(ioc, cics[i]);
} while (nr == CIC_GANG_NR);
rcu_read_unlock(); rcu_read_unlock();
return called; return called;
...@@ -1190,6 +1171,7 @@ static void cic_free_func(struct io_context *ioc, struct cfq_io_context *cic) ...@@ -1190,6 +1171,7 @@ static void cic_free_func(struct io_context *ioc, struct cfq_io_context *cic)
spin_lock_irqsave(&ioc->lock, flags); spin_lock_irqsave(&ioc->lock, flags);
radix_tree_delete(&ioc->radix_root, cic->dead_key); radix_tree_delete(&ioc->radix_root, cic->dead_key);
hlist_del_rcu(&cic->cic_list);
spin_unlock_irqrestore(&ioc->lock, flags); spin_unlock_irqrestore(&ioc->lock, flags);
kmem_cache_free(cfq_ioc_pool, cic); kmem_cache_free(cfq_ioc_pool, cic);
...@@ -1280,6 +1262,7 @@ cfq_alloc_io_context(struct cfq_data *cfqd, gfp_t gfp_mask) ...@@ -1280,6 +1262,7 @@ cfq_alloc_io_context(struct cfq_data *cfqd, gfp_t gfp_mask)
if (cic) { if (cic) {
cic->last_end_request = jiffies; cic->last_end_request = jiffies;
INIT_LIST_HEAD(&cic->queue_list); INIT_LIST_HEAD(&cic->queue_list);
INIT_HLIST_NODE(&cic->cic_list);
cic->dtor = cfq_free_io_context; cic->dtor = cfq_free_io_context;
cic->exit = cfq_exit_io_context; cic->exit = cfq_exit_io_context;
elv_ioc_count_inc(ioc_count); elv_ioc_count_inc(ioc_count);
...@@ -1501,6 +1484,7 @@ cfq_drop_dead_cic(struct cfq_data *cfqd, struct io_context *ioc, ...@@ -1501,6 +1484,7 @@ cfq_drop_dead_cic(struct cfq_data *cfqd, struct io_context *ioc,
rcu_assign_pointer(ioc->ioc_data, NULL); rcu_assign_pointer(ioc->ioc_data, NULL);
radix_tree_delete(&ioc->radix_root, (unsigned long) cfqd); radix_tree_delete(&ioc->radix_root, (unsigned long) cfqd);
hlist_del_rcu(&cic->cic_list);
spin_unlock_irqrestore(&ioc->lock, flags); spin_unlock_irqrestore(&ioc->lock, flags);
cfq_cic_free(cic); cfq_cic_free(cic);
...@@ -1561,6 +1545,8 @@ static int cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc, ...@@ -1561,6 +1545,8 @@ static int cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc,
spin_lock_irqsave(&ioc->lock, flags); spin_lock_irqsave(&ioc->lock, flags);
ret = radix_tree_insert(&ioc->radix_root, ret = radix_tree_insert(&ioc->radix_root,
(unsigned long) cfqd, cic); (unsigned long) cfqd, cic);
if (!ret)
hlist_add_head_rcu(&cic->cic_list, &ioc->cic_list);
spin_unlock_irqrestore(&ioc->lock, flags); spin_unlock_irqrestore(&ioc->lock, flags);
radix_tree_preload_end(); radix_tree_preload_end();
......
...@@ -50,6 +50,7 @@ struct cfq_io_context { ...@@ -50,6 +50,7 @@ struct cfq_io_context {
sector_t seek_mean; sector_t seek_mean;
struct list_head queue_list; struct list_head queue_list;
struct hlist_node cic_list;
void (*dtor)(struct io_context *); /* destructor */ void (*dtor)(struct io_context *); /* destructor */
void (*exit)(struct io_context *); /* called on task exit */ void (*exit)(struct io_context *); /* called on task exit */
...@@ -77,6 +78,7 @@ struct io_context { ...@@ -77,6 +78,7 @@ struct io_context {
struct as_io_context *aic; struct as_io_context *aic;
struct radix_tree_root radix_root; struct radix_tree_root radix_root;
struct hlist_head cic_list;
void *ioc_data; void *ioc_data;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment