Skip to contentSkip to conversation

UDP packet loss when running lsof

DISCUSSION John Miller 2 participants 5 messages May 21, 2007 – May 22, 2007 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I'm experiencing silent (no counter increased or log message) UDP packet loss inside the kernel (2.6.16.27 from Novell).

My application receives about 50 MB of multicast UDP traffic and writes the packets into files. If I comment out the write() call, the application runs for days without packet loss. With the write() at some random times (20 minuntes or even hours) blocks of packets (from 10 to 300) are lost.

While I can run 10 "while true; do true; done" or a "dd" that writes additional data to disk without any effect on the packet loss, a simple "lsof" forces packet loss most of the time.

Are there any more configuration options of the kernel that will help? Which system calls of lsof are blocking the network data throughput of the kernel?

Some background about the things I already did:

- I increased the max allowed receive buffer through proc/sys/net/core/rmem_max and the application calls the right syscall. "netstat -su" does not show any "packet receive errors".

- After getting "kernel: swapper: page allocation failure. order:0, mode:0x20", I increased /proc/sys/vm/min_free_kbytes

- ixgb.txt in kernel network documentation suggests to increase net.core.netdev_max_backlog to 300000. This did not help.

- I also had to increase net.core.optmem_max, because the default value was too small for 700 multicast groups.

- Network card is handled by bnx2 kernel module

- The application uses multiple threads for receiving and writing, so the receiver threads can still receive while the writer threads are waiting for I/O completions.

TIA for any help and suggestions.
JM

#2 lore raw
In reply to a message not in the archive

Hi Eric,

Quoted 2 lines

I CCed netdev since this stuff is about network and not lkml.

Ok, dropped the CC...

Quoted 1 line

What kind of machine do you have ? SMP or not ?

It's a HP system with two dual core CPUs at 3GHz, the storage system is connected through QLogic FC-HBA. It should really be fast enough to handle a data stream of 50 MB/s...

Quoted 3 lines

If you have many sockets on this machine, lsof can be very slow reading /proc/net/tcp and/or /proc/net/udp, locking some tables long enough to drop packets.

First I tried with one UDP socket and during tests I switched to 16 sockets with no effect. As I removed nearly all daemons there aren't many open sockets.

/proc/net/tcp seems to be one cause of the problem: a simple "cat /proc/net/tcp" leads nearly allways to immediate UDP packet loss. So it seems that reading TCP statistics blocks UDP packet processing.

As it isn't my goal to collect statistics all the time, I could live with disabling access to /proc/net/tcp, but I wouldn't call this a good solution...

Quoted 3 lines

If you have a low count of tcp sockets, you might want to boot with thash_entries=2048 or so, to reduce tcp hash table size.

This did help a lot, I tried thash_entries=10 and now only a while loop around the "cat ...tcp" triggers packet loss. Tests are now running and I can say more tomorrow.

Getting information about thash_entries is really hard. Even finding out the default value: For a system with 2GB RAM it could be around 100000.

Quoted 1 line

no RcvbufErrors error as well ?

The kernel is a bit too old (2.6.18). Looking at the patch from 2.16.18 to 1.6.19 I found that RcvbufErrors is only increased when InErrors is increased. So my answer would be yes.

Quoted 3 lines
Quoted 1 line

- Network card is handled by bnx2 kernel module

I dont know this NIC, does it support ethtool ?

It is a "Broadcom Corporation NetXtreme II BCM5708S Gigabit Ethernet (rev 12)", and it seems ethtool is supported.

The output below was captured after packet loss (I don't see any hints, but maybe you):

Quoted 1 line

ethtool -S eth0

NIC statistics:

     rx_bytes: 155481467364
     rx_error_bytes: 0
     tx_bytes: 5492161
     tx_error_bytes: 0
     rx_ucast_packets: 18341
     rx_mcast_packets: 137321933
     rx_bcast_packets: 2380
     tx_ucast_packets: 14416
     tx_mcast_packets: 190
     tx_bcast_packets: 8
     tx_mac_errors: 0
     tx_carrier_errors: 0
     rx_crc_errors: 0
     rx_align_errors: 0
     tx_single_collisions: 0
     tx_multi_collisions: 0
     tx_deferred: 0
     tx_excess_collisions: 0
     tx_late_collisions: 0
     tx_total_collisions: 0
     rx_fragments: 0
     rx_jabbers: 0
     rx_undersize_packets: 0
     rx_oversize_packets: 0
     rx_64_byte_packets: 244575
     rx_65_to_127_byte_packets: 6828
     rx_128_to_255_byte_packets: 167
     rx_256_to_511_byte_packets: 94
     rx_512_to_1023_byte_packets: 393
     rx_1024_to_1522_byte_packets: 137090597
     rx_1523_to_9022_byte_packets: 0
     tx_64_byte_packets: 52
     tx_65_to_127_byte_packets: 7547
     tx_128_to_255_byte_packets: 3304
     tx_256_to_511_byte_packets: 399
     tx_512_to_1023_byte_packets: 897
     tx_1024_to_1522_byte_packets: 2415
     tx_1523_to_9022_byte_packets: 0
     rx_xon_frames: 0
     rx_xoff_frames: 0
     tx_xon_frames: 0
     tx_xoff_frames: 0
     rx_mac_ctrl_frames: 0
     rx_filtered_packets: 158816
     rx_discards: 0
     rx_fw_discards: 0
Quoted 1 line

ethtool -c eth0

Coalesce parameters for eth1:
Adaptive RX: off TX: off
stats-block-usecs: 999936
sample-interval: 0
pkt-rate-low: 0
pkt-rate-high: 0

rx-usecs: 18
rx-frames: 6
rx-usecs-irq: 18
rx-frames-irq: 6

tx-usecs: 80
tx-frames: 20
tx-usecs-irq: 80
tx-frames-irq: 20

rx-usecs-low: 0
rx-frame-low: 0
tx-usecs-low: 0
tx-frame-low: 0

rx-usecs-high: 0
rx-frame-high: 0
tx-usecs-high: 0
tx-frame-high: 0

Quoted 1 line

ethtool -g eth0

Ring parameters for eth1:
Pre-set maximums:

RX:             1020
RX Mini:        0
RX Jumbo:       0
TX:             255
Current hardware settings:
RX:             100
RX Mini:        0
RX Jumbo:       0
TX:             255
Quoted 2 lines

Just to make sure, does your application setup a huge enough SO_RCVBUF val?

Yes, my first try with one socket was 5MB, but I also tested with 10 and even 25MB. With 16 sockets I also set it to 5MB. When pausing the application netstat shows the filled buffers.

Quoted 1 line

What values do you have in /proc/sys/net/ipv4/tcp_rmem ?

I kept the default values there:
4096 43689 87378

Quoted 1 line

cat /proc/meminfo

MemTotal:      2060664 kB
MemFree:        146536 kB
Buffers:         10984 kB
Cached:        1667740 kB
SwapCached:          0 kB
Active:         255228 kB
Inactive:      1536352 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      2060664 kB
LowFree:        146536 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:          820740 kB
Writeback:         112 kB
Mapped:         127612 kB
Slab:           104184 kB
CommitLimit:   1030332 kB
Committed_AS:   774944 kB
PageTables:       1928 kB
VmallocTotal: 34359738367 kB
VmallocUsed:      6924 kB
VmallocChunk: 34359731259 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

Thanks for your help!
Regards,
John

#3 lore raw
Quoted 5 lines · John Miller

Hi Eric,

Quoted 2 lines

I CCed netdev since this stuff is about network and not lkml.

Quoted 7 lines

Ok, dropped the CC...

Quoted 1 line

What kind of machine do you have ? SMP or not ?

It's a HP system with two dual core CPUs at 3GHz, the storage system is connected through QLogic FC-HBA. It should really be fast enough to handle a data stream of 50 MB/s...

Then you might try to bind network IRQ to one CPU
(echo 1 >/proc/irq/XX/smp_affinity)

XX being your NIC interrupt (cat /proc/interrupts to catch it)

and bind your user program to another cpu(s)

You might hit a cond_resched_softirq() bug that Ingo and others are sorting out right now. Using separate CPU for softirq handling and your programs should help a lot here.

Quoted 18 lines
Quoted 4 lines

If you have many sockets on this machine, lsof can be very slow reading /proc/net/tcp and/or /proc/net/udp, locking some tables long enough to drop packets.

First I tried with one UDP socket and during tests I switched to 16 sockets with no effect. As I removed nearly all daemons there aren't many open sockets.

/proc/net/tcp seems to be one cause of the problem: a simple "cat /proc/net/tcp" leads nearly allways to immediate UDP packet loss. So it seems that reading TCP statistics blocks UDP packet processing.

As it isn't my goal to collect statistics all the time, I could live with disabling access to /proc/net/tcp, but I wouldn't call this a good solution...

Quoted 7 lines
Quoted 3 lines

If you have a low count of tcp sockets, you might want to boot with thash_entries=2048 or so, to reduce tcp hash table size.

This did help a lot, I tried thash_entries=10 and now only a while loop around the "cat ...tcp" triggers packet loss. Tests are now running and I can say more tomorrow.

I dont understand here : using a small thash_entries makes the bug always appear ?

Quoted 162 lines

Getting information about thash_entries is really hard. Even finding out the default value: For a system with 2GB RAM it could be around 100000.

Quoted 1 line

no RcvbufErrors error as well ?

The kernel is a bit too old (2.6.18). Looking at the patch from 2.16.18 to 1.6.19 I found that RcvbufErrors is only increased when InErrors is increased. So my answer would be yes.

Quoted 3 lines
Quoted 1 line

- Network card is handled by bnx2 kernel module

I dont know this NIC, does it support ethtool ?

It is a "Broadcom Corporation NetXtreme II BCM5708S Gigabit Ethernet (rev 12)", and it seems ethtool is supported.

The output below was captured after packet loss (I don't see any hints, but maybe you):

Quoted 1 line

ethtool -S eth0

NIC statistics:

     rx_bytes: 155481467364
     rx_error_bytes: 0
     tx_bytes: 5492161
     tx_error_bytes: 0
     rx_ucast_packets: 18341
     rx_mcast_packets: 137321933
     rx_bcast_packets: 2380
     tx_ucast_packets: 14416
     tx_mcast_packets: 190
     tx_bcast_packets: 8
     tx_mac_errors: 0
     tx_carrier_errors: 0
     rx_crc_errors: 0
     rx_align_errors: 0
     tx_single_collisions: 0
     tx_multi_collisions: 0
     tx_deferred: 0
     tx_excess_collisions: 0
     tx_late_collisions: 0
     tx_total_collisions: 0
     rx_fragments: 0
     rx_jabbers: 0
     rx_undersize_packets: 0
     rx_oversize_packets: 0
     rx_64_byte_packets: 244575
     rx_65_to_127_byte_packets: 6828
     rx_128_to_255_byte_packets: 167
     rx_256_to_511_byte_packets: 94
     rx_512_to_1023_byte_packets: 393
     rx_1024_to_1522_byte_packets: 137090597
     rx_1523_to_9022_byte_packets: 0
     tx_64_byte_packets: 52
     tx_65_to_127_byte_packets: 7547
     tx_128_to_255_byte_packets: 3304
     tx_256_to_511_byte_packets: 399
     tx_512_to_1023_byte_packets: 897
     tx_1024_to_1522_byte_packets: 2415
     tx_1523_to_9022_byte_packets: 0
     rx_xon_frames: 0
     rx_xoff_frames: 0
     tx_xon_frames: 0
     tx_xoff_frames: 0
     rx_mac_ctrl_frames: 0
     rx_filtered_packets: 158816
     rx_discards: 0
     rx_fw_discards: 0
Quoted 1 line

ethtool -c eth0

Coalesce parameters for eth1:
Adaptive RX: off TX: off
stats-block-usecs: 999936
sample-interval: 0
pkt-rate-low: 0
pkt-rate-high: 0

rx-usecs: 18
rx-frames: 6
rx-usecs-irq: 18
rx-frames-irq: 6

tx-usecs: 80
tx-frames: 20
tx-usecs-irq: 80
tx-frames-irq: 20

rx-usecs-low: 0
rx-frame-low: 0
tx-usecs-low: 0
tx-frame-low: 0

rx-usecs-high: 0
rx-frame-high: 0
tx-usecs-high: 0
tx-frame-high: 0

Quoted 1 line

ethtool -g eth0

Ring parameters for eth1:
Pre-set maximums:

RX:             1020
RX Mini:        0
RX Jumbo:       0
TX:             255
Current hardware settings:
RX:             100
RX Mini:        0
RX Jumbo:       0
TX:             255
Quoted 2 lines

Just to make sure, does your application setup a huge enough SO_RCVBUF val?

Yes, my first try with one socket was 5MB, but I also tested with 10 and even 25MB. With 16 sockets I also set it to 5MB. When pausing the application netstat shows the filled buffers.

Quoted 1 line

What values do you have in /proc/sys/net/ipv4/tcp_rmem ?

I kept the default values there:
4096 43689 87378

Quoted 1 line

cat /proc/meminfo

MemTotal:      2060664 kB
MemFree:        146536 kB
Buffers:         10984 kB
Cached:        1667740 kB
SwapCached:          0 kB
Active:         255228 kB
Inactive:      1536352 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      2060664 kB
LowFree:        146536 kB
SwapTotal:           0 kB
SwapFree:            0 kB
Dirty:          820740 kB
Writeback:         112 kB
Mapped:         127612 kB
Slab:           104184 kB
CommitLimit:   1030332 kB
Committed_AS:   774944 kB
PageTables:       1928 kB
VmallocTotal: 34359738367 kB
VmallocUsed:      6924 kB
VmallocChunk: 34359731259 kB
HugePages_Total:     0
HugePages_Free:      0
HugePages_Rsvd:      0
Hugepagesize:     2048 kB

Thanks for your help!
Regards,
John

#4 lore raw
Quoted 14 lines · Eric Dumazet
Quoted 5 lines · John Miller

Hi Eric,

Quoted 2 lines

I CCed netdev since this stuff is about network and not lkml.

Quoted 7 lines

Ok, dropped the CC...

Quoted 1 line

What kind of machine do you have ? SMP or not ?

It's a HP system with two dual core CPUs at 3GHz, the storage system is connected through QLogic FC-HBA. It should really be fast enough to handle a data stream of 50 MB/s...

Quoted 8 lines

Then you might try to bind network IRQ to one CPU
(echo 1 >/proc/irq/XX/smp_affinity)

XX being your NIC interrupt (cat /proc/interrupts to catch it)

and bind your user program to another cpu(s)

You might hit a cond_resched_softirq() bug that Ingo and others are sorting out right now. Using separate CPU for softirq handling and your programs should help a lot here.

You might try this patch, now that Ingo "Signed-off-by" it.

http://marc.info/?l=linux-kernel&m=117981607429875&w=2

I guess that with a correct softirq resched, no need to play with IRQ affinities, unless you really want to push performance.

#5 lore raw
In reply to Eric Dumazet

Hi Eric,

Quoted 8 lines
Quoted 1 line

It's a HP system with two dual core CPUs at 3GHz, the

Then you might try to bind network IRQ to one CPU
(echo 1 >/proc/irq/XX/smp_affinity)

XX being your NIC interrupt (cat /proc/interrupts to catch it)

and bind your user program to another cpu(s)

the NIC was already fixed at CPU0 and the irq_balancer switched the timer interrupt between all CPUs and the storage HBA between CPU1 and CPU4. Stopping the balancer and leaving NIC alone on CPU0 and the other interrupts and my program on CPU2-4 did not improve the situation.
At least I could not see an improvement over just adding thash_entries=2048.

Quoted 3 lines

You might hit a cond_resched_softirq() bug that Ingo and others are sorting out right now. Using separate CPU for softirq handling and your programs should help a lot here.

Shouldn't I get some syslog messages if this bug is triggered?

Nevertheless I also opened a call on Novell about this issue, as the current cond_resched_softirq() does look completely different than in 2.6.18

Quoted 5 lines
Quoted 2 lines

This did help a lot, I tried thash_entries=10 and now only a while loop around the "cat ...tcp" triggers packet loss. Tests

I dont understand here : using a small thash_entries makes the bug always appear ?

No. thash_entries=10 improves the situation. Without the param nearly every look at /proc/net/tcp leads to packet loss, with thash_entries=10 (or 2048, does not matter) I have to start a "while true; do cat /prc/net/tcp ; done" to get packet loss every minute.

But even with thash_entries=10 and if I leave my program alone
on he system I get packet loss every few hours.

Regards,
John