From patchwork Thu Mar 22 14:14:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 10301591 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6729F600F6 for ; Thu, 22 Mar 2018 14:01:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B997285CD for ; Thu, 22 Mar 2018 14:01:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A3D1285D4; Thu, 22 Mar 2018 14:01:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF3BD285B7 for ; Thu, 22 Mar 2018 14:01:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A20776EC27; Thu, 22 Mar 2018 14:01:00 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8B4D36EC26 for ; Thu, 22 Mar 2018 14:00:53 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2018 07:00:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,345,1517904000"; d="scan'208";a="30323522" Received: from intel-desktop.iind.intel.com ([10.223.26.163]) by fmsmga002.fm.intel.com with ESMTP; 22 Mar 2018 07:00:51 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Thu, 22 Mar 2018 19:44:55 +0530 Message-Id: <1521728098-3669-3-git-send-email-praveen.paneri@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1521728098-3669-1-git-send-email-praveen.paneri@intel.com> References: <1521728098-3669-1-git-send-email-praveen.paneri@intel.com> Subject: [Intel-gfx] [RFC 2/5] drm/i915: Calculate total shmem GFX memory consumed X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, nidhi1.gupta@intel.com MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Sourab Gupta There are some GFX buffers e.g. ringbuffers, ctx buffers, etc. which are not associated with any drm fd. Thus, the sum of the shmem memory consumed by processes would be less than the total memory actually consumed in the system. This patch keeps track of all shmem memory consumptions in the system which is given out by the sysfs interface introduced earlier. Signed-off-by: Sourab Gupta Signed-off-by: Akash Goel Signed-off-by: Nidhi Gupta Signed-off-by: Praveen Paneri --- drivers/gpu/drm/i915/i915_drv.h | 2 ++ drivers/gpu/drm/i915/i915_gem.c | 38 +++++++++++++++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_object.h | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index c23ba28..b760133 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -980,6 +980,8 @@ struct i915_gem_mm { spinlock_t object_stat_lock; u64 object_memory; u32 object_count; + + size_t phys_mem_total; }; #define I915_IDLE_ENGINES_TIMEOUT (200) /* in ms */ diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 49555ea..6116e37 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2313,6 +2313,17 @@ static void i915_gem_object_free_mmap_offset(struct drm_i915_gem_object *obj) */ shmem_truncate_range(file_inode(obj->base.filp), 0, (loff_t)-1); obj->mm.madv = __I915_MADV_PURGED; + + /* + * Mark the object as not having backing pages, as physical space + * returned back to kernel + */ + if (obj->has_backing_pages == 1) { + struct drm_i915_private *dev_priv = obj->base.dev->dev_private; + + dev_priv->mm.phys_mem_total -= obj->base.size; + obj->has_backing_pages = 0; + } obj->mm.pages = ERR_PTR(-EFAULT); } @@ -2600,6 +2611,13 @@ static int i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj) __i915_gem_object_set_pages(obj, st, sg_page_sizes); + if (obj->has_backing_pages == 0) { + struct drm_i915_private *dev_priv = obj->base.dev->dev_private; + + dev_priv->mm.phys_mem_total += obj->base.size; + obj->has_backing_pages = 1; + } + return 0; err_sg: @@ -4667,6 +4685,11 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj, init_request_active(&obj->frontbuffer_write, frontbuffer_retire); obj->mm.madv = I915_MADV_WILLNEED; + /* + * Mark the object as not having backing pages, as no allocation + * for it yet + */ + obj->has_backing_pages = 0; INIT_LIST_HEAD(&obj->pid_info); INIT_RADIX_TREE(&obj->mm.get_page.radix, GFP_KERNEL | __GFP_NOWARN); mutex_init(&obj->mm.get_page.lock); @@ -4858,6 +4881,13 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915, if (obj->base.import_attach) drm_prime_gem_destroy(&obj->base, NULL); + if (!obj->stolen && (obj->has_backing_pages == 1)) { + struct drm_i915_private *dev_priv = + obj->base.dev->dev_private; + + dev_priv->mm.phys_mem_total -= obj->base.size; + obj->has_backing_pages = 0; + } reservation_object_fini(&obj->__builtin_resv); drm_gem_object_release(&obj->base); @@ -6318,6 +6348,8 @@ static int i915_obj_shared_count(struct drm_i915_gem_object *obj, u64 nr_bytes = i915_obj_get_shmem_pages_alloced(obj)*PAGE_SIZE; + if (obj->has_backing_pages) + stats->num_obj_allocated++; if (obj->mm.madv == I915_MADV_DONTNEED) { stats->num_obj_purgeable++; if (nr_bytes != 0) @@ -6325,7 +6357,6 @@ static int i915_obj_shared_count(struct drm_i915_gem_object *obj, } if (nr_bytes != 0) { - stats->num_obj_allocated++; if (obj_shared_count > 1) { stats->phys_space_allocated_shared += nr_bytes; stats->phys_space_shared_proportion += @@ -6416,7 +6447,7 @@ static int i915_gem_object_pid_order(int id, void *ptr, void *data) struct drm_device *dev) { struct drm_file *file; - + struct drm_i915_private *dev_priv = dev->dev_private; struct name_entry *entry, *next; struct pid_stat_entry *pid_entry, *temp_entry; struct pid_stat_entry *new_pid_entry, *new_temp_entry; @@ -6519,7 +6550,8 @@ static int i915_gem_object_pid_order(int id, void *ptr, void *data) err_printf(m, "\t\t\t\t\t\t\t\t%13zdK\t%12zdK\tTotal\n", total_shared_prop_space, total_priv_space); - + err_printf(m, "\nTotal used GFX Shmem Physical space %8zdK\n", + dev_priv->mm.phys_mem_total/1024); if (ret) return ret; if (m->bytes == 0 && m->err) diff --git a/drivers/gpu/drm/i915/i915_gem_object.h b/drivers/gpu/drm/i915/i915_gem_object.h index 8176d7d..8eb0288 100644 --- a/drivers/gpu/drm/i915/i915_gem_object.h +++ b/drivers/gpu/drm/i915/i915_gem_object.h @@ -147,6 +147,7 @@ struct drm_i915_gem_object { #define I915_BO_CACHE_COHERENT_FOR_READ BIT(0) #define I915_BO_CACHE_COHERENT_FOR_WRITE BIT(1) unsigned int cache_dirty:1; + unsigned int has_backing_pages:1; /** * @read_domains: Read memory domains.