From patchwork Fri May 27 17:24:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9138819 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 08B9460467 for ; Fri, 27 May 2016 17:24:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F10522822B for ; Fri, 27 May 2016 17:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E48F328285; Fri, 27 May 2016 17:24:26 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 4BCFA2822B for ; Fri, 27 May 2016 17:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756388AbcE0RYW (ORCPT ); Fri, 27 May 2016 13:24:22 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:25705 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756332AbcE0RYV (ORCPT ); Fri, 27 May 2016 13:24:21 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.11/8.16.0.11) with SMTP id u4RHLHbl024914 for ; Fri, 27 May 2016 10:24:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : subject : date : message-id : mime-version : content-type; s=facebook; bh=Fg6ORXOfRKNltdCaFO4NpuIiD7Iah5we4ooyz94OIhA=; b=jLbAEgj2x3iIFnuUikTlBCVkXD8zJqI7HVJuhaNijPX/A4eANfXTO2OzprSMbHWQF6J1 WhyZ+b0yCbiyG3UotoK7Jhaw7bpptFLrpz1gVIAj7u2AtJilGuB24DE8BMhIyhKRBK0b OXX8F8mq/9T+a9I1w3PZ+ik2NgyvLSFqOp8= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0089730.ppops.net with ESMTP id 236rfah47h-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 27 May 2016 10:24:20 -0700 Received: from na01-by2-obe.outbound.protection.outlook.com (192.168.183.28) by o365-in.thefacebook.com (192.168.177.29) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 27 May 2016 13:24:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=mfEVrmbbTH+JH7F9ukGVokSKyUxRSUzM57RuX8z5/74=; b=RZeGXEmOwqUI2fYGwQ4CG6m3fI/lQmHAH/hZ04HNQWm/9Aw7BQssmE1CcTFcnGWEGaM4yXIU2On1Vapx7Qb9bq4raGEzA5ZnldmqXcbrFRYzb7fCu2GuYqUUT/4Fev/SkzHGeFLTp+kbsLEB1FO4fmdQm3TekZe0V88p6FK/quc= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=fb.com; Received: from localhost (107.15.72.49) by DM3PR15MB0845.namprd15.prod.outlook.com (10.164.201.25) with Microsoft SMTP Server (TLS) id 15.1.501.7; Fri, 27 May 2016 17:24:16 +0000 From: Josef Bacik To: , Subject: [PATCH] Btrfs: use FLUSH_LIMIT for relocation in reserve_metadata_bytes Date: Fri, 27 May 2016 13:24:13 -0400 Message-ID: <1464369853-12614-1-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [107.15.72.49] X-ClientProxiedBy: SN1PR05CA0014.namprd05.prod.outlook.com (10.163.68.152) To DM3PR15MB0845.namprd15.prod.outlook.com (10.164.201.25) X-MS-Office365-Filtering-Correlation-Id: 4d0605bd-5ecf-489d-906f-08d38653bb1a X-Microsoft-Exchange-Diagnostics: 1; DM3PR15MB0845; 2:xp0a0PhUxhn4BHNMMhWTQShzjJyhemf3LU0pS52uPdE0lpRuS5oI5ki9bNlSb/zJ89iJmXr7mQMrbVYAnqWuBBXXD91ZAymAtWrcO814YDzqRWpXMXfdMURgX4JyR+OZ7O8JwxAW1+NhXVxwRR4/+oOHNdkzklqx5XsvqAMv67TiTEp7yMK7lI0539mKWoD1; 3:QzFiXNEcwvhVmVQ82ZI1WYnpY450yRrpYjauGX1jAFh94ZBmmyBfTWfFGa2osFKLBFQtagxbDFA6D1CMgZONmJ/fTKjX6Jnea+ttzuLxET93X9jEKXA+OOasUFviNVOi X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM3PR15MB0845; X-Microsoft-Exchange-Diagnostics: 1; DM3PR15MB0845; 25:wOHR6jfOZAi+2B5kIonHCFW4dqEHE1gHx7san+VB+nhyWLHUmTGAc8kwm03SoWCxubuHyd0zqkyx+MgBQVEqrpYCFGnCsZ51mFKCcZ1nGV7mudfs6NRxs7YcfouUxqqx/RiFt0A2HEGp6qjP5hX69xVTW50Iw3mBLsuTgvKm/3sA4LaQVrd2NHHCFiIT0hovBieSv59H7j6t+3/89Jyv1iQH8s6Ohs7RKCmJGClw4XAMD7gqn2dgaeCZtnMwgjjGEHdmYtsmKu0/Wab8EzUETX48w4XL0sPOASxoSaQIpcsQADSaTUIb8Vm9F0QBaq9KvwrGPZ6aL4mN/dR/Fie9Oh/9u34hbrfcbAwaUkOXqObv8ioD4FtZsfsaafVCM99HfHwrALwCHXoG5Uk5kXptCvU2mAYtpfKAJPNGOu2NSUe1/33fDJFrew/iB/SOvhZjI6aRsFdtx/wZ5JEnxsIQJaBREwI/exZPTdprueYDFYWvqyTFCvPeTbgc6utYHHWlhcS0JAl9papJysW0GJqRSsL3J8aEQ/hVEliNXQpbgnAalZ1nonsdmMcp4hokiRZ7ktx59V1I0yfnX3n32ADl8sQuYnaiGJ2vQBVOV/ef86GcxTJK9gNiJMTK8pgMqKOhcSS+OHgyl35rZsTOGXI79u5GPMe3spPhkhsP2XnYG5CzRsCkhnuXps4GNb7OwdMNdfR+Gfr+R+4+Jn9/H0p7FxwPaWj3y1qJUlfOX2USDkIAQJ/eSr1bu25Fgi+2gEz7; 20:3L75426MZwT44RYSd4WTQsHjO/97VKDSnvjIZYrKuJSYEoww+7cHak4n+8fJzhbI+casP8gUmMmyNYpHxND5cXkanNXpnuNlifmWH3TbeL0RRiaY3zJydq0qsvCun5ZnrxbAf0GzgOtqA2iy8O8BJo/chicgffhkqZ1qd qUOnck= X-LD-Processed: 8ae927fe-1255-47a7-a2af-5f3a069daaa2,ExtAddr X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001); SRVR:DM3PR15MB0845; BCL:0; PCL:0; RULEID:; SRVR:DM3PR15MB0845; X-Microsoft-Exchange-Diagnostics: 1; DM3PR15MB0845; 4:IVdSxVt3TdpAWmLeIFcjIJAd/fYmbzhCKsxI9Wp2UlJeVPaM2QKzAiIh7lOJK1ol0Mx394kM4Dh5/Z2Q1f0Tn5PwtZzR2UuwpE4qvCc/UNMj2rB9ORMB9eGsfcFX8COorHmgSb9vc13FRhB2cAepapN/gnhNAmghYcCF7cRkiupfaTyZwoa0UKrHsyk9kGEq04/BxJCm5OTEmfEVyG0bPYaUrqVeQj9rnhsU0hd0Ff39couNaiiQc7ttfkh5+4KjkmC6M3bOo2T+1Qvqo//llt8+OyR2fn9+1Qbxkh5W8i7P8AULYppYheql9+h3hWOJa6yyT831Av0ZQ6uoydaMsvB5lta+hSuONYFVYRbsqYKHsoVPBOiXk0pQR/AcikiT6TfQcdj5xy19qgS6YU38pPGPfOSejIQF68wlKSbUjTA= X-Forefront-PRVS: 09555FB1AD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(5004730100002)(6116002)(50226002)(47776003)(81166006)(66066001)(450100001)(8676002)(48376002)(107886002)(189998001)(86362001)(50466002)(50986999)(42186005)(3846002)(2906002)(36756003)(5008740100001)(551934003)(76506005)(33646002)(586003)(19580405001)(77096005)(5001770100001)(92566002)(19580395003)(5003940100001)(229853001)(4720700001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM3PR15MB0845; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; DM3PR15MB0845; 23:1WX0y/NwwSSkvR+JApx8mwIezIpxZlSy5p8hGbFCCsY/dceeD1bUbvxfWyXR26N+MlHLdtbSISG8+SKihUd6HPNz2oXxUI3/vofCLdHyAaP88ZYBslbdTzBpB89CNM22fRONGaqQ5hFplxxPcbJBbRi6q5Scv4oEuKOX8FimK6UNEDYDMqPMYA90R+q2nDzLuS+jn9sDjErL7bUtXbZao0qrRl3Y5P19dmHLz5o+Q3HL87kxlRdLuAy1QiVtzFV/ThyoNehatAEveExolYad84BWhbeRnLimJX+Pb68E9W36HrRlk06IrItMb3ewFRgptOex3dw98KPXTRcwGcLDcmGzev2KuzZgrLGQ5JPfupR/+BYLe7a0ua6NiYqo3RDeOmOb4Me/lrgt7UkUEo/0heCOJfRHyJ9FOtbGUqfckUD5FBZ2DoaCR5gVcDCVvAHYu9aVLRA0x5ibjNX7s259+uUF+JF4sZCo3K+lClhKDOAR5hOhhG9s+3gEZ3KVdu3a7UakMKAjW30lx5PZmjQCbEFeKTEa0a/K1grNHJOEq7y89VEs/dvyZIxW4htYOtFzMjBAkUMGCK6Jq4me3WaNOBvH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: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2016 17:24:16.7140 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR15MB0845 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-05-27_10:, , signatures=0 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 We used to allow you to set FLUSH_ALL and then just wouldn't do things like commit transactions or wait on ordered extents if we noticed you were in a transaction. However now that all the flushing for FLUSH_ALL is asynchronous we've lost the ability to tell, and we could end up deadlocking. So instead use FLUSH_LIMIT in reserve_metadata_bytes in relocation and then return -EAGAIN if we error out to preserve the previous behavior. I've also added an ASSERT() to catch anybody else who tries to do this. Thanks, Signed-off-by: Josef Bacik --- fs/btrfs/extent-tree.c | 2 ++ fs/btrfs/relocation.c | 37 ++++++++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 528b9a8..651a811 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -5070,6 +5070,8 @@ static int __reserve_metadata_bytes(struct btrfs_root *root, int ret = 0; ASSERT(orig_bytes); + ASSERT(!current->journal_info || flush != BTRFS_RESERVE_FLUSH_ALL); + spin_lock(&space_info->lock); ret = -ENOSPC; used = space_info->bytes_used + space_info->bytes_reserved + diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 959cb4e..ca145fc 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2603,25 +2603,28 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans, trans->block_rsv = rc->block_rsv; rc->reserved_bytes += num_bytes; + + /* + * We are under a transaction here so we can only do limited flushing. + * If we get an enospc just kick back -EAGAIN so we know to drop the + * transaction and try to refill when we can flush all the things. + */ ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes, - BTRFS_RESERVE_FLUSH_ALL); + BTRFS_RESERVE_FLUSH_LIMIT); if (ret) { - if (ret == -EAGAIN) { - tmp = rc->extent_root->nodesize * - RELOCATION_RESERVED_NODES; - while (tmp <= rc->reserved_bytes) - tmp <<= 1; - /* - * only one thread can access block_rsv at this point, - * so we don't need hold lock to protect block_rsv. - * we expand more reservation size here to allow enough - * space for relocation and we will return eailer in - * enospc case. - */ - rc->block_rsv->size = tmp + rc->extent_root->nodesize * - RELOCATION_RESERVED_NODES; - } - return ret; + tmp = rc->extent_root->nodesize * RELOCATION_RESERVED_NODES; + while (tmp <= rc->reserved_bytes) + tmp <<= 1; + /* + * only one thread can access block_rsv at this point, + * so we don't need hold lock to protect block_rsv. + * we expand more reservation size here to allow enough + * space for relocation and we will return eailer in + * enospc case. + */ + rc->block_rsv->size = tmp + rc->extent_root->nodesize * + RELOCATION_RESERVED_NODES; + return -EAGAIN; } return 0;