Blame view
fs/btrfs/space-info.h
5.05 KB
8719aaae8 btrfs: move space... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef BTRFS_SPACE_INFO_H #define BTRFS_SPACE_INFO_H struct btrfs_space_info { spinlock_t lock; u64 total_bytes; /* total bytes in the space, this doesn't take mirrors into account */ u64 bytes_used; /* total bytes used, this doesn't take mirrors into account */ u64 bytes_pinned; /* total bytes pinned, will be freed when the transaction finishes */ u64 bytes_reserved; /* total bytes the allocator has reserved for current allocations */ u64 bytes_may_use; /* number of bytes that may be used for delalloc/allocations */ u64 bytes_readonly; /* total bytes that are read only */ u64 max_extent_size; /* This will hold the maximum extent size of the space info if we had an ENOSPC in the allocator. */ unsigned int full:1; /* indicates that we cannot allocate any more chunks for this space */ unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ unsigned int flush:1; /* set if we are trying to make space */ unsigned int force_alloc; /* set if we need to force a chunk alloc for this space */ u64 disk_used; /* total bytes used on disk */ u64 disk_total; /* total bytes on disk, takes mirrors into account */ u64 flags; /* * bytes_pinned is kept in line with what is actually pinned, as in * we've called update_block_group and dropped the bytes_used counter * and increased the bytes_pinned counter. However this means that * bytes_pinned does not reflect the bytes that will be pinned once the * delayed refs are flushed, so this counter is inc'ed every time we * call btrfs_free_extent so it is a realtime count of what will be * freed once the transaction is committed. It will be zeroed every * time the transaction commits. */ struct percpu_counter total_bytes_pinned; struct list_head list; /* Protected by the spinlock 'lock'. */ struct list_head ro_bgs; struct list_head priority_tickets; struct list_head tickets; |
db161806d btrfs: account ti... |
57 58 59 60 61 62 |
/* * Size of space that needs to be reclaimed in order to satisfy pending * tickets */ u64 reclaim_size; |
8719aaae8 btrfs: move space... |
63 64 65 66 67 68 69 70 71 |
/* * tickets_id just indicates the next ticket will be handled, so note * it's not stored per ticket. */ u64 tickets_id; struct rw_semaphore groups_sem; /* for block groups in our same type */ struct list_head block_groups[BTRFS_NR_RAID_TYPES]; |
8719aaae8 btrfs: move space... |
72 73 74 75 |
struct kobject kobj; struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; }; |
b338b013e btrfs: move btrfs... |
76 |
struct reserve_ticket { |
b338b013e btrfs: move btrfs... |
77 78 |
u64 bytes; int error; |
7f9fe6144 btrfs: improve gl... |
79 |
bool steal; |
b338b013e btrfs: move btrfs... |
80 81 82 |
struct list_head list; wait_queue_head_t wait; }; |
8719aaae8 btrfs: move space... |
83 84 85 86 87 |
static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) { return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) && (space_info->flags & BTRFS_BLOCK_GROUP_DATA)); } |
bb96c4e57 btrfs: move the s... |
88 89 90 91 |
/* * * Declare a helper function to detect underflow of various space info members */ |
f3e75e380 btrfs: roll trace... |
92 |
#define DECLARE_SPACE_INFO_UPDATE(name, trace_name) \ |
bb96c4e57 btrfs: move the s... |
93 94 95 96 97 |
static inline void \ btrfs_space_info_update_##name(struct btrfs_fs_info *fs_info, \ struct btrfs_space_info *sinfo, \ s64 bytes) \ { \ |
f3e75e380 btrfs: roll trace... |
98 |
const u64 abs_bytes = (bytes < 0) ? -bytes : bytes; \ |
bb96c4e57 btrfs: move the s... |
99 100 |
lockdep_assert_held(&sinfo->lock); \ trace_update_##name(fs_info, sinfo, sinfo->name, bytes); \ |
f3e75e380 btrfs: roll trace... |
101 102 103 |
trace_btrfs_space_reservation(fs_info, trace_name, \ sinfo->flags, abs_bytes, \ bytes > 0); \ |
bb96c4e57 btrfs: move the s... |
104 105 106 107 108 109 110 |
if (bytes < 0 && sinfo->name < -bytes) { \ WARN_ON(1); \ sinfo->name = 0; \ return; \ } \ sinfo->name += bytes; \ } |
f3e75e380 btrfs: roll trace... |
111 112 |
DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info"); DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned"); |
bb96c4e57 btrfs: move the s... |
113 |
|
280c29088 btrfs: move the s... |
114 115 116 117 118 119 120 |
int btrfs_init_space_info(struct btrfs_fs_info *fs_info); void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, u64 total_bytes, u64 bytes_used, u64 bytes_readonly, struct btrfs_space_info **space_info); struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info, u64 flags); |
e1f60a658 btrfs: add __pure... |
121 |
u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info, |
280c29088 btrfs: move the s... |
122 123 |
bool may_use_included); void btrfs_clear_space_info_full(struct btrfs_fs_info *info); |
5da6afeb3 btrfs: move dump_... |
124 125 126 |
void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, struct btrfs_space_info *info, u64 bytes, int dump_block_groups); |
0d9764f6d btrfs: move reser... |
127 128 129 130 |
int btrfs_reserve_metadata_bytes(struct btrfs_root *root, struct btrfs_block_rsv *block_rsv, u64 orig_bytes, enum btrfs_reserve_flush_enum flush); |
18fa2284a btrfs: refactor t... |
131 132 |
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info); |
a30a3d206 btrfs: take overc... |
133 134 135 |
int btrfs_can_overcommit(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, u64 bytes, enum btrfs_reserve_flush_enum flush); |
18fa2284a btrfs: refactor t... |
136 |
|
d05e46497 btrfs: rename btr... |
137 |
static inline void btrfs_space_info_free_bytes_may_use( |
18fa2284a btrfs: refactor t... |
138 139 140 141 142 143 144 145 146 |
struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, u64 num_bytes) { spin_lock(&space_info->lock); btrfs_space_info_update_bytes_may_use(fs_info, space_info, -num_bytes); btrfs_try_granting_tickets(fs_info, space_info); spin_unlock(&space_info->lock); } |
8698fc4eb btrfs: add btrfs_... |
147 148 |
int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes, enum btrfs_reserve_flush_enum flush); |
d44b72aa1 btrfs: export spa... |
149 |
|
8719aaae8 btrfs: move space... |
150 |
#endif /* BTRFS_SPACE_INFO_H */ |