1

当我使用 mlockall 将所有进程锁定在内存中时,我有一个运行内存占用约为 150MB 的多线程 Linux 应用程序。这样做是为了避免一些具有低延迟要求的高优先级线程的页面错误。但是,只有选择执行流/上下文具有这样的要求,我试图仅为这些流锁定代码和数据,以便我可以减少进程的锁定内存占用。这个想法是将所有这些功能收集在一个单独的文本部分中,然后锁定页面。该想法的蓝图如下

//Define a marker for compiler for all code that needs to be locked:
#define __hard_rt_fn  __section(.locked.txt)

//mark the identified functions with the marker
Event* __hard_rt_fn GetEvent();

//Ask the loader/linker script to give the start and end address of the 
.locked ():
{
    __locked_start = .;
    *(.text);
    *(.rodata.*);
}
__locked_size = SIZEOF(.locked);
Export(__locked_start);
Export(__locked_size);

//In the main initialisation function, lock the section

extern long int __locked_start;
extern long int __locked_size;

Main()
{
 ……
 mlock(__locked_start,__locked_size);
 ……

}

这种方法的灵感来自嵌入式系统上采用的方法,其中一部分代码需要重新定位在 RAM 中,而其余部分则留在 ROM 中。我有以下疑问
1.这可以通过动态(gnu)链接器/加载器实现吗?
2.如何为动态加载的共享库指定页面锁定。
3.是否有更好的方法或工具来仅锁定已识别的代码和数据部分。

4

0 回答 0