Fix - Uses `fetch_add()` to accumulate usage counters in `LoadedPrograms` (#34319)
Uses fetch_add() to accumulate usage counters.
This commit is contained in:
parent
70896b8999
commit
f70d5481bc
|
@ -609,13 +609,11 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
if matches!(existing.program, LoadedProgramType::Unloaded(_)) {
|
if matches!(existing.program, LoadedProgramType::Unloaded(_)) {
|
||||||
// The unloaded program is getting reloaded
|
// The unloaded program is getting reloaded
|
||||||
// Copy over the usage counter to the new entry
|
// Copy over the usage counter to the new entry
|
||||||
let mut usage_count = existing.tx_usage_counter.load(Ordering::Relaxed);
|
entry.tx_usage_counter.fetch_add(
|
||||||
saturating_add_assign!(
|
existing.tx_usage_counter.load(Ordering::Relaxed),
|
||||||
usage_count,
|
Ordering::Relaxed,
|
||||||
entry.tx_usage_counter.load(Ordering::Relaxed)
|
|
||||||
);
|
);
|
||||||
entry.tx_usage_counter.store(usage_count, Ordering::Relaxed);
|
entry.ix_usage_counter.fetch_add(
|
||||||
entry.ix_usage_counter.store(
|
|
||||||
existing.ix_usage_counter.load(Ordering::Relaxed),
|
existing.ix_usage_counter.load(Ordering::Relaxed),
|
||||||
Ordering::Relaxed,
|
Ordering::Relaxed,
|
||||||
);
|
);
|
||||||
|
@ -807,7 +805,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
}));
|
}));
|
||||||
let mut extracting = extracted.lock().unwrap();
|
let mut extracting = extracted.lock().unwrap();
|
||||||
extracting.loaded.entries = keys
|
extracting.loaded.entries = keys
|
||||||
.filter_map(|(key, (match_criteria, count))| {
|
.filter_map(|(key, (match_criteria, usage_count))| {
|
||||||
let mut reloading = false;
|
let mut reloading = false;
|
||||||
if let Some(second_level) = self.entries.get(&key) {
|
if let Some(second_level) = self.entries.get(&key) {
|
||||||
for entry in second_level.iter().rev() {
|
for entry in second_level.iter().rev() {
|
||||||
|
@ -830,7 +828,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
|| entry.deployment_slot == current_slot
|
|| entry.deployment_slot == current_slot
|
||||||
|| is_ancestor
|
|| is_ancestor
|
||||||
{
|
{
|
||||||
if current_slot >= entry.effective_slot {
|
let entry_to_return = if current_slot >= entry.effective_slot {
|
||||||
if !Self::is_entry_usable(entry, current_slot, &match_criteria)
|
if !Self::is_entry_usable(entry, current_slot, &match_criteria)
|
||||||
|| !Self::matches_environment(entry, environments)
|
|| !Self::matches_environment(entry, environments)
|
||||||
{
|
{
|
||||||
|
@ -842,27 +840,26 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut usage_count =
|
entry.clone()
|
||||||
entry.tx_usage_counter.load(Ordering::Relaxed);
|
|
||||||
saturating_add_assign!(usage_count, count);
|
|
||||||
entry.tx_usage_counter.store(usage_count, Ordering::Relaxed);
|
|
||||||
return Some((key, entry.clone()));
|
|
||||||
} else if entry.is_implicit_delay_visibility_tombstone(current_slot) {
|
} else if entry.is_implicit_delay_visibility_tombstone(current_slot) {
|
||||||
// Found a program entry on the current fork, but it's not effective
|
// Found a program entry on the current fork, but it's not effective
|
||||||
// yet. It indicates that the program has delayed visibility. Return
|
// yet. It indicates that the program has delayed visibility. Return
|
||||||
// the tombstone to reflect that.
|
// the tombstone to reflect that.
|
||||||
return Some((
|
Arc::new(LoadedProgram::new_tombstone(
|
||||||
key,
|
entry.deployment_slot,
|
||||||
Arc::new(LoadedProgram::new_tombstone(
|
LoadedProgramType::DelayVisibility,
|
||||||
entry.deployment_slot,
|
))
|
||||||
LoadedProgramType::DelayVisibility,
|
} else {
|
||||||
)),
|
continue;
|
||||||
));
|
};
|
||||||
}
|
entry_to_return
|
||||||
|
.tx_usage_counter
|
||||||
|
.fetch_add(usage_count, Ordering::Relaxed);
|
||||||
|
return Some((key, entry_to_return));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extracting.missing.insert(key, (count, reloading));
|
extracting.missing.insert(key, (usage_count, reloading));
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
.collect::<HashMap<Pubkey, Arc<LoadedProgram>>>();
|
.collect::<HashMap<Pubkey, Arc<LoadedProgram>>>();
|
||||||
|
|
Loading…
Reference in New Issue