From patchwork Mon Aug 7 11:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343500 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 568F0C001DF for ; Mon, 7 Aug 2023 11:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D30F86B0074; Mon, 7 Aug 2023 07:14:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE0DC8D0003; Mon, 7 Aug 2023 07:14:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD0098D0002; Mon, 7 Aug 2023 07:14:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ADB1C6B0074 for ; Mon, 7 Aug 2023 07:14:55 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8D91D8084F for ; Mon, 7 Aug 2023 11:14:55 +0000 (UTC) X-FDA: 81097051350.28.2C57B93 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf07.hostedemail.com (Postfix) with ESMTP id A66794000D for ; Mon, 7 Aug 2023 11:14:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cGZjKVIa; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.178 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=1691406893; 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=41xmtjHXWdMgLIKiQIRlxv7trVO9ZOyoGRN9dVMIVRc=; b=cmcFMNWU0UIHMA2J/beSZjkWUWLHDTybEaNmFJy0dbKvzH7ol8IALn+BSc9HZLKthF+gPj L1hdFOaHE9owph+O70qLrlG5zSoGcSFq2GFLpZPc3sZCSeENJRNFsmue6105V5oV4gm9NI Zktm/tl/gqdUj97ZOWPkuCSE/PYT4v0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cGZjKVIa; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691406893; a=rsa-sha256; cv=none; b=rrH473kuhfFB6Bt9DUrheSxOwRxZBLmA4skOGpBi1OHUVYAEgfZ0jkaIedD0JJy4CmkZ8U jof3yva+yj9xx7HqkLJU6+AuY4S2i2wSWzhgkCaMXvix5V09CyNiQCLm/pHoxxaX4i4a6g XFISixUCUx709LWHlJr3cuy3/V94K/A= Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5643140aa5fso526036a12.0 for ; Mon, 07 Aug 2023 04:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691406892; x=1692011692; 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=cGZjKVIao4X1FE56kj8UAePkqWwhSzpoTbmrNAzfkmDpF5Xo4+OZiBUKSePxV9R+oc G1IRJ+7A7isb1SWVoDvsvP7l1acqUKxcQyd+kXEYl5Mu0ooyN6hulkaLMfilFtlIEGla KkeKIkL2nH6oGSLP/+1vanRLPdOnR/fS9enRnBTg7aqB7pi9sxUPyWaMbNSM9pXnXQt9 F+c8OaDe/t6AXuSYKYbMSCyXVTJsX7WpDTPUxY7FQSwi2t5FHO1P7yp1d3ZwE/GiUbMl ZFX6hlQGpFpm61JBWLj396znt7v4WHHVqgWWYpv/xKPpAaGWrpTBuQAyZLcxUgv1USuO WJbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691406892; x=1692011692; 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=VEk45x/EsRkw66p4WAqz8aGg+SiQf4eR7TTJ1IMv4u8U+QYCSu3wFSUSbSGqp1g4xr /t4Y5/plw6ZLBrx5E4RglTL10hSN2YYPz0nBtQPN2D231SO5sJxiYwfKODwuvAf1EhBj +8Fl9H01kK76Nbd5P7v4ufMwLCS9wroZUddT+B/QVWWhrsOGkkrmYd/dbbBHFZgjPGjh oliyd7nQXEp/5xxGBzc3g6iidg7K50gvTGZP1wgEjCJcCqPAw3ZTTeYJ6j7FkxKlc51e wjfjGNwWwy4aiRTl69hFeBiYzfDuE4fRMh/76VaZEZmORLCguOSd/jiAn2hGEZ0FqPew 5HkQ== X-Gm-Message-State: AOJu0YyKeBPPtMoxyKla32gNl0huVXkI6TByKUXGGMit/uVIBSW/7Az+ JEGQb9faWbAHpINJlJ58IZOKCQ== X-Google-Smtp-Source: AGHT+IHGYi4H3eJU6+xZDF9BksA4+I5hA9Bl5pPgRuSaTGIaReiVuXjmY2IFcPrIIfpO+IdhjanDJQ== X-Received: by 2002:a17:90a:9c3:b0:269:41cf:7212 with SMTP id 61-20020a17090a09c300b0026941cf7212mr4963504pjo.4.1691406892562; Mon, 07 Aug 2023 04:14:52 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:14:52 -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, simon.horman@corigine.com, dlemoal@kernel.org 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 v4 23/48] drm/i915: dynamically allocate the i915_gem_mm shrinker Date: Mon, 7 Aug 2023 19:09:11 +0800 Message-Id: <20230807110936.21819-24-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A66794000D X-Rspam-User: X-Stat-Signature: sb9oo5jfk58tc5mth7rkgnacasyeupos X-Rspamd-Server: rspam01 X-HE-Tag: 1691406893-684558 X-HE-Meta: U2FsdGVkX1+zzHsx+yby34y3iS5Yqt84gGz2qntIWTi0Ne9v1kPneVN4Y59/CKuejmdtX51EDnzmZrMUA0BtDe2xw4naFmvaPVcTgH2+bYxLXQmAVyayEbgm3bknm/WgUpARLm+1jmyaLN3UbDzPSUvS9lzdZxtvMg3qE07GGXHpoxtTycpxsJos7GBI2w3b7Im7MBa+RQLeIBdyLPpCzMWV6Wte6BC1ck//CXFfgLOcykqG4ujLNEYrCH9+e8J4t1dpurLTtf1EX01hBliYgWjGc41isPfSuYtPLWlTHU898sGyLcWUcjC7zhE4o99tKRHYZYUCcgxECwltvh2p7W6MgZrOSToIcA/Z7uOS4k1eNKjw247xIoiv8GBp/F1LWxjyXdZM/Bf+bmOsRFTeL5CRV1yQHZyClIy+e4YiDRLh59HZEJnPpQVLZ+kIABXy6DT5HGGQRXqa5epo1MdQsluYdCjO3Y7XQdzFHvB1q6p6iZbH7Zkq2dSlDZn32lRce4AgnSwpsloLOxjS9ZA/HmXIrhOqaVO4UGAKfSJXmnbjCWAFfJ0kZVGynkBU7fimunhHqknIRu5Twk6nvMKC2bvjczF760balUyQoobfKRY8GaXYxxaw9Eg+QSGpnP+Yijf040fJBuV+kGQKcs3lRw/G8tgF3//3NbvthNxeGxmXN4+StKqDCaXANnZBCjX4NeCwtEBPCT4a1YPbzS/t1rmPjnjptIHPRMHomq1q1c0jlldF71dEgdFJ8kdqQSqP0n9y/f+N19IAa3by+5b0JsLfUjf9poP8PkCNBALT7NxFfu2fp0YIgSDhc3XGpa8wED/hIZOkkWF+eb6UM112DhxYvDd5OjH0yjqTXFevwXu1+YmGz+UOc2wgRwHa7VY+n+wK2M74P9cGLhJ6WSUTPTi1I+8cApVEe8eMRH9yxWCM74rn3GE8XfH5u+4jZRCXiuBVtTKQD5SZ0rVFNFG uul+d8yo P9PNyWQuaJdZVfJgPxPv6euB8CQSB8B16SwhQHbcrUSNzTXZps8Q1RJ/4IDyrrW6DJbnK3MitwqFEPo/9MaSTTGS1UnPetdssbm7BcvvytbH6beHqw6B7HreqarKItNCXoghfouQMjresAMVSsHULTgeFmh8NpXBaO554nk0tfGUdfkO/ybJvdClhb1RTjwWuN0bbFkn9eSpZcU6ziaXTiTo1bIvbTDi45NriQs6XEkuwhmgPbd2aKWF9sqki6mzw9+q6zWdClJO85Eu6zUQcgw0+HlusvFKC7OTpo1sFYJtEaiUkmaj0dWE6uY9ISW7x8VmxUaRGwRmme0eHOMAKpXsmZH8Q592Zsc2WhqLE/1MEEm6zv179py2SR6arPQgQwlpy92gr6cY7ozlHMztMHI5yfyNUIZm00Z7MEHEed7n4zwD6PfGfZRpU3gHMgTt7wvQR4gWrj45zjdwWWoSzblXZxA== 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 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_private *i915) static unsigned long i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct drm_i915_private *i915 = - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 = shrinker->private_data; unsigned long num_objects; unsigned long count; @@ -302,8 +301,8 @@ i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) if (num_objects) { unsigned long avg = 2 * count / num_objects; - i915->mm.shrinker.batch = - max((i915->mm.shrinker.batch + avg) >> 1, + i915->mm.shrinker->batch = + max((i915->mm.shrinker->batch + avg) >> 1, 128ul /* default SHRINK_BATCH */); } @@ -313,8 +312,7 @@ i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) static unsigned long i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct drm_i915_private *i915 = - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 = shrinker->private_data; unsigned long freed; sc->nr_scanned = 0; @@ -422,12 +420,18 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr void i915_gem_driver_register__shrinker(struct drm_i915_private *i915) { - i915->mm.shrinker.scan_objects = i915_gem_shrinker_scan; - i915->mm.shrinker.count_objects = i915_gem_shrinker_count; - i915->mm.shrinker.seeks = DEFAULT_SEEKS; - i915->mm.shrinker.batch = 4096; - drm_WARN_ON(&i915->drm, register_shrinker(&i915->mm.shrinker, - "drm-i915_gem")); + i915->mm.shrinker = shrinker_alloc(0, "drm-i915_gem"); + if (!i915->mm.shrinker) { + drm_WARN_ON(&i915->drm, 1); + } else { + i915->mm.shrinker->scan_objects = i915_gem_shrinker_scan; + i915->mm.shrinker->count_objects = i915_gem_shrinker_count; + i915->mm.shrinker->seeks = DEFAULT_SEEKS; + i915->mm.shrinker->batch = 4096; + i915->mm.shrinker->private_data = i915; + + shrinker_register(i915->mm.shrinker); + } i915->mm.oom_notifier.notifier_call = 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_i915_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); } 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_drv.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 { struct notifier_block oom_notifier; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; #ifdef CONFIG_MMU_NOTIFIER /**