linux-bcachefs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikita Ofitserov via B4 Relay <devnull+himikof.gmail.com@kernel.org>
To: Kent Overstreet <kent.overstreet@linux.dev>
Cc: linux-bcachefs@vger.kernel.org, Nikita Ofitserov <himikof@gmail.com>
Subject: [PATCH 03/12] bcachefs: Use explicit node counts in progress reporting
Date: Wed, 27 Aug 2025 01:49:09 +0300	[thread overview]
Message-ID: <20250827-better-progress-v1-3-74c24de7988a@gmail.com> (raw)
In-Reply-To: <20250827-better-progress-v1-0-74c24de7988a@gmail.com>

From: Nikita Ofitserov <himikof@gmail.com>

Also consider the metadata_replicas option when better
accounting is not available.

Signed-off-by: Nikita Ofitserov <himikof@gmail.com>
---
 fs/bcachefs/progress.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/bcachefs/progress.c b/fs/bcachefs/progress.c
index 792fc6fef27018c73168c59857e7f3497c1969f4..3ad4e1f6f653c8c75205efdd6d72560b8dda4c51 100644
--- a/fs/bcachefs/progress.c
+++ b/fs/bcachefs/progress.c
@@ -12,6 +12,10 @@ void bch2_progress_init(struct progress_indicator_state *s,
 
 	s->next_print = jiffies + HZ * 10;
 
+	/* This is only an estimation: nodes can have different replica counts */
+	const u32 expected_node_disk_sectors =
+		READ_ONCE(c->opts.metadata_replicas) * btree_sectors(c);
+
 	for (unsigned i = 0; i < BTREE_ID_NR; i++) {
 		if (!(btree_id_mask & BIT_ULL(i)))
 			continue;
@@ -19,9 +23,23 @@ void bch2_progress_init(struct progress_indicator_state *s,
 		struct disk_accounting_pos acc;
 		disk_accounting_key_init(acc, btree, .id = i);
 
-		u64 v;
-		bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc), &v, 1);
-		s->nodes_total += div64_ul(v, btree_sectors(c));
+		struct {
+			u64 disk_sectors;
+			u64 total_nodes;
+			u64 inner_nodes;
+		} v = {0};
+		bch2_accounting_mem_read(c, disk_accounting_pos_to_bpos(&acc),
+			(u64 *)&v, sizeof(v) / sizeof(u64));
+
+		/*
+		 * We check for zeros to degrade gracefully when run
+		 * with un-upgraded accounting info (missing some counters).
+		 */
+
+		if (v.total_nodes != 0)
+			s->nodes_total += v.total_nodes - v.inner_nodes;
+		else
+			s->nodes_total += div_u64(v.disk_sectors, expected_node_disk_sectors);
 	}
 }
 

-- 
2.50.1



  parent reply	other threads:[~2025-08-26 22:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 22:49 [PATCH 00/12] Accounting for accurate progress reporting Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 01/12] bcachefs: Relax restrictions on the number of accounting counters Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 02/12] bcachefs: Introduce btree node number accounting Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` Nikita Ofitserov via B4 Relay [this message]
2025-08-26 22:49 ` [PATCH 04/12] bcachefs: Introduce btree_leaf_has_triggers_mask Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 05/12] bcachefs: Better progress reporting for btree iteration without leaves Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 06/12] bcachefs: Refactor/rename btree_type_has_ptrs Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 07/12] bcachefs: More accurate progress reporting for inner node iteration Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 08/12] bcachefs: Fix progress reporting for unknown btrees Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 09/12] bcachefs: Partially fix old device removal with " Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 10/12] bcachefs: Improve check_allocations pass speed not in fsck Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 11/12] bcachefs: Fix missing c->usage updates from early recovery Nikita Ofitserov via B4 Relay
2025-08-26 22:49 ` [PATCH 12/12] bcachefs: Fix online hidden (sb+journal) data accounting Nikita Ofitserov via B4 Relay
2025-08-27 17:17 ` [PATCH 00/12] Accounting for accurate progress reporting Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250827-better-progress-v1-3-74c24de7988a@gmail.com \
    --to=devnull+himikof.gmail.com@kernel.org \
    --cc=himikof@gmail.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcachefs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).