#!/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.")