From patchwork Tue Feb 25 03:56:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 029181871 for ; Tue, 25 Feb 2020 03:56:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6CD424653 for ; Tue, 25 Feb 2020 03:56:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Vs/b5fqO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728938AbgBYD45 (ORCPT ); Mon, 24 Feb 2020 22:56:57 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728869AbgBYD44 (ORCPT ); Mon, 24 Feb 2020 22:56:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603016; x=1614139016; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tNwvHai4fsiAk8JlvX2+ZibtWTJAuRpY2joJ7KuILW4=; b=Vs/b5fqOOMi3rp85JAM1xtlkBZozqsSDNoXFVcbogE1HQNsrqHpU/4eS zxMfLfbIXYMrbzPJ/ElbEZdVOsbyAhH4N3smWeqhwwEEOJo/86Z9JByPM egsNTh0MGsYYZkk9GSGsoHXVTQSxJ1aaXv7or/+4ZAqlhhibmfXEMp1rj 1QEuVREzDEddCUhOy0uG/K+bSvPKwBbVSfg84wB4nBe3OYSxvBWy9HbN6 +l1f9NS/TDltONPG57n0P6JjJwjn+IxkUfSG/cob+E8aWL8EW5yWd7kTF mH9L2hSBHpXhPvFd/mVyEpbV5Q6/Yy9pF/G2hu9MJhm7Kl35tEu8zKAJ8 g==; IronPort-SDR: Kpr64vxqqZxbgM8hZrDhvpDEpcEHy9yulp8P+EMfOiWpR6F6+oRZR2qEq96lNclULsOHbgaC5j zsIkfHUBOoopj1e5NYn/UzgbaU89geG32L9lRMMbVBwWG2bNAMgYz98e7WbFyPfbF/Nq/tKrun vRWCkdwc5FWoA6DLrzRooQ6u6yGqrMep9nkDS75WJ12FHu3S3/O12FCjvcPcU5o1Y/xeo6pbKo qL/reD1nJ4jYDctJcCCN85gyR+gxG8URGE7M5rSd/Uk8dOCQ4/y7Y28xlp/PK58vTtOxx0SCCe o6A= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168259" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:56:56 +0800 IronPort-SDR: F41V5dl82bm+oeGSh6KNdNTaRIOKcuINR7zy/2LJpIca690+DYWay09T6RA8+g5ruRMoYskcgh 30BfKokjetPqBOmEkcnAbsB1EK3qvVIo9IryKW86QZP9pPycLnwaNcKb7tD1YdFBfRaDLjLNXU C1GJ1xr+wjlksozMmYdTG7FBy0gLTXsbGUcQ8VFwR88KZRFMc9vQqNTad9Veqi3i+///YCk7YL ByQCs6dH/2FzhLV7hPQ8bMk65PM7BlhiriTJAh9/Et2I6UjCl12NkJu1XYBqjH0wRaaKr9UMav 5eR9MwE4tUXzFOAqcMRdHegF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:24 -0800 IronPort-SDR: XZxoQOoFcLIc3CRw4SpqoBsRdof1+2QP8uG1Evt5LY3knLxfKUWItEM8wN7yOQp6zsWRrRccKW lNuYZDGkbevCYSkfNvIjtnTD27m+C6EE3V9oD+2aE4qsUt+BTXjm+GYcdIXjNXkeArDhWSKBXh h0GwiEfVWxH3EyLwzdEz8hPm7hBtKR/Q4vmK/ukaZktGAVmcLlj5IOHTH4PCyMxJwirmNG3/zB sjmqc7uisTBonUGprfDQ/O+Lu8mSnI5CIg8hZKvzAljx9HJLbhknYYRFH8Ud7hRortSbqd/GuQ N4w= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:56:56 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 01/21] btrfs: change type of full_search to bool Date: Tue, 25 Feb 2020 12:56:06 +0900 Message-Id: <20200225035626.1049501-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org While the "full_search" variable defined in find_free_extent() is bool, but the full_search argument of find_free_extent_update_loop() is defined as int. Let's trivially fix the argument type. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a7bc66121330..ed646a13956d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3672,7 +3672,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, struct btrfs_free_cluster *last_ptr, struct btrfs_key *ins, struct find_free_extent_ctl *ffe_ctl, - int full_search, bool use_cluster) + bool full_search, bool use_cluster) { struct btrfs_root *root = fs_info->extent_root; int ret; From patchwork Tue Feb 25 03:56:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402451 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60FC314B4 for ; Tue, 25 Feb 2020 03:57:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 40FCE24653 for ; Tue, 25 Feb 2020 03:57:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="oMU0EerB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728939AbgBYD5B (ORCPT ); Mon, 24 Feb 2020 22:57:01 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5B (ORCPT ); Mon, 24 Feb 2020 22:57:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603021; x=1614139021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rg1rLjmj+DSyV1SVu1U/M6KZj12YPQ6OF9qfNb6SDtM=; b=oMU0EerB14JYLTyyAhNm0zGfvo7hukuhxbGH/wEKqvdRmd5Z2FaHcAVn Qal4yG+ptknNV6z1uZdXe+xtd2/6u9rkpVRNZtj+XPW+/ME/jeQelL6iZ XWMm1oBzPANBU8P8uLxrPut7repHT4w+mnwc0Op8i4sXDgsDlpwFBJhiE cadBQLm44o+/KtDfs2S+J2W0d91Yx1ZsdeZ+MQN6lCTsSZu3hFU2yWouH xEQsciD2wz1A95QEgpTwVDCHuQfNVHytwuXkU9GGcclvbzbKF5jmwlVGe xINodi6AIXU2DHFR6Z8XF1RjMLPwi0rYFQCX9swiOP8mSXHbcDWTa/0is g==; IronPort-SDR: A3qeY6M9IA5XPc6kt1JVIw+YzV5UtZxjxcg1MFNFw39YiM1im5aUEQYCIgexR9aNYPbw6E6KqN thI+mOb9mD+uir65eUaNrCs2YHpsAV5tu4KztJ/nCO52tD+6Zj7806I/wy1F+9gATLupJK4vPd 2gCXKe37fkrxvjkm9mbqx4dI9nPIvvhl1nThuuIGadyrdM+m4eJPP8MeZhObP8ii/UcKGANjEF XltaYTQN3SFlqhhh4kNHa0idhS7gvzzRLSzjj1Ty5HIWnDwFelYucJ3au2kS84jQxYrZBZaQfK uhY= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168264" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:56:57 +0800 IronPort-SDR: 9yN0LgqKVjgFIVd5TrCvlJnI2RahBBBA59Rz9HKsfNg4NcV5Rbkv3ydkyrxnI3uVc1n+GXRC6j 5FBhAbzlyZtuproAHerADGodQet8gDUmKMPDLu+abIw27GRJajc1avWwaOE6wlH7i4BIV9nULV wOiCQNvFqDdp5rYfY3DKS41aYYRB7Ilvlmz5kKKX3XeNP0UMLbtB+68BL0JKbRt3rAonTOJ+S1 PXguTmYxWMGdzk4+mhJeWt8t4HWydHn2lBfmMhvkj3O8SLCO5PkmUTxGZPPh1lnQjWYVruQxUa I5d7amYlg9G94ZQwB4E1mJCw Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:25 -0800 IronPort-SDR: RbAFj17KKMxpUxwPaY1ANu5+QSdjXY7PnKhogQQBqIzY3jOSOdmERiHxq18nm47PAuaIVZxL6t ajuuQEPdfbJyb7N8gRRq50zMsv+M0c3QgkAMU2D1D5AQeWOEtR92SUz3pw/XiHqUQg4YZgO56+ XpfaQmpV0+E0q8GW84OoLzt6NrPPFkzsnlFAIRqAtAq+6xOhcbYEK0bm69xnlic+hHdGyknKMs bIvK5mJzuPMWSHLEXst9+4eTN4LY7enIbs+Z6S/uSrWRNSNCg0EA19yT1NJr0hzLI4zMi6zjnH lv8= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:56:57 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn , Johannes Thumshirn Subject: [PATCH v3 02/21] btrfs: do not BUG_ON with invalid profile Date: Tue, 25 Feb 2020 12:56:07 +0900 Message-Id: <20200225035626.1049501-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Do not BUG_ON() when an invalid profile is passed to __btrfs_alloc_chunk(). Instead return -EINVAL with ASSERT() to catch a bug in the development stage. Suggested-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9cfc668f91f4..911c6b7c650b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4809,7 +4809,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int j; int index; - BUG_ON(!alloc_profile_is_valid(type, 0)); + if (!alloc_profile_is_valid(type, 0)) { + ASSERT(0); + return -EINVAL; + } if (list_empty(&fs_devices->alloc_list)) { if (btrfs_test_opt(info, ENOSPC_DEBUG)) From patchwork Tue Feb 25 03:56:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E78514B4 for ; Tue, 25 Feb 2020 03:57:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E93024653 for ; Tue, 25 Feb 2020 03:57:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="C24u+x5u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728941AbgBYD5F (ORCPT ); Mon, 24 Feb 2020 22:57:05 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5F (ORCPT ); Mon, 24 Feb 2020 22:57:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603025; x=1614139025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oUGVNLNv/Xw1+4E0FweGNhJuWYzoIgjs7aWOG25iDyo=; b=C24u+x5ujizJutypIotzv6Pw9baaVyN0KKAPhqe7t608jZpL5ZLsT1Tk AKFz7iMKQetm/y+lRYfXdIL+ZaswkRYUoXsrumZPkCgiOTUEKqKi3Ul8W G6dbD4AIgGvlLX8h77RXu+yr3zAoaoB+IgAAyO1i/GmHNwqpkuXWigbqL 94gDljjdH1WmpkfhjOgqSKHVA6VvCgYd0heQyxTKuVJ+rOGefCbB0OvQX eX41XoHj1t/FW3ysUprlbFZ2dte84TRelv0bz/q1/Cmx+m/97gZS4bb3a oTqJVOHZTthsPnATdRL0ticafq83Wv7idD9w2u6Fw9ZunLviqRMwhBrD0 Q==; IronPort-SDR: +SiF8UWNWXNUy+0PH27sFWOPi0PFa9ap1VCwE0TwtTih1Z3xqP5fAMGjxK6zHmtKce9O327NTX 3C8ngYseMq/LBlHWiuyTUG1WGu0RNcMolYcRpqRedF3RRhfWiwkSAJm6qS270QtCH3mnjMR57t NTVKaSDLo04CzfySreHnbhFM7LozbYcmvF2Tu67ebeQSAGDlEJEodGvHeZsd3CY1x2N4PENWjL zak5W3z91ka1jRTiAWoTFQ9tuXaCOmci3/z/ie55ELGb2tWkunOk4dr89zL9Qb/h5fH0qB6PTt 7uI= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168270" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:56:59 +0800 IronPort-SDR: aXty77n9zTc4eca0Nj5sxe2B9m5eaDEXghoifpSwUkasHc/4waJSblTQf32fWmUn3FY/BulMG5 DrJqmmp1SKHmLEBg2v7f1CrkJg/TzexGr6QYej3pBhddsadez+pg/YemVdKwLfQ536TiaM5rwd C1Koi1O7Xx/G67/bChlcwUVhcXC5dXe+zPnnAVQacXZcD3eErxGnw0XUBSxLBo5Rsek1HWFXuY Rb7qQWsOqEtteT3fQ2FJobZt3KhEwSTwWHE1Zfx2N+BnTcVjzdlqcwq+XSIZ1VVZyIdmQSBZZy UaZ2s4DcXz5IMeBNUrVb9Mzo Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:27 -0800 IronPort-SDR: PDgzJIZcZldsS0B55yUMsUMnEuJEVi3tX3HNlwY6HwskILyxuoyVU8sGwVcR9gx062UgWMzX/3 OInz7ee8CXh5IzJkiVv2US1yPz8YGYqipWMeh+fgUR3Yuw0BQdmS9BFLkZrgPOP2oMx0Bc9fHC RCM3pQO72uIRdZSBV+FTFcQfOSQZA3aBx51Azllal1KKEKVjcHvTYOLAlFnOSKw3aRw9S1Xvdj fDYln1cZd3pTvOtHfOavEQZJIPd05GL7U53xNBAtr7vwBSGAHpx0FjvY8cym9WP1bCWmqQW8C2 97g= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:56:58 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 03/21] btrfs: introduce chunk allocation policy Date: Tue, 25 Feb 2020 12:56:08 +0900 Message-Id: <20200225035626.1049501-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This commit introduces chunk allocation policy for btrfs. This policy controls how btrfs allocate a chunk and device extents from devices. There is no functional change introduced with this commit. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 1 + fs/btrfs/volumes.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 911c6b7c650b..9fcbed9b57f9 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1209,6 +1209,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices, fs_devices->opened = 1; fs_devices->latest_bdev = latest_dev->bdev; fs_devices->total_rw_bytes = 0; + fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR; out: return ret; } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 309cda477589..6f462b337fce 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -209,6 +209,10 @@ BTRFS_DEVICE_GETSET_FUNCS(total_bytes); BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes); BTRFS_DEVICE_GETSET_FUNCS(bytes_used); +enum btrfs_chunk_allocation_policy { + BTRFS_CHUNK_ALLOC_REGULAR, +}; + struct btrfs_fs_devices { u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ u8 metadata_uuid[BTRFS_FSID_SIZE]; @@ -260,6 +264,8 @@ struct btrfs_fs_devices { struct kobject *devices_kobj; struct kobject *devinfo_kobj; struct completion kobj_unregister; + + enum btrfs_chunk_allocation_policy chunk_alloc_policy; }; #define BTRFS_BIO_INLINE_CSUM_SIZE 64 From patchwork Tue Feb 25 03:56:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402455 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26B2914B4 for ; Tue, 25 Feb 2020 03:57:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05FBA24650 for ; Tue, 25 Feb 2020 03:57:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="bvPi3JaR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728944AbgBYD5I (ORCPT ); Mon, 24 Feb 2020 22:57:08 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5I (ORCPT ); Mon, 24 Feb 2020 22:57:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603028; x=1614139028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p76b2Z9W1j9sNe0wGDijDSAPLjG4vHyi/VECMPT1Duc=; b=bvPi3JaR4gBNASKqSnC0KEUJhn3QUUIW8al41uWjy7qoj6y1RE+nt6J1 Tlh0ffhPZKfshN8NADQrtNb9bVFX6n+zASyAuZumCyp6k2lsaEfM7UGqr 3U3kKh06VW19NmpoVqKnSjPtg0Bx66tfjkDpUj+N+xPJL5ib++Y2r99sX 8Zx9GIs+P15OtubsrN6hNSpjhA3wF3qhuJNL79Y40141A2uPf1UWRdlMs NSmN4lt4CYfBZkx5fMPaNMlnSgcpqI23/koDe4zeOgmDF+GiGxhJZgVwT JNqkHQMMrAz0Lt/pfPufV0Z2cRCStm9g1zhMlCcf/Ywfoas9wIZbasNCa w==; IronPort-SDR: qKRdP/wVg66FC74EQzf+D+BJCJvmbjIJN5jf3fxCOy1NzzPg8vu5kVd2KteeScaNIAVQK87X/g 9f9OF5JSPG8qx28NWYyThdeJ5f/ZZWyh2hkVAJARWu4CBv/nob+b8XHudrsPOUdnrkN0K89Su7 l8zPYUdUQJH763rdj9gOmBBReoeTAU/+ieT48FDxIPh4SlTWAzUjzSbk0OmjHED24srKCuJW6r wvEUmh1oi5juyt3RhytqmDsrzrMJ6VlwRoK15fEku9INaJyI/cneQkobIbBur+0QadaAbUHVCR KNE= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168277" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:00 +0800 IronPort-SDR: P0iy3/Z6ZKKVTte6G8eNRqQkaJnjPXrCa3XbV9Tl9Fod8KgXetQYulS/gc6HW6qjTRm/BBtbPh tftw59/3ubWzA4NgBmGhm5nOeZr30XKuMzbj9hcVT6q/I7Wh8quoLBEcTctXywupwXgOsaOe4r EWbpUV/Zqsd2+pKbHRWKHfREqX5WjyAE1c1JvPrbfarTQHFDi8fiDE5gs9ywUSSILuwjlsvNHf rZSXP3Mpag9R0r3aNp8k/hj8J6gZyCDRP1bBFOf/JH0P+nNI52zOCaaC0fhRryoaqsFs4t+SCf nW3KnsMSXU22OfrwxqB2MI2g Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:28 -0800 IronPort-SDR: PyI20wHEXcTfzvowH0Gj/vPNtk93S4lcAUVnc/KJEASRA2TNJYxlW76h5/+hBIe4jMX2ZkRh0s MVoNUZo5hNapbHT1CVTQNBAFyxJ9AiQHgkSvfdhWsY06Ui4W7C4npvRYDo1p95eQSQu6tGE5zX q9nVJciZj8CKUQ0crqa1Cexe/QcTvMXohSm+xElpyuiKB3vQFEIGgw8wdo+3cHme65Zvtyj7EF Koxg06L0XuAiepVUNjDlhNxiBfX1/q0idjUEIqenKLM8ECsMG9TuQYhYQjqRcp0rko/dZwcMyP 1bA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:00 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 04/21] btrfs: refactor find_free_dev_extent_start() Date: Tue, 25 Feb 2020 12:56:09 +0900 Message-Id: <20200225035626.1049501-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out two functions from find_free_dev_extent_start(). dev_extent_search_start() decides the starting position of the search. dev_extent_hole_check() checks if a hole found is suitable for device extent allocation. These functions also have the switch-cases to change the allocation behavior depending on the policy. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 80 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9fcbed9b57f9..5f4e875a42f6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1384,6 +1384,61 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start, return false; } +static u64 dev_extent_search_start(struct btrfs_device *device, u64 start) +{ + switch (device->fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + /* + * We don't want to overwrite the superblock on the + * drive nor any area used by the boot loader (grub + * for example), so we make sure to start at an offset + * of at least 1MB. + */ + return max_t(u64, start, SZ_1M); + default: + BUG(); + } +} + +/** + * dev_extent_hole_check - check if specified hole is suitable for allocation + * @device: the device which we have the hole + * @hole_start: starting position of the hole + * @hole_size: the size of the hole + * @num_bytes: the size of the free space that we need + * + * This function may modify @hole_start and @hole_end to reflect the + * suitable position for allocation. Returns 1 if hole position is + * updated, 0 otherwise. + */ +static bool dev_extent_hole_check(struct btrfs_device *device, u64 *hole_start, + u64 *hole_size, u64 num_bytes) +{ + bool changed = false; + u64 hole_end = *hole_start + *hole_size; + + /* + * Have to check before we set max_hole_start, otherwise we + * could end up sending back this offset anyway. + */ + if (contains_pending_extent(device, hole_start, *hole_size)) { + if (hole_end >= *hole_start) + *hole_size = hole_end - *hole_start; + else + *hole_size = 0; + changed = true; + } + + switch (device->fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + /* No extra check */ + break; + default: + BUG(); + } + + return changed; +} /* * find_free_dev_extent_start - find free space in the specified device @@ -1430,12 +1485,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, int slot; struct extent_buffer *l; - /* - * We don't want to overwrite the superblock on the drive nor any area - * used by the boot loader (grub for example), so we make sure to start - * at an offset of at least 1MB. - */ - search_start = max_t(u64, search_start, SZ_1M); + search_start = dev_extent_search_start(device, search_start); path = btrfs_alloc_path(); if (!path) @@ -1493,18 +1543,8 @@ static int find_free_dev_extent_start(struct btrfs_device *device, if (key.offset > search_start) { hole_size = key.offset - search_start; - - /* - * Have to check before we set max_hole_start, otherwise - * we could end up sending back this offset anyway. - */ - if (contains_pending_extent(device, &search_start, - hole_size)) { - if (key.offset >= search_start) - hole_size = key.offset - search_start; - else - hole_size = 0; - } + dev_extent_hole_check(device, &search_start, &hole_size, + num_bytes); if (hole_size > max_hole_size) { max_hole_start = search_start; @@ -1543,8 +1583,8 @@ static int find_free_dev_extent_start(struct btrfs_device *device, */ if (search_end > search_start) { hole_size = search_end - search_start; - - if (contains_pending_extent(device, &search_start, hole_size)) { + if (dev_extent_hole_check(device, &search_start, &hole_size, + num_bytes)) { btrfs_release_path(path); goto again; } From patchwork Tue Feb 25 03:56:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F211871 for ; Tue, 25 Feb 2020 03:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BEB7A24653 for ; Tue, 25 Feb 2020 03:57:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="m3eD0V/I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728950AbgBYD5L (ORCPT ); Mon, 24 Feb 2020 22:57:11 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5K (ORCPT ); Mon, 24 Feb 2020 22:57:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603030; x=1614139030; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UXooGQ6m9FbDHNc2PR+2H55BH57wjrn1A6srh2NtkdA=; b=m3eD0V/IkleFin06Xu3kdobNh6AMNU80cUPf9KZeqMyOsdu38HGc28m4 FNnslVcwXMHWZpQc6neRQmVEYm5svzUNW/FZQtwkB0k5RVFwZmER7k9v8 Xxckff6cSZUHHacVn1JQFXq2GU426U1W3UeC7TI4n2xg+q9iIHypQ5iCA N2V/tEkq1Ifk/q88Pb0T3tcnTleV0ITYaMKHquKDpsnjjo9lig3RYQOXy 2p0NbxVevDWaDY7UUbzFGtuQBUstEPGIJyDhQCgRb+gSwpxSgGxePhN2Q VtXGgIjFYozACKTRH5m4ZqpIHRsIVWD2U+d0+H3m+VW51GCkTZhnPTvxj A==; IronPort-SDR: Y1Rv3pCzkYN5ZGX4163RWH41k5fwBm5g3P1IcZtx+wV+HbhH67dltqQ+zmVDFb5CerN8NZ+B7k NgX8Pyjw9OHNdIS7UlaFmwGc+D7sUZbpJuVOZ1oJw5m9IUYGt9JeLk47zmfBQblhUvTI0W25wo Jgllu4cOsQKn9DxY5Obv/7BN9fbNKPmcEw/JaH/Kp4pJm9NLPm772AUp8WzEE/kAMrN+v3XvRI SgplNvQk6Ws/UwgVl7jgmb1uOB1dLkIsjzHiTt9ym7KntjXqW5UaoXBTp4H2I0eXpxaDl76Drv yPs= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168278" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:01 +0800 IronPort-SDR: j2OlMM/NaZClB6ZcQt50LkjdpTO7ooGDJ8usTWGOLNPB2Ms3XdYE/ZmRutMCF8lXCkDvftPlLF 6kU8Rac2uKKLDl7OTL7vyWQR7uyIFi6u/lIubQG+qz4M85gbUQcvUF9c6+8cqmTIS4yWaiRuAH 7GsnDqCnXBSBOyr5wbVZd4n9Pfbch/ob1YsWVBJN+DJGCW6UkWha/L+nSBevD+Q+7orYxeIuQn nbwf3YPzREJ8OWAqFqB2Y0iVcjVl02XXv40dnsYfhtxaZNkrJGUPVEL94Qyrbe4ppVR3zdSXAz cTw3riOGHsvVxvqXdnrhPjw5 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:30 -0800 IronPort-SDR: a+28elkjtYJa04Y7IRuD4Nu2a6CL7VFLC/yLvyh+B3Yefdov1RFx9rqQi/y7ekp3CsW+t1RqOI vRsjp6vI1lVbI11XlqDITzKjHpDqIpOxNR5cd+JyCetKjH8AHW0PdyTLBezgXnaMIs3bYZE1n0 g2sP2ghxKBn5VKB8xaJbrfTkxXu75dsDdBZuG4GfRv/W4AguG9Ubucs4l9CwOzlhrYYqr0Hfd3 jvVbujTvJyd03GV4enTY9SUw19e8/x7pc4R0vcVk2nYz+tlXlLSwpXo34aK4xwqWbI7LSsITCA 2N8= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:01 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 05/21] btrfs: introduce alloc_chunk_ctl Date: Tue, 25 Feb 2020 12:56:10 +0900 Message-Id: <20200225035626.1049501-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce "struct alloc_chunk_ctl" to wrap needed parameters for the chunk allocation. This will be used to split __btrfs_alloc_chunk() into smaller functions. This commit folds a number of local variables in __btrfs_alloc_chunk() into one "struct alloc_chunk_ctl ctl". There is no functional change. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 151 ++++++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 65 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 5f4e875a42f6..ed90e9d2bd9b 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4818,6 +4818,29 @@ static void check_raid1c34_incompat_flag(struct btrfs_fs_info *info, u64 type) btrfs_set_fs_incompat(info, RAID1C34); } +/* + * Structure used internally for __btrfs_alloc_chunk() function. + * Wraps needed parameters. + */ +struct alloc_chunk_ctl { + u64 start; + u64 type; + int num_stripes; /* total number of stripes to allocate */ + int sub_stripes; /* sub_stripes info for map */ + int dev_stripes; /* stripes per dev */ + int devs_max; /* max devs to use */ + int devs_min; /* min devs needed */ + int devs_increment; /* ndevs has to be a multiple of this */ + int ncopies; /* how many copies to data has */ + int nparity; /* number of stripes worth of bytes to + store parity information */ + u64 max_stripe_size; + u64 max_chunk_size; + u64 stripe_size; + u64 chunk_size; + int ndevs; +}; + static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 start, u64 type) { @@ -4828,23 +4851,11 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct extent_map_tree *em_tree; struct extent_map *em; struct btrfs_device_info *devices_info = NULL; + struct alloc_chunk_ctl ctl; u64 total_avail; - int num_stripes; /* total number of stripes to allocate */ int data_stripes; /* number of stripes that count for block group size */ - int sub_stripes; /* sub_stripes info for map */ - int dev_stripes; /* stripes per dev */ - int devs_max; /* max devs to use */ - int devs_min; /* min devs needed */ - int devs_increment; /* ndevs has to be a multiple of this */ - int ncopies; /* how many copies to data has */ - int nparity; /* number of stripes worth of bytes to - store parity information */ int ret; - u64 max_stripe_size; - u64 max_chunk_size; - u64 stripe_size; - u64 chunk_size; int ndevs; int i; int j; @@ -4861,32 +4872,36 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } + ctl.start = start; + ctl.type = type; + index = btrfs_bg_flags_to_raid_index(type); - sub_stripes = btrfs_raid_array[index].sub_stripes; - dev_stripes = btrfs_raid_array[index].dev_stripes; - devs_max = btrfs_raid_array[index].devs_max; - if (!devs_max) - devs_max = BTRFS_MAX_DEVS(info); - devs_min = btrfs_raid_array[index].devs_min; - devs_increment = btrfs_raid_array[index].devs_increment; - ncopies = btrfs_raid_array[index].ncopies; - nparity = btrfs_raid_array[index].nparity; + ctl.sub_stripes = btrfs_raid_array[index].sub_stripes; + ctl.dev_stripes = btrfs_raid_array[index].dev_stripes; + ctl.devs_max = btrfs_raid_array[index].devs_max; + if (!ctl.devs_max) + ctl.devs_max = BTRFS_MAX_DEVS(info); + ctl.devs_min = btrfs_raid_array[index].devs_min; + ctl.devs_increment = btrfs_raid_array[index].devs_increment; + ctl.ncopies = btrfs_raid_array[index].ncopies; + ctl.nparity = btrfs_raid_array[index].nparity; if (type & BTRFS_BLOCK_GROUP_DATA) { - max_stripe_size = SZ_1G; - max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; + ctl.max_stripe_size = SZ_1G; + ctl.max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; } else if (type & BTRFS_BLOCK_GROUP_METADATA) { /* for larger filesystems, use larger metadata chunks */ if (fs_devices->total_rw_bytes > 50ULL * SZ_1G) - max_stripe_size = SZ_1G; + ctl.max_stripe_size = SZ_1G; else - max_stripe_size = SZ_256M; - max_chunk_size = max_stripe_size; + ctl.max_stripe_size = SZ_256M; + ctl.max_chunk_size = ctl.max_stripe_size; } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { - max_stripe_size = SZ_32M; - max_chunk_size = 2 * max_stripe_size; - devs_max = min_t(int, devs_max, BTRFS_MAX_DEVS_SYS_CHUNK); + ctl.max_stripe_size = SZ_32M; + ctl.max_chunk_size = 2 * ctl.max_stripe_size; + ctl.devs_max = min_t(int, ctl.devs_max, + BTRFS_MAX_DEVS_SYS_CHUNK); } else { btrfs_err(info, "invalid chunk type 0x%llx requested", type); @@ -4894,8 +4909,8 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } /* We don't want a chunk larger than 10% of writable space */ - max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), - max_chunk_size); + ctl.max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), + ctl.max_chunk_size); devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), GFP_NOFS); @@ -4931,21 +4946,21 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (total_avail == 0) continue; - ret = find_free_dev_extent(device, - max_stripe_size * dev_stripes, - &dev_offset, &max_avail); + ret = find_free_dev_extent( + device, ctl.max_stripe_size * ctl.dev_stripes, + &dev_offset, &max_avail); if (ret && ret != -ENOSPC) goto error; if (ret == 0) - max_avail = max_stripe_size * dev_stripes; + max_avail = ctl.max_stripe_size * ctl.dev_stripes; - if (max_avail < BTRFS_STRIPE_LEN * dev_stripes) { + if (max_avail < BTRFS_STRIPE_LEN * ctl.dev_stripes) { if (btrfs_test_opt(info, ENOSPC_DEBUG)) btrfs_debug(info, "%s: devid %llu has no free space, have=%llu want=%u", __func__, device->devid, max_avail, - BTRFS_STRIPE_LEN * dev_stripes); + BTRFS_STRIPE_LEN * ctl.dev_stripes); continue; } @@ -4960,30 +4975,31 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, devices_info[ndevs].dev = device; ++ndevs; } + ctl.ndevs = ndevs; /* * now sort the devices by hole size / available space */ - sort(devices_info, ndevs, sizeof(struct btrfs_device_info), + sort(devices_info, ctl.ndevs, sizeof(struct btrfs_device_info), btrfs_cmp_device_info, NULL); /* * Round down to number of usable stripes, devs_increment can be any * number so we can't use round_down() */ - ndevs -= ndevs % devs_increment; + ctl.ndevs -= ctl.ndevs % ctl.devs_increment; - if (ndevs < devs_min) { + if (ctl.ndevs < ctl.devs_min) { ret = -ENOSPC; if (btrfs_test_opt(info, ENOSPC_DEBUG)) { btrfs_debug(info, "%s: not enough devices with free space: have=%d minimum required=%d", - __func__, ndevs, devs_min); + __func__, ctl.ndevs, ctl.devs_min); } goto error; } - ndevs = min(ndevs, devs_max); + ctl.ndevs = min(ctl.ndevs, ctl.devs_max); /* * The primary goal is to maximize the number of stripes, so use as @@ -4992,14 +5008,15 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, * The DUP profile stores more than one stripe per device, the * max_avail is the total size so we have to adjust. */ - stripe_size = div_u64(devices_info[ndevs - 1].max_avail, dev_stripes); - num_stripes = ndevs * dev_stripes; + ctl.stripe_size = div_u64(devices_info[ctl.ndevs - 1].max_avail, + ctl.dev_stripes); + ctl.num_stripes = ctl.ndevs * ctl.dev_stripes; /* * this will have to be fixed for RAID1 and RAID10 over * more drives */ - data_stripes = (num_stripes - nparity) / ncopies; + data_stripes = (ctl.num_stripes - ctl.nparity) / ctl.ncopies; /* * Use the number of data stripes to figure out how big this chunk @@ -5007,44 +5024,46 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, * and compare that answer with the max chunk size. If it's higher, * we try to reduce stripe_size. */ - if (stripe_size * data_stripes > max_chunk_size) { + if (ctl.stripe_size * data_stripes > ctl.max_chunk_size) { /* * Reduce stripe_size, round it up to a 16MB boundary again and * then use it, unless it ends up being even bigger than the * previous value we had already. */ - stripe_size = min(round_up(div_u64(max_chunk_size, - data_stripes), SZ_16M), - stripe_size); + ctl.stripe_size = + min(round_up(div_u64(ctl.max_chunk_size, data_stripes), + SZ_16M), + ctl.stripe_size); } /* align to BTRFS_STRIPE_LEN */ - stripe_size = round_down(stripe_size, BTRFS_STRIPE_LEN); + ctl.stripe_size = round_down(ctl.stripe_size, BTRFS_STRIPE_LEN); - map = kmalloc(map_lookup_size(num_stripes), GFP_NOFS); + map = kmalloc(map_lookup_size(ctl.num_stripes), GFP_NOFS); if (!map) { ret = -ENOMEM; goto error; } - map->num_stripes = num_stripes; - for (i = 0; i < ndevs; ++i) { - for (j = 0; j < dev_stripes; ++j) { - int s = i * dev_stripes + j; + map->num_stripes = ctl.num_stripes; + + for (i = 0; i < ctl.ndevs; ++i) { + for (j = 0; j < ctl.dev_stripes; ++j) { + int s = i * ctl.dev_stripes + j; map->stripes[s].dev = devices_info[i].dev; map->stripes[s].physical = devices_info[i].dev_offset + - j * stripe_size; + j * ctl.stripe_size; } } map->stripe_len = BTRFS_STRIPE_LEN; map->io_align = BTRFS_STRIPE_LEN; map->io_width = BTRFS_STRIPE_LEN; map->type = type; - map->sub_stripes = sub_stripes; + map->sub_stripes = ctl.sub_stripes; - chunk_size = stripe_size * data_stripes; + ctl.chunk_size = ctl.stripe_size * data_stripes; - trace_btrfs_chunk_alloc(info, map, start, chunk_size); + trace_btrfs_chunk_alloc(info, map, start, ctl.chunk_size); em = alloc_extent_map(); if (!em) { @@ -5055,10 +5074,10 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags); em->map_lookup = map; em->start = start; - em->len = chunk_size; + em->len = ctl.chunk_size; em->block_start = 0; em->block_len = em->len; - em->orig_block_len = stripe_size; + em->orig_block_len = ctl.stripe_size; em_tree = &info->mapping_tree; write_lock(&em_tree->lock); @@ -5070,20 +5089,22 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } write_unlock(&em_tree->lock); - ret = btrfs_make_block_group(trans, 0, type, start, chunk_size); + ret = btrfs_make_block_group(trans, 0, type, start, ctl.chunk_size); if (ret) goto error_del_extent; for (i = 0; i < map->num_stripes; i++) { struct btrfs_device *dev = map->stripes[i].dev; - btrfs_device_set_bytes_used(dev, dev->bytes_used + stripe_size); + btrfs_device_set_bytes_used(dev, + dev->bytes_used + ctl.stripe_size); if (list_empty(&dev->post_commit_list)) list_add_tail(&dev->post_commit_list, &trans->transaction->dev_update_list); } - atomic64_sub(stripe_size * map->num_stripes, &info->free_chunk_space); + atomic64_sub(ctl.stripe_size * map->num_stripes, + &info->free_chunk_space); free_extent_map(em); check_raid56_incompat_flag(info, type); From patchwork Tue Feb 25 03:56:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C17013A4 for ; Tue, 25 Feb 2020 03:57:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EFBA624653 for ; Tue, 25 Feb 2020 03:57:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="EQaIsfhb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728956AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603031; x=1614139031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PRhYCqlHGa1Ffrr0vuTgOoIhkWEOWH9/AqOyghGgX5w=; b=EQaIsfhbDtzdrbaxmms7dLDsBdlgo6aZMMg/16+QWXfP7Wh/HTKZH9Zm 46lmKkf6f+NGqhuMhNcm15LjpxtH+M1/XFv+P/MwvqjAiq83FSWGco/Z1 dARz/XUEVPuuxPz2cthaQBJyH0ljRkkc62ew7uXtMKkxtPBcW4NpyMpPp sgqg0kj2zFE3l/1TBb5ic6dQiRg0NBKZrjZYbG3WW4W3CP6FwqQ/xIcmH Dn+1fKT7XPi0lp5FEfLuBh22SaeTGPKy9DMSgt3zyY0K6YhQMW/0E9fkP Uu0M0bvyPOOw08mc+F9/RAd3At1H0p6HgWsR6+Q4LB9gXuyeRhfXtX0co g==; IronPort-SDR: 1PqLTxwRFgMN/ky2xKdK34coMWwCGS0Qv3w/QUFamsQSzFaYQmNyOoYuZ9QrcMGpRaC7GX1kwJ BzUfIBAAtZfvbEZ7HAgnOI9w1rD+WSEmkgaZOh3mS1Rp0fPEJldGHstxjRrRdO/YR8+MAz3Krb BKbR+myhh29/zQ5QqoXk1NyNACzg4npJMj5oWd89YFS0R6ojbPz179Uu/8zpLfBsLUK/TbF8Gu rsTvtQ4oZ5of+2LBJ2KCv9Ibw9gP+zgGIgXiIzOqnPxIGE1+LKPCeDTONgrrV1iRwuIkZYyZr1 7kw= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168281" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:03 +0800 IronPort-SDR: Zmow8N0wJC2Hb9HwSYxembgmCr0iBT0N4W1iZAjAzm3eGoOdH1h+K2uyAFF3C9FBumRRN13ZAo OiGwEJIrER0EEJJZOxOX2RfhZKOIAdaXUx/m0LS1wEicGqVfFjTKmq8r/ZUpPYLkFnBmFFagH1 IwHtTyskD0XCc31YevZTyPOMDOlKxRugpjs9gOfVoFs0lXP15g+XDEnGpsSoP0OhLpc/FH6hgX glOXJtWL4OtzErVcyvMKDcWPt5a5mEDJ+cjrutuygUILwRLhHBtLKHPbOIBWf/djT0289RyEaQ cyKgJnppmxJsCVG1dPPS6dWA Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:31 -0800 IronPort-SDR: UqPuoLznLTU6UIAcY3Kg9wTz25xAnNO2+UnfXTT+Q3dmJzKfBiAujhnIFUHwWfjgVgdV0tOTV7 0Et6yBy5CbaqMss5m79+8oXnhQPxrVH4PUnKSKzC5mua2dIvPz/HXr1yaMw88QTrJFMUuKB+rB edpH44rYG6YiNh1yoqtQQ1tZUdDzvVCyqXFdt8Dg/C1qCeLPVKtDJ2QZqZG9kNOhcEdqCbRYDs CpuNFlQTyXmUKzbVPsmUNGm7wL/4+g2ltmUA4mpwjrlKUXvaYi5LWdB+fl7EWY2XHrvM2vx8XC aRU= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:02 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 06/21] btrfs: factor out init_alloc_chunk_ctl Date: Tue, 25 Feb 2020 12:56:11 +0900 Message-Id: <20200225035626.1049501-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out init_alloc_chunk_ctl() from __btrfs_alloc_chunk(). This function initialises parameters of "struct alloc_chunk_ctl" for allocation. init_alloc_chunk_ctl() handles a common part of the initialisation to load the RAID parameters from btrfs_raid_array. init_alloc_chunk_ctl_policy_regular() decides some parameters for its allocation. The last "else" case in the original code is moved to __btrfs_alloc_chunk() to handle the error case in the common code. Replace the BUG_ON with ASSERT() and error return at the same time. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 100 ++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ed90e9d2bd9b..b15c2bb6f913 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4841,6 +4841,61 @@ struct alloc_chunk_ctl { int ndevs; }; +static void +init_alloc_chunk_ctl_policy_regular(struct btrfs_fs_devices *fs_devices, + struct alloc_chunk_ctl *ctl) +{ + u64 type = ctl->type; + + if (type & BTRFS_BLOCK_GROUP_DATA) { + ctl->max_stripe_size = SZ_1G; + ctl->max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; + } else if (type & BTRFS_BLOCK_GROUP_METADATA) { + /* for larger filesystems, use larger metadata chunks */ + if (fs_devices->total_rw_bytes > 50ULL * SZ_1G) + ctl->max_stripe_size = SZ_1G; + else + ctl->max_stripe_size = SZ_256M; + ctl->max_chunk_size = ctl->max_stripe_size; + } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { + ctl->max_stripe_size = SZ_32M; + ctl->max_chunk_size = 2 * ctl->max_stripe_size; + ctl->devs_max = min_t(int, ctl->devs_max, + BTRFS_MAX_DEVS_SYS_CHUNK); + } else { + BUG(); + } + + /* We don't want a chunk larger than 10% of writable space */ + ctl->max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), + ctl->max_chunk_size); +} + +static void init_alloc_chunk_ctl(struct btrfs_fs_devices *fs_devices, + struct alloc_chunk_ctl *ctl) +{ + int index = btrfs_bg_flags_to_raid_index(ctl->type); + + ctl->sub_stripes = btrfs_raid_array[index].sub_stripes; + ctl->dev_stripes = btrfs_raid_array[index].dev_stripes; + ctl->devs_max = btrfs_raid_array[index].devs_max; + if (!ctl->devs_max) + ctl->devs_max = BTRFS_MAX_DEVS(fs_devices->fs_info); + ctl->devs_min = btrfs_raid_array[index].devs_min; + ctl->devs_increment = btrfs_raid_array[index].devs_increment; + ctl->ncopies = btrfs_raid_array[index].ncopies; + ctl->nparity = btrfs_raid_array[index].nparity; + ctl->ndevs = 0; + + switch (fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + init_alloc_chunk_ctl_policy_regular(fs_devices, ctl); + break; + default: + BUG(); + } +} + static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 start, u64 type) { @@ -4859,7 +4914,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int ndevs; int i; int j; - int index; if (!alloc_profile_is_valid(type, 0)) { ASSERT(0); @@ -4872,45 +4926,15 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } - ctl.start = start; - ctl.type = type; - - index = btrfs_bg_flags_to_raid_index(type); - - ctl.sub_stripes = btrfs_raid_array[index].sub_stripes; - ctl.dev_stripes = btrfs_raid_array[index].dev_stripes; - ctl.devs_max = btrfs_raid_array[index].devs_max; - if (!ctl.devs_max) - ctl.devs_max = BTRFS_MAX_DEVS(info); - ctl.devs_min = btrfs_raid_array[index].devs_min; - ctl.devs_increment = btrfs_raid_array[index].devs_increment; - ctl.ncopies = btrfs_raid_array[index].ncopies; - ctl.nparity = btrfs_raid_array[index].nparity; - - if (type & BTRFS_BLOCK_GROUP_DATA) { - ctl.max_stripe_size = SZ_1G; - ctl.max_chunk_size = BTRFS_MAX_DATA_CHUNK_SIZE; - } else if (type & BTRFS_BLOCK_GROUP_METADATA) { - /* for larger filesystems, use larger metadata chunks */ - if (fs_devices->total_rw_bytes > 50ULL * SZ_1G) - ctl.max_stripe_size = SZ_1G; - else - ctl.max_stripe_size = SZ_256M; - ctl.max_chunk_size = ctl.max_stripe_size; - } else if (type & BTRFS_BLOCK_GROUP_SYSTEM) { - ctl.max_stripe_size = SZ_32M; - ctl.max_chunk_size = 2 * ctl.max_stripe_size; - ctl.devs_max = min_t(int, ctl.devs_max, - BTRFS_MAX_DEVS_SYS_CHUNK); - } else { - btrfs_err(info, "invalid chunk type 0x%llx requested", - type); - BUG(); + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(info, "invalid chunk type 0x%llx requested", type); + ASSERT(0); + return -EINVAL; } - /* We don't want a chunk larger than 10% of writable space */ - ctl.max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), - ctl.max_chunk_size); + ctl.start = start; + ctl.type = type; + init_alloc_chunk_ctl(fs_devices, &ctl); devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), GFP_NOFS); From patchwork Tue Feb 25 03:56:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3C801871 for ; Tue, 25 Feb 2020 03:57:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8AB0524653 for ; Tue, 25 Feb 2020 03:57:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rxsZApzA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729001AbgBYD52 (ORCPT ); Mon, 24 Feb 2020 22:57:28 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728952AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603032; x=1614139032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=58e7jhwrOPqQXuahKyYyBxRkosy+3/SpZVRmVxJC8L0=; b=rxsZApzAUglAeDKWM2wOUL4U8tzEXuFaZTVJHTbUBQ2cQ2EaWK1S+sE/ fSoAie4n+bH56u7rmTHrO7OPZFO1J/ASGzMVkLMzFiDhvhVL5BcqdmmgD m6kjCcn8WnUpoChgex9VqEDtFoB7SmyQa7mFjYqvxHGMTao9H1u8DZm0u bqpiDPNc53TwDDbpu6POIHkn5nAeyg4jobCTJw2oCEAs1l70WSXeV1jVm LK91dy7DVuNwloY8XtC6kHb3GJROVVDf9EnIX9dc11LOhMSvflHzfZrQL KHtooO3Uu/RtVv5ayhtwHO7fHHPxG9z/GStOxuAoUJV1zP19RXtsjxjVH Q==; IronPort-SDR: YY6ftMzAFATfFmWdb9JS2Us2Oww7bh0Dt5vkooM2k7X0/WJHUStOHZtJFzO/V/mXOujh+qkXMe GRy2q130CjfxA3OQq7VvNbcvoxUhB4Ef6+7lzaK4X2LDthhU3W3NAOb9N5tLVLfQPLWS4ha6mB sSTmBgrRA+OytqctoXhLkwaJfnSn+g8yMVex6cGERcys0hT8q+VlNrZzQLBbUq+sTqUYdKTPg7 yW0cvJbnGHrSgHtX6JSalHWe4fnT+ko3udZGrGVpb5Rr2EIOXeYmSHazBEvY0osR2o9mjb6dZO R3A= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168284" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:04 +0800 IronPort-SDR: Heqydof3Bj3oZwZBzMzwfmIbGCV1hOeJxozE9AaY3D4F5XEf3cvQePEQXjSGUWdY0Ls4/o9gkP Pp6/l4w0CXAHNehZmoZbE0NLL4hX5kn3+A90kZjxcCXuMnyQ2UGkLnkbF9pZVYsbD4XkGpAMIz VZOWuIAGLsLvgHmdBL1z/bhB/9lRgd7RHBDmO6H67M1XbZ3tXNd2UgG3w7oy4IThQKaqF/ve8N +MO4Y269obTmUMeCzF55st0d3vqQHQXe+nSelmiZMXDnAuxUr2dM3bW5QwQWaoqstuGKDD9/uj ygJtyl3zQn3SaySCqQh2jxBd Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:32 -0800 IronPort-SDR: zTIjyhSa6neA6e2kEb8/I1AlCSTe57qT34k/tQJsoPearMC/PB58E1uE8aMlWz3UO20mQ0qft5 EQA4lrUVIYs4si0Pploku1GZJiV35FPhL8Fmrz3uuhDAoN0XehZBdvSDE5G3YiSYeIDERFl5SP jEpNRCY/Fb3GT/q3hMlhUj3pn8F55pp1raFzpdKJiyOnS6ZI5oXfDJ/en//1BX8KrBsFg7b9Nz nuDzq13A1X0dUmhPqYcfDFnqr/A/p3hdRE9AzHyXKRshv2SCa6giKNcg7gflBB98CmYvOqN8Ry 3GE= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:03 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 07/21] btrfs: factor out gather_device_info() Date: Tue, 25 Feb 2020 12:56:12 +0900 Message-Id: <20200225035626.1049501-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out gather_device_info() from __btrfs_alloc_chunk(). This function iterates over devices list and gather information about devices. This commit also introduces "max_avail" and "dev_extent_min" to fold the same calculation to one variable. This commit has no functional changes. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 121 +++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b15c2bb6f913..cd3a46a803d8 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4896,60 +4896,25 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_devices *fs_devices, } } -static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, - u64 start, u64 type) +static int gather_device_info(struct btrfs_fs_devices *fs_devices, + struct alloc_chunk_ctl *ctl, + struct btrfs_device_info *devices_info) { - struct btrfs_fs_info *info = trans->fs_info; - struct btrfs_fs_devices *fs_devices = info->fs_devices; + struct btrfs_fs_info *info = fs_devices->fs_info; struct btrfs_device *device; - struct map_lookup *map = NULL; - struct extent_map_tree *em_tree; - struct extent_map *em; - struct btrfs_device_info *devices_info = NULL; - struct alloc_chunk_ctl ctl; u64 total_avail; - int data_stripes; /* number of stripes that count for - block group size */ + u64 dev_extent_want = ctl->max_stripe_size * ctl->dev_stripes; + u64 dev_extent_min = BTRFS_STRIPE_LEN * ctl->dev_stripes; int ret; - int ndevs; - int i; - int j; - - if (!alloc_profile_is_valid(type, 0)) { - ASSERT(0); - return -EINVAL; - } - - if (list_empty(&fs_devices->alloc_list)) { - if (btrfs_test_opt(info, ENOSPC_DEBUG)) - btrfs_debug(info, "%s: no writable device", __func__); - return -ENOSPC; - } - - if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { - btrfs_err(info, "invalid chunk type 0x%llx requested", type); - ASSERT(0); - return -EINVAL; - } - - ctl.start = start; - ctl.type = type; - init_alloc_chunk_ctl(fs_devices, &ctl); - - devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), - GFP_NOFS); - if (!devices_info) - return -ENOMEM; + int ndevs = 0; + u64 max_avail; + u64 dev_offset; /* * in the first pass through the devices list, we gather information * about the available holes on each device. */ - ndevs = 0; list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) { - u64 max_avail; - u64 dev_offset; - if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) { WARN(1, KERN_ERR "BTRFS: read-only device in alloc_list\n"); @@ -4970,21 +4935,20 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (total_avail == 0) continue; - ret = find_free_dev_extent( - device, ctl.max_stripe_size * ctl.dev_stripes, - &dev_offset, &max_avail); + ret = find_free_dev_extent(device, dev_extent_want, &dev_offset, + &max_avail); if (ret && ret != -ENOSPC) - goto error; + return ret; if (ret == 0) - max_avail = ctl.max_stripe_size * ctl.dev_stripes; + max_avail = dev_extent_want; - if (max_avail < BTRFS_STRIPE_LEN * ctl.dev_stripes) { + if (max_avail < dev_extent_min) { if (btrfs_test_opt(info, ENOSPC_DEBUG)) btrfs_debug(info, - "%s: devid %llu has no free space, have=%llu want=%u", + "%s: devid %llu has no free space, have=%llu want=%llu", __func__, device->devid, max_avail, - BTRFS_STRIPE_LEN * ctl.dev_stripes); + dev_extent_min); continue; } @@ -4999,14 +4963,63 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, devices_info[ndevs].dev = device; ++ndevs; } - ctl.ndevs = ndevs; + ctl->ndevs = ndevs; /* * now sort the devices by hole size / available space */ - sort(devices_info, ctl.ndevs, sizeof(struct btrfs_device_info), + sort(devices_info, ndevs, sizeof(struct btrfs_device_info), btrfs_cmp_device_info, NULL); + return 0; +} + +static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, + u64 start, u64 type) +{ + struct btrfs_fs_info *info = trans->fs_info; + struct btrfs_fs_devices *fs_devices = info->fs_devices; + struct map_lookup *map = NULL; + struct extent_map_tree *em_tree; + struct extent_map *em; + struct btrfs_device_info *devices_info = NULL; + struct alloc_chunk_ctl ctl; + int data_stripes; /* number of stripes that count for + block group size */ + int ret; + int i; + int j; + + if (!alloc_profile_is_valid(type, 0)) { + ASSERT(0); + return -EINVAL; + } + + if (list_empty(&fs_devices->alloc_list)) { + if (btrfs_test_opt(info, ENOSPC_DEBUG)) + btrfs_debug(info, "%s: no writable device", __func__); + return -ENOSPC; + } + + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(info, "invalid chunk type 0x%llx requested", type); + ASSERT(0); + return -EINVAL; + } + + ctl.start = start; + ctl.type = type; + init_alloc_chunk_ctl(fs_devices, &ctl); + + devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), + GFP_NOFS); + if (!devices_info) + return -ENOMEM; + + ret = gather_device_info(fs_devices, &ctl, devices_info); + if (ret < 0) + goto error; + /* * Round down to number of usable stripes, devs_increment can be any * number so we can't use round_down() From patchwork Tue Feb 25 03:56:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8484014B4 for ; Tue, 25 Feb 2020 03:57:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B01B24650 for ; Tue, 25 Feb 2020 03:57:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rzTkLNXw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728963AbgBYD5N (ORCPT ); Mon, 24 Feb 2020 22:57:13 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34231 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603031; x=1614139031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oJTSQ1c89aup4pa+F8rEF7dY+Ra69cRKtlf1ymhuCeY=; b=rzTkLNXwGGLxgh7jpPlrJ1TSMMo2MERs2D7W0e7Nzh9ogW6XsZC+dore uPyK8pmf3KP4fiMz5tDG9PI0bKdZdzY0MnSB1wfWYhY8XONq1Dm6Vd9Bv WCYNJM7gxq4/q0IK3IHCM6zANe6MPcxn6JDlxDxjGZ2H4PrbhdzbkQXLu w0ycZEktpMnhwsynwuC6dLxSEqY4Amrs55tKukcS5AEWsvbQE+hohp3wq tZixFw93Q+g946F/OSVD3UaG7FRzmtbUhJ/EoGj7ijpCuHrj9LqeNODR/ TwJae5i4s0v4gtCwdfl38Aqp+NzxnmDv7OYUg/eKF9sfHcYwLkrlPEseS A==; IronPort-SDR: oF6oLSuwua4QWYkFvae92F/qzNnvhoPNN/NkoXlrHueydwNum0MYEIj8Fs7ymTVJSLYnoHyP8t buHbr6KeP3Herv9hUgI2fpPzssQMYMGNYe+ydZknbiZ3dmBOTMS3O12l5o+42jRk0tbBD0RCNi JnLY+NCzqLtsHCr9f5lbVUgZ2vQEkzjl0U33l96FLI0zvwVcXt4tqQcYlEfQ5CaDhrxcjpmHTs uvtCc5ytcICXoqFLU6iBywWqPlcWjmC+Ku+fMohhYbIgvtjeINS3UUblMncApuccNU8ZlRYA44 boE= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168285" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:05 +0800 IronPort-SDR: 0WZ41MwDPiEr3ku5ikxTew868HjOrRp26nhw8MD3v0yNFjHwrwlD28WkAtYJAClQZd+m+8Wse6 hIeS3hUPZizPH7NQ1heof7U5GzSzjsBOhm9MTbgsOuSPf8Quzpt1iwgGRWBVLomS1H83bWmjYj fXSFaw04IVRCDqPfMApckf2uta0g8z82JK1i37bX7L47h9C5p5KViQjkM55p7KgZwXthNrAPLy LidTs1PRAewB7w1qPmuN/RMNH3xvLBIDwP6nE/rB9ef+pt4g/y0S5Ff1JPKa5+D14/UKBRN1ps zTZ9g24gGsSn/bE0yr1WZ6oH Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:33 -0800 IronPort-SDR: i2WMMgh6Anx/RwUa5qKxxAZs6RB17B+SylMx3thr6av9hxTn6mM30uZRyCZwni/pHm8h+grUdh PMtxshYb9UoJ1GF9PHGKEuYCieIqHHnV9ffuVp/hGVLtR1oQl9yHQs3xw36aUzpDCbkr4tV7dV r/1zcrFlJrMpH/155tFhNqiOrxaZLghuzrEFcZiIaW2nHuOFXwPx9ayeZAz6UReonXh3pgaQ+u kt5y0bVOEuUE1DeLcGo03f40kOiWtvFPYbN8S8VAix4KB6WUj/YczvHrt5RA45NFfstoQ8+URq FN4= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:05 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 08/21] btrfs: factor out decide_stripe_size() Date: Tue, 25 Feb 2020 12:56:13 +0900 Message-Id: <20200225035626.1049501-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out decide_stripe_size() from __btrfs_alloc_chunk(). This function calculates the actual stripe size to allocate. decide_stripe_size() handles the common case to round down the 'ndevs' to 'devs_increment' and check the upper and lower limitation of 'ndevs'. decide_stripe_size_regular() decides the size of a stripe and the size of a chunk. The policy is to maximize the number of stripes. This commit has no functional changes. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 138 ++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 58 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index cd3a46a803d8..fe194bc0bce3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4974,6 +4974,84 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, return 0; } +static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl, + struct btrfs_device_info *devices_info) +{ + int data_stripes; /* number of stripes that count for + block group size */ + + /* + * The primary goal is to maximize the number of stripes, so use as + * many devices as possible, even if the stripes are not maximum sized. + * + * The DUP profile stores more than one stripe per device, the + * max_avail is the total size so we have to adjust. + */ + ctl->stripe_size = div_u64(devices_info[ctl->ndevs - 1].max_avail, + ctl->dev_stripes); + ctl->num_stripes = ctl->ndevs * ctl->dev_stripes; + + /* + * this will have to be fixed for RAID1 and RAID10 over + * more drives + */ + data_stripes = (ctl->num_stripes - ctl->nparity) / ctl->ncopies; + + /* + * Use the number of data stripes to figure out how big this chunk + * is really going to be in terms of logical address space, + * and compare that answer with the max chunk size. If it's higher, + * we try to reduce stripe_size. + */ + if (ctl->stripe_size * data_stripes > ctl->max_chunk_size) { + /* + * Reduce stripe_size, round it up to a 16MB boundary again and + * then use it, unless it ends up being even bigger than the + * previous value we had already. + */ + ctl->stripe_size = min(round_up(div_u64(ctl->max_chunk_size, + data_stripes), SZ_16M), + ctl->stripe_size); + } + + /* align to BTRFS_STRIPE_LEN */ + ctl->stripe_size = round_down(ctl->stripe_size, BTRFS_STRIPE_LEN); + ctl->chunk_size = ctl->stripe_size * data_stripes; + + return 0; +} + +static int decide_stripe_size(struct btrfs_fs_devices *fs_devices, + struct alloc_chunk_ctl *ctl, + struct btrfs_device_info *devices_info) +{ + struct btrfs_fs_info *info = fs_devices->fs_info; + + /* + * Round down to number of usable stripes, devs_increment can be any + * number so we can't use round_down() + */ + ctl->ndevs -= ctl->ndevs % ctl->devs_increment; + + if (ctl->ndevs < ctl->devs_min) { + if (btrfs_test_opt(info, ENOSPC_DEBUG)) { + btrfs_debug(info, + "%s: not enough devices with free space: have=%d minimum required=%d", + __func__, ctl->ndevs, ctl->devs_min); + } + return -ENOSPC; + } + + ctl->ndevs = min(ctl->ndevs, ctl->devs_max); + + switch (fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + return decide_stripe_size_regular(ctl, devices_info); + default: + BUG(); + } +} + static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 start, u64 type) { @@ -4984,8 +5062,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct extent_map *em; struct btrfs_device_info *devices_info = NULL; struct alloc_chunk_ctl ctl; - int data_stripes; /* number of stripes that count for - block group size */ int ret; int i; int j; @@ -5020,61 +5096,9 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (ret < 0) goto error; - /* - * Round down to number of usable stripes, devs_increment can be any - * number so we can't use round_down() - */ - ctl.ndevs -= ctl.ndevs % ctl.devs_increment; - - if (ctl.ndevs < ctl.devs_min) { - ret = -ENOSPC; - if (btrfs_test_opt(info, ENOSPC_DEBUG)) { - btrfs_debug(info, - "%s: not enough devices with free space: have=%d minimum required=%d", - __func__, ctl.ndevs, ctl.devs_min); - } + ret = decide_stripe_size(fs_devices, &ctl, devices_info); + if (ret < 0) goto error; - } - - ctl.ndevs = min(ctl.ndevs, ctl.devs_max); - - /* - * The primary goal is to maximize the number of stripes, so use as - * many devices as possible, even if the stripes are not maximum sized. - * - * The DUP profile stores more than one stripe per device, the - * max_avail is the total size so we have to adjust. - */ - ctl.stripe_size = div_u64(devices_info[ctl.ndevs - 1].max_avail, - ctl.dev_stripes); - ctl.num_stripes = ctl.ndevs * ctl.dev_stripes; - - /* - * this will have to be fixed for RAID1 and RAID10 over - * more drives - */ - data_stripes = (ctl.num_stripes - ctl.nparity) / ctl.ncopies; - - /* - * Use the number of data stripes to figure out how big this chunk - * is really going to be in terms of logical address space, - * and compare that answer with the max chunk size. If it's higher, - * we try to reduce stripe_size. - */ - if (ctl.stripe_size * data_stripes > ctl.max_chunk_size) { - /* - * Reduce stripe_size, round it up to a 16MB boundary again and - * then use it, unless it ends up being even bigger than the - * previous value we had already. - */ - ctl.stripe_size = - min(round_up(div_u64(ctl.max_chunk_size, data_stripes), - SZ_16M), - ctl.stripe_size); - } - - /* align to BTRFS_STRIPE_LEN */ - ctl.stripe_size = round_down(ctl.stripe_size, BTRFS_STRIPE_LEN); map = kmalloc(map_lookup_size(ctl.num_stripes), GFP_NOFS); if (!map) { @@ -5098,8 +5122,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, map->type = type; map->sub_stripes = ctl.sub_stripes; - ctl.chunk_size = ctl.stripe_size * data_stripes; - trace_btrfs_chunk_alloc(info, map, start, ctl.chunk_size); em = alloc_extent_map(); From patchwork Tue Feb 25 03:56:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402461 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF74A13A4 for ; Tue, 25 Feb 2020 03:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6F9F24653 for ; Tue, 25 Feb 2020 03:57:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nW0emgl7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728966AbgBYD5N (ORCPT ); Mon, 24 Feb 2020 22:57:13 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34231 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728953AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603032; x=1614139032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4gKHM1cxWMBKItzCjnljwfJOG9PGvWyOJiXX2xNIIZ8=; b=nW0emgl7Vxo8ePStoL3wj/zieFzFnj85j5gRwAbyiHyUJyCqU3V3ebij dzYh7v6w6sQ2iq/TkW8UxFYKQdoBzKPidHyVvtyl1naBo7m8U0kQuAP4U 44pMvhcLw1AZ5LWBm0DlvnwYv2wPpwmk8oD0sBgCEYyqyeEJRv71277U3 VTqAAmL9+X7TDIkg1saXjab4VD3AnmtoAs24JFxOMIWTHIVQZbkTvJnvg HethIF1V+0tJ/Lm1rnMgmmakVYQWWaYM02ygL9aL66j8szahBtsupJEHx KoYeJ4kh7YJxyQaNIREnAygVdFNafOLwz6tN3MgxsexWaP0HlWoWtx0pK g==; IronPort-SDR: 9vwUnehC9MBRJIU0HxOZKkWA89dLLOJKMIaa3CIuxvCy8+xFwl62KA8RBFtlCXDpVZS1BQWz6y 6w+vQs9Kmc9pW88vTYdlDKQ7uKVz14UUEeGa6Ptcxmt9QtQGcfRB42XUO3v9+yXcg61wy+ycZI gnzAGSemz6Rr+sP3RKNFpMSYSNvl3EjmbB0WCOeFYDuGdXE4/Q6bWHRtmFun1lifhfkdFqa4IU eCt6Bd5ZpZXo5YOyfW9ygGurcjQVBYXixbQtAZBjE6WPiu5KN9Jjf50NkeyeIEbtP+iprXNP03 Ufg= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168287" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:07 +0800 IronPort-SDR: DCtrkvrxJ4Xg8CDNNDzch7h+BVKt/bWPJgLp3FNPzAIe2/3+e0PNuPTV2wONynXsYpCNvwYu2f GYn7dBOQrSQcPxSWvNRks/ZRnssSKYXqxF865MJNPUz3/XLM5XG5LapfV3/ZlqBesl13z3d68X 8YUxg6gCSiFOkFlU9lOAGIkh1KWIJxruqc0fm5QgfjHanbAPNi175gVcIdubOdIwVoI/lbMybR p68nthHfIMK0zGeVXKTM9kMQ1GAurE9vXYpkYs8A+28kSZEs5OLjfLfkqDC0fhnGFwCJxKKfSS LmYKwOqNO+ZBJWrKSENTohK2 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:35 -0800 IronPort-SDR: 5v3XTsPu6k/5tzaYXuOXjOx9IbKsQLpv5iKrgnHx27dj0Hjyh7bgc7dTqmTLb4hLdIP7Z+kUEN +a1UCMp3bTNLYgNHkEFqvjGf1zcGzyMp+vh/DMEvQkkxIBInf1PZbNAOl98AzKw0oMS7wpAvDj hrHf+JSuuhiyneLU6TaGP3z6rxY1jh0/s7w+RUsFAFP2Zl/mcP7Njj2F3WlbLwX8bJNC2CjCLG hDDWPcZQgBCk0NKts5Mp8hgQ0qmZqxIuuozoD3dX/ewEyLzUfzc6kyJHt0QwL8WukgeuoZj0Jh 3Gs= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:06 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 09/21] btrfs: factor out create_chunk() Date: Tue, 25 Feb 2020 12:56:14 +0900 Message-Id: <20200225035626.1049501-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out create_chunk() from __btrfs_alloc_chunk(). This function finally creates a chunk. There is no functional changes. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 132 ++++++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index fe194bc0bce3..cd854d6b8208 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5052,91 +5052,53 @@ static int decide_stripe_size(struct btrfs_fs_devices *fs_devices, } } -static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, - u64 start, u64 type) +static int create_chunk(struct btrfs_trans_handle *trans, + struct alloc_chunk_ctl *ctl, + struct btrfs_device_info *devices_info) { struct btrfs_fs_info *info = trans->fs_info; - struct btrfs_fs_devices *fs_devices = info->fs_devices; struct map_lookup *map = NULL; struct extent_map_tree *em_tree; struct extent_map *em; - struct btrfs_device_info *devices_info = NULL; - struct alloc_chunk_ctl ctl; + u64 start = ctl->start; + u64 type = ctl->type; int ret; int i; int j; - if (!alloc_profile_is_valid(type, 0)) { - ASSERT(0); - return -EINVAL; - } - - if (list_empty(&fs_devices->alloc_list)) { - if (btrfs_test_opt(info, ENOSPC_DEBUG)) - btrfs_debug(info, "%s: no writable device", __func__); - return -ENOSPC; - } - - if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { - btrfs_err(info, "invalid chunk type 0x%llx requested", type); - ASSERT(0); - return -EINVAL; - } - - ctl.start = start; - ctl.type = type; - init_alloc_chunk_ctl(fs_devices, &ctl); - - devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), - GFP_NOFS); - if (!devices_info) + map = kmalloc(map_lookup_size(ctl->num_stripes), GFP_NOFS); + if (!map) return -ENOMEM; + map->num_stripes = ctl->num_stripes; - ret = gather_device_info(fs_devices, &ctl, devices_info); - if (ret < 0) - goto error; - - ret = decide_stripe_size(fs_devices, &ctl, devices_info); - if (ret < 0) - goto error; - - map = kmalloc(map_lookup_size(ctl.num_stripes), GFP_NOFS); - if (!map) { - ret = -ENOMEM; - goto error; - } - - map->num_stripes = ctl.num_stripes; - - for (i = 0; i < ctl.ndevs; ++i) { - for (j = 0; j < ctl.dev_stripes; ++j) { - int s = i * ctl.dev_stripes + j; + for (i = 0; i < ctl->ndevs; ++i) { + for (j = 0; j < ctl->dev_stripes; ++j) { + int s = i * ctl->dev_stripes + j; map->stripes[s].dev = devices_info[i].dev; map->stripes[s].physical = devices_info[i].dev_offset + - j * ctl.stripe_size; + j * ctl->stripe_size; } } map->stripe_len = BTRFS_STRIPE_LEN; map->io_align = BTRFS_STRIPE_LEN; map->io_width = BTRFS_STRIPE_LEN; map->type = type; - map->sub_stripes = ctl.sub_stripes; + map->sub_stripes = ctl->sub_stripes; - trace_btrfs_chunk_alloc(info, map, start, ctl.chunk_size); + trace_btrfs_chunk_alloc(info, map, start, ctl->chunk_size); em = alloc_extent_map(); if (!em) { kfree(map); - ret = -ENOMEM; - goto error; + return -ENOMEM; } set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags); em->map_lookup = map; em->start = start; - em->len = ctl.chunk_size; + em->len = ctl->chunk_size; em->block_start = 0; em->block_len = em->len; - em->orig_block_len = ctl.stripe_size; + em->orig_block_len = ctl->stripe_size; em_tree = &info->mapping_tree; write_lock(&em_tree->lock); @@ -5144,11 +5106,11 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, if (ret) { write_unlock(&em_tree->lock); free_extent_map(em); - goto error; + return ret; } write_unlock(&em_tree->lock); - ret = btrfs_make_block_group(trans, 0, type, start, ctl.chunk_size); + ret = btrfs_make_block_group(trans, 0, type, start, ctl->chunk_size); if (ret) goto error_del_extent; @@ -5156,20 +5118,19 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct btrfs_device *dev = map->stripes[i].dev; btrfs_device_set_bytes_used(dev, - dev->bytes_used + ctl.stripe_size); + dev->bytes_used + ctl->stripe_size); if (list_empty(&dev->post_commit_list)) list_add_tail(&dev->post_commit_list, &trans->transaction->dev_update_list); } - atomic64_sub(ctl.stripe_size * map->num_stripes, + atomic64_sub(ctl->stripe_size * map->num_stripes, &info->free_chunk_space); free_extent_map(em); check_raid56_incompat_flag(info, type); check_raid1c34_incompat_flag(info, type); - kfree(devices_info); return 0; error_del_extent: @@ -5181,7 +5142,56 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, free_extent_map(em); /* One for the tree reference */ free_extent_map(em); -error: + + return ret; +} + +static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, + u64 start, u64 type) +{ + struct btrfs_fs_info *info = trans->fs_info; + struct btrfs_fs_devices *fs_devices = info->fs_devices; + struct btrfs_device_info *devices_info = NULL; + struct alloc_chunk_ctl ctl; + int ret; + + if (!alloc_profile_is_valid(type, 0)) { + ASSERT(0); + return -EINVAL; + } + + if (list_empty(&fs_devices->alloc_list)) { + if (btrfs_test_opt(info, ENOSPC_DEBUG)) + btrfs_debug(info, "%s: no writable device", __func__); + return -ENOSPC; + } + + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(info, "invalid chunk type 0x%llx requested", type); + ASSERT(0); + return -EINVAL; + } + + ctl.start = start; + ctl.type = type; + init_alloc_chunk_ctl(fs_devices, &ctl); + + devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), + GFP_NOFS); + if (!devices_info) + return -ENOMEM; + + ret = gather_device_info(fs_devices, &ctl, devices_info); + if (ret < 0) + goto out; + + ret = decide_stripe_size(fs_devices, &ctl, devices_info); + if (ret < 0) + goto out; + + ret = create_chunk(trans, &ctl, devices_info); + +out: kfree(devices_info); return ret; } From patchwork Tue Feb 25 03:56:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 600AE13A4 for ; Tue, 25 Feb 2020 03:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4207124653 for ; Tue, 25 Feb 2020 03:57:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="l1d1dkz5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728924AbgBYD51 (ORCPT ); Mon, 24 Feb 2020 22:57:27 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34231 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728958AbgBYD5M (ORCPT ); Mon, 24 Feb 2020 22:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603032; x=1614139032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3UNk3JARnboYJecuheSmhGM6q4Yh6IyVDpJ+YcGbGUI=; b=l1d1dkz5I4WnBO0t9eI/b84Edx/HI3dd6Pnm2hHI1qGU5LUPK123+YU3 EdXXtTix9+s9eELYCr+fCWOg/7ZZYSThGVCrSJsmQGsesYIhooeFEl9xx bG2phz4q3lAUWNKSi5OdVpmcjC4uBBgtEuuU6uAcA9ZUtbFzFSvLn3dff oivnxYii5tQ8D5IPbXPAvBLixfHVkag7JFNKJ2G1AakXYmGswJIxrxs3R Bo187Dn5p/4WdHysV9+NCMbx4EvgjfTF+f4gbqI9pKB63dgXzX8WuTF10 n7rpHmOpqx+6HSm3AK+lGtIDCuxjOQ3al9975rF/J2sxJiP0jIImf863O g==; IronPort-SDR: PYFTd090tJzFcdGk7VfMaSUZJjnEIQuunz19QID7m3E+oHM04LDMQLwCfRhaaVK6cRDx/5z2Ym 2S93VSmKUwwfiHWXVRrZ1qeVvx3mch+tDqIo2wJZZjJjUUypNmJJVvIKEaxyb9ucOMIptuZEta aqokuL7ph9nH0TMttqStLFn1A61SjHz9pMeuRppztO3BnFpEVsS7AczhPXxkdfphWBXikPAe+q 5VmjNJFy2NQJLuU0jC0WW0L+dI6pMxtxFg/rZj3FnkpC9nr+KrKsQAvuHpScVTLq2GfcNLglaY fp4= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168288" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:08 +0800 IronPort-SDR: RBj2EnjYOAXdxQNjvMbFdnfdLwFHNevM/cKdO53KRC84equo4vCHpAGyg42fDHYpp0SOEm51zL nrUs1smZWbKM67+SHsRGS6eTcKuju28WsBsTbiJ915dfqON7/H4VqfrBapclXiqiKogCt+TA/g nm0MDu9OSWybSQJT7jMEdForXR4790/sxCmLpQA8nl/XZtXN+kIwCp92Ig4H+WNFs1oUjqswO3 KktKSuJWl2bU95WWGf6hWxzCAe9a129S9pq48VXA5iPGcLdVhe2VGjMSBZEbrXMZCr4Svx9rGi IXdcKYwhkUwSSIsVx1zJ3PVy Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:36 -0800 IronPort-SDR: oD8yRF73XrPO/ns/qdqOV4kELIoeLiQu2KPMJtgOa/DjvnNIoXa8LbwAotZLDwQDfJYGRojVFR EZYKFso09x1E3VjBVsSGNm5wtf/3kRM+zKdxfM/lDUFoD5+WCpcUK09m7R2gPcLY2iJ9mxVSu9 2mDgwCmzEfUWKPpjxmb6YOXjmhPKG86g7HF9KRFxZ26gYaFZlDUWdTkO1DsiGUOCZq3wTuhJsr l/UcVgIhIxjkmyr5invsAkef9RM0H/rAibbo9z/LE+hUGrPfuoasfnEirNk+YUzQnLkDH7QAvL fTU= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:07 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 10/21] btrfs: parameterize dev_extent_min Date: Tue, 25 Feb 2020 12:56:15 +0900 Message-Id: <20200225035626.1049501-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently, we ignore a device whose available space is less than "BTRFS_STRIPE_LEN * dev_stripes". This is a lower limit for current allocation policy (to maximize the number of stripes). This commit parameterizes dev_extent_min, so that other policies can set their own lower limitation to ignore a device with an insufficient space. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index cd854d6b8208..c5c64252d1f3 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4836,6 +4836,7 @@ struct alloc_chunk_ctl { store parity information */ u64 max_stripe_size; u64 max_chunk_size; + u64 dev_extent_min; u64 stripe_size; u64 chunk_size; int ndevs; @@ -4869,6 +4870,7 @@ init_alloc_chunk_ctl_policy_regular(struct btrfs_fs_devices *fs_devices, /* We don't want a chunk larger than 10% of writable space */ ctl->max_chunk_size = min(div_factor(fs_devices->total_rw_bytes, 1), ctl->max_chunk_size); + ctl->dev_extent_min = BTRFS_STRIPE_LEN * ctl->dev_stripes; } static void init_alloc_chunk_ctl(struct btrfs_fs_devices *fs_devices, @@ -4904,7 +4906,6 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, struct btrfs_device *device; u64 total_avail; u64 dev_extent_want = ctl->max_stripe_size * ctl->dev_stripes; - u64 dev_extent_min = BTRFS_STRIPE_LEN * ctl->dev_stripes; int ret; int ndevs = 0; u64 max_avail; @@ -4932,7 +4933,7 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, total_avail = 0; /* If there is no space on this device, skip it. */ - if (total_avail == 0) + if (total_avail < ctl->dev_extent_min) continue; ret = find_free_dev_extent(device, dev_extent_want, &dev_offset, @@ -4943,12 +4944,12 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, if (ret == 0) max_avail = dev_extent_want; - if (max_avail < dev_extent_min) { + if (max_avail < ctl->dev_extent_min) { if (btrfs_test_opt(info, ENOSPC_DEBUG)) btrfs_debug(info, "%s: devid %llu has no free space, have=%llu want=%llu", __func__, device->devid, max_avail, - dev_extent_min); + ctl->dev_extent_min); continue; } From patchwork Tue Feb 25 03:56:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A037E14B4 for ; Tue, 25 Feb 2020 03:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8035924650 for ; Tue, 25 Feb 2020 03:57:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="W3H4n7U7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728909AbgBYD5P (ORCPT ); Mon, 24 Feb 2020 22:57:15 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34216 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5N (ORCPT ); Mon, 24 Feb 2020 22:57:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603033; x=1614139033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=S0X2I6mNARdubB8ebF8WxvZdHBmncnPsrup3zWZuyh4=; b=W3H4n7U78yXPq523d6gBZpmBLCX2y0ILl3KtGCi2mHzE/Lg3onQfTDP4 IYgvczhGuCVQ3+zloOt/dBfdnbB0TeAurfSNVV50wdC5ZcxtzjQnu+Wu1 thjuQsXb9YubKbPR6PhAoCoah9pvMuLTPsJNHojImFxtnN+oX4emsLuqH tPiVfp2XeXuXk0nMbbS/AtghgoCnqaXDK+FTBMcqeyb1wfsGW6Nj/3qK8 6YTGObzGxgvCMaj7zJkETQ2qhunvifT7++lzdTdki9cc0HyTrhq6YRc4x 2aqxsGEl2oFh4YXU4ulwyXhc7fOqvJWJIhiE7N/e/3AyPDz4+bwXycCDn Q==; IronPort-SDR: ZrCfKVRyXUdzYvoiNgx6piMZqKkPfl4Ho/7HcEGW3k13swJDwgqAAasksmZjUkL/ulPQu6oZuv pubSoiKJxtCCOJkoURcrRdN30n9NrlOG2TKSqgnfr7HEIJ52UFYtQJqURYWJPRuUfILzfUw9w8 8dSx+J1IGCCCQuGzB5Vrw/kYWTDyaIgRB0n2ybypbeBO5WQVD7s6hXF2RUEI2FXq+WfZntwfi/ cfB8dTT3fQTE1Ay6mUE6uj//GXQCRhWQvAoOBQJ6737s+e2eZDLdDrhh+MdF3c/KaZY5cVZqp9 ehw= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168291" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:09 +0800 IronPort-SDR: YZFbmZAHJH6t/iNN2FEbsh0QPIZ+ZzuFPFmhqIkYZPINbEPV0VfKif8GmiwFvCfuDyy58I9oMm 9/zygxMdLIB+EoFtOjAg1HAw/QLBD7479DeQvf7NbeDkVCvS/frLayywwal44skIiaRBrb+XAn nQnGV0tnvB4Nph9dyYfOwYPi0gsSSwY0BOfChq7HQutKF78aYStsRD64NhkNESjrvS1MdrqVrf 6nmJyi3TTpe91hA652LEiraG1A14zBqL1ScRv1j0kguoc1nEBJXQLrgJig52Yae63Pl9xhDCIF ihBKxO6m4KQMCto7k8tWkt1Y Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:37 -0800 IronPort-SDR: 8rfZb1n1ntXVSwar8jZBKReg3qkv7kMDukPl6N1N3rHp0/0LRkr/VAZmLHsQI3WeSiM6fpskI9 g46RQKFE/jf19J5S1pfCi17Qe4cCO85XELquAVSztG0o+pU1LNygf8OWys3Sy4EGCOjMwymJHQ slpN2hlp+NzQeVRyzyqVG7TTcGhxvQd4mN2Y91vak5SFAiVI0lPP+R+LfHmnJ20Y7ZTe78/AYL OYgXEP/TX2duYOwywnSPf/D/LtgZEYo+gimzHffn1iOSL/IfXHz3tZDQ15/Suzy2xiPS3TlzCL hXo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:09 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 11/21] btrfs: introduce extent allocation policy Date: Tue, 25 Feb 2020 12:56:16 +0900 Message-Id: <20200225035626.1049501-12-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This commit introduces extent allocation policy for btrfs. This policy controls how btrfs allocate an extents from block groups. There is no functional change introduced with this commit. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index ed646a13956d..edc72e768119 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3438,6 +3438,10 @@ btrfs_release_block_group(struct btrfs_block_group *cache, btrfs_put_block_group(cache); } +enum btrfs_extent_allocation_policy { + BTRFS_EXTENT_ALLOC_CLUSTERED, +}; + /* * Structure used internally for find_free_extent() function. Wraps needed * parameters. @@ -3489,6 +3493,9 @@ struct find_free_extent_ctl { /* Found result */ u64 found_offset; + + /* Allocation policy */ + enum btrfs_extent_allocation_policy policy; }; @@ -3826,6 +3833,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ffe_ctl.have_caching_bg = false; ffe_ctl.orig_have_caching_bg = false; ffe_ctl.found_offset = 0; + ffe_ctl.policy = BTRFS_EXTENT_ALLOC_CLUSTERED; ins->type = BTRFS_EXTENT_ITEM_KEY; ins->objectid = 0; From patchwork Tue Feb 25 03:56:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 118031871 for ; Tue, 25 Feb 2020 03:57:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E63B924653 for ; Tue, 25 Feb 2020 03:57:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="pUeFBJG8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728921AbgBYD5O (ORCPT ); Mon, 24 Feb 2020 22:57:14 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34231 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbgBYD5N (ORCPT ); Mon, 24 Feb 2020 22:57:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603033; x=1614139033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RNXg1axbqdLZuo9+0jRwDCry1grvNkhf/pZs0xTqJv8=; b=pUeFBJG8nudcTAUqKiHq6nlIasE5UFJdKs986c2cZDaoVwgB8NpoyPmU Rd+7UoU656EQeZ7q3cuJit49a/xgri87LZbJ1Ug5Sc8yCLAl6M0hVA/Oh XIvHzWmAHhSpymHhh8A6VB+DBy3ijWZwNToJeL8kIdGdV3rfbUK1ufHJ0 JxWr9Nfyo2bN/rhy5vZVPQ4vycmTOKBX1KE1YJ12/mjxhlDnzp89d5Ob5 0XiKU1eyYlVCuWDN4fF4A+R3uTMyXzbF4M0si3TvGO/8WKAFF6JMbJ7cf Tp2qVk7DJSrIXZnO2ptve49yckWLJj2fV8oRKR5MJ6kPnIbvQT0ikm6KR w==; IronPort-SDR: avIlmCml6DXzwccXDtozplQU5wIAD05vMw19zopgzEdCRXXV/RwIYc/Egckl2fiaehHrkUUvoF 9h4H/bpTlLa5/M2FEyWyxqSJ/f4KEgMXeD5P581NX1X/Kh3jz9MTBWwC0Ec/aWYU45IEschnDc UNhY3UxIHImgvRmXSKY4FiErCSq5DJ0XALHtuSwIT/9WGjRmy83QQQVoVkRCOK9oEayLdacbcp 77D4GgksbmQYiIoNKEgFz1d0nNeZiobzv5vHZMZFbKeJRS3w+wYKm0+1NqGakRMbZ2Rdk9XxI9 ZlU= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168293" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:11 +0800 IronPort-SDR: QRxniGvbs0Hg7KSBbBZQ2DDui3Oei0n+ZXOZxTVac3eT1LcZgO9mnJvbzKspKAUlVHsCtrmnzO 20Vv2IUUEyXmf6Ujqxo4LwwLVGsxEBLpr1O7ohdJL7tB0WqIkh9N8YrnjziyqeRTO1Z5KiarWm YjZd6402xQuXElViAp4KflHr+Y/hbYXGgJAgth47J5cDIru9AnRH78RV2e0Kj1rmhjKByT25gn oe6TDUjst2WLXBYbnNN0q0Nuk7Wv9zYhrDHV/4qmjjlIqLbd/u+pvzCQdxU5Hlgzh3iyNeAhQI dLxUTc+EyK9uanlrYQq1D/Fl Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:39 -0800 IronPort-SDR: tpN2SGHEYZp+Vqjk8jksaptYYmMio6Uh/8USKAmtDf9Sc8iq1qVzLZFa3hhPuUPPlDXL5d2C6S 0ko/babL13s2UTzjpBLpy5NZw3l0p1rAtth85+4hkzoN6qqE4xJAaLi3hyYxe5/j/crW3paUBk iEhUUx7Z6BrgcOPT2NIDKMLXa6BqoNY/b0Rtu2AGoJuYsJ4+UDdKb1E/M3QcimkjFOuj3ty8AR MhwXb4jnOV2erFQEm31aZgXpJ53ogirZl/TQrsanWe49smjlJCi2IsZyVRWD7OTMw9+EgCE3MD Mhc= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:10 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 12/21] btrfs: move hint_byte into find_free_extent_ctl Date: Tue, 25 Feb 2020 12:56:17 +0900 Message-Id: <20200225035626.1049501-13-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This commit moves hint_byte into find_free_extent_ctl, so that we can modify the hint_byte in the other functions. This will help us split find_free_extent further. This commit also renames the function argument "hint_byte" to "hint_byte_orig" to avoid misuse. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index edc72e768119..93f07988d480 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3494,6 +3494,9 @@ struct find_free_extent_ctl { /* Found result */ u64 found_offset; + /* Hint byte to start looking for an empty space */ + u64 hint_byte; + /* Allocation policy */ enum btrfs_extent_allocation_policy policy; }; @@ -3808,7 +3811,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, */ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, u64 ram_bytes, u64 num_bytes, u64 empty_size, - u64 hint_byte, struct btrfs_key *ins, + u64 hint_byte_orig, struct btrfs_key *ins, u64 flags, int delalloc) { int ret = 0; @@ -3833,6 +3836,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ffe_ctl.have_caching_bg = false; ffe_ctl.orig_have_caching_bg = false; ffe_ctl.found_offset = 0; + ffe_ctl.hint_byte = hint_byte_orig; ffe_ctl.policy = BTRFS_EXTENT_ALLOC_CLUSTERED; ins->type = BTRFS_EXTENT_ITEM_KEY; @@ -3875,14 +3879,14 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, if (last_ptr) { spin_lock(&last_ptr->lock); if (last_ptr->block_group) - hint_byte = last_ptr->window_start; + ffe_ctl.hint_byte = last_ptr->window_start; if (last_ptr->fragmented) { /* * We still set window_start so we can keep track of the * last place we found an allocation to try and save * some time. */ - hint_byte = last_ptr->window_start; + ffe_ctl.hint_byte = last_ptr->window_start; use_cluster = false; } spin_unlock(&last_ptr->lock); @@ -3890,8 +3894,8 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ffe_ctl.search_start = max(ffe_ctl.search_start, first_logical_byte(fs_info, 0)); - ffe_ctl.search_start = max(ffe_ctl.search_start, hint_byte); - if (ffe_ctl.search_start == hint_byte) { + ffe_ctl.search_start = max(ffe_ctl.search_start, ffe_ctl.hint_byte); + if (ffe_ctl.search_start == ffe_ctl.hint_byte) { block_group = btrfs_lookup_block_group(fs_info, ffe_ctl.search_start); /* From patchwork Tue Feb 25 03:56:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 56CE81871 for ; Tue, 25 Feb 2020 03:57:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3747E24653 for ; Tue, 25 Feb 2020 03:57:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NSRQ9xDs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728976AbgBYD5R (ORCPT ); Mon, 24 Feb 2020 22:57:17 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34233 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728915AbgBYD5Q (ORCPT ); Mon, 24 Feb 2020 22:57:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603035; x=1614139035; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L6l356z3pl1I86GSIvQvTqyGvqY8mUX91kLnKVgQnAo=; b=NSRQ9xDs0OSVrvy6sr9fdzYB5Gf3g4Zw/yyiCksOwNsks7TMRnL8UxVh T8dvf1uiH4wIoR14BaBhcG1Kc4IVka4n3W09Xdv4y8ZpEIMX46oTNDzPM MRrk80e5/tr9QZy4s7zTQZAesk0/13mAkVqmcc79MysK6/7oudY3c/0fb aimYWLsVDReFd+WbnlTh8thcmlsnGedjZUpr0tH81fjBELDoVdWAJVzcg cUH+QYDmf3Kj7Bo1obpqhVhn51UbdC6Z/7T10tWahLD4Ar+tuQEw8neKb 3W1c2pQUXs4vFZ9MvLVOWdB3w5tpDXpwilrx5HN2Mxnpbe2rr5mJ4gUp1 A==; IronPort-SDR: a9cm32hx9RnyUmFHyIK+2HFsGS5Yl2Up+MpssTvbUf0rxZDOSsbB1hDngQU6dSXHwPfc54qFyZ zGSDv4d59bDPu3ZaYZ/ea10B3ajMmze/8QdkOeTJj4Y20GhcrdQfLQN6r9sCYHxwL+HXLzz0F3 +ITkcTlMZwdLOV7Jp4TfXE5+vrCTrbD7AxDzryunvMKwI0VYHsgiHDcJ1uqz9qGAZorAGO/QSN +CrOhp+2CPeRqwW4CzSBi87EbqS80N5wh6sjaf2PRPGRFbiGKq4LB4D3LIWXGm9yMD22LrD8I7 PtE= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168295" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:12 +0800 IronPort-SDR: iz2MBQTwuZLDEaKNJkMrrMmNkE+Mlx5bfNesAN73imF1tombx4j0FD4Oz2C3PPdIu77YPy35mt H605poY3CahTYVsc1Mm578YG8wgwKeF8mj1yKEDqCMuH0w1xP2MPdnzrxcPWPPd93Oh6WXipHf ABm/7TWf8exj5Gx1ByPoGJS3V58AsyZSPI8+3LjxWfyqxY7bzrGbmDlr9OPbIZUgqegzZ4hqhR ToXbPEH3z7sXPNWaH9p241WD6O+9OT2ON478SMBw3+roHgJiv8GiOHH1sJoLANXQPo2MrVi0pG i/QOKlzKKm9+uMUo9hrtc08s Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:40 -0800 IronPort-SDR: mZheM10dLWLQ0VDJAKsypsX37gfQHQGRAn3IZGq2zB0lIcC5NqjenlkXu9YGzZZPvtQ/BZRlVy Mu42LFxQ/ggxx4GMHTeFSoINUhveIpqau8mIs+zQFBvUGrC6mSnxGRG84FZx6e5Mli4XPpYJUP JddPS4E0PI+HMQ5v9eGlNEZxsrPwcNGFkTCxh6xdFA7nPiRXxz6+L2mbrZuFDNgt09qA8oOp/8 aHS2Z7fbWBr4NSom9SJi2SmW2PoNt3+una9HMtKc+WfiltCQ6d3LiDHG7fHpiI9S0TMaG4+PFe Tug= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:11 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 13/21] btrfs: move variables for clustered allocation into find_free_extent_ctl Date: Tue, 25 Feb 2020 12:56:18 +0900 Message-Id: <20200225035626.1049501-14-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Move "last_ptr" and "use_cluster" into struct find_free_extent_ctl, so that hook functions for clustered allocator can use these variables. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 93f07988d480..cbb89ac6cda3 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3458,6 +3458,8 @@ struct find_free_extent_ctl { /* For clustered allocation */ u64 empty_cluster; + struct btrfs_free_cluster *last_ptr; + bool use_cluster; bool have_caching_bg; bool orig_have_caching_bg; @@ -3816,11 +3818,9 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, { int ret = 0; int cache_block_group_error = 0; - struct btrfs_free_cluster *last_ptr = NULL; struct btrfs_block_group *block_group = NULL; struct find_free_extent_ctl ffe_ctl = {0}; struct btrfs_space_info *space_info; - bool use_cluster = true; bool full_search = false; WARN_ON(num_bytes < fs_info->sectorsize); @@ -3829,8 +3829,6 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ffe_ctl.empty_size = empty_size; ffe_ctl.flags = flags; ffe_ctl.search_start = 0; - ffe_ctl.retry_clustered = false; - ffe_ctl.retry_unclustered = false; ffe_ctl.delalloc = delalloc; ffe_ctl.index = btrfs_bg_flags_to_raid_index(flags); ffe_ctl.have_caching_bg = false; @@ -3839,6 +3837,12 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, ffe_ctl.hint_byte = hint_byte_orig; ffe_ctl.policy = BTRFS_EXTENT_ALLOC_CLUSTERED; + /* For clustered allocation */ + ffe_ctl.retry_clustered = false; + ffe_ctl.retry_unclustered = false; + ffe_ctl.last_ptr = NULL; + ffe_ctl.use_cluster = true; + ins->type = BTRFS_EXTENT_ITEM_KEY; ins->objectid = 0; ins->offset = 0; @@ -3869,14 +3873,16 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, spin_unlock(&space_info->lock); return -ENOSPC; } else if (space_info->max_extent_size) { - use_cluster = false; + ffe_ctl.use_cluster = false; } spin_unlock(&space_info->lock); } - last_ptr = fetch_cluster_info(fs_info, space_info, - &ffe_ctl.empty_cluster); - if (last_ptr) { + ffe_ctl.last_ptr = fetch_cluster_info(fs_info, space_info, + &ffe_ctl.empty_cluster); + if (ffe_ctl.last_ptr) { + struct btrfs_free_cluster *last_ptr = ffe_ctl.last_ptr; + spin_lock(&last_ptr->lock); if (last_ptr->block_group) ffe_ctl.hint_byte = last_ptr->window_start; @@ -3887,7 +3893,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, * some time. */ ffe_ctl.hint_byte = last_ptr->window_start; - use_cluster = false; + ffe_ctl.use_cluster = false; } spin_unlock(&last_ptr->lock); } @@ -4000,10 +4006,11 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, * Ok we want to try and use the cluster allocator, so * lets look there */ - if (last_ptr && use_cluster) { + if (ffe_ctl.last_ptr && ffe_ctl.use_cluster) { struct btrfs_block_group *cluster_bg = NULL; - ret = find_free_extent_clustered(block_group, last_ptr, + ret = find_free_extent_clustered(block_group, + ffe_ctl.last_ptr, &ffe_ctl, &cluster_bg); if (ret == 0) { @@ -4021,8 +4028,8 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, /* ret == -ENOENT case falls through */ } - ret = find_free_extent_unclustered(block_group, last_ptr, - &ffe_ctl); + ret = find_free_extent_unclustered(block_group, + ffe_ctl.last_ptr, &ffe_ctl); if (ret == -EAGAIN) goto have_block_group; else if (ret > 0) @@ -4071,8 +4078,9 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, } up_read(&space_info->groups_sem); - ret = find_free_extent_update_loop(fs_info, last_ptr, ins, &ffe_ctl, - full_search, use_cluster); + ret = find_free_extent_update_loop(fs_info, ffe_ctl.last_ptr, ins, + &ffe_ctl, full_search, + ffe_ctl.use_cluster); if (ret > 0) goto search; From patchwork Tue Feb 25 03:56:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 002ED18E8 for ; Tue, 25 Feb 2020 03:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D496C24653 for ; Tue, 25 Feb 2020 03:57:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="QRjPE4+T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728978AbgBYD5S (ORCPT ); Mon, 24 Feb 2020 22:57:18 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34233 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728866AbgBYD5Q (ORCPT ); Mon, 24 Feb 2020 22:57:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603036; x=1614139036; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9Dm5xWcxeGHQQfziuoYwU9OlBKzzE4/PR/QwWTqCGu4=; b=QRjPE4+TT4vGwZ7sVdheOWNMPTIjjzoBOPamX8Rvc7I45LQ+qIi0aHbk j3uGULozUVKef+rQSgLM3zy41tG3+Fis6B+BpCLaOrOEYRYJRjhLt5QVk 2/FnLTBoaTZ2zQjL0zF9k6WcYcm/jr5EWm6mKhJf/lRy70sHMJgIhULKO Fd6wgsjf3hJosdUQd1uSz/mcUn43GxgY6f420Um6qA5SGrhDMOQVKYubP 7BTtuqOfETwW+TYgzSdmfHNMiKn/JCWVZma5X1UBhNJIaRU2YNRY9MPVd lXFCD6KZ8DBfXw4ollLlW5aDyXhMBqd75j8Ukq8NPC+aVn+0sSoA+2pSF Q==; IronPort-SDR: Kdx7wWxfm75py5MoEqI7BktDEaFpi3pBdEuuD9nDqAYtdgEu24O9cpnqSCM0M+C243XlV0HlQj 4WodE85RWKBwBrtdVukGeGiRqAFj8mk1ML8m/8ExPNPX6OEpSdxO/qvQJvlhBldpVMHbkKqPvH Y3ZHL35IhG/ptX6Kj2INnzOvhPRUIaymrqqtbqfOtqJ5Ry2s+ffwQs/q5HthprxfFrRuYn2kk1 fTTCta720vjJEQZZkgUJQZRc0aXHY+RzxyoB8jjOPbIGYhT71R8h0Tt3/12TsokDiCAqZ2DxXL vQo= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168297" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:13 +0800 IronPort-SDR: uXhAI9yeWWIqa4IzFvOodnRBRIKY8uEMIiQz7M1D/d2c+N42iVTkzNVVl5qFp8EJ+lhTbDRQHx +x1OA4nJzBYYtkaNSVtOgubtN/7C6oCpMU1NmSf6ku8wIWPLM0Ryj9YfJdV2w77FckF0/Nezbc v++Q/0sjfKN7eKWpXSpBMTkJoTAjIaIdaeAnvgxJiJmE8VrpuVtmfzs0hybQfDH6PJ3sLGDNTu muZ+JzOj9SbSu9wDnbXyngdGgF4z1CVHoFinf7M+KC1WWslqp3G8Ci2vaw69J49lYHtrSiqAJ8 X1X4L9DP4t8Esq1KRhpx1xXE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:41 -0800 IronPort-SDR: 66f2lL5FNr6NLa2QXeUf0+Bec05FA3uiSx95F/IQOsMCrsmCOoL+JGAd9PbSZusgpHihoypuUb Ao2t9dRo+FhI7a6hT5wLE93WzkWhgH/mb3b63LO6MKZeZoczlENNRQDxzV/PpakcoOF1CegAnA 3AyuBPPMepaR+WdfIH7SEEDWD2q4AyPH6FgokimxaNVrsAllwf4nPYMZOhrbuc8r2Cg9mo4cu7 FwAgIABBrew2bRHfBjIB/DkKEdxGd4e7kJoDCKRx6xhozSsUXF44WSmPEkumbiYDJrqDV4unCz eW0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:13 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 14/21] btrfs: factor out do_allocation() Date: Tue, 25 Feb 2020 12:56:19 +0900 Message-Id: <20200225035626.1049501-15-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out do_allocation() from find_free_extent(). This function do an actual allocation in a given block group. The ffe_ctl->policy is used to determine the actual allocator function to use. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent-tree.c | 78 +++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index cbb89ac6cda3..1ed12a033ba9 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3675,6 +3675,39 @@ static int find_free_extent_unclustered(struct btrfs_block_group *bg, return 0; } +static int do_allocation_clustered(struct btrfs_block_group *block_group, + struct find_free_extent_ctl *ffe_ctl, + struct btrfs_block_group **bg_ret) +{ + int ret; + + /* + * Ok we want to try and use the cluster allocator, so lets look there + */ + if (ffe_ctl->last_ptr && ffe_ctl->use_cluster) { + ret = find_free_extent_clustered(block_group, ffe_ctl->last_ptr, + ffe_ctl, bg_ret); + if (ret >= 0 || ret == -EAGAIN) + return ret; + /* ret == -ENOENT case falls through */ + } + + return find_free_extent_unclustered(block_group, ffe_ctl->last_ptr, + ffe_ctl); +} + +static int do_allocation(struct btrfs_block_group *block_group, + struct find_free_extent_ctl *ffe_ctl, + struct btrfs_block_group **bg_ret) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + return do_allocation_clustered(block_group, ffe_ctl, bg_ret); + default: + BUG(); + } +} + /* * Return >0 means caller needs to re-search for free extent * Return 0 means we have the needed free extent. @@ -3942,6 +3975,8 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, down_read(&space_info->groups_sem); list_for_each_entry(block_group, &space_info->block_groups[ffe_ctl.index], list) { + struct btrfs_block_group *bg_ret; + /* If the block group is read-only, we can skip it entirely. */ if (unlikely(block_group->ro)) continue; @@ -4002,40 +4037,21 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, if (unlikely(block_group->cached == BTRFS_CACHE_ERROR)) goto loop; - /* - * Ok we want to try and use the cluster allocator, so - * lets look there - */ - if (ffe_ctl.last_ptr && ffe_ctl.use_cluster) { - struct btrfs_block_group *cluster_bg = NULL; - - ret = find_free_extent_clustered(block_group, - ffe_ctl.last_ptr, - &ffe_ctl, &cluster_bg); - - if (ret == 0) { - if (cluster_bg && cluster_bg != block_group) { - btrfs_release_block_group(block_group, - delalloc); - block_group = cluster_bg; - } - goto checks; - } else if (ret == -EAGAIN) { - goto have_block_group; - } else if (ret > 0) { - goto loop; + bg_ret = NULL; + ret = do_allocation(block_group, &ffe_ctl, &bg_ret); + if (ret == 0) { + if (bg_ret && bg_ret != block_group) { + btrfs_release_block_group(block_group, + delalloc); + block_group = bg_ret; } - /* ret == -ENOENT case falls through */ - } - - ret = find_free_extent_unclustered(block_group, - ffe_ctl.last_ptr, &ffe_ctl); - if (ret == -EAGAIN) + } else if (ret == -EAGAIN) { goto have_block_group; - else if (ret > 0) + } else if (ret > 0) { goto loop; - /* ret == 0 case falls through */ -checks: + } + + /* checks */ ffe_ctl.search_start = round_up(ffe_ctl.found_offset, fs_info->stripesize); From patchwork Tue Feb 25 03:56:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64A151871 for ; Tue, 25 Feb 2020 03:57:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 43FA924650 for ; Tue, 25 Feb 2020 03:57:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="IBj5M84c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728980AbgBYD5S (ORCPT ); Mon, 24 Feb 2020 22:57:18 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34237 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728971AbgBYD5R (ORCPT ); Mon, 24 Feb 2020 22:57:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603037; x=1614139037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WszfEOyJxfwxKdrqWiMsACV0CNVMVid1fA7DXhfQYxA=; b=IBj5M84cN8G7p43p0GUs9tZOtImj/JO+InmicYASiMbHaYjF8MlBcFWT DfY+zQZ4rIoGyCb9wxWzjw9dKWRJOc8MDdtQ3V+lOq8tjlGdV+WySqIAP WlhYxh72//b63Sjrd3k5P7dhO3ombG7Bl5Js6+YyJHtzvLHZ9FLH0G0Ge Pl2cuCnCh2zzoD58E7lJemzC5beGoV5TN3adIqHJ9luHknAFbUg6/hKm0 g615NaITx0Q2xsmCKkjqe5r69fWeU97VqjJ5Ic+LnZ92aXc4CodRMaVKm BU3A6ZcfDrFZL9Zr2wwzEi9todN8416IpMF/RKdiG6x2LpKir/BUwLtrQ Q==; IronPort-SDR: N2rrXzvxgrEUZDfruhnOhjH940tC2YF85UbrjhNP6BPmEE5ex3kIPzuJBiarKuxCAhSeW7iD1F 68OT5gX4Hu5QM1kFH/Qpgy8CCeGPucnPMSJVQKLPQCmnFhaMKW5sEyUXKx1ziBrCQkmDXZhiWV zPr90HvbluWbeI/WrWH5POqdrFPxNo22YUCxknH0XffkaL1Bi4+RhJchK8/59oh6WyLiJJ5lOG LdatseH8GiuFfKlQ/3CYoyewafKBbz5m4XkJ8RmwsGKTOlGafLSAJmrCZFflPGu1tZHle6uIrW hYA= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168302" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:15 +0800 IronPort-SDR: zj4TSWMaohhnupbpCZZNerFfrL4N9llyBeV3oEHWA+o1wKMNOWav7eZaBwtfK8K4+flA5HVtMT 6i+e7U4gap8qBapbUhKtBnuxasKZ2gmWxZzY8x0HSP7qh1H55lU3WzjORlLl3CybDXO+f02tmv qBZH8rt9DP9FVLSAyCrHE6GhV0bheu99TS12d3SLeXeUaI0y05DwHLxrv+1OdOo2IUiHwUeACY LlEVTYjB0PexzUaoD4ht5W9JPKzWgbcSFe4+F3tDN4GTTiRbOpfl2eWegiN2GyFO+qtOrP0rB7 jSfSdmrgF8v2UGbDhBMbPRHa Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:43 -0800 IronPort-SDR: yVgXqp+UxezeIxfcWKvYcY2/oz3alplTut9ES/YjGAXTw8X2BU7FRAU7eosoYWAx0G0bRUyNS8 I/McIKDoqgVirDKJneOIv2J+EeGmtt59iXq6ZyzmoR7JzwcAF/XYW2g6Ttqd+Au4L6+dhkq/wY fAcikBZPS7RvQlO1bnyQ5bV5NJsFjF0PFxJfuuhAPt6B76WcbPJGZZv8YjGIkDBYCVIIJSyCh2 uU3dVhRiocPRn1xJfpSPumzZcyN4UWk50NTLcRKVEndoRINR8NhMBXLdkgFwM4iksuxmuNdcVu d4s= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:14 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 15/21] btrfs: drop unnecessary arguments from clustered allocation functions Date: Tue, 25 Feb 2020 12:56:20 +0900 Message-Id: <20200225035626.1049501-16-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that, find_free_extent_clustered() and find_free_extent_unclustered() can access "last_ptr" from the "clustered" variable, we can drop it from the arguments. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1ed12a033ba9..1c0c94a2a8e0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3513,11 +3513,11 @@ struct find_free_extent_ctl { * Return 0 means we have found a location and set ffe_ctl->found_offset. */ static int find_free_extent_clustered(struct btrfs_block_group *bg, - struct btrfs_free_cluster *last_ptr, - struct find_free_extent_ctl *ffe_ctl, - struct btrfs_block_group **cluster_bg_ret) + struct find_free_extent_ctl *ffe_ctl, + struct btrfs_block_group **cluster_bg_ret) { struct btrfs_block_group *cluster_bg; + struct btrfs_free_cluster *last_ptr = ffe_ctl->last_ptr; u64 aligned_cluster; u64 offset; int ret; @@ -3617,9 +3617,9 @@ static int find_free_extent_clustered(struct btrfs_block_group *bg, * Return -EAGAIN to inform caller that we need to re-search this block group */ static int find_free_extent_unclustered(struct btrfs_block_group *bg, - struct btrfs_free_cluster *last_ptr, - struct find_free_extent_ctl *ffe_ctl) + struct find_free_extent_ctl *ffe_ctl) { + struct btrfs_free_cluster *last_ptr = ffe_ctl->last_ptr; u64 offset; /* @@ -3685,15 +3685,13 @@ static int do_allocation_clustered(struct btrfs_block_group *block_group, * Ok we want to try and use the cluster allocator, so lets look there */ if (ffe_ctl->last_ptr && ffe_ctl->use_cluster) { - ret = find_free_extent_clustered(block_group, ffe_ctl->last_ptr, - ffe_ctl, bg_ret); + ret = find_free_extent_clustered(block_group, ffe_ctl, bg_ret); if (ret >= 0 || ret == -EAGAIN) return ret; /* ret == -ENOENT case falls through */ } - return find_free_extent_unclustered(block_group, ffe_ctl->last_ptr, - ffe_ctl); + return find_free_extent_unclustered(block_group, ffe_ctl); } static int do_allocation(struct btrfs_block_group *block_group, From patchwork Tue Feb 25 03:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07AD114B4 for ; Tue, 25 Feb 2020 03:57:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC1E824653 for ; Tue, 25 Feb 2020 03:57:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ICxVAsT9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728983AbgBYD5T (ORCPT ); Mon, 24 Feb 2020 22:57:19 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34233 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728972AbgBYD5R (ORCPT ); Mon, 24 Feb 2020 22:57:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603037; x=1614139037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nc1KMUIXBP1u4BIelQu8vLGgpaHwULi+6lmDWLNOIb4=; b=ICxVAsT9b/9k3Iw8cI83gPx08mQh8mrCoQkOOKFsZafDW4LOOFUSBo4H z3YMRTjl54y0AUsseUaI964ylPyWYNsMdGztWZ0Vi3YXw16I9S3Jn75vV 48hT8IH3ixyZ/QbUAiHt4WaeNcoqJvwJvoA6xahgL2eoIsttYxFhQoOXs D3fxGWPyXIgj2ZTBxgDwpZaEAmEFkgrmsnONAd8U8bhwQPmqXv5C5SXVX R9VJdz6icrnD1QxXyRFQbEzyOAduM5QHAGg8epruz8pCrC1QSiOWnmbYD ltUODUHuB1C1uKdjtUm4zOS1hNQ1JiOgmD2wJhs1Zs+GhIyXXFfPr3nqg A==; IronPort-SDR: 6Na8bBhhne928wWw6Ugvo3YEvxNfjAsZJmhA44WRGhGW/+vb66jtrG6zxsZLaTZYtcXCjQvH6E /9Vle+ARvKCG986aDKmRZwCRCl8KPBAi9ubDh4bz6uV/1CP8KmhEuUJwxCgML16jL3BMJKz2G3 MUYZbq7qRVdzanCSYXSgsXuFR0a5b4OT8Egx13utwpj6ie1KkswaRtOjFjNgcfdkmKMsYbeaS+ YXzCaswXZ+yZg9cRXCMJAEolH2nMSA1BTsiVOp55IiNuJ2jqDXRGlL5BrZmWhpFIe0JXFPMvO6 JuQ= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168303" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:16 +0800 IronPort-SDR: 0RyhmNCsIq8cmYE3rmu4Z5WKucfgKZNR9vMhraclS3POrp6bPWYpzQWj6gBjVDv5zn207PSpQq YHIkELwt3nqdCgJu195dZnAV+jJ+dyUiYgK8vSQ/EqihxUOEziyW0BDxvyqVrpjpzCF0xrpRZo jtRdi8L8Z/n9hKBTkWQNQJUl6zIKv3qGcycr3QS5i8EZrLguvvRDlLPw0tewe8qcvYPmmwaYck q9WX+1Ru6bSzzD2LzCnTgF/20UgmAD1y0wt27eI+xGLY9GUn7glP/mDgIKTzXcGcZ4TgfeigAK Y1b1xNbNBR2zT1NG5Zeq6RbB Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:44 -0800 IronPort-SDR: xneidgKyQHH2ArnQKzLTHZz67/h3YjpiXZ0u9HwdjPBdJuBiHzq7hAlwUjiqaMrCDh+TXDPea/ z1zDRJTUAkOfbs9Y3d+4BbjL3gGGcR1WsXgpy1je53uI2K4l+wgX2JYBYt7W6n70exnywOTL14 N6qM0R225Pk862XwUW0183/NHNi5sIHEN5qwI/c37HgFsMsRJMTbgBFfdsyuLtuUQBqWxzabic mSrrnTRzwpF9FBGx71v4d8eowMbRqbAo+5j3wK4ga1FwFEGiQ17GNA1OSaR7DEXsJ1l7xjHBYr jfo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:15 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 16/21] btrfs: factor out release_block_group() Date: Tue, 25 Feb 2020 12:56:21 +0900 Message-Id: <20200225035626.1049501-17-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out release_block_group() from find_free_extent(). This function is called when it gives up an allocation from a block group. Each allocation policy should reset their information for an allocation in the next block group. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1c0c94a2a8e0..76e05ed33f1f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3706,6 +3706,24 @@ static int do_allocation(struct btrfs_block_group *block_group, } } +static void release_block_group(struct btrfs_block_group *block_group, + struct find_free_extent_ctl *ffe_ctl, + int delalloc) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + ffe_ctl->retry_clustered = false; + ffe_ctl->retry_unclustered = false; + break; + default: + BUG(); + } + + BUG_ON(btrfs_bg_flags_to_raid_index(block_group->flags) != + ffe_ctl->index); + btrfs_release_block_group(block_group, delalloc); +} + /* * Return >0 means caller needs to re-search for free extent * Return 0 means we have the needed free extent. @@ -4083,11 +4101,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, btrfs_release_block_group(block_group, delalloc); break; loop: - ffe_ctl.retry_clustered = false; - ffe_ctl.retry_unclustered = false; - BUG_ON(btrfs_bg_flags_to_raid_index(block_group->flags) != - ffe_ctl.index); - btrfs_release_block_group(block_group, delalloc); + release_block_group(block_group, &ffe_ctl, delalloc); cond_resched(); } up_read(&space_info->groups_sem); From patchwork Tue Feb 25 03:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A992714B4 for ; Tue, 25 Feb 2020 03:57:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88CD324650 for ; Tue, 25 Feb 2020 03:57:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="LcGo3nos" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728986AbgBYD5V (ORCPT ); Mon, 24 Feb 2020 22:57:21 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34237 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728975AbgBYD5R (ORCPT ); Mon, 24 Feb 2020 22:57:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603037; x=1614139037; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ixCL4dVUEY7dMteTQlDqJxOzfdZTV36CemBrGbDvYzY=; b=LcGo3nos9qqMsT+3DWJsaAA7jg1LXmMZLRSk6TiYkhUeBU8vqhsb0g/n KLQJit84xnyutqG83hnRWkl39Umwaah1xbGJdGUHP84ogeX5M+HQ4q0Xr 4HnH6jzEJaoIMJSkvrVpgyqpdwVDOdrCTNw9/krufnbE5AtpgxAP4qkHp n1LkAn7R7vityupXgxiyjiSnlqGfBBiUoDg8gM+vASUzuBLofTQ6yopLo RU8OBl54pmiHIFnA+wlvSgbQQ3nK8jbwYs5X/julunoXaxTQERQu9FJg2 2OM0WWoDTLLXT0gcqjCBZdD3opLLy6tAxfTrH1HZoAca9ilrOf+hDG09w g==; IronPort-SDR: U7E8+EUAlIW+ptikd3CJKanCVwu1tlYLZqSbdGXC1i+2/eXYaLm+xKMHvyhoSwsBqtsF0hOjHT +EEKszLETyW8o//6wqpPMoNcGeWRjiHTicg+KKq+r2iOcVou8EfPB7ta4BzlI+pXvNo4IuCcJQ mF8RfnrHX1mz+G6rwreIBUqBsmuXsrXxO8Aif8yrsZKhPtPB87HU7CPF4mHnLosrn1j6j3TIe1 vweYt0BEnSAhEmFK2hugXzARtrI+CzQGEw8sFodaotXd6Ihe1eYxHV+8ENqwdOkzQzafAidP+6 8Yc= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168307" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:17 +0800 IronPort-SDR: GPH9oS0Z13REenc5DpVzGbcA5qq98IKxIvX+HZDFVFVLiZDUGKl38DTJsaPsrJd63X3HvtDZIx 01AnUhTbR00hjfDrni3ornJzvJ6F1C0g/mQTUfEOg76JsnvZtRqYgHpoKFv4M829GVfcWxHaoL n/0QIS+gxiM/PCjGpzgnN5dN6lqTMHzVMG9vXJu3Ivt/nFwcLaJwuB32EeG+G4K/qn6jHuVMRO dRY1YkUPJ2Lr/aaqU026lymzw1VLU8hCXjvKhb4aKTYG4Bo2BdCBiZGI28JgGEEuykfeavzOS7 1BzLg4PXzkrkYOWMtYhVrHSQ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:45 -0800 IronPort-SDR: +/2DpfSQtlqU+vHP87YDcs/k4DRc3fJuVrsdxZj5qNvtuQPD3wnpjzjtZxQIw2ZgJTNhFD/fNf jgp+OucnEjKNE+dAOtktzwOmkA4VRWTvGSlyl+4vUpCQ+kKrklVpglYFY+5hhaqVfzGt8iLBQ0 68LtUMR+9TOUaGsN/QFBt/hHyDC9nN2B8B6v+x2n9+7vN7+eDjQxDDyCttdcXBqVCn8O72pEK7 9C+hQ84SoL9TgcviEePdHGvlgH7xiRdL22cR3PdreP7sioeZJZKk7O/WhHmYKalqhf+XXkVvFC Qr0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:17 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 17/21] btrfs: factor out found_extent() Date: Tue, 25 Feb 2020 12:56:22 +0900 Message-Id: <20200225035626.1049501-18-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out found_extent() from find_free_extent_update_loop(). This function is called when a proper extent is found and before returning from find_free_extent(). Hook functions like found_extent_clustered() should save information for a next allocation. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 76e05ed33f1f..46d0338659d7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3724,6 +3724,30 @@ static void release_block_group(struct btrfs_block_group *block_group, btrfs_release_block_group(block_group, delalloc); } +static void found_extent_clustered(struct find_free_extent_ctl *ffe_ctl, + struct btrfs_key *ins) +{ + struct btrfs_free_cluster *last_ptr = ffe_ctl->last_ptr; + + if (!ffe_ctl->use_cluster && last_ptr) { + spin_lock(&last_ptr->lock); + last_ptr->window_start = ins->objectid; + spin_unlock(&last_ptr->lock); + } +} + +static void found_extent(struct find_free_extent_ctl *ffe_ctl, + struct btrfs_key *ins) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + found_extent_clustered(ffe_ctl, ins); + break; + default: + BUG(); + } +} + /* * Return >0 means caller needs to re-search for free extent * Return 0 means we have the needed free extent. @@ -3750,11 +3774,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, return 1; if (ins->objectid) { - if (!use_cluster && last_ptr) { - spin_lock(&last_ptr->lock); - last_ptr->window_start = ins->objectid; - spin_unlock(&last_ptr->lock); - } + found_extent(ffe_ctl, ins); return 0; } From patchwork Tue Feb 25 03:56:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 43ECB13A4 for ; Tue, 25 Feb 2020 03:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 24BFE24653 for ; Tue, 25 Feb 2020 03:57:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="ggHy8ioA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728993AbgBYD5W (ORCPT ); Mon, 24 Feb 2020 22:57:22 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34241 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728981AbgBYD5T (ORCPT ); Mon, 24 Feb 2020 22:57:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603039; x=1614139039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lsyM0jh2svvdUUkTSuSBO4Z9YHTah9mGdrGa6zXuy5U=; b=ggHy8ioAmziehfJOfG1rI25wN95ZY2gCwDovMQwUBnEJ6n/azROyEFPO PfYIkBO8nhrTHWIUYEyg9aUz7rMJCtFDVQwVfCQaIynfRqsTk3M60upCV R++idwDcHHTdeEfBOOO6P088Xe9CTbV2sQ+gltmSEBuomnqT6aXrJjdMD Zk+wyJWFJCOW22LTxlOpndAxqgTo2gpBPSSQ9OYuDASGgvbHw+EKYgLOc m4J/rk+AWAtAQ6W+OCgmxYee/SCG5ow3dw0fscrTvFhz5HlXoElIRZYoC 0TvgSpiZ3yIVhwE371/cdkCe1d8+1gPpMGHtODVzu3eT1xv1nGTbHXFdp w==; IronPort-SDR: LkINrf7a5pa2VmiDuNBP/35InMxxZdEIcADPY5K9zGhHnyhjrLwylyzm85OfoJGQaxCSkRkNHz NQTbTUaPVMXexSsak58VekkkbRT0Mgc9Hcx7jI2A/vWQCARLDnIB2sIqSk2lNR+CX0HEJsdBv2 tQhYy9fcaity6mddyjcdnaoTZHKtnMoxWhoTE09OVuUz8je+saI8cwa2X66QedKcpFfX3eVX6V ekhtmNMtplwAcC3kf5XRylcw7srIFWuP4AhC6+bExQ1KCt1SgN5MDG7aWtL4K84d4Bx3ZGWJvL ODY= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168308" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:19 +0800 IronPort-SDR: sVAMJfbkQidmdlB/iZ+crZn0SrNJWjI5NtYsZUt+4t01pgr9fqPmcHbXBbTJw6StXac5u+BEKI 2/OFuVi7BKFEG65QdXLlwE5AZKpfAi1t7rNanKM3k4XRyyJk/Fuf7bonjFvqr96/rXxWJ+7Nj/ X27PQ1Zuduika06kcLS9cKqK2BP9cquxJpwp3gI4Gx1vrF5MOtfHbqyvWlkDcM2du9JC6sl1vU 4T7QC9IPNtyQifWSwY2NJ2637aW6JNjbhwqg+nbiiRv6gMYel9Gif2sY2QP0a2nsbIEh6pEKlH VS8kUsp6ziBXEYWHKepeROA2 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:47 -0800 IronPort-SDR: 8nMOSDcJMpTzQ5xvPRQlohgN1MXw0TYtqwToT+NUqXIyhYPvpijpZZVjbgqpr86XcLRNK9VrEe aTc2QdR8CfrSf5eHQOfuK2Ur0DT1P5x7a/B329SBl6t1x6dRYaclKQswBTp1mXlQtmvlueHbhB IipeM/4RISIcFvjuG6U8QiizmvnsHiyDhw8QoE53jG34NJ6YdeqNRXb33TU/EQKLI6AFTReKoL sHq993TduBxaamPQRblGzKKYuWffJ4KEolKd1miKLANE2b0wyt3i9Q5EQoP3NrDtyP7NDLPWdM TLY= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:18 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 18/21] btrfs: drop unnecessary arguments from find_free_extent_update_loop() Date: Tue, 25 Feb 2020 12:56:23 +0900 Message-Id: <20200225035626.1049501-19-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Now that, we don't use last_ptr and use_cluster in the function. Drop these arguments from it. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 46d0338659d7..05edd69f5fe1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3754,10 +3754,9 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl, * Return <0 means we failed to locate any free extent. */ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, - struct btrfs_free_cluster *last_ptr, struct btrfs_key *ins, struct find_free_extent_ctl *ffe_ctl, - bool full_search, bool use_cluster) + bool full_search) { struct btrfs_root *root = fs_info->extent_root; int ret; @@ -4126,9 +4125,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, } up_read(&space_info->groups_sem); - ret = find_free_extent_update_loop(fs_info, ffe_ctl.last_ptr, ins, - &ffe_ctl, full_search, - ffe_ctl.use_cluster); + ret = find_free_extent_update_loop(fs_info, ins, &ffe_ctl, full_search); if (ret > 0) goto search; From patchwork Tue Feb 25 03:56:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A79DA1871 for ; Tue, 25 Feb 2020 03:57:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 860A624650 for ; Tue, 25 Feb 2020 03:57:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nxPjCebZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728995AbgBYD5W (ORCPT ); Mon, 24 Feb 2020 22:57:22 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34241 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728984AbgBYD5U (ORCPT ); Mon, 24 Feb 2020 22:57:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603040; x=1614139040; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rn2jZXEY45B3cB+vxe8yFrI8seLsouh27GclU6Cx07Q=; b=nxPjCebZ10cpn/mrSEBBfv1MJDiA8krgFnyAdeEECWwpxHcC3bk916d6 ghgC8eUYw8KOStgKhr4Nlv9B4kRR6T7Ut8cF/6Q3TQ40B7NTtSB1vHmod Jn2YBq39m2PyBPXx0u+dbKoFrDV292iwGGvPuAJJ/A5P4dM5ak5eL/Cmv PltWk5dtnnGMNZ4bhLt7Hiz/UTr/8SX+LoKF22z5cw7yiF2yTtUSHl7WD 9T8Pp96MKpTFf6t6P3IyyRRR1ry+wdecl/VO3XBO1fJPl9GZyWHvv1lW8 MCNtXucvzLpohJs9tXxJTL6PnYMSkmmhjF9xUzOSEQptlab3RHYHbbij0 A==; IronPort-SDR: FY0b5ssDC80qV3iPE56bJ6HKvWMlhfWsWMRLFGX9h19DGmeLXnyBt4z/gNOJbCtmG4G41zgKWN OX+HEeMzwERibCVirqfHT7cjUuRWWagrOSCo+z4gp3RAHrMlep6QW1CKyFPW0ezpG8DSGGInuY pXajYCgMOWreDu79R+MuI6wUt3ZeHNV0LhYrxNa4GALw17Je44rsdFuEXHoGpYV6ZI6OQP86F5 zruT6sS8iQGZbplgu1RE2GD9Vdw6WO9FmBifVUFGx09uy/KAhEmfcwFYl7//P95BOl/Tkk9Hw1 uE8= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168311" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:20 +0800 IronPort-SDR: djicKxs1OKwOxinZ+SdyHav7sSO6DtfOLA9QMsKm5rC2oDNOKhwD/5cUDKz2h4KyscvlrKkd0H PGHD2XeNiOKeP1rRzrC7um9RfCapllSXlGFD3BfyDKQ2nRB6zCEnfGYIKs+101ocPD9hMsyrmV HFMJg8HXLze3uHVLIn54rDAElITpqLkPpX+88BCVbNRhd3w4mfeTvjYPtFylMdZZjo6z5vBX2R 9B/rIoeQOYWEBXHi3feaW6Esefyv3h20UY+vkN56MAmObs4hTma48RgEHocbXvWJsuONPRAl7B 07ujbKANYYuiy4Sl9swSYdrI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:48 -0800 IronPort-SDR: 6j30vn6JJx+CmgQLAmHHANdkENu6Pty5nzfBBcxUztr5vQrTYuYpp2wvpYu/sORgFodIf7u0v7 BQbacFdV5VuPo8z71DiUk5fiZCEjf6nsqNL8OVo0PXTui4Eq2+ElaQM10etBKrD13w9z22jGeB g2UH8nh29W7PyyqUWh7x+zEB6EwqN+NT03OCgQyxK4Oup9gZ0mGT5vrGxHx8irB6ofjEGoJtrT S5K9nKr37V5gB8pbdRJJi1hipsR0fPle+C0Pnbo5Dom3YYul6A+5nHkmvWGMFj/G7WnASj8C8z HyE= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:19 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota , Johannes Thumshirn Subject: [PATCH v3 19/21] btrfs: factor out chunk_allocation_failed() Date: Tue, 25 Feb 2020 12:56:24 +0900 Message-Id: <20200225035626.1049501-20-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out chunk_allocation_failed() from find_free_extent_update_loop(). This function is called when it failed to allocate a chunk. The function can modify "ffe_ctl->loop" and return 0 to continue with the next stage. Or, it can return -ENOSPC to give up here. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent-tree.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 05edd69f5fe1..cb82eaf28033 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3748,6 +3748,21 @@ static void found_extent(struct find_free_extent_ctl *ffe_ctl, } } +static int chunk_allocation_failed(struct find_free_extent_ctl *ffe_ctl) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + /* + * If we can't allocate a new chunk we've already looped through + * at least once, move on to the NO_EMPTY_SIZE case. + */ + ffe_ctl->loop = LOOP_NO_EMPTY_SIZE; + return 0; + default: + BUG(); + } +} + /* * Return >0 means caller needs to re-search for free extent * Return 0 means we have the needed free extent. @@ -3819,16 +3834,10 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, ret = btrfs_chunk_alloc(trans, ffe_ctl->flags, CHUNK_ALLOC_FORCE); - /* - * If we can't allocate a new chunk we've already looped - * through at least once, move on to the NO_EMPTY_SIZE - * case. - */ - if (ret == -ENOSPC) - ffe_ctl->loop = LOOP_NO_EMPTY_SIZE; - /* Do not bail out on ENOSPC since we can do more. */ - if (ret < 0 && ret != -ENOSPC) + if (ret == -ENOSPC) + ret = chunk_allocation_failed(ffe_ctl); + else if (ret < 0) btrfs_abort_transaction(trans, ret); else ret = 0; From patchwork Tue Feb 25 03:56:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2C4D14B4 for ; Tue, 25 Feb 2020 03:57:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D249124650 for ; Tue, 25 Feb 2020 03:57:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="pk+MyDRT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728996AbgBYD5X (ORCPT ); Mon, 24 Feb 2020 22:57:23 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34241 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbgBYD5V (ORCPT ); Mon, 24 Feb 2020 22:57:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603041; x=1614139041; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XWrI90aDEphiiA5Z6NW3K5GOLZGJ7lzPGm1rMKuq+hg=; b=pk+MyDRTR8cPdld1BMIGSK+l8LYDtP2pdezGzriEpsDAwrnhkW1PdNh9 0InzXvuhCcf7d4rsjQlBbzhtYSCHSjKSXbu+UPDvcVYnhOprsCq5MLaNz XEucmN5G4itBrKM+jP6QUzP8ju4e+Zu2ZkwHwNCI8wKfcVeYFB7AEs4dT ZOySLsHnkFZh4Qnsgqz1h8Tk/dusZIPS9Pd47oI+2SRjo25HdZkXoKh4a JWwRyiCW3MSz2Iaf1qpAUo6M8qbZWfvTwThJYKrlN4rssty5oNKWrTcEC pbcT+IZDXP2HpG6Y72RDmGzv1WJQ4hyrXy3o54HcMZs+zq2oidMODjCq9 g==; IronPort-SDR: rqop3zUc9d98Q2yTAY5uSppm7eLvEAAyJW+D84V9upUdn8hNI5UQ3A3Z/q0h6MbhOlT9oW+j+G FJISJMHho4xmTNkKVKe/VXGalHUSJH6K98wYZxA6P3zD0iY8h0Wfcwdx0F/mau7Wmx4Srx+ugV 0F5WwCnY77PQNDlRXQQTxcu/oRFU6EY6YHIfcsw9/7jpTQOKkSv1qUKISvs6OywjIizEm3Gk5/ okXwTSCv92H/ygygKdysnFQ5orVALFOcwlio6TAYxjO9j37ixvzHEOUisl0LhBjQcz3Ee3ZZEF 2Vo= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168314" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:21 +0800 IronPort-SDR: NfO4TinymR6TuEs4ejiuqvmIJUbNsfP8Fv7KX5KP96//hAKNztpgk4MvuqYgYMu407uKeqlR8L TIW//J/TJqISXhhSA2DhyY9u67kbPr94bgF+6WG7CG0u2v/9Kb2kbY3EkXhdp8FptgsLxhlY0K RAyR+SCyKp+yM3Ko1mkMsd7141kxqXYPJ9LeoTiQOsDmOz23eHHyrdmfKCa73zS0c4WFb1MuvQ OiYwnmW4xCNQbFMlLDR7bhwOcZpdQngEXAIPvHIzxYsqQS8GeLZrRhSaBVHYc53q8KhkPPDB/f J4jIwWwu2va3cMp5L75h5guk Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:49 -0800 IronPort-SDR: r4RRgt7DwMBS8zdORmjO7B8i88iZTEm+chR4/S4fhSQcHxuRwwtwwtBnRcDkafBsgCBUr1mCPd kyCWpS08AsPqxDqk5m1xCM7ITWJyvQQkssAe7tCiZO6LW8w9htcPihzXl/GUTUYH4UTDGCQ2+h dzE1832+pf8wxROnpgQL6RKj4k3GOKA4d4j5pvFdNXWRKsryek69Yhofv/7a4VFPcg2vi2nKDw 58hSSxJ73cHE0phPOrfr1Z9oO0omsAmZg2M+nZpFCd5hsD/WwvSoBaR1m3MSx7GFRR4TIiowBl 6qg= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:21 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 20/21] btrfs: skip LOOP_NO_EMPTY_SIZE if not clustered allocation Date: Tue, 25 Feb 2020 12:56:25 +0900 Message-Id: <20200225035626.1049501-21-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org LOOP_NO_EMPTY_SIZE is solely dedicated for clustered allocation. So, we can skip this stage and give up the allocation. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index cb82eaf28033..055097bff12b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3848,6 +3848,9 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, } if (ffe_ctl->loop == LOOP_NO_EMPTY_SIZE) { + if (ffe_ctl->policy != BTRFS_EXTENT_ALLOC_CLUSTERED) + return -ENOSPC; + /* * Don't loop again if we already have no empty_size and * no empty_cluster. From patchwork Tue Feb 25 03:56:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11402483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00C7414B4 for ; Tue, 25 Feb 2020 03:57:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CBB5424656 for ; Tue, 25 Feb 2020 03:57:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="VtXvjIws" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728998AbgBYD5Y (ORCPT ); Mon, 24 Feb 2020 22:57:24 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:34241 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728988AbgBYD5W (ORCPT ); Mon, 24 Feb 2020 22:57:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582603042; x=1614139042; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D/o4C3jAvJlpnMDRfZCjJPHU27WatnH5haOBXeabW0s=; b=VtXvjIwsHxPczzpSOne34AWAbl6cQk9eJ1tOEHoSABRQtlR5zKKzGTgJ rdBtGYEiNvtGxyPHqhsfoqHe2zxEOCihfTt0qruldTVPLASBcTU3zbq5x QcjVqjFtKtMuDj8hveKVJfVyAxgbh+YFTl1kvp3QcUIPp+DZ/DSblykHB asT+OFdW2WPahxSKfzzTjV5XbFXw+8ECEfgF+3BAm29LxkphDzqfcWclH aSHLW329jkbBqdtra3Gt1tUWX7n7zOLkYsEndHhIiD4fZ7K6bT6uXQY9C t3OugJA+lVb9/gLWTKrb7wWpash1RB8GsozMWMFqhtOkZTHuJ34rZN3py g==; IronPort-SDR: /f1drOPCf0gh+1eCfHK2pYk21die39adGsIo/qVQz/dRbPUGSx32MGAsongHT+C1MI5KwTBjgl OqxYaKUbhMxCPZAE19fmpl6GtaXqm96IatOH2MPX2puVooywDGjEZ404wk/tIZyB5WHZ1qloaq IoYQcUgUXU74/XDpIxOMmYrLai2JfZcdLMvanI6jmxyA50hrlnOQvwNnw3lpKwg7j4IDc2qNPy 5X5wvFZKvIOOig9q+mXXOPZC21RfY21j47hZpaHsLBd4+CL5nTe6ZpaSJXVfHl1jSlmjQdjczw OB8= X-IronPort-AV: E=Sophos;i="5.70,482,1574092800"; d="scan'208";a="131168315" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Feb 2020 11:57:22 +0800 IronPort-SDR: C5vn9e8GFqmuKJF4x7o0E/JLtvhcZ/Uax4yoXf1AGASmQRSufS0T1azmDYoZwMVr+VduzDBtw3 tVNTn57x/pmK0V3cnoGZozHG4Zu88Fa7KhzwsDJQwJK4yZjXVNgaK+C3j/wgw35RQCcWNAT1xr mwmxXEqK7DNO37yfTwndaBwzI92McT/zJ7LaSsBzBYtedZgyzQ/UlpX+TinoFXwsXQydSM+t5a ms20LpZ2qaRUrEDO6bCRNCgcSzl+8wScmLeQKbIelpN6PzqzqhBaMqPtH3pBntWrBnAWxk65mR CuJt69nhy/KxJundFyTxoI9C Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2020 19:49:50 -0800 IronPort-SDR: AvEXL6ulo6szn/RhkHuGEOyeZuzdJGy8h7iHHGWdvZES1O+t0FgD00K3kWGGVwEQZeDGnMnCKR vfM/EGzp//Xm5IxkIoKmsVp1DaVZ0TqBoDJv996DTbdg30NeaRkTLNbRHcTWJYvgLaC8ze+x6t 2pfjSJZB7Qik0ojdY7S5FDRDXks/T0Zao3q/Eme9U0bISAxoxyuFtT6Q7v0T2lKAqjoCPhouLR LYYXgu3rK0D7PY+08k8cKMynRBvtYbY4jAed7PCTCrevinVJHLeNNbI7mrVtAkf5ElRjvS9KwA rpc= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 24 Feb 2020 19:57:22 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Josef Bacik , Nikolay Borisov , Naohiro Aota Subject: [PATCH v3 21/21] btrfs: factor out prepare_allocation() Date: Tue, 25 Feb 2020 12:56:26 +0900 Message-Id: <20200225035626.1049501-22-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200225035626.1049501-1-naohiro.aota@wdc.com> References: <20200225035626.1049501-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This function finally factor out prepare_allocation() form find_free_extent(). This function is called before the allocation loop and a specific allocator function like prepare_allocation_clustered() should initialize their private information and can set proper hint_byte to indicate where to start the allocation with. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/extent-tree.c | 110 +++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 055097bff12b..1340485b392b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3866,6 +3866,71 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, return -ENOSPC; } +static int prepare_allocation_clustered(struct btrfs_fs_info *fs_info, + struct find_free_extent_ctl *ffe_ctl, + struct btrfs_space_info *space_info, + struct btrfs_key *ins) +{ + /* + * If our free space is heavily fragmented we may not be able to make + * big contiguous allocations, so instead of doing the expensive search + * for free space, simply return ENOSPC with our max_extent_size so we + * can go ahead and search for a more manageable chunk. + * + * If our max_extent_size is large enough for our allocation simply + * disable clustering since we will likely not be able to find enough + * space to create a cluster and induce latency trying. + */ + if (unlikely(space_info->max_extent_size)) { + spin_lock(&space_info->lock); + if (space_info->max_extent_size && + ffe_ctl->num_bytes > space_info->max_extent_size) { + ins->offset = space_info->max_extent_size; + spin_unlock(&space_info->lock); + return -ENOSPC; + } else if (space_info->max_extent_size) { + ffe_ctl->use_cluster = false; + } + spin_unlock(&space_info->lock); + } + + ffe_ctl->last_ptr = fetch_cluster_info(fs_info, space_info, + &ffe_ctl->empty_cluster); + if (ffe_ctl->last_ptr) { + struct btrfs_free_cluster *last_ptr = ffe_ctl->last_ptr; + + spin_lock(&last_ptr->lock); + if (last_ptr->block_group) + ffe_ctl->hint_byte = last_ptr->window_start; + if (last_ptr->fragmented) { + /* + * We still set window_start so we can keep track of the + * last place we found an allocation to try and save + * some time. + */ + ffe_ctl->hint_byte = last_ptr->window_start; + ffe_ctl->use_cluster = false; + } + spin_unlock(&last_ptr->lock); + } + + return 0; +} + +static int prepare_allocation(struct btrfs_fs_info *fs_info, + struct find_free_extent_ctl *ffe_ctl, + struct btrfs_space_info *space_info, + struct btrfs_key *ins) +{ + switch (ffe_ctl->policy) { + case BTRFS_EXTENT_ALLOC_CLUSTERED: + return prepare_allocation_clustered(fs_info, ffe_ctl, + space_info, ins); + default: + BUG(); + } +} + /* * walks the btree of allocated extents and find a hole of a given size. * The key ins is changed to record the hole: @@ -3935,48 +4000,9 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, return -ENOSPC; } - /* - * If our free space is heavily fragmented we may not be able to make - * big contiguous allocations, so instead of doing the expensive search - * for free space, simply return ENOSPC with our max_extent_size so we - * can go ahead and search for a more manageable chunk. - * - * If our max_extent_size is large enough for our allocation simply - * disable clustering since we will likely not be able to find enough - * space to create a cluster and induce latency trying. - */ - if (unlikely(space_info->max_extent_size)) { - spin_lock(&space_info->lock); - if (space_info->max_extent_size && - num_bytes > space_info->max_extent_size) { - ins->offset = space_info->max_extent_size; - spin_unlock(&space_info->lock); - return -ENOSPC; - } else if (space_info->max_extent_size) { - ffe_ctl.use_cluster = false; - } - spin_unlock(&space_info->lock); - } - - ffe_ctl.last_ptr = fetch_cluster_info(fs_info, space_info, - &ffe_ctl.empty_cluster); - if (ffe_ctl.last_ptr) { - struct btrfs_free_cluster *last_ptr = ffe_ctl.last_ptr; - - spin_lock(&last_ptr->lock); - if (last_ptr->block_group) - ffe_ctl.hint_byte = last_ptr->window_start; - if (last_ptr->fragmented) { - /* - * We still set window_start so we can keep track of the - * last place we found an allocation to try and save - * some time. - */ - ffe_ctl.hint_byte = last_ptr->window_start; - ffe_ctl.use_cluster = false; - } - spin_unlock(&last_ptr->lock); - } + ret = prepare_allocation(fs_info, &ffe_ctl, space_info, ins); + if (ret < 0) + return ret; ffe_ctl.search_start = max(ffe_ctl.search_start, first_logical_byte(fs_info, 0));