Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From the kernel to the user space (DMA)

Lately, I have been reading a lot of websites,and books about 10gb/s NICs, their DMA and the way data are handled by the linux kernel (10/100 mb/s NICs) and a few questions came to my mind.

What would be the easiest way to send a 10GB/s flow of data from the NIC to the user-land (I assume being able to process the data in the user-land at the same rate).

And

Do you think it would be a good idea to implement the DMA buffer inside the user-space to read the raw data directly from there (and process them obviously at the same rate)

or is their any better solutions I didn't think of :/

Thank you.

like image 844
noktec Avatar asked Jun 21 '12 11:06

noktec


People also ask

What is DMA in kernel?

DMA stands for direct memory access and refers to the ability of devices or other entities in a computing system to modify main memory contents without going through the CPU.

How do you allocate DMA memory?

Allocating a Huge Page Each huge page allocation is described by a HugePage structure. This structure encapsulates the virtual and physical address of an allocated huge page along with the size of the page in bytes. To allocate a huge page we want to use the mmap system call with the MAP_HUGETLB flag.

Does Linux use DMA?

So that Linux can use the dynamic DMA mapping, it needs some help from the drivers, namely it has to take into account that DMA addresses should be mapped only for the time they are actually used and unmapped after the DMA transfer. The following API will work of course even on platforms where no such hardware exists.

What is DMA mapping?

DMA mapping is a conversion from virtual addressed memory to a memory which is DMA-able on physical addresses (actually bus addresses).


2 Answers

The easiest thing it to use Linux's normal sockets. It might not be the most efficient, but it's easiest.

There are frameworks, which allow very efficiently to receive and transmit data in user space. They map the same buffers to the NIC (DMA) and the process, so data doesn't need to be copied.
These frameworks bypass the kernel completely - you have to interact with the NICs directly. Such frameworks are, for example, PF-RING and Netmap

like image 97
ugoren Avatar answered Oct 13 '22 12:10

ugoren


I would also suggest to take a look at the PFQ framework ( https://github.com/pfq/PFQ and http://netgroup.iet.unipi.it/software/pfq/), which build on top of netmap and pf_ring concepts and hides them to allow simple multi-core packet processing in user space.

like image 33
pierigno Avatar answered Oct 13 '22 12:10

pierigno