do-nothing code in sysv_shm.c

John Baldwin jhb at FreeBSD.org
Thu May 12 20:52:00 GMT 2005


On Monday 11 April 2005 12:03 pm, Vladislav Shabanov wrote:
> I`ve found the following code in sysv_shm.c :
>
> ............
> static void
> shminit()
> {
>         int i;
>
>         TUNABLE_INT_FETCH("kern.ipc.shmmaxpgs", &shminfo.shmall);
>         for (i = PAGE_SIZE; i > 0; i--) {
>                 shminfo.shmmax = shminfo.shmall * PAGE_SIZE;
>                 if (shminfo.shmmax >= shminfo.shmall)
>                         break;
>         }
>         TUNABLE_INT_FETCH("kern.ipc.shmmin", &shminfo.shmmin);
> .........
>
> IMHO, loop does nothing. Possible variant:
>
> #define shmall_bits   (sizeof(shminfo.shmall)*8)
>
> if (0 == (shminfo.shmall & (~ ( (1<<(shmall_bits-PAGE_SHIFT-1)) - 1)))) {
>   /* if high PAGE_SHIFT+1 bits of shminfo.shmall is zero */
>   shminfo.shmmax = shminfo.shmall << PAGE_SHIFT;
> } else {
>   shminfo.shmmax = __INT_MAX;
> }
>
> ------------------------------
> previous changes in this part of code:
>
> http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/sysv_shm.c.diff?r1=1.78&
>r2=1.79&f=h
> http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/kern/sysv_shm.c.diff?r1=1.79&
>r2=1.80&f=h _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"

After talking to Alfred, I just changed it to use 'i' rather than PAGE_SIZE in 
the loop as it's easy to follow and given that this code only runs once at 
boot it's not critical that it be fast.  Thanks for the report!

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-hackers mailing list