RFR: 8370254: Add VM_MEMORY_JAVA mmap tag to MacOS mmap calls [v15]
Jaikiran Pai
jpai at openjdk.org
Sat Nov 15 05:54:10 UTC 2025
On Fri, 14 Nov 2025 04:38:43 GMT, Nityanand Rai <duke at openjdk.org> wrote:
>> Add VM_MEMORY_JAVA tag to mmap calls in os_bsd.cpp for better memory tracking of java process on macOs
>
> Nityanand Rai has updated the pull request incrementally with one additional commit since the last revision:
>
> cleanup
src/hotspot/os/bsd/os_bsd.hpp line 43:
> 41: // Bsd_OS defines the interface to Bsd operating systems
> 42:
> 43: static constexpr int bsd_mmap_fd =
I don't have familiarity in this area, but looking at the man page of `mmap` on my local macos, it states this:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset);
...
MAP_ANON Map anonymous memory not associated with any specific file. The offset argument is ignored. Mac OS X specific: the file descriptor used for
creating MAP_ANON regions can be used to pass some Mach VM flags, and can be specified as -1 if no such flags are associated with the region.
Mach VM flags are defined in <mach/vm_statistics.h> and the ones that currently apply to mmap are:
VM_FLAGS_PURGABLE to create Mach purgable (i.e. volatile) memory.
VM_MAKE_TAG(tag) to associate an 8-bit tag with the region.
<mach/vm_statistics.h> defines some preset tags (with a VM_MEMORY_ prefix). Users are encouraged to use tags between 240 and 255. Tags are used
by tools such as vmmap(1) to help identify specific memory regions.
So this special value handling of `fd` value is only applicable if `MAP_ANON` is part of the `flags`.
Given this, should the name of constexpr be a bit more specific and the call sites, where this gets used, verify/assert that the flags indeed contains the `MAP_ANON` flag?
Plus, this is very macos specific, calling it `bsd_...` feels much more generic. Maybe we should consider naming it `macos_mmap_anon_fd`?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27868#discussion_r2529614816
More information about the hotspot-dev
mailing list