1

What are in-memory function calls? Could someone please point me to some resource discussing this technique and its advantages. I need to learn more about them and at the moment do not know where to go. Google does not seem to help as it takes me to the domain of cognition and nervous system etc..

Ketan Maheshwari
  • 2,002
  • 3
  • 25
  • 31
  • 1
    Can you better specify what you mean? Where did you read this term? – sarnold May 22 '11 at 23:48
  • As much as I understood: If a program or a set of programs are very large, at run time, they are allocated memory which is supposedly allocated function-wise. That means, for a set of active programs, some functions are in the memory (which means calls are quick) while others are not in memory thus calls are slower. The idea is to somehow only call (as much as possible) functions that are in memory at a time. – Ketan Maheshwari May 23 '11 at 00:31
  • 6 questions, no accepted answers? – Joe May 23 '11 at 01:58
  • @Joe, Does that amount to anything? Not sure why this comment on this question. Fixed it for a couple questions anyways. For the rest, I really am not satisfied with the answers. Thanks for reminding. – Ketan Maheshwari May 23 '11 at 03:20
  • This is a site predicated on questions and answers. If you are getting good answers, they should be accepted. I'm not saying it should be 100%, but 0% implies a lack of respect for the community. If you've asked 5 or 6 questions with no acceptable answers, you might want to look at the quality and focus of the questions you are asking. – Joe May 23 '11 at 10:51

1 Answers1

1

Assuming your explanatory comment is correct (I'd have to see the original source of your question to know for sure..) it's probably a matter of either (a) function binding times or (b) demand paging.

Function Binding

When a program starts, the linker/loader finds all function references in the executable file that aren't resolvable within the file. It searches all the linked libraries to find the missing functions, and then iterates. At least the Linux ld.so(8) linker/loader supports two modes of operation: LD_BIND_NOW forces all symbol references to be resolved at program start up. This is excellent for finding errors and it means there's no penalty for the first use of a function vs repeated use of a function. It can drastically increase application load time. Without LD_BIND_NOW, functions are resolved as they are needed. This is great for small programs that link against huge libraries, as it'll only resolve the few functions needed, but for larger programs, this might require re-loading libraries from disk over and over, during the lifetime of the program, and that can drastically influence response time as the application is running.

Demand Paging

Modern operating system kernels juggle more virtual memory than physical memory. Each application thinks it has access to an entire machine of 4 gigabytes of memory (for 32-bit applications) or much much more memory (for 64-bit applications), regardless of the actual amount of physical memory installed in the machine. Each page of memory needs a backing store, a drive space that will be used to store that page if the page must be shoved out of physical memory under memory pressure. If it is purely data, the it gets stored in a swap partition or swap file. If it is executable code, then it is simply dropped, because it can be reloaded from the file in the future if it needs to be. Note that this doesn't happen on a function-by-function basis -- instead, it happens on pages, which are a hardware-dependent feature. Think 4096 bytes on most 32 bit platforms, perhaps more or less on other architectures, and with special frameworks, upwards of 2 megabytes or 4 megabytes. If there is a reference for a missing page, the memory management unit will signal a page fault, and the kernel will load the missing page from disk and restart the process.

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • Hi, I am curious if an executable is poorly written that it has many dead codes referring like 1000 of functions externally (i.e. .so files) but only like 100 of those functions are actually called during runtime, will LD_BIND_NOW=1 be worse than LD_BIND_NOW not set? Because the Procedure Linkage Table will contain 900 useless function addresses? Worse in a sense of memory footprint and performance (as I don't know whether the lookup is O(n)). Thanks in advance! – Hei Dec 19 '17 at 00:58
  • @Hei, it'd probably be best to ask this as a new question, to get the most chance of getting high-quality answers. I suspect `LD_BIND_NOW` performance in that case would be pretty painful compared to demand-binding, but the security benefits of `LD_BIND_NOW` may make it worthwhile all the same. – sarnold Jan 05 '18 at 00:40
  • Thanks. Just started another post: https://stackoverflow.com/questions/48109146/ld-bind-now-can-make-the-executable-run-slower – Hei Jan 05 '18 at 07:37