do-nothing code in sysv_shm.c

Vladislav Shabanov vs at rambler-co.ru
Mon Apr 11 08:58:20 PDT 2005


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


More information about the freebsd-hackers mailing list