Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Increment usage count for loaded programs and call eviction #30900

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use {
fmt::Debug,
mem,
rc::Rc,
sync::Arc,
sync::{atomic::Ordering, Arc},
},
thiserror::Error,
};
Expand Down Expand Up @@ -588,6 +588,8 @@ fn process_instruction_common(
if let Some(load_program_metrics) = load_program_metrics {
load_program_metrics.submit_datapoint(&mut invoke_context.timings);
}

executor.usage_counter.fetch_add(1, Ordering::Relaxed);
match &executor.program {
LoadedProgramType::Invalid => Err(InstructionError::InvalidAccountData),
LoadedProgramType::LegacyV0(executable) => execute(executable, invoke_context),
Expand Down
7 changes: 6 additions & 1 deletion programs/loader-v3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ use {
saturating_add_assign,
transaction_context::{BorrowedAccount, InstructionContext},
},
std::{cell::RefCell, rc::Rc, sync::Arc},
std::{
cell::RefCell,
rc::Rc,
sync::{atomic::Ordering, Arc},
},
};

fn get_state(data: &[u8]) -> Result<&LoaderV3State, InstructionError> {
Expand Down Expand Up @@ -584,6 +588,7 @@ pub fn process_instruction(invoke_context: &mut InvokeContext) -> Result<(), Ins
get_or_create_executor_time.as_us()
);
drop(program);
loaded_program.usage_counter.fetch_add(1, Ordering::Relaxed);
match &loaded_program.program {
LoadedProgramType::Invalid => Err(InstructionError::InvalidAccountData),
LoadedProgramType::Typed(executable) => execute(invoke_context, executable),
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4650,6 +4650,11 @@ impl Bank {

execution_time.stop();

self.loaded_programs_cache
.write()
.unwrap()
.sort_and_evict(None);

debug!(
"check: {}us load: {}us execute: {}us txs_len={}",
check_time.as_us(),
Expand Down