Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10590339rwd; Thu, 22 Jun 2023 01:57:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vVqX12mTo5m8IBPoy/cpbg+3BRBmL5yOJIMJgQVwaTHG4WAHWCxuXVY9g/CqKJkM3jnfK X-Received: by 2002:a05:620a:6797:b0:764:6805:603e with SMTP id rr23-20020a05620a679700b007646805603emr2104786qkn.48.1687424274671; Thu, 22 Jun 2023 01:57:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424274; cv=none; d=google.com; s=arc-20160816; b=PlKtP1nSFUPszJWA+FiggRcundJQKjzq1bfLDcKtARsItCrbCP92hP4YpYixRxnAck VB2GMdLz9ihXezQU7aCmBUp6rqGXusUPx7t3WT6dIMrn8qGkYFamrlhvW3UHWAsUamgP k5q+l/FAbX6DlWt6QQh7JsB80lyrrL+j9vCChHY3kQtbSZ8YMkStBFxWlc+9SM9NTXNq 4LHnp58x0Xp4YlJ1WtTvkXL7JV/+dC+rtlvouJW0O3LU/Ozzh7+giXI6jVHjPVf+8ecb l9Pd2febeqq2SuBK4PZ+b0cdnPHEEACbAGBG7pIdSrKLp6tKSa8mSd64fSUSzCK3epmA qv1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TQaNNe8oXaUFeFpLguh+yca1iGAODo9pDL1sZw6pJSE=; b=NjrE9/yhH3NOncGS+ZMmrycAYCHzzN3iGvXWd4H826POoAafTeVVwpEK+YvA53WIEF LZ02teu5qPv6iEW4aMDUFWErIFLWPHQQV0K9XJ7w+8spghJiNr4QuHsDWa7GUl6c/4SK i0/3itkFMaRzPyECOFQUOdsmtrlyfWAuTJqRm7OnE2dG2RptJd40zVPyUBZ1p+wrxXWQ njunQecWN5N5ebg6Pa9Va4saWmi0m9EDb0o6O6rzFf+0usaJUqbHT3E/Py+BMBwTe5k7 iziS1wPGSj+PQNeqUIVLWlDMjhPZ6TTAd9NNR7n6I4h3VL+ST3U2HoqoaMQsd5JGeN9Q 3slw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=bLkRMM1j; 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 k137-20020a636f8f000000b0053fbb36fc65si6070357pgc.382.2023.06.22.01.57.42; Thu, 22 Jun 2023 01:57:54 -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=bLkRMM1j; 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 S231446AbjFVI4K (ORCPT + 99 others); Thu, 22 Jun 2023 04:56:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231451AbjFVIzN (ORCPT ); Thu, 22 Jun 2023 04:55:13 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF3D2107 for ; Thu, 22 Jun 2023 01:54:43 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1b5079b8cb3so12587905ad.1 for ; Thu, 22 Jun 2023 01:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424083; x=1690016083; 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=TQaNNe8oXaUFeFpLguh+yca1iGAODo9pDL1sZw6pJSE=; b=bLkRMM1jSdqXsEty9KLAFC9vFSq6Mb8s85EPujNxx1fG7cL+WhObUy7eJvjIIVVT27 Kiy5rsYxFdvQkjX/Hn7QfCF/H515sUldxTAV8THo6pKuerK5LdnjnrVU9ezaWAUUfrz8 rV0yX1ewF3SUu27Tytlc8UIGxdmoc2rf5KwQXmt4TN0xZENUrrBpDEpOBdYckFOGmW+/ CnWb/ghzLgegjrSPuJYmDsQVFRVYxO2XxU7X4C2jxwq5osf5N5i/+CYLyq1fNxhJsVCX q//piIl1OJNIHjgKTj8Fx/a4slkfZ5A+zdUvxvyRJBR/16JSIqSsZUTa9z9xdPFzC7nq BhVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424083; x=1690016083; 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=TQaNNe8oXaUFeFpLguh+yca1iGAODo9pDL1sZw6pJSE=; b=KCv3igdHlNgkjhunspgx50Wd8N33cu7cnWumtOJCn1igzxlXUq1EuJjBtDM+pyxS3J FQj8qrTFfhx105KN3m38tqwB8UdmkrheHm2Azv+jX8VrvQOuIQqXq4ONLCy/8NCHblk8 zKraWIY5wmD/OVRTp3MEc/KMt8mS19ssGV0rlomVsYC4vQ31xQRQlDAV1W4y+B4sERpA 9eGstPVXjcq7KNzVdFELbG18h338Lk6GzhdsYRatB9ytJO4SI4ICD/AKj42/4udAFjPW jpBgEJ5uGrosFMDIi2X1QnYBqxZq7O2q4cSdWHZ8xbHb5OHgH+vYH8BCUpKGs9aWJox2 8k7Q== X-Gm-Message-State: AC+VfDwo+yVWNqCj6C3yVg4uM581emZ6kac56Rc8JGmcdAA4Hc9Xw92W OkxFYBry3LG45HRnlFpKdhWj5Q== X-Received: by 2002:a17:903:32c4:b0:1b0:3cda:6351 with SMTP id i4-20020a17090332c400b001b03cda6351mr21555341plr.0.1687424083229; Thu, 22 Jun 2023 01:54:43 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:54:42 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.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-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 05/29] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Thu, 22 Jun 2023 16:53:11 +0800 Message-Id: <20230622085335.77010-6-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 In preparation for implementing lockless slab shrink, we need 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 --- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 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_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c index bf0170782f25..2a5513eb9e1f 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; @@ -100,10 +98,15 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) void 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_and_init(panfrost_gem_shrinker_count, + panfrost_gem_shrinker_scan, 0, + DEFAULT_SEEKS, 0, pfdev); + if (pfdev->shrinker && + register_shrinker(pfdev->shrinker, "drm-panfrost")) { + shrinker_free(pfdev->shrinker); + WARN_ON(1); + } } /** @@ -116,7 +119,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->nr_deferred) + unregister_and_free_shrinker(pfdev->shrinker); } -- 2.30.2