1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-19 15:33:56 +00:00

Move the implementation of M_ZERO into UMA so that it can be passed to

uma_zalloc and friends.  Remove this functionality from the malloc wrapper.

Document this change in uma.h and adjust variable names in uma_core.
This commit is contained in:
Jeff Roberson 2002-04-30 04:26:34 +00:00
parent 883ee9463e
commit 2cc35ff9c6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=95766
3 changed files with 21 additions and 19 deletions

View File

@ -183,9 +183,6 @@ malloc(size, type, flags)
if (ksp->ks_memuse > ksp->ks_maxused)
ksp->ks_maxused = ksp->ks_memuse;
/* XXX: Do idle pre-zeroing. */
if (va != NULL && (flags & M_ZERO))
bzero(va, size);
return ((void *) va);
}

View File

@ -198,8 +198,7 @@ void uma_zdestroy(uma_zone_t zone);
* Arguments:
* zone The zone we are allocating from
* arg This data is passed to the ctor function
* wait This flag indicates whether or not we are allowed to block while
* allocating memory for this zone should we run out.
* flags See sys/malloc.h for available flags.
*
* Returns:
* A non null pointer to an initialized element from the zone is
@ -207,7 +206,7 @@ void uma_zdestroy(uma_zone_t zone);
* returned if the zone is empty or the ctor failed.
*/
void *uma_zalloc_arg(uma_zone_t zone, void *arg, int wait);
void *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags);
/*
* Allocates an item out of a zone without supplying an argument
@ -215,12 +214,12 @@ void *uma_zalloc_arg(uma_zone_t zone, void *arg, int wait);
* This is just a wrapper for uma_zalloc_arg for convenience.
*
*/
static __inline void *uma_zalloc(uma_zone_t zone, int wait);
static __inline void *uma_zalloc(uma_zone_t zone, int flags);
static __inline void *
uma_zalloc(uma_zone_t zone, int wait)
uma_zalloc(uma_zone_t zone, int flags)
{
return uma_zalloc_arg(zone, NULL, wait);
return uma_zalloc_arg(zone, NULL, flags);
}
/*

View File

@ -1290,7 +1290,7 @@ uma_zdestroy(uma_zone_t zone)
/* See uma.h */
void *
uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
{
void *item;
uma_cache_t cache;
@ -1323,6 +1323,8 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
CPU_UNLOCK(zone, cpu);
if (zone->uz_ctor)
zone->uz_ctor(item, zone->uz_size, udata);
if (flags & M_ZERO)
bzero(item, zone->uz_size);
return (item);
} else if (cache->uc_freebucket) {
/*
@ -1389,7 +1391,7 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
if (bucket == NULL)
bucket = uma_zalloc_internal(bucketzone,
NULL, wait, NULL);
NULL, flags, NULL);
if (bucket != NULL) {
#ifdef INVARIANTS
@ -1397,7 +1399,7 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
#endif
bucket->ub_ptr = -1;
if (uma_zalloc_internal(zone, udata, wait, bucket))
if (uma_zalloc_internal(zone, udata, flags, bucket))
goto zalloc_restart;
else
uma_zfree_internal(bucketzone, bucket, NULL, 0);
@ -1410,7 +1412,7 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
printf("uma_zalloc_arg: Bucketzone returned NULL\n");
#endif
return (uma_zalloc_internal(zone, udata, wait, NULL));
return (uma_zalloc_internal(zone, udata, flags, NULL));
}
/*
@ -1419,7 +1421,7 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
* Arguments
* zone The zone to alloc for.
* udata The data to be passed to the constructor.
* wait M_WAITOK or M_NOWAIT.
* flags M_WAITOK, M_NOWAIT, M_ZERO.
* bucket The bucket to fill or NULL
*
* Returns
@ -1434,7 +1436,7 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int wait)
*/
static void *
uma_zalloc_internal(uma_zone_t zone, void *udata, int wait, uma_bucket_t bucket)
uma_zalloc_internal(uma_zone_t zone, void *udata, int flags, uma_bucket_t bucket)
{
uma_slab_t slab;
u_int8_t freei;
@ -1503,7 +1505,7 @@ uma_zalloc_internal(uma_zone_t zone, void *udata, int wait, uma_bucket_t bucket)
zone->uz_pages >= zone->uz_maxpages) {
zone->uz_flags |= UMA_ZFLAG_FULL;
if (wait & M_WAITOK)
if (flags & M_WAITOK)
msleep(zone, &zone->uz_lock, PVM, "zonelimit", 0);
else
goto alloc_fail;
@ -1512,7 +1514,7 @@ uma_zalloc_internal(uma_zone_t zone, void *udata, int wait, uma_bucket_t bucket)
}
zone->uz_recurse++;
slab = slab_zalloc(zone, wait);
slab = slab_zalloc(zone, flags);
zone->uz_recurse--;
/*
* We might not have been able to get a slab but another cpu
@ -1565,7 +1567,8 @@ uma_zalloc_internal(uma_zone_t zone, void *udata, int wait, uma_bucket_t bucket)
if (bucket != NULL) {
/* Try to keep the buckets totally full, but don't block */
if (bucket->ub_ptr < zone->uz_count) {
wait = M_NOWAIT;
flags |= M_NOWAIT;
flags &= ~M_WAITOK;
goto new_slab;
} else
zone->uz_fills--;
@ -1574,8 +1577,11 @@ uma_zalloc_internal(uma_zone_t zone, void *udata, int wait, uma_bucket_t bucket)
ZONE_UNLOCK(zone);
/* Only construct at this time if we're not filling a bucket */
if (bucket == NULL && zone->uz_ctor != NULL)
if (bucket == NULL && zone->uz_ctor != NULL) {
zone->uz_ctor(item, zone->uz_size, udata);
if (flags & M_ZERO)
bzero(item, zone->uz_size);
}
return (item);