From owner-freebsd-net@FreeBSD.ORG Thu Sep 9 20:46:05 2004 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 485B816A4CE for ; Thu, 9 Sep 2004 20:46:05 +0000 (GMT) Received: from gw.Awfulhak.org (awfulhak.demon.co.uk [80.177.173.150]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9592243D54 for ; Thu, 9 Sep 2004 20:46:04 +0000 (GMT) (envelope-from brian@Awfulhak.org) Received: from dev.lan.Awfulhak.org (brian@dev.lan.Awfulhak.org [172.16.0.5]) by gw.Awfulhak.org (8.12.11/8.12.11) with SMTP id i89Kk1Hp043344 for ; Thu, 9 Sep 2004 21:46:01 +0100 (BST) (envelope-from brian@Awfulhak.org) Date: Thu, 9 Sep 2004 21:46:00 +0100 From: Brian Somers To: freebsd-net@FreeBSD.org Message-ID: <20040909214600.12bb5fd5@dev.lan.Awfulhak.org> X-Mailer: Sylpheed-Claws 0.9.12a (GTK+ 1.2.10; i386-portbld-freebsd6.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=no version=2.64 X-Spam-Checker-Version: SpamAssassin 2.64 (2004-01-11) on gw.lan.Awfulhak.org Subject: uma_zcreate() call from kern_mbuf.c - bug? 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: Thu, 09 Sep 2004 20:46:05 -0000 I'm a bit confused by this uma_zcreate() call in kern_mbuf.c: zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_MAXBUCKET); Given that dtom() is defined as: #define dtom(x) ((struct mbuf *)((intptr_t)(x) & ~(MSIZE-1))) shouldn't this mean that the uma_zcreate should be: zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, NULL, NULL, MSIZE - 1, UMA_ZONE_MAXBUCKET); Of course m_get() et. al. seem to manage to get MSIZE aligned pointers back from uma_zalloc_arg(zone_mbuf...) anyway, but surely that's an implementation side effect and the align argument should be corrected. There should probably also be a KASSERT here to ensure that MSIZE is sane (and to stop idiots like me from shooting themselves in the foot with ``options MSIZE=320''). Comments on this patch ? Index: kern_mbuf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_mbuf.c,v retrieving revision 1.3 diff -u -r1.3 kern_mbuf.c --- kern_mbuf.c 2 Aug 2004 00:18:35 -0000 1.3 +++ kern_mbuf.c 9 Sep 2004 20:24:46 -0000 @@ -131,11 +131,15 @@ mbuf_init(void *dummy) { + /* Ensure that MSIZE doesn't break dtom() */ + KASSERT((((MSIZE - 1) ^ MSIZE) + 1) >> 1 == MSIZE, + ("Invalid MSIZE - must only have a single bit set")); + /* * Configure UMA zones for Mbufs, Clusters, and Packets. */ zone_mbuf = uma_zcreate("Mbuf", MSIZE, mb_ctor_mbuf, mb_dtor_mbuf, - NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_MAXBUCKET); + NULL, NULL, MSIZE - 1, UMA_ZONE_MAXBUCKET); zone_clust = uma_zcreate("MbufClust", MCLBYTES, mb_ctor_clust, mb_dtor_clust, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_REFCNT); if (nmbclusters > 0) -- Brian Don't _EVER_ lose your sense of humour !