Index: sys/vm/uma_core.c =================================================================== --- sys/vm/uma_core.c +++ sys/vm/uma_core.c @@ -192,6 +192,7 @@ static enum { BOOT_COLD, BOOT_KVA, + BOOT_PCPU, BOOT_RUNNING, BOOT_SHUTDOWN, } booted = BOOT_COLD; @@ -304,7 +305,6 @@ static int hash_expand(struct uma_hash *, struct uma_hash *); static void hash_free(struct uma_hash *hash); static void uma_timeout(void *); -static void uma_startup3(void); static void uma_shutdown(void); static void *zone_alloc_item(uma_zone_t, void *, int, int); static void zone_free_item(uma_zone_t, void *, void *, enum zfreeskip); @@ -360,8 +360,6 @@ &uma_skip_cnt, "memory items skipped, not debugged"); #endif -SYSINIT(uma_startup3, SI_SUB_VM_CONF, SI_ORDER_SECOND, uma_startup3, NULL); - SYSCTL_NODE(_vm, OID_AUTO, uma, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, "Universal Memory Allocator"); @@ -2661,9 +2659,10 @@ (UMA_ZONE_INHERIT | UMA_ZFLAG_INHERIT)); out: - if (__predict_true(booted >= BOOT_RUNNING)) { + if (booted >= BOOT_PCPU) { zone_alloc_counters(zone, NULL); - zone_alloc_sysctl(zone, NULL); + if (booted >= BOOT_RUNNING) + zone_alloc_sysctl(zone, NULL); } else { zone->uz_allocs = EARLY_COUNTER; zone->uz_frees = EARLY_COUNTER; @@ -2905,11 +2904,23 @@ bucket_enable(); } +static void +uma_startup_pcpu(void *arg __unused) +{ + /* + * Allocate counters as early as possible so that boot-time events are + * counted properly. + */ + zone_foreach_unlocked(zone_alloc_counters, NULL); + booted = BOOT_PCPU; +} +SYSINIT(uma_startup_pcpu, SI_SUB_COUNTER, SI_ORDER_ANY, uma_startup_pcpu, NULL); + /* * Finish our initialization steps. */ static void -uma_startup3(void) +uma_startup3(void *arg __unused) { #ifdef INVARIANTS @@ -2917,7 +2928,6 @@ uma_dbg_cnt = counter_u64_alloc(M_WAITOK); uma_skip_cnt = counter_u64_alloc(M_WAITOK); #endif - zone_foreach_unlocked(zone_alloc_counters, NULL); zone_foreach_unlocked(zone_alloc_sysctl, NULL); callout_init(&uma_callout, 1); callout_reset(&uma_callout, UMA_TIMEOUT * hz, uma_timeout, NULL); @@ -2926,6 +2936,7 @@ EVENTHANDLER_REGISTER(shutdown_post_sync, uma_shutdown, NULL, EVENTHANDLER_PRI_FIRST); } +SYSINIT(uma_startup3, SI_SUB_VM_CONF, SI_ORDER_SECOND, uma_startup3, NULL); static void uma_shutdown(void)