From 6263e6848ccb950bc4899e4bd42f32fd475e0c76 Mon Sep 17 00:00:00 2001 From: Will Miao Date: Tue, 16 Jun 2026 23:12:02 +0800 Subject: [PATCH] fix: move posix_fadvise(DONTNEED) after read loop so it actually evicts pages (#985) --- py/utils/file_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py/utils/file_utils.py b/py/utils/file_utils.py index 2dea8c66..91de5b9c 100644 --- a/py/utils/file_utils.py +++ b/py/utils/file_utils.py @@ -44,9 +44,11 @@ async def calculate_sha256(file_path: str) -> str: chunk_size = _get_hash_chunk_size_bytes() with open(file_path, "rb") as f: fd = f.fileno() - os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED) for byte_block in iter(lambda: f.read(chunk_size), b""): sha256_hash.update(byte_block) + # Evict pages after reading so the data doesn't linger in the kernel page + # cache — on WSL this otherwise appears as unreclaimable VmmemWSL growth. + os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED) return sha256_hash.hexdigest()