1

How one should implement a dynamic loading system where instead of loading an entire library to the memory, the kernel would load only the necessary function?

Considering that each function have a hash id (md5 maybe) from its binary format, where each application using that function only point to the hash. The system would load the function from a functions repository and checking it's id against the hash sum, when it's not found on the local filesystem.

Would it be necessary to mess with kernel code in order to implement this?

closed as too broad by Michael Homer, Rui F Ribeiro, ilkkachu, Archemar, jimmij Feb 25 at 13:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • "the kernel would load" ... "Would it be necessary to mess with kernel?" if you want the kernel to do something, you'll have to mess with it. Necessarily. But in fact a) it's not the kernel which is doing the dynamic linking and resolving symbols and b) when a library is "loaded" (mmaped) in the address space of a process, it is not copied whole from disk into the memory at once; its pages will be only faulted in by the kernel when used. So, in the current implementation, only the code actually used is loaded from disk. Your idea offers no benefits whatsoever. – mosvy Feb 24 at 21:15
  • You are essentially thinking on a kernel with very small, hot-swappable modules. It could be done and it would work. However, today the kernel uses only a very little RAM, at most some tens of megabytes (but some megs are more typical). There is no need to really optimize it out, but it could be done and it wouldn't be a very big work. – peterh Feb 25 at 18:17