Search code examples
network-programmingdata-structureslinux-kernellinux-device-driver

Where is the Ring Buffer in linux kernel networking?


I know when you recv data from NIC, there is a ring buffer that NIC DMA data into it, and some NIC supports multiple ring buffer. But I wonder where does the ring buffer store, in which struct, or should I manually alloc a ring buffer when writing a Network Driver?

where does the ring buffer store, and what does it look like, better if show me the source code, thank you a lot.


Solution

  • image it: enter image description here

    your question ---- where does the ring buffer store, in which struct, or should I manually alloc a ring buffer when writing a Network Driver?

    • it's created by net driver, the ring buffer, using kernel's fifo data structor, and its memory is allocated through kernel's method, thus located in kernel's data segment.

    • the kernel(without net driver) called net driver to pull up the nic(hardware), and the net driver manage the ring buffer for the kernel's ip protocal stack to use.

    • when data come from nic, nic do 2 things(which is not drawn in the picture above):

      1. save data through DMA into the ring buffer
      2. hardware interrupt: tell cpu(the kernel thread) to recv data from the ring buffer