Index: vm_reserv.c =================================================================== --- vm_reserv.c +++ vm_reserv.c @@ -168,6 +168,27 @@ } /* + * Are all bits in the population map range clear? + */ +static __inline boolean_t +popmap_range_is_clear(popmap_t popmap[], int start, int count) +{ + popmap_t mask; + int end, i; + + end = start + count; + for (i = start / NBPOPMAP, mask = -1UL << (start % NBPOPMAP); + i < end / NBPOPMAP && (mask & popmap[i]) == 0; + i++, mask = -1UL); + if (i < end / NBPOPMAP) + return (false); + if (end % NBPOPMAP == 0) + return (true); + mask &= ~(-1UL << (end % NBPOPMAP)); + return ((mask & popmap[i]) == 0); +} + +/* * The reservation structure * * A reservation structure is constructed whenever a large physical page is @@ -646,11 +667,8 @@ ((pa ^ (pa + size - 1)) & ~(boundary - 1)) != 0) goto out; /* Handle vm_page_rename(m, new_object, ...). */ - for (i = 0; i < npages; i++) { - if (popmap_is_set(rv->popmap, index + i)) - goto out; - } - if (!vm_domain_allocate(vmd, req, npages)) + if (!popmap_range_is_clear(rv->popmap, index, npages) || + !vm_domain_allocate(vmd, req, npages)) goto out; for (i = 0; i < npages; i++) vm_reserv_populate(rv, index + i);