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

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

问题描述

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

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天全站免登陆