--- b/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -362,13 +362,32 @@ bucket_init(void) * to allocate the bucket. */ static struct uma_bucket_zone * -bucket_zone_lookup(int entries) +bucket_zone_lookup(uma_zone_t zone, int entries) { struct uma_bucket_zone *ubz; + uma_keg_t keg; - for (ubz = &bucket_zones[0]; ubz->ubz_entries != 0; ubz++) - if (ubz->ubz_entries >= entries) - return (ubz); + for (ubz = &bucket_zones[0]; ubz->ubz_entries != 0; ubz++) { + if (ubz->ubz_entries < entries) + continue; +#ifdef DEBUG_MEMGUARD + if (zone == ubz->ubz_zone) { + if ((ubz + 1)->ubz_entries != 0) + continue; + return (memguard_cmp_zone((ubz - 1)->ubz_zone) ? + ubz - 2 : ubz - 1); + } + if (zone != NULL && memguard_cmp_zone(ubz->ubz_zone) && + (keg = zone_first_keg(zone)) != NULL && + (keg->uk_flags & (UMA_ZONE_VM | UMA_ZFLAG_BUCKET)) != 0) { + if ((ubz + 1)->ubz_entries == 0) + return (zone == (ubz - 1)->ubz_zone ? + ubz - 2 : ubz - 1); + continue; + } +#endif + return (ubz); + } ubz--; return (ubz); } @@ -422,7 +441,7 @@ bucket_alloc(uma_zone_t zone, void *udata, int flags) } if ((uintptr_t)udata & UMA_ZFLAG_CACHEONLY) flags |= M_NOVM; - ubz = bucket_zone_lookup(zone->uz_count); + ubz = bucket_zone_lookup(zone, zone->uz_count); if (ubz->ubz_zone == zone && (ubz + 1)->ubz_entries != 0) ubz++; bucket = uma_zalloc_arg(ubz->ubz_zone, udata, flags); @@ -446,7 +465,7 @@ bucket_free(uma_zone_t zone, uma_bucket_t bucket, void *udata) ("bucket_free: Freeing a non free bucket.")); if ((zone->uz_flags & UMA_ZFLAG_BUCKET) == 0) udata = (void *)(uintptr_t)zone->uz_flags; - ubz = bucket_zone_lookup(bucket->ub_entries); + ubz = bucket_zone_lookup(NULL, bucket->ub_entries); uma_zfree_arg(ubz->ubz_zone, bucket, udata); }