public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/i915: Shrink the GEM kmem_caches upon idling
Date: Tue, 16 Jan 2018 15:16:28 +0000	[thread overview]
Message-ID: <08001f89-802f-97da-6e40-aea955265474@linux.intel.com> (raw)
In-Reply-To: <4ce412fe-13d0-b06b-4e4d-7fe14bbb7ef4@linux.intel.com>


On 16/01/2018 15:12, Tvrtko Ursulin wrote:
> 
> On 16/01/2018 13:05, Chris Wilson wrote:
>> When we finally decide the gpu is idle, that is a good time to shrink
>> our kmem_caches.
>>
>> v2: Comment upon the random sprinkling of rcu_barrier() inside the idle
>> worker.
>>
>> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
>> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
>> ---
>>   drivers/gpu/drm/i915/i915_gem.c | 30 ++++++++++++++++++++++++++++++
>>   1 file changed, 30 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_gem.c 
>> b/drivers/gpu/drm/i915/i915_gem.c
>> index 335731c93b4a..61b13fdfaa71 100644
>> --- a/drivers/gpu/drm/i915/i915_gem.c
>> +++ b/drivers/gpu/drm/i915/i915_gem.c
>> @@ -4716,6 +4716,21 @@ i915_gem_retire_work_handler(struct work_struct 
>> *work)
>>       }
>>   }
>> +static void shrink_caches(struct drm_i915_private *i915)
>> +{
>> +    /*
>> +     * kmem_cache_shrink() discards empty slabs and reorders partially
>> +     * filled slabs to prioritise allocating from the mostly full slabs,
>> +     * with the aim of reducing fragmentation.
>> +     */
>> +    kmem_cache_shrink(i915->priorities);
>> +    kmem_cache_shrink(i915->dependencies);
>> +    kmem_cache_shrink(i915->requests);
>> +    kmem_cache_shrink(i915->luts);
>> +    kmem_cache_shrink(i915->vmas);
>> +    kmem_cache_shrink(i915->objects);
>> +}
>> +
>>   static inline bool
>>   new_requests_since_last_retire(const struct drm_i915_private *i915)
>>   {
>> @@ -4803,6 +4818,21 @@ i915_gem_idle_work_handler(struct work_struct 
>> *work)
>>           GEM_BUG_ON(!dev_priv->gt.awake);
>>           i915_queue_hangcheck(dev_priv);
>>       }
>> +
>> +    /*
>> +     * We use magical TYPESAFE_BY_RCU kmem_caches whose pages are not
>> +     * returned to the system imediately but only after an RCU grace
>> +     * period. We want to encourage such pages to be returned and so
>> +     * incorporate a RCU barrier here to provide some rate limiting
>> +     * of the driver and flush the old pages before we free a new batch
>> +     * from the next round of shrinking.
>> +     */
>> +    rcu_barrier();
> 
> Should this go into the conditional below? I don't think it makes a 
> difference effectively, but may be more logical.
> 
>> +
>> +    if (!new_requests_since_last_retire(dev_priv)) {
>> +        __i915_gem_free_work(&dev_priv->mm.free_work);
> 
> I thought for a bit if re-using the worker from here is completely fine 
> but I think it is. We expect only one pass when called from here so 
> need_resched will be correctly neutralized/not-relevant from this path. 
> Hm, unless if we consider mmap_gtt users.. so we could still have new 
> objects appearing on the free_list after the 1st pass. And then 
> need_resched might kick us out. What do you think?

This also ties back to what I wrote in the earlier reply - do we want to 
shrink the obj and vma caches from here? It may be colliding with 
mmap_gtt operations. But it sounds appealing to tidy them, and I can't 
think of any other convenient point. Given how we are de-prioritising 
mmap_gtt its probably fine.

> 
> Regards,
> 
> Tvrtko
> 
>> +        shrink_caches(dev_priv);
>> +    }
>>   }
>>   int i915_gem_suspend(struct drm_i915_private *dev_priv)
>>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2018-01-16 15:16 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15 21:24 Prevent trivial oom from gem_exec_nop/sequential Chris Wilson
2018-01-15 21:24 ` [PATCH 01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs Chris Wilson
2018-01-17 10:29   ` Tvrtko Ursulin
2018-01-18  9:16     ` Chris Wilson
2018-01-18  9:19     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 02/10] drm/i915: Move i915_gem_retire_work_handler Chris Wilson
2018-01-17 10:33   ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 03/10] drm/i915: Shrink the GEM kmem_caches upon idling Chris Wilson
2018-01-16 10:00   ` Tvrtko Ursulin
2018-01-16 10:19     ` Chris Wilson
2018-01-16 13:05     ` [PATCH v2] " Chris Wilson
2018-01-16 15:12       ` Tvrtko Ursulin
2018-01-16 15:16         ` Tvrtko Ursulin [this message]
2018-01-16 15:21         ` Chris Wilson
2018-01-16 17:25           ` Tvrtko Ursulin
2018-01-16 17:36             ` Chris Wilson
2018-01-17 10:18               ` Tvrtko Ursulin
2018-01-18 18:06                 ` Chris Wilson
2018-01-15 21:24 ` [PATCH 04/10] drm/i915: Shrink the request kmem_cache on allocation error Chris Wilson
2018-01-16 10:10   ` Tvrtko Ursulin
2018-01-16 10:26     ` Chris Wilson
2018-01-16 13:15     ` [PATCH v2] " Chris Wilson
2018-01-16 15:19       ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 05/10] drm/i915: Trim the retired request queue after submitting Chris Wilson
2018-01-16 10:18   ` Tvrtko Ursulin
2018-01-16 10:32     ` Chris Wilson
2018-01-17 10:23       ` Tvrtko Ursulin
2018-01-16 13:30     ` [PATCH v2] " Chris Wilson
2018-01-15 21:24 ` [PATCH 06/10] drm/i915/breadcrumbs: Drop request reference for the signaler thread Chris Wilson
2018-01-15 21:24 ` [PATCH 07/10] drm/i915: Reduce spinlock hold time during notify_ring() interrupt Chris Wilson
2018-01-17 10:45   ` Tvrtko Ursulin
2018-01-18 18:08     ` Chris Wilson
2018-01-18 18:10     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 08/10] drm/i915: Move the irq_counter inside the spinlock Chris Wilson
2018-01-17 12:12   ` Tvrtko Ursulin
2018-01-15 21:24 ` [PATCH 09/10] drm/i915: Only signal from interrupt when requested Chris Wilson
2018-01-17 12:22   ` Tvrtko Ursulin
2018-01-18 18:12     ` Chris Wilson
2018-01-15 21:24 ` [PATCH 10/10] drm/i915/breadcrumbs: Reduce signaler rbtree to a sorted list Chris Wilson
2018-01-15 22:04 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs Patchwork
2018-01-16  9:21 ` ✓ Fi.CI.IGT: " Patchwork
2018-01-16  9:52 ` Prevent trivial oom from gem_exec_nop/sequential Tvrtko Ursulin
2018-01-16 10:02   ` Chris Wilson
2018-01-16 13:10   ` Chris Wilson
2018-01-16 13:42 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs (rev3) Patchwork
2018-01-16 14:02 ` ✓ Fi.CI.BAT: success for series starting with [01/10] drm/i915: Only attempt to scan the requested number of shrinker slabs (rev4) Patchwork
2018-01-16 15:29 ` ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08001f89-802f-97da-6e40-aea955265474@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox