Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp372324pxf; Wed, 7 Apr 2021 01:22:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwYlVmNnzE+JhxNJu5v9FIYz85rbIUO17jWlEr/+uAomGvm//NI0NYUikFirkcG2yq/mu17 X-Received: by 2002:a92:da12:: with SMTP id z18mr1857530ilm.189.1617783727354; Wed, 07 Apr 2021 01:22:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617783727; cv=none; d=google.com; s=arc-20160816; b=IejzHfiCbrBLRWEqCValPikK6cYPxDntjFGcvwevNvpw+f98DF7oQIlY6neCsOnIQA 7TuQCixqdNvAaLYtq3te7VFOLzQGde7gCDXphNobTpdeXocZbHBPt67NDpwYYrLQekOB +PmP4mFXGTtie9HbqtF63IC1OPHGNRy+WlBlr/DaAzxMmRFlMxWcM8mYJJtcjNFAv6Hg rckLLQ5fxNnH7EN1WpspkIB4wHWosfXAcwNI8wJEfiUBW05ZvGpZNGn1cZQo4cC69KtA qTm09KXZWaYCEKoHEFAD+voqSB3Fn2BY9jNRhRyVnhihZ/BwA3wkurBSQIGGHGDcwYoe ZHLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9ym7fnN02BGhD2IwZ2fakQvS1+eBOSpJm6r44NQnjAw=; b=nC+qa/HIzjqymPoemzP9wYx7lz1TjwXmOBOWeZCOzhDFop5IDy6iiIgQOmBD+GDUqV JQCHdhv3cC4ELvoro4rVsPEThdAn/HzZRbGI1TN+31lCJ2kueGJT6lKOv0vS9FSIoEhR zeUp8TaNTidC0ff2MeK9tvcRqfyiEGaqjFsHD1nGE7bmpX5oHm+BZFa6hBsvK2O5akD/ 430+sgKrJ80ft8Uc62UqSoK2FzGyT5VXHZ9D71wtvfUPMWy9D59Mo6zPKNq0qph7LSMa w+M/WMkoubg8k+0MuGsCMjQ3q2WjzmKvUHKlWUGRnA3DF/h/BdELA1Bok90PXIy06Vsg 7pbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Yk5lNV2D; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si20103597iop.53.2021.04.07.01.21.54; Wed, 07 Apr 2021 01:22:07 -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=@gmail.com header.s=20161025 header.b=Yk5lNV2D; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233905AbhDFTAM (ORCPT + 99 others); Tue, 6 Apr 2021 15:00:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231315AbhDFTAK (ORCPT ); Tue, 6 Apr 2021 15:00:10 -0400 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CC13C06174A; Tue, 6 Apr 2021 12:00:01 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id q26so16095117qkm.6; Tue, 06 Apr 2021 12:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9ym7fnN02BGhD2IwZ2fakQvS1+eBOSpJm6r44NQnjAw=; b=Yk5lNV2D7P99rW6gcaAWyO09heuCK21b7bv63CmrcUadS+lzOxteEzzS1KytJiSc2U GQpHo1ajHLW/xrQkDYM8BKWvZKFr1klaFJCrjceNzmEsMiMlhC/ACq4fspQc9OuwR5L7 5wvblAeAlv4oePkxbqJQNfhjjFLJaejp/bvbnW6AbP57X4aPVb2TXn25qQmNV6QVMCPb 2lMH8Vyzc9J/7WFjqt9ZHlqatP61l/5mE5Kq6KV4GXtb3gexIOC2mMNnsLYrGSdkuwAL AOvuieb4rlkM9PqX3qnikO4Zc2kfqIsog21nqV1cPlL6ZZfMawLvX9pZcGyRJmozuEuZ FgRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9ym7fnN02BGhD2IwZ2fakQvS1+eBOSpJm6r44NQnjAw=; b=AfWnYotx1g3Zj9C1epPrK4E40yTLJYx6oRPFie3etGIQYTolP72SnWVaBYBCKuXkXz 3BGyC9fyZqEYEh/0kWUKxUJfw2IWsReL4j7XH4LdO04BSV/F/EQnxet0CoefqMRDVhnQ r+D/5bzXP1Z118eY+fijoH5O5iKIVZ1DjOJKpIrbFuZhw23qlEqAw1pnX+1FHn0QN3nS MUfLZ9jbUHcaTGQfh4Tlos4rK4HJyq8P7KZ+QiCs/9JO18nwT2VOXIWJqxj0GKaJndc1 zOKLsGfYcYER8zK9ORdJBsUOftE0fLAEhBs545vqGtVay/ElbNXslPsxnJ4ppxujKlKH jPHQ== X-Gm-Message-State: AOAM532JCKTIcQCiwR7DP4rt5rYCxf98K9h5lVBHom0WskpZzXrZ88ag ZRHa6zkRRlq4cHWnPt07MRU= X-Received: by 2002:a37:b103:: with SMTP id a3mr31924660qkf.261.1617735600751; Tue, 06 Apr 2021 12:00:00 -0700 (PDT) Received: from dschatzberg-fedora-PC0Y6AEN.dhcp.thefacebook.com ([2620:10d:c091:480::1:438]) by smtp.gmail.com with ESMTPSA id d10sm16484412qko.70.2021.04.06.11.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 12:00:00 -0700 (PDT) Date: Tue, 6 Apr 2021 14:59:57 -0400 From: Dan Schatzberg To: Hillf Danton Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 1/3] loop: Use worker per cgroup instead of kworker Message-ID: References: <20210402191638.3249835-1-schatzberg.dan@gmail.com> <20210403020902.1384-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210403020902.1384-1-hdanton@sina.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hillf, thanks for the review On Sat, Apr 03, 2021 at 10:09:02AM +0800, Hillf Danton wrote: > On Fri, 2 Apr 2021 12:16:32 Dan Schatzberg wrote: > > +queue_work: > > + if (worker) { > > + /* > > + * We need to remove from the idle list here while > > + * holding the lock so that the idle timer doesn't > > + * free the worker > > + */ > > + if (!list_empty(&worker->idle_list)) > > + list_del_init(&worker->idle_list); > > Nit, only queue work if the worker is inactive - otherwise it is taking > care of the cmd_list. By worker is inactive, you mean worker is on the idle_list? Yes, I think you're right that queue_work() is unnecessary in that case since each worker checks empty cmd_list then adds itself to idle_list under the lock. > > > + work = &worker->work; > > + cmd_list = &worker->cmd_list; > > + } else { > > + work = &lo->rootcg_work; > > + cmd_list = &lo->rootcg_cmd_list; > > + } > > + list_add_tail(&cmd->list_entry, cmd_list); > > + queue_work(lo->workqueue, work); > > + spin_unlock_irq(&lo->lo_work_lock); > > } > [...] > > + /* > > + * We only add to the idle list if there are no pending cmds > > + * *and* the worker will not run again which ensures that it > > + * is safe to free any worker on the idle list > > + */ > > + if (worker && !work_pending(&worker->work)) { > > The empty cmd_list is a good enough reason for worker to become idle. This is only true with the above change to avoid a gratuitous queue_work(), right? Otherwise we run the risk of freeing a worker concurrently with loop_process_work() being invoked.