如何创建100M字节缓冲区 [英] Howto create 100M Byte Buffer

查看:150
本文介绍了如何创建100M字节缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试Linux上接口的吞吐量.我正在使用DMA进行数据传输. DMA需要连续的内存位置.但是kmalloc无法分配超过1MB的内存.还有其他方法可以创建高达100M字节的大缓冲区位置吗?

I am testing the throughput of an interface on Linux. I am using the DMA todo the data transfer. DMA needs contiguous memory location. But the kmalloc is unable to allocate more then 1MB. Is there any other way to create big buffer location upto 100M Bytes?

推荐答案

我以为kmalloc无法分配超过128kB的空间,如何分配1MB的空间呢?

I thought kmalloc couldn't allocate over 128kB, how did you get it to allocate 1MB ?

无论如何,假设您正在使用新启动的系统,则最多可以保留2048个连续页面.页面通常为4k,因此占用8MB.

Anyway, assuming you're working on a freshly booted system, you can reserve up to 2048 contiguous pages. Pages are generally 4k, so this makes 8MB.

_get_free_pages(_GFP_DMA, get_order(2048));

但是,如果需要更多内存,则应在引导时进行分配. 如果要编写驱动程序,则可以使用alloc_bootmem_*函数来实现. 如果要编写模块,则必须将mem=参数传递给内核,然后再使用ioremap.

However, if you need more memory, you should do the allocation at boot-time. If you are writing a driver, this can be achieved with the alloc_bootmem_* functions. If you are writing a module, you have to pass mem= argument to your kernel and later use ioremap.

例如,如果您有2GB,则可以传递mem=1GB来禁止内核使用较高的1GB,然后再调用ioremap(0x40000000, 0x40000000)来访问仅为您使用的较高1GB.

For example, if you have 2GB, you can pass mem=1GB to forbid the kernel from using the upper 1GB, and later call ioremap(0x40000000, 0x40000000) to get access to the upper 1GB, just for you.

但是您知道,您应该将巨大的缓冲区拆分为许多小缓冲区,这将变得更加容易,并且更像是现实生活中的应用程序.

But you know, you should just split your huge buffer into many small ones, it'll be much easier and much more like real-life applications.

这篇关于如何创建100M字节缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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