2.6.11 - NMI lockup with CFQ scheduler
Subsystems (2)
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I have one IDE hard disc, but I was using a USB memory stick at one
point. (Notice the usb-storage and vfat modules in my list.) Could that be the troublesome SCSI device?
Quoted 8 lines · --- Jens Axboe
Yes, it probably is. What happens is that you insert the stick and do io against it, which sets up a process io context for that device. That context persists until the process exits (or later, if someone still holds a reference to it), but the
queue_lockwill be dead when you yank the usb device.It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.
That would explain why it was nautilus which caused the oops then. Does this mean that the major distros aren't using the CFQ then? Because how else can they be avoiding this oops with USB storage devices?
Send instant messages to your online friends http://uk.messenger.yahoo.com
Quoted 11 lines · Chris Rankin
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I have one IDE hard disc, but I was using a USB memory stick at one
point. (Notice the usb-storage and vfat modules in my list.) Could that be the troublesome SCSI device?
Quoted 6 lines · --- Jens Axboe
Yes, it probably is. What happens is that you insert the stick and do io against it, which sets up a process io context for that device. That context persists until the process exits (or later, if someone still holds a reference to it), but the
queue_lockwill be dead when you yank the usb device.
Quoted 7 lines
Quoted 2 lines
It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.
That would explain why it was nautilus which caused the oops then. Does this mean that the major distros aren't using the CFQ then? Because how else can they be avoiding this oops with USB storage devices?
CFQ with io contexts is relatively new, only there since 2.6.10 or so. On UP, we don't grab the queue lock effetively so the problem isn't seen there.
You can work around this issue by using a different default io scheduler at boot time, and then select cfq for your ide hard drive when the system has booted with:
# echo cfq > /sys/block/hda/queue/scheduler
(substitute hda for any other solid storage device).
Signature · 1 line
Jens Axboe
Quoted 24 lines · Jens Axboe
Quoted 11 lines · Chris Rankin
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I have one IDE hard disc, but I was using a USB memory stick at one
point. (Notice the usb-storage and vfat modules in my list.) Could that be the troublesome SCSI device?
Quoted 6 lines · --- Jens Axboe
Yes, it probably is. What happens is that you insert the stick and do io against it, which sets up a process io context for that device. That context persists until the process exits (or later, if someone still holds a reference to it), but the
queue_lockwill be dead when you yank the usb device.Quoted 7 lines
Quoted 2 lines
It is quite a serious problem, not just for CFQ. SCSI referencing is badly broken there.
That would explain why it was nautilus which caused the oops then. Does this mean that the major distros aren't using the CFQ then? Because how else can they be avoiding this oops with USB storage devices?
CFQ with io contexts is relatively new, only there since 2.6.10 or so. On UP, we don't grab the queue lock effetively so the problem isn't seen there.
Quoted 7 lines
You can work around this issue by using a different default io scheduler at boot time, and then select cfq for your ide hard drive when the system has booted with:
# echo cfq > /sys/block/hda/queue/scheduler(substitute hda for any other solid storage device).
Can you check if this work-around solves the problem for you? Thanks!
===== include/linux/blkdev.h 1.162 vs edited =====
include/linux/blkdev.h +2 -0
@@ -279,6 +288,7 @@typedef int (issue_flush_fn ) (request_queue_t *,struct gendisk *,sector_t *);typedef int (prepare_flush_fn ) (request_queue_t *,struct request *);typedef void (end_flush_fn ) (request_queue_t *,struct request *); +typedef void (release_queue_data_fn ) (request_queue_t *);enum blk_queue_state { Queue_down,
@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state
===== drivers/scsi/scsi_sysfs.c 1.72 vs edited =====
drivers/scsi/scsi_sysfs.c +0 -3
@@ -175,9 +175,6 @@scsi_target_reap (scsi_target (sdev)); -kfree (sdev->inquiry); -kfree (sdev); -if (parent)put_device (parent); }
===== drivers/scsi/scsi_lib.c 1.153 vs edited =====
drivers/scsi/scsi_lib.c +14 -0
@@ -1420,6 +1420,18 @@ }EXPORT_SYMBOL (scsi_calculate_bounce_limit); +static void scsi_release_queue_data (request_queue_t *q) +{ +struct scsi_device *sdev = q->queuedata; + +if (sdev) { +kfree (sdev->inquiry); +kfree (sdev); + } + + q->queuedata =NULL ; +} +struct request_queue *scsi_alloc_queue (struct scsi_device *sdev) {struct Scsi_Host *shost = sdev->host;
@@ -1437,6 +1449,8 @@blk_queue_bounce_limit (q,scsi_calculate_bounce_limit (shost));blk_queue_segment_boundary (q, shost->dma_boundary);blk_queue_issue_flush_fn (q, scsi_issue_flush_fn); + + q->release_queue_data_fn = scsi_release_queue_data;/* * ordered tags are superior to flush ordering
Signature · 1 line
Jens Axboe
include/linux/blkdev.h line 340
Quoted 8 lines
include/linux/blkdev.h +1
-0@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state
where does this function method actually get called?
Quoted 10 lines · Arjan van de Ven
Review line 340
Quoted 8 lines
(quoted diff) +1
-0@@ -324,6 +334,7 @@ issue_flush_fn *issue_flush_fn; prepare_flush_fn *prepare_flush_fn; end_flush_fn *end_flush_fn; + release_queue_data_fn *release_queue_data_fn; /* * Auto-unplugging statewhere does this function method actually get called?
I missed the hunk in ll_rw_blk.c, rmk pointed the same thing out not 5 minutes ago :-)
The patch would not work anyways, as scsi_sysfs.c clears queuedata unconditionally. This is a better work-around, it just makes the queue hold a reference to the device as well only killing it when the queue is torn down.
Still not super happy with it, but I don't see how to solve the circular dependency problem otherwise.
===== drivers/scsi/scsi_lib.c 1.153 vs edited =====
drivers/scsi/scsi_lib.c +13 -0
@@ -1420,6 +1420,13 @@ }EXPORT_SYMBOL (scsi_calculate_bounce_limit); +static void scsi_release_queue_data (request_queue_t *q) +{ +struct scsi_device *sdev = q->queuedata; + +put_device (&sdev->sdev_gendev); +} +struct request_queue *scsi_alloc_queue (struct scsi_device *sdev) {struct Scsi_Host *shost = sdev->host;
@@ -1437,6 +1444,12 @@blk_queue_bounce_limit (q,scsi_calculate_bounce_limit (shost));blk_queue_segment_boundary (q, shost->dma_boundary);blk_queue_issue_flush_fn (q, scsi_issue_flush_fn); + +/* +* let the queue drop a reference, when it is killed +*/ +get_device (&sdev->sdev_gendev); + q->release_queue_data_fn = scsi_release_queue_data;/* * ordered tags are superior to flush ordering
===== include/linux/blkdev.h 1.162 vs edited =====
include/linux/blkdev.h +2 -0
@@ -279,6 +288,7 @@typedef int (issue_flush_fn ) (request_queue_t *,struct gendisk *,sector_t *);typedef int (prepare_flush_fn ) (request_queue_t *,struct request *);typedef void (end_flush_fn ) (request_queue_t *,struct request *); +typedef void (release_queue_data_fn ) (request_queue_t *);enum blk_queue_state { Queue_down,
@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state
===== drivers/block/ll_rw_blk.c 1.288 vs edited =====
drivers/block/ll_rw_blk.c +3 -0
@@ -1621,6 +1623,9 @@blk_sync_queue (q); +if (q->release_queue_data_fn) + q->release_queue_data_fn (q); +if (rl->rq_pool)mempool_destroy (rl->rq_pool);
Signature · 1 line
Jens Axboe
Quoted 17 lines · Jens Axboe
Quoted 10 lines · Arjan van de Ven
include/linux/blkdev.h line 340
Quoted 8 lines
include/linux/blkdev.h +1
-0@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state where does this function method actually get called?
I missed the hunk in
ll_rw_blk.c, rmk pointed the same thing out not 5 minutes ago :-)
Quoted 8 lines
The patch would not work anyways, as
scsi_sysfs.cclears queuedata unconditionally. This is a better work-around, it just makes the queue hold a reference to the device as well only killing it when the queue is torn down.Still not super happy with it, but I don't see how to solve the circular dependency problem otherwise.
Hello, Jens.
I've been thinking about it for a while. The problem is that we're
reference counting two different objects to track lifetime of one entity. This happens in both SCSI upper and mid layers. In the upper layer, genhd and scsi_disk (or scsi_cd, ...) are ref'ed separately while they share their destiny together (not really different entity) and in the middle layer scsi_device and request_queue does the same thing. Circular dependency is occuring because we separate one entity into two and reference counting them separately. Two are actually one and necessarily want each other. (until death aparts. Wow, serious. :-)
IMHO, what we need to do is consolidate ref counting such that in each
layer only one object is reference counted, and the other object is freed when the ref counted object is released. The object of choice would be genhd in upper layer and request_queue in mid layer. All ref-counting should be updated to only ref those objects. We'll need to add a release callback to genhd and make request_queue properly reference counted.
Conceptually, scsi_disk extends genhd and scsi_device extendsrequest_queue. So, to go one step further, as what UL represents is genhd (disk device) and ML request_queue (request-based device), embedding scsi_disk into genhd and scsi_device into request_queue will make the architecture clearer. To do this, we'll need something like alloc_disk_with_udata(int minors, size_t udata_len) and the equivalent for request_queue.
I've done this half-way and then doing it without fixing the SCSI
model seemed silly so got into working on the state model. (BTW, the state model is almost done, I'm about to run tests.)
What do you think? Jens?
Signature · 1 line
tejun
Quoted 29 lines · Tejun Heo
Quoted 17 lines · Jens Axboe
Quoted 10 lines · Arjan van de Ven
include/linux/blkdev.h line 340
Quoted 8 lines
include/linux/blkdev.h +1
-0@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state where does this function method actually get called?
I missed the hunk in
ll_rw_blk.c, rmk pointed the same thing out not 5 minutes ago :-)Quoted 8 lines
The patch would not work anyways, as
scsi_sysfs.cclears queuedata unconditionally. This is a better work-around, it just makes the queue hold a reference to the device as well only killing it when the queue is torn down.Still not super happy with it, but I don't see how to solve the circular dependency problem otherwise.
Hello, Jens.
Quoted 9 lines
I've been thinking about it for a while. The problem is that we're
reference counting two different objects to track lifetime of one entity. This happens in both SCSI upper and mid layers. In the upper layer, genhd andscsi_disk(orscsi_cd, ...) are ref'ed separately while they share their destiny together (not really different entity) and in the middle layerscsi_deviceandrequest_queuedoes the same thing. Circular dependency is occuring because we separate one entity into two and reference counting them separately. Two are actually one and necessarily want each other. (until death aparts. Wow, serious. :-)
That's precisely correct.
Quoted 16 lines
IMHO, what we need to do is consolidate ref counting such that in each
layer only one object is reference counted, and the other object is freed when the ref counted object is released. The object of choice would be genhd in upper layer andrequest_queuein mid layer. All ref-counting should be updated to only ref those objects. We'll need to add a release callback to genhd and makerequest_queueproperly reference counted.Conceptually,
scsi_diskextends genhd andscsi_deviceextendsrequest_queue. So, to go one step further, as what UL represents is genhd (disk device) and MLrequest_queue(request-based device), embeddingscsi_diskinto genhd andscsi_deviceintorequest_queuewill make the architecture clearer. To do this, we'll need something likealloc_disk_with_udata(int minors, size_t udata_len)and the equivalent forrequest_queue.
Quoted 5 lines
I've done this half-way and then doing it without fixing the SCSI
model seemed silly so got into working on the state model. (BTW, the state model is almost done, I'm about to run tests.)What do you think? Jens?
It is of course the optimal solution to really solve the hierarchy of references, but more involved. If you have time / desire to do it, I'd be happy to review it :-)
For now I'm happy with the work-around. It's not too ugly, and at least it makes it possible to kill the worse work-around of scsi_kill_requests().
Signature · 1 line
Jens Axboe
Quoted 55 lines · Tejun Heo [[email protected]] wrote:
Quoted 17 lines · Jens Axboe
Quoted 10 lines · Arjan van de Ven
include/linux/blkdev.h line 340
Quoted 8 lines
include/linux/blkdev.h +1
-0@@ -324,6 +334,7 @@issue_flush_fn *issue_flush_fn;prepare_flush_fn *prepare_flush_fn;end_flush_fn *end_flush_fn; +release_queue_data_fn *release_queue_data_fn;/* * Auto-unplugging state where does this function method actually get called?
I missed the hunk in
ll_rw_blk.c, rmk pointed the same thing out not 5 minutes ago :-)Quoted 8 lines
The patch would not work anyways, as
scsi_sysfs.cclears queuedata unconditionally. This is a better work-around, it just makes the queue hold a reference to the device as well only killing it when the queue is torn down.Still not super happy with it, but I don't see how to solve the circular dependency problem otherwise.
Hello, Jens.
I've been thinking about it for a while. The problem is that we're
reference counting two different objects to track lifetime of one entity. This happens in both SCSI upper and mid layers. In the upper layer, genhd andscsi_disk(orscsi_cd, ...) are ref'ed separately while they share their destiny together (not really different entity) and in the middle layerscsi_deviceandrequest_queuedoes the same thing. Circular dependency is occuring because we separate one entity into two and reference counting them separately. Two are actually one and necessarily want each other. (until death aparts. Wow, serious. :-)IMHO, what we need to do is consolidate ref counting such that in each
layer only one object is reference counted, and the other object is freed when the ref counted object is released. The object of choice would be genhd in upper layer andrequest_queuein mid layer. All ref-counting should be updated to only ref those objects. We'll need to add a release callback to genhd and makerequest_queueproperly reference counted.Conceptually,
scsi_diskextends genhd andscsi_deviceextendsrequest_queue. So, to go one step further, as what UL represents is genhd (disk device) and MLrequest_queue(request-based device), embeddingscsi_diskinto genhd andscsi_deviceintorequest_queuewill make the architecture clearer. To do this, we'll need something likealloc_disk_with_udata(int minors, size_t udata_len)and the equivalent forrequest_queue.
Quoted 5 lines
I've done this half-way and then doing it without fixing the SCSI
model seemed silly so got into working on the state model. (BTW, the state model is almost done, I'm about to run tests.)What do you think? Jens?
Well I think extends is one way to look at the subsystem objects, Couldn't it also be said that these objects from each subsystem have just a relationship (parent / child, etc). As reference counting has been implemented in each subsystem sometimes interfaces that cross subsystem boundaries (had / have) not been converted to use similar life time rules.
Well your solution tries to solve the problem by creating a new larger object that contains both of the old objects. Another solution would be to use a consistent lifetime rules and stay with smaller objects. Unless going to large objects helps with allocation fragmentation or we get some other benefit it would seem that these combined structures may sometime in the future limit creation of lighter or flexible objects.
It would appear another solution is that when you allocate a resource from another subsystem (i.e. blk_init_queue) that both subsystems participate in the same reference counting model and in the allocation routine you past in your object to be referenced counted by the allocating subsystem. Then when it is time to shutdown you do not free the others subsystems object directly, but use the normal release routines.
-andmike
--
Michael Anderson
[email protected]