From patchwork Mon Sep 11 09:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379079 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 906B3EEB581 for ; Mon, 11 Sep 2023 09:49:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 345D46B020A; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F5FE6B020B; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 197426B020C; Mon, 11 Sep 2023 05:49:00 -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 081806B020A for ; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D86201408A3 for ; Mon, 11 Sep 2023 09:48:59 +0000 (UTC) X-FDA: 81223842798.07.A123658 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf08.hostedemail.com (Postfix) with ESMTP id 1006C160018 for ; Mon, 11 Sep 2023 09:48:57 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YOj6IdCF; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.48 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=1694425738; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=iyhIsNI0LOJQ4C7+FxB7Or6+46V61W7ZHlg4ufF+npj6TqdpBYj4owSdbD9Rju2z7v65rR uv2mg9aaII5ozQbexaf2VwvVkHpdR0ZoQCUrjHjbNuy6kzhG2uVKbJXWuh4Ynz5P5aBIRT bYatQkQrUm/SdXKb44yI+viT0HLFcXo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YOj6IdCF; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425738; a=rsa-sha256; cv=none; b=1LLOtOPPh8kCim+dTcMfUTjFEHChR1GMJG2LkfSbZkRL/A+7s130KLw/358e7fYZYwMThw ybW+EijyM0lodCD9pMoqmLuAIaGWtwR7i1KHPLUzBXR0LE3j5AYIMdjkQ9o46PV7hmUSu0 W5T70DxIIrUq7DKIkGhoO84NH1vIc6w= Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-273d9b1908eso716542a91.0 for ; Mon, 11 Sep 2023 02:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425737; x=1695030537; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=YOj6IdCFFB14yl9zRUgkblgikz7eGwnXnRWU6rZ1V0Y/3zaFn75nVpvRuh8p+mi9xw myJSml30BKDlrGhdL7m+LzyZ/7GtGuEmjXe3DwTE9Aoo4B3JeG/zRMIUyodlKrfUCnFo k/JWbCcCU4rQuDdiBo+Nb8SNPxnCUNC09Qtgvx1QfME7vnhfhdbrSUvNAHIOpiaQZMGL h7IxJIE8pOtRdxytw4fGlXWqWGsoZ5G4y2hExvbs/NCt7d9bv3f6cHuZDDBWTlXQG4mi ExNqpYQS2gA0o619V1wAol02SsckD0DZR4ib+SQqSiZQ7Z21VQ0v+WdrPU2n3O25GVo3 ytRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425737; x=1695030537; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=CDNRW7bpvGnTgcmKAJCYQ6/r8wguCBqpDbWhqd2x+DlEvVGzzgDiahXKMhR5jBEQVl 6SAfMPQVsPKuXx4TGNWS3P6I7eUBxNo4AKWuIbH2pIpdVnV5KBgGqv7SjVAbf9gxoDo+ vsv+wtUTKP9sJF6d/GxcSP06GvOGhHvcwBD80BPb/TVEhqyXPkf0WwaHEZNgN8/KMNZP YFKEYTqk5Z3vSYzOT3feaJgZ1G7siVMNC+WQfu6GslzB/0HmanowYDrYTtMJERYpHN/P XmFYpsHCDJ7w7tess+7tG7ithO0TcbVL4fB7ur3JKLFwWoPRQ20SWyGRYZxciKmH6HXx HtBg== X-Gm-Message-State: AOJu0Yz3M2xoZUioJw9LHjE0J/w+8JaV7DS+FP8nJzMfRthQxvyFX4Gm 8rrxZaAEimPhrmLEDGnuEfQQIg== X-Google-Smtp-Source: AGHT+IFZ0Cuso7zcW7EGyUKF+CdPkMsrNNduA/1bSkXKanT+gK0Pmmcny6T+hZLeB0kr56AjQb9xKw== X-Received: by 2002:a05:6a20:4401:b0:140:ca4c:740d with SMTP id ce1-20020a056a20440100b00140ca4c740dmr14472508pzb.4.1694425737026; Mon, 11 Sep 2023 02:48:57 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:56 -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 , Muchun Song , Song Liu , linux-raid@vger.kernel.org Subject: [PATCH v6 25/45] md/raid5: dynamically allocate the md-raid5 shrinker Date: Mon, 11 Sep 2023 17:44:24 +0800 Message-Id: <20230911094444.68966-26-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1006C160018 X-Stat-Signature: j5qprb3n1eepjryicjc1ncj63t3ufz6m X-HE-Tag: 1694425737-545099 X-HE-Meta: U2FsdGVkX1+VRdOaouldbe1FeL672HhGjZTD0gVx92eH3KsHdLhfvuZ2hG8yFmxsGMX8hRj8IFlg3aWCuMdPc8Yofx5JSUiCLKje3r0B/wtMujbBSrXF4PGpUOhUaShMWe5jBc5FQMrtl6o4QBJP5UvZwqIiiPyWkO/x8ICa+UAxdoUS4F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dYiiMk+sd1Q72sRNiHGt7mVs69HADrUAxDgJgXdTmBdw+mph/GKq/Tj3N4+TyLlcssF6Nt+yPvJspNZIbpwlTCI345pgD39gaH/gBoo0rFTLlUYWIvni7PwJXmLP7R86GaXNMIuvP8y/hWI6WvZUFDJL+LoALcj/8r1P6ps7jYVKLJw7nCCD8rMSJeY3EFDwJU50Bnr6TG3XAd2 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-raid5 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 r5conf. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Reviewed-by: Song Liu CC: linux-raid@vger.kernel.org --- drivers/md/raid5.c | 26 +++++++++++++++----------- drivers/md/raid5.h | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 4cb9c608ee19..c8d2c6e50aa1 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7401,7 +7401,7 @@ static void free_conf(struct r5conf *conf) log_exit(conf); - unregister_shrinker(&conf->shrinker); + shrinker_free(conf->shrinker); free_thread_groups(conf); shrink_stripes(conf); raid5_free_percpu(conf); @@ -7449,7 +7449,7 @@ static int raid5_alloc_percpu(struct r5conf *conf) static unsigned long raid5_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; unsigned long ret = SHRINK_STOP; if (mutex_trylock(&conf->cache_size_mutex)) { @@ -7470,7 +7470,7 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink, static unsigned long raid5_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; if (conf->max_nr_stripes < conf->min_nr_stripes) /* unlikely, but not impossible */ @@ -7705,18 +7705,22 @@ static struct r5conf *setup_conf(struct mddev *mddev) * it reduces the queue depth and so can hurt throughput. * So set it rather large, scaled by number of devices. */ - conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; - conf->shrinker.scan_objects = raid5_cache_scan; - conf->shrinker.count_objects = raid5_cache_count; - conf->shrinker.batch = 128; - conf->shrinker.flags = 0; - ret = register_shrinker(&conf->shrinker, "md-raid5:%s", mdname(mddev)); - if (ret) { - pr_warn("md/raid:%s: couldn't register shrinker.\n", + conf->shrinker = shrinker_alloc(0, "md-raid5:%s", mdname(mddev)); + if (!conf->shrinker) { + ret = -ENOMEM; + pr_warn("md/raid:%s: couldn't allocate shrinker.\n", mdname(mddev)); goto abort; } + conf->shrinker->seeks = DEFAULT_SEEKS * conf->raid_disks * 4; + conf->shrinker->scan_objects = raid5_cache_scan; + conf->shrinker->count_objects = raid5_cache_count; + conf->shrinker->batch = 128; + conf->shrinker->private_data = conf; + + shrinker_register(conf->shrinker); + sprintf(pers_name, "raid%d", mddev->new_level); rcu_assign_pointer(conf->thread, md_register_thread(raid5d, mddev, pers_name)); diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 97a795979a35..22bea20eccbd 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -670,7 +670,7 @@ struct r5conf { wait_queue_head_t wait_for_stripe; wait_queue_head_t wait_for_overlap; unsigned long cache_state; - struct shrinker shrinker; + struct shrinker *shrinker; int pool_size; /* number of disks in stripeheads in pool */ spinlock_t device_lock; struct disk_info *disks;