From: Artem Bityutskiy <dedekind1@gmail.com>
To: Richard Weinberger <richard@nod.at>
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] Don'd hold work_sem while calling worker functions
Date: Wed, 17 Sep 2014 11:42:35 +0300 [thread overview]
Message-ID: <1410943355.28850.92.camel@sauron.fi.intel.com> (raw)
In-Reply-To: <1410873998-2955-1-git-send-email-richard@nod.at>
On Tue, 2014-09-16 at 15:26 +0200, Richard Weinberger wrote:
> I fail to see why we need work_sem while wrk->func() is executed.
> Artem, do you have an idea?
>
> Having the wear_leveling_worker() called without work_sem held
> would simplify the fastmap code too. I'm currently reworking some
> of it's code and I'm in locking hell. 8-)
Well, the best way for getting clue about the meaning of an R/W
semaphore with an unlimited amount of read-takers I found for myself is
to focus on the write-takers. Read-takers are non-interesting, because
they can race freely.
So let's check write-takers.
There are 2 of them - one in your code, one in the one I wrote many
years ago.
"Mine" is in 'ubi_wl_flush()':
down_write(&ubi->work_sem);
up_write(&ubi->work_sem);
And the only reason it is there is to make sure that flush() really
flushes the queue, and when 'ubi_wl_flush()' returns, you may be sure
that all the in-flight works were finished.
There are other ways to achieve this, but I probably found using the R/W
semaphore to be the easiest. Indeed, just make all the works have it in
read mode, and when you have to wait for all the in-flight works to
complete, you take it in write mode - easy.
IOW, this is a bit of an unusual use of R/W semaphores.
HTH.
P.S. Generally, if you have a trouble with a lock, start with checking
the place where it is defined, I tried to document locks there briefly.
And there may be pices of useful comments elsewhere. This should be true
for both UBI and UBIFS. So just a general hint.
For 'work_sem' you'd need to check ubi.h. But unfortunately, the comment
there is not helpful, and even has a typo which makes it confusing.
While on it, would you refine the comment and say something like:
work_sem: used to wait for all the scheduled works to finish and prevent
new works from being submitted
--
Best Regards,
Artem Bityutskiy
prev parent reply other threads:[~2014-09-17 8:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 13:26 Richard Weinberger
2014-09-16 13:26 ` [PATCH 1/2] UBI: Call worker functions without work_sem held Richard Weinberger
2014-09-16 13:26 ` [PATCH 2/2] UBI: Get rid of __schedule_ubi_work() Richard Weinberger
2014-09-17 8:42 ` Artem Bityutskiy [this message]
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=1410943355.28850.92.camel@sauron.fi.intel.com \
--to=dedekind1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®