News for hackers. Stuff that matters.
Re:The abysmal state of GNU/Linux and a case against shared ... by odo1242 on Monday October 14, 2024 @04:21PM (#41841509)
Something worth noting with shared dependencies is that yes, they save on disk space, but they also save on memory. A 200MB non-shared dependency will take up 600MB across three apps, but a 200MB shared dependency can be loaded on it's own and save 400 megabytes. (Most operating systems manage this at the physical page level, by mapping multiple instances of a shared library to the same physical memory pages.)

400 megabytes of memory usage is probably worth more than 400 megabytes of storage. It may not be a make-or break thing on it's own, but it's one of the reasons Linux can run on lower-end devices.

Re:The abysmal state of GNU/Linux and a case against shared ... by packetlost on Monday October 14, 2024 @04:25PM (#41841555)
When you statically compile an application, you only store text (code) of functions you actually use, generally, so unless you're using all 400Mb of code you're not going to have a 400Mb+ binary. I don't think I've ever seen a dependency that was 400Mb of compiled code if you stripped debug information and weren't embedding graphical assets, so I'm not sure how relevant this is in the first place. 400Mb of opcodes is... a lot.
Re:The abysmal state of GNU/Linux and a case against shared ... by AshamedCaptain on Monday October 14, 2024 @04:43PM (#41841760)
I have seen a binary that is approximately 1.1GB of text. That is without debug symbols. With debug symbols it would hit GDB address space overflow bugs all the time. You have not seen what 30 year old engineering software houses can produce. And this is not the largest software by any chance.

Also, sibling comments argue that kernel samepage merging can help avoid the bloat of static linking. But here what you argue will make every copy of the shared libraries oh-so-slightly-different and therefore prevent KSM from working at all. Really, no one is thinking this through very well. Even distributions that do static linking in all but name (such as NixOS) do still technically use dynamic linking for the disk space and memory savings.

Re:The abysmal state of GNU/Linux and a case against shared ... by sunshowers on Monday October 14, 2024 @06:10PM (#41842606)
Some programs are definitely that complicated, and it's a horrible idea for them to use dynamic binding! The test matrix is absurdly large. (You are testing the software you ship as you ship it, aren't you?)
Re:The abysmal state of GNU/Linux and a case against shared ... by AshamedCaptain on Monday October 14, 2024 @06:18PM (#41842681)
By the same logic, you also would have to test the software with every display resolution / terminal width in existance. You are testing the software you ship as you ship it, aren't you?

Abstractions are a thing in computer science. Abstracting at the shared library layer makes as much sense as abstracting in the RPC layer (which your software is most likely going to be obligated to do) or abstracting at the ISA level (which your software IS obligated to do). Your software has as many chances to break from a library change as it does from a display driver change or from a screen resolution change or from a processor upgrade. Why the first would bloat the "testing matrix" but not the later is over me, and already shows a bias against dynamic linking: you assume library developers are incapable of keeping an ABI but that the CPU designers are. (Anecdotally, as a CPU designer, I would rather trust the library developers..)

Re:The abysmal state of GNU/Linux and a case against shared ... by sunshowers on Monday October 14, 2024 @06:24PM (#41842762)
In practice, I've seen breakage from shared library updates be much more common than breakage from display resolutions.

Many modern software development paradigms are simply not compatible with ABIs or dynamic binding. Dynamic binding also likely means you're leaving a bunch of performance on the table, since inlining across libraries isn't an option.

Re:The abysmal state of GNU/Linux and a case against shared ... by AshamedCaptain on Monday October 14, 2024 @06:35PM (#41842885)
> In practice, I've seen breakage from shared library updates be much more common than breakage from display resolutions.

You'd be surprised, specially when I'm thinking 30 year old software. Again, usually I can patch around it thanks to dynamic linking...

> Many modern software development paradigms are simply not compatible with ABIs or dynamic binding

This is nonsense.

> Dynamic binding also likely means you're leaving a bunch of performance on the table, since inlining across libraries isn't an option.

Again, why set the goalpost here and not say ISA level or any other abstraction layer? I could literally make the same argument to any of these levels (e.g. "you are leaving a bunch of performance on the table" by not specializing your ISA to your software). How much are you really leaving? And how much would you pay if you remove the abstraction? What are the actual pros/cons?

Re:The abysmal state of GNU/Linux and a case against shared ... by sunshowers on Monday October 14, 2024 @06:42PM (#41842951)
True! That is a completely valid argument. Why not ship your own kernel? Your own processors with your own ISA?

The answer to each of these questions is specific to the circumstances. You have to decide based on general principles (what do you value?), the specific facts, and ultimately judgment.

I think in some cases (e.g kernel or libc) using dynamic binding generally makes sense, but I happen to think forcing shared library use has many more costs than benefits.

You're absolutely right that everyone should ask these questions, though. I work at Oxide where we did ask these questions, and decided that to provide a high-quality cloud-like experience we need much tighter coupling between our components than is generally available to the public. So. for example, we don't use a BIOS or UEFI—we have our own firmware that is geared towards loading exactly the OS we ship.

> This is nonsense.

Monomorphization like in C++ or Rust doesn't work with dynamic binding. C macros and header-only libraries don't work with dynamic binding either.

Re:The abysmal state of GNU/Linux and a case against shared ... by packetlost on Monday October 14, 2024 @04:48PM (#41841819)
Your poor I$.

The fact of the matter is outside of GPU drivers and poorly designed GUI applications, that's an extreme statistical outlier.

Re:The abysmal state of GNU/Linux and a case against shared ... by AshamedCaptain on Monday October 14, 2024 @06:24PM (#41842760)
Sum the GPU driver and the mandatory LLVM requirement that comes with it, and you already have almost half a gigabyte of text per exec. No wonder that your logic forces you to literally dismiss all GUI applications as "extreme statistical outliers" out of hand.

For the record, the 1.1GB executable I'm thinking about is a popular _terminal-only_ simulation package. No GUI.

Re:The abysmal state of GNU/Linux and a case against shared ... by nightowl_games on Monday October 14, 2024 @07:09PM (#41843165)
Can't you just tell us what it is?
Re:The abysmal state of GNU/Linux and a case against shared ... by packetlost on Monday October 14, 2024 @08:26PM (#41843694)
Most applications do not use CUDA (I assume that's what you're referring to) and the ones that do only need to pull in the runtime (libcudart_static, in this case) which is nowhere near as big. You don't link all of LLVM into a CUDA application lol
Re:The abysmal state of GNU/Linux and a case against shared ... by AshamedCaptain on Tuesday October 15, 2024 @11:43AM (#41849741)
For the record any application using shader definitely needs "all of LLVM", and most Gtk+ applications are using shaders due to the ill-conceived notion that GPUs are faster at 2d acceleration. So yes, all GUI apps are linking in all of the graphics driver and all of LLVM.
Re:The abysmal state of GNU/Linux and a case against shared ... by packetlost on Tuesday October 15, 2024 @12:33PM (#41850325)
Right, but they don't do so using the default loader, it looks like they likely do it via dlopen or similar runtime dynamic linking. If you compile the binaries statically, it wouldn't effect that.

I did a little math using a common GTK application as an example: nautilus. Using `ldd` and several shell utilities, if you were to statically link it it clocks in at around 80MB in binary size, but that would be worst case without LTO.

FWIW I think graphics stacks are one of the few places where dynamic linking is still highly relevant.

Re:The abysmal state of GNU/Linux and a case against shared ... by lostmsu on Monday October 14, 2024 @04:53PM (#41841872)
You mean GPU libraries, right?

Just watch how these become used in every other app over the next few years.

And yes, the fact that you won't use those apps does not make it easier for the rest of us.

Re:The abysmal state of GNU/Linux and a case against shared ... by vvanders on Monday October 14, 2024 @04:42PM (#41841758)
Yes, this is lost in most discussions when it comes to DSOs. Not only do you have the complexity of versioning and vending but also you can't optimize with LTO and other techniques(which can make a significant difference in final binary size).

If you've got 10-15+ consumers of a shared library or want to do plugins/hot-code reloading and have a solid versioning story by all means vend a DSO. If you don't however I would strongly recommend trying to keep all dependencies static and letting LTO/LTCG do its thing.

Re:The abysmal state of GNU/Linux and a case against shared ... by intelVISA on Monday October 14, 2024 @07:46PM (#41843443)
Indeed, I'm biased but often the arguments in favor of shared objs have fundamental misconceptions that betray a lack of lower-level tinkering that makes it hard to take seriously.
Re:The abysmal state of GNU/Linux and a case against shared ... by saagarjha on Monday October 14, 2024 @09:37PM (#41844073)
The same can be said for any position in this debate.
Re:The abysmal state of GNU/Linux and a case against shared ... by Lerc on Monday October 14, 2024 @04:42PM (#41841756)
In practice I don't think this results in memory savings. By having a shared library and shared memory use, you also have distributed the blame for the size of the application.

It would be true that this save memory if applications did not increase their memory requirements over time, but the fast is that they do, and the rate at which they increase their memory use seems to be dictated not by how much memory they intrinsically need but how much is available to them.

There are notable exceptions. AI models, Image manipulation programs etc. do actually require enough memory to store the relevant data.

On the other hand I have used a machine where the volume control sitting in the system tray used almost 2% of the system RAM.

Static linking enables the cause of memory use to be more clearly identified, That enables people to see who is wasting resources. When people can see who is wasting resources, there is a higher incentive to not waste them.

Re:The abysmal state of GNU/Linux and a case against shared ... by pessimizer on Monday October 14, 2024 @04:51PM (#41841850)
This is a law of averages argument. There is no rational argument for bloat in order to protect software from bloat. This is like saying that it doesn't matter that we waste money, because we're going to spend the entire budget anyway.
Re:The abysmal state of GNU/Linux and a case against shared ... by Lerc on Monday October 14, 2024 @04:54PM (#41841882)
I think it's more like,

If we pay money to someone to audit our books, we are more likely to achieve more within our budget.

Re:The abysmal state of GNU/Linux and a case against shared ... by intelVISA on Monday October 14, 2024 @07:51PM (#41843483)
Please don't soapbox under false pretenses - in no world does this "200mb non-shared dependency" comparison exist: that would imply static linkage is just appending a shared object into the executable at compile-time.
Re:The abysmal state of GNU/Linux and a case against shared ... by tdtd on Monday October 14, 2024 @06:42PM (#41842945)
This is certainly true on Windows, where loaded DLLs share the base addresses across processes even with ASLR enabled, but is it the case on Linux, where ASLR forces randomization of .so base addresses per process, so relocations will make the data in their pages distinct? Or is it the case that on modern architectures with IP-relative addressing (like x64) that relocations are so uncommon that most library pages contain none?
Re:The abysmal state of GNU/Linux and a case against shared ... by saagarjha on Monday October 14, 2024 @07:09PM (#41843167)
Code pages are intentionally designed to stay clean; relocations are applied elsewhere in pages that are different for each process.
Re:The abysmal state of GNU/Linux and a case against shared ... by pradn on Monday October 14, 2024 @04:25PM (#41841559)
It's possible for the OS to recognize that several pages have the same content (ie: doing a hash) and then de-duplicate them. This can happen across multiple applications. It's easiest for read-only pages, but you can swing it for mutable pages as well. You just have to copy the page on the first write (ie: copy-on-write).

I don't know which OSs do this, but I know hypervisors certainly do this across multiple VMs.

Re:The abysmal state of GNU/Linux and a case against shared ... by slabity on Monday October 14, 2024 @04:43PM (#41841769)
Even if the OS could perfectly deduplicate pages based on their contents, static linking doesn't guarantee identical pages across applications. Programs may include different subsets of library functions and the linker can throw out unused ones. Library code isn't necessarily aligned consistently across programs or the pages. And if you're doing any sort of LTO then that can change function behavior, inlining, and code layout.

It's unlikely for the OS to effectively deduplicate memory pages from statically linked libraries across different applications.

Re:The abysmal state of GNU/Linux and a case against shared ... by pradn on Monday October 14, 2024 @10:22PM (#41844315)
Ah, good to know! Thank you for explaining.

I guess much of this is why its hard to use shared libraries in the first place.

Re:The abysmal state of GNU/Linux and a case against shared ... by ChocolateGod on Monday October 14, 2024 @04:30PM (#41841618)
Correct me if I'm wrong Linux only supports KSM (memory-deduping) between processes when doing it between VMs, as QEMU provides information to the kernel to perform it.
Re:The abysmal state of GNU/Linux and a case against shared ... by yjftsjthsd-h on Monday October 14, 2024 @06:13PM (#41842633)
https://www.kernel.org/doc/html/latest/admin-guide/mm/ksm.ht...

> KSM was originally developed for use with KVM (where it was known as Kernel Shared Memory), to fit more virtual machines into physical memory, by sharing the data common between them. But it can be useful to any application which generates many instances of the same data

Although...

> KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call

Re:The abysmal state of GNU/Linux and a case against shared ... by pradn on Monday October 14, 2024 @10:22PM (#41844319)
I wonder if you could just madvise the entire address space. My hunch is that it's for performance reasons only - fewer pages to scan, hash, and de-duplicate.
Re:The abysmal state of GNU/Linux and a case against shared ... by MrDrMcCoy on Tuesday October 15, 2024 @01:26AM (#41845220)
You can. There are custom kernel builds that do this, as well as shim loaders that do that madvise call. However, those are considerably less practical than the recent systemd feature that allows you to do it per unit. If applied to the system scope, it effectively covers the whole system. However, there are caveats:

1. You need a much better newer systemd than your distro likely packages.

2. KSM dedupe scans aren't free. Your system can spend its time doing that scan or it can spend its doing work with duplicate pages. Only relatively idle or highly homogenous systems would be free of the penalty.

3. For applications, especially statically linked ones, the duplicated code is not super likely to fall along page boundaries, thus the actual detectable duplication will be relatively low.

That said, it's still great for densely deploying a high traffic microservice that's more memory than CPU bound.

Re:The abysmal state of GNU/Linux and a case against shared ... by indigodaddy on Monday October 14, 2024 @04:32PM (#41841638)
I remember many years ago VMWare developed a technology to take advantage of these shared library savings across VMs as well.

https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsp...

Re:The abysmal state of GNU/Linux and a case against shared ... by abhinavk on Monday October 14, 2024 @04:39PM (#41841721)
Linux’s KVM has it too. It’s called KSM.
Re:The abysmal state of GNU/Linux and a case against shared ... by indigodaddy on Monday October 14, 2024 @04:40PM (#41841742)
ah right, forgot about that as well
Re:The abysmal state of GNU/Linux and a case against shared ... by bbatha on Monday October 14, 2024 @04:25PM (#41841560)
Only if you don’t have LTO on. If you have LTO on you’re likely to use a fraction of the shared dependency size even across multiple apps.
Re:The abysmal state of GNU/Linux and a case against shared ... by odo1242 on Monday October 14, 2024 @04:31PM (#41841632)
That is a good point.
Re:The abysmal state of GNU/Linux and a case against shared ... by whatshisface on Monday October 14, 2024 @04:24PM (#41841545)
Isn't 200MB a little large for a dependency? The Linux kernel is ~30MB.
Re:The abysmal state of GNU/Linux and a case against shared ... by odo1242 on Monday October 14, 2024 @04:27PM (#41841587)
It's around the size of OpenCV, to be specific. I do see your argument though.
Re:The abysmal state of GNU/Linux and a case against shared ... by anotherhue on Monday October 14, 2024 @04:47PM (#41841811)
Assuming it is worth it with modern memory sizes (I think not), could this present a negative on NUMA systems? Forcing contention when a simple copy would have been sufficient?

I assume there's something optimising that away but I'm not well versed.

Re:The abysmal state of GNU/Linux and a case against shared ... by 839302 on Monday October 14, 2024 @07:09PM (#41843170)
Hola. No