From owner-freebsd-hackers Sun Mar 10 10:34:11 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from scaup.prod.itd.earthlink.net (scaup.mail.pas.earthlink.net [207.217.120.49]) by hub.freebsd.org (Postfix) with ESMTP id DF6AB37B41E for ; Sun, 10 Mar 2002 10:33:45 -0800 (PST) Received: from pool0441.cvx21-bradley.dialup.earthlink.net ([209.179.193.186] helo=mindspring.com) by scaup.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16k88D-0003h6-00; Sun, 10 Mar 2002 10:33:18 -0800 Message-ID: <3C8BA6DD.7D57BAB1@mindspring.com> Date: Sun, 10 Mar 2002 10:33:01 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Giorgos Keramidas Cc: Simon 'corecode' Schubert , freebsd-hackers@freebsd.org Subject: Re: Swapping performance References: <20020307090707.GC26621@elvis.mu.org> <20020307142759.0d95d467.mitko@rila.bg> <20020307080906.367be8df.gclarkii@vsservices.com> <20020307164724.D377@straylight.oblivion.bg> <20020307153615.GB1942@student.uu.se> <20020307164500.5dd21d16.corecode@corecode.ath.cx> <20020310125158.GA798@hades.hell.gr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Giorgos Keramidas wrote: > On 2002-03-07 16:45, Simon 'corecode' Schubert wrote: > > to everybody who doesn't believe that: it really generates bad code. > > i've been having severe problems with my tcp and udp stack lately (on a > > i586/mmx machine). guess what, -O2 resulted in code which >>sometimes<< > > generated bad tcp and/or udp checksums (depending on ip). i didn't > > investigate any further, but believe me: not being able to access some > > dns servers is a pain in the ass. > > I've seen this too. When I built both my kernel and userland with -O3, > problems accessing the Internet started. When I tried to use tcpdump to > find out what went wrong, I saw that it reported *all* outgoing packets for > *some* hosts as invalid [0xffff]. > > The funny thing was that depending on which source/destination I used, it > would either work or fail. For destinations that it failed once, it failed > all the time. Since I could not verify both the userland and kernel > binaries, I chose to disable most optimizations and stick with -O :-) Uh, I told you guys the NAT checksum code is broken for certain underflow cases. THis includes the TCP pseudo-header rewrite and the IP header rewrite, when the source and destination address sum goes negative. A simple way of fixing the calculation is to convert all operands to shorts, and then add with carry into an int, folding the final result. You have to accumulate the old value (m) and the new value (m') in seperate accumulators, then reduce the accumulations to shorts, again. THen you compute the final value, per RFC 1624, and reduce it to a short, as well: HC' = ~(~HC + ~m +m') Those are all 16-bit "~"'s; the same effect is available for an int value (which the accumulators should be) via m^0x0000ffff. The key here is that the underflow is associative, but not commutative (this failure, though, is a different commutation than the failure dicussed in the reason RFC 1624 is updating the algorithm). Note that your accumulators must be int's, or you aren't folding the carrys correctly. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message