Подтвердить что ты не робот

Linux: невозможно выделить более 32 ГБ /64 ГБ памяти в одном процессе из-за ограничения виртуальной памяти

У меня есть компьютер с 128 ГБ ОЗУ, работающий под управлением Linux (3.19.5-200.fc21.x86_64). Однако я не могу выделить более 30 ГБ ОЗУ в одном процессе. Помимо этого, malloc завершается с ошибкой:

#include <stdlib.h>
#include <iostream>

int main()
{
   size_t gb_in_bytes = size_t(1)<<size_t(30); // 1 GB in bytes (2^30).
   // try to allocate 1 block of 'i' GB.
   for (size_t i = 25; i < 35; ++ i) {
      size_t n = i * gb_in_bytes;
      void *p = ::malloc(n);
      std::cout << "allocation of 1 x " << (n/double(gb_in_bytes)) << " GB of data. Ok? " << ((p==0)? "nope" : "yes") << std::endl;
      ::free(p);
   }
}

Это приводит к следующему выводу:

/tmp> c++ mem_alloc.cpp && a.out

allocation of 1 x 25 GB of data. Ok? yes
allocation of 1 x 26 GB of data. Ok? yes
allocation of 1 x 27 GB of data. Ok? yes
allocation of 1 x 28 GB of data. Ok? yes
allocation of 1 x 29 GB of data. Ok? yes
allocation of 1 x 30 GB of data. Ok? yes
allocation of 1 x 31 GB of data. Ok? nope
allocation of 1 x 32 GB of data. Ok? nope
allocation of 1 x 33 GB of data. Ok? nope
allocation of 1 x 34 GB of data. Ok? nope

Я искал довольно давно и обнаружил, что это связано с максимальным размером виртуальной памяти:

~> ulimit -all
[...]
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
virtual memory          (kbytes, -v) 32505856
[...]

Я могу увеличить этот предел до ~ 64 ГБ через ulimit -v 64000000, но не дальше. Помимо этого, я получаю ошибки operation not permitted:

~> ulimit -v 64000000
~> ulimit -v 65000000                                                                                                                                  
bash: ulimit: virtual memory: cannot modify limit: Operation not permitted                                                                              
~> ulimit -v unlimited
bash: ulimit: virtual memory: cannot modify limit: Operation not permitted 

Еще один поиск показал, что в принципе можно установить эти ограничения через запись "как" (адресное пространство) в /etc/security/limits.conf. Однако, делая это, я мог только уменьшить максимальное количество виртуальной памяти, а не увеличивать ее.

Есть ли способ полностью снять этот лимит виртуальной памяти на один процесс или увеличить его за пределы 64 ГБ? Я хотел бы использовать всю физическую память в одном приложении.

EDIT:

  • После Ingo Leonhardt я пробовал ulimits -v unlimited после входа в систему как root, а не как обычный пользователь. Это решает проблему для root (программа может затем распределить всю физическую память, запустив ее как root). Но это работает только для root, а не для других пользователей. Однако, по крайней мере, это означает, что в принципе ядро ​​может справиться с этим просто отлично, и что есть только проблема с конфигурацией.

  • Относительно limits.conf: я попытался явно добавить

    • жесткий как неограниченный
    • soft как неограниченный

    до /etc/security/limits.conf и перезагрузка. Это не имело никакого эффекта. После входа в качестве стандартного пользователя ulimit -v все еще возвращает около 32 ГБ, а ulimit -v 65000000 все еще говорит permission denied (пока ulimit -v 64000000 работает). Остальная часть limits.conf закомментирована, а в /etc/security/limits.d имеется только одна другая несвязанная запись (ограничение nproc до 4096 для пользователей без полномочий root). То есть ограничение виртуальной памяти должно происходить от другого места, кроме limits.conf. Любые идеи, что еще может привести к ulimits -v не "неограниченному"?

ИЗМЕНИТЬ/Решение:

  • Это было вызвано моей собственной глупостью. У меня была (давно забытая) программа в моей пользовательской настройке, которая использовала setrlimit, чтобы ограничить объем памяти для каждого процесса, чтобы не допустить замены Linux. Он был непреднамеренно скопирован с 32-гигабайтной машины на 128-гигабайтную машину. Спасибо Полю и Эндрю Янке и всем остальным за то, что они помогли отследить его. Извините всех:/.

  • Если кто-то еще сталкивается с этим: найдите ulimit/setrlimit в настройках bash и профиля, а также программы, потенциально вызывающие их (как ваши собственные, так и общесистемные /etc ) и убедитесь, что /security/limits.conf не включает этот предел... (или, по крайней мере, попробуйте создать нового пользователя, чтобы убедиться, что это происходит в вашем пользователе или в настройке системы)

4b9b3361

Ответ 1

Это проблема с ulimit и системой, а не с проблемой С++.

Я могу запустить ваш модифицированный код в экземпляре экземпляра Amazon EC2 r3.4xlarge без проблем. Они стоят менее 0,20 долл. США/час на спотовом рынке, и поэтому я предлагаю вам арендовать один и, возможно, взглянуть в /etc и сравнить с вашей собственной настройкой... или, возможно, вам нужно перекомпилировать ядро ​​Linux для использования этого много памяти... но это не проблема С++ или gcc.

Ubuntu на машине EC2 уже настроен для неограниченной памяти процесса.

$ sudo su
# ulimit -u
--> unlimited

У этого есть 125 ГБ оперативной памяти

# free
             total       used       free     shared    buffers     cached
Mem:     125903992    1371828  124532164        344      22156     502248
-/+ buffers/cache:     847424  125056568
Swap:            0          0          0

Я изменил ограничения на вашу программу, чтобы перейти на 149 ГБ.

Здесь вывод. Выглядит хорошо до 118 ГБ.

[email protected]:/home/ubuntu# ./memtest
allocation of 1 x 25 GB of data. Ok? yes
allocation of 1 x 26 GB of data. Ok? yes
allocation of 1 x 27 GB of data. Ok? yes
allocation of 1 x 28 GB of data. Ok? yes
allocation of 1 x 29 GB of data. Ok? yes
allocation of 1 x 30 GB of data. Ok? yes
allocation of 1 x 31 GB of data. Ok? yes
allocation of 1 x 32 GB of data. Ok? yes
allocation of 1 x 33 GB of data. Ok? yes
allocation of 1 x 34 GB of data. Ok? yes
allocation of 1 x 35 GB of data. Ok? yes
allocation of 1 x 36 GB of data. Ok? yes
allocation of 1 x 37 GB of data. Ok? yes
allocation of 1 x 38 GB of data. Ok? yes
allocation of 1 x 39 GB of data. Ok? yes
allocation of 1 x 40 GB of data. Ok? yes
allocation of 1 x 41 GB of data. Ok? yes
allocation of 1 x 42 GB of data. Ok? yes
allocation of 1 x 43 GB of data. Ok? yes
allocation of 1 x 44 GB of data. Ok? yes
allocation of 1 x 45 GB of data. Ok? yes
allocation of 1 x 46 GB of data. Ok? yes
allocation of 1 x 47 GB of data. Ok? yes
allocation of 1 x 48 GB of data. Ok? yes
allocation of 1 x 49 GB of data. Ok? yes
allocation of 1 x 50 GB of data. Ok? yes
allocation of 1 x 51 GB of data. Ok? yes
allocation of 1 x 52 GB of data. Ok? yes
allocation of 1 x 53 GB of data. Ok? yes
allocation of 1 x 54 GB of data. Ok? yes
allocation of 1 x 55 GB of data. Ok? yes
allocation of 1 x 56 GB of data. Ok? yes
allocation of 1 x 57 GB of data. Ok? yes
allocation of 1 x 58 GB of data. Ok? yes
allocation of 1 x 59 GB of data. Ok? yes
allocation of 1 x 60 GB of data. Ok? yes
allocation of 1 x 61 GB of data. Ok? yes
allocation of 1 x 62 GB of data. Ok? yes
allocation of 1 x 63 GB of data. Ok? yes
allocation of 1 x 64 GB of data. Ok? yes
allocation of 1 x 65 GB of data. Ok? yes
allocation of 1 x 66 GB of data. Ok? yes
allocation of 1 x 67 GB of data. Ok? yes
allocation of 1 x 68 GB of data. Ok? yes
allocation of 1 x 69 GB of data. Ok? yes
allocation of 1 x 70 GB of data. Ok? yes
allocation of 1 x 71 GB of data. Ok? yes
allocation of 1 x 72 GB of data. Ok? yes
allocation of 1 x 73 GB of data. Ok? yes
allocation of 1 x 74 GB of data. Ok? yes
allocation of 1 x 75 GB of data. Ok? yes
allocation of 1 x 76 GB of data. Ok? yes
allocation of 1 x 77 GB of data. Ok? yes
allocation of 1 x 78 GB of data. Ok? yes
allocation of 1 x 79 GB of data. Ok? yes
allocation of 1 x 80 GB of data. Ok? yes
allocation of 1 x 81 GB of data. Ok? yes
allocation of 1 x 82 GB of data. Ok? yes
allocation of 1 x 83 GB of data. Ok? yes
allocation of 1 x 84 GB of data. Ok? yes
allocation of 1 x 85 GB of data. Ok? yes
allocation of 1 x 86 GB of data. Ok? yes
allocation of 1 x 87 GB of data. Ok? yes
allocation of 1 x 88 GB of data. Ok? yes
allocation of 1 x 89 GB of data. Ok? yes
allocation of 1 x 90 GB of data. Ok? yes
allocation of 1 x 91 GB of data. Ok? yes
allocation of 1 x 92 GB of data. Ok? yes
allocation of 1 x 93 GB of data. Ok? yes
allocation of 1 x 94 GB of data. Ok? yes
allocation of 1 x 95 GB of data. Ok? yes
allocation of 1 x 96 GB of data. Ok? yes
allocation of 1 x 97 GB of data. Ok? yes
allocation of 1 x 98 GB of data. Ok? yes
allocation of 1 x 99 GB of data. Ok? yes
allocation of 1 x 100 GB of data. Ok? yes
allocation of 1 x 101 GB of data. Ok? yes
allocation of 1 x 102 GB of data. Ok? yes
allocation of 1 x 103 GB of data. Ok? yes
allocation of 1 x 104 GB of data. Ok? yes
allocation of 1 x 105 GB of data. Ok? yes
allocation of 1 x 106 GB of data. Ok? yes
allocation of 1 x 107 GB of data. Ok? yes
allocation of 1 x 108 GB of data. Ok? yes
allocation of 1 x 109 GB of data. Ok? yes
allocation of 1 x 110 GB of data. Ok? yes
allocation of 1 x 111 GB of data. Ok? yes
allocation of 1 x 112 GB of data. Ok? yes
allocation of 1 x 113 GB of data. Ok? yes
allocation of 1 x 114 GB of data. Ok? yes
allocation of 1 x 115 GB of data. Ok? yes
allocation of 1 x 116 GB of data. Ok? yes
allocation of 1 x 117 GB of data. Ok? yes
allocation of 1 x 118 GB of data. Ok? yes
allocation of 1 x 119 GB of data. Ok? nope
allocation of 1 x 120 GB of data. Ok? nope
allocation of 1 x 121 GB of data. Ok? nope
allocation of 1 x 122 GB of data. Ok? nope
allocation of 1 x 123 GB of data. Ok? nope
allocation of 1 x 124 GB of data. Ok? nope
allocation of 1 x 125 GB of data. Ok? nope
allocation of 1 x 126 GB of data. Ok? nope
allocation of 1 x 127 GB of data. Ok? nope
allocation of 1 x 128 GB of data. Ok? nope
allocation of 1 x 129 GB of data. Ok? nope
allocation of 1 x 130 GB of data. Ok? nope
allocation of 1 x 131 GB of data. Ok? nope
allocation of 1 x 132 GB of data. Ok? nope
allocation of 1 x 133 GB of data. Ok? nope
allocation of 1 x 134 GB of data. Ok? nope
allocation of 1 x 135 GB of data. Ok? nope
allocation of 1 x 136 GB of data. Ok? nope
allocation of 1 x 137 GB of data. Ok? nope
allocation of 1 x 138 GB of data. Ok? nope
allocation of 1 x 139 GB of data. Ok? nope
allocation of 1 x 140 GB of data. Ok? nope
allocation of 1 x 141 GB of data. Ok? nope
allocation of 1 x 142 GB of data. Ok? nope
allocation of 1 x 143 GB of data. Ok? nope
allocation of 1 x 144 GB of data. Ok? nope
allocation of 1 x 145 GB of data. Ok? nope
allocation of 1 x 146 GB of data. Ok? nope
allocation of 1 x 147 GB of data. Ok? nope
allocation of 1 x 148 GB of data. Ok? nope
allocation of 1 x 149 GB of data. Ok? nope

Теперь о том, что 0,17 доллара США потратил на это...