On my server, I have a long running batch process, process_a, which have been running for several days now. I don't mind the duration of which the process needs. The problem is how process_a always hogs ALL (99%) of the memory (RAM) to itself. I have process_b which I really need to be ran now. However, process_b is always hanging presumably because of insufficient RAM.

Is there a way to limit a process' memory usage while it is running?

I do not want to restart process_a because all the progress made could be lost. I am not the owner of the program that runs process_a, so I cannot modify process_a to save progress checkpoints at regular intervals. I am thinking of maybe somehow forcing half the memory of process_a to be dumped to swap in order to regain some memory for process_b.

All the answers to this question and this question does not address the fact the the process is running.

  • You can use cgclassify to move an existing process to a cgroup, so you can use this answer unix.stackexchange.com/a/125024/260978. Example for cgclassify: unix.stackexchange.com/a/40247/260978
    – Olorin
    Mar 6 '19 at 5:38
  • 1
  • @Olorin The first answer you refer to specifies that the process is executed by cgexec -g memory:myGroup pdftoppm which means that I need to start the process with cgexec in the first place. The second answer also does not mention any thing about limiting the process memory usage while it is running. Do you have any reference to support that cgclassify can be used to reduce a process' RAM usage while the process is running?
    – krismath
    Mar 6 '19 at 6:04
  • That's literally what the other post (example for cgclassify) is about.
    – Olorin
    Mar 6 '19 at 6:19
  • So if process_a is running with full RAM, when I set a limit using cgclassify, what happens to the used memory that is over the limit?
    – krismath
    Mar 6 '19 at 6:28

If process_a does not use the memory actively, then it will be swapped out when process_b starts.

So if you do not see that process_a's memory is swapped out, then it could be because process_a is using the memory actively.

So how can you tell process_a to be inactive for a while?

You suspend it.

kill -TSTP $pid

Then you run process_b and let process_a move to swap.

If you want to push more memory out to swap check out: https://gitlab.com/ole.tange/tangetools/tree/master/swapout

Finally when process_b is done, you release the brake on process_a:

kill -CONT $pid
Check for the priority of the process

Higher priority is -20
lower prioritty is +19
Neutral is 0

if process_a is having highher priority based on your requirement reduce the priority (-20 to +19). Higher the priority it will consumes most of resources

You can try with ulimit command options too
  • 1
    How does this limit the process’ memory usage? Mar 6 '19 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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