-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/i915: Make request allocation caches global
As kmem_caches share the same properties (size, allocation/free behaviour) for all potential devices, we can use global caches. While this potential has worse fragmentation behaviour (one can argue that different devices would have different activity lifetimes, but you can also argue that activity is temporal across the system) it is the default behaviour of the system at large to amalgamate matching caches. The benefit for us is much reduced pointer dancing along the frequent allocation paths. v2: Defer shrinking until after a global grace period for futureproofing multiple consumers of the slab caches, similar to the current strategy for avoiding shrinking too early. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190228102035.5857-1-chris@chris-wilson.co.uk
- Loading branch information
Chris Wilson
committed
Feb 28, 2019
1 parent
bd2be14
commit 32eb6bc
Showing
19 changed files
with
312 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Copyright © 2019 Intel Corporation | ||
*/ | ||
|
||
#include <linux/slab.h> | ||
#include <linux/workqueue.h> | ||
|
||
#include "i915_active.h" | ||
#include "i915_globals.h" | ||
#include "i915_request.h" | ||
#include "i915_scheduler.h" | ||
|
||
int __init i915_globals_init(void) | ||
{ | ||
int err; | ||
|
||
err = i915_global_active_init(); | ||
if (err) | ||
return err; | ||
|
||
err = i915_global_request_init(); | ||
if (err) | ||
goto err_active; | ||
|
||
err = i915_global_scheduler_init(); | ||
if (err) | ||
goto err_request; | ||
|
||
return 0; | ||
|
||
err_request: | ||
i915_global_request_exit(); | ||
err_active: | ||
i915_global_active_exit(); | ||
return err; | ||
} | ||
|
||
static void i915_globals_shrink(void) | ||
{ | ||
/* | ||
* 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. | ||
*/ | ||
i915_global_active_shrink(); | ||
i915_global_request_shrink(); | ||
i915_global_scheduler_shrink(); | ||
} | ||
|
||
static atomic_t active; | ||
static atomic_t epoch; | ||
struct park_work { | ||
struct rcu_work work; | ||
int epoch; | ||
}; | ||
|
||
static void __i915_globals_park(struct work_struct *work) | ||
{ | ||
struct park_work *wrk = container_of(work, typeof(*wrk), work.work); | ||
|
||
/* Confirm nothing woke up in the last grace period */ | ||
if (wrk->epoch == atomic_read(&epoch)) | ||
i915_globals_shrink(); | ||
|
||
kfree(wrk); | ||
} | ||
|
||
void i915_globals_park(void) | ||
{ | ||
struct park_work *wrk; | ||
|
||
/* | ||
* Defer shrinking the global slab caches (and other work) until | ||
* after a RCU grace period has completed with no activity. This | ||
* is to try and reduce the latency impact on the consumers caused | ||
* by us shrinking the caches the same time as they are trying to | ||
* allocate, with the assumption being that if we idle long enough | ||
* for an RCU grace period to elapse since the last use, it is likely | ||
* to be longer until we need the caches again. | ||
*/ | ||
if (!atomic_dec_and_test(&active)) | ||
return; | ||
|
||
wrk = kmalloc(sizeof(*wrk), GFP_KERNEL); | ||
if (!wrk) | ||
return; | ||
|
||
wrk->epoch = atomic_inc_return(&epoch); | ||
INIT_RCU_WORK(&wrk->work, __i915_globals_park); | ||
queue_rcu_work(system_wq, &wrk->work); | ||
} | ||
|
||
void i915_globals_unpark(void) | ||
{ | ||
atomic_inc(&epoch); | ||
atomic_inc(&active); | ||
} | ||
|
||
void __exit i915_globals_exit(void) | ||
{ | ||
/* Flush any residual park_work */ | ||
rcu_barrier(); | ||
flush_scheduled_work(); | ||
|
||
i915_global_scheduler_exit(); | ||
i915_global_request_exit(); | ||
i915_global_active_exit(); | ||
|
||
/* And ensure that our DESTROY_BY_RCU slabs are truly destroyed */ | ||
rcu_barrier(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* Copyright © 2019 Intel Corporation | ||
*/ | ||
|
||
#ifndef _I915_GLOBALS_H_ | ||
#define _I915_GLOBALS_H_ | ||
|
||
int i915_globals_init(void); | ||
void i915_globals_park(void); | ||
void i915_globals_unpark(void); | ||
void i915_globals_exit(void); | ||
|
||
#endif /* _I915_GLOBALS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.