Commit db161806 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

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: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent f8e66081
...@@ -389,6 +389,8 @@ void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info, ...@@ -389,6 +389,8 @@ void btrfs_try_granting_tickets(struct btrfs_fs_info *fs_info,
space_info, space_info,
ticket->bytes); ticket->bytes);
list_del_init(&ticket->list); list_del_init(&ticket->list);
ASSERT(space_info->reclaim_size >= ticket->bytes);
space_info->reclaim_size -= ticket->bytes;
ticket->bytes = 0; ticket->bytes = 0;
space_info->tickets_id++; space_info->tickets_id++;
wake_up(&ticket->wait); wake_up(&ticket->wait);
...@@ -784,16 +786,12 @@ static inline u64 ...@@ -784,16 +786,12 @@ static inline u64
btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info, btrfs_calc_reclaim_metadata_size(struct btrfs_fs_info *fs_info,
struct btrfs_space_info *space_info) struct btrfs_space_info *space_info)
{ {
struct reserve_ticket *ticket;
u64 used; u64 used;
u64 avail; u64 avail;
u64 expected; u64 expected;
u64 to_reclaim = 0; u64 to_reclaim = space_info->reclaim_size;
list_for_each_entry(ticket, &space_info->tickets, list) lockdep_assert_held(&space_info->lock);
to_reclaim += ticket->bytes;
list_for_each_entry(ticket, &space_info->priority_tickets, list)
to_reclaim += ticket->bytes;
avail = calc_available_free_space(fs_info, space_info, avail = calc_available_free_space(fs_info, space_info,
BTRFS_RESERVE_FLUSH_ALL); BTRFS_RESERVE_FLUSH_ALL);
...@@ -1192,8 +1190,10 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info, ...@@ -1192,8 +1190,10 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
* the list and we will do our own flushing further down. * the list and we will do our own flushing further down.
*/ */
if (ret && flush != BTRFS_RESERVE_NO_FLUSH) { if (ret && flush != BTRFS_RESERVE_NO_FLUSH) {
ASSERT(space_info->reclaim_size >= 0);
ticket.bytes = orig_bytes; ticket.bytes = orig_bytes;
ticket.error = 0; ticket.error = 0;
space_info->reclaim_size += ticket.bytes;
init_waitqueue_head(&ticket.wait); init_waitqueue_head(&ticket.wait);
if (flush == BTRFS_RESERVE_FLUSH_ALL) { if (flush == BTRFS_RESERVE_FLUSH_ALL) {
list_add_tail(&ticket.list, &space_info->tickets); list_add_tail(&ticket.list, &space_info->tickets);
......
...@@ -54,6 +54,13 @@ struct btrfs_space_info { ...@@ -54,6 +54,13 @@ struct btrfs_space_info {
struct list_head ro_bgs; struct list_head ro_bgs;
struct list_head priority_tickets; struct list_head priority_tickets;
struct list_head tickets; struct list_head tickets;
/*
* Size of space that needs to be reclaimed in order to satisfy pending
* tickets
*/
u64 reclaim_size;
/* /*
* tickets_id just indicates the next ticket will be handled, so note * tickets_id just indicates the next ticket will be handled, so note
* it's not stored per ticket. * it's not stored per ticket.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment