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: 13363527 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81BA8EE49AD for ; Thu, 24 Aug 2023 03:53:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239979AbjHXDwo (ORCPT ); Wed, 23 Aug 2023 23:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233422AbjHXDvs (ORCPT ); Wed, 23 Aug 2023 23:51:48 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D6C41BC7 for ; Wed, 23 Aug 2023 20:50:14 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-34bae11c5a6so6422445ab.0 for ; Wed, 23 Aug 2023 20:50:14 -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=XXHu+xjXQ2iAnnc4OIWFV3temhh3Dh2jo9GbYORC6IcfK96sv89gcomgSNO6kWKSyl 9a0EadjcZvQxkwx7kvM2KG1IvjXBNYihUFeJUxbrZ6W4Wk/I+uizHxB7EOF2+2FVFbR9 iD1sUAVnd9n4ot4bMssQBYUyiIxG2mr5exS0vnqfKTYd9TDeN8STk796G/gghubez+9I ms3W7SgNinV7vU6RO7nR3h/7pwY4RHfF3bCCNIwUdrJnquPYbftTLY/uAkOCCRX6Ouzm NBPllKVBHGt4jY+5deYQ2AhVae6qXMYFCF4tNgL0v9SSi/ZXXH41OrGCN90Ln1iH9APd 3kYw== X-Gm-Message-State: AOJu0Yw6H2J3ltSE8hwZsavaEoWDX0h9v4JxxZCubQQG2HHvmoQOU6E8 JTgNtDTxA9nckP6daIQJilPAaQ== 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 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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)