分配最大的缓冲而不使用交换 [英] Allocating largest buffer without using swap

查看:86
本文介绍了分配最大的缓冲而不使用交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux下的C / C ++,我需要分配一个大的内存(数千兆字节)块,以从连接到以太网端口和流数据大约110MB / s的传感器,存储实时数据。我想分配的内存可能量最大,以最大限度地提高,我可以存储数据序列的长度。然而,我还需要确保不会有圆盘交换,因为所得延迟和磁盘访问有限带宽引起传感器的(非常有限的)缓冲器溢出。

In C/C++ under Linux, I need to allocate a large (several gigabyte) block of memory, in order to store real-time data from a sensor connected to the ethernet port and streaming data at about 110MB/s. I'd like to allocate the largest amount of memory possible, to maximise the length of data sequence that I can store. However, I also need to make sure that there will be no disk-swapping, since the resulting delay and limited bandwidth of disk access causes the sensor's (very limited) buffer to overflow.

什么是确定有多少内存分配的最佳方式?难道我只限于分配大于报告的可用内存稍小块,或者我可以更直接地与Linux虚拟内存管理器界面?

What is the best way to determine how much memory to allocate? Am I limited to just allocating a slightly smaller block than the reported free memory, or can I interface more directly with the linux virtual memory manager?

推荐答案

那么,在Linux下你可以使用MLOCK()/ mlockall用于(),以保持在物理内存和prevent它的ADRESS范围内被交换出去。使用MLOCK这个过程需要一对夫妇的权限这样做,人MLOCK有详细信息。我不知道有关最高mlock'able块(它可能会从什么似乎是免费的不同),所以可能是一个二进制搜索可以帮助(锁定一个范围,如果失败减少面积等尺寸。)

Well, under linux you can use mlock()/mlockall() to keep an adress range in physical memory and prevent it from being swapped out. The process using mlock needs a couple of privileges to do so, "man mlock" has the details. I am not sure about the maximum mlock'able block (it might differ from what seems to be "free"), so probably a binary search could help (lock a range, if that fails reduce the size of the area etc..)

在另一方面,110MB / s是不是真的固态驱动器有问题。 60GB的SSD具有280MB / s的写入速度在角落里的成本约为$ 200。只是将传感器数据复制到一个小的写缓冲器和流是到SSD。

On the other hand, 110MB/s is not really a problem for a Solid-State-Drive. A 60GB SSD with 280MB/s write speed costs about $200 on the corner. Just copy the sensor data into a small write buffer and stream that to the SSD.

这篇关于分配最大的缓冲而不使用交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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