alloc_background_format.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BCACHEFS_ALLOC_BACKGROUND_FORMAT_H
  3. #define _BCACHEFS_ALLOC_BACKGROUND_FORMAT_H
  4. struct bch_alloc {
  5. struct bch_val v;
  6. __u8 fields;
  7. __u8 gen;
  8. __u8 data[];
  9. } __packed __aligned(8);
  10. #define BCH_ALLOC_FIELDS_V1() \
  11. x(read_time, 16) \
  12. x(write_time, 16) \
  13. x(data_type, 8) \
  14. x(dirty_sectors, 16) \
  15. x(cached_sectors, 16) \
  16. x(oldest_gen, 8) \
  17. x(stripe, 32) \
  18. x(stripe_redundancy, 8)
  19. enum {
  20. #define x(name, _bits) BCH_ALLOC_FIELD_V1_##name,
  21. BCH_ALLOC_FIELDS_V1()
  22. #undef x
  23. };
  24. struct bch_alloc_v2 {
  25. struct bch_val v;
  26. __u8 nr_fields;
  27. __u8 gen;
  28. __u8 oldest_gen;
  29. __u8 data_type;
  30. __u8 data[];
  31. } __packed __aligned(8);
  32. #define BCH_ALLOC_FIELDS_V2() \
  33. x(read_time, 64) \
  34. x(write_time, 64) \
  35. x(dirty_sectors, 32) \
  36. x(cached_sectors, 32) \
  37. x(stripe, 32) \
  38. x(stripe_redundancy, 8)
  39. struct bch_alloc_v3 {
  40. struct bch_val v;
  41. __le64 journal_seq;
  42. __le32 flags;
  43. __u8 nr_fields;
  44. __u8 gen;
  45. __u8 oldest_gen;
  46. __u8 data_type;
  47. __u8 data[];
  48. } __packed __aligned(8);
  49. LE32_BITMASK(BCH_ALLOC_V3_NEED_DISCARD,struct bch_alloc_v3, flags, 0, 1)
  50. LE32_BITMASK(BCH_ALLOC_V3_NEED_INC_GEN,struct bch_alloc_v3, flags, 1, 2)
  51. struct bch_alloc_v4 {
  52. struct bch_val v;
  53. __u64 journal_seq;
  54. __u32 flags;
  55. __u8 gen;
  56. __u8 oldest_gen;
  57. __u8 data_type;
  58. __u8 stripe_redundancy;
  59. __u32 dirty_sectors;
  60. __u32 cached_sectors;
  61. __u64 io_time[2];
  62. __u32 stripe;
  63. __u32 nr_external_backpointers;
  64. /* end of fields in original version of alloc_v4 */
  65. __u64 _fragmentation_lru; /* obsolete */
  66. __u32 stripe_sectors;
  67. __u32 pad;
  68. } __packed __aligned(8);
  69. #define BCH_ALLOC_V4_U64s_V0 6
  70. #define BCH_ALLOC_V4_U64s (sizeof(struct bch_alloc_v4) / sizeof(__u64))
  71. BITMASK(BCH_ALLOC_V4_NEED_DISCARD, struct bch_alloc_v4, flags, 0, 1)
  72. BITMASK(BCH_ALLOC_V4_NEED_INC_GEN, struct bch_alloc_v4, flags, 1, 2)
  73. BITMASK(BCH_ALLOC_V4_BACKPOINTERS_START,struct bch_alloc_v4, flags, 2, 8)
  74. BITMASK(BCH_ALLOC_V4_NR_BACKPOINTERS, struct bch_alloc_v4, flags, 8, 14)
  75. #define KEY_TYPE_BUCKET_GENS_BITS 8
  76. #define KEY_TYPE_BUCKET_GENS_NR (1U << KEY_TYPE_BUCKET_GENS_BITS)
  77. #define KEY_TYPE_BUCKET_GENS_MASK (KEY_TYPE_BUCKET_GENS_NR - 1)
  78. struct bch_bucket_gens {
  79. struct bch_val v;
  80. u8 gens[KEY_TYPE_BUCKET_GENS_NR];
  81. } __packed __aligned(8);
  82. #endif /* _BCACHEFS_ALLOC_BACKGROUND_FORMAT_H */