4 ms·
> " By default Linux is set to over commit memory, so malloc always be succeeds even if you're out of memory." How does Linux handle 1 trillion mallocs of 1MB,
by SeanDav 9y ago
> " By default Linux is set to over commit memory, so malloc always be succeeds even if you're out of memory."
How does Linux handle 1 trillion mallocs of 1MB, on a 8GB system with 500GB hard drive, without failing?
There is nothing magic about Linux, it still cannot allocate and use memory which physically and virtually is simply not there.
- steveklabnik 9y agoWhen overcommit is set, it's not malloc that fails; the OS kills your process. So, checking the result of your allocations will never let you handle this kind of error.
- rcxdude 9y agoThough if the allocation is ludicrously oversized (not sure the threshold, but 2x present memory will do it) it will just straight up fail without over-committing.