-
Notifications
You must be signed in to change notification settings - Fork 656
Limit the maximum number of items stored in a fixed-size poll allocator. #6158
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Michal Zientkiewicz <[email protected]>
| if (ptr) | ||
| res.deallocate(ptr, size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this succeed once with plain host mem - in this case, even if the test fails, we should free the memory.
|
CI MESSAGE: [41737713]: BUILD STARTED |
Greptile SummaryFixed unbounded memory growth in thread-local memory pool allocators by adding a threshold-based size limit. When the free list exceeds the threshold (default 1024 items), it trims down to half the threshold during deallocation. Key Changes:
Impact: Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Thread1 as Thread 1
participant Thread2 as Thread 2
participant Allocator as fixed_size_allocator<br/>(thread_local)
participant FreeList as Free List
Note over Thread1,FreeList: Before fix: unbounded growth
Thread1->>Allocator: allocate()
Allocator->>FreeList: pop from free_list
Note over FreeList: count-- (new in PR)
Allocator-->>Thread1: return block
Thread2->>Allocator: deallocate(block)
Allocator->>FreeList: push to free_list
Note over FreeList: count++ (new in PR)
Note over Allocator: If count > threshold
Allocator->>Allocator: Trim to threshold/2
loop while count > threshold/2
Allocator->>FreeList: pop block
Allocator->>Allocator: free(block)
Note over FreeList: count--
end
Note over Thread1,FreeList: Prevents unbounded memory growth<br/>when threads have imbalanced alloc/dealloc
|
| free_list_ = bptr; | ||
| count_++; | ||
| if (threshold && count_ > threshold) { | ||
| while (count_ > threshold / 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why threshold / 2?
Category:
Bug fix (non-breaking change which fixes an issue)
Description:
Reported in #6153
The auxiliary thread-local pool could grow indefinitely when there was imbalance between threads (one thread caused allocation of auxiliary blocks and the other returned them to the pool and they were never reused).
Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
We don't have facilities for memory consumption testing. The repro from #6153 no longer increases memory consumption.
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A