From: "Christian König" <ckoenig.leichtzumerken-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Roger He <Hongbo.He-5C7GfCeVMHo@public.gmane.org>,
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 3/4] drm/ttm: add page order support in ttm_pages_put
Date: Tue, 21 Nov 2017 10:52:08 +0100 [thread overview]
Message-ID: <2cdc63db-a321-c2bb-70be-b208a5c1a865@gmail.com> (raw)
In-Reply-To: <1511256742-5601-4-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
Am 21.11.2017 um 10:32 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 27b2402..90546fd 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 = NULL;
> + struct page *p = NULL;
> + unsigned int i, j, pages_nr = 1 << order;
> +
> + if (order > 0) {
> + pages_to_free = kmalloc_array(pages_nr, sizeof(struct page *),
> + GFP_KERNEL);
We can't call kmalloc here, when this function is called by the shrinker
we are tight on memory anyway.
That's also the reason we have this static buffer dance in
ttm_page_pool_free() as well.
Christian.
> + 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) {
> + 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);
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2017-11-21 9:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 9:32 [PATCH 0/4] *** fix memory leak for HUGE PAGE *** Roger He
2017-11-21 9:32 ` [PATCH 1/4] drm/ttm: add page order in page pool Roger He
2017-11-21 9:52 ` Christian König
[not found] ` <1511256742-5601-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-11-23 20:07 ` kbuild test robot
2017-11-23 21:49 ` kbuild test robot
2017-11-21 9:32 ` [PATCH 2/4] drm/ttm: use NUM_PAGES_TO_ALLOC always Roger He
[not found] ` <1511256742-5601-3-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-11-21 9:41 ` Christian König
2017-11-21 9:32 ` [PATCH 3/4] drm/ttm: add page order support in ttm_pages_put Roger He
[not found] ` <1511256742-5601-4-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-11-21 9:52 ` Christian König [this message]
[not found] ` <1511256742-5601-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org>
2017-11-21 9:32 ` [PATCH 4/4] drm/ttm: free one in huge pool even shrink request less than one element Roger He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2cdc63db-a321-c2bb-70be-b208a5c1a865@gmail.com \
--to=ckoenig.leichtzumerken-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=Hongbo.He-5C7GfCeVMHo@public.gmane.org \
--cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=christian.koenig-5C7GfCeVMHo@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox