/* * SPDX-License-Identifier: MIT * * Copyright © 2008-2015 Intel Corporation */ #include <linux/oom.h> #include <linux/sched/mm.h> #include <linux/shmem_fs.h> #include <linux/slab.h> #include <linux/swap.h> #include <linux/pci.h> #include <linux/dma-buf.h> #include <linux/vmalloc.h> #include "gt/intel_gt_requests.h" #include "gt/intel_gt.h" #include "i915_trace.h" static bool swap_available(void) { … } static bool can_release_pages(struct drm_i915_gem_object *obj) { … } static bool drop_pages(struct drm_i915_gem_object *obj, unsigned long shrink, bool trylock_vm) { … } static int try_to_writeback(struct drm_i915_gem_object *obj, unsigned int flags) { … } /** * i915_gem_shrink - Shrink buffer object caches * @ww: i915 gem ww acquire ctx, or NULL * @i915: i915 device * @target: amount of memory to make available, in pages * @nr_scanned: optional output for number of pages scanned (incremental) * @shrink: control flags for selecting cache types * * This function is the main interface to the shrinker. It will try to release * up to @target pages of main memory backing storage from buffer objects. * Selection of the specific caches can be done with @flags. This is e.g. useful * when purgeable objects should be removed from caches preferentially. * * Note that it's not guaranteed that released amount is actually available as * free system memory - the pages might still be in-used to due to other reasons * (like cpu mmaps) or the mm core has reused them before we could grab them. * Therefore code that needs to explicitly shrink buffer objects caches (e.g. to * avoid deadlocks in memory reclaim) must fall back to i915_gem_shrink_all(). * * Also note that any kind of pinning (both per-vma address space pins and * backing storage pins at the buffer object level) result in the shrinker code * having to skip the object. * * Returns: * The number of pages of backing storage actually released. */ unsigned long i915_gem_shrink(struct i915_gem_ww_ctx *ww, struct drm_i915_private *i915, unsigned long target, unsigned long *nr_scanned, unsigned int shrink) { … } /** * i915_gem_shrink_all - Shrink buffer object caches completely * @i915: i915 device * * This is a simple wraper 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) { … } static unsigned long i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { … } static unsigned long i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { … } static int i915_gem_shrinker_oom(struct notifier_block *nb, unsigned long event, void *ptr) { … } static int i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr) { … } void i915_gem_driver_register__shrinker(struct drm_i915_private *i915) { … } void i915_gem_driver_unregister__shrinker(struct drm_i915_private *i915) { … } void i915_gem_shrinker_taints_mutex(struct drm_i915_private *i915, struct mutex *mutex) { … } /** * i915_gem_object_make_unshrinkable - Hide the object from the shrinker. By * default all object types that support shrinking(see IS_SHRINKABLE), will also * make the object visible to the shrinker after allocating the system memory * pages. * @obj: The GEM object. * * This is typically used for special kernel internal objects that can't be * easily processed by the shrinker, like if they are perma-pinned. */ void i915_gem_object_make_unshrinkable(struct drm_i915_gem_object *obj) { … } static void ___i915_gem_object_make_shrinkable(struct drm_i915_gem_object *obj, struct list_head *head) { … } /** * __i915_gem_object_make_shrinkable - Move the object to the tail of the * shrinkable list. Objects on this list might be swapped out. Used with * WILLNEED objects. * @obj: The GEM object. * * DO NOT USE. This is intended to be called on very special objects that don't * yet have mm.pages, but are guaranteed to have potentially reclaimable pages * underneath. */ void __i915_gem_object_make_shrinkable(struct drm_i915_gem_object *obj) { … } /** * __i915_gem_object_make_purgeable - Move the object to the tail of the * purgeable list. Objects on this list might be swapped out. Used with * DONTNEED objects. * @obj: The GEM object. * * DO NOT USE. This is intended to be called on very special objects that don't * yet have mm.pages, but are guaranteed to have potentially reclaimable pages * underneath. */ void __i915_gem_object_make_purgeable(struct drm_i915_gem_object *obj) { … } /** * i915_gem_object_make_shrinkable - Move the object to the tail of the * shrinkable list. Objects on this list might be swapped out. Used with * WILLNEED objects. * @obj: The GEM object. * * MUST only be called on objects which have backing pages. * * MUST be balanced with previous call to i915_gem_object_make_unshrinkable(). */ void i915_gem_object_make_shrinkable(struct drm_i915_gem_object *obj) { … } /** * i915_gem_object_make_purgeable - Move the object to the tail of the purgeable * list. Used with DONTNEED objects. Unlike with shrinkable objects, the * shrinker will attempt to discard the backing pages, instead of trying to swap * them out. * @obj: The GEM object. * * MUST only be called on objects which have backing pages. * * MUST be balanced with previous call to i915_gem_object_make_unshrinkable(). */ void i915_gem_object_make_purgeable(struct drm_i915_gem_object *obj) { … }