Search code examples
c++linuxmemorymemory-overcommitment

C++ memory overcommit Linux


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!


Solution

  • 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.