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?
我在ELF共享库中有很多代码,它只在库初始化期间使用(它是从静态初始化器调用的)。如果我把这段代码放在它自己的部分(或者它可以进入.init部分),我可以使用__attribute __((section(“。mysection”))),有没有办法强制这部分是在库加载后分页?
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.
这个问题是相关的,但结论是内核会在内存不足时分页出未使用的页面,因此没有必要明确地这样做。但是,我正在一个内存非常宝贵的嵌入式环境中工作,而来自磁盘(慢速USB闪存驱动器)的代码分页成本很高。因此,我宁愿显式刷新这段代码,我知道永远不会再次使用它,而不是内核可能决定刷新其他可能最终需要重新分页的代码。
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?
我确定我记得读过有关系统调用的内容,要求内核进入或退出某些内存区域,虽然我无法在任何地方找到任何引用,所以也许我想象它。这样的事情存在吗?
1 个解决方案
#1
2
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.
查找有关精灵叠加层的文档。排列代码,使您有一个覆盖初始化,另一个用于处理。您可能还想查看关闭的叠加层。当调用下一个叠加时,应替换叠加中的代码。
#1
2
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.
查找有关精灵叠加层的文档。排列代码,使您有一个覆盖初始化,另一个用于处理。您可能还想查看关闭的叠加层。当调用下一个叠加时,应替换叠加中的代码。