A SERVICE OF

logo

4285ch01.fm Draft Document for Review May 4, 2007 11:35 am
28 Linux Performance and Tuning Guidelines
Network API (NAPI)
The network subsystem has undergone some changes with the introduction of the new
network API (NAPI). The standard implementation of the network stack in Linux focuses more
on reliability and low latency than on low overhead and high throughput. While these
characteristics are favorable when creating a firewall, most enterprise applications such as
file and print or databases will perform more slowly than a similar installation under
Windows®.
In the traditional approach of handling network packets, as depicted by the blue arrows in
Figure 1-25, the network interface card eventually moves the packet into a network buffer of
the operating systems kernel and issues a hard interrupt at the CPU, as we stated before.
This is only a simplified view of the process of handling network packets, but it illustrates one
of the shortcomings of this very approach. As you have realized, every time an Ethernet
frame with a matching MAC address arrives at the interface, there will be a hard interrupt.
Whenever a CPU has to handle a hard interrupt, it has to stop processing whatever it was
working on and handle the interrupt, causing a context switch and the associated flush of the
processor cache. While one might think that this is not a problem if only a few packets arrive
at the interface, Gigabit Ethernet and modern applications can create thousands of packets
per second, causing a vast number of interrupts and context switches to occur.
Figure 1-25 The Linux network stack
DEVICE
/net/core/dev.c:_netif_rx_schedule(&queue->backlog_dev)
/net/core/dev.c:int netif_rx(struct sk_buff *skb)
/net/core/dev.c_raise_softirq_irqoff(NET_RX)SOFTIRQ)
net/core/dev.c:net_rx_action(struct softirq_action *h)
process_backlog(struct net_device *backlog_dev, int *budget)
netif_receive_skb(skb)
ip_rcv() arp_rcv()
NAPI way
DEVICE
/net/core/dev.c:_netif_rx_schedule(&queue->backlog_dev)
/net/core/dev.c:int netif_rx(struct sk_buff *skb)
/net/core/dev.c_raise_softirq_irqoff(NET_RX)SOFTIRQ)
net/core/dev.c:net_rx_action(struct softirq_action *h)
process_backlog(struct net_device *backlog_dev, int *budget)
netif_receive_skb(skb)
ip_rcv() arp_rcv()
NAPI way