From: Andrew Morton <akpm@osdl.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org,
dwalker@mvista.com, mingo@elte.hu, sct@redhat.com
Subject: Re: kjournald wasting CPU in invert_lock fs/jbd/commit.c
Date: Mon, 11 Jul 2005 15:41:13 -0700 [thread overview]
Message-ID: <20050711154113.5abc81dd.akpm@osdl.org> (raw)
In-Reply-To: <1121120222.6087.44.camel@localhost.localdomain>
Steven Rostedt <rostedt@goodmis.org> wrote:
>
> I noticed that the code in commit.c of the jbd system can waste CPU
> cycles.
How did you notice? By code inspection or by runtime observation? If the
latter, please share.
> The offending code is as follows.
>
> static int inverted_lock(journal_t *journal, struct buffer_head *bh)
> {
> if (!jbd_trylock_bh_state(bh)) {
> spin_unlock(&journal->j_list_lock);
> schedule();
> return 0;
> }
> return 1;
> }
"offending" is a good description. That code sucks. But it sits on the
edge between two subsystems which really really want to take those locks in
opposite order.
> This code makes a loop if the jbd_trylock_bh_state fails. This code will
> wait till whoever owns the lock releases it. But it is really in a busy
> loop and will only be interrupted when the kjournald uses up all its
> quota. So it's basically just wasting CPU cycles here.
Yeah. But these _are_ spinlocks, so spinning is what's supposed to happen.
Maybe we should dump that silly schedule() and just do cpu_relax().
Although I do recall once theorising that the time we spend in the
schedule() might be preventing livelocks.
> The following
> patch should fix this.
>
> Signed-off-by: Steven Rostedt rostedt@goodmis.org
Please put "<>" around the email address.
> ---
> --- a/fs/jbd/commit.c 2005-07-11 17:51:37.000000000 -0400
> +++ b/fs/jbd/commit.c 2005-07-11 17:51:58.000000000 -0400
> @@ -87,7 +87,7 @@ static int inverted_lock(journal_t *jour
> {
> if (!jbd_trylock_bh_state(bh)) {
> spin_unlock(&journal->j_list_lock);
> - schedule();
> + yield();
> return 0;
> }
> return 1;
Nope, yield() can cause terribly long delays when other tasks are cpu-bound.
next prev parent reply other threads:[~2005-07-11 22:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-11 22:17 kjournald wasting CPU in invert_lock fs/jbd/commit.c Steven Rostedt
2005-07-11 22:41 ` Andrew Morton [this message]
2005-07-11 23:09 ` Steven Rostedt
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=20050711154113.5abc81dd.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=dwalker@mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rostedt@goodmis.org \
--cc=sct@redhat.com \
--cc=torvalds@osdl.org \
/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;
as well as URLs for NNTP newsgroup(s).