summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2013-11-19 10:05:53 +0000
committermav <mav@FreeBSD.org>2013-11-19 10:05:53 +0000
commitbdb3c9c41b08909bb3c3c198c3f00076446f04e0 (patch)
treee37f62a44d8bc8ec49a2a7e99feb1e61ffd3d856 /sys/vm
parent62c161bc59b459ca9045583c55921b481bf30aeb (diff)
downloadFreeBSD-src-bdb3c9c41b08909bb3c3c198c3f00076446f04e0.zip
FreeBSD-src-bdb3c9c41b08909bb3c3c198c3f00076446f04e0.tar.gz
Implement soft pressure on UMA cache bucket sizes.
Every time system detects low memory condition decrease bucket sizes for each zone by one item. As result, higher memory pressure will push to smaller bucket sizes and so smaller per-CPU caches and so more efficient memory use. Before this change there was no force to oppose buckets growth as result of practically inevitable zone lock conflicts, and after some run time per-CPU caches could consume enough RAM to kill the system.
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/uma_core.c9
-rw-r--r--sys/vm/uma_int.h3
2 files changed, 11 insertions, 1 deletions
diff --git a/sys/vm/uma_core.c b/sys/vm/uma_core.c
index e39654e..8710f95 100644
--- a/sys/vm/uma_core.c
+++ b/sys/vm/uma_core.c
@@ -701,6 +701,13 @@ bucket_cache_drain(uma_zone_t zone)
bucket_free(zone, bucket, NULL);
ZONE_LOCK(zone);
}
+
+ /*
+ * Shrink further bucket sizes. Price of single zone lock collision
+ * is probably lower then price of global cache drain.
+ */
+ if (zone->uz_count > zone->uz_count_min)
+ zone->uz_count--;
}
static void
@@ -1461,6 +1468,7 @@ zone_ctor(void *mem, int size, void *udata, int flags)
zone->uz_fails = 0;
zone->uz_sleeps = 0;
zone->uz_count = 0;
+ zone->uz_count_min = 0;
zone->uz_flags = 0;
zone->uz_warning = NULL;
timevalclear(&zone->uz_ratecheck);
@@ -1552,6 +1560,7 @@ out:
zone->uz_count = bucket_select(zone->uz_size);
else
zone->uz_count = BUCKET_MAX;
+ zone->uz_count_min = zone->uz_count;
return (0);
}
diff --git a/sys/vm/uma_int.h b/sys/vm/uma_int.h
index 00e8519..1ffc7d5 100644
--- a/sys/vm/uma_int.h
+++ b/sys/vm/uma_int.h
@@ -300,7 +300,8 @@ struct uma_zone {
volatile u_long uz_fails; /* Total number of alloc failures */
volatile u_long uz_frees; /* Total number of frees */
uint64_t uz_sleeps; /* Total number of alloc sleeps */
- uint16_t uz_count; /* Highest amount of items in bucket */
+ uint16_t uz_count; /* Amount of items in full bucket */
+ uint16_t uz_count_min; /* Minimal amount of items there */
/* The next three fields are used to print a rate-limited warnings. */
const char *uz_warning; /* Warning to print on failure */
OpenPOWER on IntegriCloud