From: Jeff Mahoney <jeffm@suse.com>
To: Btrfs Development List <linux-btrfs@vger.kernel.org>
Cc: Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 5/5] Btrfs: fix potential busy loop in find_worker
Date: Fri, 13 Feb 2009 17:17:43 -0500 [thread overview]
Message-ID: <1234563463-7585-5-git-send-email-jeffm@suse.com> (raw)
In-Reply-To: <1234563463-7585-4-git-send-email-jeffm@suse.com>
When the system fails to allocate a new worker or create a new thread,
find_worker can loop indefinitely. It goes into a busy loop trying
to create a new thread and won't return until it is successful.
This patch takes an error from btrfs_start_workers to mean that
there is a resource shortage and falls back to using the first
worker thread in order to make progress.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/btrfs/async-thread.c | 44 ++++++++++++++++++++++++--------------------
1 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 66def6f..b1bfb28 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -344,6 +344,22 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
return worker;
}
+static struct btrfs_worker_thread *first_worker(struct btrfs_workers *workers)
+{
+ struct list_head *list = NULL;
+
+ if (!list_empty(&workers->worker_list))
+ list = &workers->worker_list;
+
+ if (!list_empty(&workers->idle_list))
+ list = &workers->idle_list;
+
+ if (!list)
+ return NULL;
+
+ return list_first_entry(list, struct btrfs_worker_thread, worker_list);
+}
+
/*
* selects a worker thread to take the next job. This will either find
* an idle worker, start a new worker up to the max count, or just return
@@ -351,37 +367,25 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
*/
static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
{
- struct btrfs_worker_thread *worker;
+ struct btrfs_worker_thread *worker = NULL;
unsigned long flags;
+ int ret = 0;
again:
spin_lock_irqsave(&workers->lock, flags);
worker = next_worker(workers);
- spin_unlock_irqrestore(&workers->lock, flags);
-
if (!worker) {
- spin_lock_irqsave(&workers->lock, flags);
- if (workers->num_workers >= workers->max_workers) {
- struct list_head *fallback = NULL;
- /*
- * we have failed to find any workers, just
- * return the force one
- */
- if (!list_empty(&workers->worker_list))
- fallback = workers->worker_list.next;
- if (!list_empty(&workers->idle_list))
- fallback = workers->idle_list.next;
- BUG_ON(!fallback);
- worker = list_entry(fallback,
- struct btrfs_worker_thread, worker_list);
- spin_unlock_irqrestore(&workers->lock, flags);
- } else {
+ if (workers->num_workers >= workers->max_workers || ret)
+ worker = first_worker(workers);
+ else {
spin_unlock_irqrestore(&workers->lock, flags);
/* we're below the limit, start another worker */
- btrfs_start_workers(workers, 1);
+ ret = btrfs_start_workers(workers, 1);
goto again;
}
}
+ spin_unlock_irqrestore(&workers->lock, flags);
+ BUG_ON(!worker);
return worker;
}
--
1.6.0.2
next prev parent reply other threads:[~2009-02-13 22:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-13 22:17 [PATCH 1/5] Btrfs: fix btrfs_read_block_groups return value Jeff Mahoney
2009-02-13 22:17 ` [PATCH 2/5] Btrfs: handle transaction start failures Jeff Mahoney
2009-02-13 22:17 ` [PATCH 3/5] Btrfs: handle path alloc failures Jeff Mahoney
2009-02-13 22:17 ` [PATCH 4/5] Btrfs: fix up btrfs_start_workers error handling Jeff Mahoney
2009-02-13 22:17 ` Jeff Mahoney [this message]
2009-02-13 22:29 ` [PATCH 1/5] Btrfs: fix btrfs_read_block_groups return value Jeff Mahoney
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=1234563463-7585-5-git-send-email-jeffm@suse.com \
--to=jeffm@suse.com \
--cc=linux-btrfs@vger.kernel.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