From patchwork Thu Jul 27 08:04:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329143 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 380D5C04E69 for ; Thu, 27 Jul 2023 08:06:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEC016B0080; Thu, 27 Jul 2023 04:06:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9C616B0081; Thu, 27 Jul 2023 04:06:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3C656B0082; Thu, 27 Jul 2023 04:06:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A26056B0080 for ; Thu, 27 Jul 2023 04:06:03 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4B60F1401A4 for ; Thu, 27 Jul 2023 08:06:03 +0000 (UTC) X-FDA: 81056658606.05.6818D0A Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf02.hostedemail.com (Postfix) with ESMTP id 4E8C380022 for ; Thu, 27 Jul 2023 08:06:01 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bWsdCjXI; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1690445161; 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=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; b=7w2r35+/MKPTp3VyzSvngKhWUIF7Mc3iT3pEV5ikRKSae+L9qJ8gzvSKMGqKte4F+PqwgQ 4M7yb3R2pePP8phoZ7EPt2PijnQo7n0vPcNBE1uiA7WzHQS28/ZnV+tniADhSOUngCLmN3 NE27XoiCbeyVBbWire169osSCoibFUk= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bWsdCjXI; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445161; a=rsa-sha256; cv=none; b=vVwTQrKiuxmDnj8hPp798o4VC9HjoyLRPIn2P3AEZ6DhonwFTjRlSss7YhBBMadoyLNqzc YBdG/tEjgu0EANvCdjxT8BnFP7YdDBq8431M35dstCugcQ1uHJ+kehVj2hLeN6gIl7cK50 NdUdH8QzNbjgEKloLqKO5BKOWlIDBHA= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-686f6231bdeso112247b3a.1 for ; Thu, 27 Jul 2023 01:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445160; x=1691049960; 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=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; b=bWsdCjXI/QTCbfrXnl1D1RHs1UzV532bO1xy0F2QKWdmxdeZNg1bc8fwYppoEa2Sii fv3Dw05OLiEoJFGdDqA0cK2BR0yissZW0QGh0p8G2jYOCo1VM3qmhhRKOuDu3Ld44+HC IlU/6E6PL7OGmulpkRgvQIFGvR7K7vSKmFATJlzNsM5VU0kfb+Q9ux9XLDln9HSGLjNa erFo50JbYYva+gdlhuASAFmcGCxJk1UklUElA3OcQq/NsulVXFSALP8x8A3jEL8k5O2s pAuqLDXkBW250K5e8xHlcez81V5k+DmAOms7sfdEUrryxL8JhS9LUOK5EJtF0pDaEYI9 8JWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445160; x=1691049960; 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=CmSKD1W4o1llBpukOwDAPdWOg+LYzWoL67ya0UPwqvg=; b=AtHOQP3wMOcRS3acLn6hGmNl3x3FR6NZ6rJJ5/AsuofZ7fDn1s8a4SICvIPhNFoEdl PdLHcwGnTXpA0C6p61+aDgUwJby9yN4wntX8sYiDa9d1oF09tYInQOw8YLUj4Q2OFMa3 uVsVRfIZGubrzsrBHygu/6V5X5RstmihPHjsqSZNC6hiCFoPsBD44gX6w/brUJtMifzr bxIIcEtU09o0qYoU0+qL2RdpSg9OBWAe0d8772wl3AsEX3NvLt+fS1FcSXqx2GgFzeQd XNpBYu60xnWSz7EEzsdFcRMqSUJ/eGUNd4skHsszmKF8m3A8MJLnrb08vU6n+MUTGNkq eiXA== X-Gm-Message-State: ABy/qLb2TvjBoLE8KIiwggKXDDnMcxnmXp8q/f+MUSpeq+ToUW4jFvFx 5ZsGGbT3M7UWTaA5rLaQfMK+QA== X-Google-Smtp-Source: APBJJlGsBl3klUilUFzaktHEHOMbkNlcOB/1K8g6HjcIbYlgfdxi92AgDTolw1HjCRkDLU6/tzA6hQ== X-Received: by 2002:a05:6a21:78a8:b0:137:3eba:b81f with SMTP id bf40-20020a056a2178a800b001373ebab81fmr6002609pzc.3.1690445159927; Thu, 27 Jul 2023 01:05:59 -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.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:05:59 -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 , Carlos Llamas Subject: [PATCH v3 01/49] binder: fix memory leak in binder_init() Date: Thu, 27 Jul 2023 16:04:14 +0800 Message-Id: <20230727080502.77895-2-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 X-Rspamd-Queue-Id: 4E8C380022 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wo4yike1d1jmdanchedrto5ft6cb9pib X-HE-Tag: 1690445161-795311 X-HE-Meta: U2FsdGVkX18g/cv+jn/mFJSzGRllXaPoE0M+GFAhagRG8/+ehlLbrKpr4+dNRvArmozV0CQUlOy9z6Ddpgntjq2Mtr+bY7ZkLVJQDrBisAr1twIHJzso2vhrBxTWQ/WxVH98StZ0p3u3u3Vt12mcZeLMQ7Ts2OFNdcL+AlPh59J66c0MCLYl4KTkLrT+1pJVdjOq4XrTJgKmYCWp2jMvimNV4zL+m6BUwwUIRFIGsYzACgYTRgaNcddZMGvBW4Ak+jO9y0gZmmoCERAR8PtlApJ1EINLy/RuukyoY14OoVG7Ata6D7qFg4NpKI6B99MjOSeBkbqfbvd2rj9vKji06vPebEVFKesUiIN2Xwls8BuFEuxAXh6GynTS/1037n4D6xQm7a3p3m9o73GyOd5sbLx55LtHX8zCxad4pIL75Rd8h/684vlnoQoAaA4hYGMR1uaRsDExpUsaauODSut7e63kKXDA7XPx1b3kAdHcJ8c6b5D+5PC6x3PhwagOX/ycRS+Hl1l13ZY8/1dWkruOYVlfoF0wq9z22Rp9MXaGeDmpLxyES/O+RsaOsdRDuVjBDGkkssKaOQwhKIcrx3k/8o03wkE60F8Cf9U/M76dCpNTWhC4/CxbRHViZN+bLz52zme4fgd+PN838MLh3zJmvCvRcI2T2lzinNG8sN5awrLF7w54hMP60boP+Kga6dRoHg0z9TD5KWaK1bFdbSf4xmU5ps81TjqjaGCRzlTnWbI2HVaBiqd/w2uaABEpR/iUS/OjTxgzZ7wEds+dbk4vPSX6BxKEUK03jYRLYh37tHlfR7p3BkJsgFttcpnD9t/D5xeuGn+KQM22tbzAdfnEspkgbfI0WQ3uHyZWwjeIestS+M/VZFS4AFiWItiv+keUf+D+xureFI6OX5+WwpbF77ILb30lQ72PYfWSP85W0PT2XbekHM5K2gIVNhVnn7e6FUP5ozyw7vFOiklBEZ7 Lq/OcNxt qoNdmcxuHsoM1qdQuy77qNBEqxQVtrBZ3Z8mPHb4U9MqhrVQ8aaRwljevAchqLlA0Zae1DlHqi0iKNuVPyLPxHX+X+YLm/iPWo0g/d6PqaEW4qrrrhT/zU0X7Kj/plOU4UWqOPAChxrRV0eRAw658bGB3rx6uZofOOlpEVkMhH+3IxFnwBNoMQonsDPR5fKz/4GnMkfHAlvC5+BZnIvg4H0cXd5jLRsj2znaaRdTgzg3nj0YlfhloagObplz/b3tBopNEpz7TU/RAZqXsY8De48lYk8Lkad7Qr3O2ud9WZCUpC2mL4MCjAeQ54aFwmcoeGp1WW1FWufwH0iP/1gQO56CT+sI1csytW1EhO53LmCisLOdbZ6c60r5Bda4QzZI5NZWEtE/rRcBxHryNWGXduGGiG+4ne4qzx66gn10YpJ+zit4TW5WoDLjFKXMl57uinIxjMuix1EW9wpRo4Jr1JjcH6llJeHaew9hEO6HbPHK9b9o= 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 binder_init(), the destruction of binder_alloc_shrinker_init() is not performed in the wrong path, which will cause memory leaks. So this commit introduces binder_alloc_shrinker_exit() and calls it in the wrong path to fix that. Fixes: f2517eb76f1f ("android: binder: Add global lru shrinker to binder") Signed-off-by: Qi Zheng Acked-by: Carlos Llamas --- drivers/android/binder.c | 1 + drivers/android/binder_alloc.c | 6 ++++++ drivers/android/binder_alloc.h | 1 + 3 files changed, 8 insertions(+) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 486c8271cab7..d720f93d8b19 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -6617,6 +6617,7 @@ static int __init binder_init(void) err_alloc_device_names_failed: debugfs_remove_recursive(binder_debugfs_dir_entry_root); + binder_alloc_shrinker_exit(); return ret; } diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 662a2a2e2e84..e3db8297095a 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void) return ret; } +void binder_alloc_shrinker_exit(void) +{ + unregister_shrinker(&binder_shrinker); + list_lru_destroy(&binder_alloc_lru); +} + /** * check_buffer() - verify that buffer/offset is safe to access * @alloc: binder_alloc for this proc diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h index 138d1d5af9ce..dc1e2b01dd64 100644 --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc, int pid); extern void binder_alloc_init(struct binder_alloc *alloc); extern int binder_alloc_shrinker_init(void); +extern void binder_alloc_shrinker_exit(void); extern void binder_alloc_vma_close(struct binder_alloc *alloc); extern struct binder_buffer * binder_alloc_prepare_to_free(struct binder_alloc *alloc, From patchwork Thu Jul 27 08:04:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329144 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 E6C61C00528 for ; Thu, 27 Jul 2023 08:06:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830376B0081; Thu, 27 Jul 2023 04:06:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E0BC6B0082; Thu, 27 Jul 2023 04:06:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A7CA8D0001; Thu, 27 Jul 2023 04:06:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5C3196B0081 for ; Thu, 27 Jul 2023 04:06:16 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 33153C109E for ; Thu, 27 Jul 2023 08:06:16 +0000 (UTC) X-FDA: 81056659152.10.68CBB75 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf14.hostedemail.com (Postfix) with ESMTP id 4ABE4100009 for ; Thu, 27 Jul 2023 08:06:13 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AHxGvLfH; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1690445173; 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=hMz0NiXWW4aad/y0uXjwCFa/Ag/H17CXQFU4sIH/+zs=; b=RBmAS2nHrdZvrthg1REhipSj+CIY5KmK6cTYYCOQcN3+HZgQTWJ7FozSB998ixy4xpkJC9 68psOZtEIf0Sz7WOgYJlexh/XH5M5eTtk1N9XG9nyZPItibuhTbAnC+lalhZ8IhC3Z5c7W WsiKeSZJiwrN9Y11a0vt7m6cS9wl65c= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AHxGvLfH; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445173; a=rsa-sha256; cv=none; b=eujEl7of/NXrL4w1YhRTkc5cjq0OhkaSKt6XujZYy8/8pgoSnITzr6Tucm0kHmGHfu3cVm UaeDppk8esvlqdDJtyzWyhJ/PAI7W6GXRRFOrHVS80TVI0Uw18i22yDuSAU3oMFyfOHQkr B4Zh5VYkloShQ/KO4fRsNbm3oQiPyN4= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6748a616e17so182231b3a.1 for ; Thu, 27 Jul 2023 01:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445172; x=1691049972; 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=hMz0NiXWW4aad/y0uXjwCFa/Ag/H17CXQFU4sIH/+zs=; b=AHxGvLfHLl40j8B2JJRU5s4VfBVIfkKAsI0cQEyx34RUKm+kvHJrB2iQzGzRnBcS3v 6USwrAVD49Q91VdWL412Beuc1lh9luLsvseTAfwZXNQFTlfXj/44XL3QSDLO3kE477UK PuQisTQDtaTenLhmz9UxJrWIk76t/9C2sGl3AoIFTG0F/GG2DtEXlZsFxPta58HNNxGh nuotqk/EcRuGp6B6DpQqHvzB1OaU8/LVfrpsdfcpoHM2+LjVOOXNlq+MDZzMAY0XeOby XoS1N9oa25ZJEGOvTPLqpEaa/2bkazEZHcopiam72Y0TXS5KlF1vjQrUn3lGIfR4Oiwn FzZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445172; x=1691049972; 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=hMz0NiXWW4aad/y0uXjwCFa/Ag/H17CXQFU4sIH/+zs=; b=C9zoDepvJ+kLxizUpb9iY/DKUaLVWaQebir7wgWdw1VuW76VSoXikixh/lwnPuXjqV ojQSGilCaoj6BHeLv+dmb17Rsp3Tr27L3pDszMBV4BTvZiLK2KGXsvNiVRnwpeIRT5HM zq6TeD/o2TsCdf+C86lyNEOwTMgFq55ILTovoo2ErIw2ogX69pjCZIMzrbx/TxE6ob4F 3UaLuvYErXp4lMoAggBaGtXTiMksp4m8yqDpBiKGwfQ+IUiE+M48m16Pop2Z4Svqdwvg 2w9DMrNpa7e6KcT7TydHZANqEo2ABlKd7K4aiPgMGhS3o16PCXaeWJnTFygq/w3KD9Ue R4YQ== X-Gm-Message-State: ABy/qLYpW5UVcPCuq+QnEIwIJJ5iNaFd+Q2BEXOE707g6rr8mCGBH/LX jgM1QVgs+QFEuYzshIseLZfPsg== X-Google-Smtp-Source: APBJJlELtr5cWJQ0To//AtRPEOYgFBMbhSo+p4MsXdX0IoPp5bJSVuIL2HKgeywTxbzsVW+qtVe8tQ== X-Received: by 2002:a05:6a00:4792:b0:668:834d:4bd with SMTP id dh18-20020a056a00479200b00668834d04bdmr4674312pfb.0.1690445172123; Thu, 27 Jul 2023 01:06:12 -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.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:06:11 -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 Subject: [PATCH v3 02/49] mm: move some shrinker-related function declarations to mm/internal.h Date: Thu, 27 Jul 2023 16:04:15 +0800 Message-Id: <20230727080502.77895-3-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 X-Rspamd-Queue-Id: 4ABE4100009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wu7ji58mfgsxuhx64tjxnst9rsxt51ax X-HE-Tag: 1690445173-759818 X-HE-Meta: U2FsdGVkX18S8cXTomIz5scOFW876gLz1fVS4KtNR9yZeKhvzv7QJyVJVDW/f5wRIR5VVZmYZTKA04d84DtQim/ZpYKEd+nO9e4CCXPd/lQOMexMqf5AkR46Pohtw9UA2SZtVv7Lm0BjCypaXfllv9cy3jwnHCRYWSk+Z2ma/WBDm7F1R9wR/Va4nphLxQC75fNdSBk1EMYxE7c6vrdw4KOrxggK6TlqkiX2T10fuJcI6M4kyuwHRJCe7ToKnsr3jpZfdoyRwOJrkI63awilK/UCRl9l95cX/yiWZHjzqxCTsuFau8Qiy9MTcggt4q7V7Ua9X4LNmw+RvuHUD7VrdjvbFHnwQze4nW6fUrD2L4hwqopvAU/kD8TjCBd9bvkyqDdpKn7MJ9F0SH7kV0diShL+xDgMuNbBhmuuAmHBiBV5V3p+yurMLPaFVbirQnnUizY84686f6d4ICAeKgw5dha4f9d4qCU8oiUwUOCwJ4k49dI6pxeiWOVCY3/lxkfYQj9cw17Y5LobpJYGzSDnwCS160sq8jXAEG7My0TUUE9doEpClCkAReoQ3G0EJ7YlF1zrqTQCo8zmUhHy5eA70Salikm77hOxswP29KeT+aPhgpRCKjqrXBbhpDEwOwF+Ewib8qbdo/sgxWz8AdzHSx8n7Wi1+mB1yzvhl1oi+kpW6nGsd2jHmfRgXwpw5VWBG5nKB0bwkRJr6X7hkgoPGr0FeWtDp1a3LaXuZIJ9FQevHUbh1W5VyeJEMfnJFf7WMnOGVVysZ39bTrX1/hTZ44NjNkKnrxcNSOL83xxQ5QoJiWWbjleeNI9j91/qejQdp5xiDBqCdKDUd0eaFGgLkjGYfDJVhaQ5wWqCEKD9UUTuEC4uwjbg8mtotfPRUJ9UdjB2hG13rok8dPB2Lb8CzJYX2CRAVwxACjdsdVRdtkCvrqeU8qMpBAkJKksHwALV5uHdWaXZlwiUQfJLlE2 MjHEHkwV q3POk/jRThUltynO3dyOUCTFSxNo/slbnHxxMzyog9reVYgU/beHno3aDvZOgulaZHHZIR31CRcCgGTpEId4jAphdQAhZckTw16D1jIJm4g8YQ4q8mRtmDZnPgrhfUlOtESi6P3fZYe03c54QleG3sm8EZd5QHmsqNMwe9moQ3RwnMKebwjaoFdehhIrf8zfq6A665SvpGU29ohSiohBnlpA/3hns5ytqqpKDp8ui+1UleyBZn6mE25tRez3rebNAxn/Hg6QCBiacGIfIMnWrkpJ0t6aOSa7A2o3zAvcc4jAyTW2uxEWY23n+wMdB9giTHyEd2+CkUcE3JXluDxcR177lyPy6rhEfPyvLrWlaMfLJY2Lo0O9aryviXb27PtMUuCMl4g/OYeOWZYHj5YM3V4GSrLv0hyLRA8kt 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: The following functions are only used inside the mm subsystem, so it's better to move their declarations to the mm/internal.h file. 1. shrinker_debugfs_add() 2. shrinker_debugfs_detach() 3. shrinker_debugfs_remove() Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 19 ------------------- mm/internal.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 224293b2dd06..8dc15aa37410 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -106,28 +106,9 @@ extern void free_prealloced_shrinker(struct shrinker *shrinker); extern void synchronize_shrinkers(void); #ifdef CONFIG_SHRINKER_DEBUG -extern int shrinker_debugfs_add(struct shrinker *shrinker); -extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, - int *debugfs_id); -extern void shrinker_debugfs_remove(struct dentry *debugfs_entry, - int debugfs_id); extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...); #else /* CONFIG_SHRINKER_DEBUG */ -static inline int shrinker_debugfs_add(struct shrinker *shrinker) -{ - return 0; -} -static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, - int *debugfs_id) -{ - *debugfs_id = -1; - return NULL; -} -static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, - int debugfs_id) -{ -} static inline __printf(2, 3) int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) { diff --git a/mm/internal.h b/mm/internal.h index 5a03bc4782a2..8aeaf16ae039 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1135,4 +1135,32 @@ struct vma_prepare { struct vm_area_struct *remove; struct vm_area_struct *remove2; }; + +/* + * shrinker related functions + */ + +#ifdef CONFIG_SHRINKER_DEBUG +extern int shrinker_debugfs_add(struct shrinker *shrinker); +extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, + int *debugfs_id); +extern void shrinker_debugfs_remove(struct dentry *debugfs_entry, + int debugfs_id); +#else /* CONFIG_SHRINKER_DEBUG */ +static inline int shrinker_debugfs_add(struct shrinker *shrinker) +{ + return 0; +} +static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, + int *debugfs_id) +{ + *debugfs_id = -1; + return NULL; +} +static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, + int debugfs_id) +{ +} +#endif /* CONFIG_SHRINKER_DEBUG */ + #endif /* __MM_INTERNAL_H */ From patchwork Thu Jul 27 08:04:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329145 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 9675CC0015E for ; Thu, 27 Jul 2023 08:06:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 328306B0082; Thu, 27 Jul 2023 04:06:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FD7C6B0083; Thu, 27 Jul 2023 04:06:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 150236B0085; Thu, 27 Jul 2023 04:06:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 035816B0082 for ; Thu, 27 Jul 2023 04:06:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B8A171C8A04 for ; Thu, 27 Jul 2023 08:06:27 +0000 (UTC) X-FDA: 81056659614.19.0B55B0C Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf15.hostedemail.com (Postfix) with ESMTP id BA486A0003 for ; Thu, 27 Jul 2023 08:06:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dFcunJeB; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 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=1690445185; 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=vI5hWAAeOUoE+dMovb/D2X/oBxOfX13HzrcTYb1vz0I=; b=WKQiMG5IHZPtYvWHMsNVnPetCgHXz0eyLqaW7GgnwN3Jg2jjKVCtpeU9jQmaaEVtoUGeog mTg9CH67d4GymDtiqZWE6wvU88tEmOrHYSwzZwOYWZHMjY0DRKqP5jpf+Pr+130f+ScYuz hKeXVvUlhK2lZ148WlVEGro1nHwVKlY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445185; a=rsa-sha256; cv=none; b=UG8uzAz7KAQdrNQfclaMC+94YcA2+UNyBQV9C18dgwACzPQGeb18D0QcjVJdR3ejpwH1MT Wid8oKLMeU+fH7VwqXX4XVetnjEMcZdResoieNBEKrdFqZWw/EjYWiq64xL5dYCFHRqQzo xl54szoOb4P5SWJs/xk4lPHknK7gGm8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dFcunJeB; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6862d4a1376so188235b3a.0 for ; Thu, 27 Jul 2023 01:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445184; x=1691049984; 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=vI5hWAAeOUoE+dMovb/D2X/oBxOfX13HzrcTYb1vz0I=; b=dFcunJeB79ox2F0Rn+L+Ss/aWoXzDxKcNTgoMtSiuj+R85Grv/ifhPoCAYtSbfGHwD TN0TMZIT88znj2keZ9rlGhcrxVh5zoF7ou5zBLgFYZ+8GtzSkW6ttwEwzrVZ73rrcsKk Bt5NstGzjNj5wQR0SJsSiScfi/AoSbSgUURLi5AbKNlwLcHNXojaazr7TUzXr0VxgpPh ilOatJLN9iwU3xsY4z4CNud6NNYXu/Juzbmnr02ENPJJbLqLArfiZgortFTjSKEVsx2h SvmWtZ3p0UXGsnvcQZtSSU/TR+kHNVgIw9puhY5Un5ogXuVZgRJ5ohSqB3ZskthfsuP1 MspA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445184; x=1691049984; 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=vI5hWAAeOUoE+dMovb/D2X/oBxOfX13HzrcTYb1vz0I=; b=Mj1UHQmyvA7HmebdHALM8uG9dKHunEOA3ZBbzDW262bYED2GH8xDSpnctWQZ1bVR8k bCsoA5OAU9R+gqt8M+57czZHOyStfhZPKDsNan/OCuJNI1EAsDrC0JTnbRqU3QTm6/i5 Sdvi5pjc2MAKswmGMxUnYwd2ivWXrCFUjqG5eIqNjxuBHkUXUAy81nMFXjiEnbvuXezK ZLcfZaMqXZhvSELdm4E18e0qA7OWYwUKW92ihtt6CplvBgXbFq+mfUC9VTivuDSmbt8Z 2LlEvRm6/gjrUC7Ci83Zqx0DnEHTldXs+vSI7iYpJL3RWPT3ZeJUhxWGRRsRTjjMUi4i gcuQ== X-Gm-Message-State: ABy/qLbjKq8dACU8vFpPwghbG4alhursiuVr2LVfvoo/5euY3MpRgVfw J8TZIojZ5YMvIEEwE8WfXZU+BQ== X-Google-Smtp-Source: APBJJlEb99v7+CdH8B0GZsAuMmdcyj4bEuOvXz2nhojj2e+pKLrqUoZ6mCJVVpRQiMktWs/uO/mPuA== X-Received: by 2002:a05:6a20:3d21:b0:134:76d6:7f7 with SMTP id y33-20020a056a203d2100b0013476d607f7mr5758628pzi.4.1690445184293; Thu, 27 Jul 2023 01:06:24 -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.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:06:23 -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 Subject: [PATCH v3 03/49] mm: vmscan: move shrinker-related code into a separate file Date: Thu, 27 Jul 2023 16:04:16 +0800 Message-Id: <20230727080502.77895-4-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 X-Stat-Signature: zhakcsoe6ciyoqe7kx8i19xynnrynbpn X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BA486A0003 X-Rspam-User: X-HE-Tag: 1690445185-843211 X-HE-Meta: U2FsdGVkX1+cmh5NNZNquhYHGHMDOvEAYYWdKV/pYY5qIFsZ2OX4osWlGK/nK7DpJFzb9p8R3CgqutE8x+dpbz2Fk0G5OXIyD0HGIpNG+bnYQ4QQYk9bjX1ODdgiPauJpHuqaUZB7KAayxgNo/I5Bn9zE076NEBQXVziKVMAee6hpZ87Twh+I4eiw/L7yWOk13U7zUIh9Yy5NgRblqdx9uZQ0lHuXSed3TKEU88NPiCzHgBtnqspZsL/YEG7FsEVRIsbFpf94WcIB34zYw4unjUQZX8whTVFudD7yRTxOHW5/RiitF+9KuW48UVIj7KXaDcjZ5ZIC/hD7wa4mGNFKsB6LJoVwwbMdE71gkgtQyCZ5KImh2lxqCd/P41SeggCj8fa4KjS+CdZTo/4eIHMGwJzDHVCe3ryxEtsUypb86yWXXMVV0og1X+SuLplWpMsgGvafSdutVPvJK5PiIGyzW37d8Yi7jdU9qAtE7oiug2WLTMORFiA+1rqMjvbBoHzdvGKNpF3TGh4oiI98rhBtmD+L0DRtc38H7EFUc0y9Wan9eiUroRJZPWT9A91YNNY83mcGG77MsHUafN3ygLBrQ7zJGmkbHEmmdEsGhc6h9Dk0lfahfJiIfUGBX1XUUHMQOC7AZKUTLjfwjfbosk1DrjfaB9ILqXVZMTJkuGt/LEFJs7FZX5WUHhAabXPDv2qAmI17Vm5KoeShm5z046sbaTDGuv7TWcrG/pAsRwKKEmA117mot0G2LYih92YLPsrOmC0mboPUIRVR36W+yvaWAo7Xv/efB5CoWkSe8mtthmXiualHBxZTMRS5i6R7+jwHODt4WezZoldG4Sp8W/KQgJiCYkTWQbhL1meP8TDrvHXoFfN7NTSynRRKO/q9qMq7aAbwJzy7iWF8NNokpPUEnJDAVPg/aPcoDWyvHuWwOJVlRA1gsMv47NsRK14A0vHJmA899BHQEDYW8T93UY ywcVfJQH nqk9bqhEzgjCUrsuyOdrdG8x5wwlELntOpMDAkg2z3u8JlJSn1tHjiTGdUEK890xzDxydrQvBhW2kZJMRPkYVsNyvrXYoGZpGGUL4c0tUuYRPuAyue83Y+mC/Lq87D7XOQTp88QjmwNt01bGMdFqX5EE23Iz4uxPhnaPOWyaBij+Bc3JzUZ3lohpahW7fi/9pJN4qTrR4hi65sal6slfkMRALHmdsYbhuhPyWEEQ5UvbYhEyFreL+BAhGkHM1IEAp/OEfqQDzr1tHBXE9+o1L3KQ3ePVWnOILezRmLwrimBKO0r0KJTOuxbqYKnp+2pbx5ocx9I6tng5yp1A7r8DYxSFDCQIvIMv9fo5soDPmqsNHje7u+4LNtSMOCHS1zq6tagxJvbVQRr75Jej5HVmmd3Ee36FC3cTdn6+K 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: The mm/vmscan.c file is too large, so separate the shrinker-related code from it into a separate file. No functional changes. Signed-off-by: Qi Zheng --- mm/Makefile | 4 +- mm/internal.h | 2 + mm/shrinker.c | 709 ++++++++++++++++++++++++++++++++++++++++++++++++++ mm/vmscan.c | 701 ------------------------------------------------- 4 files changed, 713 insertions(+), 703 deletions(-) create mode 100644 mm/shrinker.c diff --git a/mm/Makefile b/mm/Makefile index e6d9a1d5e84d..48a2ab9f86ac 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -48,8 +48,8 @@ endif obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ maccess.o page-writeback.o folio-compat.o \ - readahead.o swap.o truncate.o vmscan.o shmem.o \ - util.o mmzone.o vmstat.o backing-dev.o \ + readahead.o swap.o truncate.o vmscan.o shrinker.o \ + shmem.o util.o mmzone.o vmstat.o backing-dev.o \ mm_init.o percpu.o slab_common.o \ compaction.o show_mem.o\ interval_tree.o list_lru.o workingset.o \ diff --git a/mm/internal.h b/mm/internal.h index 8aeaf16ae039..8b82038dcc6a 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1139,6 +1139,8 @@ struct vma_prepare { /* * shrinker related functions */ +unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, + int priority); #ifdef CONFIG_SHRINKER_DEBUG extern int shrinker_debugfs_add(struct shrinker *shrinker); diff --git a/mm/shrinker.c b/mm/shrinker.c new file mode 100644 index 000000000000..043c87ccfab4 --- /dev/null +++ b/mm/shrinker.c @@ -0,0 +1,709 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +#include "internal.h" + +LIST_HEAD(shrinker_list); +DECLARE_RWSEM(shrinker_rwsem); + +#ifdef CONFIG_MEMCG +static int shrinker_nr_max; + +/* The shrinker_info is expanded in a batch of BITS_PER_LONG */ +static inline int shrinker_map_size(int nr_items) +{ + return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); +} + +static inline int shrinker_defer_size(int nr_items) +{ + return (round_up(nr_items, BITS_PER_LONG) * sizeof(atomic_long_t)); +} + +void free_shrinker_info(struct mem_cgroup *memcg) +{ + struct mem_cgroup_per_node *pn; + struct shrinker_info *info; + int nid; + + for_each_node(nid) { + pn = memcg->nodeinfo[nid]; + info = rcu_dereference_protected(pn->shrinker_info, true); + kvfree(info); + rcu_assign_pointer(pn->shrinker_info, NULL); + } +} + +int alloc_shrinker_info(struct mem_cgroup *memcg) +{ + struct shrinker_info *info; + int nid, size, ret = 0; + int map_size, defer_size = 0; + + down_write(&shrinker_rwsem); + map_size = shrinker_map_size(shrinker_nr_max); + defer_size = shrinker_defer_size(shrinker_nr_max); + size = map_size + defer_size; + for_each_node(nid) { + info = kvzalloc_node(sizeof(*info) + size, GFP_KERNEL, nid); + if (!info) { + free_shrinker_info(memcg); + ret = -ENOMEM; + break; + } + info->nr_deferred = (atomic_long_t *)(info + 1); + info->map = (void *)info->nr_deferred + defer_size; + info->map_nr_max = shrinker_nr_max; + rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); + } + up_write(&shrinker_rwsem); + + return ret; +} + +static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, + int nid) +{ + return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, + lockdep_is_held(&shrinker_rwsem)); +} + +static int expand_one_shrinker_info(struct mem_cgroup *memcg, + int map_size, int defer_size, + int old_map_size, int old_defer_size, + int new_nr_max) +{ + struct shrinker_info *new, *old; + struct mem_cgroup_per_node *pn; + int nid; + int size = map_size + defer_size; + + for_each_node(nid) { + pn = memcg->nodeinfo[nid]; + old = shrinker_info_protected(memcg, nid); + /* Not yet online memcg */ + if (!old) + return 0; + + /* Already expanded this shrinker_info */ + if (new_nr_max <= old->map_nr_max) + continue; + + new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, nid); + if (!new) + return -ENOMEM; + + new->nr_deferred = (atomic_long_t *)(new + 1); + new->map = (void *)new->nr_deferred + defer_size; + new->map_nr_max = new_nr_max; + + /* map: set all old bits, clear all new bits */ + memset(new->map, (int)0xff, old_map_size); + memset((void *)new->map + old_map_size, 0, map_size - old_map_size); + /* nr_deferred: copy old values, clear all new values */ + memcpy(new->nr_deferred, old->nr_deferred, old_defer_size); + memset((void *)new->nr_deferred + old_defer_size, 0, + defer_size - old_defer_size); + + rcu_assign_pointer(pn->shrinker_info, new); + kvfree_rcu(old, rcu); + } + + return 0; +} + +static int expand_shrinker_info(int new_id) +{ + int ret = 0; + int new_nr_max = round_up(new_id + 1, BITS_PER_LONG); + int map_size, defer_size = 0; + int old_map_size, old_defer_size = 0; + struct mem_cgroup *memcg; + + if (!root_mem_cgroup) + goto out; + + lockdep_assert_held(&shrinker_rwsem); + + map_size = shrinker_map_size(new_nr_max); + defer_size = shrinker_defer_size(new_nr_max); + old_map_size = shrinker_map_size(shrinker_nr_max); + old_defer_size = shrinker_defer_size(shrinker_nr_max); + + memcg = mem_cgroup_iter(NULL, NULL, NULL); + do { + ret = expand_one_shrinker_info(memcg, map_size, defer_size, + old_map_size, old_defer_size, + new_nr_max); + if (ret) { + mem_cgroup_iter_break(NULL, memcg); + goto out; + } + } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); +out: + if (!ret) + shrinker_nr_max = new_nr_max; + + return ret; +} + +void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) +{ + if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) { + struct shrinker_info *info; + + rcu_read_lock(); + info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); + if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { + /* Pairs with smp mb in shrink_slab() */ + smp_mb__before_atomic(); + set_bit(shrinker_id, info->map); + } + rcu_read_unlock(); + } +} + +static DEFINE_IDR(shrinker_idr); + +static int prealloc_memcg_shrinker(struct shrinker *shrinker) +{ + int id, ret = -ENOMEM; + + if (mem_cgroup_disabled()) + return -ENOSYS; + + down_write(&shrinker_rwsem); + /* This may call shrinker, so it must use down_read_trylock() */ + id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); + if (id < 0) + goto unlock; + + if (id >= shrinker_nr_max) { + if (expand_shrinker_info(id)) { + idr_remove(&shrinker_idr, id); + goto unlock; + } + } + shrinker->id = id; + ret = 0; +unlock: + up_write(&shrinker_rwsem); + return ret; +} + +static void unregister_memcg_shrinker(struct shrinker *shrinker) +{ + int id = shrinker->id; + + BUG_ON(id < 0); + + lockdep_assert_held(&shrinker_rwsem); + + idr_remove(&shrinker_idr, id); +} + +static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + struct shrinker_info *info; + + info = shrinker_info_protected(memcg, nid); + return atomic_long_xchg(&info->nr_deferred[shrinker->id], 0); +} + +static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + struct shrinker_info *info; + + info = shrinker_info_protected(memcg, nid); + return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); +} + +void reparent_shrinker_deferred(struct mem_cgroup *memcg) +{ + int i, nid; + long nr; + struct mem_cgroup *parent; + struct shrinker_info *child_info, *parent_info; + + parent = parent_mem_cgroup(memcg); + if (!parent) + parent = root_mem_cgroup; + + /* Prevent from concurrent shrinker_info expand */ + down_read(&shrinker_rwsem); + for_each_node(nid) { + child_info = shrinker_info_protected(memcg, nid); + parent_info = shrinker_info_protected(parent, nid); + for (i = 0; i < child_info->map_nr_max; i++) { + nr = atomic_long_read(&child_info->nr_deferred[i]); + atomic_long_add(nr, &parent_info->nr_deferred[i]); + } + } + up_read(&shrinker_rwsem); +} +#else +static int prealloc_memcg_shrinker(struct shrinker *shrinker) +{ + return -ENOSYS; +} + +static void unregister_memcg_shrinker(struct shrinker *shrinker) +{ +} + +static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + return 0; +} + +static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, + struct mem_cgroup *memcg) +{ + return 0; +} +#endif /* CONFIG_MEMCG */ + +static long xchg_nr_deferred(struct shrinker *shrinker, + struct shrink_control *sc) +{ + int nid = sc->nid; + + if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) + nid = 0; + + if (sc->memcg && + (shrinker->flags & SHRINKER_MEMCG_AWARE)) + return xchg_nr_deferred_memcg(nid, shrinker, + sc->memcg); + + return atomic_long_xchg(&shrinker->nr_deferred[nid], 0); +} + + +static long add_nr_deferred(long nr, struct shrinker *shrinker, + struct shrink_control *sc) +{ + int nid = sc->nid; + + if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) + nid = 0; + + if (sc->memcg && + (shrinker->flags & SHRINKER_MEMCG_AWARE)) + return add_nr_deferred_memcg(nr, nid, shrinker, + sc->memcg); + + return atomic_long_add_return(nr, &shrinker->nr_deferred[nid]); +} + +#define SHRINK_BATCH 128 + +static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, + struct shrinker *shrinker, int priority) +{ + unsigned long freed = 0; + unsigned long long delta; + long total_scan; + long freeable; + long nr; + long new_nr; + long batch_size = shrinker->batch ? shrinker->batch + : SHRINK_BATCH; + long scanned = 0, next_deferred; + + freeable = shrinker->count_objects(shrinker, shrinkctl); + if (freeable == 0 || freeable == SHRINK_EMPTY) + return freeable; + + /* + * copy the current shrinker scan count into a local variable + * and zero it so that other concurrent shrinker invocations + * don't also do this scanning work. + */ + nr = xchg_nr_deferred(shrinker, shrinkctl); + + if (shrinker->seeks) { + delta = freeable >> priority; + delta *= 4; + do_div(delta, shrinker->seeks); + } else { + /* + * These objects don't require any IO to create. Trim + * them aggressively under memory pressure to keep + * them from causing refetches in the IO caches. + */ + delta = freeable / 2; + } + + total_scan = nr >> priority; + total_scan += delta; + total_scan = min(total_scan, (2 * freeable)); + + trace_mm_shrink_slab_start(shrinker, shrinkctl, nr, + freeable, delta, total_scan, priority); + + /* + * Normally, we should not scan less than batch_size objects in one + * pass to avoid too frequent shrinker calls, but if the slab has less + * than batch_size objects in total and we are really tight on memory, + * we will try to reclaim all available objects, otherwise we can end + * up failing allocations although there are plenty of reclaimable + * objects spread over several slabs with usage less than the + * batch_size. + * + * We detect the "tight on memory" situations by looking at the total + * number of objects we want to scan (total_scan). If it is greater + * than the total number of objects on slab (freeable), we must be + * scanning at high prio and therefore should try to reclaim as much as + * possible. + */ + while (total_scan >= batch_size || + total_scan >= freeable) { + unsigned long ret; + unsigned long nr_to_scan = min(batch_size, total_scan); + + shrinkctl->nr_to_scan = nr_to_scan; + shrinkctl->nr_scanned = nr_to_scan; + ret = shrinker->scan_objects(shrinker, shrinkctl); + if (ret == SHRINK_STOP) + break; + freed += ret; + + count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned); + total_scan -= shrinkctl->nr_scanned; + scanned += shrinkctl->nr_scanned; + + cond_resched(); + } + + /* + * The deferred work is increased by any new work (delta) that wasn't + * done, decreased by old deferred work that was done now. + * + * And it is capped to two times of the freeable items. + */ + next_deferred = max_t(long, (nr + delta - scanned), 0); + next_deferred = min(next_deferred, (2 * freeable)); + + /* + * move the unused scan count back into the shrinker in a + * manner that handles concurrent updates. + */ + new_nr = add_nr_deferred(next_deferred, shrinker, shrinkctl); + + trace_mm_shrink_slab_end(shrinker, shrinkctl->nid, freed, nr, new_nr, total_scan); + return freed; +} + +#ifdef CONFIG_MEMCG +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, + struct mem_cgroup *memcg, int priority) +{ + struct shrinker_info *info; + unsigned long ret, freed = 0; + int i; + + if (!mem_cgroup_online(memcg)) + return 0; + + if (!down_read_trylock(&shrinker_rwsem)) + return 0; + + info = shrinker_info_protected(memcg, nid); + if (unlikely(!info)) + goto unlock; + + for_each_set_bit(i, info->map, info->map_nr_max) { + struct shrink_control sc = { + .gfp_mask = gfp_mask, + .nid = nid, + .memcg = memcg, + }; + struct shrinker *shrinker; + + shrinker = idr_find(&shrinker_idr, i); + if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { + if (!shrinker) + clear_bit(i, info->map); + continue; + } + + /* Call non-slab shrinkers even though kmem is disabled */ + if (!memcg_kmem_online() && + !(shrinker->flags & SHRINKER_NONSLAB)) + continue; + + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) { + clear_bit(i, info->map); + /* + * After the shrinker reported that it had no objects to + * free, but before we cleared the corresponding bit in + * the memcg shrinker map, a new object might have been + * added. To make sure, we have the bit set in this + * case, we invoke the shrinker one more time and reset + * the bit if it reports that it is not empty anymore. + * The memory barrier here pairs with the barrier in + * set_shrinker_bit(): + * + * list_lru_add() shrink_slab_memcg() + * list_add_tail() clear_bit() + * + * set_bit() do_shrink_slab() + */ + smp_mb__after_atomic(); + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) + ret = 0; + else + set_shrinker_bit(memcg, nid, i); + } + freed += ret; + + if (rwsem_is_contended(&shrinker_rwsem)) { + freed = freed ? : 1; + break; + } + } +unlock: + up_read(&shrinker_rwsem); + return freed; +} +#else /* !CONFIG_MEMCG */ +static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, + struct mem_cgroup *memcg, int priority) +{ + return 0; +} +#endif /* CONFIG_MEMCG */ + +/** + * shrink_slab - shrink slab caches + * @gfp_mask: allocation context + * @nid: node whose slab caches to target + * @memcg: memory cgroup whose slab caches to target + * @priority: the reclaim priority + * + * Call the shrink functions to age shrinkable caches. + * + * @nid is passed along to shrinkers with SHRINKER_NUMA_AWARE set, + * unaware shrinkers will receive a node id of 0 instead. + * + * @memcg specifies the memory cgroup to target. Unaware shrinkers + * are called only if it is the root cgroup. + * + * @priority is sc->priority, we take the number of objects and >> by priority + * in order to get the scan target. + * + * Returns the number of reclaimed slab objects. + */ +unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, + int priority) +{ + unsigned long ret, freed = 0; + struct shrinker *shrinker; + + /* + * The root memcg might be allocated even though memcg is disabled + * via "cgroup_disable=memory" boot parameter. This could make + * mem_cgroup_is_root() return false, then just run memcg slab + * shrink, but skip global shrink. This may result in premature + * oom. + */ + if (!mem_cgroup_disabled() && !mem_cgroup_is_root(memcg)) + return shrink_slab_memcg(gfp_mask, nid, memcg, priority); + + if (!down_read_trylock(&shrinker_rwsem)) + goto out; + + list_for_each_entry(shrinker, &shrinker_list, list) { + struct shrink_control sc = { + .gfp_mask = gfp_mask, + .nid = nid, + .memcg = memcg, + }; + + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) + ret = 0; + freed += ret; + /* + * Bail out if someone want to register a new shrinker to + * prevent the registration from being stalled for long periods + * by parallel ongoing shrinking. + */ + if (rwsem_is_contended(&shrinker_rwsem)) { + freed = freed ? : 1; + break; + } + } + + up_read(&shrinker_rwsem); +out: + cond_resched(); + return freed; +} + +/* + * Add a shrinker callback to be called from the vm. + */ +static int __prealloc_shrinker(struct shrinker *shrinker) +{ + unsigned int size; + int err; + + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { + err = prealloc_memcg_shrinker(shrinker); + if (err != -ENOSYS) + return err; + + shrinker->flags &= ~SHRINKER_MEMCG_AWARE; + } + + size = sizeof(*shrinker->nr_deferred); + if (shrinker->flags & SHRINKER_NUMA_AWARE) + size *= nr_node_ids; + + shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); + if (!shrinker->nr_deferred) + return -ENOMEM; + + return 0; +} + +#ifdef CONFIG_SHRINKER_DEBUG +int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) +{ + va_list ap; + int err; + + va_start(ap, fmt); + shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); + va_end(ap); + if (!shrinker->name) + return -ENOMEM; + + err = __prealloc_shrinker(shrinker); + if (err) { + kfree_const(shrinker->name); + shrinker->name = NULL; + } + + return err; +} +#else +int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) +{ + return __prealloc_shrinker(shrinker); +} +#endif + +void free_prealloced_shrinker(struct shrinker *shrinker) +{ +#ifdef CONFIG_SHRINKER_DEBUG + kfree_const(shrinker->name); + shrinker->name = NULL; +#endif + if (shrinker->flags & SHRINKER_MEMCG_AWARE) { + down_write(&shrinker_rwsem); + unregister_memcg_shrinker(shrinker); + up_write(&shrinker_rwsem); + return; + } + + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; +} + +void register_shrinker_prepared(struct shrinker *shrinker) +{ + down_write(&shrinker_rwsem); + list_add_tail(&shrinker->list, &shrinker_list); + shrinker->flags |= SHRINKER_REGISTERED; + shrinker_debugfs_add(shrinker); + up_write(&shrinker_rwsem); +} + +static int __register_shrinker(struct shrinker *shrinker) +{ + int err = __prealloc_shrinker(shrinker); + + if (err) + return err; + register_shrinker_prepared(shrinker); + return 0; +} + +#ifdef CONFIG_SHRINKER_DEBUG +int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) +{ + va_list ap; + int err; + + va_start(ap, fmt); + shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); + va_end(ap); + if (!shrinker->name) + return -ENOMEM; + + err = __register_shrinker(shrinker); + if (err) { + kfree_const(shrinker->name); + shrinker->name = NULL; + } + return err; +} +#else +int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) +{ + return __register_shrinker(shrinker); +} +#endif +EXPORT_SYMBOL(register_shrinker); + +/* + * Remove one + */ +void unregister_shrinker(struct shrinker *shrinker) +{ + struct dentry *debugfs_entry; + int debugfs_id; + + if (!(shrinker->flags & SHRINKER_REGISTERED)) + return; + + down_write(&shrinker_rwsem); + list_del(&shrinker->list); + shrinker->flags &= ~SHRINKER_REGISTERED; + if (shrinker->flags & SHRINKER_MEMCG_AWARE) + unregister_memcg_shrinker(shrinker); + debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); + up_write(&shrinker_rwsem); + + shrinker_debugfs_remove(debugfs_entry, debugfs_id); + + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; +} +EXPORT_SYMBOL(unregister_shrinker); + +/** + * synchronize_shrinkers - Wait for all running shrinkers to complete. + * + * This is equivalent to calling unregister_shrink() and register_shrinker(), + * but atomically and with less overhead. This is useful to guarantee that all + * shrinker invocations have seen an update, before freeing memory, similar to + * rcu. + */ +void synchronize_shrinkers(void) +{ + down_write(&shrinker_rwsem); + up_write(&shrinker_rwsem); +} +EXPORT_SYMBOL(synchronize_shrinkers); diff --git a/mm/vmscan.c b/mm/vmscan.c index 4039620d30fe..07bc58af6f26 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -188,246 +187,7 @@ struct scan_control { */ int vm_swappiness = 60; -LIST_HEAD(shrinker_list); -DECLARE_RWSEM(shrinker_rwsem); - #ifdef CONFIG_MEMCG -static int shrinker_nr_max; - -/* The shrinker_info is expanded in a batch of BITS_PER_LONG */ -static inline int shrinker_map_size(int nr_items) -{ - return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); -} - -static inline int shrinker_defer_size(int nr_items) -{ - return (round_up(nr_items, BITS_PER_LONG) * sizeof(atomic_long_t)); -} - -static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, - int nid) -{ - return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, - lockdep_is_held(&shrinker_rwsem)); -} - -static int expand_one_shrinker_info(struct mem_cgroup *memcg, - int map_size, int defer_size, - int old_map_size, int old_defer_size, - int new_nr_max) -{ - struct shrinker_info *new, *old; - struct mem_cgroup_per_node *pn; - int nid; - int size = map_size + defer_size; - - for_each_node(nid) { - pn = memcg->nodeinfo[nid]; - old = shrinker_info_protected(memcg, nid); - /* Not yet online memcg */ - if (!old) - return 0; - - /* Already expanded this shrinker_info */ - if (new_nr_max <= old->map_nr_max) - continue; - - new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, nid); - if (!new) - return -ENOMEM; - - new->nr_deferred = (atomic_long_t *)(new + 1); - new->map = (void *)new->nr_deferred + defer_size; - new->map_nr_max = new_nr_max; - - /* map: set all old bits, clear all new bits */ - memset(new->map, (int)0xff, old_map_size); - memset((void *)new->map + old_map_size, 0, map_size - old_map_size); - /* nr_deferred: copy old values, clear all new values */ - memcpy(new->nr_deferred, old->nr_deferred, old_defer_size); - memset((void *)new->nr_deferred + old_defer_size, 0, - defer_size - old_defer_size); - - rcu_assign_pointer(pn->shrinker_info, new); - kvfree_rcu(old, rcu); - } - - return 0; -} - -void free_shrinker_info(struct mem_cgroup *memcg) -{ - struct mem_cgroup_per_node *pn; - struct shrinker_info *info; - int nid; - - for_each_node(nid) { - pn = memcg->nodeinfo[nid]; - info = rcu_dereference_protected(pn->shrinker_info, true); - kvfree(info); - rcu_assign_pointer(pn->shrinker_info, NULL); - } -} - -int alloc_shrinker_info(struct mem_cgroup *memcg) -{ - struct shrinker_info *info; - int nid, size, ret = 0; - int map_size, defer_size = 0; - - down_write(&shrinker_rwsem); - map_size = shrinker_map_size(shrinker_nr_max); - defer_size = shrinker_defer_size(shrinker_nr_max); - size = map_size + defer_size; - for_each_node(nid) { - info = kvzalloc_node(sizeof(*info) + size, GFP_KERNEL, nid); - if (!info) { - free_shrinker_info(memcg); - ret = -ENOMEM; - break; - } - info->nr_deferred = (atomic_long_t *)(info + 1); - info->map = (void *)info->nr_deferred + defer_size; - info->map_nr_max = shrinker_nr_max; - rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); - } - up_write(&shrinker_rwsem); - - return ret; -} - -static int expand_shrinker_info(int new_id) -{ - int ret = 0; - int new_nr_max = round_up(new_id + 1, BITS_PER_LONG); - int map_size, defer_size = 0; - int old_map_size, old_defer_size = 0; - struct mem_cgroup *memcg; - - if (!root_mem_cgroup) - goto out; - - lockdep_assert_held(&shrinker_rwsem); - - map_size = shrinker_map_size(new_nr_max); - defer_size = shrinker_defer_size(new_nr_max); - old_map_size = shrinker_map_size(shrinker_nr_max); - old_defer_size = shrinker_defer_size(shrinker_nr_max); - - memcg = mem_cgroup_iter(NULL, NULL, NULL); - do { - ret = expand_one_shrinker_info(memcg, map_size, defer_size, - old_map_size, old_defer_size, - new_nr_max); - if (ret) { - mem_cgroup_iter_break(NULL, memcg); - goto out; - } - } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); -out: - if (!ret) - shrinker_nr_max = new_nr_max; - - return ret; -} - -void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) -{ - if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) { - struct shrinker_info *info; - - rcu_read_lock(); - info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); - if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { - /* Pairs with smp mb in shrink_slab() */ - smp_mb__before_atomic(); - set_bit(shrinker_id, info->map); - } - rcu_read_unlock(); - } -} - -static DEFINE_IDR(shrinker_idr); - -static int prealloc_memcg_shrinker(struct shrinker *shrinker) -{ - int id, ret = -ENOMEM; - - if (mem_cgroup_disabled()) - return -ENOSYS; - - down_write(&shrinker_rwsem); - /* This may call shrinker, so it must use down_read_trylock() */ - id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); - if (id < 0) - goto unlock; - - if (id >= shrinker_nr_max) { - if (expand_shrinker_info(id)) { - idr_remove(&shrinker_idr, id); - goto unlock; - } - } - shrinker->id = id; - ret = 0; -unlock: - up_write(&shrinker_rwsem); - return ret; -} - -static void unregister_memcg_shrinker(struct shrinker *shrinker) -{ - int id = shrinker->id; - - BUG_ON(id < 0); - - lockdep_assert_held(&shrinker_rwsem); - - idr_remove(&shrinker_idr, id); -} - -static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, - struct mem_cgroup *memcg) -{ - struct shrinker_info *info; - - info = shrinker_info_protected(memcg, nid); - return atomic_long_xchg(&info->nr_deferred[shrinker->id], 0); -} - -static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, - struct mem_cgroup *memcg) -{ - struct shrinker_info *info; - - info = shrinker_info_protected(memcg, nid); - return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); -} - -void reparent_shrinker_deferred(struct mem_cgroup *memcg) -{ - int i, nid; - long nr; - struct mem_cgroup *parent; - struct shrinker_info *child_info, *parent_info; - - parent = parent_mem_cgroup(memcg); - if (!parent) - parent = root_mem_cgroup; - - /* Prevent from concurrent shrinker_info expand */ - down_read(&shrinker_rwsem); - for_each_node(nid) { - child_info = shrinker_info_protected(memcg, nid); - parent_info = shrinker_info_protected(parent, nid); - for (i = 0; i < child_info->map_nr_max; i++) { - nr = atomic_long_read(&child_info->nr_deferred[i]); - atomic_long_add(nr, &parent_info->nr_deferred[i]); - } - } - up_read(&shrinker_rwsem); -} /* Returns true for reclaim through cgroup limits or cgroup interfaces. */ static bool cgroup_reclaim(struct scan_control *sc) @@ -468,27 +228,6 @@ static bool writeback_throttling_sane(struct scan_control *sc) return false; } #else -static int prealloc_memcg_shrinker(struct shrinker *shrinker) -{ - return -ENOSYS; -} - -static void unregister_memcg_shrinker(struct shrinker *shrinker) -{ -} - -static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, - struct mem_cgroup *memcg) -{ - return 0; -} - -static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, - struct mem_cgroup *memcg) -{ - return 0; -} - static bool cgroup_reclaim(struct scan_control *sc) { return false; @@ -557,39 +296,6 @@ static void flush_reclaim_state(struct scan_control *sc) } } -static long xchg_nr_deferred(struct shrinker *shrinker, - struct shrink_control *sc) -{ - int nid = sc->nid; - - if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) - nid = 0; - - if (sc->memcg && - (shrinker->flags & SHRINKER_MEMCG_AWARE)) - return xchg_nr_deferred_memcg(nid, shrinker, - sc->memcg); - - return atomic_long_xchg(&shrinker->nr_deferred[nid], 0); -} - - -static long add_nr_deferred(long nr, struct shrinker *shrinker, - struct shrink_control *sc) -{ - int nid = sc->nid; - - if (!(shrinker->flags & SHRINKER_NUMA_AWARE)) - nid = 0; - - if (sc->memcg && - (shrinker->flags & SHRINKER_MEMCG_AWARE)) - return add_nr_deferred_memcg(nr, nid, shrinker, - sc->memcg); - - return atomic_long_add_return(nr, &shrinker->nr_deferred[nid]); -} - static bool can_demote(int nid, struct scan_control *sc) { if (!numa_demotion_enabled) @@ -671,413 +377,6 @@ static unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, return size; } -/* - * Add a shrinker callback to be called from the vm. - */ -static int __prealloc_shrinker(struct shrinker *shrinker) -{ - unsigned int size; - int err; - - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - err = prealloc_memcg_shrinker(shrinker); - if (err != -ENOSYS) - return err; - - shrinker->flags &= ~SHRINKER_MEMCG_AWARE; - } - - size = sizeof(*shrinker->nr_deferred); - if (shrinker->flags & SHRINKER_NUMA_AWARE) - size *= nr_node_ids; - - shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); - if (!shrinker->nr_deferred) - return -ENOMEM; - - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __prealloc_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - - return err; -} -#else -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __prealloc_shrinker(shrinker); -} -#endif - -void free_prealloced_shrinker(struct shrinker *shrinker) -{ -#ifdef CONFIG_SHRINKER_DEBUG - kfree_const(shrinker->name); - shrinker->name = NULL; -#endif - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - down_write(&shrinker_rwsem); - unregister_memcg_shrinker(shrinker); - up_write(&shrinker_rwsem); - return; - } - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} - -void register_shrinker_prepared(struct shrinker *shrinker) -{ - down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); - shrinker->flags |= SHRINKER_REGISTERED; - shrinker_debugfs_add(shrinker); - up_write(&shrinker_rwsem); -} - -static int __register_shrinker(struct shrinker *shrinker) -{ - int err = __prealloc_shrinker(shrinker); - - if (err) - return err; - register_shrinker_prepared(shrinker); - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __register_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - return err; -} -#else -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __register_shrinker(shrinker); -} -#endif -EXPORT_SYMBOL(register_shrinker); - -/* - * Remove one - */ -void unregister_shrinker(struct shrinker *shrinker) -{ - struct dentry *debugfs_entry; - int debugfs_id; - - if (!(shrinker->flags & SHRINKER_REGISTERED)) - return; - - down_write(&shrinker_rwsem); - list_del(&shrinker->list); - shrinker->flags &= ~SHRINKER_REGISTERED; - if (shrinker->flags & SHRINKER_MEMCG_AWARE) - unregister_memcg_shrinker(shrinker); - debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); - up_write(&shrinker_rwsem); - - shrinker_debugfs_remove(debugfs_entry, debugfs_id); - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} -EXPORT_SYMBOL(unregister_shrinker); - -/** - * synchronize_shrinkers - Wait for all running shrinkers to complete. - * - * This is equivalent to calling unregister_shrink() and register_shrinker(), - * but atomically and with less overhead. This is useful to guarantee that all - * shrinker invocations have seen an update, before freeing memory, similar to - * rcu. - */ -void synchronize_shrinkers(void) -{ - down_write(&shrinker_rwsem); - up_write(&shrinker_rwsem); -} -EXPORT_SYMBOL(synchronize_shrinkers); - -#define SHRINK_BATCH 128 - -static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, - struct shrinker *shrinker, int priority) -{ - unsigned long freed = 0; - unsigned long long delta; - long total_scan; - long freeable; - long nr; - long new_nr; - long batch_size = shrinker->batch ? shrinker->batch - : SHRINK_BATCH; - long scanned = 0, next_deferred; - - freeable = shrinker->count_objects(shrinker, shrinkctl); - if (freeable == 0 || freeable == SHRINK_EMPTY) - return freeable; - - /* - * copy the current shrinker scan count into a local variable - * and zero it so that other concurrent shrinker invocations - * don't also do this scanning work. - */ - nr = xchg_nr_deferred(shrinker, shrinkctl); - - if (shrinker->seeks) { - delta = freeable >> priority; - delta *= 4; - do_div(delta, shrinker->seeks); - } else { - /* - * These objects don't require any IO to create. Trim - * them aggressively under memory pressure to keep - * them from causing refetches in the IO caches. - */ - delta = freeable / 2; - } - - total_scan = nr >> priority; - total_scan += delta; - total_scan = min(total_scan, (2 * freeable)); - - trace_mm_shrink_slab_start(shrinker, shrinkctl, nr, - freeable, delta, total_scan, priority); - - /* - * Normally, we should not scan less than batch_size objects in one - * pass to avoid too frequent shrinker calls, but if the slab has less - * than batch_size objects in total and we are really tight on memory, - * we will try to reclaim all available objects, otherwise we can end - * up failing allocations although there are plenty of reclaimable - * objects spread over several slabs with usage less than the - * batch_size. - * - * We detect the "tight on memory" situations by looking at the total - * number of objects we want to scan (total_scan). If it is greater - * than the total number of objects on slab (freeable), we must be - * scanning at high prio and therefore should try to reclaim as much as - * possible. - */ - while (total_scan >= batch_size || - total_scan >= freeable) { - unsigned long ret; - unsigned long nr_to_scan = min(batch_size, total_scan); - - shrinkctl->nr_to_scan = nr_to_scan; - shrinkctl->nr_scanned = nr_to_scan; - ret = shrinker->scan_objects(shrinker, shrinkctl); - if (ret == SHRINK_STOP) - break; - freed += ret; - - count_vm_events(SLABS_SCANNED, shrinkctl->nr_scanned); - total_scan -= shrinkctl->nr_scanned; - scanned += shrinkctl->nr_scanned; - - cond_resched(); - } - - /* - * The deferred work is increased by any new work (delta) that wasn't - * done, decreased by old deferred work that was done now. - * - * And it is capped to two times of the freeable items. - */ - next_deferred = max_t(long, (nr + delta - scanned), 0); - next_deferred = min(next_deferred, (2 * freeable)); - - /* - * move the unused scan count back into the shrinker in a - * manner that handles concurrent updates. - */ - new_nr = add_nr_deferred(next_deferred, shrinker, shrinkctl); - - trace_mm_shrink_slab_end(shrinker, shrinkctl->nid, freed, nr, new_nr, total_scan); - return freed; -} - -#ifdef CONFIG_MEMCG -static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, - struct mem_cgroup *memcg, int priority) -{ - struct shrinker_info *info; - unsigned long ret, freed = 0; - int i; - - if (!mem_cgroup_online(memcg)) - return 0; - - if (!down_read_trylock(&shrinker_rwsem)) - return 0; - - info = shrinker_info_protected(memcg, nid); - if (unlikely(!info)) - goto unlock; - - for_each_set_bit(i, info->map, info->map_nr_max) { - struct shrink_control sc = { - .gfp_mask = gfp_mask, - .nid = nid, - .memcg = memcg, - }; - struct shrinker *shrinker; - - shrinker = idr_find(&shrinker_idr, i); - if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { - if (!shrinker) - clear_bit(i, info->map); - continue; - } - - /* Call non-slab shrinkers even though kmem is disabled */ - if (!memcg_kmem_online() && - !(shrinker->flags & SHRINKER_NONSLAB)) - continue; - - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) { - clear_bit(i, info->map); - /* - * After the shrinker reported that it had no objects to - * free, but before we cleared the corresponding bit in - * the memcg shrinker map, a new object might have been - * added. To make sure, we have the bit set in this - * case, we invoke the shrinker one more time and reset - * the bit if it reports that it is not empty anymore. - * The memory barrier here pairs with the barrier in - * set_shrinker_bit(): - * - * list_lru_add() shrink_slab_memcg() - * list_add_tail() clear_bit() - * - * set_bit() do_shrink_slab() - */ - smp_mb__after_atomic(); - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) - ret = 0; - else - set_shrinker_bit(memcg, nid, i); - } - freed += ret; - - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } - } -unlock: - up_read(&shrinker_rwsem); - return freed; -} -#else /* CONFIG_MEMCG */ -static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, - struct mem_cgroup *memcg, int priority) -{ - return 0; -} -#endif /* CONFIG_MEMCG */ - -/** - * shrink_slab - shrink slab caches - * @gfp_mask: allocation context - * @nid: node whose slab caches to target - * @memcg: memory cgroup whose slab caches to target - * @priority: the reclaim priority - * - * Call the shrink functions to age shrinkable caches. - * - * @nid is passed along to shrinkers with SHRINKER_NUMA_AWARE set, - * unaware shrinkers will receive a node id of 0 instead. - * - * @memcg specifies the memory cgroup to target. Unaware shrinkers - * are called only if it is the root cgroup. - * - * @priority is sc->priority, we take the number of objects and >> by priority - * in order to get the scan target. - * - * Returns the number of reclaimed slab objects. - */ -static unsigned long shrink_slab(gfp_t gfp_mask, int nid, - struct mem_cgroup *memcg, - int priority) -{ - unsigned long ret, freed = 0; - struct shrinker *shrinker; - - /* - * The root memcg might be allocated even though memcg is disabled - * via "cgroup_disable=memory" boot parameter. This could make - * mem_cgroup_is_root() return false, then just run memcg slab - * shrink, but skip global shrink. This may result in premature - * oom. - */ - if (!mem_cgroup_disabled() && !mem_cgroup_is_root(memcg)) - return shrink_slab_memcg(gfp_mask, nid, memcg, priority); - - if (!down_read_trylock(&shrinker_rwsem)) - goto out; - - list_for_each_entry(shrinker, &shrinker_list, list) { - struct shrink_control sc = { - .gfp_mask = gfp_mask, - .nid = nid, - .memcg = memcg, - }; - - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) - ret = 0; - freed += ret; - /* - * Bail out if someone want to register a new shrinker to - * prevent the registration from being stalled for long periods - * by parallel ongoing shrinking. - */ - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } - } - - up_read(&shrinker_rwsem); -out: - cond_resched(); - return freed; -} - static unsigned long drop_slab_node(int nid) { unsigned long freed = 0; From patchwork Thu Jul 27 08:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329146 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 6C1E0C04E69 for ; Thu, 27 Jul 2023 08:06:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC3806B0080; Thu, 27 Jul 2023 04:06:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C74506B0081; Thu, 27 Jul 2023 04:06:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B15156B0083; Thu, 27 Jul 2023 04:06:39 -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 A3A2E6B0080 for ; Thu, 27 Jul 2023 04:06:39 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8606D1C8B32 for ; Thu, 27 Jul 2023 08:06:39 +0000 (UTC) X-FDA: 81056660118.19.890B5BD Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id 9A6C7100011 for ; Thu, 27 Jul 2023 08:06:37 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EEgKRQyP; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 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=1690445197; 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=5ddhCZTkz2TFo7oGCFzg4uU7nrLecafIDKLLill2eh8=; b=Es0pFLZtGXmK2k9QXBNPEa2jB4N4MK/6jLnmbSqkE6d7RCL78qzF2hs138iUT9LaWEPimX pE8r77HypXG+GZLrvQF/3UOm7MuXHVY5q0uOdwH56BA86kC6ktYQxati+zkr+QT8h0uhzc iDm7Lw+baii9v1aYz4QSVXNo2pp9uho= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EEgKRQyP; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445197; a=rsa-sha256; cv=none; b=N7NVGCJMTMZQMMQILkK+8IZdS29FM7PORkGg/04celEE67L++EaymfGWt7S9NaiKA0rAK6 KYpq1Pgpg1Y9A75ml5Dx/pwR7YFlppfsICjn3a+q8qkTGsBxAylr4lxhBzq3TUYqrx8ORn 8szJb1wB1JW8+kT+iUyEiJYukPXC2Y4= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6748a616e17so182346b3a.1 for ; Thu, 27 Jul 2023 01:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445196; x=1691049996; 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=5ddhCZTkz2TFo7oGCFzg4uU7nrLecafIDKLLill2eh8=; b=EEgKRQyP19rDGzyMkxrAyrND65/av9N1ZEpraFKdjf5iHd/PgC9Uhy/xnwzeo3ff8l m3TJD5UzpvFEDeBzcRtJtOD/qHmmEUSLFJuussVMd7PAkAK7iQKGftfC2f44nNeUEfJr mKle0CkHpRLYz5sWKpGW6Zb4t5WjMo/pANabwTgogYiGmsOD2+fKJGiw7ZJ36fC4jq2K 1KqECLKCfE0K//MR+hlNLb+3ZgY7viYlU4DaknQaSi+VFe2dV+fDBnzCaNkdmNFv1cVa f6nuMbduVm+LsREYRbVVclCckYchB0Qi+6OZAWegvIeaDdeHomKe1HhIBSolAxF7uDUX dSVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445196; x=1691049996; 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=5ddhCZTkz2TFo7oGCFzg4uU7nrLecafIDKLLill2eh8=; b=g8uHz6J0n8s+v2CXX8AJCk3qzdz5w+VGoG8wd6yRlmK4Jv7lzDKptMMxYRzgFU66dS jAqEZPmt5aRyMX/vGaZAqKrZlBdkwRS0eMxMK59FgCZaJRcDMko92KSwcNdff6ZjtML/ HFHfFyz7Kzdr9ZA9lYCBYnyE2yTFsvc3w3ghiZ6VagxaDB5TsyyjGD/XUBA7yN2hajgW DnNhzYoGSs61evitKbcd854jrX1nD40WM7wEfdofFgDi0OWLqG1EpTihfP8lgv+aWZSu JyMkXQql6mXKT5BrfwjKwLafKr9HU3hiqZMNEjoRpNaJADWm6anRxiz0mGMhIhXMCFuB IuXQ== X-Gm-Message-State: ABy/qLYpE9pCfHx0to6oZCKe/U9qmCTwbRiIcj+A7RkJN9cnpsTr2IwT aBCwcAVwyGJ3wUHrKQvou/gBFQ== X-Google-Smtp-Source: APBJJlGC9GcjpF//RTfgHk/e3ibfMuX5WCzda5QO/QIZ+yDcAz1vV0DX9dFwhd70yzWPOAQ384luFQ== X-Received: by 2002:a05:6a21:6da1:b0:134:1671:6191 with SMTP id wl33-20020a056a216da100b0013416716191mr5882289pzb.0.1690445196605; Thu, 27 Jul 2023 01:06:36 -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.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:06:36 -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 04/49] mm: shrinker: remove redundant shrinker_rwsem in debugfs operations Date: Thu, 27 Jul 2023 16:04:17 +0800 Message-Id: <20230727080502.77895-5-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 X-Rspam-User: X-Stat-Signature: paryphwmymrtff3q96yra6dckiwkxqcu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9A6C7100011 X-HE-Tag: 1690445197-670591 X-HE-Meta: U2FsdGVkX1+BNSnEmmKOzKhgtdKAd8posNCWoju33ZZZvGfqHIQ7c2AdPyuf4bMc8obHxgWnZ9/dJQ+ZhNhSeNXB3c+DVIUeOnCu617Djna04SOozJwe/ODBmH/gDhuYBFvLLWBsNJaahzJx2HxgTX3oTVLelLUsGTBqJ0syekf0n0oBpxCgzjgEMFQiKZp44ETRuedx2+hpo0BWY0kVc/ib3nhEAcmbO8REPx5X6FupwcitrEs5eIhOf6GeKFvnnbfd1ECcdbnYvkCfW3JmV0tfVLQ+IlpjYpy6XIctKZr4SUa5L9E59V/BDpSTJI6/TkhOdXSQRgnulCFWL3LN+NwbunETsOxnPUH+eirTMFcK5zrg5CL1qesLm20jpWm4KUhpEc94A+r635AvLb7CH+4VDm816DhilbY8dBPpNkNTig7Xd0WG+U6M2bXcSHslPpz1dCwwfhdNiZ6N77vlrvf69ZSqWSbRE+QV2i71VN/QzVWy5d4cXqfZslpWE8HpxvqIaJ34hyNDm1tWz07XBh7Vkh0Syh0UFzNQLOWxTiPpw3BN2+ndRG8KppAP0WWD3fEZWLesfl7yyH1oXdKoWPKfuz1zDFLOr1enhKIBGJJePAVgBkfDBPwZDV8zcoRBs+Ik2h7qqH1zWf1Aa77Q9SusQhGjD3LobRqSHiuJZSFI/KQW6ZEwiOkhKcT4taXiCUXWcsY8m3adB97D72mFrQpERyFYwbgYwRB+Dur5PWdliDm2MqipMq5RWcg0UIx6hjQ/J3cD9rHS72Og8SNvM85UhldtmjiYrjcWEDrrH/zUZpKl5tj5zCoqhhg/qfMC3wREhLTVGrjfpftqgmz54ZfFjhuZ4Ca7fOhbjokiOHpaVIqr/GrgZ8mdVknilk01HJJpAeCYSc9vcu3zTrqhkntmO1sRiJh/xSIxuzR1iQJ61kF1FLVE/Dl0jtEbe5nMvvcHQAOXYCJy2t6Nbjw Z5FqwUqv KXtjwwt6Ae/azaWFXyugL5SHBCpKLXD5V5wVoO985vExCDVD9rNl2O/uhkcZ5dOtH2vDZQQKZ60PyyNinz3QzyYYBtxYVtm0l4R+mb7ESIKioezQgGVr/B571YTCoBNXoyNW0JFaEMQSadeoAjgn2+KKX2J6x6gVp7K1IqS4EWmuJXB8f6HTfAQ2dHRYWr50B7aR00GXKVnXXR2ytJtU8ajL/tlIe2Ddz3nB7JUXt2/m/rXOeS3v+nmA6f+5XoGO+lW9Rnv0EbIhwGQvHzKiTKVV1UmRhrEc6PJdDmrrzpJNg790Y8XbKR0wSBbMVleGgcthSOdmQe568c26lEADzybFTItrlfLSqDHqxvrfyTlpix0GAhPtopX2VSbW2S36CN04UftFSZd7bi6682b+RpOUS5fo/s3b7lCP/nn8SrT3IezmiivEn2RG5JumpKjM7qBSIH8P+h2vKpUSD56USXqp29Q== 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: The debugfs_remove_recursive() will wait for debugfs_file_put() to return, so the shrinker will not be freed when doing debugfs operations (such as shrinker_debugfs_count_show() and shrinker_debugfs_scan_write()), so there is no need to hold shrinker_rwsem during debugfs operations. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/shrinker_debug.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 3ab53fad8876..f1becfd45853 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -55,11 +55,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) if (!count_per_node) return -ENOMEM; - ret = down_read_killable(&shrinker_rwsem); - if (ret) { - kfree(count_per_node); - return ret; - } rcu_read_lock(); memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; @@ -92,7 +87,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); rcu_read_unlock(); - up_read(&shrinker_rwsem); kfree(count_per_node); return ret; @@ -117,7 +111,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, struct mem_cgroup *memcg = NULL; int nid; char kbuf[72]; - ssize_t ret; read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1); if (copy_from_user(kbuf, buf, read_len)) @@ -146,12 +139,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, return -EINVAL; } - ret = down_read_killable(&shrinker_rwsem); - if (ret) { - mem_cgroup_put(memcg); - return ret; - } - sc.nid = nid; sc.memcg = memcg; sc.nr_to_scan = nr_to_scan; @@ -159,7 +146,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, shrinker->scan_objects(shrinker, &sc); - up_read(&shrinker_rwsem); mem_cgroup_put(memcg); return size; From patchwork Thu Jul 27 08:04:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329147 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 6DA2AC001E0 for ; Thu, 27 Jul 2023 08:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1048F6B0081; Thu, 27 Jul 2023 04:06:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B5206B0083; Thu, 27 Jul 2023 04:06:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E70898D0001; Thu, 27 Jul 2023 04:06:53 -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 D94D36B0081 for ; Thu, 27 Jul 2023 04:06:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A56F0140F6E for ; Thu, 27 Jul 2023 08:06:53 +0000 (UTC) X-FDA: 81056660706.27.83414B2 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 8C1DD180016 for ; Thu, 27 Jul 2023 08:06:51 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GBN6icr0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1690445211; 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=BqN9tp9prAKwSL/xaaZwvgP8yGlZqKh7lkz65rMIkwI=; b=XSShq1gh27U2elVmYs7vOcPA4/y6zgo9wvSDXRx+HL/Q7OoJuxtFYzrRw16ceeGO1y/H3l 5sKxzuYdNpGsvTbAO+EUji5QHLlPnz9HdpJsxzbQEUSS7QAAWY9B2/qgD1bcTZsNqDjICp 5i0G09kkerAavJm8zHAzglKB2sV1ne0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GBN6icr0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445211; a=rsa-sha256; cv=none; b=mNvVfz/u/9LEOVu5r77FZpiR0mTNsHf9kZb5KEalWrG6e/HtUagZemnLKYYKnHYuWSXIcn WzzyxBwRPkvfuGpK65aczX6dIiWnak/2yWk326jhxD9kv9EbaB4tS2uK2tUXRvmwTQiVNF uJMdGkqEzCSqJKcpr5bwtdGxfUAs5X4= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6748a616e17so182394b3a.1 for ; Thu, 27 Jul 2023 01:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445210; x=1691050010; 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=BqN9tp9prAKwSL/xaaZwvgP8yGlZqKh7lkz65rMIkwI=; b=GBN6icr0hE5mqHPTJBEmQxE0sSmLZpA0St1dP4Z/yKynevT5W5Jxqj0TR7Mr4urM6a rcvFQA+K57yE1B1k6K85qRXWvWixdU3NSLe4VzCycF5GoWTLlRciA5X2RKhqi0HQoE8b 1a0IYfWezvO06Io3dLOeFyq1ZqsXTQYxhrgkmMYVYzQ0UKpbC4ibvswUM8qhqUbr7+wb uRN2A2UnEH8zWwCm8m7EgP4dOqoYkNd5OlXdJtG3fRVi7RhcVNJSFfLr6LMTE1C8b+sp ezPa3QCc3RdGZTkOuGv4gf4U4junA2Kk+3yhYNlyx/A90D5GFHra7wi3SwF/mLuKqPhB hHsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445210; x=1691050010; 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=BqN9tp9prAKwSL/xaaZwvgP8yGlZqKh7lkz65rMIkwI=; b=Fkw5ac+kBc0A1cbyCInUNyTBOf9VpR0R8HXYckh/xFO+PL7Du4+sxifS1R3br3pS+a OgJycq7ls68ECj69Wnp0S30Kq6MtfwOCRcSBHEqr09Wcl4Oluq3d6rpuShi9ejaSZgnj W6K4W7vNQ4GIVEtr2Iuh+xySsu7JiN1wwvayS36aramIyz0Rj+9QMN7APWC1O1ShhYyr vbsGTySTwOlWzoPmnux03f0SRs1jjBXkMclQxoa6gtCBXVz5iKrHRstdQx6H2nVbeMER vSi5RuwuDDLX14HJsQEhGzkbx2u7B8CpVUEJSjfECZELT/sYGTK9QenDWaejzA/UiUYl N8Og== X-Gm-Message-State: ABy/qLYefPLdc0Jv67RA+68Az9vlbbANZ6B/Rwxwvog3B2xxP1RcA23d QXXSQFRNaOf1v4vKmW2fSM9FtA== X-Google-Smtp-Source: APBJJlGqyHUGzcwYP72gZn72jBkXTN2mSwLe5z3KDdW3R9YyUcC+gdVHx8KhimUXzhfrGyXx8SlIVg== X-Received: by 2002:a05:6a20:918e:b0:11a:dbb3:703b with SMTP id v14-20020a056a20918e00b0011adbb3703bmr5539836pzd.6.1690445210111; Thu, 27 Jul 2023 01:06:50 -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.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:06:48 -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 Subject: [PATCH v3 05/49] mm: shrinker: add infrastructure for dynamically allocating shrinker Date: Thu, 27 Jul 2023 16:04:18 +0800 Message-Id: <20230727080502.77895-6-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8C1DD180016 X-Stat-Signature: bq9d71gxnimmey5nhgi8984mbc6e3qs6 X-HE-Tag: 1690445211-407985 X-HE-Meta: U2FsdGVkX18gC14A6eZdvgJbBAWwJOmLAiwp6oNvlvzZoxGB5ouAzIYNzdMIkNJE1ePAQvY7CFHsXbq+ZnihWGg2K5SyJCLxXYQ8mUZyI0JnwYIFKxvqWMMKJ3Sr4S4/5Ze/p0/6LwdT7UhsILW4de+ufLmPOObpFHt0evziTkk233liSP9hfbZBPS2vq/3wJKQLtC83/mOOquF7GLmmS+exdsKDpi41O2hsQTa0LmaXpzoEEDRJwcOvenKg5Vz3QUahxDFP+FV8EL21X9FM9EbeiqTg5jBmvv5AbkuAeVUf7Ci8yt3HlA1zqKYwKalEpoeIeek0xsAQPlUHi7PHVxX0lV1fei2Xpf3mlA6Y4fr4vsHABoouyB/Smum12s3xIBB5n3sLseWkzcsxiJS2sqfEOL3IZjCYfUVmcNe921izNP9Yg999YKk7jM71g3Q0o0MqVG4i9TXKbiimbUCxk3YJR9PR7tyBjrGUYa+0qpY8kivQuLAsEYVx0aCDmT8Xm/S7qQ9QJn+s1SFuOSqXgUpd8wI0Gnrq2ggl8fBBCqkTJ0Dlh+2fRvwGZiQ7JqRmxB+I7tnXdwkuovS4iKCfrrQ0fwjRJ2ag8nadLpi7RZYzjNCPiX/gKCYvxivD2yzm95XohyBY420pEmdTNOGTcWKEsobtq/6Z79aQdyp+jNO2Rh5Xb4MavMiz22hC2xZaCsVwwsCSnjGjQ01JP3UtdKjM8dAESFxdCcyrMAa7hwcvsyzK40HLLlh8D2/9SyT0Vw7++/uA5TS62+d4PIqUwTvxGtiVADTiLqSOGUtj1gBVRbMqBMEz1zD3Pth6wmm9pwGnQHa6BLl34ZcaESjTV9e/cmn39m7KhHG+X/sJXgzLNoTNNKmlaJptLhyMABWZTb4hunoZ6ZWfBMzFsheV4rl3QnN5sfLvuLYMtVZkeEScQNT7inLI2o/R906alOaSvtjtmI+iHk/GQPbS8b7 BAFDSMBy uxXt3i4f+nEWjPZVw+4o7aK6rKO1+3CsWMu7mjZMO10Qcwb9eEC4Ay13pscrBE2xjc1sPx/EBTON4PybWjC9qpvFwWQyzkY5sBK4JyDPIzl6KXeOly8e6xKpRuy6LjLUBjBv/oDtS21wu9BRgSyS0zGASGlVIBEEjkrqb0QpgsSG0mz5XHyzdzgRcb58YZDkrOiqtFugMbwYZEsZGnHsw/gjzbeP3gGIzSxQWBDPJYKz6rJB6hkFb2oodQM/0ymLQoJRMu+i06WfRHc/dOJ8ZxGSuxXhlSCawz41xXHO00wiP+3u/TXwFI89KO2tRtLDl5BDatH0GpuulWq6zypPO71QdPQwQ1gqypGIPHCgYss1K76HjsLbntWIG4lv9sg0CfejQF3cPegrX+GUGwPTyROIf7oaXryqn5xsJ 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: Currently, the shrinker instances can be divided into the following three types: a) global shrinker instance statically defined in the kernel, such as workingset_shadow_shrinker. b) global shrinker instance statically defined in the kernel modules, such as mmu_shrinker in x86. c) shrinker instance embedded in other structures. For case a, the memory of shrinker instance is never freed. For case b, the memory of shrinker instance will be freed after synchronize_rcu() when the module is unloaded. For case c, the memory of shrinker instance will be freed along with the structure it is embedded in. In preparation for implementing lockless slab shrink, we need to dynamically allocate those shrinker instances in case c, then the memory can be dynamically freed alone by calling kfree_rcu(). So this commit adds the following new APIs for dynamically allocating shrinker, and add a private_data field to struct shrinker to record and get the original embedded structure. 1. shrinker_alloc() Used to allocate shrinker instance itself and related memory, it will return a pointer to the shrinker instance on success and NULL on failure. 2. shrinker_register() Used to register the shrinker instance, which is same as the current register_shrinker_prepared(). 3. shrinker_free() Used to unregister (if needed) and free the shrinker instance. In order to simplify shrinker-related APIs and make shrinker more independent of other kernel mechanisms, subsequent submissions will use the above API to convert all shrinkers (including case a and b) to dynamically allocated, and then remove all existing APIs. This will also have another advantage mentioned by Dave Chinner: ``` The other advantage of this is that it will break all the existing out of tree code and third party modules using the old API and will no longer work with a kernel using lockless slab shrinkers. They need to break (both at the source and binary levels) to stop bad things from happening due to using uncoverted shrinkers in the new setup. ``` Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 7 +++ mm/internal.h | 11 +++++ mm/shrinker.c | 101 +++++++++++++++++++++++++++++++++++++++ mm/shrinker_debug.c | 17 ++++++- 4 files changed, 134 insertions(+), 2 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 8dc15aa37410..cc23ff0aee20 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -70,6 +70,8 @@ struct shrinker { int seeks; /* seeks to recreate an obj */ unsigned flags; + void *private_data; + /* These are for internal use */ struct list_head list; #ifdef CONFIG_MEMCG @@ -95,6 +97,11 @@ struct shrinker { * non-MEMCG_AWARE shrinker should not have this flag set. */ #define SHRINKER_NONSLAB (1 << 3) +#define SHRINKER_ALLOCATED (1 << 4) + +struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); +void shrinker_register(struct shrinker *shrinker); +void shrinker_free(struct shrinker *shrinker); extern int __printf(2, 3) prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/internal.h b/mm/internal.h index 8b82038dcc6a..38434175df86 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1144,6 +1144,9 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, #ifdef CONFIG_SHRINKER_DEBUG extern int shrinker_debugfs_add(struct shrinker *shrinker); +extern int shrinker_debugfs_name_alloc(struct shrinker *shrinker, + const char *fmt, va_list ap); +extern void shrinker_debugfs_name_free(struct shrinker *shrinker); extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, int *debugfs_id); extern void shrinker_debugfs_remove(struct dentry *debugfs_entry, @@ -1153,6 +1156,14 @@ static inline int shrinker_debugfs_add(struct shrinker *shrinker) { return 0; } +static inline int shrinker_debugfs_name_alloc(struct shrinker *shrinker, + const char *fmt, va_list ap) +{ + return 0; +} +static inline void shrinker_debugfs_name_free(struct shrinker *shrinker) +{ +} static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, int *debugfs_id) { diff --git a/mm/shrinker.c b/mm/shrinker.c index 043c87ccfab4..43a375f954f3 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -550,6 +550,107 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, return freed; } +struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) +{ + struct shrinker *shrinker; + unsigned int size; + va_list ap; + int err; + + shrinker = kzalloc(sizeof(struct shrinker), GFP_KERNEL); + if (!shrinker) + return NULL; + + va_start(ap, fmt); + err = shrinker_debugfs_name_alloc(shrinker, fmt, ap); + va_end(ap); + if (err) + goto err_name; + + shrinker->flags = flags | SHRINKER_ALLOCATED; + + if (flags & SHRINKER_MEMCG_AWARE) { + err = prealloc_memcg_shrinker(shrinker); + if (err == -ENOSYS) + shrinker->flags &= ~SHRINKER_MEMCG_AWARE; + else if (err == 0) + goto done; + else + goto err_flags; + } + + /* + * The nr_deferred is available on per memcg level for memcg aware + * shrinkers, so only allocate nr_deferred in the following cases: + * - non memcg aware shrinkers + * - !CONFIG_MEMCG + * - memcg is disabled by kernel command line + */ + size = sizeof(*shrinker->nr_deferred); + if (flags & SHRINKER_NUMA_AWARE) + size *= nr_node_ids; + + shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); + if (!shrinker->nr_deferred) + goto err_flags; + +done: + return shrinker; + +err_flags: + shrinker_debugfs_name_free(shrinker); +err_name: + kfree(shrinker); + return NULL; +} +EXPORT_SYMBOL_GPL(shrinker_alloc); + +void shrinker_register(struct shrinker *shrinker) +{ + if (unlikely(!(shrinker->flags & SHRINKER_ALLOCATED))) { + pr_warn("Must use shrinker_alloc() to dynamically allocate the shrinker"); + return; + } + + down_write(&shrinker_rwsem); + list_add_tail(&shrinker->list, &shrinker_list); + shrinker->flags |= SHRINKER_REGISTERED; + shrinker_debugfs_add(shrinker); + up_write(&shrinker_rwsem); +} +EXPORT_SYMBOL_GPL(shrinker_register); + +void shrinker_free(struct shrinker *shrinker) +{ + struct dentry *debugfs_entry = NULL; + int debugfs_id; + + if (!shrinker) + return; + + down_write(&shrinker_rwsem); + if (shrinker->flags & SHRINKER_REGISTERED) { + list_del(&shrinker->list); + debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); + shrinker->flags &= ~SHRINKER_REGISTERED; + } else { + shrinker_debugfs_name_free(shrinker); + } + + if (shrinker->flags & SHRINKER_MEMCG_AWARE) + unregister_memcg_shrinker(shrinker); + up_write(&shrinker_rwsem); + + if (debugfs_entry) + shrinker_debugfs_remove(debugfs_entry, debugfs_id); + + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; + + kfree(shrinker); +} +EXPORT_SYMBOL_GPL(shrinker_free); + /* * Add a shrinker callback to be called from the vm. */ diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index f1becfd45853..506257585408 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -191,6 +191,20 @@ int shrinker_debugfs_add(struct shrinker *shrinker) return 0; } +int shrinker_debugfs_name_alloc(struct shrinker *shrinker, const char *fmt, + va_list ap) +{ + shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); + + return shrinker->name ? 0 : -ENOMEM; +} + +void shrinker_debugfs_name_free(struct shrinker *shrinker) +{ + kfree_const(shrinker->name); + shrinker->name = NULL; +} + int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) { struct dentry *entry; @@ -239,8 +253,7 @@ struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, lockdep_assert_held(&shrinker_rwsem); - kfree_const(shrinker->name); - shrinker->name = NULL; + shrinker_debugfs_name_free(shrinker); *debugfs_id = entry ? shrinker->debugfs_id : -1; shrinker->debugfs_entry = NULL; From patchwork Thu Jul 27 08:04:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329194 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 B2051C0015E for ; Thu, 27 Jul 2023 08:07:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 523B96B0075; Thu, 27 Jul 2023 04:07:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D4228D0001; Thu, 27 Jul 2023 04:07:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3745B6B0083; Thu, 27 Jul 2023 04:07:10 -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 291B76B0075 for ; Thu, 27 Jul 2023 04:07:10 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4C972B2AA4 for ; Thu, 27 Jul 2023 08:07:05 +0000 (UTC) X-FDA: 81056661210.09.D4C866B Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf25.hostedemail.com (Postfix) with ESMTP id 64437A001B for ; Thu, 27 Jul 2023 08:07:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AioCATUl; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 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=1690445223; a=rsa-sha256; cv=none; b=siGTxdll3FwghwG4Qc3IjoTd95HLFJVLZ6UJl6vsrBEJLA+Mp16ObuTMLlUxlSQtFChQMj SZsVWAJCziyinR2gZf00ViqXGG6DVVunuehyHXG5YCl8jpJnViiAf7mpXz9sk4lRg5aY4H ZdPKcvB3giYwImdpvR2r/0oN8Ujo6TE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AioCATUl; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 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=1690445223; 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; b=NfFdCEFaqt18eteMcC/N/zg6eImeud87k3qGJBEgCVdPQ+R4HkmAOVJ420M5eDE+QVmE5D smKft89hSWLXZKqfHY4XkkQ1g4uVfdpzceK0yQcaB77vrp2ywTcf0JU9ySwaJk3ivoyrJ6 W/sJQFv9FyBaPc6x11TfIb57nFPMLpM= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6862d4a1376so188381b3a.0 for ; Thu, 27 Jul 2023 01:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445222; x=1691050022; 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; b=AioCATUlkHfrdNMX26y5cMG8yiZzcrqJVPo4kMJoo0a/SPBGZMItYxbURGlfK0qQ3U pdquqHjvBnBibcfcPa96/7pchRYEBHxyNnf24E8fTswl7dwSe4DIa81z6/ovJRcM58gW OCn1XGDPuwokH00bwAsXcK1Gr5D3vpz/ZXjhjYJknWBgLZAbQPwFGeGyEdzXyVgOqH5z Y8WwL8gpftvasBEeZpl0cei4t7+d2ZCdr5qxpBrrzaVJwzr8lwB/25SUTyxKcTGn9xox E7xpcSMCUuenHibKLxGm6dPJne0R4y90eWbLKKoQI9m29dm8UqZ2/hC+L12FcXTeAlus bdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445222; x=1691050022; 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; b=M+UynH9GzAqcReX6ysuJ95bWedHu2pAkHEkEvJw5OxIwib1goKvQZb2X1wzhDzYU0b QTuL9K0/xUBlM0nJHlewU4qRgTfcQcWyfDD083URInO3veK/LDgK4SYIK+Q2IuY/KeKi gbuES7kOjajQOb3BZKd/YJWH8YJ+qRsL7BV7W/xc8/LzshXSsB0uR7cfByNgGBGKa/2L ZG06px27y9HVC8BJgudTazHUBoW7UsEjkb8PTESP1kXPxZAScTi4IBNJPFpt8W8VrUn/ XbmXCG7uw2W8RjfTi/13plmo/Y+kFgXvlSqYffMpP70YcYU+mCkiHrc6ega5UlEE/KXA zlyw== X-Gm-Message-State: ABy/qLbIhhd7fYBXkwILqtfTww3M147y3/Na4cQQhkY1EwaNq7xJTOIQ 7tG4SAuYKGOw/bDIPGbPXr2yXQ== X-Google-Smtp-Source: APBJJlEQjBlPfpR5V6JAfBPtQGnM4uH9f200On7b1qJi/VneGv5RiS5uPlFi7ClY0YXsCiY0kjcbBw== X-Received: by 2002:aa7:8615:0:b0:681:9fe0:b543 with SMTP id p21-20020aa78615000000b006819fe0b543mr4619538pfn.2.1690445222261; Thu, 27 Jul 2023 01:07:02 -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.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:01 -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 06/49] kvm: mmu: dynamically allocate the x86-mmu shrinker Date: Thu, 27 Jul 2023 16:04:19 +0800 Message-Id: <20230727080502.77895-7-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 64437A001B X-Stat-Signature: mg9xdnwx8egpn63u5y8iidcs7444xmpq X-Rspam-User: X-HE-Tag: 1690445223-878960 X-HE-Meta: U2FsdGVkX1+07CTRvMAI5vxvkQTrrxsn8wroBBRiMm443eMm4nLs/6PMUy29Xb0sr7ozYp3FYJCbZqcK3uOttHEsFNyE410qgeI1nBd5rBDXRvcKZgMEccVyp429GoqwpZPEWBBD4geKRoh8R8WDw6wshkydfaLTBj8JVr76JiLFfSf8arKPoz/A139ebynxdbgddRbB6q52sbL0+NHB2s4//2TyHbijGU7VZQcjmMkcHe9O8lTGRkPzhHrGM/xfY9WZfF7fOv7iKyMilxR56ppO+fjf/n0VYXZoNCeVq7331N6CIIZWhz1+e8oVzy5Wru9W0k0wLXwJa21RgTYyllTGFIShRjajcCNpQJEP/gKPxDsr4ld8fYaredLnf8GCjvLuS34nQiBFftL29Vgki6wbXaP6ed/sgBa5/Y6lpRmoM1tFp8y1W6GnyBU2O9a+rOoylikvM3Xpirk8r/Bg/bbajhbmWNdnST4dBpZUKJ46VoTtS7uRp5KvQKxNK9ahZ14hH+PfybiZDfNuD+2gDVJeCpR8T+8RUQwtjDjmrVnM/n2X5rc0yS8KeC/s4Sb41Sys3nf0zHoOigbDIjL7g5sWul6Q5kkGW6/F6siErRVTZSQvmrNgXT0cMnaicpT1unn9cphhCACFW4UImqQr8xGYkKEomr2qr8zqUxKFH7SsNIC/biJtX386bIOxV7l5RCl+n3toXnGTXmpHEHJfn+6xDO7XMytJg5m3YYPCymHZXP0NAP/79nBI9+dV46hUwAhBeLz8jITDipK6sN4vjAzk1g6UEc7Q1k+SH9yrLa3dpMdyyp3g6BZIFeUPDbG8A9FOMoOUs++NaaVRN3ahBznb/+CRuyNGO8QOTdI+7Fjdlb7vzlhW+QCXwFxwwu1tqoYhCDrM9IB/Vs9pJVKDTAxo4maTdh/t2+l7hg7D1EpJ/sQXJf7cgM4pfUyMqD9/Ys5/HcRBdryZonuclTj 2tBWhxl7 t5L2rxYBdz7vUpFOFPBLDSMudH5uWnzg5/RM6fNIVLGLc4rSKbb3VuBE5FPttuZp60a79o7Joo3BO7WiDVpR07y6dl2QVscPWcanNc3BJ4sSkb8kpPlJsU8dhKY1j5pqNH8rmz1Sg+5/TMUSOHe/V2E++E5HOsOh9I7FGQTz8hyZ84WgSTQdu3jS6r3cX5rHGsYnhg88EzC62OhNsmm+Ot6WUCiWHu1+w12iKr9FrXFhNvkX078vCrpmgxSdb1A5aAH4+JgXZH4OEK3U3p3EzaUWj5HGoEwbHiG9aZ1fNdux0/IgOaPxo5Y19IYXSB+V53psIIP0+l3+vVSu8NMooEqpPQvlohODXtO53m+SqnXrwTBjAWAEANJQlw7VPAGZxbjcOT9D4LWh+bjt+M4cKeGsNIuI9WbKo/msD 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: Use new APIs to dynamically allocate the x86-mmu shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- arch/x86/kvm/mmu/mmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ec169f5c7dce..15fc92a24a26 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6847,11 +6847,7 @@ static unsigned long mmu_shrink_count(struct shrinker *shrink, return percpu_counter_read_positive(&kvm_total_used_mmu_pages); } -static struct shrinker mmu_shrinker = { - .count_objects = mmu_shrink_count, - .scan_objects = mmu_shrink_scan, - .seeks = DEFAULT_SEEKS * 10, -}; +static struct shrinker *mmu_shrinker; static void mmu_destroy_caches(void) { @@ -6984,10 +6980,16 @@ int kvm_mmu_vendor_module_init(void) if (percpu_counter_init(&kvm_total_used_mmu_pages, 0, GFP_KERNEL)) goto out; - ret = register_shrinker(&mmu_shrinker, "x86-mmu"); - if (ret) + mmu_shrinker = shrinker_alloc(0, "x86-mmu"); + if (!mmu_shrinker) goto out_shrinker; + mmu_shrinker->count_objects = mmu_shrink_count; + mmu_shrinker->scan_objects = mmu_shrink_scan; + mmu_shrinker->seeks = DEFAULT_SEEKS * 10; + + shrinker_register(mmu_shrinker); + return 0; out_shrinker: @@ -7009,7 +7011,7 @@ void kvm_mmu_vendor_module_exit(void) { mmu_destroy_caches(); percpu_counter_destroy(&kvm_total_used_mmu_pages); - unregister_shrinker(&mmu_shrinker); + shrinker_free(mmu_shrinker); } /* From patchwork Thu Jul 27 08:04: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: 13329195 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 CFE47C0015E for ; Thu, 27 Jul 2023 08:07:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747806B0082; Thu, 27 Jul 2023 04:07:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F6396B0083; Thu, 27 Jul 2023 04:07:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 597D26B0085; Thu, 27 Jul 2023 04:07:17 -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 4AB336B0082 for ; Thu, 27 Jul 2023 04:07:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 19085C1099 for ; Thu, 27 Jul 2023 08:07:17 +0000 (UTC) X-FDA: 81056661714.24.B54439A Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf22.hostedemail.com (Postfix) with ESMTP id 32773C0003 for ; Thu, 27 Jul 2023 08:07:14 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=krf0rRSB; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 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=1690445235; 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=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; b=YVtnDRGV6R+1r9teacEb4IEVEzP9Y9uyf6fNu52hoj3wqHGcEjGDWevJPkqVEmZvQb6Ti9 wd5XdarWEvbStE9cH5SHz6UiOIofqz5ZxBK+QwvJn8dQLstfu3FYrlbd+Ai/ypwHtUofm6 6VOeVlkD8RJlo3ZwUvt1ryq36CgVOmQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=krf0rRSB; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445235; a=rsa-sha256; cv=none; b=Q9fBcBD0qSPNP4VSdCvv6ts/cdd+RqM0qn37PbfmIAnnbrGmLg710Fqtdj52LMZ5SCkS5/ kqP8t1Fa0sIyTY70cvBMuT7UGgtL06R5AHdpwmKvfKfJtlmdqFRbOvIOphco21izgAXjv8 5Zs9Z8Yi3+P62/6lDvdCQUNuAOBMIms= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6862d4a1376so188438b3a.0 for ; Thu, 27 Jul 2023 01:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445234; x=1691050034; 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=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; b=krf0rRSBuACihGG0HOfvmWM3fExNQmmDQBZSFypO9OF26g2F9IRQXNjarXAj+rDJ2F j6wi8ORGszAJ8F4/2B5RfozFOO9c5wQvkPuwF+U0dnMIFYzI2u+dIV518lO0Mey/M0g+ DAIhAFbNX4boMgnEYCrLvSqMruXRlIM+AwHL8QP9OXWtql9jawORm8JA9K2pNt2CM3by 1AI1wCMU2elwBWzc8zmddDhb5S57BlUFVrs7Qpu26KSs608fAqSWn4u6Hcxn6Nu/AYp6 eAYr/PxpZmg2LEli6lhHn6OsT6FdGj3gL7SNMtigAeYxmILx7EQ2Lx+oYLfIsw664x5Q hi2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445234; x=1691050034; 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=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; b=NG5+N+Pk851FcYM8ae64O/synnqLRBTgUfRyKh3bSPqqmxH3y+7EDPHou3khj4M5nt F3SNY/C8t/XAVgMJEyMZlFWO9vti7lPRPgtIaxIWfMNZ5aq8t24/h7P7mSdMTTNWG7sn OcDcSlJOj7cdYHUnOVctxMGsXHzZDhpxJQUED2oc1OY3n8dlfxIwTFZBXc4y7YCnXANy 4r75YsTB3g5/VzZTbFp2ya5EmbDvBbMVI+gcYOessxkUSV/vT+7o2QFRQ71dCmm0jNUM G3TjQ2qYwvzxxPQYkqPYOhwV4hnDH1wbY4TygsQnRq8lhMlIEgQ7gV3puTyjBEdi/GqR oOmA== X-Gm-Message-State: ABy/qLZcOtokQCvKsPHeI6iKhgL0QhgvF949IRlmxt6QH/bH9zptT4te jgRYyL4WbkFmfAlFVJwFymkETw== X-Google-Smtp-Source: APBJJlExJjCwBoW4B5netumBOqdfs5+SJLDXxiJ/1dno6haNjCE+wUan/A+nwEsop7KuM9iLlMTgjA== X-Received: by 2002:a05:6a20:918e:b0:11a:dbb3:703b with SMTP id v14-20020a056a20918e00b0011adbb3703bmr5540739pzd.6.1690445233998; Thu, 27 Jul 2023 01:07:13 -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.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:13 -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 Subject: [PATCH v3 07/49] binder: dynamically allocate the android-binder shrinker Date: Thu, 27 Jul 2023 16:04:20 +0800 Message-Id: <20230727080502.77895-8-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 32773C0003 X-Stat-Signature: ugyke8wrx9gg1knz6c1a8h9ipow56pw6 X-HE-Tag: 1690445234-732346 X-HE-Meta: U2FsdGVkX18rg6tGjpQnqsW0Xec8LnhmWYubPYulRzDGjVcRedbBtlVplZKJL34owQeOT/Hi6IkbDCgsUKvP0AVHoYC6t6FBw5MrtnRutsGdWkapwZ4mv8c+/Pc/TnGnpSuCo0OkPrOTNHIYz1KP3OWU7vaIO+wuHSxPKSgBGHRvtHlWAtatvbsj7mDdXystuRhlA/0/vWXKRHnhJNQNBrsHHSzoiiCKijm/e5J/yMh22HvNP6XFmxu1t3K4S7jiIzeTTFJeKyhhxe7KHaE5F5sHiviUgx3f7lc03kttcLxKunMMAtlDQvXCn2Jn7yDkYO+5zv5A1XIYakklbsRQkZzABQqWX2QmI0lOeo5uCkw5Uq6eT+3R900KpRjOJJOrm8epGAm4gZTPCOJNoU1rjHm6eYnHPJz1SVd31P5mQ5H4a1Q4eewrwvEHg0HfJjHgLH9Xi7gqy7x4KkhGCT+vr/X7WMtl3W+gjGEFCrB4NFrBGYaVJ0SHorGBZeJNl861B8c+a3RhnfwMHwQ4p45yMvSyAJmN2JF+oh1QpZyoSknVetQvq5Bk7Jb8ucoIOAfYkFkq7DaKbG5/zdvdGRU4NecWz0MiYWQwA6sByH6lWuH9SbGXnd7lc/g10p24/wxzJw+7uAVmFAppkUeoWygUbmO5e+r8zbeziRgouRVkmbR8Bb91zsE9bAAqPaUYqGWO/3KoKsb0hkKWvhZxTKJCzI1U3xxxkqXvGSrVPAAMiXh54Nf66rQRZWTeV162XxXB9xGSa57kqBZnDP6eqrur+WxVo5YwDvBz6jIn4UYkDLiTQ/Tvs8eCHdHXVAtubrHYhU2sV1cJyiWhYykhzSzsCJjCO2x2pQy2YAk2qW/8Bk/FrFVLRa6LcRvgai9l2+0yazbUbdU6avCQvR21/rU3BEp31PyWT7BVDQOPujj0R8Ytt2fN5BPiI9fMRNZoAFWN0d4Cs7IU1idmh9HrpK2 z713rY9q 7Kvybkn734kJPQUTM9u1xgQPAOOJRnVYj3A2ariLleDbLEc7m1MZ091SEeWVYiFfXdueakwMzxtAyu7iHuNqLQp9Ll9UqTXAYVQi7vAbuoYnMY6BqaL3CYATBB7Ekhd9vUeBZw+A5X3fus3zLpFYDqfTLOy7ddsly3t+3zIzv5ESgHqc9E0jvTAtQj+RgQOZC4mH+YBRPL1uSLI8aehrj1SInrzbpq7H+Uu9H31hucplpV2Lwrmaib0pZXiSMlu/7EwToASeTVWL2SoJrzWnnvPrZGNUmi5AmpJAAYvHXTHpMYHwrljiJ7ws8l2OgH2h5AB4XhupNetQIOnMaVQtQuJwbcdeuv1WSQdJ5FsJe7l5cFGziCn5AQMCm1eDtI6rMY3Hwk8TAUHa8WIrVOIS3x3xgkzdmMgfuwB+0 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: Use new APIs to dynamically allocate the android-binder shrinker. Signed-off-by: Qi Zheng --- drivers/android/binder_alloc.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e3db8297095a..62675cedd38e 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1053,11 +1053,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) NULL, sc->nr_to_scan); } -static struct shrinker binder_shrinker = { - .count_objects = binder_shrink_count, - .scan_objects = binder_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *binder_shrinker; /** * binder_alloc_init() - called by binder_open() for per-proc initialization @@ -1077,19 +1073,30 @@ void binder_alloc_init(struct binder_alloc *alloc) int binder_alloc_shrinker_init(void) { - int ret = list_lru_init(&binder_alloc_lru); + int ret; - if (ret == 0) { - ret = register_shrinker(&binder_shrinker, "android-binder"); - if (ret) - list_lru_destroy(&binder_alloc_lru); + ret = list_lru_init(&binder_alloc_lru); + if (ret) + return ret; + + binder_shrinker = shrinker_alloc(0, "android-binder"); + if (!binder_shrinker) { + list_lru_destroy(&binder_alloc_lru); + return -ENOMEM; } - return ret; + + binder_shrinker->count_objects = binder_shrink_count; + binder_shrinker->scan_objects = binder_shrink_scan; + binder_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(binder_shrinker); + + return 0; } void binder_alloc_shrinker_exit(void) { - unregister_shrinker(&binder_shrinker); + shrinker_free(binder_shrinker); list_lru_destroy(&binder_alloc_lru); } From patchwork Thu Jul 27 08:04:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329196 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 5FB0DC001E0 for ; Thu, 27 Jul 2023 08:07:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEB0B6B0075; Thu, 27 Jul 2023 04:07:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C9C766B0083; Thu, 27 Jul 2023 04:07:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B64898D0001; Thu, 27 Jul 2023 04:07:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A57586B0075 for ; Thu, 27 Jul 2023 04:07:29 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 789178102E for ; Thu, 27 Jul 2023 08:07:29 +0000 (UTC) X-FDA: 81056662218.11.8B645BD Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf23.hostedemail.com (Postfix) with ESMTP id 787FF14000E for ; Thu, 27 Jul 2023 08:07:27 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KpqQJYQn; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1690445247; 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=ppdDbzxLfV7T8uyJ0+LWzuRMVQS50F9BO9dGotbDPbU=; b=a6SS2KHlPvt/KLX5GlSCqdgKctGVkRGHzWEoOCVzcl08hBY3GvyX2inXsw1L8rBF0MkIRh QvfOtB9wXe9XlcHbiCbVbEJ165WNTlaBpY+I0oQ1f/fLE3rn98aY6Ru6dpMDX2v6PLOI5w /84YcTkpUXE7nXMzama6PyEueJH+lHA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KpqQJYQn; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445247; a=rsa-sha256; cv=none; b=ZzRus5boQO4uRHtDX0U8224BHOm6Vty1ExWSXO/ojdj6KFfbDfWanLh0JR8TCIviNfYiH8 OnY01Eb1+A+crgk9C1g6VLuug0ERuye1rAjRjzxykI2jxT1FYyPU0oNNja4mZadRK/b50Z k7rLv9jC2910tG/GYhLvwvll6Mid0GY= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-686f74a8992so77393b3a.1 for ; Thu, 27 Jul 2023 01:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445246; x=1691050046; 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=ppdDbzxLfV7T8uyJ0+LWzuRMVQS50F9BO9dGotbDPbU=; b=KpqQJYQnD6XZcHjbv/+muTq0vlYb8upK5OWv1aGKt50KKzUi7i+JzF6oBUUsqnnZ8J r8wNd0ItebBMmbL+7PFob82/siVz2lcTITJgiPWkofH/9LJHrT7eh309V59HxxQ0mOlE DIoyoSTd+eeARDBsSwfCZZT+D1eJ9vMkwqGXz/n2dx2kEZLuZLLaNunG9PbX3wXH0AxZ KS3Doj3WekVbT+DS1JWdAAgXSNDy2XRSFj8TbzZy0Apg5FVE8T/dZYbRy2KedtCvtde/ VVp4H8rT9xtwGwXR6cSDDmcPYDcWy0CdFKjtAgYv/8XnYUvwEF4uwit6TMoEpzOExIim mxxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445246; x=1691050046; 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=ppdDbzxLfV7T8uyJ0+LWzuRMVQS50F9BO9dGotbDPbU=; b=iBMoPybgGeMu6ffuRPyie3AAt2xzQ7tzmocKt7d7p9CzBfpq4FNZCIABDWwWpxKWXh hWdtfY6I0Rl7BBDL9klkM+am3Tt/DvsxGO+tryYFurmw0IbcwSDPgz4ZdeJF2g+lYojC Fdba+6de2I1nEVBDx5m/4QM1h//7qMDF7EKR2xV6GEacUFkatv9qg8tz28Tri23Y207m UFDL7NtNAkZx6ySHS2HchjbxbnIcBMa2ljK2+Wa+xwAi0YYeKYGAcpXMEgLxA4Fgam/Z sepeEYeO8dy7ryUkpo8ql/7t3IkM5dIkKAw6/miGRHjc8Ox0QVudbWFAeWmgIybrwX+A pajQ== X-Gm-Message-State: ABy/qLYEce9KTm+shdtAgpdziwq5zIcstCvCY+FQQEVQHhE5vZdjYXMH M5bTmNdX70UdzD0vLfEKxfnuIQ== X-Google-Smtp-Source: APBJJlG6gnRngQzsFbw9KnzolcByCK3s/MKtuzn55eodinGMlyRsxgSHfIHEIFN3Q1pZ+W9H3PfVAg== X-Received: by 2002:a05:6a00:2b90:b0:67d:308b:97ef with SMTP id dv16-20020a056a002b9000b0067d308b97efmr4583872pfb.2.1690445246349; Thu, 27 Jul 2023 01:07:26 -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.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:25 -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 08/49] drm/ttm: dynamically allocate the drm-ttm_pool shrinker Date: Thu, 27 Jul 2023 16:04:21 +0800 Message-Id: <20230727080502.77895-9-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 X-Rspamd-Queue-Id: 787FF14000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dihjie8wuyjnxaurz3k3x36zsgd3hyz6 X-HE-Tag: 1690445247-84103 X-HE-Meta: U2FsdGVkX1+wqmFyz5C3JzcIZJDADGfNoS/ZycAhH6f05whknJ+HsU86wHbcz7Rfg1on0gjaIobmXnc9HzP57dqJ9V1xo19byLXCp/DCnDrG2OUsQzh/BrbOi3jl+imZyupn40Vs+HZnztRC2yNwEFkJrISnFsKKlkPEjXV8oj8Xsa/kQN04U7HC8Ux+osr7JD8IF8aMURY/dILQHK+nVqSbJx7F1dZeXXMozIGK5gtNpyd8gROrLs3ZwFiSFIpwA8FJXiYsCWIYMwnMwYjXnN712+T3m2ryok55umpQjbRvQxJWPqrezfcv7FYsZ4spXJsjA2DNJlVmUFTFUgDt2lU0yPoze+aW93x5MWfI2RwcvdTF3GBEIPj3NAksY3eF/DOozdZxJoEvp2M2bNs3JOaJggGx/g+aI8z+8SDFo8n2T6XdHe0Z+rwkKQmCcEfgQx6nKdATiw5p2jl8WL6ydu/CbSuhT/UJWIWhGZLnkOL8uWDfPOQGmDtE0ZpWOA6SIjyVeXXrVHZyaCg7eJObG2bSu+SNOIoczhnT/SpqybJm5qhFh5tpqlPcXntoA7nV/DWeWWEVopE+1oY7awkQPd4jRvgSSnhuhzDSwVPQ5faxlg8IQanMuM8+syaqS/z+V3rHrIgKRJTPVQ76o6XwLvZtS+dqKosQAPHKbgyS4PkVd0EKOEXZvXV4Lb7PTV4Vi4FOBHZgGZ8o5SQMjvxgJzeux01hrpfX1/oVd5apLKVzs80+zcGha33PtOrL7od8iy91CoGBhxnivcC12OMaEUoKAFuil5U/t8ZwuqLSw/Lzm66Sl80ieYEZ7Gc562NR4swpRNBwFqlWVon00u29bICmILoosmrmVtJV3U+latS+Ipdzl6uQ3++NW/XG7l2PnfvBb7S2CYwQW4uNrNgvHnX1/xUwdjJyrRBDFmMnDsRFG/LEeHLVNDYqK1pT7kSn33I/fr48SnZolSNImDa dpEaGe68 ta1ptZMDMn163BGc814RbZIlHF+Igc94kXUdFGWCVd4rpTFxbNGN68+Ye9pQK2evvM94vbHatOb+7fB2FYOeNjZlSq+vHiTM0KzOZIx2y4w62gFKalUXYO7nybKiMnJVNWYLfl9JtIkpukbXeVQX6mtP8jpZ8h6cda4NAaaUtV4zYg2KxjeNikugx2Gx2jgM1W4RUMkMoln72mTKuh8ee+zu7obSx5l/7kSF8Uy+MJgpxWAgQAkKk0wVlsJ46ub+e/zubzfCiMW3C3DIbV+49HluUNM3gry+zt2jWKQ+S6wvZdgymtGD0/VbQ5BVNyAuvD2ubjMSdKyT7SxFcqLoOC0TFYWXOdpfABgM7jgSM8bk8c+lWaMR8YDaTFNX4yFosQi4axRvI2WvEyniFPSpSDPMxQHOqYLC4gOsvumg/zzis+sD7vnnWSpAstHvRPH+C8buS0xME7+UGGyb9KzRMxjS58A== 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: Use new APIs to dynamically allocate the drm-ttm_pool shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/gpu/drm/ttm/ttm_pool.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index cddb9151d20f..c9c9618c0dce 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -73,7 +73,7 @@ static struct ttm_pool_type global_dma32_uncached[MAX_ORDER + 1]; static spinlock_t shrinker_lock; static struct list_head shrinker_list; -static struct shrinker mm_shrinker; +static struct shrinker *mm_shrinker; /* Allocate pages of size 1 << order with the given gfp_flags */ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, @@ -734,8 +734,8 @@ static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data) struct shrink_control sc = { .gfp_mask = GFP_NOFS }; fs_reclaim_acquire(GFP_KERNEL); - seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(&mm_shrinker, &sc), - ttm_pool_shrinker_scan(&mm_shrinker, &sc)); + seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(mm_shrinker, &sc), + ttm_pool_shrinker_scan(mm_shrinker, &sc)); fs_reclaim_release(GFP_KERNEL); return 0; @@ -779,10 +779,17 @@ int ttm_pool_mgr_init(unsigned long num_pages) &ttm_pool_debugfs_shrink_fops); #endif - mm_shrinker.count_objects = ttm_pool_shrinker_count; - mm_shrinker.scan_objects = ttm_pool_shrinker_scan; - mm_shrinker.seeks = 1; - return register_shrinker(&mm_shrinker, "drm-ttm_pool"); + mm_shrinker = shrinker_alloc(0, "drm-ttm_pool"); + if (!mm_shrinker) + return -ENOMEM; + + mm_shrinker->count_objects = ttm_pool_shrinker_count; + mm_shrinker->scan_objects = ttm_pool_shrinker_scan; + mm_shrinker->seeks = 1; + + shrinker_register(mm_shrinker); + + return 0; } /** @@ -802,6 +809,6 @@ void ttm_pool_mgr_fini(void) ttm_pool_type_fini(&global_dma32_uncached[i]); } - unregister_shrinker(&mm_shrinker); + shrinker_free(mm_shrinker); WARN_ON(!list_empty(&shrinker_list)); } From patchwork Thu Jul 27 08:04:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329197 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 636AEC04E69 for ; Thu, 27 Jul 2023 08:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01B696B0080; Thu, 27 Jul 2023 04:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F34C48D0001; Thu, 27 Jul 2023 04:07:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD5546B0083; Thu, 27 Jul 2023 04:07:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CE4AF6B0080 for ; Thu, 27 Jul 2023 04:07:42 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C865C0452 for ; Thu, 27 Jul 2023 08:07:42 +0000 (UTC) X-FDA: 81056662764.10.0E11CAC Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf12.hostedemail.com (Postfix) with ESMTP id C7B2F40017 for ; Thu, 27 Jul 2023 08:07:40 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bsOGFEHM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 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=1690445260; 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=bO4yc6b0222dRNj48HoFyPuU9QjRVolFKKVhhMGpLKw=; b=l8Aj+brXRCsFmdl+AWgGKt9mNEgf2aTo5PfqMQvfz4is4T2jJ0S189U4VSJjrFcRTnXEw/ zGREI79Uql30GfCBcOZfdVYf0nD5ZRTFC0yPxriD2V5oCKVRlE7+M8prHEq95HRfIyszVG DkFJq/cvZ+OrTfC5DXcckz2mHooHsAw= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bsOGFEHM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445260; a=rsa-sha256; cv=none; b=8NZXs3UrR5gpWYaSSCWbKtHcFPVx/XdAs53sjaG8ChG6IqT2dsE7eMvO05p2n0G8Qb0R9i 5S/VPGDNe11ldpf572GTJ5WTqb+PzNnPFRuymR+BYDcV7/NbNGfs5ghMh2p4nA8HJLTaUW Af8ErtVptHnhjRbPSjK4SPqC5oGErR0= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-682b1768a0bso174679b3a.0 for ; Thu, 27 Jul 2023 01:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445259; x=1691050059; 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=bO4yc6b0222dRNj48HoFyPuU9QjRVolFKKVhhMGpLKw=; b=bsOGFEHMBlylId/BUUU6j2E7pnjQ9uMa3Dv7D6LoIY48uPLQavKrpj689NrNUpNLTl Aanz7sKMrDaOTTGh4q0MwHTWAvihn1jLx/NBWz0K9CQrFU5rnVI5CzfKG4yO6ADEleGk +0iHBjbO0i9m2+usUNEX9xFmZ3EhQv1mJHg4H05ocCDdgDOngyKPTxLLXx+aCRh/qeWu DaVggQ15a1Fk3lZ/quyODiCtb+FgmREKB0V2Ac2I9AcArTAe8N9Pb2STGieOdKv9GKuP YDdg42gSOnr6HuMRpDchso7LM2qcKeKJNp+Y2dbUP8m4urT1oK6m0eJU2zmqUir1DcF2 Lspg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445259; x=1691050059; 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=bO4yc6b0222dRNj48HoFyPuU9QjRVolFKKVhhMGpLKw=; b=Hi97L6KUue8xu4OIY68QjgjbhqF7DGZZMHZNi8CC7Pl7SZk1LALaY5yR53/UIdy5uE AwsDU5LrHbm0MHzkanslEF/OlGTE995UsAYDJzSBqG0Y63IfFN8klnU+twfXLA22NC8C 1hpW9AAvt/3/ZI9JQTofHXnoRsYqR79HInJm1sdLcLaEOGSQ/MXeIQc+Skj5KPabkCRq rmNw7kWLgfQAQdNKxmFisRSmF4A7Ki6yzPE8DchNPh8YGIZplEXxbViLCn8Q0eVQHdXw 8RTByxpuZ4jvcadUZfWPYvJJbihSVbGlYdqHDmvLr/v60/n7SA8wTZ7O6WZvpZUePw3k IOYg== X-Gm-Message-State: ABy/qLZ4n9vwVSxyQtC8sDSHEodWxRxWid4j8gvvkoCQWrQNsutU+HDD r0WuERAGiWpX7uLYFe8OZC/DbQ== X-Google-Smtp-Source: APBJJlEtjuu7JvMViG/zI1+BRK6QgnXajX34xFKdSMMqB1WswZOW9mIhLIlLvIrLtx031P4ulw5hGg== X-Received: by 2002:a05:6a20:9381:b0:137:8f19:1de7 with SMTP id x1-20020a056a20938100b001378f191de7mr6160325pzh.0.1690445259706; Thu, 27 Jul 2023 01:07:39 -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.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:39 -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 09/49] xenbus/backend: dynamically allocate the xen-backend shrinker Date: Thu, 27 Jul 2023 16:04:22 +0800 Message-Id: <20230727080502.77895-10-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 X-Rspam-User: X-Stat-Signature: b18qc5j7x8nt1pn3kjcjoyfo55y63s49 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C7B2F40017 X-HE-Tag: 1690445260-778965 X-HE-Meta: U2FsdGVkX18TqQo8i7/g0RI58r78aTd515KtjXqubah+ik19FSpF5B2NTejTieqxqunULlRl4K4AoeXPXK5vQENysvfH4qP7GIipA1NJKw5tbSz+sXVQRv03868Fg0R5whmYtMomygnjtExbIHX3abimfZhxbqP1B4z6wWXgzw+4zpR1pPSTl6DZBW8SbHPYgsOlUBy7yd72fA6BpVPNO6xKcE4diWxNFxhBO1A3LdT7gAXRXji75gd0ahXYjEwG1RdjnJdAnR4KKJeGFjnLCOgrSKZg+qQmxkBKAauSCnnNy6nSDDBXxME6R072eJV0+8kjkq6WuF4tgCQDAyNC1W0DqIxJQG5sCTvgWCmkXIMBeWrYKOlHbBUziRYCrA4Emge6WZscJ3r1fkkCWlcu2X66WZuGnKwnG/lCNUd6QfMjhTgfYvNROp2y6MjlhWwXt7QGWS5Wz7utfa6/judtnoWemzLOoO4ZsbsIKIpfZZVAaoLbH3RuCUBf+3Jx61PFIksUANRep70Bqg/RjDQMRLRdGqKeVPLSh01aMMzxzsT1i9uCD2zEV9WDYikS8j9PmEbvlw3v3Lbn8IP383snJZTArLXUC2j81YKGoVI2g7m4cT3OPGZpmfJVdC0Rl/5UpowZ0QaXVADor6QWJdEVRo7URrM/eYKOhAPMr6PtP0pO/dokL7ZYKNFR4U/zuW/lcJ9IvTqpNEXvDwmP9+OaVT9xbT+FGG8KO0jjFPMq12uxqjvHrMiSFJaWKYSCUaU4k5RNWpI6fTibkI+QCXuACU292StcWggkFvSwzkj4dGH7CuAuNAJwnWxcyHzf/9AUpj1dump/TYdPJf2n14qlbFOTylN0/C0y3N9zieVjz3LwSVhEU2uNJMT0gFP1ZVa/RQ6NwLirRb9yr3WYXXH3zxpEyu8r9TdXHk5sRJlBf3RkdBlgvpmg1pLW1KdWLsk+mjS9Y4HTG2z63FshKeT M0ePGus/ TnvzAsEILO6PQJaWMJlpjbxJlskb1q9e3jtb3mQqhhugQ6EI+mnQKbxcH4QbudeIBRvUmRADGK6Ze89y4yScasXvw5HWkLoH2GMjv6hGyayWRCJSU/WZASrHtKUsDOt/VpmfvopuZ1P7o4NL2jC5vCAjaONc8xMTpm0Hb63C/CK1HZiVCBDqqYH5IwemvCactdDOwvNcvvfCmTvZJOGlFGl4FUGQoItV9CzgabkcSSMYNlgB0CNmopzg53ddBqClcrwyn0MKYFF1gdizDhwAv0VMSV6DoNJJ+Dty/v0aVXdblJ1bTxbvxgV0DiAro+QOBihVJzGsE8mtP0OuK5/RdWXWJ9kvDHlsyx2zHhzcTcE1NzUopvf3DQwrDYnmvv+eDft0fBX3lt5MaV8V0/wqGhBP+rzUAjkddcKAN 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: Use new APIs to dynamically allocate the xen-backend shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/xen/xenbus/xenbus_probe_backend.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c index da96c260e26b..929c41a5ccee 100644 --- a/drivers/xen/xenbus/xenbus_probe_backend.c +++ b/drivers/xen/xenbus/xenbus_probe_backend.c @@ -284,13 +284,9 @@ static unsigned long backend_shrink_memory_count(struct shrinker *shrinker, return 0; } -static struct shrinker backend_memory_shrinker = { - .count_objects = backend_shrink_memory_count, - .seeks = DEFAULT_SEEKS, -}; - static int __init xenbus_probe_backend_init(void) { + struct shrinker *backend_memory_shrinker; static struct notifier_block xenstore_notifier = { .notifier_call = backend_probe_and_watch }; @@ -305,8 +301,16 @@ static int __init xenbus_probe_backend_init(void) register_xenstore_notifier(&xenstore_notifier); - if (register_shrinker(&backend_memory_shrinker, "xen-backend")) - pr_warn("shrinker registration failed\n"); + backend_memory_shrinker = shrinker_alloc(0, "xen-backend"); + if (!backend_memory_shrinker) { + pr_warn("shrinker allocation failed\n"); + return 0; + } + + backend_memory_shrinker->count_objects = backend_shrink_memory_count; + backend_memory_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(backend_memory_shrinker); return 0; } From patchwork Thu Jul 27 08:04:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329198 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 BD9F4C00528 for ; Thu, 27 Jul 2023 08:07:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 599826B0082; Thu, 27 Jul 2023 04:07:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 549C66B0083; Thu, 27 Jul 2023 04:07:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E9D16B0085; Thu, 27 Jul 2023 04:07:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 31F066B0082 for ; Thu, 27 Jul 2023 04:07:55 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 090CE81029 for ; Thu, 27 Jul 2023 08:07:55 +0000 (UTC) X-FDA: 81056663310.07.C7079BA Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf30.hostedemail.com (Postfix) with ESMTP id 2313B8000A for ; Thu, 27 Jul 2023 08:07:52 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JnEFWCJ0; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 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=1690445273; 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=ubpyp4SIhGXjO6/VTKiZvWjlRzyN8ANvKHVN5xSGnIw=; b=xkG0jk7HqNAwDMMCo8vzjUDkfNxQboWXQ+AWe+tnoabiodm6LUf7eG3+kWG04scTbqmCCp Kz+9GzSE4d+CYiVwdA60tbHxIRYMTbKbHx5nOsRsmXy298hB7NEm/hkdPSpXIDLLd7uKsK DcsGqLui2fUPfF+H+bC2YS2ewIdYMsw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445273; a=rsa-sha256; cv=none; b=O32eyTPXpPDo2ze2eR04qoLp7Osc/iJNk2dhZ4zZnmsozZ65PRUh7yx+aNSbEUoiKXXGpH s1q1Vi5nFxt4RgLY1SKwt2bfBVHcueMGjucDRPpuBjzvgkVd1Urlvft3YS6VMWSZ+H0FoH Q0edsD2TwiRFHtJhAjbtJ0ugAV5Yams= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JnEFWCJ0; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6748a616e17so182589b3a.1 for ; Thu, 27 Jul 2023 01:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445272; x=1691050072; 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=ubpyp4SIhGXjO6/VTKiZvWjlRzyN8ANvKHVN5xSGnIw=; b=JnEFWCJ0lfqLQ09KAhpDiGnRAmdtfYhke3aIyqMGyaI1u+7/j8X1g+ymABPYujVt+w cz28zAP40524HNhXDL9Q5SofaC1n/CPA+MmByiqiYd170BhvKkwUMWNTWGQlZaYnqgaR FBpKNnlG1vtBshrp2zrDJ2SvCtcPtO2Uoxi7Td9WriKIRN+9BBM1kAj+4w0IHie3PsAJ NEqh91Op9gs693bzhjwiJV1tmOiwkF+OnmYUm9c5BSiHcRPJXsNw4NR6JZLqvW90Jp1l wYlHCbMfcgp//O2TdulFnaEsdlVg5OO3iU4DnTCf9/O5RCqrJgKtWA6LRsXmBpSaFsGJ 4ftA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445272; x=1691050072; 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=ubpyp4SIhGXjO6/VTKiZvWjlRzyN8ANvKHVN5xSGnIw=; b=gpAtrPk3RkFejdIzyRBgbZMbX6SFc8NDn26uYTSN138uLYN/XfKIGDizJi+VTBVgRA MUkGXnUaJW/wvAFGLfiBGWDrU7ER/1vVY85fJWqKU6ZwMPybijLzdG2c3b6Lo5kJAI2p MIBVkiJvXb7vOuBOAj6UZOkBeu3dDf6pbdDX/dqJzL2Md47q5iBhwle1rYGYg2kLNwBh e3OpvAUxGA/xkD53/WrXAtK7Wu9rUNjbsO12oGb7zdTq0XFhREIQ9F+L3g54kk3SIpNb RNuzlVrFqbGLlaRLAJMQgCLi6SI9QbaO9ldCh/9RTmhM+b5jOiNxtLdgX9tR88AJ0ggi xo7A== X-Gm-Message-State: ABy/qLbjO/tIDPjLKwXGa/s9QxWeyUnuWg+L0VeGxcnjzCwmPNeLGfNR hn2MLP+gWuOUGpCUM+7A/HaUDg== X-Google-Smtp-Source: APBJJlH8Hm//FCUnZvKJ1Fsda02AnYQWQqq2rUtStc8LnYU5/NdJ+w8F5lFLyohrr/NHLskzxbNOmQ== X-Received: by 2002:a05:6a00:2d09:b0:682:59aa:178d with SMTP id fa9-20020a056a002d0900b0068259aa178dmr4647270pfb.1.1690445272018; Thu, 27 Jul 2023 01:07:52 -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.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:51 -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 10/49] erofs: dynamically allocate the erofs-shrinker Date: Thu, 27 Jul 2023 16:04:23 +0800 Message-Id: <20230727080502.77895-11-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 X-Stat-Signature: d9tixcpu6ohpiqom3yiwyx5bcme1t344 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2313B8000A X-Rspam-User: X-HE-Tag: 1690445272-358446 X-HE-Meta: U2FsdGVkX1/Egx6AkOKJW0GfEJX6xhxCumreYVaS7/EocPDVHsxPYl7l3cyLPlot8bYd/Dz47wvDM9ybqF7ph16YX4jfeVwRd37sw46Rq9pffR5KrIGJKgTtncAc/kW3+TeUPAOwYCsILYKyDhYt2/OsbJmxgE0S5L3h1dqWVd4uGK107QmEpMsXnho0FVl/8lDxh79PQMQpnjFdUIomCc1ePyXH0br4VA1RNAbgin9+/UFo4ZaBvlhONjLnHT4EjeQ2wAFC1fHvQHJsUV8JY1+7FvmZdSjFDvQn9964N55VKuSYchlOfnniV6cVh3wKIXVud2RmFm2AZYMEJjaCSaXQxaB7UEBjV9stLZ8FXAZ6w12lxpye9x0koWSfMP+M4TOpenLLSyUncNejdWoyEeZL+3OiHtT1WjyIDjwOuTMGOqK5ooCqxXWizbGKosyjVH05eoxBfCQjGNYWrj/ZXusEV9oeGjQhyxYpX6F3DYBs1M27OeGpjMXTMR7ZeLRp4bRMpTGMkCS4sDdek9F2uwh0bY8ONuh4YfLcwPMpuS0Ltp2Huy+U33XjaLS7FV6QX1Z3as130ityxkMNGI9onqHk5m0zfW6vCmAT/LAvYO2+IxHpUvS8nwCBK4OB8ZTviQodw7IUAkHHY69fflWttqTKl5Voc1jy89sdv4ZRROpS6HVBF3Dby+vYobSWKRoAt6MeQtWxBdY++kXb4kovVC+YH2q+kOdvD6PpR75tegKD1D4kAJG4dFyN4cbdowTlTuKDbrfbCCPT/b0ydIjkEMFm1vDj0BJv0FngS2jkIRbvUglAkFrZeyrdf0IxSzFbR3CymbWlD8/ABtBvKrHyTkyeJeEbo8mzKfUMvI+irVZsT4WT9g7GvDayfqWbM62h+HKFy88RiHyGz4wkkTybsBGyhKYawhAFRVNqYX/IeF9d0BfxjqCpoCs2uMT4wOypRbXsTZ2onQdW7up3HHa STa881Nt DGGvdHRtSx64YrD0q/cszIpjuciAKyw8R3z9CZq/Z4f705XBmoqXkHvOSrQi9a6nWhzuA3Fobbp2f+qRzwMSYdasenPTJn8kcHRcKj8GeABs0Vj2Y2FsdppiWMQze3ZF7YkrBSAfQ+RrtN7p6nCcVVUcyURmd4BADkm2GKtb3Wy4gz5ioJVWma0ifApLtSz+rzL3IkK5Uvbg/pYufNit1tolz0ivkjKY1lM0eihMqIksZiOlrtGwauicTrHlo8f7StdJNJQAYBiVisv174Ew9rLZ0SMM2cDayZIt5deLx2M7r2W3zB/Q/Tdc3DodDZFK+N6LmLg2laL9/d44QmJLXVAF8GfgrOFqrKIxTomBTGgE0/bNb4Mn7HLcEeDOwBmysz6F+alYOCdea8cUphYPP1r/rA73Wm0thraBi X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use new APIs to dynamically allocate the erofs-shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/erofs/utils.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c index cc6fb9e98899..6e1a828e6ca3 100644 --- a/fs/erofs/utils.c +++ b/fs/erofs/utils.c @@ -270,19 +270,25 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink, return freed; } -static struct shrinker erofs_shrinker_info = { - .scan_objects = erofs_shrink_scan, - .count_objects = erofs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *erofs_shrinker_info; int __init erofs_init_shrinker(void) { - return register_shrinker(&erofs_shrinker_info, "erofs-shrinker"); + erofs_shrinker_info = shrinker_alloc(0, "erofs-shrinker"); + if (!erofs_shrinker_info) + return -ENOMEM; + + erofs_shrinker_info->count_objects = erofs_shrink_count; + erofs_shrinker_info->scan_objects = erofs_shrink_scan; + erofs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(erofs_shrinker_info); + + return 0; } void erofs_exit_shrinker(void) { - unregister_shrinker(&erofs_shrinker_info); + shrinker_free(erofs_shrinker_info); } #endif /* !CONFIG_EROFS_FS_ZIP */ From patchwork Thu Jul 27 08:04:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329199 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 F1CD2C00528 for ; Thu, 27 Jul 2023 08:08:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F4A06B0075; Thu, 27 Jul 2023 04:08:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A57D6B0083; Thu, 27 Jul 2023 04:08:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76D766B0085; Thu, 27 Jul 2023 04:08:08 -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 693936B0075 for ; Thu, 27 Jul 2023 04:08:08 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4B3FF1604B3 for ; Thu, 27 Jul 2023 08:08:08 +0000 (UTC) X-FDA: 81056663856.02.FB012C7 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 775378001A for ; Thu, 27 Jul 2023 08:08:05 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=abLX7f3+; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 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=1690445285; 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; b=tBYhwKkMEimHfvhzEVrBGNT7Qjgmc6oXPyu02U2i1RsQsupwU6nIREPg1smYK1pDMDABOB QDF4Q3vH8RPayApgYQIJzBKQhaTsXGdsexoko4fXK2fxlzcSSwBDiDGY5Ckjjzh5BbXV1i FisbxYifW3v1Wa9FO4lafteGtulycfM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445285; a=rsa-sha256; cv=none; b=CR9amtZzONcC16CVW2lHt0UmWv7mObuOwNte65t/ipERSY0f9SyQIxZLHBzwB1nhaoD9o+ oyossa66HZy+BABrNHHu4Dizlwh6evrHk1txWrdKY6wMcdpt1ARy49/xcByLNrDuZPqdU1 Cj4+q2a/WFF20KQ6sjsxgntH4V6Tays= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=abLX7f3+; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-682eef7d752so203596b3a.0 for ; Thu, 27 Jul 2023 01:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445284; x=1691050084; 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; b=abLX7f3+1Jx7z4l7fMDPHLPoRZGZ9R0nM8ns3oWVX7aiHujgqPmDptRXrf7K4N1NV7 iafFd1vKgmMytglgpeByIm2etm8PBx6nYdrahZ4g0/dxHWR3bRoC5c0K2oAToNHdR0rs G85XXQ+OMNSfgkQPICGhKu4AFUznJk92yyLKwDX6t68bXy1Y1afxgcqF2Hrs2hRsS8Pi 1cVGQ/135Rq8DHs2i32YJ/uaSpZLHmMFkQEdBwI9bGEy1fU1/6Py8qR+g4Mw2XtURfuH rP2vSQAfzwsm7AmoQxkWOyj1kIWSKeW+aRYJEV/VwcFYAz1pgMCM8AVBtPjE13HITA/4 GS9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445284; x=1691050084; 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=f+zNYaRC7WOrXvS9MeEiQUBTAQfjLjc/pgN/esuhj34=; b=iEZe8OuxdiPwzFyzNASE0nsn+3EiqXWMMeEeu4brPMuD2kYajhemxlXBqAYELaLGIQ 6bFcv+gfQ77oUZXsgAUKFyj12dklZlOcbPgFtRnU6pIwM1OF2cuUGQvTU5O3V2aSrgla ZeiYw9GgoK0C6bgdlR1kit8ji4Fkj0FlFiJmaWIntsPrkwhhpWJfpY8t8h2WfhzZyrlu f1YR9PqnO40I0LW/JHFJHvCIsmEH8+K6DkZ30PgpC/hxqTLsBFyUxEeGf7FCmJG6txNB 29hApmD9mBLFDp69SeBnKUqMOg5Q1BJlfcWFU53YgnTfPG6UU7/tbZU5G079i+jEbp58 nvZw== X-Gm-Message-State: ABy/qLYmxUiOpsfN1kN7AufCKcyZs0+igV6LwVRT4nwDgE1YNA4JyZ6r m0A5hRvSPUR0M3tdNPrCs6hOGw== X-Google-Smtp-Source: APBJJlHpYZMPheHhGtAzh7w//Dgf2VgsvvziRNiT4CodVVfE3Y9RoyQKb/hEjPAgUidNi6thlhXB+g== X-Received: by 2002:a05:6a20:4286:b0:12d:77e:ba3 with SMTP id o6-20020a056a20428600b0012d077e0ba3mr6418674pzj.0.1690445284151; Thu, 27 Jul 2023 01:08:04 -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.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08:03 -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 11/49] f2fs: dynamically allocate the f2fs-shrinker Date: Thu, 27 Jul 2023 16:04:24 +0800 Message-Id: <20230727080502.77895-12-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 X-Stat-Signature: qgp43dcmmb6jmes6dejqdki1mpyaynpi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 775378001A X-Rspam-User: X-HE-Tag: 1690445285-129936 X-HE-Meta: U2FsdGVkX1/TjgcvAQIajFqZs2KKZjn71kCttUF1qGmfbT/EtP72ATH8M5MEg5+PEKgNKo1DPDevavG/3Ke7GkzPoYVGQM2MdjnHLy+xwTjn/MhkbvSycFOIpse8OnJQN7XG+AXYzcCuqphX8FT7RrP4/Lz2Qol3Dv4aNpOD0vPhnCTkqN+UyV5W3gACR2XqaoOHn0s/MYnbxYykQ13BmtUDRKtM7mcEO8H/6LICze2ng4coq7TmbLG/UV9Z8FuKgWhvgtOg8J2OIKQICM8pFf3MtpYnO66nq7P0mOT3zMufzI7hIduiNcaSNEqDYisfStOKPxrB6N8ZIcf8xaM2c/2m0sbDoaUre286Yksrgp6I5UfbPUGG1bddTuQzIRA4zLnxDLuskAWHWrr4tJRrBttDBPw/vb8RElb6VQiHMmxtla3aq5dgzlV5iER4kH/35N+ClU0ySjErA6iyd6VJGsvTR5QakIxZ38prwKrKQJfRulJs83yPQgmkoKw93GvH0yhT0pmcezEgng3JiFC4lcyv38XnoRvhM2TxxIqxfYzmeowGqUuDpnjhd4yNdWSCsj2zWlD1JtMAJsFys8w6R1u8ElU7QixebUsG4Y9wm8wLGXAaLlRfWSMqNfaFKw6xXzL7kkxSeMalIyPMJBAVp1V3hMeRwWaPfhLEhSv0ep0Y3n4+KxdrGV4d+BdalT17Gi5dN2VgZkCRX/dx7A3weR7dPAE4Yv5nzc6aG5AY9Qz+n+CT22eigy/VBo7AZSF2yQInfyBkZS02Pg3OVATvLsE9OINoHPiZNVUNNMjdNbnwI1lCCqVkm53XmOf/PzkrpvIhvh9CoQt4b45I4ZB+fB65cTA9MQo+xZ9mKBO8aa3BDlUSVQsikTsJpDO6O50ysuSb6gZ2syCSIxbYV8GlPy+FCqazZje3LXmAgBWkjjHi5dyngaIME3jPtJHtGTOYfYy7+8aH/H4XjJcof8B 9YxePQhZ cBzh5RmVRTHnR2R15lTBW07upp+t1Fod9v3icNva8f/Bzk3Uy0+/C5zyn7XW9hK9KKD+evjpmHyZFlUGOt4dD4LK4nLaTngnwI5m/4ISzNdui2dSsB0LItV34lHZnNFzp7lmpx40u5ABS+oSQQc07uF950GzvGPtNMMInDkXXYuvdXKozKrOWv0P+PNpQ7i8yTsJnS5xD/g9Zrf/pjN+f021IbwXCmaWKnS/UF2RKTyNM3GHgyJEYrxFuVjBzeOr0oF6My4F1N7YdpHelnAvY494PmXhWGsAK5zi47q9YcsMD73er+f9RaVqQ6OYLLeb5BxiPcRiNN/4Mz72KZDz3vS08ErBsVhl88wHsK0TS5vP6e6ie2xfwgra7jB9nY9AucAxB6HTDMdjzTNW4k7i+QjJ654sIEiIxq8ol 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: Use new APIs to dynamically allocate the f2fs-shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/f2fs/super.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a123f1378d57..9200b67aa745 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -83,11 +83,27 @@ void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, #endif /* f2fs-wide shrinker description */ -static struct shrinker f2fs_shrinker_info = { - .scan_objects = f2fs_shrink_scan, - .count_objects = f2fs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *f2fs_shrinker_info; + +static int __init f2fs_init_shrinker(void) +{ + f2fs_shrinker_info = shrinker_alloc(0, "f2fs-shrinker"); + if (!f2fs_shrinker_info) + return -ENOMEM; + + f2fs_shrinker_info->count_objects = f2fs_shrink_count; + f2fs_shrinker_info->scan_objects = f2fs_shrink_scan; + f2fs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(f2fs_shrinker_info); + + return 0; +} + +static void f2fs_exit_shrinker(void) +{ + shrinker_free(f2fs_shrinker_info); +} enum { Opt_gc_background, @@ -4937,7 +4953,7 @@ static int __init init_f2fs_fs(void) err = f2fs_init_sysfs(); if (err) goto free_garbage_collection_cache; - err = register_shrinker(&f2fs_shrinker_info, "f2fs-shrinker"); + err = f2fs_init_shrinker(); if (err) goto free_sysfs; err = register_filesystem(&f2fs_fs_type); @@ -4982,7 +4998,7 @@ static int __init init_f2fs_fs(void) f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); free_shrinker: - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); free_sysfs: f2fs_exit_sysfs(); free_garbage_collection_cache: @@ -5014,7 +5030,7 @@ static void __exit exit_f2fs_fs(void) f2fs_destroy_post_read_processing(); f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); f2fs_exit_sysfs(); f2fs_destroy_garbage_collection_cache(); f2fs_destroy_extent_cache(); From patchwork Thu Jul 27 08:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329200 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 1D646C0015E for ; Thu, 27 Jul 2023 08:08:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3E2B6B0083; Thu, 27 Jul 2023 04:08:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEF5A6B0085; Thu, 27 Jul 2023 04:08:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B6778D0001; Thu, 27 Jul 2023 04:08:19 -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 888246B0083 for ; Thu, 27 Jul 2023 04:08:19 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 550EE160503 for ; Thu, 27 Jul 2023 08:08:19 +0000 (UTC) X-FDA: 81056664318.16.6F54FC1 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf09.hostedemail.com (Postfix) with ESMTP id 439CB14000B for ; Thu, 27 Jul 2023 08:08:17 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LFYvlia4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1690445297; 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=XAY9+N2BbVQBjCT3MmFWkPxUR/2vf6o4m+CtMBoAzag=; b=8VoHTnfYgCnEJbk0tyI66JBsARMCh1kXgnpXq3s/fLEUBXi6zfCALh46HngPSYjQYyuawI BYfj+pNYIF7jh8BhyTl+dz3akmX9B+ixKuZmIHYgqBhAU16zmfXy9dpWy3UshT8ifG2/VC ME+BcWskl0ghTHuoatv61MIv8m+C9ns= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LFYvlia4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445297; a=rsa-sha256; cv=none; b=N+nUgQ2uRkjynGf1KFOUlwYFJDrFITQuXZEgmaGMffapTweASfHq7Qhgfq5NWH8O8h7370 ZGjQwxowr16eR3RrTrgFBqszO/NFdlDkdOk8aO/q97ThMirwtYQjooAME3BEYkbVZIpJU5 ofW1ubxAX10EmjGq4KOs6+7No8nZTkQ= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-686f6231bdeso112650b3a.1 for ; Thu, 27 Jul 2023 01:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445296; x=1691050096; 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=XAY9+N2BbVQBjCT3MmFWkPxUR/2vf6o4m+CtMBoAzag=; b=LFYvlia4velFDizk2hHXlBW7f/l7rbfbGMuqLFZUpWLlBrVWlN4fEmfbvc4omxzXDA GS62NEHVqB0PFgv0flEq3EjMDASyoMQLwnHtJ15RD867cmoYFSzpLBJze2MH0FTuVYWD NsiHc1gWK/drytRuk+pd4JkJ3rj2hRu9B8SocS/OtbfY5xFfSOGukZMVRW73BQpYmdrG /5Ymr320vt1GGeIXCFFSw58+k2f5zcvch0LSG0bHy5CbC3AFLqLQjQMF/E7WQcKZk1m8 rvHs1btuYuzdVvuVmWOj+XioQ9BrFWnwjxo07/zHn9Dajw02v1LQ6Dr1U7VOL/6BCiXk S4AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445296; x=1691050096; 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=XAY9+N2BbVQBjCT3MmFWkPxUR/2vf6o4m+CtMBoAzag=; b=WPtOt37NbhpZmtu/R+3FRTXobd/bbu2/ULfO+UAZ0TOXd/eIFuBTIxlK3FAoHYyr+h XodokLbzivPIcQSAv81/PKoatvVdpiO1HPiXPFTEhSkyEkQ3m+8QQ5d6oR2q/pd3it6g 7AtUvNq5kSGWA0QdH2pFoqjWpf1Qw/ZYfwu0JPLVnd/UcHo7y/JK1HEZXRJ7GSHW+Emv OGtslAKGXsEyKP+/nYhOq5sKkzTHeGKu5UIhLpH8jDD8bovlcLdZFfo4zgoxL84GSXNc kwGGAl7GBP2+gLjocR7NI/nFHYdFm4gfBCh8pM4GCQY7LcYvRzK0Cb1knHeLjPlnK6Sv y52A== X-Gm-Message-State: ABy/qLa3o5qt0XqbomYsm4wQwdLD5zbxNavmvf263aYMs9KZOnDyTlXq k5G59GiTWHy7oLsuik95IxhqCw== X-Google-Smtp-Source: APBJJlFXIDspBDKYt+edW+ekZSGIMkDEJizocNVTOvlzV7xMQBKW4TeDX8VYOaL7MgnXn0ggLAa8Tw== X-Received: by 2002:a05:6a00:1586:b0:67f:8ef5:2643 with SMTP id u6-20020a056a00158600b0067f8ef52643mr5200829pfk.2.1690445296182; Thu, 27 Jul 2023 01:08:16 -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.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08:15 -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 12/49] gfs2: dynamically allocate the gfs2-glock shrinker Date: Thu, 27 Jul 2023 16:04:25 +0800 Message-Id: <20230727080502.77895-13-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 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 439CB14000B X-Stat-Signature: kp15e77o4yajgtbsxw4wfzipij5sk9oq X-Rspam-User: X-HE-Tag: 1690445297-387781 X-HE-Meta: U2FsdGVkX18RMzjloJN3/t9200wYEpePLQlFSSCeU7qwnVXNmFF9a0VOtL1ElT4YHD7WfQVQqh3DSetCNI1jjJrcoXUQ8vRh2QhGUS3KLn3k0pdTsKt8fE9mMx18bo6ww2ZZNdypAZF19QMvoH6WV4P9IGKrgBnAt+xZfbb95vaxhb6pS8ns7//amOsXc7CRZ06StjvorO8ox89645tYBQHQgS131qBoPDKE0MH08m3yGkbVV35pEz6PLW3hf3A1LtvGQBtkbkLTdnRX8GxgtDkwOZi/rPfJGoR1V6tbUjwg54skHKrDl50ZSDT2u3eUVRwGFN1o1yW+mZ6WLSpsDHuPKP/QevhhWDGejLHRdnW+HI6t54qFMrF0Wn+VRS1m9FQK6BgOReAPF9OgznLsVj+Pe5NPo4ZOWaneIEAMl2RpzNEIhz/kzL6rn+N1untB8B1gzcC/QXJlnh4ro4pj6rck3Qtko6wb9VCC5IFHSWixdg/d3Bw08CdHDLd+rl723BOedPtNupWRWOfDYi9ppaC0h/oFBxTfZgIhWCDga1QuWkImvXaBxnpPKKnb016ts/Eu9nU//WGTC+ST80zPXjaJYkvTL54q4xdm6ZmYiF3HIcroAGOwpGdfnLITd53vGpkrZfv6e8gNx5ZUAZamEHGr7OVl0iQ7tbcYLExwDITUJnDSlqA8UIwruDejm5n6pwNqli/2PYQp6+hmCjTcdJGdd7bMuYUtFDPdYlJR02VaWDhnA+DzqLiDCJbyvngMlyf3ZSl5IqIFNFI14qIsmxfLKSkQOLkC0s5tw9JAFneQYxfFzoBrLD1nW3Rg1+I4uAnXJtb45IKRYAXIUyS/5Op90Ok/BzMZ/Z+GcPTCd4mVaD7iXd1FkVVN4WgvDomhjbcjTOKsnOMbfDGYreo4tWhKOe0vq7GkQ4vuPADIHc676ZuGLo1oqBPRCjvhehMDampLROwU516zHVALoZZ 2hZb2Zuu akNHeZYlhznYquvDc2p5JI71QUY+oGXHBXc/2fbmoniwICeiqhtvtcej1x5qRe6UzZzgz2+dX+xLI4mKdTIN/vAZmUeO6rSAMehigTXrkVbAghHUFjrbK/oY33ENPXRbEk5jraMFMgmJsyLVASFUZxIuuqExPCL7tCulb5oU/AXvIhNPtRQxFd8dfieskuriUAk0tGktp+0TT8hD8UQHxNxgsl/MVYj2pUFKJoICLzpG7A7+JXUqyQri4xeeVvfoA7IUNyfgsfwyyCwXXnXcxgrVVybt9GXZUJ1LIgGqjN2Vvj23uj6AbatdgQzTiZTA0Z9iVM/aXsviEEZV4MQgxdApWAHhelnwmvgvahG995/3hyxADqagKSzTz0KObtTxmyTNsOzgdSojaSWpld14JTdKeCr5ArTAaTUdN 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: Use new APIs to dynamically allocate the gfs2-glock shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/gfs2/glock.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 1438e7465e30..8d582ba7514f 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2046,11 +2046,7 @@ static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink, return vfs_pressure_ratio(atomic_read(&lru_count)); } -static struct shrinker glock_shrinker = { - .seeks = DEFAULT_SEEKS, - .count_objects = gfs2_glock_shrink_count, - .scan_objects = gfs2_glock_shrink_scan, -}; +static struct shrinker *glock_shrinker; /** * glock_hash_walk - Call a function for glock in a hash bucket @@ -2472,13 +2468,19 @@ int __init gfs2_glock_init(void) return -ENOMEM; } - ret = register_shrinker(&glock_shrinker, "gfs2-glock"); - if (ret) { + glock_shrinker = shrinker_alloc(0, "gfs2-glock"); + if (!glock_shrinker) { destroy_workqueue(glock_workqueue); rhashtable_destroy(&gl_hash_table); - return ret; + return -ENOMEM; } + glock_shrinker->count_objects = gfs2_glock_shrink_count; + glock_shrinker->scan_objects = gfs2_glock_shrink_scan; + glock_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(glock_shrinker); + for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++) init_waitqueue_head(glock_wait_table + i); @@ -2487,7 +2489,7 @@ int __init gfs2_glock_init(void) void gfs2_glock_exit(void) { - unregister_shrinker(&glock_shrinker); + shrinker_free(glock_shrinker); rhashtable_destroy(&gl_hash_table); destroy_workqueue(glock_workqueue); } From patchwork Thu Jul 27 08:04:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329201 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 47D75C0015E for ; Thu, 27 Jul 2023 08:08:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4D216B0085; Thu, 27 Jul 2023 04:08:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFDEF8D0001; Thu, 27 Jul 2023 04:08:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC3EA6B0088; Thu, 27 Jul 2023 04:08:31 -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 BD9C76B0085 for ; Thu, 27 Jul 2023 04:08:31 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 94A6F140FC8 for ; Thu, 27 Jul 2023 08:08:31 +0000 (UTC) X-FDA: 81056664822.06.B77CDAE Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf14.hostedemail.com (Postfix) with ESMTP id B9CA2100005 for ; Thu, 27 Jul 2023 08:08:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Xysv3RsP; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445309; 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=PjmSZHUI5/Kx8ZOfBbo02iydikdUH/y22dszJBbwnrc=; b=Iath2tAqaN3GR35Somgm/3UFjWV7T5FDi5opE4MwElU5rxSFvVW3bWKGUeHQYmnUIQzAiv /q6sRvt1jZlg48CIiZcKMKoEKfoi3B5fh8lb5av/xk77wyf7j3raPUXZnZyqapoVsfRtvq 5Nlg3ww/j1QT+UtMiJH2HbADwk0H8nA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445309; a=rsa-sha256; cv=none; b=7bE4B8sjCHm/EC7uQDHNCEentqKZG7MF3TpC5+zP4Y+yEZTRY0Mxj3rqLQMpyQlhunteWW x91uFu4xMi3X2BVeTK04dLGekV8HZlKbnOW95UgprO7uNcgol/Hw0CMjhK9k9ajwFgpE+Q ak5FWk8qFcV4BBftdWV4M5tFfZiTeZU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Xysv3RsP; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-686f6231bdeso112718b3a.1 for ; Thu, 27 Jul 2023 01:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445308; x=1691050108; 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=PjmSZHUI5/Kx8ZOfBbo02iydikdUH/y22dszJBbwnrc=; b=Xysv3RsPsBshttSMBUyUOf01pFj7ACJomxAeSKClYNtUM/IzDnc+1qcVpxKo3Yk7lI PMJO/0QAsBuNTHH31vZSyAI+mqZzOZhxUKyEZ0z882UMy5ds0dV7wjv4n79QhgQIluxL 7aiFKUJGI5uVRXEWRoqfDwEepuojrPx+nt9lSRf3+jabTyI60DcKdVq5RfgL5+gSsYt+ gIHfo7xL/z2KDHdpCbDlWUD9Wlzvl0HFxAouF/jEEZTs97EVMQFcZk2wLBhFoNV93wDr cOODQ3G+tMDc7b4BNamRJNYxJL3PiF9jIw3/5zQqa59OSVfyqIzXn4AyZmUz4TWVr103 SUHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445308; x=1691050108; 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=PjmSZHUI5/Kx8ZOfBbo02iydikdUH/y22dszJBbwnrc=; b=dM87kg+ENnUo1k7nX7m72kaFZVCCxwMcXejraFBcRw1fZzj3HUzSFbtSFu3UjHa5e6 GCrd3qJlSd5EwsnSQjIxmdXzKwyWX8SIcwcY5aitifppcFwNaHpl2EOOWkhSwSEGynCQ RyNaOiCjeewAl8QTBOek5iy7k9ryhHzvTWtvqeOxX8Q6AjURZS+KsUMlDiVOTjEJORLc 2L7LddrN6bzYZMhwYYio/n6S9LPT5w3pDgu23a0vDVI0ydQmi8zeeZx5/XD+iDwmRTma 2FBJ4E88GnWGS/khXGTy/gDQsiKW5CSW/RuGNDeMJEF5a+sjn0Ie5zObmEMMfHjwZ9p3 HawA== X-Gm-Message-State: ABy/qLbRdfB/j3LmFRSQeiUne0pb+fITHhPEuuVuVRnwc/ljuUaIBvbe WFkBZvr8H7mBHotIdLE0iZRhCg== X-Google-Smtp-Source: APBJJlEap1sNysOWJSQnWaDnt336ll2X4eQUWxGjP7f0SXFaJg3Iw5H2LPNpa2qt6BR3D4CNzXfNwg== X-Received: by 2002:a05:6a00:4a0e:b0:677:3439:874a with SMTP id do14-20020a056a004a0e00b006773439874amr5196539pfb.3.1690445308627; Thu, 27 Jul 2023 01:08:28 -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.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08:28 -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 Subject: [PATCH v3 13/49] gfs2: dynamically allocate the gfs2-qd shrinker Date: Thu, 27 Jul 2023 16:04:26 +0800 Message-Id: <20230727080502.77895-14-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 X-Rspamd-Queue-Id: B9CA2100005 X-Rspam-User: X-Stat-Signature: dxa314xy7gn671z8zkotd84xbs563g5a X-Rspamd-Server: rspam03 X-HE-Tag: 1690445309-1323 X-HE-Meta: U2FsdGVkX18jV/FCuIiZ3t6xPj1yNW8qGV/aOmEA89/BOfuJ7CKbTVs/oWzjRr5C9toq4k0kXcBRRDHBrxFsJYe8h0qmP144+AcQYdii5Insgo99yCDikbQBf9nT/prMzguRIHN7hvWtWVTAq/Xevw9Qwad+eGZr9VdQuKsrl70VrR2H/nw5U9LQmdUvZBVJ8iCAwhBnAWNAJbR2hqJhyF5csMQXYtX6j+7HWi1HkkSmGeJEjV1MFa/EtsK8KZStXfE9pWfzgJKNK6tS3DLBHA59G+DALPH7X7yk56aP6etZKFcTmdHicgwSiSK39NBrHK/S/07gn3mi5YPjzPhGfjrdrDXxfxU0ylaj9m0gO4bdiVYD3DRyyajIEnh/kY9vvYaIiTt/pvNcZu+n8vEDgupVKdnptS2COCtD5MmcKRe0JqZXi7FJi9NDd0d4g3MxM/qRlVzZSRWTr1GajvT086hzGt4AKNyFFm1g2BwsGYXXD3msQTFfH6GcHKMNaCFXBQywN5mQILNtLfAxsMH0fV4BbaYCCDeuK6uGpjSjbR/KQrteSwD4hdI+6nWLxCuZK7cGVETpqW9qoAeRyCnMGTZ4Wy5Ib3Mwc3w4IDKcV01wqsDGPy92wUnvOprVhir3D2bnPH3F9a1q3nak3xAHb+MhUgYsh58A/7sRJ8dQBCqhrtyn/awFU4h8u6VTHX9wOHub3e5tXXXElC+vZ/UQdqiOnych5/hDG7/PgABHHa8J+LTIvPkwrKxWVcF0GcwlGQNMvJf2QjGsm9mHQnfj+r1tE0bzpuBZf8dkJCY3leVgJcf138S2hD2R/3xryD0Vp3P22eFUGlxQ6Z/FYeaBHhCHFThww2JfXiJ5f9QeucIHn2PTCS/au7oJg9wh0jBd7Ly5l7M9odO5ITjeEOHzjz3puqCHOavh0Rnmtm7wnWl6uSpxyEayJTFBO7WFkxSAN0ouhAyqSzFzYIn/NBC XRaprQqO msUYZhzuJd85n7cwzP7KodZLj1Bqt+N7zr7Jj/YHENFGRJ9efutsRRXisRl8OIrvReAFA2WPbNMt6aP7w8XI67jqQzRC4KeMVEele88+cUYw1EzJlVj/Bu4kELAB8wZpNHgIID8Wn7gPG4EuzTEx5aTB79oNWgQQywbuGc145EUb1w/b4GiKkEJ0fi+6aWuFiRRbFhN44wACIOnGZF3BdhcwFqQTrRVJn5cKBI9vWTAMaZMDt3mvmCZLQkS1NnDdcBeJwAAtvK2ceZ6RcHeuVOEVZy2wwnqMULtQhI9nLsnCI0Mx72jKRrwqKVLC5nYYw8SXGcWvjqGecmG9xLbzbeKOwJkUhqwVa/UxZNXaeJMQ+VeMdsuLiD4EASVQ36dtQ36AScw6zwPAatyGGk2PWfUe9t+IjGCtxVEqXa61i7eNRx/d6ThRyG2A/rnqi6Klv4eRqpzNhVdQTkjU= 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: Use new APIs to dynamically allocate the gfs2-qd shrinker. Signed-off-by: Qi Zheng --- fs/gfs2/main.c | 6 +++--- fs/gfs2/quota.c | 26 ++++++++++++++++++++------ fs/gfs2/quota.h | 3 ++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index afcb32854f14..e47b1cc79f59 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -147,7 +147,7 @@ static int __init init_gfs2_fs(void) if (!gfs2_trans_cachep) goto fail_cachep8; - error = register_shrinker(&gfs2_qd_shrinker, "gfs2-qd"); + error = gfs2_qd_shrinker_init(); if (error) goto fail_shrinker; @@ -196,7 +196,7 @@ static int __init init_gfs2_fs(void) fail_wq2: destroy_workqueue(gfs_recovery_wq); fail_wq1: - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); fail_shrinker: kmem_cache_destroy(gfs2_trans_cachep); fail_cachep8: @@ -229,7 +229,7 @@ static int __init init_gfs2_fs(void) static void __exit exit_gfs2_fs(void) { - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); gfs2_glock_exit(); gfs2_unregister_debugfs(); unregister_filesystem(&gfs2_fs_type); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index aa5fd06d47bc..6cbf323bc4d0 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -186,13 +186,27 @@ static unsigned long gfs2_qd_shrink_count(struct shrinker *shrink, return vfs_pressure_ratio(list_lru_shrink_count(&gfs2_qd_lru, sc)); } -struct shrinker gfs2_qd_shrinker = { - .count_objects = gfs2_qd_shrink_count, - .scan_objects = gfs2_qd_shrink_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE, -}; +static struct shrinker *gfs2_qd_shrinker; + +int __init gfs2_qd_shrinker_init(void) +{ + gfs2_qd_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "gfs2-qd"); + if (!gfs2_qd_shrinker) + return -ENOMEM; + + gfs2_qd_shrinker->count_objects = gfs2_qd_shrink_count; + gfs2_qd_shrinker->scan_objects = gfs2_qd_shrink_scan; + gfs2_qd_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(gfs2_qd_shrinker); + return 0; +} + +void gfs2_qd_shrinker_exit(void) +{ + shrinker_free(gfs2_qd_shrinker); +} static u64 qd2index(struct gfs2_quota_data *qd) { diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 21ada332d555..f0d54dcbbc75 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -59,7 +59,8 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, } extern const struct quotactl_ops gfs2_quotactl_ops; -extern struct shrinker gfs2_qd_shrinker; +int __init gfs2_qd_shrinker_init(void); +void gfs2_qd_shrinker_exit(void); extern struct list_lru gfs2_qd_lru; extern void __init gfs2_quota_hash_init(void); From patchwork Thu Jul 27 08:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329202 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 55EB2C04E69 for ; Thu, 27 Jul 2023 08:08:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9A8A6B0082; Thu, 27 Jul 2023 04:08:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4AF76B0085; Thu, 27 Jul 2023 04:08:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEBC96B0087; Thu, 27 Jul 2023 04:08:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C157B6B0082 for ; Thu, 27 Jul 2023 04:08:44 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A3F36121054 for ; Thu, 27 Jul 2023 08:08:43 +0000 (UTC) X-FDA: 81056665326.18.F37756C Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf18.hostedemail.com (Postfix) with ESMTP id C9C601C001B for ; Thu, 27 Jul 2023 08:08:41 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=FYj50vEz; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445321; a=rsa-sha256; cv=none; b=fFV/c82T4J2DQlHHJ6VbS7/sBRP2w1w081J0jpZjRaHPvHFQdQY7c421YKyLLuukFS7q93 No5mFaSGbTgjvrHKhS6ceLxaJLk5i9lPwp+DNnpPuDm7o38B1luEO5wrlGzlFA82KDpAo0 6AqLsHh9V4/8q7LYrzVnPIUCm5HONWY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=FYj50vEz; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf18.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 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=1690445321; 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=XXAG7UeexodYStcT1Y2gz+/6q+0E2xrK+D1h2eKApUE=; b=6nA30oA+sLkySZKRNNAh97/GCh/ihEUiWvResTwUrUQAeQc061hj5YwcS9pDSr/kRqCJzr D3ZzGWAbT0N/SlMwdpjfpPyOc3fMdxgmQb/fC6wlxWv+Wycizw3BDCTlN8c7J6OBd0Jwtx 6rG7vw5pD/AfZe89rz0VsE3ny6OMlEQ= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6862d4a1376so188740b3a.0 for ; Thu, 27 Jul 2023 01:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445320; x=1691050120; 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=XXAG7UeexodYStcT1Y2gz+/6q+0E2xrK+D1h2eKApUE=; b=FYj50vEzpqpR7/JHkZvpr0BbTAfzFzYsY4J3w1nZqjf0BTlUYZg3ENXBt/E7bux565 4DCZMkbhxlQ4uTban0w+5H7n5bf7VgzCbRNW1xqy8V5Ii4h7bosDaVHN++mTVrl/7/23 WZSmzaLueVj3BrcJoWAHCGvwk4IeXhgQ2bRNwNFy4V/7BgrLzTS5YJPWuEtp82HeU9Up caVaRRGf3jcxw3YWyZv3sYid2tLZtftHEV5/wvAbdGp4oPWlqnmvAPY3i6LJ0BE1y1ID 4Y8Xa75Xt3wm60SqSMunOKTUxH6aZ+1fGysddWTaZe8OA5PjpbdliSp8jUu0Z/6yBQXn rqWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445320; x=1691050120; 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=XXAG7UeexodYStcT1Y2gz+/6q+0E2xrK+D1h2eKApUE=; b=V7AOIvN9PHp4O805qTY3+elWvoTUIcxxo3VuJZgr4+KN4amjp976wUxlY8mIuctgm4 cwam9WEpdTepEPeFV41TDs69KgJ9fikZev/YTQI6pzjKejJTGZet7Sq4l6cwgJS6gmXK b1XZjXzj4ZuZZW007E1XNZOYXzkvLoM/6HC3Gfkj3ByLT9+Ossf5TcxEqQZie1Jxf21v JFM3N2SmummnPxstuVOjtJUEABuA4GENdF+MvnnawP5J97MBXNkkbnW67wcZn0cbYRTD JEThxy4p/lty+nt6LQ/6nmJ9m/OPbLE3j5x1NFYUEanwyIyRy0kYdM7OwaTEqqrqKt2c AXaA== X-Gm-Message-State: ABy/qLboer2R2KWlBhtl7cUGgVclDTUCuwn6NLKkM32/I8n5SAwtMHDf qTL7BKIZdKR/tvLuUw4p17vbHw== X-Google-Smtp-Source: APBJJlHkKWPiTWl3kfFSQlaHJ4f9EFj8oaHZmEibAoOMDshGtR3BMo+XERT90zfJYijHcIQQmSOpWQ== X-Received: by 2002:a05:6a21:32a9:b0:136:f3ef:4d2 with SMTP id yt41-20020a056a2132a900b00136f3ef04d2mr6059155pzb.3.1690445320596; Thu, 27 Jul 2023 01:08:40 -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.08.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08:40 -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 14/49] NFSv4.2: dynamically allocate the nfs-xattr shrinkers Date: Thu, 27 Jul 2023 16:04:27 +0800 Message-Id: <20230727080502.77895-15-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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C9C601C001B X-Stat-Signature: pksropmu415kh5f4434stdohyi8g1bpa X-HE-Tag: 1690445321-676598 X-HE-Meta: U2FsdGVkX193OCrk+LmsG9QjwZ9d0QFzPz3hZiE4O2k7C+ofGuCoFLaOiNXeo+KRBHSocFUxY8XQQrZqd3nEuQS9KWXZtKP68NzCW2m7KP/U1eSclJQ9DExTjm6xPdj5tRz6XtwtTCBsSGctsdGMVmyL/UQkTCgBjRYNZ0jacchaU6fmNRUndhhx0ryHmGez4yRNMAFtWiPMLeUG2ENhh878Ety/zaEqv55UJoOzHXznbAqlxaaHKPaRQnkBalXdjkHSO/Bmv4ZmjfRYq/0UXdM3Y8K6T8TBN6n24WZcgg2PTbdAXN7PY8IXQUGG9e7mfNrZdeTtDwlVkhEWK5VCM29I0lRbPjg5+NPxZDmk5Yx0RdwMccPzkgEXVl5oNLRpM2vYE+fug5jmPMDMpoq03oD1OcXGZsVTCSEwWWCj2ucXbHOKg5m/m1Ka7MAZ28fIkllbWawlCjA35TD8GLRsGoJXctD8kvbcFWmhiKI9HdVQNA+O88a+AyGJsz9tebRAghGiWZQ7zlqqESKf/lAfNNPbF9yjsAvdP0+2NZTxUg05npbLhTyGBiz8GYuW2qZrDiucJEQ3a28v8453XImy4mwhWxwmNtNb5VfVDl6i75+AxNDoheiA4szGP3jrCRw05019JXTVo/bgrT+aBmaaWPCc51E67gEnsyH5Oa/3muMKXU3fy7Cq7RmryTY97NU7vmelq5UfboEFrrKZvWhSPJSBChg13Ru3QOzMq2HxAB/y3xuSbUwoSdpY5uxIhcyaTPKe7ikU2WscQvt8wxxHP1XocNcENs4HqrUhoYpHC3Gw9MR6O4oYiF+pX1ED4e6IWxAHR5YP7zHmdRrWFIjeEI5Gv65lGxTaoQnvZiMsUabmIjGDBLVfyboc2odKhM8yIIP7lDlQEwGYTX2JWHnx7BAWbH4E9KFSxAzPm84fd06NibYBnOTEUdyigF/LuGrHyO6g+10PnVS8W6wjdJP hK/Zoz6O v00EQ/Lb+5vgfZpZLA9UNgDRGdFamV5pe4f2VunKumQu6VttRSVEvkqU6ZhIxLE9+eGik5FW9xC/FM7Q9u39CaSs4iNncvdHeuwoMUMN9UxKDp5nmUAsoW/IWAt6cClpXP4JokM/9uWh0Iv8xcujG2H7q6mdbhZxh5nWCrlPGfo65W9bIAblgkoEEmKmAs0HkrMonK/kwuNuMJpOBB3ur/UkUtBSrUxn4HJ9N7Odfhsad2Z2ixi/nwxF8syaOhndnPKx/rpvmuHaJ+Wehjmfun0WOc9iTt4WLynKKj7NOkgYaOf5oI3ancos9774bwGQbJqszqWb61qnB05uhOF0EYy9/2gpGhl+MtgPdankF8wh1R+emblf88OvbO/fyqVpRvUg6P3G7rallpZR39DAA4Py1i8pxZ0FRRil+ 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: Use new APIs to dynamically allocate the nfs-xattr shrinkers. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/nfs/nfs42xattr.c | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/fs/nfs/nfs42xattr.c b/fs/nfs/nfs42xattr.c index 911f634ba3da..2ad66a8922f4 100644 --- a/fs/nfs/nfs42xattr.c +++ b/fs/nfs/nfs42xattr.c @@ -796,28 +796,9 @@ static unsigned long nfs4_xattr_cache_scan(struct shrinker *shrink, static unsigned long nfs4_xattr_entry_scan(struct shrinker *shrink, struct shrink_control *sc); -static struct shrinker nfs4_xattr_cache_shrinker = { - .count_objects = nfs4_xattr_cache_count, - .scan_objects = nfs4_xattr_cache_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_MEMCG_AWARE, -}; - -static struct shrinker nfs4_xattr_entry_shrinker = { - .count_objects = nfs4_xattr_entry_count, - .scan_objects = nfs4_xattr_entry_scan, - .seeks = DEFAULT_SEEKS, - .batch = 512, - .flags = SHRINKER_MEMCG_AWARE, -}; - -static struct shrinker nfs4_xattr_large_entry_shrinker = { - .count_objects = nfs4_xattr_entry_count, - .scan_objects = nfs4_xattr_entry_scan, - .seeks = 1, - .batch = 512, - .flags = SHRINKER_MEMCG_AWARE, -}; +static struct shrinker *nfs4_xattr_cache_shrinker; +static struct shrinker *nfs4_xattr_entry_shrinker; +static struct shrinker *nfs4_xattr_large_entry_shrinker; static enum lru_status cache_lru_isolate(struct list_head *item, @@ -943,7 +924,7 @@ nfs4_xattr_entry_scan(struct shrinker *shrink, struct shrink_control *sc) struct nfs4_xattr_entry *entry; struct list_lru *lru; - lru = (shrink == &nfs4_xattr_large_entry_shrinker) ? + lru = (shrink == nfs4_xattr_large_entry_shrinker) ? &nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru; freed = list_lru_shrink_walk(lru, sc, entry_lru_isolate, &dispose); @@ -971,7 +952,7 @@ nfs4_xattr_entry_count(struct shrinker *shrink, struct shrink_control *sc) unsigned long count; struct list_lru *lru; - lru = (shrink == &nfs4_xattr_large_entry_shrinker) ? + lru = (shrink == nfs4_xattr_large_entry_shrinker) ? &nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru; count = list_lru_shrink_count(lru, sc); @@ -991,18 +972,34 @@ static void nfs4_xattr_cache_init_once(void *p) INIT_LIST_HEAD(&cache->dispose); } -static int nfs4_xattr_shrinker_init(struct shrinker *shrinker, - struct list_lru *lru, const char *name) +typedef unsigned long (*count_objects_cb)(struct shrinker *s, + struct shrink_control *sc); +typedef unsigned long (*scan_objects_cb)(struct shrinker *s, + struct shrink_control *sc); + +static int __init nfs4_xattr_shrinker_init(struct shrinker **shrinker, + struct list_lru *lru, const char *name, + count_objects_cb count, + scan_objects_cb scan, long batch, int seeks) { - int ret = 0; + int ret; - ret = register_shrinker(shrinker, name); - if (ret) + *shrinker = shrinker_alloc(SHRINKER_MEMCG_AWARE, name); + if (!*shrinker) + return -ENOMEM; + + ret = list_lru_init_memcg(lru, *shrinker); + if (ret) { + shrinker_free(*shrinker); return ret; + } - ret = list_lru_init_memcg(lru, shrinker); - if (ret) - unregister_shrinker(shrinker); + (*shrinker)->count_objects = count; + (*shrinker)->scan_objects = scan; + (*shrinker)->batch = batch; + (*shrinker)->seeks = seeks; + + shrinker_register(*shrinker); return ret; } @@ -1010,7 +1007,7 @@ static int nfs4_xattr_shrinker_init(struct shrinker *shrinker, static void nfs4_xattr_shrinker_destroy(struct shrinker *shrinker, struct list_lru *lru) { - unregister_shrinker(shrinker); + shrinker_free(shrinker); list_lru_destroy(lru); } @@ -1026,27 +1023,31 @@ int __init nfs4_xattr_cache_init(void) return -ENOMEM; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_cache_shrinker, - &nfs4_xattr_cache_lru, - "nfs-xattr_cache"); + &nfs4_xattr_cache_lru, "nfs-xattr_cache", + nfs4_xattr_cache_count, + nfs4_xattr_cache_scan, 0, DEFAULT_SEEKS); if (ret) goto out1; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_entry_shrinker, - &nfs4_xattr_entry_lru, - "nfs-xattr_entry"); + &nfs4_xattr_entry_lru, "nfs-xattr_entry", + nfs4_xattr_entry_count, + nfs4_xattr_entry_scan, 512, DEFAULT_SEEKS); if (ret) goto out2; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_large_entry_shrinker, &nfs4_xattr_large_entry_lru, - "nfs-xattr_large_entry"); + "nfs-xattr_large_entry", + nfs4_xattr_entry_count, + nfs4_xattr_entry_scan, 512, 1); if (!ret) return 0; - nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker, &nfs4_xattr_entry_lru); out2: - nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker, &nfs4_xattr_cache_lru); out1: kmem_cache_destroy(nfs4_xattr_cache_cachep); @@ -1056,11 +1057,11 @@ int __init nfs4_xattr_cache_init(void) void nfs4_xattr_cache_exit(void) { - nfs4_xattr_shrinker_destroy(&nfs4_xattr_large_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_large_entry_shrinker, &nfs4_xattr_large_entry_lru); - nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker, &nfs4_xattr_entry_lru); - nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker, &nfs4_xattr_cache_lru); kmem_cache_destroy(nfs4_xattr_cache_cachep); } From patchwork Thu Jul 27 08:04:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329203 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 9780AC04E69 for ; Thu, 27 Jul 2023 08:08:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 378666B0085; Thu, 27 Jul 2023 04:08:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3270D6B0087; Thu, 27 Jul 2023 04:08:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C9FF8D0001; Thu, 27 Jul 2023 04:08:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0F4B56B0085 for ; Thu, 27 Jul 2023 04:08:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D6096160FDE for ; Thu, 27 Jul 2023 08:08:55 +0000 (UTC) X-FDA: 81056665830.10.BD292A9 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf19.hostedemail.com (Postfix) with ESMTP id F14BA1A000E for ; Thu, 27 Jul 2023 08:08:53 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=fVbo4B1S; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 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=1690445334; 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=9TzzNXWnGUC4v0Im6lZC1fetjV0NX81rj7dQA53Eb1w=; b=VfUSqQGv2bZk1AJs1tGVnS5kz6F7Cb7Cs1u5X+1SMAmZe44Q8jISRHy0VjonWyy5LAZoAY CedZmn7QQ3Xvh7XB4diBiKu2lLiKQh0mxhl2wOX/IwxNIBeEl1Li/JStYcR6RRcerDABne D2FVPjhOs5LB/UxtR1wSTOtnSYCl7m4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=fVbo4B1S; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445334; a=rsa-sha256; cv=none; b=Rc5ZgNiffVAB7U6IB9KG52QJdukcPboxLTYsPvxMGsXahQWzKMoURmaf/BW6ZiusrvdgtC TTWMmqkh9Vs89uOd2tVPyQbLk49MQuLPh80WxjWLTWahqE2JIpp/OyiG04nvhtpphuwoed C+XbH4Y2AUUWfSDM83BDQrSr7MQihtg= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-686f74a8992so77598b3a.1 for ; Thu, 27 Jul 2023 01:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445332; x=1691050132; 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=9TzzNXWnGUC4v0Im6lZC1fetjV0NX81rj7dQA53Eb1w=; b=fVbo4B1Sn0AGX1nNJK0Eo1gukSsful8PC6Tpi9R2ay4P+tk9frdioPsIm2s6rPxi46 ++BpYvSQrpfhaqWc0rmuBFjQPz0zzH5N+AGXb67rsChsvEkjfu687Mjmoln0lCJnbS1t S6gxfZ/pYInNuKorknrCkgDtrsNJQ+5b+KQpVkQdCPQpNRB6D3agySMM3uM99/xhPotu rAoYyPnK20sDnc7vY5XomSSW5p6ngHpl0qbTjtgeFdhf5V6H8EL0+GE/5QBEhSY2aRe8 CqIfoMbQ3ZACqieIYGVBf+Lq9zLueZGm5ISvf4EF/2FFF37Zi67sB1q+1Y4ZesHEzWZS zb1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445332; x=1691050132; 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=9TzzNXWnGUC4v0Im6lZC1fetjV0NX81rj7dQA53Eb1w=; b=W2JucjnrdFIOj+NEGtDfDnv+ByyEftlMDhfMVcfidoXeVvsYnnr84q4cnwVKyExKqm k/sJ2p8d2ELiwsMNHR20X7O76aGjJyBXHnayRBVGjj4CPOwBwyucn8tPr02D1ZMzN1MJ 9sNxNMZSOFWpKxVm3X3Asn1pkJ/U3cyJn/CG+Sy75P4v+CzafdzeegHNyDhwaol+kU8+ u7hRhzAGV8tnIOIK9IqHBj9qxL77Vt1PkSMV1G8Asxde9YcJsPuyJ/a+ydUNptGR4gy5 r0g6vQaJJIs1HRxq2/qXaDzTQiT0GE/MEEUODBvawqdThy8UwLINrb4NSzn1ckXosV+j j1aw== X-Gm-Message-State: ABy/qLbPOEvIPkXXN3uupsXGEWqZSF9Dmx9r1WJ1Z7AWzyqURg7eAnDU 7v9VuKfItlzCVoat4YJK5LyTWw== X-Google-Smtp-Source: APBJJlFfoYzSpk6JWYRi+8IvWqqU5f15Mb/GG4zvV09auI3h1+KA8DLVYcizqJGa8aoS7uGFfDYCtA== X-Received: by 2002:a05:6a00:488e:b0:677:bb4c:c321 with SMTP id dk14-20020a056a00488e00b00677bb4cc321mr4639246pfb.0.1690445332713; Thu, 27 Jul 2023 01:08:52 -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.08.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:08: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 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 15/49] nfs: dynamically allocate the nfs-acl shrinker Date: Thu, 27 Jul 2023 16:04:28 +0800 Message-Id: <20230727080502.77895-16-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 X-Rspamd-Queue-Id: F14BA1A000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: rrn55ebobxuzke73gq5f45coe7pme8q9 X-HE-Tag: 1690445333-416610 X-HE-Meta: U2FsdGVkX18YviimhaiPAyq8N+km82hBv2pAqlwoLyc4UQAlBeelrtjTRKvpknlDBq4DGjfa+15Um72Vr+diaIIcf7HBefhN7kDypmYBzNNaurMzX/FZhnNyG/ytp20WE8nX5G+K3JrIQE52ApyO+0xRxBTdytjWb7ZiO+iw8ZrQs7mjI7l3lIryKkHnMdzdlt6duHXSGCDv52kfg3VhalBGEqGurWzAzUHksZTnu0BLFmXxgAZ9CzjL3jLgqNzEPfhyEyoW04j09JEWhKTQs56ZFecjLTxxJ/+83XGaMJoxznMrHvEMcDEMD7cslzF3+HbfKkSq6yTeCu/eiBnPRB0UZKxry331isScF2p11p5wVe7NthyWr6OMFboaxZhBTVUEBwOBVMFPfy909PDm85qUBWkQ+zExXVWjy8Vf1Eud6vZFZCTl3u1N5ewRCQ40zKNVJN+b48rOGs5xUiZYlIgAoQyTKPMoUbRVkCvlLASgTQV0eJGcPYknrddrr53FjQ/aCyfRnT8ciQEJqH4NoEwdkPXBdMExsqY5tUflhIiZJiOmT58aq+0EStzjonC09UjfDuAHt2cugDS2YrkXEnRVMLcnmnVURBAsa/YrzkhWSzyUu2aLMebOAZyngv+TNsp8Bs4wOP884PhhIgYErW7m264n2AzhPnXL4Ztigk2u1BMGgwnYZxyj/rTO+DAlkJjnYEs1pCu0n76MeudtuQFJUx+gLcBq7Xg3kIfnTTqCFvP9oSAEwKrhaGmIhXK+9O4/zmA0Ti54MOFwCMq4antvwJgbp/jRpXMHCZWU1biMdlle3tk1+o60kGd+qeHGJSk3EdRLTYmwTIemoCRjrDcEZiFQ/excJcZq5yNBy7n09KD+zJo0oMP8dipdwMgxxEcTQc7v0wIUcJsFIGio9WUPhQUPVFSAhpxkzIradlEWjzMIkXQTOklDtqlni079pTjFhXfjMUOD+bt6yxb G6LTzNyo xCscO4ImXdfD//djoivcenmeOD+eCH2PZvJ2J6T3ZLm50buI3bJEV/tIQcXiRgogEYCBL7H9LabJM9KoasNSd8QYNaJJAhzGTrd2yoq4Z0fyIgFDYFJ0fyim8wfezug55mAnqf5MgMvv2cubTDpflFcUMvRwROr5N5Bf6h55W+aDtpuQb2tkMw3ehFu9SfS2DkmDw5hTGMrEIrEsgt4nukC9aC852Q/SxUZpLy8mbQTWmNjgc65ioKvEqI0x48UYwRSW2wBnVeuQ9LeAToriqPZsy7mm8IYu0t1ZPCDgknPzBhSPM7VIWspFxUou+oDUD6dGhzQh2cNXbqCIVu9U5JXKjOvNRuAaxfIsqtwjzU2FOeyJOzSEBiactVc6f+qWdhRmiD4vZRODIOccmlzGgFZ2Zdb4OB8nYPNCn 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: Use new APIs to dynamically allocate the nfs-acl shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/nfs/super.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 2284f749d892..072d82e1be06 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -129,11 +129,7 @@ static void nfs_ssc_unregister_ops(void) } #endif /* CONFIG_NFS_V4_2 */ -static struct shrinker acl_shrinker = { - .count_objects = nfs_access_cache_count, - .scan_objects = nfs_access_cache_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *acl_shrinker; /* * Register the NFS filesystems @@ -153,9 +149,17 @@ int __init register_nfs_fs(void) ret = nfs_register_sysctl(); if (ret < 0) goto error_2; - ret = register_shrinker(&acl_shrinker, "nfs-acl"); - if (ret < 0) + + acl_shrinker = shrinker_alloc(0, "nfs-acl"); + if (!acl_shrinker) goto error_3; + + acl_shrinker->count_objects = nfs_access_cache_count; + acl_shrinker->scan_objects = nfs_access_cache_scan; + acl_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(acl_shrinker); + #ifdef CONFIG_NFS_V4_2 nfs_ssc_register_ops(); #endif @@ -175,7 +179,7 @@ int __init register_nfs_fs(void) */ void __exit unregister_nfs_fs(void) { - unregister_shrinker(&acl_shrinker); + shrinker_free(acl_shrinker); nfs_unregister_sysctl(); unregister_nfs4_fs(); #ifdef CONFIG_NFS_V4_2 From patchwork Thu Jul 27 08:04:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329204 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 79F1AC001E0 for ; Thu, 27 Jul 2023 08:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A2446B0083; Thu, 27 Jul 2023 04:09:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1538F8D0001; Thu, 27 Jul 2023 04:09:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F36476B0088; Thu, 27 Jul 2023 04:09:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E5F936B0083 for ; Thu, 27 Jul 2023 04:09:07 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BC38E160FDE for ; Thu, 27 Jul 2023 08:09:07 +0000 (UTC) X-FDA: 81056666334.01.DC96007 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf06.hostedemail.com (Postfix) with ESMTP id E8233180009 for ; Thu, 27 Jul 2023 08:09:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=f78FOiI4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445346; a=rsa-sha256; cv=none; b=K92MMo2v/SFt0TzEJ5T/+FZ+n2wm1leWN87rkNVWEl7ybmQyv1u+TFTjdcDptXiratJspM c3mWTIbP7qHt6M1E/w3PUAoL2gVAQKeNWV3noacz6LcdkAxqSLSW28ANXp18bi5SMrbFCS mRgQ6Wsso9136ZY4g6r0OYGnpPCeY+4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=f78FOiI4; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1690445346; 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; b=QOORO1JrwZ6RyI11aWtA3vJVynOiqr+k1OB/QIXxhSeC/mAqCqfsUD7UxC6q6ubQDpo/9l 1Q+I8u/n7ovt79skVgtL4fJO8+scjkqhLLLS/5IjXD4gMnJs1l2ZXnNmtiArgxUEbW0En9 FP06ti7t2Vr/I0dKLjuhr8rCYj+j10E= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-682ae5d4184so170863b3a.1 for ; Thu, 27 Jul 2023 01:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445345; x=1691050145; 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; b=f78FOiI4CNId+Ml2PzU7mY1IxHereBLlHPf7s7X8Gy+u8ge3z2zcNtZJbXgkJ1G/QR Bypsj3Qfs4NqFk8L9OHPUra+lfok5RS+DDluwPHI9kxnAJLSgVKbtyU1LC00kLM6jzmr VkgjJJoznrUMJZqGeb8qVz0Juy94c4XL4Hr58JZjfVBDwwW2089Gloj9mnDr01+e3vie ATN8u6YkhMkKc+i92NbP56LSIJl/sZe4eRd/+9U9Zz62iXDekK8cKEfr5HTH0aUYxIkr BT13YNvigorKsMJZpm5Ugf1VrzOLWJZerOzcVEByhulhpkn1iKJBA5Dz0oLwz2cUXQdL iC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445345; x=1691050145; 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; b=M0/n7tlDk5SJTRMxFoMAu0h5buI//hJwKgUMmrTfu+5LqnYQgH2VTEp5z5Gc5QHrc+ yXRLl/cJt2HOTtnUL8KFDYPfCpEw7hKldAXpxpTrmPtLFu0AZm4XyI5UhBcf0fCb6zeJ ikzaC5BZAUV0b1xDIeCnntd5sv1kSozeQ0XoEs8tzU3zFfAd5FhUEsYfPnLBjDeBn38x DfJ2hDkfNVsEuCkZ4VhqkVqKzcwuBfUdKlDXibyo6wkg0ww/f59IEcbTFU2A1hu6sapZ 8keHmD/QFXuW6CHz5Wb7juU7KJFR682AYXyKAysPhbVTwbPbn9EREBU8WKxnwhWKtZoA XGlA== X-Gm-Message-State: ABy/qLYxPtQ5X9/dDi3DvN+gTigku5ADGGsUz23vuQlBXymq72stvUZW 4o2A7rMUjTIjFNmoy9iHV2Bxbw== X-Google-Smtp-Source: APBJJlFoKDsbKkERIQGnm+LFaFeLpxhRzI1EaDrRxfTAKZLr632PKwn78Yey2tH1KRLEMSWua5HIxg== X-Received: by 2002:a05:6a00:4a10:b0:686:b990:560f with SMTP id do16-20020a056a004a1000b00686b990560fmr4379620pfb.2.1690445344746; Thu, 27 Jul 2023 01:09:04 -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.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09:04 -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 16/49] nfsd: dynamically allocate the nfsd-filecache shrinker Date: Thu, 27 Jul 2023 16:04:29 +0800 Message-Id: <20230727080502.77895-17-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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E8233180009 X-Stat-Signature: dk3s96ckxhjpijduqh69a8euryu4o34s X-HE-Tag: 1690445345-12922 X-HE-Meta: U2FsdGVkX191jVr8UhUDEAqMRqD4gGtd+JLJVFf8zLHLA7kLLSMKo3dDTeXop4/5lPnr5ztq+xneDGMNOcKivJvSU8rKGmhMiOSXNLo/KUt3aXL5X57iGzOztI8TuCoQS/T+PGzdIbOeL6myiBasdCNanTpOxQEKIiwym5v0GIa+o6qO8jpKZl0YmhsLlFpSb2xMiMezx7pfa7lPiBMwvoC73MWNwO1vLyguIDViP0sXTmVNHDZ3vYb5ghCvmFLomkYX/I80PIaPkpNE0GzkHd3B5BqfWW9t3uFEz3Yz9qp/umtJ63c9Hl6aebjcFN73zs1K6e7XFpb6OEJKOkWIdFAphOUHy6XBUi/k7vY9cVhu9o1awiVm5N76o7iGqw99dx0sJ7wLY2PNlLuXaJ2J9k9POhxXk27OqOh2BH7oeAL+KvLM/gKMV8ewap183ITtTDvYLBM3a9PxWUzEbsI3JNnbUKsdOY8HubIJzDPA1ueVro2YOnN5NNf2C+D50ccZ+kisOMtTCwApBqvxBsRqapLGfJZe4YSXVGuD9llzpANbDKBRzzrGTtOAXvlbklvVk48YD1lxn7ox63pqyPYSiKL7z0+2asblAsgniNlRI+CEYmwfZyRFoJ96qBK1HcUpS6TIlAGnr4nUpgZ080f4GfNN+QNMQ+54SgEdUMDCMTjwMkVYxVe3lPig35GeKdJp//1094uO3Z5L6mgv4sad+AENgHaLZ0GVIi1xKU/QQ9oFltV/dp0eFB0rPk9UMw8MH0RvxFM/7UOp7jErlGqsRf+8Ph7/+KjzLnFCrLq/j4s10qZJ8jvcbfk6mLqldliGfqbhOHXKoRNq8bhTgWNmmJ97nCc8UPD5hR3vAQQEVJYE1JJvcHMJaZfL9ktQGqAOW3jL5Jxd0tcOM8gh06rKWa+Fh+ucZiAGrz4UQfSA+bOCdnfPLVyAY2L9uBVlQZms7uJWlptDvcP6SuSrRS6 JM0pxdF/ lu0a+9vArWaGHZyQw0kwlr1/Qw28srzGFL6y6Tv1+NasUf5SFw/C0oowkcqyAsDQSFUlSg6X3l/EqmZBQ8Qqeke0fOUurCAZIBlNq56zRBhJpsVYuZ5jI6IwdEWoZCAoFJG/OSOmSfLWfVwda0uoBTmZXGFEBrskBYNgK6z19kL9qM8Xr6YKBV5SX6kg2pzHQHPB8A5Yu3fN9r6yDMhp2NKImZ/sdI8HooX5KHfPIXbs4CxpfA6dUDWiXO3yZgQe/hXfNPwvCuKqJUvyVmP72Po/PBlgHiBLKK6EikGVo0zc3jvEzGG85iUagJiGMZgtBjcVgYDzl3ZO8N3lNRrnmex26lLFIOmNeiXr4/WvEjTBkVVv1ca6MsFgXfSKeMQWb6Zbv3ZyUT+N7Q0fCilnJvj6Ln+Z3HCLWXOAR 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: Use new APIs to dynamically allocate the nfsd-filecache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/nfsd/filecache.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ee9c923192e0..872eb9501965 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -521,11 +521,7 @@ nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) return ret; } -static struct shrinker nfsd_file_shrinker = { - .scan_objects = nfsd_file_lru_scan, - .count_objects = nfsd_file_lru_count, - .seeks = 1, -}; +static struct shrinker *nfsd_file_shrinker; /** * nfsd_file_cond_queue - conditionally unhash and queue a nfsd_file @@ -746,12 +742,18 @@ nfsd_file_cache_init(void) goto out_err; } - ret = register_shrinker(&nfsd_file_shrinker, "nfsd-filecache"); - if (ret) { - pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret); + nfsd_file_shrinker = shrinker_alloc(0, "nfsd-filecache"); + if (!nfsd_file_shrinker) { + pr_err("nfsd: failed to allocate nfsd_file_shrinker\n"); goto out_lru; } + nfsd_file_shrinker->count_objects = nfsd_file_lru_count; + nfsd_file_shrinker->scan_objects = nfsd_file_lru_scan; + nfsd_file_shrinker->seeks = 1; + + shrinker_register(nfsd_file_shrinker); + ret = lease_register_notifier(&nfsd_file_lease_notifier); if (ret) { pr_err("nfsd: unable to register lease notifier: %d\n", ret); @@ -774,7 +776,7 @@ nfsd_file_cache_init(void) out_notifier: lease_unregister_notifier(&nfsd_file_lease_notifier); out_shrinker: - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); out_lru: list_lru_destroy(&nfsd_file_lru); out_err: @@ -891,7 +893,7 @@ nfsd_file_cache_shutdown(void) return; lease_unregister_notifier(&nfsd_file_lease_notifier); - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); /* * make sure all callers of nfsd_file_lru_cb are done before * calling nfsd_file_cache_purge From patchwork Thu Jul 27 08:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329205 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 A7EFCC001E0 for ; Thu, 27 Jul 2023 08:09:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43BA46B0085; Thu, 27 Jul 2023 04:09:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EAD96B0087; Thu, 27 Jul 2023 04:09:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28BC06B0088; Thu, 27 Jul 2023 04:09:20 -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 1CC0D6B0085 for ; Thu, 27 Jul 2023 04:09:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C1EF3140829 for ; Thu, 27 Jul 2023 08:09:19 +0000 (UTC) X-FDA: 81056666838.15.3AEDA89 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf24.hostedemail.com (Postfix) with ESMTP id D7C19180015 for ; Thu, 27 Jul 2023 08:09:17 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WprFfHhw; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1690445357; 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=1//FAyntSoVVhHGcFkYF5rOUv8OYZDaOr/FI52lXs1g=; b=5wCFVeteb8nvky7Y62IQTbIbbbBz7ve2/fAH/QrRefTdI8Lqbhg7UPKCx4+VIJkIpZNB+N +42rLyQvxg2mqRhVNnrDIZW7svtFlniRtPVU80myqT+DlaNvuH7rLAkQIUUgm9LZPYF54n znDBiAswNIMfPH36ojb5R6dzTeA8LTw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WprFfHhw; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445357; a=rsa-sha256; cv=none; b=vIGFl5Kf+tgKyAQZiB6NsZHmwOq9bFmeTd7QwEK1jPIWZNwzNcRCI4xJUre7ECPPNGgyia 6zNgjtCvawYKqLLbgGaaOK8NCE61MBcbSFtFKS2Cudd9ueqF2TiE+KGSNWCdlsngiNZBTu GJYTn+RFH/1Ygfn7r5/ItInZgXjmdww= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-686f6231bdeso112891b3a.1 for ; Thu, 27 Jul 2023 01:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445357; x=1691050157; 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=1//FAyntSoVVhHGcFkYF5rOUv8OYZDaOr/FI52lXs1g=; b=WprFfHhwxvgCbIOGEhvz/77THpnE+uaWMbMuLLIIDpVeL3Jz2616v8wLFkzo7HZvSd TNFFTtJffBxh3fLTgZ0hA52iTzwFJ1lb7YC8GT96AcRGLEmRK6UnsPg5TF0WeT/gBbXI n3D8mngVfbe3MYXC32UZAJFJiGuaHBVIWM9CunOWIYu990kGDPAj43N4rpm3m8rpgsHd 02xW2JacWcelFq3TAnDCLUfDJo66VYYZvDcSFvyxJpg5YwEtAXcJf/FphGWJu7IrCr2v NhF0NyS2ftTWJJ0Gd6+a6tHW0SZpG4hIgkFC42XLIYM9ZEOFnWGm8ZzCwBndTMQ8KaY8 M1zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445357; x=1691050157; 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=1//FAyntSoVVhHGcFkYF5rOUv8OYZDaOr/FI52lXs1g=; b=SvkvWdAmOU1AEDO5omEPBQO5J3wZln6L16xcmjOCYyVD4N6mWopq6tk57BmMG8MO+Y zKBYU41gzgcJf/OV9ElXnMcDUKXmxLCCrd83uMfF4dt4fFyCi+9hDp7bzWiI9eJ4nLKo cArTZn7zoq2g+4VkefbQlFF7+T1/yXZsywO7ISrUVh+z8h3v09QbFaCbJjWBM1Lt+XzX J2ogbg/XwvYbA2s00OqnEe+1Z6tB9XBsvWnDmlIIi+RWfzbaBcQnSC5MbhA7oGUvDwvs O1bmz9ppPele9j0B/P6FEx3vk8fx68da6vzZJaAQ8V+Gx11Ln4mzbbbiNwOzw0ns6DBC uuEA== X-Gm-Message-State: ABy/qLYpWWz/TOBKFSeUpaGR9+6GqscnfR0k/EzlPiCPAFFxhqdsQZPk a1bv/6qLu0BUQNoD9FqU5Xsveg== X-Google-Smtp-Source: APBJJlHvmYnqUEfQMupLlQUSLLnEPxVICkIYSDMBUwnFYoQAuRxCEO7ekKLA8kJr4NX0LnRrY6UJ3A== X-Received: by 2002:a05:6a00:13a3:b0:676:2a5c:7bc5 with SMTP id t35-20020a056a0013a300b006762a5c7bc5mr5229938pfg.1.1690445356761; Thu, 27 Jul 2023 01:09:16 -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.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09:16 -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 17/49] quota: dynamically allocate the dquota-cache shrinker Date: Thu, 27 Jul 2023 16:04:30 +0800 Message-Id: <20230727080502.77895-18-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 X-Rspamd-Queue-Id: D7C19180015 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 5npgyewmf8q1wbot3eqxi175k9sy7j5y X-HE-Tag: 1690445357-163306 X-HE-Meta: U2FsdGVkX19UXRpRIp4c2vSm8+Kdqz1dDS7g+g4lnj4Wy9Z3e95BZwi7277xI3FCFUWMZhhkhQzGgumbWt2kw6XWLGpGLZeweO3bnTvP9DY8Ouvl7iZN7HZGjJe6FdJs55KUvspVG5hDPX+mWO6lhnCWHOLcWPdlsahqdFrRxWXFvyrthc4sf8uj2+kch1vgNEYHF2UR/3iwlX+Qfz+PGqDbKQ2rz8vQr5Esa3GgMe0GyOeGoQ4q3bBfYY9uFd5Wzom1Qp5F3/lzuaT6yxgeBONFxnpWzmIDikBjpFTHghdrgbLUX94siaCK1uBwagjlhkdUmtxoBdlErzNPPa82Q45E0jKsud+IgjGji5qxclis4ccNJVp6P6ck0zKdbWmxJrhk+vhAnql4ZEuuiR33VWPq3Q6NRkuNp+TczwY1aD19DJ/rM0RbzwvwJa3TrNzoCR/Xvz4i4gu2Zd7m5Og2QGbsh8ZyppSlblys5NXsNIDcx3AeuyVbQongumC5QVkZ4i13azZf9OanMhz5bMp8mb0D+SRsMM53GOHQxJ4BJU4Bgil2eEfShYE1I5NhSI9mYEpJjMiwd0yPmWOSr7P+tvac0gq9E7/SCSogBJTFSLqaqiVTxICF8Q/6KuN8YCzJiB5suCBhZ8L2rRqBmhrl94Js+upYSBbJ1SONmsiUT/SN9j3iHiC/ysgXIcLj3zPYhFd6qO8ASzynt5Vx4EBoeOJRBfW9RDrw6WyvUistnwoE+LHuA2Yg18Mwk9O+o9fuAc2XkQQouRoAfdctkMWP9kH/Yw74fEG2QTIKxFQo+QqfjLwJFQ7ac/RW81Q3bfurt/S75n2TdR3IQ1eKCw6XspWxTUTeeP4Vi7QykSg1etA4jPykOsO4vPfbhYarWrIJLXFvfskAh+tK1SP9EFQlnqaOEDPynjdV3V4Burf5YqWyPxCv4v33fHJ79XkbAYLwBW1sBw7ZGXTw042AzlA +qqpS9Nq 3aQXkzobmeuVmmQ6zekAjM8GjOxjmd6hRmTOyD4cQv9dnTfalpYwzDlNmOOLn+Z7c3e5CpuxH/gacjwpExnj6loYJcclnG4RyFxGKrn/F/t/i6dBsEbIiGJOeVTito4mWHCFTjpKjiB4/BAlKFZXb9Ux6PUHBUNogfrxAWCG1LVLvGiIAOLC39V+V4NMPiqioWERHMi1/tAQdPBlt5lMXP+xoOAnXCk8FM63Xcl29ueyCfwuKK13SWb2JqGRp94YcJ1zz1Zv28bMRmRr+h9mgqFNVOQok+0sFhY35LUY6cnHW351gDi81p+Rf4htfA1c1jTP/JAXmYVMg+YdZ1JJ1+/csJkrWuCyVmMChZhss9+vGqDkG9TeKaCBYnTwnvh0BkBauqVrZZFTa/qgzN2VO9Hd4P26ku9LBelIh 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: Use new APIs to dynamically allocate the dquota-cache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/quota/dquot.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index e8232242dd34..8883e6992f7c 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -791,12 +791,6 @@ dqcache_shrink_count(struct shrinker *shrink, struct shrink_control *sc) percpu_counter_read_positive(&dqstats.counter[DQST_FREE_DQUOTS])); } -static struct shrinker dqcache_shrinker = { - .count_objects = dqcache_shrink_count, - .scan_objects = dqcache_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; - /* * Safely release dquot and put reference to dquot. */ @@ -2957,6 +2951,7 @@ static int __init dquot_init(void) { int i, ret; unsigned long nr_hash, order; + struct shrinker *dqcache_shrinker; printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__); @@ -2991,8 +2986,15 @@ static int __init dquot_init(void) pr_info("VFS: Dquot-cache hash table entries: %ld (order %ld," " %ld bytes)\n", nr_hash, order, (PAGE_SIZE << order)); - if (register_shrinker(&dqcache_shrinker, "dquota-cache")) - panic("Cannot register dquot shrinker"); + dqcache_shrinker = shrinker_alloc(0, "dquota-cache"); + if (!dqcache_shrinker) + panic("Cannot allocate dquot shrinker"); + + dqcache_shrinker->count_objects = dqcache_shrink_count; + dqcache_shrinker->scan_objects = dqcache_shrink_scan; + dqcache_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(dqcache_shrinker); return 0; } From patchwork Thu Jul 27 08:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329206 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 28BE1C0015E for ; Thu, 27 Jul 2023 08:09:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C03026B0087; Thu, 27 Jul 2023 04:09:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB32D6B0088; Thu, 27 Jul 2023 04:09:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A54006B0089; Thu, 27 Jul 2023 04:09:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 994C36B0087 for ; Thu, 27 Jul 2023 04:09:32 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6945FA0426 for ; Thu, 27 Jul 2023 08:09:32 +0000 (UTC) X-FDA: 81056667384.12.9230793 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf04.hostedemail.com (Postfix) with ESMTP id 99D9C40013 for ; Thu, 27 Jul 2023 08:09:30 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZArGb8yz; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 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=1690445370; 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=et7oKjMo2RpAm9eGe6PO8KzXkO6yMET8jj6KuxhxE1o=; b=CLaKjfwoY9auLMKeAFJvUN5QLyoZAQrJObwfWLRzMAr6wluX14L8TH6l2Jq9eWOCcR7Ova K+3VQBJjE/cEZK9XXbGSg984pekx8mMvLvEDxc0vMMa+o5PGeaVJfKoJKcV2bfxy9Cu0bI IpzZ2jfuMyLGUcEPmYMu5Wtx0xg0uNE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445370; a=rsa-sha256; cv=none; b=ZwqX2WBB8PdM4yXnvyDmylqlK25/evWTp5Ok1GoOGbl/NFuQXXMbNlpD+eR+NNZs/YNk8q A7GNI4CCoXAe6j0FwcFFodisO5Bk6//BvudVf+digU8pfILtSa/UOAx3J+0N6zTLWwxJma wk3j81IsPvWOC/MIaG0FTkpaUUOKlO4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZArGb8yz; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-682b1768a0bso174996b3a.0 for ; Thu, 27 Jul 2023 01:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445369; x=1691050169; 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=et7oKjMo2RpAm9eGe6PO8KzXkO6yMET8jj6KuxhxE1o=; b=ZArGb8yz+8ycxhYpd3TfnObsbskAktwxKp/LK6E+gx1lOsm2QqxHLjO1qFt766mx4G 4UOFzMb5rOBT3wq7QpcOo/50dqnABPqLouzBdNx69dJP3kndLHofbdJgcQSOE87tIEP3 gOFIB0th/ApJ4utKzdT3r6irRm20AGsjylo629bfexLkXBuL+hMcZdtnwSmPAtxRA7F8 l3r/R789CkvCTacsaPitu2Mn9fHBZCoAT7Xd7Py97lY3Lp4c0X3H7O8uSS1JwsanI4Cy Pf3LZprk/pnZjQej6Xzx3T3CJ+QGRGxZd7LUmSV8XGImv+0X4BPv+EIagOcfGqekhivR Bv+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445369; x=1691050169; 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=et7oKjMo2RpAm9eGe6PO8KzXkO6yMET8jj6KuxhxE1o=; b=OBYCGglXLlvolxS6yqE+AJroepl/u9rRhFMjwlL01G5ZUi7o6YehkBgYRwNK3AQ59R 2wz292YwqBLKs2923Ra4eElDgL/vH+e+vh5pqWbR/dj7cXX4qhjKnDfGalfS3JrHwo8W 05ATm8WrSNWmlCb06jOSdiCaSlRRo/zMGDMa32bmsfCO8EAI1kLhX+gIaR4Ahtjk/uGA lckm7qbHb6Hm4zAPFVnTZ3S8JVIkH6Uc+3OGQFD8QMPAj1InbMr/2nlnmQLQQJCZzXv7 qZFG9GtJjfuDgfgeUN7aBFtbEwQyVyw2HsSFaAU23Jd1qw2YCxl8BVqtzUDMJZwOZRs9 UtLQ== X-Gm-Message-State: ABy/qLYoY52N1ZVz9TynP3rDwoaYJ02f3ZHqkBOEuZ5kmF7M7oUF9Hkb SEtCacwd9PPwmVXEI+4aQSXoVA== X-Google-Smtp-Source: APBJJlGUbAM65UTyBU06poLXl/mtaX6EX5YDf65AxeW9rsxnsdAR4xxA054nRzBMt6Eu4ihj5O0Oaw== X-Received: by 2002:a05:6a20:7da5:b0:137:3941:17b3 with SMTP id v37-20020a056a207da500b00137394117b3mr5573135pzj.6.1690445369382; Thu, 27 Jul 2023 01:09:29 -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.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09:28 -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 18/49] ubifs: dynamically allocate the ubifs-slab shrinker Date: Thu, 27 Jul 2023 16:04:31 +0800 Message-Id: <20230727080502.77895-19-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 X-Rspamd-Queue-Id: 99D9C40013 X-Rspam-User: X-Stat-Signature: 96g736uufj5es4k51b9zazeai5nyt6hm X-Rspamd-Server: rspam03 X-HE-Tag: 1690445370-145358 X-HE-Meta: U2FsdGVkX19u9B0IQEQcOniYkF2Np1IXZ0RyadPU+sUl0fsxobZvplqJwPTgS550fa4wLzEhFG09+GlnrNEgNW68DcE7MgVL/AUnRgyEUShubzPIRCWLCpEKAAFq+gON3uezLlK8mGNznZ2Hx+U9oB3RfQVbRCyDpt1MBRoIulHOldTgBKp/pkYarbghHE9SlDzt5s1MypmoK+eOIahbWQwQ4OKtmvRaTQVuNXG7q8Tneo51jE8Qb71SKgBYtgMVBLRxSnAPFKjw5XqWNytTtScDK4jg5RZbIC1ejQvd/0fiXyet4nroVE3RDsI5XbZ5xnZbAqbtc/UC2tRgz5yl30jzmGwTHNwY7Z1xudcgOplzTqaTcIxXLlLwMPK6a0VroPONfO4wsYSUSKQh3/TU1DOioCKkj2W+HAUSbIUibNiYQLqlnts1hpRZ7++nuCHpZ6mXNGIvh/IK8iN42Nbu2gB9TojjopJlHMutMbF9K30NR/bk6DV/gCD3Pybn0LLCatvyL/Kol7vfl37L3TShpvbhS8jqjAgxxJFCQcGlshR+BY+e3usJIxnwOXRUztXLdalpbZC3jxH696/3YhDbTfLWQyBaSdvYV0oogHCipX4DSw0iZJCoESR9IYvNfS4RMABbK0VJljn7YAvhw2K7os2uBvimUVXJ0wiPslm1rY0/xIyRTi6Ptakmgj6QXLcIJrH7/u54z3daPLXUWOjhvzheMd5Cs6xuWqsFuicAc4yyrfyv8XrlO9gnFSzFc898+Jo+K4jYM8dK2wHuC82ji/X1ktuLksBMfZPZtpG0PjLCQVEmf+Xl5QaMdsGfQUzpe55Dgkgeucma2F/re+kpEMK8ThzUD5X4zVUoS7SvyF6q9MdrlV81qPU+I6kmB8jH9bmsqQ8ZB+WXTj98e4MibRnDwlfeIoIJEFVCVLBl4GlN8jdXqCpl4kYO0DTS4w49Tj8OeU5XPUiLdx8ymrj sS4O53V6 vCWYZ7rMVHkzy1lr2h51hlerg++lhwplmifWFaarPEQoYdoFvoMM7UpuzuJqNr8AEq56pG34v0ey6hsxhszWLaLR5j5PR8GvD5gcz96o31F1MhGOytNBnSXbk10zrpzNTczWuSisuxpfWVGtqxsq5JfLDEl5pZBrnCYJxRf15n7oJOB0WVRMw8WY3n9HH8z0iySX3Xh+cCk2rQE0Dsb7Z5Y089z0AI2NUhFiBwgh5LPlqDU3sUg0TqjgQddcxoVow1QP84XHU1n8V6ShBz/DSb91PjfASVYJHWjiqXFw3SN+VLcDlGIUibjb5vEmpyzpYKEU/odI2PcvDP2iD10GLt0owbGcwmETUT889G9K2oNPiUUmzypr8TgOStA0uN3593AVzY4sHa8Ilw4Wjq2n/QSbpL2H+K+GLyuu1 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: Use new APIs to dynamically allocate the ubifs-slab shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/ubifs/super.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index b08fb28d16b5..c690782388a8 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -54,11 +54,7 @@ module_param_cb(default_version, &ubifs_default_version_ops, &ubifs_default_vers static struct kmem_cache *ubifs_inode_slab; /* UBIFS TNC shrinker description */ -static struct shrinker ubifs_shrinker_info = { - .scan_objects = ubifs_shrink_scan, - .count_objects = ubifs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *ubifs_shrinker_info; /** * validate_inode - validate inode. @@ -2373,7 +2369,7 @@ static void inode_slab_ctor(void *obj) static int __init ubifs_init(void) { - int err; + int err = -ENOMEM; BUILD_BUG_ON(sizeof(struct ubifs_ch) != 24); @@ -2439,10 +2435,16 @@ static int __init ubifs_init(void) if (!ubifs_inode_slab) return -ENOMEM; - err = register_shrinker(&ubifs_shrinker_info, "ubifs-slab"); - if (err) + ubifs_shrinker_info = shrinker_alloc(0, "ubifs-slab"); + if (!ubifs_shrinker_info) goto out_slab; + ubifs_shrinker_info->count_objects = ubifs_shrink_count; + ubifs_shrinker_info->scan_objects = ubifs_shrink_scan; + ubifs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(ubifs_shrinker_info); + err = ubifs_compressors_init(); if (err) goto out_shrinker; @@ -2467,7 +2469,7 @@ static int __init ubifs_init(void) dbg_debugfs_exit(); ubifs_compressors_exit(); out_shrinker: - unregister_shrinker(&ubifs_shrinker_info); + shrinker_free(ubifs_shrinker_info); out_slab: kmem_cache_destroy(ubifs_inode_slab); return err; @@ -2483,7 +2485,7 @@ static void __exit ubifs_exit(void) dbg_debugfs_exit(); ubifs_sysfs_exit(); ubifs_compressors_exit(); - unregister_shrinker(&ubifs_shrinker_info); + shrinker_free(ubifs_shrinker_info); /* * Make sure all delayed rcu free inodes are flushed before we From patchwork Thu Jul 27 08:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329207 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 3EC8EC04E69 for ; Thu, 27 Jul 2023 08:09:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8A276B0088; Thu, 27 Jul 2023 04:09:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D60D96B0089; Thu, 27 Jul 2023 04:09:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C50648D0001; Thu, 27 Jul 2023 04:09:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B6C706B0088 for ; Thu, 27 Jul 2023 04:09:44 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 98B0C1CA08F for ; Thu, 27 Jul 2023 08:09:44 +0000 (UTC) X-FDA: 81056667888.05.4BCFD1A Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf26.hostedemail.com (Postfix) with ESMTP id B96DC140014 for ; Thu, 27 Jul 2023 08:09:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Uigp99md; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 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=1690445382; 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=GSWsN00ewH1CUxuL2on0amogNZtYjpfZMPk3tXk1MLc=; b=HswIQgnC7NtPBM4meMLx/HOvD+o6Atl5fkCDur9HXpsze3LV+kDhtThZPUpO7Z7hN/SKOW e405UYg5ZnD8vS76Pkhp1Lzz9GeyPOgZ37KV7r7r2j2fRIERfqNgZyGYq5tRhQQUIaaEXX MqbBts8jFtoJ5hrl166DOIcqqjJzy9g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445382; a=rsa-sha256; cv=none; b=esKkcQIM+uzwtiCLR65gig5wop9HnzQsr57Vd/5gKVtAm1lLAQylWsKYFsmgYTpzQCpKm3 gDmzUAtoPkDYLFGko9emMLfd2Aa9j2euaVtZ6xB0HRIB4IBbbNqjgmBi0ZEi9PcqBO7+Rs SuC7rZ+9wpgQq1JiblxmnJYqSFY+7xs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Uigp99md; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so167939b3a.0 for ; Thu, 27 Jul 2023 01:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445381; x=1691050181; 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=GSWsN00ewH1CUxuL2on0amogNZtYjpfZMPk3tXk1MLc=; b=Uigp99md2Rr3CXBoApAa/OORnqo8B1J7RivQ80kk84PuD/8/0U/wiHIiPqvPSjzBq+ 4mgkiCdsVsAk9/e2muldWgdoE75BspngFHkVey9mAlq6MnrgeN5Z2UVnZxuIj86jdS6R rAWjfbsFjXDEfm8YOidjdqca7DNptBkelH0HrT7nXcdFtSlvKmDtxqUQOqWjbYzyZulg AN7Mzxd848XhJE6ClueXrvuJZWX5X85+XT80LyTl5276AdX2DnTvKQaDsxfVQAKr1XxX WaB1fRqts+Skr4BpFNBdK0X00kCFzaVEUe4nziyxeBmy6RtpnTKoOQLFGVCxxQosoZyC 4x+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445381; x=1691050181; 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=GSWsN00ewH1CUxuL2on0amogNZtYjpfZMPk3tXk1MLc=; b=hePOTSpT6bTO4g6EGuHGQuo38w4Ogn5A5w9xthkEezoEw/H72+Xo8L+V81mJRZny2d vqxyLeAmcgivFGhmn0QbbjHWQfXIP6IbQxddLC67rhGtcvxuSMjJwJHOoJhxa+Y1RaJ5 Ae/tD3Pho37SRMgVTcsZhENcafYxyYUc4fYulVZMTX07bYgIjuyX2Bxl2tCXVpck4C4E G8SLgwJyPd9gIBQJsuQKELb+NNyrkkD05EUO1lYvVksLhSvsOMmsvzgnVUVYcDJed2k7 NHDZbnwVTFB52X1hT7mhYQeUjGuFcybuGCX2Nj4rqbfkmkrbTy7Uj94apsSPiRn6uB14 lmig== X-Gm-Message-State: ABy/qLY6vFmZg2K0JclflUR/2SU0m5Tz57AITQGAq9ENuAHNoJBbyu4p duXkL3XrWbgZIhHjxqT3hcsxfg== X-Google-Smtp-Source: APBJJlHVjyqYSo1ak3Z7chV1yhtxMPzG2+b/e8BLYdWQhXdIbtZlkhi04HlfYJAG9z5TWY/X++2RBQ== X-Received: by 2002:a05:6a20:729a:b0:100:b92b:e8be with SMTP id o26-20020a056a20729a00b00100b92be8bemr5576237pzk.2.1690445381598; Thu, 27 Jul 2023 01:09:41 -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.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09: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 Subject: [PATCH v3 19/49] rcu: dynamically allocate the rcu-lazy shrinker Date: Thu, 27 Jul 2023 16:04:32 +0800 Message-Id: <20230727080502.77895-20-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 X-Rspamd-Queue-Id: B96DC140014 X-Rspam-User: X-Stat-Signature: 9gr9og8j8aksr1r7xujj8pxo5iwfbw3s X-Rspamd-Server: rspam03 X-HE-Tag: 1690445382-567314 X-HE-Meta: U2FsdGVkX1+ZN+hYfMcl3hGo8C9wU9f6lcXMYHLiDa22NYyPMTllyDdLbO5UpdZGO6uMSOtKBex40aI0hACEb+g+UjOX8bwEYXuD1RYbJ/MHDcQkIFZw00BugnwenSGJ5vzNBuoavOrEVc/vRlqz9Rwj6U2YJLMvG1qrlA3njS5MesGdZLijVX7weFpvnO4jklDvcFL5DA7xuriHQidoslF3kyqSfN+7HGDT9n9GPfjNXzNrOQmyVuF7s1zcc5+D/7MNxO7EzHGm6RjDtB1uu447oBWzaZNa1xzIvzYx9xdt6+OX2DZIdOnLojw1gJ3LzyQzqjU/6Ua6fux3N/JvCHJAP3RvX8ogEC05a+x6HVzKdlBQETcVW+Sle0K4e4ves8mXk0iiUrSYISNQiiUBwJgK68fdbeJxUB4ajWZKcQr3Mc66xT62kyoSd7z4My8BF+t8w9D9UlxXMOqphZb7n6yJbYQWxGkibK8YthpmNXTpS/cpoOWOOy7U/Uf6Ff7XqId22Cl65nBewKLcI+V2BOuKfbwKnyq1k8Oaw+sM9dezewrAQ9ze+03yosKMsWmWXimJJqRXU2YkMwJ7qvYm/ZfR9AsWsCgTDMO4rtYlC9bsG71al1OcXr0HbVddn+VmXwNLBLkU0IA497xrxXala47vBi+RGvaHs+i8O0YQGHnP93eafKkUARWJTILKS6QYHdLpA9w/upGaQGzX3v71Z3vlV5Zj/nI7rw8Ab8IZ2uFQZW4Hi3h0gMASylCPIBdY73uWN9pKmh8RASgutuoS/id9R/N47YlpTnyBt+Z0p7m93jj+OerJB37e0plhMYvSSs+RxC4BAWoDW62EJkpTOBD9uuURqvpfRR2tBVjF/cnK0bP23f48iqX+KYZGwa6OJbqPpx/sicrDAkbroplvsbR+Ej7MsxMaJm2GOAxPR3AmUfu66YGeymWloR1yGuJiNooUpst2T/lRGhC5llK ZAvirMc+ SyNPF/ELkRRBLQKVo0D0PwOrDPegGS1ou1PI//rZT+sr2zrbPkmeMxOTrKuFMRjTF8l1D9E126kkOUytA0fQeO0KDFXBbiiroda1R+im/hcmw59KpWTOX1ZrvWvUAPQq4/h7GA29+b3+oyz+pvySh3TN6Km0jM0tR1Tot/5JrGmcw5OlYa6t7krqZfES7Qzk2A8jlePQC2suBzVm6xks52y8ZqY3n1uIahDVghVhAfrgsz2cU9mgnEGTUs172AM1sTP/ErWW9AZuG5bjLcce5GYDniqBrEWkKCoAC3o04EjtrrkxvEGb462B5M7SV8iWt7dv4VyqIwA6fUX1e+5SFuUdcL5hm89OcsG2SWbeKHALi40fZka2DAgf2AOq5++swUYEJi0oXManTTt/M/OyuVQdILCXz7S03ArvF 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: Use new APIs to dynamically allocate the rcu-lazy shrinker. Signed-off-by: Qi Zheng --- kernel/rcu/tree_nocb.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 5598212d1f27..e1c59c33738a 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -1396,13 +1396,6 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return count ? count : SHRINK_STOP; } - -static struct shrinker lazy_rcu_shrinker = { - .count_objects = lazy_rcu_shrink_count, - .scan_objects = lazy_rcu_shrink_scan, - .batch = 0, - .seeks = DEFAULT_SEEKS, -}; #endif // #ifdef CONFIG_RCU_LAZY void __init rcu_init_nohz(void) @@ -1410,6 +1403,7 @@ void __init rcu_init_nohz(void) int cpu; struct rcu_data *rdp; const struct cpumask *cpumask = NULL; + struct shrinker * __maybe_unused lazy_rcu_shrinker; #if defined(CONFIG_NO_HZ_FULL) if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) @@ -1436,8 +1430,16 @@ void __init rcu_init_nohz(void) return; #ifdef CONFIG_RCU_LAZY - if (register_shrinker(&lazy_rcu_shrinker, "rcu-lazy")) - pr_err("Failed to register lazy_rcu shrinker!\n"); + lazy_rcu_shrinker = shrinker_alloc(0, "rcu-lazy"); + if (!lazy_rcu_shrinker) { + pr_err("Failed to allocate lazy_rcu shrinker!\n"); + } else { + lazy_rcu_shrinker->count_objects = lazy_rcu_shrink_count; + lazy_rcu_shrinker->scan_objects = lazy_rcu_shrink_scan; + lazy_rcu_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(lazy_rcu_shrinker); + } #endif // #ifdef CONFIG_RCU_LAZY if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) { From patchwork Thu Jul 27 08:04:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329208 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 37CA5C001E0 for ; Thu, 27 Jul 2023 08:09:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3B836B0089; Thu, 27 Jul 2023 04:09:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEBD76B008A; Thu, 27 Jul 2023 04:09:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8CCE6B008C; Thu, 27 Jul 2023 04:09:56 -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 AA85D6B0089 for ; Thu, 27 Jul 2023 04:09:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7FA1D160FEB for ; Thu, 27 Jul 2023 08:09:56 +0000 (UTC) X-FDA: 81056668392.18.0E63D1C Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf21.hostedemail.com (Postfix) with ESMTP id A0AE81C0012 for ; Thu, 27 Jul 2023 08:09:54 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ws66ywmi; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 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=1690445394; 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=YHU8OaKZwBmHAPsd+ulZSL5GxfVyMtJ49ZlHBntG+/k=; b=pUzfTHYlR0mXaquL703Pn97wyRDLfe8oJ/GCBh6EbDsMZULMc75aabBqlr7fzpe/R/8ivH X1uvwhGTd6JdT1KX2LMLHHTkZwyP9sJB0+TuHF+VJYSIzKZOWNSC/skZucT5u3nScJM8dV 72xpMC8HrNlOKVgq9UMf0iVuG+Ph24Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ws66ywmi; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445394; a=rsa-sha256; cv=none; b=5SFGoYfkTK1IDmyN9d+01h7Co9AGFIhIu3KbD2clpiW+pycg/8cCRjV5LD+Hdu38Dg/OIo 3JpvU5xrfLsMn+ftk8e5FICafFxfVgHkcfcGqvtUa2Yifo7nBcI6QvFxDvJpYKFnnVRoJR e4EpYY0bLHKPhbQla64SzdFYSGpp1n0= Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-682eef7d752so204032b3a.0 for ; Thu, 27 Jul 2023 01:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445393; x=1691050193; 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=YHU8OaKZwBmHAPsd+ulZSL5GxfVyMtJ49ZlHBntG+/k=; b=Ws66ywmifmcLi+WS7kmIq1OGsH1BFTj57lSknLEKHfbjZoq0FCk32P7hFix2O77y/C 4VExY7boGbko1TLXa8rf04m6+c8ScNg+Ye07GBCAr/bT75kG0yI8bdxHraEPkF+rcUYR 8BmftTtO1b4i7ZeslsgPT7KHdxn3xY8ziOGXEmWj+FzniwFS8tNvAxdGJbvq/4djXF38 gQDVTQD96XEDgWvn9v9d4yLEL0qbZzBxPnvHBbbs4StP2CGFCs0AHk/pzAfhLwFN3LYv MATNwQY8c4ti2yb34XlOR1fjl5eoQUN5qPDBlkMol6h4RrCuQdh3qGqhSkTUZQAnG9Jo zXhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445393; x=1691050193; 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=YHU8OaKZwBmHAPsd+ulZSL5GxfVyMtJ49ZlHBntG+/k=; b=bWPuIbmoaTlCPkwP3xDOqbb4yMPqhy9Gbyr+N1Qe3a4mbkghaFWYzQImxTdw3rfz5E Wz7e8X8IjDViKnScZcVgfbiCq0PyZoEVTUWduUZ9RgiVJY95QG3BI9ZPLbgboNErQ9KB Kki5j3reLljF/QUPQOLu+Rxoggq+ZRlwJ1rjR00W/cP27zX1ACqTVlLvyZpa4QPaHauB /IR1pxJqlru6TbPiBZKpMaksZYqpO9Hg2z1IAjg/sfstotwY7lJq5lyGtcQTIqYSBh9V ve1myGocuSDdFb1ox7YbWuw4Sx9j//bYoOM6SGGyscPPAPo+/dOFhcjK+LtPM+wbT9FH BIlQ== X-Gm-Message-State: ABy/qLbIfazQYs+LW4qKp0pQABGivAFEsTBwXsnK5zCdr5fbAqFvkcUD LAgAl/pg0nzh+g11qJDfNaFwzQ== X-Google-Smtp-Source: APBJJlFl46sZLt7x9x1yarGXcrDY9BzfubiI/ML/2A4f5iYMwILGEdxBDjTGuKdYIeQS2k9MfMDqhg== X-Received: by 2002:a05:6a00:4a0e:b0:677:3439:874a with SMTP id do14-20020a056a004a0e00b006773439874amr5199798pfb.3.1690445393467; Thu, 27 Jul 2023 01:09:53 -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.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09: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, 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 Subject: [PATCH v3 20/49] rcu: dynamically allocate the rcu-kfree shrinker Date: Thu, 27 Jul 2023 16:04:33 +0800 Message-Id: <20230727080502.77895-21-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 X-Rspamd-Queue-Id: A0AE81C0012 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: x4g5gwwcpseano4xs6n1g3necd587ffs X-HE-Tag: 1690445394-343728 X-HE-Meta: U2FsdGVkX19R7C9IM9DASGzMkMzX76xrwknX/0OtS00oq09Gz4OVRryxvkqCDpJdXy2NlHFUo9wv0qehZrrZao70cjlysM0nZiYuCxPE/ni8EN8bVK7Xm+1PPTAFZulpNrYLsL3x3wnPUURZ06keOKDDZVjSybP80wGYC034MmThaeKZ1fDn9aWSCLUBbidf9f22REU63UPE/ck0tyYcDSqV2B7yV2N3jmkwg4t3tNgPoMfgzA14S+wUBue2D10Ao5IkQhS/t5xWd5hO2xysj6mNynqE6hQrmzqJQvZtIGjx0swcaP+VpcAuZ4dU122axZxsaTjZWJMmA1QRA7sYeHS0rdsR9zlYKcGhcOAyYzyjokTpEBERNN6/6x2pkPOL/F/eoO/ySGOuKKGCh2ezKujnR1TGaMPAp/PGHYvzOmUk+7/HXfbvRxz3Ezy//CejbQYzxcD74pGGiGgzzb6c8aEyptOOiAbPPOYJVOlaF7E2KDUKkKyLkSHxSoh8oj6X59mTaq305V3IEwnULRotqdjJbTvo8Zv4Z0etUj+Ka4Sa9Uid+e6HfkCTR31rrZkW44oKGSj2GP3N7HTg0Lz0FC6MdnMFoq3SGHXEZcN9MQN+lh8L98gEvvt4b4H32GFDZrdrvnmbqy4TKk1VmKEylly51kUzmUJv7JanGnJO/vY8aUIvgIo/qg2AAPPC7N26N8K4+lN25q/vc8V0jqMqLdfcEHnukieUPfTbn7MORPzZmUA+VRjjgQSjY1FLxxuNxHRU5SF+43KSG0mI/fwdMB2AvFznsnaKvd9ooDM/cDJZTSfY3GdPvCvPhOs4JZm5Yl/5s/BAu7diDVdpt973Y5xBhKYNfWWV4dxeApsEmmb/1AmywywxOPm5HGi+hmFFXZKQbCvgnm42TkOVxT0MPMqVIN2yR9XBrrajrKPoGI8yBipldqhtwuMwEhleXj3WRdftrB5phy+b4IWONM6 cq60wqmt E4qgF1LC6a9+NQe3/O08UIEy5dMMuWvQ4BLix29BjiBCW27xs3rbpkec8Kk41FG/PozVu6ulHXgkUfX7C3XNZXWFgz2EFrWT0IaQxzu4rIPUeVyc/G9oEYx8AytRV/sedb+ySyvR13RdH6XVTvNZH4HlfSdOwF0ugmlcD2sj/RNBKaWlDIS2rM3KZamusr7dpH3NZWFeYUYi0H8BqkG4mR2lnt1s3AybhCW8/arwUi0S08kL7XCkqNe9XzrtbmYBMYP/jRpGEVKNkn/3SO/gjTHm+BVhqeqVilYZ78GPN+aN/NrTei4eSx7yzojXlbOA8fh/YtN7ZRSTifqhz2hWqHQVND8SCytTC7BHCOT/Qb2UxKR7Sx2RxdH/XjbOcsuXvPgjq+aXjGIzvrL2EcmrWv7kAjY3L/3nSTmo4hnz2gbv+JxC0GKOJ0KFKUy26QRA9quCS 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: Use new APIs to dynamically allocate the rcu-kfree shrinker. Signed-off-by: Qi Zheng --- kernel/rcu/tree.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..6d2f82f79c65 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3449,13 +3449,6 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return freed == 0 ? SHRINK_STOP : freed; } -static struct shrinker kfree_rcu_shrinker = { - .count_objects = kfree_rcu_shrink_count, - .scan_objects = kfree_rcu_shrink_scan, - .batch = 0, - .seeks = DEFAULT_SEEKS, -}; - void __init kfree_rcu_scheduler_running(void) { int cpu; @@ -4931,6 +4924,7 @@ static void __init kfree_rcu_batch_init(void) { int cpu; int i, j; + struct shrinker *kfree_rcu_shrinker; /* Clamp it to [0:100] seconds interval. */ if (rcu_delay_page_cache_fill_msec < 0 || @@ -4962,8 +4956,18 @@ static void __init kfree_rcu_batch_init(void) INIT_DELAYED_WORK(&krcp->page_cache_work, fill_page_cache_func); krcp->initialized = true; } - if (register_shrinker(&kfree_rcu_shrinker, "rcu-kfree")) - pr_err("Failed to register kfree_rcu() shrinker!\n"); + + kfree_rcu_shrinker = shrinker_alloc(0, "rcu-kfree"); + if (!kfree_rcu_shrinker) { + pr_err("Failed to allocate kfree_rcu() shrinker!\n"); + return; + } + + kfree_rcu_shrinker->count_objects = kfree_rcu_shrink_count; + kfree_rcu_shrinker->scan_objects = kfree_rcu_shrink_scan; + kfree_rcu_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(kfree_rcu_shrinker); } void __init rcu_init(void) From patchwork Thu Jul 27 08:04:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329209 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 4176EC0015E for ; Thu, 27 Jul 2023 08:10:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE2D96B008A; Thu, 27 Jul 2023 04:10:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D894E6B008C; Thu, 27 Jul 2023 04:10:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29686B0092; Thu, 27 Jul 2023 04:10:08 -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 B633F6B008A for ; Thu, 27 Jul 2023 04:10:08 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 92A991C91FF for ; Thu, 27 Jul 2023 08:10:08 +0000 (UTC) X-FDA: 81056668896.10.6838F03 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf10.hostedemail.com (Postfix) with ESMTP id A8A11C0006 for ; Thu, 27 Jul 2023 08:10:06 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NqYwP+7q; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445406; 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=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; b=YVXIVKLR9QcuNCrSE6umfoHhZ8O/kp6N3Ld2zPAMZ5bLWBDPMgcg+Hi9N7sJ8H7fRaowg/ +lJ4U6P63liW847sFoCDJ5kdzJxxo+3vM4M/zU2vSiQVVjX+mLUikdylaiWrZfrJ1NhQkg VvhykHWpXykDOQ03M+DJh1VZY0NTges= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NqYwP+7q; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445406; a=rsa-sha256; cv=none; b=z2O0dmW/zckdDCGA2kHDEERQFbn0IuEw4gXNpRw2afBUVwWJOGjAQ1ENtCN+d/uO+Z792R ZxW58mqo7w6IODPVLOF7UWwSS+PMQo65haH2V8a7h8z6d3yAiwPM91EWnZYOFdpaeXSgfJ t9rmmKhVgwMIai/jgPcoUecGx137V34= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6748a616e17so183058b3a.1 for ; Thu, 27 Jul 2023 01:10:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445405; x=1691050205; 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=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; b=NqYwP+7q26BX+05EQAE55Kus0VTZ4uDrn8hA+JsQeQZJT9fqe02P3PtEqTbWL+ex0x YIFFlprB9LN8XpWOyzBWvs6bF2o1el7zRiKvHm2Vd5z2Or8QA2PiX1E8ylBDH7Szeeh9 /iQcvqB1l/KdO3epgECrqpXSIR/s/RJamq92lbZYEsjapR5/FUExLIHgiZunap4eHVCx zA39TmQ89NL3AupWiP9iOshQQO6k89rLp1YMDCuDF8tqw1FNGVEm51b05cxcsW4A6ycO oxBBen2ORAG64Kh5EsfwftGMbRswk1n9HcylImCxbc9GAVmkCHyiC5Q0TKVbaeRFnqta TxEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445405; x=1691050205; 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=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; b=bZAkrOxsuPXglwqaF2EbAo9fmh5eM5sYm0oV4+IzyFtU25fxpyUoBQ9Ql8DkvfLmZq qzyWVjqJiIZ/H5lZkSJ0N4H37/LxeDVXndVCWPsc6CTzk+An8e1CyXk5mgJBZwOSTYpm aylhLEvtg+feJRV3PBFowgjUQQq/ASSByzzsg3qR89Hu668PSbFsKzCxDdOYT++9HJWh bH7jThmJRvWTbV1r5lsSd0TlcIMwcNq3WtmNh0ZpH6P+1zp6Hs6kIouSoyf42pbWOeNe HJ2YepkJuQcjwyUbdI+1d2LYzUQTJuc1CEy2Uiab76dfGbnRhd7DR9C/jt5n7BV/sZKU k5kw== X-Gm-Message-State: ABy/qLaR8+e0/xCuAxnAmNvh+Yc8JpjoNdvoBuh63tdemyH2kmJ7309z E5i9oOynVvylwPsI+NtFH6f8xA== X-Google-Smtp-Source: APBJJlGpZH0OiKzZvwM26WklEwoVdvnyU6bL6rc8uFjIqbOYU7fWKIX23eNXK117O9K5uschqUp2Jg== X-Received: by 2002:a05:6a00:4a83:b0:679:a1f1:a5f8 with SMTP id dr3-20020a056a004a8300b00679a1f1a5f8mr4623296pfb.3.1690445405268; Thu, 27 Jul 2023 01:10:05 -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.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10:04 -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 Subject: [PATCH v3 21/49] mm: thp: dynamically allocate the thp-related shrinkers Date: Thu, 27 Jul 2023 16:04:34 +0800 Message-Id: <20230727080502.77895-22-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 X-Rspamd-Queue-Id: A8A11C0006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: i9w569x7b7tqimfwsnt3y951x4t4h4bz X-HE-Tag: 1690445406-134454 X-HE-Meta: U2FsdGVkX19j6NbTFQJOl3eevFczU8qHKni9JW8U1dyXdS7WmAcb8o/0yjq1jBu/XVL0qK8oFfmDHB23zbSOaVt3UxaAI3QZmFomShbVycEU5iX/fqHbZnH5+DOw8+yasPE/QTqJ/w+GuKE7T3t/IORspt8V/zQM3xOQDM2foTuZVnylikLodgooFZ00UrVYX9giwk9qUsM28pS3b5s2FRrVBMGuNehtpoUTX5V/6px0ogoSzb+Jz8EUqM9cJYwoej4BIBm/qrvzUKMMgxRTiL4Ht4ox8R7v60f1FkFPJK+AZqbOr1WJoEt11tDvtctgT2I/Bv2nZyR1Dq2YtgQIPcIhb2376WaOpVTWjHfU947Hw8xdfRcVXKB05ZA2yuJUqNhwmw4HTfHchG4fsjYNBBcHHcNXsQcYxBudT5bhJDQpvPO927uilLjzVEIaLtZkW9enNOWuITCOfpR+rvADpkGbn8bpr53860Q2noQ60rKEsv8tQ4PIKr81qFckMbrgJvUvXYb2pci2VdbReutPKoIt8Cjwnc5qrVG/ThFIJeuiYevz4qDO7xSbACtP4gpzsHuIwpUxPfQTWu6zz6d79g8M9x4u8h4HAQZCzPiLeQyL6mx4ld9Wp7dbrL8EjmyikgtOww79q6GLTd0pt5BkPzHHHv4POnKJKHqvv4zY5XaC2cfYIabsSShY6hZr8IWQrt8c5kemgcW4BK6ukO/PeEDMqQm17KLqwssf65t6CcXycUsFAbrtPysOlgaBdDJ+tccEGXVetk9VYQPiSatnGGbASa0YokPKDSk5MWM3dDQgsr1woc0DTPHhgY6UUZprRE94D1bJRp9OyyYDWnh4ZLMlVY6zyooRUa7D5EcF7YJoQvAISLZEGEgyPoz9g69wXvAXbRSeCfVVIYEAXnRgMCfyovdv9vfo0Z2fbfqHOY6F0o634Cs4FDjKR/BVRyd4guGkhqPXNYTMQC+R+CH r0w3qg/K Yv+QrJclIwYnGSAMWlRIl9jicHhv3wseKhnENFFwKVDWp7ehM7BTLHjgImwz3eYUGaa3mDTxOgOenqEyaOFgkTUAlIK1p16aEXhrXuHdXBVf9XI4ulf4ojHug7l9/A2FA5lx9VdywCx5sl7PDBJUDI0URNEpw70N2dS4smt2eabOpmlt97j9m1xGHTdDOAe2k/Sa8kbNPCAdPqanbWPhrjk25dNDhMzFKjNgZn/fPy6uBTa8421HDRdTyCudlcJHHQUYW+S7G2ra26mvqDv/8X/qJJ/yie8rZ/LA9mcRH0PvCNua1OXT5E0hr2X9e8QRRlczDwOR31t1sXjmk8OGy6ZIEQjEg6xcumXpySiKzcD/yfrb7nqj7PR7F51keo9hh6YdFZkL0eMoZAuwbB2qbh3sq/nD2R+2bsqI/ 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: Use new APIs to dynamically allocate the thp-zero and thp-deferred_split shrinkers. Signed-off-by: Qi Zheng --- mm/huge_memory.c | 69 +++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e371503f7746..a0dbb55b4913 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -65,7 +65,11 @@ unsigned long transparent_hugepage_flags __read_mostly = (1<count_objects = shrink_huge_zero_page_count; + huge_zero_page_shrinker->scan_objects = shrink_huge_zero_page_scan; + huge_zero_page_shrinker->seeks = DEFAULT_SEEKS; + shrinker_register(huge_zero_page_shrinker); + + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + deferred_split_shrinker->seeks = DEFAULT_SEEKS; + shrinker_register(deferred_split_shrinker); + + return 0; +} + +static void __init thp_shrinker_exit(void) +{ + shrinker_free(huge_zero_page_shrinker); + shrinker_free(deferred_split_shrinker); +} + static int __init hugepage_init(void) { int err; @@ -482,12 +516,9 @@ static int __init hugepage_init(void) if (err) goto err_slab; - err = register_shrinker(&huge_zero_page_shrinker, "thp-zero"); - if (err) - goto err_hzp_shrinker; - err = register_shrinker(&deferred_split_shrinker, "thp-deferred_split"); + err = thp_shrinker_init(); if (err) - goto err_split_shrinker; + goto err_shrinker; /* * By default disable transparent hugepages on smaller systems, @@ -505,10 +536,8 @@ static int __init hugepage_init(void) return 0; err_khugepaged: - unregister_shrinker(&deferred_split_shrinker); -err_split_shrinker: - unregister_shrinker(&huge_zero_page_shrinker); -err_hzp_shrinker: + thp_shrinker_exit(); +err_shrinker: khugepaged_destroy(); err_slab: hugepage_exit_sysfs(hugepage_kobj); @@ -2833,7 +2862,7 @@ void deferred_split_folio(struct folio *folio) #ifdef CONFIG_MEMCG if (memcg) set_shrinker_bit(memcg, folio_nid(folio), - deferred_split_shrinker.id); + deferred_split_shrinker->id); #endif } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); @@ -2907,14 +2936,6 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, return split; } -static struct shrinker deferred_split_shrinker = { - .count_objects = deferred_split_count, - .scan_objects = deferred_split_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE | - SHRINKER_NONSLAB, -}; - #ifdef CONFIG_DEBUG_FS static void split_huge_pages_all(void) { From patchwork Thu Jul 27 08:04:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329210 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 1C03EC04E69 for ; Thu, 27 Jul 2023 08:10:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E0BE6B008C; Thu, 27 Jul 2023 04:10:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 990F36B0092; Thu, 27 Jul 2023 04:10:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859128D0001; Thu, 27 Jul 2023 04:10:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 799956B008C for ; Thu, 27 Jul 2023 04:10:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 54557C0513 for ; Thu, 27 Jul 2023 08:10:20 +0000 (UTC) X-FDA: 81056669400.22.F3D8CE8 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf19.hostedemail.com (Postfix) with ESMTP id 6B3421A0015 for ; Thu, 27 Jul 2023 08:10:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=T9ifvBS7; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 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=1690445418; a=rsa-sha256; cv=none; b=vfyHjXY8wFrJ4aUCrZv1YJXH3GRnMykyhLToE6XHadUzhMEoR8YjetfHEbVQAHJvrqHz7c 8kAI56cmUeIlQIMDa6xXZXQdywk97U5sQMIFhPkHMjzCFM9AAY8BdhyPY3fKrLN2vIrXLY Wq5eR8gX5JaitJnG8ImABQp4IS6jOew= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=T9ifvBS7; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 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=1690445418; 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=PYuXWIGRd3SDQUNwBNnDU/RFUGkEJd0z6ud/pRWhp58=; b=CnrdebGAfCi9Hb2Op058pXsugPLNk7o+ubXMU8PH9yHhz0/lf0CbMNnj1OpMu0JFs6FeyS Tkm5bWPS/8f10q7A81Pv/HWYbSvYRL2qMIUD2s+b8oYOndcfTJ+DRskcAP73i+V+QTCpzx KGQ3DCAfkkdRi7g8ky9gclcU/LkMEks= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-686f74a8992so77842b3a.1 for ; Thu, 27 Jul 2023 01:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445417; x=1691050217; 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=PYuXWIGRd3SDQUNwBNnDU/RFUGkEJd0z6ud/pRWhp58=; b=T9ifvBS7grSXMXHZ+aFeKzum6pF3H2DhLFdohTJRx7vF7szcBG6tJ5VPINqCVu3pCX FmubTvt88b5ysMWaYtFibatbXMnoo6Jib8lbo65gbMoj4iY6HbdoFrEeXgYSqYC9Jqe0 PGHsLAS4RpAPQjTV72r0GtDUpuZ/ybvTZ9EZC90EXosh65ardfAALzeVYgFduHUdYxNh uE3GuwKiv2CyHXolQ3XZqpbE7oSyCW4E0iZzkXVJZoTlkXjievgPAGhg1+Kv8s/E0hIi dyIaavdNWwWhQNwuCKJwqWG502/DMJOkmwjObTrka2ckcmNrtUCmvsEGY2FZ9fmQFWZZ aE4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445417; x=1691050217; 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=PYuXWIGRd3SDQUNwBNnDU/RFUGkEJd0z6ud/pRWhp58=; b=RswEv6NSszGU5SXSk7SHoJLczvERGHOOr3rqCEAvOzRnF1DO/IhLI2v3op1Bs4lBGV ZaeJ1/6Hu9IVLlM53zwr5RZYXY8amNNluh5/+7E2O5oX+Ic5ARS94CYBWJZnjRwsfTnO 9za5eilcuG9Vgq5wbZdU96v46xwGSdIjd8QILpCHH1fI9DmfNZ4KVGdSfsuowBAEX0aH RopYNPI6eBolcMgcYnXcJYb5kWCqZcobiUhD9YZgYtPKnNJM/J0yaINQibijNuPP2gyR F9sCILBgvwDjipv96RCYU1QZbr9tsFWpN7rv7mqHoeF+epmol+ZzQ4utqZyYu9kO5YBS bbgA== X-Gm-Message-State: ABy/qLZn8sY7DrZGRgW/RaLnPiGdopCIsMYINugz2EVGZRquPEjJeH7n Mh6wda/KJWiaP2+Ze6l6zNgW4w== X-Google-Smtp-Source: APBJJlFP1iLC566NPrkWwKL0iKI9L1P+4s+IlmNKaBmXVe5HE8WAAvDQ5uBELCFt4/l7YPuEeyQdfQ== X-Received: by 2002:a05:6a21:7882:b0:123:3ec2:360d with SMTP id bf2-20020a056a21788200b001233ec2360dmr5970181pzc.5.1690445417252; Thu, 27 Jul 2023 01:10:17 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10:16 -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 22/49] sunrpc: dynamically allocate the sunrpc_cred shrinker Date: Thu, 27 Jul 2023 16:04:35 +0800 Message-Id: <20230727080502.77895-23-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6B3421A0015 X-Stat-Signature: sgtb39g7ruyr5x71ioqow7xfqbs193kj X-Rspam-User: X-HE-Tag: 1690445418-773871 X-HE-Meta: U2FsdGVkX1/gTw2IZft3XbASvC4UyGFWrktmIglnK7Zo4jEpr5Yiv59XNZSzb67cNn96tc7wj6CpAQBEEyh/yk5+kezvvQ2c1i3vKG4ghunVZzTJgrdUnLst9eIM+8T7UsnQrDoWBpFxAgZk2/Qo8SMA/h86WMpw4JfFK5lEVMJDRYCjyWgWSh57qijFbzrQyd/wp/F1+rAystuDJ9cMizGNR6HxiS1VHAHDhqaVlIhmAB9JYRvV1tlZ1q6vwTDTf0R+9Xoilfau76jUoCyvRyIAMiBv14H6IbFwGn6SrfmElvtrh2chspjRGr8ofB8n25DhxGj8gricbH5mf3riJo1gY8Aa6/KU59FziuxkNO0W0kjaSQxsS8f42V/ER6vthBRZxDKLJQxt7MJTzaaCnrMr//rbOthAbZmM+lrzGBa6+3KnMEJbn6Dw6Xu/6VoqtndvYb2KwRyp6g3j1NmIwa7+LyXWTNdxmEcKMs6+l/fCdcPTfdAn3GDPnkMPCWvJTO92tn53B7QTPD3GfVHzZnNw1v7vYSd7I/L/4LM9lye5OVBMu3LdZ9SqAppKnjqpz9Qn73LDN4sqe5jOCIHIGVcP0waHJFlw6rmHOuuURc6iw3q7OmzfeXLRSY9hvikLwVdHuT7EwRuCi/AJxzrZ8NQdtvrFyeQs8PmU1w0AUS/AX1LkBZfYrRBeWrIvhRwEPx3GOMYm/AXjEmstgkMgDr4ap3IptJQW6SGZ4Av/i+Jyw+grxv6ex3PZBJZGIBpAoZI09qCvyQ+FdFBF5MhrC7g+f40Wj0alYGumPmUqdoXZqO+uWB/vvFLH/uKrIBNUENlrS8sUgouHbFs6NnhAodzbyLaPP7FYqdGmL/TkxN/21cpEgyx9VnCpjsurgwD0my89CpnkfzWB6YoM30J+eaBiS7b0CDf+wAX64bq9MtWIHl1upsGvv5r0ca6jvkZRlfk81O16TdvBmMQ0IHO rcWWcrvl ChXK2ROJAMLn9ceDZb9OSqMp9pfMpCmO/x5d9GRusSyV+LiiaJ54RGXg4Osk3GQl6D/qmBlm7v75sKXvylMMjxrtIQ1Tn/U9ImV/+zmKlqt6DL+ZHU7NxUk9eM/RcyrGeQfDmo8Y2s8NNV/Jx5pmdXDhoj/oKvYH/kfdk5poauSfkeOM7GVAvhWobCle+UUlbkkFTMQwdJAHuY1sLdowj3914dSeesCMErQf6QmwVUZsjI/rU9S1kjIu77zks3DR7mPNCW9/NWgwlr1PHhBv2uMPgaNOedbWLq3erjDeAacr/fv/JwyhrXHRA9vK70bqgZShm2btCuXQ1dpaU7dEj7TPiXrXy47yk47ObqnSQgIhj5/z8YBEC6bRZx2y56mNc95dZgHlDlmvFEfgoXM0va2QJF7Rrcv/fMW4bieh9YB6cllkvfvHLne6xvZu9oXzu6ENGI601mWtFUE+Lyy4nei43Iw== 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: Use new APIs to dynamically allocate the sunrpc_cred shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- net/sunrpc/auth.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 2f16f9d17966..6b898b1be6f5 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -861,11 +861,7 @@ rpcauth_uptodatecred(struct rpc_task *task) test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0; } -static struct shrinker rpc_cred_shrinker = { - .count_objects = rpcauth_cache_shrink_count, - .scan_objects = rpcauth_cache_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *rpc_cred_shrinker; int __init rpcauth_init_module(void) { @@ -874,9 +870,16 @@ int __init rpcauth_init_module(void) err = rpc_init_authunix(); if (err < 0) goto out1; - err = register_shrinker(&rpc_cred_shrinker, "sunrpc_cred"); - if (err < 0) + rpc_cred_shrinker = shrinker_alloc(0, "sunrpc_cred"); + if (!rpc_cred_shrinker) goto out2; + + rpc_cred_shrinker->count_objects = rpcauth_cache_shrink_count; + rpc_cred_shrinker->scan_objects = rpcauth_cache_shrink_scan; + rpc_cred_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(rpc_cred_shrinker); + return 0; out2: rpc_destroy_authunix(); @@ -887,5 +890,5 @@ int __init rpcauth_init_module(void) void rpcauth_remove_module(void) { rpc_destroy_authunix(); - unregister_shrinker(&rpc_cred_shrinker); + shrinker_free(rpc_cred_shrinker); } From patchwork Thu Jul 27 08:04:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329211 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 2894DC001E0 for ; Thu, 27 Jul 2023 08:10:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2ABE6B0092; Thu, 27 Jul 2023 04:10:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDBA58D0001; Thu, 27 Jul 2023 04:10:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7D576B0095; Thu, 27 Jul 2023 04:10:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9B2306B0092 for ; Thu, 27 Jul 2023 04:10:32 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 23611C10A0 for ; Thu, 27 Jul 2023 08:10:32 +0000 (UTC) X-FDA: 81056669904.20.C8396D7 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf28.hostedemail.com (Postfix) with ESMTP id 36E37C0005 for ; Thu, 27 Jul 2023 08:10:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iVGfsyXk; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445430; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=Qtn5Fut1mEXeKEkO4qSDRcsRWrOcN2VsJA+cyO1frFBgjM4bbx3yMILqWp+HMoKUC3TbyO 7TleqczSIfcn6Uv19E+JYU8L8pr+tDdq3SWMKOUGj4rJbF8OmrRYE/k+Q8mV0Qmnl2sVg/ itC8Ss4vp6Bk3oZ+heIKzUpNm8452Lc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iVGfsyXk; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445430; a=rsa-sha256; cv=none; b=PLG9o0Kf0Tyb7tcbqPMM/jVYgpx9F64E2j+6KPZ/EMDdgadaAFwFav12W5T/aBIFJYUyff WJFHNBcxTt+rAEzXToSCeXAcSJPo9+Oills4b7CEE6wVrVVYJ60hAY9Ldj6/8zUvSJswCv erTF2NekFaofWhAagTRxcc8U+xusUWM= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-686f74a8992so77889b3a.1 for ; Thu, 27 Jul 2023 01:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445429; x=1691050229; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=iVGfsyXkMcKNuSj4S4+ETT1e5FnNKRSLwcupS7aKQrOa2P/cg11EPb/fa7MepSVN0c souD70V3XZBCWCF1GY2G8kOBoazYK/GwCZP5iJVITEwRi2CFhPhtCnmN6NHRYDRfscjM ei11bn/3SqGlS2cI+uWxsIZ60GgV8/Th1+KRHAcGdOM/vcClXnAdg9IcKu5dXKtmCkaz 1Uv1368bMlurEfH1GvebpNgAfjlYTQWl+OVWRYv+SAitVhKYxMqk7I6vstlqXAV5ZTFg 13mCns35aGRuj+msRJnkqY3lYp1C9AqbhcZNDVttxslcFzKIxthPN+0g8mDIqHh31rTQ XhNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445429; x=1691050229; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=UfjyrKPrZc12zzEcAjr/jjJolgZlDOWzHemjVHtrRlMYfy70wcMBB/x6Qiysq5MwvP 6LtBjXpow9tOUBT2juWrksHLrfRSeET8CzsjPWAmhDTEAMA4kx24ixQkQxxaulSEaFRZ t4tOjNzDlCra4Cmy95lRMCtIknihgY6gLx+jT7E0LQWJ7RDFsaajFFNuwOfAn4MDlKOl ElToWCMyLHWG9xxuP4rmqfOBxwjzEWrTBrmiqk+oL9eo4CIPs4366kLq5PAQCQtmtbi8 cZWnw4pLhvzgixHfVVJOvnkEWfWLwIy+gGY89TLkEERhr6x3b5J8a+f9r/gC7hRBpQHx +FHw== X-Gm-Message-State: ABy/qLZwHMBqKrK0RYdHhRbk4zNEOMfXpcjHgNf5AFk1M3snVR5f8lQa 37MI2kDfB+q1X0qSIbC2aVZqlA== X-Google-Smtp-Source: APBJJlHGswV8UzzwdSNooBFOlXCa2QxTNwcJjWEIeOA/B6KtVME+e61/tgitLanHgBraDSTbcyHPAw== X-Received: by 2002:a05:6a20:1595:b0:137:30db:bc1e with SMTP id h21-20020a056a20159500b0013730dbbc1emr5696433pzj.3.1690445429121; Thu, 27 Jul 2023 01:10:29 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10:28 -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 Subject: [PATCH v3 23/49] mm: workingset: dynamically allocate the mm-shadow shrinker Date: Thu, 27 Jul 2023 16:04:36 +0800 Message-Id: <20230727080502.77895-24-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 X-Rspamd-Queue-Id: 36E37C0005 X-Rspam-User: X-Stat-Signature: igmfjj5h86awq6ck1ijndq9kay8wra78 X-Rspamd-Server: rspam01 X-HE-Tag: 1690445430-797251 X-HE-Meta: U2FsdGVkX1/eE53FrlxbFUU4fFdEo5x8zoj1KTY1fFISzXbKUsD5wuTEJC5cVKVxVKmTY8a7vdKH7thpUI0seIXGBAarAgGIMrolVT5kyePCdcpVE1YUxtlIMp9O/50hVE8fxJjrb+WOKwXwjxozi/MgF9fP6c3wK2fNwDLwOInloX1Q5tg0+jivmfGIco18NL3riRBQoYmf98/VRVNVLOydGrn9MSOIDicfLrc8C5qL1bq4F8+7RfV52dfXqxudRPawx5OiWRGv+7RUsrDFuw6u4qCZ0srmRhhsdN4SV8aNBPPWAkcaBgcCxJZ/HajaztMmM4J1dZbF0AR/Rfi6SlVpxhww/kP+BKbpw/owVEVX74m298vhYHEXPPZU2NDmurClQZAwXoqffK7uLMlCMR0XB91R5+pPesoLUAHzOOae8C0NNwkd57GVGiMhQI/ywPXy0m5WH8n7zbOAv+P7gqXT3Z1JsWzBPjlXUwwbI5PDdApJ2teFdXNbf584o5xuW5ZzVHSctJiuHIgPP5gGjcDr8SHDnWKLfGPTjhuKVV7SwMs52WMZZvWU5D5CgQZJiewmwsWDvQme3uyWp1MRVH/BJQ9B+4mwic+m7nrmWmEbvvexgmtaud7Z9kbbNmi/b8nbPKuUnesTD7RDDe80Pdfs3Uf3pjaPNO0fPqKMQXfdKXmdVenNmke8D/AlFB7yi8fveyLtBfAdiHVK6S5YYUrgB7tRklnSvTX8umiDHk+1oekZ0IdMstbOSaRtZvgpAD2FtF3qTDwL9IbOQPWYGMQPjNoV7rERRrJO15gYjTNrjyk6ac981mvhaDt4+82x1Sp5hEJ/iWt9nK4ZyymAk7z+OY1GRkR2sdSjp45NTonbDsxv9NOQ8JhjSmhzL5Ji3mHm6l6FVbYI9+kr7qXd7B8Yf4JdfdoOhkOJcQ9rYNDNqjGtzKEZrq8ylp8drReuBVTmaX+u553qLf25/Ut +tVXMd0O Cgn/P5ACpaHfLQiMF7OnT4Qp0Vgx86pij9Nyopx9PPUTm9b5JZrcuv5Xwo+U50ShAK95St5CGJNCYlJM9NVzilaOsc1QiJbRkaZTdug1UgJ0wWQlGGvZrpONq9bPqPBe8t2tR4Xl+SEcqrv/byZLQu9w4JmuoMj3tT6+rircEwMCbFjhzBW5BOBRfBsFROao95UkQDmsMQUjT/zUTWwfs5LQEXFZJu/LrO3h+8JTJp10Usd+CpHJypF1Q6I8ZZG80Lp/Sn5678soXdsCRbwFh2TNyqimpvacrhCVnbNweOjqDyimpHp5zCxnf2/bsEDMHC5wKblco4nPd7x47kmWxjrwj7UeAmek4N044U1o3o0XLlEHukHOJhiE4yosIKhGfKl+LDNVd60LAtgAv0M7CQuhW1yfU6yo2sKTo 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: Use new APIs to dynamically allocate the mm-shadow shrinker. Signed-off-by: Qi Zheng --- mm/workingset.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index da58a26d0d4d..3c53138903a7 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -763,13 +763,6 @@ static unsigned long scan_shadow_nodes(struct shrinker *shrinker, NULL); } -static struct shrinker workingset_shadow_shrinker = { - .count_objects = count_shadow_nodes, - .scan_objects = scan_shadow_nodes, - .seeks = 0, /* ->count reports only fully expendable nodes */ - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, -}; - /* * Our list_lru->lock is IRQ-safe as it nests inside the IRQ-safe * i_pages lock. @@ -778,9 +771,10 @@ static struct lock_class_key shadow_nodes_key; static int __init workingset_init(void) { + struct shrinker *workingset_shadow_shrinker; unsigned int timestamp_bits; unsigned int max_order; - int ret; + int ret = -ENOMEM; BUILD_BUG_ON(BITS_PER_LONG < EVICTION_SHIFT); /* @@ -797,17 +791,24 @@ static int __init workingset_init(void) pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n", timestamp_bits, max_order, bucket_order); - ret = prealloc_shrinker(&workingset_shadow_shrinker, "mm-shadow"); - if (ret) + workingset_shadow_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE | + SHRINKER_MEMCG_AWARE, + "mm-shadow"); + if (!workingset_shadow_shrinker) goto err; + ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key, - &workingset_shadow_shrinker); + workingset_shadow_shrinker); if (ret) goto err_list_lru; - register_shrinker_prepared(&workingset_shadow_shrinker); + + workingset_shadow_shrinker->count_objects = count_shadow_nodes; + workingset_shadow_shrinker->scan_objects = scan_shadow_nodes; + + shrinker_register(workingset_shadow_shrinker); return 0; err_list_lru: - free_prealloced_shrinker(&workingset_shadow_shrinker); + shrinker_free(workingset_shadow_shrinker); err: return ret; } From patchwork Thu Jul 27 08:04:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329212 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 29216C001E0 for ; Thu, 27 Jul 2023 08:10:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C04026B0083; Thu, 27 Jul 2023 04:10:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDBCC6B0085; Thu, 27 Jul 2023 04:10:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7C416B0087; Thu, 27 Jul 2023 04:10:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9AA2C6B0083 for ; Thu, 27 Jul 2023 04:10:44 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 772F0404D7 for ; Thu, 27 Jul 2023 08:10:44 +0000 (UTC) X-FDA: 81056670408.11.17C69ED Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 6180C10000B for ; Thu, 27 Jul 2023 08:10:42 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jJgBI8VQ; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 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=1690445442; a=rsa-sha256; cv=none; b=Z7LsNkzI4EmvgkZMB8/AU236xJgsLS9C1o8sTScSZjtGLz9b6cB/pUqk7lblsZakVgdQGt QOAi5H8Bj5kEikXekeo9QhdR903zePQ8YI+QoO0ZEvxYNMdN92LlrBzvM85aIJ1343ptlm QiF78J8reZwgi6O7PUaN6Is5C748Q/4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jJgBI8VQ; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 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=1690445442; 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=oNmFII8upz3F/YexAsu0bG7mdRWahQoNK+zo4RSsp0zxTz+Up8fhqD85Cob3WN5/Pl53DB tRR49H3jEng11YOnkqQ9ijb8XMPg84UFNzxpcBYhbNiT4AkS0sFDh66/bW+zKnrO0OX2p1 i56k7xi6yk9W6qQ7qfFiYJdNFzUIoj0= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-682b1768a0bso175221b3a.0 for ; Thu, 27 Jul 2023 01:10:42 -0700 (PDT) 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=ktlU174OVAUIW7hTAXLRUe4KPygsVlNfx8A6QS0lvHLVwXcP551UZ74lPXo8wVCYrt p4wzLFMDfDaw+G0RsqzlIfzgV9CRRhxLwhjXs+YpAWKVPHrW+ErFyhgzrGqOgnN4/B+Q +4FVweSgoE3x4aUqEYUScdBxJjM+Gco4kRcsNha+CfHSbXAnTcC9XwF9ce0WdCsIakJL kJ1IJtN10qLvd2VtFkUcy1JFTdDyB8X4axgYahx3v6/mHXlh1aUjDF5JofhyadIhkyT+ eCtBGjjiophgTJPw8EP/HfRlBax7+w+4SwBQMPUeo/g0rAWlY7obv33zTexl4BEoY0/y lyzg== X-Gm-Message-State: ABy/qLZp1O0AQ4yd92hHysd3skqMjWVyNesBTHRKWl9/xtbf7OXow9FY FPyXzfXuRxUGD36wyTLzb6xWnQ== 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) 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) 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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6180C10000B X-Stat-Signature: u34yyuwkpu5ayyc13dxpjxdtgmmhouuw X-Rspam-User: X-HE-Tag: 1690445442-45217 X-HE-Meta: U2FsdGVkX1/PTxVzzWT8YNEDSo9xeNp5JweFUmlKyC/8Et94eXURGXeJan9HmG1ql1OS1qRihnSlVbu74hxv89riqY7FfJOvnvNVvJV8lA6L4cItGqrfv6pvAVuUyDI6UnfNLOOW6X7RDjoFwPZWHbz9HToXNqsIJTRd7PSOwh5ItiefZWWQAy0m0vi89xgrgNA+S0+0KXluu78QQ8BSP4lqUXy/QbkVnrykGD/AdoHiM0cYW1739OCV+Qadv50csovQuQDAIcdGNG3Wfe5OflEhPGC9T68VUbPUbSSU2Tpgqz4SlZUO8dWyHJVCHIOry8zUe2jiwQcnodGhgqky+X7oe5iDdQDNlLE3pJRZXV3mMZoiQXAy+/408nLGZBwShGZI6KzomTOKadZ1phu1FjRDkWRvMt0aGKrOgwYpnRx84fHmhw9zBHjsBlTF7j1jp2MzKS5IlLh6um2/GveOphf8IDHnCXrJxLZlApqvKTXuq7JN6W1DulvqeS5LVzMwqoqgghrhvAhrkfSzZ+ofmZHJ00yMDO+3cK0AI4QDb74MfdmoLAr5O9lNJ3P7YdFGLDjuaOM9EmO0uOTBCgUfwBmW0SaMeYf7GUXP8hu6C8BdgQBpgAa2ZuxZcHciMLh2T/Y7VMqz3a7OR2TX4UQVVNLxj1/5N+kTWWMb/BdDpJAeIt76nOUw1WNbzyoi6MsrmlDTKXJciaabG8+UYeBKaI704vXQMZkbYSzBgQJWKdxtKT/UeUnABeJ0EwOoKs1Mygg2aiDDSNoKSQc0SlU2gJ705gnQbcEzaN3p1DSUF2we9tz39rOSaNT83bjiLWck5sYiBoBYbnR+zBMqj6veSkdVmN+ySV+8w5xeFrfllzQX23pyru+i6cUMbj3FZfwSUlRIKidv27M8F+Gf1kvAntSNBZjoSnQrv79Dz2qvf+r0Ej25c5l8jBlbdyzpMdfFj1GQFwjdAZusegJvVrL TLgu/J6N saOuqn+8KsZr7XNi5pNBtizgXPugXXHnIr7W7QW4U0+5iFV19jVU2G//6Lh0hcqOnMsr5RsxRLxj3Rwr9pOD4IQTuDlYi+Wz/tCQj5DQUHBEZqx0QUtwak9KDloADL2xAZJwtHw51s2AGTwJOteBsO5w+qiKSmWrSmACEGnw6C64VsiGqJ9XGevmdLuTV+8BlHMTcj2IHHHlpHPxrwbVAxy5GgOHmoQrw4JeZCADamg5fEEirvyxKBiv46m4qLwPz7XLtd9tQUxMtpCRZwSTURJuLgFCdxgDqAAcS9RwSDm9gZGKay2oM0tMgxOtogOrP8RPvS/ObHz1DqSs1mXg9oPKcFyDRTDWu4bCmsW+r0YaesdDouljCJssQtbMR3kur3U/sEvIwIwS35p0mG2yNPGf9tVKMQKUQV6nYad4aneTHsfS6sA/v7P23ZbIyQoHRdsyfT9B6MEKiJ7uDCcin0MO/hA== 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 /** From patchwork Thu Jul 27 08:04:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329213 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 57624C00528 for ; Thu, 27 Jul 2023 08:10:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEA186B0085; Thu, 27 Jul 2023 04:10:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9AAA6B0087; Thu, 27 Jul 2023 04:10:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D62AA6B0093; Thu, 27 Jul 2023 04:10:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C9D9F6B0085 for ; Thu, 27 Jul 2023 04:10:56 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A702C40450 for ; Thu, 27 Jul 2023 08:10:56 +0000 (UTC) X-FDA: 81056670912.09.DE63275 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf01.hostedemail.com (Postfix) with ESMTP id D688A40002 for ; Thu, 27 Jul 2023 08:10:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SsnsAPan; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 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=1690445454; 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=Tu9w5C30y8MI/napZavPwFZ6nIJBEFlaB1CCEG9BfCw=; b=G6ibEJLn/6BqXECM4hxT3UBiR+Gwsmi1p2tq27dvCxPiPsJ5hpSCYP6NZ5rgeMLPebRh0q O1iQFVt6rmVbKboJ10Pp3yw5dbaxfZ6VpDO9++irhCxBLa9RlNmsxyXZVslQjcVrsDPE63 PsfzKzYZItJyqzKPEVqKwFe/SI8T5PM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445454; a=rsa-sha256; cv=none; b=d11qJBL7aLYlHO8RXBW1fqtvfYaamFWLKRLDAtBpytxG4MysOyTyiQCg71+eOY7I5zdrJh zkl6jOmBiPUsQZTdT/cTA8FlfiwxVM2WUniU//AAruCRqGu1QpsqALeTFeesQHeI05QW1n Kdmw9bGd/1YmaQ7KUfpQaQWzRpEeB2Q= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SsnsAPan; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-682eef7d752so204323b3a.0 for ; Thu, 27 Jul 2023 01:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445453; x=1691050253; 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=Tu9w5C30y8MI/napZavPwFZ6nIJBEFlaB1CCEG9BfCw=; b=SsnsAPan45QSmQpJqAj4mS8LLavDombkZ7lBafLri7RggDFTDcpBOPuNyPBGUpCtjr o6WPy8R5HZiwm+Xan4YH//v4pvtUrfeXD65Yl1az+1fl+mR3tGlsBglM3Vyq8SiK2wyq igQhG5qCvspbkK2WSeD0wTcUc/mVkzohC4cNnc0XbtmIoWLvLOUFPW/6keJGSZm27mRz h/WfB+fRpcVUE83zuhvMF8jYZ5b4nmh/qAHVpz3lROeGSQfLjlNrgG+gcbPX1nT5Mc7l SChQ2Lyx0ddDcRFnW8nA/XTZimbKDOI/X2WL7QqkejXsVeMe1ddjPlvbW0l5uaRLNo6A kpeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445453; x=1691050253; 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=Tu9w5C30y8MI/napZavPwFZ6nIJBEFlaB1CCEG9BfCw=; b=crC4DKBYagVjoJ8+ngwM1fm2oYbXudQ516zkFOUrlfgvVJ2TN8T5wdf10zwkTFuSoK eSqNJQT3yWehPAZ0RPRt4toTqnci0tok02sZILJ8vyNLr3Y2sqo+5TPgaU0utDTjk/2p RxLJi6KFFj2ysRtY8qTrDrnZT+oLg6vNFhaMgDOjYKekhUVVLgn+0ky+4+K/C4ze/p9h iprv1aGSjI8OKdCT0h/GaBJUEUbzG6Yrm46n1lPAEkV8Lhweq1GKvDLuQ9Qddi8t+G7u DWd7FnJmp5nH6ja4Ej5pR91NrlYkrvfeforGO7qCpqydEZ2culhzJ+aSDiYbWf0rcb+3 mHQg== X-Gm-Message-State: ABy/qLZo/M7pyxFnpGmAaGxTAHh9F+wCZHoJ/xeWV7oLlMrSgDzIVYUN zM8ot+nm/1MQaTQT7rrl2S4dsg== X-Google-Smtp-Source: APBJJlH8SkZovaBL43/tLWqoZ3fBR0XBkmVGy0uXARpdi3AER3WOYf3EsHJKszN8s65be9uhrbpx8A== X-Received: by 2002:a05:6a20:12d3:b0:125:6443:4eb8 with SMTP id v19-20020a056a2012d300b0012564434eb8mr5769272pzg.5.1690445453524; Thu, 27 Jul 2023 01:10:53 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10: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, 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 25/49] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Thu, 27 Jul 2023 16:04:38 +0800 Message-Id: <20230727080502.77895-26-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 X-Rspamd-Queue-Id: D688A40002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: xxsyxy1oujky7hx65c949w44rd3hx7ou X-HE-Tag: 1690445454-780537 X-HE-Meta: U2FsdGVkX1+RMiuTJ1A5RL8hRMMRiR8EV7D19ME7qcLCjan8ZqJZFMt2o9HbAXhIdWTKJ5fwCG80QoiJM+AmS3a/vouHSCGy2mn+SCGn9eeKgMJj4bi0CEukjAJIDwhozbmCvcwf582hQOGsPpKUA9WF2oX1al7GZreTP7lpu9qc9DW9jEhTKi6w82qSXN7+lJfDKmmU0CthxHPzzsC9rhpZ/WsvFKrVywg7vpQ3YWOGzEJ4vk5bzyc1XRhp8PAS1tFhI80g7YxXKLloMuDI+ijhN5ex6UvsFFsi15w4BvD4p1pSU/iW9ZQFL/1WLMIu0q45snd9dEo6kUW54NrE/UVVU5h0IBf0fBfrRgLEM4cAQMPBUUsiHQ3uL4JJivnWTiXmYn2TsB8KR7tXqeIV1YRY7bTP4+90ddBI1GiPbWPfa05ivK14yaXtUdbmM8q6QZCOANT9nlBheddwAc2AeVdxd0B5J3Wu0fB3+iuZr8KrR++vcRfsp9NPTg/th8KCNOqTi0jZ/2tSonsb3ZX9fFMPlT3Ezmi18lw01xJcy5sSJJp75IGsOy6DFij4YMEhqRz/40Osuv7nkqK+sFHt1p7DXxcq/by7cigsiJ0dwMKSUkipaSuUEkCqfhz05WSsg9pnXhE5ARlaEmwb028bBZrklAPSuV1xKHxm9dIXYx9IU5XBETy/zoQR/0GKfb2vuCcfnJyeI047YJizeV+q/LGi/myDG5wMcXTKwcPefk81yZ875Czq6w2UGZdb2Rb//7YV+xuodSiEJTFUAjQVDkVSwt6ut4qHwHxVwVISdewX7MB12UFLS22hslewqzU7HvZ012A5Zzu0PpIwoIbix3BYwlspPYTI39PsTVgXhEAMMIIzVc6LD3EaP55fDhOYOf+W6sshwEGzqZSKCqk1ZjyfiBAcY1QOqByqedhF4MBQkNWjLFkus93NYWnfXobo7DDLj6wW55EavR0YD/E wfosR3oG o9nngjjXlRQLA4Ww8J1pKNrMotV0oal4vLZnH8zfmfzZNo8DrEhM5ABF9MCbyt34iAcMxIl6enHXdFF8tFj0+YUg6fJW1252yrPp6WcPr16R6GNCl4HEB3OS7QIoKhckH0g365enG4FW1K5jIPve/M/TSYfW71R/bKfKW6O1SmvS6Jjaf9Tvyv7YTw6oPvac8V+6cA8z8bwbmR0XvWe6/QVB3k/j3mjARud3eA/M4KZkzHnFGXWxeYigdFF++BY6V84RnM3/25v4+HbV0Q8ahdLH9EYKsCPfbxcpXFxr0SNtFueVV5GPTovwkcSVTYBB/l40IDuosBvCJNUUK5dAe1ZySYF8aXL8sDHEx0qAWYKF70YejHClHp5Ra+4Ez9+08sX6yO3+eBwmd0FF1+WJwai+mxNg5AodN3G9HoUU8EgoAVowbFHuWqvZ9lKM8b7m6aSQ0D6LirUosJPKZMmnj3QO3RA== 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 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 Reviewed-by: Muchun Song --- 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); } } From patchwork Thu Jul 27 08:04:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329214 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 813F2C04E69 for ; Thu, 27 Jul 2023 08:11:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 240886B0087; Thu, 27 Jul 2023 04:11:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F1516B0093; Thu, 27 Jul 2023 04:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 092248D0001; Thu, 27 Jul 2023 04:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EFF416B0087 for ; Thu, 27 Jul 2023 04:11:08 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C5E2980FE5 for ; Thu, 27 Jul 2023 08:11:08 +0000 (UTC) X-FDA: 81056671416.02.241A9D6 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf10.hostedemail.com (Postfix) with ESMTP id DF0F7C001B for ; Thu, 27 Jul 2023 08:11:06 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KWf7bMy1; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 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=1690445466; 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=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=Nz4G/+vcd1jSxXMbdyQdA5MMvGIMRxq8/LI8lNxKcjT4GVeDeuoeTuhUxjoKSPa/tWXV6z Ke/rweCQOx75bwzR59hvx1hSDZvLMOGs2OU/9G51HUinpxkEpGRsmtZOLfaMPNDDY7YbEq k7YDcQ3omOZOrVypXIf4x9+OrDJ3yRw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445467; a=rsa-sha256; cv=none; b=MopKbwHXEW8qAVf2EXs5X8o7XeBoGIT5ArgMn7g8heS89wAl3V3UHLuALCChl49ytRsa2A To/ho9GpLJ99EGwOUff7WHzF4RuCcVXa2IGRnoUCr4ojXCXUFa9ZUx6pgl7/7cu5kSe8Wq IsXk4ZjN2G+pBJ65iLfaLT2SMBH1gdM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KWf7bMy1; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6748a616e17so183298b3a.1 for ; Thu, 27 Jul 2023 01:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445466; x=1691050266; 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=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=KWf7bMy1nbQ37OxDK+aLk4UU+d+DpidRt45gsv6WisntZ5r23wZ3pYKMCoLchBsQxQ dbRrJ4b0aFwJmGna2/IEy8T8QiKnn2NACgYbVRTrckTcQDGJyAPHMooOCl62MUAwOoyA JbZysBi4oQBt301gAOSv+2GS8dKtdtSP0nG8DKgUtI05eGkdQUUBXQMQvZN3o0luNYiw 8kcVk8roCfN8SKqwYrPgL6wyyB4sigzvUww4WP5NJ+eSnXEpjiht6HKW6ptfgHl7+XLv 6NnbrWDfXzNY62UnzW5yOMd63/qymxxfuyafQ4go8x2ZHPA9qwKwZ1PQJSZV3Wy/oPgn SKCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445466; x=1691050266; 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=vjqO/ZPr/Go39gpx6DVg0WzFepitwPif37hI1XuxbyE=; b=i81MPiUepArfRzslJBOGroOUPBqLVovchg29IdzfUyG6CrTJXfMpIpCEZon66sVgra r8i48DFZVQ7UTk2rSSiSYXRK/osafxvngwSfCvCWImm3bvyw1PI89i3Uzmo96b6wTti6 dqAd254GfnPGQsm9yK63He5F1gA2drVMdGVl6qR7ktYYj27nzZPfwhrl5V7LF05TOqhM HIhVtwgS6SDnx+mMpm44EB+DcXvHjVovseGVSXg2FqszWDawoq87qDQQ+gZrFuigYb8v B1cQaqHo3dgfUHJ7h63MX+I4jWhsHl89MBjYIv7L/OpkWYo2oORMQ2ugKqPiWOiS9l89 vI1g== X-Gm-Message-State: ABy/qLbc6Qmc2/seHO1EbUWIzZGajNM58h/sfMvMxt0AnyRn/c/WAOqd i5R9gWGC7XKaezr2dlS82W9Nqg== X-Google-Smtp-Source: APBJJlHsQWiMeK1ZGCoT9EMqzV36W3zQjtsLKzuNfdQAXhrStS5DTpZT9lorCJhzpRLn0tDb83CKIQ== X-Received: by 2002:aa7:8615:0:b0:681:9fe0:b543 with SMTP id p21-20020aa78615000000b006819fe0b543mr4626555pfn.2.1690445465777; Thu, 27 Jul 2023 01:11:05 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:05 -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 Subject: [PATCH v3 26/49] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Thu, 27 Jul 2023 16:04:39 +0800 Message-Id: <20230727080502.77895-27-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 X-Stat-Signature: mfpkhk5eiu93g6b4teku4uagj1bpxhbk X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DF0F7C001B X-Rspam-User: X-HE-Tag: 1690445466-794163 X-HE-Meta: U2FsdGVkX1/1z4zIw+AqSnppxi3FydfxtQDQN8Tk29TxhHGeIR541G9IBGdxoOFYXkkLpxHhGd6KuvzR5U6gXsYHBhULqyovwWEWquij5zOcXBEZBBXeK1pvEGmy9zW3baCab1NPYEievMgoj/QaVu6BbbImVsON6mY08pRNKTPOMoJbakZaClmBVJSc5FBw2we4LO6tjGxIGDZDxuK43HVFNBc4UntKChohUZ8IqZVt2RsR6HCWiupF/itoc0oNIH/CAJyCmCiQq5JEVwrhoHkxxSnGVDmwnu2m0Hk1K1iG9E7TRnZsHtaEbiCdkZjNp3miDHqy0jiU2Odgo8vtfuALqVhrmzNuPlOVwYnC56NwM8Q3fzSx+WwDdApEg/uoEybXpQZsNZ0nm9rb2QNUHj4CdIDygjMk5/OeraEzGx0FQczx0fgL4ygqGkZExiVaW06WV+xHxxhhFNmNTdpr4iqpC42DeX1ImSl6As79vQn+yniyvguEamXtnDncRYLkajCgV2Yrg3cMl2ZT56jJB8Trj9Zf0iN4k1Tx5VGDL+J9ZlQSuBG46e+9nfKzhWdfqAWoRpevLtTPwlb41/s55XE7hDznpBTGRUL0jE7Kn4o/oPJSwNAHp5ZjiPvF/BjZJWMPDd5lz9qfaCMJyuBNbEVgdGaoV1KJHfG+2ZDyZRQ2dkz5G0SL5WPNbsiI98gmo9rw1FeDR3qHA0hgqoeak2txcl/3jnLP4BPDJO4moOUunqSRoSWwwrrHeVgPkUP9NQJOjXhItz4uDelsv+pPKFO1/NY5kKJtm1mm+wGDh54VLwz0fb3id/0gRFPBQzfFf3xvAid6SV+qzQmXyE6vynSrXIkwqpKqiDnpAD/KEUgSlxGy3RG+R1rPk8EC+BeBtBnZ4fjxqj24rpp+M/ilxy6/PE3YpEbfLSsVwQ/jwjCzP7lgnB3Fu5Hx8xuWEPyEcKz8VTMZoPnX4/Duq4f 3CTQPEx+ pKNWa2IbK0yfUeHwtQb4F1oCfoXVyXpuXaS3SQDlzoTEg8RfmItHwuzgK7Z8/K1ZSDRUPmvY1IZEW/bHhpeCQQDOxkMkc1h32QtSRYqK30BWbFcDdapAeJRh71jUR4/US1a45M08ZwBRtX6lA2SxND2EUr7+BPPo2/NzMGoYCVSkEGtQOXAkBurfqhGeJ+J1cQTTCt/N0eizfQS3jn2XixMHgu6LWLnrkHjO6UJFJyTUwZ1goehEu7RuZ9dtDg/bxe7rS2Nkgb4dJ0qXEcFDDTBbO5yhWywcjJasU9/griSTJ6NAfYTEsAA96fiCmmL3CH3GtW6xR8w8nBXBaGPTaRO/pdPt5aPzJsppxriBVKL3wa2vMnPDbplQH3rZtY/c43k1cKflF4ztQop+hXvEpUSU+PXXpgivlHTzQQjfN5mWrWb7mPl7SnnD8AWHE/FginXONc5JbXDFOTEplcI5yQGY/ym4SkSoA3zxG 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-panfrost 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 panfrost_device. Signed-off-by: Qi Zheng Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++- drivers/gpu/drm/panfrost/panfrost_gem.h | 2 +- .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 30 +++++++++++-------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index b0126b9fbadc..e667e5689353 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -118,7 +118,7 @@ struct panfrost_device { struct mutex shrinker_lock; struct list_head shrinker_list; - struct shrinker shrinker; + struct shrinker *shrinker; struct panfrost_devfreq pfdevfreq; }; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index a2ab99698ca8..e1d0e3a23757 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -601,10 +601,14 @@ static int panfrost_probe(struct platform_device *pdev) if (err < 0) goto err_out1; - panfrost_gem_shrinker_init(ddev); + err = panfrost_gem_shrinker_init(ddev); + if (err) + goto err_out2; return 0; +err_out2: + drm_dev_unregister(ddev); err_out1: pm_runtime_disable(pfdev->dev); panfrost_device_fini(pfdev); diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index ad2877eeeccd..863d2ec8d4f0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -81,7 +81,7 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo, void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping); void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo); -void panfrost_gem_shrinker_init(struct drm_device *dev); +int panfrost_gem_shrinker_init(struct drm_device *dev); void panfrost_gem_shrinker_cleanup(struct drm_device *dev); #endif /* __PANFROST_GEM_H__ */ diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c index 6a71a2555f85..3dfe2b7ccdd9 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c @@ -18,8 +18,7 @@ static unsigned long panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct panfrost_device *pfdev = - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev = shrinker->private_data; struct drm_gem_shmem_object *shmem; unsigned long count = 0; @@ -65,8 +64,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj) static unsigned long panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct panfrost_device *pfdev = - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev = shrinker->private_data; struct drm_gem_shmem_object *shmem, *tmp; unsigned long freed = 0; @@ -97,13 +95,22 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) * * This function registers and sets up the panfrost shrinker. */ -void panfrost_gem_shrinker_init(struct drm_device *dev) +int panfrost_gem_shrinker_init(struct drm_device *dev) { struct panfrost_device *pfdev = dev->dev_private; - pfdev->shrinker.count_objects = panfrost_gem_shrinker_count; - pfdev->shrinker.scan_objects = panfrost_gem_shrinker_scan; - pfdev->shrinker.seeks = DEFAULT_SEEKS; - WARN_ON(register_shrinker(&pfdev->shrinker, "drm-panfrost")); + + pfdev->shrinker = shrinker_alloc(0, "drm-panfrost"); + if (!pfdev->shrinker) + return -ENOMEM; + + pfdev->shrinker->count_objects = panfrost_gem_shrinker_count; + pfdev->shrinker->scan_objects = panfrost_gem_shrinker_scan; + pfdev->shrinker->seeks = DEFAULT_SEEKS; + pfdev->shrinker->private_data = pfdev; + + shrinker_register(pfdev->shrinker); + + return 0; } /** @@ -116,7 +123,6 @@ void panfrost_gem_shrinker_cleanup(struct drm_device *dev) { struct panfrost_device *pfdev = dev->dev_private; - if (pfdev->shrinker.nr_deferred) { - unregister_shrinker(&pfdev->shrinker); - } + if (pfdev->shrinker) + shrinker_free(pfdev->shrinker); } From patchwork Thu Jul 27 08:04: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: 13329215 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 80701C0015E for ; Thu, 27 Jul 2023 08:11:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F3AE6B0089; Thu, 27 Jul 2023 04:11:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A2E86B0093; Thu, 27 Jul 2023 04:11:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 091DE6B0095; Thu, 27 Jul 2023 04:11:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF3216B0089 for ; Thu, 27 Jul 2023 04:11:20 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BB83E1204F7 for ; Thu, 27 Jul 2023 08:11:20 +0000 (UTC) X-FDA: 81056671920.26.A2A6F07 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf06.hostedemail.com (Postfix) with ESMTP id D1FB5180018 for ; Thu, 27 Jul 2023 08:11:18 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XMYYvlyX; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1690445478; 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=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=snScBGekjPR1OWxja20uDQ9Pr0Qfm0nS8GTTwC1ONcuVI8TiqAhjJAJ1soKUZoXzsMPYRz SZAJoHR1xkvuqNZp0G16X6vc/CDXvtSmZQo48KRrO1Zx9xDlgXc3SJuv5O4pS3CPKRAnyI 5C1af6r+L+1e2sfzjMdlY6rpSnxyuFQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XMYYvlyX; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445478; a=rsa-sha256; cv=none; b=MaKzKo8gPxoP+4FkYK9ZVSAQD6MW3BppKsPSZNlLuOL91bB794EKpzIZcY9mItUJz8tI4v 54ZXa2LpQeIrxu9QFh8rEiInf4e/sPV5QDMBQSYP0KsuHp97f1Ql5uJB8vIdQKo1N6FeN8 MXzc244pTnHo/zvUZa7oZOsMnSmVZQk= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168363b3a.0 for ; Thu, 27 Jul 2023 01:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445477; x=1691050277; 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=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=XMYYvlyXrTmu7TBUMUrS0fAERGM3ULbRWCn4in2BRNinhRwId1ryL35VoKr2h4Rx+U HjLlRWIKGbBKN0lkokdfiXe7DL4/cW8JhUixM/OhO46u6zDYby/ZSHvD4zMfuAy6v0wa kMUIVYEZOCmoajTRWB9O5pPKf2KXDL1RA9QX/iWGDKdd+7AiEQpaXll5+7XF5hXMtboW QGfdfOEZoiLr6B07ra4S8ESol/cU0lfuHqis0vxsY6ajpZNCyt33YYUETwhkXmLJyVVM wWI0H3b2jkyty5FrIH3eGt0u2K+zpCq6JQc2FhUeW7es/kOOMNTlHxQiuG1Uqt5RUvfA 07oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445477; x=1691050277; 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=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=EUI+dOR99GUFMSEcamD3vywqDHkZ0QbxfumPA6cAIH0YSWnwzZzkt92sk4DjzIPvPg EG/vyelBpGXerwN15hNMXxi8tIxNE1p7rfLr+FonK9ete0YsGAADmhDriP+nhkFEudI/ Q0FrAcjMIe0YSDh+v7F30EdHXfWca06pWSPNDfFnA6yITDY8gjhkD+nev8SPJbrNOr9D 6/x71v7AdSUALZDup3lFVW7xvGyckCLjEjkZ1iCCZHQKN6xDTHY8flaWJY5XjgP/lIOv E8Xe7uEKOo93BHmriu1YPuMLJERw8KDC35VzS6nh2ZWR6HvTWyEwJ380e0q8Fi3mmRUD eCOA== X-Gm-Message-State: ABy/qLYbmswipHThLqgN6eO4Xy6AugXjwKWoBAbnQMPFmtrwWUivBLvY doZ2uqW22JKpsDMJa6xv9eZj3A== X-Google-Smtp-Source: APBJJlG87NINI+/+i4SJ1KgSTM1EJ+JwVd/Dy5o7cICQ6coQ1cuBExOC2izM/xbO/Jy48XOYsOKRHA== X-Received: by 2002:a05:6a00:2b90:b0:67d:308b:97ef with SMTP id dv16-20020a056a002b9000b0067d308b97efmr4590349pfb.2.1690445477689; Thu, 27 Jul 2023 01:11:17 -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.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:17 -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 27/49] dm: dynamically allocate the dm-bufio shrinker Date: Thu, 27 Jul 2023 16:04:40 +0800 Message-Id: <20230727080502.77895-28-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 X-Rspamd-Queue-Id: D1FB5180018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 89m63psy8h8nzbapo484oatidd6h7w5i X-HE-Tag: 1690445478-142149 X-HE-Meta: U2FsdGVkX18LsE3D4MXX2gvTzWCjon/SCCP2/RLLKyLwhL3O/fvkGimUByYfpL38NDAKeuatvv4N8wN2u+N4LrH1f+Hl31H6h8xgTxWqHM+RjvvRQ+mqBURVAfMaIhOeVmKryIeGmHEnmWFR6KegbwO3Zpu4SvoZZOhdU/r4AaPX+sD9ErqCzS5pcFIrMZkbMJQblygiPBhIuh+K+I1ZttbUWXSy0O9o/vqOvMjfhPkbreAqCfT7TDGWPwW7Drg1Qg7UPdzHryCqHMSQ46e6X+HGMVT7vC3qZGE+HVsXpKHSfxzUzaXvnrVrYkJgXdOkzsQ5RXddFxFI/AGAUibMC0bN0iP9fss9KuQi16r4kw0uIhBYIM4foK36Y4ZuVafpHYM8kNfDlL1DzbZmwTKI+8KsIYCZFprgTswXEZCIMNLryipdIR618pH/46ysmkmf9yoMVT/DZSttYtm0u3YaFY4GQfpa7u2dUOoUrFu8iqcX+wJw1coGbrA9CXBl9k9pIQwsP2jI1wgw/D7WlvUcBJ0RTQHMX+96u8eC/777G+NvMA0b8B8AkvdJ1Hl7jZfR1H2UxHOcVhh6kQyrmQ+Ssu7NwQ2+365uuC9ksofM1uL2ZjmV9HCyt4YWojlJXBwdmQZdc0ftkcDc+UcJeWRiu5Rx4QLfOnPFtTs/buaQsfe0Py7hd8s2GxkDkElr3iCdQOEJZ5qAHysSo4OZbFXmCKUoI8f/maLSDo032ODvV9cevlH9y9nHKhqmGHcUm9OEiy9fz/Rr+8UDODF9pCx5L8uCen/kY4Ql6sZuVV5tpq+ickLb8pj7zZLNvZbhrF7A7pwpk5MqtRSQHhzSE4ZbrP2hGoRFNyPRRdKI22SuRW26EKVg+kVBddVWZrbj3rjB9mp/sIpby6I6xCjY3Xg5D25+cTVVVmffb067Tp5NtY2e2f8j1ViPNHdPiESMDo0MLO/coer520ligIhpjc+ NNcq8ucJ AeOoJJATVSKaIMIN8ZTxsezVZNjxTUW8tbkbV8V32VOT78JC6vRIVWCqPrxyDh+Y3Oho4yFQTh7rXSYKiqrW6I3IuMMBEmjrWIbTF+rgtQCGWGCR3CHYlb8sSYKOh4rHI4YKOABT+j6CUqNd5k3kdxlwSuln2II86Ag+8Rx0l7fOV9WDBPkPtmzV329UlCpCEyruzn8qRVREYxkUISFisKiHn0ExWsr7l9s+UTtyKXEwlP9YugGsL1ZyhOhawJ3BtngoJAyPTpEPpKGxIyPV/Uhh4jXv5lTQWoRSkOVWc3KIgVZmX3ad2bb3UL7jq+kcpeKIzBsuZV5gOE194aJmsq7+ejHeW5q7tqVpm+jjPbRhrGEVBk5KWTj2IGCjWJks3gRppb/he57yR/cwAMFC4oPwOy5wNhY1hHMfc 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 dm-bufio 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 dm_bufio_client. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/md/dm-bufio.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index bc309e41d074..5a9124b83d53 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -963,7 +963,7 @@ struct dm_bufio_client { sector_t start; - struct shrinker shrinker; + struct shrinker *shrinker; struct work_struct shrink_work; atomic_long_t need_shrink; @@ -2368,7 +2368,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink { struct dm_bufio_client *c; - c = container_of(shrink, struct dm_bufio_client, shrinker); + c = shrink->private_data; atomic_long_add(sc->nr_to_scan, &c->need_shrink); queue_work(dm_bufio_wq, &c->shrink_work); @@ -2377,7 +2377,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); + struct dm_bufio_client *c = shrink->private_data; unsigned long count = cache_total(&c->cache); unsigned long retain_target = get_retain_buffers(c); unsigned long queued_for_cleanup = atomic_long_read(&c->need_shrink); @@ -2490,15 +2490,19 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign INIT_WORK(&c->shrink_work, shrink_work); atomic_long_set(&c->need_shrink, 0); - c->shrinker.count_objects = dm_bufio_shrink_count; - c->shrinker.scan_objects = dm_bufio_shrink_scan; - c->shrinker.seeks = 1; - c->shrinker.batch = 0; - r = register_shrinker(&c->shrinker, "dm-bufio:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (r) + c->shrinker = shrinker_alloc(0, "dm-bufio:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); + if (!c->shrinker) goto bad; + c->shrinker->count_objects = dm_bufio_shrink_count; + c->shrinker->scan_objects = dm_bufio_shrink_scan; + c->shrinker->seeks = 1; + c->shrinker->batch = 0; + c->shrinker->private_data = c; + + shrinker_register(c->shrinker); + mutex_lock(&dm_bufio_clients_lock); dm_bufio_client_count++; list_add(&c->client_list, &dm_bufio_all_clients); @@ -2537,7 +2541,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c) drop_buffers(c); - unregister_shrinker(&c->shrinker); + shrinker_free(c->shrinker); flush_work(&c->shrink_work); mutex_lock(&dm_bufio_clients_lock); From patchwork Thu Jul 27 08:04:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329216 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 DBFD6C04FE0 for ; Thu, 27 Jul 2023 08:11:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7989F8D0002; Thu, 27 Jul 2023 04:11:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 747EB8D0001; Thu, 27 Jul 2023 04:11:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6116D8D0002; Thu, 27 Jul 2023 04:11:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4EFD18D0001 for ; Thu, 27 Jul 2023 04:11:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 294E3804D8 for ; Thu, 27 Jul 2023 08:11:33 +0000 (UTC) X-FDA: 81056672466.24.B2D95E6 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf07.hostedemail.com (Postfix) with ESMTP id 5BDDF40019 for ; Thu, 27 Jul 2023 08:11:31 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lwOoY+Od; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1690445491; 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=ze2BfjPj3zI6XK14aBXxwpj9cG5VKS+QoT9VkWxAsig=; b=A05lryWCsMnVrhTw9eHOZLH7t5IDRANl7yTUZBMpACVg8+NOhNR9TM4efE5zJ5OtxIc5tC vIZCnGMl2pXHEDNliPJKw5XlU80o0s34/Xbg/K1vhSB8rtUIp9k/+rAv3CrbJ3zx/QnZs7 hSRKV5sdWmJnAILV1leeYyCigQMA8XQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lwOoY+Od; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445491; a=rsa-sha256; cv=none; b=XdV23NEyryM50IABlgvXU9gBSuPzEOQjS3odREKk21j++LcceUAm5ii6MioImtLx7NC4K3 c4gYUOMcd7LoUo3gNTB5AAnAAHz9Lbz5LyFwdasueLvTYu4IpuZXDCdI4kEyUd+ZKN6GGz t7rF5Wwk1vWIBTRJDJYKmOYXj4J21OA= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-682eef7d752so204439b3a.0 for ; Thu, 27 Jul 2023 01:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445490; x=1691050290; 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=ze2BfjPj3zI6XK14aBXxwpj9cG5VKS+QoT9VkWxAsig=; b=lwOoY+OdQN9yyaycuuDe1xOBPNuMdpjPWf9iVdWyTJX4Rze1Ujyu7FqyyXfPUD3aU2 0geNSiBV+SjLplmH7ILvbtRHCHKM3vLFmOVDmsv1BEm9fkWkTRAM1imR53z99mDpf0IW ffoAdzAoMkEyhpVqT3oRFQGqTsCjJOMqkqnQ0DFV07QdT6HdoSrpGoFduwBz2OfpOwFt CWOX0mmKGcSRamco0Cg7QpPpz6Lx/kpTjodIKj6Sfbh0QvlZA2O3b8FhSM1hAbz32D/P 0DhVwgLc1Xu9esSsJfTXPYkz1XSyCT4LoDf/9vVVRpeHu2USWPZ+XNt9qGqYRzfEx2BR Y6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445490; x=1691050290; 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=ze2BfjPj3zI6XK14aBXxwpj9cG5VKS+QoT9VkWxAsig=; b=ZhWcJK80UEbekoZrE3N1QaFxPcUNIPXZ8T9b2A2QFW8YfxOA/Kefa1SGLhiRCFas1i Hbk6fbjWIiHbVAwjdcnxZ1isctXFZh2LNn5I20SO6576lf9NVweSqjNPdlpQ9dZ1VSL4 JTqqEd+uGDGqJf8wXOt2jIL5Za40CYFTl8b0JQl7Y1LsseME+jKGuTdVbGd3940XkPHA sXLOP5vPi9IpZxXUcVpMWLpFTvDTWPJdGAR2hvPEuPahfn0TfWsVEpw6WCWdbkAhBpJm v4VKq9L4pytiNtU+J2IO94Ld+nh8bbK22mtfbW36sJZgEDmoiqZjofHqj1EjAdCKLZd/ dFGA== X-Gm-Message-State: ABy/qLZqDwYs+FkoKrX6DY991w90CHajyx9KQ2kbKsfPxGHaAr3Bygbz YAoHI/0zPsnTO9qeZSw7Wf7+iA== X-Google-Smtp-Source: APBJJlFMZtECqV3NWJubuagzux89byKCTiavknA18umD2w/BadGADzl49oXppHX8YppKwxO9L0rdOg== X-Received: by 2002:a05:6a00:1586:b0:67f:8ef5:2643 with SMTP id u6-20020a056a00158600b0067f8ef52643mr5208150pfk.2.1690445490190; Thu, 27 Jul 2023 01:11:30 -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.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:29 -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 28/49] dm zoned: dynamically allocate the dm-zoned-meta shrinker Date: Thu, 27 Jul 2023 16:04:41 +0800 Message-Id: <20230727080502.77895-29-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 X-Rspamd-Queue-Id: 5BDDF40019 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: k3uwgoi94itaryh7wguya8cqgnxi3x1g X-HE-Tag: 1690445491-676706 X-HE-Meta: U2FsdGVkX1+WtlSe50+kWmq9TlpMO5XsllUPX7R+UEEa9M//PVU4Ged1mksktFlemG869XG1eYrunlIinpq7cFRwPBwLiU79T0hZsLCAj/Lwm62Tu7FrDILDE2hBZBr/6XQpc95uT60rNh9SVf7fBiSUxIWCNCW0DA4WdExS+1x3y4nstxxuyJJgezAll07Hc1Il7J0Nje2NwQ9WrN6Wq+6/Tap9w6SjG4DUex0kyB9CrZ+Lq1m3ZZYxsdQSXdoJXWaqaXeWEdraXyRLMftXDt9KIa+rrqzkIg0kUQWbApYbLWlGTK26k27bwlNeKmkPajyv2zq/DH0jp3hxMABX5VKAN0EGoW4rgywhuVn/KBTHmJ8VGW8YWRPEJCxI+J4FILNcIOxuTKp0Q426FBBVpBIXFDJkyEXUscjfE/a2ggX//XSU+rJeKwKg8EYlIrKNN5rkmXzPUyn7ahdf8buYEuN5ovqSCEcVuE+K5vttdiZlxEQmgaZ852XPXUTzjweb1iny3g/0Vr1xYPwU3WKSBSgKrDPK/dc95A6Q6PR+KKkKjhBOdn/OkD9dYwEC2Dzaad62lAcpb26L/gcZfrJVORd6gou0LNFKvenFfKY8n8swAAt2tIoBDQzsKq9M2AsCXf74l3UEhrd6fw6/fGYrFbC5hUbEskUzuBMLuCUIX0/jlkCuZgby9J/qnsWwKLL63tr7n6F7aFWQAoTuLl1Pyte4eDO1QL+a7FB+OEpMFIkhBXEOLT9f+WAg+caUpe0cCn6B1ZfM8KAhHA4xyZ8MHYVcnL86jrR87tFD9xbwS0u1XwMJaJ4Lm7k+0fsGu5+Z85ls66cQ19rn0TOh4mcEmGibgbXcgDj5JGSlyE9E4GSgefMbH92z/7gfrejHdEG7pLamMSeRYz+m5f5nGasSoYVe32TS9QqPM9OQc+Qoob/uG/ZtSYam7cyv3unjLT/fgUJcNx+I0fASQ7S3iEq 2gsVVzFr rBl6g4Fob1N9zOFGOKPM547ql88eaOIJYNKJcvroVFziTohzHEHJfhHSXeVY/KDLudZsEgFjfiTi8xW9CCZbGX0Lpy6jH7grjvNHz6Mcbrjj262WcVX3e+YOcfZhhwmoatg6dAG51Dlef6iujrfNr98jtuFoj7fHEDUPEjpQOAmaS2sn7bxK/Pg3OEpV0qsOtXrfGGjJnZDLfsl31vuSyr2/VcWxXLH26QtHgZcyVCUtV5jFIjYVZZXQg4vKoX8j0cpp/RNDcSv4eoiOCxlrSazhiYEjtgn+rdQcJWF+imAzi00zzJ7k9TPgKtP7TDMR0hOEUenMpRC+oODowznLDpfNKgpTfGQz+Fr4D0pRhN7tJo+8l2vSxWo7l91Gosti1WbiBClFNe4OMT0g1sH3fxRvDiahCLhbfOF8e 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 dm-zoned-meta 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 dmz_metadata. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/md/dm-zoned-metadata.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 9d3cca8e3dc9..0bcb26a43578 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -187,7 +187,7 @@ struct dmz_metadata { struct rb_root mblk_rbtree; struct list_head mblk_lru_list; struct list_head mblk_dirty_list; - struct shrinker mblk_shrinker; + struct shrinker *mblk_shrinker; /* Zone allocation management */ struct mutex map_lock; @@ -615,7 +615,7 @@ static unsigned long dmz_shrink_mblock_cache(struct dmz_metadata *zmd, static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; return atomic_read(&zmd->nr_mblks); } @@ -626,7 +626,7 @@ static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, static unsigned long dmz_mblock_shrinker_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; unsigned long count; spin_lock(&zmd->mblk_lock); @@ -2936,19 +2936,23 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ zmd->min_nr_mblks = 2 + zmd->nr_map_blocks + zmd->zone_nr_bitmap_blocks * 16; zmd->max_nr_mblks = zmd->min_nr_mblks + 512; - zmd->mblk_shrinker.count_objects = dmz_mblock_shrinker_count; - zmd->mblk_shrinker.scan_objects = dmz_mblock_shrinker_scan; - zmd->mblk_shrinker.seeks = DEFAULT_SEEKS; /* Metadata cache shrinker */ - ret = register_shrinker(&zmd->mblk_shrinker, "dm-zoned-meta:(%u:%u)", - MAJOR(dev->bdev->bd_dev), - MINOR(dev->bdev->bd_dev)); - if (ret) { - dmz_zmd_err(zmd, "Register metadata cache shrinker failed"); + zmd->mblk_shrinker = shrinker_alloc(0, "dm-zoned-meta:(%u:%u)", + MAJOR(dev->bdev->bd_dev), + MINOR(dev->bdev->bd_dev)); + if (!zmd->mblk_shrinker) { + dmz_zmd_err(zmd, "Allocate metadata cache shrinker failed"); goto err; } + zmd->mblk_shrinker->count_objects = dmz_mblock_shrinker_count; + zmd->mblk_shrinker->scan_objects = dmz_mblock_shrinker_scan; + zmd->mblk_shrinker->seeks = DEFAULT_SEEKS; + zmd->mblk_shrinker->private_data = zmd; + + shrinker_register(zmd->mblk_shrinker); + dmz_zmd_info(zmd, "DM-Zoned metadata version %d", zmd->sb_version); for (i = 0; i < zmd->nr_devs; i++) dmz_print_dev(zmd, i); @@ -2995,7 +2999,7 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ void dmz_dtr_metadata(struct dmz_metadata *zmd) { - unregister_shrinker(&zmd->mblk_shrinker); + shrinker_free(zmd->mblk_shrinker); dmz_cleanup_metadata(zmd); kfree(zmd); } From patchwork Thu Jul 27 08:04:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329217 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 0A218C04FE0 for ; Thu, 27 Jul 2023 08:11:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0A028D0003; Thu, 27 Jul 2023 04:11:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B9A08D0001; Thu, 27 Jul 2023 04:11:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 881938D0003; Thu, 27 Jul 2023 04:11:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 790428D0001 for ; Thu, 27 Jul 2023 04:11:45 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5179DB2A37 for ; Thu, 27 Jul 2023 08:11:45 +0000 (UTC) X-FDA: 81056672970.21.0A5AE18 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf15.hostedemail.com (Postfix) with ESMTP id 60F15A0010 for ; Thu, 27 Jul 2023 08:11:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SGV84iDT; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1690445503; 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=LaFX3BwmrpvhCQ7689MuoFj6fWFWMuerWJZNZNxWVVc=; b=YJuBeNeSUZZtOf/OTZ4qb1pU8+Q/4a/86wGUoWIDE6rs37tSeo9DjaVYiu1obwrJ8t0UUV 6PYMPT0ZkYjXZ/zVFbqyEqZTUOouX8O52UDgK1b4AWtEEck4vkRgowk1lIBNNPOFH31pfu orQBZrs5mc8zRxcMQC2j2hvKXA0RvWY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SGV84iDT; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445503; a=rsa-sha256; cv=none; b=ebzUGyeXSn0aFFikPFjeEs7skt5ECYuwpJDZzNJ9RJ08ah7Ze5C7fOZF4Lsva5nOFOjxN1 nDhJiGeXT/3+4o1hpZJ68sXdq/u9hOh27xt3OCbsbAphqkho6pr6TCdbtWZNNTxxF0WIFH aTAx/F368KgeoAH8ISIFdt6XJwidV/A= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-682eef7d752so204501b3a.0 for ; Thu, 27 Jul 2023 01:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445502; x=1691050302; 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=LaFX3BwmrpvhCQ7689MuoFj6fWFWMuerWJZNZNxWVVc=; b=SGV84iDT12fuj4KQ/vgxpHx68bD/8JsYSa9nhb7ntFAq0TKpEUCTaHREzmRsJ3Oz9G gFKmoptXd+Bze48vx/wk2NbZ7T10E7S2MEqYjOuFeG7krpKwSKpfVHBIQRglXfDWTvzO H6VjPKPaTyQraf7CXaxRYntDfW/rFmDGA8pIc8wp3mkyDCZKtDmTVn+WhnbJ9UTHRuGw cfWrmdeiaPvvoPdILYK4+expmzf+8d5vjjDAS5qG8jY/gHHW1jvZoSyULsapwlJ7yOSa R+fxk2s2E87YRuuXF3DsPLATcyScHTHvPiXBlY0TGTmF0pFa842v0dWDdf9orTc8Pn3s TgHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445502; x=1691050302; 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=LaFX3BwmrpvhCQ7689MuoFj6fWFWMuerWJZNZNxWVVc=; b=ChE8JVc0N0aBs9w9838lhwPgDnm/eMYnLYBcHhe+J09p2ZyK4XQdXJRsvCJMEWcZfg 08oYqtDsWUdaw/uzzz4zD4wMgYysZmmpaMOwse3Q0VxdCYOhKdkyGWimmIy9BbnWEaU+ tNKLVXl1Bp1SvyP8fN0rXaS9XAeMPNQDEk8mkWieyXigXOTe1RBczFkpecp/FJQtAfXe jZKpLMlp73GuqkzHdObKcPnWZw5AFtBVvEU+KMUGNWhJ1HjCDzlBND/aLGzfGBoupARO uXNWfApqiXoSUq+IMKHAmj4bBdcAptTJZi3UPk5HR8/W8cOWH7utKc36f21VK6DlzlEh ywTA== X-Gm-Message-State: ABy/qLaCJBrmigmA/IGISmn09SyREDnY/QPoSpveB51ON3Tnpg43BrTA BZVTeodXomi+r9mrde0r4PL9oQ== X-Google-Smtp-Source: APBJJlE5krPFtX55mdmbm5NUPWWjP9qjtSRaT4qUAQtTa6jtnXVyWfbzlnq9LXdP1SlmgTnMsVycpA== X-Received: by 2002:a05:6a21:78a8:b0:137:3eba:b81f with SMTP id bf40-20020a056a2178a800b001373ebab81fmr6016028pzc.3.1690445502183; Thu, 27 Jul 2023 01:11: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.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11: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 29/49] md/raid5: dynamically allocate the md-raid5 shrinker Date: Thu, 27 Jul 2023 16:04:42 +0800 Message-Id: <20230727080502.77895-30-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 X-Rspam-User: X-Stat-Signature: zw5i44hr8pw61wqs5fynahfr9ripj8z3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 60F15A0010 X-HE-Tag: 1690445503-400997 X-HE-Meta: U2FsdGVkX18gakWlX86/vQ017vf0Hafom+gxJOQu4MhqqAMVOQGX9q+xXa2k1isJERiyPyXlyYA3CNeHaXNNS6r42y1mdbOGOgs1xrj2rgKxy1se0BsyspaPsLmFxEPrUHzaJAFNQxmFAi3HIlq7RpZS8OiZKbHLZW6fWpsrzt6uGDezobTq+KlgPQAUKae/55jIiTd/6HhD/ksLn067bFm10M7Lef/TcRHvKy1F4z61bmBUw6efudkHQrOFz5vSYg0PYjMYviyoD4wXNmCqTPGjIHtB3hi05NrUe95eWpoaZjwlTS6PQFpc1duuUWPQB0qaoGIncoe3To5CB6yYExfErPSnsJnn2H10VS+LvwhUjOF8zYN9Owt0lr6ZPX3ijsJlici43QidbHmmJd+B83MHPHIzQCJ4jm17h/EGSGLGzgjX0BkjQ2mvzAiIM0V6irfx5aM/Py9dxAqPYGQF8O0YyHl08Js95U3vQwH0Zlhg5PSnuTXqDXfv/pgJp7fCyg171RVWP02y//c7ilXJEvrwCB4+qu8xHeFGmtNQ2pSjwtjCpZ9Up2qLMG16t+3Jec8L0IhJ8jKbBZBF2lXRFNnSzEWEUYXXSKfcVpQopqoFX0TzFDPYcX9N6NCB6wHhbpd+uswW99DENZtwtg5DlAkX6x1yBpNxknhrtTXoDO1rVeAfKlz+SzxqrGT2Hi57cEM0jnVVKO+y9f9kYEkKLn9yjFxu5StUZQLFO/7ZJfboSc4mjtxkmY+lBZp7ffoZ914AmuwflMXkWRdK0hNxQpmQcpDGzPKWq7KeecRQPGqGO8T7dHANokjzfjjth1sL4uOFXs1PtxrAzOxlgYDWXbFLZJ1pLk2eSun8iKhE4wpuP0MWj7oXJZJjTIKY1bAWgNlsrU71MnSikqsrMqz3RVPoHlf6lXZI49lBtqJ19kVscYAQMdbyG30LezD4JZVggbGMj58k++1uCLKntXr bJnPKRXO JO2eXjyyZ2AecXI7SF/M4zcoG33f4fgf3cpIElYkA4OTQZVzrXheIjUryKgjAohd6DjI5TR/t5gnfJD7DFMQh6Tzjuw1A4o8PAtbVMZ7LY4S9amvkYPovVDVCouVAT0rnCGpePKKggn12lKL8jm/9dmzmB0sk+5y6VqderkXe9ISUgyIiZTHI9G3Lp6MpnGtQzLZ6PCIczPcLXprfvUAVpimQlvvr9N18n1uydYMlij9CKZVfB4MGH6qVsdMwwS5hpjuFEZCVegw4ElVWAUMut/fevw/+/9l14u7UVstInUg5T60mgPPMS17H2uYgngPGPiuTycK5wOPvPwq5e/SSms2WEepmF4V3i0IHYPJMvzIrfdfzLZeqPEHRGrrF8yQRHqUKGXaTN7kPNO5wp+ErZfAUmuy6UqKPPsq+ 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 md-raid5 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 r5conf. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/md/raid5.c | 25 ++++++++++++++----------- drivers/md/raid5.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 85b3004594e0..fbb4e6f5ff43 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7414,7 +7414,7 @@ static void free_conf(struct r5conf *conf) log_exit(conf); - unregister_shrinker(&conf->shrinker); + shrinker_free(conf->shrinker); free_thread_groups(conf); shrink_stripes(conf); raid5_free_percpu(conf); @@ -7462,7 +7462,7 @@ static int raid5_alloc_percpu(struct r5conf *conf) static unsigned long raid5_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; unsigned long ret = SHRINK_STOP; if (mutex_trylock(&conf->cache_size_mutex)) { @@ -7483,7 +7483,7 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink, static unsigned long raid5_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; if (conf->max_nr_stripes < conf->min_nr_stripes) /* unlikely, but not impossible */ @@ -7718,18 +7718,21 @@ static struct r5conf *setup_conf(struct mddev *mddev) * it reduces the queue depth and so can hurt throughput. * So set it rather large, scaled by number of devices. */ - conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; - conf->shrinker.scan_objects = raid5_cache_scan; - conf->shrinker.count_objects = raid5_cache_count; - conf->shrinker.batch = 128; - conf->shrinker.flags = 0; - ret = register_shrinker(&conf->shrinker, "md-raid5:%s", mdname(mddev)); - if (ret) { - pr_warn("md/raid:%s: couldn't register shrinker.\n", + conf->shrinker = shrinker_alloc(0, "md-raid5:%s", mdname(mddev)); + if (!conf->shrinker) { + pr_warn("md/raid:%s: couldn't allocate shrinker.\n", mdname(mddev)); goto abort; } + conf->shrinker->seeks = DEFAULT_SEEKS * conf->raid_disks * 4; + conf->shrinker->scan_objects = raid5_cache_scan; + conf->shrinker->count_objects = raid5_cache_count; + conf->shrinker->batch = 128; + conf->shrinker->private_data = conf; + + shrinker_register(conf->shrinker); + sprintf(pers_name, "raid%d", mddev->new_level); rcu_assign_pointer(conf->thread, md_register_thread(raid5d, mddev, pers_name)); diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 97a795979a35..22bea20eccbd 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -670,7 +670,7 @@ struct r5conf { wait_queue_head_t wait_for_stripe; wait_queue_head_t wait_for_overlap; unsigned long cache_state; - struct shrinker shrinker; + struct shrinker *shrinker; int pool_size; /* number of disks in stripeheads in pool */ spinlock_t device_lock; struct disk_info *disks; From patchwork Thu Jul 27 08:04:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329218 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 B5541C001E0 for ; Thu, 27 Jul 2023 08:11:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 576628D0005; Thu, 27 Jul 2023 04:11:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 525B48D0001; Thu, 27 Jul 2023 04:11:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F89B8D0005; Thu, 27 Jul 2023 04:11: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 322FC8D0001 for ; Thu, 27 Jul 2023 04:11:57 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0546C1A106D for ; Thu, 27 Jul 2023 08:11:56 +0000 (UTC) X-FDA: 81056673474.29.96DCDC7 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf01.hostedemail.com (Postfix) with ESMTP id 0E9B540016 for ; Thu, 27 Jul 2023 08:11:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lyW6JZhn; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 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=1690445515; 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=7cqR4cS8FmCj5BmJe4BckgvILKu/fuVsr4BFabqQafTdEtA5OFEyXMua1oAXPZBUIc5oPN Ke6mtmS6N+HjNDwGjhFR5NFbiFIjrxit/4NYiXr19A+2yQlZ8aDC9WZvYcn5sbUODd55TZ 5Cf7YuUHOyXBbAIyb6geCphnJid8r6s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445515; a=rsa-sha256; cv=none; b=jaj1EbjqpiVop/+cq7JDXoTIc9V21YkZO9DRYZVlEp/k2dhG/+CEWD+T2ljx2ohvqE/l0d T3nBqOLaZubJxlbRiE3Pf2Vi3P8Q9No4ZGfSks+4gg30+uQkExAq2NnnRe9MdzQYAmrTzg xFKacfaYsNwrcl828HzadeHeOMFZZHw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lyW6JZhn; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-686f6231bdeso113526b3a.1 for ; Thu, 27 Jul 2023 01:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445514; x=1691050314; 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=lyW6JZhnNvjcNaB7GqN1uV2v79yXaXII/N9CUBx8Ax42gYi0bx7SyKZlp7ota5OGyc xz3LFUjbyjINutpLynebvvBHzacoCfStfnIiREC/M8s52LB/S8PozvhLHL2LaKHkf4jF 9DRdteQ8XPpE6p0UjhjwxUS6BE53kxXxgyc4CEqj+ED289GAULMwnheYekYUqCpohGt5 Gmsuq+KFKYVL89VZVFvc5W/65nqN5yxt+BmUFxBx+3K9aBUApmiSNjlOWSgfmJvwi5CC 101OAH2cZQROpO/yBfNUpOitoioZFpWL88ogBko0HO5BvQ0gPjZ0smA8q12LAj1M0Z4O lOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445514; x=1691050314; 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=SUv7dihn9C3UR1Di48m3Ek8qh0FOWqKNEV1NkiqONDJxN7b2W10X8IcST7cMs0hYb9 vMKypSuHv4NAi3EDvFEAwSLWNiuYFzLXYPJCAYUgQD8uqQH9ZmLlnUwsfRQqe7cz2Htp uIbRpel8ICqFKkATTM4ngp5+amxiXot/nyDdLPzLGeK4hCOWsjLQ6a5uwex4bXavrpCL iMADZ3uH4jgzSDk/Zu5jRcld4CF7iLNkjUXR7+DKf0KCmkd17MGeVF7XNuAoQLY34eUs KrcdITvUeBv21rS44MHl6TIKHjo3snwyYNJjGoeCzjV6L9V1HrLdnhjxhupTcsUQDHrl Htug== X-Gm-Message-State: ABy/qLYTWRG1oEiP8Ega/pNGWdlep1AFT9huE6kv1Cu5ij99lMi2+xd7 W/4f8TUmAp5LwihwXt8/ihsc4g== X-Google-Smtp-Source: APBJJlFvU3cjl1WLZK8F+guGojMG4R1fFJkvV7n2FNowsaFmG5z+7vBu+UKq72H6C7V5uf+meL2LRA== X-Received: by 2002:a05:6a00:4a0e:b0:677:3439:874a with SMTP id do14-20020a056a004a0e00b006773439874amr5204339pfb.3.1690445513983; Thu, 27 Jul 2023 01:11:53 -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.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11: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, 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 Subject: [PATCH v3 30/49] bcache: dynamically allocate the md-bcache shrinker Date: Thu, 27 Jul 2023 16:04:43 +0800 Message-Id: <20230727080502.77895-31-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 X-Rspamd-Queue-Id: 0E9B540016 X-Rspam-User: X-Stat-Signature: nqqhgpx1zq6ao9exg3eoy7rnk4azrdps X-Rspamd-Server: rspam03 X-HE-Tag: 1690445514-12779 X-HE-Meta: U2FsdGVkX18Z0TNCc3MF4Q7G/h/80D1CAGpgMuSwToXs0T94q4jbyK+FiHUc+gHUSw+x1EAmS1QGOeZZ15h94kh124TAxnho+hHogKiyR94f/KgqiX797DODF4CRTjUZNQuXB4xzN1eg9JxskTDKHaUHa4g+Jmd6K3bLc/o8N5ApF/IRBq1x8sCJ6osjHA1ywy2xmuAbtdpjN8vW5pkfS95iShcqTOpXRSBEH7UNh82t5YQfUOoP3+hjj8Bxv6Sm3+gAbXdcszP33oR2X2DE58dzDcw7x5WWMr33Wrlk+b9Of9V0wfW3l0l3lkuv5fEDfsOID9IR6K8izEUPvW47qhgHsQS3EMeA+6aPbbzSg3zz7BIG2mwFzSlBgciFZoFhru0/5wzcjUET28IG1kc4T0ZlSaO0rMjtZsvkvLx7T86/5sso1vSF7MPUADPzHn0gaBswTLGQrubs1hXyzW1GZneFeMflBA+afhx2NR2UUG2dK3A6ndkgp7eW6VE/7qTzF5VIWOgI6kGlbNFlE+fuQGVcA8LwNKak6Cm2MHs0ikwdCCuUaVI+g1eMkJFucwmsLpb3lRPqIKvyQlpCXQ5dQl/L+fgwCYvc7DjRi1f/vQZgTcS1MUG8cXcMq8rgwVyCSaHa11JRO4ApGE+gcCoHhhwft6K4wwQgKVePRX1WUKX5/nSIqZmG1xi8PFBXXG4dLv4FpC0THWvqxu8hfJjLzTvi2VWN3WCR79UQ9jdWhP9kFk7lkBToq92wSU2Me4AuA7ZPQXVUTqmLCZz/h463/8YH6i+6MfZlzQjF/tEVtCTbrflPQytLNOiy4mloJIdHNC2tfRSBXgJwwb1gqsMfBRbcEC4A9QpP0ZRvss+WGRkcY0OtXx7jE0QnIVIjLYXLQjNxeuFU/SSn4WcOiHfFHiXKv1uoIRmRHtJjXBgs8lpw6lgmovBqeSgmiWzlhFBi2CA+sSePjfPfCAZRGh/ wXI9juvz PcVIfpb9YWChMj2ZJMZuXOi38KZp/n2bzEb/NMa8giPo2sfAb6GnCl2B2KnMilIlBMVKQvJZPefr53LRLxGE3i+nDBRg+Pu6cM/Fur9gSLcrkZ8oaXk4IzjzifqoB2ypT1KacWH3vwCrxWxYPCq3IKeFMdoSCuA9jnL0SVsuTSDsBsgxq0AI+1UF8EpDwRXg6YrqZx2ZHuO7MWdtWEMqGGhYYpyv09y+Hgd7vDVq9itRrqouSVIZ//oLp8kLgUOHw0owiXnvtAwavj9CdhU35M2iX/OQhcrFDqkNINqzzPYH/bpAJrtIydq+WCWAVqX9sIjkv6qrYljRCb8DG9Bc7FNpY8Ye1VcH1EjKrzPq2LPlR15cU90Uv9Et99r2PIHZrM+4TmRDntM/fiQqgl1Jpk2H6B7HTuHasZYc0EdF1tAvBnDufH12QL0uo3iDbGepBzDblL45+1H8AmuCymaYxDGB3+Ib2XuCf5drYib+vhROtNpSLgcOZFUURHyoC9zpZ1lrbFyJhVndWWs4FCsL1S1/bdQ== 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 md-bcache 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 cache_set. Signed-off-by: Qi Zheng --- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/btree.c | 27 ++++++++++++++++----------- drivers/md/bcache/sysfs.c | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 5a79bb3c272f..c622bc50f81b 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -541,7 +541,7 @@ struct cache_set { struct bio_set bio_split; /* For the btree cache */ - struct shrinker shrink; + struct shrinker *shrink; /* For the btree cache and anything allocation related */ struct mutex bucket_lock; diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index fd121a61f17c..ae5cbb55861f 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -667,7 +667,7 @@ static int mca_reap(struct btree *b, unsigned int min_order, bool flush) static unsigned long bch_mca_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; struct btree *b, *t; unsigned long i, nr = sc->nr_to_scan; unsigned long freed = 0; @@ -734,7 +734,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, static unsigned long bch_mca_count(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; if (c->shrinker_disabled) return 0; @@ -752,8 +752,8 @@ void bch_btree_cache_free(struct cache_set *c) closure_init_stack(&cl); - if (c->shrink.list.next) - unregister_shrinker(&c->shrink); + if (c->shrink) + shrinker_free(c->shrink); mutex_lock(&c->bucket_lock); @@ -828,14 +828,19 @@ int bch_btree_cache_alloc(struct cache_set *c) c->verify_data = NULL; #endif - c->shrink.count_objects = bch_mca_count; - c->shrink.scan_objects = bch_mca_scan; - c->shrink.seeks = 4; - c->shrink.batch = c->btree_pages * 2; + c->shrink = shrinker_alloc(0, "md-bcache:%pU", c->set_uuid); + if (!c->shrink) { + pr_warn("bcache: %s: could not allocate shrinker\n", __func__); + return 0; + } + + c->shrink->count_objects = bch_mca_count; + c->shrink->scan_objects = bch_mca_scan; + c->shrink->seeks = 4; + c->shrink->batch = c->btree_pages * 2; + c->shrink->private_data = c; - if (register_shrinker(&c->shrink, "md-bcache:%pU", c->set_uuid)) - pr_warn("bcache: %s: could not register shrinker\n", - __func__); + shrinker_register(c->shrink); return 0; } diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 0e2c1880f60b..45d8af755de6 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -866,7 +866,8 @@ STORE(__bch_cache_set) sc.gfp_mask = GFP_KERNEL; sc.nr_to_scan = strtoul_or_return(buf); - c->shrink.scan_objects(&c->shrink, &sc); + if (c->shrink) + c->shrink->scan_objects(c->shrink, &sc); } sysfs_strtoul_clamp(congested_read_threshold_us, From patchwork Thu Jul 27 08:04:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329219 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 A66A7C00528 for ; Thu, 27 Jul 2023 08:12:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 464FB8D0006; Thu, 27 Jul 2023 04:12:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4154E8D0001; Thu, 27 Jul 2023 04:12:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B6588D0006; Thu, 27 Jul 2023 04:12:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1F65F8D0001 for ; Thu, 27 Jul 2023 04:12:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DF775804D6 for ; Thu, 27 Jul 2023 08:12:08 +0000 (UTC) X-FDA: 81056673936.08.1C3CBC9 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 0C93F4000F for ; Thu, 27 Jul 2023 08:12:06 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DFuBBIj0; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445527; 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=2n4eBW/y496rw0R30jGqgr9PaTd+TyGx4MFgxeJTY98=; b=vbIfV/GWG7K8br2Rguuit0tgikDE57eO/2GDBAETqFF+fWPPt+vmwBimpeo1gxoArY6PCu u/jRe5S+ZmV3xb0KLU63B0fXUY4Ee6WC4gELxnFCLTuY6LicQLkqJeXmsrI1r42o4VmLXw Pc2wmY6v/5y6NwQOiyAw7AJy0WazlkQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DFuBBIj0; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445527; a=rsa-sha256; cv=none; b=lPZSpkwnjcTaZySAr5lSPoBL9aUxa53R5w7D0Nw4deuQTrKFpGkF5IpNRavrVaiDvmAc7P XHeqsVVUUBZjxuKiEp/eFfGTVSF0XorOcN1CMGq2uGDVRXfXTn3Bq+2r//WY3m2vvrQ13g qjp5ieE9M+w6On7bFWnp8Svex59UvlM= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-682b1768a0bso175473b3a.0 for ; Thu, 27 Jul 2023 01:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445526; x=1691050326; 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=2n4eBW/y496rw0R30jGqgr9PaTd+TyGx4MFgxeJTY98=; b=DFuBBIj0qr+rYIge0pXV6Iz/WQCtDScPhobpwepkK1qFA4vWSgHpJ4XkcYuuPfpNPf m1KmSzju36tqFFEerRbxzoJUh0jIYJTO7HIOFb+RZm+pVFB00ovmyWsAOFYYwfcBZmMb e24YxGtb0LaJS553DCfCR3CRRqCI01KNxWybG2aaWT/P5M881ZLs+BB0bNl6iFKLm1jP 1CGPhfxCNsRDquotgL0k/wpTHggVzHbYlQp/c6oXuHB7Tn0FP6ZxNpyiHbKUJJqBcB/S A1bIsa86Qg72/76knWel/9Oqk1Wqg5ySfdUAutMowRhvxEtU3jYo18G5n5eEy4cYbgQS NQLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445526; x=1691050326; 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=2n4eBW/y496rw0R30jGqgr9PaTd+TyGx4MFgxeJTY98=; b=AsQnvMc5o50LQb3tXkSVYbMWR43eKwmI7SdpuVXPKqU7IQkkY4avSOKwLiXlSogZjG uB4m3Q5vFIeCjgQ3Im1dl77rm8MDBiDrMXZVevvJnGP/6kK3t4e4aDG4mpOpiH5mvHMW 1jtZKlng8kDLxvez/kmFyxW2JQdJxQsZPgHVd+V0t7SnjvysPuh3anhJzZoWeU5i2it5 kBvFKUb52PmvOEvX+OCKJp3WthtV+Loa4IkMPyGwib5NbWjPwqnvqcjLa60A40W9penX hZ071koR8OTkozJGjHtKyGW0xan2ISXzK8xy0lXvJ6PE4nrbXRFnImCwg46ZzZX8WZSm V11w== X-Gm-Message-State: ABy/qLbFKW9I8QzLJamKHn5qFKzpIfIpT8sLhMr5AL682MAQQ+ouLpoP 4nyzy39dSQzmita3s7X40huBJQ== X-Google-Smtp-Source: APBJJlHcYWOCpFnX36R6RazQvm5Mh7k9Kqh4ud2Oospjm3wjIj4ouKJfJr17R2K3rHFvQEDvt90Syw== X-Received: by 2002:a05:6a00:4685:b0:675:8521:ddc7 with SMTP id de5-20020a056a00468500b006758521ddc7mr4426362pfb.0.1690445525874; Thu, 27 Jul 2023 01:12:05 -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.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12:05 -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 31/49] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Thu, 27 Jul 2023 16:04:44 +0800 Message-Id: <20230727080502.77895-32-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 X-Rspamd-Queue-Id: 0C93F4000F X-Rspam-User: X-Stat-Signature: yorasuuxaef43kbbo6dhoapcerskiorb X-Rspamd-Server: rspam01 X-HE-Tag: 1690445526-903610 X-HE-Meta: U2FsdGVkX19PEbvObfglh7VLUTtbFVDXWojBOfcTOZXZDtsIsYYl7DRtbw30F/tAScvFtjnNUZD89BchX7cpNpsHTysElJSFH5dWVATzvxNFUrwNwfAB6AbtVLmGrOJM4Y1C0zwRzszRa8Q1aYrfgBpgh9aW2qeZDAR9p94+N85LIw1HecnySUjBjyz1IOGxkMTLBr8wX041pT8v/cAh0ciomnCITblvJoztDaeqUuwl4SD/OgND0RKrHLGZN/8L8LtitNkKnXsMLveDUUOjxBZVH6Cyfjc8jVtfdyLfMgH7J6NNtGDzJDb/n0DQ+pXiVHpd8W7WElcrySkTwkdR8taul+XmzPwb/3urgtM7/PDsAcjxVF581BuooJA/ZS3oE0E+KDRZ74BQBw+G0EVCsxevCJXSyvlhB2sVwa14SA1IIaSVXg0Dd+lnnMp7hNOYBBgpWOvU16KnNX0t5gSSKK5egoWEvhwX4Gj8mJ/kOpcyj+WLiV8NtRTQZLfLjD3EDd5OuJS8pf+xQ9YSqQX5QZ426rQzRyRcNj8p+BDBgG5EeOXcn5dD/aD1D5SZ4u+g4Lq2y37GO4o/aKex2SWwg6W2UNjF5KDS6H/LjPbQnXhvAFEupp6jyi81mFKeU/zndbR/2w587CDIOs5rGbGAL73z4/q3r3CYQ0aSJZm/VEv71OjUBQxaejL+axQean6H8x+iX2hRdH3Y4PjxrPiccG6u2hVioHt5EKQj3bNqc+Km1X1xDBRUA8Cw/vsNbwRHVohR5zn/ZpBNYSpbLKGW/Zvvt7BXindXjy1oEcuC2uTtg5OwHp9EBH/pJuD52f+Bx+KyEF9YoqcTQdozDkOjiCPOZbkKsSjYsbI8lFo+VGJbjTJtzmv8AU9Rf8hF7KEKiZGcJoOL1bzEKMkV0m7O5HwtTLqroVsiAgwyptaQtME3fN3kGczIFOV/io4CCZIemyQx7AXBcAL4UaxQ3KJ Q/Dc0cP3 Z7HQFVSE+lravu1BNBMYvyJDHdU7bDuEf+wWXJQbAQaC0Tm1GuUee+cQvnDsC1kWm16BfXxvgdGfTpGI/ihtwWms/EZq9wntse4d0TyNTEvjx8pScDtxz4uaB3ChpcmGsJUlC5608/og+j47fILZll9ZeFQUdBG/o18u12lnqtvAOahK8dRnu2cdrTHtKWY2jeh0wboQNcp6Ui3UmwEnJ5z4PNKzq+qlH42eFRamBj48YZlFc89BnodkuVp3GrqOTJXh8buojhwCI/zNoKokkO69mRj0JVgu051AuYaljucHiAMXuyaQT1PbwoNc6bhHA10lSzYLXbGCeQdHKBJIlY86Axw7kjJYgt9J/FEDjf+GMJ8oDdrY+TpFYSKDFRix8PTdfylSMPiwEbwFKx62u1KgDWPpfOyD0fXjKvHiUtEzpqhpq1XMg6x8HQx39IEn6glrmDyUCZeufNrj2/S4Dzecq2A== 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 vmw-balloon 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 vmballoon. And we can simply exit vmballoon_init() when registering the shrinker fails. So the shrinker_registered indication is redundant, just remove it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/misc/vmw_balloon.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index 9ce9b9e0e9b6..ac2cdb6cdf74 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -380,16 +380,7 @@ struct vmballoon { /** * @shrinker: shrinker interface that is used to avoid over-inflation. */ - struct shrinker shrinker; - - /** - * @shrinker_registered: whether the shrinker was registered. - * - * The shrinker interface does not handle gracefully the removal of - * shrinker that was not registered before. This indication allows to - * simplify the unregistration process. - */ - bool shrinker_registered; + struct shrinker *shrinker; }; static struct vmballoon balloon; @@ -1568,29 +1559,27 @@ static unsigned long vmballoon_shrinker_count(struct shrinker *shrinker, static void vmballoon_unregister_shrinker(struct vmballoon *b) { - if (b->shrinker_registered) - unregister_shrinker(&b->shrinker); - b->shrinker_registered = false; + shrinker_free(b->shrinker); } static int vmballoon_register_shrinker(struct vmballoon *b) { - int r; - /* Do nothing if the shrinker is not enabled */ if (!vmwballoon_shrinker_enable) return 0; - b->shrinker.scan_objects = vmballoon_shrinker_scan; - b->shrinker.count_objects = vmballoon_shrinker_count; - b->shrinker.seeks = DEFAULT_SEEKS; + b->shrinker = shrinker_alloc(0, "vmw-balloon"); + if (!b->shrinker) + return -ENOMEM; - r = register_shrinker(&b->shrinker, "vmw-balloon"); + b->shrinker->scan_objects = vmballoon_shrinker_scan; + b->shrinker->count_objects = vmballoon_shrinker_count; + b->shrinker->seeks = DEFAULT_SEEKS; + b->shrinker->private_data = b; - if (r == 0) - b->shrinker_registered = true; + shrinker_register(b->shrinker); - return r; + return 0; } /* @@ -1883,7 +1872,7 @@ static int __init vmballoon_init(void) error = vmballoon_register_shrinker(&balloon); if (error) - goto fail; + return error; /* * Initialization of compaction must be done after the call to @@ -1905,9 +1894,6 @@ static int __init vmballoon_init(void) vmballoon_debugfs_init(&balloon); return 0; -fail: - vmballoon_unregister_shrinker(&balloon); - return error; } /* From patchwork Thu Jul 27 08:04:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329220 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 AD551C0015E for ; Thu, 27 Jul 2023 08:12:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5283E8D0002; Thu, 27 Jul 2023 04:12:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D7DB8D0001; Thu, 27 Jul 2023 04:12:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39FF98D0002; Thu, 27 Jul 2023 04:12:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2ACF68D0001 for ; Thu, 27 Jul 2023 04:12:21 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F2189160FA4 for ; Thu, 27 Jul 2023 08:12:20 +0000 (UTC) X-FDA: 81056674440.30.EA9D40F Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 15DE1180011 for ; Thu, 27 Jul 2023 08:12:18 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=P3BNYmrn; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445539; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=7jeVF8hdrYu0pkMtGmowVnHtCZoWZPjDAI9GDEdkus2SbDsYHZBAIlul+b7bAvhqRay3AG 6mlxU3L61+fae/l6+XYWfl1mfINnZvHnocAfMJgXwAHRFtwT3UeMm0qvLe9ZCMCeMTxDwt Nsr+s5/r6v7Q0Em8rATomj1JGL8y5sM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445539; a=rsa-sha256; cv=none; b=6d4MhfIgUlDekm3JEca+eVedz0twnR1jeviS7mTsj978kim7zZCOdPqobTnjsInYKO3T2G QMO/MeAos0Uimif9YjFKDNvkU7yaUteqPBZfjfMHP34YmteKXVFEBzEiLmAU4golICEbg3 Bj0KsCFWRq6etkr0k0T5MxQCrl6GkOA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=P3BNYmrn; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-686f6231bdeso113614b3a.1 for ; Thu, 27 Jul 2023 01:12:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445538; x=1691050338; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=P3BNYmrnn+aNeQX6tJNAWjBR47qoFVwe6V1hXSSWwFyS61HuOjfx1CldC/bVPLDS4b tBSPVcIpokpC1gG54dPeypV2gv1H1PsrEki/AFkEglXm+WyAmzSAHFAjlypTbwzHUkTv XwwWUlwnKhA8sSKQw+cOvBa/dT3CBu+sYvYNSpbwNT6pp20knmU+insJC0lJR8d7KNA/ XFw3RfaoZY9/IU0U207vkdiCmyduxENHuADRmTAqpUtqVvF1N7pwLKXyEsFC4IstCLHw nMtpKLIm0n/1aYuhmB1FsTVe4JczwGUa2wEUGkSK8KQu0Fafs8lJ3mpNN+7ETdaWOSMf 16qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445538; x=1691050338; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=YUBNa0nz80WPY/qfaR3boOg+beR+Zx8GXPy6ZX0T6BGNA1UXy3oDdTXklzS/fDK2gd nvT8Hosd/xLagh9BV49DUizsJ4CZNxBZ1TuJWA5pSTTH5VP7i3JKyWO24lSYirBZYPDT pJPa6l4mcxlNniSHNiwSG5BtkQzTyNdWA0u/fkrxsiekl85N7M4POH72OZQUBrQH80/d x7l+sxxS1jVNCtDkqRhTJZrVx4W7/zCcJ/IsSysK5fxWaNFQ/nnDwfez8jG8QybTOm+K lAo7TCk6hx8+eNvFFhooJAO0QMUNbw2uQEUpn/PbojPFr+b15pBcfZNC/1Wa+lvdkVAy 0QnQ== X-Gm-Message-State: ABy/qLbVTiIGUdecUOLfIYwqsdp9JclitdBE3Q1+p47ml5nsCosuDhfM rG76c59/y0genIIzKvZTz75LgQ== X-Google-Smtp-Source: APBJJlELYJ+VP3jkb44itFX28rq7UhufR3zr/NDN3xCao+bv4nVfpqzapahZiZsalg40ZmAEO1GP5Q== X-Received: by 2002:a05:6a00:13a3:b0:676:2a5c:7bc5 with SMTP id t35-20020a056a0013a300b006762a5c7bc5mr5236670pfg.1.1690445537850; Thu, 27 Jul 2023 01:12:17 -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.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12:17 -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 32/49] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Thu, 27 Jul 2023 16:04:45 +0800 Message-Id: <20230727080502.77895-33-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 X-Rspamd-Queue-Id: 15DE1180011 X-Rspam-User: X-Stat-Signature: 8o6pfne95xk3u5yy36kf1r4zmictjusz X-Rspamd-Server: rspam03 X-HE-Tag: 1690445538-280206 X-HE-Meta: U2FsdGVkX18jFXbC74VyFXipYTm0V9u/Kuq+vEWzuztcR99MpH9KYoSJOe/sDwbJgd15WCYU78LI0J1LQiYFp1WR2p+sm/FqKdBhMPh020j4L3jTCaeX4e86nQmO/Dk4tLnu8mE0Jyz7+0wXysBRrAhdpq6xYtiqmlD4su+q+EEsFVoAyZSRxPoLXhrl9/6ZlNMwZbLowJbV/mRFKXyDMjQHwLWjLhLHKE6hGJsCe5eNJsI07t/aOKGP3Ui2p6kDALckzTwPKn83MZRisVZYUpcO7ma/29XH77AjE0Vjh24iPR+gfONCyb9sgjBn5xBkYLf9gZlWSnBzgZLK+Ry83h7V+n2vKN1k8y5VNFsch6plLkuWazPwVqGFtDn8Xi0lknIChtOWSyk24nlDPDxH5xlyaO4loCk5VTVKVf+mW++ucu7pnwan3so+PQaootLkv+dZV/1PrQuX1B9GmQnMCQaRIYDkkp/vjCf1tWqfCNVWyFXsuhtarDTSA74d71kEFMkdG5cmSrgwthVv+K0mO/iJ91uNBRgrJMSl16paGu7dnX+XVPKP3CTOi734Zh0c92VJ0l2Ztlfx7OhJ+xFjkPyWP499WjS6q1HRTcirb2PRfZHHeLDtqskicztvU9NhOKwzjD9J9wCVyB0h8PqDHeazGQGiPk8PuKlWfnhEG5VyOja88V8Haq0emwWEYH3Fd1QC69piNRV+2PoH2ns8XvC+iyr9n801J4AuN7AE/QxywN+jYvCNUasu7Iw1oIC4puri6pdNLoCwnJeRtSGU7VHFju7fE98ZIRYbvOsyBGOTnShxpZREaLiH2bQXG/kk1bF5FTqIISbEjy4pIea0El01YhcjNzn0VFKdHg1FiQghkGI0DfTa1Y70atQ0ExQH1LFZcb1KBk4zJqZ6GkLBVpSZVdQzKd4vXBkkUYZLFsmdl1YnvjT6zm/UkT1gDLjh6UlAOMVKCcDXjvHlOPf zrCC+M05 2uTzuhs3X4ONiKL+s8WoEd3kr4nI6KqEMgxLiyk+XoWTQ0uqrcuXzhhArS5SCbPGvPEbH2nZRvrwbh0H/0PPhfpO21j1jDBK4eCtdYOY/JXIPeisqTQ7/iRMAX6UT3MvhUKAOv6gEon4DhCTQcgRVUt4oVzVsxirFTgAwEtgDAcIJiRy7TjI2aLS1GRK6wMSKsWWmDYeZl0toct8RCmPfsLerJo0Pe3NdP54xGn27kklXHzy3DxDCRzZ7YMNn+INjXYOGFQm0yzPCwHD1AcsWQAG9Gf4Tg7gB7OYUEzH3AvpivAoy4rEk9BfXKxy3kXGTAxIYBK57+KAkmwxgIyTvJ9vOXz7lExm1f9e3RbaHcC940S8MqJ0Mrtb7zMfkKsPX2YvOYZx73IgQN51EuXzFhfBl0qc0qIzqgJnLfoixA5EJmnNeuXlh82gecscUhSPY5qxp74p3XVpyaQHwmHaghrmT0Q== 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 virtio-balloon 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 virtio_balloon. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/virtio/virtio_balloon.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 5b15936a5214..82e6087073a9 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -111,7 +111,7 @@ struct virtio_balloon { struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR]; /* Shrinker to return free pages - VIRTIO_BALLOON_F_FREE_PAGE_HINT */ - struct shrinker shrinker; + struct shrinker *shrinker; /* OOM notifier to deflate on OOM - VIRTIO_BALLOON_F_DEFLATE_ON_OOM */ struct notifier_block oom_nb; @@ -816,8 +816,7 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb, static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return shrink_free_pages(vb, sc->nr_to_scan); } @@ -825,8 +824,7 @@ static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; } @@ -847,16 +845,23 @@ static int virtio_balloon_oom_notify(struct notifier_block *nb, static void virtio_balloon_unregister_shrinker(struct virtio_balloon *vb) { - unregister_shrinker(&vb->shrinker); + shrinker_free(vb->shrinker); } static int virtio_balloon_register_shrinker(struct virtio_balloon *vb) { - vb->shrinker.scan_objects = virtio_balloon_shrinker_scan; - vb->shrinker.count_objects = virtio_balloon_shrinker_count; - vb->shrinker.seeks = DEFAULT_SEEKS; + vb->shrinker = shrinker_alloc(0, "virtio-balloon"); + if (!vb->shrinker) + return -ENOMEM; - return register_shrinker(&vb->shrinker, "virtio-balloon"); + vb->shrinker->scan_objects = virtio_balloon_shrinker_scan; + vb->shrinker->count_objects = virtio_balloon_shrinker_count; + vb->shrinker->seeks = DEFAULT_SEEKS; + vb->shrinker->private_data = vb; + + shrinker_register(vb->shrinker); + + return 0; } static int virtballoon_probe(struct virtio_device *vdev) From patchwork Thu Jul 27 08:04:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329369 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 E043BC04E69 for ; Thu, 27 Jul 2023 08:12:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8830C8D0003; Thu, 27 Jul 2023 04:12:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8357C8D0001; Thu, 27 Jul 2023 04:12:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FBAD8D0003; Thu, 27 Jul 2023 04:12:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 610D58D0001 for ; Thu, 27 Jul 2023 04:12:33 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 254E0B2A5A for ; Thu, 27 Jul 2023 08:12:33 +0000 (UTC) X-FDA: 81056674986.08.FF8226A Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf23.hostedemail.com (Postfix) with ESMTP id 54431140003 for ; Thu, 27 Jul 2023 08:12:31 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VWs5xsEp; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 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=1690445551; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=DcxAXNqKfkEIAsIODv6V2QwXA/g3Bj3d6fSOzErVdAnWyHxSc2CBQynG+vNu79CstBpQWP p73mgwR67u/aDcHUs32YCz+OwS6W0G4a6SI6hELleyDoSfHjmyeZfPxQVzgyzmm0I6nWua GMnrQlnczADYjm1l6dmWRDllbwv6Zpw= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VWs5xsEp; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445551; a=rsa-sha256; cv=none; b=2gY8m8YHMcQBhRpbHnp6kN6k3n7kxBTsX+INjnKf/Pha+XxwwV0uofIFpZlwHCM+/pnOpD Ctw8MSMP8vGACRMUvS3xKtWhT/pLxU2q80/FLNyt1f4PWZcukxzX9c1Cn9hzEBjrOwbqH3 /3vyIwwHP//2PzeVGThJqZFKl2ID0Mk= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6748a616e17so183582b3a.1 for ; Thu, 27 Jul 2023 01:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445550; x=1691050350; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=VWs5xsEpAgA4DYNqF8K/FN4j7udZSbXqCeXnxv3YTG0Ik0TL2nl/Ugga9u7R+ZJeNR Wigeakgpk32H5TPwyUhkE7IqyM04zeUMVcePDa9eTKcIqF7mvyeMYMdU6pDKFeWcNWaR qvQCy7Nu/xowW6gGi5vD7bu0NuXZ8UlBiffMC2ufEn1khdTpqjsjaFRzBjIrPJfwSFKG LuwPnQLNAsZ+sSXWuMdy2i4BIcl75Eemb6JwQ/h/qU8W848mv79pSK1svvdUmrASzQOQ aQzV7ZNEhcTzx5oZvxCfNrl/tTU7BbbCJB9SufDvnC5P9J0UXQ5a+DGx/aTVEKn/U2IP 9i7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445550; x=1691050350; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=GQWgH6zNIXDDKQlAsNgSSp4GD7Pz0m+/eTa1bUNb4NcJZNhrMj4v+pBSDvCu1FniJw iDNUCI87IPzT4yrtaXIhxSfBB22pcU0TvijT3GrT8XUZq5GPP/cNY5Fzk4IPqKvjAnaJ 9ocKdrgRDzWqqgi/HC5dt6D7M45J+t01d/bYRN0NSqZq1oPIUNuHcfd3btotOMEIpFKg BHj10pkwTljSTB9VraVQPFCZPQav4JPsC8zFkhxKoQ+zRa6VHIzzaQwVdWr+GHRpcwJt 2EOSaM8Nt7YnAPknBPlP240parcn7Zd4MD3pv7QtjvP6Ucz4z/hf5EX81Agcs5R8E0wY OYyg== X-Gm-Message-State: ABy/qLacnH+oxsARjRNfYYpSiA/qRvA4w93Nyj8GYbUoMAAiJ+OnWjYR PO9a/9yVt3ScKVJXQDrP15qlTA== X-Google-Smtp-Source: APBJJlF08KF/2Ja1GiYKXzi0SbMDWba0XluK8fJxZEI3QrufrkFF+7lpMuNnhPZU1iQtSxNfzq1jqw== X-Received: by 2002:a05:6a21:32a9:b0:136:f3ef:4d2 with SMTP id yt41-20020a056a2132a900b00136f3ef04d2mr6069372pzb.3.1690445550183; Thu, 27 Jul 2023 01:12:30 -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.12.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12:29 -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 33/49] mbcache: dynamically allocate the mbcache shrinker Date: Thu, 27 Jul 2023 16:04:46 +0800 Message-Id: <20230727080502.77895-34-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 X-Rspamd-Queue-Id: 54431140003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: prjzgidmurjyntnmxa3j3akfrzam3zyx X-HE-Tag: 1690445551-511710 X-HE-Meta: U2FsdGVkX18SbyDIvYDDiCowbE3u7gzSugsGjSrsoq+r1KWKh/XlPTrB40I0hcReUvltobMHAp1lDoKp22XhXKAvJRdFjlHXarJAF7+8ppvM9Ozwb+8DgUHQogqaGfz+2nE6Zb0X0AaqyFnMPbg4//LVNnkZSXI8pqPJgm5bxnDEiMg2OVn9hwlUngynFKFY62ei35b6pUWVSYu6iORPFnFWzJIjT/SsHltmbj9BreaTaO/cAGUMpKgSTuH0Ib8iaYHyePg3iYQzAcUzWY6R8SdcX5OFg9Ii9zBRGNBqYWquR/eVdP1ysEWZjskccu0MXoqdaPt5lrh797ojdqUhdlk+D52JEMKJbGvvgJkLu2Pfas0NTr+kkImiYviqaW68TozsEIesGYi4R+0q8O1jKsfn2S8jrQ0aypIeBJHRm+qUw4YpoH0DoMAsABeyp8h/bx2/LGgssQirfsu0hjM6jLi9Btlh96HzULfmf+rvTEYB8lVG/gn6yjzidtADGuGPTORjIOzc6pQuhbpVfJVAeYnazDNPCueD7WuUgbxWv1b6IhY5L/mCLZI+J53fTrDv27CpZmv42dSzCtUd3O97PI9cUMQZ6q6Xxp9+BWOJGHMOk+0DK2npQ5l5uqS60/OHLuWQxNLlZpGOcseJD5Ldg1mjdw5rrdC35bMdQOOI+1qF7qdpOCS9wFJPZaqxfaUz5UnFMobG1vONbPbRsl492G6Sq4Lmnh8kmOchwyhx9psVCddG14zjwAI8JVY5QFubKrpVMRe3cVEPk2wWM0fhx4dxCH28KXgGuQbaTImSRNj0Vnxq/99TnU1gTP4IFpZ6eTUjkd+qs8QWffGh6qGNud8gFGCYzxhV3o3dGXlBkSL2jWbSF0px0mG8zT0ZQCG9/Y7jqs3qquyE7vOMmg4LdifjL4VMT1IixXivussZQtQrvZX/ZejysoVxDsHvsbjAiim7wZkVZ/rdpv95C/5 Xpppwyhf w5aY6Rfd2jenkPsOhyqUCbN5KdkXXI9ajoSekdZDjHJcGSrqDMw3od8YI2PVAzVOzrIkP2AtW8dUbPq3a15GQE/lTMxXTk1NIBOXHwzMiBK7ROKNSvfgf7kDZQ0V3slAgZAKX2WggWYUpOjDEWN9bhAJOBntR1Ui5nIeR/Cwc7aepVlmeNEUdYGx6KeNKsKDXjlOJTsQmDVVJ+5tRR5FI+2li/GmQb5LFhvFwORq/BIibS187uCqCft7uXVj4bnqclgxPY0YMRP2w6FxAk1yPRivGHpM9pdkugk2/ESAgd3tFy6g4dra3Jn2Lu3TLhkzldOEgrIiIzQDfBP+SoJi+LbZai87P/12++yNb/nqH/oCPiv+HRglx5jUseI74N9IqFeviqVygTLfcW0R37TNpwXxGe+98y84jRnwAs2EufvnD8B4QoK10QHNREh81LqWlDRQ6 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 mbcache 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 mb_cache. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/mbcache.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..0d1e24e9a5e3 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -37,7 +37,7 @@ struct mb_cache { struct list_head c_list; /* Number of entries in cache */ unsigned long c_entry_count; - struct shrinker c_shrink; + struct shrinker *c_shrink; /* Work for shrinking when the cache has too many entries */ struct work_struct c_shrink_work; }; @@ -293,8 +293,7 @@ EXPORT_SYMBOL(mb_cache_entry_touch); static unsigned long mb_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return cache->c_entry_count; } @@ -333,8 +332,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, static unsigned long mb_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return mb_cache_shrink(cache, sc->nr_to_scan); } @@ -377,15 +375,20 @@ struct mb_cache *mb_cache_create(int bucket_bits) for (i = 0; i < bucket_count; i++) INIT_HLIST_BL_HEAD(&cache->c_hash[i]); - cache->c_shrink.count_objects = mb_cache_count; - cache->c_shrink.scan_objects = mb_cache_scan; - cache->c_shrink.seeks = DEFAULT_SEEKS; - if (register_shrinker(&cache->c_shrink, "mbcache-shrinker")) { + cache->c_shrink = shrinker_alloc(0, "mbcache-shrinker"); + if (!cache->c_shrink) { kfree(cache->c_hash); kfree(cache); goto err_out; } + cache->c_shrink->count_objects = mb_cache_count; + cache->c_shrink->scan_objects = mb_cache_scan; + cache->c_shrink->seeks = DEFAULT_SEEKS; + cache->c_shrink->private_data = cache; + + shrinker_register(cache->c_shrink); + INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); return cache; @@ -406,7 +409,7 @@ void mb_cache_destroy(struct mb_cache *cache) { struct mb_cache_entry *entry, *next; - unregister_shrinker(&cache->c_shrink); + shrinker_free(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this From patchwork Thu Jul 27 08:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329370 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 59D86C00528 for ; Thu, 27 Jul 2023 08:12:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3E738D0007; Thu, 27 Jul 2023 04:12:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEE3C8D0001; Thu, 27 Jul 2023 04:12:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB6DE8D0007; Thu, 27 Jul 2023 04:12:46 -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 A95398D0001 for ; Thu, 27 Jul 2023 04:12:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7AA3C16050D for ; Thu, 27 Jul 2023 08:12:46 +0000 (UTC) X-FDA: 81056675532.02.F251321 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf07.hostedemail.com (Postfix) with ESMTP id 9BD3040005 for ; Thu, 27 Jul 2023 08:12:44 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="X2/dKeRh"; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 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=1690445564; 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=QelXbRgYcu/a7kVf8tT2xmPKs8Q6fhUGUeX576V7Nl8=; b=MQ4wMCQt6tueyr4JudBs3/zDh0eUeax03NLUN3ud5BioZe5haS7LWWqs5mKzN2i5nT5Gsy PEWi6BdzDSIrlpmo7saynhfMqiO0YPvZUrxsTJmx5GPZfekKEYaJAngPQSRg6+naJtxNJI GO3o48x0XubIi1p7FYgF7DiFBhDcxbY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445564; a=rsa-sha256; cv=none; b=XzDNNipaz/rFrmXqbycCDihY7/913Bu83Opg96ZmcZ4oh8ExiYfMim85p3rLSk7awipUOw +CVi2SoMPbMZ69vgY/93TA5qqmTU8RJf5/hlHOfw8O7fG8YuobnbgTyR5Onl3lF8QLI294 oLfrpK+RpFeBNWgIc9ykjZJ9YE+zDkQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="X2/dKeRh"; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-682eef7d752so204764b3a.0 for ; Thu, 27 Jul 2023 01:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445563; x=1691050363; 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=QelXbRgYcu/a7kVf8tT2xmPKs8Q6fhUGUeX576V7Nl8=; b=X2/dKeRh3K1ZUeUXRmYcuLAwkmDYhdwx9iwlPAtXfC0B4vHXtLguXST30gjNSIXFT7 OLt7OLAHNBNYpcouioFmzFwp83h1VVZBZI/b5TZHZteUiScXCbvweVFodKUOy9sCj8AV ZENggnGp80mAUTxGhU/fnzaRvZdNkV5cPcoIInnSny5prudiipt4/IqGTm49bA8p77kr 6rthKHnFEd97DZ60+ymFLTYrwmYvoXhejWrNb12L9I2KL1LTnT8oJzoHo7/LmyIBjEhr 5sNbvq2AFaPoM5/YQzjEzmuEQi5h7hErc8c8ASDByEVVMFkteQf8s6ncJNWVLrxavMEP hYjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445563; x=1691050363; 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=QelXbRgYcu/a7kVf8tT2xmPKs8Q6fhUGUeX576V7Nl8=; b=Gc4G+zGCnjKoBHGM6fopyivWmH3FOlsoulbYMuPrh0uNgKR4OM9gCoL8bglRiWl4Dp efs400IAcuPQ3EVjjre1aksCkFe3dBoDsYROTn1ki17gpQik6fW8W+j079Ecny4VLUgX K3GL1TdXwCKEu5RD6ghyz0LAddsEnRLdkLwJJ9wzVkLQy9CIRjsvnZW0NU/EejPmSL12 ynmcISQgI1RN2TBLavfQ7q3Qxaue6pYQF9za8/qlthP/hq1eKsagxXIxSPa4aBPzz/qv sRrGWgV+ebfHxYMylcGvzGippBu4w1/raFlSNQIr6qYTg7D1+nSlBEk48ZBMQ1iCrbHx 3o4g== X-Gm-Message-State: ABy/qLafoTAWj5YisIKyWWu7YMHmud8xHd+uer39u3Tt1hDyJHAHGn3O AnF2A0IThyGgMQTQMvWYIEtvPw== X-Google-Smtp-Source: APBJJlG3us3D1/FzajU+z+h8urvbqwZdl/1CQD95N0Bm05n475Xxe2FLYU/iNliwdKbEyGNSdPUcwg== X-Received: by 2002:a05:6a00:13a3:b0:676:2a5c:7bc5 with SMTP id t35-20020a056a0013a300b006762a5c7bc5mr5237596pfg.1.1690445563409; Thu, 27 Jul 2023 01:12:43 -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.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12:43 -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 34/49] ext4: dynamically allocate the ext4-es shrinker Date: Thu, 27 Jul 2023 16:04:47 +0800 Message-Id: <20230727080502.77895-35-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 X-Stat-Signature: m9c49qjqo9w8ro7ujm4t77e3bwfnffqj X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9BD3040005 X-Rspam-User: X-HE-Tag: 1690445564-261093 X-HE-Meta: U2FsdGVkX1+w4uekywz1QPfZnHH2XRf7ACT88CFOuUcD9swMN/Pbpy/jIw51jumF4H+xnqV34286T/C/Qbamc4ufU9w7j7IfElTULHUyqDCbzPwQzC26rXWTcqtwSEAZ6Do/Km8SkrkENU3gRL25I5inHhnYjFdE2NIoe2fQRqN59jSavw9Go7EhP/Uy7CDq2Wpn6GdoFpoPcb/H1ZqHKa1YNvCupGH3RLHHMg7vUX0W9sWZ//wFtlkv0MjYwzB3LoBx7okau6iSPNtR565ii9HEUuynWCsrXQWIE8vIIKvNZ6uCQ7N25CUToNNCcsrwSeJ6S2E/5454+yrAbrb5jSsdTVKpetMEcySoiSQ3iwWb55kdnWUZI64GgMQ2/cMM3rzeWTp9yfBy++cCtpAyEWnngah+7KHQ19HNmj4Nx/6pRvMOWH5GEzA+KkVcFmjTNV7jSTrf1TupHXDdVyG5YYhOJ6aTti4ARAdC9kfPNaiJOusdICUR4uBwp+L2uLhcO/XXJcpnoglqBrCXPZLUSNc458W7LZPKC7K0Rgi7HpqerNOu5ojDt9zQlhiCg/UflIfNPNf04sKX9l7UN3gsAPoiIcUR+85l5TvFz3qcsRfPMwU1IFCRruuDQ1fyR0AGDpK/8FFyCNl5OUPQA94Zz3vXdr0HS2O4pb/UeeLk14upY/Ng6FqQjNFXJv2cJNCwStDfo3oHuR5WARgcZjE+ElsC9O0VRUnfpE0Idpz4ZT7mtUwj2j9GcOUMmGd6iCT7jXj04c/4TYUMLmrzztjQChTUf5jxkvE51qYi1aNPmEmI6XjkHxNI6/PZOcKUU9PjFl2120gVV4b10Bxvqr7zTcF23zz0e7pygpHQKl3K7FT5qzpp8vLn2jYa3+HRmIw4f0vGWYT/guptJ7GpOILv+e+t5ZQ0nzLBXHCRAl+Bq8zg5DgbmdyBmHFRhIKHu95YzGYrOPOoN8HbkRZJzOM 7eMX6534 /eOiRsyip39EbytIhmhvnsPDrOeeIW6w9Y85ATwhZPGDNx60Z1B3/chXtQOlGXV6VUubSzQqysOpwATZyIseaEU4+XPQ5BJaCpwyDb/fDGzU+ks4Yg41YGuQeM17gFj9L3653cYEaHud5m7pGlZG7YUc87Zk8XB2kxzk3pf5nT1clpYnPiNBmBaoBxD9zt0v11oFYGLnBPkUPgpPDWvbhGDwm9MxX4SV2NxNes8v9PSV7QaM0TwioAJETaVtQMvw0EaxigT++9+sMe+WOSDjIyZSw5u/IHiT+w6n/3P4BRcuNYKtye6tTs/mEPEtAnMrVIJRQnPA6qD0OB6MumDD6US4uP8oj/XT8N2MRVTQH9aisEdJLKhawWGtBrrqUuhsK5k3G/WFw0NK4LxHfN2xFK572Si0HEqUMvGOb 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 ext4-es 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 ext4_sb_info. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/ext4/ext4.h | 2 +- fs/ext4/extents_status.c | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 1e2259d9967d..82397bf0b33e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1657,7 +1657,7 @@ struct ext4_sb_info { __u32 s_csum_seed; /* Reclaim extents from extent status tree */ - struct shrinker s_es_shrinker; + struct shrinker *s_es_shrinker; struct list_head s_es_list; /* List of inodes with reclaimable extents */ long s_es_nr_inode; struct ext4_es_stats s_es_stats; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 9b5b8951afb4..74bb64fadbc4 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1596,7 +1596,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, unsigned long nr; struct ext4_sb_info *sbi; - sbi = container_of(shrink, struct ext4_sb_info, s_es_shrinker); + sbi = shrink->private_data; nr = percpu_counter_read_positive(&sbi->s_es_stats.es_stats_shk_cnt); trace_ext4_es_shrink_count(sbi->s_sb, sc->nr_to_scan, nr); return nr; @@ -1605,8 +1605,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, static unsigned long ext4_es_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct ext4_sb_info *sbi = container_of(shrink, - struct ext4_sb_info, s_es_shrinker); + struct ext4_sb_info *sbi = shrink->private_data; int nr_to_scan = sc->nr_to_scan; int ret, nr_shrunk; @@ -1690,14 +1689,17 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) if (err) goto err3; - sbi->s_es_shrinker.scan_objects = ext4_es_scan; - sbi->s_es_shrinker.count_objects = ext4_es_count; - sbi->s_es_shrinker.seeks = DEFAULT_SEEKS; - err = register_shrinker(&sbi->s_es_shrinker, "ext4-es:%s", - sbi->s_sb->s_id); - if (err) + sbi->s_es_shrinker = shrinker_alloc(0, "ext4-es:%s", sbi->s_sb->s_id); + if (!sbi->s_es_shrinker) goto err4; + sbi->s_es_shrinker->scan_objects = ext4_es_scan; + sbi->s_es_shrinker->count_objects = ext4_es_count; + sbi->s_es_shrinker->seeks = DEFAULT_SEEKS; + sbi->s_es_shrinker->private_data = sbi; + + shrinker_register(sbi->s_es_shrinker); + return 0; err4: percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); @@ -1716,7 +1718,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); - unregister_shrinker(&sbi->s_es_shrinker); + shrinker_free(sbi->s_es_shrinker); } /* From patchwork Thu Jul 27 08:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329371 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 CD01EC0015E for ; Thu, 27 Jul 2023 08:12:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AE608D0008; Thu, 27 Jul 2023 04:12:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 65EF08D0001; Thu, 27 Jul 2023 04:12:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5270A8D0008; Thu, 27 Jul 2023 04:12:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4721E8D0001 for ; Thu, 27 Jul 2023 04:12:59 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 151591A1069 for ; Thu, 27 Jul 2023 08:12:59 +0000 (UTC) X-FDA: 81056676078.28.9F6E789 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf13.hostedemail.com (Postfix) with ESMTP id 287C720023 for ; Thu, 27 Jul 2023 08:12:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=h7BzAXWM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1690445577; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=YbV1LZrcWf12cQfLTPBha13CGg3tpd1JV/d+QmbYJH1Sx2Xca6AJnQ42dedoXroUOG3esN M+Am34Uw4ZSHTmgNulieAQ4kTHX4dnRO5MgFxSQJojvqRzMS2K3+DXSABhHpfA3eJnwucq ffO8JxUkO54ZI7xEjH0BmqiqHWyYBV0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=h7BzAXWM; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445577; a=rsa-sha256; cv=none; b=iqSW5hZydUAYXMZ8D29SCMzAXwhzanypGthiYVhQJcuy2khXIQS1ql3f7jQ+gujUf/k+o/ /Pdji0YGzi39TfvJLFCi0MO2qr0OyNqsYzclu56D+p64ofK6SJ30P0L4hx47nrVnWuRa/E jZn83J5IOC9Gw0+2vV6L0mAZ8bpTunw= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-682b1768a0bso175654b3a.0 for ; Thu, 27 Jul 2023 01:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445576; x=1691050376; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=h7BzAXWMeO6q413o2q8QBGFyYtSJJQDVtscFkPudih7uYq32KqAohX6ko7JdrT58zZ jQesZevPWI16RJ584HoFfkctqZliFhC+Sy5DmGf4/p07EAXTPpKceV5c/mFhCQtFe2kc GT00j/8cVqT7gjAO9UrE6yMmEVq+vAOowivD6U/C54ThBKsCCzPpN8b7GVd2fZWCigOk vXp6v9qkHcNnCSidh0rHnK6MCacYxO0sYof9O+5/aUkm0GolyNtTHq/urdLytozqbZlU y5SGivZA8rDsT4B1CBykaduW0zvqtcacoHqzhUYbcvZiZaKGJdqILCFM7NZx5HG0wVY2 fpkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445576; x=1691050376; 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=48waxWZGd1WUnLYaDrTSxvJywKXLcopaiUkWgt7j5Rg=; b=YJa3hXBNofwjGEQA9s1alSaaSXLRzsDIci+OBJ0gHrVlM7XqnH24oylWM980iG+Yjt XMJclnYWIEJolGtBNNpMbm1n47Ir63/DbM7+ndy/GZRC0AK5Img6LTMwcAr8kddNl5xi z3u0Eu7LpqjC3Y2wpkPwtHPJ7VIpnUk93qVC7w94nQ1lInlDsjrV7V1QCfU2lSiQweCM YzvGBI/qiCDadpmG6i8Bn7WQCgqxu/7cafp9a4hurCqFQ8PU84HUDSsvv180NqtO/iME IuDXXaXOIMTgDyKXZyr16Tk90PJ0rp4DFvyLByUort+mbxq2lfLxHE4AX2Hvzsona805 XqCA== X-Gm-Message-State: ABy/qLa+YTuxdjnbUMt48t9Fr9u0lb2juQJysQNfdcY//1kqWUoI6k72 kBv4XRsgam5cT/jdhLTFzeeLxQ== X-Google-Smtp-Source: APBJJlGlNC1VbP/jxEyWXSRyFxMRuhVQW95Y9Ngz7T3+dCe8qyleorovPEoXgtcixk5kZ4l7rZv1Dg== X-Received: by 2002:a05:6a00:4a10:b0:686:b990:560f with SMTP id do16-20020a056a004a1000b00686b990560fmr4386534pfb.2.1690445576006; Thu, 27 Jul 2023 01:12:56 -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.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12:55 -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 35/49] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Thu, 27 Jul 2023 16:04:48 +0800 Message-Id: <20230727080502.77895-36-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 X-Rspamd-Queue-Id: 287C720023 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sy6rogthxshzisdzmtsesuikhojsbzm9 X-HE-Tag: 1690445576-483863 X-HE-Meta: U2FsdGVkX19b82uowLsilOTTSElGg5pAlzTgjVsHCGa8BQGQM6EK0rm/KLYHJWJXvyPi9hcjGRabkLnEZ43CVY7rYVC0OnsB55cGPYWNOKBup3lbycSFrtkug2ursBR/YV3BNqTzgQZTtsVtA7RYUFoMZwFTvGpVuGim7L5ACryXuSif4F6CSB8vo2gnWo1wLTud9nHTSxATY6FrcyEk6lUEOQo/y/UizTieh1p/1NDpFI1mlzGBBnLbAAfcEVqx5qWWdVPTwz7tV654OdMlQ4tWFUpz/nFdI3cd6HHSwRu6TtxMfIFJyKQ2UDfRgNoxzAdLT9U+hdBB7zXzXW6IgCKrLg6G5Y3c4ccaSU7zQHi1jxua7lue+k+HU/zngoXRQrbAXMEyFoW2pMmmuFoYNZt6bVKQUHHWXqU0RFLQOYce4dPStiS6+62b9ma53w3zDmusb1F2E3rVZVJQxX6+3QjNWmpvLaL4ltGRwhVOnqsd8NO6lyXb1Gc9yR1a1cHQqFQ0h2eA76r6moqRV1f0J5ulkLyK+NSc8pjmAWrOGFOOqzpjc6R1IGYT3VbfejCFMbhp/LjdRYqqGCpE4oWOWGlnXPYmI60ZrqzKR8ndYyFeWq85QEATYqzFxxbgOl7aV1QLl211VkiwiSEUbsNURD+IEOFU7CW40C0WLpN28N+Mn8aGylavy0pWdHuk5+lGRIRJYZ1H3T1LMJOJWxChjC0t2CKB48WsmPbX4xogczoPtOW3nPzzFv0LiVfOAcIN/UiUSecdzQj/Lr/lgcgSo4tHVU5OBYHwhh2WW5JFOxqr8hOy4fARmuBNasMe4jgbT2KstfqBNLFYcx1wKNCraKurCINtOykkacC8iiR3BcTcPFsiBGxfGaw/HlZcgvupd4yxkEt4NAOeQfFeRyWFi2LhISLXE5wfUlQbjPSUFqSMCbTPQHYj9PF3pppZYf3SKjQ8bw3gBtA09+ufTQw tijIm8sU Hcqj1/K98gauO3n5vnzShWuu0gI7EA7bqef+l8KoxJmOpRrNw7u4VkskfjhRZaj1Dz+kNdrSozlWhiGxy3AgggujOYRRKYCHiETs0/PH6ij4yrM+FahaWB7D9QndHQdvGQJE/2Cmf2nHyfA5y1od9qsOfJtvIe5ipp+e5mc1IGfh1aMf8se5ff1fppMz8oMuYkFDPMZkMtNSXGE0jj+uhfvHsNJ/KghRLnvD4+p9gmPV/D7gkMoeJ/ZMo3016cBpI03t/KFL5TngmocCcbaDVbWEfZkeppeQn+1K6KiC7sIU5SyITkevFVsAWcdIUviMJF+OQnVGl8tvZQFji83Am3L+Rw6yhQu1KlWMuu8KSTzJhhz3pYY5xRcL/y/zRAk8HTi2+qaqMZAYcciOiM0EH+SutfoUcpzy0LY4W 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 jbd2-journal 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 journal_s. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/jbd2/journal.c | 27 +++++++++++++++++---------- include/linux/jbd2.h | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 1b5a45ab62b0..4c421da03fee 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1298,7 +1298,7 @@ static int jbd2_min_tag_size(void) static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long nr_to_scan = sc->nr_to_scan; unsigned long nr_shrunk; unsigned long count; @@ -1324,7 +1324,7 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long count; count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); @@ -1412,19 +1412,26 @@ static journal_t *journal_init_common(struct block_device *bdev, journal->j_superblock = (journal_superblock_t *)bh->b_data; journal->j_shrink_transaction = NULL; - journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan; - journal->j_shrinker.count_objects = jbd2_journal_shrink_count; - journal->j_shrinker.seeks = DEFAULT_SEEKS; - journal->j_shrinker.batch = journal->j_max_transaction_buffers; if (percpu_counter_init(&journal->j_checkpoint_jh_count, 0, GFP_KERNEL)) goto err_cleanup; - if (register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev))) { + journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), + MINOR(bdev->bd_dev)); + if (!journal->j_shrinker) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); goto err_cleanup; } + + journal->j_shrinker->scan_objects = jbd2_journal_shrink_scan; + journal->j_shrinker->count_objects = jbd2_journal_shrink_count; + journal->j_shrinker->seeks = DEFAULT_SEEKS; + journal->j_shrinker->batch = journal->j_max_transaction_buffers; + journal->j_shrinker->private_data = journal; + + shrinker_register(journal->j_shrinker); + return journal; err_cleanup: @@ -2187,9 +2194,9 @@ int jbd2_journal_destroy(journal_t *journal) brelse(journal->j_sb_buffer); } - if (journal->j_shrinker.flags & SHRINKER_REGISTERED) { + if (journal->j_shrinker) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); - unregister_shrinker(&journal->j_shrinker); + shrinker_free(journal->j_shrinker); } if (journal->j_proc_entry) jbd2_stats_proc_exit(journal); diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 44c298aa58d4..beb4c4586320 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -891,7 +891,7 @@ struct journal_s * Journal head shrinker, reclaim buffer's journal head which * has been written back. */ - struct shrinker j_shrinker; + struct shrinker *j_shrinker; /** * @j_checkpoint_jh_count: From patchwork Thu Jul 27 08:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329372 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 E8859C00528 for ; Thu, 27 Jul 2023 08:13:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8837F8D0002; Thu, 27 Jul 2023 04:13:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 833E78D0001; Thu, 27 Jul 2023 04:13:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 723208D0002; Thu, 27 Jul 2023 04:13:11 -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 64EF48D0001 for ; Thu, 27 Jul 2023 04:13:11 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 425A9B2AC4 for ; Thu, 27 Jul 2023 08:13:11 +0000 (UTC) X-FDA: 81056676582.04.C78BBF3 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf03.hostedemail.com (Postfix) with ESMTP id 64A5A20002 for ; Thu, 27 Jul 2023 08:13:09 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kd6rt5g6; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445589; a=rsa-sha256; cv=none; b=oio0HSUzGNE7uuGDNSKr0FP9NMkCzIg0uK16TUg1r5/ZlU9m2O1MdPAJiAyR9lo+H3BoJW ZYoJR03ucdg1LFHZwA5ljdKnO/M4NNkV8hZYULhVO5HNHGMn6wayZjH4yiDo6xdK4DNGob MrFx+wMwPhbEGLTr1iieZ9lYCF28xfE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kd6rt5g6; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1690445589; 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=SQyM2U1mZ/Gwc1nAOvYev1L9XLZmdJlRT0RgZ5HuwGo=; b=v9jt6qOUudPztB2fmc2esAm4Ox4HrstQBV5HGlAcCpq2kAmKQJca/usPaZFq5IhSmGPlST 3bpu+eZIEH6rsJSYBYFezh5rp+EIwrjRVbQsrQ1OfAHajzjcltzbrSQfaAyUdvijpkoBPa cBRUCktgdx5ICMywT75zaFEvdMLgtMI= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168615b3a.0 for ; Thu, 27 Jul 2023 01:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445588; x=1691050388; 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=SQyM2U1mZ/Gwc1nAOvYev1L9XLZmdJlRT0RgZ5HuwGo=; b=kd6rt5g6FvxszAExAWwDvnGLZ3nlFI6+LjpyYA2SwsBpfxyntyz5JxeLs4IsuFoqam BPrbW0IZbPo4bp5jr8CP6dW+kXsV2/xzlGqHNQMPkgHqzMSniXcziiHnCVK42nJM1noq S50aGwia7MX8euX+8hfeRRERjX2qwSrJrcd+yJ4VULel6DaWSf6W0hZ/qFtzG1N+JN0n uQB95m4CN8ZeNY7Xsu+pZiPFb9O3G4aVUw6FAsCxKpZx+yuB9vunfivBBZ8XUQHuWQvc AX+QkUyO8AP8Aa2+4wftvFDhdV62VUn8gnj7NjCNsCf/vREHbdt8IjenIeReKEgqNeKN BvoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445588; x=1691050388; 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=SQyM2U1mZ/Gwc1nAOvYev1L9XLZmdJlRT0RgZ5HuwGo=; b=XX6MmwsQB7638B/EcHVme+sdmvUji9gO9P+05SNb1067Njyh9t7OjUvIUG2/MX+DLJ lO1jlLtqi+ajk2LJ+RO1lsB8wj7q3ST0ezfm3kI9EmKP3QtReJi1lVx4E1st+DDyhEx1 E2B7AkzLQYSFILQHsTZNGPzinbUcNnOGpWxWBi1vvqWb42pCtZiaScLrqx+op5s66QjC R6ytN0qiuL76RdRSkeLgs59OQbFLS1oeuwH1kXEw+1F+SVOYqydaTUlpME9d550jAY2D E0af8uMThzY5GOdBs22qtHVQNj5efcFI7wkMnPK6tUb/RCZZ8KXjHKePnV1a1R5PkH4i T1Ow== X-Gm-Message-State: ABy/qLbdx/17BHbCbrPB4l2lSncbIVMQlClmE59vZyDvov/6qhIHB5Kf P2Kxu+xbnbz+Sm2Jiokjj2W09A== X-Google-Smtp-Source: APBJJlGx3t3etMepgJMVu+n+Us77oI88lCmbMpzaxwGd8c6y1MJ13X5vnrHVztpBTHVV1RS/gpzzOQ== X-Received: by 2002:a05:6a21:3281:b0:137:514a:982d with SMTP id yt1-20020a056a21328100b00137514a982dmr6062167pzb.6.1690445588272; Thu, 27 Jul 2023 01:13:08 -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.12.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13:07 -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 , Chuck Lever , Jeff Layton Subject: [PATCH v3 36/49] nfsd: dynamically allocate the nfsd-client shrinker Date: Thu, 27 Jul 2023 16:04:49 +0800 Message-Id: <20230727080502.77895-37-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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 64A5A20002 X-Stat-Signature: 9hkdxjcanj99tfbh4niu1gxk8sbedwgd X-HE-Tag: 1690445589-715201 X-HE-Meta: U2FsdGVkX1/71GNf45qHUIdfBp/+rNBYUW0klAdUhQXyxJt7zj0NQAG1C9wdqdcHxWy5A1kr/JcEM2FFLrcApmI9+9ytLBb80DP6UhsFqBqY0IMlVK4V/KPOTjeZps83RY4ws/JyyO6ISr8FXZGGDgNOoRWI0PW+OKmyzA3yizDN/hcQ2j9IWDHhcMpEOqzcFtIojFgDyzR2qChmK3fzzfhFK2pQbr8oWkf/EWFX9TBRVMQfr5CE3LcKTCwyVAm+BvUzI88K8LqEzBwSHbvYAUAcCFqDgAYFX2mOt8v6mvs8Eo8HigjdZ+eW8izpQE1WpMHL/XN17nYpi6m7HZdD7ofwgph+u0QRlBShPO+DdS2I4j0Sn9zJ4J5789JTnP/XBGrXzlouvXcJPP1PF9QQ3oPSLQGrn/pxjpbu1bYNuAzc5nlm4tqp1mKEYqg6Mp3sgi+fmZ0UCNxj4a6Ntvt+AJcSKYo6pkqz9yomD89GUx9uROaZ57a3plw/003Pxr+zFSoMEUBZH2y62kIYXsBFfJcrXu8sVOuHxV09Ohj/pzMRFmEmEjq/pKJQ9sPr6LQYMei00f+cYD96TeN9LAyMHmeE8r6hR+LaWV60z/rQ7MoyUR7bF7vbZCxjP4lcfZ0OrjMtkjvUNFj65pwW9FjyOVOx27jdh/J0DP+EmdeBpbtCzWRCkMYwSx5fson0XBharegNjwc3jmFR64UG0Da7EeLg0scEe0XhT1gMvOxF6PjqNPVeJWBIQ4RVGE4+7+vETNc1DPqcpE2t4YTYTIJzqFtQ8nu2IZV9N+G3igs4EqEG6yFVwOXczNWq/Ul3ZnKICeV90dPYWZlm1THnGsSRLcR3/vlW3r+ME5XBmxATNVEo0TWlLa14F8IwuJNqS0Lm88gkKpph4z3w5K3sTigPS6Klc9ORwh1ODdAjLizxjuFpDkIdSx+g6rBieVPe3CUdNC+48yCdxAT3uRpNlQ5 jY1jyGt9 2IJ+uaVjE+cOxukgX5DeNGHN8ho1Z2YLXHe3LeW56SbX+8ANrt9R8vPUwo1cuII2gRSL72D/erDkEVBhI51WkZ+DvCrF6m/J5srtzIgPXOrZoFo30iW5qeC2ufpVdY21bIwDpHeo9fSZ108i6YAp+eq/4Et3vRwbVruJFyOhPtZWjgq2YPc9WZlhbowplevGz7vhFPkpWhpH/Tbn8o7OriI4dTZ3mwt93dzmetpQanxUGjlVvfjqc9r9wCtip5pMAIu03B6dP7dqvkegZWuIHrQ7m5w41yQSB5yx6R/QJYqZq//Wk4j0ije7l+6mddOw92hOqsJ4AtYoUPrd4RdF3WU2mXX2rV2bHPuIe6+FfmVojaBidS+D5nktQRKaqkLUquT7zS0nRapuR5FEzUhuZCqVpAPNSPHHIozkd+OmZ9GsETuVo96gdfGiFjdzQjjH0YSSER5NVOeOYZ0+7DnNwJFkljXSu0eMh2gQ4zEYeNZLUBB87VbhS2f8+3w== 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 nfsd-client 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 nfsd_net. Signed-off-by: Qi Zheng Acked-by: Chuck Lever Acked-by: Jeff Layton --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfs4state.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index ec49b200b797..f669444d5336 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -195,7 +195,7 @@ struct nfsd_net { int nfs4_max_clients; atomic_t nfsd_courtesy_clients; - struct shrinker nfsd_client_shrinker; + struct shrinker *nfsd_client_shrinker; struct work_struct nfsd_shrinker_work; }; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index ef7118ebee00..75334a43ded4 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4388,8 +4388,7 @@ static unsigned long nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { int count; - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_client_shrinker); + struct nfsd_net *nn = shrink->private_data; count = atomic_read(&nn->nfsd_courtesy_clients); if (!count) @@ -8123,12 +8122,17 @@ static int nfs4_state_create_net(struct net *net) INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); get_net(net); - nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; - nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; - nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; - - if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) + nn->nfsd_client_shrinker = shrinker_alloc(0, "nfsd-client"); + if (!nn->nfsd_client_shrinker) goto err_shrinker; + + nn->nfsd_client_shrinker->scan_objects = nfsd4_state_shrinker_scan; + nn->nfsd_client_shrinker->count_objects = nfsd4_state_shrinker_count; + nn->nfsd_client_shrinker->seeks = DEFAULT_SEEKS; + nn->nfsd_client_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_client_shrinker); + return 0; err_shrinker: @@ -8226,7 +8230,7 @@ nfs4_state_shutdown_net(struct net *net) struct list_head *pos, *next, reaplist; struct nfsd_net *nn = net_generic(net, nfsd_net_id); - unregister_shrinker(&nn->nfsd_client_shrinker); + shrinker_free(nn->nfsd_client_shrinker); cancel_work(&nn->nfsd_shrinker_work); cancel_delayed_work_sync(&nn->laundromat_work); locks_end_grace(&nn->nfsd4_manager); From patchwork Thu Jul 27 08:04:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329373 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 83957C001E0 for ; Thu, 27 Jul 2023 08:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21B1E8D0003; Thu, 27 Jul 2023 04:13:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CC488D0001; Thu, 27 Jul 2023 04:13:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06DF28D0003; Thu, 27 Jul 2023 04:13:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EF86D8D0001 for ; Thu, 27 Jul 2023 04:13:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B9746B2A9C for ; Thu, 27 Jul 2023 08:13:23 +0000 (UTC) X-FDA: 81056677086.13.A590503 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf20.hostedemail.com (Postfix) with ESMTP id CE5A81C0003 for ; Thu, 27 Jul 2023 08:13:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iCbLBUqU; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445601; 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=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=bttbCGtNaZMaev9OxsMXaJdV9v+7m7D9WP89om3gI8642FxdcS1aBjz+q6UhpWUD2k9Kol S9CLj5jb9i6QrpvjjjUhSwU6pygsXZixUOqbaYqh7HLR9rXav/CuBBVv10DD1CxSjSw3x2 cTpRdmIMspYVXP1JjEIkuygkp/VdeWU= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=iCbLBUqU; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445601; a=rsa-sha256; cv=none; b=772n4/cip9JKQTBSTjHo3MYfkrKZtgHacFIXB98FbZorRYvmAb5/kYZ+8uwW27FLguMnMZ fjqjRjod23hAFoxdzllGrK0xlC5PmMQTVfmMBf8IdxN+OLXwODIMwX8lq0L99p4pXzVXT9 H14YxxFbNb8pvOGCxoBrQk4fGx7A9hg= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-686f74a8992so78338b3a.1 for ; Thu, 27 Jul 2023 01:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445600; x=1691050400; 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=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=iCbLBUqUt9Nmpfx9vnMv71z6ZoxeAA3Kwx+3hOoXd1GaTMzDfIKBdQZJLnwkBZI0pa Lp64e3iwzE/rImCGGIb1ibgUBPxOPSIGFFuuYRtSxlo+aqH0+DTZDA4mGtoxEeFwJjn7 eVXRc7yr9jM32bf+/xn99rZxVedfvtJlhFw9fGMGNkAD3ORupJUg3X+ANXG24/AH/vl7 jpmLaXt1oCEYJ/yvLZ0XDwvzYMWndPPs0hfwCexWDUJDE/XQyc02dMzlI6K63u7Ep8SN XNSeVfJxqvuXvz57tL/Yxcln+9J35CIKIXgWOW2mH/cpcfLsA9vX9cNULDu6wCRYP4Zg 0nEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445600; x=1691050400; 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=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=fhY4u9fZBq4F1AKAHlXGnJ7mkbQK+p4ZHBI3bz4fD15HWVStd46wiN91otCaVMzydv JDqPlhQL2/CBycJYqe9TlB5iC370NkIpSRVI6YyQxOwEV/mTmJxPoa30+M402u8fphyc NFtHA4nXWaLGwlLbP5NxQ2W7gcSuAhze29L1qYeSssRmAq5zBYyNrkvedw1rDvlMqXa1 D1J36qRnrqGraLx8SMzcKsN1CtSukyoY4HID0WZ96/pgm9O6RtDd3e80+IxLXT2XFgkR 4qlNEjzbddpsfGOljfzkIF0blG8W3bV5CtOKIk8zA3bjWa2qb1HCtPCcD1M90FjfNj6F ub0Q== X-Gm-Message-State: ABy/qLa50j7tnRZjkKhNlmfiZOBXv8WrsCFFN6clzid4o0GIaRsdzAhp kBpw+lhoFqJpiRh99emR3j6WlQ== X-Google-Smtp-Source: APBJJlFVIfpGcg6LJptv9vKKDXXp5NoXAxRgeIF2Co73Rpi3BTRYlDiWRgj+jM16dBQ5q2UaSpGRNg== X-Received: by 2002:a05:6a20:729a:b0:100:b92b:e8be with SMTP id o26-20020a056a20729a00b00100b92be8bemr5583609pzk.2.1690445600629; Thu, 27 Jul 2023 01:13:20 -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.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13: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, 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 , Chuck Lever , Jeff Layton Subject: [PATCH v3 37/49] nfsd: dynamically allocate the nfsd-reply shrinker Date: Thu, 27 Jul 2023 16:04:50 +0800 Message-Id: <20230727080502.77895-38-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 X-Rspamd-Queue-Id: CE5A81C0003 X-Rspam-User: X-Stat-Signature: o33sb7cqguzs3p8aaxriyzrgqg5ctimb X-Rspamd-Server: rspam01 X-HE-Tag: 1690445601-998735 X-HE-Meta: U2FsdGVkX1+N8xPozyy3A8OQj6ilffHgpCS6amxowp1rEPtBqmwKpl1PkAetXyghJj6bUXthdQrIsz2dmbseAsCD1CHWliH/R51lM42yew4o9tERG1t0saCPaQ59THHbkFz7Xw+scUxTDHDO7+1ggXheHwr9huSYZuMTIHuMn0Jzs/vPFiBlmbgDbw/LfsO4DND9V2ZRVfFOzwU0ttttNUcrR/lzLVdzo87Nj7w3GrZAhT73t+2TRwTOWYwvvG2wzF6el2PXxMOlCRhTiQc7ojpqIw3vlsx5HURhodrFA6qjrIpb+O6ibcsc/nG+ZPH2fVQwkEFQLHC/rtf8ohlKbH64KChaX3ZyJouWcU7nevxlK4pvhgfIGi2YtBEGadxb/nDQCpegK4KrL32kpv5xcknyYkkp/erIrjsP6Vt3Tw7SgKp8zFs+4qzpSzUlgFvDR5REilh5HaKD0UC+2b3Xy9Kee7S7qhnIfIaAw14prw5PJixXAsEwtRowf0phYHMZ5p+7+iodpwJxx1HtS7CEpnodb19d/UGlDNZGYUgUaYMXsVskB3dHSRIw0MX+/xzoXNro3tSQpIiMwAdcsrFxEZDGiQ8ksmT4nd2bio/+GuQO8cgX6PMWK7lzngsoI5XqDLrzr8FPIeOWH+W12N5iDyIEsW8D5E4sV+JEGOO+KHhnLWMqI+czsJXpUGbEsIox0ZMC0PPG6NDVqFKmWHcro39x/X44C04qTn3sfAaOMJWOPJgTUpoAKRfrVzOw6NuItGXQ8GG93DcO+9ITI886YC7VbIAHl6yulmNcPArKl/F9JL2ypOlKcqPGuU3Vk6ZPQv93SgF+b/gY7RRUcFv6ewqFphyuDTsCnZEBb31McgKOlWqHGWKjsQHjkj2+QC5+GtVmxz4Vx3OOlP8CQ13zzczJ0NPhm6JtIWRd0FHIYz6TuCo/N0EIQ/zVSjcsrRGiyYTu5kQljyfcKOqxRIK 28CnRU1g R89eaRKnWBfT3urdFAglzzqbxP95RD2rWh2GQp9J7Sg+GscuTqvPNdM5iIbKBoKPABZGrfNeStOEilvjV2C2xmL0fcVJv4k4Y0LrzF7qF6pu8+JHP0uC6yIe2dsHG+/7k4G8+T1UhnkdlVyHMIq7qPjuwXGWK1DpsiPdQuq2kJ7QKmMzLaH92iHiG/iRlo8WLzQJB98lPkiKCk5CzO3yobBtuFJyc/xYVCQDQx6FbfwHlf2q8FdngokscKKiCykueodIN472NqfuYbP9iVbSY6nzZJlUxzbbaMikqqp9PghVg2yuTWbtJj7xcPCypvjlazKPk3eZLX5Fod3TC7eoESIp+YYG5q7oOFxCFPiDwZDioRTQjejn44McZaRYCM/CD8q28lAO+BpcQCV58Ztk8BvTSxinyr96sMMXfvkMTHhFec8Axq1PPogr6Fy1wzXFaUNI0u+SSz/rpCcWvJk1oAtaHD/PI1ut/1KWynv6m19vgWOgrK7IgVmqFgQ== 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 nfsd-reply 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 nfsd_net. Signed-off-by: Qi Zheng Acked-by: Chuck Lever Acked-by: Jeff Layton --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfscache.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index f669444d5336..ab303a8b77d5 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -177,7 +177,7 @@ struct nfsd_net { /* size of cache when we saw the longest hash chain */ unsigned int longest_chain_cachesize; - struct shrinker nfsd_reply_cache_shrinker; + struct shrinker *nfsd_reply_cache_shrinker; /* tracking server-to-server copy mounts */ spinlock_t nfsd_ssc_lock; diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 80621a709510..fd56a52aa5fb 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -201,26 +201,29 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) { unsigned int hashsize; unsigned int i; - int status = 0; nn->max_drc_entries = nfsd_cache_size_limit(); atomic_set(&nn->num_drc_entries, 0); hashsize = nfsd_hashsize(nn->max_drc_entries); nn->maskbits = ilog2(hashsize); - nn->nfsd_reply_cache_shrinker.scan_objects = nfsd_reply_cache_scan; - nn->nfsd_reply_cache_shrinker.count_objects = nfsd_reply_cache_count; - nn->nfsd_reply_cache_shrinker.seeks = 1; - status = register_shrinker(&nn->nfsd_reply_cache_shrinker, - "nfsd-reply:%s", nn->nfsd_name); - if (status) - return status; - nn->drc_hashtbl = kvzalloc(array_size(hashsize, sizeof(*nn->drc_hashtbl)), GFP_KERNEL); if (!nn->drc_hashtbl) + return -ENOMEM; + + nn->nfsd_reply_cache_shrinker = shrinker_alloc(0, "nfsd-reply:%s", + nn->nfsd_name); + if (!nn->nfsd_reply_cache_shrinker) goto out_shrinker; + nn->nfsd_reply_cache_shrinker->scan_objects = nfsd_reply_cache_scan; + nn->nfsd_reply_cache_shrinker->count_objects = nfsd_reply_cache_count; + nn->nfsd_reply_cache_shrinker->seeks = 1; + nn->nfsd_reply_cache_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_reply_cache_shrinker); + for (i = 0; i < hashsize; i++) { INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head); spin_lock_init(&nn->drc_hashtbl[i].cache_lock); @@ -229,7 +232,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) return 0; out_shrinker: - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + kvfree(nn->drc_hashtbl); printk(KERN_ERR "nfsd: failed to allocate reply cache\n"); return -ENOMEM; } @@ -239,7 +242,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn) struct nfsd_cacherep *rp; unsigned int i; - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + shrinker_free(nn->nfsd_reply_cache_shrinker); for (i = 0; i < nn->drc_hashsize; i++) { struct list_head *head = &nn->drc_hashtbl[i].lru_head; @@ -323,8 +326,7 @@ nfsd_prune_bucket_locked(struct nfsd_net *nn, struct nfsd_drc_bucket *b, static unsigned long nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; return atomic_read(&nn->num_drc_entries); } @@ -343,8 +345,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) static unsigned long nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; unsigned long freed = 0; LIST_HEAD(dispose); unsigned int i; From patchwork Thu Jul 27 08:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329374 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 69180C001E0 for ; Thu, 27 Jul 2023 08:13:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BBCF8D0006; Thu, 27 Jul 2023 04:13:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 046AF8D0001; Thu, 27 Jul 2023 04:13:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E01218D0006; Thu, 27 Jul 2023 04:13:36 -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 C9A778D0001 for ; Thu, 27 Jul 2023 04:13:36 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A0A0A1204EC for ; Thu, 27 Jul 2023 08:13:36 +0000 (UTC) X-FDA: 81056677632.20.E3DB87A Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 82C3A80020 for ; Thu, 27 Jul 2023 08:13:34 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AiXoaCJQ; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445614; a=rsa-sha256; cv=none; b=2hGL/kU8OIslPUiYBime0SXRbD0OikvEfnIADBYLQN/wA0xHXpiS6IdqbhlE5rMBQEH9cB YByisAaE5Q8brr0qYccq1bIKEoGweWKwB6lVBccqt14ujywdHPQj8/IeHVhMSrBgSwZy2s UXleCwyMKGz92Cs5xbltz5AU1MNbKMo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AiXoaCJQ; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445614; 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=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=uvEeF1x7Pv6l3bo6Bv0RNIFmmwyH6kYWb71iK/nhr5asiLK4RJn5RqHLBeRJ0o0S6IuZS4 Y1Xgt9IqViB7MoiIynU4pDbxk806jHJ52Y43XdZx8EN+ww/msgGoCkibRxhl1wBRgOx0rW lP5UWFqVZCdBv0SAe9tMGO2X8ZwbnrY= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-686f74a8992so78388b3a.1 for ; Thu, 27 Jul 2023 01:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445613; x=1691050413; 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=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=AiXoaCJQdjYD9eYmeEdrfJ7ezATe9Yx6/bwBgW+5G+EPOMCuXYwEAcwi/JFENHTjN3 RLofwFvJd4EkqfH7Ye6KmIjKXgnfjEMN6IQZZPzERz8d2kaa1LDxbOfy1pXfbOXi//fW yPmgpOzP5ISM/DRd0jetvScx//7ssTCBUe2enciakCKenXGhXZrdb9q6vjgbH3ZMQFpH R1cJwZwEOETjjGMipjwgI0l9uWlKWu8vb1MB9swWpnARqP7hyemEh7msGfN9mYd5xYpI D03dkm0FvaoEJlj9bRrg4eXRdtCSaQUY5I5xaJER5wRv+adUsRWUp3ZNy7xFaIahEhPe Q+Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445613; x=1691050413; 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=jaqVlo27zysQOw4inLaa7RWYi61naAqQm5GJ5upJpN4=; b=Ni73ZTA2jDpqK1k1gKhPnSgUvHHL/fTBVeUlx5rzIDZO0p+MVqwQDZ9GAZEYXllM0A W4IrDWbr1ZIZ5r9874KP1zU0MCX1M2/dnRsNZ1EwS/Ve8EEh9ri/BpdMX83VJThhCZdN Ree/1sjG98HXYSUdRk/2yXIU4Fau+YYWRLw9f+wOUVI1YI+7EJGwho2yxUCQK63PcU10 OIq4YOr8jWySdPlFEdoHz3jLyQxs+r7eoMzgKf6t2KJG8yG1k01wD1UMh8rsBuXUKkIb vYYAJ12OIEgypE0NFS6v7bo5jE2RvG4cAiUiymZVYe40EYTRHJAx/Y32P8obGQJluHtk pd3Q== X-Gm-Message-State: ABy/qLbTlfK6S7L9VvQVlR4GIKNgyc/XLNOgXPv97zIdVftttKnZgwFX e8JX1Dgk2RgMl2XNHiueQKutVg== X-Google-Smtp-Source: APBJJlG+tRTw+eNG8sDYXmQBYWrWDa50m7E6kRjtDYwVrWUQOS5ovTAWRl9t0zD5rxSD0dIJ86GpuQ== X-Received: by 2002:a05:6a00:2d82:b0:675:8627:a291 with SMTP id fb2-20020a056a002d8200b006758627a291mr4587660pfb.3.1690445613284; Thu, 27 Jul 2023 01:13:33 -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.13.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13:32 -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 38/49] xfs: dynamically allocate the xfs-buf shrinker Date: Thu, 27 Jul 2023 16:04:51 +0800 Message-Id: <20230727080502.77895-39-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 82C3A80020 X-Stat-Signature: dyojoaez1osucai6gecydoagkw5xu61f X-Rspam-User: X-HE-Tag: 1690445614-681758 X-HE-Meta: U2FsdGVkX194IB1hIZ7uup36zEtXe7bPAsRNc/JZV2AOHfS3YPx3gqn2f2igpeKKRZVLXnPbD3fNIeeRvyOZ+cT2zosadYqNom6y6gFZA1kkSfJL+uQQqrU5AB675UStKGADjzGZMLPrGBU/51Ch+1ENzsp+CvJP2b0X+FpU2+3q9veqf3m7/kQb5p0qEpm/6EQgsp3weyoYulc2tTcZO6fE5tU0EBziTp9AlPGBM0NtnfXb+n/q7UXmFz8wEtaNsR3J9PrbnhqEQz4pSCYstVvy9kkHYt/G8HDCFU4yDbwiqAFIuDTaYwnkcp+X6UBuaA5rn1KIiWQkyjIYOXvzQwqafVyUbl2C9fV6VJb+LsWR+W1FAZ8gqEWigo/VAmbgM84IDSXTJftXJOUfjPIDUYZWTzexbnDzYXEOF4BIP22bekZ5uZv2ae+F4vHt0SgGgJVvoAaDqGwIcqNZnYrCMnI9eHFmt+48f+gchFkLMkO+hhz+0hZvZ4E8uOn6nruk0QVRClERm7vEQs7//dtqPdm3pEQ3R7VrsTHfOslybXAGpm2/bMhd1assp8DaK60imgZUMisWiKAszSkqZAq3ou/LLfcPpXUWbK1Vo9l3RXPt5qa5yMXZHiXAJpiM2DLevPBHSVzK0SVqjQtNIcBBkc6ZsORPRbz/6KZntBtmFzmIxIHcIZddCSFuJbsgYGhrNXLj2F9WMqox+H5pNGGjyhIIArrffLwIYtgxK3DqoBUPkq5XEK+dDOxzxW+QAAL1qRW2jNs0DgBK131SJ9cXlEaVx8YhjYb1F2NziBgswmaEsJLrAyg7JaLF0c7l60VEaJpN/zE0wnK3XSf+Uy5oV+SPvqPuDyArtteN0Wku5640f9VeJTkB+lJa9sVJycpZUSc+ORKbimdw4RFOzBL1oWhYlfgk+PWXOjFHO9aM4wv+2QcD1wyAUTAVSKc3OUaRDGnw/aaTkj6u+vqpFDY fiqNKWLj 4Ndjjxo4pC3RFEHIEwkXFywPNsdllh9gMopYmNL07B9dV+MLqo5JyN47kXpAWEVKupC3Ty82+5R/EWTE/l4G7tHNcF0FPRCiC48daryHQhoqMj+rXLOms5KFtq0mlOb4nAWYqhysr9EfbXO8NF1OhA9twhDsC8P4b1xYYnQjzQewyHgbkKnnf0J/2l6gCh6hXc6s0E3AJeboZB6VH6lvoo0O1ant8d+udSON0+Cr0mLTUhtysdZEaYbDvJ0fQ1QFaZRoof1Ggc2T6l7rLqCYHEsMI3/t7Pg0A0POSh5ilvAnXGRJXwInb2zEE2SzwOx63b8Viw4gx795l0Jakppaex3Ly+Vshm77pwCw0AlJpeWNrNbDodNOYgmwChkODXwZa7tW7wLXM7gtzCsV4y0OXZTl2acWfNeROLrTT 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 xfs-buf 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 xfs_buftarg. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/xfs/xfs_buf.c | 25 ++++++++++++++----------- fs/xfs/xfs_buf.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 15d1e5a7c2d3..715730fc91cb 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1906,8 +1906,7 @@ xfs_buftarg_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; LIST_HEAD(dispose); unsigned long freed; @@ -1929,8 +1928,7 @@ xfs_buftarg_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; return list_lru_shrink_count(&btp->bt_lru, sc); } @@ -1938,7 +1936,7 @@ void xfs_free_buftarg( struct xfs_buftarg *btp) { - unregister_shrinker(&btp->bt_shrinker); + shrinker_free(btp->bt_shrinker); ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0); percpu_counter_destroy(&btp->bt_io_count); list_lru_destroy(&btp->bt_lru); @@ -2021,13 +2019,18 @@ xfs_alloc_buftarg( if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) goto error_lru; - btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; - btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; - btp->bt_shrinker.seeks = DEFAULT_SEEKS; - btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; - if (register_shrinker(&btp->bt_shrinker, "xfs-buf:%s", - mp->m_super->s_id)) + btp->bt_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "xfs-buf:%s", + mp->m_super->s_id); + if (!btp->bt_shrinker) goto error_pcpu; + + btp->bt_shrinker->count_objects = xfs_buftarg_shrink_count; + btp->bt_shrinker->scan_objects = xfs_buftarg_shrink_scan; + btp->bt_shrinker->seeks = DEFAULT_SEEKS; + btp->bt_shrinker->private_data = btp; + + shrinker_register(btp->bt_shrinker); + return btp; error_pcpu: diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 549c60942208..4e6969a675f7 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -102,7 +102,7 @@ typedef struct xfs_buftarg { size_t bt_logical_sectormask; /* LRU control structures */ - struct shrinker bt_shrinker; + struct shrinker *bt_shrinker; struct list_lru bt_lru; struct percpu_counter bt_io_count; From patchwork Thu Jul 27 08:04:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329375 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 32075C04E69 for ; Thu, 27 Jul 2023 08:13:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7FA98D0007; Thu, 27 Jul 2023 04:13:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0A698D0001; Thu, 27 Jul 2023 04:13:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 884078D0007; Thu, 27 Jul 2023 04:13:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 704EF8D0001 for ; Thu, 27 Jul 2023 04:13:48 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 48CA21C9253 for ; Thu, 27 Jul 2023 08:13:48 +0000 (UTC) X-FDA: 81056678136.29.F0EEFC6 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf21.hostedemail.com (Postfix) with ESMTP id 747A91C0015 for ; Thu, 27 Jul 2023 08:13:46 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dkRrWVkS; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 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=1690445626; 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=vAE6p5mA5n3yxm+4IPfXfMLc8MGv4J5wg3qHubren08=; b=2ClKWz+f/ghtcbNwfsssE1O7aj78nq71jzvEiijlzELqumCox6Gb+9QIbZYdpqj7R+7myw gg82gri1amGe/TYtDNO6t/tav3Dzi8Y+QFCHBlbzrUP4xHKtmm51x738ezP/fZsUiUwMv2 pw1L5AFBgO8dtqiM2evHzx2d2eDm6Go= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445626; a=rsa-sha256; cv=none; b=RObdaIAwruwO/VR0BClT/7MmGakJhuow345kgYx8mD89qeWrzSAy8Apwy+pLlLHqrI/yaM Kjutxdrfdpvx4IR6JQbxC45GHYH85fQqQRfIfQYDCzmaIvLpYIZ0s45+XHIyS4dQUJ5GWJ h8CxO9IYtUNXyfAZDJvLYt6zpKRN91o= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dkRrWVkS; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168744b3a.0 for ; Thu, 27 Jul 2023 01:13:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445625; x=1691050425; 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=vAE6p5mA5n3yxm+4IPfXfMLc8MGv4J5wg3qHubren08=; b=dkRrWVkSv9/U3+e6QsQd29dMPuttcg2M13ZLMDEEIMbfSamBJHJdLtNY2sbEZ+YzhY 5BtYLYzutGknAA+e956eNSlbl7nK+9UwGbTk4YjZb6fHHFpCk0FXoHpJAi6M0jM7aFZF +CarAybA7Fmb9F2zoNtgG1DfzDYBp6eqgkICDj2Asy83tRT0LF5pvIpkdtR75UYStLmf 37kqliTWk9DV3Fw2NufQf0BV5/WVkKX05IEilefRJ/OwJCaH2LBTkZCCI3ZIC5RNHqLc p1thIF8tkbzc9m+CHBYGB6mtVDqiYNqHlAVUDSIfQN8XwfU9rYwJVwEXJvC3bJUByZYt Gdag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445625; x=1691050425; 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=vAE6p5mA5n3yxm+4IPfXfMLc8MGv4J5wg3qHubren08=; b=imdKpSPthQsHJczelwzJgnNzE61xRMB3C2kx5z6JcyymqKCWApLYD76HGzG4TENp6t mVtcN8f7rF0R3XaDOXoNkNN6OAzLBCy3QIGrvplOepfXMjgAhoOR3kca/OJgbx/f/2hy rV2LH06TMHxXlEEn3vvUnKRXCBRo1jEpz0b2hWLtIMrwim4NC5DH48dmslpQmXWhkbO8 6kDGU1e+hbxQY/GHFSRF9lIwlhMpeslcq7lumeb84Fk8S1t4EB8qfBOB4ugbkRbrXlLM Ou11Q8ssOLolEFnbBzrONYhmA9onimY/AC2elkRnLDTNT+kdxfkIXuRpRVGBH6Q3Vlqc n6WQ== X-Gm-Message-State: ABy/qLbHtsztk9j+vARxIqdZxavK9H0UsRaeOvPnenDrEN95GXdZsPDC wIrR9HRkRMCtN9tBHrE+72LIMg== X-Google-Smtp-Source: APBJJlGsGKc/yd3ypxFPLcm5JieT1oixTNIsPQhWBcbXzQEArQwAQppjIOSAREcWHLbqRGZH8ALcGA== X-Received: by 2002:a05:6a20:7d87:b0:12e:f6e6:882b with SMTP id v7-20020a056a207d8700b0012ef6e6882bmr6446407pzj.1.1690445625322; Thu, 27 Jul 2023 01:13:45 -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.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13:44 -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 39/49] xfs: dynamically allocate the xfs-inodegc shrinker Date: Thu, 27 Jul 2023 16:04:52 +0800 Message-Id: <20230727080502.77895-40-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 X-Stat-Signature: 4jjfjb68wjqy3rbaeoxpezbps6b5sg3m X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 747A91C0015 X-Rspam-User: X-HE-Tag: 1690445626-535448 X-HE-Meta: U2FsdGVkX1+vmI3xxAaLadO/fmjnqT9t9+C0S5JweSUvFyKXnaexWLR8jKslF/+eEsWXgqx9P5vORy2Y+t6GzHcYNeeDRFraPlmTN2VJHZG12urvkd7nKijB/8hsB0GbfhzO1vmKrrUmQ6Aittuzn/vSDWnCuoYQeQEVO1CpvFPjkgP2GyTV7r+NLncSm/bBF7laANE2gdR1g34VbBBrtPyy4qiupbB4bHLODmhr4sD4SiGslfEiS/dVyOo319eLTATPMzc8dbyZqdAUe47aq2A0zZ5tuUPSU7h+VMnSbQkgBaQI9TRDpWWTHaheWVlQ7fsJHS/+Z7OCn9LVTDwvYlZU2rpSmZRx09vedTk9BPIE+a3Lj4O1sqOXQx8EQrmTG8g9kpTqPUXc3aXa38nAXfs0KhbShRjGkUsMzGWDL1lbpJ8UnUtZs4iKwWHFMGnf84eU2g3V84qTADdP1WXRWzTyJYy8klnfpMb+P7sI9UrlU/n+yaxbW/v04sFa9kjJhC7OBsisZMDV8IwmX5Gp3BRPk0idci7T/4BTvknEKBgWKfn2UiUCSvJkdOtSbZp/wNaongJF+vkDAFDVTgCgLQb1nblZAKqpeKc5OKUtp+21u8Z0EjNXxTwTTwkwnO4rWLEREEstZuG4GQPq1JhYYP9+KSudRoFeotqIRiiUmhw7jfRfvMpKiic0L7nDGBjgWkNs7Pe6zUUAlnOQI8wA6hRb4c35hO1RwxrO9UUMBtcQw4aiLw+fsdSxrdvExozMfXXGUYjxegKOIow2cPi9UdOTFqSF1vujsyNVi1SHJE/X2gjDh11yAYQPBv7lCSGMncNhSzLcvUrDqefuEZv65AYT5oEfX1NdQuMvKFqBZkHLB6CBIFK/eQ9JQXcZR8BjYFqG18Krm94CKJeg3UJ+ckAyGqD7J0/kg3YWRa3eBzWD0SIw86ek7CuhA/dIWvRqOVZCn5Kxutz4Ug0lYfc WqiD2j50 tqNngrU/DxoEv9k6G8p4/IK7htp9UWsh8xX/gpmi0iLjmi9xyHJi1UZ3xNF2qQ3ye+8bhWE/1zQE14s+44aCz4ZdemOTH+NKFLFpsmFdlnIYjDXTZvfAG55AAOWewRaZ2CIBQpP/gNyZzyO8xBwVD6+5ztSbxCOK1dywJFdo2HdI73QSZtkzwkdtI5U3Gb9Qv44P8K8+nUPhyggohFZL+Shs+sNNaFdftfDgn0W4c2lmC6RSghZTsKCfM8g85jtsUIn1HhPPrcLYIqKwNfUfnJnLGi1tqOt5weCKEFRvTJCNX51W0wMgqEfponFZvMxqFApgSs062a5CO0TZ/o0OUwb2K75K/N8sxgsiNntq2npNKWubgO/ula69a5W+2k1EElDb4bUIor1rBVS4LXllZnIC0vRAP+gYjFWEi 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 xfs-inodegc 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 xfs_mount. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/xfs/xfs_icache.c | 26 +++++++++++++++----------- fs/xfs/xfs_mount.c | 4 ++-- fs/xfs/xfs_mount.h | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 453890942d9f..751c380afd5a 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -2225,8 +2225,7 @@ xfs_inodegc_shrinker_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; @@ -2247,8 +2246,7 @@ xfs_inodegc_shrinker_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; bool no_items = true; @@ -2284,13 +2282,19 @@ int xfs_inodegc_register_shrinker( struct xfs_mount *mp) { - struct shrinker *shrink = &mp->m_inodegc_shrinker; + mp->m_inodegc_shrinker = shrinker_alloc(SHRINKER_NONSLAB, + "xfs-inodegc:%s", + mp->m_super->s_id); + if (!mp->m_inodegc_shrinker) + return -ENOMEM; + + mp->m_inodegc_shrinker->count_objects = xfs_inodegc_shrinker_count; + mp->m_inodegc_shrinker->scan_objects = xfs_inodegc_shrinker_scan; + mp->m_inodegc_shrinker->seeks = 0; + mp->m_inodegc_shrinker->batch = XFS_INODEGC_SHRINKER_BATCH; + mp->m_inodegc_shrinker->private_data = mp; - shrink->count_objects = xfs_inodegc_shrinker_count; - shrink->scan_objects = xfs_inodegc_shrinker_scan; - shrink->seeks = 0; - shrink->flags = SHRINKER_NONSLAB; - shrink->batch = XFS_INODEGC_SHRINKER_BATCH; + shrinker_register(mp->m_inodegc_shrinker); - return register_shrinker(shrink, "xfs-inodegc:%s", mp->m_super->s_id); + return 0; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index fb87ffb48f7f..640d09891a4e 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1018,7 +1018,7 @@ xfs_mountfs( out_log_dealloc: xfs_log_mount_cancel(mp); out_inodegc_shrinker: - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); out_fail_wait: if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) xfs_buftarg_drain(mp->m_logdev_targp); @@ -1100,7 +1100,7 @@ xfs_unmountfs( #if defined(DEBUG) xfs_errortag_clearall(mp); #endif - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); xfs_free_perag(mp); xfs_errortag_del(mp); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index e2866e7fa60c..562c294ca08e 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -217,7 +217,7 @@ typedef struct xfs_mount { atomic_t m_agirotor; /* last ag dir inode alloced */ /* Memory shrinker to throttle and reprioritize inodegc */ - struct shrinker m_inodegc_shrinker; + struct shrinker *m_inodegc_shrinker; /* * Workqueue item so that we can coalesce multiple inode flush attempts * into a single flush. From patchwork Thu Jul 27 08:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329376 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 23DBCC0015E for ; Thu, 27 Jul 2023 08:14:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB9AF8D0008; Thu, 27 Jul 2023 04:14:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B42588D0001; Thu, 27 Jul 2023 04:14:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BBA68D0008; Thu, 27 Jul 2023 04:14:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 85FD58D0001 for ; Thu, 27 Jul 2023 04:14:00 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 66419404CC for ; Thu, 27 Jul 2023 08:14:00 +0000 (UTC) X-FDA: 81056678640.11.8470F4A Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf29.hostedemail.com (Postfix) with ESMTP id 74FCE12001B for ; Thu, 27 Jul 2023 08:13:58 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EDfCdETq; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445638; 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=wkWZ9/xaCXa97bQ5JXnZc5xW9B3SNGrJMT1hKcCw6ws=; b=Lfe/aj9ytl9Vsx7XkJpYLaj2JcIzDoRcAt4VxqJ3ou14vxWDA82QvMPp2kBNJ7+1ys9MCD e1eY/l4jF1CvZ3Ti9vqZ8BtdVKd1TqvU3ZqWx7HOOXjWidCFAuvxXvHVgO4iAy8FlNgEv9 kKDfTRi9avFTv7+iL0Tj1JI/s3i5ENk= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EDfCdETq; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445638; a=rsa-sha256; cv=none; b=w7rmCQx/Nmfk6gZyGTpNCTPZ/ChA2h7fd2382emTDzSWU7fMt63F7lkgQDAz2g8tEj4qEi fnTv6uKVf5xHEVKaj17aEkln2XJvnEQKDHwbqB2bjZ1IewYcGjA8l7L/Wba+/HCc+Xnd9C 7eTkrDMjgikNeCSbpnvKjMpQRpOYL5c= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-682eef7d752so204933b3a.0 for ; Thu, 27 Jul 2023 01:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445637; x=1691050437; 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=wkWZ9/xaCXa97bQ5JXnZc5xW9B3SNGrJMT1hKcCw6ws=; b=EDfCdETq+fWum4Z4rVmLJcfO1jsg67VgnqiA/czndVSbNlSpbiLUxCCQQbrycQZD4N jQ6ZzEztmrAV1/GQh0DPbs4MerEzMqTN5oUJT+1JgEVVCAFedy/wmgVhs7WN/b/b654/ J3bWoofyGEQUeJzT2evHimB9xJj54scgZA3ezNM1eyl//hvUHn6qW8m2jc5RxZ9Q53pq qjYZmev8IqT72hXdHUOA71yDJ6nyeNuVcIJzjtWGkynPPHPpyqKgHAKZWC3Im8l22hhd 2mNa6yYVElvUfcaQGhKZMnwewb3KL70R9vxxm9ctoitBRKZ5V08UPUQRdkaKB4nkVDWK NCpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445637; x=1691050437; 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=wkWZ9/xaCXa97bQ5JXnZc5xW9B3SNGrJMT1hKcCw6ws=; b=ZcKNhtXX/NNk5QPBTgnicyfpDgN0Y8muLdSbZYS8NYqph4YI7f1OgFBxXGBY/B3Gu6 aLDIg7EGxJg5CpOcCnLnuaWkcEOWVzdvhyLRhxTwImyuxOvpisxHXvZSJx65lcDXpHon JfH+Av3G/NO75SJW1YGbfrln4lXrcuJ4JbJifoaND69XzDE7hCU208nVtXr1RP5cbUvK /6QtOfPXb/r+yKEWjOJ1VfeaJCY53YkzQ4tRuXTHU5zrCRrDKTNQqecK8LS3mTtLS6KH yRWvxv04CZf0pHh3htz0ZaDx/C1nFW4XHE1QEtJwEvxCMu242og4B1iNLvsDCYjLtKcp 53qQ== X-Gm-Message-State: ABy/qLb3todLpmsbBCyADwOcJHEPkIUtqxRjDLdGnjXXz3o58u3aZLe/ CmWBPZyAnhIOje2Y+yopXzfB7Q== X-Google-Smtp-Source: APBJJlHv3kehM44VAWCca2syD2CKM7i434EcumRqZh5gO/U3rxv+9ZnIssQP5Ien17rj+O8gWl3H0Q== X-Received: by 2002:a05:6a00:1586:b0:67f:8ef5:2643 with SMTP id u6-20020a056a00158600b0067f8ef52643mr5213351pfk.2.1690445637383; Thu, 27 Jul 2023 01:13:57 -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.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:13:57 -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 40/49] xfs: dynamically allocate the xfs-qm shrinker Date: Thu, 27 Jul 2023 16:04:53 +0800 Message-Id: <20230727080502.77895-41-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 74FCE12001B X-Stat-Signature: oko63qwew18pm73m4oj8pyd7jwi594dq X-HE-Tag: 1690445638-981369 X-HE-Meta: U2FsdGVkX19x26eQaiGLWiK9eRfkSpMljW9BASCZpr6pATriS79IfGLJylJZKblGvKxC/YatdLcJngu1MPhht0eWqZCa9Cq1g/2VfGJQ8x5xIjRDeWTqR2cxEG6B67DGyu3I3NoxgZ8X+hk0m9pmhVMeMyh9rLMhu0hl1eqKbdQEZIXb4w3VAFYRiCfJ0OQocr2vOmlyBy7vnp7drCe2CGgUIyf/+DpUxQuxF0SeZDzcaOpJV3Nsf5vkTILg/4XK6rFl76UHzoRK2LaEWifET8gHeWXTWvg9VOVBCj7HedBo6OcYN5sd/RlRTv3XXlz6lgjnjG5qxvj0whujuP0rhTMokcBbxrA6qHkEjTv+YIBgKod0uRYmwtS6OHGSEI5kGM4Q96jGkbpaWN++JaGALwjtXxgKFTljCQ2TYnA6QnfAjG4G8lULOJQMCLR3xeT8EIn/bLh63KVBUn7pptvAjaJFE32WbNAa/fiQ1ERTitPu/Id5NbZkbnd3v+EA1F05Yt2WO0jGbp/aw0ZaXfaw3FGDOLuOmCa+VrgzT/9G2AsoGDKDjxhctc2btEG4To2Ob98JFPEl3P+G93l2lSGqcQlD8EBy1rpy07u+U8mtpjlLVmY/6MPHtQDfKuo8Ag+xf4tHEuWu7QGNezJ/wmeTsMQ2jl3ffOrvOxckzvzgPlIFPnoIOzPyzXvxnsl34ES0NtmurE2Now2q+dz/UM/KQYgfXINNjdIx3mC3ya4F3FQ1rcF1oEh8IWZIBFbmh+ztlhg2P7RrpKH1Zj25YjjztjJaCss3jP6pM38N8oXkLwNxUxqx/bQ8zI2Sk5I9rArJpgDubtQMWruqz0kCV3eo2K40658rCiWmRae61pxzhe9PD7tAzEgLHSykm7sMXZCAhAe6gDd4oTS60Pukb/cajQGqynQwD3jyZZ8mkM/FEgVLtvRCApYLBh2rqEde16ckPcjkZmLwNgD+XKabYL3 hlX8vMoX AyxQR0nt6u9//xAeZeH7j6GiNj2nF/YiwwGBTpen1MO27cLdusqxB225XG6xAtYr1xqY9cwqprsQRtLOZxY+Fl/vBtQNXtGQbrQCn8YWBszaDcyg2X2FsC+1UiKzG57c/R+CoFLQijff9wChKOvQR23z6P+qK6F9LNv0ugSrPjcU7x87oAYfg64V0P3jI0Zya8AbRNTL/Rwo6WsUYZJqMf8apPiXPeF6JEKQA1Xr4s7mNujEXOMPrzhzWXgBYp5U7bIt6iDPyUvGQskyJsyVLFtvzlmDCj2Me/HxjTDLDjV81I44pUwWXxfhVyTmvs8/P9KAeMQMhEoPa1FbQfOOiNqlgAQ4zO6h5mHf63vqp3sJvL5nIRTYkqktksSRaWpH9S5Ja6AzeKyhDkbwIxtawlqSyn2xbSRZFQXY2 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 xfs-qm 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 xfs_quotainfo. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/xfs/xfs_qm.c | 26 +++++++++++++------------- fs/xfs/xfs_qm.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 6abcc34fafd8..032f0a208bd2 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -504,8 +504,7 @@ xfs_qm_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_quotainfo *qi = container_of(shrink, - struct xfs_quotainfo, qi_shrinker); + struct xfs_quotainfo *qi = shrink->private_data; struct xfs_qm_isolate isol; unsigned long freed; int error; @@ -539,8 +538,7 @@ xfs_qm_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_quotainfo *qi = container_of(shrink, - struct xfs_quotainfo, qi_shrinker); + struct xfs_quotainfo *qi = shrink->private_data; return list_lru_shrink_count(&qi->qi_lru, sc); } @@ -680,16 +678,18 @@ xfs_qm_init_quotainfo( if (XFS_IS_PQUOTA_ON(mp)) xfs_qm_set_defquota(mp, XFS_DQTYPE_PROJ, qinf); - qinf->qi_shrinker.count_objects = xfs_qm_shrink_count; - qinf->qi_shrinker.scan_objects = xfs_qm_shrink_scan; - qinf->qi_shrinker.seeks = DEFAULT_SEEKS; - qinf->qi_shrinker.flags = SHRINKER_NUMA_AWARE; - - error = register_shrinker(&qinf->qi_shrinker, "xfs-qm:%s", - mp->m_super->s_id); - if (error) + qinf->qi_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "xfs-qm:%s", + mp->m_super->s_id); + if (!qinf->qi_shrinker) goto out_free_inos; + qinf->qi_shrinker->count_objects = xfs_qm_shrink_count; + qinf->qi_shrinker->scan_objects = xfs_qm_shrink_scan; + qinf->qi_shrinker->seeks = DEFAULT_SEEKS; + qinf->qi_shrinker->private_data = qinf; + + shrinker_register(qinf->qi_shrinker); + return 0; out_free_inos: @@ -718,7 +718,7 @@ xfs_qm_destroy_quotainfo( qi = mp->m_quotainfo; ASSERT(qi != NULL); - unregister_shrinker(&qi->qi_shrinker); + shrinker_free(qi->qi_shrinker); list_lru_destroy(&qi->qi_lru); xfs_qm_destroy_quotainos(qi); mutex_destroy(&qi->qi_tree_lock); diff --git a/fs/xfs/xfs_qm.h b/fs/xfs/xfs_qm.h index 9683f0457d19..d5c9fc4ba591 100644 --- a/fs/xfs/xfs_qm.h +++ b/fs/xfs/xfs_qm.h @@ -63,7 +63,7 @@ struct xfs_quotainfo { struct xfs_def_quota qi_usr_default; struct xfs_def_quota qi_grp_default; struct xfs_def_quota qi_prj_default; - struct shrinker qi_shrinker; + struct shrinker *qi_shrinker; /* Minimum and maximum quota expiration timestamp values. */ time64_t qi_expiry_min; From patchwork Thu Jul 27 08:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329377 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 37866C04E69 for ; Thu, 27 Jul 2023 08:14:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6BE68D0009; Thu, 27 Jul 2023 04:14:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF3E58D0001; Thu, 27 Jul 2023 04:14:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96EC88D0009; Thu, 27 Jul 2023 04:14:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 82B998D0001 for ; Thu, 27 Jul 2023 04:14:12 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5076F1204EC for ; Thu, 27 Jul 2023 08:14:12 +0000 (UTC) X-FDA: 81056679144.19.4FE6018 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf14.hostedemail.com (Postfix) with ESMTP id 783CD100009 for ; Thu, 27 Jul 2023 08:14:10 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YUtSHImz; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445650; a=rsa-sha256; cv=none; b=f9k2JtSFiePKj6WbVIzDb+NQsndQhCqwZufT9s2ACQArrY5b4DS+dMy3meKw8YpaJ1KLIO mIQwOf6ZbKXw/gRlk1kX+HaACvk792ugCyyRdBZkcslfgNqbT15QdiTvamyr8s68M7A/vv 7tc5iSXu57qN/gVI8p/1FSkC5B4yQgo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YUtSHImz; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445650; 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=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=VsdZyu276g0S3xQ0+CyWAfDxY6IKkGke9BfkXfFCbsE3AW2ELk8vXio6Fdt4VshaeqMqlH lh99cRIMRT1eIS34omsa2Ukd2SIyuWu6CC7u/Q6az4Ew1EMH/cAj13crxfHfqCmkrfWjAp xlQvSNVjSHP1nXv8eC/CEus0V/r05LA= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6748a616e17so183915b3a.1 for ; Thu, 27 Jul 2023 01:14:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445649; x=1691050449; 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=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=YUtSHImzHFhUVx7c3A38/9eSWP8Y2UYGj1FAohSpraRjdigKG79oH7xXGVv/st6Oxo VyXpyLT7a2poDQM1BLbe2YZ2f+F4NjGwYTjXKgOmjtdNRT3EltoPRUERX0NGCPGwABx/ guLbSxl8SczSn7UsZFsKIT2jSYiALWPELONV4dGxl+BgYW8LTo4BMAXY89ObnQ5bwB+z TeqwZ6TJLFD7PjgbTEQMgvSuaTCzQbN9MksnEsjGQ7GcxsQYflnPZl/UkK6mnnTiCX+x HfuT7U9+62kKpSnlvuoFhz2dd+gEGZ79L6Z5RTD7Q/dArvGRObCoRNap6LnHLL+kySjl YAWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445649; x=1691050449; 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=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=FrUoZCZhNn2LG04dV9DsxiyOIHgTZJju/BgipfH096ZUu9K6+fGn3Am8wMHee4ZHd2 MtGMQktsek5De6azJ6MK//JquNki3KVgidjWZ8h+lRCGPnwCYmQLyZlR7YM1VRZq9fVY GTSrWyaQqNrfwxZJ3h0Ueq2LIo95jd2eEEIoPvoYj/M8XEUkFbuC2qP4TdOehABU0VBO E6Z3ijfp2xIo4X3G0hcBrIHBrd6lxqkRL+HMu4zu0ZfYVZXHFXHd0sNajydDXLXROX/M fXSdOSGF9MO21gFxnSlbRbp1qboXvp/sUo7vQdp3LzBHUzF7XTEVO2RrzHHAp1Zzv3qs BqBA== X-Gm-Message-State: ABy/qLYM97t9kOESZsZa3gvZcGlERWvrOfwFLJhEfdMnaFLHR9I6/+9d ukIO9XUIqAd7jglglyUNQIPxjw== X-Google-Smtp-Source: APBJJlHWG/nG8cYGh+bA6ihiUuY1h+OmDGzY+AfGFIW0cwXlJC7qa3aS8ftT4KQ6i8EuYK6gaQtAEg== X-Received: by 2002:a05:6a20:918e:b0:11a:dbb3:703b with SMTP id v14-20020a056a20918e00b0011adbb3703bmr5557054pzd.6.1690445649366; Thu, 27 Jul 2023 01:14:09 -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.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:08 -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 41/49] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 27 Jul 2023 16:04:54 +0800 Message-Id: <20230727080502.77895-42-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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 783CD100009 X-Stat-Signature: y8n8oefacqrx6a4zxeq73qcbk46ktr7p X-Rspam-User: X-HE-Tag: 1690445650-411046 X-HE-Meta: U2FsdGVkX19+Q5lWav4X/ulAdP2cJObW77kNTh2TV7VFTDQjWvRTgMNW9mcwPcBevgdjAeAx4xcUj4VoUMhY5CVA8Z9x/jQvQY/6XkxfmRZCGRnBSHNzXxOt5b92ciiVxGt2MY5B5GlLM1huf8m5vOxcInX8PVFd4B/1aaCaRJrHrMXRmtDiCq7suJ1E3NkZJj6eESAy4Jj5s7NPrJu6zUvF1Sv9Hfer6KBa8l9WBSIYQTaTx6hJ6H3vNeCxdHsnkcjelfMyEmEMYaW+XeBtySL68Tukwo9ViIjVtMPFzil0CubdlN/ruABpkOrQoFt5QLMF9p4GuZBBeGznja1fYuc4eLFzINR4dXRg0sDIoXh8H0J/JnrDs0JxfsZchEQ6yZaS9yhIMZtD6u8zJ2g54eJ+BU9BuoQD0rGMzS2V2D1J+RP/aTti55Ok699JgEGn40f9T6HywfYvcx5eyB3B/ENT0UIXzjonQc0a+mJM8Fgp5HhqPB2THnc0T5C390X6XI7p62pRbthVq4ftWVrrWgjcDNu+QKN/SLMSdf70zia9OabpTbXr5H/pKNigUrKoFpbyk04pIhRTYFt8MKLOfCdsY+IIZ1JH5iytTnJr0NJCUbUbI9gyf2BvOrJtwswk+BjtDpz1wCoT4JfiutXgBOKzzDujSJEy05z8LkMmRB4E9seJvV6qsk6+8ilm4FUJOfWodoO73uN56QAlWSxi4oIDVQrf6bDm3AGviAO9p30Pkm8NXsZTC9F1Vks93wqDnXk+P+IH6IpwMS4jmSZCayC1uDkZfV5aGhCryi0kC7uMlmYbQvHvXOCnymXXZriMOmcAiHWkOjKrPDIrsAuObmbpta5bHq8Jd0JfuceVEeHQdNLuf1+XBCtRwfuriW1egEkbDiy2bpqZN6kLCmCaU9SJBoOiZvXr0a1fxX5uPJ7JF7lCdotunam6AByHY2jF/n5eNXnqbPr9d3Il31Z 3BlBTtky cVtyS9HT5JfnEWGLAwKajSKohsk6xEPu423KAz5AGMfuRl6uNBTMdSESe2Uzn7Hii44i++wjFkckKPjlfciHCwFUfLOwIVLLJ0nLb6iiL6XptSVWkT8KZJwkNxzPjPepX4Odod+PHRd4DT5pE1zmOiTNuGx+DFvxTH9SbyCPUi4b3Dyn/VlupDCEgtIUUswjkp/VDZRYR1lkuqlt7/nXjM4lIpLbNfW+v05/7OeU00C0SWNBwWBPNqPeRxA783tHDeAYUhzBvf6ZhfXMitLw2DHqxF1ewOY8MIoA1qgPvSx3FRRen0+M/wfaXjCe1G0LqwOy+BCjX3QBgfZwI9MvdxQoYYbk3xHAMIR4v5L96P/Z/q0feQMBkLJEbarRmtRSQQTUatU4gkqrtvlHgDaDLdFr92/0Ceo+s5le7f6qzFnI3gHLWY/YcJCRKu+aZ0QARcuyqDsKrxF/lOqs= 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 mm-zspool 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 zs_pool. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b96230402a8d..e63302e07c97 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -229,7 +229,7 @@ struct zs_pool { struct zs_pool_stats stats; /* Compact classes */ - struct shrinker shrinker; + struct shrinker *shrinker; #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; @@ -2086,8 +2086,7 @@ static unsigned long zs_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { unsigned long pages_freed; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; /* * Compact classes and calculate compaction delta. @@ -2105,8 +2104,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, int i; struct size_class *class; unsigned long pages_to_free = 0; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { class = pool->size_class[i]; @@ -2121,18 +2119,24 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, static void zs_unregister_shrinker(struct zs_pool *pool) { - unregister_shrinker(&pool->shrinker); + shrinker_free(pool->shrinker); } static int zs_register_shrinker(struct zs_pool *pool) { - pool->shrinker.scan_objects = zs_shrinker_scan; - pool->shrinker.count_objects = zs_shrinker_count; - pool->shrinker.batch = 0; - pool->shrinker.seeks = DEFAULT_SEEKS; + pool->shrinker = shrinker_alloc(0, "mm-zspool:%s", pool->name); + if (!pool->shrinker) + return -ENOMEM; + + pool->shrinker->scan_objects = zs_shrinker_scan; + pool->shrinker->count_objects = zs_shrinker_count; + pool->shrinker->batch = 0; + pool->shrinker->seeks = DEFAULT_SEEKS; + pool->shrinker->private_data = pool; - return register_shrinker(&pool->shrinker, "mm-zspool:%s", - pool->name); + shrinker_register(pool->shrinker); + + return 0; } static int calculate_zspage_chain_size(int class_size) From patchwork Thu Jul 27 08:04:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329378 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 54088C0015E for ; Thu, 27 Jul 2023 08:14:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E29CD8D000A; Thu, 27 Jul 2023 04:14:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB3118D0001; Thu, 27 Jul 2023 04:14:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2DD28D000A; Thu, 27 Jul 2023 04:14:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id ADE768D0001 for ; Thu, 27 Jul 2023 04:14:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 796EFC0897 for ; Thu, 27 Jul 2023 08:14:24 +0000 (UTC) X-FDA: 81056679648.14.B8270F8 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf15.hostedemail.com (Postfix) with ESMTP id 93FF4A0003 for ; Thu, 27 Jul 2023 08:14:22 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M90va2ss; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1690445662; 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=Z8shjZqP4Y8hZDaFLi0y7A+vG6rpfakjLEwLFWECHfw=; b=JywjcJiNvKU0ycNQOLGtmKuwJy4TUAApOakScRlEm7ugSSGhzr/ynfOccW07CJX5MmEcb5 qUt45kXTCn08SFmNS+TzxpXq6rnUtgTv9anZ/vui+BaOsfEI5yxUvhLz71jr8iyniUhVjD AYNcb5Z0unMjy025TRgqq87x68SDELI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M90va2ss; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445662; a=rsa-sha256; cv=none; b=DU+EzNYGlARDZ4/XL6Cnq8qEnCh9hKyCFPfMYnAKZaS1LjCOGt1O82ipLyaU2Q92eV7v/r ZyUv6DmSCWzKi0SYsLYbGQEn30MPVg9q5SAgW4FmKvjb0CnDTyY9NU/zfDPDOPczAHCXg7 cC+sAHPLgFZLM8lfLdaxAORywYSwZ9c= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168855b3a.0 for ; Thu, 27 Jul 2023 01:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445661; x=1691050461; 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=Z8shjZqP4Y8hZDaFLi0y7A+vG6rpfakjLEwLFWECHfw=; b=M90va2ss9YMh+De8/KZ+mVAcBrFGEU+GzcGNqxT+B7hxTFEFMd5WuiRk55c0waVg/i KUSKiUTPKXnQRLgL7+hNGJB6n7fW48sv8jtOOA7F/yud6N73bo3romR87IwxTWFghhtj +YqkOMHpv3kLBbjEgh8NplH0r6imKflx3JaCipHnW/k8FR0eXG63PDYGiheNwgxfAvYO s4RNvSYPNCMRAhjFOV4c7zk3yoOMMnjDLt+tw6HnbliXEGOVORcHeWA+2V79c3P+B/9H uhy/DS05CaNG4GhbfQJuetBgKgR0N62DJbP4l44spA0q6/uulU3xcf96dcv+7F9txF9C bWPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445661; x=1691050461; 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=Z8shjZqP4Y8hZDaFLi0y7A+vG6rpfakjLEwLFWECHfw=; b=ObNVZjGoF1IPNd4i1QcCWN4m1rcRDS9uKnN+6UnOzVkGJgalC6/Qu048SZZ8msdYSa Ijb+zS+wcHjinqLpgEpAnrUjWqP9MHtZi7YC83/FemYyi+y+LewvmQ1Onwv6n9wKoOuW 8WJ2y6+EV9fLThuf5MG43CfigCWFTDQi78W3Dciau3yn6owu1Rx6I5O9EamHmUluVfLT qMy4NtRyUZoI2CdTZLYAbxFy/Ckmh41nLn8IdZqBqaslxI9k4/WmennkDfmMIMyKGd1D HiT/Wjve65r91wTwCWXws7joKPXqeIeQmcOvOMCJQagqedh2IFiY7q6cW2IArIE+dXoh L4YQ== X-Gm-Message-State: ABy/qLY7DIpmEmbvBMzf1SZwuqE0wITnhv0RgBovnQfVGMvyHCPX9jeJ /Nm8Ns8kyi9m0joW7rXoIpRjmg== X-Google-Smtp-Source: APBJJlFLUJzqiKbCmr51AmVixakC62oPoMujZW4POdUPOnyVlrtViOXc2TPW8l2+gcY0Xyv3B9lWUA== X-Received: by 2002:a05:6a20:4304:b0:111:a0e5:d2b7 with SMTP id h4-20020a056a20430400b00111a0e5d2b7mr5727834pzk.4.1690445661472; Thu, 27 Jul 2023 01:14:21 -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.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:21 -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 42/49] fs: super: dynamically allocate the s_shrink Date: Thu, 27 Jul 2023 16:04:55 +0800 Message-Id: <20230727080502.77895-43-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 X-Rspam-User: X-Stat-Signature: fxx9tx11xhjzh8dcxddw1rcdhau8nro7 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 93FF4A0003 X-HE-Tag: 1690445662-186113 X-HE-Meta: U2FsdGVkX19w+4IALuch2FP8AAPhd7MhyJnPEBQFD5qhjHPjLwUZ1xEFGDZ1ekLmQbt91AvPvHy481yZR9eNIrwCpu6U4QVLAGk2sGF9MP5Wf6YSZZGRo6kcmBoczBOuqHFajT3ZTDiWrkYrsBQpkHfy6zP1GbnyOg5MG6YYnN+js2DCHat24V1hxbIhCsVwwTPlCHavoFpyDboOuE+SUDpkdDoF1g6hNf2ZgsKrJ5+ApI35duDa7Ud+nrTAjjbTQHcERQ3GXw1Ji5sQGZrC4c+HBOvZQZadSbLqu9ssDkjNUD3f73jE7ua4HaDhkvZ1kO4OazqxQkLFm/+bQYVbCwbjky8n4EdQYDy/IgPOX5XDc1qbcWpYY12vPCSe0HXANspGa9z7npGDtcZH2jB1Pnoee5fzJ2O1vfn9sPfivL/BgsE+O3QiK2OIWDWh2uwkeeVbSJ+ha3VxkySKcrNfYqvyrva/R0BS70EBcJO9P+lW1aHP+BiFAhTd/6PRdVfiogl0HBu4dmfTo8CnrH/hD6ErtUO+aqyRHnXn4X+vsNBZ/g+S6VQ6whtDNWHozlgXNdLX8bc5TB09Sl0wUarPKkmxX/BqfdcaZJk3N9uR0NANdmsto6rDBIgZBZj5XkPlIPsVUcuqrplh8aJIevAXGrT0dVFfkjc9rywdDOXYnUKDpVu5Olf8Q4WkNdR1Qiz+iJki9daCLtV9C+O8vfK+cKstCz9veVpV3l2acNFhVCL4gUnPS18TRpgXUUMDwJafhSPrakWDHrugrqc6uRvs0fnYPqjMJjT9ZGTpiAq/PxavFsIV5UqaV8y0kpEcKs/UHJvvWIJsqRjCgDrIK7UOmVN0zdYKBR8kLh8MX5yQMdbBq4Rq7bRAhDLhTOEvKfIfWV1WZLIl8gYYrL9+2K53ikv/gj690tC6DYv5S4y0aqA6ZWEr/GDf6B1K+FTzhd3FGdO0oKE5GRKVraSrarc 66Str5o7 8p8BRsToYK0G745Lp1I9eaOh0OayDGqN+4Dr970hXSzDQX0RXlcJ+svSfkKYoUdKC+MqT6Kdt9NAzf2e1yvZWTwBhTom4Q+sSdaxIui04odE+Xmw/vLBW6rdmP/iRpDXjK6VogHoY3tL0lWmsKNmNUdiqorUFx8vqthdYsnIZJWFCdBuRaMTvwr40rMEx3mt31t2qRlWFXja7WSKnEbVPU8p972t1ARrERMjq/w2lXZmJZG8zQcEva0n+cj4lJ5keT14I+/3NStqlIsgGqlo67pHhkWbMr06f0Z7DRGJQ/SW9dKw/7VrT2C/kOK7Qs7qHMOQ8ayF+5Y1aoR93XjC3PoMunVzxe3NnUlrzjkplIQxfpMvIbbnnelo3Ftt1jPNS9KEdMXKfzYLPTRrh2xRer/7l6oxh0j+eFiF/nMOWy8ruuADSA7Vn7dGw7JdwOCkLE33WPxuprdAW+a23SxpYkZKg7A== 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 s_shrink, 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 super_block. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/btrfs/super.c | 2 +- fs/kernfs/mount.c | 2 +- fs/proc/root.c | 2 +- fs/super.c | 36 ++++++++++++++++++++---------------- include/linux/fs.h | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index cffdd6f7f8e8..4c9c878b0da4 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1519,7 +1519,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, error = -EBUSY; } else { snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name, + shrinker_debugfs_rename(s->s_shrink, "sb-%s:%s", fs_type->name, s->s_id); btrfs_sb(s)->bdev_holder = fs_type; error = btrfs_fill_super(s, fs_devices, data); diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index d49606accb07..2657ff1181f1 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -256,7 +256,7 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k sb->s_time_gran = 1; /* sysfs dentries and inodes don't require IO to create */ - sb->s_shrink.seeks = 0; + sb->s_shrink->seeks = 0; /* get root inode, initialize and unlock it */ down_read(&kf_root->kernfs_rwsem); diff --git a/fs/proc/root.c b/fs/proc/root.c index a86e65a608da..22b78b28b477 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -188,7 +188,7 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH; /* procfs dentries and inodes don't require IO to create */ - s->s_shrink.seeks = 0; + s->s_shrink->seeks = 0; pde_get(&proc_root); root_inode = proc_get_inode(s, &proc_root); diff --git a/fs/super.c b/fs/super.c index da68584815e4..68b3877af941 100644 --- a/fs/super.c +++ b/fs/super.c @@ -67,7 +67,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink, long dentries; long inodes; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * Deadlock avoidance. We may hold various FS locks, and we don't want @@ -120,7 +120,7 @@ static unsigned long super_cache_count(struct shrinker *shrink, struct super_block *sb; long total_objects = 0; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * We don't call trylock_super() here as it is a scalability bottleneck, @@ -182,7 +182,7 @@ static void destroy_unused_super(struct super_block *s) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); - free_prealloced_shrinker(&s->s_shrink); + shrinker_free(s->s_shrink); /* no delays needed */ destroy_super_work(&s->destroy_work); } @@ -259,16 +259,20 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; - s->s_shrink.seeks = DEFAULT_SEEKS; - s->s_shrink.scan_objects = super_cache_scan; - s->s_shrink.count_objects = super_cache_count; - s->s_shrink.batch = 1024; - s->s_shrink.flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE; - if (prealloc_shrinker(&s->s_shrink, "sb-%s", type->name)) + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, + "sb-%s", type->name); + if (!s->s_shrink) goto fail; - if (list_lru_init_memcg(&s->s_dentry_lru, &s->s_shrink)) + + s->s_shrink->seeks = DEFAULT_SEEKS; + s->s_shrink->scan_objects = super_cache_scan; + s->s_shrink->count_objects = super_cache_count; + s->s_shrink->batch = 1024; + s->s_shrink->private_data = s; + + if (list_lru_init_memcg(&s->s_dentry_lru, s->s_shrink)) goto fail; - if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink)) + if (list_lru_init_memcg(&s->s_inode_lru, s->s_shrink)) goto fail; return s; @@ -326,7 +330,7 @@ void deactivate_locked_super(struct super_block *s) { struct file_system_type *fs = s->s_type; if (atomic_dec_and_test(&s->s_active)) { - unregister_shrinker(&s->s_shrink); + shrinker_free(s->s_shrink); fs->kill_sb(s); /* @@ -599,7 +603,7 @@ struct super_block *sget_fc(struct fs_context *fc, hlist_add_head(&s->s_instances, &s->s_type->fs_supers); spin_unlock(&sb_lock); get_filesystem(s->s_type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; share_extant_sb: @@ -678,7 +682,7 @@ struct super_block *sget(struct file_system_type *type, hlist_add_head(&s->s_instances, &type->fs_supers); spin_unlock(&sb_lock); get_filesystem(type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; } EXPORT_SYMBOL(sget); @@ -1312,7 +1316,7 @@ int get_tree_bdev(struct fs_context *fc, down_write(&s->s_umount); } else { snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", + shrinker_debugfs_rename(s->s_shrink, "sb-%s:%s", fc->fs_type->name, s->s_id); sb_set_blocksize(s, block_size(bdev)); error = fill_super(s, fc); @@ -1385,7 +1389,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, down_write(&s->s_umount); } else { snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", + shrinker_debugfs_rename(s->s_shrink, "sb-%s:%s", fs_type->name, s->s_id); sb_set_blocksize(s, block_size(bdev)); error = fill_super(s, data, flags & SB_SILENT ? 1 : 0); diff --git a/include/linux/fs.h b/include/linux/fs.h index 891cf662b26f..500238213fd9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1232,7 +1232,7 @@ struct super_block { const struct dentry_operations *s_d_op; /* default d_op for dentries */ - struct shrinker s_shrink; /* per-sb shrinker handle */ + struct shrinker *s_shrink; /* per-sb shrinker handle */ /* Number of inodes with nlink == 0 but still referenced */ atomic_long_t s_remove_count; From patchwork Thu Jul 27 08:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329379 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 C63C0C0015E for ; Thu, 27 Jul 2023 08:14:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 663588D000B; Thu, 27 Jul 2023 04:14:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EAC78D0001; Thu, 27 Jul 2023 04:14:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465768D000B; Thu, 27 Jul 2023 04:14:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 32F868D0001 for ; Thu, 27 Jul 2023 04:14:37 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EB0B64050F for ; Thu, 27 Jul 2023 08:14:36 +0000 (UTC) X-FDA: 81056680152.21.34C7B84 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf26.hostedemail.com (Postfix) with ESMTP id 176E9140007 for ; Thu, 27 Jul 2023 08:14:34 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MBKqtR+m; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1690445675; 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=G6s8y0Dka4KE4srOwy3I0FSAaIGrcYmvE6JrVZfCpDs=; b=GQHFPtlk0wHT50y05JBmSC7kRvc2CU650wW0/T6uYhhvfChYxp9qPlpkt4wncZ6zTkpfKW +GKzNO+6V+9W37QZI6KEMe6jT8cwlE77z+N+Lc3245S7GttOaLktedujefcJl6Edwl3PMv t3GnGJe88YmUIlc4BLmo5Sgvk3lX/1k= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MBKqtR+m; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445675; a=rsa-sha256; cv=none; b=qUugM5b2TmEZjTQVtXTtogPRen+U2hMqbvKq3RiXjO21FGRa+rkX2iAqtLB/s/DiXsUHmB SaHk3phXAdZ/Kay00ffZh5+wIjHqtu4iEjGjT88BctQniiNAUYRAWK7PGLvnubZ5foIO1t orVtLY4AtPwpLQrNb7SrGXPxSJJx2qo= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-682eef7d752so205030b3a.0 for ; Thu, 27 Jul 2023 01:14:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445674; x=1691050474; 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=G6s8y0Dka4KE4srOwy3I0FSAaIGrcYmvE6JrVZfCpDs=; b=MBKqtR+m6tRDLwGbmGnhkuL4q0cqlWsjDeU7ZVRwaOZMOF0riGkcJrkyInKFI0pYis mWaNeHtwDzmym2/d2f7OIfkckgap6Prz7ne5Q+65Q9kFa2z8w6TXtQPQCrjIFsYVVR2m PRIs97KnddHeo2KzvpuxuJU//NWKLj0FPiuARmlExd2GlY1ot6WyHoUBUu1qPjJUPpT3 ZsG43k1Oz59Ii0r86zAALutb1Gd6A6cdhWxvrkZ21MO6UtDcxtLUaksPoYyR3li5MX3H RGe7M6IrmRvaAAMZm9ToAYQ8mPB0OkHGFsJVWBGXFBUa+qGlQpcM3sB1mv4YN0cfvLiI gBbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445674; x=1691050474; 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=G6s8y0Dka4KE4srOwy3I0FSAaIGrcYmvE6JrVZfCpDs=; b=k+WVbblT6rHpxvf1wDC5JQ1TK2jxfEMedc9KiVGm80iGprrrkc/7ToAauEV6G3Gk+/ PTojCZIG4AooSINBLmj9BMAZEBOxpPXFY2z39KbxgLsPVeTrqraKFu5jZgPrAgemb0Y1 oifPyj5MfDGKzQa3kQjPmSlV6k0TjpbEzJR4fcj2pqRji/68olpO0pidjGfkhbhHGdUq C14r+2rEvJOS3hPrrxVg/+YUTb9HUAj7yfYiMUzbVyslu7T1CJ4NalpdVDrcsHrm83a4 HBY6M2/msgwIaXXb0BCokJZPDfdAh5XGhfTxXfMFWFEo5iaCaHbWMjiFxEYLgFNCr4L3 72hQ== X-Gm-Message-State: ABy/qLZ8CXCAiFPgUUaQ+WDh5QGv+5U8uu4J1jjFqrQLSwZWc8c+gneo xsQ3msNh5Q8n4yLnWEAS9wc9zQ== X-Google-Smtp-Source: APBJJlHZc+tyEor0irWiukNNv0+VJsTfo/jEPBj29UYMUTILxfRG5SoeWB7BzCnWVmRXaEQSTc0xVA== X-Received: by 2002:a05:6a00:4a0e:b0:677:3439:874a with SMTP id do14-20020a056a004a0e00b006773439874amr5210105pfb.3.1690445673911; Thu, 27 Jul 2023 01:14:33 -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.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:33 -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 43/49] mm: shrinker: remove old APIs Date: Thu, 27 Jul 2023 16:04:56 +0800 Message-Id: <20230727080502.77895-44-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 X-Rspamd-Queue-Id: 176E9140007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jie7zkh8fsqn6ou78jgimsg3epfx9cjb X-HE-Tag: 1690445674-694273 X-HE-Meta: U2FsdGVkX1/t8RueVertOYqvKRnIW6I4QdQ4wVIzeA85r4ldvwGYa/mKZMTN2ecGs2Z6HKvBgBGFAz3VEnCXhhd78H/GTfSNNR0mNPJr/BOpqcQVPrxs6q5q1d9AajD+Q0J9gqpZmABdZ9vgxmVSMa/HXjKDa8qt3PasI1LM7zLvnEZz1qv6hqrczdxCpxTgLliJ6NSe/WZ2OM2JgbIBhjvgqjzo9iO5UwpwJ2Xz3yLs8NMrVUQbc0tcYUV7rh/gR3Q9yW8V3fnoqiVRObuXwj09FRof5v4U9p4q4JSrWSrdNi+4DL9NQ+mKGmLRYnw3YUK4buPvuhxgHIBAp813elweFGRFitO+hkf0wneyCR3JnErq+XfIdC4liCFHZKxMPBTmNrp95VvNb1eKkNq09xceZgmEV6iNSm2mkMSVB16o8INa4fjBW6hPiMVbOvJT4c0t+3opq+o1YUS1hYW4Pqkf6ZtFxBKOsoM13d8s30vUF6zzqqRhkI6OM1mqjB0BFZad6H4nq9iJcm8U4p1X21yoqqo6RM2AmnKcEoHH3CgpJ2mug8/CHcVdJuavDFW/Ogir9Jck9s1pbr3AYPPPe3W4DG47yprkUoD8dKEUYvsVhx//DVcJsEeF3rcRnphr8ATZW10/njNXiKHFBtxBy85bYbxk1tE9nTd6+PpgC+A7f/DwLtYylLeiHFNYF/oU1D+UqUSFFhBdSIjx/YgLHXZCnaUz9UHslYWwqDKQ+GifJlNjuhX5axSbGriIwdIIreaz0N1OIezs4LNwASH1S6kw7sxvgTEiZB+3v7gz1DwF4NMB8DOoQf+V0yUqU0N5uWWFro4iW3c6xKQQcyrtO2PCVvifYMNEHX+9w0e39CJ61jO942j7C6GwKbXHKTkrOZCTHZI+2p4iZX2/EGgtfYKL4oWQm5M6y95f9TH1+ITqYT7AyAmIM6wYI9tPqWPvAcHGyLRUcVsDKCbC6mR 0i8ZmMIF 2W8xa3KeUVGiYnMn186jaDh0uBOsE+felt8mJ3yVnYdhEcHJJJKdMeg9B7SnaivzZwRJyXbtFVMHvi48XqwOHTmA7e8mO9uXTFixYVMAbTRLrE/NFIHy7ZMPYx4dUZgCo3C+MP4TbxCcNmpbszXo/b8sGmGNZjBeaA4WVjm1MqVfDsgPPgNj/cpCPJ49k9DIt4EQRmgB0FZ+W1IUPVGK/8JHmRY8OFm+Upst4HEG0KmrcExXzlG9f3SWivlw3q5A+9jcsmMTg0TQXv0ItPZfwliCA22E+GkHXMUf2V128h2W8Cwb1yc7HQxvRqGHoHJW9ZK/A8tU8vzxyhyTbJBq56/S2ySPoGc5RK8xu49saoi4TjSE/lcnnL9FY+c/yltsm5jDjI47DfIjOLUAHgzFt1H/cMqNMmylCIyQM 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: Now no users are using the old APIs, just remove them. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/linux/shrinker.h | 7 -- mm/shrinker.c | 143 --------------------------------------- 2 files changed, 150 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index cc23ff0aee20..c55c07c3f0cb 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -103,13 +103,6 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); -extern int __printf(2, 3) prealloc_shrinker(struct shrinker *shrinker, - const char *fmt, ...); -extern void register_shrinker_prepared(struct shrinker *shrinker); -extern int __printf(2, 3) register_shrinker(struct shrinker *shrinker, - const char *fmt, ...); -extern void unregister_shrinker(struct shrinker *shrinker); -extern void free_prealloced_shrinker(struct shrinker *shrinker); extern void synchronize_shrinkers(void); #ifdef CONFIG_SHRINKER_DEBUG diff --git a/mm/shrinker.c b/mm/shrinker.c index 43a375f954f3..3ab301ff122d 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -651,149 +651,6 @@ void shrinker_free(struct shrinker *shrinker) } EXPORT_SYMBOL_GPL(shrinker_free); -/* - * Add a shrinker callback to be called from the vm. - */ -static int __prealloc_shrinker(struct shrinker *shrinker) -{ - unsigned int size; - int err; - - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - err = prealloc_memcg_shrinker(shrinker); - if (err != -ENOSYS) - return err; - - shrinker->flags &= ~SHRINKER_MEMCG_AWARE; - } - - size = sizeof(*shrinker->nr_deferred); - if (shrinker->flags & SHRINKER_NUMA_AWARE) - size *= nr_node_ids; - - shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); - if (!shrinker->nr_deferred) - return -ENOMEM; - - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __prealloc_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - - return err; -} -#else -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __prealloc_shrinker(shrinker); -} -#endif - -void free_prealloced_shrinker(struct shrinker *shrinker) -{ -#ifdef CONFIG_SHRINKER_DEBUG - kfree_const(shrinker->name); - shrinker->name = NULL; -#endif - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - down_write(&shrinker_rwsem); - unregister_memcg_shrinker(shrinker); - up_write(&shrinker_rwsem); - return; - } - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} - -void register_shrinker_prepared(struct shrinker *shrinker) -{ - down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); - shrinker->flags |= SHRINKER_REGISTERED; - shrinker_debugfs_add(shrinker); - up_write(&shrinker_rwsem); -} - -static int __register_shrinker(struct shrinker *shrinker) -{ - int err = __prealloc_shrinker(shrinker); - - if (err) - return err; - register_shrinker_prepared(shrinker); - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __register_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - return err; -} -#else -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __register_shrinker(shrinker); -} -#endif -EXPORT_SYMBOL(register_shrinker); - -/* - * Remove one - */ -void unregister_shrinker(struct shrinker *shrinker) -{ - struct dentry *debugfs_entry; - int debugfs_id; - - if (!(shrinker->flags & SHRINKER_REGISTERED)) - return; - - down_write(&shrinker_rwsem); - list_del(&shrinker->list); - shrinker->flags &= ~SHRINKER_REGISTERED; - if (shrinker->flags & SHRINKER_MEMCG_AWARE) - unregister_memcg_shrinker(shrinker); - debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); - up_write(&shrinker_rwsem); - - shrinker_debugfs_remove(debugfs_entry, debugfs_id); - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} -EXPORT_SYMBOL(unregister_shrinker); - /** * synchronize_shrinkers - Wait for all running shrinkers to complete. * From patchwork Thu Jul 27 08:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329380 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 10718C41513 for ; Thu, 27 Jul 2023 08:14:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5BEC8D000C; Thu, 27 Jul 2023 04:14:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E38D8D0001; Thu, 27 Jul 2023 04:14:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 884F18D000C; Thu, 27 Jul 2023 04:14:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 75DAF8D0001 for ; Thu, 27 Jul 2023 04:14:49 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 523121CA143 for ; Thu, 27 Jul 2023 08:14:49 +0000 (UTC) X-FDA: 81056680698.18.A942911 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf24.hostedemail.com (Postfix) with ESMTP id 760E818000C for ; Thu, 27 Jul 2023 08:14:47 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MqP96Bm9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 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=1690445687; 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=dp1PQp+5gTkm4DG/kxrQVAZ0rB7KyI/rGW6TiEnUaUw=; b=UkC9rmZ6ME5NWoAwp7Rbh5Lo1muZ0Tia84cFntrB7u3kAcAMQNf+hkEEcj8V/VF52Im+/1 zN6lVfAq7k19QCGwapN62yfWYAwS4OdIRqD1rXLbHiUY3h/hxMHCF45rQZvMA0+JjkijXq OLffKvoDTjUbSLb4pXQk/m+stWurz8E= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MqP96Bm9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445687; a=rsa-sha256; cv=none; b=PDofk9NBVXQxMiRhtfrY2eI04tbDm2xeBz5zK7JFi0BbPLzPpzm3vKO6JuzJTVpOgoxa0i lmXe3FMOEjcj79cd+gSeMcSCKgvujNworszLbbvMbjw+i0S5KJ8SIECAmEE34p7iszotdQ ruOh7FWBG2GAQtrb9pCZwX0PQHexGfI= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-682eef7d752so205080b3a.0 for ; Thu, 27 Jul 2023 01:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445686; x=1691050486; 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=dp1PQp+5gTkm4DG/kxrQVAZ0rB7KyI/rGW6TiEnUaUw=; b=MqP96Bm9fq0jb+xCLhNx3qXYFKB4F/mSOAZlWu4Jm1FlamJjkRz7LK2fKulsbN+LSn l0VYmbaw65P+tcDvLp0k7E9haUqgvwJAWE6OpcHuKyrg08ULwJDb+WP/772xDJT911c7 7zPxywkNsS4PFeXucHGoe87Ta2cj9HmvnL8UOM3A93e62EY5SL9atdoN3JsX9JTRnBw0 N6tNSQutP8zPFknN6y/kLRagvKGA92ju9GvGVVfPXxOrB71gJD9FTKmQ9dcanmCJl0Mj XtJnZ+1w8I86OoTRE6esFmZWRayBNnTg+LYaUjuJMZuWhMZx1Zg8pNqMQLhwRUKqGlU2 KUKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445686; x=1691050486; 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=dp1PQp+5gTkm4DG/kxrQVAZ0rB7KyI/rGW6TiEnUaUw=; b=mBFLia+oKmIWo5iKBbB1cCCwHe8rcRa5WgKG/HTX3JEYdW5zBGRSzGMtS6auiIFISS Ym4qBDQwP+hUOQ7bRSddyY2Br5lUbi5SaFpLdYv1ZfIV194JcHRJlxneSwIv3BtD/nMu EQ8mjQLYRZ4ha980k0mVM3X7eAR7cCjRQ8rmSAUSIt4Y0sBO5669qF7rtRsdZBC8G0yv ngfARXnLfC9FtP9fdf27OGEoE3aWXicVvdQVJhdTSo8X40/GV4EphqVBXfJu35D9QE9d hsb7zvvPJ6tQhySTanpxsEUV0G6mtmspxifboYtjNcsqLQU/FJytdHX0bxqH37eAe7fK 98xQ== X-Gm-Message-State: ABy/qLbNvNSDA3IrszX2U1ehpT4EXeuScCKK8gAR6hhZQ/0EU2DchyIu i81qIAPSry0WjFMQNeravwL7Dw== X-Google-Smtp-Source: APBJJlEKqhcD6VVO3jjfSZcBy2+bKwiVuLncssOJVtvwGRfgIG5yeQydG6zmLtiTondHAX8WGQ4FoA== X-Received: by 2002:a05:6a20:841d:b0:133:7a67:b477 with SMTP id c29-20020a056a20841d00b001337a67b477mr6364506pzd.1.1690445686337; Thu, 27 Jul 2023 01:14:46 -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.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:45 -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 44/49] drm/ttm: introduce pool_shrink_rwsem Date: Thu, 27 Jul 2023 16:04:57 +0800 Message-Id: <20230727080502.77895-45-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 760E818000C X-Stat-Signature: 5qddy76wxyu54zx97ntmt7wqbge48q8r X-HE-Tag: 1690445687-327922 X-HE-Meta: U2FsdGVkX190XOscs3MhrK9UylO3560wCLE7VAqiZLI9I0l7tMudmW67QpH4+Ju+Qh8psq3D72rLGIHOGFVbOFIePrGcUlgHYgc25nSFr6xqDfFjSow+dlQgS0yUr3EVmfjXOcjPLastJvywfjfrHbanj1mNcbLKXhWyAMboXwMHj72SNvsw80RmFBgdSGJqU9rFOcf5Pb7M5BcqJZ09lGn/hFaP9XnjOmYXSCxfP/GAyF+WP9zZYhfnlz4n5z25hUslsZOz4vZyul3Q9RsHGB7X70jKWJPqrlLRZt2iSSsVDHFOtUhjVhXNxS/k8+63ddc8GidOna3mOFWiUBdf8oinVG98846ixLrS9NWB6jJOxEorUN+4DQ0CR/ocEhaLAKj7Uh9jaGIG/TXxxWAG+HGETjlK9LeMlHjZN7jL8O3ED8zOx5FuuHkTWBcp7j+XtF2OQrGGxfQ2EojS9Zleo5mV0Eu3MPb7/ID+maq0wZ1TgBKabyBcXQbzRW9uJXpkOaobYQoZNO6urKM8qUSsWlqFP7RsGTmRf1AOLk0XbPSSYFQHzScUGHmN8TYuc/jnLFPiCM3XSue68wTf8rv7sdrEToPiDTyNo7x5Pi7q4jc22ynVk3fwPRAKPXX9W1dftX4q1lNs+Y8YNr4/3bEXQwsLV779nI8WnDqTd8NoIheYkV2grvv/Q9Miu4KGBVYIliMb7AXQfUhD4zOjX+ipTPso3HVQ+chXxcLAkpJZ4rrldzS5WYUYX/H3m+BpctXZ8CZaZee39/I1QfTnd1oW9FtgXWaxbDNy8i21gvZUCZjkqXT9XPDbRM6Rme8nRCdBtN9MJOsgnfhyq4cOrF/h2V7RbqepKBOVAJJZB7fJLLqOzBCk6PY5tRMHf7IzXpJG2pmC0Itb/JZ0gSxLq7Im7vwUWb1gx3WgxfQsdqm/2mfzAETY4PFth3GKZndpVlQoU9K582Jjku583h+TCDo 66T0u8UV x4/yb9vK9pvDNF9ib7XL6cnPEioIjVHxMCc/UwQRSQS792d1s9NoEhN8qOBzrRK45vSCgSBQJtdtbsqIAJ46uB+Ph9kHjbiPitFM9V2dpuryKJFZaifkwhn1dBaCuhE5L6ooRrGVedHKsWHYCJPyHU3DOEjdNpqSxI/IExMaYHsJ0rNUjCfCHneXiEOSUKtFjbZQR6p4M9ZWewy5iCXmftr9sETmguU5yzWFyv+aN3k7+s/HLKBQeiAGWObIAqNnUFwiwI1RWmZwLRRk71E55nrhYqiFb38lHHakS492Gew9Ek2conAEwkg9M7UvdqnUrFRTfOEItm0dYnzK4HShuLNIf3LMd7fAIoALu5fEdKEd22diF3RhLjgsOssStlPtSQPiY9htG/R0gX0hRoqoFzSIFtAmjlQVfgOcRkbBqmgR/ZjpVwWtMWgEAJCR0/gev3p5Nl9im21BJmRNjdEomFAFidw== 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: Currently, the synchronize_shrinkers() is only used by TTM pool. It only requires that no shrinkers run in parallel. After we use RCU+refcount method to implement the lockless slab shrink, we can not use shrinker_rwsem or synchronize_rcu() to guarantee that all shrinker invocations have seen an update before freeing memory. So we introduce a new pool_shrink_rwsem to implement a private synchronize_shrinkers(), so as to achieve the same purpose. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/gpu/drm/ttm/ttm_pool.c | 15 +++++++++++++++ include/linux/shrinker.h | 2 -- mm/shrinker.c | 15 --------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index c9c9618c0dce..38b4c280725c 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -74,6 +74,7 @@ static struct ttm_pool_type global_dma32_uncached[MAX_ORDER + 1]; static spinlock_t shrinker_lock; static struct list_head shrinker_list; static struct shrinker *mm_shrinker; +static DECLARE_RWSEM(pool_shrink_rwsem); /* Allocate pages of size 1 << order with the given gfp_flags */ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags, @@ -317,6 +318,7 @@ static unsigned int ttm_pool_shrink(void) unsigned int num_pages; struct page *p; + down_read(&pool_shrink_rwsem); spin_lock(&shrinker_lock); pt = list_first_entry(&shrinker_list, typeof(*pt), shrinker_list); list_move_tail(&pt->shrinker_list, &shrinker_list); @@ -329,6 +331,7 @@ static unsigned int ttm_pool_shrink(void) } else { num_pages = 0; } + up_read(&pool_shrink_rwsem); return num_pages; } @@ -572,6 +575,18 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev, } EXPORT_SYMBOL(ttm_pool_init); +/** + * synchronize_shrinkers - Wait for all running shrinkers to complete. + * + * This is useful to guarantee that all shrinker invocations have seen an + * update, before freeing memory, similar to rcu. + */ +static void synchronize_shrinkers(void) +{ + down_write(&pool_shrink_rwsem); + up_write(&pool_shrink_rwsem); +} + /** * ttm_pool_fini - Cleanup a pool * diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index c55c07c3f0cb..025c8070dd86 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -103,8 +103,6 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); -extern void synchronize_shrinkers(void); - #ifdef CONFIG_SHRINKER_DEBUG extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/shrinker.c b/mm/shrinker.c index 3ab301ff122d..a27779ed3798 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -650,18 +650,3 @@ void shrinker_free(struct shrinker *shrinker) kfree(shrinker); } EXPORT_SYMBOL_GPL(shrinker_free); - -/** - * synchronize_shrinkers - Wait for all running shrinkers to complete. - * - * This is equivalent to calling unregister_shrink() and register_shrinker(), - * but atomically and with less overhead. This is useful to guarantee that all - * shrinker invocations have seen an update, before freeing memory, similar to - * rcu. - */ -void synchronize_shrinkers(void) -{ - down_write(&shrinker_rwsem); - up_write(&shrinker_rwsem); -} -EXPORT_SYMBOL(synchronize_shrinkers); From patchwork Thu Jul 27 08:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329381 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 E7BBBC04E69 for ; Thu, 27 Jul 2023 08:15:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 577FA8D000D; Thu, 27 Jul 2023 04:15:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5017C8D0001; Thu, 27 Jul 2023 04:15:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 353E18D000D; Thu, 27 Jul 2023 04:15:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1DA358D0001 for ; Thu, 27 Jul 2023 04:15:02 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D5AD2404CC for ; Thu, 27 Jul 2023 08:15:01 +0000 (UTC) X-FDA: 81056681202.25.B942932 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf30.hostedemail.com (Postfix) with ESMTP id C223B8000A for ; Thu, 27 Jul 2023 08:14:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="j/RnjlDR"; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1690445699; 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=hyLc13iHrkV+klh05yD71xFAgQY4jD2CPzn+LZNOh3k=; b=VqdFReJVnObrkHoY6C2HERPLkqNSr987pg4VORupcdRPyfb94j6U7zo5GGpGSpmdbLpOON yFuXQKj843aqcNvXfMWY+aXPNR3FRPYZmTk9ajeOtye54PHQYmj5PGhXLOitKPXPughdGQ MLlaxCI4+ycm6iBsUdVisYxgDOHtdds= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445699; a=rsa-sha256; cv=none; b=VSCPCUmtGqh2ZOxkompoX4K/7L+lNQ8h1N3glx6DxTUZOkiMbrhqokUYj0/5ZSpFgX69fa zVDv2/yZhCbcdKIarCvkns7m9HiQh15EHWoqEaozsDNEUdBBYxA9u/4ebhvm0W9+MTax85 ohcMkmrV85BFJ0rskKxzRnaxuiSo9R4= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="j/RnjlDR"; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6862d4a1376so189964b3a.0 for ; Thu, 27 Jul 2023 01:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445698; x=1691050498; 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=hyLc13iHrkV+klh05yD71xFAgQY4jD2CPzn+LZNOh3k=; b=j/RnjlDR/6PJZ/VyI7X0aptMT1iXf8RcI3J7hjmtLDlbxdSOVetAiPedXKNsMAsgMH vW2t4XX80i81CSKm1+58CCJFBxWJpCYufXIihrr1Qh0iO58Dre4wc/nYIv2x1kkcDjep Q77tkS1cKyF/pOEivdyfGUKn80RYpS5tTRhJav3vzv1noykGmdY/2w8uvsgxbLtx6BmO OFB/9kEDCl8hjuP0RIabQrnt0SteIjjBa9je+XXYyBGZ78X0iI751Sfa8HKvZa7gdAPd T87WUXRoY50jn0E4HH6vQWiTU2dwGY69uu92bxpk78xQ0HZ4QCB+dWaTfpG84kK4Opxe wgjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445698; x=1691050498; 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=hyLc13iHrkV+klh05yD71xFAgQY4jD2CPzn+LZNOh3k=; b=BiiHZG/o7R3ayRUH9wjpiigFRPDmUgo9KbVuXLGXvXTGtVLgu6BMV3zxUzkqmN5oq8 vkG9sgpTW9JNKAatUw5YN2C3TjqDwBiKNd0C1UeaiVyeog5TFG9J4uyHb8vXk4A8xzFB 3nntLlPvvOiw19QQoC3mGjjd6da0I5xcMqz1aUApVTTz0CvUofrUOhMIPHcAsrlsI41W LnGp5R7yIbR/tz6hJrcZazw3nbsTs72IJCr+S+SkVSyp1LXOoa/FWLzzd7zVH8uiEXmx F87JUY5oQriLV0b7NLkz6K2cptA3YYrdMJqYP343jj/tEdQfbRNaLJQqd7s/eqns8jeb mNrg== X-Gm-Message-State: ABy/qLYzgew7QjRW7NwRP+zMR83cTrTXRXgQd8rpv1IJ2I2pYykYyN+N j3LFDjtVnoyyfZl6AoYxW9fBbg== X-Google-Smtp-Source: APBJJlHHYMtR97FgZwPKg/I4FvBtMIi/WenRh8r+QxTKT4uZnBzRavnMRN782PTiMjlEUg18pWA/Fw== X-Received: by 2002:a05:6a20:8f23:b0:137:8ddf:4647 with SMTP id b35-20020a056a208f2300b001378ddf4647mr5934103pzk.2.1690445698478; Thu, 27 Jul 2023 01:14:58 -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.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:58 -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 45/49] mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred} Date: Thu, 27 Jul 2023 16:04:58 +0800 Message-Id: <20230727080502.77895-46-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 X-Stat-Signature: h81obrku9dts73dzof9ege8sf8t98wxe X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C223B8000A X-Rspam-User: X-HE-Tag: 1690445699-878121 X-HE-Meta: U2FsdGVkX181PeDhRXgMRkZB+W+DYUE2kn9kabc4h7LoR1UiHvhgPi1LYzGM47mw+7WC837gScF093Lev5FcslxUodfzGo3hR8vnZlEEcvkg5DBCD5bLt0yZoTcspY0B3gSA/uVt4nDuRgzi63iZp2vWivM8Yc4T+dmKVtxNe7ShnDl2Zu+IG1G7HUbxU+jqBUTiE7FDDwqQQ58jcXt7BFcpFi9Px9mg/lzTqd61hxPwLf7vv1pLyRfzDGP5lOmFR1k9rByD5Bhf4G6f3Pwxx5KlLkU7OE57voiIY3joVwPlhyKU7JnWm84JPvQ8VJMp5T9StM1JkGpz61CAV1Ce1I2Y29mC17Byyrq+87Bv/WaSF1WEQDI9ee5QNZH5KnNLjx8A9GYj1y8l58jxWv7nX0cJABR3ugqZW0baSBRq5n4daXRf+fZDlUq5l4hXeeUYaeruXFUqCClLHYQEdMgZrTxa/NTWCE1nw6GffRj1L7+GFUQKJj/dCAoP9xVejWHgHcb5qkqixp7pUoHAyxm6dwjLeIjnXXLoHgtkLgNTM9y3SAX0+FhgvzwxbqFwUDO1sjAX2ZF50GnrPGI8t+xZ6cg9Sxy5BuZow5V9f42uI/hZy+54UkVBJ+oMMkZnX54Y/vTGyfkce+aGcmSzCJ4lSPyJF7ERF3mVewuAU/QB8xBTtGJONyXRK3nhQm8yU3Zsbnx2La09qCXl2CtijVSWHDYTAnDsjw2QidAc8w+4w8WQ5a1DS0/E3o9zswUkeUs5UFeo2mhUqmEd1dsKgDGcQ7/b9HtnABoAlINkX6mCWshw7keIIfTcpNeBwShYh6S06na2/AXq5OK/dY/MHoN3XId1xeSvFhF9W1tG9s0MNqoepSIh/5a8djD7Oo0L+TfLCiwmz9XeZ4lnX9MqtT6gwUsctTgTt9uJmK3deC8oMpRGNWH1xb4A2Al2vWmm77pNZCx5tJq2kAGxaCxGjBh VWCdv+t7 3awhqAEUsJ32qUtzJitkf4+ilZ0kgTql2lI8mgqZQrEamxBjV1ryy4kCQyZaWlCaMP+380V0+3rhHQKLEBzCg09OAOl0dVFlysZI+JxRcSnSaMxIqXp8CloOundC4Sv8KKU7Z4QSTFtTAFyzBWTp6vwc+4aIa25RlPfjFjzFhw9XDFK6Aozc419YlieorZfyXLy8Cw/RYsWUvglv43InasEPVUj6DgofZgFiwldP2esuW1gXElrcxaMs0IhLPlgW18v2SVDwI1nUHoVxQmY5cLX14d9M0JTK5dQ5zImkx0oG9oAcR62wUdWq+mm4veXLlZOyIYJJOsLNWiAfdBkoVXAW8hdqXnVq/eHqnIN+MKQC8dQJsjLoRAX/36HGbKyvZvjDV3oREGpbIJHm475QvCHUmjSLatzlXI2/tvLeHySuzpNnCKROgeVTc3gt0Xymbicy8LUsYo/09to3Q3ybclHA50XPT0le1IHNvepdU07w0OxCYGnVonRmQWtRic5Pi0HvSZ0KGMjhBmXeeGbYKprVspA== 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: Currently, we maintain two linear arrays per node per memcg, which are shrinker_info::map and shrinker_info::nr_deferred. And we need to resize them when the shrinker_nr_max is exceeded, that is, allocate a new array, and then copy the old array to the new array, and finally free the old array by RCU. For shrinker_info::map, we do set_bit() under the RCU lock, so we may set the value into the old map which is about to be freed. This may cause the value set to be lost. The current solution is not to copy the old map when resizing, but to set all the corresponding bits in the new map to 1. This solves the data loss problem, but bring the overhead of more pointless loops while doing memcg slab shrink. For shrinker_info::nr_deferred, we will only modify it under the read lock of shrinker_rwsem, so it will not run concurrently with the resizing. But after we make memcg slab shrink lockless, there will be the same data loss problem as shrinker_info::map, and we can't work around it like the map. For such resizable arrays, the most straightforward idea is to change it to xarray, like we did for list_lru [1]. We need to do xa_store() in the list_lru_add()-->set_shrinker_bit(), but this will cause memory allocation, and the list_lru_add() doesn't accept failure. A possible solution is to pre-allocate, but the location of pre-allocation is not well determined. Therefore, this commit chooses to introduce a secondary array for shrinker_info::{map, nr_deferred}, so that we only need to copy this secondary array every time the size is resized. Then even if we get the old secondary array under the RCU lock, the found map and nr_deferred are also true, so no data is lost. [1]. https://lore.kernel.org/all/20220228122126.37293-13-songmuchun@bytedance.com/ Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/linux/memcontrol.h | 12 +- include/linux/shrinker.h | 17 +++ mm/shrinker.c | 250 +++++++++++++++++++++++-------------- 3 files changed, 172 insertions(+), 107 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e765d1ff9cbb..2c9327d27c3b 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -21,6 +21,7 @@ #include #include #include +#include struct mem_cgroup; struct obj_cgroup; @@ -88,17 +89,6 @@ struct mem_cgroup_reclaim_iter { unsigned int generation; }; -/* - * Bitmap and deferred work of shrinker::id corresponding to memcg-aware - * shrinkers, which have elements charged to this memcg. - */ -struct shrinker_info { - struct rcu_head rcu; - atomic_long_t *nr_deferred; - unsigned long *map; - int map_nr_max; -}; - struct lruvec_stats_percpu { /* Local (CPU and cgroup) state */ long state[NR_VM_NODE_STAT_ITEMS]; diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 025c8070dd86..eb342994675a 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -5,6 +5,23 @@ #include #include +#define SHRINKER_UNIT_BITS BITS_PER_LONG + +/* + * Bitmap and deferred work of shrinker::id corresponding to memcg-aware + * shrinkers, which have elements charged to the memcg. + */ +struct shrinker_info_unit { + atomic_long_t nr_deferred[SHRINKER_UNIT_BITS]; + DECLARE_BITMAP(map, SHRINKER_UNIT_BITS); +}; + +struct shrinker_info { + struct rcu_head rcu; + int map_nr_max; + struct shrinker_info_unit *unit[]; +}; + /* * This struct is used to pass information from page reclaim to the shrinkers. * We consolidate the values for easier extension later. diff --git a/mm/shrinker.c b/mm/shrinker.c index a27779ed3798..1911c06b8af5 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -12,15 +12,50 @@ DECLARE_RWSEM(shrinker_rwsem); #ifdef CONFIG_MEMCG static int shrinker_nr_max; -/* The shrinker_info is expanded in a batch of BITS_PER_LONG */ -static inline int shrinker_map_size(int nr_items) +static inline int shrinker_unit_size(int nr_items) { - return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); + return (DIV_ROUND_UP(nr_items, SHRINKER_UNIT_BITS) * sizeof(struct shrinker_info_unit *)); } -static inline int shrinker_defer_size(int nr_items) +static inline void shrinker_unit_free(struct shrinker_info *info, int start) { - return (round_up(nr_items, BITS_PER_LONG) * sizeof(atomic_long_t)); + struct shrinker_info_unit **unit; + int nr, i; + + if (!info) + return; + + unit = info->unit; + nr = DIV_ROUND_UP(info->map_nr_max, SHRINKER_UNIT_BITS); + + for (i = start; i < nr; i++) { + if (!unit[i]) + break; + + kvfree(unit[i]); + unit[i] = NULL; + } +} + +static inline int shrinker_unit_alloc(struct shrinker_info *new, + struct shrinker_info *old, int nid) +{ + struct shrinker_info_unit *unit; + int nr = DIV_ROUND_UP(new->map_nr_max, SHRINKER_UNIT_BITS); + int start = old ? DIV_ROUND_UP(old->map_nr_max, SHRINKER_UNIT_BITS) : 0; + int i; + + for (i = start; i < nr; i++) { + unit = kvzalloc_node(sizeof(*unit), GFP_KERNEL, nid); + if (!unit) { + shrinker_unit_free(new, start); + return -ENOMEM; + } + + new->unit[i] = unit; + } + + return 0; } void free_shrinker_info(struct mem_cgroup *memcg) @@ -32,6 +67,7 @@ void free_shrinker_info(struct mem_cgroup *memcg) for_each_node(nid) { pn = memcg->nodeinfo[nid]; info = rcu_dereference_protected(pn->shrinker_info, true); + shrinker_unit_free(info, 0); kvfree(info); rcu_assign_pointer(pn->shrinker_info, NULL); } @@ -40,28 +76,27 @@ void free_shrinker_info(struct mem_cgroup *memcg) int alloc_shrinker_info(struct mem_cgroup *memcg) { struct shrinker_info *info; - int nid, size, ret = 0; - int map_size, defer_size = 0; + int nid, ret = 0; + int array_size = 0; down_write(&shrinker_rwsem); - map_size = shrinker_map_size(shrinker_nr_max); - defer_size = shrinker_defer_size(shrinker_nr_max); - size = map_size + defer_size; + array_size = shrinker_unit_size(shrinker_nr_max); for_each_node(nid) { - info = kvzalloc_node(sizeof(*info) + size, GFP_KERNEL, nid); - if (!info) { - free_shrinker_info(memcg); - ret = -ENOMEM; - break; - } - info->nr_deferred = (atomic_long_t *)(info + 1); - info->map = (void *)info->nr_deferred + defer_size; + info = kvzalloc_node(sizeof(*info) + array_size, GFP_KERNEL, nid); + if (!info) + goto err; info->map_nr_max = shrinker_nr_max; + if (shrinker_unit_alloc(info, NULL, nid)) + goto err; rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); } up_write(&shrinker_rwsem); return ret; + +err: + free_shrinker_info(memcg); + return -ENOMEM; } static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, @@ -71,15 +106,12 @@ static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, lockdep_is_held(&shrinker_rwsem)); } -static int expand_one_shrinker_info(struct mem_cgroup *memcg, - int map_size, int defer_size, - int old_map_size, int old_defer_size, - int new_nr_max) +static int expand_one_shrinker_info(struct mem_cgroup *memcg, int new_size, + int old_size, int new_nr_max) { struct shrinker_info *new, *old; struct mem_cgroup_per_node *pn; int nid; - int size = map_size + defer_size; for_each_node(nid) { pn = memcg->nodeinfo[nid]; @@ -92,21 +124,18 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, if (new_nr_max <= old->map_nr_max) continue; - new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, nid); + new = kvmalloc_node(sizeof(*new) + new_size, GFP_KERNEL, nid); if (!new) return -ENOMEM; - new->nr_deferred = (atomic_long_t *)(new + 1); - new->map = (void *)new->nr_deferred + defer_size; new->map_nr_max = new_nr_max; - /* map: set all old bits, clear all new bits */ - memset(new->map, (int)0xff, old_map_size); - memset((void *)new->map + old_map_size, 0, map_size - old_map_size); - /* nr_deferred: copy old values, clear all new values */ - memcpy(new->nr_deferred, old->nr_deferred, old_defer_size); - memset((void *)new->nr_deferred + old_defer_size, 0, - defer_size - old_defer_size); + /* copy old values, allocate all new values */ + memcpy(new->unit, old->unit, old_size); + if (shrinker_unit_alloc(new, old, nid)) { + kvfree(new); + return -ENOMEM; + } rcu_assign_pointer(pn->shrinker_info, new); kvfree_rcu(old, rcu); @@ -118,9 +147,8 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, static int expand_shrinker_info(int new_id) { int ret = 0; - int new_nr_max = round_up(new_id + 1, BITS_PER_LONG); - int map_size, defer_size = 0; - int old_map_size, old_defer_size = 0; + int new_nr_max = round_up(new_id + 1, SHRINKER_UNIT_BITS); + int new_size, old_size = 0; struct mem_cgroup *memcg; if (!root_mem_cgroup) @@ -128,15 +156,12 @@ static int expand_shrinker_info(int new_id) lockdep_assert_held(&shrinker_rwsem); - map_size = shrinker_map_size(new_nr_max); - defer_size = shrinker_defer_size(new_nr_max); - old_map_size = shrinker_map_size(shrinker_nr_max); - old_defer_size = shrinker_defer_size(shrinker_nr_max); + new_size = shrinker_unit_size(new_nr_max); + old_size = shrinker_unit_size(shrinker_nr_max); memcg = mem_cgroup_iter(NULL, NULL, NULL); do { - ret = expand_one_shrinker_info(memcg, map_size, defer_size, - old_map_size, old_defer_size, + ret = expand_one_shrinker_info(memcg, new_size, old_size, new_nr_max); if (ret) { mem_cgroup_iter_break(NULL, memcg); @@ -150,17 +175,34 @@ static int expand_shrinker_info(int new_id) return ret; } +static inline int shriner_id_to_index(int shrinker_id) +{ + return shrinker_id / SHRINKER_UNIT_BITS; +} + +static inline int shriner_id_to_offset(int shrinker_id) +{ + return shrinker_id % SHRINKER_UNIT_BITS; +} + +static inline int calc_shrinker_id(int index, int offset) +{ + return index * SHRINKER_UNIT_BITS + offset; +} + void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) { if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) { struct shrinker_info *info; + struct shrinker_info_unit *unit; rcu_read_lock(); info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); + unit = info->unit[shriner_id_to_index(shrinker_id)]; if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { /* Pairs with smp mb in shrink_slab() */ smp_mb__before_atomic(); - set_bit(shrinker_id, info->map); + set_bit(shriner_id_to_offset(shrinker_id), unit->map); } rcu_read_unlock(); } @@ -209,26 +251,31 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, struct mem_cgroup *memcg) { struct shrinker_info *info; + struct shrinker_info_unit *unit; info = shrinker_info_protected(memcg, nid); - return atomic_long_xchg(&info->nr_deferred[shrinker->id], 0); + unit = info->unit[shriner_id_to_index(shrinker->id)]; + return atomic_long_xchg(&unit->nr_deferred[shriner_id_to_offset(shrinker->id)], 0); } static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, struct mem_cgroup *memcg) { struct shrinker_info *info; + struct shrinker_info_unit *unit; info = shrinker_info_protected(memcg, nid); - return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); + unit = info->unit[shriner_id_to_index(shrinker->id)]; + return atomic_long_add_return(nr, &unit->nr_deferred[shriner_id_to_offset(shrinker->id)]); } void reparent_shrinker_deferred(struct mem_cgroup *memcg) { - int i, nid; + int nid, index, offset; long nr; struct mem_cgroup *parent; struct shrinker_info *child_info, *parent_info; + struct shrinker_info_unit *child_unit, *parent_unit; parent = parent_mem_cgroup(memcg); if (!parent) @@ -239,9 +286,13 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); - for (i = 0; i < child_info->map_nr_max; i++) { - nr = atomic_long_read(&child_info->nr_deferred[i]); - atomic_long_add(nr, &parent_info->nr_deferred[i]); + for (index = 0; index < shriner_id_to_index(child_info->map_nr_max); index++) { + child_unit = child_info->unit[index]; + parent_unit = parent_info->unit[index]; + for (offset = 0; offset < SHRINKER_UNIT_BITS; offset++) { + nr = atomic_long_read(&child_unit->nr_deferred[offset]); + atomic_long_add(nr, &parent_unit->nr_deferred[offset]); + } } } up_read(&shrinker_rwsem); @@ -407,7 +458,7 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, { struct shrinker_info *info; unsigned long ret, freed = 0; - int i; + int offset, index = 0; if (!mem_cgroup_online(memcg)) return 0; @@ -419,56 +470,63 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, if (unlikely(!info)) goto unlock; - for_each_set_bit(i, info->map, info->map_nr_max) { - struct shrink_control sc = { - .gfp_mask = gfp_mask, - .nid = nid, - .memcg = memcg, - }; - struct shrinker *shrinker; + for (; index < shriner_id_to_index(info->map_nr_max); index++) { + struct shrinker_info_unit *unit; - shrinker = idr_find(&shrinker_idr, i); - if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { - if (!shrinker) - clear_bit(i, info->map); - continue; - } + unit = info->unit[index]; - /* Call non-slab shrinkers even though kmem is disabled */ - if (!memcg_kmem_online() && - !(shrinker->flags & SHRINKER_NONSLAB)) - continue; + for_each_set_bit(offset, unit->map, SHRINKER_UNIT_BITS) { + struct shrink_control sc = { + .gfp_mask = gfp_mask, + .nid = nid, + .memcg = memcg, + }; + struct shrinker *shrinker; + int shrinker_id = calc_shrinker_id(index, offset); - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) { - clear_bit(i, info->map); - /* - * After the shrinker reported that it had no objects to - * free, but before we cleared the corresponding bit in - * the memcg shrinker map, a new object might have been - * added. To make sure, we have the bit set in this - * case, we invoke the shrinker one more time and reset - * the bit if it reports that it is not empty anymore. - * The memory barrier here pairs with the barrier in - * set_shrinker_bit(): - * - * list_lru_add() shrink_slab_memcg() - * list_add_tail() clear_bit() - * - * set_bit() do_shrink_slab() - */ - smp_mb__after_atomic(); - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) - ret = 0; - else - set_shrinker_bit(memcg, nid, i); - } - freed += ret; + shrinker = idr_find(&shrinker_idr, shrinker_id); + if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { + if (!shrinker) + clear_bit(offset, unit->map); + continue; + } - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; + /* Call non-slab shrinkers even though kmem is disabled */ + if (!memcg_kmem_online() && + !(shrinker->flags & SHRINKER_NONSLAB)) + continue; + + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) { + clear_bit(offset, unit->map); + /* + * After the shrinker reported that it had no objects to + * free, but before we cleared the corresponding bit in + * the memcg shrinker map, a new object might have been + * added. To make sure, we have the bit set in this + * case, we invoke the shrinker one more time and reset + * the bit if it reports that it is not empty anymore. + * The memory barrier here pairs with the barrier in + * set_shrinker_bit(): + * + * list_lru_add() shrink_slab_memcg() + * list_add_tail() clear_bit() + * + * set_bit() do_shrink_slab() + */ + smp_mb__after_atomic(); + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) + ret = 0; + else + set_shrinker_bit(memcg, nid, shrinker_id); + } + freed += ret; + + if (rwsem_is_contended(&shrinker_rwsem)) { + freed = freed ? : 1; + goto unlock; + } } } unlock: From patchwork Thu Jul 27 08:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329382 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 70037C001E0 for ; Thu, 27 Jul 2023 08:15:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07CCE8D000E; Thu, 27 Jul 2023 04:15:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3A308D0001; Thu, 27 Jul 2023 04:15:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8CF88D000E; Thu, 27 Jul 2023 04:15:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C0D738D0001 for ; Thu, 27 Jul 2023 04:15:13 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 997C381037 for ; Thu, 27 Jul 2023 08:15:13 +0000 (UTC) X-FDA: 81056681706.13.CEA4537 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf05.hostedemail.com (Postfix) with ESMTP id 9913810000C for ; Thu, 27 Jul 2023 08:15:11 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Q9tqRuTf; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1690445711; 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=VvZzKGLWBPnU/YifQKDl8Wb9pt+zZKHS88YiwcrJMO0=; b=zepV8zilnCAZ2nJ1XOMIPtICJ0i485ag10qgRtFlq/h9SngXzaumTBCKohYNK51VwwKaBT MJ8yddL4CPeVjBN1tojzE8AddxaYv9/q5gnHL+W7/b5nT3NlrSvONdRpbZTUC31TGsaJRe xW5K5au9qTC9D7CmIb/0FpvESCioPqs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Q9tqRuTf; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445711; a=rsa-sha256; cv=none; b=axmNoTnvuJvuk+3ew6AfCqepOx2GshtsCBPMNG1fMmD4HKQzekYa3CJHB4vXSBczYNywK3 PPsS+pEv8W5oIKwbfHwwgDyB0N5dLCR8HKWaeSAmXfQGcwNGtKEmxTCIM6EZd1e+4R1mGy 5V/R3aOBHtSX9LfNiS2hCcpYcYb8PX0= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-682ae5d4184so171874b3a.1 for ; Thu, 27 Jul 2023 01:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445710; x=1691050510; 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=VvZzKGLWBPnU/YifQKDl8Wb9pt+zZKHS88YiwcrJMO0=; b=Q9tqRuTfW+cY5srbHn7u8IP29b5ufDGfp68smV7E8fCftTGxosTYM3eDhoIDWtvZOS DRED9X92lIXCPbqcQpIlzzNJl6Y97wba6ST6WufRGhIvIpuge106NPqvp5c2ehyU/Asd oMSA8Tv1DuVK+y2e86ZmSQomDeERnbVDEUOxskrhk9BtE3TwMnb685MJvFtGPrph/mim WUrL9AIFCCdRfI7Aqv+dUVQoQAzWWodSjUeYusw3M4ZTGfzP+pFvJNDluf8pwba1l8gY qAENLjZRBpCKMNG/eYYva8ELPdIrnFs1AFMKEYzGL9aFEWuygoSzbktPATbV892qAF+O GibA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445710; x=1691050510; 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=VvZzKGLWBPnU/YifQKDl8Wb9pt+zZKHS88YiwcrJMO0=; b=fhyBLY6NRBHk0T6HEmXfWNheEcqeuXLdXgCBLMb7lKA46RG9MbC4HT4IrP9iUGYAPS ZNileMD0COyhCpSxz/cOqwm3jppRR9ialRbu5gAOM1f55kCnnAaQIowEL/jOGhPEsBQS S5FzzkVLnJamyQmpEG3Z8oIxxsNL9TBR7d7OH9pUjOEX40sr3WUZG2aBkyoE9Rabv6Ls 4K0Mco9Xir6blRRVdRNjCjsWZ18vs4KK0xAvSESMu1F1fIn29ieYdEpmJYgMXVTNdAi2 tWRIS0xSJQZFXDxA1Hz2bI3225qPFS62RaHK3HsDHVM9kNDLXhjpF2OlwFwvWlMCo58u 2raw== X-Gm-Message-State: ABy/qLbh5EWo/1xW3iWjyOVkUNqhStt1UVxi/kC0qkcdIV1qN55+7Hr4 LkuJJK29lYKDug1/dgBncDVaKA== X-Google-Smtp-Source: APBJJlFdwRyoe8DFBb0YfEbWLnk7UTz07biEby4+6kjTFVFVYib+WaYPD1SK6i9vhrIynDbldBSUcQ== X-Received: by 2002:a62:1d04:0:b0:66f:3fc5:6167 with SMTP id d4-20020a621d04000000b0066f3fc56167mr4406413pfd.1.1690445710333; Thu, 27 Jul 2023 01:15:10 -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.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:15:09 -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 Subject: [PATCH v3 46/49] mm: shrinker: make global slab shrink lockless Date: Thu, 27 Jul 2023 16:04:59 +0800 Message-Id: <20230727080502.77895-47-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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9913810000C X-Stat-Signature: uuagce5419roa54d15idobqjnqsxfgit X-HE-Tag: 1690445711-678976 X-HE-Meta: U2FsdGVkX1/ZtWPt1OiFGf+oV8dUqMW+HmwKBdBhhQ18bR+zoQsBKs8JfsYekMNCnSNY3Xo/9Nr9yG5hWNLps1+DgNPV0SwqJDincdgRnOF9TV5PoWpXGRISGDAPDkTsdhIr6liEWGkvFkzTKbrkjsVIMm/o+B1sL++rLQhi9ZUZRs1v9AHEQHv+jy3JgYwcu/AhGg2EES84bd7QfY27TNYDbXwuihjzQhrKYJhX1zRBvwrKWJRdGIz3yWx1cWkpvUtluACu4FutY2f8mWKh5BVPlfaL89KAqXr50spBI/EGsIJqZoyrgcyCW8YtZFeVWgE2RvGt3H5zry4FpAhegpMQOqT9GONf3Cf6LSxW8OqEwte96nxs+UxLwy/Xx3DvP6igY0oPuZzGXoxpJ9LLcc2Km8uPI8UVZklqGjbWgTMuV2koBzkv7a5td+hnOrfLYyX6qZNs8BrxoeOHUoEjl1YuLuua50V+NJx96zB7IJJsPI8ZKkOtOXFp6r+VgpVHOayfjDtJmwd0af2yiIoNq55Oc0OZTqi08WA3d7JTRd4YGG7bsfrRB1qJtnHA78SVVzyXmVM9kz8wSR8TwQi2xR9byZPH/uxA5SbmA5g/afcDypuFbGf//HBQ8XNZ73pymsFmfI1sPD0OYwniMNr0rNON8WPKx+d09eE8I3zzfkiI7ac661BOqNuq6MzDrrJMUfGVoC8/bjM4msVpaMEj/22sxbrIivvLcvTI0zqoFaP5hI8Be5DaYA4bOAJNG41BfAFzcczMebgVn7/X3xWXvR/W72i8T+o2b+N8x6QQ4VWaIa0vM+zktF9uBfnhtC95RkDTHr1bbAX8NmywrnvfpJ8YabtS4GnkyIPrG8LjsUhNPqNPxezO4hY3OJi68rT4Xk/nuBPCRZTuTvNoeBCqYP+8v4HoKY5dgNZUdXUssxMTb4xt4179DV9s7+3l43t+tZzpCsGnt0J2TwB4fEr zLbSa55h D3U5TTVLVo1s7IaIFsvoZnMuU9YzY1Q3SPfjMZKFUeiDuYO4Hl15Cl1MWbr4PspV/FIIYqcSS78cgU7Nkpl8UCKkL1PJYAg2Rb/8uD/1+YZi+gekzqYJ06a0t4FoEh1gygB7Uf81d+DssctmgKAvzlTzWXzNyuHT2w8KrxGuFjdWjOaNdXqWL3oGhVdD4AktB9ipZ1zoSl63P2jEzbF4+D+oG+UUFmCkhoEFVlKyA/LUHNSFI+uZwWbPhyJ80FTbJTibt+7GcUQxdUzRvb8jl1TJZ9FXMZV2VHEtS50Jz3ajxsrmGScU/ZtIHpS5o8xk+uTUisL4R8U/iDONQdGeBHZTGbt4m0JJtcljO3kXjtj04NVfKLHjgZkqjed5x0dQQ8Oa5uEGpvXzHZFcDhfQT6xyvV01Pu57ZrAq6xBIlHS29MP1THOwgNJsXy4VraPPNnrvGsoCfWhtDtZxy1IkltZgOM2kyShKDTlsPsdtg5bO0UGQuorq+VmX7aj6Yp12Y4CXgGGpOHyzVBvVuH4o+kqnL5apXnCCcy3Yr6mg2D1/D9NpzrHNyK9qskA== 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: The shrinker_rwsem is a global read-write lock in shrinkers subsystem, which protects most operations such as slab shrink, registration and unregistration of shrinkers, etc. This can easily cause problems in the following cases. 1) When the memory pressure is high and there are many filesystems mounted or unmounted at the same time, slab shrink will be affected (down_read_trylock() failed). Such as the real workload mentioned by Kirill Tkhai: ``` One of the real workloads from my experience is start of an overcommitted node containing many starting containers after node crash (or many resuming containers after reboot for kernel update). In these cases memory pressure is huge, and the node goes round in long reclaim. ``` 2) If a shrinker is blocked (such as the case mentioned in [1]) and a writer comes in (such as mount a fs), then this writer will be blocked and cause all subsequent shrinker-related operations to be blocked. Even if there is no competitor when shrinking slab, there may still be a problem. The down_read_trylock() may become a perf hotspot with frequent calls to shrink_slab(). Because of the poor multicore scalability of atomic operations, this can lead to a significant drop in IPC (instructions per cycle). We used to implement the lockless slab shrink with SRCU [2], but then kernel test robot reported -88.8% regression in stress-ng.ramfs.ops_per_sec test case [3], so we reverted it [4]. This commit uses the refcount+RCU method [5] proposed by Dave Chinner to re-implement the lockless global slab shrink. The memcg slab shrink is handled in the subsequent patch. For now, all shrinker instances are converted to dynamically allocated and will be freed by call_rcu(). So we can use rcu_read_{lock,unlock}() to ensure that the shrinker instance is valid. And the shrinker instance will not be run again after unregistration. So the structure that records the pointer of shrinker instance can be safely freed without waiting for the RCU read-side critical section. In this way, while we implement the lockless slab shrink, we don't need to be blocked in unregister_shrinker(). The following are the test results: stress-ng --timeout 60 --times --verify --metrics-brief --ramfs 9 & 1) Before applying this patchset: setting to a 60 second run per stressor dispatching hogs: 9 ramfs stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s (secs) (secs) (secs) (real time) (usr+sys time) ramfs 735238 60.00 12.37 363.70 12253.05 1955.08 for a 60.01s run time: 1440.27s available CPU time 12.36s user time ( 0.86%) 363.70s system time ( 25.25%) 376.06s total time ( 26.11%) load average: 10.79 4.47 1.69 passed: 9: ramfs (9) failed: 0 skipped: 0 successful run completed in 60.01s (1 min, 0.01 secs) 2) After applying this patchset: setting to a 60 second run per stressor dispatching hogs: 9 ramfs stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s (secs) (secs) (secs) (real time) (usr+sys time) ramfs 746698 60.00 12.45 376.16 12444.02 1921.47 for a 60.01s run time: 1440.28s available CPU time 12.44s user time ( 0.86%) 376.16s system time ( 26.12%) 388.60s total time ( 26.98%) load average: 9.01 3.85 1.49 passed: 9: ramfs (9) failed: 0 skipped: 0 successful run completed in 60.01s (1 min, 0.01 secs) We can see that the ops/s has hardly changed. [1]. https://lore.kernel.org/lkml/20191129214541.3110-1-ptikhomirov@virtuozzo.com/ [2]. https://lore.kernel.org/lkml/20230313112819.38938-1-zhengqi.arch@bytedance.com/ [3]. https://lore.kernel.org/lkml/202305230837.db2c233f-yujie.liu@intel.com/ [4]. https://lore.kernel.org/all/20230609081518.3039120-1-qi.zheng@linux.dev/ [5]. https://lore.kernel.org/lkml/ZIJhou1d55d4H1s0@dread.disaster.area/ Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 17 ++++++++++ mm/shrinker.c | 70 +++++++++++++++++++++++++++++----------- 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index eb342994675a..f06225f18531 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -4,6 +4,8 @@ #include #include +#include +#include #define SHRINKER_UNIT_BITS BITS_PER_LONG @@ -87,6 +89,10 @@ struct shrinker { int seeks; /* seeks to recreate an obj */ unsigned flags; + refcount_t refcount; + struct completion done; + struct rcu_head rcu; + void *private_data; /* These are for internal use */ @@ -120,6 +126,17 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); +static inline bool shrinker_try_get(struct shrinker *shrinker) +{ + return refcount_inc_not_zero(&shrinker->refcount); +} + +static inline void shrinker_put(struct shrinker *shrinker) +{ + if (refcount_dec_and_test(&shrinker->refcount)) + complete(&shrinker->done); +} + #ifdef CONFIG_SHRINKER_DEBUG extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/shrinker.c b/mm/shrinker.c index 1911c06b8af5..d318f5621862 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "internal.h" @@ -577,33 +578,42 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, if (!mem_cgroup_disabled() && !mem_cgroup_is_root(memcg)) return shrink_slab_memcg(gfp_mask, nid, memcg, priority); - if (!down_read_trylock(&shrinker_rwsem)) - goto out; - - list_for_each_entry(shrinker, &shrinker_list, list) { + rcu_read_lock(); + list_for_each_entry_rcu(shrinker, &shrinker_list, list) { struct shrink_control sc = { .gfp_mask = gfp_mask, .nid = nid, .memcg = memcg, }; + if (!shrinker_try_get(shrinker)) + continue; + + /* + * We can safely unlock the RCU lock here since we already + * hold the refcount of the shrinker. + */ + rcu_read_unlock(); + ret = do_shrink_slab(&sc, shrinker, priority); if (ret == SHRINK_EMPTY) ret = 0; freed += ret; + /* - * Bail out if someone want to register a new shrinker to - * prevent the registration from being stalled for long periods - * by parallel ongoing shrinking. + * This shrinker may be deleted from shrinker_list and freed + * after the shrinker_put() below, but this shrinker is still + * used for the next traversal. So it is necessary to hold the + * RCU lock first to prevent this shrinker from being freed, + * which also ensures that the next shrinker that is traversed + * will not be freed (even if it is deleted from shrinker_list + * at the same time). */ - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } + rcu_read_lock(); + shrinker_put(shrinker); } - up_read(&shrinker_rwsem); -out: + rcu_read_unlock(); cond_resched(); return freed; } @@ -671,13 +681,29 @@ void shrinker_register(struct shrinker *shrinker) } down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); + list_add_tail_rcu(&shrinker->list, &shrinker_list); shrinker->flags |= SHRINKER_REGISTERED; shrinker_debugfs_add(shrinker); up_write(&shrinker_rwsem); + + init_completion(&shrinker->done); + /* + * Now the shrinker is fully set up, take the first reference to it to + * indicate that lookup operations are now allowed to use it via + * shrinker_try_get(). + */ + refcount_set(&shrinker->refcount, 1); } EXPORT_SYMBOL_GPL(shrinker_register); +static void shrinker_free_rcu_cb(struct rcu_head *head) +{ + struct shrinker *shrinker = container_of(head, struct shrinker, rcu); + + kfree(shrinker->nr_deferred); + kfree(shrinker); +} + void shrinker_free(struct shrinker *shrinker) { struct dentry *debugfs_entry = NULL; @@ -686,9 +712,18 @@ void shrinker_free(struct shrinker *shrinker) if (!shrinker) return; + if (shrinker->flags & SHRINKER_REGISTERED) { + shrinker_put(shrinker); + wait_for_completion(&shrinker->done); + } + down_write(&shrinker_rwsem); if (shrinker->flags & SHRINKER_REGISTERED) { - list_del(&shrinker->list); + /* + * Lookups on the shrinker are over and will fail in the future, + * so we can now remove it from the lists and free it. + */ + list_del_rcu(&shrinker->list); debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); shrinker->flags &= ~SHRINKER_REGISTERED; } else { @@ -702,9 +737,6 @@ void shrinker_free(struct shrinker *shrinker) if (debugfs_entry) shrinker_debugfs_remove(debugfs_entry, debugfs_id); - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; - - kfree(shrinker); + call_rcu(&shrinker->rcu, shrinker_free_rcu_cb); } EXPORT_SYMBOL_GPL(shrinker_free); From patchwork Thu Jul 27 08:05:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329383 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 099C8C3DA40 for ; Thu, 27 Jul 2023 08:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9982A900002; Thu, 27 Jul 2023 04:15:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 920838D0001; Thu, 27 Jul 2023 04:15:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7734B900002; Thu, 27 Jul 2023 04:15:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 638608D0001 for ; Thu, 27 Jul 2023 04:15:25 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2027C1204F2 for ; Thu, 27 Jul 2023 08:15:25 +0000 (UTC) X-FDA: 81056682210.12.A61E89E Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 4310D1A0008 for ; Thu, 27 Jul 2023 08:15:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EAS6K8pj; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1690445723; 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=kfKKsEp61SZUnTy00HUcIO/dAXsDrrCBrc1q4f5gA2g=; b=0KXWkoZmuN4p0nX4B73Zi5boxe5CUJfVkYg+3hySDz5gTuhwcc9pggs1RP9uInbecujFUh mhj9fGZPnb+FUN4Oe256sGwBF57k1JTSaEeK8fYnTVH1zzFGNt+g/SwHkh/uv7KBcKQAbh pj9/hfyrLPiFCBozzvkRiKB1OQhX2P8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445723; a=rsa-sha256; cv=none; b=EXOu+5I+Wt34P1Kc1/ptQ9vgIDCfs1TXOuIHi1bF8i0J8r0LmpwsMDFICW/VPIcJauxjZg MkKV20QsWLOOLRTc1QYO2o7a6rrzpxzlPv0Uh59TwckYalHpZY36WkpT+XWRswfskgtnin 0WBOWXtzJrXoBja7kLQ4jleeSnV5g9Q= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EAS6K8pj; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6748a616e17so184171b3a.1 for ; Thu, 27 Jul 2023 01:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445722; x=1691050522; 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=kfKKsEp61SZUnTy00HUcIO/dAXsDrrCBrc1q4f5gA2g=; b=EAS6K8pjZHV2xJO1k0B0O2ENzb3/Vvl+c5sC6vZF5+RNctHPYXK3F4aD7Xzt8amvSX Sp0sM3dY6nrfZgyX03OOoIKbasLRWXH327iv4+GYUr4WlO1QPIHvBbrRjUoddMLJYEtj qslIbW38aWpZfadSfI+TaMUP7PcrUPJ3woAJMv4ugKgPJM767PAG7K9gWxMSKIL9CKj3 w5CY/SzoV5mu91kUw+3ztoEROa7i9Mv96qiOzuHElFUZjh2ImlDQY3RLu003MMnVyV3S TQhJNq9ppxsbvsUjd927IP6iiwsq7VIfzEbkN9zPwoI9Valaw0w8Qu8JFGFsYg3rQsoY gM7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445722; x=1691050522; 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=kfKKsEp61SZUnTy00HUcIO/dAXsDrrCBrc1q4f5gA2g=; b=a6wRMJcAXlD/hsSDKK3UYozsFe1bXu5fPTJPFhhZ9ycFXmo2zb9av1+HHkEOyjvRFQ cKXggwibhVXNS9OwVdJHAGGnIdkWAn+eGyZHbTNgU/mEsQwtP4onF1J384TCXIH33MqF V+5EfQS7x73VjlNr5+yvh47MQNzUrSlc2zGnQeG+UAVyRNKa+pdACZ/7Bl6kewjj+rQU 5YPwWysZWmW/nlD1Yj6RU3nriA4Co0vg16b4XubP8XuH/aZ3yBreYMPOtkuPWBNBUfYo rwfELQYJpO89HWOAlHvUzBcbkp3RmCOTeDjxtPr6vGM0eCFoDhYJbB32KcKxE8Y3lFSY ACgQ== X-Gm-Message-State: ABy/qLaq4LGuDKc3X7WxM2BQj8gimvDV6W7ILizKzZh/0+43OIlvj+Q3 CoFtQq5DQssZWkXyye2UGsgKxw== X-Google-Smtp-Source: APBJJlGaIHiWHX80BWphqmbYYC2Qe9rA0t1NXuG9/ru/q26OnfFQXVEhM5bGyqGhtVnixSectLT5LA== X-Received: by 2002:a05:6a00:4792:b0:668:834d:4bd with SMTP id dh18-20020a056a00479200b00668834d04bdmr4689753pfb.0.1690445722143; Thu, 27 Jul 2023 01:15:22 -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.15.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:15:21 -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 Subject: [PATCH v3 47/49] mm: shrinker: make memcg slab shrink lockless Date: Thu, 27 Jul 2023 16:05:00 +0800 Message-Id: <20230727080502.77895-48-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 X-Stat-Signature: uscqi1g8xjeijck6khwwpy4qxrgyte7w X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 4310D1A0008 X-Rspam-User: X-HE-Tag: 1690445723-74188 X-HE-Meta: U2FsdGVkX1//MdMUZJXkdEAKGNwCQDBqcC1BOWVDDUeSOlsDvO/sabcLRbpNRvVhN1xAC9n/pHl+PkYsAh5hwJyC1WZjOR6nexyN5e29r2H7n28JQ02di7EjuszbGbKvxvshTzkDDDo0SgOK3sCVswm5paMsnwmEJy4juBWhba2Gw1wVOZwDkocs5AJ9CcDhBY1uwZTYAlBKSCKpl5TeZ42f1Ado0Nh6WrCgVLPvYhiB5GDKWYLG3daLB/7rxRQwfEAGa0+XW1tnBh9m/JJLQm/noNfCVccNcw+KI3msA+/vGVg4OQ/r2vo3hjwMx8i2sOiviLZV2nNK8Xt2tCdKjv3R+XhBdsB69KB7R8fJOfv1RwjiXHIZ7IUucdsd+rIlmkwzSaiOSjlC97ha4Q1fu/Q+5gxREc717FYItTHL6XYnlzsI+L+IYVfbioh+FNCnoxXpjA6jzcE7dh1R8gPeoQkJOigaDVnnxhThhgSsb/GSEI/KscPqNe6fiFoeomrhmMuSjjw9XhUd17FZlvv7aKTuvK2Iw76QbN1Xq6ILmlar50/q7Z/NSL7yY9P+H+eHfJI3fDX3ewlrgRWYcOjUfjx1Jb6aOXGluJHxqbHgQrDBE9ygYDYpgMww+FydDTpO6GsuzfNCNiGzcOoSi2tnYKEqJNqbzJcLGSheXnD2xv//P+5JGt12eRaMxOZBRIHmFnRVI3/q2Q2jAi3rQBWoWXjft0XxO8lWA1exJ+EaQFJMzafSwYuAcG2qJk22TpeLfnNCbKAsWzd+9Dh9IRTpw1T6u3oTxoOS5YaniaTKjqfAeHRnA8peoDQcAzHz6qwKUI1XZ8lrhau7eWelLLx/X4rf1UARrtP8o9t8O1BUBUHQm9QScJxsPWsbbCZkqBm+wzcouKGAY4untW4OHFZbgfSWWsNZtYlfERI3PI2rjNUmS9+3v/swXmGlqlLb2eA5hLCZaM3Pf4wqM7DqyYY 5M3nmtUw dkUcr2FwotBHg/qzb06o4SLYWHGpe6dFp3EfwAzQBnpF1frNGzVqM7nE2l5aJIXIBNU/F+szPyKkUg9B8g1K3ns6J6sUpanuQTPr2zOfqR7d4Oq2mbqqX3GCyvWGMBLHT+r3W1iDpa7aWP2sfDmGiJPA7epYkwgbpjJ21rW1mZl22XDt5RBulAK+e8+mKVOvOSBzY3IL/bOJAUZjDsmdy+0pyjYOqZmUxqo+7pvqb+7dQg3PS2Cb2Ijsv7qYLq5eurMfse+KMhT5DU3G+SYbO18WufgJk6dMJVlwn6NG4JeuTi7oXWFoZcCDiR2vstChTgjr54NLrztTe+mNwYTI02xYn2yYHTkZbZAt0RlPqiSbeQqBr12MFYezNysA7Wv+op1kWCwdJHAOiE5SG7JFD8gP8Q7jmHnthry7e 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: Like global slab shrink, this commit also uses refcount+RCU method to make memcg slab shrink lockless. Use the following script to do slab shrink stress test: ``` DIR="/root/shrinker/memcg/mnt" do_create() { mkdir -p /sys/fs/cgroup/memory/test echo 4G > /sys/fs/cgroup/memory/test/memory.limit_in_bytes for i in `seq 0 $1`; do mkdir -p /sys/fs/cgroup/memory/test/$i; echo $$ > /sys/fs/cgroup/memory/test/$i/cgroup.procs; mkdir -p $DIR/$i; done } do_mount() { for i in `seq $1 $2`; do mount -t tmpfs $i $DIR/$i; done } do_touch() { for i in `seq $1 $2`; do echo $$ > /sys/fs/cgroup/memory/test/$i/cgroup.procs; dd if=/dev/zero of=$DIR/$i/file$i bs=1M count=1 & done } case "$1" in touch) do_touch $2 $3 ;; test) do_create 4000 do_mount 0 4000 do_touch 0 3000 ;; *) exit 1 ;; esac ``` Save the above script, then run test and touch commands. Then we can use the following perf command to view hotspots: perf top -U -F 999 1) Before applying this patchset: 40.44% [kernel] [k] down_read_trylock 17.59% [kernel] [k] up_read 13.64% [kernel] [k] pv_native_safe_halt 11.90% [kernel] [k] shrink_slab 8.21% [kernel] [k] idr_find 2.71% [kernel] [k] _find_next_bit 1.36% [kernel] [k] shrink_node 0.81% [kernel] [k] shrink_lruvec 0.80% [kernel] [k] __radix_tree_lookup 0.50% [kernel] [k] do_shrink_slab 0.21% [kernel] [k] list_lru_count_one 0.16% [kernel] [k] mem_cgroup_iter 2) After applying this patchset: 60.17% [kernel] [k] shrink_slab 20.42% [kernel] [k] pv_native_safe_halt 3.03% [kernel] [k] do_shrink_slab 2.73% [kernel] [k] shrink_node 2.27% [kernel] [k] shrink_lruvec 2.00% [kernel] [k] __rcu_read_unlock 1.92% [kernel] [k] mem_cgroup_iter 0.98% [kernel] [k] __rcu_read_lock 0.91% [kernel] [k] osq_lock 0.63% [kernel] [k] mem_cgroup_calculate_protection 0.55% [kernel] [k] shrinker_put 0.46% [kernel] [k] list_lru_count_one We can see that the first perf hotspot becomes shrink_slab, which is what we expect. Signed-off-by: Qi Zheng --- mm/shrinker.c | 80 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index d318f5621862..fee6f62904fb 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -107,6 +107,12 @@ static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, lockdep_is_held(&shrinker_rwsem)); } +static struct shrinker_info *shrinker_info_rcu(struct mem_cgroup *memcg, + int nid) +{ + return rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); +} + static int expand_one_shrinker_info(struct mem_cgroup *memcg, int new_size, int old_size, int new_nr_max) { @@ -198,7 +204,7 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) struct shrinker_info_unit *unit; rcu_read_lock(); - info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); + info = shrinker_info_rcu(memcg, nid); unit = info->unit[shriner_id_to_index(shrinker_id)]; if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { /* Pairs with smp mb in shrink_slab() */ @@ -211,7 +217,7 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) static DEFINE_IDR(shrinker_idr); -static int prealloc_memcg_shrinker(struct shrinker *shrinker) +static int shrinker_memcg_alloc(struct shrinker *shrinker) { int id, ret = -ENOMEM; @@ -219,7 +225,6 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) return -ENOSYS; down_write(&shrinker_rwsem); - /* This may call shrinker, so it must use down_read_trylock() */ id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); if (id < 0) goto unlock; @@ -237,7 +242,7 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) return ret; } -static void unregister_memcg_shrinker(struct shrinker *shrinker) +static void shrinker_memcg_remove(struct shrinker *shrinker) { int id = shrinker->id; @@ -253,10 +258,15 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, { struct shrinker_info *info; struct shrinker_info_unit *unit; + long nr_deferred; - info = shrinker_info_protected(memcg, nid); + rcu_read_lock(); + info = shrinker_info_rcu(memcg, nid); unit = info->unit[shriner_id_to_index(shrinker->id)]; - return atomic_long_xchg(&unit->nr_deferred[shriner_id_to_offset(shrinker->id)], 0); + nr_deferred = atomic_long_xchg(&unit->nr_deferred[shriner_id_to_offset(shrinker->id)], 0); + rcu_read_unlock(); + + return nr_deferred; } static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, @@ -264,10 +274,16 @@ static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, { struct shrinker_info *info; struct shrinker_info_unit *unit; + long nr_deferred; - info = shrinker_info_protected(memcg, nid); + rcu_read_lock(); + info = shrinker_info_rcu(memcg, nid); unit = info->unit[shriner_id_to_index(shrinker->id)]; - return atomic_long_add_return(nr, &unit->nr_deferred[shriner_id_to_offset(shrinker->id)]); + nr_deferred = + atomic_long_add_return(nr, &unit->nr_deferred[shriner_id_to_offset(shrinker->id)]); + rcu_read_unlock(); + + return nr_deferred; } void reparent_shrinker_deferred(struct mem_cgroup *memcg) @@ -299,12 +315,12 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) up_read(&shrinker_rwsem); } #else -static int prealloc_memcg_shrinker(struct shrinker *shrinker) +static int shrinker_memcg_alloc(struct shrinker *shrinker) { return -ENOSYS; } -static void unregister_memcg_shrinker(struct shrinker *shrinker) +static void shrinker_memcg_remove(struct shrinker *shrinker) { } @@ -464,18 +480,23 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, if (!mem_cgroup_online(memcg)) return 0; - if (!down_read_trylock(&shrinker_rwsem)) - return 0; - - info = shrinker_info_protected(memcg, nid); +again: + rcu_read_lock(); + info = shrinker_info_rcu(memcg, nid); if (unlikely(!info)) goto unlock; - for (; index < shriner_id_to_index(info->map_nr_max); index++) { + if (index < shriner_id_to_index(info->map_nr_max)) { struct shrinker_info_unit *unit; unit = info->unit[index]; + /* + * The shrinker_info_unit will not be freed, so we can + * safely release the RCU lock here. + */ + rcu_read_unlock(); + for_each_set_bit(offset, unit->map, SHRINKER_UNIT_BITS) { struct shrink_control sc = { .gfp_mask = gfp_mask, @@ -485,12 +506,14 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, struct shrinker *shrinker; int shrinker_id = calc_shrinker_id(index, offset); + rcu_read_lock(); shrinker = idr_find(&shrinker_idr, shrinker_id); - if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { - if (!shrinker) - clear_bit(offset, unit->map); + if (unlikely(!shrinker || !shrinker_try_get(shrinker))) { + clear_bit(offset, unit->map); + rcu_read_unlock(); continue; } + rcu_read_unlock(); /* Call non-slab shrinkers even though kmem is disabled */ if (!memcg_kmem_online() && @@ -523,15 +546,20 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, set_shrinker_bit(memcg, nid, shrinker_id); } freed += ret; - - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - goto unlock; - } + shrinker_put(shrinker); } + + /* + * We have already exited the read-side of rcu critical section + * before calling do_shrink_slab(), the shrinker_info may be + * released in expand_one_shrinker_info(), so reacquire the + * shrinker_info. + */ + index++; + goto again; } unlock: - up_read(&shrinker_rwsem); + rcu_read_unlock(); return freed; } #else /* !CONFIG_MEMCG */ @@ -638,7 +666,7 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) shrinker->flags = flags | SHRINKER_ALLOCATED; if (flags & SHRINKER_MEMCG_AWARE) { - err = prealloc_memcg_shrinker(shrinker); + err = shrinker_memcg_alloc(shrinker); if (err == -ENOSYS) shrinker->flags &= ~SHRINKER_MEMCG_AWARE; else if (err == 0) @@ -731,7 +759,7 @@ void shrinker_free(struct shrinker *shrinker) } if (shrinker->flags & SHRINKER_MEMCG_AWARE) - unregister_memcg_shrinker(shrinker); + shrinker_memcg_remove(shrinker); up_write(&shrinker_rwsem); if (debugfs_entry) From patchwork Thu Jul 27 08:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329384 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 19A84C0015E for ; Thu, 27 Jul 2023 08:15:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF9B2900003; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA7F38D0001; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92233900003; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7B73E8D0001 for ; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 484541204EC for ; Thu, 27 Jul 2023 08:15:37 +0000 (UTC) X-FDA: 81056682714.30.D503040 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf21.hostedemail.com (Postfix) with ESMTP id 6B7BF1C0009 for ; Thu, 27 Jul 2023 08:15:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j4pDVeMc; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 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=1690445735; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=BpeO3eHemQbyCSZNB8AqCaicaS58AfDTuuS0MtBH+RIyNZcG7aPEF9x2V1ItZwUjw2Jyx1 NJYghpmkJnyReGFrrGj2p6i+ZEu8C35F76efQDqDGs9ZEUy0U4eKO1l/wzekOaB1/4V7CQ 4+0yD9Q+H1rlYZxGWf3HsrkCxxblM/0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445735; a=rsa-sha256; cv=none; b=p/ACMCY/PPmaSbXYDVKax5+tJx/iBsm4wkZq41xHSDpBGbfdzLWttqTuq7NRzmk2C2BoY4 ve34MA20hX4nvv0R1tooBOXHd4sBgjoh1POf8X7b9gzggarjyQiwL17mxE5sFyPl5Hj2xD WCOYr2/ARnAmhcIBuJLiFH1xx28Ylec= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j4pDVeMc; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168977b3a.0 for ; Thu, 27 Jul 2023 01:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445734; x=1691050534; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=j4pDVeMcXcw7i7IAx1DNlz6iKEYUEIabVz59nN5q7bAhCS1y2gOKuzdzTgG4j/dBwO H4HIbZq+pOLjZVM5UGP2bbBpIOa2ebzQlUp84F0j/JFisMPJqEmZ2hJuFivDCiuZb9qk P5NgTQLX0gtg3X+vGmP6/3oCCgeQ9FljDUkAtb6pQhQ/VT+3lIzONbNoOLFITLjS+g+5 Vjj6M2H3z3FRG2iT9u3T7VH/LPW2zOuTNtSoF+jLae0SEMd2/P/I3VxNY7Hl9q3RH2MH NSqRY7EFleJMoWuU3X7ly6d0/rJ15DhvMCCJQ4sCCtoszhR0yDF7rbG/n/mEuDtWN3AJ wtVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445734; x=1691050534; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=ZKManSnH1pI4+jt78CYNm6imlITpUOxdXue0LsJChP643vN9oEb2Lm6NNUL8dBdWzY y9/xAxilnKBZaLTPZmfr0UtNdNQwKZDkgrNiu+QZdwdOjPoa+k7nEO65mck3QJ97K6QD a1tUg2A7ZalMCkSGlDXn+9/sFFO9UcyDZKqGjsTDOe/x4MP7xgmyY7kR9VciN0B861MZ XfYuL3XP+N1d9ntLnWsBVCf5IScQt3NmG9SgKmbAkV5CD7YCMTdYN/Y5geqLFScH8+e+ LUUQ7q+hEzyEjsDTOjnUPtG91/XdO29SoNC7XpaYaz4UFPyu3UplbysZFDV6fnBfVZiz 8r1g== X-Gm-Message-State: ABy/qLYIFVyeWzQQAgxGwS58+0poaTHJwoOIg18Y66FUKMzY3pQ0ASDC xFUCEdmn2jsH0FpiCk7Rbns5Qw== X-Google-Smtp-Source: APBJJlGCk2Vrs4jG84R1mGLjwsvlQmrr2Zz0KCmUr/tZ9etimLEYhkynVpF/d5AFiEeYea7/v2C0Wg== X-Received: by 2002:a05:6a20:7d87:b0:12e:f6e6:882b with SMTP id v7-20020a056a207d8700b0012ef6e6882bmr6451328pzj.1.1690445734330; Thu, 27 Jul 2023 01:15:34 -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.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:15:33 -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 Subject: [PATCH v3 48/49] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Thu, 27 Jul 2023 16:05:01 +0800 Message-Id: <20230727080502.77895-49-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 X-Rspamd-Queue-Id: 6B7BF1C0009 X-Rspam-User: X-Stat-Signature: snmxan55zty33nisrryrfnkumuo89s8n X-Rspamd-Server: rspam03 X-HE-Tag: 1690445735-858174 X-HE-Meta: U2FsdGVkX1+l/5fWEY0dhV9jMV1+g83RROy3dYj1NBKYNprayEl9IuQxz7cgiDEkeOmut7syUB9yP0KIgzcNGJCbBy899BK6udUmV4c3PnWt9dezwxDTSuzrk7cs2ID364HbAXMdr36SBrPXEUJ+xDIxtAEXfHVGLiERC3GzWYcT7dPpi308Z/YQeRevA2gMtmciINNMlUfASHdZbAtJ+6rxN8tKeOnUlIxNb5iZOS3kZpjEZMTlYzG22H+pCfwQOyIobSOfq4DLWVFLEQQ+FYq1e8mYzp4/EUsvCAaroNXlKR6Nl1ZS22V8ChIzjixH0Xv94ROvKB6Pry7wjz0ibNoZReI1h9T7ULso3wxQkwuU0HIH+fgVDIprrcv5HmkP181QsNeeFpob5/nE65yzNyZL5Dw0HjF8+jXZgZkG7u9EHZkN5LhE5X4+6xR4A5YIyTtmJUB3d+M+b4Q56FbnLA7qx8ZmnprMpLlNckSudTkbnCuGQLm5B9DhZvVrFaMYKyaKXGAHeSfnDJ9iPNGrgMYfOsNGoV5GfOh0sl70PTQv3i386NVVQsbqZDWXE02Fx9/+cS5XXKJC58ecoOKyS4BXaFnkk0MtovcXCqb7Wrei4DwOteFl8+M2j6UIWcbMS84AZYNjOqXFPh7L3duiJPPo3b5T0qx/P7pPv4TCpkpoLdmprT3PCrsf93ezpotuZGDpsNVvsxqCIKG5bE7EqTz27FbyNdT9WIJqw5FJJjmCsXN+oygDGyuHeMtw02+L+DwwOd191Q8jChdSjcL9AAmEemIwbbEufar3hTp0TtMyXPP9XL+nqhWbiTe1MbMkz/8UBcuAg+m63PjVyCdwTodnf5W3DG1i7MWPEeWU1qsNwHxp+O3Kzr9ZccHqdP2Yhl+dCd6X1RAyq5R1JW+y71lOuH6U9ufGXIpyr6po9s+T2QeYNihPF6svDk4SE0881L1L3UbXpCW/xaJq7CR CbLNfN3Y AndQGll9iqcsn+b8qGbHpl817jrZ/O4/0nOhLk565IO6qeox5fB0L00Nd6DUU70/dudlDYgLuiy3dkyn7JpQfiUDS6x0SwZuyu/VlkHXnoqs9sJlvjtfXe5e/SuLrk/GJtIag15g0N77BLhVYq9cWWVeKLQ5FW+SCbYSc6TgPwdtrpSQ3sZF0mv9wYqa57oKKNDb/SQOVnsEQ5MD/HZ0w15/h3Zva1gwU5LrwVrgAX2unPhhu/1ArO9D8CwulguMI1r0SYUJRd+xuEznQVcM62wfOOLg9HXWz+U4+rUJW8MVekt6psCFWIYFY7evpdhy99iPkW2D9/zSEMr9Wa0/TmPj1z+ojlmwKKbRZrpR59UXQGQgNiP13+6VGJrzsx1nrHE0s4VtDUtdSo7YGZzmco8bejyIIFckmibJ5IvpixSPdj5VQrX6lHlKJ53rBTQGq5dTxCKeiDU/JievCIQVlhtq2o7aqG+c5qAklNmGRIBEODxEmfs6mE/PW1Pu2kW5l1VZWDfaOrlBENFmR6GpjWUtgFgaWoYxu0eXCbpDrxiFT+vkC20XksxpdApW/DabqCa3CwuBSKEW45EM= 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: For now, reparent_shrinker_deferred() is the only holder of read lock of shrinker_rwsem. And it already holds the global cgroup_mutex, so it will not be called in parallel. Therefore, in order to convert shrinker_rwsem to shrinker_mutex later, here we change to hold the write lock of shrinker_rwsem to reparent. Signed-off-by: Qi Zheng --- mm/shrinker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index fee6f62904fb..a12dede5d21f 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -299,7 +299,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_read(&shrinker_rwsem); + down_write(&shrinker_rwsem); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -312,7 +312,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_read(&shrinker_rwsem); + up_write(&shrinker_rwsem); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker) From patchwork Thu Jul 27 08:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329385 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 1717EC04E69 for ; Thu, 27 Jul 2023 08:15:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACFEA900004; Thu, 27 Jul 2023 04:15:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A595E8D0001; Thu, 27 Jul 2023 04:15:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D341900004; Thu, 27 Jul 2023 04:15:49 -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 7A3B78D0001 for ; Thu, 27 Jul 2023 04:15:49 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 50549C0510 for ; Thu, 27 Jul 2023 08:15:49 +0000 (UTC) X-FDA: 81056683218.12.9A4C2CC Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf01.hostedemail.com (Postfix) with ESMTP id 6392440002 for ; Thu, 27 Jul 2023 08:15:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TaRPl345; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1690445747; 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=V+VUr/yqCBhRzWtIhjCO81y0MQsQ8/nBil0vz0xF6BE=; b=bF8gafK/4Hvq4NsmuUyXWs9HXWOkUrfHwaJOrwsAouUatMsqU7esThjPE7Zo2JP3xuX1RC 1HffmG2znmufZcfe6AqzECdtVSdiLQO9UZcyEXar3FWte/ZmhYQJVtGPZ7CESzcFqO0KO5 0gVFniEdw1OJ2UhSNQ0B8WMjaZVT4Wg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TaRPl345; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445747; a=rsa-sha256; cv=none; b=mDRnODM1yFsskVh+Ez0sSgpn4obgomGbz0vzYoJBCCUq+75/qM51HyNHTDV3g9wIjzTjZT rNOOX3WMA45uk7Zl6NkvJ7H9sML2MEFPHD+u5tiG/XiZfWclubWeSDcVs7VyOjdtVu71cY dOKIQrkZ9t58MrDF/JjWYCsQz/T628U= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-686f6231bdeso114265b3a.1 for ; Thu, 27 Jul 2023 01:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445746; x=1691050546; 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=V+VUr/yqCBhRzWtIhjCO81y0MQsQ8/nBil0vz0xF6BE=; b=TaRPl345AKbrAIMueUHfPwp1x6uI6QP6FYTf0gbRl5pBKvfKuQ+QWduLyPJpV8ScsL Q5TivksWMgrstH3HdJCskaPbEKYgZ24uChwqAdIFrOrWwAa2WQwZ8NT8kZyVgbNoH85T do2ODt4uNF4INjJdWRp+atPQdybcUxTwq7Q7CB0q5LWN8BolV4yvFIRahlHyro/xVHih Vepy/KyZesG0IyAMF6CRgG8Mi1ITRqBiZ02IP7raj5LrBsVY5eCkMeBoD4m40xyPsJDZ tcd1kL8KzTvRLgjfGcyP08MdoeQiDGrvVHZmsG1n2bLc4Z4qfZKKlhoGJ8kGn6E5dkaY Cwmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445746; x=1691050546; 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=V+VUr/yqCBhRzWtIhjCO81y0MQsQ8/nBil0vz0xF6BE=; b=bd2OY21g9i7Jd53KO14XgOpq6eOPW5YoGjqHP+Q1VyMEmP4zqZvevD1h80RKqb8VVO uhYWEmXbk80Qp4LmVtUP0QkiN/3W7yLiO8OS1UqznHWUcZEfXEgYT1AooYextwd4vnRS shu8PUNpJAHzr9qnuxeP8zkMmqPTCOCavJ1QCkGEzkgcWTN0gSl2GwzzsFiF5YgPpOYU aX6cAt17iudUbutiXCjVLYIjXmhEyy08GtAdHSxuJ0eNPU9Rme7VOXtkhhZSFPW9v1OK 0/pjK/EH+xlVRXiy8lguONko/lHpn3fe8IWnGQd2dqLZ9F1IG1MREOewnUDwUx8zwWDH d0vA== X-Gm-Message-State: ABy/qLaDs+Md1qgoDrg4KC3+vA8uT1TLYDPvURlcuZN02q4Lz+bZwCIN TTHcTu/nKq0NsFC1cQaCKMsBHQ== X-Google-Smtp-Source: APBJJlEPnp3RDXXbUxyHg3EG2jnu2Scq2lS38vCuYEIB7nQxuybwzYpkjm+dcqMi61BwYttNjNAkLg== X-Received: by 2002:aa7:84d0:0:b0:686:bf43:60fa with SMTP id x16-20020aa784d0000000b00686bf4360famr5267613pfn.0.1690445746275; Thu, 27 Jul 2023 01:15:46 -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.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:15:45 -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 Subject: [PATCH v3 49/49] mm: shrinker: convert shrinker_rwsem to mutex Date: Thu, 27 Jul 2023 16:05:02 +0800 Message-Id: <20230727080502.77895-50-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 X-Rspamd-Queue-Id: 6392440002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: yxu1r5988cz8s1mu6hekfxq6w4awqruu X-HE-Tag: 1690445747-989374 X-HE-Meta: U2FsdGVkX18FCr6TkH+aTpUztcgwgdsUxmvh/GMU8dXf6Lh1qlubB1/AxawQLxYlVT/U8B2eYfpWpP80fYShaUP9I0LSyo6NJTtf87vD/TPUDs1LrsAJWj2KjG3ZjiDHrZqOVad1cFEX+MzbVavSyPAK8o3JAbNQTtvL1k2+lkJxxXXxdPWYMKRLKpc/5WMmHh/Q9xtnKsXTDsi5FwiMzdbJ5/lJYUiVlmF0Tc3lSLHlokPkyqcpYtIGnhT7wxIXP2LQoG6MZNpj+niEyvKpK6i+q+E7AX6/VLQ4a7eh0MlAWwhg//l9VJPWc718Qh//QfXaeRMkbrgoaLdOo5fNUMFBZZg4FnN3pGS8DAKahhV4fOU5+PWDK7gJ4bpt5qaw65+JTpOwJPrBCoSIAvK1+7ThEtz3mxFNVxfmRtCLDuRx8meYQYfw7+1rt1hV/H+tDzpTD/yr/EhrcXhtnAH0um2v10RLdZui36GEOwceiK593Rl9eZLeI1zEYYyEiihZzMdPgpDsnmqGLAOIgsUeUZM+Q3xzBwWrwlftpwrpWYs03XuUYG4EN05RcH60Ic2XvJ/PBRoB8AMnudNgSRBFM0TavFplpw6CAMrmZDm5rN4NdlsV4xEHoDaRMsHWhKYBjGgoBGB+HtOCPQkFh46KVPVSCLTeIqC4prmuVjR+B0qUT2FS6zWGuJhMJdMeRAl53RMVhRfBgRugbqQzii55yoIYla4Z5HFqs6rNsfU5knB2MY5m2JEpoS3+gjpnmdjvNja7g8sCwee5VfdvfnsfMPqoSQlAkHDuTLpKQVrzzvh7rVR4XKn+hPeEOmiOFyCoYm7JxWeAiwJSoxDhNHPKVY1hx8GA3JPghkvRiWBnroQosCDsPWpX2vTm0ZmnREAothrOk/S1J+lmfxY2oIH/kZOogfGqZeT9e9GqudIiBKOEjIwao0l9XKrNKkn49D2RDZFabYVzN7W6wqp5H6P FFvXDhcy znKFpfG43wZOMwLLPIQXWtHGXbJwB+jDXXNUa/5mNzLHXzQSmB/2tvThENK4rIV9n/+nK/wcu9VFFPjv5yZLVZlYcloAs6M+1vySG+YWiQEXQj2bwrzWg3anawfKz/sCPPFn1Xzjg8+S7QiiJYgraIM2qdzDppO5vzlmp9vBU9oK3wdIHBJ8wnuK/oMwBDHDKAFjYgQv63WMEFWGmI6av/fw7z+4FJDPmSAOnx8ks8f3aWkg3zMMKrlzhE/4mj7OPiW3Url52huJDzFJTZ1OFu4EerjgForJQ4lpCYq7UtNiZoQA9jP6jykDl7/G/ew/cnRqmaKl9LF1OYhVvaczaxYo1ZcKC2qQgR3DtO6mmaBQzkigWC91sf3X1cg0jdb8VAdhZqJc2wITQ17m3GdcrnN3Zm/F+WYvdcZFAybr0hI2kfBF4/Vqqer0SXuFk18R/LmhcHJnv7Zqn5hPPl02IxGCVxw== 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: Now there are no readers of shrinker_rwsem, so we can simply replace it with mutex lock. Signed-off-by: Qi Zheng --- drivers/md/dm-cache-metadata.c | 2 +- fs/super.c | 2 +- mm/shrinker.c | 28 ++++++++++++++-------------- mm/shrinker_debug.c | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index acffed750e3e..9e0c69958587 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c @@ -1828,7 +1828,7 @@ int dm_cache_metadata_abort(struct dm_cache_metadata *cmd) * Replacement block manager (new_bm) is created and old_bm destroyed outside of * cmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of * shrinker associated with the block manager's bufio client vs cmd root_lock). - * - must take shrinker_rwsem without holding cmd->root_lock + * - must take shrinker_mutex without holding cmd->root_lock */ new_bm = dm_block_manager_create(cmd->bdev, DM_CACHE_METADATA_BLOCK_SIZE << SECTOR_SHIFT, CACHE_MAX_CONCURRENT_LOCKS); diff --git a/fs/super.c b/fs/super.c index 68b3877af941..fdde72e2a357 100644 --- a/fs/super.c +++ b/fs/super.c @@ -54,7 +54,7 @@ static char *sb_writers_name[SB_FREEZE_LEVELS] = { * One thing we have to be careful of with a per-sb shrinker is that we don't * drop the last active reference to the superblock from within the shrinker. * If that happens we could trigger unregistering the shrinker from within the - * shrinker path and that leads to deadlock on the shrinker_rwsem. Hence we + * shrinker path and that leads to deadlock on the shrinker_mutex. Hence we * take a passive reference to the superblock to avoid this from occurring. */ static unsigned long super_cache_scan(struct shrinker *shrink, diff --git a/mm/shrinker.c b/mm/shrinker.c index a12dede5d21f..3d44a335ef3c 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -8,7 +8,7 @@ #include "internal.h" LIST_HEAD(shrinker_list); -DECLARE_RWSEM(shrinker_rwsem); +DEFINE_MUTEX(shrinker_mutex); #ifdef CONFIG_MEMCG static int shrinker_nr_max; @@ -80,7 +80,7 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) int nid, ret = 0; int array_size = 0; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); array_size = shrinker_unit_size(shrinker_nr_max); for_each_node(nid) { info = kvzalloc_node(sizeof(*info) + array_size, GFP_KERNEL, nid); @@ -91,7 +91,7 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) goto err; rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; @@ -104,7 +104,7 @@ static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, int nid) { return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, - lockdep_is_held(&shrinker_rwsem)); + lockdep_is_held(&shrinker_mutex)); } static struct shrinker_info *shrinker_info_rcu(struct mem_cgroup *memcg, @@ -161,7 +161,7 @@ static int expand_shrinker_info(int new_id) if (!root_mem_cgroup) goto out; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); new_size = shrinker_unit_size(new_nr_max); old_size = shrinker_unit_size(shrinker_nr_max); @@ -224,7 +224,7 @@ static int shrinker_memcg_alloc(struct shrinker *shrinker) if (mem_cgroup_disabled()) return -ENOSYS; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); if (id < 0) goto unlock; @@ -238,7 +238,7 @@ static int shrinker_memcg_alloc(struct shrinker *shrinker) shrinker->id = id; ret = 0; unlock: - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; } @@ -248,7 +248,7 @@ static void shrinker_memcg_remove(struct shrinker *shrinker) BUG_ON(id < 0); - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); idr_remove(&shrinker_idr, id); } @@ -299,7 +299,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -312,7 +312,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker) @@ -708,11 +708,11 @@ void shrinker_register(struct shrinker *shrinker) return; } - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); list_add_tail_rcu(&shrinker->list, &shrinker_list); shrinker->flags |= SHRINKER_REGISTERED; shrinker_debugfs_add(shrinker); - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); init_completion(&shrinker->done); /* @@ -745,7 +745,7 @@ void shrinker_free(struct shrinker *shrinker) wait_for_completion(&shrinker->done); } - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); if (shrinker->flags & SHRINKER_REGISTERED) { /* * Lookups on the shrinker are over and will fail in the future, @@ -760,7 +760,7 @@ void shrinker_free(struct shrinker *shrinker) if (shrinker->flags & SHRINKER_MEMCG_AWARE) shrinker_memcg_remove(shrinker); - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); if (debugfs_entry) shrinker_debugfs_remove(debugfs_entry, debugfs_id); diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 506257585408..368fa0484a44 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -7,7 +7,7 @@ #include /* defined in vmscan.c */ -extern struct rw_semaphore shrinker_rwsem; +extern struct mutex shrinker_mutex; extern struct list_head shrinker_list; static DEFINE_IDA(shrinker_debugfs_ida); @@ -163,7 +163,7 @@ int shrinker_debugfs_add(struct shrinker *shrinker) char buf[128]; int id; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); /* debugfs isn't initialized yet, add debugfs entries later. */ if (!shrinker_debugfs_root) @@ -220,7 +220,7 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) if (!new) return -ENOMEM; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); old = shrinker->name; shrinker->name = new; @@ -238,7 +238,7 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) shrinker->debugfs_entry = entry; } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); kfree_const(old); @@ -251,7 +251,7 @@ struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, { struct dentry *entry = shrinker->debugfs_entry; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); shrinker_debugfs_name_free(shrinker); @@ -279,14 +279,14 @@ static int __init shrinker_debugfs_init(void) shrinker_debugfs_root = dentry; /* Create debugfs entries for shrinkers registered at boot */ - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); list_for_each_entry(shrinker, &shrinker_list, list) if (!shrinker->debugfs_entry) { ret = shrinker_debugfs_add(shrinker); if (ret) break; } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; }