From patchwork Thu Aug 24 03:42: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: 13363500 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 2FCB8C71145 for ; Thu, 24 Aug 2023 03:49:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8E932800AB; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3D3D8E0011; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDF52800AB; Wed, 23 Aug 2023 23:49:20 -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 9B1248E0011 for ; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 71E74C011D for ; Thu, 24 Aug 2023 03:49:20 +0000 (UTC) X-FDA: 81157618080.06.2BFEB94 Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by imf17.hostedemail.com (Postfix) with ESMTP id A7F8A40002 for ; Thu, 24 Aug 2023 03:49:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L7x5jXCL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.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=1692848957; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=1w9WNfuz66tJj6wPdlPQcLHTlTuKyig1N+p/PRbfr+WHHWNRrfaPlI7AKzW6DoVlnGMvik dqfh5HFbILEaCYKfKXC8On/DNFf12d0dVPcRwEDYcc9TvOwe26SLRVT1cpy4UJKGF3zhJ9 XCz4LxqI4zZxJ9VTrrpv3cYfEaAKX10= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L7x5jXCL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848957; a=rsa-sha256; cv=none; b=EJLTGqWTr80T4Sjyb+MP4pvUISORvyX9NC7tLe5FAsbgo9cQogIuXdHrJAfxKyNk6D8/pR tKXHekjZHvZ9jV6fixeIhASKSF4iSJRU60gIIiTlETQa71m/m3r7r9mSmA9SSlArq5GygX kc77zukwSiTikXw5ssdLPdR99cKY0fQ= Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-34bae11c5a6so6422475ab.0 for ; Wed, 23 Aug 2023 20:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848957; x=1693453757; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=L7x5jXCLRGUnKfPoBNOZqmPlrSGKRjlLEl7C6BxvHVl4niA5K6OO+mhnHCeKV33Trg +tz2csuJvDBNqrKXB6/XcE2vyYga4ztF29T2SN17wG+jUVfGj/XDICzaJYljRr5dxCYG Zm9tvrOY9nQ5m3dzv6Iorm144WDh/2Giohela4lh6+P/anbg+SrBnxyEIv6MLHI2yIeP XULXQeHly2RIA6FIjYfl5Z7hCEVdjI7+MeoWo9KLOjxdk6l1SClYS6K9jnti4St8NGny 27VX03IgH80SMo75G/G/PAhxd05H78j0nGdfg90bK5XQZyVIF0HyYteEvPnP8OTgORus PfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848957; x=1693453757; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=l3LEhJFhufOinwTUNWCL/O6qim45jthhOA3EM3PNCwBwbsak2K5RrUbLk+azTOa9MN nodqS11zXu4N+TGpplHNzfkbYXG27EwDm8BULQ0U+R6fpZpk3eXJPL36xek7vhXV48pl JCXkDUJ2JZzDVX9WEcxKEjWfYBxtwDxbpg6Dj2nuacRp8Ggi0kM49qyKimotxdmP2pH5 rs/aeBXZEFRdNrhpDVjVBjD4IpDIi9dcv1q8LldXwsX35qZ/wVBJgKl00ISw9T1vaCND W5nilQYgtbWhS+5Ku/edtc96fjuu0n/Of5qB31XuGc+qY3YYUOIkO/qXxnS2Pd70WSBf owtA== X-Gm-Message-State: AOJu0Yx21bFd9tE6lX9bevWA6swIGbHtTLK42McpqgvGokXI/81I2FZX XdAZbDHdbu0D2xw9t2uuDxt5dw== X-Google-Smtp-Source: AGHT+IGm+Au0wCemT3+vxgVXGUpM4u4I3YXm6qtEhhQvyIskTUE4OJ/MtrbM8i5okDP0p1r/eUsjCQ== X-Received: by 2002:a92:da88:0:b0:349:4e1f:e9a0 with SMTP id u8-20020a92da88000000b003494e1fe9a0mr15611442iln.2.1692848956912; Wed, 23 Aug 2023 20:49:16 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49: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, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Minchan Kim Subject: [PATCH v5 37/45] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 24 Aug 2023 11:42:56 +0800 Message-Id: <20230824034304.37411-38-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A7F8A40002 X-Stat-Signature: pz4edd45gxr4exii7s864ydhhnz69nwa X-HE-Tag: 1692848957-533713 X-HE-Meta: U2FsdGVkX1/Sy2gRCK/pV35OtfN7rYmwGWS0P0sW3SI3SBT+GYV+2oeyivxuVlNNCx6hPXPiXM2RVpb5oF85Yiao/qtpzigIWeKnOm5wI511Pr+dnSmTDNlOjUxUZhy2jUt5v/hUWZ6vZCMRg94IbkyqxmKuPiqJRWEnhjqcMFo4XmVUmwk5nCPn4kqwilj3QrMgZTpQtO+E4BzLfn45tjRLiQL+Mir+4c0o3oS14b1HbeWm1DiD2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toohPlY8DfL5Iski3sZNH2SiJXIXAETrylzwai58ht2l4XkhTvLoblMVW0g85G4QbJYRJ2PE/Q4Fr+KUV4hcbhWwY/zYckq7hqEP9GLzGW4SKbVwcbp/LB/5o2JoWUymxz9gPa/57MZKQ7niQDEZRr73yIkMzf0ZdwlZfqMs1La6APC3Sj9jqyK7ptexfVEtlo8hIIiIgHurRu2kqtRxGDSorNKZQjS9ozFWRFP9qfh+WDPpxcNx8M4h4uZ1ZGxWM= 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 via 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 CC: Minchan Kim CC: Sergey Senozhatsky Reviewed-by: Sergey Senozhatsky --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b58f957429f0..1909234bb345 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)