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;
                        }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to