mem_limit.cpp 779 B

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