Earlier quoted context omitted.
Are there any things that are illegal between fork and exec? It is perfectly legal to exec whenever you want, and it it perfectly legal to fork whenever you want. I'm not aware of any requirements around the fork/exec sequence.
For a single-threaded process, sure. But in a multi threaded context, almost any operation done in the child after fork() can royally mess up the system. There are many versions of libcs where malloc() after fork() is likely to deadlock between the parent and child processes, as they share the internal malloc() locks.
In C, how do you know if the dynamic allocation succeeded?
191–198 of 198 posts
Re: In C, how do you know if the dynamic allocation succeeded?
#192Earlier quoted context omitted.
TIL, unless you explicitly disable memory overcommit, it can and will overcommit. This is crazy to me.
So, uh, how do you feel about fractional reserve banking? Nearly all banks worldwide practice it. Statistically, it's not impossible that the entire world financial system could collapse due to uncorrelated bank runs.
I guess it's beneficial in >99% of use-cases, and the <1% of other cases can turn it off. Still I guess I'm naive enough to hope a correct program would not crash.
Re: In C, how do you know if the dynamic allocation succeeded?
#193I once complained about malloc happily allocating memory that the physical memory system couldn't satisfy (never let your hand write a check your ass can't cash?) but the more experienced programmer asked me if I'd heard of fractional reserve banking, and if not, whether it bothered me too.
Re: In C, how do you know if the dynamic allocation succeeded?
#194Earlier quoted context omitted.
if overcommit is disabled, then the system drops its internal caches (dentry cache, pagecache) to satisfy a memory allocation. Since most applications don't touch pages they allocate, that means the OS could have avoided dropping the caches. Since it did drop the caches, other parts of the system will then have to do more work to reconstruct the caches (looking up an dentry explicitly, or loading a page from disk ins…
> if overcommit is disabled, then the system drops its internal caches (dentry cache, pagecache) to satisfy a memory allocation. Couldn't the system just reserve the pages for future use by the application but still use them for caching until the application actually tries to use them?
Re: In C, how do you know if the dynamic allocation succeeded?
#195This made be curious to check the real and virtual memory of some processes on my laptop (MacBook Air M1). The real memory size of Safari is ~160MB but virtual memory size is 392GB which doesn't look right. I checked other processes and all the processes have similar virtual memory size which is around ~390GB. I wonder if this is a bug in Activity Monitor or the virtual memory allocations really are this big for each…
Re: In C, how do you know if the dynamic allocation succeeded?
#196Earlier quoted context omitted.
> if overcommit is disabled, then the system drops its internal caches (dentry cache, pagecache) to satisfy a memory allocation. Couldn't the system just reserve the pages for future use by the application but still use them for caching until the application actually tries to use them?
This sounds like it would cause LRU caches to lose their LRU properties...
Re: In C, how do you know if the dynamic allocation succeeded?
#197Earlier quoted context omitted.
Virtual memory is always on... If you actually hit swap the system effectively deadlocks anyway because the swap daemon is too dumb by being too fair. Persistent memory might change this but it needs so much work.
it was a throwback down the memory lane and the years before my first Linux in 1995 i had been dealing with Windows where configuration of swap was "configuring virtual memory", so i automatically used that term. > If you actually hit swap the system effectively deadlocks anyway that depends. In many cases in the past the options would be either with swap and thus slow or pretty much not at all. And again these days…
Re: In C, how do you know if the dynamic allocation succeeded?
#198Earlier quoted context omitted.
Please don’t blindly declare it ‘totally dumb’. If you disallow overcommit, you can end up with a system that can’t fork and run /bin/true, even if there are gigabytes of memory left. Both styles of memory allocation have their uses, and their drawbacks, but please understand them before declaring many OS designers as stupid and dumb.
I agree with you on all counts, but it's worth highlighting that the parent did not call the designers dumb, but rather the situation and implementation. I know it can seem like a distinction without a difference, but I think it's fair to critique work. I think they could have been more articulate and considerate towards the designers, and have some empathy that many people have worked very hard on it, and did their…