drivers/gpu/drm/i915/i915_gem_evict.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_gem_evict.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/i915_gem_evict.c- Extension
.c- Size
- 15981 bytes
- Lines
- 546
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
gem/i915_gem_context.hgt/intel_gt.hgt/intel_gt_requests.hi915_drv.hi915_gem_evict.hi915_trace.hselftests/i915_gem_evict.c
Detected Declarations
function dying_vmafunction ggtt_flushfunction list_for_each_entryfunction grab_vmafunction ungrab_vmafunction mark_freefunction defer_evictfunction i915_gem_evict_somethingfunction elementsfunction unbindfunction i915_gem_evict_for_nodefunction pinfunction drm_mm_for_each_node_in_rangefunction list_for_each_entry_safefunction i915_gem_evict_vmfunction list_for_each_entryfunction list_for_each_entry_safefunction list_for_each_entry_safe
Annotated Snippet
if (!i915_gem_object_trylock(vma->obj, ww)) {
i915_gem_object_put(vma->obj);
return false;
}
} else {
/* Dead objects don't need pins */
atomic_and(~I915_VMA_PIN_MASK, &vma->flags);
}
return true;
}
static void ungrab_vma(struct i915_vma *vma)
{
if (dying_vma(vma))
return;
i915_gem_object_unlock(vma->obj);
i915_gem_object_put(vma->obj);
}
static bool
mark_free(struct drm_mm_scan *scan,
struct i915_gem_ww_ctx *ww,
struct i915_vma *vma,
unsigned int flags,
struct list_head *unwind)
{
if (i915_vma_is_pinned(vma))
return false;
if (!grab_vma(vma, ww))
return false;
list_add(&vma->evict_link, unwind);
return drm_mm_scan_add_block(scan, &vma->node);
}
static bool defer_evict(struct i915_vma *vma)
{
if (i915_vma_is_active(vma))
return true;
if (i915_vma_is_scanout(vma))
return true;
return false;
}
/**
* i915_gem_evict_something - Evict vmas to make room for binding a new one
* @vm: address space to evict from
* @ww: An optional struct i915_gem_ww_ctx.
* @min_size: size of the desired free space
* @alignment: alignment constraint of the desired free space
* @color: color for the desired space
* @start: start (inclusive) of the range from which to evict objects
* @end: end (exclusive) of the range from which to evict objects
* @flags: additional flags to control the eviction algorithm
*
* This function will try to evict vmas until a free space satisfying the
* requirements is found. Callers must check first whether any such hole exists
* already before calling this function.
*
* This function is used by the object/vma binding code.
*
* Since this function is only used to free up virtual address space it only
* ignores pinned vmas, and not object where the backing storage itself is
* pinned. Hence obj->pages_pin_count does not protect against eviction.
*
* To clarify: This is for freeing up virtual address space, not for freeing
* memory in e.g. the shrinker.
*/
int
i915_gem_evict_something(struct i915_address_space *vm,
struct i915_gem_ww_ctx *ww,
u64 min_size, u64 alignment,
unsigned long color,
u64 start, u64 end,
unsigned flags)
{
struct drm_mm_scan scan;
struct list_head eviction_list;
struct i915_vma *vma, *next;
struct drm_mm_node *node;
enum drm_mm_insert_mode mode;
struct i915_vma *active;
struct intel_gt *gt;
int ret;
Annotation
- Immediate include surface: `gem/i915_gem_context.h`, `gt/intel_gt.h`, `gt/intel_gt_requests.h`, `i915_drv.h`, `i915_gem_evict.h`, `i915_trace.h`, `selftests/i915_gem_evict.c`.
- Detected declarations: `function dying_vma`, `function ggtt_flush`, `function list_for_each_entry`, `function grab_vma`, `function ungrab_vma`, `function mark_free`, `function defer_evict`, `function i915_gem_evict_something`, `function elements`, `function unbind`.
- 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.