Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transferring very large DMA buffers #9

Open
McGr opened this issue Feb 14, 2017 · 2 comments
Open

Transferring very large DMA buffers #9

McGr opened this issue Feb 14, 2017 · 2 comments

Comments

@McGr
Copy link

McGr commented Feb 14, 2017

Hi Jeremy,
I'm trying to DMA very large buffers (512M byte if I can) into memory. I seem to run into a memory problem for sg_alloc_table if I try to create a DMA buffer > 1Mbyte. I believe I just have too many entries in the sg table.
My AXI DMA core is configured with 23bit addressing for the scatter/gather engine which should allow for individual DMA blocks of up to 8MByte each, so it should be possible to describe the 512 MByte buffer with just 64 chained entries. Looking at the ezdma driver it seems like you are allocating blocks of 4096 bytes for each of the scatterlist entries. Is there a way to allocate 8Mbyte blocks for each of the scatterlist entries so I can reduce the number of them?

Thanks Mike.

@jeremytrimble
Copy link
Owner

Mike,

I think the reasoning for this is because there's no guarantee that the userspace buffer (which appears to be contiguous inside the userspace process's virtual memory) is actually physically contiguous. In fact, if you have a 512 Mbyte buffer I'm almost sure that it isn't physically-contiguous -- on Zynq systems I've worked with, 4 MB was the maximum physically-contiguous allocation that was possible without special accomodations (e.g. the CMA -- contiguous memory allocator).

4096 bytes is the size of a single page (the smallest unit of contiguous allocation), so allocating buf_size/4096 is kind of assuming worst-case (every page is physically discontiguous). I suspect with a little bit of logic after calling get_user_pages() it would be possible to compute exactly how many scatterlist entries are required (one for each contiguous section), and only allocate that many entries in sg_alloc_table().

@Livius90
Copy link

Livius90 commented Apr 16, 2021

Hi Jeremy,
I'm trying to DMA very large buffers (512M byte if I can) into memory. I seem to run into a memory problem for sg_alloc_table if I try to create a DMA buffer > 1Mbyte. I believe I just have too many entries in the sg table.
My AXI DMA core is configured with 23bit addressing for the scatter/gather engine which should allow for individual DMA blocks of up to 8MByte each, so it should be possible to describe the 512 MByte buffer with just 64 chained entries. Looking at the ezdma driver it seems like you are allocating blocks of 4096 bytes for each of the scatterlist entries. Is there a way to allocate 8Mbyte blocks for each of the scatterlist entries so I can reduce the number of them?

Thanks Mike.

Root cause of your problem is that there is a hard-coded limitation in the Linux kernel driver xilinx_dma.c.

https://github.com/Xilinx/linux-xlnx/blob/xilinx-v2020.2/drivers/dma/xilinx/xilinx_dma.c#L181

#define XILINX_DMA_NUM_DESCS		255

You need to make a patch for Linux kernel and increase this max desc num, for example to 8*255 or more for your 8MB demand and it should works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants