uma: implement provisional api for per-cpu zones
Per-cpu zone allocations are very rarely done compared to regular zones. The intent is to avoid pessimizing the latter case with per-cpu specific code. In particular contrary to the claim in r334824, M_ZERO is sometimes being used for such zones. But the zeroing method is completely different and braching on it in the fast path for regular zones is a waste of time.
This commit is contained in:
parent
4f63fbc955
commit
4e180881ae
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334858
@ -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 @@ key_newsav(const struct sadb_msghdr *mhp, struct secasindex *saidx,
|
||||
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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
16
sys/vm/uma.h
16
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.
|
||||
*/
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user