|
@@ -411,11 +411,12 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
|
|
|
*
|
|
|
* @pool: to free the pages from
|
|
|
* @nr_free: If set to true will free all pages in pool
|
|
|
- * @gfp: GFP flags.
|
|
|
+ * @use_static: Safe to use static buffer
|
|
|
**/
|
|
|
static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
|
|
|
- gfp_t gfp)
|
|
|
+ bool use_static)
|
|
|
{
|
|
|
+ static struct page *static_buf[NUM_PAGES_TO_ALLOC];
|
|
|
unsigned long irq_flags;
|
|
|
struct dma_page *dma_p, *tmp;
|
|
|
struct page **pages_to_free;
|
|
@@ -432,7 +433,11 @@ static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
|
|
|
npages_to_free, nr_free);
|
|
|
}
|
|
|
#endif
|
|
|
- pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), gfp);
|
|
|
+ if (use_static)
|
|
|
+ pages_to_free = static_buf;
|
|
|
+ else
|
|
|
+ pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
|
|
|
+ GFP_KERNEL);
|
|
|
|
|
|
if (!pages_to_free) {
|
|
|
pr_err("%s: Failed to allocate memory for pool free operation\n",
|
|
@@ -502,7 +507,8 @@ restart:
|
|
|
if (freed_pages)
|
|
|
ttm_dma_pages_put(pool, &d_pages, pages_to_free, freed_pages);
|
|
|
out:
|
|
|
- kfree(pages_to_free);
|
|
|
+ if (pages_to_free != static_buf)
|
|
|
+ kfree(pages_to_free);
|
|
|
return nr_free;
|
|
|
}
|
|
|
|
|
@@ -531,7 +537,8 @@ static void ttm_dma_free_pool(struct device *dev, enum pool_type type)
|
|
|
if (pool->type != type)
|
|
|
continue;
|
|
|
/* Takes a spinlock.. */
|
|
|
- ttm_dma_page_pool_free(pool, FREE_ALL_PAGES, GFP_KERNEL);
|
|
|
+ /* OK to use static buffer since global mutex is held. */
|
|
|
+ ttm_dma_page_pool_free(pool, FREE_ALL_PAGES, true);
|
|
|
WARN_ON(((pool->npages_in_use + pool->npages_free) != 0));
|
|
|
/* This code path is called after _all_ references to the
|
|
|
* struct device has been dropped - so nobody should be
|
|
@@ -986,7 +993,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
|
|
|
|
|
|
/* shrink pool if necessary (only on !is_cached pools)*/
|
|
|
if (npages)
|
|
|
- ttm_dma_page_pool_free(pool, npages, GFP_KERNEL);
|
|
|
+ ttm_dma_page_pool_free(pool, npages, false);
|
|
|
ttm->state = tt_unpopulated;
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
|
|
@@ -996,8 +1003,6 @@ EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
|
|
|
*
|
|
|
* XXX: (dchinner) Deadlock warning!
|
|
|
*
|
|
|
- * We need to pass sc->gfp_mask to ttm_dma_page_pool_free().
|
|
|
- *
|
|
|
* I'm getting sadder as I hear more pathetical whimpers about needing per-pool
|
|
|
* shrinkers
|
|
|
*/
|
|
@@ -1030,8 +1035,8 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
|
|
|
if (++idx < pool_offset)
|
|
|
continue;
|
|
|
nr_free = shrink_pages;
|
|
|
- shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free,
|
|
|
- sc->gfp_mask);
|
|
|
+ /* OK to use static buffer since global mutex is held. */
|
|
|
+ shrink_pages = ttm_dma_page_pool_free(p->pool, nr_free, true);
|
|
|
freed += nr_free - shrink_pages;
|
|
|
|
|
|
pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
|