Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared objects overhead

We have a very modular application with a lot of shared objects (.so). Some people argue that on low-end platforms with limited memory/flash, it is better to statically link everything into one big executable as shared objects have overhead.

What is your opinion on this ?

Best Regards,

Paul

like image 335
Paul Praet Avatar asked Oct 19 '11 11:10

Paul Praet


People also ask

What are shared objects?

A shared object is an indivisible unit that is generated from one or more relocatable objects. Shared objects can be bound with dynamic executables to form a runable process. As their name implies, shared objects can be shared by more than one application.

What are shared objects in Linux?

so (short for "shared object"). Shared libraries are the most common way to manage dependencies on Linux systems. These shared resources are loaded into memory before the application starts, and when several processes require the same library, it will be loaded only once on the system.

How do shared object libraries work?

Simply put, A shared library/ Dynamic Library is a library that is loaded dynamically at runtime for each application that requires it. Dynamic Linking doesn't require the code to be copied, it is done by just placing name of the library in the binary file.

How do I view the contents of a .so file?

Instead, they're just placed in an appropriate folder and used automatically by other programs via Linux's dynamic link loader. However, you might be able to read the SO file as a text file by opening it in a text editor like Leafpad, gedit, KWrite, or Geany if you're on Linux, or Notepad++ on Windows.


1 Answers

The costs of shared libraries are roughly (per library):

  • At least 4k of private dirty memory.
  • At least 12k of virtual address space.
  • Several filesystem access syscalls, mmap and mprotect syscalls, and at least one page fault at load time.
  • Time to resolve symbol references in the library code.

Plus position-independent code costs:

  • Loss of one general-purpose register (this can be huge on x86 (32bit) but mostly irrelevant on other archs).
  • Extra level of indirection accessing global/static variables (and constants).

If you have a large long-running application, the costs may not matter to you at all, unless you're on a tiny embedded system. On the other hand, if you're writing something that may be invoked many times for short tasks (like a language interpreter) these costs can be huge. Putting all of the standard modules in their own .so files rather than static linking them by default is a huge part of why Perl, Python, etc. are so slow to start.

Personally, I would go with the strategy of using dynamic loaded modules as a extensibility tool, not as a development model.

like image 156
R.. GitHub STOP HELPING ICE Avatar answered Oct 11 '22 20:10

R.. GitHub STOP HELPING ICE