Skip to content

Commit 515b8b7

Browse files
committed
drm/i915: Flush the freed object list on file close
As we increase the number of RCU objects, it becomes easier for us to have several hundred thousand objects in the deferred RCU free queues. An example is gem_ctx_create/files which continually creates active contexts, which are not immediately freed upon close as they are kept alive by outstanding requests. This lack of backpressure allows the context objects to persist until they overwhelm and starve the system. We can increase our backpressure by flushing the freed object queue upon closing the device fd which should then not impact other clients. Testcase: igt/gem_ctx_create/*files Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190802212137.22207-2-chris@chris-wilson.co.uk
1 parent 1aff190 commit 515b8b7

4 files changed

Lines changed: 7 additions & 36 deletions

File tree

‎drivers/gpu/drm/i915/gem/i915_gem_object.c‎

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -211,48 +211,18 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
211211

212212
void i915_gem_flush_free_objects(struct drm_i915_private *i915)
213213
{
214-
struct llist_node *freed;
215-
216-
/* Free the oldest, most stale object to keep the free_list short */
217-
freed = NULL;
218-
if (!llist_empty(&i915->mm.free_list)) { /* quick test for hotpath */
219-
/* Only one consumer of llist_del_first() allowed */
220-
spin_lock(&i915->mm.free_lock);
221-
freed = llist_del_first(&i915->mm.free_list);
222-
spin_unlock(&i915->mm.free_lock);
223-
}
224-
if (unlikely(freed)) {
225-
freed->next = NULL;
214+
struct llist_node *freed = llist_del_all(&i915->mm.free_list);
215+
216+
if (unlikely(freed))
226217
__i915_gem_free_objects(i915, freed);
227-
}
228218
}
229219

230220
static void __i915_gem_free_work(struct work_struct *work)
231221
{
232222
struct drm_i915_private *i915 =
233223
container_of(work, struct drm_i915_private, mm.free_work);
234-
struct llist_node *freed;
235-
236-
/*
237-
* All file-owned VMA should have been released by this point through
238-
* i915_gem_close_object(), or earlier by i915_gem_context_close().
239-
* However, the object may also be bound into the global GTT (e.g.
240-
* older GPUs without per-process support, or for direct access through
241-
* the GTT either for the user or for scanout). Those VMA still need to
242-
* unbound now.
243-
*/
244-
245-
spin_lock(&i915->mm.free_lock);
246-
while ((freed = llist_del_all(&i915->mm.free_list))) {
247-
spin_unlock(&i915->mm.free_lock);
248224

249-
__i915_gem_free_objects(i915, freed);
250-
if (need_resched())
251-
return;
252-
253-
spin_lock(&i915->mm.free_lock);
254-
}
255-
spin_unlock(&i915->mm.free_lock);
225+
i915_gem_flush_free_objects(i915);
256226
}
257227

258228
void i915_gem_free_object(struct drm_gem_object *gem_obj)

‎drivers/gpu/drm/i915/i915_drv.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,9 @@ static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
20522052
mutex_unlock(&dev->struct_mutex);
20532053

20542054
kfree(file_priv);
2055+
2056+
/* Catch up with all the deferred frees from "this" client */
2057+
i915_gem_flush_free_objects(to_i915(dev));
20552058
}
20562059

20572060
static void intel_suspend_encoders(struct drm_i915_private *dev_priv)

‎drivers/gpu/drm/i915/i915_drv.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ struct i915_gem_mm {
773773
*/
774774
struct llist_head free_list;
775775
struct work_struct free_work;
776-
spinlock_t free_lock;
777776
/**
778777
* Count of objects pending destructions. Used to skip needlessly
779778
* waiting on an RCU barrier if no objects are waiting to be freed.

‎drivers/gpu/drm/i915/i915_gem.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,6 @@ void i915_gem_init_mmio(struct drm_i915_private *i915)
16481648
static void i915_gem_init__mm(struct drm_i915_private *i915)
16491649
{
16501650
spin_lock_init(&i915->mm.obj_lock);
1651-
spin_lock_init(&i915->mm.free_lock);
16521651

16531652
init_llist_head(&i915->mm.free_list);
16541653

0 commit comments

Comments
 (0)