xref: /linux/fs/xfs/xfs_zone_priv.h (revision c148bc7535650fbfa95a1f571b9ffa2ab478ea33)
14e4d5207SChristoph Hellwig /* SPDX-License-Identifier: GPL-2.0 */
24e4d5207SChristoph Hellwig #ifndef _XFS_ZONE_PRIV_H
34e4d5207SChristoph Hellwig #define _XFS_ZONE_PRIV_H
44e4d5207SChristoph Hellwig 
54e4d5207SChristoph Hellwig struct xfs_open_zone {
64e4d5207SChristoph Hellwig 	/*
74e4d5207SChristoph Hellwig 	 * Entry in the open zone list and refcount.  Protected by
84e4d5207SChristoph Hellwig 	 * zi_open_zones_lock in struct xfs_zone_info.
94e4d5207SChristoph Hellwig 	 */
104e4d5207SChristoph Hellwig 	struct list_head	oz_entry;
114e4d5207SChristoph Hellwig 	atomic_t		oz_ref;
124e4d5207SChristoph Hellwig 
134e4d5207SChristoph Hellwig 	/*
144e4d5207SChristoph Hellwig 	 * oz_write_pointer is the write pointer at which space is handed out
154e4d5207SChristoph Hellwig 	 * for conventional zones, or simple the count of blocks handed out
164e4d5207SChristoph Hellwig 	 * so far for sequential write required zones and is protected by
174e4d5207SChristoph Hellwig 	 * oz_alloc_lock/
184e4d5207SChristoph Hellwig 	 */
194e4d5207SChristoph Hellwig 	spinlock_t		oz_alloc_lock;
204e4d5207SChristoph Hellwig 	xfs_rgblock_t		oz_write_pointer;
214e4d5207SChristoph Hellwig 
224e4d5207SChristoph Hellwig 	/*
234e4d5207SChristoph Hellwig 	 * oz_written is the number of blocks for which we've received a
244e4d5207SChristoph Hellwig 	 * write completion.  oz_written must always be <= oz_write_pointer
254e4d5207SChristoph Hellwig 	 * and is protected by the ILOCK of the rmap inode.
264e4d5207SChristoph Hellwig 	 */
274e4d5207SChristoph Hellwig 	xfs_rgblock_t		oz_written;
284e4d5207SChristoph Hellwig 
294e4d5207SChristoph Hellwig 	/*
30*64d03611SHans Holmberg 	 * Write hint (data temperature) assigned to this zone, or
31*64d03611SHans Holmberg 	 * WRITE_LIFE_NOT_SET if none was set.
32*64d03611SHans Holmberg 	 */
33*64d03611SHans Holmberg 	enum rw_hint		oz_write_hint;
34*64d03611SHans Holmberg 
35*64d03611SHans Holmberg 	/*
364e4d5207SChristoph Hellwig 	 * Is this open zone used for garbage collection?  There can only be a
374e4d5207SChristoph Hellwig 	 * single open GC zone, which is pointed to by zi_open_gc_zone in
384e4d5207SChristoph Hellwig 	 * struct xfs_zone_info.  Constant over the life time of an open zone.
394e4d5207SChristoph Hellwig 	 */
404e4d5207SChristoph Hellwig 	bool			oz_is_gc;
414e4d5207SChristoph Hellwig 
424e4d5207SChristoph Hellwig 	/*
434e4d5207SChristoph Hellwig 	 * Pointer to the RT groups structure for this open zone.  Constant over
444e4d5207SChristoph Hellwig 	 * the life time of an open zone.
454e4d5207SChristoph Hellwig 	 */
464e4d5207SChristoph Hellwig 	struct xfs_rtgroup	*oz_rtg;
474e4d5207SChristoph Hellwig };
484e4d5207SChristoph Hellwig 
49080d01c4SChristoph Hellwig /*
50080d01c4SChristoph Hellwig  * Number of bitmap buckets to track reclaimable zones.  There are 10 buckets
51080d01c4SChristoph Hellwig  * so that each 10% of the usable capacity get their own bucket and GC can
52080d01c4SChristoph Hellwig  * only has to walk the bitmaps of the lesser used zones if there are any.
53080d01c4SChristoph Hellwig  */
54080d01c4SChristoph Hellwig #define XFS_ZONE_USED_BUCKETS		10u
55080d01c4SChristoph Hellwig 
564e4d5207SChristoph Hellwig struct xfs_zone_info {
574e4d5207SChristoph Hellwig 	/*
584e4d5207SChristoph Hellwig 	 * List of pending space reservations:
594e4d5207SChristoph Hellwig 	 */
604e4d5207SChristoph Hellwig 	spinlock_t		zi_reservation_lock;
614e4d5207SChristoph Hellwig 	struct list_head	zi_reclaim_reservations;
624e4d5207SChristoph Hellwig 
634e4d5207SChristoph Hellwig 	/*
644e4d5207SChristoph Hellwig 	 * List and number of open zones:
654e4d5207SChristoph Hellwig 	 */
664e4d5207SChristoph Hellwig 	spinlock_t		zi_open_zones_lock;
674e4d5207SChristoph Hellwig 	struct list_head	zi_open_zones;
684e4d5207SChristoph Hellwig 	unsigned int		zi_nr_open_zones;
694e4d5207SChristoph Hellwig 
704e4d5207SChristoph Hellwig 	/*
714e4d5207SChristoph Hellwig 	 * Free zone search cursor and number of free zones:
724e4d5207SChristoph Hellwig 	 */
734e4d5207SChristoph Hellwig 	unsigned long		zi_free_zone_cursor;
744e4d5207SChristoph Hellwig 	atomic_t		zi_nr_free_zones;
754e4d5207SChristoph Hellwig 
764e4d5207SChristoph Hellwig 	/*
774e4d5207SChristoph Hellwig 	 * Wait queue to wait for free zones or open zone resources to become
784e4d5207SChristoph Hellwig 	 * available:
794e4d5207SChristoph Hellwig 	 */
804e4d5207SChristoph Hellwig 	wait_queue_head_t	zi_zone_wait;
814e4d5207SChristoph Hellwig 
824e4d5207SChristoph Hellwig 	/*
834e4d5207SChristoph Hellwig 	 * Pointer to the GC thread, and the current open zone used by GC
844e4d5207SChristoph Hellwig 	 * (if any).
854e4d5207SChristoph Hellwig 	 *
864e4d5207SChristoph Hellwig 	 * zi_open_gc_zone is mostly private to the GC thread, but can be read
874e4d5207SChristoph Hellwig 	 * for debugging from other threads, in which case zi_open_zones_lock
884e4d5207SChristoph Hellwig 	 * must be taken to access it.
894e4d5207SChristoph Hellwig 	 */
904e4d5207SChristoph Hellwig 	struct task_struct      *zi_gc_thread;
914e4d5207SChristoph Hellwig 	struct xfs_open_zone	*zi_open_gc_zone;
924e4d5207SChristoph Hellwig 
934e4d5207SChristoph Hellwig 	/*
944e4d5207SChristoph Hellwig 	 * List of zones that need a reset:
954e4d5207SChristoph Hellwig 	 */
964e4d5207SChristoph Hellwig 	spinlock_t		zi_reset_list_lock;
974e4d5207SChristoph Hellwig 	struct xfs_group	*zi_reset_list;
98080d01c4SChristoph Hellwig 
99080d01c4SChristoph Hellwig 	/*
100080d01c4SChristoph Hellwig 	 * A set of bitmaps to bucket-sort reclaimable zones by used blocks to help
101080d01c4SChristoph Hellwig 	 * garbage collection to quickly find the best candidate for reclaim.
102080d01c4SChristoph Hellwig 	 */
103080d01c4SChristoph Hellwig 	spinlock_t		zi_used_buckets_lock;
104080d01c4SChristoph Hellwig 	unsigned int		zi_used_bucket_entries[XFS_ZONE_USED_BUCKETS];
105080d01c4SChristoph Hellwig 	unsigned long		*zi_used_bucket_bitmap[XFS_ZONE_USED_BUCKETS];
106080d01c4SChristoph Hellwig 
1074e4d5207SChristoph Hellwig };
1084e4d5207SChristoph Hellwig 
109*64d03611SHans Holmberg struct xfs_open_zone *xfs_open_zone(struct xfs_mount *mp,
110*64d03611SHans Holmberg 		enum rw_hint write_hint, bool is_gc);
1114e4d5207SChristoph Hellwig 
112080d01c4SChristoph Hellwig int xfs_zone_gc_reset_sync(struct xfs_rtgroup *rtg);
113080d01c4SChristoph Hellwig bool xfs_zoned_need_gc(struct xfs_mount *mp);
114080d01c4SChristoph Hellwig int xfs_zone_gc_mount(struct xfs_mount *mp);
115080d01c4SChristoph Hellwig void xfs_zone_gc_unmount(struct xfs_mount *mp);
116080d01c4SChristoph Hellwig 
1170bb21930SChristoph Hellwig void xfs_zoned_resv_wake_all(struct xfs_mount *mp);
1180bb21930SChristoph Hellwig 
1194e4d5207SChristoph Hellwig #endif /* _XFS_ZONE_PRIV_H */
120