From nobody Wed Nov 27 22:28:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445923; cv=none; d=zohomail.com; s=zohoarc; b=MMK7ER53EKJkf4tk3hcm0tfD27rqqxt66H9raAY80EFrjnZyvdfMHnudzHTQBFHEsKf8E8u+GvhoA7tkjLwKi+NY97Jm3cFBoZKfpz9iOl5MetE6yV3MzJ2XuQQ1C4pVpcw9D6qVTBA2lwdpNpfoqfD+c5HhvExLpdPwRHYA8xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445923; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=41xmtjHXWdMgLIKiQIRlxv7trVO9ZOyoGRN9dVMIVRc=; b=bQr5iqAsJao7Aylh6CqqCbBrlXJBUJsXD/frU99A6BCLwAFvyWgHnJoNBgbFTLrKiI5TQ0BvEPKhwxgIXTT+f8eAwh4dstkzlKBw0G2EGKpGX8XHTWAO9bYE5ATbO6YjDa3gzOpYvPsO0YLhPJ7e81ShlCt4IOq0iYMwzs+D388= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445923462353.4321348819383; Thu, 27 Jul 2023 01:18:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570894.893387 (Exim 4.92) (envelope-from ) id 1qOwBf-0000Xn-6m; Thu, 27 Jul 2023 08:17:31 +0000 Received: by outflank-mailman (output) from mailman id 570894.893387; Thu, 27 Jul 2023 08:17:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOwBe-0000VL-JO; Thu, 27 Jul 2023 08:17:30 +0000 Received: by outflank-mailman (input) for mailman id 570894; Thu, 27 Jul 2023 08:17:28 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw55-0001DS-61 for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:10:43 +0000 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [2607:f8b0:4864:20::42b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 142c4fa7-2c55-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 10:10:42 +0200 (CEST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-682ae5d4184so171173b3a.1 for ; Thu, 27 Jul 2023 01:10:42 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10:40 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 142c4fa7-2c55-11ee-b247-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445441; x=1691050241; 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=41xmtjHXWdMgLIKiQIRlxv7trVO9ZOyoGRN9dVMIVRc=; b=jJgBI8VQPI/Z/ccNdZLQtiBsmt12TPxNxcyEmmLc3cIOt24zWvO/St4DfrzxY5Admf 3SDYEYmgqkbX/HCmKk1mhlFmceeqU6DbMAGX6sKGDtq8kQ9lxaCqTKXpNvB2geQpeb/h vsR6q4NMVpErQyh+gExoRBpaWXOpdpMQoCMJklMeKJXld9SnNAjyhQYKrvvJBu4rqMJ/ BskSxQtm7+yyLnANci339dgBsgl+QpehmZaSNibUdDIkrrPM4ocpVsZrOOzcHGIll593 Cyr5YWDE/4EhF6WmCmYK5tukhzqSpwAn7rBK0/njtLGQr3gzTYmZeQalMU7Drn0Ngg3k gxSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445441; x=1691050241; 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=41xmtjHXWdMgLIKiQIRlxv7trVO9ZOyoGRN9dVMIVRc=; b=cM0aEXn5AIVyT3O6nvD1xe+3mlvh4uWwQmTUG1LG33mRqOYDoFwhuDajgo8VkyFAlR XHP6O50eDqFIwBl/FUG95b123wnrLI9b+6sYdx6SZsPl4ER6WYWGera7if0gDaTdDTVy lAoEfB0o9MBoKzHuroUnkjAu739nvHDFOsRnlj3Hiwhe6Rxe5GSilYUmrXkn5GXNFGNI RU7OZydMK8THoI9+VFDd4UxOlbZTEpHRuDiNO9Fr8zmRvid/cUPVZ0TRb8ddVkbzcZNp lRh1VSXqv1ifybWwMxYpjRiXy8QHNNZ5HaIo6n0gfSOwMHHFHC3W1raqsGocCV3EixjM fOtw== X-Gm-Message-State: ABy/qLZO07wSQJxLO1ChF/4XHc/41TDTbVU99QQyxTBmtleW4Z4N/X9X bZp7atyMfwWLeSP4uGQvU6LR9A== X-Google-Smtp-Source: APBJJlFv8o3eRUEIkT8KpumLsadZadNPzVgwQnm8JqI4lPxEdXnFu9DFIlRiQ246ApgsoZodQYjNqA== X-Received: by 2002:a05:6a20:1590:b0:137:4fd0:e2e1 with SMTP id h16-20020a056a20159000b001374fd0e2e1mr5901952pzj.4.1690445441148; Thu, 27 Jul 2023 01:10:41 -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, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.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-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng , Muchun Song Subject: [PATCH v3 24/49] drm/i915: dynamically allocate the i915_gem_mm shrinker Date: Thu, 27 Jul 2023 16:04:37 +0800 Message-Id: <20230727080502.77895-25-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445924729100001 Content-Type: text/plain; charset="utf-8" In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the i915_gem_mm 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 drm_i915_private. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 30 +++++++++++--------- drivers/gpu/drm/i915/i915_drv.h | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c b/drivers/gpu/drm= /i915/gem/i915_gem_shrinker.c index 214763942aa2..4504eb4f31d5 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c @@ -284,8 +284,7 @@ unsigned long i915_gem_shrink_all(struct drm_i915_priva= te *i915) static unsigned long i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *= sc) { - struct drm_i915_private *i915 =3D - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 =3D shrinker->private_data; unsigned long num_objects; unsigned long count; =20 @@ -302,8 +301,8 @@ i915_gem_shrinker_count(struct shrinker *shrinker, stru= ct shrink_control *sc) if (num_objects) { unsigned long avg =3D 2 * count / num_objects; =20 - i915->mm.shrinker.batch =3D - max((i915->mm.shrinker.batch + avg) >> 1, + i915->mm.shrinker->batch =3D + max((i915->mm.shrinker->batch + avg) >> 1, 128ul /* default SHRINK_BATCH */); } =20 @@ -313,8 +312,7 @@ i915_gem_shrinker_count(struct shrinker *shrinker, stru= ct shrink_control *sc) static unsigned long i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *s= c) { - struct drm_i915_private *i915 =3D - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 =3D shrinker->private_data; unsigned long freed; =20 sc->nr_scanned =3D 0; @@ -422,12 +420,18 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, uns= igned long event, void *ptr =20 void i915_gem_driver_register__shrinker(struct drm_i915_private *i915) { - i915->mm.shrinker.scan_objects =3D i915_gem_shrinker_scan; - i915->mm.shrinker.count_objects =3D i915_gem_shrinker_count; - i915->mm.shrinker.seeks =3D DEFAULT_SEEKS; - i915->mm.shrinker.batch =3D 4096; - drm_WARN_ON(&i915->drm, register_shrinker(&i915->mm.shrinker, - "drm-i915_gem")); + i915->mm.shrinker =3D shrinker_alloc(0, "drm-i915_gem"); + if (!i915->mm.shrinker) { + drm_WARN_ON(&i915->drm, 1); + } else { + i915->mm.shrinker->scan_objects =3D i915_gem_shrinker_scan; + i915->mm.shrinker->count_objects =3D i915_gem_shrinker_count; + i915->mm.shrinker->seeks =3D DEFAULT_SEEKS; + i915->mm.shrinker->batch =3D 4096; + i915->mm.shrinker->private_data =3D i915; + + shrinker_register(i915->mm.shrinker); + } =20 i915->mm.oom_notifier.notifier_call =3D i915_gem_shrinker_oom; drm_WARN_ON(&i915->drm, register_oom_notifier(&i915->mm.oom_notifier)); @@ -443,7 +447,7 @@ void i915_gem_driver_unregister__shrinker(struct drm_i9= 15_private *i915) unregister_vmap_purge_notifier(&i915->mm.vmap_notifier)); drm_WARN_ON(&i915->drm, unregister_oom_notifier(&i915->mm.oom_notifier)); - unregister_shrinker(&i915->mm.shrinker); + shrinker_free(i915->mm.shrinker); } =20 void i915_gem_shrinker_taints_mutex(struct drm_i915_private *i915, diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_dr= v.h index 682ef2b5c7d5..389e8bf140d7 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -163,7 +163,7 @@ struct i915_gem_mm { =20 struct notifier_block oom_notifier; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; =20 #ifdef CONFIG_MMU_NOTIFIER /** --=20 2.30.2