From patchwork Thu Dec 5 07:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894810 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF72D1C07C0 for ; Thu, 5 Dec 2024 07:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385027; cv=none; b=bfqv+kNIlpWnlGQ35Ihy6zNkqLYk/v8+61FLNHfodszTMhJarhi6Y4d5mfToVg4Vd7OEwMyZ8GX23l2zNxiEIRdI3mpCgq6GF8iB2aV4Ivl/NI4hEBrvrAYJzyhtRXthCX8HiwqBzJPvcE4lA7/prEFD9/T4a7v2KmEHUIja0LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385027; c=relaxed/simple; bh=YjjDeHf+w8o96lOUWoaiRELiQqsiRMvqrYboslEmP1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sAXqyI6Bsfz7dW13FpqddO/LsmeTHhNqFrJe4ong/dQp11qjiYiloy6bTPB+p47a37l6xb3IxGaxB0nsxAe9X+B2ArC81GTwMmy7lY8ES+d0doYhW/v8L04iQSH5d3x5VgK7hbXZeRai6TrcXqxhzXkzSRRsRJHH4gOUwCYWTQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=qNH+yyTz; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="qNH+yyTz" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385025; x=1764921025; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YjjDeHf+w8o96lOUWoaiRELiQqsiRMvqrYboslEmP1c=; b=qNH+yyTz0q6rx90aqVi5VLOW2k61pLKJYD7tIxCk5IZZXTW3I8NsvEM9 fyhKZgUfZXOoK9tJUfysc68rHM8rnzEl6nh6HqhbSj1qKEeX6K10EjBbQ PbesczejT45GX4uIJSD0hoK5JOnW316fUNRtsS/QD27yBvzKOrjbE0Akh 6jpbY6PeqeyQx4UtcQkd2/zeIbILXgpA6qeWuErUDWqoYRLNQFvtddCqk Quyb4x1f27jx27fMfsDhDpAm++EjJ33W6NyTk3dgtKTWz+rBgPdhjkXOm l5uJ8YHyxXDRmO9oIWEv3UdspN8wheb8b7eSJ1xOh6wBXSwKnwDof7+IA w==; X-CSE-ConnectionGUID: ongSMWW2SrCd63shs5xAlQ== X-CSE-MsgGUID: /vRgEzn7TP2yss9gaWdchw== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626100" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:16 +0800 IronPort-SDR: 67514c57_6LA2j008VhpWlEq7qvSByj57VIpBlx0DfUTgO0hwWHW2peK h1KnLX4nc9mfdyoLJ1CsPHKYXlV/bFgEU5qRFQA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:47 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:16 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 01/11] btrfs: take btrfs_space_info in btrfs_reserve_data_bytes Date: Thu, 5 Dec 2024 16:48:17 +0900 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Take struct btrfs_space_info in btrfs_reserve_data_bytes() to allow reserving the data from multiple data space_info candidates. This is a preparation for the following commits and there is no functional change. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/delalloc-space.c | 4 ++-- fs/btrfs/space-info.c | 10 +++++----- fs/btrfs/space-info.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c index 88e900e5a43d..e9750f96f86c 100644 --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -123,7 +123,7 @@ int btrfs_alloc_data_chunk_ondemand(const struct btrfs_inode *inode, u64 bytes) if (btrfs_is_free_space_inode(inode)) flush = BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE; - return btrfs_reserve_data_bytes(fs_info, bytes, flush); + return btrfs_reserve_data_bytes(fs_info->data_sinfo, bytes, flush); } int btrfs_check_data_free_space(struct btrfs_inode *inode, @@ -144,7 +144,7 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode, else if (btrfs_is_free_space_inode(inode)) flush = BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE; - ret = btrfs_reserve_data_bytes(fs_info, len, flush); + ret = btrfs_reserve_data_bytes(fs_info->data_sinfo, len, flush); if (ret < 0) return ret; diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index a341d087567a..2c07871480b6 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1836,10 +1836,10 @@ int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info, * This will reserve bytes from the data space info. If there is not enough * space then we will attempt to flush space as specified by flush. */ -int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes, +int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes, enum btrfs_reserve_flush_enum flush) { - struct btrfs_space_info *data_sinfo = fs_info->data_sinfo; + struct btrfs_fs_info *fs_info = space_info->fs_info; int ret; ASSERT(flush == BTRFS_RESERVE_FLUSH_DATA || @@ -1847,12 +1847,12 @@ int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes, flush == BTRFS_RESERVE_NO_FLUSH); ASSERT(!current->journal_info || flush != BTRFS_RESERVE_FLUSH_DATA); - ret = __reserve_bytes(fs_info, data_sinfo, bytes, flush); + ret = __reserve_bytes(fs_info, space_info, bytes, flush); if (ret == -ENOSPC) { trace_btrfs_space_reservation(fs_info, "space_info:enospc", - data_sinfo->flags, bytes, 1); + space_info->flags, bytes, 1); if (btrfs_test_opt(fs_info, ENOSPC_DEBUG)) - btrfs_dump_space_info(fs_info, data_sinfo, bytes, 0); + btrfs_dump_space_info(fs_info, space_info, bytes, 0); } return ret; } diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index a96efdb5e681..7459b4eb99cd 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -288,7 +288,7 @@ static inline void btrfs_space_info_free_bytes_may_use( btrfs_try_granting_tickets(space_info->fs_info, space_info); spin_unlock(&space_info->lock); } -int btrfs_reserve_data_bytes(struct btrfs_fs_info *fs_info, u64 bytes, +int btrfs_reserve_data_bytes(struct btrfs_space_info *space_info, u64 bytes, enum btrfs_reserve_flush_enum flush); void btrfs_dump_space_info_for_trans_abort(struct btrfs_fs_info *fs_info); void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info); From patchwork Thu Dec 5 07:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894811 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 682721C3BEF for ; Thu, 5 Dec 2024 07:50:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385029; cv=none; b=GL3sV+IPi0mk59ZE4pY4fLUrtwypc3GsP54uEEMAqhbOTFJwRA/lUQgLhaX/4WlKKiTpNVwi1xKmSOI2nNwO41wQHp9uPd+0Rd+xro1HL9XnAkLNuNUGgQVn+00lTPX0OY7RElakTtlEOlLoeWznKE7uMUatBvhb1j3m/vDucxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385029; c=relaxed/simple; bh=JZ6gIsb/gUBOJXCjjL+njWjuSlcmCFqNY2hYIXXCUBs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XosLleDlfc/70nzDlnLyy6djA5lToy9/oq0GhvLubajh66m8+6MKroVcK9HUGrkVQRfs/iRswo5Zjs3SeP/k3I32s0h9nSc+PJ6ajNro2ZVqvwxQl3CLw6W7iqdM3z6xU9RS6A9DRcPFCsWZ0feTZL/iYKDW9sTFZDv/2c4yJ2o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=LmNezw+N; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="LmNezw+N" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385027; x=1764921027; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JZ6gIsb/gUBOJXCjjL+njWjuSlcmCFqNY2hYIXXCUBs=; b=LmNezw+NtYVVsEOHa6cHynSvXOiKLbn1AIWHEwAaYdR2b39miopTdaY3 9F+xaHmbZhyaICKN4pFUzpCgLTVwSM9SrT7+XJgEexhUhgYB98rqlfgRk 5QdZrJ5gROxpRBLTkMfmpsRnyVwXJSsX3r+kBWr+n2Dh3vFExOK7pyBUr GXswqZiNd2fSu5NaVUv4PPtifOk05Qf0UQLwKHy9QQDaA6kdLQtn5IYh/ EUv6OaRQRWA00vvBRrrAi5UyszT3D6T+Cq0KVZCK+kPf6JrPvN+s+1w1W B+NgwoTcv2G/5Ap207qjRjLRiMgk3yJN9GIgRnL774qG5UMrQLpPX/inP g==; X-CSE-ConnectionGUID: fONgq3zEQCCvihJpmjCK/w== X-CSE-MsgGUID: HDtVRW9WT6uMcKuitfrPxg== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626104" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:17 +0800 IronPort-SDR: 67514c58_6xYeuVneTnExcf4HDWrP6xuaLKihg4cQ5cdtYVSSZBNrB2u KqjVqqfMr+oOma8fzlMY/4tOJuWXbI4EyYmpCLw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:48 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:17 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 02/11] btrfs: take struct btrfs_inode in btrfs_free_reserved_data_space_noquota Date: Thu, 5 Dec 2024 16:48:18 +0900 Message-ID: <49c05fff4552b688e962e540328d2631b4814d63.1733384171.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 As well as the last patch, take struct btrfs_inode in the function and let it distinguish which data space it is working on in a later patch. There is no functional change with this commit. Signed-off-by: Naohiro Aota Reviewed-by: Johannes Thumshirn --- fs/btrfs/delalloc-space.c | 7 ++++--- fs/btrfs/delalloc-space.h | 3 +-- fs/btrfs/inode.c | 4 ++-- fs/btrfs/relocation.c | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c index e9750f96f86c..918ba2ab1d5f 100644 --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -151,7 +151,7 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode, /* Use new btrfs_qgroup_reserve_data to reserve precious data space. */ ret = btrfs_qgroup_reserve_data(inode, reserved, start, len); if (ret < 0) { - btrfs_free_reserved_data_space_noquota(fs_info, len); + btrfs_free_reserved_data_space_noquota(inode, len); extent_changeset_free(*reserved); *reserved = NULL; } else { @@ -168,9 +168,10 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode, * which we can't sleep and is sure it won't affect qgroup reserved space. * Like clear_bit_hook(). */ -void btrfs_free_reserved_data_space_noquota(struct btrfs_fs_info *fs_info, +void btrfs_free_reserved_data_space_noquota(struct btrfs_inode *inode, u64 len) { + struct btrfs_fs_info *fs_info = inode->root->fs_info; struct btrfs_space_info *data_sinfo; ASSERT(IS_ALIGNED(len, fs_info->sectorsize)); @@ -196,7 +197,7 @@ void btrfs_free_reserved_data_space(struct btrfs_inode *inode, round_down(start, fs_info->sectorsize); start = round_down(start, fs_info->sectorsize); - btrfs_free_reserved_data_space_noquota(fs_info, len); + btrfs_free_reserved_data_space_noquota(inode, len); btrfs_qgroup_free_data(inode, reserved, start, len, NULL); } diff --git a/fs/btrfs/delalloc-space.h b/fs/btrfs/delalloc-space.h index 3f32953c0a80..d582779dac5a 100644 --- a/fs/btrfs/delalloc-space.h +++ b/fs/btrfs/delalloc-space.h @@ -18,8 +18,7 @@ void btrfs_free_reserved_data_space(struct btrfs_inode *inode, void btrfs_delalloc_release_space(struct btrfs_inode *inode, struct extent_changeset *reserved, u64 start, u64 len, bool qgroup_free); -void btrfs_free_reserved_data_space_noquota(struct btrfs_fs_info *fs_info, - u64 len); +void btrfs_free_reserved_data_space_noquota(struct btrfs_inode *inode, u64 len); void btrfs_delalloc_release_metadata(struct btrfs_inode *inode, u64 num_bytes, bool qgroup_free); int btrfs_delalloc_reserve_space(struct btrfs_inode *inode, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c4997200dbb2..e553264eaa0f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2556,7 +2556,7 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, !btrfs_is_free_space_inode(inode) && !(state->state & EXTENT_NORESERVE) && (bits & EXTENT_CLEAR_DATA_RESV)) - btrfs_free_reserved_data_space_noquota(fs_info, len); + btrfs_free_reserved_data_space_noquota(inode, len); percpu_counter_add_batch(&fs_info->delalloc_bytes, -len, fs_info->delalloc_batch); @@ -9644,7 +9644,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, * bytes_may_use. */ if (!extent_reserved) - btrfs_free_reserved_data_space_noquota(fs_info, disk_num_bytes); + btrfs_free_reserved_data_space_noquota(inode, disk_num_bytes); out_unlock: unlock_extent(io_tree, start, end, &cached_state); out_folios: diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index bf267bdfa8f8..d60e118e88a3 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -2828,8 +2828,7 @@ static noinline_for_stack int prealloc_file_extent_cluster(struct reloc_control btrfs_inode_unlock(inode, 0); if (cur_offset < prealloc_end) - btrfs_free_reserved_data_space_noquota(inode->root->fs_info, - prealloc_end + 1 - cur_offset); + btrfs_free_reserved_data_space_noquota(inode, prealloc_end + 1 - cur_offset); return ret; } From patchwork Thu Dec 5 07:48:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894812 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D55811C3F0E for ; Thu, 5 Dec 2024 07:50:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385029; cv=none; b=iIbsAycqKvqCC81SDiCvob7WCqkJpsvSxniHMoo2tKMsPaHoOqH0ylve+7PtbKUubTey7kTi07QjFi+jb5NfLPymJgH5VYUqexQy1ZBwFY5jR3IkLh8By1CGmKUcJA7NJmlHjxD/X+P1Wy3A3ZWOW1QepobtvUgV25wV288jY7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385029; c=relaxed/simple; bh=5pIbaYCfT7dLhEaTKxPPX3lrT2IKE6rJS8dQpQ8ji3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJD0cgY6dJXn/BAfR6BEtuojJaBU0Jm/R3tquBL5qwtEJqy1o9GwCsY3AntN+rUazjReCor8/KWxnMoLiuKphMk21G4yn8ikhr5JEaRdvQcKllS+fKK8b1oE9A5X8GUvXRHO5RyPjnzlVoJY8sAxCvETWBxdGlUOElMzl/hMFNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Lmb1jlxE; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Lmb1jlxE" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385027; x=1764921027; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5pIbaYCfT7dLhEaTKxPPX3lrT2IKE6rJS8dQpQ8ji3A=; b=Lmb1jlxEHW3X7me9CcntqT8pDhpU1FG2WFwcAT96SgUEnoQpP16IinqF YS+734h/eFlRhlC9KWSrie01a+QdIgrJmpfUsx68QqC5CVGzPqMLoCTag lEcMf0gxCTVPjRnBqPyccxNsBd5JAzjF1qTMeXg6FIX72A+6qWkdX2/eL NynjtQdLC6dUqq4RDBBMQ+QsyHdbEzj0F5mlJ9CWdYnrkntnJLmns27n4 ViMYJlvVVEIBf7gRzny+Tu116W4IEqdmQZcV3ZxSs3k0c/jkBmWcglwvn TvYipDZq8P+IYXYj+TITHlmen6IS4VYRCSmyOYOh3Zvq/+uQLk3AUmArg w==; X-CSE-ConnectionGUID: ld71wB4jSPKHzHvBCLZbhQ== X-CSE-MsgGUID: 2LbYQrqKR9CaoIydna+WQw== X-Ironport-Invalid-End-Of-Message: True X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626107" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:18 +0800 IronPort-SDR: 67514c59_ASG92JhxIOUYJb8HgXh9dNOtoDn1RU9mOc2T3O1nqI0YwRg sixucwD8a5lDs63wgS1+ynHUST4shSGaxj8eqQw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:49 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:18 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 03/11] btrfs: factor out init_space_info() Date: Thu, 5 Dec 2024 16:48:19 +0900 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Factor out initialization of the space_info struct, which is used in a later patch. There is no functional change. Signed-off-by: Naohiro Aota --- fs/btrfs/space-info.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 2c07871480b6..782807c926e1 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -234,19 +234,11 @@ void btrfs_update_space_info_chunk_size(struct btrfs_space_info *space_info, WRITE_ONCE(space_info->chunk_size, chunk_size); } -static int create_space_info(struct btrfs_fs_info *info, u64 flags) +static void init_space_info(struct btrfs_fs_info *info, + struct btrfs_space_info *space_info, u64 flags) { - - struct btrfs_space_info *space_info; - int i; - int ret; - - space_info = kzalloc(sizeof(*space_info), GFP_NOFS); - if (!space_info) - return -ENOMEM; - space_info->fs_info = info; - for (i = 0; i < BTRFS_NR_RAID_TYPES; i++) + for (int i = 0; i < BTRFS_NR_RAID_TYPES; i++) INIT_LIST_HEAD(&space_info->block_groups[i]); init_rwsem(&space_info->groups_sem); spin_lock_init(&space_info->lock); @@ -260,6 +252,19 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) if (btrfs_is_zoned(info)) space_info->bg_reclaim_threshold = BTRFS_DEFAULT_ZONED_RECLAIM_THRESH; +} + +static int create_space_info(struct btrfs_fs_info *info, u64 flags) +{ + + struct btrfs_space_info *space_info; + int ret; + + space_info = kzalloc(sizeof(*space_info), GFP_NOFS); + if (!space_info) + return -ENOMEM; + + init_space_info(info, space_info, flags); ret = btrfs_sysfs_add_space_info_type(info, space_info); if (ret) From patchwork Thu Dec 5 07:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894813 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32E451C07C0 for ; Thu, 5 Dec 2024 07:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385030; cv=none; b=llDg6EdY06PJwbAx6Q0/7CnfGcmnBIxsWw9DXUD4HUcTuedDAyOFSYNH+RS6+vOlSpHG2xFhcxjcZo0srerEyT53vxcP6qDNZ6n11i/d7YgwTYADo/3JR0cM93C/k4Fg8VyBmoEIZcyT4aPfTU0uT4iDZFOsRFCmlJwJ1y8PPFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385030; c=relaxed/simple; bh=O24tceXdPH9SXIYhNagjzLySpjXnqbkC2A8hCZkz0PA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dg0A/7lsLYjxrbAGo1qYUN+bI2FyzxlBqDxNTAZIRxmJ9QFWasaSEU7PlPhFXE6+DCMbWvhRz2Cq7YRj0hgX2Z97Fwc39NHnMDzoTNTv45B64X4t00dIQaYzlQ75Cm/GUvRpk/bhLLvyIYTIu4K7B0zntl9eQVDJkoBMcg7Ftt8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Jnj3Ar8+; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Jnj3Ar8+" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385028; x=1764921028; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=O24tceXdPH9SXIYhNagjzLySpjXnqbkC2A8hCZkz0PA=; b=Jnj3Ar8+r4VoLZirrM7Vqn2Kged86mZjUEMAH0WFwk0qrzdUXV5lRj5p 4Kb/s9mtoR1kL1aSFpMAx4JYQcFuIU/JTGlINGTvm22poYukQFfxbr5Mw u+7d40ZdQR7KcOT4CVIPeZXprEzPBWLNFlZH7f4YsFvrRTKXAmebHN/T8 HNAYDCHRQ+00iNG/efgXD6xVzXkhAfIGxTsI74bXmda6qrSjlgvTq+rZr chOz8sB9bZC9L1UkX94kSjlbPsg5zhuRkJ6ItJU6qt+Vwm/Iqilwoq1cU d/vsbK0sCRXiwb2MIe3st5fd397tz7oCrU8qx6w7s2EkjBQz1r/n5BFUw w==; X-CSE-ConnectionGUID: DBkW6k2dS+KsDAc6SMq0fw== X-CSE-MsgGUID: 3jE7qvjZSaGLzF13y6eUgA== X-Ironport-Invalid-End-Of-Message: True X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626110" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:19 +0800 IronPort-SDR: 67514c59_hylhd4/iaGsQFhUo2o+iBt5k9CdSZcLWSMe9ZVWt2dHcxEt /stZMsoiqToRCBsFJ6lQUkQiWFiitBOeYUhayrw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:49 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:19 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 04/11] btrfs: spin out do_async_reclaim_data_space() Date: Thu, 5 Dec 2024 16:48:20 +0900 Message-ID: <6d7d620adf02ddf7245c991cd74696633cc279d3.1733384171.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Factor out the main part of btrfs_async_reclaim_data_space() to do_async_reclaim_data_space(), so it can take data space_info parameter it is working on. There is no functional change. Signed-off-by: Naohiro Aota --- fs/btrfs/space-info.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 782807c926e1..1fb55655f49d 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1323,16 +1323,12 @@ static const enum btrfs_flush_state data_flush_states[] = { ALLOC_CHUNK_FORCE, }; -static void btrfs_async_reclaim_data_space(struct work_struct *work) +static void do_async_reclaim_data_space(struct btrfs_space_info *space_info) { - struct btrfs_fs_info *fs_info; - struct btrfs_space_info *space_info; + struct btrfs_fs_info *fs_info = space_info->fs_info; u64 last_tickets_id; enum btrfs_flush_state flush_state = 0; - fs_info = container_of(work, struct btrfs_fs_info, async_data_reclaim_work); - space_info = fs_info->data_sinfo; - spin_lock(&space_info->lock); if (list_empty(&space_info->tickets)) { space_info->flush = 0; @@ -1400,6 +1396,16 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work) spin_unlock(&space_info->lock); } +static void btrfs_async_reclaim_data_space(struct work_struct *work) +{ + struct btrfs_fs_info *fs_info; + struct btrfs_space_info *space_info; + + fs_info = container_of(work, struct btrfs_fs_info, async_data_reclaim_work); + space_info = fs_info->data_sinfo; + do_async_reclaim_data_space(space_info); +} + void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info) { INIT_WORK(&fs_info->async_reclaim_work, btrfs_async_reclaim_metadata_space); From patchwork Thu Dec 5 07:48:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894814 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 793271C4A07 for ; Thu, 5 Dec 2024 07:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385031; cv=none; b=eb60Du6gbzdPdnaRCNZFINZ3ygyjL3PxiAKfBl1dj11OJVw6jBdQGV7SVCYbU59HW3nSrpvhSnG4RExd4AgEnA3jESdeKOF7UtmfHULtk1eeSyqsKEAImlh3mS5cVvDUKohNScSFB+G+yaEJ8Svn8P2YEdMnldtnXnQbaIez8Kc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385031; c=relaxed/simple; bh=lZ+yT6pwbh23dlNXWUiG5N2+oMNnGGtMCFbEkWjS5Nc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RRkjcqDF9rrAG7RBbIsxSumzTOS1uz4RkjamYcEa+f8UoacZT+JWF8Q2V8wasmh5Eg0AaHxmjsxkp/rEbzkT6Vd8RtcKPvok0Drj4NeiA1KQ9xAf1YlMfYlUZH/jOqhiyUfFmMB+I97J1/7JxdNqpaLcl4Pi7ohBDCpp3YyPBvw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=BLwtlqru; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="BLwtlqru" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385029; x=1764921029; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lZ+yT6pwbh23dlNXWUiG5N2+oMNnGGtMCFbEkWjS5Nc=; b=BLwtlqrukwlTWo6367MsHC7g4umzKYIVa+8IaoD+kip7TyJygsG+wbjw fgwbSZ8ojSwSjbSuGkDkYA87MIyisOGB/0lANWEmSH7SE9rzGdOMSsfoZ zZTE/0CnO1ZcA5w0LAsJ4sRHIgpoenbTmgUVsJ4BSxKAO0sZjPydJoQqq SA8Y/cZIiKgfKDx1AV68A9B4ZcmAGyKRswHImTDnwNBAKqcAEcdMamp6q GtOBRJBg7u01scjJeyFhXy02NeY8n3M3lxzJMAaXXfB28qDEZUcEYICaw DxdkpoS2n3iRlKWJO1+IWUDsZJt7eNsodKZUdnLO7SlJqIYZv+2LH4Brm Q==; X-CSE-ConnectionGUID: lRBe0N3cQvKqebC+neTuaQ== X-CSE-MsgGUID: g9aKElVhSWqKVZy3LzG7Jg== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626111" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:19 +0800 IronPort-SDR: 67514c5a_xgmzIVUvNaPkyC0XBGeNU3OwuiNjzjHXTdpc4McoJokYEEI 0KxWYaBMJGGU0kuk/d+B32of/xaq5L98QSPO9UA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:50 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:20 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 05/11] btrfs: factor out check_removing_space_info() Date: Thu, 5 Dec 2024 16:48:21 +0900 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Factor out check_removing_space_info() from btrfs_free_block_groups(). It sanity checks a to-be-removed space_info. There is no functional change. --- fs/btrfs/block-group.c | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 5be029734cfa..4b8071a8d795 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -4371,6 +4371,34 @@ void btrfs_put_block_group_cache(struct btrfs_fs_info *info) } } +static void check_removing_space_info(struct btrfs_space_info *space_info) +{ + struct btrfs_fs_info *info = space_info->fs_info; + + /* + * Do not hide this behind enospc_debug, this is actually + * important and indicates a real bug if this happens. + */ + if (WARN_ON(space_info->bytes_pinned > 0 || + space_info->bytes_may_use > 0)) + btrfs_dump_space_info(info, space_info, 0, 0); + + /* + * If there was a failure to cleanup a log tree, very likely due + * to an IO failure on a writeback attempt of one or more of its + * extent buffers, we could not do proper (and cheap) unaccounting + * of their reserved space, so don't warn on bytes_reserved > 0 in + * that case. + */ + if (!(space_info->flags & BTRFS_BLOCK_GROUP_METADATA) || + !BTRFS_FS_LOG_CLEANUP_ERROR(info)) { + if (WARN_ON(space_info->bytes_reserved > 0)) + btrfs_dump_space_info(info, space_info, 0, 0); + } + + WARN_ON(space_info->reclaim_size > 0); +} + /* * Must be called only after stopping all workers, since we could have block * group caching kthreads running, and therefore they could race with us if we @@ -4472,28 +4500,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) struct btrfs_space_info, list); - /* - * Do not hide this behind enospc_debug, this is actually - * important and indicates a real bug if this happens. - */ - if (WARN_ON(space_info->bytes_pinned > 0 || - space_info->bytes_may_use > 0)) - btrfs_dump_space_info(info, space_info, 0, 0); - - /* - * If there was a failure to cleanup a log tree, very likely due - * to an IO failure on a writeback attempt of one or more of its - * extent buffers, we could not do proper (and cheap) unaccounting - * of their reserved space, so don't warn on bytes_reserved > 0 in - * that case. - */ - if (!(space_info->flags & BTRFS_BLOCK_GROUP_METADATA) || - !BTRFS_FS_LOG_CLEANUP_ERROR(info)) { - if (WARN_ON(space_info->bytes_reserved > 0)) - btrfs_dump_space_info(info, space_info, 0, 0); - } - - WARN_ON(space_info->reclaim_size > 0); + check_removing_space_info(space_info); list_del(&space_info->list); btrfs_sysfs_remove_space_info(space_info); } From patchwork Thu Dec 5 07:48:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894815 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E4FE1C4A13 for ; Thu, 5 Dec 2024 07:50:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385031; cv=none; b=IRs6qjO2R3pdcYCWKf21rEXFvfO1JjGQJX2BREOiJO+uRCqoeDWRVBGdTqeLQwUum+kOQ3wFHL6sKMAarbQtRgcVnF9hSYYElc5VKFYiYG0Ou4JMCM17fP5z4NEiyMke2swaEbjP/AynHcV4zldxSoY0GjhXn2ayG8C1wnNcRMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733385031; c=relaxed/simple; bh=VhoQsMWSlMKsnY+HDBm6j7DjgomzY8oFLNxDxXaiyN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DLCXxL7aE8f6Ux4/n0f8tZXMfxpCzptaI31cwMMuWTr8ACiCylZ37kSyaxQ9dZilAemzAraAQOjfa5VdNIj8u6ehjmM6qC6rtC7t98EuXMjr5yf9nITUdTZ2TxiTxD9GY4GRc5FA+w0HkbI7/qy7hm0K3jFurPX8oahxSV5UKv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=YBMTzkml; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="YBMTzkml" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733385029; x=1764921029; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VhoQsMWSlMKsnY+HDBm6j7DjgomzY8oFLNxDxXaiyN4=; b=YBMTzkmlMKskNLKv002UqWl3VyoIEAnjSGJwmarlWJ19ZmLiS1XjY5XF D/CDppArFfyOnBZSNmp1F2flKBMkM21j+Wv89eYNY6ypBUbeC5k3LzyN1 KhESAsZR1TyrjgMoMGnXwMA7h2bGtYBCIGz07GyEVkoJrzz5FmJaCb1Mx hqqRosVTTV6LgREYUy32/S62VVYSM5u5OzjAQdA9mrg8AhqvKrzT/ydT7 vHVQsB8n3eSLEhImlept0HrFabLUCSKd5jDUTwxqGo0BKfwn2/VPv2pFh MWjNZButa/zEUrezLR0zklRfzGRjD9+lfjerSOSu9Rnt8R4/VHvNtnTNx Q==; X-CSE-ConnectionGUID: 9W8coqWGRXuQEuONhddNYg== X-CSE-MsgGUID: KdsZel5hQqaPy0RR7/u/Dg== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626112" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:20 +0800 IronPort-SDR: 67514c5b_qdirNMJa/HPXO+eO/cnOrfq8sW0bOObqcf3GF037uqyOeGg TU9YVeT+4uIxF3GYpt6XFbC3Czz+IIFWhODnNVQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:51 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:20 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 06/11] btrfs: introduce space_info argument to btrfs_chunk_alloc Date: Thu, 5 Dec 2024 16:48:22 +0900 Message-ID: <57f3882377b6783592d3e13ca7c85ac19ac4f71c.1733384171.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Take an optional btrfs_space_info argument in btrfs_chunk_alloc(). If specified, btrfs_chunk_alloc() works on the space_info. If not, the default space_info is used as the same as before. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 19 ++++++++++++------- fs/btrfs/block-group.h | 3 ++- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/space-info.c | 2 +- fs/btrfs/transaction.c | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 4b8071a8d795..ad78c8f1d381 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2985,7 +2985,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, */ alloc_flags = btrfs_get_alloc_profile(fs_info, cache->flags); if (alloc_flags != cache->flags) { - ret = btrfs_chunk_alloc(trans, alloc_flags, + ret = btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE); /* * ENOSPC is allowed here, we may have enough space @@ -3014,7 +3014,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, goto unlock_out; alloc_flags = btrfs_get_alloc_profile(fs_info, cache->space_info->flags); - ret = btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE); + ret = btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE); if (ret < 0) goto out; /* @@ -3870,7 +3870,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type) { u64 alloc_flags = btrfs_get_alloc_profile(trans->fs_info, type); - return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE); + return btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE); } static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags) @@ -4073,12 +4073,15 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans * - return 0 if it doesn't need to allocate a new chunk, * - return 1 if it successfully allocates a chunk, * - return errors including -ENOSPC otherwise. + * + * @space_info can optionally be specified to make a new chunk belong to it. If + * it is NULL, it is set automatically. */ -int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, +int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, + struct btrfs_space_info *space_info, u64 flags, enum btrfs_chunk_alloc_enum force) { struct btrfs_fs_info *fs_info = trans->fs_info; - struct btrfs_space_info *space_info; struct btrfs_block_group *ret_bg; bool wait_for_alloc = false; bool should_alloc = false; @@ -4117,8 +4120,10 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, if (flags & BTRFS_BLOCK_GROUP_SYSTEM) return -ENOSPC; - space_info = btrfs_find_space_info(fs_info, flags); - ASSERT(space_info); + if (!space_info) { + space_info = btrfs_find_space_info(fs_info, flags); + ASSERT(space_info); + } do { spin_lock(&space_info->lock); diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 36937eeab9b8..c01f3af726a1 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -342,7 +342,8 @@ int btrfs_add_reserved_bytes(struct btrfs_block_group *cache, bool force_wrong_size_class); void btrfs_free_reserved_bytes(struct btrfs_block_group *cache, u64 num_bytes, int delalloc); -int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags, +int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, + struct btrfs_space_info *space_info, u64 flags, enum btrfs_chunk_alloc_enum force); int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type); void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2f9126528a01..334a1701ff33 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4118,7 +4118,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info, return ret; } - ret = btrfs_chunk_alloc(trans, ffe_ctl->flags, + ret = btrfs_chunk_alloc(trans, NULL, ffe_ctl->flags, CHUNK_ALLOC_FORCE_FOR_EXTENT); /* Do not bail out on ENOSPC since we can do more. */ diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 1fb55655f49d..1d0f0c9d8956 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -817,7 +817,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, ret = PTR_ERR(trans); break; } - ret = btrfs_chunk_alloc(trans, + ret = btrfs_chunk_alloc(trans, space_info, btrfs_get_alloc_profile(fs_info, space_info->flags), (state == ALLOC_CHUNK) ? CHUNK_ALLOC_NO_FORCE : CHUNK_ALLOC_FORCE); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 15312013f2a3..e5852316f0b6 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -755,7 +755,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, if (do_chunk_alloc && num_bytes) { u64 flags = h->block_rsv->space_info->flags; - btrfs_chunk_alloc(h, btrfs_get_alloc_profile(fs_info, flags), + btrfs_chunk_alloc(h, NULL, btrfs_get_alloc_profile(fs_info, flags), CHUNK_ALLOC_NO_FORCE); } From patchwork Thu Dec 5 07:48:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894805 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76DD51B4F3E for ; Thu, 5 Dec 2024 07:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384966; cv=none; b=oVKUeTZLubRy4Sb/orK5Ruh4QeKUVB5vcVetTmnZJT/LUEhO+u7GKh8RRCbGxddUd6nLjf4NwPrt50Fw+C/cOJgDR5z8ArweM4koYuZIEg2IFE2FjYoGA4HlgQlwLOeKclNb9Egt8Wg5FwOystejWjvo8bl/HdTTIpDWJISI6nM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384966; c=relaxed/simple; bh=gtpFDF7OxtUFik/G4W4FeP4H7ISC29x/D3mxLbq+w1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gjx5YOYmReGJk7ob7WPDZsyczMG722sV3phmWUrkLtw/OFShUmiyiFH9WgWgJnHZU2TgStSvZ905Swd8C4q7phLBvYNY7ApKhale+r0vuB90S5a/6yoPUx9zmlnVt4Wy3q9CM/ABuy+JnBgKZj5eEnCX63a2ePB2mzOShyR4/tI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Wuphavap; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Wuphavap" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733384964; x=1764920964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gtpFDF7OxtUFik/G4W4FeP4H7ISC29x/D3mxLbq+w1w=; b=Wuphavap197WVl1rfCkkyyiJPlwVaEcCYnTYpcQa/EKGr++hA90pNLbp nz18L/z2ANQeONU7PdRz6uEXkj6/EUfOXmdCX/9Fp5UcUc1B3qwzSNgqe 1EPkbBVGPcCqDu9ib0DjHR0ISS8/OoxwsvK6rLkx2MRSVczsMX4r/B585 wQ3QKnFX4D8u0HbmJunbsdGBbBjklnq7szdmTbDTAU23mdzZZ3Ge3LhGf Axbd/YpMkemjr9hy0bhYYvDyl7cnUqkwkU3MUbzwK70oGEZ4zUPbMtWRk K99macYz34GhGwrcDtSMd5aSS8o16f7rbx07ZicHrAhSFmzbDBYhn5Hq/ g==; X-CSE-ConnectionGUID: mWlbXwBRSjWItWx5P+/zDg== X-CSE-MsgGUID: HUpFImBWT8OCyQwkrMhGZQ== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626113" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:21 +0800 IronPort-SDR: 67514c5c_cvAOFmFyYmFbqX/GtG0VlPG96oSHHJyQXH6WenRqngwmRdn VWFxZ3WsKq2thLMOQpe6xJoKFSsDEuYyQzi+BRA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:52 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:21 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 07/11] btrfs: pass space_info for block group creation Date: Thu, 5 Dec 2024 16:48:23 +0900 Message-ID: <127cf9ae217dd4ac2ce651317fccf6923dd765a9.1733384171.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add btrfs_space_info parameter to btrfs_make_block_group(), its related functions and related struct. Passed space_info will have a new block group. If NULL is passed, it uses the default space_info. The parameter is used in a later commit and the behavior is unchanged now. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 15 ++++++++------- fs/btrfs/block-group.h | 2 +- fs/btrfs/volumes.c | 16 +++++++++++----- fs/btrfs/volumes.h | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index ad78c8f1d381..6787f7034b9e 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2833,7 +2833,7 @@ static u64 calculate_global_root_id(const struct btrfs_fs_info *fs_info, u64 off } struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans, - u64 type, + struct btrfs_space_info *space_info, u64 type, u64 chunk_offset, u64 size) { struct btrfs_fs_info *fs_info = trans->fs_info; @@ -2888,7 +2888,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran * assigned to our block group. We want our bg to be added to the rbtree * with its ->space_info set. */ - cache->space_info = btrfs_find_space_info(fs_info, cache->flags); + cache->space_info = space_info; ASSERT(cache->space_info); ret = btrfs_add_block_group_cache(fs_info, cache); @@ -3873,7 +3873,8 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type) return btrfs_chunk_alloc(trans, NULL, alloc_flags, CHUNK_ALLOC_FORCE); } -static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags) +static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, + struct btrfs_space_info *space_info, u64 flags) { struct btrfs_block_group *bg; int ret; @@ -3886,7 +3887,7 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans */ check_system_chunk(trans, flags); - bg = btrfs_create_chunk(trans, flags); + bg = btrfs_create_chunk(trans, space_info, flags); if (IS_ERR(bg)) { ret = PTR_ERR(bg); goto out; @@ -3935,7 +3936,7 @@ static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans const u64 sys_flags = btrfs_system_alloc_profile(trans->fs_info); struct btrfs_block_group *sys_bg; - sys_bg = btrfs_create_chunk(trans, sys_flags); + sys_bg = btrfs_create_chunk(trans, NULL, sys_flags); if (IS_ERR(sys_bg)) { ret = PTR_ERR(sys_bg); btrfs_abort_transaction(trans, ret); @@ -4185,7 +4186,7 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, force_metadata_allocation(fs_info); } - ret_bg = do_chunk_alloc(trans, flags); + ret_bg = do_chunk_alloc(trans, space_info, flags); trans->allocating_chunk = false; if (IS_ERR(ret_bg)) { @@ -4268,7 +4269,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans, * the paths we visit in the chunk tree (they were already COWed * or created in the current transaction for example). */ - bg = btrfs_create_chunk(trans, flags); + bg = btrfs_create_chunk(trans, NULL, flags); if (IS_ERR(bg)) { ret = PTR_ERR(bg); } else { diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index c01f3af726a1..cb9b0405172c 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -326,7 +326,7 @@ void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info); void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg); int btrfs_read_block_groups(struct btrfs_fs_info *info); struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans, - u64 type, + struct btrfs_space_info *space_info, u64 type, u64 chunk_offset, u64 size); void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans); int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 1cccaf9c2b0d..d1f3068377aa 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3403,7 +3403,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset) const u64 sys_flags = btrfs_system_alloc_profile(fs_info); struct btrfs_block_group *sys_bg; - sys_bg = btrfs_create_chunk(trans, sys_flags); + sys_bg = btrfs_create_chunk(trans, NULL, sys_flags); if (IS_ERR(sys_bg)) { ret = PTR_ERR(sys_bg); btrfs_abort_transaction(trans, ret); @@ -5202,6 +5202,8 @@ struct alloc_chunk_ctl { u64 stripe_size; u64 chunk_size; int ndevs; + /* Space_info the block group is going to belong. */ + struct btrfs_space_info *space_info; }; static void init_alloc_chunk_ctl_policy_regular( @@ -5603,7 +5605,7 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans, return ERR_PTR(ret); } - block_group = btrfs_make_block_group(trans, type, start, ctl->chunk_size); + block_group = btrfs_make_block_group(trans, ctl->space_info, type, start, ctl->chunk_size); if (IS_ERR(block_group)) { btrfs_remove_chunk_map(info, map); return block_group; @@ -5629,7 +5631,7 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans, } struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, - u64 type) + struct btrfs_space_info *space_info, u64 type) { struct btrfs_fs_info *info = trans->fs_info; struct btrfs_fs_devices *fs_devices = info->fs_devices; @@ -5657,8 +5659,12 @@ struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, return ERR_PTR(-EINVAL); } + if (!space_info) + space_info = btrfs_find_space_info(info, type); + ASSERT(space_info); ctl.start = find_next_chunk(info); ctl.type = type; + ctl.space_info = space_info; init_alloc_chunk_ctl(fs_devices, &ctl); devices_info = kcalloc(fs_devices->rw_devices, sizeof(*devices_info), @@ -5826,12 +5832,12 @@ static noinline int init_first_rw_device(struct btrfs_trans_handle *trans) */ alloc_profile = btrfs_metadata_alloc_profile(fs_info); - meta_bg = btrfs_create_chunk(trans, alloc_profile); + meta_bg = btrfs_create_chunk(trans, NULL, alloc_profile); if (IS_ERR(meta_bg)) return PTR_ERR(meta_bg); alloc_profile = btrfs_system_alloc_profile(fs_info); - sys_bg = btrfs_create_chunk(trans, alloc_profile); + sys_bg = btrfs_create_chunk(trans, NULL, alloc_profile); if (IS_ERR(sys_bg)) return PTR_ERR(sys_bg); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 3a416b1bc24c..2faee2d2e584 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -690,7 +690,7 @@ struct btrfs_discard_stripe *btrfs_map_discard(struct btrfs_fs_info *fs_info, int btrfs_read_sys_array(struct btrfs_fs_info *fs_info); int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info); struct btrfs_block_group *btrfs_create_chunk(struct btrfs_trans_handle *trans, - u64 type); + struct btrfs_space_info *space_info, u64 type); void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info); int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, blk_mode_t flags, void *holder); From patchwork Thu Dec 5 07:48:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894804 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76D831AB517 for ; Thu, 5 Dec 2024 07:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384966; cv=none; b=g6+NV1+NX6Mr2EZAOMzzBtULRyC94PGP74gvNBDCN+Zxj2GtQ0eCKStR5Kt0RZUv3bCr5IAX1DaL1n8GKpxNsRRi8ONYvFtQmIxn/GyT7SQ2bPb1Ic8TVIXYagb+EJLaYft2Kz0fa9OVNJKLiI1HOdFBH+O243qHVZOLJCoX7KQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384966; c=relaxed/simple; bh=0W3hrWB/Irav8nhuGzm/DQC/6Ab9jzUquKNv08/4ztk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DSO22eiSkdJ6YIC2qUN0jhpi562wfn+MXy8ncpfDCGqBQya2E2GMTk8OK9q5riYTc4jujuJK8JWL6q4sdBhoJXHxxm9JOn5PFixmSFi/FEJB72qprTrpGBlp/i5GxwldPe2tfOPK4kCV/aG/jAQNegONQtJK76rjmsF1klXBsok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=WGGG/BKC; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="WGGG/BKC" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733384964; x=1764920964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0W3hrWB/Irav8nhuGzm/DQC/6Ab9jzUquKNv08/4ztk=; b=WGGG/BKCWXjH2tYt+FVNzIsBaPY6/EUqDSdJrX3IezB4ydgWqg1H/bjZ fa4JOW66COXsoZM1LdKLHCeBdEWOKHhMwV2CB8hG1lxnllPrfiB6aJBFC I1CL8rl+Z2E0Gvfq1BttKlIAZtNwVLJXJu5fwDuILK8QXWabZkn0UDqNb 7YLFVCrq0+QFTL3VPMGgV8mQyEzwY/41rhBI4fnMCElh6UH4KGJ5zsPxd ocWiksR0oLY/pybKZH9q6bAzNkH8+cPi55slrV32yhs73gzPRIpxm0bqe aJT6r4nT0wcTlpN5s0Z2jd3CS8xVQMzgQ0Xkg45KBA4jQTHQ0+5IIyCtc A==; X-CSE-ConnectionGUID: b73YNZ6DQpC6QHPkQkfqjA== X-CSE-MsgGUID: VwEMmshqTLKjnQVM7cWnfQ== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626117" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:22 +0800 IronPort-SDR: 67514c5d_kd7HbZeenE6h44DccAEH0CdnGrjdJBd3KGS9IHK7wOVZvgI MXime4eq3Dk8su7KYqqb5ZNgyAMNj147v4BEyuQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:53 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:22 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 08/11] btrfs: introduce btrfs_space_info sub-group Date: Thu, 5 Dec 2024 16:48:24 +0900 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Current code assumes we have only one space_info for each block group type (DATA, METADATA, and SYSTEM). We sometime needs multiple space_info to manage special block groups. One example is handling the data relocation block group for the zoned mode. That block group is dedicated for writing relocated data and we cannot allocate any regular extent from that block group, which is implemented in the zoned extent allocator. That block group still belongs to the normal data space_info. So, when all the normal data block groups are full and there are some free space in the dedicated block group, the space_info looks to have some free space, while it cannot allocate normal extent anymore. That results in a strange ENOSPC error. We need to have a space_info for the relocation data block group to represent the situation properly. This commit adds a basic infrastructure for having a "sub-group" of a space_info: creation and removing. A sub-group space_info belongs to one of the primary space_infos and has the same flags as its parent. Currently, the sub-group is only implemented for the relocation data space_info. In the future, we can also implement the space_info for the tree-log block group. Or, it could be useful to implement tiered storage for btrfs e.g, by implementing a sub-group space_info for block groups resides on a fast storage. Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 6 ++++++ fs/btrfs/space-info.c | 20 ++++++++++++++++++-- fs/btrfs/space-info.h | 8 ++++++++ fs/btrfs/sysfs.c | 16 +++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 6787f7034b9e..aa35b62e9773 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -4506,6 +4506,12 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info) struct btrfs_space_info, list); + for (int i = 0; i < BTRFS_SPACE_INFO_SUB_GROUP_MAX; i++) { + if (space_info->sub_group[i]) { + check_removing_space_info(space_info->sub_group[i]); + kfree(space_info->sub_group[i]); + } + } check_removing_space_info(space_info); list_del(&space_info->list); btrfs_sysfs_remove_space_info(space_info); diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 1d0f0c9d8956..16beb25be4b0 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -249,6 +249,7 @@ static void init_space_info(struct btrfs_fs_info *info, INIT_LIST_HEAD(&space_info->priority_tickets); space_info->clamp = 1; btrfs_update_space_info_chunk_size(space_info, calc_chunk_size(info, flags)); + space_info->subgroup_id = SUB_GROUP_PRIMARY; if (btrfs_is_zoned(info)) space_info->bg_reclaim_threshold = BTRFS_DEFAULT_ZONED_RECLAIM_THRESH; @@ -266,6 +267,20 @@ static int create_space_info(struct btrfs_fs_info *info, u64 flags) init_space_info(info, space_info, flags); + if (btrfs_is_zoned(info) && (flags & BTRFS_BLOCK_GROUP_DATA)) { + struct btrfs_space_info *reloc = kzalloc(sizeof(*reloc), GFP_NOFS); + + if (!reloc) + return -ENOMEM; + init_space_info(info, reloc, flags); + space_info->sub_group[SUB_GROUP_DATA_RELOC] = reloc; + reloc->parent = space_info; + reloc->subgroup_id = SUB_GROUP_DATA_RELOC; + + ret = btrfs_sysfs_add_space_info_type(info, reloc); + ASSERT(!ret); + } + ret = btrfs_sysfs_add_space_info_type(info, space_info); if (ret) return ret; @@ -561,8 +576,9 @@ static void __btrfs_dump_space_info(const struct btrfs_fs_info *fs_info, lockdep_assert_held(&info->lock); /* The free space could be negative in case of overcommit */ - btrfs_info(fs_info, "space_info %s has %lld free, is %sfull", - flag_str, + btrfs_info(fs_info, + "space_info %s (sub-group id %d) has %lld free, is %sfull", + flag_str, info->subgroup_id, (s64)(info->total_bytes - btrfs_space_info_used(info, true)), info->full ? "" : "not "); btrfs_info(fs_info, diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 7459b4eb99cd..64641885babd 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -98,8 +98,16 @@ enum btrfs_flush_state { RESET_ZONES = 12, }; +enum btrfs_space_info_sub_group { + SUB_GROUP_DATA_RELOC = 0, + SUB_GROUP_PRIMARY = -1, +}; +#define BTRFS_SPACE_INFO_SUB_GROUP_MAX 1 struct btrfs_space_info { struct btrfs_fs_info *fs_info; + struct btrfs_space_info *parent; + struct btrfs_space_info *sub_group[BTRFS_SPACE_INFO_SUB_GROUP_MAX]; + int subgroup_id; spinlock_t lock; u64 total_bytes; /* total bytes in the space, diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index fdcbf650ac31..041ffe5e9cc5 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1792,15 +1792,25 @@ void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info) kobject_put(&space_info->kobj); } -static const char *alloc_name(u64 flags) +static const char *alloc_name(struct btrfs_space_info *space_info) { + u64 flags = space_info->flags; + switch (flags) { case BTRFS_BLOCK_GROUP_METADATA | BTRFS_BLOCK_GROUP_DATA: return "mixed"; case BTRFS_BLOCK_GROUP_METADATA: return "metadata"; case BTRFS_BLOCK_GROUP_DATA: - return "data"; + switch (space_info->subgroup_id) { + case SUB_GROUP_PRIMARY: + return "data"; + case SUB_GROUP_DATA_RELOC: + return "data-reloc"; + default: + WARN_ON_ONCE(1); + return "data (unknown sub-group)"; + } case BTRFS_BLOCK_GROUP_SYSTEM: return "system"; default: @@ -1820,7 +1830,7 @@ int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, ret = kobject_init_and_add(&space_info->kobj, &space_info_ktype, fs_info->space_info_kobj, "%s", - alloc_name(space_info->flags)); + alloc_name(space_info)); if (ret) { kobject_put(&space_info->kobj); return ret; From patchwork Thu Dec 5 07:48:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894806 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50BD81917EE for ; Thu, 5 Dec 2024 07:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384967; cv=none; b=ookjk3Pf9qx3qH1/z4thoLeLO3M5GkDFBzZMw8Qt1L3tJjso5ZbkQpaeiL4IEA4XKmKwtztWGTCxfIzFSrNN7kklx4oatx6v+y9UGMDCDm0VP8c3wLgOQdnV01WIuWCSxtXqr6RBFe/jquPP9c88FuAZBJexmyeX35AAObc7x+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384967; c=relaxed/simple; bh=oXKGifZDNTPXMwkxKmhIsPbAT3cxcevpsRdIunfQg4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r0jJSe3Eh4UO1GBR95+35hFPJoFu+izf8c9jHYvnxJXmeoGEyeCSW4V+TabPlB2xbyRO+eYvfc7IhucAko/SbkqkkSZ1+DWP89NWI2seMSlNg5ciEVviwsSLh3JAN2Rkq5Uq3oWVhSmRh/YWBLP1muvPdIGoF1/q8Qb/6Ktd8v0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=q1p4QWr7; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="q1p4QWr7" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733384966; x=1764920966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oXKGifZDNTPXMwkxKmhIsPbAT3cxcevpsRdIunfQg4Q=; b=q1p4QWr7OCnaOj8WjuER3G93lHLFabglat2G9CAiqWSJiiNVMcnQbNF7 tJmzxfZZyaQ0VhtiWfD+o8zcrzLez3VAZPh/0evZzQ0SMrMbAig5oJeo0 rnvQ3iOlff87ZmKDlm3+eNj86iu+8EieIgYRRnBFCJuKKZPn5loO9A3hB uOpyoLRx5qtAzWNA6pK+c09Wp+Cndt+WhsuCL7qNGFb8LYgaZeKkPkxcF AIHSAGdOOUfaBF788qlk9TEiR4YJMSnAvemvcX6amdwN3pH5r7kh4uKNn B3tbtAK/Nja44HblZPM9FmHCLU31E0bQwbGyznHcjslI4IbxwYeKBQixu w==; X-CSE-ConnectionGUID: 4tTk+s1zSoO5VyRNISXJWA== X-CSE-MsgGUID: PLXJEomQTj6grEF5pWDuQg== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626118" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:23 +0800 IronPort-SDR: 67514c5e_/qYJ8XD7Gsh1eaMWkjW6W3FB4w886g2X8VHSs9J4+96IxLy 84FDI2bvegiqgk3AnlCRNnKJSOOAici5+Apr3Jw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:54 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:23 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 09/11] btrfs: tweak extent/chunk allocation for space_info sub-space Date: Thu, 5 Dec 2024 16:48:25 +0900 Message-ID: <8bc8fa625af5d29a6863e3864d5c8b371f913fdc.1733384172.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Make the extent allocator and the chunk allocator aware of the sub-space. It now uses SUB_GROUP_DATA_RELOC sub-space for data relocation block group. And, it needs to check the space_info is the right one when a block group candidate is given. Also, new block group should now belong to the specified one. Signed-off-by: Naohiro Aota --- fs/btrfs/extent-tree.c | 3 +++ fs/btrfs/space-info.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 334a1701ff33..2f32497d2577 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4342,6 +4342,8 @@ static noinline int find_free_extent(struct btrfs_root *root, btrfs_err(fs_info, "No space info for %llu", ffe_ctl->flags); return -ENOSPC; } + if (btrfs_is_zoned(fs_info) && ffe_ctl->for_data_reloc) + space_info = space_info->sub_group[SUB_GROUP_DATA_RELOC]; ret = prepare_allocation(fs_info, ffe_ctl, space_info, ins); if (ret < 0) @@ -4361,6 +4363,7 @@ static noinline int find_free_extent(struct btrfs_root *root, * picked out then we don't care that the block group is cached. */ if (block_group && block_group_bits(block_group, ffe_ctl->flags) && + block_group->space_info == space_info && block_group->cached != BTRFS_CACHE_NO) { down_read(&space_info->groups_sem); if (list_empty(&block_group->list) || diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 16beb25be4b0..cfc59123b00c 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -337,7 +337,9 @@ void btrfs_add_bg_to_space_info(struct btrfs_fs_info *info, factor = btrfs_bg_type_to_factor(block_group->flags); - found = btrfs_find_space_info(info, block_group->flags); + found = block_group->space_info; + if (!found) + found = btrfs_find_space_info(info, block_group->flags); ASSERT(found); spin_lock(&found->lock); found->total_bytes += block_group->length; From patchwork Thu Dec 5 07:48:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894808 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BCE51B6CF5 for ; Thu, 5 Dec 2024 07:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384969; cv=none; b=fnQyHDdZQ690Tm2ta+hxI4ORUcHPJwRfQmkACMXUaO/XLxRHA2l3KLH3zMrd+qB11TimqUF+QvFCAHXV6bSgfRQio14WR7oJ3Y/xEkMed/i3XrF2GiY+T0Pr8gvdSYpHyCTKrAcMo/jlVfRZ7dE7R6Fzm7fEr3y6NXAYCEqoeeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384969; c=relaxed/simple; bh=Yg0/ZKYktG7fEObUSD/PxEuyOeGev+Ml7YIOtl0mV1E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GK+1E10H5/zzqVpa6fFA+5vt2/baBGbQrdqcuqKS4E6C7CCioHiosxvDI2bXKZzcC6f9h2Jy4Cz8QxF3brS1OW+Rep58F9NeGDwUPY2jUXHxJT4dSYW7Ci//3frcgGuEQZPyEHGz1ojAKO3JbNp8SJhHRal7i/PsHKShdhLTlZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=U0Odgy0i; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="U0Odgy0i" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733384966; x=1764920966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yg0/ZKYktG7fEObUSD/PxEuyOeGev+Ml7YIOtl0mV1E=; b=U0Odgy0iIBFmeOnhNm2VUJY75wQmjX+0QLpGLLsKHvYYJvD2bCM4sg7m DGn3HYbKOsuMnd6liibzVvOKIxIonlNnovA4xIW1din4G8LmEIbc0QcnN IhUsbNY2JmGGpKMJrX3skcmelyjq1uwvSPQmRu+dxWjO14pDuzid9Xsia P9k/nEi/Tq3ltfzJJWX+sO3W9pov0bXjttg4+bPgAHuVhRgvoE5m+GyIs c4ZxifdzUcHiv9Xt7cewOy5eETSSHeuhAZlPVXbqv7TKwHlTrP6Aj+qhR v/P+5wvUUDid9PyBakHy6pkqioIXHMvzo5BHdrrS+d3umJVZZsBtdyYiJ Q==; X-CSE-ConnectionGUID: WPhGFnXeTxqd85RKGkPIWA== X-CSE-MsgGUID: knZqfTAlS5SIH3iQwNKdRA== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626121" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:24 +0800 IronPort-SDR: 67514c5f_zPQiYFT1egw4/XMQgixMReUnsxIeewho8AId2iz/wH106My 1UOvZHupdUJmNdKdqiAscuE9X3WcWhvzPhUg1YA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:55 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:24 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 10/11] btrfs: use proper data space_info Date: Thu, 5 Dec 2024 16:48:26 +0900 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that, we have data sub-space for the zoned mode. This commit tweaks some space_info functions to use proper space_info for a file. Signed-off-by: Naohiro Aota --- fs/btrfs/delalloc-space.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c index 918ba2ab1d5f..89e43abfb2b8 100644 --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -111,6 +111,17 @@ * making error handling and cleanup easier. */ +static inline struct btrfs_space_info* data_sinfo_for_inode(const struct btrfs_inode *inode) +{ + struct btrfs_fs_info *fs_info = inode->root->fs_info; + + if (!btrfs_is_zoned(fs_info)) + return fs_info->data_sinfo; + if (btrfs_is_data_reloc_root(inode->root)) + return fs_info->data_sinfo->sub_group[SUB_GROUP_DATA_RELOC]; + return fs_info->data_sinfo; +} + int btrfs_alloc_data_chunk_ondemand(const struct btrfs_inode *inode, u64 bytes) { struct btrfs_root *root = inode->root; @@ -123,7 +134,7 @@ int btrfs_alloc_data_chunk_ondemand(const struct btrfs_inode *inode, u64 bytes) if (btrfs_is_free_space_inode(inode)) flush = BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE; - return btrfs_reserve_data_bytes(fs_info->data_sinfo, bytes, flush); + return btrfs_reserve_data_bytes(data_sinfo_for_inode(inode), bytes, flush); } int btrfs_check_data_free_space(struct btrfs_inode *inode, @@ -144,7 +155,7 @@ int btrfs_check_data_free_space(struct btrfs_inode *inode, else if (btrfs_is_free_space_inode(inode)) flush = BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE; - ret = btrfs_reserve_data_bytes(fs_info->data_sinfo, len, flush); + ret = btrfs_reserve_data_bytes(data_sinfo_for_inode(inode), len, flush); if (ret < 0) return ret; @@ -172,12 +183,10 @@ void btrfs_free_reserved_data_space_noquota(struct btrfs_inode *inode, u64 len) { struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct btrfs_space_info *data_sinfo; ASSERT(IS_ALIGNED(len, fs_info->sectorsize)); - data_sinfo = fs_info->data_sinfo; - btrfs_space_info_free_bytes_may_use(data_sinfo, len); + btrfs_space_info_free_bytes_may_use(data_sinfo_for_inode(inode), len); } /* From patchwork Thu Dec 5 07:48:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13894807 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93F121B87F5 for ; Thu, 5 Dec 2024 07:49:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.143.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384968; cv=none; b=aP/ElumvdzH5cD9JJT0xRlhzsMbaWa89B18J6Bl2qKL+Hb4GQCVvw2j/4YkOr9doVvoxCWNWFS3ZezQatENrUPAE526TwrhFoi0LNX92Fm4Gwy3Ak87ZuPbp0q8CBTKW+ii739yyky/QJjMKOvNN8375z0F8rB4nZWezPpZK7dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733384968; c=relaxed/simple; bh=3tBkqOd1pC4GxPWICfAVG4PrFEovkK9wiyAIFebpEh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hJ+YRPsJVxW63yonBk8LNd0uFBg59nEu9U5O2YXR9Jpm7/TiW6mQbAdEQj3xslXv45gGf3JEDjSZif1LberEzHA6O0iFfGXx5bLXUZStlPLBGMsHaLTyjJluetU6F3SlCg9byxnBMBZ7pEvYJ8z92JU0QAECuWu+6ffp4sAHrpo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=Reg1ER9k; arc=none smtp.client-ip=68.232.143.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="Reg1ER9k" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1733384966; x=1764920966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3tBkqOd1pC4GxPWICfAVG4PrFEovkK9wiyAIFebpEh8=; b=Reg1ER9kA1tD3B54+dPaM5UMQeyjxcjZfXWkOlBWIh9Vk5cOXCmmmBBU 8TnxPJdg7J/9fkqKSCCsq68h1nwRAqh6dS9iQFaxq/+HffIhv719io2bw FE0UiKixtkckhCnVqSCfBRRLPolkWyet68AJFsf9PKG2lqwU/GcV43ngB oHywG7eCb/SgUWFOGELt9hnwSUKv8Q96K2pkCGxzGPLZo93xt1OpFsMXR a3mNWIQbNcVKbr04209P93GmauuZ34PYR6rIxLpd1BaLAEHFpDndUlVQQ QHQJNLz3s8Ge3MsdFZWBivbtS/u2iu7ezsuLmv+qGUF+XaauzeL4n62YV g==; X-CSE-ConnectionGUID: i0Gzz4ouSuC9WI09/PW7Qg== X-CSE-MsgGUID: d+aBypK9RK6KFKvKN25CIg== X-IronPort-AV: E=Sophos;i="6.12,209,1728921600"; d="scan'208";a="33626122" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 05 Dec 2024 15:49:25 +0800 IronPort-SDR: 67514c60_cTovsuVHf4oaMNDdXVY0UprsilgBsGgPo3oBsChCvAU5IgL 510Qgvh3hQXJOLEyAQt+nE/Gb6DulAFwaZVzXIQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 04 Dec 2024 22:46:56 -0800 WDCIronportException: Internal Received: from naota-x1.dhcp.fujisawa.hgst.com (HELO naota-x1.ad.shared) ([10.89.81.175]) by uls-op-cesaip02.wdc.com with ESMTP; 04 Dec 2024 23:49:25 -0800 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 11/11] btrfs: reclaim from data sub-space space_info Date: Thu, 5 Dec 2024 16:48:27 +0900 Message-ID: <36e642488814dbff7719c77b1fbdca5a8066ffc6.1733384172.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, we only have sub-space space_info for data. Modify btrfs_async_data_reclaim() to run the reclaim process on the sub-spaces as well. Signed-off-by: Naohiro Aota --- fs/btrfs/space-info.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index cfc59123b00c..ddb042845e86 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1422,6 +1422,9 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work) fs_info = container_of(work, struct btrfs_fs_info, async_data_reclaim_work); space_info = fs_info->data_sinfo; do_async_reclaim_data_space(space_info); + for (int i = 0; i < BTRFS_SPACE_INFO_SUB_GROUP_MAX; i++) + if (space_info->sub_group[i]) + do_async_reclaim_data_space(space_info->sub_group[i]); } void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info)