非阻塞mlock() [英] Non-blocking mlock()

查看:362
本文介绍了非阻塞mlock()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有阻塞的mlock()这样的东西?在流量较大的情况下,我不希望我的线程阻塞等待I / O。我宁愿只告诉Linux内核使用mlock()从一个mmap()的d文件需要什么区域,然后当页面被获取时得到通知。 (据我所知,标准mlock()调用是阻塞的。)

解决方案

我相信你想要一个组合 madvise() posix_madvise() mincore()



您将使用 madvise 调用来询问内核 MADV_WILLNEED 。然后,您必须使用 mincore 轮询,以检查页面是否已读入内存。



如果系统在负载很重的情况下,页面可能不会被 madvise 调用读取,因此您需要超时和回退到阻塞读取模式。 / p>

Is there such a thing as non-blocking mlock()? Under heavy traffic, I don't want my threads block waiting for I/O. I'd rather just tell the Linux kernel what region I need from a mmap()'d file using mlock() and then get notified when the pages has been fetched. (As far as I know, the standard mlock() call is blocking.)

解决方案

I believe that you want a combination of madvise() or posix_madvise() and mincore().

You would use a madvise call to ask the kernel for MADV_WILLNEED. Then you would have to poll using mincore to check if the pages had been read into memory.

If the system is under heavy memory load it is possible for the pages to never be read in by the madvise call, so you would need a timeout and a fallback to a blocking read mode.

这篇关于非阻塞mlock()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆