简体   繁体   English

释放锁定的内存是否可以解锁相应的页面?

[英]Does freeing locked memory unlock the corresponding pages?

It's clear how you can combine mlockall() and malloc() to lock all the pages allocated by a process during its life. 很明显,如何结合使用mlockall()malloc()来锁定进程在其生命周期内分配的所有页面。 What is not clear to me by reading the documentation is whether freeing already locked memory implies an automatic unlock of the corresponding pages. 通过阅读文档对我来说不清楚的是,释放已经锁定的内存是否意味着相应页面的自动解锁。

If free returns the memory to the system (ie it was allocated with mmap and will be freed with munmap ), then the lock will automatically be removed when it is unmapped. 如果free将内存返回给系统(即,它是使用mmap分配的,并且将通过munmap释放),那么在取消映射时,锁将自动删除。 This is typically the case with large allocations. 分配较大时通常是这种情况。

If free returns the memory to a heap managed within the process, then the lock will remain. 如果free将内存返回到进程内管理的堆,则锁将保留。 This is typically the case for small allocations. 小分配通常是这种情况。

On GNU/Linux, you can use mallopt to get and set the threshold for allocations using mmap ; 在GNU / Linux上,您可以使用mallopt使用mmap获取并设置分配阈值; the default (on my computer, at least) is 128kb. 默认值(至少在我的计算机上)为128kb。 On other Unix flavours, you might need to use mmap directly if you need that level of control. 在其他Unix风格上,如果需要该级别的控制,则可能需要直接使用mmap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM