blob: 87a0db833e3830e58b3004f4d31adc6056a41bbd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#ifdef __unix__
#include <sys/resource.h>
#endif
#include <util/generic/yexception.h>
#include "mem_limit.h"
namespace NYql {
void SetAddressSpaceLimit(ui64 memLimit) {
if (memLimit) {
#ifdef __unix__
auto memLimitBytes = memLimit * 1024 * 1024;
struct rlimit rl;
if (getrlimit(RLIMIT_AS, &rl)) {
throw TSystemError() << "Cannot getrlimit(RLIMIT_AS)";
}
rl.rlim_cur = memLimitBytes;
if (setrlimit(RLIMIT_AS, &rl)) {
throw TSystemError() << "Cannot setrlimit(RLIMIT_AS) to " << memLimitBytes << " bytes";
}
#else
throw yexception() << "Memory limit can not be set on this platfrom";
#endif
}
}
} // namespace NYql
|