From patchwork Tue Nov 9 22:02:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12611157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63CC5C433F5 for ; Tue, 9 Nov 2021 22:02:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44D3361178 for ; Tue, 9 Nov 2021 22:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244715AbhKIWFT (ORCPT ); Tue, 9 Nov 2021 17:05:19 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:45248 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244705AbhKIWFR (ORCPT ); Tue, 9 Nov 2021 17:05:17 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.1.2/8.16.1.2) with SMTP id 1A9M0akE017618 for ; Tue, 9 Nov 2021 14:02:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=WOmvpA7cjYl18JiJPhPmgpakNV7ab7toCumdh3DpANI=; b=mt9r3bJQurICS4uU4No2rlxQFFh+FKZIUQMWeOgg4PX1a8IczLqyPbQwegroAhdkDlbW pUwhCq1+HbQ/K2phue7Yzi8tW9soClYVvCu0Tzm4uyhyZPWvmp4dDZsipJPpvlhP3i77 l/JxpfHcsPv+wpoCSVPneUNwI5M0LyqoMzA= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 3c7w04jfgk-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 09 Nov 2021 14:02:30 -0800 Received: from intmgw002.25.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Tue, 9 Nov 2021 14:02:29 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 3A0376326D80; Tue, 9 Nov 2021 14:02:21 -0800 (PST) From: Stefan Roesch To: , CC: Subject: [PATCH v5 1/4] btrfs: store chunk size in space-info struct. Date: Tue, 9 Nov 2021 14:02:15 -0800 Message-ID: <20211109220218.602995-2-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109220218.602995-1-shr@fb.com> References: <20211109220218.602995-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-GUID: W_MZeBEvvCoX4XmOj-qonF1h29Sq4FIL X-Proofpoint-ORIG-GUID: W_MZeBEvvCoX4XmOj-qonF1h29Sq4FIL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-09_07,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 clxscore=1015 phishscore=0 adultscore=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111090119 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The chunk size is stored in the btrfs_space_info structure. It is initialized at the start and is then used. A new api is added to update the current chunk size. This api is used to be able to expose the chunk_size as a sysfs setting. Signed-off-by: Stefan Roesch --- fs/btrfs/space-info.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/space-info.h | 3 +++ fs/btrfs/volumes.c | 28 +++++++++------------------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 48d77f360a24..3a31aea701a8 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -181,6 +181,46 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info) found->full = 0; } +/* + * Compute chunk size depending on block type for regular volumes. + */ +static u64 compute_chunk_size_regular(struct btrfs_fs_info *info, u64 flags) +{ + ASSERT(flags & BTRFS_BLOCK_GROUP_TYPE_MASK); + + if (flags & BTRFS_BLOCK_GROUP_DATA) + return SZ_1G; + else if (flags & BTRFS_BLOCK_GROUP_SYSTEM) + return SZ_32M; + + /* Handle BTRFS_BLOCK_GROUP_METADATA */ + if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G) + return SZ_1G; + + return SZ_256M; +} + +/* + * Compute chunk size depending on volume type. + */ +static u64 compute_chunk_size(struct btrfs_fs_info *info, u64 flags) +{ + if (btrfs_is_zoned(info)) + return info->zone_size; + + return compute_chunk_size_regular(info, flags); +} + +/* + * Update default chunk size. + * + */ +void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info, + u64 chunk_size) +{ + atomic64_set(&space_info->chunk_size, chunk_size); +} + static int create_space_info(struct btrfs_fs_info *info, u64 flags) { @@ -202,6 +242,7 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) INIT_LIST_HEAD(&space_info->tickets); INIT_LIST_HEAD(&space_info->priority_tickets); space_info->clamp = 1; + btrfs_update_space_info_chunk_size(space_info, compute_chunk_size(info, flags)); ret = btrfs_sysfs_add_space_info_type(info, space_info); if (ret) diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index cb5056472e79..b0ea8fa65cef 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -23,6 +23,7 @@ struct btrfs_space_info { u64 max_extent_size; /* This will hold the maximum extent size of the space info if we had an ENOSPC in the allocator. */ + atomic64_t chunk_size; /* chunk size in bytes */ int clamp; /* Used to scale our threshold for preemptive flushing. The value is >> clamp, so turns @@ -115,6 +116,8 @@ void btrfs_update_space_info(struct btrfs_fs_info *info, u64 flags, u64 total_bytes, u64 bytes_used, u64 bytes_readonly, u64 bytes_zone_unusable, struct btrfs_space_info **space_info); +void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info, + u64 chunk_size); struct btrfs_space_info *btrfs_find_space_info(struct btrfs_fs_info *info, u64 flags); u64 __pure btrfs_space_info_used(struct btrfs_space_info *s_info, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 45c91a2f172c..6e24007ce0d2 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5096,26 +5096,16 @@ static void init_alloc_chunk_ctl_policy_regular( struct btrfs_fs_devices *fs_devices, struct alloc_chunk_ctl *ctl) { - u64 type = ctl->type; + struct btrfs_space_info *space_info; - 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(); - } + space_info = btrfs_find_space_info(fs_devices->fs_info, ctl->type); + ASSERT(space_info); + + ctl->max_chunk_size = atomic64_read(&space_info->chunk_size); + ctl->max_stripe_size = ctl->max_chunk_size; + + if (ctl->type & BTRFS_BLOCK_GROUP_SYSTEM) + ctl->devs_max = min_t(int, ctl->devs_max, BTRFS_MAX_DEVS_SYS_CHUNK); /* 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), From patchwork Tue Nov 9 22:02:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12611159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDA5C4332F for ; Tue, 9 Nov 2021 22:02:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C88F61177 for ; Tue, 9 Nov 2021 22:02:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244776AbhKIWFU (ORCPT ); Tue, 9 Nov 2021 17:05:20 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:18956 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244705AbhKIWFU (ORCPT ); Tue, 9 Nov 2021 17:05:20 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.1.2/8.16.1.2) with SMTP id 1A9M0akH017618 for ; Tue, 9 Nov 2021 14:02:33 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=XaCykFwXMCDAcNbB2ExNRUs+wHOEbi/f6LfQ6DxQcGs=; b=pKO7YIVj0CkonrrXUqgXF0zbLgrmudYzgbnfXI68jUUThl3yvEvPOv0IuosW57ufUbaU wdtjyRI+FOGALg+O6QIhmf+IZJQwPU/2PClIl/zcwDIIUYqYNphFK/VIXMQpvvGzC9Nn r+b791CU4G4EnOO75X+l5pGIyPagYpfPYRM= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 3c7w04jfgk-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 09 Nov 2021 14:02:33 -0800 Received: from intmgw006.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Tue, 9 Nov 2021 14:02:32 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 3EA6D6326D82; Tue, 9 Nov 2021 14:02:21 -0800 (PST) From: Stefan Roesch To: , CC: Subject: [PATCH v5 2/4] btrfs: expose chunk size in sysfs. Date: Tue, 9 Nov 2021 14:02:16 -0800 Message-ID: <20211109220218.602995-3-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109220218.602995-1-shr@fb.com> References: <20211109220218.602995-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-GUID: E2Je954UWtfzG1Usi3L7ISzUVYn2uyyX X-Proofpoint-ORIG-GUID: E2Je954UWtfzG1Usi3L7ISzUVYn2uyyX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-09_07,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 clxscore=1015 phishscore=0 adultscore=1 lowpriorityscore=0 mlxscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111090119 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This adds a new sysfs entry in /sys/fs/btrfs//allocation//chunk_size. This allows to query the chunk size and also set the chunk size. Signed-off-by: Stefan Roesch --- fs/btrfs/sysfs.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index f9eff3b0f77c..39890ea21997 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -21,6 +21,7 @@ #include "space-info.h" #include "block-group.h" #include "qgroup.h" +#include "misc.h" /* * Structure name Path @@ -92,6 +93,7 @@ static struct btrfs_feature_attr btrfs_attr_features_##_name = { \ static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj); static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj); +static inline struct kobject *get_btrfs_kobj(struct kobject *kobj); static struct btrfs_feature_attr *to_btrfs_feature_attr(struct kobj_attribute *a) { @@ -708,6 +710,81 @@ static ssize_t btrfs_space_info_show_##field(struct kobject *kobj, \ } \ BTRFS_ATTR(space_info, field, btrfs_space_info_show_##field) +/* + * Return space info chunk size. + */ +static ssize_t btrfs_chunk_size_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_space_info *sinfo = to_space_info(kobj); + + return sysfs_emit(buf, "%llu\n", atomic64_read(&sinfo->chunk_size)); +} + +/* + * Store new user supplied chunk size in space info. + * + * Note: If the new chunk size value is larger than 10% of free space it is + * reduced to match that limit. + */ +static ssize_t btrfs_chunk_size_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj)); + u64 val; + int ret; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (!fs_info) { + pr_err("couldn't get fs_info\n"); + return -EPERM; + } + + if (sb_rdonly(fs_info->sb)) + return -EROFS; + + if (!fs_info->fs_devices) + return -EINVAL; + + if (btrfs_is_zoned(fs_info)) + return -EINVAL; + + if (!space_info) { + btrfs_err(fs_info, "couldn't get space_info\n"); + return -EPERM; + } + + /* System block type must not be changed. */ + if (space_info->flags & BTRFS_BLOCK_GROUP_SYSTEM) + return -EINVAL; + + ret = kstrtoull(buf, 10, &val); + if (ret) + return ret; + + val = min(val, BTRFS_MAX_DATA_CHUNK_SIZE); + + /* + * Limit stripe size to 10% of available space. + */ + val = min(div_factor(fs_info->fs_devices->total_rw_bytes, 1), val); + + /* Must be multiple of 256M. */ + val &= ~(SZ_256M - 1); + + /* Must be at least 256M. */ + if (val < SZ_256M) + return -EINVAL; + + btrfs_update_space_info_chunk_size(space_info, val); + + return val; +} + SPACE_INFO_ATTR(flags); SPACE_INFO_ATTR(total_bytes); SPACE_INFO_ATTR(bytes_used); @@ -718,6 +795,8 @@ SPACE_INFO_ATTR(bytes_readonly); SPACE_INFO_ATTR(bytes_zone_unusable); SPACE_INFO_ATTR(disk_used); SPACE_INFO_ATTR(disk_total); +BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, + btrfs_chunk_size_store); /* * Allocation information about block group types. @@ -735,6 +814,7 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, bytes_zone_unusable), BTRFS_ATTR_PTR(space_info, disk_used), BTRFS_ATTR_PTR(space_info, disk_total), + BTRFS_ATTR_PTR(space_info, chunk_size), NULL, }; ATTRIBUTE_GROUPS(space_info); @@ -1099,6 +1179,20 @@ static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj) return to_fs_devs(kobj)->fs_info; } +/* + * Get btrfs sysfs kobject. + */ +static inline struct kobject *get_btrfs_kobj(struct kobject *kobj) +{ + while (kobj) { + if (kobj->ktype == &btrfs_ktype) + return kobj; + kobj = kobj->parent; + } + + return NULL; +} + #define NUM_FEATURE_BITS 64 #define BTRFS_FEATURE_NAME_MAX 13 static char btrfs_unknown_feature_names[FEAT_MAX][NUM_FEATURE_BITS][BTRFS_FEATURE_NAME_MAX]; From patchwork Tue Nov 9 22:02:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12611155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3146C433EF for ; Tue, 9 Nov 2021 22:02:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBDCD61177 for ; Tue, 9 Nov 2021 22:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244712AbhKIWFT (ORCPT ); Tue, 9 Nov 2021 17:05:19 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:64342 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237422AbhKIWFQ (ORCPT ); Tue, 9 Nov 2021 17:05:16 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A9LviBD019749 for ; Tue, 9 Nov 2021 14:02:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=8qufuFiPOctj4aEwGygamM5nb7hRbgBQFF0u4nF9s/w=; b=ZcToQOwuVECdCS5Igc6q1tzUGLgRD2rmVKFPg5WbI5gJ4S6w4+TIF0zA1GI8mY2+6d86 +UUDaIL0sR6qUhUG1YtVMIKrizD3/y/WpLiYKh/WlwM83g52UDCcU+DpAHBQ00Fqap2a Rk1JO4pC8YB0+6C+BG3GowebHFlGXyF1dLA= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3c7ys2rw4u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 09 Nov 2021 14:02:30 -0800 Received: from intmgw002.25.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Tue, 9 Nov 2021 14:02:29 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 43B196326D84; Tue, 9 Nov 2021 14:02:21 -0800 (PST) From: Stefan Roesch To: , CC: Subject: [PATCH v5 3/4] btrfs: add force_chunk_alloc sysfs entry to force allocation Date: Tue, 9 Nov 2021 14:02:17 -0800 Message-ID: <20211109220218.602995-4-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109220218.602995-1-shr@fb.com> References: <20211109220218.602995-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: AoUePj2GoWTqbvokZFVOtjWv9wp6b6d_ X-Proofpoint-GUID: AoUePj2GoWTqbvokZFVOtjWv9wp6b6d_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-09_07,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 phishscore=0 adultscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111090119 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This adds the force_chunk_alloc sysfs entry to be able to force a storage allocation. This is a debugging and test feature and is enabled with the CONFIG_BTRFS_DEBUG configuration option. It is stored at /sys/fs/btrfs//allocation//force_chunk_alloc. --- fs/btrfs/sysfs.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 39890ea21997..7eff8b8c4f1f 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -62,6 +62,10 @@ struct raid_kobject { .store = _store, \ } +#define BTRFS_ATTR_W(_prefix, _name, _store) \ + static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ + __INIT_KOBJ_ATTR(_name, 0200, NULL, _store) + #define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \ static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ __INIT_KOBJ_ATTR(_name, 0644, _show, _store) @@ -785,6 +789,54 @@ static ssize_t btrfs_chunk_size_store(struct kobject *kobj, return val; } +#ifdef CONFIG_BTRFS_DEBUG +/* + * Request chunk allocation with current chunk size. + */ +static ssize_t btrfs_force_chunk_alloc_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + struct btrfs_space_info *space_info = to_space_info(kobj); + struct btrfs_fs_info *fs_info = to_fs_info(get_btrfs_kobj(kobj)); + struct btrfs_trans_handle *trans; + unsigned long val; + int ret; + + if (!fs_info) { + pr_err("couldn't get fs_info\n"); + return -EPERM; + } + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (sb_rdonly(fs_info->sb)) + return -EROFS; + + ret = kstrtoul(buf, 10, &val); + if (ret) + return ret; + + if (val == 0) + return -EINVAL; + + /* + * Allocate new chunk. + */ + trans = btrfs_start_transaction(fs_info->extent_root, 0); + if (!trans) + return PTR_ERR(trans); + ret = btrfs_force_chunk_alloc(trans, space_info->flags); + btrfs_end_transaction(trans); + + if (ret == 1) + return len; + + return -ENOSPC; +} +#endif + SPACE_INFO_ATTR(flags); SPACE_INFO_ATTR(total_bytes); SPACE_INFO_ATTR(bytes_used); @@ -797,6 +849,9 @@ SPACE_INFO_ATTR(disk_used); SPACE_INFO_ATTR(disk_total); BTRFS_ATTR_RW(space_info, chunk_size, btrfs_chunk_size_show, btrfs_chunk_size_store); +#ifdef CONFIG_BTRFS_DEBUG +BTRFS_ATTR_W(space_info, force_chunk_alloc, btrfs_force_chunk_alloc_store); +#endif /* * Allocation information about block group types. @@ -815,6 +870,9 @@ static struct attribute *space_info_attrs[] = { BTRFS_ATTR_PTR(space_info, disk_used), BTRFS_ATTR_PTR(space_info, disk_total), BTRFS_ATTR_PTR(space_info, chunk_size), +#ifdef CONFIG_BTRFS_DEBUG + BTRFS_ATTR_PTR(space_info, force_chunk_alloc), +#endif NULL, }; ATTRIBUTE_GROUPS(space_info); From patchwork Tue Nov 9 22:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 12611153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE5E1C433EF for ; Tue, 9 Nov 2021 22:02:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD9B261055 for ; Tue, 9 Nov 2021 22:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244677AbhKIWFQ (ORCPT ); Tue, 9 Nov 2021 17:05:16 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:36406 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237422AbhKIWFO (ORCPT ); Tue, 9 Nov 2021 17:05:14 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.1.2/8.16.1.2) with SMTP id 1A9LwJcj005580 for ; Tue, 9 Nov 2021 14:02:27 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=uv8tcymSgViQDXFTk5CH4OYDAeiQrzXqUVLW3ixjzSc=; b=OjxkAYvjYjUurub3NCrgMI2C0Ey7U8S1BVMZ+Apf3GhGlkP3B0C59NSJsPHn4DUbtOBf PGFchhMkezrMQf6cNlu4iCpStQQaVNtiCE9rRrWL9q5xxtg/38/X8tB2LiHJmXRZYQd9 JoDvxJOIgpVqNPPHoJG31sllmPl2EgwxAjM= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0001303.ppops.net with ESMTP id 3c7tefcpb6-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 09 Nov 2021 14:02:27 -0800 Received: from intmgw001.05.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Tue, 9 Nov 2021 14:02:22 -0800 Received: by devvm225.atn0.facebook.com (Postfix, from userid 425415) id 494036326D86; Tue, 9 Nov 2021 14:02:21 -0800 (PST) From: Stefan Roesch To: , CC: Subject: [PATCH v5 4/4] btrfs: increase metadata alloc size to 5GB for volumes > 50GB Date: Tue, 9 Nov 2021 14:02:18 -0800 Message-ID: <20211109220218.602995-5-shr@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109220218.602995-1-shr@fb.com> References: <20211109220218.602995-1-shr@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-GUID: O0EflO94qmEqxJJaUa4i9V4pEId20gFG X-Proofpoint-ORIG-GUID: O0EflO94qmEqxJJaUa4i9V4pEId20gFG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-09_07,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 adultscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111090119 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This increases the metadata default allocation size from 1GB to 5GB for volumes with a size greater than 50GB. Signed-off-by: Stefan Roesch --- fs/btrfs/space-info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 3a31aea701a8..0d0accbe3bfb 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -195,7 +195,7 @@ static u64 compute_chunk_size_regular(struct btrfs_fs_info *info, u64 flags) /* Handle BTRFS_BLOCK_GROUP_METADATA */ if (info->fs_devices->total_rw_bytes > 50ULL * SZ_1G) - return SZ_1G; + return 5ULL * SZ_1G; return SZ_256M; }