summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/mm/buddy_allocator.c')
-rw-r--r--drivers/gpu/nvgpu/common/mm/buddy_allocator.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c b/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
index eee0b634..6f4c670a 100644
--- a/drivers/gpu/nvgpu/common/mm/buddy_allocator.c
+++ b/drivers/gpu/nvgpu/common/mm/buddy_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,
@@ -24,8 +24,6 @@
24 24
25#include "buddy_allocator_priv.h" 25#include "buddy_allocator_priv.h"
26 26
27static struct kmem_cache *buddy_cache; /* slab cache for meta data. */
28
29/* Some other buddy allocator functions. */ 27/* Some other buddy allocator functions. */
30static struct nvgpu_buddy *balloc_free_buddy(struct nvgpu_buddy_allocator *a, 28static struct nvgpu_buddy *balloc_free_buddy(struct nvgpu_buddy_allocator *a,
31 u64 addr); 29 u64 addr);
@@ -103,7 +101,7 @@ static struct nvgpu_buddy *balloc_new_buddy(struct nvgpu_buddy_allocator *a,
103{ 101{
104 struct nvgpu_buddy *new_buddy; 102 struct nvgpu_buddy *new_buddy;
105 103
106 new_buddy = kmem_cache_alloc(buddy_cache, GFP_KERNEL); 104 new_buddy = nvgpu_kmem_cache_alloc(a->buddy_cache);
107 if (!new_buddy) 105 if (!new_buddy)
108 return NULL; 106 return NULL;
109 107
@@ -232,7 +230,7 @@ cleanup:
232 buddy = list_first_entry(balloc_get_order_list(a, i), 230 buddy = list_first_entry(balloc_get_order_list(a, i),
233 struct nvgpu_buddy, buddy_entry); 231 struct nvgpu_buddy, buddy_entry);
234 balloc_blist_rem(a, buddy); 232 balloc_blist_rem(a, buddy);
235 kmem_cache_free(buddy_cache, buddy); 233 nvgpu_kmem_cache_free(a->buddy_cache, buddy);
236 } 234 }
237 } 235 }
238 236
@@ -285,7 +283,7 @@ static void nvgpu_buddy_allocator_destroy(struct nvgpu_allocator *__a)
285 bud = list_first_entry(balloc_get_order_list(a, i), 283 bud = list_first_entry(balloc_get_order_list(a, i),
286 struct nvgpu_buddy, buddy_entry); 284 struct nvgpu_buddy, buddy_entry);
287 balloc_blist_rem(a, bud); 285 balloc_blist_rem(a, bud);
288 kmem_cache_free(buddy_cache, bud); 286 nvgpu_kmem_cache_free(a->buddy_cache, bud);
289 } 287 }
290 288
291 if (a->buddy_list_len[i] != 0) { 289 if (a->buddy_list_len[i] != 0) {
@@ -305,6 +303,7 @@ static void nvgpu_buddy_allocator_destroy(struct nvgpu_allocator *__a)
305 } 303 }
306 } 304 }
307 305
306 nvgpu_kmem_cache_destroy(a->buddy_cache);
308 kfree(a); 307 kfree(a);
309 308
310 alloc_unlock(__a); 309 alloc_unlock(__a);
@@ -348,8 +347,8 @@ static void balloc_coalesce(struct nvgpu_buddy_allocator *a,
348 balloc_coalesce(a, parent); 347 balloc_coalesce(a, parent);
349 348
350 /* Clean up the remains. */ 349 /* Clean up the remains. */
351 kmem_cache_free(buddy_cache, b->buddy); 350 nvgpu_kmem_cache_free(a->buddy_cache, b->buddy);
352 kmem_cache_free(buddy_cache, b); 351 nvgpu_kmem_cache_free(a->buddy_cache, b);
353} 352}
354 353
355/* 354/*
@@ -371,7 +370,7 @@ static int balloc_split_buddy(struct nvgpu_buddy_allocator *a,
371 370
372 right = balloc_new_buddy(a, b, b->start + half, b->order - 1); 371 right = balloc_new_buddy(a, b, b->start + half, b->order - 1);
373 if (!right) { 372 if (!right) {
374 kmem_cache_free(buddy_cache, left); 373 nvgpu_kmem_cache_free(a->buddy_cache, left);
375 return -ENOMEM; 374 return -ENOMEM;
376 } 375 }
377 376
@@ -783,7 +782,7 @@ err_and_cleanup:
783 782
784 __balloc_buddy_list_rem(a, bud); 783 __balloc_buddy_list_rem(a, bud);
785 balloc_free_buddy(a, bud->start); 784 balloc_free_buddy(a, bud->start);
786 kmem_cache_free(buddy_cache, bud); 785 nvgpu_kmem_cache_free(a->buddy_cache, bud);
787 } 786 }
788 787
789 return 0; 788 return 0;
@@ -1307,10 +1306,8 @@ int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
1307 balloc_allocator_align(a); 1306 balloc_allocator_align(a);
1308 balloc_compute_max_order(a); 1307 balloc_compute_max_order(a);
1309 1308
1310 /* Shared buddy kmem_cache for all allocators. */ 1309 a->buddy_cache = nvgpu_kmem_cache_create(g, sizeof(struct nvgpu_buddy));
1311 if (!buddy_cache) 1310 if (!a->buddy_cache) {
1312 buddy_cache = KMEM_CACHE(nvgpu_buddy, 0);
1313 if (!buddy_cache) {
1314 err = -ENOMEM; 1311 err = -ENOMEM;
1315 goto fail; 1312 goto fail;
1316 } 1313 }
@@ -1340,6 +1337,8 @@ int __nvgpu_buddy_allocator_init(struct gk20a *g, struct nvgpu_allocator *__a,
1340 return 0; 1337 return 0;
1341 1338
1342fail: 1339fail:
1340 if (a->buddy_cache)
1341 nvgpu_kmem_cache_destroy(a->buddy_cache);
1343 kfree(a); 1342 kfree(a);
1344 return err; 1343 return err;
1345} 1344}