diff mbox

[3/4] drm/ttm: add static buffer for ttm_pages_put to support pool shrink

Message ID 1511329016-552-3-git-send-email-Hongbo.He@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

He, Hongbo Nov. 22, 2017, 5:36 a.m. UTC
Change-Id: Ic20c016eb3043d7cfedc2e3648790a017168da6c
Signed-off-by: Roger He <Hongbo.He@amd.com>
---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index de64209..37c2f2f 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -285,20 +285,27 @@  static struct ttm_page_pool *ttm_get_pool(int flags, bool huge,
 }
 
 /* set memory back to wb and free the pages. */
+#define STATIC_BUF_PUT_SIZE 512
 static void ttm_pages_put(struct page *pages[], unsigned npages,
-		unsigned int order)
+		unsigned int order, bool use_static)
 {
+	static struct page *static_buf_put[STATIC_BUF_PUT_SIZE];
 	struct page **pages_to_free = NULL;
 	struct page **pages_array;
 	struct page *p;
 	unsigned int i, j, pages_nr = (1 << order);
 
+	BUG_ON(use_static && pages_nr > STATIC_BUF_PUT_SIZE);
 	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;
+		if (use_static)
+			pages_to_free = static_buf_put;
+		else {
+			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;
+			}
 		}
 	}
 
@@ -317,7 +324,8 @@  static void ttm_pages_put(struct page *pages[], unsigned npages,
 		__free_pages(pages[i], order);
 	}
 
-	kfree(pages_to_free);
+	if (!use_static)
+		kfree(pages_to_free);
 }
 
 static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
@@ -380,7 +388,8 @@  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, pool->order);
+			ttm_pages_put(pages_to_free, freed_pages, pool->order,
+					use_static);
 			if (likely(nr_free != FREE_ALL_PAGES))
 				nr_free -= freed_pages;
 
@@ -415,7 +424,8 @@  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, pool->order);
+		ttm_pages_put(pages_to_free, freed_pages, pool->order,
+			use_static);
 out:
 	if (pages_to_free != static_buf)
 		kfree(pages_to_free);