From patchwork Thu Aug 24 03:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363454 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 9AFD5C71145 for ; Thu, 24 Aug 2023 03:46:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3FFF2280095; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AFD48E0011; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22A06280095; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0B2628E0011 for ; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DD596C018E for ; Thu, 24 Aug 2023 03:46:56 +0000 (UTC) X-FDA: 81157612032.13.20F9A31 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) by imf17.hostedemail.com (Postfix) with ESMTP id 2138A4000B for ; Thu, 24 Aug 2023 03:46:54 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RN1mTOYq; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.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=1692848815; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=mEFZfPpEkPetTVsOGuPqdfSmJbzO4kyokRZGFW69OHu3SFn9jpIakI0+72vgYItpxTJGZ9 6X0b7J4FjMHPXmV4ttX3AQlscSZ1N/5MelJLiI02YLsq3kXMbmGqlSasPp38NerVeURCo/ jGk+zPsyCl4dq7HSQyepyrmoI9sKmuw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848815; a=rsa-sha256; cv=none; b=Ayg6mt2dTaOYYd4l+4PGwo0MXcA7QyQtpTtaV7PUAYD9RoRmWGHMYFTTHRjcH/vcP+B/sT is/+lr7UuaQ2pEv7nRXw6fbb7JB5N+ruov7q2ShWDHcIHAFZ3scjsSoaMChwWbOqqACN8+ pcvcuuSZzTdD19Q+R7TsRusgqnJzc6Q= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RN1mTOYq; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.53 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-57328758a72so32467eaf.1 for ; Wed, 23 Aug 2023 20:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848814; x=1693453614; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=RN1mTOYqeP3avt9zPEfyVXBeBNAQ8xUum2++yofpjKihMRzWKaexWVds4tD6V7wsIw 3d5/HMQodK2lDRKB3Hvhhg7R2LKBUPTz4foWriRhng96eFsm3nWKhQQ0/O6bcRFM3MJC +RLzQkwSUIX1ml+0BnTKRnbLipEaKec3PbjqhV9dxmp7JAWauKv/AeQCqdq/vzvHEFsf rCKVM7V0ua1GmOHzKpj68Ofh2DOeDKGWGBdHN71OFxMQ9d/TSugo+gBJOkmh9nR1r/OL eVcP9OEAfMz4av6avwQtJpiLw09RYNCv1fAajmP4zjNQQ2P7i9FdedmRGYhnia/2LEnH 3/Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848814; x=1693453614; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=WO9+LimnlM1DkQx47ySlkt9feGoKQRKs5devKy3YuESo2GGSShLTu2jV4P7ZGU1pop ls6ngTGfbR496w/eUqDMcLtY4vN4GvziKjoh+K6Dcrb/5UBofNjVKx2uTwKPzPN6tgs0 hEtfdJSc5T+jvMQajOiJLI/PRk3cmG5Gmeq25VzThtGsGgkY2V9HeH9oMIQ3DqBwLios ZzVHpYBI29XpF+FFRqVdgC/VXAU2+dRCERirbtNrPjcFtxe9jEHf1YdM47Qu3T35sT4/ jpEXPjWQ16kB0Bdkwc7mqg5jXc2Dx5oIXVfaXuvjMKvGISfwwPN71vxVoJraQUyvjCQq XZQQ== X-Gm-Message-State: AOJu0YwJ4kCyKZyg/sV4iHkPEjWyXvgUb2nIr/xRrgXQyIdsoqPGwVqt Hc/pDfTWnHZdkvAI6oiF/Fn9Mw== X-Google-Smtp-Source: AGHT+IFg9G87rSymCG7MIid1bupCDmKVyUn8qbP2ZMCQySTJZV8TnOPBtknFVjpmYamcXmmZPTN/qg== X-Received: by 2002:a05:6808:152a:b0:3a7:72e2:3262 with SMTP id u42-20020a056808152a00b003a772e23262mr17149902oiw.5.1692848814359; Wed, 23 Aug 2023 20:46:54 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46:53 -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 , Muchun Song , Daniel Vetter , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , Marijn Suijten , David Airlie , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v5 21/45] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Thu, 24 Aug 2023 11:42:40 +0800 Message-Id: <20230824034304.37411-22-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-Stat-Signature: wwkhfnn9qx6ms7mehn11mqww9rqubotc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2138A4000B X-Rspam-User: X-HE-Tag: 1692848814-326194 X-HE-Meta: U2FsdGVkX1+7sBVOq85mKML/kV9EFWtwr3NOYgzzVFjBpVa4ybtmPiTg192Jz6Idpq2Xdvr6TKglyA4/cIWoNtn5tLpyZzytd+TQHewOyRiz3t5Ugbeh+j926CZcZ3L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XsSGY7G3MK15kMWporA7NOspQ5meejpP28SDtFQ6eb6fTSEeT+8Zz42Hhms7z1Uptfjo3iAaRDJMfH/Lq6xSd3OPGkupOvXNU2TmYWgFUSTymlDJL+in9Tm13hGhyQf0THFiL8txxuSZ/2k5h8evvA244N1Ie5f7pBDu8FrgmQBojCxuZ5kogxzsJOMjqr9rcPd+vMHBzf4l9iRBBd4F9YsaqYtwPfApDSZGp/tqRnsKb9sdv8ueAzMCekrXrtRVrW+VHXxBK3bOXsizzjb7W95yWyX0sQT512EDcYrfXpHsv6VnvaF4/00T9CtkRS7VAdsc144mS36OOR1dKSy72SH09/GpBevRlpskY/Mwj7nRxuxDilLlAVDaQpCr8RZHkwz1hDh5jfn1jrCN//F70o/cuq63sLVepIzF+1+uraakSWFsHv9H6X3xtY5h54CWxXWCGmOjSCLFwbOzzPWe1SQHfhToi0+wLHfOb5RxeSvUkTwqGDEe6ZIKYEDVQ3z1lmQWBjXkLD58foCllPZ3R/OEYkj6wV5vyR3k+379O+fGeZxNzGBrs44nRDN6Nd+qQ== 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-msm_gem 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 msm_drm_private. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Daniel Vetter CC: Rob Clark CC: Abhinav Kumar CC: Dmitry Baryshkov CC: Sean Paul CC: Marijn Suijten CC: David Airlie CC: linux-arm-msm@vger.kernel.org CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/msm/msm_drv.c | 4 ++- drivers/gpu/drm/msm/msm_drv.h | 4 +-- drivers/gpu/drm/msm/msm_gem_shrinker.c | 34 ++++++++++++++++---------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 4bd028fa7500..7f20249d6071 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -462,7 +462,9 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) if (ret) goto err_msm_uninit; - msm_gem_shrinker_init(ddev); + ret = msm_gem_shrinker_init(ddev); + if (ret) + goto err_msm_uninit; if (priv->kms_init) { ret = priv->kms_init(ddev); diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 02fd6c7d0bb7..e2fc56f161b5 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -221,7 +221,7 @@ struct msm_drm_private { } vram; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; struct drm_atomic_state *pm_state; @@ -283,7 +283,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, unsigned long msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_to_scan); #endif -void msm_gem_shrinker_init(struct drm_device *dev); +int msm_gem_shrinker_init(struct drm_device *dev); void msm_gem_shrinker_cleanup(struct drm_device *dev); struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj); diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c index f38296ad8743..20699993e4f8 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); @@ -148,10 +146,11 @@ msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_to_scan) struct shrink_control sc = { .nr_to_scan = nr_to_scan, }; - int ret; + unsigned long ret = SHRINK_STOP; fs_reclaim_acquire(GFP_KERNEL); - ret = msm_gem_shrinker_scan(&priv->shrinker, &sc); + if (priv->shrinker) + ret = msm_gem_shrinker_scan(priv->shrinker, &sc); fs_reclaim_release(GFP_KERNEL); return ret; @@ -210,16 +209,25 @@ msm_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr) * * This function registers and sets up the msm shrinker. */ -void msm_gem_shrinker_init(struct drm_device *dev) +int 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(0, "drm-msm_gem"); + if (!priv->shrinker) + return -ENOMEM; + + priv->shrinker->count_objects = msm_gem_shrinker_count; + priv->shrinker->scan_objects = msm_gem_shrinker_scan; + priv->shrinker->seeks = DEFAULT_SEEKS; + priv->shrinker->private_data = priv; + + shrinker_register(priv->shrinker); priv->vmap_notifier.notifier_call = msm_gem_shrinker_vmap; WARN_ON(register_vmap_purge_notifier(&priv->vmap_notifier)); + + return 0; } /** @@ -232,8 +240,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) { WARN_ON(unregister_vmap_purge_notifier(&priv->vmap_notifier)); - unregister_shrinker(&priv->shrinker); + shrinker_free(priv->shrinker); } }