mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-24 02:22:34 +03:00
gpu: nvgpu: Move kmem_caches to allocator
Instead of using a single static kmem_cache for each type of data structure the allocators may want to allocate each allocator now has its own instance of the kmem_cache. This is done so that each GPU driver instance can accurately track how much memory it is using. In order to support this on older kernels a new NVGPU API has been made, nvgpu_kmem_cache_create(struct gk20a *g, size_t size) To handle the possibility that caches cannot be created with the same name. This patch also fixes numerous places where kfree() was wrongly used to free kmem_cache allocs. Bug 1799159 Bug 1823380 Change-Id: Id674f9a5445fde3f95db65ad6bf3ea990444603d Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: http://git-master/r/1283826 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> GVS: Gerrit_Virtual_Submit
This commit is contained in:
committed by
mobile promotions
parent
24e8ee192a
commit
cf0ef133e6
83
drivers/gpu/nvgpu/common/linux/kmem.c
Normal file
83
drivers/gpu/nvgpu/common/linux/kmem.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/atomic.h>
|
||||
|
||||
#include <nvgpu/kmem.h>
|
||||
|
||||
/*
|
||||
* Statically declared because this needs to be shared across all nvgpu driver
|
||||
* instances. This makes sure that all kmem caches are _definitely_ uniquely
|
||||
* named.
|
||||
*/
|
||||
static atomic_t kmem_cache_id;
|
||||
|
||||
/*
|
||||
* Linux specific version of the nvgpu_kmem_cache struct. This type is
|
||||
* completely opaque to the rest of the driver.
|
||||
*/
|
||||
struct nvgpu_kmem_cache {
|
||||
struct gk20a *g;
|
||||
struct kmem_cache *cache;
|
||||
|
||||
/*
|
||||
* Memory to hold the kmem_cache unique name. Only necessary on our
|
||||
* k3.10 kernel when not using the SLUB allocator but it's easier to
|
||||
* just carry this on to newer kernels.
|
||||
*/
|
||||
char name[128];
|
||||
};
|
||||
|
||||
struct nvgpu_kmem_cache *nvgpu_kmem_cache_create(struct gk20a *g, size_t size)
|
||||
{
|
||||
struct nvgpu_kmem_cache *cache =
|
||||
kzalloc(sizeof(struct nvgpu_kmem_cache), GFP_KERNEL);
|
||||
|
||||
if (!cache)
|
||||
return NULL;
|
||||
|
||||
cache->g = g;
|
||||
|
||||
snprintf(cache->name, sizeof(cache->name),
|
||||
"nvgpu-cache-0x%p-%d-%d", g, (int)size,
|
||||
atomic_inc_return(&kmem_cache_id));
|
||||
cache->cache = kmem_cache_create(cache->name,
|
||||
size, size, 0, NULL);
|
||||
if (!cache->cache) {
|
||||
kfree(cache);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
void nvgpu_kmem_cache_destroy(struct nvgpu_kmem_cache *cache)
|
||||
{
|
||||
kmem_cache_destroy(cache->cache);
|
||||
kfree(cache);
|
||||
}
|
||||
|
||||
void *nvgpu_kmem_cache_alloc(struct nvgpu_kmem_cache *cache)
|
||||
{
|
||||
return kmem_cache_alloc(cache->cache, GFP_KERNEL);
|
||||
}
|
||||
|
||||
void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr)
|
||||
{
|
||||
kmem_cache_free(cache->cache, ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user