From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 438E511707 for ; Mon, 21 Aug 2023 19:53:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B85FCC433C7; Mon, 21 Aug 2023 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1692647622; bh=SH4lfkJy/hzaoxsj0dLnBKMsOwwBdIbMwXySeatlCkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yNHK3qVi81R07OFb1ebScq5OKvCSmzFSk0wQ5yC/uUCu7oCrJNnEJ/i3Rxi92QTRd bIovZ2kBgGEffEX8HXnZTZexjnJoAZW6ct9VyAZobk3dDa5xKGzqL2Z4LuKaDmQhB5 a39NAvr3cdDbl45/tX63RuAlqMH67yeMjwdz8/5g= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Filipe Manana , Johannes Thumshirn , Naohiro Aota , David Sterba , Sasha Levin Subject: [PATCH 6.1 080/194] btrfs: move out now unused BG from the reclaim list Date: Mon, 21 Aug 2023 21:40:59 +0200 Message-ID: <20230821194126.295372559@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230821194122.695845670@linuxfoundation.org> References: <20230821194122.695845670@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Naohiro Aota [ Upstream commit a9f189716cf15913c453299d72f69c51a9b0f86b ] An unused block group is easy to remove to free up space and should be reclaimed fast. Such block group can often already be a target of the reclaim process. As we check list_empty(&bg->bg_list), we keep it in the reclaim list. That block group is never reclaimed until the file system is filled e.g. up to 75%. Instead, we can move unused block group to the unused list and delete it fast. Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Filipe Manana Reviewed-by: Johannes Thumshirn Signed-off-by: Naohiro Aota Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/block-group.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 3495bc775afa3..9f5a971bfed42 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1528,11 +1528,14 @@ void btrfs_mark_bg_unused(struct btrfs_block_group *bg) { struct btrfs_fs_info *fs_info = bg->fs_info; + trace_btrfs_add_unused_block_group(bg); spin_lock(&fs_info->unused_bgs_lock); if (list_empty(&bg->bg_list)) { btrfs_get_block_group(bg); - trace_btrfs_add_unused_block_group(bg); list_add_tail(&bg->bg_list, &fs_info->unused_bgs); + } else { + /* Pull out the block group from the reclaim_bgs list. */ + list_move_tail(&bg->bg_list, &fs_info->unused_bgs); } spin_unlock(&fs_info->unused_bgs_lock); } -- 2.40.1