-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(stream): fast buffer freeing for large cache #1053
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
Conversation
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.
Pull Request Overview
This PR introduces a memory management optimization for large buffer allocations by adding support for anonymous mmap allocation. The feature enables faster memory freeing for large caches through a configurable threshold.
Key changes:
- Adds
MinMmapAllocSize
configuration option (default 4MB) to control when mmap allocation is used - Replaces
sync.Pool
with a custom genericPool[T]
implementation for better type safety - Implements mmap-based buffer allocation for buffers exceeding the threshold size
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
pkg/pool/pool.go | Introduces new generic pool implementation with capacity limits |
internal/stream/util.go | Updates buffer pool to use custom pool and mmap allocation for large buffers |
internal/stream/stream.go | Adds mmap allocation support for file stream caching |
internal/net/request.go | Refactors Buf struct to use direct byte slice with mmap support instead of bytes.Buffer |
internal/conf/var.go | Adds MinMmapAllocSize configuration variable |
internal/conf/config.go | Adds MinMmapAllocSize field to Config struct with default value |
internal/bootstrap/config.go | Initializes MinMmapAllocSize from configuration |
internal/stream/stream_test.go | Updates test configuration and test name |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: j2rong4cn <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: j2rong4cn <[email protected]>
添加配置选项 mmap_thresholdMB
默认为4 单位:MB
大于或等于该大小的[]byte将使用
匿名mmap
来达到快速释放内存占用的目的