Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1546858ybh; Thu, 23 Jul 2020 11:32:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9O57cX34c9bHDMuq5pOXK2HG0XfXqEvEURorg0F3ceBBn95FTAqQ5n+oAvxvC83y2QHJ5 X-Received: by 2002:aa7:d78b:: with SMTP id s11mr5615063edq.319.1595529167134; Thu, 23 Jul 2020 11:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595529167; cv=none; d=google.com; s=arc-20160816; b=SIu+Y0PMIvrHzeHc55IMnasu1cKK3S+wwQjCcJg4NavQmEbeceMXHjOUnBcw2gFvTV tHDr5VEgAL5KWwBahM64M/nDymxa1nbmXC4PwNX6C/wjDWhlVjrqcJRJpcMKL8YuwhN0 51rMscot2/zJjWBqC1Cpkb4VCjE1sMw+lY0Pgfth0Ytgawp2kMbS5INOOwj6l3lXrRZA m8rF4qXck/Mr8Y2y3K6Vf1Rz9xAX1kQinGQUfv9lWioHh9HCP7KpE6yyjiTNkJAHOv0T CZCKv/Nr91bHgKctBHX8NfFxeAowseFqSc51cNzJkJRGtVA04kVGCjSHiKU2uJKHInbZ LSDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rvUCij/xI8Tu7Ds4R4Iwkd7YIUxN/AQl5LxQFfi62KU=; b=v+pwNZcszStFG+pFuLEHrj+gHj4Y+iftCqYiI3PL4HRu0BO3j9XQo9uytKw/R+ecJU FcuOwugzILo5qkVGV0cbwp8Xk2j4jN3r07f3XA+mK8A8dc899JVG+IZdqvQfOQ/Qj8fh ofwT6wuqzzLTDsefGeUr0G2wD8hvIGx2NN/uK1a2GEbcZcGkFGIZf5xNleUUw5uMDKXs ugN81GkZPktqhBgxtTRlrFH1fuwIy3E/istEyhpn4dHAZQs2Onhpej9qyb8tV8kMwQU8 sDiOeZCNh6uF5n/lNAdOtqLJp0COvKRfC+RK+88txKDK2wv8Au+k7FsQ4IrSLaX5n24W 7Pyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=dTKklcAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v1si2450253ejd.505.2020.07.23.11.32.24; Thu, 23 Jul 2020 11:32:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=dTKklcAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbgGWSaJ (ORCPT + 99 others); Thu, 23 Jul 2020 14:30:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726349AbgGWSaJ (ORCPT ); Thu, 23 Jul 2020 14:30:09 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBB7AC0619DC for ; Thu, 23 Jul 2020 11:30:08 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id by13so5209771edb.11 for ; Thu, 23 Jul 2020 11:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rvUCij/xI8Tu7Ds4R4Iwkd7YIUxN/AQl5LxQFfi62KU=; b=dTKklcAdYyc9T2742GbziTsEUjY2HzcNy5SImhgF0X1Fhhrm4yJ8R9ffGhHftDA8ma RJ6TQuS2iK8jd5Lv8V2v3u0jIKl9y8RpCrv6VPj19QfH2TJw9Lq+Y+g9zktW7RsHWNOW 5bMqdegR4SP71hbyPnJPmAV+rgM3QrUrruIJKHq8gV2PnuwWS1EXr1MqwHwcFEK1pV1O 8bNdUZ//EEyMDoxvQzwop8JmYQi5Xndb/AGD7iBTxdjxk7IuD9YugtoDQEKZwkTJ+wA7 7G0JcoFLsVZ7iD9QLUKriP7QHeYYaxHI4WhiLyTPixIyRiR9YmHFcUsMumd8lz5ovwI+ 7zBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rvUCij/xI8Tu7Ds4R4Iwkd7YIUxN/AQl5LxQFfi62KU=; b=CRkEDCNIKfYEyzgtD4OrdnpuccNIWW77y7cYZ2UQ7ak9VB+4vg/TUXuiLLPC/OJM9e AlwtZ0auwcjHxAJ1pm+vMhy5KT+VQ5EonzLs1ABxeOlmo6JVBc7wqe4PwaMMdAExVR+9 mRZM5ygKa781ibP8vx3fh/f31l4yV8mtbLdqjcS43wmqBMZiu6fGSiavPG+bgorpMsSI fqiRhHRGWUnv6849CseKVarfAxwL2aqrbdDsBQ36n5yZIDbZanRD0fJ7P1uFiBSx/DXL fueevRC3H+LelyXtmY9PNmGNRPyUY3Y7+gKKBxKG6yYBHoFWYqeQNy5G+i1YOG7/o0+I vKkA== X-Gm-Message-State: AOAM532v8tpW3GGw7UVhSiWZbUlSMPJBt4ZVBpMLTuU088/0lekwt0rg 0KI22UnNHhZxYRw0QmTu/wIDfel/anIh9gC1lztd8w== X-Received: by 2002:aa7:cd18:: with SMTP id b24mr5631944edw.3.1595529007532; Thu, 23 Jul 2020 11:30:07 -0700 (PDT) MIME-Version: 1.0 References: <20200717205322.127694-1-pasha.tatashin@soleen.com> <20200717205322.127694-2-pasha.tatashin@soleen.com> <20200723180902.GV3673@sequoia> In-Reply-To: <20200723180902.GV3673@sequoia> From: Pavel Tatashin Date: Thu, 23 Jul 2020 14:29:31 -0400 Message-ID: Subject: Re: [PATCH v1 1/1] loop: scale loop device by introducing per device lock To: Tyler Hicks Cc: axboe@kernel.dk, linux-block@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tyler, Thank you for the review comments. My replies are inlined below. > > Scale it by introducing per-device lock: lo_mutex that proctests > > field in struct loop_device. Keep loop_ctl_mutex to protect global > > s/proctests field/protects the fields/ OK > > @@ -1890,22 +1890,23 @@ static int lo_open(struct block_device *bdev, fmode_t mode) > > return err; > > lo = bdev->bd_disk->private_data; > > if (!lo) { > > - err = -ENXIO; > > - goto out; > > + mutex_unlock(&loop_ctl_mutex); > > + return -ENXIO; > > } > > - > > - atomic_inc(&lo->lo_refcnt); > > -out: > > + err = mutex_lock_killable(&lo->lo_mutex); > > mutex_unlock(&loop_ctl_mutex); > > I don't see a possibility for deadlock but it bothers me a little that > we're not unlocking in the reverse locking order here, as we do in > loop_control_ioctl(). There should be no perf impact if we move the > mutex_unlock(&loop_ctl_mutex) after mutex_unlock(&lo->lo_mutex). The lo_open() was one of the top functions that showed up in contention profiling, and the only shared data that it updates is lo_recnt which can be protected by lo_mutex. We must have loop_ctl_mutex in order to get a valid lo pointer, otherwise we could race with loop_control_ioctl(LOOP_CTL_REMOVE). Unlocking in a different order is not an issue, as long as we always preserve the locking order. > > @@ -2157,6 +2158,7 @@ static int loop_add(struct loop_device **l, int i) > > disk->flags |= GENHD_FL_NO_PART_SCAN; > > disk->flags |= GENHD_FL_EXT_DEVT; > > atomic_set(&lo->lo_refcnt, 0); > > + mutex_init(&lo->lo_mutex); > > We need a corresponding call to mutex_destroy() in loop_remove(). Yes, thank you for catching this. > > +++ b/drivers/block/loop.h > > @@ -62,6 +62,7 @@ struct loop_device { > > struct request_queue *lo_queue; > > struct blk_mq_tag_set tag_set; > > struct gendisk *lo_disk; > > There's an instance, which is not in this patch's context, of accessing > lo_disk that needs lo_mutex protection. In loop_probe(), we call > get_disk_and_module(lo->lo_disk) and we need to lock and unlock lo_mutex > around that call. I will add it. Thank you, Pasha