On 19.05.22 20:31, Chih-En Lin wrote: > When creating the user process, it usually uses the Copy-On-Write (COW) > mechanism to save the memory usage and the cost of time for copying. > COW defers the work of copying private memory and shares it across the > processes as read-only. If either process wants to write in these > memories, it will page fault and copy the shared memory, so the process > will now get its private memory right here, which is called break COW. Yes. Lately we've been dealing with advanced COW+GUP pinnings (which resulted in PageAnonExclusive, which should hit upstream soon), and hearing about COW of page tables (and wondering how it will interact with the mapcount, refcount, PageAnonExclusive of anonymous pages) makes me feel a bit uneasy :) > > Presently this kind of technology is only used as the mapping memory. > It still needs to copy the entire page table from the parent. > It might cost a lot of time and memory to copy each page table when the > parent already has a lot of page tables allocated. For example, here is > the state table for mapping the 1 GB memory of forking. > > mmap before fork mmap after fork > MemTotal: 32746776 kB 32746776 kB > MemFree: 31468152 kB 31463244 kB > AnonPages: 1073836 kB 1073628 kB > Mapped: 39520 kB 39992 kB > PageTables: 3356 kB 5432 kB I'm missing the most important point: why do we care and why should we care to make our COW/fork implementation even more complicated? Yes, we might save some page tables and we might reduce the fork() time, however, which specific workload really benefits from this and why do we really care about that workload? Without even hearing about an example user in this cover letter (unless I missed it), I naturally wonder about relevance in practice. I assume it really only matters if we fork() realtively large processes, like databases for snapshotting. However, fork() is already a pretty sever performance hit due to COW, and there are alternatives getting developed as a replacement for such use cases (e.g., uffd-wp). I'm also missing a performance evaluation: I'd expect some simple workloads that use fork() might be even slower after fork() with this change. (I don't have time to read the paper, I'd expect an independent summary in the cover letter) I have tons of questions regarding rmap, accounting, GUP, page table walkers, OOM situations in page walkers, but at this point I am not (yet) convinced that the added complexity is really worth it. So I'd appreciate some additional information. [...] > TODO list: > - Handle the swap Scary if that's not easy to handle :/ > - Rewrite the TLB flush for zapping the COW PTE table. > - Experiment COW to the entire page table. (Now just for PTE level) > - Bug in some case from copy_pte_range()::vm_normal_page()::print_bad_pte(). > - Bug of Bad RSS counter in multiple times COW PTE table forking. -- Thanks, David / dhildenb