drm/ttm: add debugfs entry to test pool shrinker v2
Useful for testing. v2: add fs_reclaim_acquire()/_release() Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/414955/
This commit is contained in:
parent
ba051901d1
commit
568517686f
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/dma-mapping.h>
|
#include <linux/dma-mapping.h>
|
||||||
|
#include <linux/sched/mm.h>
|
||||||
|
|
||||||
#ifdef CONFIG_X86
|
#ifdef CONFIG_X86
|
||||||
#include <asm/set_memory.h>
|
#include <asm/set_memory.h>
|
||||||
|
@ -529,6 +530,28 @@ void ttm_pool_fini(struct ttm_pool *pool)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(ttm_pool_fini);
|
EXPORT_SYMBOL(ttm_pool_fini);
|
||||||
|
|
||||||
|
/* As long as pages are available make sure to release at least one */
|
||||||
|
static unsigned long ttm_pool_shrinker_scan(struct shrinker *shrink,
|
||||||
|
struct shrink_control *sc)
|
||||||
|
{
|
||||||
|
unsigned long num_freed = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
num_freed += ttm_pool_shrink();
|
||||||
|
while (!num_freed && atomic_long_read(&allocated_pages));
|
||||||
|
|
||||||
|
return num_freed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the number of pages available or SHRINK_EMPTY if we have none */
|
||||||
|
static unsigned long ttm_pool_shrinker_count(struct shrinker *shrink,
|
||||||
|
struct shrink_control *sc)
|
||||||
|
{
|
||||||
|
unsigned long num_pages = atomic_long_read(&allocated_pages);
|
||||||
|
|
||||||
|
return num_pages ? num_pages : SHRINK_EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
/* Count the number of pages available in a pool_type */
|
/* Count the number of pages available in a pool_type */
|
||||||
static unsigned int ttm_pool_type_count(struct ttm_pool_type *pt)
|
static unsigned int ttm_pool_type_count(struct ttm_pool_type *pt)
|
||||||
|
@ -633,30 +656,22 @@ int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(ttm_pool_debugfs);
|
EXPORT_SYMBOL(ttm_pool_debugfs);
|
||||||
|
|
||||||
|
/* Test the shrinker functions and dump the result */
|
||||||
|
static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data)
|
||||||
|
{
|
||||||
|
struct shrink_control sc = { .gfp_mask = GFP_NOFS };
|
||||||
|
|
||||||
|
fs_reclaim_acquire(GFP_KERNEL);
|
||||||
|
seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(&mm_shrinker, &sc),
|
||||||
|
ttm_pool_shrinker_scan(&mm_shrinker, &sc));
|
||||||
|
fs_reclaim_release(GFP_KERNEL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DEFINE_SHOW_ATTRIBUTE(ttm_pool_debugfs_shrink);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* As long as pages are available make sure to release at least one */
|
|
||||||
static unsigned long ttm_pool_shrinker_scan(struct shrinker *shrink,
|
|
||||||
struct shrink_control *sc)
|
|
||||||
{
|
|
||||||
unsigned long num_freed = 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
num_freed += ttm_pool_shrink();
|
|
||||||
while (!num_freed && atomic_long_read(&allocated_pages));
|
|
||||||
|
|
||||||
return num_freed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return the number of pages available or SHRINK_EMPTY if we have none */
|
|
||||||
static unsigned long ttm_pool_shrinker_count(struct shrinker *shrink,
|
|
||||||
struct shrink_control *sc)
|
|
||||||
{
|
|
||||||
unsigned long num_pages = atomic_long_read(&allocated_pages);
|
|
||||||
|
|
||||||
return num_pages ? num_pages : SHRINK_EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ttm_pool_mgr_init - Initialize globals
|
* ttm_pool_mgr_init - Initialize globals
|
||||||
*
|
*
|
||||||
|
@ -688,6 +703,8 @@ int ttm_pool_mgr_init(unsigned long num_pages)
|
||||||
#ifdef CONFIG_DEBUG_FS
|
#ifdef CONFIG_DEBUG_FS
|
||||||
debugfs_create_file("page_pool", 0444, ttm_debugfs_root, NULL,
|
debugfs_create_file("page_pool", 0444, ttm_debugfs_root, NULL,
|
||||||
&ttm_pool_debugfs_globals_fops);
|
&ttm_pool_debugfs_globals_fops);
|
||||||
|
debugfs_create_file("page_pool_shrink", 0400, ttm_debugfs_root, NULL,
|
||||||
|
&ttm_pool_debugfs_shrink_fops);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mm_shrinker.count_objects = ttm_pool_shrinker_count;
|
mm_shrinker.count_objects = ttm_pool_shrinker_count;
|
||||||
|
|
Loading…
Reference in New Issue