Skip to content

Conversation

j2rong4cn
Copy link
Member

@j2rong4cn j2rong4cn commented Aug 14, 2025

添加配置选项 mmap_thresholdMB

默认为4 单位:MB
大于或等于该大小的[]byte将使用匿名mmap来达到快速释放内存占用的目的

@dezhishen dezhishen requested a review from Copilot August 14, 2025 12:52
Copilot

This comment was marked as outdated.

@j2rong4cn j2rong4cn requested a review from Copilot August 16, 2025 08:37
Copy link
Contributor

@Copilot Copilot AI left a 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 generic Pool[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.

@j2rong4cn j2rong4cn merged commit 016ed90 into OpenListTeam:main Aug 16, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant