3 ms·
Dynamic linking gets you two benefits: reduced size on disk (which was a bigger deal a few decades ago) and also the dynamic libraries can be updated/patched wi
by philsnow 2y ago
Dynamic linking gets you two benefits: reduced size on disk (which was a bigger deal a few decades ago) and also the dynamic libraries can be updated/patched without needing to recompile the entire system (so that when openssl.so gets upgraded on disk, you just restart all the processes on the system that link it (because processes still have the old library in memory) and you're done).
This is going to sound a little weird, but if the filesystem did chunked content-aware deduplication, and if the linker knew about this and wrote out compilation units on chunk boundaries... then you could statically compile everything on the system and yet, all different binaries that have libc.a, libm.a, openssl.a etc statically linked would share the same storage and thus the same page cache.
In the example of 500 different PHP versions, if the changes were very minor (as a contrived example, a change in version.c that puts the user's username in the version string), version.c would compile to a different version.o for each user, but main.c/main.o could be identical, and then the magic dedup-aware linker mentioned above writes seven and a half disk chunks' worth of the compiled code from main.o (but those are identical to the chunks written previously, so they don't actually cause writes), one mostly-empty disk chunk for the code from version.o (which will be different than any other chunk, so you'll have 500 disk chunks each with a different version of version.o).
If the changes were more major (say, the tip of main on [0] and the 499 previous versions), there would be less sharing, but still probably quite a lot. There's also wasted space like the ends of all the version.o chunks; if a chunk is 64kB then there's probably a fair amount of wasted space and maybe the whole experiment doesn't net you anything.
Of course, under this kind of system you'd have to recompile the world when you update a core library like libc.
edit: oh man there's tons of fun stuff happening in this area already and has been for years! nix is chunking NARs as of [0] (though I haven't found anything yet about linkers being made to chunk them better for dedup ahead of time, or about re-linkers that do this with already-linked binaries, but maybe their implementation of FastCDC can do it!?). this is so cool!
[0] https://discourse.nixos.org/t/introducing-attic-a-self-hostable-nix-binary-cache-server/24343/24 https://discourse.nixos.org/t/introducing-attic-a-self-hosta...