Download root-scripts/clean_memory_cache.py from hipinis/20260718: direct link, hf CLI and curl.
- Browser
- Download file 543 Bytes
-
https://huggingface.co/hipinis/20260718/resolve/main/root-scripts/clean_memory_cache.py
- Command line
-
hf download hf://hipinis/20260718/root-scripts/clean_memory_cache.py
-
curl -L -o clean_memory_cache.py https://huggingface.co/hipinis/20260718/resolve/main/root-scripts/clean_memory_cache.py
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.") | |