From: Andrew Morton <akpm@linux-foundation.org>
To: Rajan Aggarwal <rajan.aggarwal85@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Wu Fengguang <fengguang.wu@intel.com>
Subject: Re: [PATCH 1/1] fs-writeback: Using spin_lock to check for work_list empty
Date: Wed, 31 Aug 2011 14:27:10 -0700 [thread overview]
Message-ID: <20110831142710.160df16f.akpm@linux-foundation.org> (raw)
In-Reply-To: <1314767509-17862-1-git-send-email-rajan.aggarwal85@gmail.com>
On Wed, 31 Aug 2011 10:41:49 +0530
Rajan Aggarwal <rajan.aggarwal85@gmail.com> wrote:
> The bdi_writeback_thread function does not use spin_lock to
> see if the work_list is empty.
>
> If the list is not empty, and if an interrupt happens before we
> set the current->state to TASK_RUNNING then we could be stuck in
> a schedule() due to kernel preemption.
>
> This patch acquires and releases the wb_lock to avoid this scenario.
>
> Signed-off-by: Rajan Aggarwal <rajan.aggarwal85@gmail.com>
> ---
> fs/fs-writeback.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
> index 04cf3b9..e333898 100644
> --- a/fs/fs-writeback.c
> +++ b/fs/fs-writeback.c
> @@ -936,11 +936,14 @@ int bdi_writeback_thread(void *data)
> if (pages_written)
> wb->last_active = jiffies;
>
> + spin_lock_bh(&bdi->wb_lock);
> set_current_state(TASK_INTERRUPTIBLE);
> if (!list_empty(&bdi->work_list) || kthread_should_stop()) {
> __set_current_state(TASK_RUNNING);
> + spin_unlock_bh(&bdi->wb_lock);
> continue;
> }
> + spin_unlock_bh(&bdi->wb_lock);
>
> if (wb_has_dirty_io(wb) && dirty_writeback_interval)
> schedule_timeout(msecs_to_jiffies(dirty_writeback_interval * 10));
I don't see anything particularly wrong with the current code. If a
task gets preempted while in state TASK_INTERRUPTIBLE then it will
still be in that state when that task resumes running.
There might be some cross-CPU memory ordering issues in that code. If
so, the effects would be:
a) list_empty() falsely thought to return "false": the thread will
do one additional pointless loop and will then sleep.
b) list_empty() falsely thought to return "true": the thread will
prematurely attempt to go to sleep, introducing a teent bit of
additional latency in rare cases. But I think this is a "can't
happen" because of the memory barrier in
set_current_state(TASK_INTERRUPTIBLE): if the task made this mistake
running list_empty() then it will now be in state TASK_RUNNING and
the schedule() calls will fall straight through. I think.
next prev parent reply other threads:[~2011-08-31 21:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-31 5:11 [PATCH 1/1] fs-writeback: Using spin_lock to check for work_list empty Rajan Aggarwal
2011-08-31 6:46 ` Rajan Aggarwal
2011-08-31 6:51 ` Rajan Aggarwal
2011-08-31 21:27 ` Andrew Morton [this message]
2011-09-01 7:54 ` KAMEZAWA Hiroyuki
2011-09-01 11:56 ` Peter Zijlstra
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=20110831142710.160df16f.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=fengguang.wu@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rajan.aggarwal85@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 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).