mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-08-17 16:37:30 +02:00
Add a POSIX sysconf fallback for local RAM detection
Retain the unsuperseded macOS RAM-detection contribution from PR #13 while making every optional probe fail closed. The shared MPS device, loader, cache, and dtype work is already present on current main and is intentionally not duplicated.
This commit is contained in:
committed by
Joseph Magly
parent
ff0a298c6d
commit
6c21ee243d
+21
-10
@@ -100,16 +100,27 @@ def _get_ram_gb() -> float:
|
||||
import psutil
|
||||
|
||||
return round(psutil.virtual_memory().total / 1024**3, 1)
|
||||
except ImportError:
|
||||
# Fallback: read from /proc/meminfo on Linux
|
||||
try:
|
||||
with open("/proc/meminfo") as f:
|
||||
for line in f:
|
||||
if line.startswith("MemTotal:"):
|
||||
kb = int(line.split()[1])
|
||||
return round(kb / 1024**2, 1)
|
||||
except Exception:
|
||||
pass
|
||||
except (AttributeError, ImportError, OSError, RuntimeError, ValueError):
|
||||
pass
|
||||
|
||||
# Fallback: read from /proc/meminfo on Linux.
|
||||
try:
|
||||
with open("/proc/meminfo") as f:
|
||||
for line in f:
|
||||
if line.startswith("MemTotal:"):
|
||||
kb = int(line.split()[1])
|
||||
return round(kb / 1024**2, 1)
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
|
||||
# macOS and other POSIX systems generally expose physical RAM via sysconf.
|
||||
try:
|
||||
pages = os.sysconf("SC_PHYS_PAGES")
|
||||
page_size = os.sysconf("SC_PAGE_SIZE")
|
||||
if pages > 0 and page_size > 0:
|
||||
return round(pages * page_size / 1024**3, 1)
|
||||
except (AttributeError, OSError, ValueError):
|
||||
pass
|
||||
return 0.0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user