Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes AccountStorageEntry::approx_store_count #2953

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

brooksprumo
Copy link

@brooksprumo brooksprumo commented Sep 19, 2024

Problem

The AccountStorageEntry::approx_store_count field is unused.

The comments describe it was used during/for shrink, but that is no longer the case. I end up having to re-remember this field isn't actually used though while going through the shrink/storage code. And, it's an atomic, so eventually it requires cache coherence updates ("eventually" due to the Relaxed accesses). Again, since it is not used, we can avoid doing that unnecessary work.

Summary of Changes

Remove it.

@brooksprumo brooksprumo self-assigned this Sep 19, 2024
@@ -8031,16 +8014,14 @@ impl AccountsDb {

fn is_shrinking_productive(store: &AccountStorageEntry) -> bool {
let alive_count = store.count();
let stored_count = store.approx_stored_count();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We read the approx_store_count atomic here, but it is only used for a trace! log, not determining if shrinking is productive or not.

This would be the only useful place to load this field, but since it is only used for logging, it is not actually useful.

Comment on lines -1220 to -1221
self.approx_store_count
.fetch_add(num_accounts, Ordering::Relaxed);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we never read this field in a useful way, we also do not need to write this field here.

///
/// This is used as a rough estimate for slot shrinking. As such a relaxed
/// use case, this value ARE NOT strictly synchronized with count_and_status!
approx_store_count: AtomicUsize,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...thus the whole field is useless and can be removed.

@brooksprumo brooksprumo marked this pull request as ready for review September 19, 2024 15:56
@@ -1137,14 +1127,13 @@ impl AccountStorageEntry {
slot: Slot,
id: AccountsFileId,
accounts: AccountsFile,
num_accounts: usize,
_num_accounts: usize,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next PR will remove the now-unused num_accounts param from this function.

Copy link

@HaoranYi HaoranYi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, 'approx_stored_count' seems to be a redundant counter. And its usage
is for logging and assert. Probably, it was added initially for debugging or
as sanity check to make sure that the account storage has the number of
expected accounts.

Logically, I think it is fine to remove it.

Alternatively, if we think there is value to maintain this redundant counter
check, maybe we can have add a mode to enable this? which can be done through
a CLI arg or an environment variable?

Copy link

@jeffwashington jeffwashington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@brooksprumo brooksprumo merged commit cc141d1 into anza-xyz:master Sep 27, 2024
40 checks passed
@brooksprumo brooksprumo deleted the approx-store-count/remove2 branch September 27, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants