Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Feb 1997 17:39:50 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        ache@nagual.ru, bde@zeta.org.au
Cc:        cvs-all@freefall.freebsd.org, CVS-committers@freefall.freebsd.org, cvs-sys@freefall.freebsd.org, mpp@freefall.freebsd.org, peter@spinner.dialix.com
Subject:   Re: cvs commit: src/sys/sys types.h
Message-ID:  <199702170639.RAA18161@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> >+ #define FD_ROUNDSIZE 256
>> >+ 
>> 
>> Change to something like (2048 / 6) = 341.  Now that's an odd size :-).
>
>I change it (see update patch below) but still not understand
>why 2048 is here. p_selbits_size increasing constant will be 44 in this
>case, is it good value for you too?

It is really the allocation unit size.  2048 is almost arbitrary.  It is
the next power of 2 up from the number of bits required for 6 fd_set's
with the current FD_SETSIZE (6 * 256 = 1536).

p_selbits_size would actually be 256/6 = 42.  Although this isn't a multiple
of sizeof(fdmask), there is no problem since buffers are spaced every ni
bits, not every p->p_selbits_size bits.  p_selbits_size should be changed
to the size allocated anyway.

>*** sys_generic.c.orig	Tue Jan 14 23:11:28 1997
>--- sys_generic.c	Mon Feb 17 01:33:11 1997
...
>***************
>*** 539,545 ****
>  		uap->nd = p->p_fd->fd_nfiles;   /* forgiving; slightly wrong */
>  
>  	/* The amount of space we need to allocate */
>! 	ni = howmany(roundup2 (uap->nd, FD_SETSIZE), NFDBITS) *
>  		sizeof(fd_mask);
>  
>  	if (ni > p->p_selbits_size) {
>--- 541,547 ----
>  		uap->nd = p->p_fd->fd_nfiles;   /* forgiving; slightly wrong */
>  
>  	/* The amount of space we need to allocate */
>! 	ni = howmany(roundup2 (uap->nd, FD_ROUNDSIZE), NFDBITS) *
>  		sizeof(fd_mask);
>  
>  	if (ni > p->p_selbits_size) {

Don't round up to the allocation unit here.  Set ni = roundup(uap->nd,
NFDBITS).  Then if (ni <= (OLD_FD_SETSIZE = 32 * NBBY)), use an auto
buffer of size 6*OLD_FD_SETSIZE bits.  Otherwise, use a malloced buffer
(malloc a larger one if ni > p->p_selbits_size).  This can be simplified
by always mallocing and freeing at the end.  Space can be saved by
reducing ni first for the common case when there are no exceptfd's etc.

>--- 549,579 ----
>  			free (p->p_selbits, M_SELECT);
>  
>  		while (p->p_selbits_size < ni)
>! 			p->p_selbits_size +=
>! 				howmany(FD_ROUNDSIZE, NFDBITS) *
>! 				sizeof(fd_mask);

This can be simplified to something like p_selbytes_allocated =
roundup2(6 * ni, FD_ROUNDSIZE) / NBBY.  Don't use exactly this -
it assumes that FD_ROUNDSIZE is both a multiple of NBBY and a
power of 2.  FD_ROUNDSIZE should be defined as a multiple of NBBY,
and it won't be a power of 2 on weird machines.

>  	/* The amount of space we need to copyin/copyout */
>  	ni = howmany(uap->nd, NFDBITS) * sizeof(fd_mask);

Simplify this to something ni /= NBBY (maybe rename the variable).

>+ 
>+ 	for (i = 0; i < 3; i++) {
>+ 		obits[i] = (fd_mask *)(p->p_selbits + i * ni);
>+ 		ibits[i] = (fd_mask *)(p->p_selbits + (i + 3) * ni);
>+ 	}
>+ 	if (uap->ex)
>+ 		i = 3;
>+ 	else if (uap->ou)
>+ 		i = 2;
>+ 	else if (uap->in)
>+ 		i = 1;
>+ 	else
>+ 		i = 0;
>+ 	if (i)
>+ 		bzero(p->p_selbits, i * ni);

I think there is a problem caused by stupid handling of NULL fdsets.
Nothing is copied in, but selscan() wastes time scanning the buffers.
It depends on the current behaviour of bzeroing everything.  Fixing
this would be a useful optimization than reducing the amount to
bzero :-).

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702170639.RAA18161>