Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10596924rwd; Thu, 22 Jun 2023 02:03:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7xPz0v4d8nYvSKg5P90G72b6fEXPLjZ89/uegM5pJtpTVEF2BnUYlpuAmOdl4ESVviRHEP X-Received: by 2002:a05:6a00:2d04:b0:668:7ccd:a218 with SMTP id fa4-20020a056a002d0400b006687ccda218mr14920745pfb.7.1687424595541; Thu, 22 Jun 2023 02:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424595; cv=none; d=google.com; s=arc-20160816; b=knulDwDZmc7DULUjUYX/igseOFkoUgp5PD43fGZEC7uSIQ7wGRWPpsSoblOkdD30Ky RXf+5ghnFXaPUoSx+3Fct+thm35/96Cr4yVRhg8F5/GzgEppLiaguIV63ed3/XmVobkS nt/Dt3AMre1TX3I8ew+pRxALOZwWn93lYIjzRriV9nvv7gi0sl29kmqqrai9I9CVt8Qv PWfy8ga+1x7SYvLlCtW4KbEq9pxk5/EZJbEsGwIkjqfs+Yhty645IX2F9OItVzfFaXd/ D8+MpchIRkQhZVvvZ6SJmiYjQTKaH8pvYn3UBKXqGIwxB09674oh8Z6QNZYyI7H1+GhU oUzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=HI2dFwUJg6Nkacn7NvUdZuf5lBRaN8yTBe8QbUsYngI2eiaM40TrfuqFVDzSjwA4NG vKb8y4woydHhhZJCX6fzSiQLc/Ah83htVGJUjOSw/DS7vzN7thbddyEO/UG+QQt19GbM CBE/BK8/I6c9ipOU5rFwTXXIOo8myJUJ7Q3seFf6KI5qjd45UryPo60vMaiRPWs8n20+ S1B+bm7gT3F2PoVmsyu/nf6cX47Eb0gYeaTv6ulZKrxsms6KZCJhSOADlnqebH2FSMUp TkCHdvVdRGXQFlHrZqB/qQSW9qnHD+OGxQRMhJJyKVha/8GPI1mH+8OpzFnkxa2i6yhw TNHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=E8DR3f2H; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a63d809000000b005349009f1desi6013255pgh.354.2023.06.22.02.03.03; Thu, 22 Jun 2023 02:03:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=E8DR3f2H; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbjFVJCo (ORCPT + 99 others); Thu, 22 Jun 2023 05:02:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231770AbjFVJCC (ORCPT ); Thu, 22 Jun 2023 05:02:02 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1DC7422E for ; Thu, 22 Jun 2023 01:57:11 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1b5585e84b4so6828755ad.0 for ; Thu, 22 Jun 2023 01:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424203; x=1690016203; 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=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=E8DR3f2Hoat1dr+eWUDbHZgFwAog/Y14Fyr901nadnjVcnG4wi/dzsYXue5lsR1fMf J4lGKXcngL6tZ98mDRA+meQDFEQqI8M8C2U7Jzsh+P5pb02lqX9x9oPIGG3MqGtcEQBd gtcaY6d5Wvcszm2wAYU1/GbNiI4/W6jf6+osdVtp14uPtbwdSj3xBB3cuLupxVd/0Bva 3aNVjboq1g3R8QF56ponf3Z0k9HzBLbK6msqxIkke8ZOuuk+1QHFYDcPM2BRj2r4DT2+ yfbsCvnlQ4hLgF8msig/7Mg+peyLnaUmJHbCBGncbsN2mdvtqIXKdXSMs3btfn7dPCo7 J6Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424203; x=1690016203; 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=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=hq0kpoOpRZ5mn5nTpitC2xDY2okmZQBhBIVUNF/HWCyHvcTVgCQ0VTr98p48T1xWBy bBD/bc/p1X6LRugPBzK50bRhti2hHb7PZhlijNr/Y3141aqpbyQAhoN323drVszQCMek QuraI27OpYPWXdNgGlX7R70vZi2xreRuHXiYYBXKcNeYjZZeAYLHbhWLuUB1BD6fmnyb ndoJ/arWM99Vgi2qw/HNbn37PXFH1p/SDM5apIgIB6I+Hakncw/2t/JSfNKTzEgJGwZG eSx0wiqXLzPzAqGRouINjLrHEx4XsxY4V5icjEf+PPdCd070ixO57KfVyKFzehEeLjHV Zh+A== X-Gm-Message-State: AC+VfDztB80iOaesmxhC1nlIbA8fNbigrV0NxH/wBnCxnF0qH6Cmo6CR KdnJWoILn8vsegfrKJRYYDR8aw== X-Received: by 2002:a17:902:ea01:b0:1a9:6467:aa8d with SMTP id s1-20020a170902ea0100b001a96467aa8dmr21674286plg.1.1687424203648; Thu, 22 Jun 2023 01:56:43 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:56: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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.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-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 20/29] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 22 Jun 2023 16:53:26 +0800 Message-Id: <20230622085335.77010-21-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In preparation for implementing lockless slab shrink, we need 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 --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 3f057970504e..c03b34ae637e 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; @@ -2107,8 +2107,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. @@ -2126,8 +2125,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]; @@ -2142,18 +2140,24 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, static void zs_unregister_shrinker(struct zs_pool *pool) { - unregister_shrinker(&pool->shrinker); + unregister_and_free_shrinker(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; + int ret; + + pool->shrinker = shrinker_alloc_and_init(zs_shrinker_count, + zs_shrinker_scan, 0, + DEFAULT_SEEKS, 0, pool); + if (!pool->shrinker) + return -ENOMEM; - return register_shrinker(&pool->shrinker, "mm-zspool:%s", - pool->name); + ret = register_shrinker(pool->shrinker, "mm-zspool:%s", pool->name); + if (ret) + shrinker_free(pool->shrinker); + + return ret; } static int calculate_zspage_chain_size(int class_size) -- 2.30.2