Skip to content

Commit 3e61c1f

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: gpu: Add a max object count garbage limit
This ensures the garbage Vec does not grow beyond what is reasonable, and probably reduces jank by doing more smaller GCs instead of big ones. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 2956e4f commit 3e61c1f

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

drivers/gpu/drm/asahi/gpu.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ const HALT_ENTER_TIMEOUT: Duration = Duration::from_millis(100);
9494
/// Maximum amount of firmware-private memory garbage allowed before collection.
9595
/// Collection flushes the FW cache and is expensive, so this needs to be
9696
/// reasonably high.
97-
const MAX_FW_ALLOC_GARBAGE: usize = 16 * 1024 * 1024;
97+
const MAX_FW_ALLOC_GARBAGE_BYTES: usize = 16 * 1024 * 1024;
98+
/// Maximum count of firmware-private memory garbage objects allowed before collection.
99+
/// This works out to 16K of memory in the garbage list (8 bytes each), which keeps us
100+
/// within the safe range for kmalloc (on 16K page systems).
101+
const MAX_FW_ALLOC_GARBAGE_OBJECTS: usize = 2048;
98102

99103
/// Global allocators used for kernel-half structures.
100104
pub(crate) struct KernelAllocators {
@@ -1174,7 +1178,11 @@ impl GpuManager for GpuManager::ver {
11741178
let (garbage_count, garbage_bytes) = guard.private.garbage();
11751179
let (ro_garbage_count, ro_garbage_bytes) = guard.gpu_ro.garbage();
11761180

1177-
if garbage_bytes > MAX_FW_ALLOC_GARBAGE || ro_garbage_bytes > MAX_FW_ALLOC_GARBAGE {
1181+
if garbage_bytes > MAX_FW_ALLOC_GARBAGE_BYTES
1182+
|| ro_garbage_bytes > MAX_FW_ALLOC_GARBAGE_BYTES
1183+
|| garbage_count > MAX_FW_ALLOC_GARBAGE_OBJECTS
1184+
|| ro_garbage_count > MAX_FW_ALLOC_GARBAGE_OBJECTS
1185+
{
11781186
mod_dev_dbg!(
11791187
self.dev,
11801188
"Collecting kalloc garbage (private: {} objects, {} bytes, gpuro: {} objects, {} bytes)\n",

0 commit comments

Comments
 (0)