From patchwork Mon Sep 11 09:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379075 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 6C2F3EE57DF for ; Mon, 11 Sep 2023 09:48:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0866A6B0202; Mon, 11 Sep 2023 05:48:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0366B6B0203; Mon, 11 Sep 2023 05:48:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E41326B0204; Mon, 11 Sep 2023 05:48:24 -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 D57086B0202 for ; Mon, 11 Sep 2023 05:48:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8C5BA12098D for ; Mon, 11 Sep 2023 09:48:24 +0000 (UTC) X-FDA: 81223841328.12.9534F19 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf27.hostedemail.com (Postfix) with ESMTP id B38CD40012 for ; Mon, 11 Sep 2023 09:48:21 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jbOlX3/p"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 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=1694425701; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=I4XIHDBKS4O0r5TFVnMLcGxiVO+XCXBod9+n8VxGNQuMj+sxui9+3whMY1QW5PxqOXNfyo rbJEuQQ+w98wf+Wdjn9M1faJ7vMp1OmA/imezIkzWX/0Tuoo0ZVUKhKg7idylQckAxaeMZ unJ38vuqpGUFE2jezyZzyDpYMRT0KXY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jbOlX3/p"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425701; a=rsa-sha256; cv=none; b=pSEargIqHUb3YNg1NMWtLQOazWn5yg6WStWPnZHyRJI/gFEGFWTvDOdBst2oDpDdlDvwor idFIOVTgCuOBhf2H5736WekS1gD4WGJa14+t8hKA1rvtscR4DosrdInnt7j8/5QL4F8fYp NkiXDemb/7IvFY830g2zqsoA1mjgsJY= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7088155ad.0 for ; Mon, 11 Sep 2023 02:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425700; x=1695030500; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=jbOlX3/pdoQkIM33VQ+oZKuOwERXJ4Fg77K2ba2f7/zAza/UC0xLLCydX4itoflZR3 u2lCf98p0cemc+SzuPjuth1r8qcjoYI/nHY9nCVAlFeUw+iojNjkOPh1fKTsLtzfQj4U /V0LxwrdYZ0xRHh5LhZXSSWKeQAv5MRj+6fEbFGFyKoHcdJ+6xThCM7+xd7ylQiayRkV a+P3hlIykXjC6BZXGaNLUe8BOMftVDNN3Ni/qE0s4vBjW+58rVxQAGI4SL1I2nKUisO9 HU1THsM5it3RQMgtwqBImbUKtLCvQEFzyR0vw7OkFPIVl4+op/7v0ycFOk2uoFPwJE44 fknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425700; x=1695030500; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=T0w0K36V7AHSXdTFvIbZWbG5NGQSjjgIBCPPijxEf72c82zPTlWPvaULe/zzncERPY 3svMAdNIbgwEqUKPR9G6aqzTPeQFWIWqzOfBaOVe29QDa/uGE1XREvk8OdPYOPTGNU4Y jCMp0pwVEV/qtiJvQJZ+mhIANBXEzj/bUCYpN+n6fImFaAwKKzBuIpgovkdCCvhXIkxP rlg8iXH/TiKEyKX54Vn93hkEjx83hVMW40CE4G7MIuFqDiDM+x41Eqs7XFPrAwD8ojOR WY5tGMpgnwdrpwDG7jUFTc++1loP+mVaeWYnDeau1wMYvLTrmAu1aNzglOe6N87xoAcb 32DA== X-Gm-Message-State: AOJu0YyB7aB2SEf+a9e2ToI+TEuicxPPZbksLs3OsXxVIfFMYM1GqZK3 +/+NOSzDVfOA/y36kylcKVr6iw== X-Google-Smtp-Source: AGHT+IE27vGs/uaz34ojq8+Ua2kGxMGmW1BLKwB00ljr5B+4yLh4dyEjB9Qga47N3yLXlwPZmv4ysw== X-Received: by 2002:a17:902:e750:b0:1c1:fbec:bc3f with SMTP id p16-20020a170902e75000b001c1fbecbc3fmr11508200plf.5.1694425700587; Mon, 11 Sep 2023 02:48:20 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:20 -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 v6 21/45] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Mon, 11 Sep 2023 17:44:20 +0800 Message-Id: <20230911094444.68966-22-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: 3sorfhhj51bno66w3w8pazeb8jg8mcww X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B38CD40012 X-HE-Tag: 1694425701-255311 X-HE-Meta: U2FsdGVkX1+ifdrojViHxPv43GdPNXqJQxE3wdTGGR5nwH18QJdKLLgwgqkxvGLEZJdghtqioBBWscy2RnlH3QVYiRDv2N0vwqVmskeOmR/3shIOYHHW3ufiZkyNFQ7Yx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ijdTlX3rb4AKdwlXedUnCael89uHOfSqi6vgsSSadYltvaqD2rpwGODlm/ldnXiKJrHzrG5+51LyPHgRK7tVxF413ib2MymPrEQfFk4js+RzYtRsaTUdzW1DxBw1/J4JUlZB6ZJeanSVJQiAEa8jVyhJ20iX+pSL6th6TJJ6wgNu8i4zAHdS8jSCXoBwb/ywekXIx9GJlkpYfFfMw06TpyyzXBqDDDW09xUDyy7ls8xITbudONTOJm3vtBYVSkX7JXo30em4vGtABu0V4f6rFJ7v+89OWsVaqxFuQerqA+roVPp700WgHrVkdxJ5Agzk0ZrYVyUYbVwAJ/bcLDXVxmHdoSjIBPUUteaJxJr8pFdt6eJdD1gy36OZsR3b0HFnaTPUQ1WRBmaKizK+RMgweODO8BI3A4M1LGFl8JXTdXx7ICrni76N1wJGFzeC05KtKrtIRmOxSVmfhmYMLkhIHExCbC+8Xn7OCu1TXBytZhnuEVxQYGs9f4cdEkSbJ5vny397JpWYs4CF2GoI7J8WWaRcSqDldJvIKAwc/MI3QpvR2KrSFk5Xs69EU4aMIg== 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 | 33 ++++++++++++++++---------- 3 files changed, 25 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..5a7d48c02c4b 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,24 @@ 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->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 +239,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); } }