From patchwork Thu Aug 24 03:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363457 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 37684C71145 for ; Thu, 24 Aug 2023 03:47:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D00B928009D; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C89FC8E0011; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDDF28009D; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 971F48E0011 for ; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 668B51401AE for ; Thu, 24 Aug 2023 03:47:24 +0000 (UTC) X-FDA: 81157613208.01.250D991 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 773DF140006 for ; Thu, 24 Aug 2023 03:47:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bbA3Zsc7; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.174 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=1692848841; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=KMJ22gDWeeMQKG8EQ6qNMr+3CmYy19SMr+K5lYxekHnFkXrpHd8w80DwBgV/4TZR/cHXpC 3b+1xSXHBMeBTqh3grNNcbJf6saJ9/U53btLT531h+Xo0LK7UgPbTFcqRf2NwAPpjrAEOa 6AQ8vPPyk1BK8JMwixZ7tOt1irprCj0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848841; a=rsa-sha256; cv=none; b=iXvcMxgRRPqqKzD3n/0utaPt3bxoU8ns/z53VD2FMPyjyNHPF8u49jxL+sCxK+rcUV/VP+ eQdWFUkI7VNILqAD729l+FPmNXs6G96Fp0PHEF0SL0zop2MyigJdMODNh4Ecojdoxx4Xsz hdAgZYpg8Ruh20DCtPLH3kWsMsTUvxs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bbA3Zsc7; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3a751bd3372so714426b6e.0 for ; Wed, 23 Aug 2023 20:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848840; x=1693453640; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=bbA3Zsc7IUD2am3ZTycHTYFrd1TQOR2glffiwOM82rWGJwmsEaewPHgueylM3TI4X4 0fy4O6kMrGiUtL6xCEMYVrA+5o0Hn4Kl2D80XUo6h+baumFzOxU3hlmu5grhjO+IbPzm 0Uz4Dp92EA1hhQawccSf0cOE3hJY+x9I9BT2m0Ds2y/4AnFG96IDKy5xezBiRKN7Ab6Q PgHyunTCKsFw+M5x4A8AQoFknpJ2TzQZwk+4YGLx+7riuxwrefcMbTmVYfJj2kzThdO+ gDjVOwdTnyJz+D7/eOkQqtXKM2jWS7D+5yPSU6HoCPAEzbJ75/odbhA8G4sUffTeNM2E kT3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848840; x=1693453640; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=BPeBXcnuHCp8tv1xvHFUEO7aOj4xaKb/SC5J/PR8zTMjFAg3ATWHolJHw5vrkWX/5k K1YtV+Ximmcht+292tPMJrv3I/6Ed1hzAx/HxW7kjIgelkANCj73DJj9rGTL8vXzxcqy HxTrS8ZVZ+4Z8Qq/fJohkhrdIoAv0De3eRBr9r3p2KiG4wJzFOt00JY3yt5A9sMZL7VC h7p7BfpjxrG+zr3WPebg1QyV/wJEEZizraT02uG8qkEvDy9q0VMi6wyFpMIYrfrrzFUh tJOxfLbGhfOy8T45zTJ0/PjCjgN7ZhdkptVTlVLp98qz89LtlHUkqAG7wwAWqO+TnwgK 6wdw== X-Gm-Message-State: AOJu0Yzo5MGSvZZ87XDYcHOoB899BuBGZvsMlO9zIFGO5YmFufCZH+yK t84eNZ2tKwBtflpfT+gWiJbbPQ== X-Google-Smtp-Source: AGHT+IE6mZg6R/C4hkqYLeG6aoFn5MZe1GYXgvIXJGbCBTW0CHE8uReLaaEVve/T8KY77idOwBUD4A== X-Received: by 2002:a05:6808:448d:b0:3a7:56a6:bd2b with SMTP id eq13-20020a056808448d00b003a756a6bd2bmr15345498oib.4.1692848840631; Wed, 23 Aug 2023 20:47:20 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:20 -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 , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH v5 24/45] dm zoned: dynamically allocate the dm-zoned-meta shrinker Date: Thu, 24 Aug 2023 11:42:43 +0800 Message-Id: <20230824034304.37411-25-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 X-Rspamd-Queue-Id: 773DF140006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7x44bxcd441rg535dqqy9inar6x6mqbw X-HE-Tag: 1692848841-517499 X-HE-Meta: U2FsdGVkX1+sZ2d4mS6qYlA7Izc1dAZyo5iV0Jy5S6i/ebdBElzOLPlOMKDrWkj2vK6rJ1EPRzNwCrD94Bpsu4SHEQ4LSyGeimbx2oViUuZ8tDPBNNP4so4UmGLdLgzn73gEeAx589qNo+cXSpEi4VqLYZJXY2HixcTbfqdNXmE0GUodxD5kASPt5x62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4sWPkFfpLObH4Vie/I8Oge3UXrbxLN9V9n6jZ35mpVGE6V77yXoEe+G7iunpYJqH5MrGt+RBqzrUOP2JzvJMT8VjkOyBkCdaSfUMU97e78TmBKxAv+7qb2XYly4vhnntejXcJjDSXqVHtjxjLPiTEWpT0RRYWmrr0mcSbLYl6iYNSDAG0X9ar4BcOl9We5RHi5fakaQfxAvcGz2H8fNZRUWkNJCikUir312F+mQoA== 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 dm-zoned-meta 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 dmz_metadata. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alasdair Kergon CC: Mike Snitzer CC: dm-devel@redhat.com --- drivers/md/dm-zoned-metadata.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 9d3cca8e3dc9..bbb0e69a7908 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -187,7 +187,7 @@ struct dmz_metadata { struct rb_root mblk_rbtree; struct list_head mblk_lru_list; struct list_head mblk_dirty_list; - struct shrinker mblk_shrinker; + struct shrinker *mblk_shrinker; /* Zone allocation management */ struct mutex map_lock; @@ -615,7 +615,7 @@ static unsigned long dmz_shrink_mblock_cache(struct dmz_metadata *zmd, static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; return atomic_read(&zmd->nr_mblks); } @@ -626,7 +626,7 @@ static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, static unsigned long dmz_mblock_shrinker_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; unsigned long count; spin_lock(&zmd->mblk_lock); @@ -2936,19 +2936,24 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ zmd->min_nr_mblks = 2 + zmd->nr_map_blocks + zmd->zone_nr_bitmap_blocks * 16; zmd->max_nr_mblks = zmd->min_nr_mblks + 512; - zmd->mblk_shrinker.count_objects = dmz_mblock_shrinker_count; - zmd->mblk_shrinker.scan_objects = dmz_mblock_shrinker_scan; - zmd->mblk_shrinker.seeks = DEFAULT_SEEKS; /* Metadata cache shrinker */ - ret = register_shrinker(&zmd->mblk_shrinker, "dm-zoned-meta:(%u:%u)", - MAJOR(dev->bdev->bd_dev), - MINOR(dev->bdev->bd_dev)); - if (ret) { - dmz_zmd_err(zmd, "Register metadata cache shrinker failed"); + zmd->mblk_shrinker = shrinker_alloc(0, "dm-zoned-meta:(%u:%u)", + MAJOR(dev->bdev->bd_dev), + MINOR(dev->bdev->bd_dev)); + if (!zmd->mblk_shrinker) { + ret = -ENOMEM; + dmz_zmd_err(zmd, "Allocate metadata cache shrinker failed"); goto err; } + zmd->mblk_shrinker->count_objects = dmz_mblock_shrinker_count; + zmd->mblk_shrinker->scan_objects = dmz_mblock_shrinker_scan; + zmd->mblk_shrinker->seeks = DEFAULT_SEEKS; + zmd->mblk_shrinker->private_data = zmd; + + shrinker_register(zmd->mblk_shrinker); + dmz_zmd_info(zmd, "DM-Zoned metadata version %d", zmd->sb_version); for (i = 0; i < zmd->nr_devs; i++) dmz_print_dev(zmd, i); @@ -2995,7 +3000,7 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ void dmz_dtr_metadata(struct dmz_metadata *zmd) { - unregister_shrinker(&zmd->mblk_shrinker); + shrinker_free(zmd->mblk_shrinker); dmz_cleanup_metadata(zmd); kfree(zmd); }