Index: kernel/generic/src/mm/slab.c
===================================================================
--- kernel/generic/src/mm/slab.c	(revision 1b20da07baaa3e3c424f62c927274e676e4295cd)
+++ kernel/generic/src/mm/slab.c	(revision a35b458e9db1ca95e679799dc7c1b12c83359ca3)
@@ -186,15 +186,15 @@
 {
 	size_t zone = 0;
-	
+
 	uintptr_t data_phys =
 	    frame_alloc_generic(cache->frames, flags, 0, &zone);
 	if (!data_phys)
 		return NULL;
-	
+
 	void *data = (void *) PA2KA(data_phys);
-	
+
 	slab_t *slab;
 	size_t fsize;
-	
+
 	if (!(cache->flags & SLAB_CACHE_SLINSIDE)) {
 		slab = slab_alloc(slab_extern_cache, flags);
@@ -207,18 +207,18 @@
 		slab = data + fsize - sizeof(*slab);
 	}
-	
+
 	/* Fill in slab structures */
 	size_t i;
 	for (i = 0; i < cache->frames; i++)
 		frame_set_parent(ADDR2PFN(KA2PA(data)) + i, slab, zone);
-	
+
 	slab->start = data;
 	slab->available = cache->objects;
 	slab->nextavail = 0;
 	slab->cache = cache;
-	
+
 	for (i = 0; i < cache->objects; i++)
 		*((size_t *) (slab->start + i * cache->size)) = i + 1;
-	
+
 	atomic_inc(&cache->allocated_slabs);
 	return slab;
@@ -235,7 +235,7 @@
 	if (!(cache->flags & SLAB_CACHE_SLINSIDE))
 		slab_free(slab_extern_cache, slab);
-	
+
 	atomic_dec(&cache->allocated_slabs);
-	
+
 	return cache->frames;
 }
@@ -263,19 +263,19 @@
 	if (!slab)
 		slab = obj2slab(obj);
-	
+
 	assert(slab->cache == cache);
-	
+
 	size_t freed = 0;
-	
+
 	if (cache->destructor)
 		freed = cache->destructor(obj);
-	
+
 	irq_spinlock_lock(&cache->slablock, true);
 	assert(slab->available < cache->objects);
-	
+
 	*((size_t *) obj) = slab->nextavail;
 	slab->nextavail = (obj - slab->start) / cache->size;
 	slab->available++;
-	
+
 	/* Move it to correct list */
 	if (slab->available == cache->objects) {
@@ -283,5 +283,5 @@
 		list_remove(&slab->link);
 		irq_spinlock_unlock(&cache->slablock, true);
-		
+
 		return freed + slab_space_free(cache, slab);
 	} else if (slab->available == 1) {
@@ -290,5 +290,5 @@
 		list_prepend(&slab->link, &cache->partial_slabs);
 	}
-	
+
 	irq_spinlock_unlock(&cache->slablock, true);
 	return freed;
@@ -303,7 +303,7 @@
 {
 	irq_spinlock_lock(&cache->slablock, true);
-	
+
 	slab_t *slab;
-	
+
 	if (list_empty(&cache->partial_slabs)) {
 		/*
@@ -319,5 +319,5 @@
 		if (!slab)
 			return NULL;
-		
+
 		irq_spinlock_lock(&cache->slablock, true);
 	} else {
@@ -326,16 +326,16 @@
 		list_remove(&slab->link);
 	}
-	
+
 	void *obj = slab->start + slab->nextavail * cache->size;
 	slab->nextavail = *((size_t *) obj);
 	slab->available--;
-	
+
 	if (!slab->available)
 		list_prepend(&slab->link, &cache->full_slabs);
 	else
 		list_prepend(&slab->link, &cache->partial_slabs);
-	
+
 	irq_spinlock_unlock(&cache->slablock, true);
-	
+
 	if ((cache->constructor) && (cache->constructor(obj, flags) != EOK)) {
 		/* Bad, bad, construction failed */
@@ -343,5 +343,5 @@
 		return NULL;
 	}
-	
+
 	return obj;
 }
@@ -361,5 +361,5 @@
 	slab_magazine_t *mag = NULL;
 	link_t *cur;
-	
+
 	irq_spinlock_lock(&cache->maglock, true);
 	if (!list_empty(&cache->magazines)) {
@@ -368,5 +368,5 @@
 		else
 			cur = list_last(&cache->magazines);
-		
+
 		mag = list_get_instance(cur, slab_magazine_t, link);
 		list_remove(&mag->link);
@@ -385,8 +385,8 @@
 {
 	irq_spinlock_lock(&cache->maglock, true);
-	
+
 	list_prepend(&mag->link, &cache->magazines);
 	atomic_inc(&cache->magazine_counter);
-	
+
 	irq_spinlock_unlock(&cache->maglock, true);
 }
@@ -402,12 +402,12 @@
 	size_t i;
 	size_t frames = 0;
-	
+
 	for (i = 0; i < mag->busy; i++) {
 		frames += slab_obj_destroy(cache, mag->objs[i], NULL);
 		atomic_dec(&cache->cached_objs);
 	}
-	
+
 	slab_free(&mag_cache, mag);
-	
+
 	return frames;
 }
@@ -420,11 +420,11 @@
 	slab_magazine_t *cmag = cache->mag_cache[CPU->id].current;
 	slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
-	
+
 	assert(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
-	
+
 	if (cmag) { /* First try local CPU magazines */
 		if (cmag->busy)
 			return cmag;
-		
+
 		if ((lastmag) && (lastmag->busy)) {
 			cache->mag_cache[CPU->id].current = lastmag;
@@ -433,16 +433,16 @@
 		}
 	}
-	
+
 	/* Local magazines are empty, import one from magazine list */
 	slab_magazine_t *newmag = get_mag_from_cache(cache, 1);
 	if (!newmag)
 		return NULL;
-	
+
 	if (lastmag)
 		magazine_destroy(cache, lastmag);
-	
+
 	cache->mag_cache[CPU->id].last = cmag;
 	cache->mag_cache[CPU->id].current = newmag;
-	
+
 	return newmag;
 }
@@ -457,7 +457,7 @@
 	if (!CPU)
 		return NULL;
-	
+
 	irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
-	
+
 	slab_magazine_t *mag = get_full_current_mag(cache);
 	if (!mag) {
@@ -465,10 +465,10 @@
 		return NULL;
 	}
-	
+
 	void *obj = mag->objs[--mag->busy];
 	irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
-	
+
 	atomic_dec(&cache->cached_objs);
-	
+
 	return obj;
 }
@@ -487,11 +487,11 @@
 	slab_magazine_t *cmag = cache->mag_cache[CPU->id].current;
 	slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
-	
+
 	assert(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
-	
+
 	if (cmag) {
 		if (cmag->busy < cmag->size)
 			return cmag;
-		
+
 		if ((lastmag) && (lastmag->busy < lastmag->size)) {
 			cache->mag_cache[CPU->id].last = cmag;
@@ -500,7 +500,7 @@
 		}
 	}
-	
+
 	/* current | last are full | nonexistent, allocate new */
-	
+
 	/*
 	 * We do not want to sleep just because of caching,
@@ -513,16 +513,16 @@
 	if (!newmag)
 		return NULL;
-	
+
 	newmag->size = SLAB_MAG_SIZE;
 	newmag->busy = 0;
-	
+
 	/* Flush last to magazine list */
 	if (lastmag)
 		put_mag_to_cache(cache, lastmag);
-	
+
 	/* Move current as last, save new as current */
 	cache->mag_cache[CPU->id].last = cmag;
 	cache->mag_cache[CPU->id].current = newmag;
-	
+
 	return newmag;
 }
@@ -537,7 +537,7 @@
 	if (!CPU)
 		return -1;
-	
+
 	irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
-	
+
 	slab_magazine_t *mag = make_empty_current_mag(cache);
 	if (!mag) {
@@ -545,11 +545,11 @@
 		return -1;
 	}
-	
+
 	mag->objs[mag->busy++] = obj;
-	
+
 	irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
-	
+
 	atomic_inc(&cache->cached_objs);
-	
+
 	return 0;
 }
@@ -578,8 +578,8 @@
 	size_t objects = comp_objects(cache);
 	size_t ssize = FRAMES2SIZE(cache->frames);
-	
+
 	if (cache->flags & SLAB_CACHE_SLINSIDE)
 		ssize -= sizeof(slab_t);
-	
+
 	return ssize - objects * cache->size;
 }
@@ -591,9 +591,9 @@
 {
 	assert(_slab_initialized >= 2);
-	
+
 	cache->mag_cache = slab_alloc(&slab_mag_cache, FRAME_ATOMIC);
 	if (!cache->mag_cache)
 		return false;
-	
+
 	size_t i;
 	for (i = 0; i < config.cpu_count; i++) {
@@ -602,5 +602,5 @@
 		    "slab.cache.mag_cache[].lock");
 	}
-	
+
 	return true;
 }
@@ -614,44 +614,44 @@
 {
 	assert(size > 0);
-	
+
 	memsetb(cache, sizeof(*cache), 0);
 	cache->name = name;
-	
+
 	if (align < sizeof(sysarg_t))
 		align = sizeof(sysarg_t);
-	
+
 	size = ALIGN_UP(size, align);
-	
+
 	cache->size = size;
 	cache->constructor = constructor;
 	cache->destructor = destructor;
 	cache->flags = flags;
-	
+
 	list_initialize(&cache->full_slabs);
 	list_initialize(&cache->partial_slabs);
 	list_initialize(&cache->magazines);
-	
+
 	irq_spinlock_initialize(&cache->slablock, "slab.cache.slablock");
 	irq_spinlock_initialize(&cache->maglock, "slab.cache.maglock");
-	
+
 	if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
 		(void) make_magcache(cache);
-	
+
 	/* Compute slab sizes, object counts in slabs etc. */
 	if (cache->size < SLAB_INSIDE_SIZE)
 		cache->flags |= SLAB_CACHE_SLINSIDE;
-	
+
 	/* Minimum slab frames */
 	cache->frames = SIZE2FRAMES(cache->size);
-	
+
 	while (badness(cache) > SLAB_MAX_BADNESS(cache))
 		cache->frames <<= 1;
-	
+
 	cache->objects = comp_objects(cache);
-	
+
 	/* If info fits in, put it inside */
 	if (badness(cache) > sizeof(slab_t))
 		cache->flags |= SLAB_CACHE_SLINSIDE;
-	
+
 	/* Add cache to cache list */
 	irq_spinlock_lock(&slab_cache_lock, true);
@@ -670,5 +670,5 @@
 	_slab_cache_create(cache, name, size, align, constructor, destructor,
 	    flags);
-	
+
 	return cache;
 }
@@ -685,5 +685,5 @@
 	if (cache->flags & SLAB_CACHE_NOMAGAZINE)
 		return 0; /* Nothing to do */
-	
+
 	/*
 	 * We count up to original magazine count to avoid
@@ -691,8 +691,8 @@
 	 */
 	atomic_count_t magcount = atomic_get(&cache->magazine_counter);
-	
+
 	slab_magazine_t *mag;
 	size_t frames = 0;
-	
+
 	while ((magcount--) && (mag = get_mag_from_cache(cache, 0))) {
 		frames += magazine_destroy(cache, mag);
@@ -700,5 +700,5 @@
 			break;
 	}
-	
+
 	if (flags & SLAB_RECLAIM_ALL) {
 		/* Free cpu-bound magazines */
@@ -707,19 +707,19 @@
 		for (i = 0; i < config.cpu_count; i++) {
 			irq_spinlock_lock(&cache->mag_cache[i].lock, true);
-			
+
 			mag = cache->mag_cache[i].current;
 			if (mag)
 				frames += magazine_destroy(cache, mag);
 			cache->mag_cache[i].current = NULL;
-			
+
 			mag = cache->mag_cache[i].last;
 			if (mag)
 				frames += magazine_destroy(cache, mag);
 			cache->mag_cache[i].last = NULL;
-			
+
 			irq_spinlock_unlock(&cache->mag_cache[i].lock, true);
 		}
 	}
-	
+
 	return frames;
 }
@@ -731,9 +731,9 @@
 {
 	ipl_t ipl = interrupts_disable();
-	
+
 	if ((cache->flags & SLAB_CACHE_NOMAGAZINE) ||
 	    (magazine_obj_put(cache, obj)))
 		slab_obj_destroy(cache, obj, slab);
-	
+
 	interrupts_restore(ipl);
 	atomic_dec(&cache->allocated_objs);
@@ -753,5 +753,5 @@
 	list_remove(&cache->link);
 	irq_spinlock_unlock(&slab_cache_lock, true);
-	
+
 	/*
 	 * Do not lock anything, we assume the software is correct and
@@ -759,18 +759,18 @@
 	 *
 	 */
-	
+
 	/* Destroy all magazines */
 	_slab_reclaim(cache, SLAB_RECLAIM_ALL);
-	
+
 	/* All slabs must be empty */
 	if ((!list_empty(&cache->full_slabs)) ||
 	    (!list_empty(&cache->partial_slabs)))
 		panic("Destroying cache that is not empty.");
-	
+
 	if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) {
 		slab_t *mag_slab = obj2slab(cache->mag_cache);
 		_slab_free(mag_slab->cache, cache->mag_cache, mag_slab);
 	}
-	
+
 	slab_free(&slab_cache_cache, cache);
 }
@@ -783,18 +783,18 @@
 	/* Disable interrupts to avoid deadlocks with interrupt handlers */
 	ipl_t ipl = interrupts_disable();
-	
+
 	void *result = NULL;
-	
+
 	if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
 		result = magazine_obj_get(cache);
-	
+
 	if (!result)
 		result = slab_obj_create(cache, flags);
-	
+
 	interrupts_restore(ipl);
-	
+
 	if (result)
 		atomic_inc(&cache->allocated_objs);
-	
+
 	return result;
 }
@@ -812,12 +812,12 @@
 {
 	irq_spinlock_lock(&slab_cache_lock, true);
-	
+
 	size_t frames = 0;
 	list_foreach(slab_cache_list, link, slab_cache_t, cache) {
 		frames += _slab_reclaim(cache, flags);
 	}
-	
+
 	irq_spinlock_unlock(&slab_cache_lock, true);
-	
+
 	return frames;
 }
@@ -828,5 +828,5 @@
 	printf("[cache name      ] [size  ] [pages ] [obj/pg] [slabs ]"
 	    " [cached] [alloc ] [ctl]\n");
-	
+
 	size_t skip = 0;
 	while (true) {
@@ -853,7 +853,7 @@
 		 * statistics.
 		 */
-		
+
 		irq_spinlock_lock(&slab_cache_lock, true);
-		
+
 		link_t *cur;
 		size_t i;
@@ -861,14 +861,14 @@
 		    (i < skip) && (cur != &slab_cache_list.head);
 		    i++, cur = cur->next);
-		
+
 		if (cur == &slab_cache_list.head) {
 			irq_spinlock_unlock(&slab_cache_lock, true);
 			break;
 		}
-		
+
 		skip++;
-		
+
 		slab_cache_t *cache = list_get_instance(cur, slab_cache_t, link);
-		
+
 		const char *name = cache->name;
 		size_t frames = cache->frames;
@@ -879,7 +879,7 @@
 		long allocated_objs = atomic_get(&cache->allocated_objs);
 		unsigned int flags = cache->flags;
-		
+
 		irq_spinlock_unlock(&slab_cache_lock, true);
-		
+
 		printf("%-18s %8zu %8zu %8zu %8ld %8ld %8ld %-5s\n",
 		    name, size, frames, objects, allocated_slabs,
@@ -896,18 +896,18 @@
 	    sizeof(uintptr_t), NULL, NULL, SLAB_CACHE_NOMAGAZINE |
 	    SLAB_CACHE_SLINSIDE);
-	
+
 	/* Initialize slab_cache cache */
 	_slab_cache_create(&slab_cache_cache, "slab_cache_cache",
 	    sizeof(slab_cache_cache), sizeof(uintptr_t), NULL, NULL,
 	    SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
-	
+
 	/* Initialize external slab cache */
 	slab_extern_cache = slab_cache_create("slab_t", sizeof(slab_t), 0,
 	    NULL, NULL, SLAB_CACHE_SLINSIDE | SLAB_CACHE_MAGDEFERRED);
-	
+
 	/* Initialize structures for malloc */
 	size_t i;
 	size_t size;
-	
+
 	for (i = 0, size = (1 << SLAB_MIN_MALLOC_W);
 	    i < (SLAB_MAX_MALLOC_W - SLAB_MIN_MALLOC_W + 1);
@@ -916,5 +916,5 @@
 		    NULL, NULL, SLAB_CACHE_MAGDEFERRED);
 	}
-	
+
 #ifdef CONFIG_DEBUG
 	_slab_initialized = 1;
@@ -934,20 +934,20 @@
 	_slab_initialized = 2;
 #endif
-	
+
 	_slab_cache_create(&slab_mag_cache, "slab_mag_cache",
 	    sizeof(slab_mag_cache_t) * config.cpu_count, sizeof(uintptr_t),
 	    NULL, NULL, SLAB_CACHE_NOMAGAZINE | SLAB_CACHE_SLINSIDE);
-	
+
 	irq_spinlock_lock(&slab_cache_lock, false);
-	
+
 	list_foreach(slab_cache_list, link, slab_cache_t, slab) {
 		if ((slab->flags & SLAB_CACHE_MAGDEFERRED) !=
 		    SLAB_CACHE_MAGDEFERRED)
 			continue;
-		
+
 		(void) make_magcache(slab);
 		slab->flags &= ~SLAB_CACHE_MAGDEFERRED;
 	}
-	
+
 	irq_spinlock_unlock(&slab_cache_lock, false);
 }
@@ -957,10 +957,10 @@
 	assert(_slab_initialized);
 	assert(size <= (1 << SLAB_MAX_MALLOC_W));
-	
+
 	if (size < (1 << SLAB_MIN_MALLOC_W))
 		size = (1 << SLAB_MIN_MALLOC_W);
-	
+
 	uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
-	
+
 	return slab_alloc(malloc_caches[idx], flags);
 }
@@ -970,24 +970,24 @@
 	assert(_slab_initialized);
 	assert(size <= (1 << SLAB_MAX_MALLOC_W));
-	
+
 	void *new_ptr;
-	
+
 	if (size > 0) {
 		if (size < (1 << SLAB_MIN_MALLOC_W))
 			size = (1 << SLAB_MIN_MALLOC_W);
 		uint8_t idx = fnzb(size - 1) - SLAB_MIN_MALLOC_W + 1;
-		
+
 		new_ptr = slab_alloc(malloc_caches[idx], flags);
 	} else
 		new_ptr = NULL;
-	
+
 	if ((new_ptr != NULL) && (ptr != NULL)) {
 		slab_t *slab = obj2slab(ptr);
 		memcpy(new_ptr, ptr, min(size, slab->cache->size));
 	}
-	
+
 	if (ptr != NULL)
 		free(ptr);
-	
+
 	return new_ptr;
 }
@@ -997,5 +997,5 @@
 	if (!ptr)
 		return;
-	
+
 	slab_t *slab = obj2slab(ptr);
 	_slab_free(slab->cache, ptr, slab);
