Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flush ELF section from RAM after library initialization

I have a lot of code in an ELF shared library that is only used during library initialization (it's called from static initializers). If I put this code in its own section (or perhaps it can go in the .init section), which I can do using __attribute__((section(".mysection"))), is there a way to force this section to be paged out after the library has loaded?

This question is related, but the conclusion there was that the kernel will page out unused pages when it's short of memory, so there's no need to do so explicitly. However, I am working in an embedded environment where memory is at a premium and the cost of paging in code from disk (a slow USB flash drive) is high. Therefore I'd rather explicitly flush this code, which I know is never going to be used again, rather than have the kernel maybe decide to flush some other code which might eventually need to be paged back in.

I'm sure I remember reading about a syscall to ask the kernel to page in or out certain regions of memory, though I can't find any reference to this anywhere, so maybe I imagined it. Does such a thing exist?

like image 505
jchl Avatar asked May 27 '10 20:05

jchl


1 Answers

Look for documentation on elf overlays. Arrange your code so you have an overlay for initialization, and another for processing. You may also want to look at an overlay for shutdown. Code in overlays should be replaced, when the next overlay is called.

like image 187
BillThor Avatar answered Nov 17 '22 15:11

BillThor