NDIS Driver Performance and allocation of Net Buffer Lists (NBL) and NB In the Send and Receive Path

DaveSC 20 Reputation points
2025-05-03T12:35:51.9566667+00:00

Gooday,

I am writing an NDIS filter driver and I would Like to know if it is very efficient to allocate NBL, or NBL Context from receive and send path, without affecting performance. I would like to know if functions like NdisAllocateNetBuffer(), NdisAllocateNetBufferLists() and NdisAllocateNetBufferListContext() allocate from a pool which reduces memory fragmentations and whether this is a good idea to keep allocating inside the Receive and Send Path.

So far, I have 3 approaches I am thinking about (So far I have implemented Approach 1

Approach 1: that allocates about 3000 Net Buffer Lists (NBL) with NB using NdisAllocateNetBufferLists during driver initialization. They have context so, I put them in a que. In the receive path, I then allocate from the Que

Approach 2: Instead of allocating an NBL, allocate context on the NBL from the underlying or overlying driver using NdisAllocateNetBufferListContext() and save necessary information and modify the fields in the header I am interested in. I also change the SourceHandle. When The packet is returned, I then undo the changes and return it to the original driver.

Approach 3: Allocate a New NBL using NdisAllocateNetBufferList() and NB and allocate my own MDL structure.

Approach 2 only allocates context, which allows me to modify some of the fields in the NB and MDL and restore these later.

I would like to know if there is allocating from the NdisAllocateNetBufferList() in the receive and send path will have an impact on performance? Does NDIS Cache the NBLs, NBs and Contexts so that allocation and deallocation is almost similar to Lookaside List operation.

This would have been easy if NDIS allowed NBLs, NB to be allocated from private pools.

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,685 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wagner Silva 0 Reputation points Microsoft Employee
    2025-05-03T14:18:30.1766667+00:00

    Allocating Net Buffer Lists (NBLs), Net Buffers (NBs), and associated contexts dynamically within the receive and send paths of an NDIS filter driver can impact performance if not managed efficiently. While NDIS provides functions like NdisAllocateNetBuffer(), NdisAllocateNetBufferLists(), and NdisAllocateNetBufferListContext() to allocate these structures, frequent allocations and deallocations can lead to memory fragmentation and increased latency.

    Performance Considerations

    • Memory Fragmentation: Continuous allocation and deallocation of NBLs and NBs can cause memory fragmentation, leading to inefficient memory usage and potential allocation failures.
    • Latency: Dynamic allocation during packet processing can introduce latency, affecting the overall performance of the network stack.
    • Cache Efficiency: NDIS does not inherently cache NBLs, NBs, or contexts in a manner similar to lookaside lists, meaning each allocation may involve more overhead.

    Recommended Approaches

    To mitigate performance impacts, consider the following strategies:

    1. Pre-allocate Buffers: Allocate a pool of NBLs and NBs during driver initialization. This approach reduces the need for dynamic allocations during packet processing, thereby minimizing latency and fragmentation.
    2. Use Lookaside Lists: Implement lookaside lists to manage memory for NBLs and NBs. This technique allows for efficient reuse of memory, reducing the overhead associated with frequent allocations and deallocations.
    3. Allocate Contexts Only: If the underlying or overlying driver supports it, allocate context for NBLs using NdisAllocateNetBufferListContext(). This method allows modification of certain fields without the need for full NBL allocation, reducing overhead.
    4. Optimize MDL Usage: When allocating NBs, consider using NdisAllocateNetBufferMdlAndData() to allocate the NET_BUFFER structure, MDL, and data in a single memory buffer. This approach can improve performance by reducing the number of allocations and simplifying memory management.

    While dynamic allocation of NBLs, NBs, and contexts is feasible, it is advisable to minimize such allocations within the receive and send paths to enhance performance. Implementing pre-allocation strategies and utilizing memory management techniques like lookaside lists can significantly improve the efficiency of your NDIS filter driver.

    0 comments No comments

Your answer