From owner-cvs-sys Sun Feb 16 06:06:33 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id GAA05813 for cvs-sys-outgoing; Sun, 16 Feb 1997 06:06:33 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id GAA05807; Sun, 16 Feb 1997 06:06:26 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.8.3/8.6.9) id BAA20251; Mon, 17 Feb 1997 01:04:24 +1100 Date: Mon, 17 Feb 1997 01:04:24 +1100 From: Bruce Evans Message-Id: <199702161404.BAA20251@godzilla.zeta.org.au> To: ache@nagual.ru, peter@spinner.dialix.com Subject: Re: cvs commit: src/sys/sys types.h Cc: bde@zeta.org.au, cvs-all@freefall.freebsd.org, CVS-committers@freefall.freebsd.org, cvs-sys@freefall.freebsd.org, mpp@freefall.freebsd.org Sender: owner-cvs-sys@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >I don't understand why rounding is even needed here (maybe to make less 32-bit rounding is better for bzero, copyout, etc, and doesn't cost more storage. 256-bit rounding avoids slow startup but isn't space-efficient since we're allocating 6 times that. Anyway, I think it would be better to use an auto buffer for small allocations even p_selbits has been allocated. This would have better locality. Most applications wouldn't need a malloced buffer. Half of implementation: fd_mask selbits[6 * OLD_FD_SETSIZE / NFDBITS]; ... ni = bits_to_copyin(); /* multiple of NFDBITS */ if (ni <= OLD_FD_SETSIZE) use_selbits(); else use_malloced_bits(); >*** sys_generic.c.orig Tue Jan 14 23:11:28 1997 >--- sys_generic.c Sun Feb 16 16:00:48 1997 >*************** >*** 508,513 **** >--- 508,515 ---- > return (error); > } > >+ #define FD_ROUNDSIZE 256 >+ Change to something like (2048 / 6) = 341. Now that's an odd size :-). >--- 562,580 ---- > p->p_selbits_size); > } > > /* The amount of space we need to copyin/copyout */ > ni = howmany(uap->nd, NFDBITS) * sizeof(fd_mask); >+ >+ if (ni > 8) { /* 64 bits - arbitary guess at tradeoff */ >+ /* >+ * Clear the entire return-to-user buffer space >+ */ >+ bzero (p->p_selbits + 3 * p->p_selbits_size, >+ p->p_selbits_size * 3); >+ } else { >+ for (i = 0; i < 3; i++) >+ bzero(obits[i], ni); >+ } Don't use this except possibly for very large ni together with unusual combinations of fds. Put 3 contiguous copyout buffers first (readfds, writefds, exexptfds), then 3 copyin buffers, and bzero 1*ni, 2*ni or 3*ni bits as necessary (exceptfds is usually NULL so the bzero doesn't need to cover it). The old code got this wrong mainly by spacing the buffers with separation p->p_selbits_size instead of ni. Bruce