库初始化后从 RAM 中刷新 ELF 部分

发布于 2024-09-03 05:47:15 字数 516 浏览 7 评论 0原文

我在 ELF 共享库中有很多代码,仅在库初始化期间使用(它是从静态初始化程序调用的)。如果我将此代码放在它自己的部分中(或者也许它可以放在 .init 部分中),我可以使用 __attribute__((section(".mysection"))) 来执行此操作,是否有如何在库加载后强制将此部分调出页面?

这个问题是相关的,但结论是内核将分页内存不足时未使用的页面,因此无需显式执行此操作。然而,我在嵌入式环境中工作,其中内存非常宝贵,并且从磁盘(慢速 USB 闪存驱动器)调入代码的成本很高。因此,我宁愿显式刷新这段代码,我知道这些代码永远不会再次使用,而不是让内核决定刷新一些最终可能需要重新分页的其他代码。

我确信我记得读过关于一个系统调用来要求内核调入或调出某些内存区域,尽管我在任何地方都找不到对此的任何引用,所以也许是我想象的。这样的事存在吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-09-10 05:47:15

查找有关 elf 覆盖的文档。安排您的代码,以便有一个覆盖层用于初始化,另一个覆盖层用于处理。您可能还想查看关闭的覆盖图。当调用下一个覆盖时,应替换覆盖中的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文