mirror of
https://git.adityakumar.xyz/llama.cpp.git
synced 2024-11-09 23:29:44 +00:00
llama : fixed rlimit error message (#888)
This commit is contained in:
parent
018f2279f5
commit
25d7abbd1f
1 changed files with 15 additions and 2 deletions
17
llama_util.h
17
llama_util.h
|
@ -21,6 +21,9 @@
|
||||||
#if defined(_POSIX_MAPPED_FILES)
|
#if defined(_POSIX_MAPPED_FILES)
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(_POSIX_MEMLOCK_RANGE)
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -303,8 +306,18 @@ struct llama_mlock {
|
||||||
if (!mlock(addr, size)) {
|
if (!mlock(addr, size)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "warning: failed to mlock %zu-byte buffer (after previously locking %zu bytes): %s\n" MLOCK_SUGGESTION,
|
char* errmsg = std::strerror(errno);
|
||||||
size, this->size, std::strerror(errno));
|
bool suggest = (errno == ENOMEM);
|
||||||
|
|
||||||
|
// Check if the resource limit is fine after all
|
||||||
|
struct rlimit lock_limit;
|
||||||
|
if (suggest && getrlimit(RLIMIT_MEMLOCK, &lock_limit))
|
||||||
|
suggest = false;
|
||||||
|
if (suggest && (lock_limit.rlim_max > lock_limit.rlim_cur + size))
|
||||||
|
suggest = false;
|
||||||
|
|
||||||
|
fprintf(stderr, "warning: failed to mlock %zu-byte buffer (after previously locking %zu bytes): %s\n%s",
|
||||||
|
size, this->size, errmsg, suggest ? MLOCK_SUGGESTION : "");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue