diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 96ef209518d..0b90d46d4d0 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -2957,7 +2957,7 @@ key_newsav(const struct sadb_msghdr *mhp, struct secasindex *saidx, goto done; } mtx_init(sav->lock, "ipsec association", NULL, MTX_DEF); - sav->lft_c = uma_zalloc(V_key_lft_zone, M_NOWAIT); + sav->lft_c = uma_zalloc_pcpu(V_key_lft_zone, M_NOWAIT); if (sav->lft_c == NULL) { *errp = ENOBUFS; goto done; @@ -3049,7 +3049,7 @@ done: free(sav->lock, M_IPSEC_MISC); } if (sav->lft_c != NULL) - uma_zfree(V_key_lft_zone, sav->lft_c); + uma_zfree_pcpu(V_key_lft_zone, sav->lft_c); free(sav, M_IPSEC_SA), sav = NULL; } if (sah != NULL) diff --git a/sys/netpfil/ipfw/ip_fw_sockopt.c b/sys/netpfil/ipfw/ip_fw_sockopt.c index cda7fab45de..5d32b2eb0fc 100644 --- a/sys/netpfil/ipfw/ip_fw_sockopt.c +++ b/sys/netpfil/ipfw/ip_fw_sockopt.c @@ -208,7 +208,7 @@ ipfw_alloc_rule(struct ip_fw_chain *chain, size_t rulesize) struct ip_fw *rule; rule = malloc(rulesize, M_IPFW, M_WAITOK | M_ZERO); - rule->cntr = uma_zalloc(V_ipfw_cntr_zone, M_WAITOK | M_ZERO); + rule->cntr = uma_zalloc_pcpu(V_ipfw_cntr_zone, M_WAITOK | M_ZERO); return (rule); } @@ -217,7 +217,7 @@ static void free_rule(struct ip_fw *rule) { - uma_zfree(V_ipfw_cntr_zone, rule->cntr); + uma_zfree_pcpu(V_ipfw_cntr_zone, rule->cntr); free(rule, M_IPFW); } diff --git a/sys/vm/uma.h b/sys/vm/uma.h index 41d9d88bfe3..9fe51e515f4 100644 --- a/sys/vm/uma.h +++ b/sys/vm/uma.h @@ -333,6 +333,7 @@ void uma_zdestroy(uma_zone_t zone); */ void *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags); +void *uma_zalloc_pcpu_arg(uma_zone_t zone, void *arg, int flags); /* * Allocate an item from a specific NUMA domain. This uses a slow path in @@ -354,6 +355,7 @@ void *uma_zalloc_domain(uma_zone_t zone, void *arg, int domain, int flags); * */ static __inline void *uma_zalloc(uma_zone_t zone, int flags); +static __inline void *uma_zalloc_pcpu(uma_zone_t zone, int flags); static __inline void * uma_zalloc(uma_zone_t zone, int flags) @@ -361,6 +363,12 @@ uma_zalloc(uma_zone_t zone, int flags) return uma_zalloc_arg(zone, NULL, flags); } +static __inline void * +uma_zalloc_pcpu(uma_zone_t zone, int flags) +{ + return uma_zalloc_pcpu_arg(zone, NULL, flags); +} + /* * Frees an item back into the specified zone. * @@ -374,6 +382,7 @@ uma_zalloc(uma_zone_t zone, int flags) */ void uma_zfree_arg(uma_zone_t zone, void *item, void *arg); +void uma_zfree_pcpu_arg(uma_zone_t zone, void *item, void *arg); /* * Frees an item back to the specified zone's domain specific pool. @@ -392,6 +401,7 @@ void uma_zfree_domain(uma_zone_t zone, void *item, void *arg); * */ static __inline void uma_zfree(uma_zone_t zone, void *item); +static __inline void uma_zfree_pcpu(uma_zone_t zone, void *item); static __inline void uma_zfree(uma_zone_t zone, void *item) @@ -399,6 +409,12 @@ uma_zfree(uma_zone_t zone, void *item) uma_zfree_arg(zone, item, NULL); } +static __inline void +uma_zfree_pcpu(uma_zone_t zone, void *item) +{ + uma_zfree_pcpu_arg(zone, item, NULL); +} + /* * Wait until the specified zone can allocate an item. */ diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c index 8d3ac7ebc0c..c44b10cd3f1 100644 --- a/sys/vm/uma_core.c +++ b/sys/vm/uma_core.c @@ -2230,6 +2230,32 @@ uma_zwait(uma_zone_t zone) uma_zfree(zone, item); } +void * +uma_zalloc_pcpu_arg(uma_zone_t zone, void *udata, int flags) +{ + void *item; + int i; + + MPASS(zone->uz_flags & UMA_ZONE_PCPU); + item = uma_zalloc_arg(zone, udata, flags &~ M_ZERO); + if (item != NULL && (flags & M_ZERO)) { + CPU_FOREACH(i) + bzero(zpcpu_get_cpu(item, i), zone->uz_size); + } + return (item); +} + +/* + * A stub while both regular and pcpu cases are identical. + */ +void +uma_zfree_pcpu_arg(uma_zone_t zone, void *item, void *udata) +{ + + MPASS(zone->uz_flags & UMA_ZONE_PCPU); + uma_zfree_arg(zone, item, udata); +} + /* See uma.h */ void * uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)