From patchwork Wed Mar 5 11:35:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sourab.gupta@intel.com X-Patchwork-Id: 3773401 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D942E9F1EE for ; Wed, 5 Mar 2014 11:35:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0274F20251 for ; Wed, 5 Mar 2014 11:35:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1A66A20213 for ; Wed, 5 Mar 2014 11:35:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F2B5BFA558; Wed, 5 Mar 2014 03:35:41 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id 6F626FA552 for ; Wed, 5 Mar 2014 03:35:31 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 05 Mar 2014 03:35:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,592,1389772800"; d="scan'208";a="466990228" Received: from sourabgu-desktop.iind.intel.com ([10.223.82.69]) by orsmga001.jf.intel.com with ESMTP; 05 Mar 2014 03:35:16 -0800 From: sourab.gupta@intel.com To: intel-gfx@lists.freedesktop.org Date: Wed, 5 Mar 2014 17:05:40 +0530 Message-Id: <1394019340-8811-4-git-send-email-sourab.gupta@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1394019340-8811-1-git-send-email-sourab.gupta@intel.com> References: <1394019340-8811-1-git-send-email-sourab.gupta@intel.com> Cc: "Cc: Daniel Vetter" , Sourab Gupta , "Cc: Jesse Barnes" , Akash Goel , "Cc: Chris Wilson" Subject: [Intel-gfx] [RFC 3/3] drm/i915: Add the truncation logic for Stolen objects. X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sourab Gupta Adding the truncation logic for buffer objects with backing storage from stolen memory. The objects will be truncated when user marks them as purgeable and they are part of the inactive list. Testcase: igt/gem_stolen_mem Signed-off-by: Sourab Gupta Signed-off-by: Akash Goel Signed-off-by: Sourab Gupta --- drivers/gpu/drm/i915/i915_drv.h | 1 + drivers/gpu/drm/i915/i915_gem.c | 11 ++++++++++- drivers/gpu/drm/i915/i915_gem_stolen.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index b5f603f..02142c0 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -2443,6 +2443,7 @@ i915_gem_object_create_stolen_for_preallocated(struct drm_device *dev, u32 size); void i915_gem_object_move_to_stolen(struct drm_i915_gem_object *obj); void i915_gem_object_release_stolen(struct drm_i915_gem_object *obj); +void i915_gem_object_truncate_stolen(struct drm_i915_gem_object *obj); /* i915_gem_tiling.c */ static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index f57ca31..d106806 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2071,6 +2071,11 @@ i915_gem_object_move_to_inactive(struct drm_i915_gem_object *obj) obj->fenced_gpu_access = false; obj->active = 0; + + /* Truncate the stolen obj immediately if it is marked as purgeable */ + if(obj->stolen && (i915_gem_object_is_purgeable(obj) ) ) + i915_gem_object_truncate_stolen(obj); + drm_gem_object_unreference(&obj->base); WARN_ON(i915_verify_lists(dev)); @@ -4069,6 +4074,10 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data, if (i915_gem_object_is_purgeable(obj) && obj->pages == NULL) i915_gem_object_truncate(obj); + /* if the stolen mem object is no longer active, discard its backing storage */ + if (obj->stolen && i915_gem_object_is_purgeable(obj) && i915_gem_object_is_inactive(obj)) + i915_gem_object_truncate_stolen(obj); + args->retained = obj->madv != __I915_MADV_PURGED; out: @@ -4187,7 +4196,7 @@ void i915_gem_free_object(struct drm_gem_object *gem_obj) /* Stolen objects don't hold a ref, but do hold pin count. Fix that up * before progressing. */ - if (obj->stolen) + if ((obj->stolen) && (obj->madv != __I915_MADV_PURGED)) i915_gem_object_unpin_pages(obj); if (WARN_ON(obj->pages_pin_count)) diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c index 6758ba4..1ecc447 100644 --- a/drivers/gpu/drm/i915/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/i915_gem_stolen.c @@ -471,6 +471,11 @@ i915_gem_object_move_to_stolen(struct drm_i915_gem_object *obj) if (size == 0) return; + if (obj->madv != I915_MADV_WILLNEED) { + DRM_ERROR("Attempting to allocate a purgeable object\n"); + return; + } + /* Check if already shmem space has been allocated for the object * or not. We cannot rely upon on the value of 'pages' field for this. * As even though if the 'pages' field is NULL, it does not actually @@ -549,3 +554,30 @@ i915_gem_object_release_stolen(struct drm_i915_gem_object *obj) obj->stolen = NULL; } } + +/* + * This function truncates stolen objects to reclaim their backing storage + * from stolen mem area. Currently objects are truncated when they are + * marked as purgeable and are in inactive list. + * Stolen objects are not considered for truncation by shrinker, as their + * physical pages are kept as pinned throughout their existance. + */ +void +i915_gem_object_truncate_stolen(struct drm_i915_gem_object *obj) +{ + struct i915_vma *vma_temp,*next; + + BUG_ON(!obj->stolen); + + list_for_each_entry_safe(vma_temp, next, &obj->vma_list, vma_link) + WARN_ON(i915_vma_unbind(vma_temp)); + + i915_gem_object_unpin_pages(obj); + i915_gem_object_put_pages(obj); + + /* Release the stolen space */ + i915_gem_object_release_stolen(obj); + + obj->madv = __I915_MADV_PURGED; + +}