File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 21
21
#if defined(_POSIX_MAPPED_FILES)
22
22
#include < sys/mman.h>
23
23
#endif
24
+ #if defined(_POSIX_MEMLOCK_RANGE)
25
+ #include < sys/resource.h>
26
+ #endif
24
27
#endif
25
28
#endif
26
29
@@ -303,8 +306,18 @@ struct llama_mlock {
303
306
if (!mlock (addr, size)) {
304
307
return true ;
305
308
} else {
306
- fprintf (stderr, " warning: failed to mlock %zu-byte buffer (after previously locking %zu bytes): %s\n " MLOCK_SUGGESTION,
307
- size, this ->size , std::strerror (errno));
309
+ char * errmsg = std::strerror (errno);
310
+ bool suggest = (errno == ENOMEM);
311
+
312
+ // Check if the resource limit is fine after all
313
+ struct rlimit lock_limit;
314
+ if (suggest && getrlimit (RLIMIT_MEMLOCK, &lock_limit))
315
+ suggest = false ;
316
+ if (suggest && (lock_limit.rlim_max > lock_limit.rlim_cur + size))
317
+ suggest = false ;
318
+
319
+ fprintf (stderr, " warning: failed to mlock %zu-byte buffer (after previously locking %zu bytes): %s\n %s" ,
320
+ size, this ->size , errmsg, suggest ? MLOCK_SUGGESTION : " " );
308
321
return false ;
309
322
}
310
323
}
You can’t perform that action at this time.
0 commit comments