Skip to content

Commit

Permalink
Fix - Uses fetch_add() to accumulate usage counters in `LoadedProgr…
Browse files Browse the repository at this point in the history
…ams` (#34319)

Uses fetch_add() to accumulate usage counters.

(cherry picked from commit f70d548)

# Conflicts:
#	program-runtime/src/loaded_programs.rs
  • Loading branch information
Lichtso authored and mergify[bot] committed Dec 6, 2023
1 parent 311e986 commit caf4028
Showing 1 changed file with 43 additions and 19 deletions.
62 changes: 43 additions & 19 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,11 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
if matches!(existing.program, LoadedProgramType::Unloaded(_)) {
// The unloaded program is getting reloaded
// Copy over the usage counter to the new entry
let mut usage_count = existing.tx_usage_counter.load(Ordering::Relaxed);
saturating_add_assign!(
usage_count,
entry.tx_usage_counter.load(Ordering::Relaxed)
entry.tx_usage_counter.fetch_add(
existing.tx_usage_counter.load(Ordering::Relaxed),
Ordering::Relaxed,
);
entry.tx_usage_counter.store(usage_count, Ordering::Relaxed);
entry.ix_usage_counter.store(
entry.ix_usage_counter.fetch_add(
existing.ix_usage_counter.load(Ordering::Relaxed),
Ordering::Relaxed,
);
Expand Down Expand Up @@ -790,8 +788,23 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
let mut missing = Vec::new();
let mut unloaded = Vec::new();
let current_slot = working_slot.current_slot();
<<<<<<< HEAD
let found = keys
.filter_map(|(key, (match_criteria, count))| {
=======
let extracted = Arc::new(Mutex::new(ExtractedPrograms {
loaded: LoadedProgramsForTxBatch {
entries: HashMap::new(),
slot: current_slot,
environments: environments.clone(),
},
missing: HashMap::new(),
}));
let mut extracting = extracted.lock().unwrap();
extracting.loaded.entries = keys
.filter_map(|(key, (match_criteria, usage_count))| {
let mut reloading = false;
>>>>>>> f70d5481bc (Fix - Uses `fetch_add()` to accumulate usage counters in `LoadedPrograms` (#34319))
if let Some(second_level) = self.entries.get(&key) {
for entry in second_level.iter().rev() {
let is_ancestor = if let Some(fork_graph) = &self.fork_graph {
Expand All @@ -813,6 +826,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|| entry.deployment_slot == current_slot
|| is_ancestor
{
<<<<<<< HEAD
if current_slot >= entry.effective_slot {
if !Self::is_entry_usable(entry, current_slot, &match_criteria) {
missing.push((key, count));
Expand All @@ -822,34 +836,44 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
if !Self::matches_environment(entry, environments) {
missing.push((key, count));
return None;
=======
let entry_to_return = if current_slot >= entry.effective_slot {
if !Self::is_entry_usable(entry, current_slot, &match_criteria)
|| !Self::matches_environment(entry, environments)
{
break;
>>>>>>> f70d5481bc (Fix - Uses `fetch_add()` to accumulate usage counters in `LoadedPrograms` (#34319))
}

if let LoadedProgramType::Unloaded(_environment) = &entry.program {
unloaded.push((key, count));
return None;
}

let mut usage_count =
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()));
entry.clone()
} else if entry.is_implicit_delay_visibility_tombstone(current_slot) {
// Found a program entry on the current fork, but it's not effective
// yet. It indicates that the program has delayed visibility. Return
// the tombstone to reflect that.
return Some((
key,
Arc::new(LoadedProgram::new_tombstone(
entry.deployment_slot,
LoadedProgramType::DelayVisibility,
)),
));
}
Arc::new(LoadedProgram::new_tombstone(
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));
}
}
}
<<<<<<< HEAD
missing.push((key, count));
=======
extracting.missing.insert(key, (usage_count, reloading));
>>>>>>> f70d5481bc (Fix - Uses `fetch_add()` to accumulate usage counters in `LoadedPrograms` (#34319))
None
})
.collect::<HashMap<Pubkey, Arc<LoadedProgram>>>();
Expand Down

0 comments on commit caf4028

Please sign in to comment.