From patchwork Thu Aug 24 03:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363518 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A676AC71145 for ; Thu, 24 Aug 2023 03:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239678AbjHXDto (ORCPT ); Wed, 23 Aug 2023 23:49:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239719AbjHXDs0 (ORCPT ); Wed, 23 Aug 2023 23:48:26 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFEAECD0 for ; Wed, 23 Aug 2023 20:47:34 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062658b3a.1 for ; Wed, 23 Aug 2023 20:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848850; x=1693453650; 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=rDzcwqaIquIVzn8OsvZGliHXRbA8ENN1qRnYnmk/Xe8=; b=DVQw6x+wRokChvzx3mB2d4JjmEZ8a52hJE0l07W8P8nNrlDhrotmyt3pUv3GQHPCXs 1BrfBypCNsEERgBF0IuI0x1Xr96Fhh2+gAJZZ0EK/1xIsaeYYxT6/EN1k9efrylQkcM1 zJ6XM0kKzaSamlFOt/zlkCHRnLHEfp7PkHOGXd5kLYVg7nejR+dkAMm4O/6awNT3a3Qc xgwMhP+Jmrs8A3VyzQgEal/ZVI5LfCXDTSkiUmeyykfwpxK0jmaWMGlHcl5rKNUdpgen WbYpfAOHKT2MQ9cGHKqu8Hq5a4pOBrfkWUy88QExaDxN1iywSQ8vpGlmHWNB0IOXICaV VZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848850; x=1693453650; 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=rDzcwqaIquIVzn8OsvZGliHXRbA8ENN1qRnYnmk/Xe8=; b=aYbw6QaolLhzy35Wmy1O/tUmKrfF8QGerZ6dl1F7BjhPXYt64O8pGcKmXFByq0ebk0 pebJ7atSRWNq5Ft6NkqsQMvoy4mJtGEBoTHD9D4ckrfvwT+hm3kVEyp2t1Im0XlYPliM skfoZOfGeZvbyejzGQhUGIJ/JBNK7OX0b3+DAbiOgl/KixkdduRx9/XxxOzg5llPaQGO mZIdQCKJnLNZnKALJ4gchTUxBMBiPAwVNJef6PFjDdYaxw+r/6IqgzhVx9iC6Fv2C8GE D0cZ0d7zog8NkyiY6fVC9gFzl0+M2oTIlOCAjIUn6LE/tdF5iimMCmGU3YdNT89j6k9z uvCw== X-Gm-Message-State: AOJu0YwOZmht/B6HpIMnMVCEAFKn0dXv1CvpB/Q4cEoK0LWJviY1ofWd O5SmM+XCWCyql1cReepw+fPl9Q== X-Google-Smtp-Source: AGHT+IHnOiXJrClBMOyGTENJi9JIt4dG4SRfFKrPyHzsQUg0+5rqtXlfzEqyCDyUa5PDhlr05atJeA== X-Received: by 2002:a05:6a00:1791:b0:68a:42d0:6b9b with SMTP id s17-20020a056a00179100b0068a42d06b9bmr11893102pfg.3.1692848849886; Wed, 23 Aug 2023 20:47:29 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:29 -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 v5 25/45] md/raid5: dynamically allocate the md-raid5 shrinker Date: Thu, 24 Aug 2023 11:42:44 +0800 Message-Id: <20230824034304.37411-26-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org 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 CC: Song Liu CC: linux-raid@vger.kernel.org Reviewed-by: Song Liu --- 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;