drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c- Extension
.c- Size
- 17833 bytes
- Lines
- 598
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/oom.hlinux/sched/mm.hlinux/shmem_fs.hlinux/slab.hlinux/swap.hlinux/pci.hlinux/dma-buf.hlinux/vmalloc.hdrm/drm_print.hgt/intel_gt_requests.hgt/intel_gt.hi915_trace.h
Detected Declarations
function swap_availablefunction can_release_pagesfunction drop_pagesfunction try_to_writebackfunction cachesfunction i915_gem_shrinkfunction with_intel_runtime_pmfunction i915_gem_shrinker_countfunction i915_gem_shrinker_scanfunction with_intel_runtime_pmfunction i915_gem_shrinker_oomfunction i915_gem_shrinker_vmapfunction list_for_each_entry_safefunction i915_gem_driver_register__shrinkerfunction i915_gem_driver_unregister__shrinkerfunction i915_gem_shrinker_taints_mutexfunction shrinkingfunction ___i915_gem_object_make_shrinkablefunction __i915_gem_object_make_shrinkablefunction __i915_gem_object_make_purgeablefunction i915_gem_object_make_unshrinkablefunction i915_gem_object_make_unshrinkable
Annotated Snippet
if (!ww) {
if (!i915_gem_object_trylock(obj, NULL))
goto skip;
} else {
err = i915_gem_object_lock(obj, ww);
if (err)
goto skip;
}
if (drop_pages(obj, shrink, trylock_vm) &&
!__i915_gem_object_put_pages(obj) &&
!try_to_writeback(obj, shrink))
count += obj->base.size >> PAGE_SHIFT;
if (!ww)
i915_gem_object_unlock(obj);
scanned += obj->base.size >> PAGE_SHIFT;
skip:
i915_gem_object_put(obj);
spin_lock_irqsave(&i915->mm.obj_lock, flags);
if (err)
break;
}
list_splice_tail(&still_in_list, phase->list);
spin_unlock_irqrestore(&i915->mm.obj_lock, flags);
if (err)
break;
}
if (shrink & I915_SHRINK_BOUND)
intel_runtime_pm_put(&i915->runtime_pm, wakeref);
if (err)
return err;
if (nr_scanned)
*nr_scanned += scanned;
return count;
}
/**
* i915_gem_shrink_all - Shrink buffer object caches completely
* @i915: i915 device
*
* This is a simple wrapper around i915_gem_shrink() to aggressively shrink all
* caches completely. It also first waits for and retires all outstanding
* requests to also be able to release backing storage for active objects.
*
* This should only be used in code to intentionally quiescent the gpu or as a
* last-ditch effort when memory seems to have run out.
*
* Returns:
* The number of pages of backing storage actually released.
*/
unsigned long i915_gem_shrink_all(struct drm_i915_private *i915)
{
intel_wakeref_t wakeref;
unsigned long freed = 0;
with_intel_runtime_pm(&i915->runtime_pm, wakeref) {
freed = i915_gem_shrink(NULL, i915, -1UL, NULL,
I915_SHRINK_BOUND |
I915_SHRINK_UNBOUND);
}
return freed;
}
static unsigned long
i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc)
{
struct drm_i915_private *i915 = shrinker->private_data;
unsigned long num_objects;
unsigned long count;
count = READ_ONCE(i915->mm.shrink_memory) >> PAGE_SHIFT;
num_objects = READ_ONCE(i915->mm.shrink_count);
/*
* Update our preferred vmscan batch size for the next pass.
* Our rough guess for an effective batch size is roughly 2
* available GEM objects worth of pages. That is we don't want
* the shrinker to fire, until it is worth the cost of freeing an
* entire GEM object.
*/
if (num_objects) {
unsigned long avg = 2 * count / num_objects;
Annotation
- Immediate include surface: `linux/oom.h`, `linux/sched/mm.h`, `linux/shmem_fs.h`, `linux/slab.h`, `linux/swap.h`, `linux/pci.h`, `linux/dma-buf.h`, `linux/vmalloc.h`.
- Detected declarations: `function swap_available`, `function can_release_pages`, `function drop_pages`, `function try_to_writeback`, `function caches`, `function i915_gem_shrink`, `function with_intel_runtime_pm`, `function i915_gem_shrinker_count`, `function i915_gem_shrinker_scan`, `function with_intel_runtime_pm`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.