In C, how do you know if the dynamic allocation succeeded?
1–10 of 198 posts
Re: In C, how do you know if the dynamic allocation succeeded?
#2Re: In C, how do you know if the dynamic allocation succeeded?
#3I kept reading hoping that there was going to be a solution, but not really; there are comments discussing disabling overcommit, but even that's a tradeoff (it does fix this failure mode, but you might not want to actually run a system like that).
Re: In C, how do you know if the dynamic allocation succeeded?
#4One approach is RSS, the memory in physical RAM... but what if you're swapping? Then again, maybe you swapped out memory you don't actually need and ignoring swap is fine.
The other approach is "how much memory you allocated", and then you hit fun issues mentioned in this article, like "the OS doesn't actually _really_ allocate until you touch the page".
(Longer version: https://pythonspeed.com/articles/measuring-memory-python/)
Re: In C, how do you know if the dynamic allocation succeeded?
#5Alternatively use mmap & mlock to verify the allocation succeeded, but the process can still be OOM killed at any time for any reason.
Re: In C, how do you know if the dynamic allocation succeeded?
#6Re: In C, how do you know if the dynamic allocation succeeded?
#7Re: In C, how do you know if the dynamic allocation succeeded?
#8It’s likely being OOM killed on Linux. Not sure what’s happening on Mac. Try allocating a terabyte of swap and it should run. Alternatively use mmap & mlock to verify the allocation succeeded, but the process can still be OOM killed at any time for any reason.
See no_paging_space_action() in:
https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/ke...
Edit: I think the 64 gigs number is out of date -- looks like it's now based in part on the amount of physical memory in the machine.
Re: In C, how do you know if the dynamic allocation succeeded?
#9https://www.kernel.org/doc/Documentation/vm/overcommit-accou...
Re: In C, how do you know if the dynamic allocation succeeded?
#10It’s likely being OOM killed on Linux. Not sure what’s happening on Mac. Try allocating a terabyte of swap and it should run. Alternatively use mmap & mlock to verify the allocation succeeded, but the process can still be OOM killed at any time for any reason.
Similarly on macOS. There is a limit of 64 gigs in the VM compressor (in-core and on-disk compressed "segments" combined); when this is reached, a process that owns more than 50% of the compressed memory can be killed. See no_paging_space_action() in: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/ke... Edit: I think the 64 gigs number is out of date -- looks like it's now based in part on the amount of ph…