From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cn.fujitsu.com ([222.73.24.84]:20144 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932105AbcJLJKW (ORCPT ); Wed, 12 Oct 2016 05:10:22 -0400 From: Wang Xiaoguang To: linux-btrfs@vger.kernel.org Cc: jbacik@fb.com Subject: [PATCH 2/2] btrfs: try to satisfy metadata requests if wen can overcommit Date: Wed, 12 Oct 2016 17:03:49 +0800 Message-Id: <1476263029-11879-2-git-send-email-wangxg.fnst@cn.fujitsu.com> In-Reply-To: <1476263029-11879-1-git-send-email-wangxg.fnst@cn.fujitsu.com> References: <1476263029-11879-1-git-send-email-wangxg.fnst@cn.fujitsu.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org List-ID: In shrink_delalloc(), if can_overcommit() returns true, shrink_delalloc() will give up shrinking delalloc bytes, in this case we should check whether some tickcts' requests can overcommit, if some can, we can satisfy them timely and directly. Signed-off-by: Wang Xiaoguang --- fs/btrfs/extent-tree.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 661f039..c2e6871 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4971,6 +4971,47 @@ static void wake_all_tickets(struct list_head *head) } /* + * This function must be protected by btrfs_space_info's lock. + * In shrink_delalloc(), if can_overcommit() returns true, shrink_delalloc() + * will not shrink delalloc bytes any more, in this case we should check + * whether some tickcts' requests can overcommit, if some can, we can satisfy + * them timely and directly. + */ +static void try_to_wake_tickets(struct btrfs_root *root, + struct btrfs_space_info *space_info) +{ + struct reserve_ticket *ticket; + struct list_head *head = &space_info->priority_tickets; + enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_NO_FLUSH; + u64 used; + +again: + while (!list_empty(head)) { + ticket = list_first_entry(head, struct reserve_ticket, + list); + used = space_info->bytes_used + + space_info->bytes_reserved + space_info->bytes_pinned + + space_info->bytes_readonly + space_info->bytes_may_use; + + if (used + ticket->bytes <= space_info->total_bytes || + can_overcommit(root, space_info, ticket->bytes, flush)) { + space_info->bytes_may_use += ticket->bytes; + list_del_init(&ticket->list); + ticket->bytes = 0; + space_info->tickets_id++; + wake_up(&ticket->wait); + } else + return; + } + + if (head == &space_info->priority_tickets) { + head = &space_info->tickets; + flush = BTRFS_RESERVE_FLUSH_ALL; + goto again; + } +} + +/* * This is for normal flushers, we can wait all goddamned day if we want to. We * will loop and continuously try to flush as long as we are making progress. * We count progress as clearing off tickets each time we have to loop. @@ -5006,6 +5047,8 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) ret = flush_space(fs_info->fs_root, space_info, to_reclaim, flush_state, reclaim_priority); spin_lock(&space_info->lock); + if (!ret) + try_to_wake_tickets(fs_info->fs_root, space_info); if (list_empty(&space_info->tickets)) { space_info->flush = 0; spin_unlock(&space_info->lock); -- 2.7.4