Lines Matching refs:shrinker
31 struct shrinker *shrink;
35 static struct xe_shrinker *to_xe_shrinker(struct shrinker *shrink) in to_xe_shrinker()
49 xe_shrinker_mod_pages(struct xe_shrinker *shrinker, long shrinkable, long purgeable) in xe_shrinker_mod_pages() argument
51 write_lock(&shrinker->lock); in xe_shrinker_mod_pages()
52 shrinker->shrinkable_pages += shrinkable; in xe_shrinker_mod_pages()
53 shrinker->purgeable_pages += purgeable; in xe_shrinker_mod_pages()
54 write_unlock(&shrinker->lock); in xe_shrinker_mod_pages()
139 xe_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) in xe_shrinker_count()
141 struct xe_shrinker *shrinker = to_xe_shrinker(shrink); in xe_shrinker_count() local
146 read_lock(&shrinker->lock); in xe_shrinker_count()
149 num_pages = min_t(unsigned long, num_pages, shrinker->shrinkable_pages); in xe_shrinker_count()
153 num_pages += shrinker->purgeable_pages; in xe_shrinker_count()
154 read_unlock(&shrinker->lock); in xe_shrinker_count()
166 static bool xe_shrinker_runtime_pm_get(struct xe_shrinker *shrinker, bool force, in xe_shrinker_runtime_pm_get() argument
169 struct xe_device *xe = shrinker->xe; in xe_shrinker_runtime_pm_get()
176 read_lock(&shrinker->lock); in xe_shrinker_runtime_pm_get()
177 force = (nr_to_scan > shrinker->purgeable_pages && can_backup); in xe_shrinker_runtime_pm_get()
178 read_unlock(&shrinker->lock); in xe_shrinker_runtime_pm_get()
188 queue_work(xe->unordered_wq, &shrinker->pm_worker); in xe_shrinker_runtime_pm_get()
195 static void xe_shrinker_runtime_pm_put(struct xe_shrinker *shrinker, bool runtime_pm) in xe_shrinker_runtime_pm_put() argument
198 xe_pm_runtime_put(shrinker->xe); in xe_shrinker_runtime_pm_put()
201 static unsigned long xe_shrinker_scan(struct shrinker *shrink, struct shrink_control *sc) in xe_shrinker_scan()
203 struct xe_shrinker *shrinker = to_xe_shrinker(shrink); in xe_shrinker_scan() local
221 read_lock(&shrinker->lock); in xe_shrinker_scan()
222 purgeable = !!shrinker->purgeable_pages; in xe_shrinker_scan()
223 read_unlock(&shrinker->lock); in xe_shrinker_scan()
226 runtime_pm = xe_shrinker_runtime_pm_get(shrinker, false, nr_to_scan, can_backup); in xe_shrinker_scan()
229 lret = xe_shrinker_walk(shrinker->xe, &ctx, shrink_flags, in xe_shrinker_scan()
241 runtime_pm = xe_shrinker_runtime_pm_get(shrinker, true, 0, can_backup); in xe_shrinker_scan()
245 lret = xe_shrinker_walk(shrinker->xe, &ctx, shrink_flags, in xe_shrinker_scan()
252 xe_shrinker_runtime_pm_put(shrinker, runtime_pm); in xe_shrinker_scan()
259 struct xe_shrinker *shrinker = in xe_shrinker_pm() local
260 container_of(work, typeof(*shrinker), pm_worker); in xe_shrinker_pm()
262 xe_pm_runtime_get(shrinker->xe); in xe_shrinker_pm()
263 xe_pm_runtime_put(shrinker->xe); in xe_shrinker_pm()
268 struct xe_shrinker *shrinker = arg; in xe_shrinker_fini() local
270 xe_assert(shrinker->xe, !shrinker->shrinkable_pages); in xe_shrinker_fini()
271 xe_assert(shrinker->xe, !shrinker->purgeable_pages); in xe_shrinker_fini()
272 shrinker_free(shrinker->shrink); in xe_shrinker_fini()
273 flush_work(&shrinker->pm_worker); in xe_shrinker_fini()
274 kfree(shrinker); in xe_shrinker_fini()
285 struct xe_shrinker *shrinker = kzalloc(sizeof(*shrinker), GFP_KERNEL); in xe_shrinker_create() local
287 if (!shrinker) in xe_shrinker_create()
290 shrinker->shrink = shrinker_alloc(0, "drm-xe_gem:%s", xe->drm.unique); in xe_shrinker_create()
291 if (!shrinker->shrink) { in xe_shrinker_create()
292 kfree(shrinker); in xe_shrinker_create()
296 INIT_WORK(&shrinker->pm_worker, xe_shrinker_pm); in xe_shrinker_create()
297 shrinker->xe = xe; in xe_shrinker_create()
298 rwlock_init(&shrinker->lock); in xe_shrinker_create()
299 shrinker->shrink->count_objects = xe_shrinker_count; in xe_shrinker_create()
300 shrinker->shrink->scan_objects = xe_shrinker_scan; in xe_shrinker_create()
301 shrinker->shrink->private_data = shrinker; in xe_shrinker_create()
302 shrinker_register(shrinker->shrink); in xe_shrinker_create()
303 xe->mem.shrinker = shrinker; in xe_shrinker_create()
305 return drmm_add_action_or_reset(&xe->drm, xe_shrinker_fini, shrinker); in xe_shrinker_create()