From patchwork Thu Aug 24 03:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363456 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 7D462C71145 for ; Thu, 24 Aug 2023 03:47:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22AEC28009C; Wed, 23 Aug 2023 23:47:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B4938E0011; Wed, 23 Aug 2023 23:47:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02FBC28009C; Wed, 23 Aug 2023 23:47:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E19DB8E0011 for ; Wed, 23 Aug 2023 23:47:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BF151160143 for ; Thu, 24 Aug 2023 03:47:14 +0000 (UTC) X-FDA: 81157612788.06.BA1F7B6 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 01C81120017 for ; Thu, 24 Aug 2023 03:47:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=l3iIlNkE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848833; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=nzqPXZUzHtAKFX48cqH8HxdHr65DlphUZVtux1vY61nXKAnnTk6CYDdruXFzNeZqRZW9Fd SNSWTILR3ZiGyKnWJMlOl7AbaInR6SB7mcc87qXukFPf5efraLr6kzdgkpCOZnlM6w7oXt bAwxRJHB9UJXKZ8c6baGFJ+KhO9ORr4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=l3iIlNkE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848833; a=rsa-sha256; cv=none; b=2XO+/uevDvM+rghDXDo4R1P5kcJfMKe5cXyh3+b0tTQ6X9lmaz87SDvBXcN8VZAPENty7h /NUdjw0uq5nxQfK1f/1SjMDGBIo8fAZeSJ66qp/6IdfJsO0jCEjEwzADJo2MlgBMcmjKYv kmyRwzPrjdXDTia+k3hep/Uto+cEFMQ= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062586b3a.1 for ; Wed, 23 Aug 2023 20:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848831; x=1693453631; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=l3iIlNkEM9G3Cc/znNYH0hjfEGMFScoGFsPDxRlIYD6Nl4f8r8Y4ffur08X22M57wD rIlSmJrfx+3UpxggfbKcjCE4Dvgc5I/LQBD+OIaafLzWd7xdzc3eeSUn3jYMqVJn93em 0W1GznsolsuflbV+uszoAiXaDHnfJ+tiKXIpWvpYd/Ij4f6UXGCJcJb4Hscr3UTl0p3b LW0D56skk4nR8+fdc5jfeMFs4SDrmcbSIrL0BJ5k/5kJZyOenUt/nJGwsdGpkJqafAVm Vnc6/t5P1QbupbAmEIByI7s5m2r7bE1g7Fg9vHnXnyXTIzG01/FAXBjLAVWjh1RgylMp uG3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848831; x=1693453631; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=If6Ps8fmYvKmQeBEQVAnkt7Twm61shE3A5iLt4KvmUwUqMcyaZzjO9UyQ0wfIIz7Ep oPQ4VK8w5TECaUcRRkLpQy78+oWats5aNSamOaDTfrpB6yBFENJ08W/0qsmXmyEW59Ya OHU7q2k1O7/vK98/Xiqx+/nHMnGOAXm1I7PEFnjpUa5KMfcG9lgjbuLV3wJLCZVZbKbx ihnWchNFKxdkDjWAXaq1VcKoa5aGQchEsU6ot7/1fwOH17QY1SvQJIDKjbfw9+CB+9Lp zS0Jk8fqzoQJf6wrBRxo+F4HSPNONFS4fFMzmYjeEPePfYNhS4FW/QfQKlHF+G91vYAa ZEUQ== X-Gm-Message-State: AOJu0Yy+k6iAYhRPVzucv4wfXVozkedYmWoD4tQ4+ogInvZLscZzdwjN jSqKLkflRbrhNJ+Ym61z24+8dA== X-Google-Smtp-Source: AGHT+IFa4D13lTfF9qI4lzhNEmw+/ylikA2tFRh1ZHmSW0TIoxErglnaTpv3xvyiYGMU4coQffhatQ== X-Received: by 2002:a05:6a00:3107:b0:68a:4bf9:3b21 with SMTP id bi7-20020a056a00310700b0068a4bf93b21mr11172345pfb.0.1692848831711; Wed, 23 Aug 2023 20:47:11 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:11 -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 23/45] dm: dynamically allocate the dm-bufio shrinker Date: Thu, 24 Aug 2023 11:42:42 +0800 Message-Id: <20230824034304.37411-24-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 01C81120017 X-Stat-Signature: ut5rszpoj1jxt7567a8gmbaetjchu4ww X-HE-Tag: 1692848832-499594 X-HE-Meta: U2FsdGVkX19YdnBGLr4ApegRvkTeGiM7zV37QXq5D9PWPyzkaSzSOn4Qp5g4Gq6DlBZXqgqSLi/cMCvV0xCe9+ay1Ebste3mL6AwRyoJPWVhmMDQ4+M1p/xog9YNi84tVlv7eMVtTRnFW/tBl29jzauX/TjAo3pkf16FgV6lP/twTVRaup2TA25AlT2RNJ3rUAL97ln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GB3IU26y9p0lHs4SndFqvUUMf4r5I1qvkXlT1OaqXzWr7yXEQAyiXFFP82TP4qO+1fjMSBcDdfb+Peef911HaoFqfnwt5RdTXOxnv07lJHdnDEJwPMQnKAaarmmOP54CiGa/MfDVoxx85LvKu3acxwYBfF0uSqIbx56LzvvglxDKb3TorzlAwVccofH3YNDUwHKgn9XitRGBnyBZ51ElPTeXdl0tkOZe8C9DoXfcA== 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-bufio 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 dm_bufio_client. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alasdair Kergon CC: Mike Snitzer CC: dm-devel@redhat.com --- drivers/md/dm-bufio.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index bc309e41d074..62eb27639c9b 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -963,7 +963,7 @@ struct dm_bufio_client { sector_t start; - struct shrinker shrinker; + struct shrinker *shrinker; struct work_struct shrink_work; atomic_long_t need_shrink; @@ -2368,7 +2368,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink { struct dm_bufio_client *c; - c = container_of(shrink, struct dm_bufio_client, shrinker); + c = shrink->private_data; atomic_long_add(sc->nr_to_scan, &c->need_shrink); queue_work(dm_bufio_wq, &c->shrink_work); @@ -2377,7 +2377,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); + struct dm_bufio_client *c = shrink->private_data; unsigned long count = cache_total(&c->cache); unsigned long retain_target = get_retain_buffers(c); unsigned long queued_for_cleanup = atomic_long_read(&c->need_shrink); @@ -2490,14 +2490,20 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign INIT_WORK(&c->shrink_work, shrink_work); atomic_long_set(&c->need_shrink, 0); - c->shrinker.count_objects = dm_bufio_shrink_count; - c->shrinker.scan_objects = dm_bufio_shrink_scan; - c->shrinker.seeks = 1; - c->shrinker.batch = 0; - r = register_shrinker(&c->shrinker, "dm-bufio:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (r) + c->shrinker = shrinker_alloc(0, "dm-bufio:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); + if (!c->shrinker) { + r = -ENOMEM; goto bad; + } + + c->shrinker->count_objects = dm_bufio_shrink_count; + c->shrinker->scan_objects = dm_bufio_shrink_scan; + c->shrinker->seeks = 1; + c->shrinker->batch = 0; + c->shrinker->private_data = c; + + shrinker_register(c->shrinker); mutex_lock(&dm_bufio_clients_lock); dm_bufio_client_count++; @@ -2537,7 +2543,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c) drop_buffers(c); - unregister_shrinker(&c->shrinker); + shrinker_free(c->shrinker); flush_work(&c->shrink_work); mutex_lock(&dm_bufio_clients_lock);