From 0dc66952e4df80b45c77bdbb31ce2a32f216328f Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Mon, 18 May 2015 13:37:54 -0700 Subject: gpu: nvgpu: Use vmalloc only when size >4K When allocation size is 4k or below, we should use kmalloc. vmalloc should be used only for larged allocations. Introduce nvgpu_alloc, which checks the size, and decides the API to use. Change-Id: I593110467cd319851b27e57d1bfe8d228d3f2909 Signed-off-by: Terje Bergstrom Reviewed-on: http://git-master/r/743974 (cherry picked from commit 7f56aa1f0ecafbfde7286353b60e25e494674d26) Reviewed-on: http://git-master/r/753276 Reviewed-by: Automatic_Commit_Validation_User --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 4 ++-- drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 6 +++--- drivers/gpu/nvgpu/gk20a/mm_gk20a.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'drivers/gpu/nvgpu') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index 643adca5..c12f196d 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -2155,7 +2155,7 @@ static int gk20a_ioctl_channel_submit_gpfifo( * synchronization; we might still wait and do an increment */ size = args->num_entries * sizeof(struct nvgpu_gpfifo); if (size) { - gpfifo = vmalloc(size); + gpfifo = nvgpu_alloc(size, false); if (!gpfifo) return -ENOMEM; @@ -2190,7 +2190,7 @@ static int gk20a_ioctl_channel_submit_gpfifo( gk20a_fence_put(fence_out); clean_up: - vfree(gpfifo); + nvgpu_free(gpfifo); return ret; } diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index a38db709..342d3ace 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c @@ -745,8 +745,8 @@ int gk20a_vm_get_buffers(struct vm_gk20a *vm, mutex_lock(&vm->update_gmmu_lock); - buffer_list = kzalloc(sizeof(*buffer_list) * - vm->num_user_mapped_buffers, GFP_KERNEL); + buffer_list = nvgpu_alloc(sizeof(*buffer_list) * + vm->num_user_mapped_buffers, true); if (!buffer_list) { mutex_unlock(&vm->update_gmmu_lock); return -ENOMEM; @@ -795,7 +795,7 @@ void gk20a_vm_put_buffers(struct vm_gk20a *vm, mutex_unlock(&vm->update_gmmu_lock); - kfree(mapped_buffers); + nvgpu_free(mapped_buffers); } static void gk20a_vm_unmap_user(struct vm_gk20a *vm, u64 offset) diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h index 82003cd0..7a627354 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "gk20a_allocator.h" @@ -628,4 +629,31 @@ void gk20a_mm_init_pdb(struct gk20a *g, void *inst_ptr, u64 pdb_addr); extern const struct gk20a_mmu_level gk20a_mm_levels_64k[]; extern const struct gk20a_mmu_level gk20a_mm_levels_128k[]; +static inline void *nvgpu_alloc(size_t size, bool clear) +{ + void *p; + + if (size > PAGE_SIZE) { + if (clear) + p = vzalloc(size); + else + p = vmalloc(size); + } else { + if (clear) + p = kzalloc(size, GFP_KERNEL); + else + p = kmalloc(size, GFP_KERNEL); + } + + return p; +} + +static inline void nvgpu_free(void *p) +{ + if (virt_addr_valid(p)) + kfree(p); + else + vfree(p); +} + #endif /* MM_GK20A_H */ -- cgit v1.2.2