aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-07-24 20:26:51 -0400
committerKent Overstreet <kmo@daterainc.com>2013-11-11 00:56:02 -0500
commit0b93207abb40d3c42bb83eba1e1e7edc1da77810 (patch)
treeeeca92af43a3d2413dc0a425f5cb71cfd4cad764 /drivers/md
parenta34a8bfd4e6358c646928320d37b0425c0762f8a (diff)
bcache: Move keylist out of btree_op
Slowly working on pruning struct btree_op - the aim is for it to only contain things that are actually necessary for traversing the btree. Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/bcache/btree.c1
-rw-r--r--drivers/md/bcache/btree.h4
-rw-r--r--drivers/md/bcache/journal.c11
-rw-r--r--drivers/md/bcache/request.c37
-rw-r--r--drivers/md/bcache/request.h4
-rw-r--r--drivers/md/bcache/writeback.c7
6 files changed, 36 insertions, 28 deletions
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 777c01d67ef0..731cd8e3fe90 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -113,7 +113,6 @@ void bch_btree_op_init_stack(struct btree_op *op)
113 memset(op, 0, sizeof(struct btree_op)); 113 memset(op, 0, sizeof(struct btree_op));
114 closure_init_stack(&op->cl); 114 closure_init_stack(&op->cl);
115 op->lock = -1; 115 op->lock = -1;
116 bch_keylist_init(&op->keys);
117} 116}
118 117
119/* Btree key manipulation */ 118/* Btree key manipulation */
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h
index ea0814b51574..17b7a4e39c7e 100644
--- a/drivers/md/bcache/btree.h
+++ b/drivers/md/bcache/btree.h
@@ -267,10 +267,6 @@ struct btree_op {
267 unsigned lookup_done:1; 267 unsigned lookup_done:1;
268 unsigned insert_collision:1; 268 unsigned insert_collision:1;
269 269
270 /* Anything after this point won't get zeroed in do_bio_hook() */
271
272 /* Keys to be inserted */
273 struct keylist keys;
274 BKEY_PADDED(replace); 270 BKEY_PADDED(replace);
275}; 271};
276 272
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 940e89e0d706..8866f8ee3a07 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -301,6 +301,9 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list,
301 list_entry(list->prev, struct journal_replay, list); 301 list_entry(list->prev, struct journal_replay, list);
302 302
303 uint64_t start = i->j.last_seq, end = i->j.seq, n = start; 303 uint64_t start = i->j.last_seq, end = i->j.seq, n = start;
304 struct keylist keylist;
305
306 bch_keylist_init(&keylist);
304 307
305 list_for_each_entry(i, list, list) { 308 list_for_each_entry(i, list, list) {
306 BUG_ON(i->pin && atomic_read(i->pin) != 1); 309 BUG_ON(i->pin && atomic_read(i->pin) != 1);
@@ -314,16 +317,16 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list,
314 k = bkey_next(k)) { 317 k = bkey_next(k)) {
315 trace_bcache_journal_replay_key(k); 318 trace_bcache_journal_replay_key(k);
316 319
317 bkey_copy(op->keys.top, k); 320 bkey_copy(keylist.top, k);
318 bch_keylist_push(&op->keys); 321 bch_keylist_push(&keylist);
319 322
320 op->journal = i->pin; 323 op->journal = i->pin;
321 324
322 ret = bch_btree_insert(op, s, &op->keys); 325 ret = bch_btree_insert(op, s, &keylist);
323 if (ret) 326 if (ret)
324 goto err; 327 goto err;
325 328
326 BUG_ON(!bch_keylist_empty(&op->keys)); 329 BUG_ON(!bch_keylist_empty(&keylist));
327 keys++; 330 keys++;
328 331
329 cond_resched(); 332 cond_resched();
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 1c3af44b097b..d85c7001df61 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -231,11 +231,11 @@ static void bch_data_insert_keys(struct closure *cl)
231#endif 231#endif
232 232
233 if (s->write) 233 if (s->write)
234 op->journal = bch_journal(op->c, &op->keys, 234 op->journal = bch_journal(op->c, &s->insert_keys,
235 op->flush_journal 235 op->flush_journal
236 ? &s->cl : NULL); 236 ? &s->cl : NULL);
237 237
238 if (bch_btree_insert(op, op->c, &op->keys)) { 238 if (bch_btree_insert(op, op->c, &s->insert_keys)) {
239 s->error = -ENOMEM; 239 s->error = -ENOMEM;
240 op->insert_data_done = true; 240 op->insert_data_done = true;
241 } 241 }
@@ -247,7 +247,7 @@ static void bch_data_insert_keys(struct closure *cl)
247 if (!op->insert_data_done) 247 if (!op->insert_data_done)
248 continue_at(cl, bch_data_insert_start, bcache_wq); 248 continue_at(cl, bch_data_insert_start, bcache_wq);
249 249
250 bch_keylist_free(&op->keys); 250 bch_keylist_free(&s->insert_keys);
251 closure_return(cl); 251 closure_return(cl);
252} 252}
253 253
@@ -439,6 +439,7 @@ static bool bch_alloc_sectors(struct bkey *k, unsigned sectors,
439static void bch_data_invalidate(struct closure *cl) 439static void bch_data_invalidate(struct closure *cl)
440{ 440{
441 struct btree_op *op = container_of(cl, struct btree_op, cl); 441 struct btree_op *op = container_of(cl, struct btree_op, cl);
442 struct search *s = container_of(op, struct search, op);
442 struct bio *bio = op->cache_bio; 443 struct bio *bio = op->cache_bio;
443 444
444 pr_debug("invalidating %i sectors from %llu", 445 pr_debug("invalidating %i sectors from %llu",
@@ -447,14 +448,14 @@ static void bch_data_invalidate(struct closure *cl)
447 while (bio_sectors(bio)) { 448 while (bio_sectors(bio)) {
448 unsigned len = min(bio_sectors(bio), 1U << 14); 449 unsigned len = min(bio_sectors(bio), 1U << 14);
449 450
450 if (bch_keylist_realloc(&op->keys, 0, op->c)) 451 if (bch_keylist_realloc(&s->insert_keys, 0, op->c))
451 goto out; 452 goto out;
452 453
453 bio->bi_sector += len; 454 bio->bi_sector += len;
454 bio->bi_size -= len << 9; 455 bio->bi_size -= len << 9;
455 456
456 bch_keylist_add(&op->keys, &KEY(op->inode, 457 bch_keylist_add(&s->insert_keys,
457 bio->bi_sector, len)); 458 &KEY(op->inode, bio->bi_sector, len));
458 } 459 }
459 460
460 op->insert_data_done = true; 461 op->insert_data_done = true;
@@ -466,6 +467,7 @@ out:
466static void bch_data_insert_error(struct closure *cl) 467static void bch_data_insert_error(struct closure *cl)
467{ 468{
468 struct btree_op *op = container_of(cl, struct btree_op, cl); 469 struct btree_op *op = container_of(cl, struct btree_op, cl);
470 struct search *s = container_of(op, struct search, op);
469 471
470 /* 472 /*
471 * Our data write just errored, which means we've got a bunch of keys to 473 * Our data write just errored, which means we've got a bunch of keys to
@@ -476,9 +478,9 @@ static void bch_data_insert_error(struct closure *cl)
476 * from the keys we'll accomplish just that. 478 * from the keys we'll accomplish just that.
477 */ 479 */
478 480
479 struct bkey *src = op->keys.keys, *dst = op->keys.keys; 481 struct bkey *src = s->insert_keys.keys, *dst = s->insert_keys.keys;
480 482
481 while (src != op->keys.top) { 483 while (src != s->insert_keys.top) {
482 struct bkey *n = bkey_next(src); 484 struct bkey *n = bkey_next(src);
483 485
484 SET_KEY_PTRS(src, 0); 486 SET_KEY_PTRS(src, 0);
@@ -488,7 +490,7 @@ static void bch_data_insert_error(struct closure *cl)
488 src = n; 490 src = n;
489 } 491 }
490 492
491 op->keys.top = dst; 493 s->insert_keys.top = dst;
492 494
493 bch_data_insert_keys(cl); 495 bch_data_insert_keys(cl);
494} 496}
@@ -539,12 +541,12 @@ static void bch_data_insert_start(struct closure *cl)
539 ? s->d->bio_split : op->c->bio_split; 541 ? s->d->bio_split : op->c->bio_split;
540 542
541 /* 1 for the device pointer and 1 for the chksum */ 543 /* 1 for the device pointer and 1 for the chksum */
542 if (bch_keylist_realloc(&op->keys, 544 if (bch_keylist_realloc(&s->insert_keys,
543 1 + (op->csum ? 1 : 0), 545 1 + (op->csum ? 1 : 0),
544 op->c)) 546 op->c))
545 continue_at(cl, bch_data_insert_keys, bcache_wq); 547 continue_at(cl, bch_data_insert_keys, bcache_wq);
546 548
547 k = op->keys.top; 549 k = s->insert_keys.top;
548 bkey_init(k); 550 bkey_init(k);
549 SET_KEY_INODE(k, op->inode); 551 SET_KEY_INODE(k, op->inode);
550 SET_KEY_OFFSET(k, bio->bi_sector); 552 SET_KEY_OFFSET(k, bio->bi_sector);
@@ -570,7 +572,7 @@ static void bch_data_insert_start(struct closure *cl)
570 bio_csum(n, k); 572 bio_csum(n, k);
571 573
572 trace_bcache_cache_insert(k); 574 trace_bcache_cache_insert(k);
573 bch_keylist_push(&op->keys); 575 bch_keylist_push(&s->insert_keys);
574 576
575 n->bi_rw |= REQ_WRITE; 577 n->bi_rw |= REQ_WRITE;
576 bch_submit_bbio(n, op->c, k, 0); 578 bch_submit_bbio(n, op->c, k, 0);
@@ -605,7 +607,7 @@ err:
605 op->insert_data_done = true; 607 op->insert_data_done = true;
606 bio_put(bio); 608 bio_put(bio);
607 609
608 if (!bch_keylist_empty(&op->keys)) 610 if (!bch_keylist_empty(&s->insert_keys))
609 continue_at(cl, bch_data_insert_keys, bcache_wq); 611 continue_at(cl, bch_data_insert_keys, bcache_wq);
610 else 612 else
611 closure_return(cl); 613 closure_return(cl);
@@ -634,8 +636,9 @@ err:
634void bch_data_insert(struct closure *cl) 636void bch_data_insert(struct closure *cl)
635{ 637{
636 struct btree_op *op = container_of(cl, struct btree_op, cl); 638 struct btree_op *op = container_of(cl, struct btree_op, cl);
639 struct search *s = container_of(op, struct search, op);
637 640
638 bch_keylist_init(&op->keys); 641 bch_keylist_init(&s->insert_keys);
639 bio_get(op->cache_bio); 642 bio_get(op->cache_bio);
640 bch_data_insert_start(cl); 643 bch_data_insert_start(cl);
641} 644}
@@ -724,9 +727,11 @@ static void search_free(struct closure *cl)
724 727
725static struct search *search_alloc(struct bio *bio, struct bcache_device *d) 728static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
726{ 729{
730 struct search *s;
727 struct bio_vec *bv; 731 struct bio_vec *bv;
728 struct search *s = mempool_alloc(d->c->search, GFP_NOIO); 732
729 memset(s, 0, offsetof(struct search, op.keys)); 733 s = mempool_alloc(d->c->search, GFP_NOIO);
734 memset(s, 0, offsetof(struct search, insert_keys));
730 735
731 __closure_init(&s->cl, NULL); 736 __closure_init(&s->cl, NULL);
732 737
diff --git a/drivers/md/bcache/request.h b/drivers/md/bcache/request.h
index 1f1b59d38db5..7d02ac5f936e 100644
--- a/drivers/md/bcache/request.h
+++ b/drivers/md/bcache/request.h
@@ -25,8 +25,10 @@ struct search {
25 short error; 25 short error;
26 unsigned long start_time; 26 unsigned long start_time;
27 27
28 /* Anything past op->keys won't get zeroed in do_bio_hook */
29 struct btree_op op; 28 struct btree_op op;
29
30 /* Anything past this point won't get zeroed in search_alloc() */
31 struct keylist insert_keys;
30}; 32};
31 33
32void bch_cache_read_endio(struct bio *, int); 34void bch_cache_read_endio(struct bio *, int);
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 8ffc8ec7231d..51dc709c9bf7 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -300,18 +300,21 @@ static void write_dirty_finish(struct closure *cl)
300 if (KEY_DIRTY(&w->key)) { 300 if (KEY_DIRTY(&w->key)) {
301 unsigned i; 301 unsigned i;
302 struct btree_op op; 302 struct btree_op op;
303 struct keylist keys;
304
303 bch_btree_op_init_stack(&op); 305 bch_btree_op_init_stack(&op);
306 bch_keylist_init(&keys);
304 307
305 op.type = BTREE_REPLACE; 308 op.type = BTREE_REPLACE;
306 bkey_copy(&op.replace, &w->key); 309 bkey_copy(&op.replace, &w->key);
307 310
308 SET_KEY_DIRTY(&w->key, false); 311 SET_KEY_DIRTY(&w->key, false);
309 bch_keylist_add(&op.keys, &w->key); 312 bch_keylist_add(&keys, &w->key);
310 313
311 for (i = 0; i < KEY_PTRS(&w->key); i++) 314 for (i = 0; i < KEY_PTRS(&w->key); i++)
312 atomic_inc(&PTR_BUCKET(dc->disk.c, &w->key, i)->pin); 315 atomic_inc(&PTR_BUCKET(dc->disk.c, &w->key, i)->pin);
313 316
314 bch_btree_insert(&op, dc->disk.c, &op.keys); 317 bch_btree_insert(&op, dc->disk.c, &keys);
315 closure_sync(&op.cl); 318 closure_sync(&op.cl);
316 319
317 if (op.insert_collision) 320 if (op.insert_collision)