Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10591479rwd; Thu, 22 Jun 2023 01:59:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rdbK9Fg9ukrBs9QxaVGFNuQ3zY0tekQ+WjSHMLBt3rblmdzcRRtfyBYDDBx6Z1fGLWeOu X-Received: by 2002:a17:90a:db15:b0:260:de07:c663 with SMTP id g21-20020a17090adb1500b00260de07c663mr4505978pjv.27.1687424348133; Thu, 22 Jun 2023 01:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424348; cv=none; d=google.com; s=arc-20160816; b=Nza0RwI/pWF4Wu/YTlsJMy+F3HesejKAL1W46ndVszsvqmULrZuSLZwuxBL9laHv1y o7yTpMNLdH5+unJkoE6IrwmnIUlmqwaNlc1WFcVdrhOcvyQl/h2ZqP6SFKqdM4kcL3fc +wbUeX1HdF7Mrk3tLWognRTBdwXWqQiQJ2WKhmqsljmFy31B1Dl0DhRnZmG2MhyD2C91 oPsFiQWh4ZHtmm8qUKTQVfoXZ/ZSyoCIxamyvXc34xMEQrxzIE96Ozu+HyZcW9i9zKA2 fQsZwK3NeCLCFT+NkOS/SdiUDtxuhICcfRG/Z1Ma3xseO6roWExfD+3D5nhL5w41AppN SsXw== 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=Qqb5b2GNvTgVTRVLR7iEMYBQ9KFY39GKHYb23c1SNH4=; b=E7BRl66atInk+peDRGYWlRZCfW+Gcegr4+v9kFK9Q6PvhphBJU4RFIg+7W3bMVQScb d7emlXL5temFQ/TkHKaL7E77EOK5tU8ylzEvDtwEX/z66Ag1/hHExGrEYRHxDE/vjDYN 9OrauP5gn7H4EYXRZJT1mjFHIyK3BpNMAwqSGwZ7fGrFQ0KrnfcngKJaIML7Cs5EXYVY mVamanfPVBOwsnRAYOWodPWN8WNSsXIaH/OlAmjB+D2AteysCJyr3aefkK1tpM2yZv4l k1T504cIdn8A76u53XNssGlMS2RZMAPPt2H5HkTImmlabWqUt30UhwRn8FWyveVORND6 CP4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=DTUuH0I9; 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 v9-20020a17090ae98900b0025bdc7f619asi13448549pjy.51.2023.06.22.01.58.56; Thu, 22 Jun 2023 01:59:08 -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=DTUuH0I9; 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 S229687AbjFVI6f (ORCPT + 99 others); Thu, 22 Jun 2023 04:58:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231592AbjFVI5t (ORCPT ); Thu, 22 Jun 2023 04:57:49 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB6D9271E for ; Thu, 22 Jun 2023 01:55:40 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-54f73ef19e5so678856a12.0 for ; Thu, 22 Jun 2023 01:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424140; x=1690016140; 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=Qqb5b2GNvTgVTRVLR7iEMYBQ9KFY39GKHYb23c1SNH4=; b=DTUuH0I9uHLii3LJ9Zyuu9c+EPbxYZC20xJ5+3ma+Kp5qpBNFOFTSMnclhdsEVCqLi IhMw89U+Z8kUvjOX0p1/U1TPShfVW/vJXGuaCCTRG1bGCD9nXSC4/ZiagSGalcNeTARf jURjtWkQSw5PrzWP1wBPTMrMWiplRo47rrBJgWE68ZF11RySU51PM2cKEbziuuvrByZZ Zy6z/i7b8JtNNsvUGe9g7/sl4BzjGsT0dMzcCmwPn8WMxyE8EEE7gXWjStqzol2ehPl/ 69+rSZ9IFQ8XiOW8vY+908jjX5pcw5aN354YWworQkitYsT+fnzRPZItmEL7YHvgl8Dv 6USw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424140; x=1690016140; 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=Qqb5b2GNvTgVTRVLR7iEMYBQ9KFY39GKHYb23c1SNH4=; b=GB37xEI1YUpwJ6KWagEGzxB66++3xiqK8LUMDFGLleJrL62V5zyfOnoFeghjfXFszu t5xFuQeJ74agAkFFFvuWwV5OCble3oPiRMgJ9mqGGQ5PHrW9wsRVCfAhAiMrbxmUo2He HL5vhRdzFpjNTcrPK52bQPn0+MV+s2uSjAzy8Oi/QS0gBOuLsayyfJ5uVV5kf4Nq7vqz MJf9TDjZhEsx87gJjCowdJxtXTd8klQ1N6YSMfIDEkUQNiWwdsmFs0gvebjXV5v5iqu2 AQNObmdEJJXZDi/F6+/EFDZKqSY4ziP6wRA4X7N58wNGI08Z7FTtHf2N5DJ4BXkpzaCD Romw== X-Gm-Message-State: AC+VfDwNW3nHVDEPsAEhKoYo+/eaGOUji3SdMqfsrY0U/Dm9UUruQMfm LeeW9rxFbUrpRyZQQNPMzYcCgQ== X-Received: by 2002:a17:902:d509:b0:1af:a349:3f31 with SMTP id b9-20020a170902d50900b001afa3493f31mr21732029plg.3.1687424140189; Thu, 22 Jun 2023 01:55:40 -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.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:55: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 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 12/29] mbcache: dynamically allocate the mbcache shrinker Date: Thu, 22 Jun 2023 16:53:18 +0800 Message-Id: <20230622085335.77010-13-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 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 --- fs/mbcache.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..fec393e55a66 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,8 @@ 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); } @@ -370,26 +369,30 @@ struct mb_cache *mb_cache_create(int bucket_bits) cache->c_hash = kmalloc_array(bucket_count, sizeof(struct hlist_bl_head), GFP_KERNEL); - if (!cache->c_hash) { - kfree(cache); - goto err_out; - } + if (!cache->c_hash) + goto err_c_hash; + 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")) { - kfree(cache->c_hash); - kfree(cache); - goto err_out; - } + cache->c_shrink = shrinker_alloc_and_init(mb_cache_count, mb_cache_scan, + 0, DEFAULT_SEEKS, 0, cache); + if (!cache->c_shrink) + goto err_shrinker; + + if (register_shrinker(cache->c_shrink, "mbcache-shrinker")) + goto err_register; INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); return cache; +err_register: + shrinker_free(cache->c_shrink); +err_shrinker: + kfree(cache->c_hash); +err_c_hash: + kfree(cache); err_out: return NULL; } @@ -406,7 +409,7 @@ void mb_cache_destroy(struct mb_cache *cache) { struct mb_cache_entry *entry, *next; - unregister_shrinker(&cache->c_shrink); + unregister_and_free_shrinker(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this -- 2.30.2