Message ID | 1511329016-552-2-git-send-email-Hongbo.He@amd.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 2017年11月22日 13:36, Roger He wrote: > Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 > Signed-off-by: Roger He <Hongbo.He@amd.com> > --- > drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 +++++++++++++++++++++++++++++------- > 1 file changed, 34 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c > index 0a0c653..de64209 100644 > --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c > +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c > @@ -285,13 +285,39 @@ static struct ttm_page_pool *ttm_get_pool(int flags, bool huge, > } > > /* set memory back to wb and free the pages. */ > -static void ttm_pages_put(struct page *pages[], unsigned npages) > +static void ttm_pages_put(struct page *pages[], unsigned npages, > + unsigned int order) > { > - unsigned i; > - if (set_pages_array_wb(pages, npages)) > - pr_err("Failed to set %d pages to wb!\n", npages); > - for (i = 0; i < npages; ++i) > - __free_page(pages[i]); > + struct page **pages_to_free = NULL; > + struct page **pages_array; > + struct page *p; > + unsigned int i, j, pages_nr = (1 << order); > + > + if (order > 0) { > + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *), > + GFP_KERNEL); > + if (!pages_to_free) { > + pr_err("Failed to allocate memory for ttm pages put operation\n"); > + return; > + } > + } > + > + for (i = 0; i < npages; ++i) { > + if (order > 0) { + p = pages[i]; + for (j = 0; j < pages_nr; ++j) + > pages_to_free[j] = p++; + + pages_array = pages_to_free; + } else + > pages_array = pages; + + if (set_pages_array_wb(pages_array, pages_nr)) you can use set_pages_wb(pages[i], 1 << order) to instead of creating page array marked red, this way, you will not need to kmalloc and patch#3. and more, if you select set_pages_wb, you also need to clone it in TTM like set_pages_array_wb for non-x86 case. Regards, David Zhou > + pr_err("Failed to set %d pages to wb!\n", pages_nr); > + __free_pages(pages[i], order); > + } > + > + kfree(pages_to_free); > } > > static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, > @@ -354,7 +380,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > */ > spin_unlock_irqrestore(&pool->lock, irq_flags); > > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > if (likely(nr_free != FREE_ALL_PAGES)) > nr_free -= freed_pages; > > @@ -389,7 +415,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > spin_unlock_irqrestore(&pool->lock, irq_flags); > > if (freed_pages) > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > out: > if (pages_to_free != static_buf) > kfree(pages_to_free);
From: dri-devel [mailto:dri-devel-bounces@lists.freedesktop.org] On Behalf Of Chunming Zhou Sent: Wednesday, November 22, 2017 2:02 PM To: dri-devel@lists.freedesktop.org Subject: Re: [PATCH 2/4] drm/ttm: add page order support in ttm_pages_put On 2017年11月22日 13:36, Roger He wrote: Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 Signed-off-by: Roger He <Hongbo.He@amd.com><mailto:Hongbo.He@amd.com> --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 +++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 0a0c653..de64209 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -285,13 +285,39 @@ static struct ttm_page_pool *ttm_get_pool(int flags, bool huge, } /* set memory back to wb and free the pages. */ -static void ttm_pages_put(struct page *pages[], unsigned npages) +static void ttm_pages_put(struct page *pages[], unsigned npages, + unsigned int order) { - unsigned i; - if (set_pages_array_wb(pages, npages)) - pr_err("Failed to set %d pages to wb!\n", npages); - for (i = 0; i < npages; ++i) - __free_page(pages[i]); + struct page **pages_to_free = NULL; + struct page **pages_array; + struct page *p; + unsigned int i, j, pages_nr = (1 << order); + + if (order > 0) { + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *), + GFP_KERNEL); + if (!pages_to_free) { + pr_err("Failed to allocate memory for ttm pages put operation\n"); + return; + } + } + + for (i = 0; i < npages; ++i) { + if (order > 0) { + p = pages[i]; + for (j = 0; j < pages_nr; ++j) + pages_to_free[j] = p++; + + pages_array = pages_to_free; + } else + pages_array = pages; + + if (set_pages_array_wb(pages_array, pages_nr)) you can use set_pages_wb(pages[i], 1 << order) to instead of creating page array marked red, this way, you will not need to kmalloc and patch#3. and more, if you select set_pages_wb, you also need to clone it in TTM like set_pages_array_wb for non-x86 case. good idea, going to refine code. Thanks Roger(Hongbo.He) Regards, David Zhou + pr_err("Failed to set %d pages to wb!\n", pages_nr); + __free_pages(pages[i], order); + } + + kfree(pages_to_free); } static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, @@ -354,7 +380,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, */ spin_unlock_irqrestore(&pool->lock, irq_flags); - ttm_pages_put(pages_to_free, freed_pages); + ttm_pages_put(pages_to_free, freed_pages, pool->order); if (likely(nr_free != FREE_ALL_PAGES)) nr_free -= freed_pages; @@ -389,7 +415,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, spin_unlock_irqrestore(&pool->lock, irq_flags); if (freed_pages) - ttm_pages_put(pages_to_free, freed_pages); + ttm_pages_put(pages_to_free, freed_pages, pool->order); out: if (pages_to_free != static_buf) kfree(pages_to_free);
I would rather completely nuke ttm_pages_put() instead of coming up with more workarounds here. Going to provide a cleanup patch to show what I mean, just give me a minute. Regards, Christian. Am 22.11.2017 um 06:36 schrieb Roger He: > Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 > Signed-off-by: Roger He <Hongbo.He@amd.com> > --- > drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 +++++++++++++++++++++++++++++------- > 1 file changed, 34 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c > index 0a0c653..de64209 100644 > --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c > +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c > @@ -285,13 +285,39 @@ static struct ttm_page_pool *ttm_get_pool(int flags, bool huge, > } > > /* set memory back to wb and free the pages. */ > -static void ttm_pages_put(struct page *pages[], unsigned npages) > +static void ttm_pages_put(struct page *pages[], unsigned npages, > + unsigned int order) > { > - unsigned i; > - if (set_pages_array_wb(pages, npages)) > - pr_err("Failed to set %d pages to wb!\n", npages); > - for (i = 0; i < npages; ++i) > - __free_page(pages[i]); > + struct page **pages_to_free = NULL; > + struct page **pages_array; > + struct page *p; > + unsigned int i, j, pages_nr = (1 << order); > + > + if (order > 0) { > + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *), > + GFP_KERNEL); > + if (!pages_to_free) { > + pr_err("Failed to allocate memory for ttm pages put operation\n"); > + return; > + } > + } > + > + for (i = 0; i < npages; ++i) { > + if (order > 0) { > + p = pages[i]; > + for (j = 0; j < pages_nr; ++j) > + pages_to_free[j] = p++; > + > + pages_array = pages_to_free; > + } else > + pages_array = pages; > + > + if (set_pages_array_wb(pages_array, pages_nr)) > + pr_err("Failed to set %d pages to wb!\n", pages_nr); > + __free_pages(pages[i], order); > + } > + > + kfree(pages_to_free); > } > > static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, > @@ -354,7 +380,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > */ > spin_unlock_irqrestore(&pool->lock, irq_flags); > > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > if (likely(nr_free != FREE_ALL_PAGES)) > nr_free -= freed_pages; > > @@ -389,7 +415,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > spin_unlock_irqrestore(&pool->lock, irq_flags); > > if (freed_pages) > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > out: > if (pages_to_free != static_buf) > kfree(pages_to_free);
Hi Christian: This is old patch, I already send new patches. And it is clean and simple. Please check that. Thanks Roger(Hongbo.He) -----Original Message----- From: Christian König [mailto:ckoenig.leichtzumerken@gmail.com] Sent: Wednesday, November 22, 2017 5:29 PM To: He, Roger <Hongbo.He@amd.com>; amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org Cc: Koenig, Christian <Christian.Koenig@amd.com> Subject: Re: [PATCH 2/4] drm/ttm: add page order support in ttm_pages_put I would rather completely nuke ttm_pages_put() instead of coming up with more workarounds here. Going to provide a cleanup patch to show what I mean, just give me a minute. Regards, Christian. Am 22.11.2017 um 06:36 schrieb Roger He: > Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 > Signed-off-by: Roger He <Hongbo.He@amd.com> > --- > drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 +++++++++++++++++++++++++++++------- > 1 file changed, 34 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c > b/drivers/gpu/drm/ttm/ttm_page_alloc.c > index 0a0c653..de64209 100644 > --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c > +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c > @@ -285,13 +285,39 @@ static struct ttm_page_pool *ttm_get_pool(int flags, bool huge, > } > > /* set memory back to wb and free the pages. */ -static void > ttm_pages_put(struct page *pages[], unsigned npages) > +static void ttm_pages_put(struct page *pages[], unsigned npages, > + unsigned int order) > { > - unsigned i; > - if (set_pages_array_wb(pages, npages)) > - pr_err("Failed to set %d pages to wb!\n", npages); > - for (i = 0; i < npages; ++i) > - __free_page(pages[i]); > + struct page **pages_to_free = NULL; > + struct page **pages_array; > + struct page *p; > + unsigned int i, j, pages_nr = (1 << order); > + > + if (order > 0) { > + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *), > + GFP_KERNEL); > + if (!pages_to_free) { > + pr_err("Failed to allocate memory for ttm pages put operation\n"); > + return; > + } > + } > + > + for (i = 0; i < npages; ++i) { > + if (order > 0) { > + p = pages[i]; > + for (j = 0; j < pages_nr; ++j) > + pages_to_free[j] = p++; > + > + pages_array = pages_to_free; > + } else > + pages_array = pages; > + > + if (set_pages_array_wb(pages_array, pages_nr)) > + pr_err("Failed to set %d pages to wb!\n", pages_nr); > + __free_pages(pages[i], order); > + } > + > + kfree(pages_to_free); > } > > static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, > @@ -354,7 +380,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > */ > spin_unlock_irqrestore(&pool->lock, irq_flags); > > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > if (likely(nr_free != FREE_ALL_PAGES)) > nr_free -= freed_pages; > > @@ -389,7 +415,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, > spin_unlock_irqrestore(&pool->lock, irq_flags); > > if (freed_pages) > - ttm_pages_put(pages_to_free, freed_pages); > + ttm_pages_put(pages_to_free, freed_pages, pool->order); > out: > if (pages_to_free != static_buf) > kfree(pages_to_free);
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 0a0c653..de64209 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -285,13 +285,39 @@ static struct ttm_page_pool *ttm_get_pool(int flags, bool huge, } /* set memory back to wb and free the pages. */ -static void ttm_pages_put(struct page *pages[], unsigned npages) +static void ttm_pages_put(struct page *pages[], unsigned npages, + unsigned int order) { - unsigned i; - if (set_pages_array_wb(pages, npages)) - pr_err("Failed to set %d pages to wb!\n", npages); - for (i = 0; i < npages; ++i) - __free_page(pages[i]); + struct page **pages_to_free = NULL; + struct page **pages_array; + struct page *p; + unsigned int i, j, pages_nr = (1 << order); + + if (order > 0) { + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *), + GFP_KERNEL); + if (!pages_to_free) { + pr_err("Failed to allocate memory for ttm pages put operation\n"); + return; + } + } + + for (i = 0; i < npages; ++i) { + if (order > 0) { + p = pages[i]; + for (j = 0; j < pages_nr; ++j) + pages_to_free[j] = p++; + + pages_array = pages_to_free; + } else + pages_array = pages; + + if (set_pages_array_wb(pages_array, pages_nr)) + pr_err("Failed to set %d pages to wb!\n", pages_nr); + __free_pages(pages[i], order); + } + + kfree(pages_to_free); } static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, @@ -354,7 +380,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, */ spin_unlock_irqrestore(&pool->lock, irq_flags); - ttm_pages_put(pages_to_free, freed_pages); + ttm_pages_put(pages_to_free, freed_pages, pool->order); if (likely(nr_free != FREE_ALL_PAGES)) nr_free -= freed_pages; @@ -389,7 +415,7 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, spin_unlock_irqrestore(&pool->lock, irq_flags); if (freed_pages) - ttm_pages_put(pages_to_free, freed_pages); + ttm_pages_put(pages_to_free, freed_pages, pool->order); out: if (pages_to_free != static_buf) kfree(pages_to_free);
Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 Signed-off-by: Roger He <Hongbo.He@amd.com> --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 42 +++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-)