0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd::allocator: Add interface to fetch some resource limits.

This commit is contained in:
Jason Volk 2020-05-08 00:44:13 -07:00
parent 516d7e8ad7
commit 47800ba094
2 changed files with 62 additions and 0 deletions

View file

@ -28,6 +28,10 @@ namespace ircd::allocator
template<class T = char, size_t L0_SIZE = 512> struct twolevel;
template<class T> struct node;
size_t rlimit_as();
size_t rlimit_data();
size_t rlimit_memlock();
std::unique_ptr<char, decltype(&std::free)>
aligned_alloc(const size_t &align, const size_t &size);

View file

@ -8,6 +8,8 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#include <RB_INC_SYS_RESOURCE_H
// Uncomment or -D this #define to enable our own crude but simple ability to
// profile dynamic memory usage. Global `new` and `delete` will be captured
// here by this definition file into thread_local counters accessible via
@ -295,6 +297,62 @@ 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()
{
rlimit rlim;
syscall(getrlimit, RLIMIT_MEMLOCK, &rlim);
return rlim.rlim_cur;
}
#else
size_t
ircd::allocator::rlimit_memlock()
{
return 0;
}
#endif
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_DATA)
size_t
ircd::allocator::rlimit_data()
{
rlimit rlim;
syscall(getrlimit, RLIMIT_DATA, &rlim);
return rlim.rlim_cur;
}
#else
size_t
ircd::allocator::rlimit_data()
{
return 0;
}
#endif
#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_AS)
size_t
ircd::allocator::rlimit_as()
{
rlimit rlim;
syscall(getrlimit, RLIMIT_AS, &rlim);
return rlim.rlim_cur;
}
#else
size_t
ircd::allocator::rlimit_as()
{
return 0;
}
#endif
//
// Developer profiling
//
#ifdef RB_PROF_ALLOC // --------------------------------------------------
void *