[dm-devel] [PATCH v3 09/11] dm: support IO polling for bio-based dm device
JeffleXu
jefflexu at linux.alibaba.com
Fri Feb 26 08:22:26 UTC 2021
On 2/19/21 10:17 PM, Mikulas Patocka wrote:
>
>
> On Mon, 8 Feb 2021, Jeffle Xu wrote:
>
>> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
>> index c2945c90745e..8423f1347bb8 100644
>> --- a/drivers/md/dm.c
>> +++ b/drivers/md/dm.c
>> @@ -1657,6 +1657,68 @@ static blk_qc_t dm_submit_bio(struct bio *bio)
>> return BLK_QC_T_NONE;
>> }
>>
>> +static int dm_poll_one_md(struct mapped_device *md);
>> +
>> +static int dm_poll_one_dev(struct dm_target *ti, struct dm_dev *dev,
>> + sector_t start, sector_t len, void *data)
>> +{
>> + int i, *count = data;
>> + struct request_queue *q = bdev_get_queue(dev->bdev);
>> + struct blk_mq_hw_ctx *hctx;
>> +
>> + if (queue_is_mq(q)) {
>> + if (!percpu_ref_tryget(&q->q_usage_counter))
>> + return 0;
>> +
>> + queue_for_each_poll_hw_ctx(q, hctx, i)
>> + *count += blk_mq_poll_hctx(q, hctx);
>> +
>> + percpu_ref_put(&q->q_usage_counter);
>> + } else
>> + *count += dm_poll_one_md(dev->bdev->bd_disk->private_data);
>
> This is fragile, because in the future there may be other bio-based
> drivers that support polling. You should check that "q" is really a device
> mapper device before calling dm_poll_one_md on it.
>
This can be easily fixed by calling disk->fops->poll() recursively, such as
````
if (queue_is_mq(q)) {
...
} else {
//disk = disk of underlying device
pdata->count += disk->fops->poll(q, pdata->cookie);
}
```
But meanwhile I realize that we are recursively calling
disk->fops->poll() here, and thus may cause stack overflow similar to
submit_bio() when the depth of the device stack is large enough.
Maybe the control structure like bio_list shall be needed here, to
flatten the recursive structure here.
Any thoughts?
--
Thanks,
Jeffle
More information about the dm-devel
mailing list