From patchwork Wed Sep 21 06:59:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoguang Wang X-Patchwork-Id: 9342899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9546D607D0 for ; Wed, 21 Sep 2016 07:08:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 805F92A121 for ; Wed, 21 Sep 2016 07:08:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7517D2A12B; Wed, 21 Sep 2016 07:08:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57FC22A121 for ; Wed, 21 Sep 2016 07:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754174AbcIUHIp (ORCPT ); Wed, 21 Sep 2016 03:08:45 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:42287 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752852AbcIUHIp (ORCPT ); Wed, 21 Sep 2016 03:08:45 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="853824" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 21 Sep 2016 15:05:10 +0800 Received: from localhost.localdomain (unknown [10.167.226.107]) by cn.fujitsu.com (Postfix) with ESMTP id 5C99C4056432; Wed, 21 Sep 2016 15:05:07 +0800 (CST) From: Wang Xiaoguang To: linux-btrfs@vger.kernel.org Cc: jbacik@fb.com, dsterba@suse.cz Subject: [PATCH 1/2] btrfs: try to satisfy metadata requests when every flush_space() returns Date: Wed, 21 Sep 2016 14:59:32 +0800 Message-Id: <1474441173-31049-1-git-send-email-wangxg.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 5C99C4056432.A09A6 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wangxg.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In flush_space()->shrink_delalloc(), if can_overcommit() returns true, though no bytes added to space_info, we still may satisfy some requests. Signed-off-by: Wang Xiaoguang Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 38c2df8..fdfc97f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4960,6 +4960,43 @@ static void wake_all_tickets(struct list_head *head) } /* + * This function must be protected by btrfs_space_info's lock. + */ +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. @@ -4995,6 +5032,8 @@ static void btrfs_async_reclaim_metadata_space(struct work_struct *work) ret = flush_space(fs_info->fs_root, space_info, to_reclaim, to_reclaim, flush_state); 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);