From nobody@FreeBSD.org  Thu Mar 21 15:56:26 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id CAFF737B404
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Mar 2002 15:56:25 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g2LNuPW26802;
	Thu, 21 Mar 2002 15:56:25 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200203212356.g2LNuPW26802@freefall.freebsd.org>
Date: Thu, 21 Mar 2002 15:56:25 -0800 (PST)
From: emmanuel Duros <eduros@udcast.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: natd: cpu usage gets sky high 
X-Send-Pr-Version: www-1.0
X-GNATS-Notify: cjc

>Number:         36183
>Category:       bin
>Synopsis:       natd: cpu usage gets sky high
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 21 16:00:05 PST 2002
>Closed-Date:    Fri Mar 22 03:42:21 PST 2002
>Last-Modified:  Fri Mar 22 03:42:21 PST 2002
>Originator:     emmanuel Duros
>Release:        FreeBSD 4.4R
>Organization:
UDcast
>Environment:
FreeBSD box132 4.4-RELEASE FreeBSD 4.4-RELEASE
>Description:
     CPU usage may increase drasticaly especialy when public interface is a slow link.
>How-To-Repeat:
Use a dummynet pipe on a Ethernet interface with a limited bwdth on the outgoing packets (e.g. 50kbps). Start a tcp transfer from a server to the host which runs natd. 
Observe the natd cpu rate which increases...
>Fix:
I read the natd code and I am not sure the bug is due to natd...
During the transfer, the TCP ack packets fill up the pipe completely.
As soos as we are in this situation (pipe full) natd enters in a bad loop and the cpu uasge increases.

According to the comments in the source, the main loop will take care of the packets which could not be written. Unfortunately, the select does not behave as we would like it to behave:

Instead of waiting for the "write" to be available, the select indicates that socket is available for writing... Then the sendto fails for sending the packet, reenter in the main loop and so on...

Note that the socket is a sock_raw type, I wonder if this is a sufficient reason to inform that it is always possible to write on this socket. 
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: cjc 
State-Changed-When: Fri Mar 22 03:03:19 PST 2002 
State-Changed-Why:  
Request submitter try a fix included in a later version of FreeBSD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36183 

From: "Crist J. Clark" <cjc@FreeBSD.ORG>
To: emmanuel Duros <eduros@udcast.com>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/36183: natd: cpu usage gets sky high
Date: Fri, 22 Mar 2002 03:02:31 -0800

 On Thu, Mar 21, 2002 at 03:56:25PM -0800, emmanuel Duros wrote:
 [snip]
 > I read the natd code and I am not sure the bug is due to natd...
 > During the transfer, the TCP ack packets fill up the pipe completely.
 > As soos as we are in this situation (pipe full) natd enters in a bad loop and the cpu uasge increases.
 > 
 > According to the comments in the source, the main loop will take care of the packets which could not be written. Unfortunately, the select does not behave as we would like it to behave:
 
 This code was removed in revision 1.25.2.5 which did not make
 4.5-RELEASE. Try 4.5-STABLE to see if this is still a problem for you.
 -- 
 Crist J. Clark                     |     cjclark@alum.mit.edu
                                    |     cjclark@jhu.edu
 http://people.freebsd.org/~cjc/    |     cjc@freebsd.org
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: cjc 
Responsible-Changed-When: Fri Mar 22 03:21:37 PST 2002 
Responsible-Changed-Why:  
ru handled it when a similar, probably the same, problem was reported 
previously. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36183 
State-Changed-From-To: feedback->closed 
State-Changed-By: ru 
State-Changed-When: Fri Mar 22 03:40:58 PST 2002 
State-Changed-Why:  
Already fixed in natd.c,v 1.39 (5.0-CURRENT) and v 1.25.2.5 (4.5-STABLE). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36183 
>Unformatted:
