From patchwork Fri Mar 16 01:20:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Xiong X-Patchwork-Id: 10286013 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 5A8E060291 for ; Fri, 16 Mar 2018 01:25:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E78F28CB8 for ; Fri, 16 Mar 2018 01:25:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4329D28CBF; Fri, 16 Mar 2018 01:25:10 +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 EFD0028CBA for ; Fri, 16 Mar 2018 01:25:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A3A316E4FE; Fri, 16 Mar 2018 01:24:58 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id C5B566E3AC; Fri, 16 Mar 2018 01:24:51 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Mar 2018 18:24:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,313,1517904000"; d="scan'208";a="25108920" Received: from iotg-dev-jx.fm.intel.com ([10.1.122.104]) by orsmga007.jf.intel.com with ESMTP; 15 Mar 2018 18:24:51 -0700 From: James Xiong To: chris@chris-wilson.co.uk, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Date: Thu, 15 Mar 2018 18:20:14 -0700 Message-Id: <1521163214-13521-6-git-send-email-james.xiong@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521163214-13521-1-git-send-email-james.xiong@intel.com> References: <1521163214-13521-1-git-send-email-james.xiong@intel.com> Subject: [Intel-gfx] [PATCH libdrm 5/5] intel: purge cached bucket when its cached buffer is evicted 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: james.xiong@intel.com MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: "Xiong, James" Previously when a cached MRU buffer was found to be evicted by kernel, the bucket was emptied. The new implementation purged these buffers that were freed before the evicted one. Signed-off-by: Xiong, James --- intel/intel_bufmgr_gem.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index e3d5a8d..69b361b 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -684,22 +684,20 @@ drm_intel_gem_bo_madvise(drm_intel_bo *bo, int madv) madv); } -/* drop the oldest entries that have been purged by the kernel */ +/* drop the entries that are older than the given time */ static void drm_intel_gem_bo_cache_purge_bucket(drm_intel_bufmgr_gem *bufmgr_gem, - struct drm_intel_gem_bo_bucket *bucket) + struct drm_intel_gem_bo_bucket *bucket, + time_t time) { - while (!DRMLISTEMPTY(&bucket->head)) { - drm_intel_bo_gem *bo_gem; - - bo_gem = DRMLISTENTRY(drm_intel_bo_gem, - bucket->head.next, head); - if (drm_intel_gem_bo_madvise_internal - (bufmgr_gem, bo_gem, I915_MADV_DONTNEED)) - break; - - DRMLISTDEL(&bo_gem->head); - drm_intel_gem_bo_free(&bo_gem->bo); + drm_intel_bo_gem *bo_gem, *temp; + DRMLISTFOREACHENTRYSAFE(bo_gem, temp, &bucket->head, head) { + if (bo_gem->free_time >= time) { + drm_intel_gem_bo_madvise_internal + (bufmgr_gem, bo_gem, I915_MADV_DONTNEED); + DRMLISTDEL(&bo_gem->head); + drm_intel_gem_bo_free(&bo_gem->bo); + } } } @@ -753,9 +751,10 @@ retry: if (bo_gem) { if (!drm_intel_gem_bo_madvise_internal (bufmgr_gem, bo_gem, I915_MADV_WILLNEED)) { - drm_intel_gem_bo_free(&bo_gem->bo); drm_intel_gem_bo_cache_purge_bucket(bufmgr_gem, - bucket); + bucket, + bo_gem->free_time); + drm_intel_gem_bo_free(&bo_gem->bo); return NULL; }