xref: /linux/fs/xfs/xfs_zone_priv.h (revision 0b0128e64af056a7dd29fa3bc780af654e53f861)
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 	/* Is this open zone used for garbage collection? */
36 	bool			oz_is_gc;
37 
38 	/*
39 	 * Pointer to the RT groups structure for this open zone.  Constant over
40 	 * the life time of an open zone.
41 	 */
42 	struct xfs_rtgroup	*oz_rtg;
43 
44 	struct rcu_head		oz_rcu;
45 };
46 
47 /*
48  * Number of bitmap buckets to track reclaimable zones.  There are 10 buckets
49  * so that each 10% of the usable capacity get their own bucket and GC can
50  * only has to walk the bitmaps of the lesser used zones if there are any.
51  */
52 #define XFS_ZONE_USED_BUCKETS		10u
53 
54 struct xfs_zone_info {
55 	/*
56 	 * List of pending space reservations:
57 	 */
58 	spinlock_t		zi_reservation_lock;
59 	struct list_head	zi_reclaim_reservations;
60 
61 	/*
62 	 * List and number of open zones:
63 	 */
64 	spinlock_t		zi_open_zones_lock;
65 	struct list_head	zi_open_zones;
66 	unsigned int		zi_nr_open_zones;
67 	unsigned int		zi_nr_open_gc_zones;
68 
69 	/*
70 	 * Free zone search cursor and number of free zones:
71 	 */
72 	atomic_t		zi_nr_free_zones;
73 
74 	/*
75 	 * Wait queue to wait for free zones or open zone resources to become
76 	 * available:
77 	 */
78 	wait_queue_head_t	zi_zone_wait;
79 
80 	/*
81 	 * Pointer to the GC thread.
82 	 */
83 	struct task_struct      *zi_gc_thread;
84 
85 	/*
86 	 * List of zones that need a reset:
87 	 */
88 	spinlock_t		zi_reset_list_lock;
89 	struct xfs_group	*zi_reset_list;
90 
91 	/*
92 	 * A set of bitmaps to bucket-sort reclaimable zones by used blocks to help
93 	 * garbage collection to quickly find the best candidate for reclaim.
94 	 */
95 	spinlock_t		zi_used_buckets_lock;
96 	unsigned int		zi_used_bucket_entries[XFS_ZONE_USED_BUCKETS];
97 	unsigned long		*zi_used_bucket_bitmap[XFS_ZONE_USED_BUCKETS];
98 
99 };
100 
101 struct xfs_open_zone *xfs_open_zone(struct xfs_mount *mp,
102 		enum rw_hint write_hint, bool is_gc);
103 
104 int xfs_zone_gc_reset_sync(struct xfs_rtgroup *rtg);
105 bool xfs_zoned_need_gc(struct xfs_mount *mp);
106 bool xfs_zoned_have_reclaimable(struct xfs_zone_info *zi);
107 int xfs_zone_gc_mount(struct xfs_mount *mp);
108 void xfs_zone_gc_unmount(struct xfs_mount *mp);
109 
110 void xfs_zoned_resv_wake_all(struct xfs_mount *mp);
111 
112 #endif /* _XFS_ZONE_PRIV_H */
113