sinelaw/fresh · warning · io::Error (InvalidData)
Could not parse MemTotal from /proc/meminfo
Error message
Could not parse MemTotal from /proc/meminfo
What it means
linux_total_memory_mb() parses /proc/meminfo looking for the MemTotal line, expecting a value in kB. If the file exists but no MemTotal entry can be found/parsed (or the file is empty/malformed), it returns io::ErrorKind::InvalidData with this message, since memory size cannot be established for limit enforcement.
Solutions
- Verify /proc/meminfo contains a MemTotal line (cat /proc/meminfo | grep MemTotal)
- Unmask /proc/meminfo in the container (remove volume/bind mounts hiding it)
- Fall back to getrusage/sysinfo(2) syscall or the sysinfo crate if procfs is unavailable
- Treat the error as non-fatal and skip memory limiting
Example fix
// before
let mem = total_memory_mb()?;
// after
let mem = total_memory_mb().unwrap_or_else(|e| {
log::warn!("memory detect failed: {e}; skipping limits");
u64::MAX
}); Defensive patterns
Strategy: fallback
Validate before calling
let meminfo = std::fs::read_to_string("/proc/meminfo")?;
let ok = meminfo.lines().any(|l| l.starts_with("MemTotal:"));
if !ok { /* skip limits or use fallback */ } Try / catch
match total_memory_mb() { Ok(mb) => apply_limit(mb), Err(e) if e.kind() == io::ErrorKind::InvalidData => log::warn!("procfs unreadable: {e}"), Err(e) => return Err(e.into()), } Prevention
- In containers, ensure /proc/meminfo is not masked
- Provide a syscall-based fallback (sysinfo(2)) for hardened environments
- Treat limit detection as best-effort, never a hard startup dependency
When it happens
Trigger: Calling total_memory_mb() on Linux when /proc/meminfo lacks a parseable 'MemTotal: <n> kB' line — e.g. exotic kernels, restricted containers with masked /proc/meminfo, or locale/number formatting anomalies in the file.
Common situations: Running inside a container where /proc is remounted or partially masked; non-standard embedded Linux without full procfs; security hardening that hides meminfo fields.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Failed to load config from
- Failed to create QuickJS runtime
- Failed to create QuickJS context
- Memory detection not implemented for this platform
AI-assisted analysis of sinelaw/fresh@67894ca546 (2026-09-13).
Data as JSON: /api/errors/5ad8870e4cd27b47.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fresh-editor-core/src/process_limits.rs:342
#[cfg(target_os = "linux")]
fn linux_total_memory_mb() -> io::Result<u64> {
// Read from /proc/meminfo
let meminfo = std::fs::read_to_string("/proc/meminfo")?;
for line in meminfo.lines() {
if line.starts_with("MemTotal:") {
// Format: "MemTotal: 16384000 kB"
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 2 {
if let Ok(kb) = parts[1].parse::<u64>() {
return Ok(kb / 1024); // Convert KB to MB
}
}
}
}
Err(io::Error::new(
io::ErrorKind::InvalidData,
"Could not parse MemTotal from /proc/meminfo",
))
}
/// Get total number of CPU cores
pub fn cpu_count() -> io::Result<usize> {
#[cfg(target_os = "linux")]
{
Ok(num_cpus())
}
#[cfg(not(target_os = "linux"))]
{
// TODO: Implement for other platforms
Err(io::Error::new(
io::ErrorKind::Unsupported,
"CPU detection not implemented for this platform",View on GitHub (pinned to 67894ca546)