DLL Caching Issues

In terms of top performance, does the link to the static vs dynamic link support performance because of the higher cache-skipping ratio for the DLL?

My idea is that when the library is statically , the whole program loads in one place or nearby. But when dynamically linked, a DLL can be loaded somewhere, and variables can be allocated β€œtoo far”.

Is this true or not a performance penalty for the DLL in terms of cache miss ratio ? (only fast C / C ++ code)

+4
source share
3 answers

"the whole program loads in place": your system memory manager will still map the pages of the executable memory to physical memory so that you like it - you do not control this. At run time, the physical pages will be replaced with a disk if other parts of the executable code are needed.

Using a shared library can reduce the number of code pages needed in physical memory when multiple processes can actually share the library.

In summary:

NO: dynamic or static communication does not directly affect cache misses. Dynamic linking can reduce cache misses for heavily reusable libraries.

+3
source

Memory does not have to be contiguous for good cache performance. A cache line size that ranges from a few bytes to a few hundred is usually much smaller than a DLL.

+1
source

I would say profile first!

Physical location does not affect access time. The address space seems linear, but can actually be mapped to any page of physical memory.

You need to set up custom distribution and VirtualLock to gain control over the physical layout of the pages.

Notes

  • Usually using shared DLL files mitigates the problem that you have clearly identified by sharing pages with other processes that share the same image. This results in fewer cached pages and less need to replace them.

  • I would say that the data file is not actually displayed, but rather is allocated from the private address space of processes, so locality may look like statically related data. You can try using a heap debugger / visualizer to find out how this works).

If you want a simple way to get complete control, just extract all the things from HEAP - using your preferred distribution scheme. If there is static data from a DLL, just copy it to this area?

+1
source

All Articles