From 5fb8a1b6e177708178acedd5b89b125fc9039b8e Mon Sep 17 00:00:00 2001 From: ocha98 <48848793+ocha98@users.noreply.github.com> Date: Sat, 25 Nov 2023 14:40:51 +0900 Subject: [PATCH] [Fix] memory issue in judge system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `judge.go` メモリ制限を262144から1024*1024へ変更 `run.go` `ulimit`のメモリ制限を`-m`から`-v`へ変更 終了ステータスに関わらず`TLE`、`MLE`を判定 --- mojacoder-backend/judge-image/judge.go | 2 +- mojacoder-backend/judge-image/run.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mojacoder-backend/judge-image/judge.go b/mojacoder-backend/judge-image/judge.go index b3f6d73..7871fb8 100644 --- a/mojacoder-backend/judge-image/judge.go +++ b/mojacoder-backend/judge-image/judge.go @@ -88,7 +88,7 @@ func judge(definition LanguageDefinition, data JudgeQueueData) error { return fmt.Errorf(errorMessage, err) } stdoutWriter := strings.Builder{} - result, err := run(definition, inTestcaseFile, &stdoutWriter, nil, 2, 262144) + result, err := run(definition, inTestcaseFile, &stdoutWriter, nil, 2, 1024*1024) if err != nil { return fmt.Errorf(errorMessage, err) } diff --git a/mojacoder-backend/judge-image/run.go b/mojacoder-backend/judge-image/run.go index 340ca6c..8f8a881 100644 --- a/mojacoder-backend/judge-image/run.go +++ b/mojacoder-backend/judge-image/run.go @@ -27,7 +27,8 @@ type RunResult struct { func run(definition LanguageDefinition, stdin io.Reader, stdout io.Writer, stderr io.Writer, timeLimit, memoryLimit int) (RunResult, error) { var result RunResult var err error - command := fmt.Sprintf("ulimit -u 32 -m %d && timeout --preserve-status -sSIGKILL %d %s; EXIT_CODE=$?; kill -SIGKILL -1; wait; exit $EXIT_CODE", memoryLimit, timeLimit, definition.RunCommand) + additional_memory := 5 * 1024 + command := fmt.Sprintf("ulimit -u 32 -v %d && timeout --preserve-status -sSIGKILL %d %s; EXIT_CODE=$?; kill -SIGKILL -1; wait; exit $EXIT_CODE", memoryLimit+additional_memory, timeLimit, definition.RunCommand) cmd := exec.Command("bash", "-c", command) cmd.Env = []string{} cmd.Dir = TEMP_DIR @@ -47,14 +48,13 @@ func run(definition LanguageDefinition, stdin io.Reader, stdout io.Writer, stder result.exitCode = cmd.ProcessState.ExitCode() result.time = int((end.Sub(start)).Milliseconds()) result.memory = int(cmd.ProcessState.SysUsage().(*syscall.Rusage).Maxrss) - if !cmd.ProcessState.Success() { - if result.time > timeLimit*1000 { - result.status = RunResultStatusTimeLimitExceeded - } else if result.memory > memoryLimit { - result.status = RunResultStatusMemoryLimitExceeded - } else { - result.status = RunResultStatusRunTimeError - } + + if result.time > timeLimit*1000 { + result.status = RunResultStatusTimeLimitExceeded + } else if result.memory > memoryLimit { + result.status = RunResultStatusMemoryLimitExceeded + } else if !cmd.ProcessState.Success() { + result.status = RunResultStatusRunTimeError } return result, nil }