gpt4 book ai didi

c - 您如何理解 mlockall 手册页?

转载 作者:太空狗 更新时间:2023-10-29 11:27:48 29 4
gpt4 key购买 nike

mlockall 在我的内核 3.0 上的手册页说

mlockall() locks all pages mapped into the address space of the calling process. This includes the pages of the code, data and stack segment, as well as shared libraries, user space kernel data, shared memory, and memory-mapped files. All mapped pages are guaranteed to be resident in RAM when the call returns successfully; the pages are guaranteed to stay in RAM until later unlocked.

后来又说

Real-time processes that are using mlockall() to prevent delays on page faults should reserve enough locked stack pages before entering the time-critical section, so that no page fault can be caused by function calls. This can be achieved by calling a function that allocates a sufficiently large automatic variable (an array) and writes to the memory occupied by this array in order to touch these stack pages. This way, enough pages will be mapped for the stack and can be locked into RAM. The dummy writes ensure that not even copy-on-write page faults can occur in the critical section.

我知道这个系统调用无法猜测将达到的最大堆栈大小,因此无法为堆栈锁定页面。但是为什么上面显示的人的第一部分说它也为堆栈完成了?此手册页中是否有错误,或者它只是意味着锁定是针对初始堆栈大小完成的?

最佳答案

是的,锁定是针对当前堆栈页面完成的,但不是针对所有可能的 future 堆栈页面。

关于c - 您如何理解 mlockall 手册页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10017928/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com