From patchwork Wed Feb 12 07:20:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377671 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 D0A5B109A for ; Wed, 12 Feb 2020 07:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF22F206DB for ; Wed, 12 Feb 2020 07:21:01 +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="cBAolUIw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728291AbgBLHVA (ORCPT ); Wed, 12 Feb 2020 02:21:00 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31626 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728234AbgBLHU6 (ORCPT ); Wed, 12 Feb 2020 02:20:58 -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=1581492102; x=1613028102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bC1YuEFrwP0s9alZ6tyPjEsEGuzZXo4rtDBMqWXlLkU=; b=cBAolUIw0VAfnXzPCKS5OrAVeuLjgtPccj0TxZ4oCZT5ZnPXOw2cPV4J uo6Q0GtakG3uDasJllUbqBRyRFZM01YjRAuY3yR6b8tVfIBZbj2j0tYuX L/8oBHEBL8NFYKyq2eSHy72TP6g2Ub7m/EamNgqj+BqJU/bL819E0DQyz 6nwZf56+ObB5H03gR7rPc9yjPjznvQg4gh2UPBptFS1dNlyk8y6W2SUJo KYA+xjbwiY4G/rG4iIUOmIuMj9jCN4NR7+tDMe/nlmdsgp/01zSkHphQu 2Ga3jwn0+xIECwBYqjsYKUhbFYnG1cbsq9i6QzhNd+NaY9aHQOLEfE6JQ g==; IronPort-SDR: MhY7xNFawjNUVs43l6VeOKCay/5JOcE3uJqb0TQ5t6QnIYXYM6U7GOqleFIpS0EQqu0OSa8fov fyXAy280WTEmhPPC4cvGCG/Y+TK2tSV60ZzGy3uPJWW6PUzp6vmqXRJAJ2cEaJiD/eRRc8PYOZ hVzlnI/nsvldFyg5qRIz0b9R8xWFysVLHtxSDNYcWIw/hZpVndL3QIiByKw73ZYMZVSbd6QkjI tG7l/Wf4SF16rAHirxaIDX1Ew/ze+xkt8Id32ubP9BVCH8BywXfu0MzaAPEIXT2Sx221aGG0vD iT0= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448888" 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; 12 Feb 2020 15:21:42 +0800 IronPort-SDR: mj0l6Y5ZNkO/1ikVBDroW8dwzTAtiSqFKFd9nkCbml4GeLRzJBUcHle2ITePRIlV7Aktwt0R5Y 2VoOl42xqLspy0NukhGBoQK2JJeTJr/I7cuWJxq9IABgN5KllMIknE4IKIfnlVzH6R49lnD1RP Q7vWIDdALfA7mO9WX+dKZZF/axwivp77qCa2RRvWLAf9l5SNBFTOA+3x2iDA/lXGhlhRQE9ZvA 3XGEKXpi+CvigO/GFT3m8gZPhypcsCqPXU52ufGTDGXmSPPnzDJNn6E1oJLvQeq6pXhqbOH+PB 95vCxckAygViYe4ph811Eh0Z 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; 11 Feb 2020 23:13:47 -0800 IronPort-SDR: aJXUn/usGgeUj0zO2RU586+3NNWl2XiHmoCviv8I60vq9POlNk3u4AtwW2K3ng9/B7fLuoM1g7 zcuMkbdqcJ3vpu8mGWTN5Sej/GnUDgpsYTtkNpv4oZPDhQyLWKait1jahnkKV8pMsnCxnMVeJB jhdkz+d5bnJ7OxgEyxuomcYT11zot85zUBETyCK10qisGfkpgNqRh9mGYLdYlSuguP+pMLC9/0 i9Milh8NI/U1qq729qFaT2E2l39S+YfsUbkkHU5FVxD/5zD3JtCc/3RxweVgjNN/NqcSxtmwHy eCk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:20:56 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 01/21] btrfs: change type of full_search to bool Date: Wed, 12 Feb 2020 16:20:28 +0900 Message-Id: <20200212072048.629856-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 0163fdd59f8f..227d4d628b90 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 Wed Feb 12 07:20:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377675 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 7888A13A4 for ; Wed, 12 Feb 2020 07:21:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5727F2082F for ; Wed, 12 Feb 2020 07:21:03 +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="rXZn3K3A" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbgBLHVC (ORCPT ); Wed, 12 Feb 2020 02:21:02 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31629 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728287AbgBLHVA (ORCPT ); Wed, 12 Feb 2020 02:21:00 -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=1581492105; x=1613028105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sg3sw0GwYM5quUvcsTSk5b2keVv2g1tE2y9XafdPsiQ=; b=rXZn3K3AEjZdpqsrEIze6M+GlJ73S+ql2YEV460su3HugjuNf7OtfRst dNRExq3EZ6v7FtaiiuW2sE2C/QpnI+Z8R6InvokMRV2aUixfH9FS6TcTN KNqM0QlAOJfd0D449mzb2ZHa8H7lcOkMHJwBqivmETEIOkyGyRD7mLgrJ GiDb3HPLzB2H9MS3c7M185N0HuqWPdYC6Nluv01Sc6D7+d4FRgwceCV/v x61y2U2ALbzV3Khvu4dAotRDhib3+Hb061HltzQBZA3x+VRxZQQ0b/q+i 8dsaIpv8lTeDDojd2fKMEiimJcUi5lQPP3IyR5HZ3SxG329MhGMslcaQU A==; IronPort-SDR: 5foFczpggHzay0f8OWCbmt38SRxPM5ghg6Q9tX2HuBnM0YilUD/R1v6UcbQ8DcwKxUB440VH+R 9xwF4hUKCJi9n8E+xw1g7fKUJhdGqLaCdHw65yH/EWAcCbMxAsAUh8pZvrtd8D0XmkvWNwgzp4 SvNmKx/lsY2lXbFed2vNNKghVhDGHAoEE2nuWraYyWqtbJIOAwpu4WYYBgo0VLdSUKmEO+GfYK br8CYhyqCXAsePzUWY0UEsmQNYtVkqBlva9AkdM6EEnDKqzoZzBaoiUvmFDGxHcyWsOaz1nGJX gAg= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448889" 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; 12 Feb 2020 15:21:45 +0800 IronPort-SDR: 773n2juG0ihvzeyJGobH9bURr8YLqu8Q/8bjrg3leSthwpVxIlxeExow3SnAPDT2QEQhsKkXtc UVil69CahpgFmqYsjZtQjAE1LiuRHtyAQMDh1jf6sHxCypJqwcYjIDg4VVuag8zPjOMg05wEqF MKTkQdVyxc44FD8A1YUfnC4Q/1FegsKh7HzDU1Crn41voJa4IiZyamEgdjiX0vZTh0E0y7o92Y PhHqf3KywwUF6FS/0bqgHXYc/Daoia+2VOfSvVjrIN4CZEUabg1jytZea/xUl1EAhxkk4mdeXc HvXOqG52JIbxAtHTxRpkySw4 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; 11 Feb 2020 23:13:49 -0800 IronPort-SDR: g4S4aosLn0WZQChAyQ15wsyAz91PX9T83SFra3sB2KZ7Yk99+Z3nCMPteEhweUu8+j9a3NgVm/ gfk7ET5yb17oqK+6w1z78lxNP7QlOrHNGYOsUA0V2ajTjLF6UPxd7BFZK1tc2cVyDBzVlhxwyN fsEQMswO5zQb9zJi5jwGA8vDQ+7tu4TNv71q/dvdF4FooAKXmCXUWLiK9fGLPbDmmbM1mMNkje +eBdUnDqfJVQXe34kDfD52nJTR3wA6YRGlwfGbfmwVgANG6kh+J0RzVGFD7dxEYV2nJZXgN7BC nCA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:20:58 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 02/21] btrfs: do not BUG_ON with invalid profile Date: Wed, 12 Feb 2020 16:20:29 +0900 Message-Id: <20200212072048.629856-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Wed Feb 12 07:20:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377679 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 5AA4913A4 for ; Wed, 12 Feb 2020 07:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B9E72082F for ; Wed, 12 Feb 2020 07:21:04 +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="euxG0phg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728311AbgBLHVD (ORCPT ); Wed, 12 Feb 2020 02:21:03 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728287AbgBLHVC (ORCPT ); Wed, 12 Feb 2020 02:21:02 -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=1581492063; x=1613028063; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rrs1IxCVFhT+utMagPkDYWaurfisiAV/cxE++oBN2Pc=; b=euxG0phg9jHq0BTXx+a+yL6HpmebmNpn9juhHZV7vA+l0sCTY77JvWTn AACtsPLRmxMxYHblCxPVRAgvbDFKPad5D15446pZqhFHiXYTr0SYZeIMo kfV8kVOVpM3mE9H9uhwzL4YIlR7crrVBSr6y8T6I5LFPYPr8NQXcFDM1s kevVesL4hLP2Ic7sGMyzzGE0IYm0v2dK3ez09stwXIBsAWnT6id3acxDo NJNOp5P7ke3kngeZ7IPJMocPX2LZaFpc/MYK/a0J9hATXvx2WKQm4JckY W5mNj7mUaJhHUXNlVZcCdxznOBEtmmpXZGSwHyQvueDXdKsPXsIKILdry A==; IronPort-SDR: xRD45+cnoUE2tz+ompH0p6L5MppypSY9HKvnoZDydoo8GB+p3dniRb83dCyxeeQz+QKgcx2dTM VAio4NNfnhutoxa3TVxdlpm4upFQgUHQ3G5P9805u611VCD+Y+aeXHsrZuahP39cDCG+ujbeNA Mdi+3zo5ey7FA+KlirHX3YWEPGJihpTeMhpN/ozv8nWvVaA5bXf7YPhFCa5+c17LaRGJIN+qLn Bg42jPDis8yp1qagdwvFy7p5Wb52FQwG76PyGVx5acI+EuwqIvpsp/Pb4sEXB6TSS1paD71EvQ nMg= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448895" 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; 12 Feb 2020 15:21:03 +0800 IronPort-SDR: hH6bS46+1DiK06inmBoSMAx+pKTkToiNUuFPgitqkS0Rial3/qOhXew9IDJ/HH0bIVTAjWhhi5 eLsd0CM2vNHCp2UG9EGM9GD6LV3R1feZK1+IwTr8XgpG66udtE5fEZaIfuRYCLvP0k/y4zYFEY MbhoBGZ05h8/e+WhhEkObVlTWsSVGndyYCOJ3L5eSOfV6E/YyMxhvT8nOh7/dijcen6exk5UkU kY0qTZaGAvVob4ISEBpXmRTMYOotnd/DTm8f9ikwjN6Tw9ZZKv1iEJoOYuuV3HN9TWmTSL8yt9 P/LrPYZhfyZPMAxYVlIDXLDj 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; 11 Feb 2020 23:13:51 -0800 IronPort-SDR: azjS0I6T1A5C/SZTHI6nZWsHm3m4KCXLJZCCyBTzZbK79szA/+9gbk2UA+HiNZu757tvXIVOuD pl+5oyW1bZNuoJb8uTIcJJ9ux/8m1l1wawh4TLQapdd7qNK3smtc1IMGYWoBeWmFrB6/iSF6Xj 7fc4klFgV5caiV+5Sr/lf8YRlu1gM/VeRjKOrbbOnplKo+oBGWnZ29KjK4pFqqTgiw4WViBNY7 D17/SreAvpZY5ccD5faaNSn92C/oU9bAJTmej7O95rEjtjic5jETILdYiwJSowg3wlD0oSQs1f 17M= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:00 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 03/21] btrfs: introduce chunk allocation policy Date: Wed, 12 Feb 2020 16:20:30 +0900 Message-Id: <20200212072048.629856-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 690d4f5a0653..f07e1c4240b9 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]; @@ -259,6 +263,8 @@ struct btrfs_fs_devices { struct kobject fsid_kobj; struct kobject *devices_kobj; struct completion kobj_unregister; + + enum btrfs_chunk_allocation_policy chunk_alloc_policy; }; #define BTRFS_BIO_INLINE_CSUM_SIZE 64 From patchwork Wed Feb 12 07:20:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377683 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 57E2213A4 for ; Wed, 12 Feb 2020 07:21:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 379A12082F for ; Wed, 12 Feb 2020 07:21: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="eEPgNgP+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728322AbgBLHVF (ORCPT ); Wed, 12 Feb 2020 02:21:05 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVE (ORCPT ); Wed, 12 Feb 2020 02:21:04 -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=1581492066; x=1613028066; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R54Qn5BYD/ge6T31YZRw+ymws8jMNomjMOABX4oxaIQ=; b=eEPgNgP+2w9bdUgxsWh332xJq38MEcEnc/ABpzyvc3FfQaayEX1zEmkF 6dk6BHT50pXMV7XzT3J/871PQNR0nyIEsT7e5wzS9Sl1J9NPYP6fYLc4c Pd1eS0t0rQkbxs2RMnRfSOWDN6lXTZ5R58wyLTxZDlWzzanCSnPp6pPGw qvGi2feJDYmj2/nAJx4zwEbRjd5hOMGLneA95mkdScjHPpskUTv7CGozb IpxNHRtGBNWW6GjJ4FKNOxmqL/OQAv26rpwwhVersHGI6JgUzmLgrndCb 3dvsoOv35PzG7S2BzdER+y1YIu3dGL8wej2XHawNIXEQ6OmuSzBdaZ3TB A==; IronPort-SDR: 9GTPV8F56e21ICsYPiEgHGrgnh8qgbRsHOSwcgNPAiWF2ERR7IVH9ss8dU7HCUCKlkiPAhhMZO SkeyG1lmXoUUBuORAY7VKCQsRktySvlaLuKYjcZcl4L3PI4oCz60jnDYrPjRH5PIPerWjgbvb4 0Kh2mGxRtxtWtDBq9bxBkc93CgHz2Vl+RQIch1wIkzJ68rEFCBqp+YnRe9sEK1ZoKeJMlEkOZS nODMOkI1mBkeSwLArpK+nfdUe6joPbCkW2S2LXChMjnp3SIp1xabGVhIyONImYd0prsH5yZnNU YD8= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448900" 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; 12 Feb 2020 15:21:06 +0800 IronPort-SDR: 1xGISZkL5R/dtpog7/CWjCvzQrgylaYmlTLeoAAl+fdFaKSqyPttFqLYWUoBMDA+s15NB4eGrx GNLJRuKrbQJeOL1n0poytaMxkoyLnn30WJA2dW2unMYgyLoDp+cZz3iy69epJ16qsDZRFV6+61 cSw5lXv6NWUw6UCzhbj5ak7l/blvslfvb5rd4pjLCITnLrtyNndtsiP+niBh3SfSGGoq93xC/z D636RIPhd7ZlELMakMBHtwi+AxWBTWFB7aP3qZeUmLMGwmESZFbKOXjoRCHh8XmFIkDdsgfDrW B0IlpOMAqTVv3FaYBiEoMDEl 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; 11 Feb 2020 23:13:53 -0800 IronPort-SDR: dZcfl2fTn7jL6aMVpYXq2nAiDLfBKfBhZVN7Hilg3q36HwJkz660aH/oQ2H4xaslWvQjLS/bS+ LFT8aQcR7zaFWY6XAb3x8lYpOGF/OsCKeAGjWDLe8uVyzt0lNcxbD5no7iX3Um/4MJSif8SYN3 +xvL0z6YCxDWnIHPgoh0kKCngLcNuC5eu3KN2ZrDJYpIJwOBiG2VhPAQigAXdZpD0h2vtfph8f Ey94GcrimOWM9L3TT/3VJON0YexG+cLeWGv3vePY4Sx2OeN5HvFSDc0252BX3HYlGVcpwjcRWx BPk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:02 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 04/21] btrfs: refactor find_free_dev_extent_start() Date: Wed, 12 Feb 2020 16:20:31 +0900 Message-Id: <20200212072048.629856-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Wed Feb 12 07:20:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377687 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 5B93A13A4 for ; Wed, 12 Feb 2020 07:21:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 396812082F for ; Wed, 12 Feb 2020 07:21:08 +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="E/YAmq40" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728332AbgBLHVH (ORCPT ); Wed, 12 Feb 2020 02:21:07 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVG (ORCPT ); Wed, 12 Feb 2020 02:21:06 -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=1581492067; x=1613028067; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0Fb8dCjWh/50mEJ2+lkYYY0sYLpUsEKse11id9ocHvY=; b=E/YAmq407/VVmjNFW0c5rtRQi6DUgww51BpsqU6eR4ohnL8umYzeTYdM 33T+jTkxV00lIbWHDCDVGEfUrzQ2+kR7jdlQssdRg59YLPx7/jYxFvD7h CFy7fzaJkuafo6eF+Fw/oH3LTyBJ4TiYjXQT3oQKEikyUBHBwl/74FpQQ ygZEBuJvxVtyphHnrIcjwWBN+nhB0EuV/Y1A8mcv+LEV0tcEM2/jrio8b HoLczpUn05ySGi8aAxeLIQAflkcNIpI9bJ/MSsKuKuXpLl299AOrDDgei 2DECm3iGCxKkqM8Zbe2U+MDM/K0rr26XYv3tNGbkrQSyU5WhGrU2xCJKN g==; IronPort-SDR: fkgYb3/3QckDyNP+7j/FyPIqXbSmDf2XcYUrm4UEgwxDnNKzoI/O0OKvXaqRu+POGrdPinNZlH jnxXazigI+ASqgQTcYjY99iU+tXzqP5HGs2x4CXs82ouE4ziESkme/E9KWnMZVSNxchTuPrdEN SMekK+sy/IRjOkWZUNwtQwoEtMZgbanhbPe4KciDyyRXFhPentqllOll5LXCVg46jiX4LC5D3G B2uPMoR1WmM72u0jO6WaLkspWCU/XPwj8G9cXVkO6Vx0n/maRHjWRDbLho/1u7LZPZ3ylZEKib ETk= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448905" 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; 12 Feb 2020 15:21:06 +0800 IronPort-SDR: wTxVppLMS7nHf+ayxN8klNHqhPTUCuokhJYKm/aBRovI+H3Y8aBlO7n+WIHbOlGYFczQbltQo0 Jl9IcnbIu9BjOcUH5rNz+uPrHz0mjtOV2a65/Gk4aZzh5oISV1T1zIArU4fyJYwTKIVMEnVKAQ 40shLNOxNmrTYgRWOH1EvnT/XE31UBkjkfY4hxKsyM3wcnoQGBuoqJZcU/KLukMwdgFKzViNS0 lUBTqqk5CunKHDJBnJuNUVil5wZGkPTMRZCm9pVD7P+R1NJBlCw/M/f3v9oNwhMfX7zNiEQ06L XVH2+o+kDYGM76rPzQmo9uhU 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; 11 Feb 2020 23:13:55 -0800 IronPort-SDR: 8jjY7AjmFnut5Bx2N3JaVU1WBTsB60kbmirK9rumoUtpwYKQGD36+22++JU+wL7dClgX8jZAVq k5sDiU/Mh5hqWKlgJhdimcq1CpuAOnwhBWda13dEiCciwJun6vDcvXwFelMSt5u4o8/0lFVd2m 0eUTqhP/sFzrd+MG6MtbeVCxbV9jYCwTy7O6WCiwWu4oEh3Mse3iHweb2U1bYamgSKL8u5ycz4 9p+gZ7haM01MOv2lQJfKAhPtzf4mlDsOjud2oEuOhId0rwW89unxVJDU/uOzIvmRikIzYUOi+0 dv0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:04 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 05/21] btrfs: introduce alloc_chunk_ctl Date: Wed, 12 Feb 2020 16:20:32 +0900 Message-Id: <20200212072048.629856-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Wed Feb 12 07:20:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377691 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 C168913A4 for ; Wed, 12 Feb 2020 07:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 97B042082F for ; Wed, 12 Feb 2020 07:21:10 +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="Oer5Jc+W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728344AbgBLHVJ (ORCPT ); Wed, 12 Feb 2020 02:21:09 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVI (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492070; x=1613028070; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V1d+9QvPZzYOzOKtSVHwxfSzwOvw2zonQshwL92uXyo=; b=Oer5Jc+W63zq44SAo/8n+zGusVXc+HQ9mRK0gf/d/+K06GPXtBfgpzsQ F1ANI0IAzxVAVw3tncobH8s3ngGuGz7wvQwBE1d+T+sysUOOW5QvPcXUR wRIzQ9RZZVQ8kxXmRby7TrLvnGqaKcm7mB34qk6ve7bp4ocRxGdBs4rO8 /n81nIUkkRZ5hlDTWhw5GMthkzZnqX1TohbmNc/bvi3tRL2bdKB86qq8y Yrvl9ii9fyuLJKOtDo3DJp6mTXf25ctgiaptrbmaq1CAx75dSEBk+SQYG hVIyYXD6tyW2//AaxzWz0RmPGXepIUBrX4c1mcoT8q1H5s6Wi7sRM8QBY Q==; IronPort-SDR: LJE/msJ9s/U6oJnpXRAlaJDrmFb3mTbFQroxV5WeMQZdQLkKJH5S4L5CLldczOIHtRj5USJfVU g2CduQ9pyM9/teKDCfqAC2pXmb6hv+IF8h6tIQpJuYQnG1PqLU5BTcvAIUKMRTBZjxKU1XPmPh RFL6rcTgjalr9durEVFMcq1TtEiexFP9TpkjZGE7PYrdSFHLyO/xqFjY+Z/nYf2tR14bdnJ8Q1 2OdUbeAxb0EIzZ/BvoO3yCvSp73CCNZAK9wVyUwn1mF+cf6vREUYoSBBkL/OQobr+RBJgoWKQz fqk= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448907" 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; 12 Feb 2020 15:21:09 +0800 IronPort-SDR: kbIFtWge2GdWRykNYkV4sTaEco1gu4QKqebgcD0c2lxCjQdqdR9zTJM5wGycswD/fvi/8xsQGj G+KrPuGv8zrjoHS9z7oJwZoT20GQrV89/tUCFVmhnkLkrVSVwVMxPedkey45c8D3fdy2YkPCy4 6dK4ea9IbgXGji61ai3vHma1r1sA0cfCeO7dKLaFcSF5aSkLBAVz29L51Mb1v/OYEdNzNAq1oe INjaaUg1KBngbCFFLAqcBiLPFC9ryASb8EBgNIhQgra3mgDYRKCa0WOUYDdsxcFNSkB+L1uNM/ I/b/FC/YPXN4tnC0Zdt4yKHR 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; 11 Feb 2020 23:13:57 -0800 IronPort-SDR: /yvPCQn43nPQ5TuHM9tpfsRNQlM0IaNCIADbr1kKXZQErCndMvOtMBRhYsjpSeh53uisVkb962 xCgUa1cia7El31GcDZFnu8JJbTJOiQwG/bA2+j031Z8AUgjtFTQCvDtOgBBw8esUDl/Y4jrquc S8arFjH/ECTo7yznvsxS4EqWKugmbkBfxez9e8XlMH93PyUhQSpB2yO0w+KPel1ZmPzAIrnb++ lXLFs2DWHRJMBtO9Ad3oBps7aqoRnRnmwzMaEMg3d8FG620iY+JxpGdzvxmlE1MuGu6Q77SRQ9 bVY= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:06 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 06/21] btrfs: factor out init_alloc_chunk_ctl Date: Wed, 12 Feb 2020 16:20:33 +0900 Message-Id: <20200212072048.629856-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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. Signed-off-by: Naohiro Aota Reviewed-by: Josef Bacik --- fs/btrfs/volumes.c | 97 ++++++++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ed90e9d2bd9b..9181e3ab617d 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,14 @@ 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); + if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(info, "invalid chunk type 0x%llx requested", type); 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); + 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 Wed Feb 12 07:20:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377695 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 E709113A4 for ; Wed, 12 Feb 2020 07:21:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C58A12082F for ; Wed, 12 Feb 2020 07:21:12 +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="qUUdmmoO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728350AbgBLHVL (ORCPT ); Wed, 12 Feb 2020 02:21:11 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVK (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492072; x=1613028072; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AuzFKI6hgcGOd7SGkTSu9C2SqC7HD/T06gRVqp8IFPY=; b=qUUdmmoOQQi0xa2xFpfSsJSw0sjOGiYV/ip8azMfIXrMWUQyl8Mns2RL RRLi6At65n4Dg8JRNMXXQnPH7KV/t5t3S40pLB5kbm3rap3bH//zGx16V FaaSEsMUyahKdyKHCunWF7ZMrck8mNmA6a+jQatU98RjaprkY03xPuv6U f9/HfWmLKNoAoqnEw6W/3ZaTTS6FEFE6cCzIBq2QabXU9ZJsyeIfi/ZvL n+8L/5ACnRluVUm8n+pCBShcLfIWsijRnWttMUeom6coXj+up/g+rYl/A urrhHE5kRjRjod+9Ota94A2mrI4cy4bUeM5cfwxOZb2W9W+qspWSL0/Wa A==; IronPort-SDR: VIx20YpDFq3hz0F5rAQZE4WDO8K7sqzSAY4oGPwPXTdg/hHV6HXcmLXrXqWDIQFI4bdEQyNx8o fKK1CdNP5fxyJv/kGQSo0L1DSzTS4Uz0ZrF8pqnJTJgJFcfxbXvy8Vyb+z61D66ZLQL+6dcRJt uhHTQvuCXLDkVxjDkLHHmvr8wDez/4K/s0WivEZdFNdDOhlZdhooPCuNPqxeWcvhlhtcNGpity L5pLe0ER05uqE/rn54p8hRhLrM9V3+/1n6thRXX0dgHmQw2DVocWEddVcbfsAZauL4RAK2G3fV qec= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448909" 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; 12 Feb 2020 15:21:12 +0800 IronPort-SDR: ZrzKco3eStSx3G72Zdq8hzysDRnKXZ4vXznnBspaeJh76+sneOI0wR9yJZ0WKSizLjHQpnrKny a0VYraJruix9OMXbiySi7Q3Ub/b+kktCrmOgZxj4AgkmefCI6z7eXnVGMjEYqsm1wGF6TBXpif N032b78aWgkCYPxfRekLzSrkIPUBhEakqnudftHA+SAPf0fdh6So6GtPwemLsqSkGGTb6SMxCW OwMqsiPr9S4lmGKzcVeQZmzC8GL504gjEm/dEvMUrhzPgRTan83djgHurexJVTCfDcp7SDOt5u PbbKOLtFd9Zm3ShA5NtF6iaS 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; 11 Feb 2020 23:13:59 -0800 IronPort-SDR: f1i1mC+St05AyXq2WqAHuxQWpT5MJWTw9b5RY6G8S26cF61BOP0PmnKHaRASD9izUMIEOOcHak feBvCndMAZd8pjMqoAgAJcIsgXeQfA/vcorEB6taLchutOpmIIVNS8oULYsOG6KlWW5Kv1SgK3 Qkvq6cJjNdeJtNCF93+aA4c0bvHZ640qUIuvswL7ykOYSwTpKwtLKP6V8Qp0Z5/QRHS5GHKS19 5MBhkldJl+y5QRRWh1JFq00U5b3SlseKlvtvXt94G8NPzf9XmNIJDR8sZKaUOyMB5tfcyEyNGi Isk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:08 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 07/21] btrfs: factor out gather_device_info() Date: Wed, 12 Feb 2020 16:20:34 +0900 Message-Id: <20200212072048.629856-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 | 119 +++++++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9181e3ab617d..2bd3ed830a28 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4896,59 +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); - BUG(); - } - - 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"); @@ -4969,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; } @@ -4998,14 +4963,62 @@ 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); + BUG(); + } + + 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 Wed Feb 12 07:20:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377699 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 C8BCE13A4 for ; Wed, 12 Feb 2020 07:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9EA9F2082F for ; Wed, 12 Feb 2020 07:21:14 +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="k18lWZm7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728359AbgBLHVN (ORCPT ); Wed, 12 Feb 2020 02:21:13 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVM (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492075; x=1613028075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Z5J3r4zGFRGNFn0u8ZAVRF19XIMYrkmLlIpuh19RyZc=; b=k18lWZm7y+9l4YS6a/O7HZ97ZvTq1EaZd4/V8Szlv5ddn4rLIlOQ4ziY IqjA+POuRGKBO60S7D3PxHs8El8VdCHoB8WNSWBNyZpiriLomxR6/kJkz 7SnkitKv7p6G9hFqlhGCrHp+d6xgUFJk9Z86dxRIETdYAlD7h5asUAXVb OSBfngnK6fGmKOCP2FjQsJvHg2SmcQnVHtYwW1bVwvMpCEO6rN6rHEt9N o5TETsqaY8ArtTLc73V9dchRV+UGYex6KWv5ZZTOdmux1w4yHVMi4+tbk f2LNOKr33U5FhBJkkklg+USI/4SBgnUuwDhjzdTspu9DgtATXs4g/JBnK Q==; IronPort-SDR: 7nQl2c30WI3iQUSBjwy2e5PLe14WDrQnoqavAYfnXbtqJ8COw3z+L5KOdKcHO0838LLvdSvHJc Oy/HwR7MO7u3FPxQTxqigDhjTO9ARn4LmyJGYKrn5v2F374Rqh5gFNy6iXOLwpaH3b9PVwMKny tSesQi3BZWzivhiVTncxT1NwZZyWj8vn1lwWlTe75atAWo0/hf/p73I917Yc0ajJBta3t7zqHs y+B8Zj5zdDznLI5+RXzYQBKWRYxrCkqsyVgaoIzCaCZi+rthcnTUas62zKMdWANHZhemv7ap9n eJo= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448910" 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; 12 Feb 2020 15:21:15 +0800 IronPort-SDR: uGycJsfhsii2uqSu3rzZtIG1FsBpiSrULayyF5xr4l6C3ZelHG7flDR0mg6en5yLrtX9XIbecF rygLw+mcKRLHIXGzonAjo5vK7YIy/950+UAiyq/mrvjo3JlYtgMe1MHl9+tBIPEdFmcluCl5k5 FePwSLAwmFZ591Ja9u+LHZ8eUIrbEO5wOqOJNIiqmEi4YEcKVyDEwJdKy0Mn4PPQY1P9me2/R2 mhQ5wEvQRghWikWYi35miDxJKq7dWHPioADG8ClL3uPHOIDcaZyhubfafa46+rnXBoNYLv0Q7g JoDByPMYfhlyh7zdT9QlOp2T 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; 11 Feb 2020 23:14:01 -0800 IronPort-SDR: /obRnkoZ62xQNEcg3Vw2rjAN1MO8bSfAVqvLT0rRUf+Dn9XWGVnTG2gspVlqfU/aTIX215NMQN epLxEJMRufjh/cjF94buYWPc3mrrisYXdMbus36i1nzv9XOT34+Qo/g2i4DOyZ5P5rJSqjIEKb 0Ydm2i/+eyqFM2d/kaNQgs0UD8hf1nAEJPiKOLveJ9eol2YhBIeZI6H03g/wKWknxaR3oCIkX1 HrsBG2HfmH8xkJsCX5jfD9pvNDeE+DKYOgwgqGsgI6hx+8N0fe5vTms/SMoDxcNLFDHGl2pSOf 6c0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:10 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota , Johannes Thumshirn Subject: [PATCH v2 08/21] btrfs: factor out decide_stripe_size() Date: Wed, 12 Feb 2020 16:20:35 +0900 Message-Id: <20200212072048.629856-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 2bd3ed830a28..00085943e4dd 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; @@ -5019,61 +5095,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) { @@ -5097,8 +5121,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 Wed Feb 12 07:20:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377703 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 A745413A4 for ; Wed, 12 Feb 2020 07:21:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C9542082F for ; Wed, 12 Feb 2020 07:21:16 +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="LpFb9MUH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgBLHVP (ORCPT ); Wed, 12 Feb 2020 02:21:15 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVO (ORCPT ); Wed, 12 Feb 2020 02:21:14 -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=1581492076; x=1613028076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ye2SKlsfzwS1oBfYCAJOotkkeAlWpJ1dzlzFlE1InAo=; b=LpFb9MUH3IlMiTvVgzJDRyyDUUSAJTXQ4lMhKQGHdvYsxXo2snx9qOCV viZ+JY/20hsH8OcVDLMIbqNDBmo7jDxxUDqwps+rydB2xvGjwqeH7ijYI QeogO2FKKpFNJ5sOiqDZmZA+mhEMdtBDrE81ct3FOP0D9Y7UFQSbyUqOF 9Xt8qCsVI91zIjD5TRpm2Ue6v8Huvof/NJkDNXwfQ9iSWBaT5b8vGqxxC +9/5hHXNYuVtfrqSzMtztWFAoi7TZER1qgHZfvYOYzuxcXo6M+Nu6JplF daIsSSBbx2lLEhUQKOtvqEaQ/n9GOcAZ41wIiv3GXJFxtFW6IhMHcmq8E g==; IronPort-SDR: 8n0Q+Vm0EwLiCX/mKn+qMcAnqy/p5KFyPeCZ24R2a2YS5SAwOkVfp1kZqkvtStk9wz4BYQt0qc r0XVcenlolvf/4kS7rrwQ/Eh9vvsTaBhupTV08yVaCq3V+fTjh+VOe7fiZwQJkokUNEj5rVfrf xo6OrWEe3WBUwBSwIdVxX1gFnBDvBfaC7sQIBK1RuGGZE0GZ+yxSow6w6mf6NemNoWQKUPOHcz Mn0VPj7fcp15fvwLKbG5AZNo+NazC1KGdiUe3tEx760C1uoP8voE6s0V9CUp1/X85YzqAj5Wky Eio= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448915" 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; 12 Feb 2020 15:21:16 +0800 IronPort-SDR: /6l/+qSrJ9DEcOQ+VRiE5zyAV7aiv7yqEQ0VfYAdZY6cv3WiUayB8dnqb0sjBBn3gy228MJsPB SFAzxSdKjClMd/am1odFwajqBfqgOtWKQ7xeeUZtLTdax1umJXOwN6JRvqflTTUx8VoLXX86+i 0tuazh6KgX1CjSMtA7Egex4149GQXo1F9Lh6KiInqLFMe3WivQs/XMGRDM5na3NMKKeo42UZvE yyjSG/DFMc3yfKrx/gYd3vwdcQO+9wQYJT0IeseyqT+91c1N8UxQWtoZoLlfAkapNsHK1gYJwo TYWwJ2JclHcaMLCeSAT2eLJU 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; 11 Feb 2020 23:14:03 -0800 IronPort-SDR: H+2m/vvrXz7Zf7GfjZFDvTRu3cmIP667hWUoij/bee3akSX1Tqhv/23WfrESq09+CvS0QcSD4O y5zHZrcebexWBqZOHzToBSGkbt2QWWDHAS+rRlv5BVDqwRFmAN49irdDcM7dqGgsm/mgNMOdnX gtzqGxpWjYm3IcQQzNbuZR/0x8+iEYAu82p4CNuBgU7v4OvP6og5hWCCChX2rq43JvcjfD5Uey VrzKhcSrc9DWbJ6fH3/tD9WvtAoSMV2ZRZfFC95YgSajJa/EYKnUhWRMirT2bsVvlY+PyChLpE DwQ= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:12 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 09/21] btrfs: factor out create_chunk() Date: Wed, 12 Feb 2020 16:20:36 +0900 Message-Id: <20200212072048.629856-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 | 130 ++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 60 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 00085943e4dd..3e2e3896d72a 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5052,90 +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); - BUG(); - } - - 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); @@ -5143,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; @@ -5155,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: @@ -5180,7 +5142,55 @@ 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); + BUG(); + } + + 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 Wed Feb 12 07:20:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377707 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 E5A9813A4 for ; Wed, 12 Feb 2020 07:21:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5B2620848 for ; Wed, 12 Feb 2020 07:21: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="m4y2/0Yq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbgBLHVR (ORCPT ); Wed, 12 Feb 2020 02:21:17 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVQ (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492079; x=1613028079; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5UIMNkBdCV6IK0Ha1DBLIbFIvKFl4Ob+mO8WqZyf47Q=; b=m4y2/0YqbnVMqkY5I7n7MKlcxJpp6J7ipTAHxLY8bd6E+wDZEDwCfMI3 na5G48pOhbW414FXZuwqpiGDa82FJ48iH9rOvp/6Xpf+wOgZ+8YzokqpF 63x71Tvy/fZCiYriDG7A6KPgW9D0iiNyh+xoyMxY7USgkEStJ25f/e7z4 ZFkQmywWFpS90x/ULSvM2b/RNjrvGxstW6aE++RE5zw4REuweP4XUPqQr FUUSeTG/mqEP6OD5nfsnj5d4+wiHoX/Q0lmYiQBtjQ2p+Fe30EOSrIxgt hdrMZXvoYmgivGKwd+x4pDx/S8gHRDtiaUSNDzvyq1OrEC+2P4A6jbbJ9 A==; IronPort-SDR: 6zISnJ1f7lU+cL+DEazkO63va+TqezrW1dxKisselbjhIJTbJdhRI4ZhlD+YYPgzAOy+jl5lJe aIpE+nvW9gHvy/nHdeXDD+dl02WQJNsSzj4b1n+P84JgyqZ+2V/Asw8niw5wbAvZUA3310ib4w jvAgPdjr244eD7/Ly8NOJQiHlEcx9ICzK592wNC/UvBmCL7FvsFAffF7gTwVc6vH8uehIvr2Ry UD5Ip/LvOFyQ0+HjOYBTc52ynYiLuExz/fPpagX+ArHWi6YqDZp31zfXMu+AnAQmjPfaJ/7h5K Xj4= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448918" 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; 12 Feb 2020 15:21:19 +0800 IronPort-SDR: BMm1yDDjWG83WqEhE0NQYfF/HG6LqYTeTf1mG++XhoSJm9JJ33pKwOxZhugH+hSusv9g0CDCcX XRaw0u9pWUpF3DkdmTfUpkJrj4tA0qu76sI8HgC1XSKtjbiUzbjhsjj+TGUW9evlVBHojevEgI 9Go2SfS9EtuqlziMcsss1u75YjT58wmPAL1I8AVxVswr+uXopJ6Yvbz3UcF7fQIcvzZaN30OEj SBdnEFCuRegaWBg/a5rsHTjLBII9WGnwtznWN6Hp60ReHtNrTE+cmyZBxT0EnZHdF7LAqtzW+c VdP+ADsTlo+rN/Qv3mxAdlRE 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; 11 Feb 2020 23:14:05 -0800 IronPort-SDR: rAUwtKnZS0jVuDUyLALcK8tOvnurR/BxquvuiZvKUoCr0/yK1RudaQLrCVfWdKsC/fsnQrt/UB 1OegdfJkIAXSk9N2opFVHm+8pqhnIG0Q5UbCY4BOsOWR0k8TXSwdjOabA53OZL6Wnz7hPl9Dwj 48Zjv2rAMa8YVP6f0zYv63UJDGCZjMil6q+J6oU1PVwQCvbv6Lfb7bPbeD9+gL9lcVb2BvbKam 5DTAnZoGAtlnnmWxpk7b66N2XvYbVQ6kz1hvyGDqZMmL2lyxC0DPq5qkNcKhvoMvnPhilO1lwX S0g= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:14 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 10/21] btrfs: parameterize dev_extent_min Date: Wed, 12 Feb 2020 16:20:37 +0900 Message-Id: <20200212072048.629856-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 3e2e3896d72a..38c2c425b997 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 Wed Feb 12 07:20:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377711 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 BC6EE109A for ; Wed, 12 Feb 2020 07:21:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B4862082F for ; Wed, 12 Feb 2020 07:21:21 +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="qJlov1eU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728379AbgBLHVT (ORCPT ); Wed, 12 Feb 2020 02:21:19 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728315AbgBLHVT (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492082; x=1613028082; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0mLMyvXISJkKtaveQS6Ke3dOGw0YjpT7RmJIVuVCL8Q=; b=qJlov1eUjDNYaqRwR/ESkdiE3R89XKXih3QVUmG36mkWt6RlZlIAJhIy 7ts6iKRHGPUm7YL5bysLrtt6dWAZOP51bdokHxcUMSj33AXpjWd6hIGVO 3HCJ3ldtmKyT7nMp5iooI/gNlKflkcqlTCmZi5Ljp/vgAP5k4UEMaAx1h syKDqQKjqhZTA6GT6A6Mc0sMnfHxOALCINP6sh+ZxsxpcCzkbhPWCtMt7 rZJiTHiUEQzXxmHmbrfeM0VELskWTW8zRPVvjEQuDcqEFBXYKcI0YA7Rl 60Z3uWkJUxEzkksVLLSNHcTPJ+9rYUkGvV11ZpLnE4k47ZS3zTSG9muJj Q==; IronPort-SDR: 5N4nBErIxjKP513dzC25IWttHJwreNmnqsTfaSCfyxk/U3OG5lqZElD5BD2oGTWgo7FzDDS+lL wGO6s1b4pDdioCsvH0fG6NHrjYyRl7WWc/Rvmp6ubMd9nMehgWnAw6rbYSa0Jy9iDIXNzY4hAb 92Xz5qEtnj/FceajHSjpz4FqB100wv5ecY8TQwuJhABlTxljGaj2LUI7wOM3dDeQolppqNepXV DS+NQJg07Ak7NW8wTDtew4cV4OTAyY0eZx0WoUrF9AU/EoowG4x0sLoFJ04GJKU2XQN/vAXEcF CmE= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448920" 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; 12 Feb 2020 15:21:22 +0800 IronPort-SDR: ZA6nTc1myv+bYiqvXrWL1GRrODGCcV9FOqCxvQXJW2VipNu9bS7wkL9VTfDdJndM0E4FUtXDUT hKc1hRAM9d7L2EGt4rIAvFsireK8WaApTFQQzoxH3Y6Zjqrcru1O7FesXJNOwEQKGcfvRfuEUF /CvRoVy6ac/UggL0Ks8VF0+onzfyuddKht0qJeZkhgiJl92f2850n5j+msGcsve6yY9dKs2wdD cirUuN0poPeDG3yX3nGyYW2BwMy4udfMbV053DdwgE3PcFsa5EbOg5RKdBhujbIt3IvbdQgdI6 skFesOuolTyifP+Xw0Og1nhj 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; 11 Feb 2020 23:14:07 -0800 IronPort-SDR: gd/4ZfqYymUZq9A1Uo6rAcC+kYzzupwx6DbM3+0ZE2Iy0gSJ1WY+/z81rlXQaFd4bknmQyBTIb LzqpPp1rNVxNvW3h5qKW3nnceMcA/qStOr01yuLxiVYeP5i9Jt15FChZwS1/zXQAwgWVGDJkos 0XmLpuumc70s+sK5ac6ei1DLLEPUp8WX5juiD/xONGJfMhgBL7cet6bPIr4k8WK3aBg167nP29 KCk8g8X5jTQHjzrdAoWvOL58yuTOnnwtPk6En9z3pM089Cz+vmeYqNkxA8YHNE44l1oqiLPkil Eak= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:16 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 11/21] btrfs: introduce extent allocation policy Date: Wed, 12 Feb 2020 16:20:38 +0900 Message-Id: <20200212072048.629856-12-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 227d4d628b90..247d68eb4735 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 Wed Feb 12 07:20:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377715 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 31F79109A for ; Wed, 12 Feb 2020 07:21:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1150320873 for ; Wed, 12 Feb 2020 07:21: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="jgej6Gfw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728382AbgBLHVV (ORCPT ); Wed, 12 Feb 2020 02:21:21 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728381AbgBLHVU (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492085; x=1613028085; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7kSGCvaay2SG1nIxMcRDLO5KnT8tOtaO/l1P1KJNuCY=; b=jgej6GfwZJwzlZN43sE5PtTkqIhkzijeUGIHmYwSOVbMZUDLIAH2J0DZ AS73VJKJG/CpYhNeDvZG/5qGrlef/QpoAxPCilV51YCwDQvbKZcDQKakR BwhfWBFFEkVtNhdne1il2yJCw+eVd1UyyTjIGrWAjmz8/kU+vpB2sDbej vOJFoO7HLmhvWpYRvGdebPv5QUrpvtyszStFxA/64jvnVT+w2xnMnqEax PiAio9/3bth3d22ksKDCmS4qRZoasMrIur3so/J4aeB2DeToUAo/M72Iz cPIHvdgTUthoOEGIW/jMAxeZNm7XI4B2Ok5usoXqiRof9XeCpoFt61Pbw Q==; IronPort-SDR: u0nV+EjUa/vVH4tK7EdG5XagoCWUhbSnwiJjr8t9bIR+rLMqi0PJT90fTaVDw0B1em3F66jJw4 usxRanZgXRWsH+DfqcIyt/CaBH48xkhSvnfKDvCsEtl1eM+0B/6gNvyoJrtLCeZcX7jdcMpMNC 91lwbLdULVdRXYWyffd5yEw1EFj3UOvXpcWnixAKq9iH0QSquY6QKp1vhXM4/4BpANpWHlIPvL h74g80/YMlGjXy163CD1lllqAZPp91i92eoa0NOfY5GVyp7D+OUXYP9jpYF7hUPAKntMn4p2OB 0qQ= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448925" 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; 12 Feb 2020 15:21:25 +0800 IronPort-SDR: CtsvS/RgUg15OKI/y+yEoRPL/kv+AT+S4DPmz0hv8xlzDBt3tFL7uZL5m3fnBiz7YRYIuWiJTX HnaE9XnfGqTBimm4JpS347nZgqORpWLXu7lknuyGRFuSyH946Gppc2oUlA86wmSIn4V9vFREAW fVTRrEpN/iepc6IvG7nVOm2aDU1OIKElLt6xoTZ5fwxEMCRfrxXke6nhXbPq9fCxu/be2j66xg gUIJQCjJtFpYGUfP2/W7Y4gm2FxW1+Oi+w1P8LN6r2ayDcVfg2iLpDZ4xKj1lThyqFyF9nVFTd SddsTZd0c0cn6+o9fpyeVjKS 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; 11 Feb 2020 23:14:09 -0800 IronPort-SDR: R6slTFA/MnQuZ+l6STq8NcXTpIjBlHDwwiFNiqj7qqLawoDFpBc0GbzPnPLxI8ug0Rx6wO7DNO vlk2lRdbeNeF4LLpmZyaXARROKQ/BynfdTBItaEkZNt1H49xX8KGs/2VD55qvGKE1b7n8yydoH SPbWV9ULhs36Fd5ACFz+kTIZefhSNk32v+5comUQcyniDys/+J70lKPC2LzkiOPPSIoUsJ4NXL 1z4oBO+ErFg+plaJ0lxaXyUCHGlZcMZvj6ThI007J1nxlPKd0oTNGJxuz29GzpNnBa18JyW2NL Gi0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:18 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 12/21] btrfs: move hint_byte into find_free_extent_ctl Date: Wed, 12 Feb 2020 16:20:39 +0900 Message-Id: <20200212072048.629856-13-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 247d68eb4735..b1f52eee24fe 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 Wed Feb 12 07:20:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377719 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 EE3C313A4 for ; Wed, 12 Feb 2020 07:21:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5279206DB for ; Wed, 12 Feb 2020 07:21: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="Ffluu8OK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728389AbgBLHVX (ORCPT ); Wed, 12 Feb 2020 02:21:23 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728381AbgBLHVW (ORCPT ); Wed, 12 Feb 2020 02:21: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=1581492088; x=1613028088; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5IdcOaURlYsqdA8UKxMqeUbogEQ8ynMq18DJFOr9sXg=; b=Ffluu8OKUYsvXwhga9pMbi6YiTVEakqX3JX0L+Nd2dZTfGeYdNJETyqx V5MRjNvvKqo1EIUqCMRRaRvCLcn2AhgpUD0tBr11P6syMPM0G6vOPAQj9 dgytZ1td/sRf/inHIpzEwfgiBMhp1Yewi9xRUG0vD6ebGDjP/lolD+F53 Z0gb0KZHKvFvbU3UAnTIZwFgSsuD1Jtka6qqs1kMiWdEsqNUr6/FmY+yz p2lYQu/BqZpes2T7XG21THKt7lwe3bAkimagdejbN7YyNk5eFMhjjXOke L8jq0TtOIaux3GDr9I5BcnV2DHU1xAS4KZi7iuy0k2a7x87niLeuDIXys w==; IronPort-SDR: DRUDxoXvm5KxWxclm1KJybZT2qqh75zRbgVPQCnYH2GBvEDQ0Li5CSviHfjjlvypIqEaZ7KlIf RlgC4FiQ47+sJYp0eoKnsTrzYp24JDxSpf2Tc62SLsizJV6o8Mq/6+nXp59Ka4nRyQ5L91Iwuu mtA772qYqLDYgMkFcuOkeQ4Aaue9NbS+8OcLtXhhVr9FCvwCIx23mWxBfgtUINBZ6GsqxlUE4q 8HjHv42gjaDSmOJaSAaEUdIC2YRKW9NFqCw9Ly/DsTJ5bsFa6vnjdMs7jmfPCTr1HZk2i19zuA tfY= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448930" 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; 12 Feb 2020 15:21:28 +0800 IronPort-SDR: NfWUvDFLu6qV7FlH9Ycz+sQStrn6FHWQxbnsxkZlXasqFAebXueiIyTaxe17rbU7RHigiUwiq5 kHcdHyCHHKzLbhzqb6MJkwMwyQx07jeb/xoEN6Mhriqdml9kaZ074hj5cLFYcciW8i2a3to5v6 aKj6D9XecUpkna0EU6D6e/MvZqFPyTfH7O3cQO/NH9MjcnMgBDpLu6iNEwihO9NVPPg3dpwELN QTFXW5DheDLR3YPtLvFrd3KMdSjdL4n6SG4ewFYbjHHDZthE4fic/VeXbxpbL3b6M26Vtzv30J xDfYFNvHYtpPslSY7FtyvJjP 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; 11 Feb 2020 23:14:11 -0800 IronPort-SDR: zpv4Yais84UKgy7C6tKbL4j8z3/A2kKNYaBteQ5iPxPbLSfJKgtfphKUgIpSZ5XNSvb03Osl5G Fxn/dOZJ82G8gGKo4Ka/5/RXWuO38cZMtd/1ds7uI7QHOmHNgXRyQWbgbV2J7aQYkyKZePcWwe aUqvAViuHffEnGsEW5UoN/pNrQzxv5yGpPvzgLrPDJt9wbx9/C4asEitleRo54yZUlzbT4BMzt n9Fq1S7Ipj8uPnTtC1cWOfHEwr5OEUiMyNer4fMlBXr9I2m34B3gzcoZvzUXBmQUsH4P3TOOPf rWo= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:20 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 13/21] btrfs: move vairalbes for clustered allocation into find_free_extent_ctl Date: Wed, 12 Feb 2020 16:20:40 +0900 Message-Id: <20200212072048.629856-14-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 b1f52eee24fe..fb62842ff3e6 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 Wed Feb 12 07:20:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377731 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 A34B1921 for ; Wed, 12 Feb 2020 07:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82FBC20848 for ; Wed, 12 Feb 2020 07:21:32 +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="gfw3QVe9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728402AbgBLHVZ (ORCPT ); Wed, 12 Feb 2020 02:21:25 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728393AbgBLHVY (ORCPT ); Wed, 12 Feb 2020 02:21:24 -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=1581492091; x=1613028091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ALKdw1g0vnyk1KH6I6bsOgsw3Sz+oAVi8OEJeF7h2UE=; b=gfw3QVe9HG3+ljBhX7ir/OcFpNBTFTWm57Po6+sywKQ28Bv669hRv6Fn xOKwp1bILDRreA6AexOVQC4kLKqcey3Ilgs6szOqEzs7Bx3Ry2DIAGWUk 23YLwtQCkCaSnQSyItEoN8Me56dJuyBkZQ4FxyD/IAfqD+4mZ5ktcRSNp ZDPvtyD/79XIW77aRKBj0NcCwQddbSiy1S8h7/jCqibmXILj0Livg/fAn euV0yXjCqSbZXRHde1RJyZpJLnrnuOaP18/cs4C/HOi+WwPUuWDVaNzSB zCmCneHeUZqV/Wiz/GmxYI5iMPo6ZNXT4TKfKB52iLkcXo25sRHxEaJN6 Q==; IronPort-SDR: At7pz/q56MQhNU+qAcXZvaAiwUOyE56dEXvK9wLtIX4iFafANndBw66IngBfx+nRJMusDBpeZG vhRzaOy3Xb3BmvaKuz7vCN+/I+GvNdOOU1fisck7EtybbSN5PgpCvNXksEvI8OcHS2oTKRRyuu M2xXbqu+rwoQFa+0qVazUvhe/BbdO9p2VfUwDIEZ4OK8btKT1I7xKzTtpCVYx1Z32E7G3vnFlD kM/jVdz2lbNgKt8S93Y2cXXDQ96nLU671HgQwdyH6IioL2EO6d/l/cB07RNPtRjf99npl4qv28 SEQ= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448936" 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; 12 Feb 2020 15:21:31 +0800 IronPort-SDR: nelb7CqGRRPkL4+ly6ippWJ8+J39rs3Bni1qF36nBBxX6X4rFS++lS7l/uw6UXZVSgWaJwlqmZ an/y9Aj4QTqpF6dY8ua1hUjssGBE0y0FAgNfksPn3zioCzJd3v7+v8dVzNQWqwzDwvGrAghJtO p8dqTU57HRLBEhA4Q1iTEsktJZ+uWivDXPJkdMd5xrplalHmaYyVdKGMCymtCdpVWF7gBJqyqg Fn3ElfagURqweuFOgWsUSHGHujqwgOGygMCFlktePI46cLocve/HWPi+loJr9IhCfKD3cb3++/ tuRHtQt/jkPXLakuYtT+wtaY 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; 11 Feb 2020 23:14:13 -0800 IronPort-SDR: Lzj6CFUih6WJHH/hxrjY0HUKtcQa+0DdNBidVr6+tgyuaTloLKYkkZSDwl5YR1bzZiPE5DNMRT 5sDZFaBfMa4uTeKhs9G0GT4PJ1L5V3wb+rqgHb4nZ1IDuCD4fN97bu3erqPeB+Z6kOKUR5tqgs kIYkvMo5LK2ekHqckhEybRmLItS22sg/sI/Wdw+5lS05XipdO4iH3EqAQNZOuuc+M5eD9ZZzrc 88JhXKxmIZY/FXEQyOpzhtELSH8hTgctHiqiDIbQTZHcF4jpWEPseSjVeslP/vG3TR4gSVCGfV LdM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:22 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 14/21] btrfs: factor out do_allocation() Date: Wed, 12 Feb 2020 16:20:41 +0900 Message-Id: <20200212072048.629856-15-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 Reviewed-by: Josef Bacik --- 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 fb62842ff3e6..f9fadddf0144 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 Wed Feb 12 07:20:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377723 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 50910921 for ; Wed, 12 Feb 2020 07:21:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EDC720873 for ; Wed, 12 Feb 2020 07:21: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="YS2EDDlu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728417AbgBLHV1 (ORCPT ); Wed, 12 Feb 2020 02:21:27 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728410AbgBLHV0 (ORCPT ); Wed, 12 Feb 2020 02:21:26 -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=1581492094; x=1613028094; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cIniir5NeVAmApm64cpfERWg0YOxxnYhokCRgXfvWFQ=; b=YS2EDDlu3LiU5327PRFe/hDaRidzaUi5ITEzQd/YV/2v1lzQyJLrUhZF YKxsA510obRPnnAlY0uA8wG5RUhjnMmbpFYQvQbS2+JWSh+4hl5YjxHTr eaIiZv1cZzJfa2qemcy70DObpGGZrZToP3eYTNpyHJlIRPUQY5N8EnXQ2 H2YR4oBL6UGIQn2P+Q17elhDW2tQaONL/AoXReBULYxemMGv4Oge7y4di RXnkuQOtBxb74KjmdI+H50eS4KLamK2qeSrtLc93KrN31qm9BaDlUf79z OPQhU8z1ATFeIFhmruM86M1EGU475ixuWblx3t5JLnnQXUQYXCb9Pxtef w==; IronPort-SDR: zdr0EEBE6ygG9vV+n+CXdZd1EsSqxH0UxFOPEEQA/Fa8kBlFxy4rpeECLq4iiBBoOXaGi5FL1+ lPwKaUlW4sjtzE2/FpjozOPsoTA9EV0Ev1rUVVn5P8wVd+YkgMomzFEhc6CNo4ctHoahrqo7UT Aq7YG7MFRqZskkiWKwKFZsQMEHwUrLfY7NBqoGH6ZlnaurbEQKrhRMHGy2sxJqAmwJEhOWxosi O+8NQNhsZkf+ueaTdXYRM41AOb39+SQOSohG9cSJySOCpYYx7SLOVI/4qV1hkHA89HAhT6SLAF C9Y= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448937" 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; 12 Feb 2020 15:21:34 +0800 IronPort-SDR: PVQsyjvaj+v69lvOC6yYB6XHLe2HPEl3Cke14ukChngi3v5xypE7tTSasxCPhBxiybVmwoK/Ka veRnvhfytK7m9fxGjl3TZYhhi2bZGYWH+Makv532dQ+Snm4mqdTBWj1KG8Zs1en3RcH8jTNN3D FmbBsqQRrwMibOAjugOvylb/MTOCEd+OnTegiP+egdyRpPgKdCSRI3vV9fjFQY8uRsg1mEIW2q VuchP7KZy22S3XsDtnIRjuBpaETESe4rtvV3yU0mEWtWGC6I3Qk4n/TQg06+LX6VVQmV0Cm6Sb paXIffWf9+r4Z3oJbHF2R55V 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; 11 Feb 2020 23:14:15 -0800 IronPort-SDR: hpjQu7D3QiwrAqhB3iN8bnlk1uaJx25PLwADmKhRQTtoI7MczlUk802Bg4EP1iMn2Zt3JdHCsC bCMzT/FMQKlFVykk7rjEx0ww9Ml4W3ss1+ohyey6+hJwUXeBdxJd2NFDneXss+GvNTcM0yP+SF /8zLTiUpX/zIfYH26wo7+2/9qnX3TwGE0h8Pu/UhAjaBrz1YSRkpucL24nhQgO5TMdUOwtYjMS Y/moHZKucAYcgvwaJvgHLXL/h8nfKhZfKGlL2NOD22lUZMy2PhTNhJQ9SBD1H5xkIgsCFJisPM yp4= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:24 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 15/21] btrfs: drop unnecessary arguments from clustered allocation functions Date: Wed, 12 Feb 2020 16:20:42 +0900 Message-Id: <20200212072048.629856-16-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Now that, find_free_extent_clustered() and find_free_extent_unclustered() can access "last_ptr" from the "clustered" variable. So, 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 f9fadddf0144..3dee6a385137 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 Wed Feb 12 07:20:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377729 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 0A5C613A4 for ; Wed, 12 Feb 2020 07:21:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD19420848 for ; Wed, 12 Feb 2020 07:21:31 +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="Upyi4n1e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728425AbgBLHVa (ORCPT ); Wed, 12 Feb 2020 02:21:30 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgBLHV2 (ORCPT ); Wed, 12 Feb 2020 02:21:28 -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=1581492097; x=1613028097; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ab5eMBEpbu7bGdHKONG6/oUFBqo8yqc01K4cqzOTxQI=; b=Upyi4n1eQ4sfTnpx0hJIwwYEtRsjEDBiXlIBzJ3+Unt87cj3XT+W7Sh2 W0FdDAYubT+gZq72B0Z7wniBz0dfgC9FpIdT9F67iiAf5RX0YTNvBP3Gu xIF4/H/JNmlbqIocXiYTyVGjH7B7eVFmABYxkJ6sJ8eyGIUv/CnFHxC59 J1Q0xtGcQieIinGIIkzftavAs0H2p9B43HVdkl292BHxzPOmFU7+jyHTt BP3SYi+CbyIV4KJj0VhItGjwrXZNpXfTuX1UZjxDnM4JAIHkCYPvoXkfk RSA2k8sE9z3LfQYoyoNwn7q4xQx2y6RvIokquHPUayT5wbvFECf8O2s+U A==; IronPort-SDR: zdEUoMI1kJaR4kDDK3mOW4T8/yHKkUpkz/dFHOyW7OG+PcJJiCOcUrX9bY+eg7i4ztVsWWRcVb m3gIFfvGepVU3bMj2rHwR/S3tzAmPGDgUJfirnzjBIj9X+ygVzYyxzRy+uAjyeg20L0LZts37M /0GFctAzAAWbaUe5GyFfR9RrC4uyIqG8THnAkbayc72FI65xDDAwzq5PWFDqUr6h9Qu5GSUaTO v+7EKS9+ZVt6SyOSl07Q50wCMz7dnX+JQG28CVmvh+jYDyILKn0PzxlJ3vgw1eJ2Ok26Gi2Pt2 uSM= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448940" 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; 12 Feb 2020 15:21:37 +0800 IronPort-SDR: qScDbLueH7K/K41pJb4kNAe+hUUqEx6a1QiHk+PUhpcNNBcO5N1xvYw/LIc4KBhAuw/Lop6CM+ T+AScgNvfMFYoLsh1b25xLAP+uAgWX+WG5+6YcYmOnNGekLH0TchWeOXeQT1gr9swmkMUGbcUQ EHgoFgHdHyNggvobSYtMsz4WYJOZvWI/b7FkHNbL9ExnJw2GfQOIXwZoFI2ftQ516SnXgZDjif APJ0BEM8iiiMlLSx23sh7jdtLcrxSyduQvaSOlJty0rUN1I4zBTREAMrQ8e6DYKmY7sw0B1oBG 4XuT/PPTz4g3o9HP9hSUnCHu 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; 11 Feb 2020 23:14:17 -0800 IronPort-SDR: 7Oiczw4ygFeEckWSbfLSu2n+WjTqp69FXJ7A/uoWD6j1L/0QzxIPYH397uvq7dUQI2EirV1gFe nSHmb1YWtxzHM6cXTOEovCbuqLl/CBnsld2YRpQjYAx4Hx1dSCsp+LZSdOTxAVBX786wA9gbYl ZPrzulPB0mUUpBfwaPfDO9icak5HHhEe5o8sVl4dOVmT279C2X2cQKh7Of08w5gcne58QDfMTc KRBqdzby+adKpoT714c9bedcXumddV7iy1y4mZoxcolbPXzOxd+tiWGHhyS6Mlw+vyMvafmacr ovM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:26 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 16/21] btrfs: factor out release_block_group() Date: Wed, 12 Feb 2020 16:20:43 +0900 Message-Id: <20200212072048.629856-17-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 3dee6a385137..276c12392a85 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 Wed Feb 12 07:20:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377735 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 45A73186E for ; Wed, 12 Feb 2020 07:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B412206DB for ; Wed, 12 Feb 2020 07:21:33 +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="psYEEPYt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbgBLHVb (ORCPT ); Wed, 12 Feb 2020 02:21:31 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgBLHVa (ORCPT ); Wed, 12 Feb 2020 02:21:30 -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=1581492100; x=1613028100; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sKKMbBUq06x3XlUxvd0H3BtwariMwcOhdgYDbALvWYg=; b=psYEEPYt9eQZ4z9EUPunTNOe7VBOBoRmMFzP3blf0VsZ/kRh4IHAyf8M UnvJiMEzU+AlsScz1juU87MMB08sLtlbkv5Dd/pHkJ+fAicn1KKVFZIwG gEZND7Le6MmiNjCQDnEvkqWDROW8fUpxNMyQVvh5SCI8WFVINqb3DAazK THHhKa1T6tc4OF0sF9XtV7WztBD/oX9wXH81/mS84UkWkTRWL4zKl9s5e s/GxHhxECJOh4HKc1fdy6uvQ2WIkHxGZGtHQP27muUrVq1SlY08UCHt0g uWMADOZb+rypfMtW9fchhMEteO/2w4++6Zmt0rCgfO2mW6JU9Z4El5I4q w==; IronPort-SDR: ufS8WLDrzodLumPZJYbHaY1ohyS+MYnXQXR4cyactjpbNQGjwqRrJrEj7sP+Jd399RNeznBa3b a8Qq7kfO3QdSo82UBkcQVzDSV8Cp+6wzVWUoJ03O/dosw8UDRRtCURDCaBGZbJdbnNC5iiInQd clyimo90ulTwcb5RZlWtwVTh2z1Kz6PtSJnh5Z5Rw+QcHYC/rUoJZJxDlRnnH5iV6jvaxIk+Nu w4qgY3fqr+5eZq3pr3s95PZI7fcXk9bLW2HZJTlY2qpUmkMMXqZdXYlYWh87/gMF7RjvebSfl7 CUU= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448942" 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; 12 Feb 2020 15:21:40 +0800 IronPort-SDR: rrFDwAiAcQieAkDbcWKOa8AUjX9NE3b7TWcxYl01fTE7lFd4hti5jRgeJgUB7TnInE0CZqxkp7 Ma37ifpllDXnTw+nhHbMKAnBkQL6NF4DaOiWjAZGxmZS4KlTbs0ipqd6mLNPjvz4aZmaHQltqh e4D8Z67D4swJ42UCBRjBI7TuQuVEwjkQzRgihKPAwKwdn4ufPZlaWYk5G/OZA9XYJThqEBXnjk 4mO3Vu5tIMiYVd9JLhOEmTKxqkM0Xyye4q0r8Njcg9JXegBnEfoMAV+1c26F41RPYIqe8WZlR3 GGTon05WFzvnmJapEgnopAo5 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; 11 Feb 2020 23:14:19 -0800 IronPort-SDR: lnFZFpzGm6HOlofahB3IVz9SaDZCJbSXwIIL1MOgeP39Q1COCtNt3u5LCz+XOoaG7rBOqR+Ttk 1YTj7Ta0lgUYQik92jwddaw3C3HjqT8gYDi8LLpOSzgl1tbaHyC+Cyo2RCCDIeDieDcydUdriS csVQnXTVfAFzMDhag3xVWP1tQ7xw1tVnXN1XtSgQMZrOuawq8JsOhVu1D6onhWX6jlL7tTHVjX HHLx8VKUFUvMq80rkEJCvJSG94wZnWbisIPQO2TQxYnH3LZiUTi1zVvIwr1fg87Wcnzm9lGjuR gvA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:28 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 17/21] btrfs: factor out found_extent() Date: Wed, 12 Feb 2020 16:20:44 +0900 Message-Id: <20200212072048.629856-18-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 276c12392a85..f3fa7869389b 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 Wed Feb 12 07:20:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377737 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 73DCC921 for ; Wed, 12 Feb 2020 07:21:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 535332082F for ; Wed, 12 Feb 2020 07:21:35 +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="ajl5CXpH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728435AbgBLHVe (ORCPT ); Wed, 12 Feb 2020 02:21:34 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728392AbgBLHVc (ORCPT ); Wed, 12 Feb 2020 02:21:32 -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=1581492103; x=1613028103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vNFoHTIxdH12CSqZG6yYMmU0kNe+Rs0A08BY2/Z/5KM=; b=ajl5CXpHv08XqgXcwiFudpyRaib7tkrXIkNJTgwm/tIxe8xdL4hQPy3T m0UaUWfEbdWEU/ohReUzqpVxTZQQzWxI2t189erE/rjzKtiytz2XsG/oi prtxnAegJMa2ajYWS6oiE9UQPL5pwoSlQWAhcROCy+IzfPADxScSVSrLQ b8Hru24HOZuZTm36+awSIEJSAFUSMfiagJosB/nnpqdsnmF7cHMsRLGYl PWs7O+5SsvTSBmlt4QumvpEMhwwvTkb/EM9tUfckDg3N4HH8nwcjiSmXx zgJQo1cLUMqwmU9oHOwG1ifIrj3merjPo10MxYvmh2KMgjs6gAX09GaUh Q==; IronPort-SDR: X+FQ1FZISH1o+6akB53+SxJCuU6hgcLlgQ5x1+mdIq9ea9EqihbnxJa+5fneV28Aoi/+3a1CVg pQBG+HhD1JXS8jCrNpKEnpCfGxoaFTyEZh4e4lLGkbJeyxii1UinCkLK/HsgUK2PPtvjuCmRYB qYqwte0nNupsQWonq/d7Y9uz/0TjUX5ex5KMAZx7JeAKTBET4CW4CWBVJI2ShGwJ2aYpOv7yZ0 6LwJvCfWkCEqZzN/+VU/CuHTvsKBJjXqstdOKgQhuh9dXQNqsHmlSC2agIHvNNLHgalUN9q+GJ VrU= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448944" 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; 12 Feb 2020 15:21:43 +0800 IronPort-SDR: JtZGZF5tuutD8MHMDf5NmI+t8pEwjEmWeDOdGnsN7HU2Z8JoL4GRdIZHMX6tp1zIDqyoFZKiUH ND3Vf7kOm4eyGNslU7TxOMTTkF/j82CDq/1xEXMyyc3ft0OMZPvTyl+YvNc2TzVZpwIzZn4QeL 04wPsvtIvaZfeJXm/72r9vO7scK5vjxzvZ09ouXSIc+rE+PDEQODLqZKNFaLYmSbE20269TH6e sEMeBppYo+F4MD8KHvgvW+qj4UC4X43R9yw/2m9GklXTcd293khCG5w9pXkUJ/66T0jCNKwJ7s on9G+YrVe76BYla4+caFthZC 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; 11 Feb 2020 23:14:21 -0800 IronPort-SDR: fGC2OHNwuI/RND1/w7zHQdd2BorQOJwBjwp07uBBUcEnKKPsKC4MU/T3cXF4G2C0ebUfG3VQgb IBS5m5fgm8pPEGq4OVpMTVk+9NJ3nPnxMOoRAi0EmxFJpdkuezHxdG2Sg8tmWJ76sXO30EtyJZ FestLaFCmnNlddHak7RP5c99Wi7ED0hPBQ8eWk9GbKsAJQNMekiePRWO2YgHJ88C/51xJaMd6b KsK6tL9Ui4u2CCryCe9CWw0gEDz58xIE9kAawF5gITM62pe7bhO5TGZfs9krKGnv7hdB7IUb9q M0A= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:30 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 18/21] btrfs: drop unnecessary arguments from find_free_extent_update_loop() Date: Wed, 12 Feb 2020 16:20:45 +0900 Message-Id: <20200212072048.629856-19-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 f3fa7869389b..efc653e6be29 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 Wed Feb 12 07:20:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377743 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 1082113A4 for ; Wed, 12 Feb 2020 07:21:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E3F632082F for ; Wed, 12 Feb 2020 07:21:36 +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="IVMT/3aV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728441AbgBLHVf (ORCPT ); Wed, 12 Feb 2020 02:21:35 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728438AbgBLHVe (ORCPT ); Wed, 12 Feb 2020 02:21:34 -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=1581492106; x=1613028106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kWMimSL+EvQzwLYXZN9p24BrPKUYLHK6E7qqKA+7cpA=; b=IVMT/3aVnElWoXFVCwiIRjMIHmJClPhUUg4oqZE4XYN45HUq0VYmKHwm jTH/l5J3Pn7IsIvrrqOK80vRZlBhVtJl8UvY6jmofoyQSBjwox3jMbMaW 1lM15wdDAtUx99tZeob/EEoef1nfL84WjHqzFX9oiy6oBYnh9a9s8Xiiu e+PO7DFYillwm/vg56f6xO2jpSkSMbY9imhk/6lLz6sDfJEuM7WdAMP1N p9gJ3Api0n5wDZD+kJiWx1K4eV4yoiATIqRo9ZqpcskbLuJjft5oZ8fUq HE75u8HAnj/bL0vTgVQBkZJ3iumoiNck+FZceYrepab/t+GjVuZ6tqD07 A==; IronPort-SDR: BsABXUwmKmibiF1dmJKaEsvYvsv5HXrgrAse96HxsCO8OBuGk7/eL4smJkRUX/dvPddNFkM+FG 4BeWeSQQtP1SpA8BUjj8jPVLT7mzVEBjQ/l5aZt91jCRdyUkqpU4xJYL36OpT9aT0lBqysrjGC Tq2ubr+9lI/9oqsuzrXM/DfkMyvJt6hUEaIF4vXGRK5mW1SF4Aaf+veSNtaLHs0cUiMSLiEvyw 9V1n5f/njQ1kou0T4U9FkHR+F5BmYYDwX0C/924liaxPWuUVjh+Y/gkyM1bbPDrfaRZmufxR80 Xc4= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448947" 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; 12 Feb 2020 15:21:46 +0800 IronPort-SDR: l0dO09+TBCYtwUqZB9unCQux/cJloe/8eDBFckxDJY/a5pi7wc00vji5fOyLUpd4Yp35/aIE1X IFIXwOsg9PmxebGDtArj+EljPDbMkt5jOyEW0miDU3iMdS9ALi8yWTCs07u8j+r8XsZBGfTq7L lCgbLU+r8C1gnyjPP1KEcgmhZbD47L2+GFl9QZ18PAl0h6BfmMjg63qxmwcf2Wholo+Nn/Q4gv Tl9SpOFq/01bvmiqXC/WOoT0+oIu6fnOkoQF8Rbf0QRo3LwEZSfJN+3XBNYf2Y9Bi/l++hmY9F 3TdsUwAkLetQ9on/Z8jO+s+K 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; 11 Feb 2020 23:14:23 -0800 IronPort-SDR: p5NDzplQQ0Xhy9iPh/JevzEr5BvgXIVy1lXFXmDL93tjb5mG3j6AAz2ErzB0NVgIsI77pPYBi+ mVmrL4G4iAgtfsuoddWEfity+SoAQUfSMVTEvURz85nbmoCqFaeWb8sfXsBxAlkDDRZfx2RSij GGdFnr00tKcmtK0NBE8zi6fm/ne/RRPj6c4UJpa3JkMQSZgPKYrmFv2pYwQZ9y634UTjuqN/s4 GJWUpVELE8mVvx+MtmAeD7+zINLUW1dy3k6O92c6acSMpO7AR8GFnetn65sOxxU26wi8neW+zs Erk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:32 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 19/21] btrfs: factor out chunk_allocation_failed() Date: Wed, 12 Feb 2020 16:20:46 +0900 Message-Id: <20200212072048.629856-20-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index efc653e6be29..8f0d489f76fa 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,19 +3834,12 @@ 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; + ret = chunk_allocation_failed(ffe_ctl); /* Do not bail out on ENOSPC since we can do more. */ if (ret < 0 && ret != -ENOSPC) btrfs_abort_transaction(trans, ret); - else - ret = 0; if (!exist) btrfs_end_transaction(trans); if (ret) From patchwork Wed Feb 12 07:20:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377747 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 65E0613A4 for ; Wed, 12 Feb 2020 07:21:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 461872073C for ; Wed, 12 Feb 2020 07:21:38 +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="YTKDyTFw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728447AbgBLHVh (ORCPT ); Wed, 12 Feb 2020 02:21:37 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728438AbgBLHVg (ORCPT ); Wed, 12 Feb 2020 02:21:36 -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=1581492109; x=1613028109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mlx2XiH4jsI9oCo5Mgx50W092nbMH4e0Zr+MYrOXpOs=; b=YTKDyTFw0IWxG7Xho9yUZxbfgrAfKpdShZQBwZuLwvAhR9p0hFavaWaT fI7L53x5JGA8sqlcxo5/rytRz2DrQObAtaCpEf0HLq41DLSUqE664mSY0 pwXwfIhUQFErqf0HIDm5BjZOrojHuIFYilWTKwUZLGit6+yBF2NIwo1v9 yR8U+p/Fx4LlUq7/RjYNxjomh8vBA5C0Nysa47mgr0Sxy4Bmybm825pAt HRfgZvONsAW68AtjXsnhZB8FV66Gecvhtw1Uftn9v8lHa7IL6sP8wlxxq 588ejT8x1PP7K+XrV0SlQyKBvjgbL5lg0B/UmBeNqouHjaEu0K5QHkUbw Q==; IronPort-SDR: 9XXXiwhEj66s6CPm47vltL6azC203WXjJQk900yqi1krm6tQH5+slJ02kY4LyLvfJEFtmrGuP0 lTOaDxkrllqB8hvm7T4k7SB97dBCqx/0THeCOmDTYUGxxLYP2xXcfkG6E59Ayv6llOzljK+t/S 3N6eMRlOueGzE/KospXdO/KgmztjspRuTjRPSAtwxKS3JmWP3xjHXinhFlChp4ie11c03NiPN6 eEshpG3LbNVIDKyuG4cdWhvMX2OSKTuu07nRdqt5LMGC5rCBtPSzDNC08Irc2r/+kd1Y5R4lis ZDc= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448950" 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; 12 Feb 2020 15:21:49 +0800 IronPort-SDR: GrBogoIPtUMlio/hw2fL9x+EKzye7mUfb0OR+UmATxWtSfhkNhrNAl88VUvV6gUJZ0cZIBeGMT Ew9YXKlFs0CFgbEV83iW1pbRHdxHwv1XzijaiP9aurMbr6Nw9YkXwk8huQXDJvCEPuITX+bocv cmKna5KmMChLJL5ytc/wAfwyfwdW2Hc9jDA9KnpyzWTSklHXAAgpQvS6NhE4W25kSzU4WeDN2X T2K9S0KytHuzv7zBaJ2UrZ5HUZb0pvwcjQt7vImwJgz6n0roiseSmdo8pK5EI+QyqqnBzcYntF +IE3ltU1LGVijG5sZo2EzyvQ 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; 11 Feb 2020 23:14:25 -0800 IronPort-SDR: 3fgLK+iSnyaYHbRGkiRJXmPP7tQ1CtwntQi6M7Q1rPvyhSD4Hc4Mu7yTxKyqeMeVB7RmQfoSuT KQGJZ4RrRR3AuKPEwcSFnmRN4qJkmcujnkVuAVDbAl0R7PjXNP5PvTw4MEIgkoHZ/rmDwMwlQj 3e229oUuFh7/7U82GUWcH6NENChP7qROuDy5mpxZ17NZqJPSR+gJtvN916180tuwZtLNLfsUWv gM0+ZdaoEb0KxUg/YjHYoiQNnFRZ1Ab9R++Uh7wotWvG59i63oftXGPiRPPpsMyurWZYC5qH47 ONY= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:34 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 20/21] btrfs: skip LOOP_NO_EMPTY_SIZE if not clustered allocation Date: Wed, 12 Feb 2020 16:20:47 +0900 Message-Id: <20200212072048.629856-21-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org LOOP_NO_EMPTY_SIZE is solely dedicated for clustered allocation. So, we can skip this stage and go to LOOP_GIVEUP stage to indicate we gave up the allocation. This commit also moves the scope of the "clustered" variable. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 8f0d489f76fa..3ab0d2f5d718 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3373,6 +3373,7 @@ enum btrfs_loop_type { LOOP_CACHING_WAIT, LOOP_ALLOC_CHUNK, LOOP_NO_EMPTY_SIZE, + LOOP_GIVEUP, }; static inline void @@ -3847,6 +3848,11 @@ 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) { + ffe_ctl->loop = LOOP_GIVEUP; + return -ENOSPC; + } + /* * Don't loop again if we already have no empty_size and * no empty_cluster. From patchwork Wed Feb 12 07:20:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11377751 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 43C7D13A4 for ; Wed, 12 Feb 2020 07:21:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22E532082F for ; Wed, 12 Feb 2020 07:21:40 +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="O+JOdcOW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728452AbgBLHVj (ORCPT ); Wed, 12 Feb 2020 02:21:39 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:31635 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728438AbgBLHVi (ORCPT ); Wed, 12 Feb 2020 02:21:38 -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=1581492112; x=1613028112; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NA5Q16mOvtOGxB6peLdverAtcv+FJWEIIZtEwFXx7RI=; b=O+JOdcOWK6adUNYgL1Svac5LRURaxml76MyARcOMHR3kJEfaa/32LyRt Z4qqjqv2LyiDMvtkKp/xEzt37JRcIWsUCJIC5U4tsNSiv1fn0NS0Ub796 zoTr6ALeFdaIEJ16/dmdyFRZgJ+T1/ESr4GeS6Hm11XWOE0s9ImxCPef+ qm0YZkHh9/rLxp+kvNqNK2W7wttxZt8CmZR9jJbBtnQnsQOLpwX3hBRVG Q+PneOCPTyVRMgr8gypS6KXt30GdJ+S01dYkDe0eodZ0cmmtwXrBN1PcG 5htOElfqlG+8WFs6dTezmYM/deJPqs6UntU4O1FMxFA+ljDTEJPCRZ6GR Q==; IronPort-SDR: FX3NRdjAj30K4c8wpJElQjOAom7it4iyARCh7mLfR6/O80yTOtdjEv0eNo/WvXyYKWK0zr3cRU JoSmL9SNzhR28skW7Wowm9QDDKXRpn7u3L7kCujtc0LQmRvsNiPaIkNCldGBBsmxhExnRyOdft sfncBE4Grbo0xr/BFMMTLWoK0TZoA4EpvW2KKs29JpAijc2hii8YGRINqJi5XrHXHnhtdZsD6m bDnGUXXMXlzKYu7ZXTICCYxlFqverx+x9BGWbgxRYjU4cNulIgj1cQAkEDi+tA1blHt5MZ6pMO JnI= X-IronPort-AV: E=Sophos;i="5.70,428,1574092800"; d="scan'208";a="231448953" 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; 12 Feb 2020 15:21:52 +0800 IronPort-SDR: LuLSIsX3TlJhErSK2gB99RGINiMu2UOnTCcjFzQYJT0ynCYvKQjcoLKq2uIGcAsZtaBqN6aIGt BP+OH9qZXhQfYk19BW0cvOXP06vk9sxZMg2vw9v8jIWEAWZ6FXWYzpivjLcjMfhqHenkeQcXxK /MAKnvAA+7YzfIWC2HBh28A06CuMNTpwpcB3SSVxXURippqqSi1jKn+5rL5I4N3o6wekzAzYp+ 13BL9j2q7pMK3gpuOPVgZcmIWq22aIhR5y/f1aSS7VZ2c8NM0TEX+F0sxcSvNiGIiphiwtG/Ea dgGLI//A1LQhR0Am54fwOcU6 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; 11 Feb 2020 23:14:27 -0800 IronPort-SDR: zTTgfgLwTL7PYR5oXOQCa+XPzHRLNj/E/f6JWvsXcbKTcsrpjPVa5Mtscsx1+xh+LfBnpIDo6y UiDR+qLn5r1Aj86XS2ElbnoKx6dm2HhEIIPzbiAiu7B4Ii7B3XNImMPnFvVxPAuyt86StwZ0S5 cyBnqkKrR4ee4mimBSxrWSfp2N+Uhe0r+29y2vyBIsW1CPUw7k7+atl5pl0s8RNsYmQ0gnrllx t+Y35MnTfJm9KxFawWXT6HtuQcGaZX5DF6ovMok27gWkFBGBQ3oXbIgt0f4hF4XTQv70jQSTqi ACA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Feb 2020 23:21:36 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org, David Sterba Cc: Chris Mason , Josef Bacik , Nikolay Borisov , Damien Le Moal , Johannes Thumshirn , Hannes Reinecke , Anand Jain , linux-fsdevel@vger.kernel.org, Naohiro Aota Subject: [PATCH v2 21/21] btrfs: factor out prepare_allocation() Date: Wed, 12 Feb 2020 16:20:48 +0900 Message-Id: <20200212072048.629856-22-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200212072048.629856-1-naohiro.aota@wdc.com> References: <20200212072048.629856-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 3ab0d2f5d718..6da7f6e03767 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3868,6 +3868,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: @@ -3937,48 +4002,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));