From patchwork Tue Apr 6 08:05:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184443 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13D7BC43460 for ; Tue, 6 Apr 2021 08:07:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE0CF613C3 for ; Tue, 6 Apr 2021 08:07:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236166AbhDFIHZ (ORCPT ); Tue, 6 Apr 2021 04:07:25 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34730 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233439AbhDFIHX (ORCPT ); Tue, 6 Apr 2021 04:07:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696436; x=1649232436; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3Zqw5XcHlgEJqRbG0p+Y+o9TCIn/xhvSgQL6gJALRxs=; b=ZLxVZj5/dpaCVGbeDEl9V+A6f/NVNpGtC+BeqcSF/NKWJiwOYpXVsljX EH6FhRRF8/5LnEE0d+3amL8U6eq+xz3i0Cpqe4mw0bxVsqdQHH8Y2zwAt keOvMZmJXqA/CNK/sSwoB3rWyjctaAHEBxKuGz0MVf9PsdW6CO1n6O33e Cs/SZmW3MjVhLCNz9wyCShixsiBGXwVPZ+yLa7A3u/A/Yb1XeSPEbXaPD YMPywdoE1akyMzVNUvArr2yflQ2+/htlRblgnTP4VLddV9/K+jYmajrPv q7IN2GwaIf38Reo9tlC8xA6B6F+JzhjAPewsqRVp32JNhT0pq0bTHenub A==; IronPort-SDR: onq7CYVFDsZxHfBpdEQ8iTtrUquXIDWo5+Hok40Ev2Ue/+50PWGGNQAFEtsjf6CXrbCNs1SnH2 MZ6fck8i35avdJIzXK/soJ1PiTnY2nMS1JnYfL45V1fWyYe0Q2cwYKuhdXb/6UFkFU4J6Z/J2f biKQZ++V1J+BlCx+tBmfXdKiHLHb9tN1LmBg4XFpxOD3xX2sspPjFy0NMpSivzi/OK6GANsmkq Ajz+n9j7hx4ucU+9iSbOoqhA6qJyVqpqrRRAK57vO7ev56kskhDPYGfMxqqtIXS3vQSvQvVSM/ G/g= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="163733687" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2021 16:07:06 +0800 IronPort-SDR: arUWSlQr0K4ngLmaXIrVYnk6I/bUWSd4AtD5UM6bHwP4KuNfz9OTsqCKscLxflLw2WwM4dH/Sw kkVGwAG+9lTbWIrLTJ96g2vQ/XhskE8mC9AHa1lwkFGxsw8o6C5On0joITBFlV51pPtwmzOKnZ +sASFG7IjR97xyjTAK3iocJFUGaeFfzf4VxwTP1pchgA6dzFuMdWg6siDCWs0iBMkZ/SfHms4e tjy3xxTL96gFBcPykbVWntA8WXW4C76lenj5wwUwA1ppWZdHwImCPnTFQUjaUrBNmd6dB9f98X zUNyIv9fIV0S7WdezgtUkCSw 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 Apr 2021 00:48:20 -0700 IronPort-SDR: eK0AU01QOn4egMr8+RCY+AChz0e0zWUNBm0gqhUueGu1ibLG7RPi+TuOvswCEFMgdXIXUKQBJo leVUuj00+hQAnFUgFFNS4/21jK5rIy3kMstb1ZwK2k7HDFwx0kgxjXukb87923sWiRPB24a/ZM iRXbPIfL9DNYYWyvJjwslZ6fcDZk72Wnh3UfSycM8JA5RPvEwCbx5Q8SI2BPtGChR/aw2EpmER OYoojR2RxwLkDYu+VpYbf9SrpQn+71SOo7eTyHJTeKJMey0CtwtMdqufJcumlIhTrzrKcFa0p+ Ewg= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:06:55 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 01/12] btrfs-progs: introduce chunk allocation policy Date: Tue, 6 Apr 2021 17:05:43 +0900 Message-Id: <4bedaf48df7ba0a31ed0466bfd5645d3436dfe77.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Introduce chunk allocation policy for btrfs. This policy controls how chunks and device extents are allocated from devices. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 1 + kernel-shared/volumes.h | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index ddddae62581c..7bd6af451e78 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -254,6 +254,7 @@ static int device_list_add(const char *path, fs_devices->latest_devid = devid; fs_devices->latest_trans = found_transid; fs_devices->lowest_devid = (u64)-1; + fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR; device = NULL; } else { device = find_device(fs_devices, devid, diff --git a/kernel-shared/volumes.h b/kernel-shared/volumes.h index d6e92db298ca..e1d7918dd30b 100644 --- a/kernel-shared/volumes.h +++ b/kernel-shared/volumes.h @@ -69,6 +69,10 @@ struct btrfs_device { u8 uuid[BTRFS_UUID_SIZE]; }; +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]; /* FS specific uuid */ @@ -87,6 +91,8 @@ struct btrfs_fs_devices { int seeding; struct btrfs_fs_devices *seed; + + enum btrfs_chunk_allocation_policy chunk_alloc_policy; }; struct btrfs_bio_stripe { From patchwork Tue Apr 6 08:05:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E521C433B4 for ; Tue, 6 Apr 2021 08:07:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 402F8613BE for ; Tue, 6 Apr 2021 08:07:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236224AbhDFIH0 (ORCPT ); Tue, 6 Apr 2021 04:07:26 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:49866 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236205AbhDFIHZ (ORCPT ); Tue, 6 Apr 2021 04:07:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696440; x=1649232440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HdWP9kEKhaHkVtclaCpVg0Lg/Nf0Mu06pyHA54z7Czc=; b=iNjtHKCSLTaA615RAEzoQwSsMpeodfF2Xj+vnAVgkE9FIbPmuFu17773 +UW70OFVVb6nwuv3bZkCtXu1DutAFTnMeJ4ZQg68f6EenxSPtZJekLWFh u74Ux8gPB9dLUu+ez5tZvVs/mN3OKpRp4YBYhKczUQGaGgfsX1wjhswWj +RhbXHTDJGuZFPyLDkMNIhp78eAOdZ7sVLUMuSzwA+ejCPtq0VDBcIC55 mNYwNHBrGx9WgAKaKJtcBGOXZecLtIFSmT6qCkGdR3uVEct+pcalcHwEm qr2x5T3tkxCMWCgBdFOVEqHjuaAyFsZBPmcwtgWnjmC1Vn5atCicp5xy+ A==; IronPort-SDR: RPlxRv4InD/p8JDC/TNVqm4XN+yxsGfiaZ+CSde2RR0QGnhn8GV7ffsQKpmiEvTdiZagtj7wsj SrnlERj7GAVfsIBfU/HbsfN4aKrn8BixSy9gjsHyU9vTVMCiZBOhI/7MYoNzgRZZggJtrzkYef 3RK3CLKcXTwTtM4P5kb2Dy5M+OtMb33wPykXoJJS0xoK2A2FhA6mUftlsZJdqGUgaOvaNLKxiI nmq9nT1xk2QQHfA18QYMabtG21LUBEQjAJEwcqqiSuQQ37l9aGz93YwiQvGVTvEjAok2chag/B 2zw= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290642" 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 Apr 2021 16:07:05 +0800 IronPort-SDR: 3s7pE5qkgwaxSeNgAnc27GAm5PAmz3/247ZQhHB1XewujecUxIMII+/gjpHOggtEMUuBPAIIM7 ZXDtR00H2ZMaEJzjwCBgT2WgNjoNX0FjHh1ZlwxAtKTYJnupfXtHNXfoZFO4/XDvN9xVH3Dex3 HX1h/wR+Nmm9izGpt7DuIJ0z/lyRFLBAIbvuN83HKnWcaaFfvDgVe8OnA1Mfn52XDfcFunmLJu yyVdOOHjQ1mt2StIvQFQTWeZHh8nRFvG/nliLARUWDxIoxUOYQZjHiuumB3U8hv7JJZBUmg5qA bI5943NxkrBC3EvNrFWLc+TT 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 Apr 2021 00:48:21 -0700 IronPort-SDR: dQ7U3I6QT/L4RlXWre3wa1pHWcC2Za1w5hQb5IiloTBp7smjjTqtXuR8kKvbVV90J7XIj58OBR hnlys212WFwgilxDqV+L65Ra27hK7FRGZa77Z49G2UskeAeyizyCONPRa+YP52fAz2I73L24k+ BuBxZdj5MQWoW47AsBAZ+CIDQnqQR8Cm4zCfd/ty/brK1lYxMV6Tak1FG+b3FTfNHyuWECe1JC boFDqZW1/304NxTMA9C3ZEAYs5xbDj/qxC3GjncIWzk3HC5jS0hYlglIps4Y25AHRWzpS7na2m Tsg= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:06:56 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 02/12] btrfs-progs: refactor find_free_dev_extent_start() Date: Tue, 6 Apr 2021 17:05:44 +0900 Message-Id: <71a8276cc5028cbe14914b7dc097321af9b226ed.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out the function dev_extent_search_start() from find_free_dev_extent_start() to decide the starting position of a device extent search. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 7bd6af451e78..3b1b8fc0b560 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -444,6 +444,21 @@ int btrfs_scan_one_device(int fd, const char *path, return ret; } +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(start, BTRFS_BLOCK_RESERVED_1M_FOR_SUPER); + default: + BUG(); + } +} + /* * find_free_dev_extent_start - find free space in the specified device * @device: the device which we search the free space in @@ -481,15 +496,8 @@ static int find_free_dev_extent_start(struct btrfs_device *device, int ret; int slot; struct extent_buffer *l; - u64 min_search_start; - /* - * 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. - */ - min_search_start = BTRFS_BLOCK_RESERVED_1M_FOR_SUPER; - search_start = max(search_start, min_search_start); + search_start = dev_extent_search_start(device, search_start); path = btrfs_alloc_path(); if (!path) From patchwork Tue Apr 6 08:05:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BC3AC43460 for ; Tue, 6 Apr 2021 08:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A6F1613BE for ; Tue, 6 Apr 2021 08:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238399AbhDFIHq (ORCPT ); Tue, 6 Apr 2021 04:07:46 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:49896 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236276AbhDFIHm (ORCPT ); Tue, 6 Apr 2021 04:07:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696466; x=1649232466; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gc9qcK/c/0qNHpcrdUS+T17j3sV6oMs3sVwxP5RvDgg=; b=m0AA/1Ys0ZLCgEwHC31RliNinJ5tAsROQ8AmMXvblj/dzBeFq4SjcXFN VzHFHG3En0PZb0sCFpLgvKByOKfkF/4GXhAenC7sP3+O4sfKJfM8TARkB XJCAzAiKghAjdu5OlK5aTzVKI9SMQngTqLNdmtwkyYc8PsGvzveTdf1g7 SW2w33Vr7L6sNpgmGgDpL2KknL8eFGO/zIwKG6FL0uGWViqFLzr+AVN6+ b+JEAfr5kanuQQqNcc+gojtJDhlArk9aGakgtlv7CCV2OBjl0Ex4vGJIS 8/iNO1jqtTeD39j+vLz3HTNrs6IsPofcp/+my5600GcoXIzCPzfDv74cw w==; IronPort-SDR: AZj7QY604vCMSV3BLriakZoyNq/BmIp3ienngg6GWlB/kYUs7hvREVKXB4g6MUpN4h5TEFB4SQ 5f148T+ChsBifc5Ur1YOwHZ9ztbGa8a3zyabgOqZdN3uUdjIUKPH/X2BJlEo2KatF7/DJ6o/4g kMo6VwjViRBheT0H0S0KkRTJ6BL5QhtVP9ll79X2dztsw9ZwwN2svckOpam3nGotHwMHWTJxot I4O3PE47/wn3+odJr3W5dvA5zhOLJWTPRW3I1CEa9fVNbU2n0DOVwnJHXoFRzGvsl9F1IuGCEx 2Sg= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290673" 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 Apr 2021 16:07:30 +0800 IronPort-SDR: StYNu1OKWyLycqntU61N2eydo66+LqoeA7VNEmvHeQZszQzIfddh+QgwMl8CSHfDqeTV+uxkRu 8nY3JXxPx9aiZzVBWowhISd7dvlZwc5tWeoCFD2H36Hk5YS14AsKFGaKQVAz/4RzuVAAvtFgAf gjvFBXCUM9dwmIQ9UYSnW5Wzc2pjcwJaDnsjcY0YAjbDgXKLi3fdw2fubM6YRezxOHZDS53RDn 0/ojUoB7vIndYlEddQm3q2wbDgDwhSX5jztUqzEHe73pNpJxa5Sr9H3VYXqAI5YGUaJase50DK WOnG4w4Uo07IAo7oxC/YqFKc 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 Apr 2021 00:48:22 -0700 IronPort-SDR: 0nMDjjIWDW8iqD+GcgkaaLEhnMJasJXuTtEkX+SZF4lpM0htLt+e1LeuVcvbZZEqcKOTSW6hEz RCTTjKZhatsPri0zgf/qf8L55ijL5dQcs0lxA4nfoVlE6y0/AFxUw35p99CUwtrgp5qURmPSPs b5kL5c6la8Lq8O6SB63nN3RJGFC5xfSmdHem5eLHMP6ozZxqDJHea/LnqK1CcpNlrkYGuwMtwE 0UxBRVYUGec0M6OggJb/8r2blZc1/4mkkiaxVDvjtkMQ2b8uPorgV20tjFUu2iMvHMc55PChVu RSs= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:06:57 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 03/12] btrfs-progs: convert type of alloc_chunk_ctl::type Date: Tue, 6 Apr 2021 17:05:45 +0900 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Convert alloc_chunk_ctl::type to take the original type in btrfs_alloc_chunk(). This will help refactoring in the following commits. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 3b1b8fc0b560..ea14a9413157 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -149,7 +149,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { }; struct alloc_chunk_ctl { - enum btrfs_raid_types type; + u64 type; int num_stripes; int max_stripes; int min_stripes; @@ -1008,7 +1008,7 @@ error: static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, struct alloc_chunk_ctl *ctl) { - int type = ctl->type; + enum btrfs_raid_types type = btrfs_bg_flags_to_raid_index(ctl->type); ctl->num_stripes = btrfs_raid_array[type].dev_stripes; ctl->min_stripes = btrfs_raid_array[type].devs_min; @@ -1069,7 +1069,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; } - ctl.type = btrfs_bg_flags_to_raid_index(type); + ctl.type = type; ctl.max_stripes = 0; ctl.total_devs = btrfs_super_num_devices(info->super_copy); From patchwork Tue Apr 6 08:05:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D5D0C43461 for ; Tue, 6 Apr 2021 08:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F313613C4 for ; Tue, 6 Apr 2021 08:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236431AbhDFIHn (ORCPT ); Tue, 6 Apr 2021 04:07:43 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34748 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236300AbhDFIHm (ORCPT ); Tue, 6 Apr 2021 04:07:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696455; x=1649232455; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t8mxuPUK4bxWp9SYu2R2wa8HLwqik3UtNUQGW6gRmz8=; b=GvSR8246q++weFoflj4ZHRNFKkMHorYb6cztrhTwtXp2Bx3cQ6O+T4Fo uLzwE+CDgkzt90ld5VKQPLumzoH+XjGXsIpsE4e4uA5xGnSJHYqp3cZk1 TjGL3u4ajHyuXRs6C21DfHx098pEGmtjNjtcYsMsvsIqZu8KhE324zbqa irQ1ALHqkTnrcoanfl8jsfm5fBGy+wKhLhovLMsZzhRXw3YcjyDMf/ul1 p6Mu3/puZkLALGvUXDZjIVXz1l2MdXw+Ah4GyUiTqr4MlkMU7FGkfN32I AMfnb8ZMF3MYp8pz4E2P1RL626HlIk8BNnUs/jNO4MdeBTfJokFVQu3a/ w==; IronPort-SDR: 8sBIBKJ3VjGlDCvuBeys3vvcuNumIJsmqLWnnZ8VeYbI47od47POeVdUGyAO2RuikvtMWDJmAN DON9v92d5k7w6kXcZy4DNRVNX20Wcpm/SFQD9biWrcotr3ZqSiFBbMi7eR3O9kqtKIhK+ZORnV o+e6AA+HXf2wyGjWmqr0aKXbnPn3DMPuwEzXV5jsB39SEubuoz5BKyOCmB2sxGya3bSDyZhhw3 2U4nerWBytOAHAbwP7grorvlCToI6IJ41YWEu10d1OMRevP8D83CgMw6noRrUV85L61shS2hAx +j8= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="163733727" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2021 16:07:25 +0800 IronPort-SDR: cACb7gHtw8WkkIYRxaUOj28ZY1R0LEM9imP+63XiEOA6hCQV2t2VEVfxMIqtIgRL5ubZPx7vBc bn3i2bAZ9UJjDGQ7YqU+rRPtAC1Oa8OXfqy1mgSmKgHt7MjnenWp9OytLfeEtLS/0efR/QyDkC P3ZtzjmgKRT1bakj8to8ljbKd+xXt3wI2RRudX3xUupeLDnp1E5tJqWBPpTkdwEktdbSNTQllh YidqkzD0wugmzoOVPWA3IYli6iP4IRUHLnJwSfnDSAKufYY0eFDyosf/sByrGGXCnCuHSFjykA SGnr2FgnTeIHiB/zlWUnup4v 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 Apr 2021 00:48:23 -0700 IronPort-SDR: kSvnO/QYNU1+h7T0JxOxHx9xas18TjToF8Hj74ASd6SKrlhclwXG3VVSmdFxK89v2xJH38xm69 FgSE5V/xP3uDx0GunUJ8qN/muihbF1r3ojTKovuRC8QG9/rXdvXzOtXUF8+zKBLb8cwWlQPIC5 Zk88lwpVhERTBlj8JMFpYchppqNtIREsqnYQFplRW/7ccggD0nmYnHHdGpbAZmkIf0rEH9+ESi 5u6+Q930Ru+J7/bCkq+lIhmwQI4WJXNsx80dRvW5V2KNTe7qYmukPNy/knVbSz+NLmIrNSLIcc O50= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:06:58 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 04/12] btrfs-progs: consolidate parameter initialization of regular allocator Date: Tue, 6 Apr 2021 17:05:46 +0900 Message-Id: <0639b2958d564920fa4d37959586780808a4c0c2.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Move parameter initialization code for regular allocator to init_alloc_chunk_ctl_policy_regular(). This will help adding another allocator in the future. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 112 +++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index ea14a9413157..1ca71a9bc430 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -154,6 +154,9 @@ struct alloc_chunk_ctl { int max_stripes; int min_stripes; int sub_stripes; + u64 calc_size; + u64 min_stripe_size; + u64 max_chunk_size; int stripe_len; int total_devs; }; @@ -1005,6 +1008,40 @@ error: - 2 * sizeof(struct btrfs_chunk)) \ / sizeof(struct btrfs_stripe) + 1) +static void init_alloc_chunk_ctl_policy_regular(struct btrfs_fs_info *info, + struct alloc_chunk_ctl *ctl) +{ + u64 type = ctl->type; + u64 percent_max; + + if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { + if (type & BTRFS_BLOCK_GROUP_SYSTEM) { + ctl->calc_size = SZ_8M; + ctl->max_chunk_size = ctl->calc_size * 2; + ctl->min_stripe_size = SZ_1M; + ctl->max_stripes = BTRFS_MAX_DEVS_SYS_CHUNK; + } else if (type & BTRFS_BLOCK_GROUP_DATA) { + ctl->calc_size = SZ_1G; + ctl->max_chunk_size = 10 * ctl->calc_size; + ctl->min_stripe_size = SZ_64M; + ctl->max_stripes = BTRFS_MAX_DEVS(info); + } else if (type & BTRFS_BLOCK_GROUP_METADATA) { + /* for larger filesystems, use larger metadata chunks */ + if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G) + ctl->max_chunk_size = SZ_1G; + else + ctl->max_chunk_size = SZ_256M; + ctl->calc_size = ctl->max_chunk_size; + ctl->min_stripe_size = SZ_32M; + ctl->max_stripes = BTRFS_MAX_DEVS(info); + } + } + + /* we don't want a chunk larger than 10% of the FS */ + percent_max = div_factor(btrfs_super_total_bytes(info->super_copy), 1); + ctl->max_chunk_size = min(percent_max, ctl->max_chunk_size); +} + static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, struct alloc_chunk_ctl *ctl) { @@ -1012,8 +1049,21 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, ctl->num_stripes = btrfs_raid_array[type].dev_stripes; ctl->min_stripes = btrfs_raid_array[type].devs_min; + ctl->max_stripes = 0; ctl->sub_stripes = btrfs_raid_array[type].sub_stripes; + ctl->calc_size = SZ_8M; + ctl->min_stripe_size = SZ_1M; + ctl->max_chunk_size = 4 * ctl->calc_size; ctl->stripe_len = BTRFS_STRIPE_LEN; + ctl->total_devs = btrfs_super_num_devices(info->super_copy); + + switch (info->fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + init_alloc_chunk_ctl_policy_regular(info, ctl); + break; + default: + BUG(); + } switch (type) { case BTRFS_RAID_DUP: @@ -1051,13 +1101,9 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct list_head *dev_list = &info->fs_devices->devices; struct list_head *cur; struct map_lookup *map; - int min_stripe_size = SZ_1M; - u64 calc_size = SZ_8M; u64 min_free; - u64 max_chunk_size = 4 * calc_size; u64 avail = 0; u64 max_avail = 0; - u64 percent_max; struct alloc_chunk_ctl ctl; int looped = 0; int ret; @@ -1070,60 +1116,30 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, } ctl.type = type; - ctl.max_stripes = 0; - ctl.total_devs = btrfs_super_num_devices(info->super_copy); - - if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { - if (type & BTRFS_BLOCK_GROUP_SYSTEM) { - calc_size = SZ_8M; - max_chunk_size = calc_size * 2; - min_stripe_size = SZ_1M; - ctl.max_stripes = BTRFS_MAX_DEVS_SYS_CHUNK; - } else if (type & BTRFS_BLOCK_GROUP_DATA) { - calc_size = SZ_1G; - max_chunk_size = 10 * calc_size; - min_stripe_size = SZ_64M; - ctl.max_stripes = BTRFS_MAX_DEVS(info); - } else if (type & BTRFS_BLOCK_GROUP_METADATA) { - /* for larger filesystems, use larger metadata chunks */ - if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G) - max_chunk_size = SZ_1G; - else - max_chunk_size = SZ_256M; - calc_size = max_chunk_size; - min_stripe_size = SZ_32M; - ctl.max_stripes = BTRFS_MAX_DEVS(info); - } - } - init_alloc_chunk_ctl(info, &ctl); if (ctl.num_stripes < ctl.min_stripes) return -ENOSPC; - /* we don't want a chunk larger than 10% of the FS */ - percent_max = div_factor(btrfs_super_total_bytes(info->super_copy), 1); - max_chunk_size = min(percent_max, max_chunk_size); - again: - if (chunk_bytes_by_type(type, calc_size, &ctl) > max_chunk_size) { - calc_size = max_chunk_size; - calc_size /= ctl.num_stripes; - calc_size /= ctl.stripe_len; - calc_size *= ctl.stripe_len; + if (chunk_bytes_by_type(type, ctl.calc_size, &ctl) > ctl.max_chunk_size) { + ctl.calc_size = ctl.max_chunk_size; + ctl.calc_size /= ctl.num_stripes; + ctl.calc_size /= ctl.stripe_len; + ctl.calc_size *= ctl.stripe_len; } /* we don't want tiny stripes */ - calc_size = max_t(u64, calc_size, min_stripe_size); + ctl.calc_size = max_t(u64, ctl.calc_size, ctl.min_stripe_size); - calc_size /= ctl.stripe_len; - calc_size *= ctl.stripe_len; + ctl.calc_size /= ctl.stripe_len; + ctl.calc_size *= ctl.stripe_len; INIT_LIST_HEAD(&private_devs); cur = dev_list->next; index = 0; if (type & BTRFS_BLOCK_GROUP_DUP) - min_free = calc_size * 2; + min_free = ctl.calc_size * 2; else - min_free = calc_size; + min_free = ctl.calc_size; /* build a private list of devices we will allocate from */ while(index < ctl.num_stripes) { @@ -1155,7 +1171,7 @@ again: } if (!looped && max_avail > 0) { looped = 1; - calc_size = max_avail; + ctl.calc_size = max_avail; goto again; } return -ENOSPC; @@ -1178,7 +1194,7 @@ again: } stripes = &chunk->stripe; - *num_bytes = chunk_bytes_by_type(type, calc_size, &ctl); + *num_bytes = chunk_bytes_by_type(type, ctl.calc_size, &ctl); index = 0; while(index < ctl.num_stripes) { struct btrfs_stripe *stripe; @@ -1192,11 +1208,11 @@ again: list_move(&device->dev_list, dev_list); ret = btrfs_alloc_dev_extent(trans, device, key.offset, - calc_size, &dev_offset); + ctl.calc_size, &dev_offset); if (ret < 0) goto out_chunk_map; - device->bytes_used += calc_size; + device->bytes_used += ctl.calc_size; ret = btrfs_update_device(trans, device); if (ret < 0) goto out_chunk_map; From patchwork Tue Apr 6 08:05:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 959D1C433B4 for ; Tue, 6 Apr 2021 08:07:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A0C1613C2 for ; Tue, 6 Apr 2021 08:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238957AbhDFIHt (ORCPT ); Tue, 6 Apr 2021 04:07:49 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:49896 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238263AbhDFIHq (ORCPT ); Tue, 6 Apr 2021 04:07:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696471; x=1649232471; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b/R/3lw/3WLs2RZ6MZEY4QHC4cvU8H9F8QEU1ByeZ1M=; b=eLLQkaXP/+35dxpzh1JVOxfK4LC4Vx77lO8nPxum1ZO512WOMfjTUdWZ GhYM4Bp+L0ayxNnqaMuOY9DUPnXrsCiTnKJLkq+lai2TXo57f6ohXy29l MCRDgEsNHUV+XNu5nuFN8J+Tauo5w7X67TM/au0XekOrpFn6/jJBGS2hZ f075Tjs8ARtoukNzQLa72hJffguHb9fMlXgcB13S4ljP9Epa2uRiIwEZY GyPDmfAIusZwKJolbeeWqRMcTkepabHsJfp501tj9Jz6lFb5rXFPme99E HK696++9OyreB4o0H0rEmZbh15VOJwWK6ztG7JpgiKBZ/93eLNE8WN4Ak A==; IronPort-SDR: ZEIOeAydYNdozKCuRYfrqiEAAT5Eg7TOaXLtT2oauPv1YO+s03HUni9eYorK9NY7CR3TeOtawK 8PyF527KYF7y0cziTfkSzhWsiH134jMu/3/80HVNMkirAM35gMF2k/oQ883sFJ4GJ1UNWz3eGZ WBa/ABdOw+6yT962m/s11WSBqCgyPsv/Lma76DpOsJY6CMcM+SE9jek3eyX+LuvsEs9QsM46vE 7xQmp5FINitDhCY6kI8xDAU7ciEtogfET5vQpi+hC1GcBd4n1Y6m28BVaO9Wc/d6Ci+Azndpyd Q90= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290680" 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 Apr 2021 16:07:35 +0800 IronPort-SDR: HXIPcl0+K3+vzxZo0w/nR6lRx/BK6epJchcbacNyXrpuZGjdVxaBVkdoBj5tJAzGhKh2T5c1A7 IPyRWP6EePgkrs/gKe3/PidxHC8NMD/BmIFEjrBTiqRa0jSj6DzTuAfvadj4ofSfdUKWQ5OJXi eA9QyD5TuesQsMwWF4I0mewreVWfK6cJZawcFUG46V3cXz5aJ3AzTNznZbvwq+lT4TMrw2Gf0R Qyf4znrCOlmNHmz5IRpLwJq2qWRjiNeoorLbg0u+CAkFvD+a4E70Se1mPRjcbZGoNg6Cv7dM1z xxcLtHa/FwpyBIyN+AO8XkfE 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 Apr 2021 00:48:24 -0700 IronPort-SDR: wipaC+/hoWAceLsb6Vbw3c/JrBUDqp7O1JD4VfEjjA3FZ1eosG7c/vUzl8Al8yionJSLX2A24m SdCQaRH8dA6pNGZ0NHZG6xhMwaN+v0dEOe49OEO6kNiTeZb0oj4/7OvUyRoyIQ5E37004P6dri 9ueHwzHsbPPfRceOW4WM11XrxhfKJrWodtPyXLfSuZMWVlbnLIo+vKFfyfnrwC1eAZmB5f+/R5 dkWyo2SStfRagKRnCSK0eocy/1TE3n/gt7YiIiiw9jytenSfs0JccnmJEzHmnpCLfHItdROHMa Joo= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:06:59 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 05/12] btrfs-progs: factor out decide_stripe_size() Date: Tue, 6 Apr 2021 17:05:47 +0900 Message-Id: <80a124fe2a3c9074d91e992ff833b98e9f8f8997.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out decide_stripe_size() from btrfs_alloc_chunk(). This new function calculates the actual stripe size to allocate and decides the size of a stripe (ctl->calc_size). This commit has no functional changes. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 1ca71a9bc430..95b42eab846d 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -1087,6 +1087,37 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, } } +static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl) +{ + u64 chunk_size = chunk_bytes_by_type(ctl->type, ctl->calc_size, ctl); + + if (chunk_size > ctl->max_chunk_size) { + ctl->calc_size = ctl->max_chunk_size; + ctl->calc_size /= ctl->num_stripes; + ctl->calc_size /= ctl->stripe_len; + ctl->calc_size *= ctl->stripe_len; + } + /* we don't want tiny stripes */ + ctl->calc_size = max_t(u64, ctl->calc_size, ctl->min_stripe_size); + + /* Align to the stripe length */ + ctl->calc_size /= ctl->stripe_len; + ctl->calc_size *= ctl->stripe_len; + + return 0; +} + +static int decide_stripe_size(struct btrfs_fs_info *info, + struct alloc_chunk_ctl *ctl) +{ + switch (info->fs_devices->chunk_alloc_policy) { + case BTRFS_CHUNK_ALLOC_REGULAR: + return decide_stripe_size_regular(ctl); + default: + BUG(); + } +} + int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, struct btrfs_fs_info *info, u64 *start, u64 *num_bytes, u64 type) @@ -1121,17 +1152,10 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, return -ENOSPC; again: - if (chunk_bytes_by_type(type, ctl.calc_size, &ctl) > ctl.max_chunk_size) { - ctl.calc_size = ctl.max_chunk_size; - ctl.calc_size /= ctl.num_stripes; - ctl.calc_size /= ctl.stripe_len; - ctl.calc_size *= ctl.stripe_len; - } - /* we don't want tiny stripes */ - ctl.calc_size = max_t(u64, ctl.calc_size, ctl.min_stripe_size); + ret = decide_stripe_size(info, &ctl); + if (ret < 0) + return ret; - ctl.calc_size /= ctl.stripe_len; - ctl.calc_size *= ctl.stripe_len; INIT_LIST_HEAD(&private_devs); cur = dev_list->next; index = 0; From patchwork Tue Apr 6 08:05:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32413C433ED for ; Tue, 6 Apr 2021 08:08:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2CDD613C3 for ; Tue, 6 Apr 2021 08:08:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237320AbhDFIIG (ORCPT ); Tue, 6 Apr 2021 04:08:06 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:4298 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239304AbhDFIIG (ORCPT ); Tue, 6 Apr 2021 04:08:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696502; x=1649232502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i/7A/NBkseawY7PczIVP4b9ZJDMCS9aAjjDendbEmhk=; b=NtcE/VSD6+V3WmYcQtZ2BWr/nrI4LpESMCzcTx245+9Z94s40hs6ne3Y vslOUR4uJk4g24h0T3Lfy4K5vFQl8GCrodxpd6+B1493vZ77QwZGzw+3S S4JAY2cVba0r3G68eVGkmPxN8VDDo2lo+5iWbk5N8vxbzupXhioo7AfQ4 1bCNsKG0fjhada7URWARJQEZVsWkC0X8pAfXCrauraHGPJLfRBSu9KN0m cR064o/xB7NcDtdmlJn7AyAZoe8jdh/rSatkVfDXuq/w26435hX+j9Iv4 RTmdvLs0imy1SpcXkpiCKvJtkLuPoCAym1bLwrGzp4tE8QUHnfMGE2Jyg A==; IronPort-SDR: ZbLMdSlZHsJ1VoSTtITpx4Pslhw3ARzUFjaX0dC3lNPuWdCLw6OehY8/WScP/2iJgNzdHVES8/ 9E9Rn1IkipAToULYYMRxTWqP6hHp1XvOUbQHTgPdkawVugKXIIgpfmSdj4Q3kWwZ0CJvLQDDaE aYwvti/3qnUZZOnJyNqzXgTnIsIV/lY+WU7UZE6TU/k/dZQb97XDaxV5bzYaVk5ontEBPQivKP JdmpMpCMViafdnH4+poy/Nzu5fMW3HZfaGTbQuNCf5f/tQhAzKBs+5PoW0Lf8GfGHBRBUlwf+G EH0= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290702" 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 Apr 2021 16:08:00 +0800 IronPort-SDR: 2fzsezHRC2VjcSjc2Fe5PYeQpYWgVL0G0i2fGGVC+9EZR9W+STLmlNfkRJZB30xkpatH3Xh8Vw NDm34wbLBROueZMvOUyRCSG7DM4RGF2GiQ+Z5Eg6rvtje/CbpeyMne9lckqloJgeFuDWadDBlm GbAUK72C6Xh1MN23bkx3qMWXEkc2EpuT3q2gosPM+mmpc36LohB1OflsUAFil4WE/6d+kiTM16 DBHF/nPVul7UZXDvmuxwIitARYqevf4NRyr4YxfB7SqvNLM2PrtYQPmTRvPGjVdTKzV5XZP7Gf nVs9d5Ng8D/cGUPNiB/7iNI0 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 Apr 2021 00:48:25 -0700 IronPort-SDR: 3lJ9MNbMm4I8IL02/tkXU9PT8JnCqIYDAP8rc42KcCC52d4dOxbc5KzvfjbhsKzw3KNi8UDCHs wreMTesSnEFAInX917tYR58fiK7C7ZuNFVi+t3TcY+5LZVOqwBmV8WD7BMiqHKGNTZw63sFhEw uvCyvE/y48pJyzDe4TCQ/gRchKtwjaDyXt9nR6vlv5LiqVqcOK+f2pU9s+l7LP+vnEAFRNPdvf sedPQ+ww3JqINRTls8KGtASXF+6zVaEF9x0y599W45kXvBdyzRI7CoWdwyw9hngImsTB22DpPb dAA= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:00 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 06/12] btrfs-progs: factor out create_chunk() Date: Tue, 6 Apr 2021 17:05:48 +0900 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Factor out create_chunk() from btrfs_alloc_chunk(). This new function creates a chunk. There is no functional changes. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 217 ++++++++++++++++++++++------------------ 1 file changed, 120 insertions(+), 97 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 95b42eab846d..a409dd3d0366 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -149,6 +149,7 @@ const struct btrfs_raid_attr btrfs_raid_array[BTRFS_NR_RAID_TYPES] = { }; struct alloc_chunk_ctl { + u64 start; u64 type; int num_stripes; int max_stripes; @@ -156,6 +157,7 @@ struct alloc_chunk_ctl { int sub_stripes; u64 calc_size; u64 min_stripe_size; + u64 num_bytes; u64 max_chunk_size; int stripe_len; int total_devs; @@ -1118,88 +1120,23 @@ static int decide_stripe_size(struct btrfs_fs_info *info, } } -int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, - struct btrfs_fs_info *info, u64 *start, - u64 *num_bytes, u64 type) +static int create_chunk(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *info, struct alloc_chunk_ctl *ctl, + struct list_head *private_devs) { - u64 dev_offset; struct btrfs_root *extent_root = info->extent_root; struct btrfs_root *chunk_root = info->chunk_root; struct btrfs_stripe *stripes; struct btrfs_device *device = NULL; struct btrfs_chunk *chunk; - struct list_head private_devs; struct list_head *dev_list = &info->fs_devices->devices; struct list_head *cur; struct map_lookup *map; - u64 min_free; - u64 avail = 0; - u64 max_avail = 0; - struct alloc_chunk_ctl ctl; - int looped = 0; int ret; int index; struct btrfs_key key; u64 offset; - if (list_empty(dev_list)) { - return -ENOSPC; - } - - ctl.type = type; - init_alloc_chunk_ctl(info, &ctl); - if (ctl.num_stripes < ctl.min_stripes) - return -ENOSPC; - -again: - ret = decide_stripe_size(info, &ctl); - if (ret < 0) - return ret; - - INIT_LIST_HEAD(&private_devs); - cur = dev_list->next; - index = 0; - - if (type & BTRFS_BLOCK_GROUP_DUP) - min_free = ctl.calc_size * 2; - else - min_free = ctl.calc_size; - - /* build a private list of devices we will allocate from */ - while(index < ctl.num_stripes) { - device = list_entry(cur, struct btrfs_device, dev_list); - ret = btrfs_device_avail_bytes(trans, device, &avail); - if (ret) - return ret; - cur = cur->next; - if (avail >= min_free) { - list_move(&device->dev_list, &private_devs); - index++; - if (type & BTRFS_BLOCK_GROUP_DUP) - index++; - } else if (avail > max_avail) - max_avail = avail; - if (cur == dev_list) - break; - } - if (index < ctl.num_stripes) { - list_splice(&private_devs, dev_list); - if (index >= ctl.min_stripes) { - ctl.num_stripes = index; - if (type & (BTRFS_BLOCK_GROUP_RAID10)) { - ctl.num_stripes /= ctl.sub_stripes; - ctl.num_stripes *= ctl.sub_stripes; - } - looped = 1; - goto again; - } - if (!looped && max_avail > 0) { - looped = 1; - ctl.calc_size = max_avail; - goto again; - } - return -ENOSPC; - } ret = find_next_chunk(info, &offset); if (ret) return ret; @@ -1207,36 +1144,38 @@ again: key.type = BTRFS_CHUNK_ITEM_KEY; key.offset = offset; - chunk = kmalloc(btrfs_chunk_item_size(ctl.num_stripes), GFP_NOFS); + chunk = kmalloc(btrfs_chunk_item_size(ctl->num_stripes), GFP_NOFS); if (!chunk) return -ENOMEM; - map = kmalloc(btrfs_map_lookup_size(ctl.num_stripes), GFP_NOFS); + map = kmalloc(btrfs_map_lookup_size(ctl->num_stripes), GFP_NOFS); if (!map) { kfree(chunk); return -ENOMEM; } stripes = &chunk->stripe; - *num_bytes = chunk_bytes_by_type(type, ctl.calc_size, &ctl); + ctl->num_bytes = chunk_bytes_by_type(ctl->type, ctl->calc_size, ctl); index = 0; - while(index < ctl.num_stripes) { + while (index < ctl->num_stripes) { + u64 dev_offset; struct btrfs_stripe *stripe; - BUG_ON(list_empty(&private_devs)); - cur = private_devs.next; + + BUG_ON(list_empty(private_devs)); + cur = private_devs->next; device = list_entry(cur, struct btrfs_device, dev_list); /* loop over this device again if we're doing a dup group */ - if (!(type & BTRFS_BLOCK_GROUP_DUP) || - (index == ctl.num_stripes - 1)) + if (!(ctl->type & BTRFS_BLOCK_GROUP_DUP) || + (index == ctl->num_stripes - 1)) list_move(&device->dev_list, dev_list); ret = btrfs_alloc_dev_extent(trans, device, key.offset, - ctl.calc_size, &dev_offset); + ctl->calc_size, &dev_offset); if (ret < 0) goto out_chunk_map; - device->bytes_used += ctl.calc_size; + device->bytes_used += ctl->calc_size; ret = btrfs_update_device(trans, device); if (ret < 0) goto out_chunk_map; @@ -1249,41 +1188,41 @@ again: memcpy(stripe->dev_uuid, device->uuid, BTRFS_UUID_SIZE); index++; } - BUG_ON(!list_empty(&private_devs)); + BUG_ON(!list_empty(private_devs)); /* key was set above */ - btrfs_set_stack_chunk_length(chunk, *num_bytes); + btrfs_set_stack_chunk_length(chunk, ctl->num_bytes); btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid); - btrfs_set_stack_chunk_stripe_len(chunk, ctl.stripe_len); - btrfs_set_stack_chunk_type(chunk, type); - btrfs_set_stack_chunk_num_stripes(chunk, ctl.num_stripes); - btrfs_set_stack_chunk_io_align(chunk, ctl.stripe_len); - btrfs_set_stack_chunk_io_width(chunk, ctl.stripe_len); + btrfs_set_stack_chunk_stripe_len(chunk, ctl->stripe_len); + btrfs_set_stack_chunk_type(chunk, ctl->type); + btrfs_set_stack_chunk_num_stripes(chunk, ctl->num_stripes); + btrfs_set_stack_chunk_io_align(chunk, ctl->stripe_len); + btrfs_set_stack_chunk_io_width(chunk, ctl->stripe_len); btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize); - btrfs_set_stack_chunk_sub_stripes(chunk, ctl.sub_stripes); + btrfs_set_stack_chunk_sub_stripes(chunk, ctl->sub_stripes); map->sector_size = info->sectorsize; - map->stripe_len = ctl.stripe_len; - map->io_align = ctl.stripe_len; - map->io_width = ctl.stripe_len; - map->type = type; - map->num_stripes = ctl.num_stripes; - map->sub_stripes = ctl.sub_stripes; + map->stripe_len = ctl->stripe_len; + map->io_align = ctl->stripe_len; + map->io_width = ctl->stripe_len; + map->type = ctl->type; + map->num_stripes = ctl->num_stripes; + map->sub_stripes = ctl->sub_stripes; ret = btrfs_insert_item(trans, chunk_root, &key, chunk, - btrfs_chunk_item_size(ctl.num_stripes)); + btrfs_chunk_item_size(ctl->num_stripes)); BUG_ON(ret); - *start = key.offset;; + ctl->start = key.offset; map->ce.start = key.offset; - map->ce.size = *num_bytes; + map->ce.size = ctl->num_bytes; ret = insert_cache_extent(&info->mapping_tree.cache_tree, &map->ce); if (ret < 0) goto out_chunk_map; - if (type & BTRFS_BLOCK_GROUP_SYSTEM) { + if (ctl->type & BTRFS_BLOCK_GROUP_SYSTEM) { ret = btrfs_add_system_chunk(info, &key, - chunk, btrfs_chunk_item_size(ctl.num_stripes)); + chunk, btrfs_chunk_item_size(ctl->num_stripes)); if (ret < 0) goto out_chunk; } @@ -1298,6 +1237,90 @@ out_chunk: return ret; } +int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *info, u64 *start, + u64 *num_bytes, u64 type) +{ + struct btrfs_device *device = NULL; + struct list_head private_devs; + struct list_head *dev_list = &info->fs_devices->devices; + struct list_head *cur; + u64 min_free; + u64 avail = 0; + u64 max_avail = 0; + struct alloc_chunk_ctl ctl; + int looped = 0; + int ret; + int index; + + if (list_empty(dev_list)) + return -ENOSPC; + + ctl.type = type; + /* start and num_bytes will be set by create_chunk() */ + ctl.start = 0; + ctl.num_bytes = 0; + init_alloc_chunk_ctl(info, &ctl); + if (ctl.num_stripes < ctl.min_stripes) + return -ENOSPC; + +again: + ret = decide_stripe_size(info, &ctl); + if (ret < 0) + return ret; + + INIT_LIST_HEAD(&private_devs); + cur = dev_list->next; + index = 0; + + if (type & BTRFS_BLOCK_GROUP_DUP) + min_free = ctl.calc_size * 2; + else + min_free = ctl.calc_size; + + /* build a private list of devices we will allocate from */ + while (index < ctl.num_stripes) { + device = list_entry(cur, struct btrfs_device, dev_list); + ret = btrfs_device_avail_bytes(trans, device, &avail); + if (ret) + return ret; + cur = cur->next; + if (avail >= min_free) { + list_move(&device->dev_list, &private_devs); + index++; + if (type & BTRFS_BLOCK_GROUP_DUP) + index++; + } else if (avail > max_avail) + max_avail = avail; + if (cur == dev_list) + break; + } + if (index < ctl.num_stripes) { + list_splice(&private_devs, dev_list); + if (index >= ctl.min_stripes) { + ctl.num_stripes = index; + if (type & (BTRFS_BLOCK_GROUP_RAID10)) { + ctl.num_stripes /= ctl.sub_stripes; + ctl.num_stripes *= ctl.sub_stripes; + } + looped = 1; + goto again; + } + if (!looped && max_avail > 0) { + looped = 1; + ctl.calc_size = max_avail; + goto again; + } + return -ENOSPC; + } + + ret = create_chunk(trans, info, &ctl, &private_devs); + *start = ctl.start; + *num_bytes = ctl.num_bytes; + + return ret; +} + /* * Alloc a DATA chunk with SINGLE profile. * From patchwork Tue Apr 6 08:05:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61FDEC433B4 for ; Tue, 6 Apr 2021 08:08:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32324613C8 for ; Tue, 6 Apr 2021 08:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239184AbhDFIIH (ORCPT ); Tue, 6 Apr 2021 04:08:07 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34778 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239307AbhDFIIG (ORCPT ); Tue, 6 Apr 2021 04:08:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696478; x=1649232478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZUIIE4X9IFzid6X8BbvdqDvUBb9qz4NyZvtEN3vVsi4=; b=lHhfXU48rB5Ay4UX2693mglp8AdfUq6jfvXf1sMoJ1Z2mQMQSYKzneT+ a/bu9NH/PpMKEOsrLvKeQj49XGdCF6a2xfw8NklhzGk9YpwxeI5uCO1Fl lHy5qCRiJtkbiugJWaEt/LoIc8YIWbjFMTGSVwScYB3mVJUf4xDvM5zXj 2IAwxq91IPTNxKV9VvN+KBh+jYENC2or5cM3FqAm4dEwPdwi/GikL1ATF wI46npzSN2cf7Cwa1Pd4aAvFff4JhCyILWyIS1S7JTb60a8oOzX1yjdmi SoDv3jbFF+gIhh9lT67VLsop/L8zHk76KTxVEXhF6T73U0BI9Yh1ZSy5/ g==; IronPort-SDR: TF8lzwkFAlq3PX0ah+yQDopS+nlu4iaH9OeoHTrT9+3fNaia2QJV8bJK2xLI31QodKUlFsL5BM 7m8FCIQR2EJPGvJDtpY0DCP3hnQLmmKHvhP4UvLzFjPOUMX4XEXqoVIQtNXZp3zvtUSchaL/bD IKOoU7eZPRprmwJA1smDaCPX64m7n02KWKJd+JN+kLncetWezP1vcJYWXujo6dxvoklQIINoWJ kgb6GfhvBC/r+uu/xL/wHxpTTm8MS+fxHoB3On2Tls/IMb/3lD9oM1UQx+7KviZZyfg3VOYnhW i/M= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="163733747" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2021 16:07:44 +0800 IronPort-SDR: VtALeHekJYi1NmwKUFCD4rBCbEsvd0qOAL1YM4qz05gedpoo/3AqeQAhFySB9JLEVUWnIDLDEd EV736/ZRVB0ih5z7CZudZBMoG9ikbR4f7XKV1UYm+cuBR3IlPSw5Gs17anvci1LYGO/W8g9efU khXXx2rf2SaF4mURDj4bYoDZXqyDtah8NtluXBfm6rwCBD2uC5mxnjqBBeAxGQuJff/bguEBHJ it8wxvG0XoytdDSA4p+/uodb2BWND0hQ/0GrB8t1ViHLH0iQRzyGjy5sDVPnnvjcuaB4ChRpHg le7RBFAlP1b8vSDoSYG2ce9x 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 Apr 2021 00:48:26 -0700 IronPort-SDR: U/KCdOHT66c6Jrr88YR7Ox2q/2TwVDX5Cy38U1AHrexgZbV8Q3xSKcP6TDQGascjUlev4z+ZhH uQH/Asahd7zH8W8VHDnO3cl1+4Ykiv3eTMZpsYZc+j09+YN5lPq21SdAnFCl4al9cVNREKXMz+ oRQPZdR7CAJ6Fd4ow8drJiGM9WYhm97tpdCKne21XqPX0T7Z5le3ZVp7EkBsXqe0WGPKRC+Enq da4c4faTqM9rsB49gxR2k0v34+OvPaNnwFtL6AbxYmTgX/JvURvzE61TGwVs0Fv94KZjgn68Zd Qn4= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:01 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 07/12] btrfs-progs: rewrite btrfs_alloc_data_chunk() using create_chunk() Date: Tue, 6 Apr 2021 17:05:49 +0900 Message-Id: <3c99ea11e476f18e5d1aa42bc11807a1e0c2e626.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_alloc_data_chunk() and create_chunk() have the most part in common. Let's rewrite btrfs_alloc_data_chunk() using create_chunk(). There are two differences between btrfs_alloc_data_chunk() and create_chunk(). create_chunk() uses find_next_chunk() to decide the logical address of the chunk, and it uses btrfs_alloc_dev_extent() to decide the physical address of a device extent. On the other hand, btrfs_alloc_data_chunk() uses *start for both logical and physical addresses. To support the btrfs_alloc_data_chunk()'s use case, we use ctl->start and ctl->dev_offset. If these values are set (non-zero), use the specified values as the address. It is safe to use 0 to indicate the value is not set here. Because both lower addresses of logical (0..BTRFS_FIRST_CHUNK_TREE_OBJECT_ID) and physical (0..BTRFS_BLOCK_RESERVED_1M_FOR_SUPER) are reserved. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 136 +++++++++++++--------------------------- 1 file changed, 43 insertions(+), 93 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index a409dd3d0366..2a094eab4971 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -161,6 +161,7 @@ struct alloc_chunk_ctl { u64 max_chunk_size; int stripe_len; int total_devs; + u64 dev_offset; }; struct stripe { @@ -1058,6 +1059,7 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, ctl->max_chunk_size = 4 * ctl->calc_size; ctl->stripe_len = BTRFS_STRIPE_LEN; ctl->total_devs = btrfs_super_num_devices(info->super_copy); + ctl->dev_offset = 0; switch (info->fs_devices->chunk_alloc_policy) { case BTRFS_CHUNK_ALLOC_REGULAR: @@ -1137,9 +1139,14 @@ static int create_chunk(struct btrfs_trans_handle *trans, struct btrfs_key key; u64 offset; - ret = find_next_chunk(info, &offset); - if (ret) - return ret; + if (!ctl->start) { + ret = find_next_chunk(info, &offset); + if (ret) + return ret; + } else { + offset = ctl->start; + } + key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; key.type = BTRFS_CHUNK_ITEM_KEY; key.offset = offset; @@ -1170,10 +1177,18 @@ static int create_chunk(struct btrfs_trans_handle *trans, (index == ctl->num_stripes - 1)) list_move(&device->dev_list, dev_list); - ret = btrfs_alloc_dev_extent(trans, device, key.offset, - ctl->calc_size, &dev_offset); - if (ret < 0) - goto out_chunk_map; + if (!ctl->dev_offset) { + ret = btrfs_alloc_dev_extent(trans, device, key.offset, + ctl->calc_size, &dev_offset); + if (ret < 0) + goto out_chunk_map; + } else { + dev_offset = ctl->dev_offset; + ret = btrfs_insert_dev_extent(trans, device, key.offset, + ctl->calc_size, + ctl->dev_offset); + BUG_ON(ret); + } device->bytes_used += ctl->calc_size; ret = btrfs_update_device(trans, device); @@ -1330,23 +1345,10 @@ again: int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, struct btrfs_fs_info *info, u64 *start, u64 num_bytes) { - u64 dev_offset; - struct btrfs_root *extent_root = info->extent_root; - struct btrfs_root *chunk_root = info->chunk_root; - struct btrfs_stripe *stripes; - struct btrfs_device *device = NULL; - struct btrfs_chunk *chunk; struct list_head *dev_list = &info->fs_devices->devices; - struct list_head *cur; - struct map_lookup *map; - u64 calc_size = SZ_8M; - int num_stripes = 1; - int sub_stripes = 1; - int ret; - int index; - int stripe_len = BTRFS_STRIPE_LEN; - struct btrfs_key key; - + struct list_head private_devs; + struct btrfs_device *device; + struct alloc_chunk_ctl ctl; if (*start != round_down(*start, info->sectorsize)) { error("DATA chunk start not sectorsize aligned: %llu", @@ -1354,78 +1356,26 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, return -EINVAL; } - key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; - key.type = BTRFS_CHUNK_ITEM_KEY; - key.offset = *start; - dev_offset = *start; - - chunk = kmalloc(btrfs_chunk_item_size(num_stripes), GFP_NOFS); - if (!chunk) - return -ENOMEM; - - map = kmalloc(btrfs_map_lookup_size(num_stripes), GFP_NOFS); - if (!map) { - kfree(chunk); - return -ENOMEM; - } - - stripes = &chunk->stripe; - calc_size = num_bytes; - - index = 0; - cur = dev_list->next; - device = list_entry(cur, struct btrfs_device, dev_list); - - while (index < num_stripes) { - struct btrfs_stripe *stripe; - - ret = btrfs_insert_dev_extent(trans, device, key.offset, calc_size, - dev_offset); - BUG_ON(ret); + ctl.start = *start; + ctl.type = BTRFS_BLOCK_GROUP_DATA; + ctl.num_stripes = 1; + ctl.max_stripes = 1; + ctl.min_stripes = 1; + ctl.sub_stripes = 1; + ctl.calc_size = num_bytes; + ctl.min_stripe_size = num_bytes; + ctl.num_bytes = num_bytes; + ctl.max_chunk_size = num_bytes; + ctl.stripe_len = BTRFS_STRIPE_LEN; + ctl.total_devs = btrfs_super_num_devices(info->super_copy); + ctl.dev_offset = *start; - device->bytes_used += calc_size; - ret = btrfs_update_device(trans, device); - BUG_ON(ret); - - map->stripes[index].dev = device; - map->stripes[index].physical = dev_offset; - stripe = stripes + index; - btrfs_set_stack_stripe_devid(stripe, device->devid); - btrfs_set_stack_stripe_offset(stripe, dev_offset); - memcpy(stripe->dev_uuid, device->uuid, BTRFS_UUID_SIZE); - index++; - } - - /* key was set above */ - btrfs_set_stack_chunk_length(chunk, num_bytes); - btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid); - btrfs_set_stack_chunk_stripe_len(chunk, stripe_len); - btrfs_set_stack_chunk_type(chunk, BTRFS_BLOCK_GROUP_DATA); - btrfs_set_stack_chunk_num_stripes(chunk, num_stripes); - btrfs_set_stack_chunk_io_align(chunk, stripe_len); - btrfs_set_stack_chunk_io_width(chunk, stripe_len); - btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize); - btrfs_set_stack_chunk_sub_stripes(chunk, sub_stripes); - map->sector_size = info->sectorsize; - map->stripe_len = stripe_len; - map->io_align = stripe_len; - map->io_width = stripe_len; - map->type = BTRFS_BLOCK_GROUP_DATA; - map->num_stripes = num_stripes; - map->sub_stripes = sub_stripes; - - ret = btrfs_insert_item(trans, chunk_root, &key, chunk, - btrfs_chunk_item_size(num_stripes)); - BUG_ON(ret); - - map->ce.start = key.offset; - map->ce.size = num_bytes; - - ret = insert_cache_extent(&info->mapping_tree.cache_tree, &map->ce); - BUG_ON(ret); + INIT_LIST_HEAD(&private_devs); + /* Build a list containing one device */ + device = list_entry(dev_list->next, struct btrfs_device, dev_list); + list_move(&device->dev_list, &private_devs); - kfree(chunk); - return ret; + return create_chunk(trans, info, &ctl, &private_devs); } int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len) From patchwork Tue Apr 6 08:05:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AEC6C43461 for ; Tue, 6 Apr 2021 08:08:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1CC5613C3 for ; Tue, 6 Apr 2021 08:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238263AbhDFIII (ORCPT ); Tue, 6 Apr 2021 04:08:08 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:38648 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239311AbhDFIIG (ORCPT ); Tue, 6 Apr 2021 04:08:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696502; x=1649232502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DdwkRL44P768f4/8TmEFH5I2JgoZ7i57NgCUXx1ASDA=; b=o5XylYybF1zERl3VOvmGFuq2MlRx5eaWvv0xdGe0D11MPZcb2+w+qjCE DwLpa6tJQZpDz1hio566Tlu0ony+jcZZSZICsk2QcfwrkPhdp+W2dpF+Z wABnXQ4AbzXVYHt9rs5cIfLOSJbis9wu4daP5r7Gf3RHRc8qCt4+jkrwG sLFvZiwNh2Kp7c5LgZE+U9nH8vn8JLPcRRCtB4vcbI4UIShwZHLT7wXfp ++zCBG9bVGrXUpnlyi75rWavJ7dIO1HiyPpeIhOiXK6jJPWIvhjujgJLG ZMcoJTlSumYcHWf5WnlIAgwOecZTs1QALNQx4LXqpidjxY3XKNd8YghcY Q==; IronPort-SDR: uDWOYIDFcARZTL01Dy6zl0SK8/ytUYJRVjdSfhKBsf8Mj2OiEGpkhaXsXuRHiVUQWwPRNVDUu7 tfJJqoHgrIf7Iksw0xHkD2CY+sQmKp2vXD7bPiMnC3sDKCdMd19UkuXIGp614CS5wfFiYByrIp 1PZmPtl3XzQ46qk5SntlNyO0YUk4fKBjCfIwBzFy2elr7XPa5HAo5Z44r4gNJN85tEQCOajvq1 mhP1CeKasIWwTkc+oHOWuI2uHt0Z8sD7s86C0NzBFIsdTzPOCv6p80Q3magBYkzR1g8gdS4urY tBU= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290709" 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 Apr 2021 16:08:06 +0800 IronPort-SDR: rbt1xmvK0K16OyxFhHrGBv3oy/lTQx+9KxaY/nJeg1t9UZBeJVGwIYxvbWean+cR5ovAsyPXHP TtXm54ev/uCZHCAJVqh9UMrNH0d9at6cos3T68D18LD+QV2QHUj6aItnOUaKr8Y/HyiIcbTKn9 xFQQC+BKcJ2iF+OjFGdNZB9dz0+q4COOjrr19pvTPsvRLgqWAW19zWlIrsx07VPiJgWGOaqWLW /IYxaHTAjKJFA10qwK+BbWMom/STjRZoMfli+6wn4uOf2I20NahTEo+4kMPW4ZyGCxwZmOkOpb dvRt6FAtDZ7LenDALl/FSDDP 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 Apr 2021 00:48:27 -0700 IronPort-SDR: VsafkTtppQ5WyNhXwtx6e83H+Wae4qr/85WqctVeBKtVciswyHzxngMmCP0UxI94sxK+dblDUv JEJaErROmvAGDQTxdaZ9Dgc58kxrMhI5GXEB9xwz0udbuhr1jsgN/I0gKhFk3rjhl0Ts6Sn772 UeeCqJDMNQCqfurm3vj6AN3pP2ULce8WVVfDNlErn6w8Xi8WujiBQ+uR1ef5qL7Q5yQkZwY1/M xO6cdLRNwFgae5+4nK+oXdcU+nqUZktRCeaZI6ffd+NaYpIG0CsjN3ZhMn8wfIaEgrnJ7Na1lA gEY= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:02 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 08/12] btrfs-progs: fix to use half the available space for DUP profile Date: Tue, 6 Apr 2021 17:05:50 +0900 Message-Id: <810b410d06941a1abefbf8dc2a9bac8512b4b773.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the DUP profile, we can use only half of the space available in a device extent. Fix the calculation of calc_size for it. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 2a094eab4971..ed3015bf3e0c 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -1323,7 +1323,10 @@ again: } if (!looped && max_avail > 0) { looped = 1; - ctl.calc_size = max_avail; + if (ctl.type & BTRFS_BLOCK_GROUP_DUP) + ctl.calc_size = max_avail / 2; + else + ctl.calc_size = max_avail; goto again; } return -ENOSPC; From patchwork Tue Apr 6 08:05:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8200C433B4 for ; Tue, 6 Apr 2021 08:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F11661040 for ; Tue, 6 Apr 2021 08:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239446AbhDFIIW (ORCPT ); Tue, 6 Apr 2021 04:08:22 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:39878 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236093AbhDFIIT (ORCPT ); Tue, 6 Apr 2021 04:08:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696494; x=1649232494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nb8AwbYRcUj5xB4CdIS38Xo2SZa9m6oBGFvUiOmDn0M=; b=J9zcDVMHtryPugVgLuOzPP/5wByukSiafnoGqr0zEgVEwJuLyjwBtKUs d6h2DN2pLyRcAM4j8ezRCkWvM00CFc5vQUW9nIlsMESfafB6ngI/EFChb ea2UCBGDJ0XoTeof1btiPTevz0ZVpDwwQu52uZyq3ZK+iWztm+ZW6oAjQ oRMntgQ0gverjJ6z3W/TAT3DwbzS44GuAHJDBCRxWMI72y0SXsfwEmiYz sgaZrS5IIjMtOqQSf7E6v1GtPnLbmJqtzpr8v3OKMT6odJ4ccCDQZImZr IG3/NM1Db6eGStQMMuUvF+2HQazKTQMQB9dyqH9ttkpIEfnCmRYMAS6dg Q==; IronPort-SDR: nAk0aAsFWnC5WC2feyWKv34jD0LQKTsKTs90jCc7cgWwDXueqXdPiEPHIrOOVzVQ5T4UD7UvEH UeSQJJZ7bex6DKg4racEq3CDIvJG5WSNKAuWz9snhwQtFYcqtgG0/HsTUm4Q3XNT/q6bgYqEdO 4zXIHTePiTG1s4/2ItQBsGpNHAdoj92Ulq3WSP7upRWQyusyv0VPnp4xBsFyH4N7Fp7m/LSYx1 Bs5VqSRZqEr1tw2Nms593VYQg8l7ykAK6mOMYxq6AhYaL2ZcLM58WjHwS3bjL+qPbh7ID1IseG oL8= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290719" 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 Apr 2021 16:08:00 +0800 IronPort-SDR: dCVr+uotIa01pC6Nvy+RNMA0xpHiz2QL3aZr/0zuEfMyREcYc1OLCXlNv3CBUzGwd45xv71dEa fdaSDa5uhHqg2dAx/c9BdSBet2vHzLSAguf5Y1Jiea/9VKJeQ7HWdeEcsyMcV8fd367l52XqM6 GJ4va5Xc6GDUBsObvZxcQrd2fwxlvkO6Jaez/N+NtUlAX2U68hexb9h50Gs8oQ+UZ0uhXBKQDI YNL374YdwD1OFLRKh3qySYbqU8HYyOZeZI53OTeizw3l0ZnyG+2EUJvMhZ+4PX6KgiaLBj9Ui4 X1hBOImtqVZ/4+a+TNCwial7 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 Apr 2021 00:48:28 -0700 IronPort-SDR: Y2KPYjHiuxfwI8SBODGsCIUaW0N8jgGRX6m+Y7Ci7Z8jf2Z/hqV8fv63iQeVZrANTXAkru+UY4 f5tFKbUkZ0y98L1xe+Y8N3G4kZmU0bYwPN+vlMcen8yDonIUd/hdl0/n23Cd65MSU7mWHDX5qb cBkmmXiFiHlaAspcQvv4xMr+bqmtkuv65DjEa7Pk4n7xzkn0FhRfc6k99OG4zQBfSyIHixz/zb Zqs9HM9p9SxR34ksClOnBT7uEkDGadvEE4J+QZh2eoZ3dtmM1gI6gvd0hyStEjXe1Ho+Vjh/YJ 9Kk= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:03 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 09/12] btrfs-progs: use round_down for allocation calcs Date: Tue, 6 Apr 2021 17:05:51 +0900 Message-Id: <22e1c5423bd180cebca859285942bdb77e679013.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Several calculations in the chunk allocation process use this pattern. x /= y; x *= y; Replace this pattern with round_down(). Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index ed3015bf3e0c..d01d825c67ce 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -1098,15 +1098,13 @@ static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl) if (chunk_size > ctl->max_chunk_size) { ctl->calc_size = ctl->max_chunk_size; ctl->calc_size /= ctl->num_stripes; - ctl->calc_size /= ctl->stripe_len; - ctl->calc_size *= ctl->stripe_len; + ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len); } /* we don't want tiny stripes */ ctl->calc_size = max_t(u64, ctl->calc_size, ctl->min_stripe_size); /* Align to the stripe length */ - ctl->calc_size /= ctl->stripe_len; - ctl->calc_size *= ctl->stripe_len; + ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len); return 0; } @@ -1315,8 +1313,10 @@ again: if (index >= ctl.min_stripes) { ctl.num_stripes = index; if (type & (BTRFS_BLOCK_GROUP_RAID10)) { - ctl.num_stripes /= ctl.sub_stripes; - ctl.num_stripes *= ctl.sub_stripes; + /* We know this should be 2, but just in case */ + ASSERT(is_power_of_2(ctl.sub_stripes)); + ctl.num_stripes = round_down(ctl.num_stripes, + ctl.sub_stripes); } looped = 1; goto again; From patchwork Tue Apr 6 08:05:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD721C433B4 for ; Tue, 6 Apr 2021 08:08:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71FBB613AE for ; Tue, 6 Apr 2021 08:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239909AbhDFIIY (ORCPT ); Tue, 6 Apr 2021 04:08:24 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34809 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239307AbhDFIIV (ORCPT ); Tue, 6 Apr 2021 04:08:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696494; x=1649232494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hibkeTggU1wNs/e18iHznF1h6j9dX3BeOYrY2/mH6AA=; b=XKHf9cwcpcUTnKZiLmH7PnXwPH2GLy54eeOHSIDIldRlQ9EtsOi02qhC 5WMv4vQF9CQv0lAL5gy3Xd5/k82lmUT63Hae2A8k1QK6RW+UL21mZh8RY pPGQECfFmGx9EfK7my+smQw7YBeih7jRvyZpJxSmOWjXYiK9BDE9dDwJY L/WQQjBlDpSP5u9P2G8YlpNVFiEhtnUPPhMHJ5xDsHAqyN2yC9UlaLbVg INouawrJdWTrXlxpHwpIL/j4otEDFxfReeMyDBgObpHLXC60PZJX7kvaD CEFQG0EtBnQn/Z+wvBSen4VNt3562WA68CbocCfkM0J4i5zyij4Co575m w==; IronPort-SDR: gUVC/TbdltSROjrD6B1vjb7qNAGCYxqfE7Tri2ic0HbejhCQ6CZ0lcKk/a2B9cuozTbnr3K0P4 khVyu7Z0kUeo1b1lLcLyOIs5CrXH9+mRcS1TVVqpqx1PqnBVg8noXnGBHRJyY/qA49SdrBvYKZ ZsR7iS6n+8jlV3pNpajaK7ANIxoNniwB/Tn+7PcXOZsOfG3thGkR+G7uSjP9v4kV/xw5tL/yj/ BSjDcGT48t9O5W+4FPxWjQSCKHRtWAjWh2S+thbQO7D3dIRx9Roeg0plG4iCq272uFxN3ZmUkq Ik8= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="163733759" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 06 Apr 2021 16:08:04 +0800 IronPort-SDR: dGq+Mlj7TI+iYNo2DdDgMYSu9Lk1Yb8bJxn+ZuSYOo82BlRZbfQm5vXPdmD+I7V4CaNxbtz0IR 9q0NiiX0fLd16sCQ1breNJW5uJL/OPwxd1/C0hbsmxo0dlnmhb3pu2xY+cgq6XvkY8wW4HMTIM Q6Wk2wCYNrx7jPmKazoi+N/8+UJS4wPTAb2I6xzBXxCLITDZjVbfrVc77aMwT9fPO3sW6BuVSq zToxUBFUgVAee01Bp6aqxy2PRBxdPkenqsJnqrcqrHe7DQQDxgTNnK2ZI27NaHzxZwQyRjSm6n dkOt0z2rSGGn99CkbUDSP2ex 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 Apr 2021 00:48:29 -0700 IronPort-SDR: qB8qo+ikWYt+b94hO0Z750BxFoGZY9UpVE2HzTQ+5oh8IQ7odDV4hhvcJizMrLanna6ub7kuut umNXR3aQdKBkE5/pUkNfPH2+GiPgIceROJHWN3ZKY6+4PsnPiNVgAXPM53rTxGS99a1G8/BD14 kIb3KYrUIgUqUFVncYbRdBPgRKX/U9TPipik19l7J5/9LP9OGB02vbUxywkRbtGwDiItIMROeU 7kfV/Hxbp/oO0ckpaYAvUobDPXfCEmiUm+v6l1qrHYByTY7Rn567lVlzNYFQpLlP634jw7sJed 66w= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:04 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 10/12] btrfs-progs: drop alloc_chunk_ctl::stripe_len Date: Tue, 6 Apr 2021 17:05:52 +0900 Message-Id: <82254413cb8815ee384550bd306ad0cc3c69fdc6.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Since commit b9444efb6658 ("btrfs-progs: don't pretend RAID56 has a different stripe length"), alloc_chunk_ctl::stripe_len is always fixed to BTRFS_STRIPE_LEN. Let's replace alloc_chunk_ctl::stripe_len with BTRFS_STRIPE_LEN, like in the kernel code. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index d01d825c67ce..280537f6549d 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -159,7 +159,6 @@ struct alloc_chunk_ctl { u64 min_stripe_size; u64 num_bytes; u64 max_chunk_size; - int stripe_len; int total_devs; u64 dev_offset; }; @@ -1057,7 +1056,6 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, ctl->calc_size = SZ_8M; ctl->min_stripe_size = SZ_1M; ctl->max_chunk_size = 4 * ctl->calc_size; - ctl->stripe_len = BTRFS_STRIPE_LEN; ctl->total_devs = btrfs_super_num_devices(info->super_copy); ctl->dev_offset = 0; @@ -1098,13 +1096,13 @@ static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl) if (chunk_size > ctl->max_chunk_size) { ctl->calc_size = ctl->max_chunk_size; ctl->calc_size /= ctl->num_stripes; - ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len); + ctl->calc_size = round_down(ctl->calc_size, BTRFS_STRIPE_LEN); } /* we don't want tiny stripes */ ctl->calc_size = max_t(u64, ctl->calc_size, ctl->min_stripe_size); /* Align to the stripe length */ - ctl->calc_size = round_down(ctl->calc_size, ctl->stripe_len); + ctl->calc_size = round_down(ctl->calc_size, BTRFS_STRIPE_LEN); return 0; } @@ -1206,17 +1204,17 @@ static int create_chunk(struct btrfs_trans_handle *trans, /* key was set above */ btrfs_set_stack_chunk_length(chunk, ctl->num_bytes); btrfs_set_stack_chunk_owner(chunk, extent_root->root_key.objectid); - btrfs_set_stack_chunk_stripe_len(chunk, ctl->stripe_len); + btrfs_set_stack_chunk_stripe_len(chunk, BTRFS_STRIPE_LEN); btrfs_set_stack_chunk_type(chunk, ctl->type); btrfs_set_stack_chunk_num_stripes(chunk, ctl->num_stripes); - btrfs_set_stack_chunk_io_align(chunk, ctl->stripe_len); - btrfs_set_stack_chunk_io_width(chunk, ctl->stripe_len); + btrfs_set_stack_chunk_io_align(chunk, BTRFS_STRIPE_LEN); + btrfs_set_stack_chunk_io_width(chunk, BTRFS_STRIPE_LEN); btrfs_set_stack_chunk_sector_size(chunk, info->sectorsize); btrfs_set_stack_chunk_sub_stripes(chunk, ctl->sub_stripes); map->sector_size = info->sectorsize; - map->stripe_len = ctl->stripe_len; - map->io_align = ctl->stripe_len; - map->io_width = ctl->stripe_len; + map->stripe_len = BTRFS_STRIPE_LEN; + map->io_align = BTRFS_STRIPE_LEN; + map->io_width = BTRFS_STRIPE_LEN; map->type = ctl->type; map->num_stripes = ctl->num_stripes; map->sub_stripes = ctl->sub_stripes; @@ -1369,7 +1367,6 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, ctl.min_stripe_size = num_bytes; ctl.num_bytes = num_bytes; ctl.max_chunk_size = num_bytes; - ctl.stripe_len = BTRFS_STRIPE_LEN; ctl.total_devs = btrfs_super_num_devices(info->super_copy); ctl.dev_offset = *start; From patchwork Tue Apr 6 08:05:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184463 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85B2EC43460 for ; Tue, 6 Apr 2021 08:08:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 521E8613AE for ; Tue, 6 Apr 2021 08:08:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239963AbhDFII0 (ORCPT ); Tue, 6 Apr 2021 04:08:26 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:39878 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239561AbhDFIIX (ORCPT ); Tue, 6 Apr 2021 04:08:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696500; x=1649232500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nr/roP5dmvDV6cXQ+o6UhQRvP3AXPeKsjYeZa856KhA=; b=Taaev3rg4vzFnmnPs/XMCIGAAFp2tZfyfX5IpwlI35xazTSTbKa23yvR HnpqkTNrY6Mj4jwaZR0DfuUnk7x0349dACP4V6gRND1V+4yBC6+NLU4Ug 3qiAkqfJHLMhoSnMTVwCBU2EgodvX4wWZXf3t7F5r+XCIl04obCEpy1x9 dE+uHXsb6kUdwKGr7MI/OhFMJVehnL5tY2O/c6ohYfcU88K0cB4FY7WKs qOQwZGwnvKUqf2m/rL8cUw/VF8IgfYXDuELiNUlFIG+Vxjn3+ZOpyVJpy tgaioDULOy1/gBptojhATmVg5dX//MYeGrlYlFNH47I3nA7/PPO0l/Odq A==; IronPort-SDR: ReO+OxWeuYj//g+M70sJia7nHSDCaXLG6YWbX9UYhVbhpESekkutvxGb90exgys8/yiVYBd0CT U2wEd6vFU0BDVN2J79+NJnWDcr07OJ+i6OkGF2oiqglyzCeaeQpRSC5+fLYENq0ZNjYCBMyFg0 hCBbo06G4yj3diTJkMVIaj6HVd8Snotwf1dHduOyBeIjk23QEGFgJ+Cg7y7TYIaNnVBPNHQSsK LuHu0qBwRgtwfVfLuFxBwiv1i1mVMAQXZp8BNMOx5blmgSp7fi+5kpy5GvZ3nnVeDCag+zXDOo v4c= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290726" 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 Apr 2021 16:08:05 +0800 IronPort-SDR: XVKyLbxNH8DZExdGXFDf9Ly1PwPgev7YOxhgvhKVJw/83M2oTHO6Q+4z07YDwn40tY3CSQwCul HU3+JnLfEpiZIAc1j1JqIXKUJOXqMurRnnx0o1qTgaS6PWKSVNNfGguZZaVeL0FYK3e8rFTAIJ 327gNEL7CPu/HIx3fnymrCo5+2Dqza1qxF3J2gc9yTzHuns+HXPPZpWpKcNW46yAwZlW3cAy2s 3M5h0W1m4io218fZ4vIoSblXN/W/UtyvpZN+uT0HCcpzebeOdR5xpegCNkr0l1KqVsZ5zKGJAS huxWrvCS6DeaZ32pUVoc5Mc2 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 Apr 2021 00:48:30 -0700 IronPort-SDR: OX13jAiQqMOI7lSwFCj5NirKiPSdNLJd4n8ETXrsKm2Q86Rj99AQ0B7jNMy/zuOI2ynMF6LcSm KpIIEJ2Cft7vBwxdbsoC1F/Bcjsiqzs597rfBiapkU/feLzj4x3/V8mroNv8fWxLCfBO2OBfv3 Tslhsoos7CinyF+vlQYvGiTily//sbXEw48Ii2iLaGcPbvOPSVOut5Upr6WU52EzoiBWfWzbic nsfy9r3WVB5FaHtBJaCJ8WOcNQUJLaavgjfHBos6CXPtuq1P2ijVjzjvzeSiO5h2YUW0pIsp2Z yuY= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:05 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 11/12] btrfs-progs: simplify arguments of chunk_bytes_by_type() Date: Tue, 6 Apr 2021 17:05:53 +0900 Message-Id: <38d5cd309609dc520bc9bdac8706e2481aa714ce.1617694997.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Chunk_bytes_by_type() takes type, calc_size, and ctl as arguments. But the first two can be obtained from the ctl. Let's drop these arguments for simplicity. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 280537f6549d..d4ef5d626f12 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -897,9 +897,11 @@ int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, return 0; } -static u64 chunk_bytes_by_type(u64 type, u64 calc_size, - struct alloc_chunk_ctl *ctl) +static u64 chunk_bytes_by_type(struct alloc_chunk_ctl *ctl) { + u64 type = ctl->type; + u64 calc_size = ctl->calc_size; + if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP)) return calc_size; else if (type & (BTRFS_BLOCK_GROUP_RAID1C3 | BTRFS_BLOCK_GROUP_RAID1C4)) @@ -1091,9 +1093,7 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl) { - u64 chunk_size = chunk_bytes_by_type(ctl->type, ctl->calc_size, ctl); - - if (chunk_size > ctl->max_chunk_size) { + if (chunk_bytes_by_type(ctl) > ctl->max_chunk_size) { ctl->calc_size = ctl->max_chunk_size; ctl->calc_size /= ctl->num_stripes; ctl->calc_size = round_down(ctl->calc_size, BTRFS_STRIPE_LEN); @@ -1158,7 +1158,7 @@ static int create_chunk(struct btrfs_trans_handle *trans, } stripes = &chunk->stripe; - ctl->num_bytes = chunk_bytes_by_type(ctl->type, ctl->calc_size, ctl); + ctl->num_bytes = chunk_bytes_by_type(ctl); index = 0; while (index < ctl->num_stripes) { u64 dev_offset; From patchwork Tue Apr 6 08:05:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12184465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C272AC433B4 for ; Tue, 6 Apr 2021 08:08:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F04E613C0 for ; Tue, 6 Apr 2021 08:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239982AbhDFIIi (ORCPT ); Tue, 6 Apr 2021 04:08:38 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:26861 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236196AbhDFIIi (ORCPT ); Tue, 6 Apr 2021 04:08:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1617696522; x=1649232522; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=L/blqibO+TuU9qcmt+0D/6AYl3qQRV+N08VxkKnA5ko=; b=P2bRFkuFFoWFGS8CO6eLOAK8QV0b0Os2Uf/mPYKSGNtf4KI0JAHJcg4Z F/Q7F0E7eC+ZtDhzq7gBRSvtPVr6NEjlKx03Unwm6CouRCyIFK7+OxvO8 xo5npTz4zvXii9o7nOqTG0zKppAtLnXVE1cYDje9XKt1JT/QZ6Ecxh6Z8 6YMKZOY69BDdD+TSa4oxmWPWZYuXRCs59NW5TUxDBmxN1zW8+YmcCVF4l UHgS1AJED1vwdpeBKsJJurvbGrJamJMBz0ss9DStht+7D/Yj2n0yRQoeo Zw4FWLz9WrMtXbkNlA/baP64NwyV+o364sDOJvhUHApqTrj3KAEhmXVq6 w==; IronPort-SDR: TOq9zeH44QF1iscQ4X5uuhL9pI63q2AH/ZMS1E9Zky8FBKB43441FFBw6uwGPoe6dHH79uh02V LXR1dd+e8MuN7E3UlyfxZGGmgMV1gZbPKymL3yJT2vTBnt9alKlZSsT0YVz7bh1slcQajz7LG/ u4fKCgeAqYn7mDU7C8aU9riff2YXDioCCSDZyGKZDJDMV2lwIanoz/rsv6qBHoLV9lzIBicLRC IuLesoXk5sCV7POtq+9vVpNRtpNVnKcb8MhUyDTIwQk6QoFPFdyaguu/c9ZbBbvLD72I1vdmPu mAQ= X-IronPort-AV: E=Sophos;i="5.81,308,1610380800"; d="scan'208";a="268290743" 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 Apr 2021 16:08:28 +0800 IronPort-SDR: qDg6YDBpvju7Vr84snntPCzZj79jNrRsVDbbYqeknrMV5x+2+yev7WxCIjX7aHeYfWZ9pAKzHy 0gvPLUoKowX4wajdfQB2HaRnYAmykYOX/ek80w0ueNUCNd89uKkUJwaSsn2AsYAFyZGfGI4nNM 4aSAbYOlZ8+pIV5/cdrxTutRYgMLdAjsLJI+oLf2o7pHHgjShxdChuQQ2UFfvgv3YYtCrqkcUj SOdWMMHQHEi62m7KZP3OX+sMCWZn3cAlocc/E8jFGca0SUWZK4Z/DAuJKOKr2tsOp+7SsSCI44 NHumK5D+pZIopdmBGHMO9XRW 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 Apr 2021 00:48:31 -0700 IronPort-SDR: RZxPnAcsz1mkpoQFl1vRcIMoq4saAs9dbIKRKo4ROZybipFX22lrRQQvNtLEYeIL7UWeSYO3qL DplGxI1hbDPcGAGZ2XK7j2J75O1F2/Q72RIVI4qv74PQQVN5uwhPynYvtkFZkP7JpbDBSaGdrx 60pThjm2ViBOrVTu6R5J2VOlGdf30c7G5XmKLdOLA8+wVB8xsAhhmSs4YJJA5bAnZZQRJdYdJZ ajyclELAsFxgToUM34tWfPTpzucsFRGQi6mmjuU0bfzlaxjsftFVvQnRxC1Txgcv0oOBedjYG2 YRk= WDCIronportException: Internal Received: from 5pgg7h2.ad.shared (HELO naota-xeon.wdc.com) ([10.225.49.29]) by uls-op-cesaip02.wdc.com with ESMTP; 06 Apr 2021 01:07:06 -0700 From: Naohiro Aota To: David Sterba Cc: linux-btrfs@vger.kernel.org, Naohiro Aota Subject: [PATCH 12/12] btrfs-progs: rename calc_size to stripe_size Date: Tue, 6 Apr 2021 17:05:54 +0900 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org alloc_chunk_ctl::calc_size is actually the stripe_size in the kernel side code. Let's rename it to clarify what the "calc" is. Signed-off-by: Naohiro Aota --- kernel-shared/volumes.c | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index d4ef5d626f12..f7dd879398d4 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -155,7 +155,7 @@ struct alloc_chunk_ctl { int max_stripes; int min_stripes; int sub_stripes; - u64 calc_size; + u64 stripe_size; u64 min_stripe_size; u64 num_bytes; u64 max_chunk_size; @@ -900,20 +900,20 @@ int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key, static u64 chunk_bytes_by_type(struct alloc_chunk_ctl *ctl) { u64 type = ctl->type; - u64 calc_size = ctl->calc_size; + u64 stripe_size = ctl->stripe_size; if (type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_DUP)) - return calc_size; + return stripe_size; else if (type & (BTRFS_BLOCK_GROUP_RAID1C3 | BTRFS_BLOCK_GROUP_RAID1C4)) - return calc_size; + return stripe_size; else if (type & BTRFS_BLOCK_GROUP_RAID10) - return calc_size * (ctl->num_stripes / ctl->sub_stripes); + return stripe_size * (ctl->num_stripes / ctl->sub_stripes); else if (type & BTRFS_BLOCK_GROUP_RAID5) - return calc_size * (ctl->num_stripes - 1); + return stripe_size * (ctl->num_stripes - 1); else if (type & BTRFS_BLOCK_GROUP_RAID6) - return calc_size * (ctl->num_stripes - 2); + return stripe_size * (ctl->num_stripes - 2); else - return calc_size * ctl->num_stripes; + return stripe_size * ctl->num_stripes; } /* @@ -1020,13 +1020,13 @@ static void init_alloc_chunk_ctl_policy_regular(struct btrfs_fs_info *info, if (type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { if (type & BTRFS_BLOCK_GROUP_SYSTEM) { - ctl->calc_size = SZ_8M; - ctl->max_chunk_size = ctl->calc_size * 2; + ctl->stripe_size = SZ_8M; + ctl->max_chunk_size = ctl->stripe_size * 2; ctl->min_stripe_size = SZ_1M; ctl->max_stripes = BTRFS_MAX_DEVS_SYS_CHUNK; } else if (type & BTRFS_BLOCK_GROUP_DATA) { - ctl->calc_size = SZ_1G; - ctl->max_chunk_size = 10 * ctl->calc_size; + ctl->stripe_size = SZ_1G; + ctl->max_chunk_size = 10 * ctl->stripe_size; ctl->min_stripe_size = SZ_64M; ctl->max_stripes = BTRFS_MAX_DEVS(info); } else if (type & BTRFS_BLOCK_GROUP_METADATA) { @@ -1035,7 +1035,7 @@ static void init_alloc_chunk_ctl_policy_regular(struct btrfs_fs_info *info, ctl->max_chunk_size = SZ_1G; else ctl->max_chunk_size = SZ_256M; - ctl->calc_size = ctl->max_chunk_size; + ctl->stripe_size = ctl->max_chunk_size; ctl->min_stripe_size = SZ_32M; ctl->max_stripes = BTRFS_MAX_DEVS(info); } @@ -1055,9 +1055,9 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, ctl->min_stripes = btrfs_raid_array[type].devs_min; ctl->max_stripes = 0; ctl->sub_stripes = btrfs_raid_array[type].sub_stripes; - ctl->calc_size = SZ_8M; + ctl->stripe_size = SZ_8M; ctl->min_stripe_size = SZ_1M; - ctl->max_chunk_size = 4 * ctl->calc_size; + ctl->max_chunk_size = 4 * ctl->stripe_size; ctl->total_devs = btrfs_super_num_devices(info->super_copy); ctl->dev_offset = 0; @@ -1094,15 +1094,15 @@ static void init_alloc_chunk_ctl(struct btrfs_fs_info *info, static int decide_stripe_size_regular(struct alloc_chunk_ctl *ctl) { if (chunk_bytes_by_type(ctl) > ctl->max_chunk_size) { - ctl->calc_size = ctl->max_chunk_size; - ctl->calc_size /= ctl->num_stripes; - ctl->calc_size = round_down(ctl->calc_size, BTRFS_STRIPE_LEN); + ctl->stripe_size = ctl->max_chunk_size; + ctl->stripe_size /= ctl->num_stripes; + ctl->stripe_size = round_down(ctl->stripe_size, BTRFS_STRIPE_LEN); } /* we don't want tiny stripes */ - ctl->calc_size = max_t(u64, ctl->calc_size, ctl->min_stripe_size); + ctl->stripe_size = max_t(u64, ctl->stripe_size, ctl->min_stripe_size); /* Align to the stripe length */ - ctl->calc_size = round_down(ctl->calc_size, BTRFS_STRIPE_LEN); + ctl->stripe_size = round_down(ctl->stripe_size, BTRFS_STRIPE_LEN); return 0; } @@ -1175,18 +1175,18 @@ static int create_chunk(struct btrfs_trans_handle *trans, if (!ctl->dev_offset) { ret = btrfs_alloc_dev_extent(trans, device, key.offset, - ctl->calc_size, &dev_offset); + ctl->stripe_size, &dev_offset); if (ret < 0) goto out_chunk_map; } else { dev_offset = ctl->dev_offset; ret = btrfs_insert_dev_extent(trans, device, key.offset, - ctl->calc_size, + ctl->stripe_size, ctl->dev_offset); BUG_ON(ret); } - device->bytes_used += ctl->calc_size; + device->bytes_used += ctl->stripe_size; ret = btrfs_update_device(trans, device); if (ret < 0) goto out_chunk_map; @@ -1285,9 +1285,9 @@ again: index = 0; if (type & BTRFS_BLOCK_GROUP_DUP) - min_free = ctl.calc_size * 2; + min_free = ctl.stripe_size * 2; else - min_free = ctl.calc_size; + min_free = ctl.stripe_size; /* build a private list of devices we will allocate from */ while (index < ctl.num_stripes) { @@ -1322,9 +1322,9 @@ again: if (!looped && max_avail > 0) { looped = 1; if (ctl.type & BTRFS_BLOCK_GROUP_DUP) - ctl.calc_size = max_avail / 2; + ctl.stripe_size = max_avail / 2; else - ctl.calc_size = max_avail; + ctl.stripe_size = max_avail; goto again; } return -ENOSPC; @@ -1363,7 +1363,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans, ctl.max_stripes = 1; ctl.min_stripes = 1; ctl.sub_stripes = 1; - ctl.calc_size = num_bytes; + ctl.stripe_size = num_bytes; ctl.min_stripe_size = num_bytes; ctl.num_bytes = num_bytes; ctl.max_chunk_size = num_bytes;