Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ http.workspace = true
httparse.workspace = true
hyper.workspace = true
hyper_v014.workspace = true
libc.workspace = true
log.workspace = true
once_cell.workspace = true
regex.workspace = true
Expand Down
1 change: 1 addition & 0 deletions ext/runtime/js/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function installEdgeRuntimeNamespace(kind, terminationRequestTokenRid) {
applySupabaseTag: (src, dest) => applySupabaseTag(src, dest),
systemMemoryInfo: () => ops.op_system_memory_info(),
raiseSegfault: () => ops.op_raise_segfault(),
miCollect: () => ops.op_mi_collect(),
...props,
};
break;
Expand Down
26 changes: 26 additions & 0 deletions ext/runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,31 @@ fn op_cancel_drop_token(
Ok(())
}

#[op2(fast)]
fn op_mi_collect() {
#[cfg(target_os = "linux")]
{
use std::sync::OnceLock;

type MiCollectFn = unsafe extern "C" fn(force: bool);

static MI_COLLECT: OnceLock<Option<MiCollectFn>> = OnceLock::new();

let f = MI_COLLECT.get_or_init(|| unsafe {
let sym = libc::dlsym(libc::RTLD_DEFAULT, c"mi_collect".as_ptr());
if sym.is_null() {
None
} else {
Some(std::mem::transmute::<*mut libc::c_void, MiCollectFn>(sym))
}
});

if let Some(mi_collect) = f {
unsafe { mi_collect(true) };
}
}
}

#[op2]
#[serde]
pub fn op_bootstrap_unstable_args(_state: &mut OpState) -> Vec<String> {
Expand Down Expand Up @@ -485,6 +510,7 @@ deno_core::extension!(
op_tap_promise_metrics,
op_cancel_drop_token,
op_check_outbound_rate_limit,
op_mi_collect,
],
esm_entry_point = "ext:runtime/bootstrap.js",
esm = [
Expand Down
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ declare namespace EdgeRuntime {
export function applySupabaseTag(src: Request, dest: Request): void;
export function systemMemoryInfo(): MemInfo;
export function raiseSegfault(): void;
export function miCollect(): void;

export { UserWorker as userWorkers };
}
Expand Down
Loading