Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp203986lqo; Wed, 15 May 2024 11:44:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVknOxCWEgTDu3Ylt++Z1+VMMU/xTtc703dju5h1u0nIj7cL5eTbKRcgRDZQsMdyKSXVgvIhnycGPKGtvdRNBeftO2qLOa6n7SI8X/6KQ== X-Google-Smtp-Source: AGHT+IGrWBzNMhH6pzVmrsIYVVQZfsxpi9B490pD8vdTyWkliKvxYpS73bO053S66M9T+NiRnT29 X-Received: by 2002:a05:6e02:20c8:b0:36a:1a0b:ac5e with SMTP id e9e14a558f8ab-36cc14f7b7amr178054895ab.27.1715798692916; Wed, 15 May 2024 11:44:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715798692; cv=pass; d=google.com; s=arc-20160816; b=oUiSjqRXDr8zXFTWAxYmPt/RSuYLbnYAGYuDZJw5SN3EFcELM/Gh3HP4U1FTJn8FBJ O7jbqqCK0XmOxcdRqp5tjXX0am32ED9N5Mzm3zYKSJhqi9xZgY/Sc3o4XRJ8Vk+Phv1r PR22+GpYr8rTIS3E3P1HM0wEFnjguD4HsFNsC50o8PDecF4jnJZKPCLqZtueLyvX3yvj WbQf5PGJFv+/r//+B4au87igTrU4MBV/uwKg5MdrzkGBDG+kLnqeXKExvOQM8pfgqbWg DIeREA+7clU4KFtqvFRLT2gJq0eIN9vT7nfykebQP+ShzWmpZMGvV/34N9kYEPrgMDUB /cNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from; bh=xMGciBx6a6W9YMu8j+TGhNBJjOW56w9BCchj3OIvq7g=; fh=UEYRRZonYlq294532zuy0Tn8MWDEYSS2KKhAVP4uu/8=; b=hQMjCx4otgcGRtB6V30i2je4tahKRLjElQZrPq25w6FE0Oqnml7esDBwolyKVg4nLv B5EDv/G8or7H+VCB39UfQZdwkXTdwF1rvStIMA3RxkJXQyEl8FdLxGZlkDnzKFN33eAM X6JP6MMWp9uRMUXCbjQV7XfQj/QuCEKpx9GgGUd+Kz9riqxN9oRqwFvg/+aUo2HMK64N RJmDSYMtaSpxVhFszLhIWoN5dD4jFk5A+7RrE0UjmQR/8s2HntR1+TQ6DLaeyfLQ3hgF n5JOuqqqXcuJbGW+56oA/BRNTQBG41fILZc4DweuARDz9DXzK2edpjg1Zc0fqm7StFa4 ICow==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-658d6391bd9si188404a12.176.2024.05.15.11.44.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 11:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180274-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180274-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 63569B23943 for ; Wed, 15 May 2024 18:43:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBEEC15ADA9; Wed, 15 May 2024 18:43:14 +0000 (UTC) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8329C2E622; Wed, 15 May 2024 18:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715798594; cv=none; b=MwaJj5oc41ntdoRi/Gl7IQj7+4TDX6wkfoawKLOitMa5gmwp8kHUFWo6JVC0yLovHyVpXu5bZ9u9NrH0gcmbqC9mEMUYVgL0G2S11GI6VL7I8+mid5lG+gPQ+TNOaQCJsgJpCbY4GJ8mHaWzHhbwlc8SE/sUXYyWZkSVYU8T7gE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715798594; c=relaxed/simple; bh=OuhlJZQDRifnKQDwqSTU7er/WFwoQXBxbE0NfsILInY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Akzp5HdOPhhkVWden3Y90YANgHXpvqOTN9FbnZdNKwoXditntJATp4kA05hMWg+XuDneVWw+mDrx7qxHdGayMg5Uiz6FTLYxxlsC4zP3AlpZhHVj2tUqyavGe2Gbjf9204Ynz4g008fo8TaaYEXogfBopdF6Us1hlanOLkwazGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-51f60817e34so8102007e87.2; Wed, 15 May 2024 11:43:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715798590; x=1716403390; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xMGciBx6a6W9YMu8j+TGhNBJjOW56w9BCchj3OIvq7g=; b=gM6xx+necCeuCUPYtvBTbKaGUTcqCS7l2RGc3OlsbNlLgmNl8os4LJtWpAn9VBq/eZ 3rdVGxaPORFV9R+oqrDDc1mVcPnghOXq3QDDU/heF9DqlrFjE7SNM+LEVg3t1A4KWNJw ODrvkIstbs833uoRA+oLHXueW7h0kMhIAz6bgf/qeOq9SkiR1fdMyfmiSymuMVOU/xE4 bZraGd1YCVi8FR0+Iwb98yHdhm0jSsSlENijD+1NcynDFeaaxo1p/2h7AWJ4x7E4ifqt Loa4kv84o8UrY4AUwXpgSAVKsGnFuySZDwvvQ+s3STUXO+RG3PdDgBaHgnnN20d/3blW zh1A== X-Forwarded-Encrypted: i=1; AJvYcCVtNRIT8xSqmWTcxWZb1WXiBucpy62GkeVqfZXTN+uTQsJjjnF1h7RqLqj3RxyQCc72YP8n8uVaFVtBQBkT6d5IlciVrBRtfQ4zUAbxLOIAJfaHvvWC7KgDx3U3QMaxGII+cpHAQz3hljQ= X-Gm-Message-State: AOJu0Yyd0eyDim12w7g2qOUDyp1H7XHH7RUvcXuljriBcP3VufWVHw4H MDhjzgoMowV4mXQ5vyetJRAHxm1LanuWWu/rjp9HKBKlLbSeoZnr X-Received: by 2002:a05:6512:b16:b0:51e:f52c:34eb with SMTP id 2adb3069b0e04-5220fe78cdfmr13415857e87.51.1715798590365; Wed, 15 May 2024 11:43:10 -0700 (PDT) Received: from [127.0.0.1] (p200300f6f718be00fa633ffffe02074c.dip0.t-ipconnect.de. [2003:f6:f718:be00:fa63:3fff:fe02:74c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-574f4a6280csm1724340a12.52.2024.05.15.11.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 11:43:10 -0700 (PDT) From: Johannes Thumshirn Date: Wed, 15 May 2024 20:43:06 +0200 Subject: [PATCH v2 1/2] btrfs: zoned: reserve relocation zone on mount Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240515-zoned-gc-v2-1-20c7cb9763cd@kernel.org> References: <20240515-zoned-gc-v2-0-20c7cb9763cd@kernel.org> In-Reply-To: <20240515-zoned-gc-v2-0-20c7cb9763cd@kernel.org> To: Chris Mason , Josef Bacik , David Sterba Cc: Hans Holmberg , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Naohiro Aota , Johannes Thumshirn X-Mailer: b4 0.12.4 From: Johannes Thumshirn Reserve one zone as a data relocation target on each mount. If we already find one empty block group, there's no need to force a chunk allocation, but we can use this empty data block group as our relocation target. Signed-off-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 2 ++ fs/btrfs/zoned.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 3 +++ 3 files changed, 65 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index a91a8056758a..0490f2f45fb1 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3558,6 +3558,8 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device } btrfs_discard_resume(fs_info); + btrfs_reserve_relocation_zone(fs_info); + if (fs_info->uuid_root && (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) || fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) { diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 4cba80b34387..b752f8c95f40 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -17,6 +17,7 @@ #include "fs.h" #include "accessors.h" #include "bio.h" +#include "transaction.h" /* Maximum number of zones to report per blkdev_report_zones() call */ #define BTRFS_REPORT_NR_ZONES 4096 @@ -2634,3 +2635,62 @@ void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info) } spin_unlock(&fs_info->zone_active_bgs_lock); } + +static u64 find_empty_block_group(struct btrfs_space_info *sinfo, u64 flags) +{ + struct btrfs_block_group *bg; + + for (int i = 0; i < BTRFS_NR_RAID_TYPES; i++) { + list_for_each_entry(bg, &sinfo->block_groups[i], list) { + if (bg->flags != flags) + continue; + if (bg->used == 0) + return bg->start; + } + } + + return 0; +} + +void btrfs_reserve_relocation_zone(struct btrfs_fs_info *fs_info) +{ + struct btrfs_root *tree_root = fs_info->tree_root; + struct btrfs_space_info *sinfo = fs_info->data_sinfo; + struct btrfs_trans_handle *trans; + u64 flags = btrfs_get_alloc_profile(fs_info, sinfo->flags); + u64 bytenr = 0; + + lockdep_assert_not_held(&fs_info->relocation_bg_lock); + + if (!btrfs_is_zoned(fs_info)) + return; + + bytenr = find_empty_block_group(sinfo, flags); + if (!bytenr) { + int ret; + + trans = btrfs_join_transaction(tree_root); + if (IS_ERR(trans)) + return; + + ret = btrfs_chunk_alloc(trans, flags, CHUNK_ALLOC_FORCE); + btrfs_end_transaction(trans); + + if (!ret) { + struct btrfs_block_group *bg; + + bytenr = find_empty_block_group(sinfo, flags); + if (!bytenr) + goto out; + bg = btrfs_lookup_block_group(fs_info, bytenr); + ASSERT(bg); + + if (!btrfs_zone_activate(bg)) + bytenr = 0; + btrfs_put_block_group(bg); + } + } + +out: + fs_info->data_reloc_bg = bytenr; +} diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index 77c4321e331f..048ffada4549 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -97,6 +97,7 @@ int btrfs_zone_finish_one_bg(struct btrfs_fs_info *fs_info); int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info, struct btrfs_space_info *space_info, bool do_finish); void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info); +void btrfs_reserve_relocation_zone(struct btrfs_fs_info *fs_info); #else /* CONFIG_BLK_DEV_ZONED */ static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos, struct blk_zone *zone) @@ -271,6 +272,8 @@ static inline int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info, static inline void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info) { } +static inline void btrfs_reserve_relocation_zone(struct btrfs_fs_info *fs_info) { } + #endif static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) -- 2.35.3