From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 D6FEC2BEC5F for ; Wed, 4 Feb 2026 02:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770173674; cv=none; b=oavMk1oU0NKqV3L91eIztQGM2kKC01fAh6zBZq8coSeGg9jG3q+DycG5nS7J29Uq4flkiSJeiinfcWrEI5/3Z5JLOYBL6QxWEK9ph1i3ayGLBMainyc62usK4/N3PvqwRtgo7JH2iLNoQQBzQLqlTpT7JH7LGPiqNtYGo33sdhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770173674; c=relaxed/simple; bh=lPD6mcABl8CryJ9TOBVnHVBMqY+1p32/EFCOcJazWV4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=c5Kie+WxPtgt6QFdM1YZg13gK3zf93CkniwUU6mrDqEGzct5kN0A7ZU6WQZWcdhaHOhXRqrFd2M3/4hdwhapKrQp+47HyeTw78Tiv51VnUnXw3+eQzs9M/qs/a8h8WqaNNNmk+z1ssKf+5YN0SjVNDKjWbrcgdG0qcp6GlHzgFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=nThRUV9W; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=nThRUV9W; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nThRUV9W"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nThRUV9W" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B65963E6D1 for ; Wed, 4 Feb 2026 02:54:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770173670; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=H+ij5307wPFqL6P4Rirv6Iw6YaemyInuLuGE8oPFKXA=; b=nThRUV9WYdLbPpO6ChMXXh/uJ+cqyiWDMAfJDLXmladLIdt1dsw/iRhqKQsF/W02cXvlHO RzTFIHQFcCzb1hfEgqOCpXCumyYQIaq09E1yrRTSCWwLJ1ViqqcpgVtSnP23zQhHBPncrw FzAdotvSDN1MrEbWwyohNv1xn6b/9FI= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=nThRUV9W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1770173670; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=H+ij5307wPFqL6P4Rirv6Iw6YaemyInuLuGE8oPFKXA=; b=nThRUV9WYdLbPpO6ChMXXh/uJ+cqyiWDMAfJDLXmladLIdt1dsw/iRhqKQsF/W02cXvlHO RzTFIHQFcCzb1hfEgqOCpXCumyYQIaq09E1yrRTSCWwLJ1ViqqcpgVtSnP23zQhHBPncrw FzAdotvSDN1MrEbWwyohNv1xn6b/9FI= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DE32C3EA63 for ; Wed, 4 Feb 2026 02:54:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id csSQJuW0gmknHAAAD6G6ig (envelope-from ) for ; Wed, 04 Feb 2026 02:54:29 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 0/3] btrfs: unbalanced disks aware per-profile available space estimation Date: Wed, 4 Feb 2026 13:24:05 +1030 Message-ID: X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -3.01 X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[suse.com:+] X-Spam-Level: X-Rspamd-Action: no action X-Rspamd-Queue-Id: B65963E6D1 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO [CHANGELOG] v2: - Various grammar fixes - Fix a u64 division compiling error on ppc64 Which requires the dedicated div_u64() helper. - Ignore unallocated space that's too small If the unallocated space is not enough to even cover a single stripe (64K), don't utilize it. This makes the behavior more aligned to the chunk allocator, and prevent over-estimation. - Use U64_MAX to mark the per-profile estimation as unavailable This reduce the memory usage by one unsigned long. - Update the commit message of the 2nd patch To include the overhead (runtime of btrfs_update_per_profile_avail()) in the commit message. - Minor comment cleanup on the term "balloon" The old term "balloon" is no longer utilized and there is a typo. ("ballon" -> "balloon"). - Update the estimation examples in the first patch As we allows 2 disks raid5 and 3 disks raid6. v1: - Revive from the v5.9 era fix - Make btrfs_update_per_profile_avail() to not return error Instead just mark all profiles as unavailable, and btrfs_get_per_profile_avail() will return false. The caller will need to fallback to the existing factor based estimation. This greatly simplified the error handling, which is a pain point in the original series. - Remove a lot of refactor/cleanup As that's already done in upstream. - Only make calc_available_free_space() to use the new infrastructure That's the main goal, fix can_over_commit(). Further enhancement can be done later. There is a long known bug that if metadata is using RAID1 on two unbalanced disks, btrfs have a very high chance to hit -ENOSPC during critical paths and flips RO. The bug dates back to v5.9 (where my last updates ends) and the most recent bug report is from Christoph. The idea to fix it is always here, by providing a chunk-allocator-like available space estimation. It doesn't need to be as heavy as chunk allocator, but at least it should not over-estimate. The demon is always in the details, the previous v5.9 era series requires a lot of changes in error handling, because the btrfs_update_per_profile_avail() can fail at critical paths in chunk allocation/removal and device grow/shrink/add/removal. But this time that function will no longer fail, but just mark per-profile available estimation as unreliable, and let the caller to fallback to the old factor based solution. In the real world it should not be a big deal, as the only error is -ENOMEM, but this greatly simplifies the error handling. Qu Wenruo (3): btrfs: introduce the device layout aware per-profile available space btrfs: update per-profile available estimation btrfs: use per-profile available space in calc_available_free_space() fs/btrfs/space-info.c | 27 ++++--- fs/btrfs/volumes.c | 183 +++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.h | 34 ++++++++ 3 files changed, 231 insertions(+), 13 deletions(-) -- 2.52.0