Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp691015ybl; Wed, 14 Aug 2019 04:36:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlAv5i59vbfAnmPvepttUFJ6skKOOX91abderF/vdS4n3q6FnlYaY1lisK6ft02DsSLDqD X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr6705697pju.63.1565782602491; Wed, 14 Aug 2019 04:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565782602; cv=none; d=google.com; s=arc-20160816; b=D730/NjZ+Z8ehl5rAwIZ1McyO9W95QoZvhzkR/zm6HqOgVYu6WeMk/I1B4r5FefHSM ErsEbkcC+dKtILHFgeHaX4ItaFyOiXy6D/PkzbZz19TGpGwPBluAbYfMtwZcKL0uQDlu 5WN75sCNFbAoL2DoCQ0YNvtCZi0U6T4MdPcwgGkyROl3P2hvHxdZE9ePHmgji2ZCplYb QODmOsMFEqNkNSr4/1ISLeXFedXspx+GDKFdrRbWkzA1XfNjBqSPqyPekvbHqoCopU6t 4uAM8QbvZRU04wXajqKVymbuwKLSUtIWUjux3JUFkl4FfafaJmhqv0WeVC44QT/Q4I0Y oKzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=pCIbgu1RtPXO+CpMcjIKiB3JqzaWGZFDcm2bhKEmxvQ=; b=JM4EUTO5u2JyONfLH8Zpr2cMO9NugNXmNakugDvATKGGVyFK+g0ztX56vNFnHXb7J/ ImpVGYsQbrGcnfuJyH1U2sizoupgBo3V9C4M2dYtNxAG/uL0CcnVT7RdhDSB3CNNz7p0 VkT2HHgyoZAWmxpOf9LeVkdhHt2WH8+w6m51HulUTE9AMG+9R/qmfb9LfTS/Le8umx3Q evlj3c55O77YAuXoFCchK/HPLaBb/qWry8WGMdO9SEnxbGaXE+HWAwLqsV4do5LEpvCb TJM+kjW9Z79bdyW0TfxD71uVBL8A/ieKEGHhj2si/qkKws1wo3gnCjv8QzY8WTt9eotY UfiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si15210932pfq.147.2019.08.14.04.36.26; Wed, 14 Aug 2019 04:36:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727465AbfHNLeV (ORCPT + 99 others); Wed, 14 Aug 2019 07:34:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51520 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbfHNLeU (ORCPT ); Wed, 14 Aug 2019 07:34:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B6F9309BDA3; Wed, 14 Aug 2019 11:34:20 +0000 (UTC) Received: from ming.t460p (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 96C3360F80; Wed, 14 Aug 2019 11:34:05 +0000 (UTC) Date: Wed, 14 Aug 2019 19:33:53 +0800 From: Ming Lei To: Martijn Coenen Cc: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kernel-team@android.com, narayan@google.com, dariofreni@google.com, ioffe@google.com, jiyong@google.com, maco@google.com Subject: Re: [PATCH] RFC: loop: Avoid calling blk_mq_freeze_queue() when possible. Message-ID: <20190814113348.GA525@ming.t460p> References: <20190814103244.92518-1-maco@android.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190814103244.92518-1-maco@android.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 14 Aug 2019 11:34:20 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 14, 2019 at 12:32:44PM +0200, Martijn Coenen wrote: > Since Android Q, the creation and configuration of loop devices is in > the critical path of device boot. We found that the configuration of > loop devices is pretty slow, because many ioctl()'s involve freezing the > block queue, which in turn needs to wait for an RCU grace period. On > Android devices we've observed up to 60ms for the creation and > configuration of a single loop device; as we anticipate creating many > more in the future, we'd like to avoid this delay. > Another candidate is to not switch to q_usage_counter's percpu mode until loop becomes Lo_bound, and this way may be more clean. Something like the following patch: diff --git a/drivers/block/loop.c b/drivers/block/loop.c index a7461f482467..8791f9242583 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1015,6 +1015,9 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, */ bdgrab(bdev); mutex_unlock(&loop_ctl_mutex); + + percpu_ref_switch_to_percpu(&lo->lo_queue->q_usage_counter); + if (partscan) loop_reread_partitions(lo, bdev); if (claimed_bdev) @@ -1171,6 +1174,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) lo->lo_state = Lo_unbound; mutex_unlock(&loop_ctl_mutex); + percpu_ref_switch_to_atomic(&lo->lo_queue->q_usage_counter, NULL); + /* * Need not hold loop_ctl_mutex to fput backing file. * Calling fput holding loop_ctl_mutex triggers a circular @@ -2003,6 +2008,12 @@ static int loop_add(struct loop_device **l, int i) } lo->lo_queue->queuedata = lo; + /* + * cheat block layer for not switching to q_usage_counter's + * percpu mode before loop becomes Lo_bound + */ + blk_queue_flag_set(QUEUE_FLAG_INIT_DONE, lo->lo_queue); + blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS); /* thanks, Ming