if (kmalloc_verbose)
pr_debug("Bulk alloc %zu\n", size);
pthread_mutex_lock(&cachep->lock); if (cachep->nr_objs >= size) { struct radix_tree_node *node;
for (i = 0; i < size; i++) { if (!(gfp & __GFP_DIRECT_RECLAIM)) { if (!cachep->non_kernel) break;
cachep->non_kernel--;
}
node = cachep->objs;
cachep->nr_objs--;
cachep->objs = node->parent;
p[i] = node;
node->parent = NULL;
}
pthread_mutex_unlock(&cachep->lock);
} else {
pthread_mutex_unlock(&cachep->lock); for (i = 0; i < size; i++) { if (!(gfp & __GFP_DIRECT_RECLAIM)) { if (!cachep->non_kernel) break;
cachep->non_kernel--;
}
if (cachep->align) { if (posix_memalign(&p[i], cachep->align,
cachep->size) < 0) break;
} else {
p[i] = malloc(cachep->size); if (!p[i]) break;
} if (cachep->ctor)
cachep->ctor(p[i]); elseif (gfp & __GFP_ZERO)
memset(p[i], 0, cachep->size);
}
}
if (i < size) {
size = i;
pthread_mutex_lock(&cachep->lock); for (i = 0; i < size; i++)
__kmem_cache_free_locked(cachep, p[i]);
pthread_mutex_unlock(&cachep->lock); return 0;
}
for (i = 0; i < size; i++) {
uatomic_inc(&nr_allocated);
uatomic_inc(&cachep->nr_allocated);
uatomic_inc(&cachep->nr_tallocated); if (kmalloc_verbose)
printf("Allocating %p from slab\n", p[i]);
}
/* * Test the test infrastructure for kem_cache_alloc/free and bulk counterparts.
*/ void test_kmem_cache_bulk(void)
{ int i; void *list[12]; staticstruct kmem_cache *test_cache, *test_cache2;
/* * Testing the bulk allocators without aligned kmem_cache to force the * bulk alloc/free to reuse
*/
test_cache = kmem_cache_create("test_cache", 256, 0, SLAB_PANIC, NULL);
for (i = 0; i < 5; i++)
list[i] = kmem_cache_alloc(test_cache, __GFP_DIRECT_RECLAIM);
for (i = 0; i < 5; i++)
kmem_cache_free(test_cache, list[i]);
assert(test_cache->nr_objs == 5);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.