diff options
Diffstat (limited to 'block/cfq-iosched.c')
-rw-r--r-- | block/cfq-iosched.c | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 67d446de0227..2540dfaa3e38 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c | |||
@@ -1472,19 +1472,37 @@ out: | |||
1472 | return cfqq; | 1472 | return cfqq; |
1473 | } | 1473 | } |
1474 | 1474 | ||
1475 | static void | ||
1476 | cfq_drop_dead_cic(struct io_context *ioc, struct cfq_io_context *cic) | ||
1477 | { | ||
1478 | read_lock(&cfq_exit_lock); | ||
1479 | rb_erase(&cic->rb_node, &ioc->cic_root); | ||
1480 | read_unlock(&cfq_exit_lock); | ||
1481 | kmem_cache_free(cfq_ioc_pool, cic); | ||
1482 | atomic_dec(&ioc_count); | ||
1483 | } | ||
1484 | |||
1475 | static struct cfq_io_context * | 1485 | static struct cfq_io_context * |
1476 | cfq_cic_rb_lookup(struct cfq_data *cfqd, struct io_context *ioc) | 1486 | cfq_cic_rb_lookup(struct cfq_data *cfqd, struct io_context *ioc) |
1477 | { | 1487 | { |
1478 | struct rb_node *n = ioc->cic_root.rb_node; | 1488 | struct rb_node *n; |
1479 | struct cfq_io_context *cic; | 1489 | struct cfq_io_context *cic; |
1480 | void *key = cfqd; | 1490 | void *k, *key = cfqd; |
1481 | 1491 | ||
1492 | restart: | ||
1493 | n = ioc->cic_root.rb_node; | ||
1482 | while (n) { | 1494 | while (n) { |
1483 | cic = rb_entry(n, struct cfq_io_context, rb_node); | 1495 | cic = rb_entry(n, struct cfq_io_context, rb_node); |
1496 | /* ->key must be copied to avoid race with cfq_exit_queue() */ | ||
1497 | k = cic->key; | ||
1498 | if (unlikely(!k)) { | ||
1499 | cfq_drop_dead_cic(ioc, cic); | ||
1500 | goto restart; | ||
1501 | } | ||
1484 | 1502 | ||
1485 | if (key < cic->key) | 1503 | if (key < k) |
1486 | n = n->rb_left; | 1504 | n = n->rb_left; |
1487 | else if (key > cic->key) | 1505 | else if (key > k) |
1488 | n = n->rb_right; | 1506 | n = n->rb_right; |
1489 | else | 1507 | else |
1490 | return cic; | 1508 | return cic; |
@@ -1497,29 +1515,37 @@ static inline void | |||
1497 | cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc, | 1515 | cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc, |
1498 | struct cfq_io_context *cic) | 1516 | struct cfq_io_context *cic) |
1499 | { | 1517 | { |
1500 | struct rb_node **p = &ioc->cic_root.rb_node; | 1518 | struct rb_node **p; |
1501 | struct rb_node *parent = NULL; | 1519 | struct rb_node *parent; |
1502 | struct cfq_io_context *__cic; | 1520 | struct cfq_io_context *__cic; |
1503 | 1521 | void *k; | |
1504 | read_lock(&cfq_exit_lock); | ||
1505 | 1522 | ||
1506 | cic->ioc = ioc; | 1523 | cic->ioc = ioc; |
1507 | cic->key = cfqd; | 1524 | cic->key = cfqd; |
1508 | 1525 | ||
1509 | ioc->set_ioprio = cfq_ioc_set_ioprio; | 1526 | ioc->set_ioprio = cfq_ioc_set_ioprio; |
1510 | 1527 | restart: | |
1528 | parent = NULL; | ||
1529 | p = &ioc->cic_root.rb_node; | ||
1511 | while (*p) { | 1530 | while (*p) { |
1512 | parent = *p; | 1531 | parent = *p; |
1513 | __cic = rb_entry(parent, struct cfq_io_context, rb_node); | 1532 | __cic = rb_entry(parent, struct cfq_io_context, rb_node); |
1533 | /* ->key must be copied to avoid race with cfq_exit_queue() */ | ||
1534 | k = __cic->key; | ||
1535 | if (unlikely(!k)) { | ||
1536 | cfq_drop_dead_cic(ioc, cic); | ||
1537 | goto restart; | ||
1538 | } | ||
1514 | 1539 | ||
1515 | if (cic->key < __cic->key) | 1540 | if (cic->key < k) |
1516 | p = &(*p)->rb_left; | 1541 | p = &(*p)->rb_left; |
1517 | else if (cic->key > __cic->key) | 1542 | else if (cic->key > k) |
1518 | p = &(*p)->rb_right; | 1543 | p = &(*p)->rb_right; |
1519 | else | 1544 | else |
1520 | BUG(); | 1545 | BUG(); |
1521 | } | 1546 | } |
1522 | 1547 | ||
1548 | read_lock(&cfq_exit_lock); | ||
1523 | rb_link_node(&cic->rb_node, parent, p); | 1549 | rb_link_node(&cic->rb_node, parent, p); |
1524 | rb_insert_color(&cic->rb_node, &ioc->cic_root); | 1550 | rb_insert_color(&cic->rb_node, &ioc->cic_root); |
1525 | list_add(&cic->queue_list, &cfqd->cic_list); | 1551 | list_add(&cic->queue_list, &cfqd->cic_list); |
@@ -2439,9 +2465,10 @@ static void __exit cfq_exit(void) | |||
2439 | DECLARE_COMPLETION(all_gone); | 2465 | DECLARE_COMPLETION(all_gone); |
2440 | elv_unregister(&iosched_cfq); | 2466 | elv_unregister(&iosched_cfq); |
2441 | ioc_gone = &all_gone; | 2467 | ioc_gone = &all_gone; |
2442 | barrier(); | 2468 | /* ioc_gone's update must be visible before reading ioc_count */ |
2469 | smp_wmb(); | ||
2443 | if (atomic_read(&ioc_count)) | 2470 | if (atomic_read(&ioc_count)) |
2444 | complete(ioc_gone); | 2471 | wait_for_completion(ioc_gone); |
2445 | synchronize_rcu(); | 2472 | synchronize_rcu(); |
2446 | cfq_slab_kill(); | 2473 | cfq_slab_kill(); |
2447 | } | 2474 | } |