Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10576818rwd; Thu, 22 Jun 2023 01:42:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GBKU+zl+swC3I6gHcBnfl+wfWxFqeAh58BY8ycLVUSOQ2zxflwt+FVSQiuIO/6Jf2q4Rd X-Received: by 2002:a17:90a:189:b0:25f:982:2d73 with SMTP id 9-20020a17090a018900b0025f09822d73mr7618432pjc.15.1687423359397; Thu, 22 Jun 2023 01:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687423359; cv=none; d=google.com; s=arc-20160816; b=rZmZ/D7oGmTcXrixPLPe5ycXD0ycSTyKUT4oaLO0xQOjV8KUmp3SZq1yoqrV1Nii/q YsbSsACY6+8CI/ccJcCueUli8DNuUDEQz9WZUJfQqqDhLLAPEoBPk9vJGbsxNZ409jt3 uCGUWe/vrluQmF5Hou3evSdFp+OvJgUyTSaawgjl+bHoMXo5WkDWkI6Wf5qOuFB1FhXs lvnFNNmf7tR+0Y/X6Uau8kM2mgVSzmeUoUMu/ZT6M3b9xQsHBB6JcJUoBULdg8R4Jcqa Lq3XTlYQXpnO7w5QGsxk8fNG7q7SBGmbR4gsGo26KfDE4fLe6J+ogyosES5XkeQ8HoJA 89Kg== 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=jsEwzAna4029RV6z6obfQmMl2Vwh1p3nS0yc9a+2Lh0=; b=Y5ExI1N1Qw4EWDrNmrpX0QnEsZ1bjJTMJgBZfR05EPvQjv74k2LbeOlUM3EB1KFg5t DSxX51dW8YG4akww7cEfBlcLLNFGFH2hSFKZJvij58VEVo+kAXlZC+o/ePBClgmeszg3 0U+CTEN2LJOINObcEBhbxJp63oy74xLOeCTGm09V4MwEiXJC+Qa08HdBvoc+ZOmxvviU aCzjd115xMzvkYI8NI9j+KpoAXx4xkWG4HlOuAshNEF34vlwmxy4TkXVvFOoku7A8cN3 zvioe/+r4U6c5GZscFu9CusfI0HwNRo1+pzl87VVuto+p5WZAJ+qEPN3OX8jb9nCh9sE 1OWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ozPKp77x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a17090aad8200b00244a45cb5c0si1207423pjq.42.2023.06.22.01.42.27; Thu, 22 Jun 2023 01:42:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linux.dev header.s=key1 header.b=ozPKp77x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbjFVIlB (ORCPT + 99 others); Thu, 22 Jun 2023 04:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231142AbjFVIko (ORCPT ); Thu, 22 Jun 2023 04:40:44 -0400 Received: from out-54.mta1.migadu.com (out-54.mta1.migadu.com [IPv6:2001:41d0:203:375::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC7B0212A for ; Thu, 22 Jun 2023 01:40:30 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1687423228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jsEwzAna4029RV6z6obfQmMl2Vwh1p3nS0yc9a+2Lh0=; b=ozPKp77xrQTWFLrt5JY9FY9sDiWzb4NwK8832YIIgpBuCa58zB9A3C1Ik+LPSf5cTp7v3t 9IJAZpdL4oTT3emFrHswJJuH9cCY+iz0ywCM1rCIq+rKQviZQ+esI9j+46bDRakK4PDGM5 vgbb47CgXrJSb8zRxEAcYTBfo6A4am8= 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, freedreno@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 04/29] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Thu, 22 Jun 2023 08:39:07 +0000 Message-Id: <20230622083932.4090339-5-qi.zheng@linux.dev> In-Reply-To: <20230622083932.4090339-1-qi.zheng@linux.dev> References: <20230622083932.4090339-1-qi.zheng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Qi Zheng In preparation for implementing lockless slab shrink, we need to dynamically allocate the drm-msm_gem 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 msm_drm_private. Signed-off-by: Qi Zheng --- drivers/gpu/drm/msm/msm_drv.h | 2 +- drivers/gpu/drm/msm/msm_gem_shrinker.c | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index e13a8cbd61c9..4f3ba55058cd 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -217,7 +217,7 @@ struct msm_drm_private { } vram; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; struct drm_atomic_state *pm_state; diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c index f38296ad8743..db7582ae1f19 100644 --- a/drivers/gpu/drm/msm/msm_gem_shrinker.c +++ b/drivers/gpu/drm/msm/msm_gem_shrinker.c @@ -34,8 +34,7 @@ static bool can_block(struct shrink_control *sc) static unsigned long msm_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct msm_drm_private *priv = - container_of(shrinker, struct msm_drm_private, shrinker); + struct msm_drm_private *priv = shrinker->private_data; unsigned count = priv->lru.dontneed.count; if (can_swap()) @@ -100,8 +99,7 @@ active_evict(struct drm_gem_object *obj) static unsigned long msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct msm_drm_private *priv = - container_of(shrinker, struct msm_drm_private, shrinker); + struct msm_drm_private *priv = shrinker->private_data; struct { struct drm_gem_lru *lru; bool (*shrink)(struct drm_gem_object *obj); @@ -151,7 +149,7 @@ msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_to_scan) int ret; fs_reclaim_acquire(GFP_KERNEL); - ret = msm_gem_shrinker_scan(&priv->shrinker, &sc); + ret = msm_gem_shrinker_scan(priv->shrinker, &sc); fs_reclaim_release(GFP_KERNEL); return ret; @@ -213,10 +211,15 @@ msm_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr) void msm_gem_shrinker_init(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; - priv->shrinker.count_objects = msm_gem_shrinker_count; - priv->shrinker.scan_objects = msm_gem_shrinker_scan; - priv->shrinker.seeks = DEFAULT_SEEKS; - WARN_ON(register_shrinker(&priv->shrinker, "drm-msm_gem")); + + priv->shrinker = shrinker_alloc_and_init(msm_gem_shrinker_count, + msm_gem_shrinker_scan, 0, + DEFAULT_SEEKS, 0, priv); + if (priv->shrinker && + register_shrinker(priv->shrinker, "drm-msm_gem")) { + shrinker_free(priv->shrinker); + WARN_ON(1); + } priv->vmap_notifier.notifier_call = msm_gem_shrinker_vmap; WARN_ON(register_vmap_purge_notifier(&priv->vmap_notifier)); @@ -232,8 +235,8 @@ void msm_gem_shrinker_cleanup(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; - if (priv->shrinker.nr_deferred) { + if (priv->shrinker->nr_deferred) { WARN_ON(unregister_vmap_purge_notifier(&priv->vmap_notifier)); - unregister_shrinker(&priv->shrinker); + unregister_and_free_shrinker(priv->shrinker); } } -- 2.30.2