Skip to contentSkip to conversation

drm/ttm: use bit flag to replace allow_reserved_eviction in ttm_operation_ctx

PATCH In review Roger He 3 participants 8 messages Feb 8, 2018 – Feb 9, 2018 4 messages not in the archive

Subsystems (7)
lore
Share & tools
lore

Roger He

author
#0 lore raw

PATCH 1/4 drm/ttm: use bit flag to replace allow_reserved_eviction in ttm_operation_ctx

for saving memory and more bit flag can be used in future

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++--
 drivers/gpu/drm/ttm/ttm_bo.c               | 3 ++-
 include/drm/ttm/ttm_bo_api.h               | 7 +++++--
 4 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -2
index eaa3cb0..dc34b50 100644
@@ -346,8 +346,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
 	struct ttm_operation_ctx ctx = {
 		.interruptible = true,
 		.no_wait_gpu = false,
-		.allow_reserved_eviction = false,
-		.resv = bo->tbo.resv
+		.resv = bo->tbo.resv,
+		.flags = 0
 	};
 	uint32_t domain;
 	int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
index 512612e..0338ef6 100644
@@ -341,8 +341,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	struct ttm_operation_ctx ctx = {
 		.interruptible = !kernel,
 		.no_wait_gpu = false,
-		.allow_reserved_eviction = true,
-		.resv = resv
+		.resv = resv,
+		.flags = TTM_OPT_FLAG_ALLOW_RES_EVICT
 	};
 	struct amdgpu_bo *bo;
 	enum ttm_bo_type type;
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
index d90b1cf1..a907311 100644
@@ -730,7 +730,8 @@ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
 	*locked = false;
 	if (bo->resv == ctx->resv) {
 		reservation_object_assert_held(bo->resv);
-		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+		if (ctx->flags & TTM_OPT_FLAG_ALLOW_RES_EVICT
+		    || !list_empty(&bo->ddestroy))
 			ret = true;
 	} else {
 		*locked = reservation_object_trylock(bo->resv);
include/drm/ttm/ttm_bo_api.h +5 -2
index 2cd025c..872ff6c 100644
@@ -263,8 +263,8 @@ struct ttm_bo_kmap_obj {
  *
  * @interruptible: Sleep interruptible if sleeping.
  * @no_wait_gpu: Return immediately if the GPU is busy.
- * @allow_reserved_eviction: Allow eviction of reserved BOs.
  * @resv: Reservation object to allow reserved evictions with.
+ * @flags: Including the following flags
  *
  * Context for TTM operations like changing buffer placement or general memory
  * allocation.
@@ -272,11 +272,14 @@ struct ttm_bo_kmap_obj {
 struct ttm_operation_ctx {
 	bool interruptible;
 	bool no_wait_gpu;
-	bool allow_reserved_eviction;
 	struct reservation_object *resv;
 	uint64_t bytes_moved;
+	uint32_t flags;
 };
 
+/* Allow eviction of reserved BOs */
+#define TTM_OPT_FLAG_ALLOW_RES_EVICT	0x1
+
 /**
  * ttm_bo_reference - reference a struct ttm_buffer_object
  *
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#1 lore raw

PATCH 2/4 drm/ttm: add bit flag TTM_OPT_FLAG_FORCE_ALLOC

set TTM_OPT_FLAG_FORCE_ALLOC when we are servicing for page fault routine.

for ttm_mem_global_reserve if in page fault routine, allow the gtt pages reservation always. because page fault routing already grabbed system memory and the allowance of this exception is harmless. Otherwise, it will trigger OOM killer.

the subsequent patche will use this.

v2: keep original behavior except ttm bo with flag no_retry

---
 drivers/gpu/drm/ttm/ttm_bo_vm.c          | 6 ++++--
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 1 -
 include/drm/ttm/ttm_bo_api.h             | 4 +++-
 3 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +4 -2
index 716e724..f10b8a0 100644
@@ -224,7 +224,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 		cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
 						cvma.vm_page_prot);
 	} else {
-		struct ttm_operation_ctx ctx = {
+		struct ttm_operation_ctx ttm_opt_ctx = {
 			.interruptible = false,
 			.no_wait_gpu = false
 		};
@@ -233,8 +233,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
 		cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
 						cvma.vm_page_prot);
 
+		if (ttm->page_flags & TTM_PAGE_FLAG_NO_RETRY)
+			ttm_opt_ctx.flags |= TTM_OPT_FLAG_FORCE_ALLOC;
 		/* Allocate all page at once, most common usage */
-		if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) {
+		if (ttm->bdev->driver->ttm_tt_populate(ttm, &ttm_opt_ctx)) {
 			ret = VM_FAULT_OOM;
 			goto out_io_unlock;
 		}
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -1
index b122f6e..354e0e1 100644
@@ -944,7 +944,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 	i = 0;
 
 	type = ttm_to_type(ttm->page_flags, ttm->caching_state);
-
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	if (ttm->page_flags & TTM_PAGE_FLAG_DMA32)
 		goto skip_huge;
include/drm/ttm/ttm_bo_api.h +3 -1
index 872ff6c..2142639 100644
@@ -278,7 +278,9 @@ struct ttm_operation_ctx {
 };
 
 /* Allow eviction of reserved BOs */
-#define TTM_OPT_FLAG_ALLOW_RES_EVICT	0x1
+#define TTM_OPT_FLAG_ALLOW_RES_EVICT		0x1
+/* when serving page fault or suspend, allow alloc anyway */
+#define TTM_OPT_FLAG_FORCE_ALLOC		0x2
 
 /**
  * ttm_bo_reference - reference a struct ttm_buffer_object
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 1518080761-12952-2-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org

#3 lore raw

Re: [PATCH 2/4] drm/ttm: add bit flag TTM_OPT_FLAG_FORCE_ALLOC

Am 08.02.2018 um 10:05 schrieb Roger He:

Quoted 33 lines

set TTM_OPT_FLAG_FORCE_ALLOC when we are servicing for page fault routine.

for ttm_mem_global_reserve if in page fault routine, allow the gtt pages reservation always. because page fault routing already grabbed system memory and the allowance of this exception is harmless. Otherwise, it will trigger OOM killer.

the subsequent patche will use this.

v2: keep original behavior except ttm bo with flag no_retry

---
  drivers/gpu/drm/ttm/ttm_bo_vm.c          | 6 ++++--
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 1 -
  include/drm/ttm/ttm_bo_api.h             | 4 +++-
  3 files changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -1
index 716e724..f10b8a0 100644
@@ -224,7 +224,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
  		cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
  						cvma.vm_page_prot);
  	} else {
-		struct ttm_operation_ctx ctx = {
+		struct ttm_operation_ctx ttm_opt_ctx = {
  			.interruptible = false,
  			.no_wait_gpu = false
  		};

drivers/gpu/drm/ttm/ttm_bo_vm.c static int ttm_bo_vm_fault(struct vm_fault *vmf) · line 237

Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +2 -0
@@ -233,8 +233,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
  		cvma.vm_page_prot = ttm_io_prot(bo->mem.placement,
  						cvma.vm_page_prot);
 
+		if (ttm->page_flags & TTM_PAGE_FLAG_NO_RETRY)
+			ttm_opt_ctx.flags |= TTM_OPT_FLAG_FORCE_ALLOC;

Can't we always set the TTM_OPT_FLAG_FORCE_ALLOC flag here?

I don't see a reason why we should ever not set it.

Christian.

Quoted 23 lines
drivers/gpu/drm/ttm/ttm_bo_vm.c +1 -1
  		/* Allocate all page at once, most common usage */
-		if (ttm->bdev->driver->ttm_tt_populate(ttm, &ctx)) {
+		if (ttm->bdev->driver->ttm_tt_populate(ttm, &ttm_opt_ctx)) {
  			ret = VM_FAULT_OOM;
  			goto out_io_unlock;
  		}
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -1
index b122f6e..354e0e1 100644
@@ -944,7 +944,6 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
  	i = 0;
 
  	type = ttm_to_type(ttm->page_flags, ttm->caching_state);
-
  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  	if (ttm->page_flags & TTM_PAGE_FLAG_DMA32)
  		goto skip_huge;
include/drm/ttm/ttm_bo_api.h +0 -0
index 872ff6c..2142639 100644

include/drm/ttm/ttm_bo_api.h struct ttm_operation_ctx { · line 286

Quoted 10 lines
include/drm/ttm/ttm_bo_api.h +3 -1
@@ -278,7 +278,9 @@ struct ttm_operation_ctx {
  };
 
  /* Allow eviction of reserved BOs */
-#define TTM_OPT_FLAG_ALLOW_RES_EVICT	0x1
+#define TTM_OPT_FLAG_ALLOW_RES_EVICT		0x1
+/* when serving page fault or suspend, allow alloc anyway */
+#define TTM_OPT_FLAG_FORCE_ALLOC		0x2
 
  /**
   * ttm_bo_reference - reference a struct ttm_buffer_object

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#4 lore raw

PATCH 3/4 drm/ttm: add input parameter force_alloc for ttm_bo_evict_mm

In reply to Roger He

if true, allocate TTM pages regardless of zone global memory account limit. For suspend, We should avoid TTM memory allocate failure then result in suspend failure.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |  2 +-
 drivers/gpu/drm/nouveau/nouveau_drm.c       |  2 +-
 drivers/gpu/drm/qxl/qxl_object.c            |  4 ++--
 drivers/gpu/drm/radeon/radeon_device.c      |  6 +++---
 drivers/gpu/drm/radeon/radeon_object.c      |  5 +++--
 drivers/gpu/drm/radeon/radeon_object.h      |  3 ++-
 drivers/gpu/drm/ttm/ttm_bo.c                | 16 ++++++++++------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c         |  6 +++---
 include/drm/ttm/ttm_bo_api.h                |  5 ++++-
 12 files changed, 34 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -1
index ee76b46..59ee12c 100644
@@ -763,7 +763,7 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
 	struct drm_device *dev = node->minor->dev;
 	struct amdgpu_device *adev = dev->dev_private;
 
-	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
+	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev, true));
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index e3fa3d7..3c5f9ca 100644
@@ -2168,7 +2168,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
 		}
 	}
 	/* evict vram memory */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
 	amdgpu_fence_driver_suspend(adev);
 
@@ -2178,7 +2178,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
 	 * This second call to evict vram is to evict the gart page table
 	 * using the CPU.
 	 */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
 	pci_save_state(dev->pdev);
 	if (suspend) {
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
index 0338ef6..db813f9 100644
@@ -803,14 +803,14 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
 	return r;
 }
 
-int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool force_alloc)
 {
 	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
 	if (0 && (adev->flags & AMD_IS_APU)) {
 		/* Useless to evict on IGP chips */
 		return 0;
 	}
-	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM, force_alloc);
 }
 
 static const char *amdgpu_vram_names[] = {
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -1
index c2b02f5..6724cdc 100644
@@ -227,7 +227,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 			     u64 min_offset, u64 max_offset,
 			     u64 *gpu_addr);
 int amdgpu_bo_unpin(struct amdgpu_bo *bo);
-int amdgpu_bo_evict_vram(struct amdgpu_device *adev);
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool force_alloc);
 int amdgpu_bo_init(struct amdgpu_device *adev);
 void amdgpu_bo_fini(struct amdgpu_device *adev);
 int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
index 8d4a5be..c9627ef 100644
@@ -702,7 +702,7 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime)
 	}
 
 	NV_DEBUG(drm, "evicting buffers...\n");
-	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
+	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM, true);
 
 	NV_DEBUG(drm, "waiting for kernel channels to go idle...\n");
 	if (drm->cechan) {
drivers/gpu/drm/qxl/qxl_object.c +2 -2
index f6b80fe..d8d26c8 100644
@@ -350,10 +350,10 @@ int qxl_bo_check_id(struct qxl_device *qdev, struct qxl_bo *bo)
 
 int qxl_surf_evict(struct qxl_device *qdev)
 {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV, true);
 }
 
 int qxl_vram_evict(struct qxl_device *qdev)
 {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM, true);
 }
drivers/gpu/drm/radeon/radeon_device.c +3 -3
index 8d3e3d2..c11ee06 100644
@@ -1522,7 +1522,7 @@ void radeon_device_fini(struct radeon_device *rdev)
 	DRM_INFO("radeon: finishing device.\n");
 	rdev->shutdown = true;
 	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 	radeon_fini(rdev);
 	if (!pci_is_thunderbolt_attached(rdev->pdev))
 		vga_switcheroo_unregister_client(rdev->pdev);
@@ -1607,7 +1607,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool suspend,
 		}
 	}
 	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
 	/* wait for gpu to finish processing current batch */
 	for (i = 0; i < RADEON_NUM_RINGS; i++) {
@@ -1626,7 +1626,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool suspend,
 	 * This second call to evict vram is to evict the gart page table
 	 * using the CPU.
 	 */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
 	radeon_agp_suspend(rdev);
 
drivers/gpu/drm/radeon/radeon_object.c +3 -2
index 15404af..99a9a45 100644
@@ -420,7 +420,8 @@ int radeon_bo_unpin(struct radeon_bo *bo)
 	return r;
 }
 
-int radeon_bo_evict_vram(struct radeon_device *rdev)
+int
+radeon_bo_evict_vram(struct radeon_device *rdev, bool force_alloc)
 {
 	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
 	if (0 && (rdev->flags & RADEON_IS_IGP)) {
@@ -428,7 +429,7 @@ int radeon_bo_evict_vram(struct radeon_device *rdev)
 			/* Useless to evict on IGP chips */
 			return 0;
 	}
-	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM, force_alloc);
 }
 
 void radeon_bo_force_delete(struct radeon_device *rdev)
drivers/gpu/drm/radeon/radeon_object.h +2 -1
index 9ffd821..757ba88 100644
@@ -136,7 +136,8 @@ extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
 extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
 				    u64 max_offset, u64 *gpu_addr);
 extern int radeon_bo_unpin(struct radeon_bo *bo);
-extern int radeon_bo_evict_vram(struct radeon_device *rdev);
+extern int radeon_bo_evict_vram(struct radeon_device *rdev,
+				bool force_alloc);
 extern void radeon_bo_force_delete(struct radeon_device *rdev);
 extern int radeon_bo_init(struct radeon_device *rdev);
 extern void radeon_bo_fini(struct radeon_device *rdev);
drivers/gpu/drm/ttm/ttm_bo.c +10 -6
index a907311..31d10f1 100644
@@ -1342,15 +1342,17 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 EXPORT_SYMBOL(ttm_bo_create);
 
 static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-				   unsigned mem_type)
+			unsigned mem_type, bool force_alloc)
 {
-	struct ttm_operation_ctx ctx = { false, false };
+	struct ttm_operation_ctx ttm_opt_ctx = { false, false };
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 	struct ttm_bo_global *glob = bdev->glob;
 	struct dma_fence *fence;
 	int ret;
 	unsigned i;
 
+	if (force_alloc)
+		ttm_opt_ctx.flags = TTM_OPT_FLAG_FORCE_ALLOC;
 	/*
 	 * Can't use standard list traversal since we're unlocking.
 	 */
@@ -1359,7 +1361,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
 		while (!list_empty(&man->lru[i])) {
 			spin_unlock(&glob->lru_lock);
-			ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx);
+			ret = ttm_mem_evict_first(bdev, mem_type, NULL,
+						  &ttm_opt_ctx);
 			if (ret)
 				return ret;
 			spin_lock(&glob->lru_lock);
@@ -1403,7 +1406,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 
 	ret = 0;
 	if (mem_type > 0) {
-		ret = ttm_bo_force_list_clean(bdev, mem_type);
+		ret = ttm_bo_force_list_clean(bdev, mem_type, true);
 		if (ret) {
 			pr_err("Cleanup eviction failed\n");
 			return ret;
@@ -1419,7 +1422,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_clean_mm);
 
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc)
 {
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 
@@ -1433,7 +1437,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		return 0;
 	}
 
-	return ttm_bo_force_list_clean(bdev, mem_type);
+	return ttm_bo_force_list_clean(bdev, mem_type, force_alloc);
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -3
index 184340d..28f8e4f 100644
@@ -430,7 +430,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
 	if (dev_priv->cman)
 		vmw_cmdbuf_remove_pool(dev_priv->cman);
 	if (dev_priv->has_mob) {
-		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
 		vmw_otables_takedown(dev_priv);
 	}
 	if (dev_priv->cman)
@@ -463,7 +463,7 @@ static void vmw_release_device_early(struct vmw_private *dev_priv)
 		vmw_cmdbuf_remove_pool(dev_priv->cman);
 
 	if (dev_priv->has_mob) {
-		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
 		vmw_otables_takedown(dev_priv);
 	}
 }
@@ -1342,7 +1342,7 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
 	if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
 		dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
 		spin_unlock(&dev_priv->svga_lock);
-		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
+		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM, true))
 			DRM_ERROR("Failed evicting VRAM buffers.\n");
 		vmw_write(dev_priv, SVGA_REG_ENABLE,
 			  SVGA_REG_ENABLE_HIDE |
include/drm/ttm/ttm_bo_api.h +4 -1
index 2142639..6b5db9c 100644
@@ -636,6 +636,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  *
  * @bdev: Pointer to a ttm_bo_device struct.
  * @mem_type: The memory type.
+ * @force_alloc: if true allow ttm pages allocation always
+ * regardless of zone memory account limit
  *
  * Evicts all buffers on the lru list of the memory type.
  * This is normally part of a VT switch or an
@@ -649,7 +651,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
  * -ERESTARTSYS: The call was interrupted by a signal while waiting to
  * evict a buffer.
  */
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc);
 
 /**
  * ttm_kmap_obj_virtual
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 1518080761-12952-3-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Re: [PATCH 3/4] drm/ttm: add input parameter force_alloc for ttm_bo_evict_mm

Am 08.02.2018 um 10:06 schrieb Roger He:

Quoted 3 lines

if true, allocate TTM pages regardless of zone global memory account limit. For suspend, We should avoid TTM memory allocate failure then result in suspend failure.

Why the extra parameter for amdgpu_bo_evict_vram ?

I can't think of an use case when we don't want this to succeed.

Christian.

Quoted 291 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |  2 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c       |  2 +-
  drivers/gpu/drm/qxl/qxl_object.c            |  4 ++--
  drivers/gpu/drm/radeon/radeon_device.c      |  6 +++---
  drivers/gpu/drm/radeon/radeon_object.c      |  5 +++--
  drivers/gpu/drm/radeon/radeon_object.h      |  3 ++-
  drivers/gpu/drm/ttm/ttm_bo.c                | 16 ++++++++++------
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c         |  6 +++---
  include/drm/ttm/ttm_bo_api.h                |  5 ++++-
  12 files changed, 34 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -1
index ee76b46..59ee12c 100644
@@ -763,7 +763,7 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
  	struct drm_device *dev = node->minor->dev;
  	struct amdgpu_device *adev = dev->dev_private;
 
-	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
+	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev, true));
  	return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index e3fa3d7..3c5f9ca 100644
@@ -2168,7 +2168,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  		}
  	}
  	/* evict vram memory */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
  	amdgpu_fence_driver_suspend(adev);
 
@@ -2178,7 +2178,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  	 * This second call to evict vram is to evict the gart page table
  	 * using the CPU.
  	 */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
  	pci_save_state(dev->pdev);
  	if (suspend) {
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
index 0338ef6..db813f9 100644
@@ -803,14 +803,14 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
  	return r;
  }
 
-int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool force_alloc)
  {
  	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
  	if (0 && (adev->flags & AMD_IS_APU)) {
  		/* Useless to evict on IGP chips */
  		return 0;
  	}
-	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM, force_alloc);
  }
 
  static const char *amdgpu_vram_names[] = {
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -1
index c2b02f5..6724cdc 100644
@@ -227,7 +227,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
  			     u64 min_offset, u64 max_offset,
  			     u64 *gpu_addr);
  int amdgpu_bo_unpin(struct amdgpu_bo *bo);
-int amdgpu_bo_evict_vram(struct amdgpu_device *adev);
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool force_alloc);
  int amdgpu_bo_init(struct amdgpu_device *adev);
  void amdgpu_bo_fini(struct amdgpu_device *adev);
  int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
index 8d4a5be..c9627ef 100644
@@ -702,7 +702,7 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime)
  	}
 
  	NV_DEBUG(drm, "evicting buffers...\n");
-	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
+	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM, true);
 
  	NV_DEBUG(drm, "waiting for kernel channels to go idle...\n");
  	if (drm->cechan) {
drivers/gpu/drm/qxl/qxl_object.c +2 -2
index f6b80fe..d8d26c8 100644
@@ -350,10 +350,10 @@ int qxl_bo_check_id(struct qxl_device *qdev, struct qxl_bo *bo)
 
  int qxl_surf_evict(struct qxl_device *qdev)
  {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV, true);
  }
 
  int qxl_vram_evict(struct qxl_device *qdev)
  {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM, true);
  }
drivers/gpu/drm/radeon/radeon_device.c +3 -3
index 8d3e3d2..c11ee06 100644
@@ -1522,7 +1522,7 @@ void radeon_device_fini(struct radeon_device *rdev)
  	DRM_INFO("radeon: finishing device.\n");
  	rdev->shutdown = true;
  	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
  	radeon_fini(rdev);
  	if (!pci_is_thunderbolt_attached(rdev->pdev))
  		vga_switcheroo_unregister_client(rdev->pdev);
@@ -1607,7 +1607,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool suspend,
  		}
  	}
  	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
  	/* wait for gpu to finish processing current batch */
  	for (i = 0; i < RADEON_NUM_RINGS; i++) {
@@ -1626,7 +1626,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool suspend,
  	 * This second call to evict vram is to evict the gart page table
  	 * using the CPU.
  	 */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
  	radeon_agp_suspend(rdev);
 
drivers/gpu/drm/radeon/radeon_object.c +3 -2
index 15404af..99a9a45 100644
@@ -420,7 +420,8 @@ int radeon_bo_unpin(struct radeon_bo *bo)
  	return r;
  }
 
-int radeon_bo_evict_vram(struct radeon_device *rdev)
+int
+radeon_bo_evict_vram(struct radeon_device *rdev, bool force_alloc)
  {
  	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
  	if (0 && (rdev->flags & RADEON_IS_IGP)) {
@@ -428,7 +429,7 @@ int radeon_bo_evict_vram(struct radeon_device *rdev)
  			/* Useless to evict on IGP chips */
  			return 0;
  	}
-	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM, force_alloc);
  }
 
  void radeon_bo_force_delete(struct radeon_device *rdev)
drivers/gpu/drm/radeon/radeon_object.h +2 -1
index 9ffd821..757ba88 100644
@@ -136,7 +136,8 @@ extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
  extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
  				    u64 max_offset, u64 *gpu_addr);
  extern int radeon_bo_unpin(struct radeon_bo *bo);
-extern int radeon_bo_evict_vram(struct radeon_device *rdev);
+extern int radeon_bo_evict_vram(struct radeon_device *rdev,
+				bool force_alloc);
  extern void radeon_bo_force_delete(struct radeon_device *rdev);
  extern int radeon_bo_init(struct radeon_device *rdev);
  extern void radeon_bo_fini(struct radeon_device *rdev);
drivers/gpu/drm/ttm/ttm_bo.c +10 -6
index a907311..31d10f1 100644
@@ -1342,15 +1342,17 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
  EXPORT_SYMBOL(ttm_bo_create);
 
  static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-				   unsigned mem_type)
+			unsigned mem_type, bool force_alloc)
  {
-	struct ttm_operation_ctx ctx = { false, false };
+	struct ttm_operation_ctx ttm_opt_ctx = { false, false };
  	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
  	struct ttm_bo_global *glob = bdev->glob;
  	struct dma_fence *fence;
  	int ret;
  	unsigned i;
 
+	if (force_alloc)
+		ttm_opt_ctx.flags = TTM_OPT_FLAG_FORCE_ALLOC;
  	/*
  	 * Can't use standard list traversal since we're unlocking.
  	 */
@@ -1359,7 +1361,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
  		while (!list_empty(&man->lru[i])) {
  			spin_unlock(&glob->lru_lock);
-			ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx);
+			ret = ttm_mem_evict_first(bdev, mem_type, NULL,
+						  &ttm_opt_ctx);
  			if (ret)
  				return ret;
  			spin_lock(&glob->lru_lock);
@@ -1403,7 +1406,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 
  	ret = 0;
  	if (mem_type > 0) {
-		ret = ttm_bo_force_list_clean(bdev, mem_type);
+		ret = ttm_bo_force_list_clean(bdev, mem_type, true);
  		if (ret) {
  			pr_err("Cleanup eviction failed\n");
  			return ret;
@@ -1419,7 +1422,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
  }
  EXPORT_SYMBOL(ttm_bo_clean_mm);
 
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc)
  {
  	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 
@@ -1433,7 +1437,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
  		return 0;
  	}
 
-	return ttm_bo_force_list_clean(bdev, mem_type);
+	return ttm_bo_force_list_clean(bdev, mem_type, force_alloc);
  }
  EXPORT_SYMBOL(ttm_bo_evict_mm);
 
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -3
index 184340d..28f8e4f 100644
@@ -430,7 +430,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
  	if (dev_priv->cman)
  		vmw_cmdbuf_remove_pool(dev_priv->cman);
  	if (dev_priv->has_mob) {
-		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
  		vmw_otables_takedown(dev_priv);
  	}
  	if (dev_priv->cman)
@@ -463,7 +463,7 @@ static void vmw_release_device_early(struct vmw_private *dev_priv)
  		vmw_cmdbuf_remove_pool(dev_priv->cman);
 
  	if (dev_priv->has_mob) {
-		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
  		vmw_otables_takedown(dev_priv);
  	}
  }
@@ -1342,7 +1342,7 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
  	if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
  		dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
  		spin_unlock(&dev_priv->svga_lock);
-		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
+		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM, true))
  			DRM_ERROR("Failed evicting VRAM buffers.\n");
  		vmw_write(dev_priv, SVGA_REG_ENABLE,
  			  SVGA_REG_ENABLE_HIDE |
include/drm/ttm/ttm_bo_api.h +2 -0
index 2142639..6b5db9c 100644
@@ -636,6 +636,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
   *
   * @bdev: Pointer to a ttm_bo_device struct.
   * @mem_type: The memory type.
+ * @force_alloc: if true allow ttm pages allocation always
+ * regardless of zone memory account limit
   *
   * Evicts all buffers on the lru list of the memory type.
   * This is normally part of a VT switch or an

include/drm/ttm/ttm_bo_api.h int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type); · line 658

Quoted 9 lines
include/drm/ttm/ttm_bo_api.h +2 -1
@@ -649,7 +651,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
   * -ERESTARTSYS: The call was interrupted by a signal while waiting to
   * evict a buffer.
   */
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc);
 
  /**
   * ttm_kmap_obj_virtual

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): c3465353-9dac-f0ba-a465-3c470b939f68-5C7GfCeVMHo@public.gmane.org

#8 lore raw

RE: [PATCH 3/4] drm/ttm: add input parameter force_alloc for ttm_bo_evict_mm

I can't think of an use case when we don't want this to succeed.

That is true. seems I can simplify more here.

Thanks
Roger(Hongbo.He)
-----Original Message-----
From: Koenig, Christian
Sent: Thursday, February 08, 2018 8:58 PM
To: He, Roger <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH 3/4] drm/ttm: add input parameter force_alloc for ttm_bo_evict_mm

Am 08.02.2018 um 10:06 schrieb Roger He:

Quoted 3 lines

if true, allocate TTM pages regardless of zone global memory account limit. For suspend, We should avoid TTM memory allocate failure then result in suspend failure.

Why the extra parameter for amdgpu_bo_evict_vram ?

I can't think of an use case when we don't want this to succeed.

Christian.

Quoted 308 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h  |  2 +-
  drivers/gpu/drm/nouveau/nouveau_drm.c       |  2 +-
  drivers/gpu/drm/qxl/qxl_object.c            |  4 ++--
  drivers/gpu/drm/radeon/radeon_device.c      |  6 +++---
  drivers/gpu/drm/radeon/radeon_object.c      |  5 +++--
  drivers/gpu/drm/radeon/radeon_object.h      |  3 ++-
  drivers/gpu/drm/ttm/ttm_bo.c                | 16 ++++++++++------
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c         |  6 +++---
  include/drm/ttm/ttm_bo_api.h                |  5 ++++-
  12 files changed, 34 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -1
index ee76b46..59ee12c 100644
@@ -763,7 +763,7 @@ static int amdgpu_debugfs_evict_vram(struct seq_file *m, void *data)
  	struct drm_device *dev = node->minor->dev;
  	struct amdgpu_device *adev = dev->dev_private;
 
-	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev));
+	seq_printf(m, "(%d)\n", amdgpu_bo_evict_vram(adev, true));
  	return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index e3fa3d7..3c5f9ca 100644
@@ -2168,7 +2168,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  		}
  	}
  	/* evict vram memory */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
  	amdgpu_fence_driver_suspend(adev);
 
@@ -2178,7 +2178,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  	 * This second call to evict vram is to evict the gart page table
  	 * using the CPU.
  	 */
-	amdgpu_bo_evict_vram(adev);
+	amdgpu_bo_evict_vram(adev, true);
 
  	pci_save_state(dev->pdev);
  	if (suspend) {
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -2
index 0338ef6..db813f9 100644
@@ -803,14 +803,14 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)
  	return r;
  }
 
-int amdgpu_bo_evict_vram(struct amdgpu_device *adev)
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool 
+force_alloc)
  {
  	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
  	if (0 && (adev->flags & AMD_IS_APU)) {
  		/* Useless to evict on IGP chips */
  		return 0;
  	}
-	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&adev->mman.bdev, TTM_PL_VRAM, force_alloc);
  }
 
  static const char *amdgpu_vram_names[] = { diff --git 

a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index c2b02f5..6724cdc 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -0
@@ -227,7 +227,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
  			     u64 min_offset, u64 max_offset,
  			     u64 *gpu_addr);
  int amdgpu_bo_unpin(struct amdgpu_bo *bo); -int 
 amdgpu_bo_evict_vram(struct amdgpu_device *adev);
+int amdgpu_bo_evict_vram(struct amdgpu_device *adev, bool 
+force_alloc);
  int amdgpu_bo_init(struct amdgpu_device *adev);
  void amdgpu_bo_fini(struct amdgpu_device *adev);
  int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo, diff --git 

a/drivers/gpu/drm/nouveau/nouveau_drm.c
b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 8d4a5be..c9627ef 100644

drivers/gpu/drm/nouveau/nouveau_drm.c +1 -1
@@ -702,7 +702,7 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime)
  	}
 
  	NV_DEBUG(drm, "evicting buffers...\n");
-	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
+	ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM, true);
 
  	NV_DEBUG(drm, "waiting for kernel channels to go idle...\n");
  	if (drm->cechan) {
drivers/gpu/drm/qxl/qxl_object.c +2 -2
index f6b80fe..d8d26c8 100644
@@ -350,10 +350,10 @@ int qxl_bo_check_id(struct qxl_device *qdev, 
 struct qxl_bo *bo)
 
  int qxl_surf_evict(struct qxl_device *qdev)
  {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_PRIV, true);
  }
 
  int qxl_vram_evict(struct qxl_device *qdev)
  {
-	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&qdev->mman.bdev, TTM_PL_VRAM, true);
  }
drivers/gpu/drm/radeon/radeon_device.c +2 -2
index 8d3e3d2..c11ee06 100644
@@ -1522,7 +1522,7 @@ void radeon_device_fini(struct radeon_device *rdev)
  	DRM_INFO("radeon: finishing device.\n");
  	rdev->shutdown = true;
  	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
  	radeon_fini(rdev);
  	if (!pci_is_thunderbolt_attached(rdev->pdev))
  		vga_switcheroo_unregister_client(rdev->pdev);
@@ -1607,7 +1607,7 @@ int radeon_suspend_kms(struct drm_device *dev, bool suspend,
  		}
  	}
  	/* evict vram memory */
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
  	/* wait for gpu to finish processing current batch */
  	for (i = 0; i < RADEON_NUM_RINGS; i++) { @@ -1626,7 +1626,7 @@ int 

radeon_suspend_kms(struct drm_device *dev, bool suspend,
* This second call to evict vram is to evict the gart page table
* using the CPU.
*/

drivers/gpu/drm/radeon/radeon_device.c +1 -1
-	radeon_bo_evict_vram(rdev);
+	radeon_bo_evict_vram(rdev, true);
 
  	radeon_agp_suspend(rdev);
drivers/gpu/drm/radeon/radeon_object.c +2 -1
index 15404af..99a9a45 100644
@@ -420,7 +420,8 @@ int radeon_bo_unpin(struct radeon_bo *bo)
  	return r;
  }
 
-int radeon_bo_evict_vram(struct radeon_device *rdev)
+int
+radeon_bo_evict_vram(struct radeon_device *rdev, bool force_alloc)
  {
  	/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
  	if (0 && (rdev->flags & RADEON_IS_IGP)) { @@ -428,7 +429,7 @@ int 

radeon_bo_evict_vram(struct radeon_device *rdev)
/* Useless to evict on IGP chips */ return 0;
}

drivers/gpu/drm/radeon/radeon_object.c +1 -1
-	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
+	return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM, force_alloc);
  }
 
  void radeon_bo_force_delete(struct radeon_device *rdev) diff --git 

a/drivers/gpu/drm/radeon/radeon_object.h
b/drivers/gpu/drm/radeon/radeon_object.h
index 9ffd821..757ba88 100644

drivers/gpu/drm/radeon/radeon_object.h +2 -0
@@ -136,7 +136,8 @@ extern int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr);
  extern int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain,
  				    u64 max_offset, u64 *gpu_addr);
  extern int radeon_bo_unpin(struct radeon_bo *bo); -extern int 
 radeon_bo_evict_vram(struct radeon_device *rdev);
+extern int radeon_bo_evict_vram(struct radeon_device *rdev,
+				bool force_alloc);
  extern void radeon_bo_force_delete(struct radeon_device *rdev);
  extern int radeon_bo_init(struct radeon_device *rdev);
  extern void radeon_bo_fini(struct radeon_device *rdev); diff --git 

a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index a907311..31d10f1 100644

drivers/gpu/drm/ttm/ttm_bo.c +7 -4
@@ -1342,15 +1342,17 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
  EXPORT_SYMBOL(ttm_bo_create);
 
  static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-				   unsigned mem_type)
+			unsigned mem_type, bool force_alloc)
  {
-	struct ttm_operation_ctx ctx = { false, false };
+	struct ttm_operation_ctx ttm_opt_ctx = { false, false };
  	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
  	struct ttm_bo_global *glob = bdev->glob;
  	struct dma_fence *fence;
  	int ret;
  	unsigned i;
 
+	if (force_alloc)
+		ttm_opt_ctx.flags = TTM_OPT_FLAG_FORCE_ALLOC;
  	/*
  	 * Can't use standard list traversal since we're unlocking.
  	 */
@@ -1359,7 +1361,8 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
  		while (!list_empty(&man->lru[i])) {
  			spin_unlock(&glob->lru_lock);
-			ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx);
+			ret = ttm_mem_evict_first(bdev, mem_type, NULL,
+						  &ttm_opt_ctx);
  			if (ret)
  				return ret;
  			spin_lock(&glob->lru_lock);
@@ -1403,7 +1406,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, 
 unsigned mem_type)
 
  	ret = 0;
  	if (mem_type > 0) {
-		ret = ttm_bo_force_list_clean(bdev, mem_type);
+		ret = ttm_bo_force_list_clean(bdev, mem_type, true);
  		if (ret) {
  			pr_err("Cleanup eviction failed\n");

return ret;

drivers/gpu/drm/ttm/ttm_bo.c +3 -2
@@ -1419,7 +1422,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
  }
  EXPORT_SYMBOL(ttm_bo_clean_mm);
 
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc)
  {
  	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 
@@ -1433,7 +1437,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
  		return 0;
  	}
 
-	return ttm_bo_force_list_clean(bdev, mem_type);
+	return ttm_bo_force_list_clean(bdev, mem_type, force_alloc);
  }
  EXPORT_SYMBOL(ttm_bo_evict_mm);
 
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +3 -3
index 184340d..28f8e4f 100644
@@ -430,7 +430,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
  	if (dev_priv->cman)
  		vmw_cmdbuf_remove_pool(dev_priv->cman);
  	if (dev_priv->has_mob) {
-		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		(void) ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
  		vmw_otables_takedown(dev_priv);
  	}
  	if (dev_priv->cman)
@@ -463,7 +463,7 @@ static void vmw_release_device_early(struct vmw_private *dev_priv)
  		vmw_cmdbuf_remove_pool(dev_priv->cman);
 
  	if (dev_priv->has_mob) {
-		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB);
+		ttm_bo_evict_mm(&dev_priv->bdev, VMW_PL_MOB, true);
  		vmw_otables_takedown(dev_priv);
  	}
  }
@@ -1342,7 +1342,7 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
  	if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
  		dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
  		spin_unlock(&dev_priv->svga_lock);
-		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
+		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM, true))
  			DRM_ERROR("Failed evicting VRAM buffers.\n");
  		vmw_write(dev_priv, SVGA_REG_ENABLE,
  			  SVGA_REG_ENABLE_HIDE |
(quoted diff) +0 -0

b/include/drm/ttm/ttm_bo_api.h index 2142639..6b5db9c 100644

include/drm/ttm/ttm_bo_api.h +2 -0
@@ -636,6 +636,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
   *
   * @bdev: Pointer to a ttm_bo_device struct.
   * @mem_type: The memory type.
+ * @force_alloc: if true allow ttm pages allocation always
+ * regardless of zone memory account limit
   *
   * Evicts all buffers on the lru list of the memory type.
   * This is normally part of a VT switch or an @@ -649,7 +651,8 @@ 

int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
* -ERESTARTSYS: The call was interrupted by a signal while waiting to
* evict a buffer.
*/

include/drm/ttm/ttm_bo_api.h int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type); · line 658

Quoted 6 lines
include/drm/ttm/ttm_bo_api.h +2 -1
-int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type);
+int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type,
+			bool force_alloc);
 
  /**
   * ttm_kmap_obj_virtual

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#9 lore raw

PATCH 4/4 drm/ttm: check if the mem free space is under lower limit

In reply to Roger He

mem free space and lower limit both include two parts:
system memory and swap space.

For the OOM triggered by TTM, that is the case as below:
swap space is full of swapped pages and then system memory will be filled up with ttm pages. and then any memory allocation request will run into OOM.

to cover two cases:
a. if no swap disk at all or free swap space is under
swap mem limit but available system mem is bigger than sys mem limit, allow TTM allocation;

b. if the available system mem is less than sys mem limit
but free swap space is bigger than swap mem limit, allow TTM allocation.

v2: merge two memory limit(swap and system) into one
v3: keep original behavior except with ttm->page_flags
TTM_PAGE_FLAG_NO_RETRY

---
 drivers/gpu/drm/ttm/ttm_memory.c         | 34 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/ttm/ttm_page_alloc.c     | 22 ++++++++++++++-------
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 31 ++++++++++++++++++-----------
 include/drm/ttm/ttm_memory.h             |  5 +++++
 4 files changed, 73 insertions(+), 19 deletions(-)
drivers/gpu/drm/ttm/ttm_memory.c +34 -0
index aa0c381..16ab324 100644
@@ -36,6 +36,7 @@
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/swap.h>
 
 #define TTM_MEMORY_ALLOC_RETRIES 4
 
@@ -375,6 +376,11 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
 
 	si_meminfo(&si);
 
+	/* lower limit of swap space and 256MB is enough */
+	glob->lower_mem_limit = 256 << 8;
+	/* lower limit of ram and keep consistent with each zone->emer_mem */
+	glob->lower_mem_limit += si.totalram >> 2;
+
 	ret = ttm_mem_init_kernel_zone(glob, &si);
 	if (unlikely(ret != 0))
 		goto out_no_zone;
@@ -469,6 +475,34 @@ void ttm_mem_global_free(struct ttm_mem_global *glob,
 }
 EXPORT_SYMBOL(ttm_mem_global_free);
 
+/*
+ * check if the available mem is under total memory limit
+ *
+ * a. if no swap disk at all or free swap space is under swap_mem_limit
+ * but available system mem is bigger than sys_mem_limit, allow TTM
+ * allocation;
+ *
+ * b. if the available system mem is less than sys_mem_limit but free
+ * swap disk is bigger than swap_mem_limit, allow TTM allocation.
+ */
+bool
+ttm_check_under_lowerlimit(struct ttm_mem_global *glob, bool force_alloc)
+{
+	bool ret = false;
+	uint64_t available;
+
+	/* always allow allocation, e.g. when serving page fault or suspend */
+	if (force_alloc)
+		return false;
+
+	available = get_nr_swap_pages() + si_mem_available();
+	if (available < glob->lower_mem_limit)
+		ret = true;
+
+	return ret;
+}
+EXPORT_SYMBOL(ttm_check_under_lowerlimit);
+
 static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
 				  struct ttm_mem_zone *single_zone,
 				  uint64_t amount, bool reserve)
drivers/gpu/drm/ttm/ttm_page_alloc.c +15 -7
index 5edcd89..1457a1c 100644
@@ -1094,7 +1094,8 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
 int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
 	struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
-	unsigned i;
+	unsigned i, unpopulate_count = 0;
+	bool force_alloc = true;
 	int ret;
 
 	if (ttm->state != tt_unpopulated)
@@ -1102,17 +1103,20 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 
 	ret = ttm_get_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
 			    ttm->caching_state);
-	if (unlikely(ret != 0)) {
-		ttm_pool_unpopulate_helper(ttm, 0);
-		return ret;
-	}
+	if (unlikely(ret != 0))
+		goto error_populate;
+
+	if (ttm->page_flags & TTM_PAGE_FLAG_NO_RETRY)
+		force_alloc = ctx->flags & TTM_OPT_FLAG_FORCE_ALLOC;
+	if (ttm_check_under_lowerlimit(mem_glob, force_alloc))
+		goto error_populate;
 
 	for (i = 0; i < ttm->num_pages; ++i) {
 		ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
 						PAGE_SIZE, ctx);
 		if (unlikely(ret != 0)) {
-			ttm_pool_unpopulate_helper(ttm, i);
-			return -ENOMEM;
+			unpopulate_count = i;
+			goto error_populate;
 		}
 	}
 
@@ -1126,6 +1130,10 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 
 	ttm->state = tt_unbound;
 	return 0;
+
+error_populate:
+	ttm_pool_unpopulate_helper(ttm, unpopulate_count);
+	return -ENOMEM;
 }
 EXPORT_SYMBOL(ttm_pool_populate);
 
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +19 -12
index 354e0e1..39b2a42 100644
@@ -934,6 +934,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 	struct dma_pool *pool;
 	struct dma_page *d_page;
 	enum pool_type type;
+	bool force_alloc = true;
 	unsigned i;
 	int ret;
 
@@ -943,6 +944,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 	INIT_LIST_HEAD(&ttm_dma->pages_list);
 	i = 0;
 
+	if (ttm->page_flags & TTM_PAGE_FLAG_NO_RETRY)
+		force_alloc = ctx->flags & TTM_OPT_FLAG_FORCE_ALLOC;
 	type = ttm_to_type(ttm->page_flags, ttm->caching_state);
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	if (ttm->page_flags & TTM_PAGE_FLAG_DMA32)
@@ -964,12 +967,13 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 		if (!d_page)
 			break;
 
+		if (ttm_check_under_lowerlimit(mem_glob, force_alloc))
+			goto error_populate;
+
 		ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
 						pool->size, ctx);
-		if (unlikely(ret != 0)) {
-			ttm_dma_unpopulate(ttm_dma, dev);
-			return -ENOMEM;
-		}
+		if (unlikely(ret != 0))
+			goto error_populate;
 
 		d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT;
 		for (j = i + 1; j < (i + HPAGE_PMD_NR); ++j) {
@@ -996,17 +1000,16 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 
 	while (num_pages) {
 		d_page = ttm_dma_pool_get_pages(pool, ttm_dma, i);
-		if (!d_page) {
-			ttm_dma_unpopulate(ttm_dma, dev);
-			return -ENOMEM;
-		}
+		if (!d_page)
+			goto error_populate;
+
+		if (ttm_check_under_lowerlimit(mem_glob, force_alloc))
+			goto error_populate;
 
 		ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
 						pool->size, ctx);
-		if (unlikely(ret != 0)) {
-			ttm_dma_unpopulate(ttm_dma, dev);
-			return -ENOMEM;
-		}
+		if (unlikely(ret != 0))
+			goto error_populate;
 
 		d_page->vaddr |= VADDR_FLAG_UPDATED_COUNT;
 		++i;
@@ -1023,6 +1026,10 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 
 	ttm->state = tt_unbound;
 	return 0;
+
+error_populate:
+	ttm_dma_unpopulate(ttm_dma, dev);
+	return -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(ttm_dma_populate);
 
include/drm/ttm/ttm_memory.h +5 -0
index 8936285..3aa30d6 100644
@@ -49,6 +49,8 @@
  * @work: The workqueue callback for the shrink queue.
  * @lock: Lock to protect the @shrink - and the memory accounting members,
  * that is, essentially the whole structure with some exceptions.
+ * @lower_mem_limit: include lower limit of swap space and lower limit of
+ * system memory.
  * @zones: Array of pointers to accounting zones.
  * @num_zones: Number of populated entries in the @zones array.
  * @zone_kernel: Pointer to the kernel zone.
@@ -67,6 +69,7 @@ struct ttm_mem_global {
 	struct workqueue_struct *swap_queue;
 	struct work_struct work;
 	spinlock_t lock;
+	uint64_t lower_mem_limit;
 	struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
 	unsigned int num_zones;
 	struct ttm_mem_zone *zone_kernel;
@@ -90,4 +93,6 @@ extern void ttm_mem_global_free_page(struct ttm_mem_global *glob,
 				     struct page *page, uint64_t size);
 extern size_t ttm_round_pot(size_t size);
 extern uint64_t ttm_get_kernel_zone_memory_size(struct ttm_mem_global *glob);
+extern bool ttm_check_under_lowerlimit(struct ttm_mem_global *glob,
+					bool force_alloc);
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 1518080761-12952-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#11 lore raw

Am 08.02.2018 um 10:05 schrieb Roger He:

Quoted 3 lines

for saving memory and more bit flag can be used in future

Quoted 71 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++--
  drivers/gpu/drm/ttm/ttm_bo.c               | 3 ++-
  include/drm/ttm/ttm_bo_api.h               | 7 +++++--
  4 files changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -2
index eaa3cb0..dc34b50 100644
@@ -346,8 +346,8 @@ static int amdgpu_cs_bo_validate(struct amdgpu_cs_parser *p,
  	struct ttm_operation_ctx ctx = {
  		.interruptible = true,
  		.no_wait_gpu = false,
-		.allow_reserved_eviction = false,
-		.resv = bo->tbo.resv
+		.resv = bo->tbo.resv,
+		.flags = 0
  	};
  	uint32_t domain;
  	int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
index 512612e..0338ef6 100644
@@ -341,8 +341,8 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
  	struct ttm_operation_ctx ctx = {
  		.interruptible = !kernel,
  		.no_wait_gpu = false,
-		.allow_reserved_eviction = true,
-		.resv = resv
+		.resv = resv,
+		.flags = TTM_OPT_FLAG_ALLOW_RES_EVICT
  	};
  	struct amdgpu_bo *bo;
  	enum ttm_bo_type type;
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
index d90b1cf1..a907311 100644
@@ -730,7 +730,8 @@ static bool ttm_bo_evict_swapout_allowable(struct ttm_buffer_object *bo,
  	*locked = false;
  	if (bo->resv == ctx->resv) {
  		reservation_object_assert_held(bo->resv);
-		if (ctx->allow_reserved_eviction || !list_empty(&bo->ddestroy))
+		if (ctx->flags & TTM_OPT_FLAG_ALLOW_RES_EVICT
+		    || !list_empty(&bo->ddestroy))
  			ret = true;
  	} else {
  		*locked = reservation_object_trylock(bo->resv);
include/drm/ttm/ttm_bo_api.h +1 -2
index 2cd025c..872ff6c 100644
@@ -263,8 +263,8 @@ struct ttm_bo_kmap_obj {
   *
   * @interruptible: Sleep interruptible if sleeping.
   * @no_wait_gpu: Return immediately if the GPU is busy.
- * @allow_reserved_eviction: Allow eviction of reserved BOs.
   * @resv: Reservation object to allow reserved evictions with.
+ * @flags: Including the following flags
   *
   * Context for TTM operations like changing buffer placement or general memory
   * allocation.
@@ -272,11 +272,14 @@ struct ttm_bo_kmap_obj {
  struct ttm_operation_ctx {
  	bool interruptible;
  	bool no_wait_gpu;
-	bool allow_reserved_eviction;
  	struct reservation_object *resv;

include/drm/ttm/ttm_bo_api.h struct ttm_bo_kmap_obj { · line 285

Quoted 10 lines
include/drm/ttm/ttm_bo_api.h +4 -0
  	uint64_t bytes_moved;
+	uint32_t flags;
  };
 
+/* Allow eviction of reserved BOs */
+#define TTM_OPT_FLAG_ALLOW_RES_EVICT	0x1
+
  /**
   * ttm_bo_reference - reference a struct ttm_buffer_object
   *

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx