Skip to content

Commit 18fa228

Browse files
josefbacikkdave
authored andcommitted
btrfs: refactor the ticket wakeup code
Now that btrfs_space_info_add_old_bytes simply checks if we can make the reservation and updates bytes_may_use, there's no reason to have both helpers in place. Factor out the ticket wakeup logic into it's own helper, make btrfs_space_info_add_old_bytes() update bytes_may_use and then call the wakeup helper, and replace all calls to btrfs_space_info_add_new_bytes() with the wakeup helper. Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9118264 commit 18fa228

File tree

3 files changed

+20
-58
lines changed

3 files changed

+20
-58
lines changed

fs/btrfs/extent-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,8 +2866,8 @@ static int unpin_extent_range(struct btrfs_fs_info *fs_info,
28662866
spin_unlock(&global_rsv->lock);
28672867
/* Add to any tickets we may have */
28682868
if (len)
2869-
btrfs_space_info_add_new_bytes(fs_info,
2870-
space_info, len);
2869+
btrfs_try_granting_tickets(fs_info,
2870+
space_info);
28712871
}
28722872
spin_unlock(&space_info->lock);
28732873
}

fs/btrfs/space-info.c

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags,
131131
found->bytes_readonly += bytes_readonly;
132132
if (total_bytes > 0)
133133
found->full = 0;
134-
btrfs_space_info_add_new_bytes(info, found,
135-
total_bytes - bytes_used -
136-
bytes_readonly);
134+
btrfs_try_granting_tickets(info, found);
137135
spin_unlock(&found->lock);
138136
*space_info = found;
139137
}
@@ -229,17 +227,15 @@ static int can_overcommit(struct btrfs_fs_info *fs_info,
229227
* This is for space we already have accounted in space_info->bytes_may_use, so
230228
* basically when we're returning space from block_rsv's.
231229
*/
232-
void btrfs_space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
233-
struct btrfs_space_info *space_info,
234-
u64 num_bytes)
230+
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
231+
struct btrfs_space_info *space_info)
235232
{
236233
struct list_head *head;
237234
enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_NO_FLUSH;
238235

239-
spin_lock(&space_info->lock);
240-
head = &space_info->priority_tickets;
241-
btrfs_space_info_update_bytes_may_use(fs_info, space_info, -num_bytes);
236+
lockdep_assert_held(&space_info->lock);
242237

238+
head = &space_info->priority_tickets;
243239
again:
244240
while (!list_empty(head)) {
245241
struct reserve_ticket *ticket;
@@ -268,47 +264,6 @@ void btrfs_space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
268264
flush = BTRFS_RESERVE_FLUSH_ALL;
269265
goto again;
270266
}
271-
spin_unlock(&space_info->lock);
272-
}
273-
274-
/*
275-
* This is for newly allocated space that isn't accounted in
276-
* space_info->bytes_may_use yet. So if we allocate a chunk or unpin an extent
277-
* we use this helper.
278-
*/
279-
void btrfs_space_info_add_new_bytes(struct btrfs_fs_info *fs_info,
280-
struct btrfs_space_info *space_info,
281-
u64 num_bytes)
282-
{
283-
struct reserve_ticket *ticket;
284-
struct list_head *head = &space_info->priority_tickets;
285-
286-
again:
287-
while (!list_empty(head) && num_bytes) {
288-
ticket = list_first_entry(head, struct reserve_ticket,
289-
list);
290-
if (num_bytes >= ticket->bytes) {
291-
list_del_init(&ticket->list);
292-
num_bytes -= ticket->bytes;
293-
btrfs_space_info_update_bytes_may_use(fs_info,
294-
space_info,
295-
ticket->bytes);
296-
ticket->bytes = 0;
297-
space_info->tickets_id++;
298-
wake_up(&ticket->wait);
299-
} else {
300-
btrfs_space_info_update_bytes_may_use(fs_info,
301-
space_info,
302-
num_bytes);
303-
ticket->bytes -= num_bytes;
304-
num_bytes = 0;
305-
}
306-
}
307-
308-
if (num_bytes && head == &space_info->priority_tickets) {
309-
head = &space_info->tickets;
310-
goto again;
311-
}
312267
}
313268

314269
#define DUMP_BLOCK_RSV(fs_info, rsv_name) \

fs/btrfs/space-info.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ btrfs_space_info_update_##name(struct btrfs_fs_info *fs_info, \
110110
DECLARE_SPACE_INFO_UPDATE(bytes_may_use, "space_info");
111111
DECLARE_SPACE_INFO_UPDATE(bytes_pinned, "pinned");
112112

113-
void btrfs_space_info_add_new_bytes(struct btrfs_fs_info *fs_info,
114-
struct btrfs_space_info *space_info,
115-
u64 num_bytes);
116-
void btrfs_space_info_add_old_bytes(struct btrfs_fs_info *fs_info,
117-
struct btrfs_space_info *space_info,
118-
u64 num_bytes);
119113
int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
120114
void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags,
121115
u64 total_bytes, u64 bytes_used,
@@ -133,5 +127,18 @@ int btrfs_reserve_metadata_bytes(struct btrfs_root *root,
133127
struct btrfs_block_rsv *block_rsv,
134128
u64 orig_bytes,
135129
enum btrfs_reserve_flush_enum flush);
130+
void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
131+
struct btrfs_space_info *space_info);
132+
133+
static inline void btrfs_space_info_add_old_bytes(
134+
struct btrfs_fs_info *fs_info,
135+
struct btrfs_space_info *space_info,
136+
u64 num_bytes)
137+
{
138+
spin_lock(&space_info->lock);
139+
btrfs_space_info_update_bytes_may_use(fs_info, space_info, -num_bytes);
140+
btrfs_try_granting_tickets(fs_info, space_info);
141+
spin_unlock(&space_info->lock);
142+
}
136143

137144
#endif /* BTRFS_SPACE_INFO_H */

0 commit comments

Comments
 (0)