Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

lol

Layle2c49afa1a86a
diff --git a/crates/screenshotter/src/main.rs b/crates/screenshotter/src/main.rs
index 85df6fd..5105949 100644
--- a/crates/screenshotter/src/main.rs
+++ b/crates/screenshotter/src/main.rs
@@ -3,9 +3,11 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::{Arc, Mutex};
-const WORKER_COUNT: usize = 1;
+const WORKER_COUNT: usize = 4;
const WORKER_BIN: &str = "screenshotter-worker";
+const WORKER_MEM_MAX_DEFAULT: &str = "8G";
+
fn main() {
let input_dir = PathBuf::from(
std::env::args()
@@ -53,11 +55,22 @@ fn main() {
std::process::exit(1);
}
+ let mem_max = std::env::var("GECKO_WORKER_MEM_MAX").unwrap_or_else(|_| WORKER_MEM_MAX_DEFAULT.to_owned());
+ let capped = cgroup_cap_available();
+ if capped {
+ println!(
+ "Confining each worker to a {mem_max} memory-capped cgroup scope (override with GECKO_WORKER_MEM_MAX)."
+ );
+ } else {
+ eprintln!("fuckyfucky");
+ }
+
let queue: Arc<Mutex<Vec<PathBuf>>> = Arc::new(Mutex::new(files));
let mut handles = Vec::with_capacity(WORKER_COUNT);
for worker_id in 0..WORKER_COUNT {
let queue = queue.clone();
let worker_exe = worker_exe.clone();
+ let mem_max = mem_max.clone();
handles.push(
std::thread::Builder::new()
.name(format!("screenshotter-{worker_id}"))
@@ -68,7 +81,7 @@ fn main() {
None => return,
};
- match Command::new(&worker_exe).arg(&file).status() {
+ match worker_command(&worker_exe, &file, capped, &mem_max).status() {
Ok(status) if status.success() => {}
Ok(status) => {
eprintln!("Skipping {}: worker exited with {}", file.display(), status,);
@@ -90,6 +103,41 @@ fn main() {
cleanup("screenshotdb");
}
+fn worker_command(worker_exe: &Path, file: &Path, capped: bool, mem_max: &str) -> Command {
+ if !capped {
+ let mut cmd = Command::new(worker_exe);
+ cmd.arg(file);
+ return cmd;
+ }
+
+ let mut cmd = Command::new("systemd-run");
+ cmd.args(["--user", "--scope", "--quiet", "--collect"])
+ .arg("-p")
+ .arg(format!("MemoryMax={mem_max}"))
+ .arg("-p")
+ .arg("MemorySwapMax=0")
+ .arg("--")
+ .arg(worker_exe)
+ .arg(file);
+ cmd
+}
+
+#[cfg(target_os = "linux")]
+fn cgroup_cap_available() -> bool {
+ Command::new("systemd-run")
+ .args(["--user", "--scope", "--quiet", "-p", "MemoryMax=64M", "--", "true"])
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .status()
+ .map(|s| s.success())
+ .unwrap_or(false)
+}
+
+#[cfg(not(target_os = "linux"))]
+fn cgroup_cap_available() -> bool {
+ false
+}
+
fn hash_or_delete_unicolor(path: &Path) -> Option<u64> {
let file = std::fs::File::open(path).ok()?;
let decoder = png::Decoder::new(std::io::BufReader::new(file));
diff --git a/other/game_index_wii.txt b/other/game_index_wii.txt
index 4cdd4c3..1cd286a 100644
--- a/other/game_index_wii.txt
+++ b/other/game_index_wii.txt
@@ -36,4 +36,5 @@ SLRE=LEGO The Lord of the Rings (USA) (En,Fr,Es,Pt)
SMNE=New Super Mario Bros. Wii (USA) (En,Fr,Es) (Rev 2)
SOJE=Rayman Origins (USA) (En,Fr,Es)
SOUE=Legend of Zelda, The - Skyward Sword (USA) (En,Fr,Es)
+SSQE=Mario Party 9 (USA, Asia) (En,Fr,Es)
SUKE=Kirby's Return to Dream Land (USA) (En,Fr,Es)