--- Gnu-Mach/kern/slab.c 2020/09/02 04:45:19 1.1 +++ Gnu-Mach/kern/slab.c 2020/09/02 04:49:56 1.1.1.3 @@ -79,6 +79,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,6 @@ /* * Utility macros. */ -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define P2ALIGNED(x, a) (((x) & ((a) - 1)) == 0) #define ISP2(x) P2ALIGNED(x, x) #define P2ALIGN(x, a) ((x) & -(a)) @@ -165,7 +165,7 @@ /* * Size of the VM submap from which default backend functions allocate. */ -#define KMEM_MAP_SIZE (128 * 1024 * 1024) +#define KMEM_MAP_SIZE (96 * 1024 * 1024) /* * Shift for the first kalloc cache size. @@ -289,8 +289,8 @@ vm_map_t kmem_map = &kmem_map_store; static unsigned long kmem_gc_last_tick; #define kmem_error(format, ...) \ - printf("mem: error: %s(): " format "\n", __func__, \ - ## __VA_ARGS__) + panic("mem: error: %s(): " format "\n", __func__, \ + ## __VA_ARGS__) #define kmem_warn(format, ...) \ printf("mem: warning: %s(): " format "\n", __func__, \ @@ -662,7 +662,7 @@ static void kmem_cache_error(struct kmem { struct kmem_buftag *buftag; - kmem_error("cache: %s, buffer: %p", cache->name, (void *)buf); + kmem_warn("cache: %s, buffer: %p", cache->name, (void *)buf); switch(error) { case KMEM_ERR_INVALID: @@ -702,9 +702,9 @@ static void kmem_cache_error(struct kmem */ static void kmem_cache_compute_sizes(struct kmem_cache *cache, int flags) { - size_t i, buffers, buf_size, slab_size, free_slab_size, optimal_size; + size_t i, buffers, buf_size, slab_size, free_slab_size, optimal_size = 0; size_t waste, waste_min; - int embed, optimal_embed = optimal_embed; + int embed, optimal_embed = 0; buf_size = cache->buf_size; @@ -745,6 +745,7 @@ static void kmem_cache_compute_sizes(str } while ((buffers < KMEM_MIN_BUFS_PER_SLAB) && (slab_size < KMEM_SLAB_SIZE_THRESHOLD)); + assert(optimal_size > 0); assert(!(flags & KMEM_CACHE_NOOFFSLAB) || optimal_embed); cache->slab_size = optimal_size; @@ -1432,15 +1433,18 @@ void kfree(vm_offset_t data, vm_size_t s } } -void slab_info(void) +static void _slab_info(int (printx)(const char *fmt, ...)) { struct kmem_cache *cache; - vm_size_t mem_usage, mem_reclaimable; + vm_size_t mem_usage, mem_reclaimable, mem_total, mem_total_reclaimable; - printf("cache obj slab bufs objs bufs " - " total reclaimable\n" - "name size size /slab usage count " - " memory memory\n"); + mem_total = 0; + mem_total_reclaimable = 0; + + printx("cache obj slab bufs objs bufs" + " total reclaimable\n" + "name flags size size /slab usage count" + " memory memory\n"); simple_lock(&kmem_cache_list_lock); @@ -1450,17 +1454,39 @@ void slab_info(void) 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 %7uk %10uk\n", - cache->name, cache->obj_size, cache->slab_size >> 10, + printx("%-20s %04x %7lu %3luk %4lu %6lu %6lu %7uk %10uk\n", + cache->name, cache->flags, 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); + + mem_total += mem_usage; + mem_total_reclaimable += mem_reclaimable; } simple_unlock(&kmem_cache_list_lock); + + printx("total: %uk, reclaimable: %uk\n", + mem_total, mem_total_reclaimable); } +void slab_info(void) +{ + _slab_info(printf); +} + +#if MACH_KDB +#include + + void db_show_slab_info(void) +{ + _slab_info(db_printf); +} + +#endif /* MACH_KDB */ + #if MACH_DEBUG kern_return_t host_slab_info(host_t host, cache_info_array_t *infop, unsigned int *infoCntp) @@ -1468,7 +1494,7 @@ kern_return_t host_slab_info(host_t host struct kmem_cache *cache; cache_info_t *info; unsigned int i, nr_caches; - vm_size_t info_size = info_size; + vm_size_t info_size = 0; kern_return_t kr; if (host == HOST_NULL) @@ -1502,7 +1528,7 @@ kern_return_t host_slab_info(host_t host i = 0; list_for_each_entry(&kmem_cache_list, cache, node) { - simple_lock(&cache_lock); + simple_lock(&cache->lock); info[i].flags = ((cache->flags & KMEM_CF_NO_CPU_POOL) ? CACHE_FLAGS_NO_CPU_POOL : 0) | ((cache->flags & KMEM_CF_SLAB_EXTERNAL)