3

I am currently coding a server application that basically processes workloads for clients. Based on the actual workload, the server could use huge amounts of memory. Target Platforms are Windows and Linux, the code is written in c++.

However, i am not very familiar with linux programming and during some testing today i run into some strange crashes. As it turns out, those were related to overcommited memory.

The code i have written is fairly robust and can handle out-of-memory situations (at least on Windows systems) by splitting and queueing its workloads whenever it runs into bad_alloc exceptions. Refactoring all the code to cope with errors that could occur due to overcommited memory would be a complete nightmare.

So, i was wondering if i could turn off overcommit for my process and child threads. I already found an old question here Link (at stackoverflow) that answers this as no, but realizing that this is a 10 year old answer i was wondering if that might have changed?

If its still not possible to turn this of application wise, is there at least a way of detecting the current setting for it inside my application?

Thanks in advance!

erik
  • 57
  • 7
  • That other question doesn't say it can't be done _for a process_ it's saying it can't be done globally for all processes on a system. As a matter of fact, the solution states seems to, from what you've described, to be what you need. – fredrik Jan 30 '21 at 21:12
  • One way to disable over-commit for the system as a whole is to (as root) do `echo 2 > /proc/sys/vm/overcommit_memory`. – Peter Jan 30 '21 at 22:27

1 Answers1

1

So, i was wondering if i could turn off overcommit for my process and child threads. I already found an old question here Link (at stackoverflow) that answers this as no, but realizing that this is a 10 year old answer i was wondering if that might have changed?

No, you still cannot change overcommit settings per-process. It is a system-wide setting. It can be changed only with super user privileges.

is there at least a way of detecting the current setting

You can read it from the /proc pseudo-filesystem. In particular, the file /proc/sys/vm/overcommit_memory.

eerorika
  • 232,697
  • 12
  • 197
  • 326