Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider applying MADV_DONTNEED to snapshot data section after load #44019

Closed
mraleph opened this issue Nov 2, 2020 · 3 comments
Closed

consider applying MADV_DONTNEED to snapshot data section after load #44019

mraleph opened this issue Nov 2, 2020 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. customer-google3 vm-aot-memory-footprint Related to improvements of VM memory footprint for AOT deployments

Comments

@mraleph
Copy link
Member

mraleph commented Nov 2, 2020

Once snapshot is unpacked into isolate memory it is likely that it will not be needed again (especially if lightweight isolates are enabled). For environments with strict memory constraints we should consider findings ways to let OS release this memory and decrease RSS.

/cc @mkustermann @rmacnak-google

@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. customer-google3 labels Nov 2, 2020
@mkustermann
Copy link
Member

If the memory is mmap()ed in RO mode, the OS always has the freedom to remove RAM behind the virtual pages - and page it in again on-demand. Though I agree, we could make it easier for the OS.

@mraleph mraleph added the vm-aot-memory-footprint Related to improvements of VM memory footprint for AOT deployments label Nov 2, 2020
@rmacnak-google
Copy link
Contributor

I've tried this out, and unfortunately madvise(DONTNEED) has the wrong semantics for the VM to safely use it. If the memory isn't file-backed, it will be brought back in as zeros, but we need such memory to be left resident / ignored by madvise instead. (Parts of the clustered snapshot are not read-once because of external typed data pointing into it, the embedder reusing the snapshot for other isolates, or free reading malloc metadata.) The VM isn't always passed a snapshot that is file-backed, so any madvise(DONTNEED) needs to be done in embedders when the embedder can guarantee file-backed snapshots.

@mkustermann
Copy link
Member

If we expose the right symbols, could we let the embedder(s) do the madvise calls for the region of RO which contains the serialized snapshot only (not the RO mapped heap objects)?

@a-siva a-siva added this to Tasks in Dart VM memory footprint via automation Feb 3, 2021
copybara-service bot pushed a commit that referenced this issue Oct 25, 2021
…e snapshot.

This region is mostly unused after loading, but it may be accessed again if
 - Isolate.spawn is invoke with isolate groups disabled
 - A secondary snapshot produced by splitting is loaded
 - An external typed data in the snapshot is accessed (usually a kernel file)
 - Likely other cases

Even if these cases did not exist, the region is often part of a shared library and so unable to be released independently.

madvise(DONT_NEED) on this region will cause the OS to release the memory in this region but keep the address space reservation and mapping. If it is touched again, it will be brought back in from the file. If it is not backed by a file, such as malloc memory, it will be brought back in as zeros and the program will likely fail.

TEST=ci
Bug: #44019
Bug: flutter/flutter#92120
Change-Id: I315a049b0f7d440e181d0a5e87fa6770a2fd4f79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216580
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
copybara-service bot pushed a commit that referenced this issue Nov 4, 2021
…e(DONTNEED).

TEST=ci
Bug: #44019
Change-Id: Ib717ff2123b537787929cf591e0cef7149e5292e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218064
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Dart VM memory footprint automation moved this from Tasks to Done Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. customer-google3 vm-aot-memory-footprint Related to improvements of VM memory footprint for AOT deployments
Development

No branches or pull requests

3 participants