1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-31 16:57:10 +00:00

Abstract the logic to look up the uma_bucket_zone given a desired

number of entries into bucket_zone_lookup(), which helps make more
clear the logic of consumers of bucket zones.

Annotate the behavior of bucket_init() with a comment indicating
how the various data structures, including the bucket lookup tables,
are initialized.
This commit is contained in:
Robert Watson 2004-11-06 11:43:30 +00:00
parent 5349c79d75
commit dc2c7965c0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=137309

View File

@ -261,6 +261,13 @@ bucket_enable(void)
bucketdisable = 0;
}
/*
* Initialize bucket_zones, the array of zones of buckets of various sizes.
*
* For each zone, calculate the memory required for each bucket, consisting
* of the header and an array of pointers. Initialize bucket_size[] to point
* the range of appropriate bucket sizes at the zone.
*/
static void
bucket_init(void)
{
@ -281,12 +288,24 @@ bucket_init(void)
}
}
/*
* Given a desired number of entries for a bucket, return the zone from which
* to allocate the bucket.
*/
static struct uma_bucket_zone *
bucket_zone_lookup(int entries)
{
int idx;
idx = howmany(entries, 1 << BUCKET_SHIFT);
return (&bucket_zones[bucket_size[idx]]);
}
static uma_bucket_t
bucket_alloc(int entries, int bflags)
{
struct uma_bucket_zone *ubz;
uma_bucket_t bucket;
int idx;
/*
* This is to stop us from allocating per cpu buckets while we're
@ -294,11 +313,10 @@ bucket_alloc(int entries, int bflags)
* boot pages. This also prevents us from allocating buckets in
* low memory situations.
*/
if (bucketdisable)
return (NULL);
idx = howmany(entries, 1 << BUCKET_SHIFT);
ubz = &bucket_zones[bucket_size[idx]];
ubz = bucket_zone_lookup(entries);
bucket = uma_zalloc_internal(ubz->ubz_zone, NULL, bflags);
if (bucket) {
#ifdef INVARIANTS
@ -315,10 +333,8 @@ static void
bucket_free(uma_bucket_t bucket)
{
struct uma_bucket_zone *ubz;
int idx;
idx = howmany(bucket->ub_entries, 1 << BUCKET_SHIFT);
ubz = &bucket_zones[bucket_size[idx]];
ubz = bucket_zone_lookup(bucket->ub_entries);
uma_zfree_internal(ubz->ubz_zone, bucket, NULL, SKIP_NONE);
}