Conversation
This replaces the 2048-entry hash table in check_no_duplicates (16 KB on 64-bit) with Floyd's tortoise-and-hare cycle detection inlined into the Phase 2 free-list walk. A duplicate block in a singly-linked free list necessarily creates a cycle, which Floyd's algorithm detects in O(n) time with O(1) space. Cross-bin duplicates cannot escape detection because Phase 2 already validates mapping(block_size(block)) == (fl, sl) for every entry; block in the wrong bin fails that check before any cycle could form across bins. It removes the separate block_in_free_list lookup from Phase 1 (the physical block walk), eliminating an O(n^2) worst-case path. - Stack: ~16 KB → 8 bytes (one pointer per bin walk) - Time: O(n²) worst-case → O(n) total across all phases - Coverage: no silent skip above 1433 free blocks (old 70% load cap) - Termination: Phase 2 can no longer hang on corrupted cyclic lists
WCET Results (x86-64) |
WCET Results (arm64) |
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.
This replaces the 2048-entry hash table in check_no_duplicates (16 KB on 64-bit) with Floyd's tortoise-and-hare cycle detection inlined into the Phase 2 free-list walk. A duplicate block in a singly-linked free list necessarily creates a cycle, which Floyd's algorithm detects in O(n) time with O(1) space.
Cross-bin duplicates cannot escape detection because Phase 2 already validates mapping(block_size(block)) == (fl, sl) for every entry; block in the wrong bin fails that check before any cycle could form across bins.
It removes the separate block_in_free_list lookup from Phase 1 (the physical block walk), eliminating an O(n^2) worst-case path.
Summary by cubic
Replace the 16 KB hash-table duplicate check in tlsf_check with O(1) Floyd cycle detection during the free-list walk. This cuts stack usage to one pointer per bin (~8 bytes), removes an O(n²) path, and keeps duplicate detection reliable without skips or hangs.
Refactors
Bug Fixes
Written for commit be1e0af. Summary will update on new commits.