atomisp: hmm_vm: use slab to allocate hmm vm nodes
authorDavid Cohen <david.a.cohen@intel.com>
Fri, 9 Dec 2011 09:10:51 +0000 (11:10 +0200)
committerbuildbot <buildbot@intel.com>
Tue, 3 Jan 2012 13:35:20 +0000 (05:35 -0800)
BZ: 18074

Slab is more efficient than kmalloc() to allocate same struct many
times.

Change-Id: I590375ae7f5235f4b4e4fac379064d3e95f047c7
Signed-off-by: David Cohen <david.a.cohen@intel.com>
Reviewed-on: http://android.intel.com:8080/29504
Reviewed-by: Koskinen, Ilkka <ilkka.koskinen@intel.com>
Reviewed-by: Tuominen, TeemuX <teemux.tuominen@intel.com>
Tested-by: Koski, Anttu <anttu.koski@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
drivers/media/video/atomisp/hmm/hmm_vm.c
drivers/media/video/atomisp/include/hmm/hmm_vm.h

index 9035179..27a67b4 100644 (file)
@@ -57,8 +57,10 @@ int hmm_vm_init(struct hmm_vm *vm, unsigned int start,
 
        INIT_LIST_HEAD(&vm->vm_node_list);
        spin_lock_init(&vm->lock);
+       vm->cache = kmem_cache_create("atomisp_vm", sizeof(struct hmm_vm_node),
+                                     0, 0, NULL);
 
-       return 0;
+       return vm->cache != NULL ? 0 : -ENOMEM;
 }
 
 void hmm_vm_clean(struct hmm_vm *vm)
@@ -75,8 +77,10 @@ void hmm_vm_clean(struct hmm_vm *vm)
 
        list_for_each_entry_safe(node, tmp, &new_head, list) {
                list_del(&node->list);
-               kfree(node);
+               kmem_cache_free(vm->cache, node);
        }
+
+       kmem_cache_destroy(vm->cache);
 }
 
 static struct hmm_vm_node *alloc_hmm_vm_node(unsigned int start,
@@ -85,7 +89,7 @@ static struct hmm_vm_node *alloc_hmm_vm_node(unsigned int start,
 {
        struct hmm_vm_node *node;
 
-       node = kzalloc(sizeof(struct hmm_vm_node), GFP_KERNEL);
+       node = kmem_cache_alloc(vm->cache, GFP_KERNEL);
        if (!node) {
                v4l2_err(&atomisp_dev, "out of memory.\n");
                return NULL;
@@ -170,7 +174,7 @@ void hmm_vm_free_node(struct hmm_vm_node *node)
        list_del(&node->list);
        spin_unlock(&vm->lock);
 
-       kfree(node);
+       kmem_cache_free(vm->cache, node);
 }
 
 struct hmm_vm_node *hmm_vm_find_node_start(struct hmm_vm *vm, unsigned int addr)
index 66ef6e7..f73439d 100644 (file)
@@ -35,6 +35,7 @@ struct hmm_vm {
        unsigned int size;
        struct list_head vm_node_list;
        spinlock_t lock;
+       struct kmem_cache *cache;
 };
 
 struct hmm_vm_node {