Home

2023-07-19

In every project I had worked during college, it was required to handle out-of-memory situations.

On Linux, it can be challenging to simulate out-of-memory scenarios. By default, the OS commits more memory than it actually has available, similar to how airlines sometimes overbook flights, anticipating that not all resources will be used by processes.

When you fork a process, the child initially shares the same memory as its parent through a mechanism called copy-on-write. This means that until the child process makes changes to the memory, it can use the same memory pages as its parent.

However, just like with airlines, problems arise when too many processes require memory at the same time. In such cases, Linux activates the Out Of Memory (OOM) Killer, which terminates certain processes to free up memory.

To prevent the risk of losing data, it is recommended to disable memory overcommit on systems running databases.

I personally attempted to disable memory overcommit on my desktop, and the outcome was unpleasant. I quickly ran out of memory, making it impossible to simultaneously run a web browser and an IDE.