diff options
| author | Jens Axboe <axboe@kernel.dk> | 2013-05-01 03:23:05 -0400 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2013-05-01 03:23:05 -0400 |
| commit | f50efd2fdbd9b35b11f5778ed85beb764184bda9 (patch) | |
| tree | ed92b40995d60136fb387d210886e4aae2c37231 | |
| parent | 0821e904057505c7e25d72e1a282105d023b26c9 (diff) | |
| parent | ee66850642efda91d04179cae2414310675a1f73 (diff) | |
Merge branch 'bcache-for-upstream' of http://evilpiepirate.org/git/linux-bcache into for-3.10/drivers
Kent writes:
Hey Jens, this is everything I've got ready for 3.10 - there's _still_
one more bug I'm trying to track down.
Andrew - I've got patches that rip out the pkey() and pbtree() macros,
but they're somewhat tied up with some other nontrivial refactorings so
I think I'm going to wait a bit on those.
| -rw-r--r-- | drivers/md/bcache/alloc.c | 72 | ||||
| -rw-r--r-- | drivers/md/bcache/bcache.h | 47 | ||||
| -rw-r--r-- | drivers/md/bcache/btree.c | 3 | ||||
| -rw-r--r-- | drivers/md/bcache/io.c | 35 | ||||
| -rw-r--r-- | drivers/md/bcache/request.c | 2 | ||||
| -rw-r--r-- | drivers/md/bcache/super.c | 166 |
6 files changed, 213 insertions, 112 deletions
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c index 2879487d036a..048f2947e08b 100644 --- a/drivers/md/bcache/alloc.c +++ b/drivers/md/bcache/alloc.c | |||
| @@ -243,31 +243,37 @@ static void invalidate_buckets_lru(struct cache *ca) | |||
| 243 | ca->heap.used = 0; | 243 | ca->heap.used = 0; |
| 244 | 244 | ||
| 245 | for_each_bucket(b, ca) { | 245 | for_each_bucket(b, ca) { |
| 246 | /* | ||
| 247 | * If we fill up the unused list, if we then return before | ||
| 248 | * adding anything to the free_inc list we'll skip writing | ||
| 249 | * prios/gens and just go back to allocating from the unused | ||
| 250 | * list: | ||
| 251 | */ | ||
| 252 | if (fifo_full(&ca->unused)) | ||
| 253 | return; | ||
| 254 | |||
| 246 | if (!can_invalidate_bucket(ca, b)) | 255 | if (!can_invalidate_bucket(ca, b)) |
| 247 | continue; | 256 | continue; |
| 248 | 257 | ||
| 249 | if (!GC_SECTORS_USED(b)) { | 258 | if (!GC_SECTORS_USED(b) && |
| 250 | if (!bch_bucket_add_unused(ca, b)) | 259 | bch_bucket_add_unused(ca, b)) |
| 251 | return; | 260 | continue; |
| 252 | } else { | 261 | |
| 253 | if (!heap_full(&ca->heap)) | 262 | if (!heap_full(&ca->heap)) |
| 254 | heap_add(&ca->heap, b, bucket_max_cmp); | 263 | heap_add(&ca->heap, b, bucket_max_cmp); |
| 255 | else if (bucket_max_cmp(b, heap_peek(&ca->heap))) { | 264 | else if (bucket_max_cmp(b, heap_peek(&ca->heap))) { |
| 256 | ca->heap.data[0] = b; | 265 | ca->heap.data[0] = b; |
| 257 | heap_sift(&ca->heap, 0, bucket_max_cmp); | 266 | heap_sift(&ca->heap, 0, bucket_max_cmp); |
| 258 | } | ||
| 259 | } | 267 | } |
| 260 | } | 268 | } |
| 261 | 269 | ||
| 262 | if (ca->heap.used * 2 < ca->heap.size) | ||
| 263 | bch_queue_gc(ca->set); | ||
| 264 | |||
| 265 | for (i = ca->heap.used / 2 - 1; i >= 0; --i) | 270 | for (i = ca->heap.used / 2 - 1; i >= 0; --i) |
| 266 | heap_sift(&ca->heap, i, bucket_min_cmp); | 271 | heap_sift(&ca->heap, i, bucket_min_cmp); |
| 267 | 272 | ||
| 268 | while (!fifo_full(&ca->free_inc)) { | 273 | while (!fifo_full(&ca->free_inc)) { |
| 269 | if (!heap_pop(&ca->heap, b, bucket_min_cmp)) { | 274 | if (!heap_pop(&ca->heap, b, bucket_min_cmp)) { |
| 270 | /* We don't want to be calling invalidate_buckets() | 275 | /* |
| 276 | * We don't want to be calling invalidate_buckets() | ||
| 271 | * multiple times when it can't do anything | 277 | * multiple times when it can't do anything |
| 272 | */ | 278 | */ |
| 273 | ca->invalidate_needs_gc = 1; | 279 | ca->invalidate_needs_gc = 1; |
| @@ -343,15 +349,22 @@ static void invalidate_buckets(struct cache *ca) | |||
| 343 | invalidate_buckets_random(ca); | 349 | invalidate_buckets_random(ca); |
| 344 | break; | 350 | break; |
| 345 | } | 351 | } |
| 352 | |||
| 353 | pr_debug("free %zu/%zu free_inc %zu/%zu unused %zu/%zu", | ||
| 354 | fifo_used(&ca->free), ca->free.size, | ||
| 355 | fifo_used(&ca->free_inc), ca->free_inc.size, | ||
| 356 | fifo_used(&ca->unused), ca->unused.size); | ||
| 346 | } | 357 | } |
| 347 | 358 | ||
| 348 | #define allocator_wait(ca, cond) \ | 359 | #define allocator_wait(ca, cond) \ |
| 349 | do { \ | 360 | do { \ |
| 350 | DEFINE_WAIT(__wait); \ | 361 | DEFINE_WAIT(__wait); \ |
| 351 | \ | 362 | \ |
| 352 | while (!(cond)) { \ | 363 | while (1) { \ |
| 353 | prepare_to_wait(&ca->set->alloc_wait, \ | 364 | prepare_to_wait(&ca->set->alloc_wait, \ |
| 354 | &__wait, TASK_INTERRUPTIBLE); \ | 365 | &__wait, TASK_INTERRUPTIBLE); \ |
| 366 | if (cond) \ | ||
| 367 | break; \ | ||
| 355 | \ | 368 | \ |
| 356 | mutex_unlock(&(ca)->set->bucket_lock); \ | 369 | mutex_unlock(&(ca)->set->bucket_lock); \ |
| 357 | if (test_bit(CACHE_SET_STOPPING_2, &ca->set->flags)) { \ | 370 | if (test_bit(CACHE_SET_STOPPING_2, &ca->set->flags)) { \ |
| @@ -360,7 +373,6 @@ do { \ | |||
| 360 | } \ | 373 | } \ |
| 361 | \ | 374 | \ |
| 362 | schedule(); \ | 375 | schedule(); \ |
| 363 | __set_current_state(TASK_RUNNING); \ | ||
| 364 | mutex_lock(&(ca)->set->bucket_lock); \ | 376 | mutex_lock(&(ca)->set->bucket_lock); \ |
| 365 | } \ | 377 | } \ |
| 366 | \ | 378 | \ |
| @@ -374,6 +386,11 @@ void bch_allocator_thread(struct closure *cl) | |||
| 374 | mutex_lock(&ca->set->bucket_lock); | 386 | mutex_lock(&ca->set->bucket_lock); |
| 375 | 387 | ||
| 376 | while (1) { | 388 | while (1) { |
| 389 | /* | ||
| 390 | * First, we pull buckets off of the unused and free_inc lists, | ||
| 391 | * possibly issue discards to them, then we add the bucket to | ||
| 392 | * the free list: | ||
| 393 | */ | ||
| 377 | while (1) { | 394 | while (1) { |
| 378 | long bucket; | 395 | long bucket; |
| 379 | 396 | ||
| @@ -398,17 +415,26 @@ void bch_allocator_thread(struct closure *cl) | |||
| 398 | } | 415 | } |
| 399 | } | 416 | } |
| 400 | 417 | ||
| 401 | allocator_wait(ca, ca->set->gc_mark_valid); | 418 | /* |
| 402 | invalidate_buckets(ca); | 419 | * We've run out of free buckets, we need to find some buckets |
| 420 | * we can invalidate. First, invalidate them in memory and add | ||
| 421 | * them to the free_inc list: | ||
| 422 | */ | ||
| 403 | 423 | ||
| 404 | allocator_wait(ca, !atomic_read(&ca->set->prio_blocked) || | 424 | allocator_wait(ca, ca->set->gc_mark_valid && |
| 405 | !CACHE_SYNC(&ca->set->sb)); | 425 | (ca->need_save_prio > 64 || |
| 426 | !ca->invalidate_needs_gc)); | ||
| 427 | invalidate_buckets(ca); | ||
| 406 | 428 | ||
| 429 | /* | ||
| 430 | * Now, we write their new gens to disk so we can start writing | ||
| 431 | * new stuff to them: | ||
| 432 | */ | ||
| 433 | allocator_wait(ca, !atomic_read(&ca->set->prio_blocked)); | ||
| 407 | if (CACHE_SYNC(&ca->set->sb) && | 434 | if (CACHE_SYNC(&ca->set->sb) && |
| 408 | (!fifo_empty(&ca->free_inc) || | 435 | (!fifo_empty(&ca->free_inc) || |
| 409 | ca->need_save_prio > 64)) { | 436 | ca->need_save_prio > 64)) |
| 410 | bch_prio_write(ca); | 437 | bch_prio_write(ca); |
| 411 | } | ||
| 412 | } | 438 | } |
| 413 | } | 439 | } |
| 414 | 440 | ||
| @@ -475,7 +501,7 @@ void bch_bucket_free(struct cache_set *c, struct bkey *k) | |||
| 475 | for (i = 0; i < KEY_PTRS(k); i++) { | 501 | for (i = 0; i < KEY_PTRS(k); i++) { |
| 476 | struct bucket *b = PTR_BUCKET(c, k, i); | 502 | struct bucket *b = PTR_BUCKET(c, k, i); |
| 477 | 503 | ||
| 478 | SET_GC_MARK(b, 0); | 504 | SET_GC_MARK(b, GC_MARK_RECLAIMABLE); |
| 479 | SET_GC_SECTORS_USED(b, 0); | 505 | SET_GC_SECTORS_USED(b, 0); |
| 480 | bch_bucket_add_unused(PTR_CACHE(c, k, i), b); | 506 | bch_bucket_add_unused(PTR_CACHE(c, k, i), b); |
| 481 | } | 507 | } |
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index f05723565f17..340146d7c17f 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
| @@ -223,11 +223,17 @@ struct bkey { | |||
| 223 | #define BKEY_PADDED(key) \ | 223 | #define BKEY_PADDED(key) \ |
| 224 | union { struct bkey key; uint64_t key ## _pad[BKEY_PAD]; } | 224 | union { struct bkey key; uint64_t key ## _pad[BKEY_PAD]; } |
| 225 | 225 | ||
| 226 | /* Version 1: Backing device | 226 | /* Version 0: Cache device |
| 227 | * Version 1: Backing device | ||
| 227 | * Version 2: Seed pointer into btree node checksum | 228 | * Version 2: Seed pointer into btree node checksum |
| 228 | * Version 3: New UUID format | 229 | * Version 3: Cache device with new UUID format |
| 230 | * Version 4: Backing device with data offset | ||
| 229 | */ | 231 | */ |
| 230 | #define BCACHE_SB_VERSION 3 | 232 | |
