Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcache: get rid of discard code from journal

In bcache journal there is discard functionality but almost useless in
reality. Because discard happens after a journal bucket is reclaimed,
and the reclaimed bucket is allocated for new journaling immediately.
There is no time for underlying SSD to use the discard hint for internal
data management.

The discard code in bcache journal doesn't bring any performance
optimization and wastes CPU cycles for issuing discard bios. Therefore
this patch gits rid of it from journal.c and journal.h.

Signed-off-by: Coly Li <colyli@fnnas.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Coly Li and committed by
Jens Axboe
0c72e9fc 7b2038b1

+8 -98
+8 -85
drivers/md/bcache/journal.c
··· 275 275 * ja->cur_idx 276 276 */ 277 277 ja->cur_idx = i; 278 - ja->last_idx = ja->discard_idx = (i + 1) % 279 - ca->sb.njournal_buckets; 278 + ja->last_idx = (i + 1) % ca->sb.njournal_buckets; 280 279 281 280 } 282 281 ··· 335 336 } 336 337 } 337 338 338 - static bool is_discard_enabled(struct cache_set *s) 339 - { 340 - struct cache *ca = s->cache; 341 - 342 - if (ca->discard) 343 - return true; 344 - 345 - return false; 346 - } 347 - 348 339 int bch_journal_replay(struct cache_set *s, struct list_head *list) 349 340 { 350 341 int ret = 0, keys = 0, entries = 0; ··· 349 360 BUG_ON(i->pin && atomic_read(i->pin) != 1); 350 361 351 362 if (n != i->j.seq) { 352 - if (n == start && is_discard_enabled(s)) 353 - pr_info("journal entries %llu-%llu may be discarded! (replaying %llu-%llu)\n", 354 - n, i->j.seq - 1, start, end); 355 - else { 356 - pr_err("journal entries %llu-%llu missing! (replaying %llu-%llu)\n", 357 - n, i->j.seq - 1, start, end); 358 - ret = -EIO; 359 - goto err; 360 - } 363 + pr_err("journal entries %llu-%llu missing! (replaying %llu-%llu)\n", 364 + n, i->j.seq - 1, start, end); 365 + ret = -EIO; 366 + goto err; 361 367 } 362 368 363 369 for (k = i->j.start; ··· 552 568 553 569 #define last_seq(j) ((j)->seq - fifo_used(&(j)->pin) + 1) 554 570 555 - static void journal_discard_endio(struct bio *bio) 556 - { 557 - struct journal_device *ja = 558 - container_of(bio, struct journal_device, discard_bio); 559 - struct cache *ca = container_of(ja, struct cache, journal); 560 - 561 - atomic_set(&ja->discard_in_flight, DISCARD_DONE); 562 - 563 - closure_wake_up(&ca->set->journal.wait); 564 - closure_put(&ca->set->cl); 565 - } 566 - 567 - static void journal_discard_work(struct work_struct *work) 568 - { 569 - struct journal_device *ja = 570 - container_of(work, struct journal_device, discard_work); 571 - 572 - submit_bio(&ja->discard_bio); 573 - } 574 - 575 - static void do_journal_discard(struct cache *ca) 576 - { 577 - struct journal_device *ja = &ca->journal; 578 - struct bio *bio = &ja->discard_bio; 579 - 580 - if (!ca->discard) { 581 - ja->discard_idx = ja->last_idx; 582 - return; 583 - } 584 - 585 - switch (atomic_read(&ja->discard_in_flight)) { 586 - case DISCARD_IN_FLIGHT: 587 - return; 588 - 589 - case DISCARD_DONE: 590 - ja->discard_idx = (ja->discard_idx + 1) % 591 - ca->sb.njournal_buckets; 592 - 593 - atomic_set(&ja->discard_in_flight, DISCARD_READY); 594 - fallthrough; 595 - 596 - case DISCARD_READY: 597 - if (ja->discard_idx == ja->last_idx) 598 - return; 599 - 600 - atomic_set(&ja->discard_in_flight, DISCARD_IN_FLIGHT); 601 - 602 - bio_init_inline(bio, ca->bdev, 1, REQ_OP_DISCARD); 603 - bio->bi_iter.bi_sector = bucket_to_sector(ca->set, 604 - ca->sb.d[ja->discard_idx]); 605 - bio->bi_iter.bi_size = bucket_bytes(ca); 606 - bio->bi_end_io = journal_discard_endio; 607 - 608 - closure_get(&ca->set->cl); 609 - INIT_WORK(&ja->discard_work, journal_discard_work); 610 - queue_work(bch_journal_wq, &ja->discard_work); 611 - } 612 - } 613 - 614 571 static unsigned int free_journal_buckets(struct cache_set *c) 615 572 { 616 573 struct journal *j = &c->journal; ··· 560 635 unsigned int n; 561 636 562 637 /* In case njournal_buckets is not power of 2 */ 563 - if (ja->cur_idx >= ja->discard_idx) 564 - n = ca->sb.njournal_buckets + ja->discard_idx - ja->cur_idx; 638 + if (ja->cur_idx >= ja->last_idx) 639 + n = ca->sb.njournal_buckets + ja->last_idx - ja->cur_idx; 565 640 else 566 - n = ja->discard_idx - ja->cur_idx; 641 + n = ja->last_idx - ja->cur_idx; 567 642 568 643 if (n > (1 + j->do_reserve)) 569 644 return n - (1 + j->do_reserve); ··· 592 667 ja->seq[ja->last_idx] < last_seq) 593 668 ja->last_idx = (ja->last_idx + 1) % 594 669 ca->sb.njournal_buckets; 595 - 596 - do_journal_discard(ca); 597 670 598 671 if (c->journal.blocks_free) 599 672 goto out;
-13
drivers/md/bcache/journal.h
··· 139 139 /* Last journal bucket that still contains an open journal entry */ 140 140 unsigned int last_idx; 141 141 142 - /* Next journal bucket to be discarded */ 143 - unsigned int discard_idx; 144 - 145 - #define DISCARD_READY 0 146 - #define DISCARD_IN_FLIGHT 1 147 - #define DISCARD_DONE 2 148 - /* 1 - discard in flight, -1 - discard completed */ 149 - atomic_t discard_in_flight; 150 - 151 - struct work_struct discard_work; 152 - struct bio discard_bio; 153 - struct bio_vec discard_bv; 154 - 155 142 /* Bio for journal reads/writes to this device */ 156 143 struct bio bio; 157 144 struct bio_vec bv[8];