-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Decommit instance memory after a runtime call on Linux #8998
Changes from 4 commits
c97a77e
74cf151
53e29c9
ec3cf69
5d07a20
2e07a0e
b4ee835
3943a69
dfe1170
75f04d5
56e165d
caaa7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,6 +415,38 @@ impl InstanceWrapper { | |
| slice::from_raw_parts_mut(ptr, len) | ||
| } | ||
| } | ||
|
|
||
| /// 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! { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean that There are different options there to make it work on macOS, but those are out of scope for this PR. When the time comes though it will be clear where to integrate them : )
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean we don't need the Could be just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Assuming you meant Yeah, true, not necessary. I figured I use it because:
It's not something I am married to, so can change to a plain
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah fine |
||
| 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.