开发者

Flush ELF section from RAM after library initialization

开发者 https://www.devze.com 2023-01-01 12:31 出处:网络
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

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 referenc开发者_高级运维e to this anywhere, so maybe I imagined it. Does such a thing exist?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消