Collabora Online reduces server memory usage by 50% via COW optimization
An optimization to copy-on-write (COW) memory handling allows Collabora Online to halve memory consumption per document by preventing small data writes from triggering 4KB page duplications.
Summary
Collabora Online, the web-based office suite derived from LibreOffice, has implemented a significant memory optimization targeting its process-based architecture. The suite utilizes a 'forkit' model where each document is opened in its own process 'kit,' relying on the Linux kernel's copy-on-write (COW) mechanism to share memory between the parent and child processes.
By modifying how the parent forkit manages memory gaps, the update prevents child kits from writing small amounts of data into shared pages. This change effectively stops the kernel from duplicating entire 4KB pages for just a few bytes of new data, resulting in a roughly 50% reduction in memory usage per document in testing scenarios.
Optimizing Copy-on-Write via forkit memory management
- COW Fragmentation: Previously, small data writes (such as text bits or settings) within a child kit would trigger a kernel page copy, turning a shared 4KB page into a private one for a negligible amount of new data.
- Forkit Gap Management: The optimization forces the parent forkit to fill its own internal memory gaps before spawning child kits, ensuring that the kits do not inherit and subsequently 'dirty' shared pages with small allocations.
- Memory Density: By ensuring child kits write to fresh, unshared memory pages rather than shared ones, the data is packed more tightly, maintaining the integrity of the shared memory state between the forkit and the kits.
- Performance Gains: Beyond reducing RAM consumption, the change reduces the CPU overhead previously required to duplicate pages during the COW process.
Why it matters
This optimization significantly increases the density of concurrent users a single Collabora Online server can support, potentially saving tens of gigabytes of RAM on large-scale deployments. It also provides a blueprint for other Linux applications that rely heavily on fork-based architectures and COW to optimize child process performance.
Original reference: www.phoronix.com →