Skip to contentSkip to conversation

ttm: Allow system memory as a busy placement.

PATCH New Thomas Hellstrom 1 participant 2 messages Jan 16, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ttm: Allow system memory as a busy placement.

This is needed to fix a vmwgfx memory usage bug.

---
 drivers/gpu/drm/ttm/ttm_bo.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +8 -0
index da37021..c7733c3 100644
@@ -951,6 +951,14 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		ttm_flag_masked(&cur_flags, placement->busy_placement[i],
 				~TTM_PL_MASK_MEMTYPE);
 
+
+		if (mem_type == TTM_PL_SYSTEM) {
+			mem->mem_type = mem_type;
+			mem->placement = cur_flags;
+			mem->mm_node = NULL;
+			return 0;
+		}
+
 		ret = ttm_bo_mem_force_space(bo, mem_type, placement, mem,
 						interruptible, no_wait);
 		if (ret == 0 && mem->mm_node) {
Signature · 10 lines
1.6.2.5


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
--
#1 lore raw

PATCH 2/2 vmwgfx: Optimize memory footprint for DMA buffers.

Use VRAM whenever there is free space for DMA buffers, but use system GMR memory if using VRAM would cause an eviction.

This significantly reduces the guest system memory usage for VMs with a large amount of VRAM allocated.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c   |    9 +++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h      |    1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c  |   19 +++++++++++++++++++
 drivers/gpu/drm/vmwgfx/vmwgfx_resource.c |    2 +-
 4 files changed, 30 insertions(+), 1 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c +9 -0
index 37a8192..825ebe3 100644
@@ -48,6 +48,15 @@ struct ttm_placement vmw_vram_placement = {
 	.busy_placement = &vram_placement_flags
 };
 
+struct ttm_placement vmw_vram_sys_placement = {
+	.fpfn = 0,
+	.lpfn = 0,
+	.num_placement = 1,
+	.placement = &vram_placement_flags,
+	.num_busy_placement = 1,
+	.busy_placement = &sys_placement_flags
+};
+
 struct ttm_placement vmw_vram_ne_placement = {
 	.fpfn = 0,
 	.lpfn = 0,
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +1 -0
index 7532b9b..50529a7 100644
@@ -404,6 +404,7 @@ extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
 
 extern struct ttm_placement vmw_vram_placement;
 extern struct ttm_placement vmw_vram_ne_placement;
+extern struct ttm_placement vmw_vram_sys_placement;
 extern struct ttm_placement vmw_sys_placement;
 extern struct ttm_bo_driver vmw_bo_driver;
 extern int vmw_dma_quiescent(struct drm_device *dev);
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c +19 -0
index 2e92da5..d69caf9 100644
@@ -490,10 +490,29 @@ static int vmw_validate_single_buffer(struct vmw_private *dev_priv,
 	if (vmw_dmabuf_gmr(bo) != SVGA_GMR_NULL)
 		return 0;
 
+	/**
+	 * Put BO in VRAM, only if there is space.
+	 */
+
+	ret = ttm_bo_validate(bo, &vmw_vram_sys_placement, true, false);
+	if (unlikely(ret == -ERESTARTSYS))
+		return ret;
+
+	/**
+	 * Otherwise, set it up as GMR.
+	 */
+
+	if (vmw_dmabuf_gmr(bo) != SVGA_GMR_NULL)
+		return 0;
+
 	ret = vmw_gmr_bind(dev_priv, bo);
 	if (likely(ret == 0 || ret == -ERESTARTSYS))
 		return ret;
 
+	/**
+	 * If that failed, try VRAM again, this time evicting
+	 * previous contents.
+	 */
 
 	ret = ttm_bo_validate(bo, &vmw_vram_placement, true, false);
 	return ret;
drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +1 -1
index e087807..e01db12 100644
@@ -872,7 +872,7 @@ int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
 	}
 
 	ret = vmw_dmabuf_init(dev_priv, &vmw_user_bo->dma, req->size,
-			      &vmw_vram_placement, true,
+			      &vmw_vram_sys_placement, true,
 			      &vmw_user_dmabuf_destroy);
 	if (unlikely(ret != 0))
 		return ret;
Signature · 10 lines
1.6.2.5


------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
--