From patchwork Thu Jun 22 08:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13290000 X-Patchwork-Delegate: snitzer@redhat.com 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 us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 136DEEB64D7 for ; Fri, 23 Jun 2023 05:26:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687498005; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=J48ExnqOQ415jfTUPugnM6p9TLyCbnkNh9BM3cIea+Q=; b=ZM8rUoR1wGiNDWgWAh41pm/9u62mroHjOC1sRGChxBsPx9C0lvuqAbbsnqfavbRRjYAdl2 mJ4tYObEi5HMvQJTWRMSzJTTNm0ZLLalYhECXcy3YVYZikApMMOLw1GkfKU8vo/qNKVCpg sfktBhEg/N1cosPKyQSNGDod0foeBR8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-6-ltZT-SvWOW-O7w-RZU2cNg-1; Fri, 23 Jun 2023 01:26:41 -0400 X-MC-Unique: ltZT-SvWOW-O7w-RZU2cNg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF0D88CC23C; Fri, 23 Jun 2023 05:26:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF480404A425; Fri, 23 Jun 2023 05:26:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4BA7F1954399; Fri, 23 Jun 2023 05:25:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3B5361946588 for ; Thu, 22 Jun 2023 08:55:10 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 208CD1121339; Thu, 22 Jun 2023 08:55:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 177B3112132C for ; Thu, 22 Jun 2023 08:55:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CCF67185A7A2 for ; Thu, 22 Jun 2023 08:55:09 +0000 (UTC) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-8rGma7WVO3q4YwPbkIlk-g-1; Thu, 22 Jun 2023 04:55:07 -0400 X-MC-Unique: 8rGma7WVO3q4YwPbkIlk-g-1 Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-668842bc50dso866101b3a.1 for ; Thu, 22 Jun 2023 01:55:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424107; x=1690016107; 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=VJl14vOz0XQFz+azMteX8g8XWQLmhD27loPyzQxCyWo=; b=HwylJ8EJ/GdgJuvxNgP3+L8JnaMAMNlYSMaHf9ZR8Xh4+m5h8YAxNasVsen5Mq5pWN UBuLF9lVZotxcYBG6VXOlXHL+4p0kuTrhnwBcDADnwi0rlzRd4qN1rnk4C7dD5qO3HBJ 7VlZGETnrA2xRvEv0WVppW6aid+bABXuUiW2gqSYknJ4NVa+jrucskg/Fs62/K0oK0wf TECyuNsCQPTgs2MgJCzr6WC1FO+KSHaC2yQ1cltFJ4ecP/FmLQMdlxc6Pk5zhm9JFlyc ZZidEgK7DFgzNILO9pgMrx9fx3ModhBd6Rzo0DjfaNswUKWQJEMvxDSBMYrY8AopzhMY w0ow== X-Gm-Message-State: AC+VfDyd2c0ZRp+SvgzUPGQqZAWOlkPOF5LHHEDYOafi6oUsb6Gnvuj3 Cx+cpxMfHcm1RXO9qZy7MhqIig== X-Google-Smtp-Source: ACHHUZ4GugeqE/IaG8xLwh4Bzf5woebFV8d7i9CEhVh9D6pBJJ8ySrAWkjhYmHqxBxnT9m8efiqyXQ== X-Received: by 2002:a17:902:c945:b0:1ac:40f7:8b5a with SMTP id i5-20020a170902c94500b001ac40f78b5amr21000858pla.3.1687424106926; Thu, 22 Jun 2023 01:55:06 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:55: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 Date: Thu, 22 Jun 2023 16:53:14 +0800 Message-Id: <20230622085335.77010-9-zhengqi.arch@bytedance.com> In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mailman-Approved-At: Fri, 23 Jun 2023 05:25:40 +0000 Subject: [dm-devel] [PATCH 08/29] md/raid5: dynamically allocate the md-raid5 shrinker X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-bcache@vger.kernel.org, linux-xfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-arm-msm@vger.kernel.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-raid@vger.kernel.org, linux-mm@kvack.org, dm-devel@redhat.com, Qi Zheng , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-btrfs@vger.kernel.org Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: bytedance.com In preparation for implementing lockless slab shrink, we need to dynamically allocate the md-raid5 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 r5conf. Signed-off-by: Qi Zheng --- drivers/md/raid5.c | 28 +++++++++++++++++----------- drivers/md/raid5.h | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index f4eea1bbbeaf..4866cad1ad62 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7391,7 +7391,7 @@ static void free_conf(struct r5conf *conf) log_exit(conf); - unregister_shrinker(&conf->shrinker); + unregister_and_free_shrinker(conf->shrinker); free_thread_groups(conf); shrink_stripes(conf); raid5_free_percpu(conf); @@ -7439,7 +7439,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)) { @@ -7460,7 +7460,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 */ @@ -7695,16 +7695,21 @@ 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)); + conf->shrinker = shrinker_alloc_and_init(raid5_cache_count, + raid5_cache_scan, 128, + DEFAULT_SEEKS * conf->raid_disks * 4, + 0, conf); + if (!conf->shrinker) { + pr_warn("md/raid:%s: couldn't allocate shrinker.\n", + mdname(mddev)); + goto abort; + } + + ret = register_shrinker(conf->shrinker, "md-raid5:%s", mdname(mddev)); if (ret) { pr_warn("md/raid:%s: couldn't register shrinker.\n", mdname(mddev)); - goto abort; + goto abort_shrinker; } sprintf(pers_name, "raid%d", mddev->new_level); @@ -7717,7 +7722,8 @@ static struct r5conf *setup_conf(struct mddev *mddev) } return conf; - +abort_shrinker: + shrinker_free(conf->shrinker); abort: if (conf) free_conf(conf); diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 6a92fafb0748..806f84681599 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;