有没有人见过一个分配器调用 mlock(2) 来防止 STL 容器的内容被交换到磁盘?
编写这样一个分配器只有一个棘手的部分,即通过对要 mlock 的分配进行集群来最小化 mlocked 页的数量。因此,人们可能应该从修改一些共享内存分配器开始?
Has anyone seen an allocator that calls mlock(2) to prevent an STL container's contents from being swapped to disk?
There is afaik only one tricky part to writing such an allocator, namely minimizing the number of mlocked pages by clustering allocations to be mlocked. Ergo, one should probably start by modifying some shared memory allocator?
发布评论
评论(1)
如果我想实现这个(这很难想象,因为我发现很难相信它是解决任何问题的正确解决方案:^),我会尝试使用
boost::pool_allocator
(它提供了一个来自池的标准库兼容分配器),然后 - 我忘记了细节;认为它将涉及 RequestedSize 模板参数rel="nofollow">singleton_pool
和一个user_allocator
? - 将有某种方法让它位于池的顶部,通过您选择的机制请求更大的内存块,在您的情况下,这将是分配 mlocked 页面。If I wanted to implement this (which is difficult to imagine, because I find it hard to believe it's the right solution to any problem :^), I'd try to do it by using a
boost::pool_allocator
(which provides a standard library compatible Allocator from a pool) and then - I forget the details; think it'll involve theRequestedSize
template argument tosingleton_pool
and auser_allocator
? - there will be some way of having that sit on top of a pool which requests bigger chunks of memory by the mechanism of your choice which in your case would be allocation of mlocked pages.