Skip to content

Commit dc78a20

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 3e6717b commit dc78a20

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
@@ -93,7 +93,11 @@ const HALT_ENTER_TIMEOUT: Duration = Duration::from_millis(100);
9393
/// Maximum amount of firmware-private memory garbage allowed before collection.
9494
/// Collection flushes the FW cache and is expensive, so this needs to be
9595
/// reasonably high.
96-
const MAX_FW_ALLOC_GARBAGE: usize = 16 * 1024 * 1024;
96+
const MAX_FW_ALLOC_GARBAGE_BYTES: usize = 16 * 1024 * 1024;
97+
/// Maximum count of firmware-private memory garbage objects allowed before collection.
98+
/// This works out to 16K of memory in the garbage list (8 bytes each), which keeps us
99+
/// within the safe range for kmalloc (on 16K page systems).
100+
const MAX_FW_ALLOC_GARBAGE_OBJECTS: usize = 2048;
97101

98102
/// Global allocators used for kernel-half structures.
99103
pub(crate) struct KernelAllocators {
@@ -1171,7 +1175,11 @@ impl GpuManager for GpuManager::ver {
11711175
let (garbage_count, garbage_bytes) = guard.private.garbage();
11721176
let (ro_garbage_count, ro_garbage_bytes) = guard.gpu_ro.garbage();
11731177

1174-
if garbage_bytes > MAX_FW_ALLOC_GARBAGE || ro_garbage_bytes > MAX_FW_ALLOC_GARBAGE {
1178+
if garbage_bytes > MAX_FW_ALLOC_GARBAGE_BYTES
1179+
|| ro_garbage_bytes > MAX_FW_ALLOC_GARBAGE_BYTES
1180+
|| garbage_count > MAX_FW_ALLOC_GARBAGE_OBJECTS
1181+
|| ro_garbage_count > MAX_FW_ALLOC_GARBAGE_OBJECTS
1182+
{
11751183
mod_dev_dbg!(
11761184
self.dev,
11771185
"Collecting kalloc garbage (private: {} objects, {} bytes, gpuro: {} objects, {} bytes)\n",

0 commit comments

Comments
 (0)