diff --git a/Makefile b/Makefile index ecd1f5e6..48b08161 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ VERSION=$(shell git rev-parse --short HEAD) endif BUILDTIME=$(shell date -u) -GOBUILD=CGO_ENABLED=0 go build -tags with_gvisor -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ +GOBUILD=CGO_ENABLED=0 go build -tags with_gvisor,with_low_memory -trimpath -ldflags '-X "github.com/Dreamacro/clash/constant.Version=$(VERSION)" \ -X "github.com/Dreamacro/clash/constant.BuildTime=$(BUILDTIME)" \ -w -s -buildid=' diff --git a/common/pool/buffer_low_memory.go b/common/pool/buffer_low_memory.go new file mode 100644 index 00000000..24e18a75 --- /dev/null +++ b/common/pool/buffer_low_memory.go @@ -0,0 +1,15 @@ +//go:build with_low_memory + +package pool + +const ( + // io.Copy default buffer size is 32 KiB + // but the maximum packet size of vmess/shadowsocks is about 16 KiB + // so define a buffer of 20 KiB to reduce the memory of each TCP relay + RelayBufferSize = 16 * 1024 + + // RelayBufferSize uses 20KiB, but due to the allocator it will actually + // request 32Kib. Most UDPs are smaller than the MTU, and the TUN's MTU + // set to 9000, so the UDP Buffer size set to 16Kib + UDPBufferSize = 8 * 1024 +) diff --git a/common/pool/buffer_standard.go b/common/pool/buffer_standard.go new file mode 100644 index 00000000..ff758700 --- /dev/null +++ b/common/pool/buffer_standard.go @@ -0,0 +1,15 @@ +//go:build !with_low_memory + +package pool + +const ( + // io.Copy default buffer size is 32 KiB + // but the maximum packet size of vmess/shadowsocks is about 16 KiB + // so define a buffer of 20 KiB to reduce the memory of each TCP relay + RelayBufferSize = 20 * 1024 + + // RelayBufferSize uses 20KiB, but due to the allocator it will actually + // request 32Kib. Most UDPs are smaller than the MTU, and the TUN's MTU + // set to 9000, so the UDP Buffer size set to 16Kib + UDPBufferSize = 16 * 1024 +) diff --git a/common/pool/pool.go b/common/pool/pool.go index bee4887f..288ea467 100644 --- a/common/pool/pool.go +++ b/common/pool/pool.go @@ -1,17 +1,5 @@ package pool -const ( - // io.Copy default buffer size is 32 KiB - // but the maximum packet size of vmess/shadowsocks is about 16 KiB - // so define a buffer of 20 KiB to reduce the memory of each TCP relay - RelayBufferSize = 20 * 1024 - - // RelayBufferSize uses 20KiB, but due to the allocator it will actually - // request 32Kib. Most UDPs are smaller than the MTU, and the TUN's MTU - // set to 9000, so the UDP Buffer size set to 16Kib - UDPBufferSize = 16 * 1024 -) - func Get(size int) []byte { return defaultAllocator.Get(size) }