File size: 543 Bytes
5828fd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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.")