From patchwork Mon Sep 11 09:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379080 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 5A0F3EE7FF4 for ; Mon, 11 Sep 2023 09:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB7D76B020C; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E67CE6B020D; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D300C6B020E; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C30A36B020C for ; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 885ADC0957 for ; Mon, 11 Sep 2023 09:49:09 +0000 (UTC) X-FDA: 81223843218.02.736093F Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf07.hostedemail.com (Postfix) with ESMTP id B59234000A for ; Mon, 11 Sep 2023 09:49:07 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=biBHz4rB; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425747; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=MjMb+tDB59+FWxakX2eTpInAhFP9AywY1N7tsOCzywl7nyORcdYs5q9VPAgzwPTu1bwCyj yisLllIkzR6cEsiJMRWUX77j205bfCGz/OdnFI+i4BN6c9VyykghfPNjGJ7oO5bXQ6C/mD LDsMnexguc8xM/5D9TYSNcqAuRrs/5g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425747; a=rsa-sha256; cv=none; b=E58jbKwLFUHOvlw3x1YAN8sYkvOKp2hxv0u2sQ8n7gsZyPj3Ywfxq/c5t0vL3JQB9zrgxm bsltkaKLsy+vbw+6e1/EqsYG4Ydk9Lo2FhDbjPag5fNuyTqdRiclPKd9n8m4q5/u5ngI6+ R/8j+CaL8q7bLGd20edUfsrj50UEtAE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=biBHz4rB; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-56f8334f15eso230473a12.1 for ; Mon, 11 Sep 2023 02:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425746; x=1695030546; darn=kvack.org; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=biBHz4rBqdNsCZgYBy1Fe1TAfYY3izYguVgA4m8OREe/gRwpHu+bOrfDY3PY7W4cqI fD0gEliggVM7mwqKnNvdWAUcVvvIh7yjzXQHJaweneQKuMQZ6xlHKbYI2PLdW6zVFjF4 jJeK3Miry23J1jq+IS77c5tZlJRS6kOXwFHjYjVH8+/zQX1zCiKX+UhAoMwIiR5b0TUQ Z8E8GEkhAvU5/S8xI+PXSnpHTspZOc15fGmvbaq3PxLDAuZav/SZPqW7J7U+E2IfeqJj CPzP6KM4gspcKyJTCdRNaMyoGgkurOHUTqHuQ79GgX7g3O+UHYtHyMStWuUB9lL9L4lw 1Cew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425746; x=1695030546; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=seH0ya2epAyIeKZR6W3B7s0+hY/8q9yr3ZUVPaDMkz3gvU5cc38c70SyMRyl1QIypU Hukfyw88MUZ9NIOenV2G8AsNDC9GeMIb8WR5qQ3Rne/FvTLo6efMTaqbWV2sClm2B+ZO ++pu+uVen7lmFbPV8aad9PR5uI7kmfcXdnYO9a5vs4gXensPqnq1YK1iKQtyes2vyshZ urv+HwK7khsnD1Ea3rfx5WVQpj5mET+iJYme+ZlMMUFYsy+61H/eS74+pyNBy/0UQJGf fZ7C/elbNq/bDXU4ejfC3CGyKOg+cEEEp/IxUEjVc9Xnso26tIJjczijHzqqDtCNk0GR ZmCw== X-Gm-Message-State: AOJu0YzLeckKgYgsk233g9frq4jYgU+WNRZ4rrhlNYY5ytsCtEY2fa5f P+1y443EBtynvyfwngqrDoNgqg== X-Google-Smtp-Source: AGHT+IFB4SYhQnUqjdoilwCEK8hAhTVrnXXU8/drEtqr5yeRvfcPj45sGXWOGMKyaN8MzCUyMc7RRA== X-Received: by 2002:a05:6a21:9983:b0:136:f3ef:4d2 with SMTP id ve3-20020a056a21998300b00136f3ef04d2mr12710572pzb.3.1694425746623; Mon, 11 Sep 2023 02:49:06 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:06 -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, linux-fsdevel@vger.kernel.org, Qi Zheng , Coly Li , Kent Overstreet , linux-bcache@vger.kernel.org Subject: [PATCH v6 26/45] bcache: dynamically allocate the md-bcache shrinker Date: Mon, 11 Sep 2023 17:44:25 +0800 Message-Id: <20230911094444.68966-27-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: e8nbi4gmunbqnkz8ku8jdn5jdcxybg3y X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B59234000A X-Rspam-User: X-HE-Tag: 1694425747-548208 X-HE-Meta: U2FsdGVkX19LEloQTBSayAUKgyVpm/Vx9f/wVDYXSr58Sup2mH1q59LGAzi2HMnxLE7Rhp88x8K6AYz6VWDR7G0Yg0yn+kc7yG0llQVR1eN7kLQ194dk/IjhMBUua+0U/BpobmYKcehXtmQmkp0Tam/e3hXnZEjXkwaTqVPfQCwVze3wI2FkFk2zNq1oYJcv9p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KwUn/6XuePxZvWY/Amaj7YSf7hJ3iL4c65zxONHTtaIfhL8JGd4ZGl7HMjaa4Xgkt15qXvXxu1zZNT0VS1/PPxPNEXx9N7KVo8gSYI0uwyVSOkFGS2McEslfQc7LErq70uT3fLr22gwDN3vH4ajJz8VQC2XBII1CWQ5i1qv0Z16S+LFak7xYjqv1iwz95CW1S6NRWEn5alDaJguWywR/aJ8gSMTDcH/U+/HUjrKMVnN8CpRLu4P+zBELEvRN6a4QbiS+GiVnu9QqH9i+d02Z41PB 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 md-bcache shrinker, so that it can be freed asynchronously via 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 CC: Coly Li CC: Kent Overstreet CC: linux-bcache@vger.kernel.org Acked-by: Muchun Song --- 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,