[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6049aa99-aa47-5137-f66e-350bc4723914@bytedance.com>
Date: Tue, 25 Jul 2023 11:05:04 +0800
From: Qi Zheng <zhengqi.arch@...edance.com>
To: Steven Price <steven.price@....com>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org, x86@...nel.org,
kvm@...r.kernel.org, xen-devel@...ts.xenproject.org,
linux-erofs@...ts.ozlabs.org,
linux-f2fs-devel@...ts.sourceforge.net, cluster-devel@...hat.com,
linux-nfs@...r.kernel.org, linux-mtd@...ts.infradead.org,
rcu@...r.kernel.org, netdev@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-arm-msm@...r.kernel.org,
dm-devel@...hat.com, linux-raid@...r.kernel.org,
linux-bcache@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
linux-fsdevel@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-xfs@...r.kernel.org, linux-btrfs@...r.kernel.org,
akpm@...ux-foundation.org, david@...morbit.com, tkhai@...ru,
vbabka@...e.cz, roman.gushchin@...ux.dev, djwong@...nel.org,
brauner@...nel.org, paulmck@...nel.org, tytso@....edu,
cel@...nel.org, senozhatsky@...omium.org, yujie.liu@...el.com,
gregkh@...uxfoundation.org, muchun.song@...ux.dev
Subject: Re: [PATCH v2 24/47] drm/panfrost: dynamically allocate the
drm-panfrost shrinker
Hi Steven,
On 2023/7/24 19:17, Steven Price wrote:
> On 24/07/2023 10:43, Qi Zheng wrote:
>> In preparation for implementing lockless slab shrink, use new APIs to
>> dynamically allocate the drm-panfrost shrinker, so that it can be freed
>> asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU
>> read-side critical section when releasing the struct panfrost_device.
>>
>> Signed-off-by: Qi Zheng <zhengqi.arch@...edance.com>
>
> One nit below, but otherwise:
>
> Reviewed-by: Steven Price <steven.price@....com>
>
>> ---
>> drivers/gpu/drm/panfrost/panfrost_device.h | 2 +-
>> drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++-
>> drivers/gpu/drm/panfrost/panfrost_gem.h | 2 +-
>> .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 32 ++++++++++++-------
>> 4 files changed, 27 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h
>> index b0126b9fbadc..e667e5689353 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_device.h
>> +++ b/drivers/gpu/drm/panfrost/panfrost_device.h
>> @@ -118,7 +118,7 @@ struct panfrost_device {
>>
>> struct mutex shrinker_lock;
>> struct list_head shrinker_list;
>> - struct shrinker shrinker;
>> + struct shrinker *shrinker;
>>
>> struct panfrost_devfreq pfdevfreq;
>> };
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> index bbada731bbbd..f705bbdea360 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_drv.c
>> +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c
>> @@ -598,10 +598,14 @@ static int panfrost_probe(struct platform_device *pdev)
>> if (err < 0)
>> goto err_out1;
>>
>> - panfrost_gem_shrinker_init(ddev);
>> + err = panfrost_gem_shrinker_init(ddev);
>> + if (err)
>> + goto err_out2;
>>
>> return 0;
>>
>> +err_out2:
>> + drm_dev_unregister(ddev);
>> err_out1:
>> pm_runtime_disable(pfdev->dev);
>> panfrost_device_fini(pfdev);
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h
>> index ad2877eeeccd..863d2ec8d4f0 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_gem.h
>> +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h
>> @@ -81,7 +81,7 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo,
>> void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping);
>> void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo);
>>
>> -void panfrost_gem_shrinker_init(struct drm_device *dev);
>> +int panfrost_gem_shrinker_init(struct drm_device *dev);
>> void panfrost_gem_shrinker_cleanup(struct drm_device *dev);
>>
>> #endif /* __PANFROST_GEM_H__ */
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
>> index bf0170782f25..9a90dfb5301f 100644
>> --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
>> +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c
>> @@ -18,8 +18,7 @@
>> 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 panfrost_device *pfdev = shrinker->private_data;
>> struct drm_gem_shmem_object *shmem;
>> unsigned long count = 0;
>>
>> @@ -65,8 +64,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
>> 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 panfrost_device *pfdev = shrinker->private_data;
>> struct drm_gem_shmem_object *shmem, *tmp;
>> unsigned long freed = 0;
>>
>> @@ -97,13 +95,24 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
>> *
>> * This function registers and sets up the panfrost shrinker.
>> */
>> -void panfrost_gem_shrinker_init(struct drm_device *dev)
>> +int 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"));
>> +
>> + pfdev->shrinker = shrinker_alloc(0, "drm-panfrost");
>> + if (!pfdev->shrinker) {
>> + WARN_ON(1);
>
> I don't think this WARN_ON is particularly useful - if there's a failed
> memory allocation we should see output from the kernel anyway. And we're
> changing the semantics from "continue just without a shrinker" (which
> argueably justifies the warning) to "probe fails, device doesn't work"
> which will be obvious to the user so I don't feel we need the additional
> warn.
Make sense. Will delete this WARN_ON() in the next version.
Thanks,
Qi
>
>> + return -ENOMEM;
>> + }
>> +
>> + pfdev->shrinker->count_objects = panfrost_gem_shrinker_count;
>> + pfdev->shrinker->scan_objects = panfrost_gem_shrinker_scan;
>> + pfdev->shrinker->seeks = DEFAULT_SEEKS;
>> + pfdev->shrinker->private_data = pfdev;
>> +
>> + shrinker_register(pfdev->shrinker);
>> +
>> + return 0;
>> }
>>
>> /**
>> @@ -116,7 +125,6 @@ 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);
>> - }
>> + if (pfdev->shrinker)
>> + shrinker_unregister(pfdev->shrinker);
>> }
>
Powered by blists - more mailing lists