summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-11-06 11:43:30 +0000
committerrwatson <rwatson@FreeBSD.org>2004-11-06 11:43:30 +0000
commit2b775a8633a9fd57b9fe564ed98292d3b7fac655 (patch)
tree0648f9435ff6105c0b5e779a10eb6c2b6d30be62 /sys/vm
parent723cc1105c8cd8be21a3800f116d815c99e87bb7 (diff)
downloadFreeBSD-src-2b775a8633a9fd57b9fe564ed98292d3b7fac655.zip
FreeBSD-src-2b775a8633a9fd57b9fe564ed98292d3b7fac655.tar.gz
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.
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/uma_core.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index bed3ab7..51ace74 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -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);
}
OpenPOWER on IntegriCloud