From patchwork Mon Aug 7 11:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343505 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 43026C001DB for ; Mon, 7 Aug 2023 11:16:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D598D6B0078; Mon, 7 Aug 2023 07:15:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1BA6B007D; Mon, 7 Aug 2023 07:15:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD0EF8D0002; Mon, 7 Aug 2023 07:15:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ADA626B007B for ; Mon, 7 Aug 2023 07:15:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 82D6E40978 for ; Mon, 7 Aug 2023 11:15:59 +0000 (UTC) X-FDA: 81097054038.19.B9FEF4F Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf21.hostedemail.com (Postfix) with ESMTP id A224C1C0015 for ; Mon, 7 Aug 2023 11:15:57 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AcIjUBUr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 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=1691406957; 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=x1yZWn5jqhhXD5GlPCwn7Rqy/lqVgw4fKiPcfLbuAyw=; b=f2HRdIbXL+Nsvx2/d8ht0hjx52XE09QD5zNfVKTjYU2dSZMyZ8mssXmDv7BfJFisSZbC79 nvFqM2vbGIg4CZr6dUrXhzSIfO54nAffPHf1ew1qonrtqtawhwuW1oJdutRFFSg5dhOHou n88zKuv29h0rBI5JBpSpuKvUUg4Kb2g= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=AcIjUBUr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691406957; a=rsa-sha256; cv=none; b=s1TX0oiVeWLw51MSjKPpm3Dd8oQLV70jHnvPvvaI4z2oJ7PuwXrzO7lmi/klGRTwAld0Pq Vd8UssAwyRSHTRR3u3Zpm6+n5wFVer6StTyLYNeXCUBp1tztQVKgMJwl+2u3IIit/Q3Rk1 0pLFJlIzeNhCI32W2DfXyVBVxuoCNJc= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-55b5a37acb6so362438a12.0 for ; Mon, 07 Aug 2023 04:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691406956; x=1692011756; 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=x1yZWn5jqhhXD5GlPCwn7Rqy/lqVgw4fKiPcfLbuAyw=; b=AcIjUBUrPWg0UzvX5wfFusVN+dKafMdFSH2GRzDH1OvYCulGxI33IbPnGkf00jzcfm 4A2gtuaaMbbtp6GdbHcVvPsXNRG1dmOn4MOltHcp0lO1ZvH61PsHri+EHSBurlaP3++Q 4Ay4mp+CERsWHNo0m/mtiLtHugH42cl3pUwAYaJdXbMqhQOvO09TYlTgMkhLAJn4/X6x i3g9KcsL+Xka9qDqamdAs09xw8L3SMlDoJ+EPUs9bBOqEWf8CI1XS8GEbt6nh07SwXhK J3x/B99DfdJVBmu0rw2+YUXatA5oQZwE4RwMladVYflBE1HvjLGyTI12ejp5Woqr/FOF LWLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691406956; x=1692011756; 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=x1yZWn5jqhhXD5GlPCwn7Rqy/lqVgw4fKiPcfLbuAyw=; b=jFc8AggmXdHb7bmACuuCdEgq0eWKR0e6sXGvRrXpMgIR5YoiBzrSmefZvZnLFCHal0 6CCuoeg8bcaDj6bHLg90Eg5Lmu4ewaLy1iTcScE3iLRykd+IJzAqFIf4e8i/cex+yf/K aydu7R2CJW8uBeOwyZG4XhM/xrS9GbMtu1/iffSzD3uy6kQ8ij1ef+Tj6bryf4YDF0GC RLh94SsuBlqDUPAqZL8k0dZhatj296TGw3fKZ/SU2w08BRc+/HHAt/XsAU0Sb+jBFvXT qEW23Ru0fKjMKUsez1zJE8HMKnx0Eev4wweu9YGc9RXQChAe44Jghvi+0dg+JbJbEIx+ YBSw== X-Gm-Message-State: AOJu0YxTIEIIhP/IH35SCICN5gdmHuqL3mN3SLMkCybcilYLcI8mXatT 7BJWYyATgIw11A7w/ihcFZbpmw== X-Google-Smtp-Source: AGHT+IFmiFe8iRG7X1ND7nrFgfyiRFI3F00Omyk3P1Mi12alvC2oRACqfoDpuN1VIlTmyfJiX72rxw== X-Received: by 2002:a17:90a:2909:b0:269:5bf7:d79c with SMTP id g9-20020a17090a290900b002695bf7d79cmr2218056pjd.1.1691406956537; Mon, 07 Aug 2023 04:15:56 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:15:55 -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, simon.horman@corigine.com, dlemoal@kernel.org 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 , Muchun Song Subject: [PATCH v4 28/48] md/raid5: dynamically allocate the md-raid5 shrinker Date: Mon, 7 Aug 2023 19:09:16 +0800 Message-Id: <20230807110936.21819-29-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A224C1C0015 X-Stat-Signature: 58jby1k1cdah9t4n1ziqezgqqdhmd3uf X-Rspam-User: X-HE-Tag: 1691406957-719151 X-HE-Meta: U2FsdGVkX19bZfu1NtEgc4j2doSb3r3DSGMMM95m4He8McSqXhqZ/SqzKrb+CbQGjc5B7UFbS0SMOFCXgydXfNCkuxI9wd2laT7pM9LvLm9VRd2vwzAd9XRdMlSkFByTDogoZ9EbtxdF1tbReiQxf5uZHkS9NHYklvHT7q28nITh3H6rzPOv36lDaD91kyByfMGzBaG6oXgFvfBfZ0WUOq0EenRFChg4NlUF24iP3JsMGRHPYY+ET90fiov7RUU/3ugAWgzlyxgDJ5RrcepTrZWILtlsu15Jt/3J7hwujZ0PNI5736G9IQKbvcA7ZyvwEXETaPr4xhZrqVm+jLUcKptv5UTIctD4J9lYumnpL0VrWcOOj4Z1VTary2G71wRNskZ6epuvimh6g9F49YiAfHxGJRDmd8GoS8PVtofLrQbGOIIQ6fVlmXKhV/1wOEdZ2fLxSxEMgFSC/eUvXkbjmaJ2rL0Ag9xPlQGrVexRHwnMAKyu4F84xsDASSi7hTK/VgMDYJtj+5gYFtANr1LJSd0pxDjP7Z7Ty4JeEen9PQy6kIPeOwQIC/p+sH1d7vontfeI2r74C04ZQWbX8Iav8DcS8w7hJPRLJdCwXggZHO9wgnRsm088CbYsWoO7xDqM/vNyWHiS5bP6kpj1LYh0ndyRE2E1CYzAXfHz56lPq6BgkcxBHslYCGx3J2xLwfLhH/60BCsi8ueLpHgMja5nBI9LH5c9n/4c5/yhd7r36miXK7lbrJro1n9ofxDoy2fddL9YQf+439VMsqhWDqzUYKYXN+5cUgH/7gfzSvELOYPD4jEZD024zyv/oSFvJb/gYgzYeNTeNSPRp95RsSoFNHcC7XXg/KGAValPyxWfXKKZXxJQ8t/IPu0KtDMjBs5fMHplY9JKsnhf90H/zE/3x+SMZZqGAfPoXPb6YOzLpxudvszBSua2yfOy7SEtZsM650ATTHBeGJcqwP7dyMJ dJEAKttA Q75/q8bX2VoJ4IHh2oRpyecukWpzJVVWGNbOhPMqosbMTCE1i/48hA8Zx77wWlKHH5wQefcJbdEFk/JBoZyZiz09JNOWnhgfVmlxG60tfep8qZCHs/WPQ77ZY+kuTkKAOkdO4MbX2wPeTXNZd+iQPZpSKl4+mVg+rz9LjoOJmP1qgffK/4axFGgi0xD2TTweCyjGmMfdRTW/+qfj3/IVHefygikRsdttA1rf7SXPl2Et58YL5hZFcfR2o9EF+1jH2MeCCxyICHpUavSRPBAuBy7lxkFsRvedoYKjws/n75dfNlfW1AKMUbo2tIVcOhzznVkvRmCP2fFpyBh+sxox+Xm/oMvsP65XxE6oBYloenW9m+r3JyrMn2jQD6GwI9IjGW1MOExqwUaQ1V33UDo2BIYshRAz86Nge5RDQ 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 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 Reviewed-by: Muchun Song --- 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 32a87193bad7..e284c2f7dbe4 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;