diff options
author | Alex Waterman <alexw@nvidia.com> | 2016-10-04 17:04:01 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-02-10 14:57:31 -0500 |
commit | cf0ef133e6e3075c808bb3f553b35e94fc000afd (patch) | |
tree | 13cace143fe43034791570514a05bf06cfcc47cb /drivers/gpu/nvgpu/include | |
parent | 24e8ee192a02ff75a569f8c734efa9b4b5267fc8 (diff) |
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
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/kmem.h | 40 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/page_allocator.h | 7 |
2 files changed, 46 insertions, 1 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/kmem.h b/drivers/gpu/nvgpu/include/nvgpu/kmem.h new file mode 100644 index 00000000..3d983e77 --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/kmem.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms and conditions of the GNU General Public License, | ||
6 | * version 2, as published by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
11 | * more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #ifndef NVGPU_KMEM_H | ||
18 | #define NVGPU_KMEM_H | ||
19 | |||
20 | struct gk20a; | ||
21 | |||
22 | /* | ||
23 | * In Linux there is support for the notion of a kmem_cache. It gives better | ||
24 | * memory usage characteristics for lots of allocations of the same size. Think | ||
25 | * structs that get allocated over and over. Normal kmalloc() type routines | ||
26 | * typically round to the next power-of-2 since that's easy. | ||
27 | * | ||
28 | * But if we know the size ahead of time the packing for the allocations can be | ||
29 | * much better. This is the benefit of a slab allocator. This type hides the | ||
30 | * underlying kmem_cache (or absense thereof). | ||
31 | */ | ||
32 | struct nvgpu_kmem_cache; | ||
33 | |||
34 | struct nvgpu_kmem_cache *nvgpu_kmem_cache_create(struct gk20a *g, size_t size); | ||
35 | void nvgpu_kmem_cache_destroy(struct nvgpu_kmem_cache *cache); | ||
36 | |||
37 | void *nvgpu_kmem_cache_alloc(struct nvgpu_kmem_cache *cache); | ||
38 | void nvgpu_kmem_cache_free(struct nvgpu_kmem_cache *cache, void *ptr); | ||
39 | |||
40 | #endif | ||
diff --git a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h index 7c21c117..fa586dba 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h +++ b/drivers/gpu/nvgpu/include/nvgpu/page_allocator.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. | 2 | * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | 4 | * This program is free software; you can redistribute it and/or modify it |
5 | * under the terms and conditions of the GNU General Public License, | 5 | * under the terms and conditions of the GNU General Public License, |
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/rbtree.h> | 21 | #include <linux/rbtree.h> |
22 | 22 | ||
23 | #include <nvgpu/allocator.h> | 23 | #include <nvgpu/allocator.h> |
24 | #include <nvgpu/kmem.h> | ||
24 | 25 | ||
25 | struct nvgpu_allocator; | 26 | struct nvgpu_allocator; |
26 | 27 | ||
@@ -134,6 +135,10 @@ struct nvgpu_page_allocator { | |||
134 | struct page_alloc_slab *slabs; | 135 | struct page_alloc_slab *slabs; |
135 | int nr_slabs; | 136 | int nr_slabs; |
136 | 137 | ||
138 | struct nvgpu_kmem_cache *alloc_cache; | ||
139 | struct nvgpu_kmem_cache *chunk_cache; | ||
140 | struct nvgpu_kmem_cache *slab_page_cache; | ||
141 | |||
137 | u64 flags; | 142 | u64 flags; |
138 | 143 | ||
139 | /* | 144 | /* |