There are several questions on here regarding how to set a limit on a process's memory consumption. I have recently learned about demand paging, and my question is why it would be useful to set such a limit.

As I understand it, if Process A is using a lot of memory and some other Process B needs more memory than is available, some portion of Process A's memory (e.g. some number of pages it is using) can be swapped to disk so that Process B can swap in some pages assuming A and B don't need the memory at the same time.

(obviously this is a simplification but I think it has the relevant details for this question)

If this understanding is generally correct, then what is the benefit of setting a limit on the virtual memory used by Process A? Is it just to limit the amount of swap space that could end up being used by Process A? Isn't virtual memory in a sense "infinite" due to demand paging?

  • 1
    If there were no limits to a process' memory access, what do you think would happen if ProcessB kept demanding more memory ad infinitum? ;) – Mioriin Apr 1 at 13:36
  • Eventually the swap space would be filled up but until then I don’t believe there would be a problem? – Alex Apr 1 at 13:50
  • ...and when both RAM and swap are full, the kernel calls the OOMkiller to free up some memory by randomly killing processes in a last ditch effort to maintain system stability (this is BAD). Process memory limits help avoid that situation by telling the process that it isn't getting more memory that a set amount. – Mioriin Apr 6 at 2:45

Your Answer

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

Browse other questions tagged or ask your own question.