From patchwork Mon Sep 11 09:44:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379076 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 3B87CEE57DF for ; Mon, 11 Sep 2023 09:48:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC986B0204; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6BC06B0205; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0CE16B0206; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9F9206B0204 for ; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 798B480943 for ; Mon, 11 Sep 2023 09:48:32 +0000 (UTC) X-FDA: 81223841664.15.8085B51 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf07.hostedemail.com (Postfix) with ESMTP id A4B8440009 for ; Mon, 11 Sep 2023 09:48:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ru3T2Mk9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425710; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=wnhGwlVZn5o6Ts9l0idmDnFcHgDPeWYzaUkqiq1x/Q+gnNE5u3CXqtpjZPZgx2mdJPMQRO K/daBRMu5eNvpyOOG7QG3vPwQ+j4mUFpU77DVNSHkrBFcjetiK+5vaeVHYLLVjJ/Kpnsdv l0Mo78NMBiaEZenhxyBxxGdr/i3Qa4U= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ru3T2Mk9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425710; a=rsa-sha256; cv=none; b=T1ZGdxEBwW0Se4LOP/xaGiDe3YlSWvQPtl/UPwpbHfyxGsl0HSXp0uM5V1YimEnSwMsUVL H5vst5Pw4fZUxtRtvppWrDgjVtAXn0MNkMQZIT8HYuC7vBUhvICZbzW+7gyJ1CrtixtdEc IVVqCwcN0nyiLkA4IwzHxJ4YDqsDWuA= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-68fc49ccbf2so179261b3a.0 for ; Mon, 11 Sep 2023 02:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425709; x=1695030509; darn=kvack.org; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=Ru3T2Mk9LANvaqzuJvebACPhy2qMwM/MxVTZxa9cJS/5zfa1v6BbRjbB7Glnlt1Rpj VzA6kIM5SDGP5dQaKlyrI0fR7GpxKQjEItCc4SQfvTXvssmw1Lae8a07MnfKi8hBjt/b QdEbSaTr/q8PwG9aEc2OMl0U1gNNNo0N1EsqZDIlmHu3hoz6g+bhpW+WP0+P0oqfeZgf /aLYHYFIJFXf/FUpd4cArUgdMxxhE5HXYGI0j43Lc6TbjeBbpg1S6adb0meb7TAGXaek AFbyMqX7/QkwYH4erH6aesE+ftXsVe1l7990Qsi+TMV7mjTvOt/XUEfFq10q5CvDpTcb ztuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425709; x=1695030509; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=cv/2M0biVp2Jx3vcuD6PcisfbVLFnZ1XS3yteGmala/7vTXvhLY+MiWai38B1xvaVd bVdBXt2+GYgOt9e4fadHgxH4uQ0gwjOaZwedOj9lUdx8BlM8QdlKAVn8CFu3et+b8sfT y7ovDLeN8iLzNZDelUJHmT4NxCX/ccfSyj4g6mcFdIfKfUoDNCEivvfVcc4Kg7gi3lES Gbi6TfHvp8QHQyPTmhDml5hzutjkSMM/cpUImXnWP7uD4NaXKgrkNLr9h0cqOoxUkwmN RP3DUkLP/2+TJtxu9eNZiT14ycoUvoZFzk0daB3G15alKCexfZ7sJEreOZTfIbxM0nxL JtOQ== X-Gm-Message-State: AOJu0Yzt9rBucPfLafc4+iCeHRDT7FSC48zayGgYEPTcKqTl6GKbZXBW r+2uOzaHpU9fbDITbQFrT7SbpQ== X-Google-Smtp-Source: AGHT+IEVXSXkw085oDvvWfPml14cbTQZElHnedX5HQ1+xrEfL7OjLIxrqCMvit7SAM7BpPy3zY3/Wg== X-Received: by 2002:a05:6a21:183:b0:137:3eba:b81f with SMTP id le3-20020a056a21018300b001373ebab81fmr13305516pzb.3.1694425709623; Mon, 11 Sep 2023 02:48:29 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:29 -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 v6 22/45] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Mon, 11 Sep 2023 17:44:21 +0800 Message-Id: <20230911094444.68966-23-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: h1ntxk8g35b91za6y5dpnktsd3yi48kz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A4B8440009 X-HE-Tag: 1694425710-771287 X-HE-Meta: U2FsdGVkX19UPLu3aK/PzeHkDEnV+gWyR5ebY+f7jiDu4+LT1uAYEb2+JrkseDvz75BHstMwoTdXOIT7g0XSMaBqv4ewfLz07GwSMWb45m8wjwx4NfB0oliVxmuccRNrS7v/v7TTtkQN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bGcYRhJt3WuruFgmws7LqKPEddakm4Mhb4WxpQF8f3LxKuaXsHKrykZhl1ecVZRDhi5iSsL/y/5QVmPaZwswZGtQWkXru/fTepqrhKRoMbJ8S641AnVYyVwWIOYaJpl9ZTURPxl7HV0PwD2fJsbNlkYI/MHOeF8MpkFuI2Xij2y2y/Rfp5HdXF/Xu9rLkBbsvwHc3uweP+Igoy53OKzQnoX92BoPpNan5kIztwBx7gjJDnk56bU50GV7YsUJcP+c3WFbSCjNNCwVfNjA7B18X0mqtTFr1aQgcvM+noWIGJoraKz3zntXu5ITjICwpZY1XY3V958nZlewT6YM2qzpfXFTZQ5WEaB/KoP2V6N0ZNrdPLnDFffeoVwlVM+NRF/iIYV4cGaPdsj0hZjP0qw4pe1w01Pw9KbMb+QFjBiPaQzD8TOzUiorn08BPOs4= 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 | 29 +++++++++++-------- 4 files changed, 24 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..3d9f51bd48b6 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,21 @@ 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->private_data = pfdev; + + shrinker_register(pfdev->shrinker); + + return 0; } /** @@ -116,7 +122,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); }