From owner-freebsd-net@FreeBSD.ORG Sun May 1 11:08:46 2005 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CD61316A4CE; Sun, 1 May 2005 11:08:46 +0000 (GMT) Received: from cyrus.watson.org (cyrus.watson.org [204.156.12.53]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9034A43D55; Sun, 1 May 2005 11:08:46 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by cyrus.watson.org (Postfix) with ESMTP id 309EC46B23; Sun, 1 May 2005 07:08:46 -0400 (EDT) Date: Sun, 1 May 2005 12:11:44 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Kazuaki Oda In-Reply-To: <4267E009.6010102@highway.ne.jp> Message-ID: <20050501114842.S66519@fledge.watson.org> References: <4267E009.6010102@highway.ne.jp> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed cc: freebsd-net@freebsd.org cc: andre@FreeBSD.org Subject: Re: tcp output question X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 May 2005 11:08:46 -0000 On Fri, 22 Apr 2005, Kazuaki Oda wrote: > I'm reading FreeBSD's network codes, and I have noticed that we call > tcp_output() from tcp_usr_send() with tcbinfo locked. According to the > comment in the tcp_usr_send(), we must call tcp_connect() or > tcp_usrclosed() with tcbinfo locked. But it seems that we does not need > to lock it to call tcp_output(). Is there any reason not to unlock it > before calling tcp_output()? I have tried the attached patch, so I get > about 10-20% performance up when running my test server program. You are correct. While it's less performance critical, the same approach can be applied to the PRUS_OOB branch of tcp_usr_send(). There is currently some ambiguity in the relationship between sockets and pcbs -- when various pointers can be NULL, etc. The details vary by protocol -- TCP can allow pcbs to not have sockets, for example, and some socket calls can be made during detach such that there might not be a pcb. If we resolve this ambiguity, we can lower locking overhead, and contention of the tcbinfo lock, quite a bit, avoiding unnecessary acquisition of the tcbinfo lock. Once I've finished cleaning things up elsewhere, I think we need to look carefully at the locking strategy taken for TCP and UDP and decide if they provide the right degree of granularity and overhead. Right now, the tcbinfo/udbinfo locks are held for large parts of TCP and UDP processing, acting as an implicit reference count to prevent pcbs from being free'd while in use in the in-bound delivery path. This means relatively little possible parallel processing of in-bound packets, and also typically means we hit two locks in the TCP/UDP code. Alternative models need to be explored that can help with this, both reducing contention and overhead. Thanks for the patch! Robert N M Watson