From patchwork Wed Nov 22 10:00:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10069983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 44BB560375 for ; Wed, 22 Nov 2017 10:00:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3106028E21 for ; Wed, 22 Nov 2017 10:00:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2695129979; Wed, 22 Nov 2017 10:00:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 78BED28E21 for ; Wed, 22 Nov 2017 10:00:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C9DD86E611; Wed, 22 Nov 2017 10:00:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E77EF6E609; Wed, 22 Nov 2017 10:00:33 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id b189so9028094wmd.0; Wed, 22 Nov 2017 02:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=reply-to:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=pfmtDx8/JU7oCVhdbABy+A1WWVtxFlOYGmKPxa8E2Z0=; b=WGnyOE3nlC7LTmRuSZzHUnkSbv0abydd0FQV0g5BKgXfxH/tl1laBfbjECbpQQvnfm qlruRj+iO1iJupo9gAH0I/9gocoC+7PnxOT6ucFwuajuReC9Ua1Bl6ROm0OnQxJAdFWB ht8RDgs90jDHFO6XlWA0FmW6KQf1Kum1/EeLkV3I2HUVuPHm6YaejQOI1vzPgyZ+UQ7w cyE6syGg1b+YokL5OsJ0yQWYWphtQ3s3XEAT0jNvYBiS/wdWdQWT3N0J2s2bhwPILcv4 zcWOf0QkuEGzL6Jh5hobIr7gBhRDJ0ibFfOTv/hmsMq62+hK09oqx+n7AxRCDeGi0mrc Rw0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=pfmtDx8/JU7oCVhdbABy+A1WWVtxFlOYGmKPxa8E2Z0=; b=Jye2ZYcksjWQvfkDIuY47MFy5gFdcVsRURyqr+XRHRxAPwcmm9ruY3ooLR1mzaY6qv /XACaQ65AMui57OhZ1Jfck0HbmEKv69/krygF1SC1ivPFkupt3dyxPe9WQJ+xgZcLdVm 13P6bdH2rQJsymA3Ry/8BeHYj7sylOrNOP0OJuPJHsVDdm1pwhLoFGyKGo3ErtTpXhl+ 7Ho5lX6QRv7C41VgUF430Nn+XfhO3dsVgykmUNE5PvKC2PDlnLG9kh1cr8dEt9Gdfqft qZvepNMmXaYHdkoS9HrEJpQ/EmtV/lqaeDONcOaUKQMLWq/1EBeScwbBEikASSSqehSf FvKA== X-Gm-Message-State: AJaThX5ZIXicu0qIIiAIJyXhKFcXeWD3jmy/9q0OFzzdJODawLSSHWBC 5MxwwkxAtk9dw8OErhu3loaTZ5I3 X-Google-Smtp-Source: AGs4zMYtFhB2muTISrTudAxJie6eiIslq8lBrE7wd+rnSjREsSlTtJIdgpXrBxZaF0gHN7b7UOuPhw== X-Received: by 10.80.184.165 with SMTP id l34mr28216870ede.53.1511344832148; Wed, 22 Nov 2017 02:00:32 -0800 (PST) Received: from ?IPv6:2a02:908:1251:7981:5d0:8ffd:957f:10e7? ([2a02:908:1251:7981:5d0:8ffd:957f:10e7]) by smtp.gmail.com with ESMTPSA id l4sm13542563edc.20.2017.11.22.02.00.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Nov 2017 02:00:31 -0800 (PST) Subject: Re: [PATCH 3/5] drm/ttm: add page order support in ttm_pages_put To: Roger He , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org References: <1511342234-18570-1-git-send-email-Hongbo.He@amd.com> <1511342234-18570-3-git-send-email-Hongbo.He@amd.com> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Wed, 22 Nov 2017 11:00:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1511342234-18570-3-git-send-email-Hongbo.He@amd.com> Content-Language: en-US X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP That completely negates the advantage of setting write back on multiple pages at once. In other words this way we wouldn't need the array any more at all and could remove the whole complicated handling. I'm pretty close to saying just go ahead with that and even clean up the whole stuff with the static array, but I'm not sure if that doesn't result in some performance problems. A possible alternative is the (untested) patch attached, this way we move the __free_page()/_free_pages() call out of ttm_pages_put and just need to add the correct number of pages to the array in the loop. Regards, Christian. Am 22.11.2017 um 10:17 schrieb Roger He: > Change-Id: Ia55b206d95812c5afcfd6cec29f580758d1f50f0 > Signed-off-by: Roger He > --- > drivers/gpu/drm/ttm/ttm_page_alloc.c | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c > index 9b48b93..2dc83c0 100644 > --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c > +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c > @@ -299,13 +299,16 @@ 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]); > + unsigned int i, pages_nr = (1 << order); > + > + for (i = 0; i < npages; ++i) { > + if (set_pages_wb(pages[i], pages_nr)) > + pr_err("Failed to set %d pages to wb!\n", pages_nr); > + __free_pages(pages[i], order); > + } > } > > static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, > @@ -368,7 +371,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; > > @@ -403,7 +406,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 4fcc6c40e3596e12a9712b01a44d9c0265f04582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 22 Nov 2017 10:54:58 +0100 Subject: [PATCH] drm/ttm: move __free_page out of ttm_pages_put MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way we can easier free the pages with the right order. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_page_alloc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c index 72ea037b7090..4deb9c8441b5 100644 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -286,11 +286,8 @@ 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) { - 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]); } static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, @@ -315,7 +312,8 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, { static struct page *static_buf[NUM_PAGES_TO_ALLOC]; unsigned long irq_flags; - struct page *p; + struct list_head freed; + struct page *p, *tmp; struct page **pages_to_free; unsigned freed_pages = 0, npages_to_free = nr_free; @@ -333,6 +331,8 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, return 0; } + INIT_LIST_HEAD(&freed); + restart: spin_lock_irqsave(&pool->lock, irq_flags); @@ -345,6 +345,8 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, if (freed_pages >= NUM_PAGES_TO_ALLOC) { /* remove range of pages from the pool */ __list_del(p->lru.prev, &pool->list); + /* and add to freed list */ + __list_add(&p->lru, &freed, &freed); ttm_pool_update_free_locked(pool, freed_pages); /** @@ -380,6 +382,8 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, /* remove range of pages from the pool */ if (freed_pages) { __list_del(&p->lru, &pool->list); + /* and add to freed list */ + __list_add(&p->lru, &freed, &freed); ttm_pool_update_free_locked(pool, freed_pages); nr_free -= freed_pages; @@ -392,6 +396,10 @@ static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free, out: if (pages_to_free != static_buf) kfree(pages_to_free); + + list_for_each_entry_safe(p, tmp, &freed, lru) + __free_page(p); + return nr_free; } -- 2.11.0