20260718 / root-scripts /clean_memory_cache.py
hipinis's picture
env backup 2026-11-08 from 4090: root-scripts/clean_memory_cache.py
5828fd9 verified
Raw History Blame Contribute Delete
543 Bytes
#!/usr/bin/env python3
"""利用 POSIX_FADV_DONTNEED 主动释放大模型加载产生的 Page Cache"""
import os
def drop_page_cache(path):
try:
fd = os.open(path, os.O_RDONLY)
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)
os.close(fd)
except Exception:
pass
for root in ("/workspace/ComfyUI/models", "/workspace/ComfyUI/output"):
for dirpath, _, filenames in os.walk(root):
for fn in filenames:
drop_page_cache(os.path.join(dirpath, fn))
print("Page cache trimmed.")