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?