Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2912240rwb; Mon, 7 Aug 2023 05:38:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHYKAamrjuz5lD/p7XheBO/Jxy63IWj99EHfpD6u2fkTINxI/8xMgV4M4HSajFwzLsrxviz X-Received: by 2002:a17:906:217:b0:98e:7a7:60b0 with SMTP id 23-20020a170906021700b0098e07a760b0mr9193348ejd.65.1691411926645; Mon, 07 Aug 2023 05:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691411926; cv=none; d=google.com; s=arc-20160816; b=ksctzXOMjKwxoDDez03eccl7KDPqALdWc0QRasGu9g+/aFFHQTO9DeGr77R//eoVLi xlQA8CUtQ3z0+3iXKXeoUhEidfLbgEZqOr2fzqL0u3sXUDY/eRWVw27aiHVOnrtGGLJC 3lrlsQdcCmZ2b5imByall5hVsxa8IfMQkRKSD3y3HQDMZ5OgjMPeuHfJjWNj1vvZWp4W 8mKrl6n27Bnt6ABrauBNKdpsbVLMOjQt9OoL4Rfd3DpjaDOJk8zzDKWA6JKnW252Td43 3G0ftEKg1Ugjm4O3e5zTeL9nYV2QqVbm/k9WbVogQt+OV2sZ72hgiQEYnbPsuoP9JDV/ Cgng== 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; fh=LQnZnJgbwA2rofRvgLxtxvFjbWmQSZR0bRTgn+flB4A=; b=fZ29J7O4I6U5dY1LXaMLY0lAmINRErtGISY4wXiJQLLN5vFctSmxK3d1BWUqM8vWIV MM13gZgBgtcCX5SdvjOiCIBo03pIeGF+BSZHV4XZa37wbGShhhzuBv2ah25LVxgidbki sX/Cf38qMiGiYDRSP1SYUboH8JA/SgE7bRg6TXk4gVgqXmqufh8pECSVVUwa5OkudJft KLI7UEc/YqPIPBy37paA0KkoTG3394Aab5pfMvnxedp2zDUFOvWfy1MrT2siSwDpN8cn hpH9j895aGPr/a/Zh5d0xmOCMpjECjTf9/YCCJ7iMH01tO4WKFE4WnSCSHwRm3WvTbzN B7YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=N5LgiuNz; 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 ot23-20020a170906ccd700b0098d22334ee0si5210639ejb.797.2023.08.07.05.38.21; Mon, 07 Aug 2023 05:38:46 -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=N5LgiuNz; 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 S232889AbjHGLgL (ORCPT + 99 others); Mon, 7 Aug 2023 07:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232939AbjHGLft (ORCPT ); Mon, 7 Aug 2023 07:35:49 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974A2269F for ; Mon, 7 Aug 2023 04:32:37 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-346434c7793so4009245ab.0 for ; Mon, 07 Aug 2023 04:32:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407902; x=1692012702; 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=N5LgiuNzrjaSFLE1ygm86H4bzagTcjkxQ//m+r+BSBD8DkazkH18HpwrgVraLPCpSh xiAxRPqoFcw8TlxzFCw7VVV8ueisQcThqU6viwe/a+8AqppEP60T1RkGSpwGaOZVgFk1 tC+pvtJUO3leTvtt2H1OZMkM34M/quYAp9UrHugGeFj8BeF6CCi59crt3QbaHrw1Fl8H UDCAew+KGw/bdZG6jBmPWVIVgp1o8D0mK+abU/mTF0W5MK3Ks1UAjhVeG1V6XjqPTR1+ 98b5takrq0ml1aKDb9m58/SKMb5HOY5waSlwqSklHstoQeHRl1Sf/RuFl44wwhJDDOfq CmhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407902; x=1692012702; 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=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=h7TU6j6JObu42k8ePwQCyDEOz4LJGNEsLPe7tDJqCnGf8Zdew7xwpBGEUUVyxOuPob 5avsR1u5yQ0q9L1Vt6dkwPaEE0DpOOpbTcLuJNZtG21giA3hQSNmsFJMEuzsUyiiY5Yk Kvs2s3QlUo8sxyW15CaGxCoZ8vnvur8AC1TZVhA0qsro4wAUT8E7rfDjbDabV6XKA00t xoRk74OzWbWLJNuduAvO29mTuB5yAu6M3iteRzdK7AL/COKbfBkPoH0ns0U+vO23RzMq x8yxQyUs5dxAtodRT0mIAnJcz3c08AD40ShRJ4FFD+SK6+54xmmJ3k3EQu/cHxAzstrh zXlg== X-Gm-Message-State: AOJu0YyxcJTJPNer7z4xcreEfvvbUj+14L/oAdOXgCVZzwMqix9Fr1No WeKppf/DyAtIeLrX1Z1nFIDvYpYgClrK1AYfUEU= X-Received: by 2002:a17:90a:c8d:b0:268:196f:9656 with SMTP id v13-20020a17090a0c8d00b00268196f9656mr12999255pja.1.1691406969055; Mon, 07 Aug 2023 04:16:09 -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.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:16:08 -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 Subject: [PATCH v4 29/48] bcache: dynamically allocate the md-bcache shrinker Date: Mon, 7 Aug 2023 19:09:17 +0800 Message-Id: <20230807110936.21819-30-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 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_BLOCKED, SPF_HELO_NONE,SPF_NONE 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, use new APIs to dynamically allocate the md-bcache 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 cache_set. Signed-off-by: Qi Zheng --- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/btree.c | 27 ++++++++++++++++----------- drivers/md/bcache/sysfs.c | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 5a79bb3c272f..c622bc50f81b 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -541,7 +541,7 @@ struct cache_set { struct bio_set bio_split; /* For the btree cache */ - struct shrinker shrink; + struct shrinker *shrink; /* For the btree cache and anything allocation related */ struct mutex bucket_lock; diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index fd121a61f17c..ae5cbb55861f 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -667,7 +667,7 @@ static int mca_reap(struct btree *b, unsigned int min_order, bool flush) static unsigned long bch_mca_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; struct btree *b, *t; unsigned long i, nr = sc->nr_to_scan; unsigned long freed = 0; @@ -734,7 +734,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, static unsigned long bch_mca_count(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; if (c->shrinker_disabled) return 0; @@ -752,8 +752,8 @@ void bch_btree_cache_free(struct cache_set *c) closure_init_stack(&cl); - if (c->shrink.list.next) - unregister_shrinker(&c->shrink); + if (c->shrink) + shrinker_free(c->shrink); mutex_lock(&c->bucket_lock); @@ -828,14 +828,19 @@ int bch_btree_cache_alloc(struct cache_set *c) c->verify_data = NULL; #endif - c->shrink.count_objects = bch_mca_count; - c->shrink.scan_objects = bch_mca_scan; - c->shrink.seeks = 4; - c->shrink.batch = c->btree_pages * 2; + c->shrink = shrinker_alloc(0, "md-bcache:%pU", c->set_uuid); + if (!c->shrink) { + pr_warn("bcache: %s: could not allocate shrinker\n", __func__); + return 0; + } + + c->shrink->count_objects = bch_mca_count; + c->shrink->scan_objects = bch_mca_scan; + c->shrink->seeks = 4; + c->shrink->batch = c->btree_pages * 2; + c->shrink->private_data = c; - if (register_shrinker(&c->shrink, "md-bcache:%pU", c->set_uuid)) - pr_warn("bcache: %s: could not register shrinker\n", - __func__); + shrinker_register(c->shrink); return 0; } diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 0e2c1880f60b..45d8af755de6 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -866,7 +866,8 @@ STORE(__bch_cache_set) sc.gfp_mask = GFP_KERNEL; sc.nr_to_scan = strtoul_or_return(buf); - c->shrink.scan_objects(&c->shrink, &sc); + if (c->shrink) + c->shrink->scan_objects(c->shrink, &sc); } sysfs_strtoul_clamp(congested_read_threshold_us, -- 2.30.2