From owner-freebsd-current Sat May 18 6: 4:22 2002 Delivered-To: freebsd-current@freebsd.org Received: from mail.speakeasy.net (mail16.speakeasy.net [216.254.0.216]) by hub.freebsd.org (Postfix) with ESMTP id 8298137B408 for ; Sat, 18 May 2002 06:03:53 -0700 (PDT) Received: (qmail 23564 invoked from network); 18 May 2002 13:03:52 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail16.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 18 May 2002 13:03:52 -0000 Received: from laptop.baldwin.cx (laptop.baldwin.cx [192.168.0.4]) by server.baldwin.cx (8.11.6/8.11.6) with ESMTP id g4ID3oF82147; Sat, 18 May 2002 09:03:50 -0400 (EDT) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20020518003046.A36510@panzer.kdm.org> Date: Sat, 18 May 2002 09:03:38 -0400 (EDT) From: John Baldwin To: "Kenneth D. Merry" Subject: Re: new zero copy sockets patches available Cc: net@FreeBSD.org, current@FreeBSD.org, Alfred Perlstein Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 18-May-2002 Kenneth D. Merry wrote: > On Fri, May 17, 2002 at 23:02:55 -0700, Alfred Perlstein wrote: >> * Kenneth D. Merry [020517 22:40] wrote: >> > >> > I have released a new set of zero copy sockets patches, against -current >> > from today (May 17th, 2002). >> > >> > The main change is to deal with the vfs_ioopt changes that Alan Cox made >> > in >> > kern_subr.c. (They conflicted a bit with the zero copy receive code.) >> > >> > The patches and the FAQ are available here: >> > >> > http://people.freebsd.org/~ken/zero_copy/ >> > >> > Comments, questions and reviews are all welcome! >> >> jumbo_vm_init() has a bunch of bugs >> >> first it doesn't work right if called concurrently. >> you need to protect the initialization of jumbo_vm_object otherwise >> bad things can happen. my suggestion is to store the results of >> vm_object_allocate into a temporary, grab the mutex and then check >> to see if jumbo_vm_object has been initialized again if it has then >> free the object, otherwise store the allocated object into the >> global and continue. > > The problem here is that the mutex needs to be initialized before I can > acquire it, and there's going to be a race between checking to see > whether it has been initialized and actually initializing it. > > e.g.: > > if (!mtx_initialized(&jumbo_mutex)) > mtx_init(&jumbo_mutex, "jumbo mutex", NULL, MTX_DEF); > > mtx_lock(&jumbo_mutex); > > if (jumbo_vm_object != NULL) { > mtx_unlock(&jumbo_mutex); > return (1); > } > > /* allocate our object */ > jumbo_vm_object = vm_object_allocate(OBJT_DEFAULT, JUMBO_MAX_PAGES); > > The above would work, I think, if it weren't for the race in the mutex > initialization, and assuming I can allocate a vm object while holding > the jumbo mutex. > > Suggestions? Either use a sysinit or something gross like this: static int jumbo_init = 0; ... while (jumbo_init != 2) { if (atomic_cmpset_acq_int(&jumbo_init, 0, 1) { mtx_init(&jumbo_mutex, "jumbo_mutex", NULL, MTX_DEF); atomic_store_rel_int(&jumbo_init, 2); } } mtx_lock(&jumbo_mutex); ... a sysinit is probably best though. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message