From patchwork Mon Aug 7 11:09:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343509 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 25564EB64DD for ; Mon, 7 Aug 2023 11:16:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5E256B0078; Mon, 7 Aug 2023 07:16:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0D976B007B; Mon, 7 Aug 2023 07:16:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AE708D0002; Mon, 7 Aug 2023 07:16:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8E96D6B0078 for ; Mon, 7 Aug 2023 07:16:50 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 58A2D14068F for ; Mon, 7 Aug 2023 11:16:50 +0000 (UTC) X-FDA: 81097056180.06.AC8C1D5 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf15.hostedemail.com (Postfix) with ESMTP id 66D84A0015 for ; Mon, 7 Aug 2023 11:16:48 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZpUxkeID; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.50 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=1691407008; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=3DdkfiWTgmKwMFiQAavRJRNZLs/kyw6fzkhlFavVes6sZbRmorfjxvoW7kHXBMtgoNsm1A IrE324Bu12EIIeZ/83NkBNNCnaZBxnDAGmDPyoWYX6/44m4NPVMsWTVaVBrKwKtaSW/YCO 56qdWbT7OzV3JqDuGtrf+RnqAxaZu84= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ZpUxkeID; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691407008; a=rsa-sha256; cv=none; b=czQ6qTqDb+4EsJ71TKza659ILEHy48oQIaZ0r3pphVlEGedD4uk6DrgtdVHf97CDslFkzf /LXzWeVDzRGJg5KbXsVvi+CcRPrIW2zMFypg9+BvzBVzpsj2u3qUYjEwndJBX6m+hjHTDh rRGbgPvLjH10lCUfog2tueda9/thTM0= Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-265c94064b8so593092a91.0 for ; Mon, 07 Aug 2023 04:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407007; x=1692011807; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=ZpUxkeIDSk5DebcqgtNkjC2VJVRAtk53SZcSRGK4pcR9GN/+oNusiQFLHhuL5+fDtw 7acmwH5I9QFGztB582Oi6rcT7wKm21cMdk1CbKhqvY9Cmn9xfrqO2dNVGGjerHD5cIRA JQtjfGPdI2ZqgIP1F2QTrXkDr1QXGVfPleR0HQt933rEeM4xbQBZZP8jkCpRscjQOmu/ 9ghKZGvMUY+k4JEeKO1r8tlLUiIWng6Gl6oS+MWXEsfNz6xEM3RIsZmLQbyECe49vE1Q 39HHbQOTTkWnAgiDXPq6I3IGqNg8FapL1nhN+TNChCmLrlL9RKqe8AW+z81Q9HVEEwQe Rdpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407007; x=1692011807; 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=xVRvDV5EwClRaurogoo7jeCmWiPiam6NNimoVigpYsU=; b=FpQ+S72f3Z6GXEikcwJvZqdElO8+ZmuCAmPESAaMvf3+Zn9Get/EhRFX/sfsb2x38Q 9KLcgIESmSx5l+w74bqIfaRgWWiT3nNP7pOtRuTmqgYtzqNweUbFYKe2NBEC75d2+as0 GG+5slCdqfndtaZ7VGRL4NG0hs6OOD1ptPCQO0T7CHDlFp755EE6FTTN2gHYqlT346Eq A7qLCg5/Fk22DrvBHOD9oIkCZw8j8bdrQ8HvdxNbD2yPRHS+FBbFFKKDGaK03T+skNp0 kvtN7NGZi5eWxArDHQiXWoRXePJ2tz6yOmGpqFdYyDeKTcbFt/ts0xU9KgwOnU/tHyiA HFRg== X-Gm-Message-State: ABy/qLaSi5tJ+6wyHNbbfNxfs0p6J6kdglnEhbXDdi380mybRXpdN8s/ YD5Y2CWZacHl0J7w3Fdf8c+Qww== X-Google-Smtp-Source: APBJJlGBV531Fc0h3gGTcYh+GrDchiBvn4r3DyO1GlE79UVq2Tiyx2gaPN4S9h+mnuBR5bsUMtGvYQ== X-Received: by 2002:a17:90a:ac2:b0:268:f977:848c with SMTP id r2-20020a17090a0ac200b00268f977848cmr15219032pje.2.1691407007341; Mon, 07 Aug 2023 04:16:47 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:16:47 -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, simon.horman@corigine.com, dlemoal@kernel.org 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 , Muchun Song Subject: [PATCH v4 32/48] mbcache: dynamically allocate the mbcache shrinker Date: Mon, 7 Aug 2023 19:09:20 +0800 Message-Id: <20230807110936.21819-33-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: kuaas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JjF7kQ MVdqGSVmuCG8FKGuX6ePZdiPDejYWMwtA3bCdjaL1muU43weQ4PZgfh96m/b6OiPa22DjVHuCovFaOCKUKodSFWEHtlZYKfK8AtVpAWi0no6Vt+klAB0t1WLmSXy2WinwCDk6sNh7FjTgIA9nF2gSnDB8oOgnirvWfzk8UUbzcwFp5cYNUZzSIuatj3Sn0TztCoqCasUugE2x17IgQ3MRoI1CWEXT7NsUdO2d6oVu8CenTG5d/83bI9v5H8MQl4HPpw1sjgCnmRft56VWNQdgfugNTWrw8D4hNadi55U92lCi3NQ9sU1XgGQEbR9fgKW50bVhVhbqgc0AMu7JeY5Z5dx2ie8KtlfZVmFjdB+gSCuxMt/LGyyfMEVWDQp7UGftyRMyDGE5YY/94hF5E7w7h/ktcqp3qXTUi1JuQUm4RS10xfi1VaLOy1yT7e0fkYD3geGk 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 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 Reviewed-by: Muchun Song --- fs/mbcache.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..0d1e24e9a5e3 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_free(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this