Re:Is RAM wiped before use in another LXC container?
by reisse on Wednesday April 05, 2023 @09:09AM
(#35453528)
So if I got it right, you're using fork(2) as a glorified shared memory interface. If my memory is (also) right, you can allocate shared read-only mapping with shm_open(3) + mmap(2) in parent process, and open it as a private copy-on-write mapping in child processes.
Re:Is RAM wiped before use in another LXC container?
by jacquesm on Wednesday April 05, 2023 @09:44AM
(#35454044)
No, he's using fork the way it is intended.
Shared memory came much later than fork did.
Re:Is RAM wiped before use in another LXC container?
by Asooka on Wednesday April 05, 2023 @05:23PM
(#35460551)
I have used fork as a stupid simple memory arena implementation. fork(); do work in the child; only malloc, never free; exit. It is much, much heavier than a normal memory arena would be, but also much simpler to use. Plus, if you can split the work in independent batches, you can run multiple children at a time in parallel.
As with all such stupid simple mechanisms, I would not advise its use if your program spans more than one .c file and more than a thousand lines.
But what would be better? This way I can massage my data in one process, and then fork as many other processes that use this data as I like without having to serialise it to disk and and then load it again. If the data is not modified after fork it consumes much less memory (only the page tables). Usually a little is modified, consuming only a little memory extra. If all of it is modified it doesn't consume more memory than I would have otherwise (hopefully, not sure if the Linux implementation still keeps the pre-fork copy around).
(And no, not threads. They would share modifications, which I don't want. Also since I do this in python they would have terrible performance.)