3 ms·
Hunting Down Dirty Memory Pages
- nneonneo 10y agoThe gist is that 'const' objects with pointers will end up in read-write memory due to the need to relocate them at runtime. Windows has an interesting solution to this: all libraries are relocated once (the first time they are referenced by any process), and thereafter mapped at the same virtual address into all processes. Randomization (ASLR) is therefore applied once per boot rather than once per process. Arguably, this improves both time and memory performance since processes don't have to spend time relocating libraries at startup, and much more of the library's memory can be shared between processes. Android employs a similar trick: the "zygote" process loads a bunch of common shared libraries, and all application processes descend from zygote via fork(), thereby sharing library memory with the zygote.
- tasn 10y agoThat is a fair summary, though the post is about the process more than the conclusion. A similar solution to the Windows one is available for Linux and is called prelink, but cool to know Windows does it by default. I haven't heard about zygote, it's quite an elegant solution and probably ends up sharing more than just the pages in the case mentioned in the post, so even more memory saves. I wonder though about the security implications here, because it essentially means that every unprivileged process knows the address layout of all the other processes (the same). This means that a local process could more easily exploit a system process (essentially an ASLR bypass), and in some cases maybe even enable remote remote bypass. Edit: reading it again, it seems only user applications, and not system applications fork from zygote, so I guess the implications are much less serious.