Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3940265rwo; Mon, 24 Jul 2023 20:34:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFiqwewtmmb78lsPYPzZpbTl0r4ldMNOIh7MOokhdMpbBTuFagVoBs9tPmBC8tKEDFoM2Ss X-Received: by 2002:a05:6a21:33a6:b0:125:4d74:ac77 with SMTP id yy38-20020a056a2133a600b001254d74ac77mr11678450pzb.42.1690256067939; Mon, 24 Jul 2023 20:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690256067; cv=none; d=google.com; s=arc-20160816; b=BL3Qyl1A0500TKLj5qUhdS5l101bSjp7hfp99/BFXE57toBpLit4QaHtF0pB9kaJNE 6UCHLYeeI5gXusNY1qY3d571vRs9+FwBa5dYcPBjYxrq/TDNd2+F0MfKf09f5RJB0+NB rOpCIzzHYEH147rg8t7RAikZl4EuBQiCPtx1l5Gh7rbZCObA9DoxQLbVvomoahmlvRw9 HktLM/0KkG3DlkYL85cTclTXHEvJYzJT0M6IPfUwiHQVbVnf52eesHJIeZmCvS4MosTv H1nqKmmtQmPViUN9GPMMwJxirIVvGCjdhf7HvMbjRItFDfzWz5MMJgdKvchfLuynoVLd 4ONQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=niSMZqBCvW/Me9jsMaxXz5gtuZ44llk1Ot3soT0LhIs=; fh=Z6vCzwF/wVOgkUnp8A+l9lXiMHeHdiR9Hgcsgt3gV1Q=; b=LIZa+GLopmKfnLZ6Ot4yDy+HtgWniAseAhlCb6OyVqgIx9BYa1aVyUUPnbANc3kQmC LSngsdeBIwAsfaNnx9XgLLh36j+O2c641bpH3TJDQWeSgd3oKcLItFcin580yX4cpMjO 3NsX7p5A6wpVqqcCtTsYTKplBV5zdNeXhD+tThjk9cmGgg5tDUv5VfaMzotQmpcuJDHw l4JpWFiboWRhIMPLobi+OOwphee6oXX+XuQtNEHL2LN0LgTy88p24FfXt2SZo5R9Le/5 kjsmkU/8vjYrHioWJEvhFb02mTyM95+nxWbx894wDSGH3cHBQVe6Z1ph6SVzRyc9caxE s2hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=FniJo6cf; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p16-20020a056a000b5000b0066215192dd4si11113331pfo.295.2023.07.24.20.34.14; Mon, 24 Jul 2023 20:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=FniJo6cf; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbjGYDF5 (ORCPT + 99 others); Mon, 24 Jul 2023 23:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231470AbjGYDFw (ORCPT ); Mon, 24 Jul 2023 23:05:52 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 442F71999 for ; Mon, 24 Jul 2023 20:05:25 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6864c144897so1189011b3a.1 for ; Mon, 24 Jul 2023 20:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690254325; x=1690859125; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=niSMZqBCvW/Me9jsMaxXz5gtuZ44llk1Ot3soT0LhIs=; b=FniJo6cfZiXO48N3LrJPbrRtsXuGwEsrxL+rPNcNzpIfBU8e0vwfaKRVcngIxQ6/Nq uV6IwXjWItzg/7IWT04hxNl0ft8u0yvH7EyRJ6POcXsP6dFyjR2vvuievKT7V7wXKj9i Hs4OFXg82m4uyRZZDGIHYrUPf7Daiin7owJFDMH9ALFzGhGiMR/jo54iE9PQ2yCszEax GduXKZlfrLf0f1lI69b+SeFKsM1fBAPgAwEi9/QiPJB5pr3rcwSAawR7U6Bt6cbBHX1B l+6jljnScvspLgnoIuyzCCNBX+9PGgFUwcZiZbmROS7agCNCVVXov8LOv0CsZfjvTopq 9j6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690254325; x=1690859125; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=niSMZqBCvW/Me9jsMaxXz5gtuZ44llk1Ot3soT0LhIs=; b=kIQc2Ri5iGgQc7Pt2peR+EC4lbyoc/Nd3QNJmupknFzNTSr3h0XHNw4yzM5QO2qf6X LqwDpjKJg2XXctk5L/G7btANDQdautFufetOBJYa+oaJTvqJzK7t3lg3jM0T0NB6t9bl 4mBM4Nk4pjIyn17Fm69Tudboc3TXkL83YxMlUzXbqw9TJI8O3x2jybBcvB5mGHqeNJrS X/Jp4xkdiLw7I7zHzpxRIlSK/tz4jt3bm2QQybZPEkIhHTfJ4fxfx7Y0kjISsibxGAl8 NFk7srUQFDj5++jIe0qfKZREg6FzdJk2ZY40xNc2gbM3rZGSL0VpGBFpBe5nKXexTtOK BJYw== X-Gm-Message-State: ABy/qLbVQj79/JwoqpCbLHEsntG7xcX8bOidSUh0DHJy3jSd7mJW8cmM J5osPPrdrOTzHd52YNHC/Wwyqw== X-Received: by 2002:a17:90a:1d46:b0:268:abc:83d5 with SMTP id u6-20020a17090a1d4600b002680abc83d5mr6012554pju.4.1690254324674; Mon, 24 Jul 2023 20:05:24 -0700 (PDT) Received: from ?IPV6:fdbd:ff1:ce00:1c25:884:3ed:e1db:b610? ([2408:8000:b001:1:1f:58ff:f102:103]) by smtp.gmail.com with ESMTPSA id t10-20020a17090aba8a00b002681d44071csm2043968pjr.46.2023.07.24.20.05.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Jul 2023 20:05:24 -0700 (PDT) Message-ID: <6049aa99-aa47-5137-f66e-350bc4723914@bytedance.com> Date: Tue, 25 Jul 2023 11:05:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 24/47] drm/panfrost: dynamically allocate the drm-panfrost shrinker Content-Language: en-US To: Steven Price Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-25-zhengqi.arch@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 > > One nit below, but otherwise: > > Reviewed-by: Steven Price > >> --- >> 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); >> } >