drm/ttm: remove unsued options from ttm_mem_global_alloc_page
Subsystems (4)
PATCH 1/9 drm/ttm: remove unsued options from ttm_mem_global_alloc_page
From: Christian König <[email protected]>
Nobody is actually using that, remove it.
--- drivers/gpu/drm/ttm/ttm_memory.c | 6 ++---- drivers/gpu/drm/ttm/ttm_page_alloc.c | 3 +-- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 3 +-- include/drm/ttm/ttm_memory.h | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +2 -4
@@ -546,8 +546,7 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible) +struct page *page) {struct ttm_mem_zone *zone =NULL ;
@@ -564,8 +563,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , false, false); }void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page)
drivers/gpu/drm/ttm/ttm_page_alloc.c +1 -2
@@ -882,8 +882,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -2
@@ -902,8 +902,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
include/drm/ttm/ttm_memory.h +1 -2
@@ -150,8 +150,7 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible); +struct page *page);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page);extern size_t ttm_round_pot (size_t size);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 1506082405-1556-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
PATCH 2/9 drm/ttm: add support for different pool sizes
From: Christian König <[email protected]>
Correctly handle different page sizes in the memory accounting.
--- drivers/gpu/drm/ttm/ttm_memory.c | 10 +++++----- drivers/gpu/drm/ttm/ttm_page_alloc.c | 5 +++-- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 7 ++++--- include/drm/ttm/ttm_memory.h | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +5 -5
@@ -546,7 +546,7 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page) +struct page *page,uint64_t size) {struct ttm_mem_zone *zone =NULL ;
@@ -563,10 +563,11 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , false, false); +return ttm_mem_global_alloc_zone (glob, zone, size, false, false); } -void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page) +void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page, +uint64_t size) {struct ttm_mem_zone *zone =NULL ;
@@ -577,10 +578,9 @@ void ttm_mem_global_free_page(struct ttm_mem_global *glob, struct page *page)if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -ttm_mem_global_free_zone (glob, zone,PAGE_SIZE ); +ttm_mem_global_free_zone (glob, zone, size); } -size_t ttm_round_pot (size_t size) {if ((size & (size -1 )) ==0 )
drivers/gpu/drm/ttm/ttm_page_alloc.c +3 -2
@@ -882,7 +882,8 @@ int ttm_pool_populate(struct ttm_tt *ttm)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], +PAGE_SIZE );if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;
@@ -909,7 +910,7 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)for (i =0 ; i < ttm->num_pages; ++i) {if (ttm->pages[i]) {ttm_mem_global_free_page (ttm->glob->mem_glob, - ttm->pages[i]); + ttm->pages[i],PAGE_SIZE );ttm_put_pages (&ttm->pages[i],1 , ttm->page_flags, ttm->caching_state);
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -3
@@ -902,7 +902,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], + pool->size);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;
@@ -967,13 +968,13 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)if (is_cached) {list_for_each_entry_safe (d_page, next, &ttm_dma->pages_list, page_list) {ttm_mem_global_free_page (ttm->glob->mem_glob, - d_page->p); + d_page->p, pool->size);ttm_dma_page_put (pool, d_page); } }else {for (i =0 ; i < count; i++) {ttm_mem_global_free_page (ttm->glob->mem_glob, - ttm->pages[i]); + ttm->pages[i], pool->size); } }
include/drm/ttm/ttm_memory.h +2 -2
@@ -150,9 +150,9 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page); +struct page *page,uint64_t size);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob, -struct page *page); +struct page *page,uint64_t size);extern size_t ttm_round_pot (size_t size);extern uint64_t ttm_get_kernel_zone_memory_size (struct ttm_mem_global *glob);#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/9 drm/ttm: add transparent huge page support for DMA allocations v2
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Try to allocate huge pages when it makes sense.
v2: fix comment and use ifdef
--- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 217 ++++++++++++++++++++++++------- 1 file changed, 169 insertions(+), 48 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +169 -48
@@ -60,21 +60,25 @@#define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))#define SMALL_ALLOCATION 4#define FREE_ALL_PAGES (~0U) +#define VADDR_FLAG_HUGE_POOL 1ULenum pool_type {IS_UNDEFINED =0 ,IS_WC =1 <<1 ,IS_UC =1 <<2 ,IS_CACHED =1 <<3 , -IS_DMA32 =1 <<4 +IS_DMA32 =1 <<4 , +IS_HUGE =1 <<5 };/* -* The pool structure. There are usually six pools: +* The pool structure. There are up to nine pools: * - generic (not restricted to DMA32): * - write combined, uncached, cached. * - dma32 (up to 2^32 - so up 4GB): * - write combined, uncached, cached. +* - huge (not restricted to DMA32): +* - write combined, uncached, cached. * for each 'struct device'. The 'cached' is for pages that are actively used. * The other ones can be shrunk by the shrinker API if neccessary. * @pools: The 'struct device->dma_pools' link.
@@ -114,13 +118,14 @@ struct dma_pool {* The accounting page keeping track of the allocated page along with * the DMA address. * @page_list: The link to the 'page_list' in 'struct dma_pool'. -* @vaddr: The virtual address of the page +* @vaddr: The virtual address of the page and a flag if the page belongs to a +* huge pool * @dma: The bus address of the page. If the page is not allocated * via the DMA API, it will be -1. */ struct dma_page {struct list_head page_list; -void *vaddr; +unsigned long vaddr;struct page *p;dma_addr_t dma; };
@@ -319,7 +324,8 @@ static int ttm_set_pages_caching(struct dma_pool *pool,static void __ttm_dma_free_page (struct dma_pool *pool,struct dma_page *d_page) {dma_addr_t dma = d_page->dma; -dma_free_coherent (pool->dev, pool->size, d_page->vaddr, dma); + d_page->vaddr &= ~VADDR_FLAG_HUGE_POOL ; +dma_free_coherent (pool->dev, pool->size, (void *)d_page->vaddr, dma);kfree (d_page); d_page =NULL ;
@@ -327,19 +333,22 @@ static void __ttm_dma_free_page(struct dma_pool *pool, struct dma_page *d_page)static struct dma_page *__ttm_dma_alloc_page (struct dma_pool *pool) {struct dma_page *d_page; +void *vaddr; d_page =kmalloc (sizeof (struct dma_page ),GFP_KERNEL );if (!d_page)return NULL ; - d_page->vaddr =dma_alloc_coherent (pool->dev, pool->size, - &d_page->dma, - pool->gfp_flags); -if (d_page->vaddr) { -if (is_vmalloc_addr (d_page->vaddr)) - d_page->p =vmalloc_to_page (d_page->vaddr); + vaddr =dma_alloc_coherent (pool->dev, pool->size, &d_page->dma, + pool->gfp_flags); +if (vaddr) { +if (is_vmalloc_addr (vaddr)) + d_page->p =vmalloc_to_page (vaddr);else - d_page->p =virt_to_page (d_page->vaddr); + d_page->p =virt_to_page (vaddr); + d_page->vaddr = (unsigned long )vaddr; +if (pool->type &IS_HUGE ) + d_page->vaddr |=VADDR_FLAG_HUGE_POOL ; }else {kfree (d_page); d_page =NULL ;
@@ -371,11 +380,40 @@ static void ttm_pool_update_free_locked(struct dma_pool *pool, }/* set memory back to wb and free the pages. */ +static void ttm_dma_page_put (struct dma_pool *pool,struct dma_page *d_page) +{ +struct page *page = d_page->p; +unsigned i, num_pages; +int ret; + +/* Don't set WB on WB page pool. */ +if (!(pool->type &IS_CACHED )) { + num_pages = pool->size /PAGE_SIZE ; +for (i =0 ; i < num_pages; ++i, ++page) { + ret =set_pages_array_wb (&page,1 ); +if (ret) { +pr_err ("%s: Failed to set %d pages to wb!\n" , + pool->dev_name,1 ); + } + } + } + +list_del (&d_page->page_list); +__ttm_dma_free_page (pool, d_page); +} +static void ttm_dma_pages_put (struct dma_pool *pool,struct list_head *d_pages,struct page *pages[],unsigned npages) {struct dma_page *d_page, *tmp; +if (pool->type &IS_HUGE ) { +list_for_each_entry_safe (d_page, tmp, d_pages, page_list) +ttm_dma_page_put (pool, d_page); + +return ; + } +/* Don't set WB on WB page pool. */ if (npages && !(pool->type &IS_CACHED ) &&set_pages_array_wb (pages, npages))
@@ -388,17 +426,6 @@ static void ttm_dma_pages_put(struct dma_pool *pool, struct list_head *d_pages, } } -static void ttm_dma_page_put (struct dma_pool *pool,struct dma_page *d_page) -{ -/* Don't set WB on WB page pool. */ -if (!(pool->type &IS_CACHED ) &&set_pages_array_wb (&d_page->p,1 )) -pr_err ("%s: Failed to set %d pages to wb!\n" , - pool->dev_name,1 ); - -list_del (&d_page->page_list); -__ttm_dma_free_page (pool, d_page); -} -/* * Free pages from pool. *
@@ -567,8 +594,8 @@ static int ttm_dma_pool_match(struct device *dev, void *res, void *match_data)static struct dma_pool *ttm_dma_pool_init (struct device *dev,gfp_t flags,enum pool_type type) { -char *n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"unknown" ,}; -enum pool_type t[] = {IS_WC ,IS_UC ,IS_CACHED ,IS_DMA32 ,IS_UNDEFINED }; +const char *n[] = {"wc" ,"uc" ,"cached" ," dma32" ,"huge" }; +enum pool_type t[] = {IS_WC ,IS_UC ,IS_CACHED ,IS_DMA32 ,IS_HUGE };struct device_pools *sec_pool =NULL ;struct dma_pool *pool =NULL , **ptr;unsigned i;
@@ -605,11 +632,18 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags, pool->npages_free = pool->npages_in_use =0 ; pool->nfrees =0 ; pool->gfp_flags = flags; - pool->size =PAGE_SIZE ; + if (type & IS_HUGE) +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + pool->size =HPAGE_PMD_SIZE ; +#else +BUG (); +#endif + else + pool->size = PAGE_SIZE; pool->type = type; pool->nrefills =0 ; p = pool->name; -for (i =0 ; i <5 ; i++) { +for (i =0 ; i <ARRAY_SIZE (t); i++) {if (type & t[i]) { p +=snprintf (p,sizeof (pool->name) - (p - pool->name),"%s" , n[i]);
@@ -713,7 +747,7 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool,struct dma_page *dma_p;struct page *p;int r =0 ; -unsigned i, cpages; +unsigned i, j, npages, cpages;unsigned max_cpages =min (count, (unsigned )(PAGE_SIZE /sizeof (struct page *)));
@@ -751,28 +785,32 @@ static int ttm_dma_pool_alloc_new_pages(struct dma_pool *pool, goto out; } p = dma_p->p; +list_add (&dma_p->page_list, d_pages); +#ifdef CONFIG_HIGHMEM /* gfp flags of highmem page should never be dma32 so we * we should be fine in such case */ - if (!PageHighMem(p)) +if (PageHighMem (p)) +continue ;#endif - { - caching_array[cpages++] = p; + + npages = pool->size /PAGE_SIZE ; +for (j =0 ; j < npages; ++j) { + caching_array[cpages++] = p + j;if (cpages == max_cpages) {/* Note: Cannot hold the spinlock */ r =ttm_set_pages_caching (pool, caching_array, - cpages); + cpages);if (r) {ttm_dma_handle_caching_state_failure ( - pool, d_pages, caching_array, - cpages); + pool, d_pages, caching_array, + cpages); goto out; } cpages =0 ; } } -list_add (&dma_p->page_list, d_pages); }if (cpages) {
@@ -860,6 +898,26 @@ static int ttm_dma_pool_get_pages(struct dma_pool *pool,return r; } +static gfp_t ttm_dma_pool_gfp_flags (struct ttm_dma_tt *ttm_dma,bool huge) +{ +struct ttm_tt *ttm = &ttm_dma->ttm; +gfp_t gfp_flags; + +if (ttm->page_flags &TTM_PAGE_FLAG_DMA32 ) + gfp_flags =GFP_USER |GFP_DMA32 ; +else + gfp_flags =GFP_HIGHUSER ; +if (ttm->page_flags &TTM_PAGE_FLAG_ZERO_ALLOC ) + gfp_flags |= __GFP_ZERO; + +if (huge) { + gfp_flags |=GFP_TRANSHUGE ; + gfp_flags &= ~__GFP_MOVABLE; + } + +return gfp_flags; +} +/* * On success pages list will hold count number of correctly * cached pages. On failure will hold the negative return value (-ENOMEM, etc).
@@ -868,6 +926,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev) {struct ttm_tt *ttm = &ttm_dma->ttm;struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; +unsigned long num_pages = ttm->num_pages;struct dma_pool *pool;enum pool_type type;unsigned i;
@@ -876,26 +935,61 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)if (ttm->state != tt_unpopulated)return 0 ; +INIT_LIST_HEAD (&ttm_dma->pages_list); + i =0 ; + type =ttm_to_type (ttm->page_flags, ttm->caching_state); - pool =ttm_dma_find_pool (dev, type); + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +if (ttm->page_flags &TTM_PAGE_FLAG_DMA32 ) + goto skip_huge; + + pool =ttm_dma_find_pool (dev, type |IS_HUGE );if (!pool) { -gfp_t gfp_flags; +gfp_t gfp_flags =ttm_dma_pool_gfp_flags (ttm_dma, true); -if (ttm->page_flags &TTM_PAGE_FLAG_DMA32 ) - gfp_flags =GFP_USER |GFP_DMA32 ; -else - gfp_flags =GFP_HIGHUSER ; -if (ttm->page_flags &TTM_PAGE_FLAG_ZERO_ALLOC ) - gfp_flags |= __GFP_ZERO; + pool =ttm_dma_pool_init (dev, gfp_flags, type |IS_HUGE ); +if (IS_ERR_OR_NULL (pool)) + goto skip_huge; + } - pool =ttm_dma_pool_init (dev, gfp_flags, type); -if (IS_ERR_OR_NULL (pool)) { +while (num_pages >=HPAGE_PMD_NR ) { +unsigned j; + + ret =ttm_dma_pool_get_pages (pool, ttm_dma, i); +if (ret !=0 ) +break ; + + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], + pool->size); +if (unlikely (ret !=0 )) { +ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ; } + +for (j = i +1 ; j < (i +HPAGE_PMD_NR ); ++j) { + ttm->pages[j] = ttm->pages[j -1 ] +1 ; + ttm_dma->dma_address[j] = ttm_dma->dma_address[j -1 ] + +PAGE_SIZE ; + } + + i +=HPAGE_PMD_NR ; + num_pages -=HPAGE_PMD_NR ; } -INIT_LIST_HEAD (&ttm_dma->pages_list); -for (i =0 ; i < ttm->num_pages; ++i) { +skip_huge: +#endif + + pool =ttm_dma_find_pool (dev, type); +if (!pool) { +gfp_t gfp_flags =ttm_dma_pool_gfp_flags (ttm_dma, false); + + pool =ttm_dma_pool_init (dev, gfp_flags, type); +if (IS_ERR_OR_NULL (pool)) +return -ENOMEM ; + } + +while (num_pages) { ret =ttm_dma_pool_get_pages (pool, ttm_dma, i);if (ret !=0 ) {ttm_dma_unpopulate (ttm_dma, dev);
@@ -908,6 +1002,9 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ; } + + ++i; + --num_pages; }if (unlikely (ttm->page_flags &TTM_PAGE_FLAG_SWAPPED )) {
@@ -931,10 +1028,33 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)struct dma_page *d_page, *next;enum pool_type type;bool is_cached = false; -unsigned count =0 , i, npages =0 ; +unsigned count, i, npages =0 ;unsigned long irq_flags; type =ttm_to_type (ttm->page_flags, ttm->caching_state); + +#ifdef CONFIG_TRANSPARENT_HUGEPAGE + pool =ttm_dma_find_pool (dev, type |IS_HUGE ); +if (pool) { + count =0 ; +list_for_each_entry_safe (d_page, next, &ttm_dma->pages_list, + page_list) { +if (!(d_page->vaddr &VADDR_FLAG_HUGE_POOL )) +continue ; + + count++; +ttm_mem_global_free_page (ttm->glob->mem_glob, + d_page->p, pool->size); +ttm_dma_page_put (pool, d_page); + } + +spin_lock_irqsave (&pool->lock, irq_flags); + pool->npages_in_use -= count; + pool->nfrees += count; +spin_unlock_irqrestore (&pool->lock, irq_flags); + } +#endif + pool =ttm_dma_find_pool (dev, type);if (!pool)return ;
@@ -943,6 +1063,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev) ttm_to_type(ttm->page_flags, tt_cached)) == pool);/* make sure pages array match list and count number of pages */ + count =0 ;list_for_each_entry (d_page, &ttm_dma->pages_list, page_list) { ttm->pages[count] = d_page->p; count++;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/9 drm/ttm: allocate/free multiple pages in a single call
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Totally surprisingly this is more efficient than doing it page by page.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +14 -15
@@ -873,15 +873,14 @@ int ttm_pool_populate(struct ttm_tt *ttm)if (ttm->state != tt_unpopulated)return 0 ; -for (i =0 ; i < ttm->num_pages; ++i) { - ret =ttm_get_pages (&ttm->pages[i],1 , - ttm->page_flags, - ttm->caching_state); -if (ret !=0 ) { -ttm_pool_unpopulate (ttm); -return -ENOMEM ; - } + ret =ttm_get_pages (ttm->pages, ttm->num_pages, ttm->page_flags, + ttm->caching_state); +if (unlikely (ret !=0 )) { +ttm_pool_unpopulate (ttm); +return ret; + } +for (i =0 ; i < ttm->num_pages; ++i) { ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i],PAGE_SIZE );if (unlikely (ret !=0 )) {
@@ -908,14 +907,14 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)unsigned i;for (i =0 ; i < ttm->num_pages; ++i) { -if (ttm->pages[i]) { -ttm_mem_global_free_page (ttm->glob->mem_glob, - ttm->pages[i],PAGE_SIZE ); -ttm_put_pages (&ttm->pages[i],1 , - ttm->page_flags, - ttm->caching_state); - } +if (!ttm->pages[i]) +continue ; + +ttm_mem_global_free_page (ttm->glob->mem_glob, ttm->pages[i], +PAGE_SIZE ); } +ttm_put_pages (ttm->pages, ttm->num_pages, ttm->page_flags, + ttm->caching_state); ttm->state = tt_unpopulated; }EXPORT_SYMBOL (ttm_pool_unpopulate);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/9 drm/ttm: move more logic into ttm_page_pool_get_pages
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Make it easier to add huge page pool.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 98 +++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 46 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +52 -46
@@ -627,19 +627,20 @@ static void ttm_page_pool_fill_locked(struct ttm_page_pool *pool, }/** -* Cut 'count' number of pages from the pool and put them on the return list. +* Allocate pages from the pool and put them on the return list. * -* @return count of pages still required to fulfill the request. +* @return zero for success or negative error code. */ -static unsigned ttm_page_pool_get_pages (struct ttm_page_pool *pool, -struct list_head *pages, -int ttm_flags, -enum ttm_caching_state cstate, -unsigned count) +static int ttm_page_pool_get_pages (struct ttm_page_pool *pool, +struct list_head *pages, +int ttm_flags, +enum ttm_caching_state cstate, +unsigned count) {unsigned long irq_flags;struct list_head *p;unsigned i; +int r =0 ;spin_lock_irqsave (&pool->lock, irq_flags);ttm_page_pool_fill_locked (pool, ttm_flags, cstate, count, &irq_flags);
@@ -672,7 +673,35 @@ static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool, count =0 ; out:spin_unlock_irqrestore (&pool->lock, irq_flags); -return count; + +/* clear the pages coming from the pool if requested */ +if (ttm_flags &TTM_PAGE_FLAG_ZERO_ALLOC ) { +struct page *page; + +list_for_each_entry (page, pages, lru) { +if (PageHighMem (page)) +clear_highpage (page); +else +clear_page (page_address (page)); + } + } + +/* If pool didn't have enough pages allocate new one. */ +if (count) { +gfp_t gfp_flags = pool->gfp_flags; + +/* set zero flag for page allocation if required */ +if (ttm_flags &TTM_PAGE_FLAG_ZERO_ALLOC ) + gfp_flags |= __GFP_ZERO; + +/* ttm_alloc_new_pages doesn't reference pool so we can run +* multiple requests in parallel. +**/ + r =ttm_alloc_new_pages (pages, gfp_flags, ttm_flags, cstate, + count); + } + +return r; }/* Put all pages in pages list to correct pool to wait for reuse */
@@ -742,18 +771,18 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,struct ttm_page_pool *pool =ttm_get_pool (flags, cstate);struct list_head plist;struct page *p =NULL ; -gfp_t gfp_flags =GFP_USER ;unsigned count;int r; -/* set zero flag for page allocation if required */ -if (flags &TTM_PAGE_FLAG_ZERO_ALLOC ) - gfp_flags |= __GFP_ZERO; -/* No pool for cached pages */ if (pool ==NULL ) { +gfp_t gfp_flags =GFP_USER ;unsigned i, j; +/* set zero flag for page allocation if required */ +if (flags &TTM_PAGE_FLAG_ZERO_ALLOC ) + gfp_flags |= __GFP_ZERO; +if (flags &TTM_PAGE_FLAG_DMA32 ) gfp_flags |=GFP_DMA32 ;else
@@ -791,44 +820,21 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,return 0 ; } -/* combine zero flag to pool flags */ - gfp_flags |= pool->gfp_flags; -/* First we take pages from the pool */ INIT_LIST_HEAD (&plist); - npages =ttm_page_pool_get_pages (pool, &plist, flags, cstate, npages); + r =ttm_page_pool_get_pages (pool, &plist, flags, cstate, npages); + count =0 ; -list_for_each_entry (p, &plist, lru) { +list_for_each_entry (p, &plist, lru) pages[count++] = p; - } - -/* clear the pages coming from the pool if requested */ -if (flags &TTM_PAGE_FLAG_ZERO_ALLOC ) { -list_for_each_entry (p, &plist, lru) { -if (PageHighMem (p)) -clear_highpage (p); -else -clear_page (page_address (p)); - } - } -/* If pool didn't have enough pages allocate new one. */ -if (npages >0 ) { -/* ttm_alloc_new_pages doesn't reference pool so we can run -* multiple requests in parallel. -**/ -INIT_LIST_HEAD (&plist); - r =ttm_alloc_new_pages (&plist, gfp_flags, flags, cstate, npages); -list_for_each_entry (p, &plist, lru) { - pages[count++] = p; - } -if (r) { -/* If there is any pages in the list put them back to -* the pool. */ -pr_err ("Failed to allocate extra pages for large request\n" ); -ttm_put_pages (pages, count, flags, cstate); -return r; - } +if (r) { +/* If there is any pages in the list put them back to +* the pool. +*/ +pr_err ("Failed to allocate extra pages for large request\n" ); +ttm_put_pages (pages, count, flags, cstate); +return r; }return 0 ;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 9/9 drm/amdgpu: add VM support for huge pages
In reply to a message not in the archiveFrom: Christian König <[email protected]>
Convert GTT mappings into linear ones for huge page handling.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +21 -3
@@ -1732,6 +1732,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, } do { + dma_addr_t *dma_addr = NULL; uint64_t max_entries; uint64_t addr, last;
@@ -1745,15 +1746,32 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, }if (pages_addr) { +uint64_t count; + max_entries =min (max_entries,16ull *1024ull ); - addr =0 ; +for (count =1 ; count < max_entries; ++count) { +uint64_t idx = pfn + count; + +if (pages_addr[idx] != + (pages_addr[idx -1 ] +PAGE_SIZE )) +break ; + } + +if (count <64 ) { + addr = pfn <<PAGE_SHIFT ; + dma_addr = pages_addr; + }else { + addr = pages_addr[pfn]; + max_entries = count; + } + }else if (flags &AMDGPU_PTE_VALID ) { addr += adev->vm_manager.vram_base_offset; + addr += pfn <<PAGE_SHIFT ; } - addr += pfn <<PAGE_SHIFT ; last =min ((uint64_t )mapping->last, start + max_entries -1 ); - r =amdgpu_vm_bo_update_mapping (adev, exclusive, pages_addr, vm, + r =amdgpu_vm_bo_update_mapping (adev, exclusive, dma_addr, vm, start, last, flags, addr, fence);if (r)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1506082405-1556-9-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Re: [PATCH 9/9] drm/amdgpu: add VM support for huge pages
Quoted 28 lines · Christian König
From: Christian König <[email protected]>
Convert GTT mappings into linear ones for huge page handling.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-0@@ -1732,6 +1732,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, } do { + dma_addr_t *dma_addr = NULL; uint64_t max_entries; uint64_t addr, last;@@ -1745,15 +1746,32 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, }if (pages_addr) { +uint64_t count; + max_entries =min (max_entries,16ull *1024ull );
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1760
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9
-1- addr =0 ; +for (count =1 ; count < max_entries; ++count) { +uint64_t idx = pfn + count; + +if (pages_addr[idx] != + (pages_addr[idx -1 ] +PAGE_SIZE )) +break ; + } + +if (count <64 ) {
Is 64 just an arbitrary number? As I understand it, this determines the smallest contiguous allocation you can take advantage of. It would correspond to a 256KB fragment size. I suppose this is a trade-off between TLB efficiency and the number of calls to amdgpu_vm_bo_update_mapping. Any particular reason for picking 64? To me the obvious choices would be 16 (64KB fragment) or 512 (2MB huge page).
I'm not saying it's wrong. It's just kind of arbitrary and could use a comment. Other than that, this patch is Reviewed-by: Felix Kuehling <[email protected]>.
Regards,
Felix
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0+ addr = pfn <<PAGE_SHIFT ; + dma_addr = pages_addr; + }else { + addr = pages_addr[pfn]; + max_entries = count; + } + }else if (flags &AMDGPU_PTE_VALID ) { addr += adev->vm_manager.vram_base_offset;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1777
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2+ addr += pfn <<PAGE_SHIFT ; } - addr += pfn <<PAGE_SHIFT ; last =min ((uint64_t )mapping->last, start + max_entries -1 ); - r =amdgpu_vm_bo_update_mapping (adev, exclusive, pages_addr, vm, + r =amdgpu_vm_bo_update_mapping (adev, exclusive, dma_addr, vm, start, last, flags, addr, fence);if (r)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): f5960158-8775-2ad7-088b-860738700fcf-5C7GfCeVMHo@public.gmane.org
Re: [PATCH 9/9] drm/amdgpu: add VM support for huge pages
Am 23.09.2017 um 01:50 schrieb Felix Kuehling:
Quoted 37 lines · Christian König
Quoted 36 lines
From: Christian König <[email protected]>
Convert GTT mappings into linear ones for huge page handling.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-1@@ -1732,6 +1732,7 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, } do { + dma_addr_t *dma_addr = NULL; uint64_t max_entries; uint64_t addr, last;@@ -1745,15 +1746,32 @@ static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, }if (pages_addr) { +uint64_t count; + max_entries =min (max_entries,16ull *1024ull ); - addr =0 ; +for (count =1 ; count < max_entries; ++count) { +uint64_t idx = pfn + count; + +if (pages_addr[idx] != + (pages_addr[idx -1 ] +PAGE_SIZE )) +break ; + }
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1760
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-0+ +if (count <64 ) {Is 64 just an arbitrary number? As I understand it, this determines the smallest contiguous allocation you can take advantage of. It would correspond to a 256KB fragment size. I suppose this is a trade-off between TLB efficiency and the number of calls to
amdgpu_vm_bo_update_mapping. Any particular reason for picking 64? To me the obvious choices would be 16 (64KB fragment) or 512 (2MB huge page).
Oh, yeah that is jut an arbitrary number I've put in there for testing and forgot about it. Going to fix it.
Quoted 3 lines
I'm not saying it's wrong. It's just kind of arbitrary and could use a comment. Other than that, this patch is Reviewed-by: Felix Kuehling <[email protected]>.
Thanks for the review,
Christian.
Quoted 17 lines
Regards,
FelixQuoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8
-1+ addr = pfn <<PAGE_SHIFT ; + dma_addr = pages_addr; + }else { + addr = pages_addr[pfn]; + max_entries = count; + } + }else if (flags &AMDGPU_PTE_VALID ) { addr += adev->vm_manager.vram_base_offset; + addr += pfn <<PAGE_SHIFT ; } - addr += pfn <<PAGE_SHIFT ;
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_split_mapping(struct amdgpu_device *adev, · line 1777
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1last =min ((uint64_t )mapping->last, start + max_entries -1 ); - r =amdgpu_vm_bo_update_mapping (adev, exclusive, pages_addr, vm, + r =amdgpu_vm_bo_update_mapping (adev, exclusive, dma_addr, vm, start, last, flags, addr, fence);if (r)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Nice patch series. I wasn't expecting that so quickly.
Patches 4-7 change the ttm_page_alloc allocator, which isn't used by amdgpu (as far as I can tell). Did you test those changes with a different driver? I didn't review them in as much detail as the rest. Someone with a stake in them should probably do a proper review. They are Acked-by: Felix Kuehling <[email protected]>
The rest of the series is Reviewed-by: Felix Kuehling <[email protected]>
As a possible follow up, I think ttm_vm_bo.c would need more work to do proper huge-page mappings for CPU access.
Regards,
Felix
Quoted 69 lines · Christian König
From: Christian König <[email protected]>
Nobody is actually using that, remove it.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_memory.c | 6 ++---- drivers/gpu/drm/ttm/ttm_page_alloc.c | 3 +-- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 3 +-- include/drm/ttm/ttm_memory.h | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_memory.c +2
-4@@ -546,8 +546,7 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible) +struct page *page) {struct ttm_mem_zone *zone =NULL ;@@ -564,8 +563,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , false, false); }void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page)drivers/gpu/drm/ttm/ttm_page_alloc.c +1
-2@@ -882,8 +882,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1
-2@@ -902,8 +902,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;include/drm/ttm/ttm_memory.h +0
-0
include/drm/ttm/ttm_memory.h extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 156
Quoted 9 lines
include/drm/ttm/ttm_memory.h +1
-2@@ -150,8 +150,7 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,extern void ttm_mem_global_free (struct ttm_mem_global *glob,uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible); +struct page *page);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page);extern size_t ttm_round_pot (size_t size);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 7cf66416-67c8-7b83-4ca3-db9e300a9664-5C7GfCeVMHo@public.gmane.org
Am 23.09.2017 um 02:01 schrieb Felix Kuehling:
Quoted 1 line
Nice patch series. I wasn't expecting that so quickly.
Actually I'm working on this for a few month now.
Quoted 2 lines
Patches 4-7 change the
ttm_page_allocallocator, which isn't used by amdgpu (as far as I can tell).
Well it is heavily used. See amdgpu_ttm_tt_populate(), if swiotlb is active we use the coherent allocator and if it isn't we assume we have iommu and use the mapping allocator.
That is actually not 100% correct, cause the mapping allocator won't work on pre gfx9 if you have any memory above the 1TB limit. We already had a couple of bug reports about that.
Quoted 10 lines
Did you test those changes with a
different driver? I didn't review them in as much detail as the rest. Someone with a stake in them should probably do a proper review. They are Acked-by: Felix Kuehling <[email protected]>The rest of the series is Reviewed-by: Felix Kuehling <[email protected]>
As a possible follow up, I think
ttm_vm_bo.cwould need more work to do proper huge-page mappings for CPU access.
Correct, actually it looks like the huge page is at some point decomposed.
That is not a problem for GPU huge page access (because we don't look at the compound order there), but it is rather suboptimal for CPU access.
Regards,
Christian.
Quoted 76 lines
Regards,
FelixQuoted 70 lines · Christian König
From: Christian König <[email protected]>
Nobody is actually using that, remove it.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_memory.c | 6 ++---- drivers/gpu/drm/ttm/ttm_page_alloc.c | 3 +-- drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 3 +-- include/drm/ttm/ttm_memory.h | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-)drivers/gpu/drm/ttm/ttm_memory.c +2
-4@@ -546,8 +546,7 @@ int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,EXPORT_SYMBOL (ttm_mem_global_alloc);int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible) +struct page *page) {struct ttm_mem_zone *zone =NULL ;@@ -564,8 +563,7 @@ int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,if (glob->zone_dma32 &&page_to_pfn (page) >0x00100000UL ) zone = glob->zone_kernel;#endif -return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , no_wait, - interruptible); +return ttm_mem_global_alloc_zone (glob, zone,PAGE_SIZE , false, false); }void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page)drivers/gpu/drm/ttm/ttm_page_alloc.c +1
-2@@ -882,8 +882,7 @@ int ttm_pool_populate(struct ttm_tt *ttm)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_pool_unpopulate (ttm);return -ENOMEM ;drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1
-2@@ -902,8 +902,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev)return -ENOMEM ; } - ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i], - false, false); + ret =ttm_mem_global_alloc_page (mem_glob, ttm->pages[i]);if (unlikely (ret !=0 )) {ttm_dma_unpopulate (ttm_dma, dev);return -ENOMEM ;include/drm/ttm/ttm_memory.h +0
-0@@ -150,8 +150,7 @@ extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, extern void ttm_mem_global_free(struct ttm_mem_global *glob,
Quoted 8 lines
include/drm/ttm/ttm_memory.h extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory, · line 156
Quoted 8 lines
include/drm/ttm/ttm_memory.h +1
-2uint64_t amount);extern int ttm_mem_global_alloc_page (struct ttm_mem_global *glob, -struct page *page, -bool no_wait,bool interruptible); +struct page *page);extern void ttm_mem_global_free_page (struct ttm_mem_global *glob,struct page *page);extern size_t ttm_round_pot (size_t size);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/9 drm/ttm: DMA map/unmap compound pages as a whole
In reply to Christian KönigFrom: Christian König <[email protected]>
Instead of mapping them bit by bit map/unmap the whole compound pages as in one call.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +23 -8
@@ -922,16 +922,18 @@ EXPORT_SYMBOL(ttm_pool_unpopulate);#if defined(CONFIG_SWIOTLB ) || defined(CONFIG_INTEL_IOMMU )int ttm_populate_and_map_pages (struct device *dev,struct ttm_dma_tt *tt) { -unsigned i; +unsigned i, j;int r; r =ttm_pool_populate (&tt->ttm);if (r)return r; -for (i =0 ; i < tt->ttm.num_pages; i++) { +for (i =0 ; i < tt->ttm.num_pages; ++i) { +size_t num_pages =1 <<compound_order (tt->ttm.pages[i]); + tt->dma_address[i] =dma_map_page (dev, tt->ttm.pages[i], -0 ,PAGE_SIZE , +0 , num_pages *PAGE_SIZE ,DMA_BIDIRECTIONAL );if (dma_mapping_error (dev, tt->dma_address[i])) {while (i--) {
@@ -942,6 +944,11 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt)ttm_pool_unpopulate (&tt->ttm);return -EFAULT ; } + +for (j =1 ; j < num_pages; ++j) { + tt->dma_address[i +1 ] = tt->dma_address[i] +PAGE_SIZE ; + ++i; + } }return 0 ; }
@@ -950,12 +957,20 @@ EXPORT_SYMBOL(ttm_populate_and_map_pages);void ttm_unmap_and_unpopulate_pages (struct device *dev,struct ttm_dma_tt *tt) {unsigned i; - -for (i =0 ; i < tt->ttm.num_pages; i++) { -if (tt->dma_address[i]) { -dma_unmap_page (dev, tt->dma_address[i], -PAGE_SIZE ,DMA_BIDIRECTIONAL ); + +for (i =0 ; i < tt->ttm.num_pages;) { +size_t num_pages; + +if (!tt->dma_address[i] || !tt->ttm.pages[i]) { + ++i; +continue ; } + + num_pages =1 <<compound_order (tt->ttm.pages[i]); +dma_unmap_page (dev, tt->dma_address[i], num_pages *PAGE_SIZE , +DMA_BIDIRECTIONAL ); + + i += num_pages; }ttm_pool_unpopulate (&tt->ttm); }
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/9 drm/ttm: add transparent huge page support for cached allocations
In reply to Christian KönigFrom: Christian König <[email protected]>
Try to allocate huge pages when it makes sense.
--- drivers/gpu/drm/ttm/ttm_page_alloc.c | 49 ++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 8 deletions(-)
drivers/gpu/drm/ttm/ttm_page_alloc.c +41 -8
@@ -685,12 +685,24 @@ static void ttm_put_pages(struct page **pages, unsigned npages, int flags,if (pool ==NULL ) {/* No pool for this memory type so free the pages */ -for (i =0 ; i < npages; i++) { -if (pages[i]) { -if (page_count (pages[i]) !=1 ) -pr_err ("Erroneous page count. Leaking pages.\n" ); -__free_page (pages[i]); - pages[i] =NULL ; + i =0 ; +while (i < npages) { +unsigned order; + +if (!pages[i]) { + ++i; +continue ; + } + +if (page_count (pages[i]) !=1 ) +pr_err ("Erroneous page count. Leaking pages.\n" ); + order =compound_order (pages[i]); +__free_pages (pages[i], order); + + order =1 << order; +while (order) { + pages[i++] =NULL ; + --order; } }return ;
@@ -740,12 +752,32 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,/* No pool for cached pages */ if (pool ==NULL ) { +unsigned i, j; +if (flags &TTM_PAGE_FLAG_DMA32 ) gfp_flags |=GFP_DMA32 ;else gfp_flags |=GFP_HIGHUSER ; -for (r =0 ; r < npages; ++r) { + i =0 ; +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +while (npages >=HPAGE_PMD_NR ) { +gfp_t huge_flags = gfp_flags; + + huge_flags |=GFP_TRANSHUGE ; + huge_flags &= ~__GFP_MOVABLE; + p =alloc_pages (huge_flags,HPAGE_PMD_ORDER ); +if (!p) +break ; + +for (j =0 ; j <HPAGE_PMD_NR ; ++j) + pages[i++] = p++; + + npages -=HPAGE_PMD_NR ; + } +#endif + +while (npages) { p =alloc_page (gfp_flags);if (!p) {
@@ -753,7 +785,8 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,return -ENOMEM ; } - pages[r] = p; + pages[i++] = p; + --npages; }return 0 ; }
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/9 drm/amdgpu: minor coding style fix
In reply to Christian KönigFrom: Christian König <[email protected]>
Fix two minor 80 char issues.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -2
@@ -2541,7 +2541,8 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)* @adev: amdgpu_device pointer * @fragment_size_default: the default fragment size if it's set auto */ -void amdgpu_vm_set_fragment_size (struct amdgpu_device *adev,uint32_t fragment_size_default) +void amdgpu_vm_set_fragment_size (struct amdgpu_device *adev, +uint32_t fragment_size_default) {if (amdgpu_vm_fragment_size ==-1 ) adev->vm_manager.fragment_size = fragment_size_default;
@@ -2555,7 +2556,8 @@ void amdgpu_vm_set_fragment_size(struct amdgpu_device *adev, uint32_t fragment_s* @adev: amdgpu_device pointer * @vm_size: the default vm size if it's set auto */ -void amdgpu_vm_adjust_size (struct amdgpu_device *adev,uint64_t vm_size,uint32_t fragment_size_default) +void amdgpu_vm_adjust_size (struct amdgpu_device *adev,uint64_t vm_size, +uint32_t fragment_size_default) {/* adjust vm size firstly */ if (amdgpu_vm_size ==-1 )
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel