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_write_pointer is the write pointer at which space is handed out 15 * for conventional zones, or simple the count of blocks handed out 16 * so far for sequential write required zones and is protected by 17 * oz_alloc_lock/ 18 */ 19 spinlock_t oz_alloc_lock; 20 xfs_rgblock_t oz_write_pointer; 21 22 /* 23 * oz_written is the number of blocks for which we've received a 24 * write completion. oz_written must always be <= oz_write_pointer 25 * and is 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 49 /* 50 * Number of bitmap buckets to track reclaimable zones. There are 10 buckets 51 * so that each 10% of the usable capacity get their own bucket and GC can 52 * only has to walk the bitmaps of the lesser used zones if there are any. 53 */ 54 #define XFS_ZONE_USED_BUCKETS 10u 55 56 struct xfs_zone_info { 57 /* 58 * List of pending space reservations: 59 */ 60 spinlock_t zi_reservation_lock; 61 struct list_head zi_reclaim_reservations; 62 63 /* 64 * List and number of open zones: 65 */ 66 spinlock_t zi_open_zones_lock; 67 struct list_head zi_open_zones; 68 unsigned int zi_nr_open_zones; 69 70 /* 71 * Free zone search cursor and number of free zones: 72 */ 73 unsigned long zi_free_zone_cursor; 74 atomic_t zi_nr_free_zones; 75 76 /* 77 * Wait queue to wait for free zones or open zone resources to become 78 * available: 79 */ 80 wait_queue_head_t zi_zone_wait; 81 82 /* 83 * Pointer to the GC thread, and the current open zone used by GC 84 * (if any). 85 * 86 * zi_open_gc_zone is mostly private to the GC thread, but can be read 87 * for debugging from other threads, in which case zi_open_zones_lock 88 * must be taken to access it. 89 */ 90 struct task_struct *zi_gc_thread; 91 struct xfs_open_zone *zi_open_gc_zone; 92 93 /* 94 * List of zones that need a reset: 95 */ 96 spinlock_t zi_reset_list_lock; 97 struct xfs_group *zi_reset_list; 98 99 /* 100 * A set of bitmaps to bucket-sort reclaimable zones by used blocks to help 101 * garbage collection to quickly find the best candidate for reclaim. 102 */ 103 spinlock_t zi_used_buckets_lock; 104 unsigned int zi_used_bucket_entries[XFS_ZONE_USED_BUCKETS]; 105 unsigned long *zi_used_bucket_bitmap[XFS_ZONE_USED_BUCKETS]; 106 107 }; 108 109 struct xfs_open_zone *xfs_open_zone(struct xfs_mount *mp, 110 enum rw_hint write_hint, bool is_gc); 111 112 int xfs_zone_gc_reset_sync(struct xfs_rtgroup *rtg); 113 bool xfs_zoned_need_gc(struct xfs_mount *mp); 114 int xfs_zone_gc_mount(struct xfs_mount *mp); 115 void xfs_zone_gc_unmount(struct xfs_mount *mp); 116 117 void xfs_zoned_resv_wake_all(struct xfs_mount *mp); 118 119 #endif /* _XFS_ZONE_PRIV_H */ 120