提交 735c4664 编写于 作者: C Christian König

drm/ttm: optimize pool allocations a bit v2

If we got a page pool use it as much as possible.

If we can't get more pages from the pool allocate as much as possible.

Only if that still doesn't work reduce the order and try again.

v2: minor cleanups
Signed-off-by: NChristian König <christian.koenig@amd.com>
Reviewed-by: NFelix Kuehling <Felix.Kuehling@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221107195808.1873-1-christian.koenig@amd.com
上级 611fc22c
...@@ -344,6 +344,28 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p) ...@@ -344,6 +344,28 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)
return p->private; return p->private;
} }
/* Called when we got a page, either from a pool or newly allocated */
static int ttm_pool_page_allocated(struct ttm_pool *pool, unsigned int order,
struct page *p, dma_addr_t **dma_addr,
unsigned long *num_pages,
struct page ***pages)
{
unsigned int i;
int r;
if (*dma_addr) {
r = ttm_pool_map(pool, order, p, dma_addr);
if (r)
return r;
}
*num_pages -= 1 << order;
for (i = 1 << order; i; --i, ++(*pages), ++p)
**pages = p;
return 0;
}
/** /**
* ttm_pool_alloc - Fill a ttm_tt object * ttm_pool_alloc - Fill a ttm_tt object
* *
...@@ -385,45 +407,57 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, ...@@ -385,45 +407,57 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
for (order = min_t(unsigned int, MAX_ORDER - 1, __fls(num_pages)); for (order = min_t(unsigned int, MAX_ORDER - 1, __fls(num_pages));
num_pages; num_pages;
order = min_t(unsigned int, order, __fls(num_pages))) { order = min_t(unsigned int, order, __fls(num_pages))) {
bool apply_caching = false;
struct ttm_pool_type *pt; struct ttm_pool_type *pt;
pt = ttm_pool_select_type(pool, tt->caching, order); pt = ttm_pool_select_type(pool, tt->caching, order);
p = pt ? ttm_pool_type_take(pt) : NULL; p = pt ? ttm_pool_type_take(pt) : NULL;
if (p) { if (p) {
apply_caching = true; r = ttm_pool_apply_caching(caching, pages,
} else { tt->caching);
p = ttm_pool_alloc_page(pool, gfp_flags, order); if (r)
if (p && PageHighMem(p)) goto error_free_page;
apply_caching = true;
}
if (!p) { do {
if (order) { r = ttm_pool_page_allocated(pool, order, p,
--order; &dma_addr,
continue; &num_pages,
} &pages);
r = -ENOMEM; if (r)
goto error_free_all; goto error_free_page;
if (num_pages < (1 << order))
break;
p = ttm_pool_type_take(pt);
} while (p);
caching = pages;
} }
if (apply_caching) { while (num_pages >= (1 << order) &&
(p = ttm_pool_alloc_page(pool, gfp_flags, order))) {
if (PageHighMem(p)) {
r = ttm_pool_apply_caching(caching, pages, r = ttm_pool_apply_caching(caching, pages,
tt->caching); tt->caching);
if (r) if (r)
goto error_free_page; goto error_free_page;
caching = pages + (1 << order);
} }
r = ttm_pool_page_allocated(pool, order, p, &dma_addr,
if (dma_addr) { &num_pages, &pages);
r = ttm_pool_map(pool, order, p, &dma_addr);
if (r) if (r)
goto error_free_page; goto error_free_page;
if (PageHighMem(p))
caching = pages;
} }
num_pages -= 1 << order; if (!p) {
for (i = 1 << order; i; --i) if (order) {
*(pages++) = p++; --order;
continue;
}
r = -ENOMEM;
goto error_free_all;
}
} }
r = ttm_pool_apply_caching(caching, pages, tt->caching); r = ttm_pool_apply_caching(caching, pages, tt->caching);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册