From patchwork Thu Feb 6 10:41:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368055 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 481B3924 for ; Thu, 6 Feb 2020 10:44:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2636620730 for ; Thu, 6 Feb 2020 10:44: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="EI48oNly" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728532AbgBFKoT (ORCPT ); Thu, 6 Feb 2020 05:44:19 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728119AbgBFKoT (ORCPT ); Thu, 6 Feb 2020 05:44: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=1580985858; x=1612521858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4YvSJWMUpLhL88HQSt0+R6vDbTg7IOYYN8UIF1uYmbI=; b=EI48oNlyNaO9g+XC/rBi/EKUOCjWI0gANnnb93/ZOljGz3BYNG6cU+ds 3BRiZ3dFSEHbEzT3Z+CqWiF2SroIaNHvqRD4wUxZxf4moBMrgF8rKWhAX HZdk6/ga5qT+9/2VEqTjAU31ZH6r87RGKtwZ2sed18EqZjpiA7231i8AS Fu3J746K/UO+AsZl6XOdoQd6V2ZtIWjiyPMYQHqIWFoa61v7xI00E50n/ ue6eNEwjy2BU3FqZyrwFxzXOE2tLTftNiemdAJLQag3mWCAOT50UJjLLy DCBx0uBMHRxAM+CM/Y3GCwrhrCLHy3+w1K6A2BJbeihWt+2/Mq1nOG6GU A==; IronPort-SDR: /tFawrBFI/Oqm8EJBKMWltIuePIQ11fK5G+ni5cxO+w+TZGs5nnxLrTEC53iBFt1LykepF7aCX Lxng9IMz2kGmrv64EvXizaEWY+BaTVAN//SjVh4Bo3HS+Zx18yb0fvI8pCbhQCM53cnAc7uwYf 2yxmhk56v/5EJT4OaeGcmE8XWuEtb76Hjub5BWyrguj2M70EwCKYeo7hKZrJoNmAst15d1sujE fBR3BUkhLspohWtS7wxJhv5fcvvSHi1Ys9A25Zg+MN6svGAOZqvnBmEvlNEPiRKERK8uqhCWYK C6s= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209477" 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; 06 Feb 2020 18:44:18 +0800 IronPort-SDR: ls5yzpD5TnMWBDKqIYRfCtwctWvetHY7vYGNHfXVcnVYb+x/FeelMdF/wEsoVvj/FknM2qicQU Mqo6rWXeUtYw2LdBID2sJScPkN+8rrCDjHg6sAgDhTuJDvA8sPB+5DqL17vq1RLPS4KybK5e3s n+ttRcPjAI/Imwhwh3KeWHzOkpwKfiw9ucVg9M5JyeXz+jZfpzH7KFSkp5hYMcodPS9uymlJ9r /ScHxdf/S1CuSKg9JJnOxJWalGCYh2lLQ5aUMzUV+PCfb98Iny9+NRGYu7bdKrqyOFTGJJ4le2 dt95/D6hEmjju/ZCes+jVjUw 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; 06 Feb 2020 02:37:18 -0800 IronPort-SDR: 2cJ8Y+LwxVoRAC3PRg/cEUQqvkf77oM5gbLyXNHehv8LKJvIq8C2+VKtLVoAoCRcoNqy7l/HGA NsWXAnrT3s/AU6tx8fGEgzBwxRuyXN8cPQFjziBkB5qfEgUUmnp7wB//juyHylehy9SkXbV7Ju l0wkHoW8xbw3sBzKn0hnPL9kCHYxh4SOvJDq82ue1sj3DGS2sh0HbwaK/c1DPVLInKD8QBkGYn vrF9J1jRDmlYLPN3fs4KwXWMU2Q3Zusz+DLdYufC5oRUncXPjXGsj2c3iqH9uPgXX6ate1zmQ4 064= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 01/20] btrfs: change type of full_search to bool Date: Thu, 6 Feb 2020 19:41:55 +0900 Message-Id: <20200206104214.400857-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 Thu Feb 6 10:41:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368059 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 D3D1D13A4 for ; Thu, 6 Feb 2020 10:44:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3071214AF for ; Thu, 6 Feb 2020 10:44:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="AZ2hpyJw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728539AbgBFKoV (ORCPT ); Thu, 6 Feb 2020 05:44:21 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728534AbgBFKoU (ORCPT ); Thu, 6 Feb 2020 05:44: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=1580985860; x=1612521860; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q3UpyLr0QmBvQMYnAKQmQhFsS12QjUo7UuYiDwZC2Lw=; b=AZ2hpyJwhy5tpD+RsQbUkYx+9G46nIiDaez0fkqYx7jaWGcGzjIH5Wrl N9i67J2rIBlAKs0OHvkoXDMgNwTnAAQNMUfYeUL8BtFhBXlOj0lcNMtsf Dc+iUHXl3boPbzLp++ejXrycq044XhEvsgYxu+N2L9bvyMtVqU7T6+ITQ 9fyNg83zzuFHvbLon3rfHbWwXYaZMzBPh9qPud9z/TeI9oruwqfv1Cmrz nEDLlkj0qKe5hd5/TfIpLT/Ht1lD73P3kJY8u+Mp+bp2inG0MDSFgBPyJ +QigfNEhlivteAg8V007O0MlPGXFOm6NjtBKsvS/YcHJy+6ZHahTz49gr A==; IronPort-SDR: r/YBgQ5rRT0i2Gdg6AitChvSy3T4VZY/BLQ38J7fnYZ7Rt4Aicih3Ij+xp2myZ9HSd/Zya393k lDgJvMc4B7IqeMr3P9Zh+QCLqPap9gRbTn0kJ/4QuD3h+YoZ8HFsO6IQFkm2A1ZMlm8gDc6pXD g6FVIg/Mw1NIHw4u+9Zh3JrCUAICDA0z/rlxcuMkKonEp69Vb7pjFPJErh1Ux3mUoL1fzOi5X9 Q5hfVC6DC0c0NWScxGxzsCjGDCqa0fp422xMKdl9sH7Sz4Ruo+MGJBswEiwRGrpJdfgAeZ3O39 F7o= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209484" 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; 06 Feb 2020 18:44:20 +0800 IronPort-SDR: Myw9wV9bT+Qi8WpInQOawHZXqPk3YzB9jpQ02FlyDkCg+4EohSI1iHnuQVMdjACaH9nDswf9BQ ldyVEMN4tFjs06wRnzXTkb+eeMKm6XBikMDRtCK1JGRlT4EXCTkBuhGC0OzYz8Fq/J/yq9GecR XCDyEHvfWWblUTF8338Ew3oDoKcjuDlY+L7d3hF20GRAfVf1sXJ7uiPDpEcjAjyVPKMr4FDA4C REdSVXZIQ+OyZrIk33UIaXzEvfqp9ctpxiRO3q+DRCydY7P8erWffEul5mx3hzCV3/k8Hipdf1 NlXgKfXd/MfRb7K/O8OsUAdb 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; 06 Feb 2020 02:37:19 -0800 IronPort-SDR: sF6F3tlHp6djiwRseeSE3jzFAX3K3zfA526WVRQozQOgmyrN/X663coTxPpra/bDL1RO0/Ay4O jNrQFY/Jr/ERY/LvOsqNC84FO490EO6tk3fJICjFqPc60rHzSjf8bTwqnfAs9LPMBgDBd+l995 dqHHIO6OCx5CHXyJsYxMnhyYFRxSRR+H+K4Lzs8wx5rmnhmn9uUrpzlr4WEvJRGyODQsNOz/nq VtQlfbynerAyZNMOhpTZleDaQRUf7pONLjStteT6+tqxuFEUFK59htjpxRf0aSEDVOAtau755x Hrw= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 02/20] btrfs: introduce chunk allocation policy Date: Thu, 6 Feb 2020 19:41:56 +0900 Message-Id: <20200206104214.400857-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 chuk 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 9cfc668f91f4..beee9a94142f 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 Thu Feb 6 10:41:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368063 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 68F5013A4 for ; Thu, 6 Feb 2020 10:44:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46B7C20730 for ; Thu, 6 Feb 2020 10:44:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="WvHdONng" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728541AbgBFKoX (ORCPT ); Thu, 6 Feb 2020 05:44:23 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728534AbgBFKoW (ORCPT ); Thu, 6 Feb 2020 05:44: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=1580985862; x=1612521862; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N+QkKiBW9DKyUmLy1nAZGPeXhULyD0Q+ER4MjgDcrOo=; b=WvHdONng4MF0ZMu6XoCgqOflrT9d8NFj014i3ZqvBooRZccabK8lXshr V+mVVNItb/THhjI/nVl2stZ5k/xKZOBq5E5dxjXLpsoXw9or28bzWtG2j m9L21qRGmG16WEHMuJ/h91xJINgeHDxd92vWbOGKZ6X80h10SNPRkPhRQ 4qu3MvXvTvyU9lEEbiqgNznC+Q7ZCUt8zO0Vc5N4b6UqBwk3BL8Ej0gU+ L3LvLuOW3g8P9K9OHTP9JKfJ7rSS1sNQHXo3yW2ZIDex1iRqCWXajzz6w V+IX7Aijezs3ruiZS+1tW5b2de4Cv6SU96ji6z0wVJJTZA7qjhbDYTB0/ A==; IronPort-SDR: Gchi/waDNIFeZGI5/Ge/WZyE41cjhW0K7/4i4nUHNh2X/oCnSBh0Pznij77XOfVKpakFm4wtjg nkGrR8xLGnff99BfTDgvc/bHPZnQV2YF2+Xjz6l7Ja5NdbB1UJ6eSD7C07i68yIRZ1QVkM45EF MAUIKEohlj6QwgyaPkUV+mpKP9BXfYc0vPz3rREdoCZU+vuJ68NN1xZH5zveWAnoAJCWlqaTOu UOIEUlMFEwfDBIKINj8vGc2sDcb5Uvf3J/eyiz48GrL+Rh0ngPhlB4fLIhyzAg8Z4woFd2sQa5 vGU= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209488" 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; 06 Feb 2020 18:44:22 +0800 IronPort-SDR: WFJdf2T6ZGMuOmjw71v+ie6LjSwpPw+1XY4fSRR6W04dRrYRQ2zmTeTI1rJvwrlx3Sc0ISNH8y oBLle8SQIm8PbCUlVovfGYyRlDZ7WppEjGN38j8sWO2tYu9x0JAtoVKoaMLFPy+t15cxVni+Kj SjHwtmUlpewoeNS3b1kvpFgVVde9/uGtztco3oIh5WHZJ42E5z6jdZ4JvrZmGcVWu1iwhrvVpX Q+R9VikUqnhQPbsHnMGkH7mV1D9M+839jGdwQtrTyJAVKfJYTq5xb0K5ifPVdsus9hZlQrkogY cQqk0jw1bnhd85Dnkm+qeJlQ 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; 06 Feb 2020 02:37:21 -0800 IronPort-SDR: lChjNzj7odtW5lgt9e9xIa2kRwsx6MGmNqpjIkDdQGXmL7RwVpgonUbzusvJmxDs9nZP9Muu7N fKO6CipxKN7i8MdYW6u4rfzjAYeIlNRaAPsKgNMLMuPyZ+LKNPF5IXI41DDTQpWPbcG5VoLKYe 7zhd7CqL78urcPU+PgkfXmCNekgwMWHxuhSk8pi37xwPYyDYOb1IDaYoUnjujaMaiimiT1Ck8v RGnBxpcDLFFbauhIb/KSEeBthcySNDBBz+5ci4YulSaoHYZITAvg2zqgPWD33ddvKIQmutEDT3 mAI= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 03/20] btrfs: refactor find_free_dev_extent_start() Date: Thu, 6 Feb 2020 19:41:57 +0900 Message-Id: <20200206104214.400857-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 beee9a94142f..9bb673df777a 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 int dev_extent_hole_check(struct btrfs_device *device, u64 *hole_start, + u64 *hole_size, u64 num_bytes) +{ + int ret = 0; + 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; + ret = 1; + } + + switch (device->fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + /* No extra check */ + break; + default: + BUG(); + } + + return ret; +} /* * 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 Thu Feb 6 10:41:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368067 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 926A713A4 for ; Thu, 6 Feb 2020 10:44:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71577214AF for ; Thu, 6 Feb 2020 10:44:27 +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="IB69G1Hw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbgBFKo0 (ORCPT ); Thu, 6 Feb 2020 05:44:26 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728534AbgBFKoY (ORCPT ); Thu, 6 Feb 2020 05:44: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=1580985864; x=1612521864; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c4ydwjZ/r7kMTlhRRfIDF4/7/q1Bojz3U154DtmyH9U=; b=IB69G1HwXgUEsOQUU0Hs2lAGEuYvJV0O0zgZ4cYvlIU+eI9dT4gvcBOk fK0JwK23nr3Hz1HuCu9a1J5G+tUgNlB0QCkN1hNAlXrBwEvvHccwVOKPU KIykF1de6pSaLIdiOL7aUrdF7EtHOyUKHLuqYCA6CJRQGdgoqq0l+yeWN yW+2Sll9+Ombal1kM3M9NHHA3agS/gn3l9pWNjWkEi12FVtcu4rWx3HxB Ben/XyqqU/FefNlzM4h7hZ8f4Fha8ypijrqMoCHsO/yaSlOY77ZCriTSR e1ksGBWiq6UGkPywRT0rSe8U58l2QRm0p5ZESn5W+ese1F+4pGONGHSkp Q==; IronPort-SDR: //cJmhahaUZvEQUesvE9CUYx8O0/I/F+DLcz75D2AgaIlfw8DOxDSG+3VqSHesiriv+FplMKDn xe1sHhBKmaml3fa1jzAPv2NKvlZM6RW3Xl0lz7LfIuN1/wmlVRPWT1ayZYYH6fsMj+iys/5usQ hxpgaDRERc5P/U7ao25h3ijk2jt/eN5xuTRtzfB684HJAI49ayKPacUjFMf1VAyZL0yDt8Xr0C uMa6Iefcn8Oh85O0ZxYG5rxnOKbtKffesUPfoxz5Oo/8RDOwbLBuU5pwv218M/d56jfprG2xwp nis= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209493" 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; 06 Feb 2020 18:44:24 +0800 IronPort-SDR: MQv/MTJFqUq1+0DfPJZaQLhgoQ2/wB+6fLD7O5spiMboY1xbAt6urTr0gTkjWrHaTdlrReEdaE CwIU+fGGst7LTxoX84y0dZUAZAtOgxlfImmmWTXuOTg2xRibVKv0T00alJ8hJxI4lQYRPpHlS+ q8DFfXrGqb84ZH6r4WEk8PvwomhQIOEbo1sJM5J2eme3AZcJJ7NNnT1iEeJ4KEAuv156BqnLuE p1KXtjPxGWms9vZJ7xjC0mcH/ij0Qwm6uHtlCZpk0ox+KYIF8d7Dojl5tJ27v3k2FuYs+K7yMw WBdBm7KLDeTUIYkScz3Phw9W 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; 06 Feb 2020 02:37:23 -0800 IronPort-SDR: FhFF6gQyg8jwNePhJEYo8Oz2KNXECuHMfJzIek1NIzTXznTWLd31pOevK0avDXOpTYWascks26 efUHtcnSVT77iiIxSfUBfgiHwtq5uEX10fKJ0zKw+BHfqlIcMX+EIkt/6/iyDTOVwygVRci5kF nclmrm7hKdrEENLR+/kCpv509ADilG5s1QNLAlzsw0OzBR0HTFjfbCKKK1+LdX138bnKz/dya0 hqN8ht1+J+L11x3z0JJCoUT7t+eeyrjco+jZ1oUgF94pDc0TXRrRCuKA2ADoMTzPs2tRkXNaX2 rE4= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 04/20] btrfs: introduce alloc_chunk_ctl Date: Thu, 6 Feb 2020 19:41:58 +0900 Message-Id: <20200206104214.400857-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/volumes.c | 143 +++++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 62 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9bb673df777a..cfde302bf297 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; @@ -4858,32 +4869,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); @@ -4891,8 +4906,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); @@ -4929,20 +4944,20 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, continue; ret = find_free_dev_extent(device, - max_stripe_size * dev_stripes, + 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; } @@ -4957,30 +4972,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 @@ -4989,14 +5005,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 @@ -5004,44 +5021,44 @@ 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, + ctl.stripe_size = min(round_up(div_u64(ctl.max_chunk_size, data_stripes), SZ_16M), - stripe_size); + 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; + map->num_stripes = ctl.num_stripes; - for (i = 0; i < ndevs; ++i) { - for (j = 0; j < dev_stripes; ++j) { - int s = i * 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 * 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) { @@ -5052,10 +5069,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); @@ -5067,20 +5084,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 Thu Feb 6 10:41:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368069 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 87355924 for ; Thu, 6 Feb 2020 10:44:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6556021775 for ; Thu, 6 Feb 2020 10:44: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="VS90URud" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728547AbgBFKo1 (ORCPT ); Thu, 6 Feb 2020 05:44:27 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728534AbgBFKo0 (ORCPT ); Thu, 6 Feb 2020 05:44: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=1580985866; x=1612521866; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WVb2Fml4UToQKpz/onea8bOZqpvV38ZjN7YRwIN4PBE=; b=VS90URudXEWl9CYpcAXDJDuXs01E4kXAGQG3w21SUjnjhLO+NQdVxSKH vDjYHhZFLRHN7JLIHeVsd7YiUHXtmPqFAv2KZl6F163pGWg9IWMdP0ssF MGHo5bLRHLFU5WvqWwMjuT80dFjl8TQrWjH4/bVhMLQX0lFN6iex7ORL+ cScu3sIgMfgf0ty/XK502n0WHCW1Ll7/5660O9qj6iH0q0guC3VBWUuHK nKhdRVf/Q9iZ3MYochDoarFF20PF0necNjfDDkAenn83fOF+Oday8NI2Z qnBeU4ZBM0X/0RvfMbqM6tNCBwhPi+To7nAYfsjjHMF8kCDIW3VrjYJwK g==; IronPort-SDR: vRltQV3/I/8CiwXV3fiR38IfaGyvkF+TM07GS+U4QarQ5of88m1R9WPdqhe8cjXujpnm9SakpN 7dqhKT8Eu4lC7CpLmb8G1l5gcW72P8U3IwWw1baPUAo78gxbHXvoxYdkGqs2lZNFP8gwEHT5Qx dIoIsFut5Jilufc+shmQujwxolkC07EB4dCJJCS7iKbTatOX/A9OSJmvSJgu8lp+QzK/IaVGZz +Xrf1tGbOm3MXwSmsjcTrUCRR0FUELpj3GmZleHI0/TOIfuF8uiIMyyq8cfYq3XwLhXaqbNadQ Hg4= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209499" 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; 06 Feb 2020 18:44:26 +0800 IronPort-SDR: r48tn/hTjRMRIZqg2byT60/rkNkczk4KvUhjWRCNFVnrUbG5j7S5ybCJs5vMHK7tEg9paKv3GL cl8xDxbFi2iX38vAxrxGPmqssOF89Sz6pAErjm9DgE67C+Z0C0k7mewC+9y8tOf0rklz0rRhBb vv5ezfp6VfgcS3mUgNpT3s9n4P29p1kgaHroJr1Ut+xZJ6t4QLXgQTtgOgxJcDAF5/Gitae6YI k9oPcV8p0ypM4FAmx0vW4oqKx3SESAjfOHYy5wWa2V9/vEtaq1QjesPuZGKC324ZH1OCo7VG7F k/AfBmAwnRvbWVv+aHbZB8lh 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; 06 Feb 2020 02:37:25 -0800 IronPort-SDR: nDVXff1t6eI2d7u+wddNlr0gDUylbME3AWlv9zmYHjLA+M8uvyO4U4MX+wBsQRlE+lzT+vegL6 u7YHtYeB0myMtAn4PN2S5miZ/Ma0eoHlWmxkLj3VmAP90r6BR+dW5gzcz4QvOr5sPSBFbjvT3x CPiKmQui0G5nUyRN0TwImXXonvmAj17F02FS7InWAg+nwPM0acDCZV38WAl/sI+ii30Pf2cA6m bNJGJ5EvBWlrrPJKZUAbkWuMjH/8SBjnp+jmfcSvSarIl6drHz/DpBbx0KFWQNt+Vq2cNtn6lf /LM= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 05/20] btrfs: factor out set_parameters() Date: Thu, 6 Feb 2020 19:41:59 +0900 Message-Id: <20200206104214.400857-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 set_parameters() from __btrfs_alloc_chunk(). This function initialises parameters of "struct alloc_chunk_ctl" for allocation. set_parameters() handles a common part of the initialisation to load the RAID parameters from btrfs_raid_array. set_parameters_regular() decides some parameters for its allocation. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/volumes.c | 96 ++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index cfde302bf297..a5d6f0b5ca70 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4841,6 +4841,60 @@ struct alloc_chunk_ctl { int ndevs; }; +static void set_parameters_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 set_parameters(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: + set_parameters_regular(fs_devices, ctl); + break; + default: + BUG(); + } +} + static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 start, u64 type) { @@ -4859,7 +4913,6 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, int ndevs; int i; int j; - int index; BUG_ON(!alloc_profile_is_valid(type, 0)); @@ -4869,45 +4922,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; + set_parameters(fs_devices, &ctl); devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), GFP_NOFS); From patchwork Thu Feb 6 10:42:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368075 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 A0D52924 for ; Thu, 6 Feb 2020 10:44:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7674A214AF for ; Thu, 6 Feb 2020 10:44: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="AG3JQSiU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728559AbgBFKo3 (ORCPT ); Thu, 6 Feb 2020 05:44:29 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728308AbgBFKo3 (ORCPT ); Thu, 6 Feb 2020 05:44:29 -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=1580985868; x=1612521868; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iY+OOfKKbJaIT8owC4h3HQcN0w90XXaJ/L8j+ye0u8k=; b=AG3JQSiUDMD//Abnq269Kaa42U0nP3odSIFNCQljCwcHlcIsgqEccIA6 BGhJ+gR8VmctUNg0YGqchNUXy8Tc3D/gJNvoJVfllJC3lU5wKRA9yZ9SS pP1Dfh7LIYUKr30HRyeOPQkDvXeWl7qo+vb4bgozphkXt1/gKwDfv7icb i0Z3PxcxmoNGG5Dbi/Yli4Yu2AmburS8RoufUelAFCOzZ70m9jLCUX85A NSEALxsim6OqqqzrCgMWU57Fd1dhA1Ljyl+femGGUGinoRPp7TOUwwzud DHDF9+KqL2lAuahw3fe5kG+sTF1ifCbEp7B2VhqZV3owPi8UThMF9rsv1 Q==; IronPort-SDR: CMxwk+9xLjZEm17QM0PeVzhPtv5KX2+XzBdc30SojpZhafgqYnCYCy6gQ93MgegNuOjvHbEmI9 UsY8HHKV615gQhDWRCOf1MoUI8it1+IgfXM6zUqxuRKuB0ocKkkAHLV/UbUt7b3CnV9oDXjyyc gwYZJD/Ju8d81lz1/ReLC0iMkjtOhfGLlIe955y0SenW7Rp4MmPHAW/t+Z4Flm79js2E1UNFzB J+KD/jPlUiVHq/aBmncgaa9Necm1ATRSqkZFZLwMGNsQaMedYIA3nhFeMTTiMSKUznNoSKs85w gRs= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209508" 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; 06 Feb 2020 18:44:28 +0800 IronPort-SDR: 0xlGFyKgHdAKJunSQP62cN4XgCy3aVTUtICVblwXSgvCIox7J6qgxc0OLkPULl1GKmSFnmMcGK 162m9JOBdgYYsLRaTNpYasKnCMaAdo+/xxUMcdvpTbrgVKnPM0hTroq8Hvkvyf+PmZST1BiNiA xp0uE7iAutGG94z1Iokde79kOetTIRS9QDL33I2Gqw1YTcPesl5MxqbI52OUItNcvvscv5rEJI lpWo9B4LXGge+MQXw7Bx5J3ihF/F8HbqLHGunC0o85tmLomHZlj+QoQyZEoV7ns0QJ0xLE2IJ5 +fVtJMgRxmtWbVGHKvvTrg8O 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; 06 Feb 2020 02:37:28 -0800 IronPort-SDR: ywebyAjcyDyhDEyXsKxN1dqx9IsM2kaZRDMIOpLNuD2v/CXEdF6cp4nBKA6ZsQoUAI7PiJ3RQF 10NDA0FrDCfAEcnMQukQHNnf4PPfE8ECdC6rImWRGOmtZiPrbJn8Yk62z/wrXjKU9/vGnKD70D KVv5vUoAWnm+H6me4wIV7P86xju4Td3D1yv8wrOmFA4ZxxnF+3nRXx0rgTMD39vjFLhoGCmcVR mCW8wj6Xbll0enZksJGfweUMNaYNP0Or4sbeGDjaaaXfyYCW1AWLi7NkNRDrrSa/BWQ8MVFZhG 5T8= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 06/20] btrfs: factor out gather_device_info() Date: Thu, 6 Feb 2020 19:42:00 +0900 Message-Id: <20200206104214.400857-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 | 113 +++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a5d6f0b5ca70..02bd86d126ff 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4895,56 +4895,25 @@ static void set_parameters(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; - - BUG_ON(!alloc_profile_is_valid(type, 0)); - - 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; - set_parameters(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"); @@ -4965,21 +4934,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; } @@ -4994,14 +4962,59 @@ 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; + + BUG_ON(!alloc_profile_is_valid(type, 0)); + + 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; + set_parameters(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 Thu Feb 6 10:42:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368079 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 25156139A for ; Thu, 6 Feb 2020 10:44:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE8E9214AF for ; Thu, 6 Feb 2020 10:44: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="Im5QHiMm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728563AbgBFKoc (ORCPT ); Thu, 6 Feb 2020 05:44:32 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKob (ORCPT ); Thu, 6 Feb 2020 05:44:31 -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=1580985870; x=1612521870; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yOk86koK/WO8BD/51mSjXedYTlZGA76glGdlVYTVTIk=; b=Im5QHiMm1bEuhjTKXu9g5YD8GZHIXA9h9RmbpGPirPHlTzG+pXuUokJy yJNfezLO7VBEZhmLGHrcNV2f49d1jjkASXgZfZ50ManmeAUmehxp/JrYh PMpu5d7ZR7LoekS/YmAFAXWeCP6BN1uTDBFcIjxqQ0kVm9gSqSsqX4xGw 0uMG3EHx0hDySUn0VGwVpfjn8McyTw6gZCtn8kT5+W9BZWaJnuoumRIgh PxQOvAqXVsWua9LZvcyJYQEeCXBmCkGokH3lvpE0579jrMAcrMtA7vFyK ECttjmZjrGPerSTneuKs1GRqSs6SeIazr68vQ+7wiQi+SM9s+E1VZHIzR g==; IronPort-SDR: hvC/A2nJqjzc5kZzpX/6KkuNmjlGdZaaSrlJN/0hYE6B7RRPyPZrjFzzMU9KoaRQ5xpbZPXJAz T4E8qLHKd3MkVjL69YO/5BzTO+S4p4aDMc9G/qHCMQjjSkPgd+TQcgwcmAEjnFBokUFP1sePvd pWr+iuQzMH/ClA6YVlg1lzeBArdSUw0AdJ1kCmydl/W+FJfmzWL9M/44Mi/9DRFOpUBrUEqw4N 8kqgH1MyiCgT4k4gaqpD+qpr0sa/3Ke61sig+GbNJcwKxAlLd1owZ9D/FkgQNy/RfLAaRqEkv1 h3g= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209515" 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; 06 Feb 2020 18:44:30 +0800 IronPort-SDR: jf6MgPxwjcQa6VHDFZeWWQ1Scu7fUfGuBDjt5qNkCEImFL+ZSZMh5BIG32GV/1Opxo/pGFjm+2 TfMm1GGfarp8iIkQ/loAYTs1C/pDngFagzP/B1l3ki6khnP9+9u4cWlWZfx9Nv2v0ifXjfx3DG SgiyscGoAx8Zb37wfFuTb4X6IftmbVAXIg+utyr8KgSJJ4BB3vshrysoRfudG90eRpBEIvNBnx 0Fs6PL9izfI+El+v1iBi+lOkPZxKHT9vx+/FACsqZ1ispfeWpM8lPdPxAzCGB9x+fb5vuMPQjK oteGCIMozZz/PQKg1zRsNoDX 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; 06 Feb 2020 02:37:30 -0800 IronPort-SDR: aPkiZWG/ERxmVgwv9/B9byqCcxGfeFrOLbwK0hsxwPOLZDtmtOHP+DoSoBqSy8u1ccSzZnhmVd 5Ba6aq6cTmITVJ3oh/ezSKfrDlvMJSmi54eh4u9GDdqCs1sCUDp2fz4X6sAxLQnEV4wTZvRc0K 33zEnjE+AAk+sAMrLXAlLX1LEDa4qrf04exglDModk3rMWDBni/U0oTaUPtd/keVaxXata1Zaz 3JKuK+lfZBWLBMaVCxkt1BFrS/jV9SWNJ2IEHFviOVw23+UgsOravOlOUX3CQQJNDe1PvdQaRT E/A= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 07/20] btrfs: factor out decide_stripe_size() Date: Thu, 6 Feb 2020 19:42:01 +0900 Message-Id: <20200206104214.400857-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 | 137 ++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 57 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 02bd86d126ff..85c01df26852 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4973,6 +4973,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) { @@ -4983,8 +5061,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; @@ -5015,60 +5091,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) { @@ -5091,8 +5116,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 Thu Feb 6 10:42:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368083 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 1397B13A4 for ; Thu, 6 Feb 2020 10:44:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6DF921741 for ; Thu, 6 Feb 2020 10:44: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="p8gFZA1o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728568AbgBFKoe (ORCPT ); Thu, 6 Feb 2020 05:44:34 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKod (ORCPT ); Thu, 6 Feb 2020 05:44:33 -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=1580985872; x=1612521872; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OapUE4/TXFDkDREFr3VroUVQcjh5AHK4xiF6zG3Xe+M=; b=p8gFZA1owtoB34lADSPRfrBh3PIcjvZ5uzqlsj9CzSItYediTtkDCqS3 IuiAL7NwAlNqJLw9taxzqz8gfwm/MFgWik2JuE6yKh4kWJlytqfHedYza Rz4R6nEMxa8kdrYpoCVewu4Qd80JenACb2fAQUJF1/Yw85k/fF7iroMAZ MKcagG49l8NflAv9FhgX2XMgNsmptyH9VjUGdTYQRBAwiAqajQiTK0cOe n/gaHxA0ZxRTfdY2cFJH08oDhzPwiV7rA11dF3P3OUPdek5rI/fHz1pg0 zvQRS2hLyNHqlYRZiX6a4WOIySjm1v3mQbI6zuN1lYaFO5hUdoCgSSJTH g==; IronPort-SDR: i3A0ulnW1riEarh3pKi2TSKzpBHOqBhgRZ93xTIErnEPJ51BAFR/97NFRq/20Qr4yGDeIi3ypQ z1bfXPIemhcMADBvJevdc600rengpn3CIsTrH3nJzG/js7aC26c1Ml6Av0H2gii5T55M9N00xb Mou3n0Y99ctZGmB/631rVdtmk1zqZQiURfGaYnJxN82LdwOcycH/gGU6qszG/DG7dPr6+BO9/7 sejPeyzTHB0X5sHiW97fCSKnuJyv4vw2h6CBmW+TPE/PS7Bh0Af+k/KDj/fyOAhYExMZ+Oiyd7 89I= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209519" 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; 06 Feb 2020 18:44:32 +0800 IronPort-SDR: HXKs7rFTmDo7bKWDHRI2aHNqWHphjkWQ1lHrTaDVLGVHEcoDf7e5kX/omyFYYNsxzk5zHJXZau 5oQnY3HFG8m0cwSnAB3cxagdczlSHNETUJWz3r6n6RDsM80FnKUEiHjHOYJhZEQfK+S6CoUOJ0 3Djp3QP8gjdiMre4BPhrrUvExbESYEAdjZBj1fCjfHEvXT7OtSSdgq3UqTwnIjc4/+hlD9xSl4 c5tzxRn4EPL2WxVNU3jDgFvZ0BGehkban4vfGR5eGAB794m1pJiEPV3niEsb4CjYfFOXOHPC2k soZiSvRHyjrqUlxySyAxoH41 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; 06 Feb 2020 02:37:32 -0800 IronPort-SDR: M3oCF/RQnCLLRyIPEvOh5Qs8BPXwuHYl4sZ2WKxsJBkf8OSc1OVE4vcuaC3eJF1RlGi0U/7q1q mbCzNQLq70t6JUecXOzN9k1Plje0jzdUDCVteCM5EE0N5zXwfGhPGKCgSfuYHKD8WZ6bKKyIEM 1gHz1/pyCrVvVoQTsWQjIwVRi8lqbyMSLyZZvptqSdaxNMpGF94fEFo6JS/YoncbKfVA4twh14 A1pIHk13UjLqnNhOA+prlmqRcFOmxCCCR9pxj/WifbAR6wYMnvFgFBh7RaiIRs7OZWbwrwUg63 dc0= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 08/20] btrfs: factor out create_chunk() Date: Thu, 6 Feb 2020 19:42:02 +0900 Message-Id: <20200206104214.400857-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/volumes.c | 126 +++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 85c01df26852..15837374db9c 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5051,86 +5051,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; - BUG_ON(!alloc_profile_is_valid(type, 0)); - - 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; - set_parameters(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); @@ -5138,11 +5105,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; @@ -5150,20 +5117,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: @@ -5175,6 +5141,56 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, free_extent_map(em); /* One for the tree reference */ free_extent_map(em); + + 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; + + BUG_ON(!alloc_profile_is_valid(type, 0)); + + 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; + set_parameters(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; + + ret = decide_stripe_size(fs_devices, &ctl, devices_info); + if (ret < 0) + goto error; + + ret = create_chunk(trans, &ctl, devices_info); + if (ret < 0) + goto error; + + kfree(devices_info); + return 0; + error: kfree(devices_info); return ret; From patchwork Thu Feb 6 10:42:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368087 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 B05E6924 for ; Thu, 6 Feb 2020 10:44:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F877214AF for ; Thu, 6 Feb 2020 10:44: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="hgiL65Du" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728573AbgBFKog (ORCPT ); Thu, 6 Feb 2020 05:44:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKof (ORCPT ); Thu, 6 Feb 2020 05:44:35 -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=1580985874; x=1612521874; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vVemCP0xNYYaPjT5DDr7EmVm02gdjnLY5u6jKJpIfmg=; b=hgiL65DuumB0Xx7WWdhtNveAWBzIO4MA0JsyGivv6SoVAYAwuSLitXWV Vprm6EOTSRDpyf5Ai7GK4biGWprolUoNV83OQeIwM/3Hp7U6bsSIz0mc9 sG3LX+DXgjYE6f8P/6vKkkyupJesFuUPr58j4nskRTFt2lHuAUCe8oIFo kpGwnPY35cbBKCCqDObQ5R7VdA+zfQw2wrpHnB9zJ+l1JQytDJQqPf7bB cmhglfp+ApcvOnI6FGBkbzKvV43KgC7dy/PweVuTTshL/jTqNo4mAVtvK USRTHItfJnFqJsrcGx0Mc4DbFGhr6zztfdwAODTOnVY7RBUZQz8CsOiDC w==; IronPort-SDR: Kqr24Flayh9GRHqTkOfN7cXVG5rh/cOCnge4X5dxe6FB+CAnLiKCrgWdgXA+Qizt68xVjhiuOW 55BvlwI8MOU1mAIUg9yEDv9+qPB+qM6gM3xE3i62XiTpw6sekhYo6pMD5PjrKch0ss/O10uc2N 7mCL5PBZnPFJ8aG+1l8j51GvufquPqBJaTh/dMbDH3DhbpTx+98V5FcwogjfhV6uhQ4qExUBd7 SJtD1sUk99kc+Xvno2G5uleSMw/Wgb1Vtf9MLKcqERUGxAK+TYL6loIimGGMM2kw8lf3rkx7kJ 5p0= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209525" 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; 06 Feb 2020 18:44:34 +0800 IronPort-SDR: 8PgToHsg+cQv7VJe/QKB1WDnUjHz96ny3JxfwAG5trG7h7F64XNDu7AayvKMUN34BkYz8q66c6 UooPYbrXl1rE150/81l/6dCPbN5XR9l87rai/lTydhM3emITpU3Hwm0EQ2W/QStY6J/FYk+9yI IecZ0CPeAK4OBnzQg2sbGQ/DJTfPgGnW80+Z88vBPe8IIO0QHn3U2hucYHTzZ0bVHCzFHpiK2l OAuyZgSAku5adBM53VHOQ59o+WfLysZSGrRq+AC2dqjNzpGemO3Kw+PBHJlFk24MKlX48XecCy TlVyThtQfPXngYG7TthiQ2Ll 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; 06 Feb 2020 02:37:34 -0800 IronPort-SDR: l0FXs5nBHWJ358tW3J5es40Fnpa6IxY/M/R3m8p4/nriJDsVDn6Lv2N4/JNqe/TaUuZm/k5n5T ZmTHYJ8d3PVNK0x7BEFGoAHPSNoY8j/XaFV0UCuZio8PMgNLLGoVYE5snice1ocR0obz3ezG0C 4mCTQqnlsE7hkW6K+8R4ErZ46+OhocmdSFXtot7VB2TktINJ81FiFY9j6YKL0FxAS1hZFZmsLy AqSZzGN7axfZAn7cy+33fpNxKWlyt6nGfC6+WP8RzjQMQjMeoETJmBg56bZ8aE9Coe+QcLSnou v7I= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 09/20] btrfs: parameterize dev_extent_min Date: Thu, 6 Feb 2020 19:42:03 +0900 Message-Id: <20200206104214.400857-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 15837374db9c..4a6cc098ee3e 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; @@ -4868,6 +4869,7 @@ static void set_parameters_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 set_parameters(struct btrfs_fs_devices *fs_devices, @@ -4903,7 +4905,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; @@ -4931,7 +4932,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, @@ -4942,12 +4943,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 Thu Feb 6 10:42:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368089 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 452E5139A for ; Thu, 6 Feb 2020 10:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23E9220730 for ; Thu, 6 Feb 2020 10:44:39 +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="TXOdlQAI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728580AbgBFKoi (ORCPT ); Thu, 6 Feb 2020 05:44:38 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKoh (ORCPT ); Thu, 6 Feb 2020 05:44:37 -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=1580985876; x=1612521876; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0mLMyvXISJkKtaveQS6Ke3dOGw0YjpT7RmJIVuVCL8Q=; b=TXOdlQAIIXqlQ4UQfnNWlXqi8uBdZzz5+NObCwC1+tq36JSHg3k5R21T ffIo5iYQTeRjWM+DBtmWw9R3RMWbxlecJUiUJYdWLAl/bdFGjsXFbIlEy kDfPE9hawLlsPDGSFajwETbgMPF120Dvmh7DS5hR6I1GX2a3CKz92GRoG GDYxf8NaNNs7c1SOr6Qfr3TZGi33NUQQnWNsOnOR2lApvj2fkLdhEUkyP mVw6GUWUPy8Zc60tivHWElgEtO6ddAT10rITlJ2cCbsi7Gkq/kjfY4uBD 2c1jVMxlVtovjSb+qoEs/HBcwJ1H0qS6+SC2X9HqlOk4gzHvBZq1QjPxW A==; IronPort-SDR: 3AI19ja2s/0SFD+/mNrf/5bWOpaqB3Tx2W6tAxMzMdP3Xn3e+CEulUm2Kz7XMqWJzLVpb7qrws p+qCSOsj8nnfwXdYTT8uljHiVsUTyRMRPL8KBBNJCT/f5IOJMZeUVWB8UJTRAYqdrywDfawLT5 mkSxIhRZJSzAEmfJUiq15Y4WwNQvz5MV/wxvwhV8VaKBd4SNbguTXy3mBNaXwaOBxN7SsKnezD 8yAFPUznn7GJtj0kNHqUejb+2Pn8bC4W7FZxPBgydXZ6XLTo4cchhOHuruwehPPaQQBbgYEfVM Iro= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209529" 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; 06 Feb 2020 18:44:36 +0800 IronPort-SDR: IWc0jNE4+vfzfvManjmOq1weBy6gD4QgrlAhmXFl92p3M7I7pgdi9d6OPFTGd/5vysj7U9Jqca EmJBBS/z2rMVNZscSR1yQaYkiJ1TAiMZ1Z9y4fVqBVgDFcAhdsWXO0FT0KABsXW7zW/fphF2WA maoeBchn6lTOz8X+ezh9WQKBux6kbYz7sdyoURS0uYvUs/KecivpiK2m6UBtb3fvhdv/t3aY7c yiNMVv+p25QgdM0RiRV40vnM/i1gSsSGi6e7xX2xoawmhQvrzT4b2SqJXDwGeNcBD7I3atNnaa czXY6yRBTVCI/3pV8AF2v9HQ 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; 06 Feb 2020 02:37:36 -0800 IronPort-SDR: RHVjB6SlHuAdz3hXbCGVQE54NnX5y7ZUxynWUtSHJByo9NKEkgnIXuSTbJ8Fp7V1kUxodADsMl aL6qJ3L2C8SPl3Usbgwh+xm/9TdBWKYlyySNeet5DEugG/IMrE6qCVIa0Qy2dvnFlmklvI+cCv 4brFPcuniS9m/staK+lAQayq9jHkUMJ6TLe2MZGwQctytU3/AYSidJcNiRvA46z9/htkbEWpFc m6rRCpIc92BY5wtzhU50GvQnHAZRGFLq2erxJDMxG2xniiSrFWdmCWrSAVVF+m1CsUgpvSk1Fz /6s= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 10/20] btrfs: introduce extent allocation policy Date: Thu, 6 Feb 2020 19:42:04 +0900 Message-Id: <20200206104214.400857-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 Thu Feb 6 10:42:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368095 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 5953A924 for ; Thu, 6 Feb 2020 10:44:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39352214AF for ; Thu, 6 Feb 2020 10:44:42 +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="i+i1OkLo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728581AbgBFKok (ORCPT ); Thu, 6 Feb 2020 05:44:40 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKoj (ORCPT ); Thu, 6 Feb 2020 05:44:39 -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=1580985878; x=1612521878; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7kSGCvaay2SG1nIxMcRDLO5KnT8tOtaO/l1P1KJNuCY=; b=i+i1OkLoSu3hnxz8BNrvz0cP+UYVQmSUZMr6X0GyY7jzZC6om9NSLst1 Nvu6N9zev5PxHrJ67wjDBsuvPaWqaVyvxkLja+h+cp7NjjQ7bJfZmNDrV ZJPhLT77kZ+JXCaRRF70pNLzE0TZfrdOU0HpxEtG5tZ5ZKMWnyivK+TOf NwU2uyo+Doo435xasKDXzcnB21H4s1i4dxGWEiBBtpxRpJ8wigHY2+sbc Zd2yblol25/WpO5HC0JEXEb6HsjPArEUbpy9f7504wOZD7hwHGGqAS5mz f7e5YUzLOnaBXPqeG/3zsXeT703hIkxAw8odRKE99cEruRdbPwPHICu+1 Q==; IronPort-SDR: jEP/QREmE7FKnpJRcmDO7efOYXKw/C6Ee+TGew5sTwqlAWCqXIZj1/AhQRHaQ0EAGKezP6GkVU vCKUtN73OWgc10WHjmdmkuB+pKtIoTAshD9AovaYYRTkJkR1DqljEnMlBJOtrxfuiJDZ5RNkRt XSBqQbwLNJRDXb73MwFAO9iknOsx8ksttAb29HjgHOik+ihCWw7ZaxD0hp/hHMLfIVEJKU1zk1 n50GJ9E519mZJNllzW+vX9KYDn357TDeqN/gYQF8xDLk7JrvxvTWef7ZuJCCH3adtkvXEUO3rt +pw= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209534" 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; 06 Feb 2020 18:44:38 +0800 IronPort-SDR: h0xFgMrQKK9H0OiE8Wq6X3DT6H79UFU+FPl1oxHTw4ttOiEcWjCpxZ/7oFvtw+hQUdscHICsmF 9l7c7G4bTuv2lx4hPtRt+K0r4+SBT7mqcxuvpRhdfY4vwwVGY39/Z/GfzPlBo7a/vhEp8kzpt1 Ju4TaOIFZTvPvHjIvFcoByMfOoG4n+IoKOP5ab7xYqwXyoueqYefIVJeMOsT1U/OJ73Dx0KaX0 xEurDtn2ygXs85Bjx2jH3LbRGV0qMAUio+K8ZykJS8CQwtfuZ0dT/ojG0huWLCHxCb44+fU8mk cdhTUE9dVXBMh4VUvDb0vCP3 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; 06 Feb 2020 02:37:38 -0800 IronPort-SDR: BGd5LnyGzcrNSr0OXSZBsTxbiLrqb7agv3fnqOkJCCunZ8K7aPGlKPGbQjy0xeWY0hR8DNwBZl 8+zhkFTXyIKRTk7Lma/uJ/rQesA5gnsr4EKsHacX3smCMPYJxnRjOd3Fk/yozUpdkjyPD6xHNw YVNzrrLE3NTnTcQ9S8+/kffpmtw5456yHfOMlm+fNdUPEj+snfdTYhdt1gP/yoXtDOsFPuU/vK 9+t/Iv8Gjh/LoRlLA4sxQIKNFTPMHOIXAZefYLGT1G+IEMIPW13prhglCFCMl3ZYaB0y+Txk6I cfk= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44: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 11/20] btrfs: move hint_byte into find_free_extent_ctl Date: Thu, 6 Feb 2020 19:42:05 +0900 Message-Id: <20200206104214.400857-12-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 Thu Feb 6 10:42:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368099 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 A067A13A4 for ; Thu, 6 Feb 2020 10:44:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80624217BA for ; Thu, 6 Feb 2020 10:44:43 +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="qir0KULf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728589AbgBFKom (ORCPT ); Thu, 6 Feb 2020 05:44:42 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKol (ORCPT ); Thu, 6 Feb 2020 05:44:41 -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=1580985880; x=1612521880; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AjFIfhr3Yijk4gg0CsrjosAdFdH4aBa0QxyQ8z1GznA=; b=qir0KULff0ByulJ0/QxxoPFwnfnHpf3Y+AMVcf6u9tq+PwjSrdvH1hxh ZAEBDU5Pl1wnDiv3kmx5QzpGtB1Ub968kum/N9AAyZT0PPe+lJFY/z4xl GP0+zjCG1Z2zior9cGV6dqVp25M3XngXvtL6oojGt5ZQz4rdGp5FSHzmB sv9HmCx6ivUQFjhdYD4tNZcs5pAw+G7y6FVA/ARPL22msZEZJURuhXO5v +PrlcP/xue9AhLwW2nFg5xP1izpYsqoA0kfaIwddotXJLeUj3lXZ0FZB7 yxHv6nzMzNer9UYtLdgDU+WXWGoI9jGF7rcK7+/CyTxzLQRtdfILVEKhA g==; IronPort-SDR: yhT8uvt0VMeGpA63psYc1g61QzDX/2H9JDuG8D66WCQ2UUf+VtfuNSGsQQyCdrcDuDdzcPV6Gr Js+GeGzuaQRGv2Fq3LljRV5rYC6DFHDXEmooYRzEU2sO2GX7geuWJF58bIy/JyP0fwbpdpY2bH O7PtG6XcQC10up5cG+W/PArlL950E/I4AhkgRCnILT7WpzsHxhTUsH2UblQ2zuZLGdx8qIpQXc 25uDVR1YAGK3YDe15NnL4VjuGvN/sohJvGKXhDeT9RtnK+PAPWP2WtPw/EB+jDZNWOh2ptq5mt 5+8= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209537" 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; 06 Feb 2020 18:44:40 +0800 IronPort-SDR: ZkCrN1sUPqVfQ8qWn0B4nq71GlL9+WQysWxp9oNIkuFWTiGzGhhUE9ueNATQWedNmN0gKq+RHH cXSoEGPcZcNBuOnyJPY94KQXRVxbthTkwE48AzhoE2JhM6ZjL13ui1wD2TiTr7usX3y51Dq7uO roCvoUf7D8DIgzKYdCOHXIto9WZLd1ibzF061/4YAak85GLrKlF5p0WscYP+cpURZCl0ytfQmd iwD7E81UTDC8ux+ySjxFxAD9lwrmh/Rp3AQw9NrnaoL9tfI8HrT3XQ7AePaSAn7eUS17MIDcEW aoqDKgOVdcv4F9IcOJcBS3Fo 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; 06 Feb 2020 02:37:40 -0800 IronPort-SDR: M5R9hF5VkgvwhrdFMrPbPfejJ6IzSARkVaXTBbsWRl+b7B7pJQF6KlDMW/E30nnHrzqr+Vp7iI YSnApChfZ4QPCo++rpSGO9twLVDdH7qIVH/Sm/JTt2qDwO1tH0K9mDazhthwl3hChzjt8+V2Hj 4uH3CwfW4fgEjbMupj+vDu9zInUKGwt+3l/mQbI1pP1YvJMFZsXSWJxxkoLb+QZPJJwf3iswo5 /8ZaOeISHhGSbNsNMYazpQMwXo3U/mFCB3jxQ1+JqDrle16pevhgldLe1ab6zv1hL/IM6nB/lu R9M= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:38 -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 12/20] btrfs: introduce clustered_alloc_info Date: Thu, 6 Feb 2020 19:42:06 +0900 Message-Id: <20200206104214.400857-13-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 clustered_alloc_info to manage parameters related to clustered allocation. By separating clustered_alloc_info and find_free_extent_ctl, we can introduce other allocation policy. One can access per-allocation policy private information from "alloc_info" of struct find_free_extent_ctl. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 99 +++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 40 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index b1f52eee24fe..8124a6461043 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3456,9 +3456,6 @@ struct find_free_extent_ctl { /* Where to start the search inside the bg */ u64 search_start; - /* For clustered allocation */ - u64 empty_cluster; - bool have_caching_bg; bool orig_have_caching_bg; @@ -3470,18 +3467,6 @@ struct find_free_extent_ctl { */ int loop; - /* - * Whether we're refilling a cluster, if true we need to re-search - * current block group but don't try to refill the cluster again. - */ - bool retry_clustered; - - /* - * Whether we're updating free space cache, if true we need to re-search - * current block group but don't try updating free space cache again. - */ - bool retry_unclustered; - /* If current block group is cached */ int cached; @@ -3499,8 +3484,28 @@ struct find_free_extent_ctl { /* Allocation policy */ enum btrfs_extent_allocation_policy policy; + void *alloc_info; }; +struct clustered_alloc_info { + /* For clustered allocation */ + u64 empty_cluster; + + /* + * Whether we're refilling a cluster, if true we need to re-search + * current block group but don't try to refill the cluster again. + */ + bool retry_clustered; + + /* + * Whether we're updating free space cache, if true we need to re-search + * current block group but don't try updating free space cache again. + */ + bool retry_unclustered; + + struct btrfs_free_cluster *last_ptr; + bool use_cluster; +}; /* * Helper function for find_free_extent(). @@ -3516,6 +3521,7 @@ static int find_free_extent_clustered(struct btrfs_block_group *bg, struct btrfs_block_group **cluster_bg_ret) { struct btrfs_block_group *cluster_bg; + struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; u64 aligned_cluster; u64 offset; int ret; @@ -3572,7 +3578,7 @@ static int find_free_extent_clustered(struct btrfs_block_group *bg, } aligned_cluster = max_t(u64, - ffe_ctl->empty_cluster + ffe_ctl->empty_size, + clustered->empty_cluster + ffe_ctl->empty_size, bg->full_stripe_len); ret = btrfs_find_space_cluster(bg, last_ptr, ffe_ctl->search_start, ffe_ctl->num_bytes, aligned_cluster); @@ -3591,12 +3597,12 @@ static int find_free_extent_clustered(struct btrfs_block_group *bg, return 0; } } else if (!ffe_ctl->cached && ffe_ctl->loop > LOOP_CACHING_NOWAIT && - !ffe_ctl->retry_clustered) { + !clustered->retry_clustered) { spin_unlock(&last_ptr->refill_lock); - ffe_ctl->retry_clustered = true; + clustered->retry_clustered = true; btrfs_wait_block_group_cache_progress(bg, ffe_ctl->num_bytes + - ffe_ctl->empty_cluster + ffe_ctl->empty_size); + clustered->empty_cluster + ffe_ctl->empty_size); return -EAGAIN; } /* @@ -3618,6 +3624,7 @@ 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 clustered_alloc_info *clustered = ffe_ctl->alloc_info; u64 offset; /* @@ -3636,7 +3643,7 @@ static int find_free_extent_unclustered(struct btrfs_block_group *bg, free_space_ctl = bg->free_space_ctl; spin_lock(&free_space_ctl->tree_lock); if (free_space_ctl->free_space < - ffe_ctl->num_bytes + ffe_ctl->empty_cluster + + ffe_ctl->num_bytes + clustered->empty_cluster + ffe_ctl->empty_size) { ffe_ctl->total_free_space = max_t(u64, ffe_ctl->total_free_space, @@ -3660,11 +3667,11 @@ static int find_free_extent_unclustered(struct btrfs_block_group *bg, * If @retry_unclustered is true then we've already waited on this * block group once and should move on to the next block group. */ - if (!offset && !ffe_ctl->retry_unclustered && !ffe_ctl->cached && + if (!offset && !clustered->retry_unclustered && !ffe_ctl->cached && ffe_ctl->loop > LOOP_CACHING_NOWAIT) { btrfs_wait_block_group_cache_progress(bg, ffe_ctl->num_bytes + ffe_ctl->empty_size); - ffe_ctl->retry_unclustered = true; + clustered->retry_unclustered = true; return -EAGAIN; } else if (!offset) { return 1; @@ -3685,6 +3692,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, bool full_search, bool use_cluster) { struct btrfs_root *root = fs_info->extent_root; + struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; int ret; if ((ffe_ctl->loop == LOOP_CACHING_NOWAIT) && @@ -3774,10 +3782,10 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, * no empty_cluster. */ if (ffe_ctl->empty_size == 0 && - ffe_ctl->empty_cluster == 0) + clustered->empty_cluster == 0) return -ENOSPC; ffe_ctl->empty_size = 0; - ffe_ctl->empty_cluster = 0; + clustered->empty_cluster = 0; } return 1; } @@ -3816,11 +3824,10 @@ 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; + struct clustered_alloc_info *clustered = NULL; bool full_search = false; WARN_ON(num_bytes < fs_info->sectorsize); @@ -3829,8 +3836,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; @@ -3851,6 +3856,15 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, return -ENOSPC; } + clustered = kzalloc(sizeof(*clustered), GFP_NOFS); + if (!clustered) + return -ENOMEM; + clustered->last_ptr = NULL; + clustered->use_cluster = true; + clustered->retry_clustered = false; + clustered->retry_unclustered = false; + ffe_ctl.alloc_info = clustered; + /* * If our free space is heavily fragmented we may not be able to make * big contiguous allocations, so instead of doing the expensive search @@ -3869,14 +3883,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; + clustered->use_cluster = false; } spin_unlock(&space_info->lock); } - last_ptr = fetch_cluster_info(fs_info, space_info, - &ffe_ctl.empty_cluster); - if (last_ptr) { + clustered->last_ptr = fetch_cluster_info(fs_info, space_info, + &clustered->empty_cluster); + if (clustered->last_ptr) { + struct btrfs_free_cluster *last_ptr = clustered->last_ptr; + spin_lock(&last_ptr->lock); if (last_ptr->block_group) ffe_ctl.hint_byte = last_ptr->window_start; @@ -3887,7 +3903,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; + clustered->use_cluster = false; } spin_unlock(&last_ptr->lock); } @@ -4000,10 +4016,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 (clustered->last_ptr && clustered->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, + clustered->last_ptr, &ffe_ctl, &cluster_bg); if (ret == 0) { @@ -4021,7 +4038,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, + ret = find_free_extent_unclustered(block_group, + clustered->last_ptr, &ffe_ctl); if (ret == -EAGAIN) goto have_block_group; @@ -4062,8 +4080,8 @@ 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; + clustered->retry_clustered = false; + clustered->retry_unclustered = false; BUG_ON(btrfs_bg_flags_to_raid_index(block_group->flags) != ffe_ctl.index); btrfs_release_block_group(block_group, delalloc); @@ -4071,8 +4089,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, clustered->last_ptr, ins, + &ffe_ctl, full_search, + clustered->use_cluster); if (ret > 0) goto search; From patchwork Thu Feb 6 10:42:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368103 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 1272B13A4 for ; Thu, 6 Feb 2020 10:44:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5B6F214AF for ; Thu, 6 Feb 2020 10:44:45 +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="N2eDPBd4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728584AbgBFKoo (ORCPT ); Thu, 6 Feb 2020 05:44:44 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKon (ORCPT ); Thu, 6 Feb 2020 05:44:43 -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=1580985882; x=1612521882; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wZhhXGMKeReJGrz0aGQnZVe+maRMLAzreVSLwo1NJ6w=; b=N2eDPBd42emJveZZ7Mdw2F7+xtvg3H2ek7Xvj9i0dFWNanIPZFtvLGrE o3rM/e3Y4GZA52KdoAz7M+/IAtw5OmCPaDaxVYevc5auhi4UxuX6vMY6i K5UcbjsE8jGcTbsEQEjA5BOJokHhDXdV8+ZTkrIcmCGa0ADEKrjxao4M4 y4N/6Dywxiod5UDuKM2YdL8BDcnrVjfej5FxuNxhwGS/Ed3MTUYCmValX NQMJRNbLZopbISGgc7KTEppgZUsKmEujq0xl98kIksPhc2sfv57A5lJxS QyzgCFgarcS+YSTwQXP3KdqQc28v9q98hbnIAWQFLckCGz72kJWtOcl7a w==; IronPort-SDR: c4YthHZ2nQuvUlHSxo4MiQ8Da6hZMD5FDuI/sDCM3Gbqx1JjT00O283nCxpPrtURiZp0EtanGa 4/+kqoODRV61qJ7/jPctfpwUoyeLJe9QfLbnE7WDZwjZ8Axb3HP1p4oHBqzAOPmnZQysd3U92K UM+9imFeaIexBPrRKY9HAicz4wbpi4zximrfNxlEXHpv4zo3YZw37qU9D594/9v7JQaf2m1/Dk 6QMaoFKcO/0S3QJren10hjJ7sJ9gXyUDLyTdPu/aeWwp8tuXgMSnz2gPExB3DIRKZNnU1Smbtm gsI= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209542" 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; 06 Feb 2020 18:44:42 +0800 IronPort-SDR: I2VorJhqdIi4O5fUw4Z/Ng5yTb6Pq8Ab7zjuUt2/icWqcPNwZbOLT5A5Xu7Wa1Svrks7RX7JHB MNeflpcj0ijn5JW2Vn5GTTmcOecm7XlScFgNaBp6ghoG3RKmHkBlr9oJ1jLFakIJDktOCixVnV AU+4oD0c9vaEgcIDuLmvg1A7AwZ79ep0YXHKPwt3Zefu/OU2v7xG060usAmqXVWzGatlGhQFnn f5JNPcv7HGWAm6NA/wxkY/2sSjMtvluzzlkBgc2Ietc9jiL0/WpSJPec24SrzCc2tRJpPPXLMe dYO09kAcSdCb91RuAUvqtjgW 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; 06 Feb 2020 02:37:42 -0800 IronPort-SDR: rxp3a4TiOlwOnEksuD/ShZxmoTgaR7Q8ozOqFfv9wZQ5JiwnSVVxTzJEczZequ+dr6VJVHBeB+ oLTcyefCvmChmMSDNwq5UB6DuqJtYMJaXwMMOR0CLRVNKY3ktpRZu5qJRxMzyVewFpynF+mCDa YE76iZqQZo/qRSEpEDU+JfWhGw0FPodTVQnuxqgmiUOlxPz/+1HXThJB8OwA4En3mzosgPj/l7 U0BWQxrcIPPyeOHo5qRHk/1LfWqcKW9UXjYPXXlH5SLAccCH5CjgDEGY+Gw/emYiQfysKYcxhW xxQ= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:41 -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 13/20] btrfs: factor out do_allocation() Date: Thu, 6 Feb 2020 19:42:07 +0900 Message-Id: <20200206104214.400857-14-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/extent-tree.c | 81 +++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 8124a6461043..d033d537a31d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3680,6 +3680,41 @@ 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) +{ + struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; + int ret; + + /* + * Ok we want to try and use the cluster allocator, so lets look there + */ + if (clustered->last_ptr && clustered->use_cluster) { + ret = find_free_extent_clustered(block_group, + clustered->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, clustered->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. @@ -3952,6 +3987,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; @@ -4012,41 +4049,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 (clustered->last_ptr && clustered->use_cluster) { - struct btrfs_block_group *cluster_bg = NULL; - - ret = find_free_extent_clustered(block_group, - clustered->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, - clustered->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 Thu Feb 6 10:42:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368107 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 3C6ED13A4 for ; Thu, 6 Feb 2020 10:44:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1BBD9214AF for ; Thu, 6 Feb 2020 10:44:48 +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="XcYRRuBw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728602AbgBFKoq (ORCPT ); Thu, 6 Feb 2020 05:44:46 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728556AbgBFKop (ORCPT ); Thu, 6 Feb 2020 05:44:45 -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=1580985884; x=1612521884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ES3r/Y0ptjQAMXQVg2c4+1XZs2rCnxQ9Mt5HA9CYEvA=; b=XcYRRuBwaajFJMD21YRQOpUjQmzXO7Gs2TuVZNuXgN7Wbuekvv0n5rnB SQOf7g+0PY9+Svsa4+UX6rV0IV1kAcOno1AWskDxvxlAb7+eIETFrOm4C ZyvqKy5kgqNPJe7E4Rc7Sn36mUetM8+IlKGJxEOH+r+OaJ7xZ4xSrn6S1 WbOt9REZP02ckosL8OWa/G4JDvaLHqfLFLJYmSkVX9M8c4di7PYq5N2a9 5OG4azWz0TwxcOBMzeqyeVrHtUjdtOJsmfVCot/JDjcQNM0dV5IMaNMcs CLvNBXDdm8m6CqXWZX+3rlKGLWAjSww4aV1nZvVQUu6z/YkEpXq/rbYBa Q==; IronPort-SDR: eXPug8kvUX6kSZZzNvCV/083JVktGjn+bPI2Gsyllcd0AWaHYXrGzIS1zEBwkmg/EuPs57M3UJ eK899SIGYZBNpk787ANRmygLFJzZ6LXcE52FKN+hDHxPnbriRzifTk6FIhZEPVloT/QXVQbSHp IbMN0S3zzPaPx7A7UfHlyu4d8urOStNZhxmVNVRcc9D2FAlTHlnMK6GtfrJrvNoKsrA7hc8v7S 41xzlKoOxiCssvB5llWDScdvumS3GYbD0Dm+Zh05wzIdVUVe/Y+pTY/FLzapGEFxf0LSd+0jeN nAY= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209546" 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; 06 Feb 2020 18:44:44 +0800 IronPort-SDR: CDS1K0P+JRryoNpGoJA15/FNrWUSvEKmglwOpri0gaGlpbmqmWQEalcu98p1v/As4ZyP3QjtUg DMAgnnCZkaywDabwAbhZVw2qakrNCXAVYIZoAQf0T4Y/EvvJ/EyTryQU4O1yBn+KpWZeqGm6P7 tkSvfrQ6ukNHJcw3gGas+15yl1lQu4DY2j7nb5q7XBc+xIyJWY2PIMVJFQcmk8nVggh/kSSXrG hn6HEqUBgY4J2mS24VJjUsQazrgDKaQis7pf8kNvMx0px9Zht5pQrwIEFuBGxjoKSC4b48cLOy iDKSidKlH7wtjqAXuEr6Exto 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; 06 Feb 2020 02:37:44 -0800 IronPort-SDR: 0G/ajYKBNGY+JnDHP2N5cpnyXsmkt52PV39BzxSBSF1Kkyyin6bKc9IQbEGBR3yz98Z2DKuiEj 6pzpSEXk3C/zWc3v3IuEz2h+V3lXcxs/1WTca1a23LCejwGn7XITcuydY210OXYv2xVaDxH7Ve r+JOD0n08IbtUjDsjZXSoQOLlLgds50PJgXVhHmkQxQIHa5p0JkBRbzZQrPnhyc4OfbQWEdVEQ 3M8jHC9Lbrp41t60d978RDQ/JnqX291MW+Ar0YrbaOU+XiHeMTqZA0jT+pHasOzxHVC6H2rye3 grY= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:43 -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 14/20] btrfs: drop unnecessary arguments from clustered allocation functions Date: Thu, 6 Feb 2020 19:42:08 +0900 Message-Id: <20200206104214.400857-15-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/extent-tree.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d033d537a31d..0e1fe83e5d79 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3516,12 +3516,12 @@ struct clustered_alloc_info { * 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 btrfs_block_group *cluster_bg; struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; + struct btrfs_free_cluster *last_ptr = clustered->last_ptr; u64 aligned_cluster; u64 offset; int ret; @@ -3621,10 +3621,10 @@ 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 clustered_alloc_info *clustered = ffe_ctl->alloc_info; + struct btrfs_free_cluster *last_ptr = clustered->last_ptr; u64 offset; /* @@ -3691,16 +3691,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 (clustered->last_ptr && clustered->use_cluster) { - ret = find_free_extent_clustered(block_group, - clustered->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, clustered->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 Thu Feb 6 10:42:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368109 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 5D897139A for ; Thu, 6 Feb 2020 10:44:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CCAE214AF for ; Thu, 6 Feb 2020 10:44:50 +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="rTXpXiE0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728606AbgBFKos (ORCPT ); Thu, 6 Feb 2020 05:44:48 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728604AbgBFKor (ORCPT ); Thu, 6 Feb 2020 05:44:47 -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=1580985887; x=1612521887; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lnVdddzYJtsYF0X/v47ws9xVWfRcDlWcoZiexqrpnuY=; b=rTXpXiE0apBcO2rzHXSUleOUBp8MoT4hsaFzeqZeIYRnPyLJFPQ6tAMI uDjbyI3qbBsCOaKN4nXa8IsHo/mguOLK1aWEWKs3p+Z1HUpz4sbgs9zSk +6OHLUvNWjNJdcW4f+6vXh7VKr6HiTQoxnNBcW98zhvCmVEd4PJp6yuGv GSlis0AMAJdwEADsaV41dwtBxKSYHeCBLkeoB3oQcfQplHxHYnm/afQ/k urjvBHOdIcHKB5Z49UvsZYCJRHJU6wzSiWmpsfXJ1DAtjPUtMXujb9uPJ 8GeH0kkVYwzHQwzw7DmsWF82iL4WBCVSYB3Gbf7DBPeUNbOt6hQWU9bVL Q==; IronPort-SDR: /2LaYIF1TOaAgqufXdzMbA7dybwHK1PT2Nke1IYIEdg5IFoB/lyzfMivauhPUv0Hv5Js7ZyE1v myBAg3ijnmXHxKu2V/tZxHxfs+VSdAUvFLuqis5P/gLQHGPZrw0BQV3ax2Rlsq611LDFim9wWV 7SlfjUC+91yUrB8s1EeyotveLduJb/DnXnvoOI9x0eLaE6A5Koji9HVQY0o0RQcw1bw9KT5ejW zieM23eZpG2Mexa+OU7ddOBC+Je8JOwWV7AkQWxOwR/LjqemqvHdgapT4g53cYHIVV3RikUPmh QSo= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209553" 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; 06 Feb 2020 18:44:46 +0800 IronPort-SDR: mKFsHEMWpDhAKsdZEvKme3O4cCQm+vvHJUuRMM5XIBe/NEnB2qCIeIcxaLyLo4ANwaoX+uJs7a nfu68Grbyc9tRNaYRU3zfjuMash5/WKCgsbU9wW1MKbrgPgBYi1AOxTWyilyfRD5luqSAXRxdv qMvhNEL3+JDEHhOoJNBMJxAbdwwfqPfl9PTEv+kkFBsttnZjIxCqx/tsZVQMSc5m2yQaGktZ5r L6jQuLM7jc3t5t3fq/W0KTlwPEYDZNRDdwbc/MVzOV2TE7gdsbO53qS+VyQCZm4qjqewJBZ6Q2 JVBQeoKW933xW5Imro3+3Rvi 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; 06 Feb 2020 02:37:46 -0800 IronPort-SDR: b9acYQhvnn+SntN3zRCaDE00y8ocDPZtgRDML1uELSxvGgcj4sc0AhHb1cI815temIvTzi7xji DUJ/2k6Uhpd1zc9s7wmCVLGrh62GcWuarA2q0cl0xt5pZaVyEGHWXLpIjY2Yr6CVISr2j6u6CO aaiAwKNG/+BNZu3DmXGhJIa1XmXhdKeG+2zGs18syIfBiJyeai0TB1yZxEDUvL4yyRrlW0R7PZ Vi4AE80FikvokiQeaCD5KsUiIJB2eWVLtM9cbNum2UTMBmUSbb+AC4MuLr7K51JUcMqLHEFWFj 1b8= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:45 -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 15/20] btrfs: factor out release_block_group() Date: Thu, 6 Feb 2020 19:42:09 +0900 Message-Id: <20200206104214.400857-16-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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. Allocator hook functions like release_block_group_clustered() should reset their information for an allocation in the next block group. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 0e1fe83e5d79..9f01c2bf7e11 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3712,6 +3712,31 @@ static int do_allocation(struct btrfs_block_group *block_group, } } +static void release_block_group_clustered(struct find_free_extent_ctl *ffe_ctl) +{ + struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; + + clustered->retry_clustered = false; + clustered->retry_unclustered = false; +} + +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: + release_block_group_clustered(ffe_ctl); + 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. @@ -4094,11 +4119,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, btrfs_release_block_group(block_group, delalloc); break; loop: - clustered->retry_clustered = false; - clustered->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 Thu Feb 6 10:42:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368119 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 6FE4613A4 for ; Thu, 6 Feb 2020 10:44:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4EB9920730 for ; Thu, 6 Feb 2020 10:44:55 +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="hfKU3lLA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728612AbgBFKov (ORCPT ); Thu, 6 Feb 2020 05:44:51 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728608AbgBFKot (ORCPT ); Thu, 6 Feb 2020 05:44:49 -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=1580985888; x=1612521888; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3h1CSjZZLmCI3DhjysXKyq9iW4sGpjRPXgPn7a2r0W4=; b=hfKU3lLApvFjdQnyk4MHEIEOZvS4C5Emfza9B7GR/yVcSlZFjvvJEBKp xFW2F+JLA4+JJsuWgsmKGJrCZ2wMS8fylDAUItXQoOb1mmnIwHDLTx/2v fOIqCfRnXuzmdyYUjuY3sSLx4LSOYzrGmqzY1LNeqoHcdK31r97qM7Tum 22St79I+aWF8G5Z8P6ob2STfyMBshi+a32n2wRgr0YgR84CJFm94LOmtm zu68DnVIUC+SV0RDDrwPM04Ou1T5cVqh+Z9vgQHUwAXxiZkeHIaB8ewsr 138Thu308xmsndkQaVseZZEiLnvsyAOKYGPqak6UyVkunqF8pl+wzJeWM g==; IronPort-SDR: iivgiH93mfSWxaU6lZ0q/MTm8kAZfK1Lzmz3H0ZkwYRquBkLUS/p729C75pRXiMXP5ULwsjStg 2hlET3hZ24ueCw5GI+hh2dIyaFSrMtbDwpgTdXqIRKpgBzSE5P9JLSDItgmo71iPbllvds6jOF AMYJUsJBQopUNIxDKMiyg74lrCAu7Y5Y53CrgQJ5IpB3IZRKjFB1fkQWSVNP99gCQxb5iAuIyz vB9Nm/BlqiYar+RLt4KgSrZqHaIHN2PdeEEidPk4i+jpTDwjMl6+/WK3apw8HEY17jNiwcxp2G v+0= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209557" 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; 06 Feb 2020 18:44:48 +0800 IronPort-SDR: llF9NmpMW6FSPrk+h/U93mw7r8scoIOhf1G+pm0Pt1zNEA/dAJTJkP13Fmgq0x5qzbc7z3MNkt bo0Pzzb0ZNlLqGK8n+hYAjsXWDWy6h2mrLZrzxvzR+uzbvf7gTu7o3vyRJ+jxa4+PxuPXWin4M BzKXf9PCL9a+qvAmPXdFOsgCFJwH04MhFKIjy0TznW5ZKrZC4jJWeNe9ShYk+eUeOfKaiOtQxE h063/iduVnBXGdAqsmR2JUZDYGXqC/xZnNlzvyapkRt8SkusjYC4XZWdqn6wwO2OkSBl6BYoK7 WuDBviYf3GjnRisdH3gsztJt 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; 06 Feb 2020 02:37:48 -0800 IronPort-SDR: szBchehUERUTxKfhe2Ty9MpB+1G1WiFYg5D1aCpG3PQ17YWoPlcgA67GRGihg+GNxdlDXaDDUs GaUwXJ9SVr4mWET+8O+k3X0hKXfBN/8d+DvYvVtmmf4KMqyLUnftMnsk5HzPEpfay9mTUr/qaI ZdtAHQCX2zjJ/1kc5XG+wQDdE0DIp9ZTC9Wq6HYTDDov5Y8gkHJiwUoaYFNV4sri62S40N1DuG 9JLS443zKgp/1hOmkiSANAdAxwPkbUu/6dEb+pIv8WNzAph2n690hU9rp+YXEIyaxnADalLWlI fDQ= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:47 -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 16/20] btrfs: factor out found_extent() Date: Thu, 6 Feb 2020 19:42:10 +0900 Message-Id: <20200206104214.400857-17-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/extent-tree.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9f01c2bf7e11..d70ef18de832 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3737,6 +3737,32 @@ 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 clustered_alloc_info *clustered = ffe_ctl->alloc_info; + struct btrfs_free_cluster *last_ptr = clustered->last_ptr; + bool use_cluster = clustered->use_cluster; + + if (!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. @@ -3764,11 +3790,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 Thu Feb 6 10:42:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368113 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 65507924 for ; Thu, 6 Feb 2020 10:44:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44D0C214AF for ; Thu, 6 Feb 2020 10:44:53 +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="SHflm1tg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728616AbgBFKow (ORCPT ); Thu, 6 Feb 2020 05:44:52 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728601AbgBFKov (ORCPT ); Thu, 6 Feb 2020 05:44:51 -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=1580985890; x=1612521890; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i28cB62cpvEdkeEm6OC016E5KksXp57RuPy0QhYL2+8=; b=SHflm1tgqNe4/JdRATQMRnl0LzJ/H5XgEie8mm9TrQq+Niw+2HEHsgAY wB93hKy/F1mN0fXP9w/ykcJTVvc+49APc7fhOQXQRH4wZuCv2jwG8MhCi K8msWTfM/2Td2wW/Fkp5Q6YDgefvK769GwFpc0PMQ0tGV/uSrQdMowQtU uoarTD107c7zWqIKKRbrnh9EJjsqZgKZe7XpT8guO4xkUMN3Tb8qRlSgD nRxKJ+9BhHrkLgoR7pX6Mj6Ns1A8d4rr8gd66Nc8ODIlO+7HzjyRJ0zcT +Jln00eY/ov5xhxfLPAwgNWUDnAN5xgQiBSlSlHrD1becM8HqLZv1Cnsi g==; IronPort-SDR: A4UCSZzsDXRkRjEeHzx0zXQQl1S/W0wqltqqcEc8r4A313QcXS3r9U2iEhW+LZb8cAnGjeEa1B rdpJsC8OBzw5UNpPQ7VPpspNP08F3TRrh4J+rmi+nikjmztjlX+ki09atkvxSGAqPRZqvLsDO+ WFCDuapgUzPRQgb2kwR3dKdejS8BXudJ6WjeB2F3SXL20CZu8YPQadlvYutHLshuairlYiYsRs V5hShMjNCS6/4Rmh//mBCUdoMir0h2kX0IXCjQOInZhNem22D9QiKAkH8gA09mheBiy0JDV29F f/I= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209561" 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; 06 Feb 2020 18:44:50 +0800 IronPort-SDR: kWjuX3hRQDdNZMtO3Cubkq7D3DWyg8lThTwubxirpONldyjUtsqElT++znOsa1+LubD6SUGtAN nBLo1B7uD6fXiVw8ypSBOVdn6Ve1nhYBkLwNd/yqQeQWxxLj8wnYghQCc6bqEwlUG37i3iqM1W 9JJlGe+Q/bk9kLIh307y0RngnOdV1XwcDVvKb7ml10JroaMFeLE9os8UY7WC5ZDQ8uq9PdQkOJ D0R2lMgtcrQrXeL+skZKF8YowSes3eaP6Fwvpve0qpI/tNDx/J/edmAZvCEKhSjU9BXTF3gkl2 udEnSBaCFTw69ZeQjgm8Wrsv 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; 06 Feb 2020 02:37:50 -0800 IronPort-SDR: 6aASIFtmBDUFcFopDd3Hl4jrsUIrGNzSg1HrPHLFHeWWI+iJFCnQtu81ssNmARd7Dnwe55qTzS lppOhSQbkx1t2hzIbW4o0uwuoU1YqKe6wy0DXAFH2jeSseg8Bgu4fvAqxoj9U/tMZodaLWdZ2o 5i4Ef2+5MQXknxLBpzMjCJcEPNStgcnC5eYGz96zModoR66E0/7XtGcDiD4MtNs/z8+nxebHAJ B+2go1acQyZX7R/yuMtRUUjMG3je+rydCmVxvyhJKw14B5FGpKlGLNTFLSnC5sWNAWZ0ZfxUbC VWw= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:49 -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 17/20] btrfs: drop unnecessary arguments from find_free_extent_update_loop() Date: Thu, 6 Feb 2020 19:42:11 +0900 Message-Id: <20200206104214.400857-18-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 d70ef18de832..03d17639d975 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3769,10 +3769,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; struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; @@ -4146,9 +4145,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, clustered->last_ptr, ins, - &ffe_ctl, full_search, - clustered->use_cluster); + ret = find_free_extent_update_loop(fs_info, ins, &ffe_ctl, full_search); if (ret > 0) goto search; From patchwork Thu Feb 6 10:42:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368123 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 CF023139A for ; Thu, 6 Feb 2020 10:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE818214AF for ; Thu, 6 Feb 2020 10:44:56 +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="hi1yKpKR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728621AbgBFKoy (ORCPT ); Thu, 6 Feb 2020 05:44:54 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728608AbgBFKox (ORCPT ); Thu, 6 Feb 2020 05:44:53 -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=1580985893; x=1612521893; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rDZkS49hYzcItRCk4G6j0kg9y63mQvjVa9rjC3nk5tU=; b=hi1yKpKR+RXLJI5LZGHXt7hGYZNri46SIpoOzfPYdPuB7yLB/m1CLOwR Ol5UUsWGNA8TaCpE0Urr+EXDLg3I3bfeT5CV3rGJQHHFjLjSAacFbUW1A kQ9wW01L/+hhDPZ5UE2FZQ3cf4AkQdtOlnbVWGgf++Kn/PwyptKSq5PaZ 0okjxLn9j11m/yXkN9QjyK6TR5IU457GNLxacBXB+P7DRtkb03KXn4PzA NH7GObP/vyKMdeQAIrR+3KEWVvmRQ3NAJBIl+iZn0wJHSX7p047m1x32l YHegRXNEzNsMqc07uqd/nX9pf3xwm6O5XRwpUlyeyjRPltgVfk0NlI+/G A==; IronPort-SDR: nvLjbxHBp1J/TzmMeg1BfzDoaP/s8TaA+EFIB3toiY7BTagqPaAsjb5hI5w2LdYCJUFnd/NtF8 sytdVvhr/XsP4ygluv5f7P4WWdDkO6D35L6FwpwIVQ66a5hVN79iezdaRWdY4IDTNVmuLIkZsY GtOfKJGIyYTPpPR9ZSRLLNLjRDyGLViSXwAsMh5CWZyM0mQWa1v237ij7izkp70lKkKnbzcK4V MwIxLdHECQEG35Qr1v+M669s1D7tiRLAglt77ssu3vtMZ83JxzLSatk99juqHHuVi2vZLlcaoj cqY= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209564" 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; 06 Feb 2020 18:44:52 +0800 IronPort-SDR: 1U6ryMMAlur7AQrZZfKa4igbtfZgzAGxN+iDKhOY8JO7MCSOGvnla+heAl7y0bRn1NEG4SYC5H BhPPDexbDT5ffvOrA68gkl1UxfLIKe7VWWlyqVHNE+GrsuLYdfffCoZvK4KXPIxA8UmNsIgxqw FGKSRl+y3KaTQjciaUsawL061jcZ7V9HneGuKOMwwkiqhw7Ufsdi/iACYGfGFHyA8+u3POAAIj oCLkKb93cw7xw4WuYZ3btnxeGJ8ykJJQlWxMZC2JNGv2JZOO1Ts2oHjykYb1O8ayrKEEOwwRgD vJmMYWJ0qNLEqBElCZarqmzN 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; 06 Feb 2020 02:37:52 -0800 IronPort-SDR: ELlpSVK11kZFKPTvsRTjlMiHjYiPQf/Er9R3MbV6bQDZVZanplBI3FowIBQe4ZUdiRG0+Z6+Iv cOUfIKiCewEPbchu9pUcFIPie6Z2va99Kct/pXGqPONJ3Eb9CEW+cHtG6oc25uCNVyt46wRUiT P+yGRdFZ8e6VZ8+GfJwuJbrSwl2xX7DSvIxNfiTh53h032bX3HVowJ8AGCFu4xwVJSq3X6EBAA FXoEHGaO2dXGxYGzJ0w0hGeauc7aedy3RoGKFQgTKmEK4Tyep0alPc/zo+UyvPwHyQIYpnMRbO 1Ls= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:51 -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 18/20] btrfs: factor out chunk_allocation_failed() Date: Thu, 6 Feb 2020 19:42:12 +0900 Message-Id: <20200206104214.400857-19-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- 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 03d17639d975..123b1a4e797a 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3763,6 +3763,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. @@ -3835,19 +3850,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 Thu Feb 6 10:42:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368125 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 856A6139A for ; Thu, 6 Feb 2020 10:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 625ED20730 for ; Thu, 6 Feb 2020 10:44:58 +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="NV2wkB+c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728629AbgBFKo5 (ORCPT ); Thu, 6 Feb 2020 05:44:57 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728625AbgBFKoz (ORCPT ); Thu, 6 Feb 2020 05:44:55 -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=1580985894; x=1612521894; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+3EfF9kWwSaym96gaaWEwyNN9Tptl6ELHEmXCoomO0k=; b=NV2wkB+cA/PJV3PJYHnRn/YN5/Lr8afe+YIAZ/CtYHHauy6hOPlEYmft CorU/AwFxgABRha2DZzqzZBqXprc8UxDwFdhBiHbm0qC2YVObf+RLvIeE bZ4CFPUA4QfJxA2abWfcVXNdYPNDOvbcNQ/e5PcdOc1Pgo8CZXAzTjOF5 adv6/xTOMDQ9y8XXa+MJNtCUJDVuyJzOFe1fLBDM6WUfssVDohH7sI6h4 8AaCXi4rH9K53lGNXrOioOonTcuNGNerdVXB8Z2mGSG8GUcTyeOqvc+S8 Nt5CXKTOHC2Xj0H3SF3X+aKuBCupsoOiHL6jronfIblmY07RH7ZuCRgBf g==; IronPort-SDR: 0crSytSvN0LOaSAqyDG5uCuEQ+zhf7scVodutt1DVh5D5X148H1H83vOm6X6o3/oLy0cQjtP+6 OKGOb4rgjvNv+KD4O1PGRk/NxpelDZd2ptBh8m9W4qqd0Ol3huyoBrTQ+xyjSkqA6ycrJIEIvU 9JPu7m+29W0utzZNkJ9eh1RT4ipSqDY8CglbRAesCsoVBPpyokXm/uknSqcPytRTYlWC6tqqhc VlsqlXnlSSPQRHhbOVBX7ciMaD4ocoVS585indFBa673bl2UCwcPPrmHN1qtdCo6h7D8V/2HrV pfw= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209572" 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; 06 Feb 2020 18:44:54 +0800 IronPort-SDR: xyxaHQbT3V37oUMaoCM8ZzmeMlAeqIBb61PeHleX1bdTXOgbOZJS+Um9T6/nJceVxQzuQhMNbe Mp3QUALL2PoSFIoRCkJG9f+ad8aCAhsYU9zT5SXMhzLR+YCOtj/GNu56a8jqyGzMMzkpnHgqY8 F4AF5zXhh+Oyaiofxv3mkcYAuY0H0fJE/c73FEM9HoXP4PtH6mg4MHDz6+az9ELfiIuyiYwEzJ hdlGu3yqiKMC4O78FLIEtwCB8JkRTyPlwRHyCSjbZsmov7X6q6voYePlnC3I7CpEoHLBZQU8L0 S6sU2ec+vMgtuft+vxEBdw8W 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; 06 Feb 2020 02:37:54 -0800 IronPort-SDR: VJIsXF3ricQoWhMnr+kIkpCN9h5jm+wbSrA98roCU6BN9ogyYhsa945CWsFJpfy0Cj6w/mKwXC K3Iqn6ayVTulty0ymJva/QRfhuu2w8tP6KVf2yaeJqlfNETKkzy6qnidBVSic2KsPaIEuBVJpr llVQTndZos92YlEOzfQwRGA6a5taD3gHJ/vvllwp3gG1BuXZ4nFIc8yuU9QnKNTHHeVgqFdCyn j61nw2j29R3emzaYNQa8h5IeesqC4ufAruR1t0CGDG5MMTFad/dqaaJZiy/UprDsKtu1mz8TsU wCA= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:52 -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 19/20] btrfs: skip LOOP_NO_EMPTY_SIZE if not clustered allocation Date: Thu, 6 Feb 2020 19:42:13 +0900 Message-Id: <20200206104214.400857-20-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 123b1a4e797a..2631ce2e123c 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 @@ -3789,7 +3790,6 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, bool full_search) { struct btrfs_root *root = fs_info->extent_root; - struct clustered_alloc_info *clustered = ffe_ctl->alloc_info; int ret; if ((ffe_ctl->loop == LOOP_CACHING_NOWAIT) && @@ -3863,6 +3863,14 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, } if (ffe_ctl->loop == LOOP_NO_EMPTY_SIZE) { + struct clustered_alloc_info *clustered = + ffe_ctl->alloc_info; + + 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 Thu Feb 6 10:42:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 11368131 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 CCC7713A4 for ; Thu, 6 Feb 2020 10:45:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC4E8214AF for ; Thu, 6 Feb 2020 10:45:00 +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="WINl4W26" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728625AbgBFKo7 (ORCPT ); Thu, 6 Feb 2020 05:44:59 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:50006 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728041AbgBFKo5 (ORCPT ); Thu, 6 Feb 2020 05:44:57 -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=1580985896; x=1612521896; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lhtv6ihGzfX/7/zntEdWvO6w4G5PXA356u1a0XhvbjA=; b=WINl4W26NjXT867SyVblsZfiuAHCMgc/F3D/GNeQKE3cqAwo73qLMt+5 B5CgXyhVOh13pgxYkCe+adSwqa82AgyeXY3MMyc1KV3gRzxO/CO5KoIYB RG8P5afoX763JOHgzbcK8O+aJpsclLoJDJYtlaX353KR1O0NUxExpMIOd dwGQ9YFFnk9f6zbVS8ZP69215qQ+wuxULkcXOSboZN3KyKlBkY8SehzcL vKTlfh6qebmdwQI/77WGaFSUteXPv3aissyJ7Y48VppP1ef4N0w0Hgc9a As6F1fV27khV4/IIYtyaSMELRxA+D6xVbvIeGjbrEYoAnWIv0628zCcL0 A==; IronPort-SDR: Y4Nvp4oBIZnafcrBK7Wue5k6cr+H2BZAXKJMPQkrbX91EikZI2gPT7XJ0o5QhjCfsONB0b8q1j +HZl1aJWSxH86F5MrqZudZA1EFXa1wE9zd9qW9WZCfRAG780FICbaeUN9hsntEOjZ3LwKKmUhQ kMvxISg9OXhfMhLi4AadfTAxLB4bGkxioW71aqZlVzm1Z4KFU+V5CSVKdjkkefNmU7uR1wHhjv ZQuR//MQzFgTCfi1zdrwcF6Ai85qy6/fqiMwYIM2XNKuNKDvHv0A7HdPykp2DhgA9/HwM11RxL Y0E= X-IronPort-AV: E=Sophos;i="5.70,409,1574092800"; d="scan'208";a="237209577" 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; 06 Feb 2020 18:44:56 +0800 IronPort-SDR: joVIkn3iOjnzKLxDBG6W0N1k7/0zsgf6c9sfrG5jbE/3rkscqFK4V1DZmTp94Mp8PhVL0+LuxC 48gnsW5dXC63qKzSk3pf10N1e643nAMSwYe0bIAGHd7qEDGDC/Glh168SS8hqctmVvO5OWBAT5 /CRGhxNobDbw6lrsjT2xAauGo9SO+s98nAhLDEKZqvvq4Bq+aX2ZvKfgktZWwbFpaYI410VHI7 C8rrKO/e9SlUjrKkOtK9zNCaphCoIXeLz+6ELwkdUJcJ9YzzmVLiFdobZqszNLRi6QB7+jdXvF ZTbPYqmmmsfJ+NT0OZtdNC6T 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; 06 Feb 2020 02:37:56 -0800 IronPort-SDR: Y7R1UO7fYKDK4Pk8Sgk0yMQnt8qVK97JEduly6Rv8Oti7ndZnVeY+XRglCXNXJfKkthsnZe2Lj q01x7bX5y5O54DggMAoi5h9+n9FpWNRdmcIgeHKYi12g0ZhH0qhA/X1csqB6k5XR8E4Tw+iDMh kWwEE2gEVZBUrnq79j1RaXtKFQuInRAsfAsOLuYs9rZx/9wYADHRsOiCfVl/K+vubL3f0LW7St BNv5ZCMO++GZeVep3nobR0HOJ4tyTaSDKj1cOkPi7xlq2vIvEQdwZiMwXRcQcbcaQqxKr2KWs7 XnE= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Feb 2020 02:44:54 -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 20/20] btrfs: factor out prepare_allocation() Date: Thu, 6 Feb 2020 19:42:14 +0900 Message-Id: <20200206104214.400857-21-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200206104214.400857-1-naohiro.aota@wdc.com> References: <20200206104214.400857-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 --- fs/btrfs/extent-tree.c | 131 +++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 52 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2631ce2e123c..7742786b4675 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3886,6 +3886,82 @@ 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) +{ + struct clustered_alloc_info *clustered; + + clustered = kzalloc(sizeof(*clustered), GFP_NOFS); + if (!clustered) + return -ENOMEM; + clustered->last_ptr = NULL; + clustered->use_cluster = true; + clustered->retry_clustered = false; + clustered->retry_unclustered = false; + ffe_ctl->alloc_info = clustered; + + /* + * 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) { + clustered->use_cluster = false; + } + spin_unlock(&space_info->lock); + } + + clustered->last_ptr = fetch_cluster_info(fs_info, space_info, + &clustered->empty_cluster); + if (clustered->last_ptr) { + struct btrfs_free_cluster *last_ptr = clustered->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; + clustered->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: @@ -3921,7 +3997,6 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, struct btrfs_block_group *block_group = NULL; struct find_free_extent_ctl ffe_ctl = {0}; struct btrfs_space_info *space_info; - struct clustered_alloc_info *clustered = NULL; bool full_search = false; WARN_ON(num_bytes < fs_info->sectorsize); @@ -3950,57 +4025,9 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info, return -ENOSPC; } - clustered = kzalloc(sizeof(*clustered), GFP_NOFS); - if (!clustered) - return -ENOMEM; - clustered->last_ptr = NULL; - clustered->use_cluster = true; - clustered->retry_clustered = false; - clustered->retry_unclustered = false; - ffe_ctl.alloc_info = clustered; - - /* - * 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) { - clustered->use_cluster = false; - } - spin_unlock(&space_info->lock); - } - - clustered->last_ptr = fetch_cluster_info(fs_info, space_info, - &clustered->empty_cluster); - if (clustered->last_ptr) { - struct btrfs_free_cluster *last_ptr = clustered->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; - clustered->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));