Skip to content

Commit

Permalink
model: deprecate strict_memory_limit to percise definition
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Oct 30, 2023
1 parent eded6e0 commit 2f24785
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 201 deletions.
4 changes: 2 additions & 2 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ interface Cmd {
procLimit?: number; // 线程数量限制
cpuRateLimit?: number; // 仅 Linux,CPU 使用率限制,1000 等于单核 100%
cpuSetLimit?: string; // 仅 Linux,限制 CPU 使用,使用方式和 cpuset cgroup 相同 (例如,`0` 表示限制仅使用第一个核)
strictMemoryLimit?: boolean; // 开启严格内存限制 (仅 Linux,设置 rlimit 内存限制)
strictMemoryLimit?: boolean; // deprecated: 使用 dataSegmentLimit (这个选项依然有效)
dataSegmentLimit?: boolean; // 仅linux,开启 rlimit 堆空间限制(如果不使用cgroup默认开启)
addressSpaceLimit?: boolean; // 仅linux,开启 rlimit 虚拟内存空间限制(非常严格,在所以申请时触发限制)

// 在执行程序之前复制进容器的文件列表
Expand Down Expand Up @@ -242,7 +243,6 @@ interface WSResult {
"cpuLimit": 10000000000,
"memoryLimit": 104857600,
"procLimit": 50,
"strictMemoryLimit": false,
"copyIn": {
"a": {
"fileId": "5LWIZAA45JHX4Y4Z" // 这个缓存文件的 ID 来自上一个请求返回的 fileIds
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ interface Cmd {
procLimit?: number;
cpuRateLimit?: number; // limit cpu usage (1000 equals 1 cpu)
cpuSetLimit?: string; // Linux only: set the cpuSet for cgroup
strictMemoryLimit?: boolean; // Linux only: use stricter memory limit (+ rlimit_data when cgroup enabled)
strictMemoryLimit?: boolean; // deprecated: use dataSegmentLimit instead (still working)
dataSegmentLimit?: boolean; // Linux only: use (+ rlimit_data limit) enable by default if cgroup not enabled
addressSpaceLimit?: boolean; // Linux only: use (+ rlimit_address_space limit)

// copy the correspond file to the container dst path
Expand Down Expand Up @@ -375,7 +376,6 @@ Plese use PostMan or similar tools to send request to `http://localhost:5050/run
"cpuLimit": 10000000000,
"memoryLimit": 104857600,
"procLimit": 50,
"strictMemoryLimit": false,
"copyIn": {
"a": {
"fileId": "5LWIZAA45JHX4Y4Z"
Expand Down
2 changes: 1 addition & 1 deletion cmd/executorserver/grpc_executor/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func convertPBCmd(c *pb.Request_CmdType, srcPrefix []string) (cm worker.Cmd, str
ProcLimit: c.GetProcLimit(),
CPURateLimit: c.GetCpuRateLimit(),
CPUSetLimit: c.GetCpuSetLimit(),
StrictMemoryLimit: c.GetStrictMemoryLimit(),
DataSegmentLimit: c.GetDataSegmentLimit(),
AddressSpaceLimit: c.GetAddressSpaceLimit(),
CopyOut: convertCopyOut(c.GetCopyOut()),
CopyOutCached: convertCopyOut(c.GetCopyOutCached()),
Expand Down
3 changes: 2 additions & 1 deletion cmd/executorserver/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Cmd struct {

TTY bool `json:"tty,omitempty"`
StrictMemoryLimit bool `json:"strictMemoryLimit"`
DataSegmentLimit bool `json:"dataSegmentLimit"`
AddressSpaceLimit bool `json:"addressSpaceLimit"`
}

Expand Down Expand Up @@ -257,7 +258,7 @@ func convertCmd(c Cmd, srcPrefix []string) (worker.Cmd, error) {
ProcLimit: c.ProcLimit,
CPURateLimit: c.CPURateLimit,
CPUSetLimit: c.CPUSetLimit,
StrictMemoryLimit: c.StrictMemoryLimit,
DataSegmentLimit: c.DataSegmentLimit || c.StrictMemoryLimit,
AddressSpaceLimit: c.AddressSpaceLimit,
CopyOut: convertCopyOut(c.CopyOut),
CopyOutCached: convertCopyOut(c.CopyOutCached),
Expand Down
2 changes: 1 addition & 1 deletion env/linuxcontainer/environment_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *environ) Execve(ctx context.Context, param envexec.ExecveParam) (envexe
DisableCore: true,
}

if limit.StrictMemory || c.cgPool == nil {
if limit.DataSegment || c.cgPool == nil {
rLimits.Data = limit.Memory.Byte()
}
if limit.AddressSpace {
Expand Down
2 changes: 1 addition & 1 deletion envexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Cmd struct {

// additional memory option
AddressSpaceLimit bool
StrictMemoryLimit bool
DataSegmentLimit bool
}

// CmdCopyOutFile defines the file to be copy out after cmd execution
Expand Down
2 changes: 1 addition & 1 deletion envexec/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Limit struct {
Rate uint64 // CPU Rate limit
OpenFile uint64 // Number of open files
CPUSet string // CPU set limit
StrictMemory bool // Use stricter memory limit (e.g. rlimit)
DataSegment bool // Use stricter memory limit (e.g. rlimit)
AddressSpace bool // rlimit address space
}

Expand Down
2 changes: 1 addition & 1 deletion envexec/run_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func runSingleExecve(ctx context.Context, m Environment, c *Cmd, fds []*os.File)
Rate: c.CPURateLimit,
OpenFile: c.OpenFileLimit,
CPUSet: c.CPUSetLimit,
StrictMemory: c.StrictMemoryLimit,
DataSegment: c.DataSegmentLimit,
AddressSpace: c.AddressSpaceLimit,
},
}
Expand Down
Loading

0 comments on commit 2f24785

Please sign in to comment.