开发者

How to pin a shared memory segment into physical memory

开发者 https://www.devze.com 2023-03-27 10:47 出处:网络
I use boost::interprocess::managed_shared_mem开发者_开发技巧ory to load a data structure in shared memory. I need to pin the shared memory segment into physical memory (for example similar to system c

I use boost::interprocess::managed_shared_mem开发者_开发技巧ory to load a data structure in shared memory. I need to pin the shared memory segment into physical memory (for example similar to system call mlock for mapped files).

In linux, sooner or later my data structure gets swapped out of physical memory. In my case this incurs a forbidding cost for the next process accessing the structure, after it has been swapped out.

Is there any way to pin shared memory into physical memory? I am interested in any solution, even if it means that I cannot use boost::interprocess.


Using basic_managed_xsi_shared_memory (apparently available since boost 1.46), you can access the underlying shmid (from the get_shmid member) which should allow you to control the shmid using shmctl. With shmctl you can prevent the swapping of shared memory pages by applying the SHM_LOCK command to the shmid.

Other types of locking (which you refer to as 'pinning'), such as locking memory mapped files into memory, can be realized by supplying return values obtained from mapped_region's get_address and get_size member functions to the mlock command.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号