mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Decommit instance memory after a runtime call on Linux (#8998)
* Decommit instance memory after a runtime call on Linux * Update documentation for the test * Remove unfinished comment * Use saturating_sub. Also update the doc comment. * Precise RSS tracking in the test Instead of tracking RSS for the whole process we just look at the particular mapping that is associated with the linear memory of the runtime instance * Remove unused import * Fix unused imports * Fix the unused imports error for good * Rollback an accidental change to benches * Fix the test * Remove now unneeded code
This commit is contained in:
@@ -415,6 +415,43 @@ impl InstanceWrapper {
|
||||
slice::from_raw_parts_mut(ptr, len)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the pointer to the first byte of the linear memory for this instance.
|
||||
pub fn base_ptr(&self) -> *const u8 {
|
||||
self.memory.data_ptr()
|
||||
}
|
||||
|
||||
/// Removes physical backing from the allocated linear memory. This leads to returning the memory
|
||||
/// back to the system. While the memory is zeroed this is considered as a side-effect and is not
|
||||
/// relied upon. Thus this function acts as a hint.
|
||||
pub fn decommit(&self) {
|
||||
if self.memory.data_size() == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_os = "linux")] {
|
||||
use std::sync::Once;
|
||||
|
||||
unsafe {
|
||||
let ptr = self.memory.data_ptr();
|
||||
let len = self.memory.data_size();
|
||||
|
||||
// Linux handles MADV_DONTNEED reliably. The result is that the given area
|
||||
// is unmapped and will be zeroed on the next pagefault.
|
||||
if libc::madvise(ptr as _, len, libc::MADV_DONTNEED) != 0 {
|
||||
static LOGGED: Once = Once::new();
|
||||
LOGGED.call_once(|| {
|
||||
log::warn!(
|
||||
"madvise(MADV_DONTNEED) failed: {}",
|
||||
std::io::Error::last_os_error(),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl runtime_blob::InstanceGlobals for InstanceWrapper {
|
||||
|
||||
Reference in New Issue
Block a user