Hacker News new | ask | show | jobs
by wilun 3078 days ago
Windows has vastly different policies for RAM allocation and commit than Linux. Windows basically does not overcommit while Linux systems not only does it by default but quite depend on it for various loads to work properly. In consequence, the userspace has a tendency to handle RAM differently, but there is no magic: if programs are trying to allocate twice the amount of RAM and then only use half of it, Windows with a swap that can be large enough will work perfectly while without swap the allocation will fail. Under Linux, the situation is less clear: without swap it will succeed (well it depends on the fine details of overcommit that are selected, but you get the idea) although if you really then use all that RAM, the OOM killer will start to more or less "randomly" kill "any" process to cope with the lack of RAM (as a last resort measure though; the caches and buffers are flushed before, etc.)
1 comments

Windows also has two syscalls - one to reserve memory and one to commit memory. You can reserve+commit at once, but you can also just reserve a chunk of virtual memory that you commit at a later time. Accessing pages that aren't committed is a segfault. So you can say "I might need up to X contiguous bytes of virtual memory" and then commit as you go. IIRC, Windows will let you over-reserve, but not over-commit.

Edit: sorry, not two syscals, it's an option to the malloc-equivalent - VirtualAlloc