<div dir="auto">Please remove Bob Lee from this email group.<div dir="auto">He is deceased</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 22, 2023, 1:56 AM Qi Zheng <<a href="mailto:zhengqi.arch@bytedance.com">zhengqi.arch@bytedance.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In preparation for implementing lockless slab shrink,<br>
we need to dynamically allocate the drm-panfrost shrinker,<br>
so that it can be freed asynchronously using kfree_rcu().<br>
Then it doesn't need to wait for RCU read-side critical<br>
section when releasing the struct panfrost_device.<br>
<br>
Signed-off-by: Qi Zheng <<a href="mailto:zhengqi.arch@bytedance.com" target="_blank" rel="noreferrer">zhengqi.arch@bytedance.com</a>><br>
---<br>
 drivers/gpu/drm/panfrost/panfrost_device.h    |  2 +-<br>
 .../gpu/drm/panfrost/panfrost_gem_shrinker.c  | 24 ++++++++++---------<br>
 2 files changed, 14 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h<br>
index b0126b9fbadc..e667e5689353 100644<br>
--- a/drivers/gpu/drm/panfrost/panfrost_device.h<br>
+++ b/drivers/gpu/drm/panfrost/panfrost_device.h<br>
@@ -118,7 +118,7 @@ struct panfrost_device {<br>
<br>
        struct mutex shrinker_lock;<br>
        struct list_head shrinker_list;<br>
-       struct shrinker shrinker;<br>
+       struct shrinker *shrinker;<br>
<br>
        struct panfrost_devfreq pfdevfreq;<br>
 };<br>
diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c<br>
index bf0170782f25..2a5513eb9e1f 100644<br>
--- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c<br>
+++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c<br>
@@ -18,8 +18,7 @@<br>
 static unsigned long<br>
 panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc)<br>
 {<br>
-       struct panfrost_device *pfdev =<br>
-               container_of(shrinker, struct panfrost_device, shrinker);<br>
+       struct panfrost_device *pfdev = shrinker->private_data;<br>
        struct drm_gem_shmem_object *shmem;<br>
        unsigned long count = 0;<br>
<br>
@@ -65,8 +64,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)<br>
 static unsigned long<br>
 panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)<br>
 {<br>
-       struct panfrost_device *pfdev =<br>
-               container_of(shrinker, struct panfrost_device, shrinker);<br>
+       struct panfrost_device *pfdev = shrinker->private_data;<br>
        struct drm_gem_shmem_object *shmem, *tmp;<br>
        unsigned long freed = 0;<br>
<br>
@@ -100,10 +98,15 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)<br>
 void panfrost_gem_shrinker_init(struct drm_device *dev)<br>
 {<br>
        struct panfrost_device *pfdev = dev->dev_private;<br>
-       pfdev->shrinker.count_objects = panfrost_gem_shrinker_count;<br>
-       pfdev->shrinker.scan_objects = panfrost_gem_shrinker_scan;<br>
-       pfdev->shrinker.seeks = DEFAULT_SEEKS;<br>
-       WARN_ON(register_shrinker(&pfdev->shrinker, "drm-panfrost"));<br>
+<br>
+       pfdev->shrinker = shrinker_alloc_and_init(panfrost_gem_shrinker_count,<br>
+                                                 panfrost_gem_shrinker_scan, 0,<br>
+                                                 DEFAULT_SEEKS, 0, pfdev);<br>
+       if (pfdev->shrinker &&<br>
+           register_shrinker(pfdev->shrinker, "drm-panfrost")) {<br>
+               shrinker_free(pfdev->shrinker);<br>
+               WARN_ON(1);<br>
+       }<br>
 }<br>
<br>
 /**<br>
@@ -116,7 +119,6 @@ void panfrost_gem_shrinker_cleanup(struct drm_device *dev)<br>
 {<br>
        struct panfrost_device *pfdev = dev->dev_private;<br>
<br>
-       if (pfdev->shrinker.nr_deferred) {<br>
-               unregister_shrinker(&pfdev->shrinker);<br>
-       }<br>
+       if (pfdev->shrinker->nr_deferred)<br>
+               unregister_and_free_shrinker(pfdev->shrinker);<br>
 }<br>
-- <br>
2.30.2<br>
<br>
</blockquote></div>