Print this page
5255 uts shouldn't open-code ISP2

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/vmem.c
          +++ new/usr/src/uts/common/os/vmem.c
↓ open down ↓ 912 lines elided ↑ open up ↑
 913  913   * Used to decide if a newly imported span is superfluous after re-acquiring
 914  914   * the arena lock.
 915  915   */
 916  916  static int
 917  917  vmem_canalloc(vmem_t *vmp, size_t size)
 918  918  {
 919  919          int hb;
 920  920          int flist = 0;
 921  921          ASSERT(MUTEX_HELD(&vmp->vm_lock));
 922  922  
 923      -        if ((size & (size - 1)) == 0)
      923 +        if (ISP2(size))
 924  924                  flist = lowbit(P2ALIGN(vmp->vm_freemap, size));
 925  925          else if ((hb = highbit(size)) < VMEM_FREELISTS)
 926  926                  flist = lowbit(P2ALIGN(vmp->vm_freemap, 1UL << hb));
 927  927  
 928  928          return (flist);
 929  929  }
 930  930  
 931  931  /*
 932  932   * Allocate size bytes at offset phase from an align boundary such that the
 933  933   * resulting segment [addr, addr + size) is a subset of [minaddr, maxaddr)
↓ open down ↓ 18 lines elided ↑ open up ↑
 952  952                      (void *)vmp, size, align_arg, phase, nocross,
 953  953                      minaddr, maxaddr, vmflag);
 954  954  
 955  955          if (nocross != 0 &&
 956  956              (align > nocross || P2ROUNDUP(phase + size, align) > nocross))
 957  957                  panic("vmem_xalloc(%p, %lu, %lu, %lu, %lu, %p, %p, %x): "
 958  958                      "overconstrained allocation",
 959  959                      (void *)vmp, size, align_arg, phase, nocross,
 960  960                      minaddr, maxaddr, vmflag);
 961  961  
 962      -        if (phase >= align || (align & (align - 1)) != 0 ||
 963      -            (nocross & (nocross - 1)) != 0)
      962 +        if (phase >= align || !ISP2(align) || !ISP2(nocross))
 964  963                  panic("vmem_xalloc(%p, %lu, %lu, %lu, %lu, %p, %p, %x): "
 965  964                      "parameters inconsistent or invalid",
 966  965                      (void *)vmp, size, align_arg, phase, nocross,
 967  966                      minaddr, maxaddr, vmflag);
 968  967  
 969  968          if ((mtbf = vmem_mtbf | vmp->vm_mtbf) != 0 && gethrtime() % mtbf == 0 &&
 970  969              (vmflag & (VM_NOSLEEP | VM_PANIC)) == VM_NOSLEEP)
 971  970                  return (NULL);
 972  971  
 973  972          mutex_enter(&vmp->vm_lock);
↓ open down ↓ 13 lines elided ↑ open up ↑
 987  986                   * (1)  The size is exactly a power of 2, in which case
 988  987                   *      the smaller freelist is always big enough;
 989  988                   *
 990  989                   * (2)  All other freelists are empty;
 991  990                   *
 992  991                   * (3)  We're in the highest possible freelist, which is
 993  992                   *      always empty (e.g. the 4GB freelist on 32-bit systems);
 994  993                   *
 995  994                   * (4)  We're doing a best-fit or first-fit allocation.
 996  995                   */
 997      -                if ((size & (size - 1)) == 0) {
      996 +                if (ISP2(size)) {
 998  997                          flist = lowbit(P2ALIGN(vmp->vm_freemap, size));
 999  998                  } else {
1000  999                          hb = highbit(size);
1001 1000                          if ((vmp->vm_freemap >> hb) == 0 ||
1002 1001                              hb == VMEM_FREELISTS ||
1003 1002                              (vmflag & (VM_BESTFIT | VM_FIRSTFIT)))
1004 1003                                  hb--;
1005 1004                          flist = lowbit(P2ALIGN(vmp->vm_freemap, 1UL << hb));
1006 1005                  }
1007 1006  
↓ open down ↓ 275 lines elided ↑ open up ↑
1283 1282          if (vmflag & (VM_BESTFIT | VM_FIRSTFIT))
1284 1283                  return (vmem_xalloc(vmp, size, vmp->vm_quantum, 0, 0,
1285 1284                      NULL, NULL, vmflag));
1286 1285  
1287 1286          /*
1288 1287           * Unconstrained instant-fit allocation from the segment list.
1289 1288           */
1290 1289          mutex_enter(&vmp->vm_lock);
1291 1290  
1292 1291          if (vmp->vm_nsegfree >= VMEM_MINFREE || vmem_populate(vmp, vmflag)) {
1293      -                if ((size & (size - 1)) == 0)
     1292 +                if (ISP2(size))
1294 1293                          flist = lowbit(P2ALIGN(vmp->vm_freemap, size));
1295 1294                  else if ((hb = highbit(size)) < VMEM_FREELISTS)
1296 1295                          flist = lowbit(P2ALIGN(vmp->vm_freemap, 1UL << hb));
1297 1296          }
1298 1297  
1299 1298          if (flist-- == 0) {
1300 1299                  mutex_exit(&vmp->vm_lock);
1301 1300                  return (vmem_xalloc(vmp, size, vmp->vm_quantum,
1302 1301                      0, 0, NULL, NULL, vmflag));
1303 1302          }
↓ open down ↓ 486 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX