Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Feb 2015 13:45:06 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r278153 - head/sys/dev/drm2/ttm
Message-ID:  <201502031345.t13Dj6wp060238@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Tue Feb  3 13:45:06 2015
New Revision: 278153
URL: https://svnweb.freebsd.org/changeset/base/278153

Log:
  If the vm_page_alloc_contig() failed in the ttm page allocators, do
  what other callers of vm_page_alloc_contig() do, retry after
  vm_pageout_grow_cache().
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/dev/drm2/ttm/ttm_bo.c
  head/sys/dev/drm2/ttm/ttm_page_alloc.c

Modified: head/sys/dev/drm2/ttm/ttm_bo.c
==============================================================================
--- head/sys/dev/drm2/ttm/ttm_bo.c	Tue Feb  3 13:43:03 2015	(r278152)
+++ head/sys/dev/drm2/ttm/ttm_bo.c	Tue Feb  3 13:45:06 2015	(r278153)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/drm2/ttm/ttm_module.h>
 #include <dev/drm2/ttm/ttm_bo_driver.h>
 #include <dev/drm2/ttm/ttm_placement.h>
+#include <vm/vm_pageout.h>
 
 #define TTM_ASSERT_LOCKED(param)
 #define TTM_DEBUG(fmt, arg...)
@@ -1489,15 +1490,23 @@ int ttm_bo_global_init(struct drm_global
 		container_of(ref, struct ttm_bo_global_ref, ref);
 	struct ttm_bo_global *glob = ref->object;
 	int ret;
+	int tries;
 
 	sx_init(&glob->device_list_mutex, "ttmdlm");
 	mtx_init(&glob->lru_lock, "ttmlru", NULL, MTX_DEF);
 	glob->mem_glob = bo_ref->mem_glob;
+	tries = 0;
+retry:
 	glob->dummy_read_page = vm_page_alloc_contig(NULL, 0,
 	    VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ,
 	    1, 0, VM_MAX_ADDRESS, PAGE_SIZE, 0, VM_MEMATTR_UNCACHEABLE);
 
 	if (unlikely(glob->dummy_read_page == NULL)) {
+		if (tries < 1) {
+			vm_pageout_grow_cache(tries, 0, VM_MAX_ADDRESS);
+			tries++;
+			goto retry;
+		}
 		ret = -ENOMEM;
 		goto out_no_drp;
 	}

Modified: head/sys/dev/drm2/ttm/ttm_page_alloc.c
==============================================================================
--- head/sys/dev/drm2/ttm/ttm_page_alloc.c	Tue Feb  3 13:43:03 2015	(r278152)
+++ head/sys/dev/drm2/ttm/ttm_page_alloc.c	Tue Feb  3 13:45:06 2015	(r278153)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/drm2/drmP.h>
 #include <dev/drm2/ttm/ttm_bo_driver.h>
 #include <dev/drm2/ttm/ttm_page_alloc.h>
+#include <vm/vm_pageout.h>
 
 #define NUM_PAGES_TO_ALLOC		(PAGE_SIZE/sizeof(vm_page_t))
 #define SMALL_ALLOCATION		16
@@ -460,6 +461,14 @@ static void ttm_handle_caching_state_fai
 	}
 }
 
+static vm_paddr_t
+ttm_alloc_high_bound(int ttm_alloc_flags)
+{
+
+	return ((ttm_alloc_flags & TTM_PAGE_FLAG_DMA32) ? 0xffffffff :
+	    VM_MAX_ADDRESS);
+}
+
 /**
  * Allocate new pages with correct caching.
  *
@@ -475,6 +484,7 @@ static int ttm_alloc_new_pages(struct pg
 	unsigned i, cpages, aflags;
 	unsigned max_cpages = min(count,
 			(unsigned)(PAGE_SIZE/sizeof(vm_page_t)));
+	int tries;
 
 	aflags = VM_ALLOC_NORMAL | VM_ALLOC_WIRED | VM_ALLOC_NOOBJ |
 	    ((ttm_alloc_flags & TTM_PAGE_FLAG_ZERO_ALLOC) != 0 ?
@@ -485,11 +495,18 @@ static int ttm_alloc_new_pages(struct pg
 	    M_WAITOK | M_ZERO);
 
 	for (i = 0, cpages = 0; i < count; ++i) {
+		tries = 0;
+retry:
 		p = vm_page_alloc_contig(NULL, 0, aflags, 1, 0,
-		    (ttm_alloc_flags & TTM_PAGE_FLAG_DMA32) ? 0xffffffff :
-		    VM_MAX_ADDRESS, PAGE_SIZE, 0,
-		    ttm_caching_state_to_vm(cstate));
+		    ttm_alloc_high_bound(ttm_alloc_flags),
+		    PAGE_SIZE, 0, ttm_caching_state_to_vm(cstate));
 		if (!p) {
+			if (tries < 3) {
+				vm_pageout_grow_cache(tries, 0,
+				    ttm_alloc_high_bound(ttm_alloc_flags));
+				tries++;
+				goto retry;
+			}
 			printf("[TTM] Unable to get page %u\n", i);
 
 			/* store already allocated pages in the pool after
@@ -691,6 +708,7 @@ static int ttm_get_pages(vm_page_t *page
 	int gfp_flags, aflags;
 	unsigned count;
 	int r;
+	int tries;
 
 	aflags = VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED |
 	    ((flags & TTM_PAGE_FLAG_ZERO_ALLOC) != 0 ? VM_ALLOC_ZERO : 0);
@@ -698,11 +716,18 @@ static int ttm_get_pages(vm_page_t *page
 	/* No pool for cached pages */
 	if (pool == NULL) {
 		for (r = 0; r < npages; ++r) {
+			tries = 0;
+retry:
 			p = vm_page_alloc_contig(NULL, 0, aflags, 1, 0,
-			    (flags & TTM_PAGE_FLAG_DMA32) ? 0xffffffff :
-			    VM_MAX_ADDRESS, PAGE_SIZE,
+			    ttm_alloc_high_bound(flags), PAGE_SIZE,
 			    0, ttm_caching_state_to_vm(cstate));
 			if (!p) {
+				if (tries < 3) {
+					vm_pageout_grow_cache(tries, 0,
+					    ttm_alloc_high_bound(flags));
+					tries++;
+					goto retry;
+				}
 				printf("[TTM] Unable to allocate page\n");
 				return -ENOMEM;
 			}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502031345.t13Dj6wp060238>