From: Daniel Vetter <daniel@ffwll.ch>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: ray.huang@amd.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/4] drm/ttm: add debugfs entry to test pool shrinker
Date: Tue, 22 Dec 2020 14:43:13 +0100 [thread overview]
Message-ID: <X+H38fhQIDIuBjLW@phenom.ffwll.local> (raw)
In-Reply-To: <20201218175538.1364-3-christian.koenig@amd.com>
On Fri, Dec 18, 2020 at 06:55:37PM +0100, Christian König wrote:
> Useful for testing.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/ttm/ttm_pool.c | 50 ++++++++++++++++++++++------------
> 1 file changed, 32 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> index 1d61e8fc0e81..1cdacd58753a 100644
> --- a/drivers/gpu/drm/ttm/ttm_pool.c
> +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> @@ -529,6 +529,28 @@ void ttm_pool_fini(struct ttm_pool *pool)
> }
> 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
> /* Count the number of pages available in a pool_type */
> static unsigned int ttm_pool_type_count(struct ttm_pool_type *pt)
> @@ -633,29 +655,19 @@ int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m)
> }
> EXPORT_SYMBOL(ttm_pool_debugfs);
>
> -#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)
> +/* Test the shrinker functions and dump the result */
> +static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data)
> {
> - unsigned long num_freed = 0;
> + struct shrink_control sc = { .gfp_mask = GFP_KERNEL };
>
> - do
> - num_freed += ttm_pool_shrink();
> - while (!num_freed && atomic_long_read(&allocated_pages));
Need to wrap this in fs_reclaim_acquire/release(), otherwise lockdep won't
connect the dots and the dedicated testing interface here isn't very
useful.
Also this is a bit a confusing interface, I'd expect the show function to
do the counting, and then the write function would try to write shrink as
many objects as requests with the _scan function.
Both should be annotated with fs_reclaim_acquire/release.
> + seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(&mm_shrinker, &sc),
> + ttm_pool_shrinker_scan(&mm_shrinker, &sc));
>
> - return num_freed;
> + return 0;
> }
> +DEFINE_SHOW_ATTRIBUTE(ttm_pool_debugfs_shrink);
>
> -/* 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;
> -}
> +#endif
>
> /**
> * ttm_pool_mgr_init - Initialize globals
> @@ -688,6 +700,8 @@ int ttm_pool_mgr_init(unsigned long num_pages)
> #ifdef CONFIG_DEBUG_FS
> debugfs_create_file("page_pool", 0444, ttm_debugfs_root, NULL,
> &ttm_pool_debugfs_globals_fops);
> + debugfs_create_file("page_pool_shrink", 0400, ttm_debugfs_root, NULL,
> + &ttm_pool_debugfs_shrink_fops);
I think an interface per pool would make more sense for dedicated testing.
I'm kinda wondering whether we shouldn't do this in mm/ for all shrinkers
by default, it's really quite neat for being able to test stuff.
-Daniel
> #endif
>
> mm_shrinker.count_objects = ttm_pool_shrinker_count;
> --
> 2.25.1
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-12-22 13:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 17:55 [PATCH 1/4] drm/ttm: add debugfs directory v2 Christian König
2020-12-18 17:55 ` [PATCH 2/4] drm/ttm: add a debugfs file for the global page pools Christian König
2020-12-22 13:36 ` Daniel Vetter
2020-12-18 17:55 ` [PATCH 3/4] drm/ttm: add debugfs entry to test pool shrinker Christian König
2020-12-22 13:43 ` Daniel Vetter [this message]
2020-12-18 17:55 ` [PATCH 4/4] drm/ttm: optimize ttm pool shrinker a bit Christian König
2020-12-22 13:51 ` Daniel Vetter
2021-01-07 12:49 ` Christian König
2021-01-07 16:38 ` Daniel Vetter
2021-01-19 12:11 ` Christian König
2021-01-19 13:22 ` Daniel Vetter
2020-12-22 13:31 ` [PATCH 1/4] drm/ttm: add debugfs directory v2 Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X+H38fhQIDIuBjLW@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ray.huang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox