diff options
author | Jens Axboe <axboe@suse.de> | 2006-06-08 02:49:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-06-08 18:14:23 -0400 |
commit | bc1c116974a5c3f498112a6f175d3e4a8cd5bdbc (patch) | |
tree | 69ea68db91fb871cd24a0a5c5045abbe9c77bd3a /block/as-iosched.c | |
parent | 26e780e8ef1cc3ef581a07aafe2346bb5a07b4f9 (diff) |
[PATCH] elevator switching race
There's a race between shutting down one io scheduler and firing up the
next, in which a new io could enter and cause the io scheduler to be
invoked with bad or NULL data.
To fix this, we need to maintain the queue lock for a bit longer.
Unfortunately we cannot do that, since the elevator init requires to be
run without the lock held. This isn't easily fixable, without also
changing the mempool API. So split the initialization into two parts,
and alloc-init operation and an attach operation. Then we can
preallocate the io scheduler and related structures, and run the attach
inside the lock after we detach the old one.
This patch has survived 30 minutes of 1 second io scheduler switching
with a very busy io load.
Signed-off-by: Jens Axboe <axboe@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'block/as-iosched.c')
-rw-r--r-- | block/as-iosched.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/block/as-iosched.c b/block/as-iosched.c index e25a5d79ab27..a7caf35ca0c2 100644 --- a/block/as-iosched.c +++ b/block/as-iosched.c | |||
@@ -1648,17 +1648,17 @@ static void as_exit_queue(elevator_t *e) | |||
1648 | * initialize elevator private data (as_data), and alloc a arq for | 1648 | * initialize elevator private data (as_data), and alloc a arq for |
1649 | * each request on the free lists | 1649 | * each request on the free lists |
1650 | */ | 1650 | */ |
1651 | static int as_init_queue(request_queue_t *q, elevator_t *e) | 1651 | static void *as_init_queue(request_queue_t *q, elevator_t *e) |
1652 | { | 1652 | { |
1653 | struct as_data *ad; | 1653 | struct as_data *ad; |
1654 | int i; | 1654 | int i; |
1655 | 1655 | ||
1656 | if (!arq_pool) | 1656 | if (!arq_pool) |
1657 | return -ENOMEM; | 1657 | return NULL; |
1658 | 1658 | ||
1659 | ad = kmalloc_node(sizeof(*ad), GFP_KERNEL, q->node); | 1659 | ad = kmalloc_node(sizeof(*ad), GFP_KERNEL, q->node); |
1660 | if (!ad) | 1660 | if (!ad) |
1661 | return -ENOMEM; | 1661 | return NULL; |
1662 | memset(ad, 0, sizeof(*ad)); | 1662 | memset(ad, 0, sizeof(*ad)); |
1663 | 1663 | ||
1664 | ad->q = q; /* Identify what queue the data belongs to */ | 1664 | ad->q = q; /* Identify what queue the data belongs to */ |
@@ -1667,7 +1667,7 @@ static int as_init_queue(request_queue_t *q, elevator_t *e) | |||
1667 | GFP_KERNEL, q->node); | 1667 | GFP_KERNEL, q->node); |
1668 | if (!ad->hash) { | 1668 | if (!ad->hash) { |
1669 | kfree(ad); | 1669 | kfree(ad); |
1670 | return -ENOMEM; | 1670 | return NULL; |
1671 | } | 1671 | } |
1672 | 1672 | ||
1673 | ad->arq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab, | 1673 | ad->arq_pool = mempool_create_node(BLKDEV_MIN_RQ, mempool_alloc_slab, |
@@ -1675,7 +1675,7 @@ static int as_init_queue(request_queue_t *q, elevator_t *e) | |||
1675 | if (!ad->arq_pool) { | 1675 | if (!ad->arq_pool) { |
1676 | kfree(ad->hash); | 1676 | kfree(ad->hash); |
1677 | kfree(ad); | 1677 | kfree(ad); |
1678 | return -ENOMEM; | 1678 | return NULL; |
1679 | } | 1679 | } |
1680 | 1680 | ||
1681 | /* anticipatory scheduling helpers */ | 1681 | /* anticipatory scheduling helpers */ |
@@ -1696,14 +1696,13 @@ static int as_init_queue(request_queue_t *q, elevator_t *e) | |||
1696 | ad->antic_expire = default_antic_expire; | 1696 | ad->antic_expire = default_antic_expire; |
1697 | ad->batch_expire[REQ_SYNC] = default_read_batch_expire; | 1697 | ad->batch_expire[REQ_SYNC] = default_read_batch_expire; |
1698 | ad->batch_expire[REQ_ASYNC] = default_write_batch_expire; | 1698 | ad->batch_expire[REQ_ASYNC] = default_write_batch_expire; |
1699 | e->elevator_data = ad; | ||
1700 | 1699 | ||
1701 | ad->current_batch_expires = jiffies + ad->batch_expire[REQ_SYNC]; | 1700 | ad->current_batch_expires = jiffies + ad->batch_expire[REQ_SYNC]; |
1702 | ad->write_batch_count = ad->batch_expire[REQ_ASYNC] / 10; | 1701 | ad->write_batch_count = ad->batch_expire[REQ_ASYNC] / 10; |
1703 | if (ad->write_batch_count < 2) | 1702 | if (ad->write_batch_count < 2) |
1704 | ad->write_batch_count = 2; | 1703 | ad->write_batch_count = 2; |
1705 | 1704 | ||
1706 | return 0; | 1705 | return ad; |
1707 | } | 1706 | } |
1708 | 1707 | ||
1709 | /* | 1708 | /* |