Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Two questions:

  1. Is there some way to turn off swapping for a given process, i.e., is it possible to kill a certain process if it uses all the system's primary memory available?

  2. How do I deactivate memory overcommit in a Linux system?

Context:

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
This sounds to me like the best solution. Thanks very much! (: –  Rubens Aug 20 '13 at 3:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.