Skip to content

Commit f531fe8

Browse files
committed
VirtualAlloc(.., MEM_RESET)
1 parent 781cdb9 commit f531fe8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

llama.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,27 +1653,31 @@ struct llama_anonymous_mmap : llama_mmap {
16531653
}
16541654
}
16551655

1656-
#if _WIN32_WINNT >= 0x603
16571656
void unmap_fragment(size_t first, size_t last) override {
1657+
SYSTEM_INFO siSysInfo;
1658+
GetSystemInfo(&siSysInfo);
1659+
DWORD dwPageSize = siSysInfo.dwPageSize;
1660+
1661+
align_to_next_page(&first, dwPageSize);
1662+
align_to_previous_page(&last, dwPageSize);
1663+
1664+
#if _WIN32_WINNT >= 0x603
16581665
DWORD (WINAPI *pOfferVirtualMemory) (PVOID, SIZE_T, DWORD);
16591666
HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
16601667

16611668
pOfferVirtualMemory = reinterpret_cast<decltype(pOfferVirtualMemory)> (GetProcAddress(hKernel32, "OfferVirtualMemory"));
16621669

16631670
if (pOfferVirtualMemory) {
1664-
SYSTEM_INFO siSysInfo;
1665-
GetSystemInfo(&siSysInfo);
1666-
DWORD dwPageSize = siSysInfo.dwPageSize;
1667-
1668-
align_to_next_page(&first, dwPageSize);
1669-
align_to_previous_page(&last, dwPageSize);
1670-
16711671
if (pOfferVirtualMemory((char *) addr + first, last - first, 0x00000004 /* VMOfferPriorityNormal */)) {
16721672
LLAMA_LOG_WARN("warning: OfferVirtualMemory failed: %s\n", llama_format_win_err(GetLastError()).c_str());
16731673
}
16741674
}
1675-
}
1675+
#else
1676+
if (VirtualAlloc((char *) addr + first, last - first, MEM_RESET, PAGE_NOACCESS)) {
1677+
LLAMA_LOG_WARN("warning: VirtualAlloc(.., MEM_RESET) failed: %s\n", llama_format_win_err(GetLastError()).c_str());
1678+
}
16761679
#endif
1680+
}
16771681

16781682
#else
16791683
llama_anonymous_mmap(struct llama_file * file) {

0 commit comments

Comments
 (0)