mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::allocator: Add a graceful getter/setter for RLIMIT_MEMLOCK.
This commit is contained in:
parent
728da15ad3
commit
489cf7a560
2 changed files with 43 additions and 0 deletions
|
@ -31,6 +31,7 @@ namespace ircd::allocator
|
|||
size_t rlimit_as();
|
||||
size_t rlimit_data();
|
||||
size_t rlimit_memlock();
|
||||
size_t rlimit_memlock(const size_t &request);
|
||||
|
||||
std::unique_ptr<char, decltype(&std::free)>
|
||||
aligned_alloc(const size_t &align, const size_t &size);
|
||||
|
|
|
@ -301,6 +301,48 @@ ircd::allocator::aligned_alloc(const size_t &alignment_,
|
|||
// resource limits
|
||||
//
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_MEMLOCK)
|
||||
size_t
|
||||
ircd::allocator::rlimit_memlock(const size_t &req)
|
||||
try
|
||||
{
|
||||
rlimit rlim {0};
|
||||
rlim.rlim_cur = req;
|
||||
syscall(setrlimit, RLIMIT_MEMLOCK, &rlim);
|
||||
|
||||
char pbuf[48];
|
||||
log::info
|
||||
{
|
||||
"Raised resource limit for locked memory to %s",
|
||||
req != -1UL?
|
||||
pretty(pbuf, iec(req)):
|
||||
"unlimited"_sv,
|
||||
};
|
||||
|
||||
return rlim.rlim_cur;
|
||||
}
|
||||
catch(const std::system_error &e)
|
||||
{
|
||||
char pbuf[48];
|
||||
log::warning
|
||||
{
|
||||
"Failed to raise resource limit for locked memory to %s :%s",
|
||||
req != -1UL?
|
||||
pretty(pbuf, iec(req)):
|
||||
"unlimited"_sv,
|
||||
e.what(),
|
||||
};
|
||||
|
||||
return rlimit_memlock();
|
||||
}
|
||||
#else
|
||||
size_t
|
||||
ircd::allocator::rlimit_memlock(const size_t &req)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_MEMLOCK)
|
||||
size_t
|
||||
ircd::allocator::rlimit_memlock()
|
||||
|
|
Loading…
Reference in a new issue