From patchwork Mon Sep 11 09:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379077 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 04B91EE7FF4 for ; Mon, 11 Sep 2023 09:48:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 800FB6B0206; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B11E6B0207; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 679226B0208; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 556366B0206 for ; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2F25312094C for ; Mon, 11 Sep 2023 09:48:41 +0000 (UTC) X-FDA: 81223842042.19.B639571 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf11.hostedemail.com (Postfix) with ESMTP id 5AF5740006 for ; Mon, 11 Sep 2023 09:48:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=klADAg1b; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425719; 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=PStI7luzVZJh/mYN7JpVoeKJU5ij79ho49wnrhFm4xVshN/izVEP+5ksVsaFwNSmxxCsw0 i4RArjdeDacj9QlzswbwGtggOo8SFxVKblAgpilgT8yUXa4JpAgI5RcSAHte+yZlITwLeW 0ueSH9FXao1y82sUxxpDoMqdBVPB63g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425719; a=rsa-sha256; cv=none; b=F5u+kWueYcxpQfHHDpbyzuvpZUDMlUOTNeMEKZDAfXG8Zju2ZX7UAYLgsxuI7g61VHBEYS uvz+IdcMws5mKICTBAZHekx9GzLPKBXpbY2eGw+YUZKeN2SivJ5h2d2unMHI0HrybyR4Jz NuF+r/gtnOp+HDCB5CHOFgK8tWJEMYs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=klADAg1b; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1bf7b5e1f06so7710625ad.0 for ; Mon, 11 Sep 2023 02:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425718; x=1695030518; darn=kvack.org; 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=klADAg1b+/aA5Bg3a5mBt0rPKlJv68cq6MLEl5wSWeJgnvPpxZKO8c9FIOS2DfRESB EmV+dAlDGn4qsri6x/tXQK6KD+IkNuhXbG7DHhwM1A8thBztcpe/2wSaztw3sBuL7AnV UXLi/T4NiWhiEm8TX47DlJirToSzzDedK29NXEknzasn0F7uilenjUgIy6H3y5Zu/sbB hOtiI3p3Ljq1VUGyn3rhi6mEwRn3blTNTvP89qPByvG/XziQjpl3udl6gqqp6aOI+sZU vLNLwC+FJEgigOl59Ku1+/LE+HyN1S2ThOkkPrxF2u8Yqup7b1TXIOHYOw8FgNbi/P/4 wYmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425718; x=1695030518; 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=i8jewwm0gLmcEXLn4dfXGcp1eF5vSMlpa8eh7PB/fAhfnbFHIruUtSbYbM5gj8BvIc 5dHgWVNYOc0U+PG9bmuPA3BOaMdHLKLO+kpzfSmLQwY7Lo9F4OPDEOeS4U2gbXNpx5qw SY4hbwRhfSON7IgPylIA3BWiOGe9cPFixUup4hPMzBIfZSXWrY99wHgVSzTlHab1z3LV +w/LK5FYr6qYd/hHXws7Z2rojdtwB2o0IUT5TdgvnDKvWJ3fovlwMbUcF7SFl1LQmIoQ 3cqgYNo7NUyRy6vWV9dCDBsCLGaCi0fPue16HtNWybkVyNcvacAVXkkVgxtMVPUiZVRz b+xA== X-Gm-Message-State: AOJu0YzXpVG3tNAFBoj24o6LeRsv9dhcw51ZgCsZyFf+pDTZrJrxr2go 2yO4ZqHqMtVqeZFO9KLGE/i3Jg== X-Google-Smtp-Source: AGHT+IEof/1ztyaPWaM/x9VlgcIownTF4cXEcNkOuH5WUE9F6/4W1qtB9/ubZOdVJeDf39167O8pew== X-Received: by 2002:a17:902:d48d:b0:1c2:c60:8387 with SMTP id c13-20020a170902d48d00b001c20c608387mr11160274plg.0.1694425718378; Mon, 11 Sep 2023 02:48:38 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:38 -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 v6 23/45] dm: dynamically allocate the dm-bufio shrinker Date: Mon, 11 Sep 2023 17:44:22 +0800 Message-Id: <20230911094444.68966-24-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5AF5740006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: uegpkh34jq7az7hnzf3mqs19z63xnq57 X-HE-Tag: 1694425719-932164 X-HE-Meta: U2FsdGVkX1/Zx1AZbofgQA/sV8XLpGKMwvuuf9xvU3jHRgJ/U5VjQHphy6ft4VFVwnTg8V2Uy9xpS3o8meH+L+e5ObH/nFREd4ac1HaO4tU71tjxfPe1B4sPvx5CUgnoVW1sWQ+w+0teMXa9FbGJWdVwjIzG4HojNU3jRB7fOxsTWoGvven70z9DSFYVueWfpAEx/0nNKWfF3s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ZWUI777JkE1hd/JsaNZ2cBmfUktk629ZacUv5ykFaj+ky4/G9GJX4jORTjzr2+mbEmm2rVAKGeutHYgZrC1Gh3MwRRlziXSqhrbTSgYyzwS7GWE0h6eMoX7QpokfJGmdhYFNHQCcYomACWt2wIwY/tWjpSYwpAxn7kykC2t7lm5j2lrhg6sv7clMvcv9NMDSkUIl+djQ== 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);