Repository navigation
Make HPACK safe for generational collection - #22
Merged
Merged
Conversation
One Deflater and Inflater pair encodes and decodes 20,000 header blocks. Each block repeats four headers of the previous block, which the encoder sends as indexes into the dynamic table, and adds four new ones. So the tables fill, evict their oldest entries and refill many times while the collector runs. The test asks for a 30 second timeout, since with the write-barrier checker it takes close to two seconds. The test fails on this commit with an Acton that has generational collection. With ACTON_GC_MODE=generational nghttp2 dereferences a NULL pointer in a dynamic table entry that a minor collection freed. With acton test --gc-check the checker finds new table entries and header buffers linked into the ring buffer and the inflater without a write barrier, and the test exits with status 70.
In generational mode a minor collection rescans only the heap blocks that the program recorded as written. nghttp2 links the allocations of the HPACK deflater and inflater together without a write barrier. It stores new entries into the dynamic table's ring buffer and hash map, and new header buffers into the inflater. That memory came from the ordinary GC heap, so a minor collection could free a table entry that the table still held. The allocator callbacks that Deflater and Inflater give nghttp2 now allocate from acton_malloc_rescanned, which every collection rescans. The calloc callback checks the product of its sizes for overflow and relies on acton_malloc_rescanned returning cleared memory. The realloc callback allocates from the same kind for a NULL pointer, because acton_realloc keeps the kind of an existing object but allocates ordinary memory for NULL. In ordinary mode acton_malloc_rescanned returns ordinary GC memory as before. The deflater and inflater are kept as GC pointers in u64 attributes, so the stores of those attributes now have the write barrier. This needs an Acton with the write barrier of generational collection, which provides ACTON_WBAR and acton_malloc_rescanned.
The repository had no CI. The workflow installs Acton from the tip channel on Ubuntu and runs acton test, then acton test --gc-check. The second run puts every test in generational GC mode under the write-barrier checker, which exits with status 70 at a pointer store into GC memory without its barrier. So a change that puts nghttp2's memory back on the ordinary GC heap fails CI. The checker makes the tests slower. --max-time 10000 gives each test 11 seconds instead of 3, and --min-iter 0 keeps a slow test at one run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Acton's generational GC mode a minor collection rescans only the heap blocks that the program recorded as written, so C code must put a write barrier on its pointer stores into GC memory. nghttp2 links the allocations of the HPACK deflater and inflater together by itself: it stores new entries into the dynamic table's ring buffer and hash map, and new header buffers into the inflater. That memory came from the ordinary GC heap through the allocator callbacks in src/hpack.ext.c, so a minor collection could free a table entry that the table still held.
The callbacks now allocate from acton_malloc_rescanned, which every collection rescans. The calloc callback checks for overflow, and the realloc callback allocates from the same kind when it gets a NULL pointer. The stores of the deflater and inflater pointers into their u64 attributes get ACTON_WBAR. Those two stores run while the constructor still holds the object, so the tests also pass without them, but they follow the rule for GC pointers kept in integer fields. In ordinary mode acton_malloc_rescanned returns ordinary GC memory, so nothing changes there.
The new test tables_churn_across_collections sends 20,000 header blocks through one Deflater and Inflater pair, so the dynamic tables fill, evict and refill across about 20 collections in generational mode and about 270 with the write-barrier checker. It asks for a 30 second timeout, since the checker makes it take close to two seconds. Without the fix the test crashes in every run with ACTON_GC_MODE=generational, and with acton test --gc-check it exits with status 70. With the fix all five tests pass in ordinary mode, in 10 generational runs and in 20 runs with acton test --gc-check, in both debug and --fast builds.
The repository had no CI, so this adds a workflow. On Ubuntu with Acton from the tip channel it runs acton test, and then acton test --gc-check --min-iter 0 --max-time 10000, since the checker makes some tests take longer than the default limit of 3 seconds allows. Run locally against Acton main, both steps pass with the fix, and without it the checker step fails because the new test exits with status 70.
This needs an Acton with generational collection, which provides ACTON_WBAR, acton_malloc_rescanned and acton test --gc-check. Acton main has it since actonlang/acton#3390, and CI needs a tip build from after that merge.