Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2920039rwo; Mon, 24 Jul 2023 03:34:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlG+xigjBQeMG7czx/5j72QGBKsvX+KfLtG9czSceqb+oaCgzeGl/5JbWXfAFKGz7n6DkvzC X-Received: by 2002:a05:6a00:1993:b0:661:4a00:1ea5 with SMTP id d19-20020a056a00199300b006614a001ea5mr6838354pfl.20.1690194876004; Mon, 24 Jul 2023 03:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690194875; cv=none; d=google.com; s=arc-20160816; b=papdjd+IzgsxtrbAZ0P+y88DuanICoN2TgfqaJIf1JYr6t+luq1X1qWorQ6sl6KNd8 zSvxoLA7zVYG79QxGve365PnfJ8b72/o0CiiuiKd5KoRgOeDiXOCCi0PCEyctk4yJNeP meIloz2n2BbGnwucsY6vMJi4dbIhSDClSam014vX13+RsnlSBimWp/XvSAHxgljOvy5j /PKNpUu1KDk6b1QMPSki6De4uTqhZwoDU4naEBF+LNgDvbJb2BSAY19FTifl/6C99yIA cylsvpzyGsgUsTK1OrAcY56MYM6uW8ZceRNY266UZPXvb+gOKzplN41T5Lz8RYgtiDIm fmDg== 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=xAp7xgO7HdkgEPthzXwizc0Cva5ED0l1RHYipwvkRG8=; fh=3lDHiAuENCYj3gWFb2bYij2cH/UC7c23rwbOpuSBNc8=; b=Cy7qGFm/uUCJdizGdZMl9j6UAt/MM7EJxjLBz7RHUKSCwUpkvLZN65ZXk0lZpYFFWX keZdDuD0ZmpvkKmnA0UBngDRrgZXEuGyXxB4vk1Wo/aN0dWZ6FHwerd5Dvw+pjE4vXUs 0I7lrJynK8Ou5yo1sFB8ky6HIjQNFl+oMhgGWFc4vTJXUl2ailzOh29Y9JG3ovomO0/G KKWCI5hhmtZhORc/G3IdPCbqaf4KHUy5SMlz15qniDT5ZtN/ZoTtCri/kdFUe8/6NfN9 WFNxG9UdottFJw3/2dsRc58aCiaiuJ/VA6sHJ3QsFU4Yv35w7eC3yzFInx4F44doqVoC e2/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=PE5m8TNZ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 s8-20020a63d048000000b005633498bbf3si8403572pgi.290.2023.07.24.03.34.22; Mon, 24 Jul 2023 03:34:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=PE5m8TNZ; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S233266AbjGXKOu (ORCPT + 99 others); Mon, 24 Jul 2023 06:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232492AbjGXKN6 (ORCPT ); Mon, 24 Jul 2023 06:13:58 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3A9444BD for ; Mon, 24 Jul 2023 03:06:37 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id ca18e2360f4ac-785d3a53ed6so40619339f.1 for ; Mon, 24 Jul 2023 03:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690193195; x=1690797995; 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=xAp7xgO7HdkgEPthzXwizc0Cva5ED0l1RHYipwvkRG8=; b=PE5m8TNZL1hvDfIjblVD6zFmRWt+7mQ31xbVJ5pN6sc+eZbsuJx4+6/FR38bH78iK2 uOT8JPJTJ1mi9L2NiiqIjVSiiDA82I2iQx8eRWZoLOtaBOVLZeyuAfcb6G4HGHpP6btx 9OZ+LR+EgpsRvNP5czvXZ3/0/54LSGJlbkcZKq8p6OzVX41ymTDhehwxGuO30fA0nUg5 AT/UQQpH8y/FgM7bxu3gyEBXmm/WLucwDtR6YLZR+cgWEyvdDwBH7ojrri6FkiaARox4 DzOR7BpAt10i6UFvSMWn9+oOI5ZvtLoY7OV5kPGWRtuSaZHRrFf1HTAQhalNz15JZH/E EaJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690193195; x=1690797995; 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=xAp7xgO7HdkgEPthzXwizc0Cva5ED0l1RHYipwvkRG8=; b=BWJX2RJQzTVm8scmS+Vme0e/DblDGT8Wl5+MJsx6BQb4hAT/Wjl1yF5u3dx88QsxgE PCvka8JT9UonZBFF9NK9lYrGb4A6zmowX/cE2Ih37uEOd/XM+GnmkQlOptj86cTtANZg UCuuudJHhmYDoSJDpSLWgmDFEA8Bzye30Z4XlMFb5qh+0SnlyH1A7Z1iRR4XMmyyAfgk cDWlOaqxQPPWG5ewjyVGznf0+0LTdyTG7tj5/iP1Kezu8lhwSH0xpRl8jzerPdIshFBJ 6jaSg2JCE9Rqxr0PC50nOhg63F2YxzxVkIyAH16qwEEfmv/ix3WnP+5EfCAx/kErg4lH bPLg== X-Gm-Message-State: ABy/qLYJMcpVcAJM9FIE3EKQWjvtWqX8xFd6p7M0wdHH6OSOR2viOlSf xFL1HYIwfF2NZ9+p/fmiTZ7u8b3gcD2q5LzBNhI= X-Received: by 2002:a17:902:f681:b0:1b8:a469:53d8 with SMTP id l1-20020a170902f68100b001b8a46953d8mr12728311plg.0.1690192278196; Mon, 24 Jul 2023 02:51:18 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id d5-20020a170902c18500b001bb20380bf2sm8467233pld.13.2023.07.24.02.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 02:51: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 Subject: [PATCH v2 31/47] mbcache: dynamically allocate the mbcache shrinker Date: Mon, 24 Jul 2023 17:43:38 +0800 Message-Id: <20230724094354.90817-32-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230724094354.90817-1-zhengqi.arch@bytedance.com> References: <20230724094354.90817-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-ext4@vger.kernel.org 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 --- fs/mbcache.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..bfecebeec828 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_unregister(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this -- 2.30.2