开发者

Howto create 100M Byte Buffer

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开发者_C百科 any other way to create big buffer location upto 100M Bytes?


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

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));

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.

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜