From nobody Wed Nov 27 21:32:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445949; cv=none; d=zohomail.com; s=zohoarc; b=UGP8sVwl4lSa9XcVwuweddj5QeIDC5OiyOa6p+tkFCeiph5DT7qJ99ArczMRAD3KQcIXS2g6j+0cvtO2faogHc++kFMyAaQpu4iRuty3fImd8aRB+bg/HIFGyeMhev+UigO6rpx5n7VKO9/236sTywwM/rA9dlJtHSUJh3QOHCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445949; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v2xQZfHf5bNVsT7uWSGQWuu07PHxrGT3T56hFvtqSrg=; b=JmPU8hdstVdcy5Glqm8RNr+ovvVrrZaLJP1w9PBisBQ+HlPd7mv3eWvor6YooPJF97VDxBb+xsxsAOe1Y7M5aqI5+XXsVzq9LykY5xg9lym/u7SPzZhSrIhvNt6UAk12HRDEuvfgKdCZiIsB8adMR27hl5Zbc38MrItE8/fj+6E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445949331405.9325676494673; Thu, 27 Jul 2023 01:19:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570905.893461 (Exim 4.92) (envelope-from ) id 1qOwBs-0003bV-DR; Thu, 27 Jul 2023 08:17:44 +0000 Received: by outflank-mailman (output) from mailman id 570905.893461; Thu, 27 Jul 2023 08:17:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOwBr-0003TT-9A; Thu, 27 Jul 2023 08:17:43 +0000 Received: by outflank-mailman (input) for mailman id 570905; Thu, 27 Jul 2023 08:17:39 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw6F-0001DS-Vu for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:11:55 +0000 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [2607:f8b0:4864:20::435]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3f88120e-2c55-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 10:11:55 +0200 (CEST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686f6231bdeso113528b3a.1 for ; Thu, 27 Jul 2023 01:11:55 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:53 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3f88120e-2c55-11ee-b247-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445514; x=1691050314; 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=lyW6JZhnNvjcNaB7GqN1uV2v79yXaXII/N9CUBx8Ax42gYi0bx7SyKZlp7ota5OGyc xz3LFUjbyjINutpLynebvvBHzacoCfStfnIiREC/M8s52LB/S8PozvhLHL2LaKHkf4jF 9DRdteQ8XPpE6p0UjhjwxUS6BE53kxXxgyc4CEqj+ED289GAULMwnheYekYUqCpohGt5 Gmsuq+KFKYVL89VZVFvc5W/65nqN5yxt+BmUFxBx+3K9aBUApmiSNjlOWSgfmJvwi5CC 101OAH2cZQROpO/yBfNUpOitoioZFpWL88ogBko0HO5BvQ0gPjZ0smA8q12LAj1M0Z4O lOvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445514; x=1691050314; 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=cQ5SnCCEn3ja/1qqP1DWXtMY+LlFT7LQKqk4zdVGaMlMj8OHGCctiH8ad8t7T7FCdG QjKyuDI02GvhwvjDOTe4LhGnykz+HUn3GijdjsSM455klFyOEGkmeYCBHMC7TUnSnNjL FSDbZ1/KKQq5v2YnFwt5bQhjwMVvUu0ZS8jjYxN3LpeAZZFukPK2e6yBYSnRNQgOwaes qcwcf2OuDcFvZUmA0PF70yZBj0tW5QVb+394+y7GYMQEDS4q/efhQ761d1BJslNwdx5+ vbIk8OtNsKUgSNA9Ih9IgiuImBXU1o21q9oK6l7NgfzqLpH9+fiG6ruboQ2NCJvNIwgN 7KUg== X-Gm-Message-State: ABy/qLZ+ShOtV6fjHbtZ3eD6QDYRXEUVfJVmNDhnvH5lWDHN7LbFrNsp 0fWGb6wLY9Yd9ORqlyjBhSn5GA== X-Google-Smtp-Source: APBJJlFvU3cjl1WLZK8F+guGojMG4R1fFJkvV7n2FNowsaFmG5z+7vBu+UKq72H6C7V5uf+meL2LRA== X-Received: by 2002:a05:6a00:4a0e:b0:677:3439:874a with SMTP id do14-20020a056a004a0e00b006773439874amr5204339pfb.3.1690445513983; Thu, 27 Jul 2023 01:11:53 -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 v3 30/49] bcache: dynamically allocate the md-bcache shrinker Date: Thu, 27 Jul 2023 16:04:43 +0800 Message-Id: <20230727080502.77895-31-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445950257100001 Content-Type: text/plain; charset="utf-8" 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; =20 /* For the btree cache */ - struct shrinker shrink; + struct shrinker *shrink; =20 /* 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_o= rder, bool flush) static unsigned long bch_mca_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c =3D container_of(shrink, struct cache_set, shrink); + struct cache_set *c =3D shrink->private_data; struct btree *b, *t; unsigned long i, nr =3D sc->nr_to_scan; unsigned long freed =3D 0; @@ -734,7 +734,7 @@ static unsigned long bch_mca_scan(struct shrinker *shri= nk, static unsigned long bch_mca_count(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c =3D container_of(shrink, struct cache_set, shrink); + struct cache_set *c =3D shrink->private_data; =20 if (c->shrinker_disabled) return 0; @@ -752,8 +752,8 @@ void bch_btree_cache_free(struct cache_set *c) =20 closure_init_stack(&cl); =20 - if (c->shrink.list.next) - unregister_shrinker(&c->shrink); + if (c->shrink) + shrinker_free(c->shrink); =20 mutex_lock(&c->bucket_lock); =20 @@ -828,14 +828,19 @@ int bch_btree_cache_alloc(struct cache_set *c) c->verify_data =3D NULL; #endif =20 - c->shrink.count_objects =3D bch_mca_count; - c->shrink.scan_objects =3D bch_mca_scan; - c->shrink.seeks =3D 4; - c->shrink.batch =3D c->btree_pages * 2; + c->shrink =3D 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 =3D bch_mca_count; + c->shrink->scan_objects =3D bch_mca_scan; + c->shrink->seeks =3D 4; + c->shrink->batch =3D c->btree_pages * 2; + c->shrink->private_data =3D c; =20 - 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); =20 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) =20 sc.gfp_mask =3D GFP_KERNEL; sc.nr_to_scan =3D strtoul_or_return(buf); - c->shrink.scan_objects(&c->shrink, &sc); + if (c->shrink) + c->shrink->scan_objects(c->shrink, &sc); } =20 sysfs_strtoul_clamp(congested_read_threshold_us, --=20 2.30.2