1
1
#ifndef LLAMA_UTIL_H
2
2
#define LLAMA_UTIL_H
3
3
4
- #define _CRT_SECURE_NO_WARNINGS
5
-
6
4
#include < cstdio>
7
5
#include < cstdint>
8
6
#include < cerrno>
26
24
#if defined(_WIN32)
27
25
#define WIN32_LEAN_AND_MEAN
28
26
#define NOMINMAX
29
- #include < Windows .h>
27
+ #include < windows .h>
30
28
#include < io.h>
31
29
#include < stdio.h> // for _fseeki64
32
30
#endif
@@ -238,7 +236,7 @@ struct llama_mmap {
238
236
struct llama_mlock {
239
237
void * addr = NULL ;
240
238
size_t size = 0 ;
241
- bool failed_already = false ;
239
+ bool failed_already = false ;
242
240
243
241
llama_mlock () {}
244
242
llama_mlock (const llama_mlock &) = delete ;
@@ -318,7 +316,7 @@ struct llama_mlock {
318
316
return true ;
319
317
}
320
318
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 " ,
322
320
size, this ->size , llama_format_win_err (GetLastError ()).c_str ());
323
321
return false ;
324
322
}
@@ -331,8 +329,13 @@ struct llama_mlock {
331
329
llama_format_win_err (GetLastError ()).c_str ());
332
330
return false ;
333
331
}
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;
336
339
max_ws_size += size;
337
340
if (!SetProcessWorkingSetSize (GetCurrentProcess (), min_ws_size, max_ws_size)) {
338
341
fprintf (stderr, " warning: SetProcessWorkingSetSize failed: %s\n " ,
0 commit comments