Skip to content

Commit db16180

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: account ticket size at add/delete time
Instead of iterating all pending tickets on the normal/priority list to sum their total size the cost can be amortized across ticket addition/ removal. This turns O(n) + O(m) (where n is the size of the normal list and m of the priority list) into O(1). This will mostly have effect in workloads that experience heavy flushing. Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f8e6608 commit db16180

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

fs/btrfs/space-info.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
389389
space_info,
390390
ticket->bytes);
391391
list_del_init(&ticket->list);
392+
ASSERT(space_info->reclaim_size >= ticket->bytes);
393+
space_info->reclaim_size -= ticket->bytes;
392394
ticket->bytes = 0;
393395
space_info->tickets_id++;
394396
wake_up(&ticket->wait);
@@ -784,16 +786,12 @@ static inline u64
784786
btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
785787
struct btrfs_space_info *space_info)
786788
{
787-
struct reserve_ticket *ticket;
788789
u64 used;
789790
u64 avail;
790791
u64 expected;
791-
u64 to_reclaim = 0;
792+
u64 to_reclaim = space_info->reclaim_size;
792793

793-
list_for_each_entry(ticket, &space_info->tickets, list)
794-
to_reclaim += ticket->bytes;
795-
list_for_each_entry(ticket, &space_info->priority_tickets, list)
796-
to_reclaim += ticket->bytes;
794+
lockdep_assert_held(&space_info->lock);
797795

798796
avail = calc_available_free_space(fs_info, space_info,
799797
BTRFS_RESERVE_FLUSH_ALL);
@@ -1192,8 +1190,10 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
11921190
* the list and we will do our own flushing further down.
11931191
*/
11941192
if (ret && flush != BTRFS_RESERVE_NO_FLUSH) {
1193+
ASSERT(space_info->reclaim_size >= 0);
11951194
ticket.bytes = orig_bytes;
11961195
ticket.error = 0;
1196+
space_info->reclaim_size += ticket.bytes;
11971197
init_waitqueue_head(&ticket.wait);
11981198
if (flush == BTRFS_RESERVE_FLUSH_ALL) {
11991199
list_add_tail(&ticket.list, &space_info->tickets);

fs/btrfs/space-info.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ struct btrfs_space_info {
5454
struct list_head ro_bgs;
5555
struct list_head priority_tickets;
5656
struct list_head tickets;
57+
58+
/*
59+
* Size of space that needs to be reclaimed in order to satisfy pending
60+
* tickets
61+
*/
62+
u64 reclaim_size;
63+
5764
/*
5865
* tickets_id just indicates the next ticket will be handled, so note
5966
* it's not stored per ticket.

0 commit comments

Comments
 (0)