diff options
Diffstat (limited to 'drivers/gpu/drm/ttm/ttm_page_alloc.c')
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_page_alloc.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 09874d695188..025c429050c0 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c | |||
@@ -297,11 +297,12 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, | |||
297 | * | 297 | * |
298 | * @pool: to free the pages from | 298 | * @pool: to free the pages from |
299 | * @free_all: If set to true will free all pages in pool | 299 | * @free_all: If set to true will free all pages in pool |
300 | * @gfp: GFP flags. | 300 | * @use_static: Safe to use static buffer |
301 | **/ | 301 | **/ |
302 | static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, | 302 | static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, |
303 | gfp_t gfp) | 303 | bool use_static) |
304 | { | 304 | { |
305 | static struct page *static_buf[NUM_PAGES_TO_ALLOC]; | ||
305 | unsigned long irq_flags; | 306 | unsigned long irq_flags; |
306 | struct page *p; | 307 | struct page *p; |
307 | struct page **pages_to_free; | 308 | struct page **pages_to_free; |
@@ -311,7 +312,11 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, | |||
311 | if (NUM_PAGES_TO_ALLOC < nr_free) | 312 | if (NUM_PAGES_TO_ALLOC < nr_free) |
312 | npages_to_free = NUM_PAGES_TO_ALLOC; | 313 | npages_to_free = NUM_PAGES_TO_ALLOC; |
313 | 314 | ||
314 | pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), gfp); | 315 | if (use_static) |
316 | pages_to_free = static_buf; | ||
317 | else | ||
318 | pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), | ||
319 | GFP_KERNEL); | ||
315 | if (!pages_to_free) { | 320 | if (!pages_to_free) { |
316 | pr_err("Failed to allocate memory for pool free operation\n"); | 321 | pr_err("Failed to allocate memory for pool free operation\n"); |
317 | return 0; | 322 | return 0; |
@@ -374,7 +379,8 @@ restart: | |||
374 | if (freed_pages) | 379 | if (freed_pages) |
375 | ttm_pages_put(pages_to_free, freed_pages); | 380 | ttm_pages_put(pages_to_free, freed_pages); |
376 | out: | 381 | out: |
377 | kfree(pages_to_free); | 382 | if (pages_to_free != static_buf) |
383 | kfree(pages_to_free); | ||
378 | return nr_free; | 384 | return nr_free; |
379 | } | 385 | } |
380 | 386 | ||
@@ -383,8 +389,6 @@ out: | |||
383 | * | 389 | * |
384 | * XXX: (dchinner) Deadlock warning! | 390 | * XXX: (dchinner) Deadlock warning! |
385 | * | 391 | * |
386 | * We need to pass sc->gfp_mask to ttm_page_pool_free(). | ||
387 | * | ||
388 | * This code is crying out for a shrinker per pool.... | 392 | * This code is crying out for a shrinker per pool.... |
389 | */ | 393 | */ |
390 | static unsigned long | 394 | static unsigned long |
@@ -407,8 +411,8 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) | |||
407 | if (shrink_pages == 0) | 411 | if (shrink_pages == 0) |
408 | break; | 412 | break; |
409 | pool = &_manager->pools[(i + pool_offset)%NUM_POOLS]; | 413 | pool = &_manager->pools[(i + pool_offset)%NUM_POOLS]; |
410 | shrink_pages = ttm_page_pool_free(pool, nr_free, | 414 | /* OK to use static buffer since global mutex is held. */ |
411 | sc->gfp_mask); | 415 | shrink_pages = ttm_page_pool_free(pool, nr_free, true); |
412 | freed += nr_free - shrink_pages; | 416 | freed += nr_free - shrink_pages; |
413 | } | 417 | } |
414 | mutex_unlock(&lock); | 418 | mutex_unlock(&lock); |
@@ -710,7 +714,7 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags, | |||
710 | } | 714 | } |
711 | spin_unlock_irqrestore(&pool->lock, irq_flags); | 715 | spin_unlock_irqrestore(&pool->lock, irq_flags); |
712 | if (npages) | 716 | if (npages) |
713 | ttm_page_pool_free(pool, npages, GFP_KERNEL); | 717 | ttm_page_pool_free(pool, npages, false); |
714 | } | 718 | } |
715 | 719 | ||
716 | /* | 720 | /* |
@@ -849,9 +853,9 @@ void ttm_page_alloc_fini(void) | |||
849 | pr_info("Finalizing pool allocator\n"); | 853 | pr_info("Finalizing pool allocator\n"); |
850 | ttm_pool_mm_shrink_fini(_manager); | 854 | ttm_pool_mm_shrink_fini(_manager); |
851 | 855 | ||
856 | /* OK to use static buffer since global mutex is no longer used. */ | ||
852 | for (i = 0; i < NUM_POOLS; ++i) | 857 | for (i = 0; i < NUM_POOLS; ++i) |
853 | ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, | 858 | ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, true); |
854 | GFP_KERNEL); | ||
855 | 859 | ||
856 | kobject_put(&_manager->kobj); | 860 | kobject_put(&_manager->kobj); |
857 | _manager = NULL; | 861 | _manager = NULL; |