| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _XFS_ZONE_PRIV_H |
| 3 | #define _XFS_ZONE_PRIV_H |
| 4 | |
| 5 | struct xfs_open_zone { |
| 6 | /* |
| 7 | * Entry in the open zone list and refcount. Protected by |
| 8 | * zi_open_zones_lock in struct xfs_zone_info. |
| 9 | */ |
| 10 | struct list_head oz_entry; |
| 11 | atomic_t oz_ref; |
| 12 | |
| 13 | /* |
| 14 | * oz_allocated is the amount of space already allocated out of the zone |
| 15 | * and is protected by oz_alloc_lock. |
| 16 | * |
| 17 | * For conventional zones it also is the offset of the next write. |
| 18 | */ |
| 19 | spinlock_t oz_alloc_lock; |
| 20 | xfs_rgblock_t oz_allocated; |
| 21 | |
| 22 | /* |
| 23 | * oz_written is the number of blocks for which we've received a write |
| 24 | * completion. oz_written must always be <= oz_allocated and is |
| 25 | * protected by the ILOCK of the rmap inode. |
| 26 | */ |
| 27 | xfs_rgblock_t oz_written; |
| 28 | |
| 29 | /* |
| 30 | * Write hint (data temperature) assigned to this zone, or |
| 31 | * WRITE_LIFE_NOT_SET if none was set. |
| 32 | */ |
| 33 | enum rw_hint oz_write_hint; |
| 34 | |
| 35 | /* |
| 36 | * Is this open zone used for garbage collection? There can only be a |
| 37 | * single open GC zone, which is pointed to by zi_open_gc_zone in |
| 38 | * struct xfs_zone_info. Constant over the life time of an open zone. |
| 39 | */ |
| 40 | bool oz_is_gc; |
| 41 | |
| 42 | /* |
| 43 | * Pointer to the RT groups structure for this open zone. Constant over |
| 44 | * the life time of an open zone. |
| 45 | */ |
| 46 | struct xfs_rtgroup *oz_rtg; |
| 47 | |
| 48 | struct rcu_head oz_rcu; |
| 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * Number of bitmap buckets to track reclaimable zones. There are 10 buckets |
| 53 | * so that each 10% of the usable capacity get their own bucket and GC can |
| 54 | * only has to walk the bitmaps of the lesser used zones if there are any. |
| 55 | */ |
| 56 | #define XFS_ZONE_USED_BUCKETS 10u |
| 57 | |
| 58 | struct xfs_zone_info { |
| 59 | /* |
| 60 | * List of pending space reservations: |
| 61 | */ |
| 62 | spinlock_t zi_reservation_lock; |
| 63 | struct list_head zi_reclaim_reservations; |
| 64 | |
| 65 | /* |
| 66 | * List and number of open zones: |
| 67 | */ |
| 68 | spinlock_t zi_open_zones_lock; |
| 69 | struct list_head zi_open_zones; |
| 70 | unsigned int zi_nr_open_zones; |
| 71 | |
| 72 | /* |
| 73 | * Free zone search cursor and number of free zones: |
| 74 | */ |
| 75 | unsigned long zi_free_zone_cursor; |
| 76 | atomic_t zi_nr_free_zones; |
| 77 | |
| 78 | /* |
| 79 | * Wait queue to wait for free zones or open zone resources to become |
| 80 | * available: |
| 81 | */ |
| 82 | wait_queue_head_t zi_zone_wait; |
| 83 | |
| 84 | /* |
| 85 | * Pointer to the GC thread, and the current open zone used by GC |
| 86 | * (if any). |
| 87 | * |
| 88 | * zi_open_gc_zone is mostly private to the GC thread, but can be read |
| 89 | * for debugging from other threads, in which case zi_open_zones_lock |
| 90 | * must be taken to access it. |
| 91 | */ |
| 92 | struct task_struct *zi_gc_thread; |
| 93 | struct xfs_open_zone *zi_open_gc_zone; |
| 94 | |
| 95 | /* |
| 96 | * List of zones that need a reset: |
| 97 | */ |
| 98 | spinlock_t zi_reset_list_lock; |
| 99 | struct xfs_group *zi_reset_list; |
| 100 | |
| 101 | /* |
| 102 | * A set of bitmaps to bucket-sort reclaimable zones by used blocks to help |
| 103 | * garbage collection to quickly find the best candidate for reclaim. |
| 104 | */ |
| 105 | spinlock_t zi_used_buckets_lock; |
| 106 | unsigned int zi_used_bucket_entries[XFS_ZONE_USED_BUCKETS]; |
| 107 | unsigned long *zi_used_bucket_bitmap[XFS_ZONE_USED_BUCKETS]; |
| 108 | |
| 109 | }; |
| 110 | |
| 111 | struct xfs_open_zone *xfs_open_zone(struct xfs_mount *mp, |
| 112 | enum rw_hint write_hint, bool is_gc); |
| 113 | |
| 114 | int xfs_zone_gc_reset_sync(struct xfs_rtgroup *rtg); |
| 115 | bool xfs_zoned_need_gc(struct xfs_mount *mp); |
| 116 | bool xfs_zoned_have_reclaimable(struct xfs_zone_info *zi); |
| 117 | int xfs_zone_gc_mount(struct xfs_mount *mp); |
| 118 | void xfs_zone_gc_unmount(struct xfs_mount *mp); |
| 119 | |
| 120 | void xfs_zoned_resv_wake_all(struct xfs_mount *mp); |
| 121 | |
| 122 | #endif /* _XFS_ZONE_PRIV_H */ |
| 123 | |