summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2013-01-08 00:05:48 +0100
committerRichard Braun <rbraun@sceen.net>2013-01-08 00:05:48 +0100
commitdd961d1cef715b4c1e4fedd2f43fae6703f128ba (patch)
tree0aa1828e8ff98d366657cdd919b128b30e7063eb /kern
parent392239d8c9979ac95c122b77d5d1e012f216d2ec (diff)
Add function to dump a raw summary of the slab allocator state
The purpose of this function is to allow kernel code to display the state of the slab caches in situations where the host_slab_info RPC wouldn't be available, e.g. before a panic. * kern/slab.c (slab_info): New function. * kern/slab.h: Add declaration for slab_info.
Diffstat (limited to 'kern')
-rw-r--r--kern/slab.c29
-rw-r--r--kern/slab.h5
2 files changed, 34 insertions, 0 deletions
diff --git a/kern/slab.c b/kern/slab.c
index 64f1fa8..2923f47 100644
--- a/kern/slab.c
+++ b/kern/slab.c
@@ -1490,6 +1490,35 @@ void kfree(vm_offset_t data, vm_size_t size)
}
}
+void slab_info(void)
+{
+ struct kmem_cache *cache;
+ vm_size_t mem_usage, mem_reclaimable;
+
+ printf("cache obj slab bufs objs bufs "
+ " total reclaimable\n"
+ "name size size /slab usage count "
+ " memory memory\n");
+
+ simple_lock(&kmem_cache_list_lock);
+
+ list_for_each_entry(&kmem_cache_list, cache, node) {
+ simple_lock(&cache->lock);
+
+ mem_usage = (cache->nr_slabs * cache->slab_size) >> 10;
+ mem_reclaimable = (cache->nr_free_slabs * cache->slab_size) >> 10;
+
+ printf("%-19s %6lu %3luk %4lu %6lu %6lu %7luk %10luk\n",
+ cache->name, cache->obj_size, cache->slab_size >> 10,
+ cache->bufs_per_slab, cache->nr_objs, cache->nr_bufs,
+ mem_usage, mem_reclaimable);
+
+ simple_unlock(&cache->lock);
+ }
+
+ simple_unlock(&kmem_cache_list_lock);
+}
+
#if MACH_DEBUG
kern_return_t host_slab_info(host_t host, cache_info_array_t *infop,
unsigned int *infoCntp)
diff --git a/kern/slab.h b/kern/slab.h
index 6abe2dc..47bef21 100644
--- a/kern/slab.h
+++ b/kern/slab.h
@@ -246,4 +246,9 @@ void slab_init(void);
*/
void slab_collect(void);
+/*
+ * Display a summary of all kernel caches.
+ */
+void slab_info(void);
+
#endif /* _KERN_SLAB_H */