From patchwork Thu Aug 24 03:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB88DC3DA6F for ; Thu, 24 Aug 2023 03:47:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73402280096; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BCC88E0011; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53713280096; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D6548E0011 for ; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1CEA91C9064 for ; Thu, 24 Aug 2023 03:47:06 +0000 (UTC) X-FDA: 81157612452.09.2FD9FC8 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by imf24.hostedemail.com (Postfix) with ESMTP id 5630F180012 for ; Thu, 24 Aug 2023 03:47:04 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LJZYEmbS; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.53 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848824; a=rsa-sha256; cv=none; b=yp9aNoyEAfKTtH+SuVx5ShMI73p/6/rutr6/+PCD10/KxOiHdx6U6eiRTLeN1wYuj0xIM7 c/qKUbozC9wdnbviI9mI9MXRVn1QaAix8/4bgw5V40u/5QGLMkGgxpGLztPyob/K8dN59g Wq/mvH9LwuffC73cY8DsAkyufa65LnM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LJZYEmbS; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.53 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848824; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=C34/J9mfQV3vdC+9j+PqGI+jP4Qu6NdFI4NFaJGyvWeqQmHtK8QYIUqlXC/4WMHbD5WXfy xhRFSPK1Myj6pKc2bJqK8mxVnUCkJcXfdpBod8WatSNUxpPCXHl9qrlCIeamEfBs2XHzgb 9F0iF9ow95grQnx/ob5iG3mVqPBp/V8= Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-1c134602a55so1134285fac.1 for ; Wed, 23 Aug 2023 20:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848823; x=1693453623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=LJZYEmbSlDASLCkgz3hrEPH3dcI0rjqxRg5VcsDNmoqL0ZXgf1o1Y0h/XgghMDeH/K HNX4yAoxBp9QNokVvRY5nZw0cXdicizMAkH4jh7h0xLuD7ZTgWgj+TBan6hPOXN7Z6TU hktNUzMuauvT8xDdnVT3ksoiQbTyrLpmA4jYKOLqpQSWkN7+e8l+DAsYGtPGUoX88dMa MhAVrmwr61P7V2VVrv3ap/Xuz77qa49/YegrwTqoRUio1edOetxqGxTMb//9/u6Zu5JA fSsi178BoJRqOiBvb1O12Z7bFpYPDTJqk3QV2EuyDZ9LfRM9vXhUXI0bl2tIzM0ow6yb EmuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848823; x=1693453623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=glxJ4BNr2wPd0F+9WSX/YKtoYI4Vsji7Kb65qdqY5IN8KfjauCn1F3HOQ/mdv6ji6v TQLk9BiA8iS/FwBOA/ttLiQ1za56BK5i/G7fXbK1D5Fb7a15p/VCFTHg45yfTxzxOvRN sv1xlCmBRa0BXkI926ww3kbDjJgnB6c2RDJ7LdMjYuPfMmYV21prZd7JPgimhaqmGfRe 94Ukt4guINCc2Pba/KncooqPMTfugKKMPop8F+SUDzNuGtZxMbDXLK57Qd4VyMTfJypl lBvWqz9X5g1v3CaORQ40IUxwGDAT9oapRXrtKsim6qfMIKCB0rX9+5763mU15JYUtQuI Wm0g== X-Gm-Message-State: AOJu0YyfRTtguLY2Kk9owqnMXZckx9eDwPEFSu+fpd/ruESORjYjsk6r QdWLUuRGIVhpqO2NR/mZA42m2Q== X-Google-Smtp-Source: AGHT+IGdyhShqM39wj/kCYItFqjS8mjsUh5O2g0IqPZkGOxiCTY+W38pTQGVR8rjRvn0DxKx8gxMAA== X-Received: by 2002:a05:6830:6782:b0:6bd:990:1a2 with SMTP id cs2-20020a056830678200b006bd099001a2mr16253906otb.0.1692848823235; Wed, 23 Aug 2023 20:47:03 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:02 -0700 (PDT) From: Qi Zheng To: 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, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Daniel Vetter , Rob Herring , Tomeu Vizoso , Alyssa Rosenzweig , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v5 22/45] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Thu, 24 Aug 2023 11:42:41 +0800 Message-Id: <20230824034304.37411-23-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5630F180012 X-Stat-Signature: 9wjxz54ky7jju4zx7ycifawkn38dye16 X-Rspam-User: X-HE-Tag: 1692848824-521350 X-HE-Meta: U2FsdGVkX18fuJVQKyHkUOuXvWWhWfRcNRjqefgdZIihUIVuAPhKfH8XaJlP6JNRiubYwz+Vtk9mmGuu+6kxx4Dq08MQFb6QKSyZIiUGUOIVPtB+5qUbJEgOilWedpTbEAzvw8yvM4FAF4Z6zlph59DI7ADWffSclt1+p4+GpuwXgZuI0Ny6jpR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rWOY1ql/WOcmzYG4++63XkipBvOxiwejKFDWDD+8dwXBx7X4bErWEAJ7O14aNAcAghXP/iAXcfL3tf/+lSqj09u/ym3NuXUsXFfNcWTnAIvkZOfxGm+xUnafvpL5Nm8JA5qC2hvmAhGOqJvbQWbqMmNnyJbmIye3gZC8/SN4l2gtI7sGB9JpYy25sooDvUN5XeCFLoK/kw/Dq5MEqptU/l56UPuYbfcjlWrHPGUdMnmMNRtGTElY0MvWmf3H5xEKLi0sZXGBrMyEh0CEGGtau3WgfCkPgnouP5dZXKBLQMCbKgoVCkT4tOjAyNBQ35bibylReumaEb2xB0nKiXwo+LkpHD4+xMndBD9DgETk/v0D0QXWnrk9/J4mDoSPuZf3NH4miYwGrDtBZreeNvtMIa+OKHdxNc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the drm-panfrost shrinker, so that it can be freed asynchronously via 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 Reviewed-by: Steven Price Acked-by: Daniel Vetter CC: Rob Herring CC: Tomeu Vizoso CC: Alyssa Rosenzweig CC: David Airlie CC: dri-devel@lists.freedesktop.org --- 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 | 30 +++++++++++-------- 4 files changed, 25 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 a2ab99698ca8..e1d0e3a23757 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -601,10 +601,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 6a71a2555f85..3dfe2b7ccdd9 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,22 @@ 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) + 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 +123,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_free(pfdev->shrinker); }