mmtk / mmtk-core

Memory Management ToolKit
https://www.mmtk.io
Other
379 stars 69 forks source link

Annotate mmap ranges using PR_SET_VMA #1236

Open wks opened 1 week ago

wks commented 1 week ago

We demand that every invocation of mmap within mmtk-core to be accompanied with an "annotation" for the purpose of the mmap. On Linux, we will use PR_SET_VMA_ANON_NAME to set the attribute after mmap so that it can be seen in /proc/pid/maps. This will greatly improve the debugging experience.

This is a DRAFT:

k-sareen commented 6 days ago

Why not just use the space/metadata spec name instead? Also there's a 80-byte limit for the string (including the NUL byte).

However, for Map32, spaces may interleave at chunk granularity in the shared discontiguous memory range.

Why is this a problem? If a chunk is recycled, then we should just rename it.

wks commented 5 days ago

Why not just use the space/metadata spec name instead?

Also there's a 80-byte limit for the string (including the NUL byte).

Good point. Although I don't think any space name + metadata name would exceed this limit, it's safe to perform the check when formatting.

Why is this a problem? If a chunk is recycled, then we should just rename it.

The number of mmap entries is limited at the OS level. So whenever possible, we should merge adjacent entries. If no chunk in the discontiguous space has name (annotated with PR_SET_VMA_ANON_NAME), the OS may merge adjacent entries; but if adjacent entries have different names, they can't be merged.

k-sareen commented 5 days ago

And there are mmap invocations for other purposes, too, such as SFTMap.

Yes that is a good point. Though in my branch I just use an Option<&str> because it's not always clear what name to give to an mmap region such as the side metadata implementation for 32-bits and for panic_if_unmapped.

The number of mmap entries is limited at the OS level. So whenever possible, we should merge adjacent entries. If no chunk in the discontiguous space has name (annotated with PR_SET_VMA_ANON_NAME), the OS may merge adjacent entries; but if adjacent entries have different names, they can't be merged.

I'm not sure this is a real concern? I don't imagine we'll ever be hitting the limit even for 32-bit machines. Even Android always has the annotations enabled. I strongly suggest having these on by default. If we ever hit the limit then we can disable it.