
Zwei Fragen:
Gibt es eine Möglichkeit, das Swapping für einen bestimmten Prozess zu deaktivieren, d. h. ist es möglich, einen bestimmten Prozess zu beenden, wenn er den gesamten verfügbaren Primärspeicher des Systems nutzt?
Wie deaktiviere ich die Speicherüberbelegung in einem Linux-System?
Kontext:
I'm running a distributed application, and I'd like to have a process killed once the system ran out of primary memory. The process is quite heavy on hard disk communication, for what I find reasonable to check the memory usage programatically, like:
std::ifstream statm("/proc/self/statm");
size_t mem_virt, mem_rss, mem_shared;
statm >> mem_virt >> mem_rss >> mem_shared;
if (mem_virt == MAX_SYSTEM_PRIMARY_MEMORY) {
// kills current process
}
But if there was some set of command lines capable of turning off the swap for a given process, that would be definitely better.
Yet, I still don't know how to turn off the overcommit. Any ideas?
Antwort1
You can disallow swapping in your application by calling mlockall(MCL_CURRENT|MCL_FUTURE)
, see the man page.
You can disable overcommit:
$ sysctl vm.overcommit_memory=2 # policy number 2
$ sysctl vm.overcommit_ratio=0 # ratio = 0%
Running without swap is generally a terrible idea. Now all anonymous mmaps will be be forced to be backed by RAM, even if they are not used. Unix needs swap, even if nothing is actually swapped.