Skip to content

Commit e3c91b5

Browse files
committed
PR feedback + make VirtualLock actually work
1 parent 64a5190 commit e3c91b5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ if (LLAMA_ALL_WARNINGS)
152152

153153
endif()
154154

155+
if (MSVC)
156+
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
157+
endif()
158+
155159
if (LLAMA_LTO)
156160
include(CheckIPOSupported)
157161
check_ipo_supported(RESULT result OUTPUT output)

llama.cpp

100755100644
File mode changed.

llama_util.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#ifndef LLAMA_UTIL_H
22
#define LLAMA_UTIL_H
33

4-
#define _CRT_SECURE_NO_WARNINGS
5-
64
#include <cstdio>
75
#include <cstdint>
86
#include <cerrno>
@@ -26,7 +24,7 @@
2624
#if defined(_WIN32)
2725
#define WIN32_LEAN_AND_MEAN
2826
#define NOMINMAX
29-
#include <Windows.h>
27+
#include <windows.h>
3028
#include <io.h>
3129
#include <stdio.h> // for _fseeki64
3230
#endif
@@ -238,7 +236,7 @@ struct llama_mmap {
238236
struct llama_mlock {
239237
void * addr = NULL;
240238
size_t size = 0;
241-
bool failed_already = false;
239+
bool failed_already = false;
242240

243241
llama_mlock() {}
244242
llama_mlock(const llama_mlock &) = delete;
@@ -318,7 +316,7 @@ struct llama_mlock {
318316
return true;
319317
}
320318
if (tries == 2) {
321-
fprintf(stderr, "warning: failed to VirtualLock %zu-byte buffer (after previously locking %zu bytes): %s\n",
319+
fprintf(stderr, "warning: failed to VirtualLock %zu-byte buffer (after previously locking %zu bytes): %s\n",
322320
size, this->size, llama_format_win_err(GetLastError()).c_str());
323321
return false;
324322
}
@@ -331,8 +329,13 @@ struct llama_mlock {
331329
llama_format_win_err(GetLastError()).c_str());
332330
return false;
333331
}
334-
// No way to make this atomic, so hopefully nobody is doing the
335-
// same on other threads.
332+
// Per MSDN: "The maximum number of pages that a process can lock
333+
// is equal to the number of pages in its minimum working set minus
334+
// a small overhead."
335+
// Hopefully a megabyte is enough overhead:
336+
size_t increment = size + 1048576;
337+
// The minimum must be <= the maximum, so we need to increase both:
338+
min_ws_size += size;
336339
max_ws_size += size;
337340
if (!SetProcessWorkingSetSize(GetCurrentProcess(), min_ws_size, max_ws_size)) {
338341
fprintf(stderr, "warning: SetProcessWorkingSetSize failed: %s\n",

0 commit comments

Comments
 (0)