diff options
Diffstat (limited to 'drivers/md/bcache/bcache.h')
-rw-r--r-- | drivers/md/bcache/bcache.h | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index dbdbca5a9591..0c707e4f4eaf 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
@@ -187,6 +187,7 @@ | |||
187 | #include <linux/types.h> | 187 | #include <linux/types.h> |
188 | #include <linux/workqueue.h> | 188 | #include <linux/workqueue.h> |
189 | 189 | ||
190 | #include "bset.h" | ||
190 | #include "util.h" | 191 | #include "util.h" |
191 | #include "closure.h" | 192 | #include "closure.h" |
192 | 193 | ||
@@ -309,7 +310,8 @@ struct cached_dev { | |||
309 | struct cache_sb sb; | 310 | struct cache_sb sb; |
310 | struct bio sb_bio; | 311 | struct bio sb_bio; |
311 | struct bio_vec sb_bv[1]; | 312 | struct bio_vec sb_bv[1]; |
312 | struct closure_with_waitlist sb_write; | 313 | struct closure sb_write; |
314 | struct semaphore sb_write_mutex; | ||
313 | 315 | ||
314 | /* Refcount on the cache set. Always nonzero when we're caching. */ | 316 | /* Refcount on the cache set. Always nonzero when we're caching. */ |
315 | atomic_t count; | 317 | atomic_t count; |
@@ -382,12 +384,12 @@ struct cached_dev { | |||
382 | unsigned writeback_rate_p_term_inverse; | 384 | unsigned writeback_rate_p_term_inverse; |
383 | }; | 385 | }; |
384 | 386 | ||
385 | enum alloc_watermarks { | 387 | enum alloc_reserve { |
386 | WATERMARK_PRIO, | 388 | RESERVE_BTREE, |
387 | WATERMARK_METADATA, | 389 | RESERVE_PRIO, |
388 | WATERMARK_MOVINGGC, | 390 | RESERVE_MOVINGGC, |
389 | WATERMARK_NONE, | 391 | RESERVE_NONE, |
390 | WATERMARK_MAX | 392 | RESERVE_NR, |
391 | }; | 393 | }; |
392 | 394 | ||
393 | struct cache { | 395 | struct cache { |
@@ -399,8 +401,6 @@ struct cache { | |||
399 | struct kobject kobj; | 401 | struct kobject kobj; |
400 | struct block_device *bdev; | 402 | struct block_device *bdev; |
401 | 403 | ||
402 | unsigned watermark[WATERMARK_MAX]; | ||
403 | |||
404 | struct task_struct *alloc_thread; | 404 | struct task_struct *alloc_thread; |
405 | 405 | ||
406 | struct closure prio; | 406 | struct closure prio; |
@@ -429,7 +429,7 @@ struct cache { | |||
429 | * because all the data they contained was overwritten), so we only | 429 | * because all the data they contained was overwritten), so we only |
430 | * need to discard them before they can be moved to the free list. | 430 | * need to discard them before they can be moved to the free list. |
431 | */ | 431 | */ |
432 | DECLARE_FIFO(long, free); | 432 | DECLARE_FIFO(long, free)[RESERVE_NR]; |
433 | DECLARE_FIFO(long, free_inc); | 433 | DECLARE_FIFO(long, free_inc); |
434 | DECLARE_FIFO(long, unused); | 434 | DECLARE_FIFO(long, unused); |
435 | 435 | ||
@@ -514,7 +514,8 @@ struct cache_set { | |||
514 | uint64_t cached_dev_sectors; | 514 | uint64_t cached_dev_sectors; |
515 | struct closure caching; | 515 | struct closure caching; |
516 | 516 | ||
517 | struct closure_with_waitlist sb_write; | 517 | struct closure sb_write; |
518 | struct semaphore sb_write_mutex; | ||
518 | 519 | ||
519 | mempool_t *search; | 520 | mempool_t *search; |
520 | mempool_t *bio_meta; | 521 | mempool_t *bio_meta; |
@@ -629,13 +630,15 @@ struct cache_set { | |||
629 | 630 | ||
630 | #ifdef CONFIG_BCACHE_DEBUG | 631 | #ifdef CONFIG_BCACHE_DEBUG |
631 | struct btree *verify_data; | 632 | struct btree *verify_data; |
633 | struct bset *verify_ondisk; | ||
632 | struct mutex verify_lock; | 634 | struct mutex verify_lock; |
633 | #endif | 635 | #endif |
634 | 636 | ||
635 | unsigned nr_uuids; | 637 | unsigned nr_uuids; |
636 | struct uuid_entry *uuids; | 638 | struct uuid_entry *uuids; |
637 | BKEY_PADDED(uuid_bucket); | 639 | BKEY_PADDED(uuid_bucket); |
638 | struct closure_with_waitlist uuid_write; | 640 | struct closure uuid_write; |
641 | struct semaphore uuid_write_mutex; | ||
639 | 642 | ||
640 | /* | 643 | /* |
641 | * A btree node on disk could have too many bsets for an iterator to fit | 644 | * A btree node on disk could have too many bsets for an iterator to fit |
@@ -643,13 +646,7 @@ struct cache_set { | |||
643 | */ | 646 | */ |
644 | mempool_t *fill_iter; | 647 | mempool_t *fill_iter; |
645 | 648 | ||
646 | /* | 649 | struct bset_sort_state sort; |
647 | * btree_sort() is a merge sort and requires temporary space - single | ||
648 | * element mempool | ||
649 | */ | ||
650 | struct mutex sort_lock; | ||
651 | struct bset *sort; | ||
652 | unsigned sort_crit_factor; | ||
653 | 650 | ||
654 | /* List of buckets we're currently writing data to */ | 651 | /* List of buckets we're currently writing data to */ |
655 | struct list_head data_buckets; | 652 | struct list_head data_buckets; |
@@ -665,7 +662,6 @@ struct cache_set { | |||
665 | unsigned congested_read_threshold_us; | 662 | unsigned congested_read_threshold_us; |
666 | unsigned congested_write_threshold_us; | 663 | unsigned congested_write_threshold_us; |
667 | 664 | ||
668 | struct time_stats sort_time; | ||
669 | struct time_stats btree_gc_time; | 665 | struct time_stats btree_gc_time; |
670 | struct time_stats btree_split_time; | 666 | struct time_stats btree_split_time; |
671 | struct time_stats btree_read_time; | 667 | struct time_stats btree_read_time; |
@@ -683,9 +679,9 @@ struct cache_set { | |||
683 | unsigned error_decay; | 679 | unsigned error_decay; |
684 | 680 | ||
685 | unsigned short journal_delay_ms; | 681 | unsigned short journal_delay_ms; |
682 | bool expensive_debug_checks; | ||
686 | unsigned verify:1; | 683 | unsigned verify:1; |
687 | unsigned key_merging_disabled:1; | 684 | unsigned key_merging_disabled:1; |
688 | unsigned expensive_debug_checks:1; | ||
689 | unsigned gc_always_rewrite:1; | 685 | unsigned gc_always_rewrite:1; |
690 | unsigned shrinker_disabled:1; | 686 | unsigned shrinker_disabled:1; |
691 | unsigned copy_gc_enabled:1; | 687 | unsigned copy_gc_enabled:1; |
@@ -707,13 +703,8 @@ struct bbio { | |||
707 | struct bio bio; | 703 | struct bio bio; |
708 | }; | 704 | }; |
709 | 705 | ||
710 | static inline unsigned local_clock_us(void) | ||
711 | { | ||
712 | return local_clock() >> 10; | ||
713 | } | ||
714 | |||
715 | #define BTREE_PRIO USHRT_MAX | 706 | #define BTREE_PRIO USHRT_MAX |
716 | #define INITIAL_PRIO 32768 | 707 | #define INITIAL_PRIO 32768U |
717 | 708 | ||
718 | #define btree_bytes(c) ((c)->btree_pages * PAGE_SIZE) | 709 | #define btree_bytes(c) ((c)->btree_pages * PAGE_SIZE) |
719 | #define btree_blocks(b) \ | 710 | #define btree_blocks(b) \ |
@@ -726,21 +717,6 @@ static inline unsigned local_clock_us(void) | |||
726 | #define bucket_bytes(c) ((c)->sb.bucket_size << 9) | 717 | #define bucket_bytes(c) ((c)->sb.bucket_size << 9) |
727 | #define block_bytes(c) ((c)->sb.block_size << 9) | 718 | #define block_bytes(c) ((c)->sb.block_size << 9) |
728 | 719 | ||
729 | #define __set_bytes(i, k) (sizeof(*(i)) + (k) * sizeof(uint64_t)) | ||
730 | #define set_bytes(i) __set_bytes(i, i->keys) | ||
731 | |||
732 | #define __set_blocks(i, k, c) DIV_ROUND_UP(__set_bytes(i, k), block_bytes(c)) | ||
733 | #define set_blocks(i, c) __set_blocks(i, (i)->keys, c) | ||
734 | |||
735 | #define node(i, j) ((struct bkey *) ((i)->d + (j))) | ||
736 | #define end(i) node(i, (i)->keys) | ||
737 | |||
738 | #define index(i, b) \ | ||
739 | ((size_t) (((void *) i - (void *) (b)->sets[0].data) / \ | ||
740 | block_bytes(b->c))) | ||
741 | |||
742 | #define btree_data_space(b) (PAGE_SIZE << (b)->page_order) | ||
743 | |||
744 | #define prios_per_bucket(c) \ | 720 | #define prios_per_bucket(c) \ |
745 | ((bucket_bytes(c) - sizeof(struct prio_set)) / \ | 721 | ((bucket_bytes(c) - sizeof(struct prio_set)) / \ |
746 | sizeof(struct bucket_disk)) | 722 | sizeof(struct bucket_disk)) |
@@ -783,20 +759,34 @@ static inline struct bucket *PTR_BUCKET(struct cache_set *c, | |||
783 | return PTR_CACHE(c, k, ptr)->buckets + PTR_BUCKET_NR(c, k, ptr); | 759 | return PTR_CACHE(c, k, ptr)->buckets + PTR_BUCKET_NR(c, k, ptr); |
784 | } | 760 | } |
785 | 761 | ||
786 | /* Btree key macros */ | 762 | static inline uint8_t gen_after(uint8_t a, uint8_t b) |
763 | { | ||
764 | uint8_t r = a - b; | ||
765 | return r > 128U ? 0 : r; | ||
766 | } | ||
787 | 767 | ||
788 | static inline void bkey_init(struct bkey *k) | 768 | static inline uint8_t ptr_stale(struct cache_set *c, const struct bkey *k, |
769 | unsigned i) | ||
789 | { | 770 | { |
790 | *k = ZERO_KEY; | 771 | return gen_after(PTR_BUCKET(c, k, i)->gen, PTR_GEN(k, i)); |
791 | } | 772 | } |
792 | 773 | ||
774 | static inline bool ptr_available(struct cache_set *c, const struct bkey *k, | ||
775 | unsigned i) | ||
776 | { | ||
777 | return (PTR_DEV(k, i) < MAX_CACHES_PER_SET) && PTR_CACHE(c, k, i); | ||
778 | } | ||
779 | |||
780 | /* Btree key macros */ | ||
781 | |||
793 | /* | 782 | /* |
794 | * This is used for various on disk data structures - cache_sb, prio_set, bset, | 783 | * This is used for various on disk data structures - cache_sb, prio_set, bset, |
795 | * jset: The checksum is _always_ the first 8 bytes of these structs | 784 | * jset: The checksum is _always_ the first 8 bytes of these structs |
796 | */ | 785 | */ |
797 | #define csum_set(i) \ | 786 | #define csum_set(i) \ |
798 | bch_crc64(((void *) (i)) + sizeof(uint64_t), \ | 787 | bch_crc64(((void *) (i)) + sizeof(uint64_t), \ |
799 | ((void *) end(i)) - (((void *) (i)) + sizeof(uint64_t))) | 788 | ((void *) bset_bkey_last(i)) - \ |
789 | (((void *) (i)) + sizeof(uint64_t))) | ||
800 | 790 | ||
801 | /* Error handling macros */ | 791 | /* Error handling macros */ |
802 | 792 | ||