From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90565C43381 for ; Fri, 26 Feb 2021 08:23:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40EBE64DA1 for ; Fri, 26 Feb 2021 08:23:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbhBZIXR (ORCPT ); Fri, 26 Feb 2021 03:23:17 -0500 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:2413 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbhBZIXK (ORCPT ); Fri, 26 Feb 2021 03:23:10 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R751e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UPchXz8_1614327746; Received: from admindeMacBook-Pro-2.local(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0UPchXz8_1614327746) by smtp.aliyun-inc.com(127.0.0.1); Fri, 26 Feb 2021 16:22:27 +0800 Subject: Re: [dm-devel] [PATCH v3 09/11] dm: support IO polling for bio-based dm device To: Mikulas Patocka Cc: axboe@kernel.dk, snitzer@redhat.com, caspar@linux.alibaba.com, io-uring@vger.kernel.org, linux-block@vger.kernel.org, joseph.qi@linux.alibaba.com, dm-devel@redhat.com, hch@lst.de References: <20210208085243.82367-1-jefflexu@linux.alibaba.com> <20210208085243.82367-10-jefflexu@linux.alibaba.com> From: JeffleXu Message-ID: <60703cc8-a1bf-0e7e-683f-594b1ea1639f@linux.alibaba.com> Date: Fri, 26 Feb 2021 16:22:26 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org 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