Repository navigation
Implement retain on Windows. - #1545
Conversation
87e6663 to
a145d2b
Compare
|
@Ignition, @frederik-h, @santagada, @cytoo, @j0t -- FYI that we plan to do a 5.2.1 release in a couple of weeks, for the Windows VM leak fix in this patch. The issues you guys experienced before on Windows are likely all related to the issue here; any chance you could help test / benchmark the changes here? |
|
Will do, but I can't guarantee that I'll be able to do proper testing in this timeframe. |
|
The way I built for windows retain was not default true. Even with |
|
Ok, never mind. It was due to my conan build cache having an old build. I now get |
| return true; | ||
| /* | ||
| * When coalesce is not always allowed (Windows), only merge | ||
| * extents with identical sn (i.e. from the same VirtualAlloc |
There was a problem hiding this comment.
Can you include some back-of-the envelope math to convince me / the reader that "same sn == same VirtualAlloc call"? This is the first time that we're making that fact a correctness issue instead of just a QoI one, and that makes me somewhat nervous.
|
You know, it occurs to me that we can use two rtree bits to indicate "same VirtualAlloc" instead of using the extent sn. Have the bits be 0 if the extent is in the interior of a mapping, 1 if it's at the beginning of a mapping, and 2 if it's at the end of a mapping. That would let us avoid trying to play games with serial numbers entirely. |
|
Actually, we don't even need to take it from the rtree; it can just live in the extent state itself. We can take two bits from the serial number (or squirrel them away into the low bits of a pointer, etc.), and then we get a firm correctness guarantee regardless of serial number overflow. |
Yeah realized we can further simplify by only tracking the |
|
Just have tested my app with a library built from latest However, some jemalloc tests didn't pass. Don't know yet is it a specific CYGWIN issue or something else. Will try to found out more later. |
davidtgoldblatt
left a comment
There was a problem hiding this comment.
Can you squash down? It's a little harder to review this way.
| } | ||
|
|
||
| /* See comments in extent_merge_default_impl(). */ | ||
| return opt_retain ? false : true; |
There was a problem hiding this comment.
Why does extent splitting return an error only if retain is off? I see why we might want to treat this differently, but erroring out on splitting seems like a weird way to do so.
Also, I think this whole thing is most clearly written as: return !(maps_coalesce || opt_retain).
There was a problem hiding this comment.
Will refactor this. I wanted to separate the Windows logic and add some comments. Let me make that happen.
I think we want to consider the returning true as "not allowed to split" instead of a real error; without retain, purging does MEM_RELEASE which only accepts the whole region. In that case we don't allow split / merge. The user custom hooks might return true as a way to say not-allowed as well, e.g. in hhvm for arenas owning reserved huge pages (but with regular pages as back up), they may check if an extent is part of the huge pages and disallow purging.
bfac669 to
eb9460a
Compare
|
@j0t : which tests are failing for you? You can test against the dev branch to verify if it's related to retain here. |
|
You are welcome! It's great that this issue has been resolved finally.
Here are two stats, |
No, the same failures are originated from |
The VirtualAlloc and VirtualFree APIs are different because MEM_DECOMMIT cannot be used across multiple VirtualAlloc regions. To properly support decommit, only allow merge / split within the same region -- this is done by tracking the "is_head" state of extents and not merging cross-region. Add a new state is_head (only relevant for retain && !maps_coalesce), which is true for the first extent in each VirtualAlloc region. Determine if two extents can be merged based on the head state, and use serial numbers for sanity checks.
This can only happen on Windows and with opt.retain disabled (which isn't the default). The solution is suboptimal, however not a common case as retain is the long term plan for all platforms anyway.
|
@j0t : thanks again for sharing the details! I checked the stats and they looked good; also added a new counter in #1553 to detect the problematic behavior just in case. For the profiling related fix, please feel free to submit when ready; we have a 5.2.1 release coming in a couple of weeks, if it's a small-ish change we can still include it. |
@interwq, oh, thanks, that's nice! Will check this counter later.
Currently I'm struggling with some build/makefile issues related to CYGWIN specific, carefully trying |


The VirtualAlloc and VirtualFree APIs are different because MEM_DECOMMIT cannot
be used across multiple VirtualAlloc regions. To properly support decommit, only
allow merge / split within the same region -- this is done by not merging extents
with different serial numbers (w/ opt.retain).