On Thu, 5 Mar 2026 08:59:23 GMT, Afshin Zafari <[email protected]> wrote:
> What do you think about this:
>
> ```
> if (pd_release_memory()) {
> nmt_lock
> update NMT
> nmt_unlock
> } else {
> fatal(...)
> }```
Hmm I think that this might still allow for a race. For example:
1. Thread_A calls `pd_release_memory()` on region_1. The OS releases region_1.
2. Thread_B calls `os::reserve_memory` and the OS returns region_1 to it.
3. Thread_B acquires the lock, calls
`MemTracker::record_virtual_memory_reserve`, then releases the lock
4. Thread_A acquires the lock, calls
`MemTracker::record_virtual_memory_release`, then releases the lock
So now region_1 is reserved, but NMT thinks that it is free.
> Also, we can think about moving the NMT LOCKing into the
> record_virtual_memory_release() function, like other
> record_virtual_memory_xxxx() functions.
Yes, I agree. That would be another good benefit of shrinking the lock scope.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/29962#issuecomment-4006651319