Re:Is RAM wiped before use in another LXC container?
by l33tman on Wednesday April 05, 2023 @07:11AM
(#35452198)
No, it doesn't. See "overcommit"
[ Parent
| on HN ]
Re:Is RAM wiped before use in another LXC container?
by enedil on Wednesday April 05, 2023 @07:43AM
(#35452448)
In a sense it does. Page tables would need to be copied.
Re:Is RAM wiped before use in another LXC container?
by jacquesm on Wednesday April 05, 2023 @07:50AM
(#35452514)
Yes, but they all point to the same pages. The tables take up a small fraction of the memory of the pages themselves.
Re:Is RAM wiped before use in another LXC container?
by enedil on Wednesday April 05, 2023 @09:11AM
(#35453550)
But large fraction, if all you do afterwards is an exec call. Given 8 bytes per page table entry and 4k pages, it's 1/512 memory wasted. So if your process uses 8GB, it's 16MB. Still takes noticeable time if you spawn often.
Re:Is RAM wiped before use in another LXC container?
by jacquesm on Wednesday April 05, 2023 @09:28AM
(#35453789)
I've never had the page tables be the cause of out of memory issues. Besides the fact that they are usually pre-allocated to avoid recursive page faults.
Re:Is RAM wiped before use in another LXC container?
by lxgr on Wednesday April 05, 2023 @10:37AM
(#35455013)
Aren't page tables nested? I don't know if any OS or hardware architecture actually supports it, but I could imagine the parent-level page table being virtual and copy-on-write itself.
Re:Is RAM wiped before use in another LXC container?
by reisse on Wednesday April 05, 2023 @08:58AM
(#35453383)
Please read the parent comments. Overcommit is necessary exactly because kernel has to reserve memory for both processes, and overcommit allows to reserve more memory than there is physically present.
If kernel could not reserve memory for forked process, overcommit would not be necessary.
Re:Is RAM wiped before use in another LXC container?
by lxgr on Wednesday April 05, 2023 @10:34AM
(#35454953)
I think you've got it backwards: With overcommit, there is no memory reservation. The forked processes gets an exact copy of the other's page table, but with all writable memory marked as copy-on-write instead. The kernel might well be tallying these up to some number, but nothing important happens with it.
Only without overcommit does the kernel does need to start accounting for hypothetically-writable memory before it actually is written to.
Re:Is RAM wiped before use in another LXC container?
by reisse on Wednesday April 05, 2023 @01:02PM
(#35457219)
Yes, you're right here, that was what I wanted to say but probably was not able to formulate.
Re:Is RAM wiped before use in another LXC container?
by blitzkrieg3 on Wednesday April 05, 2023 @11:59AM
(#35456294)
This is a misconception you and parent are perpetuating. fork() existed in this problematic 2x memory implementation _way_ before overcommit, and overcommit was non-existent or disabled on Unix (which has fork()) before Linux made it the default. Today with CoW we don't even have this "reserve memory for forked process" problem, so overcommit does nothing for us with regard to fork()/exec() (to say nothing of the vfork()/clone() point others have brought up). But if you want you can still disable overcommit on linux and observe that your apps can still create new processes.
What overcommit enables is more efficient use of memory for applications that request more memory than they use (which is most of them) and more efficient use of page cache. It also pretty much guarantees an app gets memory when it asks for it, at the cost of getting oom-killed later if the system as a whole runs out.