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
Recompacting the heap can segfault with best-fit #9736
Comments
Nice catch, but I don't think it can be triggered on 64-bit. Here's why:
Still, the bug could trigger on 32-bit. Moreover, I would like to maintain the property that compaction can be done whenever the major GC is idle (i.e. at the end of any sweep phase) and it is broken by this remnant business. I'll submit a PR soon. |
To be clear, I found this bug by it happening on a 64bit machine. I think that recompaction can happen with more than one heap chunk, and indeed in the case where I saw this bug recompaction was triggered with 3 heap chunks. The small block was not in the large chunk with left-over space but in one of the smaller chunks. |
Oh that's right I didn't think of this case. |
The best-fit allocator must prepare the heap for compaction. Fixes #9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
(cherry-picked from commit 85e4563)
(cherry-picked from commit 85e4563)
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
The best-fit allocator must prepare the heap for compaction. Fixes ocaml#9736
When compaction has finished rearranging all the blocks into the earliest chunks, it has to add any left over space in the remaining chunks to the free list. Which it does with the call to
caml_make_free_blocks
currently on line 423 of compact.c. Whilst not generally guaranteed by calls to this function, historically this would always produceCaml_blue
blocks because they could not be merged with anything else around them. With best-fit however, these blocks make now beCaml_white
if they are less than 16 words.Making the new free blocks
Caml_white
is not normally a problem, because they will only be seen bysweep_slice
which does not care about their contents. However, very rarely a "recompaction" is triggered, which immediately does a second compaction. Compaction scansCaml_white
blocks looking for pointers to reverse. Since the data in theseCaml_white
blocks is essentially arbitrary this can easily segfault.I'm not sure what the best fix is. The blocks going onto the freelist could possibly be given a no scan tag. The compactor could possibly treat
Caml_white
blocks as free. Either or those seems fine to me, but I'm not confident enough in my knowledge of all the invariants in the GC to make the decision.The text was updated successfully, but these errors were encountered: