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 <tbergstrom@nvidia.com>
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
This commit is contained in:
Terje Bergstrom
2015-05-18 13:37:54 -07:00
parent d5fd0689c2
commit 0dc66952e4
3 changed files with 33 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -22,6 +22,7 @@
#include <linux/dma-attrs.h>
#include <linux/iommu.h>
#include <linux/tegra-soc.h>
#include <linux/vmalloc.h>
#include <asm/dma-iommu.h>
#include <asm/cacheflush.h>
#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 */