summaryrefslogtreecommitdiffstats
path: root/drivers/md/bcache/alloc.c
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2013-04-24 19:01:12 -0700
committerKent Overstreet <koverstreet@google.com>2013-06-26 17:09:13 -0700
commit119ba0f82839cd80eaef3e6991988f1403965d5b (patch)
tree35422c7c210537530083632ecb2d1119298d307a /drivers/md/bcache/alloc.c
parenta9dd53adbb84c12f769a862ba2c80404873c2c99 (diff)
downloadlinux-119ba0f82839cd80eaef3e6991988f1403965d5b.tar.bz2
bcache: Convert allocator thread to kthread
Using a workqueue when we just want a single thread is a bit silly. Signed-off-by: Kent Overstreet <koverstreet@google.com>
Diffstat (limited to 'drivers/md/bcache/alloc.c')
-rw-r--r--drivers/md/bcache/alloc.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
index 048f2947e08b..38428f46ea74 100644
--- a/drivers/md/bcache/alloc.c
+++ b/drivers/md/bcache/alloc.c
@@ -63,6 +63,7 @@
#include "bcache.h"
#include "btree.h"
+#include <linux/kthread.h>
#include <linux/random.h>
#define MAX_IN_FLIGHT_DISCARDS 8U
@@ -151,7 +152,7 @@ static void discard_finish(struct work_struct *w)
mutex_unlock(&ca->set->bucket_lock);
closure_wake_up(&ca->set->bucket_wait);
- wake_up(&ca->set->alloc_wait);
+ wake_up_process(ca->alloc_thread);
closure_put(&ca->set->cl);
}
@@ -358,30 +359,26 @@ static void invalidate_buckets(struct cache *ca)
#define allocator_wait(ca, cond) \
do { \
- DEFINE_WAIT(__wait); \
- \
while (1) { \
- prepare_to_wait(&ca->set->alloc_wait, \
- &__wait, TASK_INTERRUPTIBLE); \
+ set_current_state(TASK_INTERRUPTIBLE); \
if (cond) \
break; \
\
mutex_unlock(&(ca)->set->bucket_lock); \
if (test_bit(CACHE_SET_STOPPING_2, &ca->set->flags)) { \
- finish_wait(&ca->set->alloc_wait, &__wait); \
- closure_return(cl); \
+ closure_put(&ca->set->cl); \
+ return 0; \
} \
\
schedule(); \
mutex_lock(&(ca)->set->bucket_lock); \
} \
- \
- finish_wait(&ca->set->alloc_wait, &__wait); \
+ __set_current_state(TASK_RUNNING); \
} while (0)
-void bch_allocator_thread(struct closure *cl)
+static int bch_allocator_thread(void *arg)
{
- struct cache *ca = container_of(cl, struct cache, alloc);
+ struct cache *ca = arg;
mutex_lock(&ca->set->bucket_lock);
@@ -442,7 +439,7 @@ long bch_bucket_alloc(struct cache *ca, unsigned watermark, struct closure *cl)
{
long r = -1;
again:
- wake_up(&ca->set->alloc_wait);
+ wake_up_process(ca->alloc_thread);
if (fifo_used(&ca->free) > ca->watermark[watermark] &&
fifo_pop(&ca->free, r)) {
@@ -552,6 +549,19 @@ int bch_bucket_alloc_set(struct cache_set *c, unsigned watermark,
/* Init */
+int bch_cache_allocator_start(struct cache *ca)
+{
+ ca->alloc_thread = kthread_create(bch_allocator_thread,
+ ca, "bcache_allocator");
+ if (IS_ERR(ca->alloc_thread))
+ return PTR_ERR(ca->alloc_thread);
+
+ closure_get(&ca->set->cl);
+ wake_up_process(ca->alloc_thread);
+
+ return 0;
+}
+
void bch_cache_allocator_exit(struct cache *ca)
{
struct discard *d;