summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/bitmap_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/bitmap_allocator.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
index 5042980f..6fc508d6 100644
--- a/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/bitmap_allocator.c
@@ -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,
@@ -22,9 +22,6 @@
22 22
23#include "bitmap_allocator_priv.h" 23#include "bitmap_allocator_priv.h"
24 24
25static struct kmem_cache *meta_data_cache; /* slab cache for meta data. */
26static DEFINE_MUTEX(meta_data_cache_lock);
27
28static u64 nvgpu_bitmap_alloc_length(struct nvgpu_allocator *a) 25static u64 nvgpu_bitmap_alloc_length(struct nvgpu_allocator *a)
29{ 26{
30 struct nvgpu_bitmap_allocator *ba = a->priv; 27 struct nvgpu_bitmap_allocator *ba = a->priv;
@@ -195,7 +192,7 @@ static int __nvgpu_bitmap_store_alloc(struct nvgpu_bitmap_allocator *a,
195 u64 addr, u64 len) 192 u64 addr, u64 len)
196{ 193{
197 struct nvgpu_bitmap_alloc *alloc = 194 struct nvgpu_bitmap_alloc *alloc =
198 kmem_cache_alloc(meta_data_cache, GFP_KERNEL); 195 nvgpu_kmem_cache_alloc(a->meta_data_cache);
199 196
200 if (!alloc) 197 if (!alloc)
201 return -ENOMEM; 198 return -ENOMEM;
@@ -312,7 +309,8 @@ static void nvgpu_bitmap_free(struct nvgpu_allocator *__a, u64 addr)
312 a->bytes_freed += alloc->length; 309 a->bytes_freed += alloc->length;
313 310
314done: 311done:
315 kfree(alloc); 312 if (a->meta_data_cache && alloc)
313 nvgpu_kmem_cache_free(a->meta_data_cache, alloc);
316 alloc_unlock(__a); 314 alloc_unlock(__a);
317} 315}
318 316
@@ -330,9 +328,10 @@ static void nvgpu_bitmap_alloc_destroy(struct nvgpu_allocator *__a)
330 alloc_entry); 328 alloc_entry);
331 329
332 rb_erase(node, &a->allocs); 330 rb_erase(node, &a->allocs);
333 kfree(alloc); 331 nvgpu_kmem_cache_free(a->meta_data_cache, alloc);
334 } 332 }
335 333
334 nvgpu_kmem_cache_destroy(a->meta_data_cache);
336 kfree(a->bitmap); 335 kfree(a->bitmap);
337 kfree(a); 336 kfree(a);
338} 337}
@@ -382,14 +381,6 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
382 int err; 381 int err;
383 struct nvgpu_bitmap_allocator *a; 382 struct nvgpu_bitmap_allocator *a;
384 383
385 mutex_lock(&meta_data_cache_lock);
386 if (!meta_data_cache)
387 meta_data_cache = KMEM_CACHE(nvgpu_bitmap_alloc, 0);
388 mutex_unlock(&meta_data_cache_lock);
389
390 if (!meta_data_cache)
391 return -ENOMEM;
392
393 if (WARN_ON(blk_size & (blk_size - 1))) 384 if (WARN_ON(blk_size & (blk_size - 1)))
394 return -EINVAL; 385 return -EINVAL;
395 386
@@ -414,6 +405,15 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
414 if (err) 405 if (err)
415 goto fail; 406 goto fail;
416 407
408 if (!(flags & GPU_ALLOC_NO_ALLOC_PAGE)) {
409 a->meta_data_cache = nvgpu_kmem_cache_create(g,
410 sizeof(struct nvgpu_bitmap_alloc));
411 if (!a->meta_data_cache) {
412 err = -ENOMEM;
413 goto fail;
414 }
415 }
416
417 a->base = base; 417 a->base = base;
418 a->length = length; 418 a->length = length;
419 a->blk_size = blk_size; 419 a->blk_size = blk_size;
@@ -424,8 +424,10 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
424 424
425 a->bitmap = kcalloc(BITS_TO_LONGS(a->num_bits), sizeof(*a->bitmap), 425 a->bitmap = kcalloc(BITS_TO_LONGS(a->num_bits), sizeof(*a->bitmap),
426 GFP_KERNEL); 426 GFP_KERNEL);
427 if (!a->bitmap) 427 if (!a->bitmap) {
428 err = -ENOMEM;
428 goto fail; 429 goto fail;
430 }
429 431
430 wmb(); 432 wmb();
431 a->inited = true; 433 a->inited = true;
@@ -441,6 +443,8 @@ int nvgpu_bitmap_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
441 return 0; 443 return 0;
442 444
443fail: 445fail:
446 if (a->meta_data_cache)
447 nvgpu_kmem_cache_destroy(a->meta_data_cache);
444 kfree(a); 448 kfree(a);
445 return err; 449 return err;
446} 450}