All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Dan Schatzberg <schatzberg.dan@gmail.com>
Cc: Hillf Danton <hdanton@sina.com>, Jens Axboe <axboe@kernel.dk>,
	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
Date: Wed,  7 Apr 2021 14:53:00 +0800	[thread overview]
Message-ID: <20210407065300.1478-1-hdanton@sina.com> (raw)
In-Reply-To: <YGyvra69F/DIa7KI@dschatzberg-fedora-PC0Y6AEN.dhcp.thefacebook.com>

On Tue, 6 Apr 2021 Dan Schatzberg wrote:
>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?

It is always true because of the empty cmd_list - the idle_list is the only
place for the worker to go at this point.

>Otherwise we run the risk of freeing a worker
>concurrently with loop_process_work() being invoked.

My suggestion is a minor optimization at most without any change to removing
worker off the idle_list on queuing work - that cuts the risk for you.


  reply	other threads:[~2021-04-07  6:53 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 19:16 [PATCH V12 0/3] Charge loop device i/o to issuing cgroup Dan Schatzberg
2021-04-02 19:16 ` Dan Schatzberg
2021-04-02 19:16 ` Dan Schatzberg
2021-04-02 19:16 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-03  2:09   ` Hillf Danton
2021-04-06 18:59     ` Dan Schatzberg
2021-04-07  6:53       ` Hillf Danton [this message]
2021-04-07 14:43         ` Dan Schatzberg
2021-04-06  1:44   ` Ming Lei
2021-04-06  1:44     ` Ming Lei
2021-04-02 19:16 ` [PATCH 2/3] mm: Charge active memcg when no mm is set Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-03  5:47   ` [External] " Muchun Song
2021-04-03  5:47     ` Muchun Song
2021-04-03  5:47     ` Muchun Song
2021-04-02 19:16 ` [PATCH 3/3] loop: Charge i/o to mem and blk cg Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-02 19:16   ` Dan Schatzberg
2021-04-06  3:23   ` Ming Lei
2021-04-06  3:23     ` Ming Lei
2021-04-06  3:23     ` Ming Lei
2021-04-12 15:45 ` [PATCH V12 0/3] Charge loop device i/o to issuing cgroup Johannes Weiner
2021-04-12 15:45   ` Johannes Weiner
2021-04-12 15:50   ` Jens Axboe
2021-04-12 15:50     ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2021-06-10 17:39 [PATCH V14 " Dan Schatzberg
2021-06-10 17:39 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2021-06-10 17:39   ` Dan Schatzberg
2021-06-03 14:57 [PATCH V13 0/3] Charge loop device i/o to issuing cgroup Dan Schatzberg
2021-06-03 14:57 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2021-06-03 14:57   ` Dan Schatzberg
2021-03-29 14:48 [PATCH V11 0/3] Charge loop device i/o to issuing cgroup Dan Schatzberg
2021-03-29 14:48 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2021-03-29 14:48   ` Dan Schatzberg
2021-03-29 14:48   ` Dan Schatzberg
2021-03-16 15:36 [PATCH v10 0/3] Charge loop device i/o to issuing cgroup Dan Schatzberg
2021-03-16 15:36 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2021-03-16 15:36   ` Dan Schatzberg
2021-03-16 15:36   ` Dan Schatzberg
2020-08-31 15:36 [PATCH v8 0/3] Charge loop device i/o to issuing cgroup Dan Schatzberg
2020-08-31 15:36 ` [PATCH 1/3] loop: Use worker per cgroup instead of kworker Dan Schatzberg
2020-08-31 15:36   ` Dan Schatzberg
2020-08-31 15:36   ` Dan Schatzberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210407065300.1478-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=schatzberg.dan@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.