From 2a8ba70e235e5807cb27e734ce8faec1b1ec21de Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 2 Nov 2023 10:23:31 +0100 Subject: [PATCH] limit the ram usage of ffmpeg --- src/render/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/render/mod.rs b/src/render/mod.rs index 1c963e0..b5ea7e4 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -21,6 +21,8 @@ use std::{ process::{Command, Stdio} }; +const MEMORY_LIMIT: &str = "2G"; + const INTRO_LEN: Time = Time { seconds: 3, micros: 0 @@ -39,8 +41,18 @@ const FF_LOGO_SIZE: usize = 128; const LOGO_SIZE: usize = 96; fn cmd() -> Command { - let mut cmd = Command::new("busybox"); - cmd.arg("ash") + // we use systemd-run to limit the process memory + // I tried others like ulimit, chpst or isolate, but none worked + let mut cmd = Command::new("systemd-run"); + cmd.arg("--scope") + .arg("-q") + .arg("--expand-environment=no") + .arg("-p") + .arg(format!("MemoryMax={MEMORY_LIMIT}")) + .arg("--user"); + // we use busybox ash for having a shell that outputs commands with -x + cmd.arg("busybox") + .arg("ash") .arg("-exuo") .arg("pipefail") .arg("-c")