e33c267ab7
Currently shrinkers are anonymous objects. For debugging purposes they can be identified by count/scan function names, but it's not always useful: e.g. for superblock's shrinkers it's nice to have at least an idea of to which superblock the shrinker belongs. This commit adds names to shrinkers. register_shrinker() and prealloc_shrinker() functions are extended to take a format and arguments to master a name. In some cases it's not possible to determine a good name at the time when a shrinker is allocated. For such cases shrinker_debugfs_rename() is provided. The expected format is: <subsystem>-<shrinker_type>[:<instance>]-<id> For some shrinkers an instance can be encoded as (MAJOR:MINOR) pair. After this change the shrinker debugfs directory looks like: $ cd /sys/kernel/debug/shrinker/ $ ls dquota-cache-16 sb-devpts-28 sb-proc-47 sb-tmpfs-42 mm-shadow-18 sb-devtmpfs-5 sb-proc-48 sb-tmpfs-43 mm-zspool:zram0-34 sb-hugetlbfs-17 sb-pstore-31 sb-tmpfs-44 rcu-kfree-0 sb-hugetlbfs-33 sb-rootfs-2 sb-tmpfs-49 sb-aio-20 sb-iomem-12 sb-securityfs-6 sb-tracefs-13 sb-anon_inodefs-15 sb-mqueue-21 sb-selinuxfs-22 sb-xfs:vda1-36 sb-bdev-3 sb-nsfs-4 sb-sockfs-8 sb-zsmalloc-19 sb-bpf-32 sb-pipefs-14 sb-sysfs-26 thp-deferred_split-10 sb-btrfs:vda2-24 sb-proc-25 sb-tmpfs-1 thp-zero-9 sb-cgroup2-30 sb-proc-39 sb-tmpfs-27 xfs-buf:vda1-37 sb-configfs-23 sb-proc-41 sb-tmpfs-29 xfs-inodegc:vda1-38 sb-dax-11 sb-proc-45 sb-tmpfs-35 sb-debugfs-7 sb-proc-46 sb-tmpfs-40 [roman.gushchin@linux.dev: fix build warnings] Link: https://lkml.kernel.org/r/Yr+ZTnLb9lJk6fJO@castle Reported-by: kernel test robot <lkp@intel.com> Link: https://lkml.kernel.org/r/20220601032227.4076670-4-roman.gushchin@linux.dev Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev> Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Cc: Dave Chinner <dchinner@redhat.com> Cc: Hillf Danton <hdanton@sina.com> Cc: Kent Overstreet <kent.overstreet@gmail.com> Cc: Muchun Song <songmuchun@bytedance.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
123 lines
3.0 KiB
C
123 lines
3.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (C) 2019 Arm Ltd.
|
|
*
|
|
* Based on msm_gem_freedreno.c:
|
|
* Copyright (C) 2016 Red Hat
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
*/
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <drm/drm_device.h>
|
|
#include <drm/drm_gem_shmem_helper.h>
|
|
|
|
#include "panfrost_device.h"
|
|
#include "panfrost_gem.h"
|
|
#include "panfrost_mmu.h"
|
|
|
|
static unsigned long
|
|
panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc)
|
|
{
|
|
struct panfrost_device *pfdev =
|
|
container_of(shrinker, struct panfrost_device, shrinker);
|
|
struct drm_gem_shmem_object *shmem;
|
|
unsigned long count = 0;
|
|
|
|
if (!mutex_trylock(&pfdev->shrinker_lock))
|
|
return 0;
|
|
|
|
list_for_each_entry(shmem, &pfdev->shrinker_list, madv_list) {
|
|
if (drm_gem_shmem_is_purgeable(shmem))
|
|
count += shmem->base.size >> PAGE_SHIFT;
|
|
}
|
|
|
|
mutex_unlock(&pfdev->shrinker_lock);
|
|
|
|
return count;
|
|
}
|
|
|
|
static bool panfrost_gem_purge(struct drm_gem_object *obj)
|
|
{
|
|
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
|
|
struct panfrost_gem_object *bo = to_panfrost_bo(obj);
|
|
bool ret = false;
|
|
|
|
if (atomic_read(&bo->gpu_usecount))
|
|
return false;
|
|
|
|
if (!mutex_trylock(&bo->mappings.lock))
|
|
return false;
|
|
|
|
if (!mutex_trylock(&shmem->pages_lock))
|
|
goto unlock_mappings;
|
|
|
|
panfrost_gem_teardown_mappings_locked(bo);
|
|
drm_gem_shmem_purge_locked(&bo->base);
|
|
ret = true;
|
|
|
|
mutex_unlock(&shmem->pages_lock);
|
|
|
|
unlock_mappings:
|
|
mutex_unlock(&bo->mappings.lock);
|
|
return ret;
|
|
}
|
|
|
|
static unsigned long
|
|
panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
|
|
{
|
|
struct panfrost_device *pfdev =
|
|
container_of(shrinker, struct panfrost_device, shrinker);
|
|
struct drm_gem_shmem_object *shmem, *tmp;
|
|
unsigned long freed = 0;
|
|
|
|
if (!mutex_trylock(&pfdev->shrinker_lock))
|
|
return SHRINK_STOP;
|
|
|
|
list_for_each_entry_safe(shmem, tmp, &pfdev->shrinker_list, madv_list) {
|
|
if (freed >= sc->nr_to_scan)
|
|
break;
|
|
if (drm_gem_shmem_is_purgeable(shmem) &&
|
|
panfrost_gem_purge(&shmem->base)) {
|
|
freed += shmem->base.size >> PAGE_SHIFT;
|
|
list_del_init(&shmem->madv_list);
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&pfdev->shrinker_lock);
|
|
|
|
if (freed > 0)
|
|
pr_info_ratelimited("Purging %lu bytes\n", freed << PAGE_SHIFT);
|
|
|
|
return freed;
|
|
}
|
|
|
|
/**
|
|
* panfrost_gem_shrinker_init - Initialize panfrost shrinker
|
|
* @dev: DRM device
|
|
*
|
|
* This function registers and sets up the panfrost shrinker.
|
|
*/
|
|
void panfrost_gem_shrinker_init(struct drm_device *dev)
|
|
{
|
|
struct panfrost_device *pfdev = dev->dev_private;
|
|
pfdev->shrinker.count_objects = panfrost_gem_shrinker_count;
|
|
pfdev->shrinker.scan_objects = panfrost_gem_shrinker_scan;
|
|
pfdev->shrinker.seeks = DEFAULT_SEEKS;
|
|
WARN_ON(register_shrinker(&pfdev->shrinker, "drm-panfrost"));
|
|
}
|
|
|
|
/**
|
|
* panfrost_gem_shrinker_cleanup - Clean up panfrost shrinker
|
|
* @dev: DRM device
|
|
*
|
|
* This function unregisters the panfrost shrinker.
|
|
*/
|
|
void panfrost_gem_shrinker_cleanup(struct drm_device *dev)
|
|
{
|
|
struct panfrost_device *pfdev = dev->dev_private;
|
|
|
|
if (pfdev->shrinker.nr_deferred) {
|
|
unregister_shrinker(&pfdev->shrinker);
|
|
}
|
|
}
|