Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2867303rwb; Mon, 7 Aug 2023 05:01:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiJQ57vkVsjwg2dn3j8z7+5/cDB6BZHanz/u+iylyZfbRfTRWmucGTKbeo9eX4lACQGSHh X-Received: by 2002:a17:90b:4f82:b0:263:1720:f802 with SMTP id qe2-20020a17090b4f8200b002631720f802mr6875555pjb.30.1691409710812; Mon, 07 Aug 2023 05:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691409710; cv=none; d=google.com; s=arc-20160816; b=HWJ9kXxX1DkzZwfJtqY6+Vg+LdSb1Ee/iYQ505uGK/2owA+RcM+MR1IqhEXfzcMnCK VyED2JopvKJ1nvDKUWKLg7fjvzNDAMMNdVe7CJmO8aw9Zn6BD8LEZzJSy7K8MzEdLIMf rRosgr9WOp5PH1pQA8ZLh6Eih60ubR/6aSFmG8lQPZJ0sLbZBS2rlF6DF6k9oXvOGbxE BQr9ZBD2QvHQ8m7fo4uuOX/6WveBq5+LOL6bkaySRRtcz75tyxZq16lhVi2ApX6ttvwS YQGvSwtVQamXZ0X91dehjq/bF5TgCdjRynTQGcTFawE1tSGLRjMzh8YLQHkGMzUiQ1wp 6eDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8Rfav5Nxe+GtybemfHCRLQWJ1Wm1Jr8phC3oTaQ6f/s=; fh=JwrRg0ndXrpURY0vwDVMB2JxbP/kKK+/sa4yghEeBpo=; b=rkPArEUt/N2wfzQuF8WKQhfhq+CxzJn75E3yt1SGOr0plNIfFBGnYDcUI2q/m7XTQ3 TKRhGVuX4Unixsk8cJ87OwwfO2vVe2S4yNy3cluri3CI1SvJprcqcAOn1urd7DldsHeS gqecARN0c1CjbCF+Sx/OII1AWN1SsjlSM59rd6B07kBI4cVPk/yCd4oO0aoyTF/Vmw5b N4zAkxu+2W06uNsKEneS7lZjtvBlVbsVCX8XqRyG5vOV3JJeR99n+zTqlDA+qNtVOXuC Ky2N4OzZVYU71ni6KPVeAGVrOC//MVTuLaAYtoFUZ6JJ/uck6qZT+JGm05zB2vz1ucKK 8GXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=RhTNRytl; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a17090a940900b00262ff3a4545si8855586pjo.169.2023.08.07.05.01.30; Mon, 07 Aug 2023 05:01:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=RhTNRytl; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjHGLSv (ORCPT + 99 others); Mon, 7 Aug 2023 07:18:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232424AbjHGLSL (ORCPT ); Mon, 7 Aug 2023 07:18:11 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFC0F359F for ; Mon, 7 Aug 2023 04:16:40 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-77dcff76e35so48628739f.1 for ; Mon, 07 Aug 2023 04:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691406930; x=1692011730; 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=8Rfav5Nxe+GtybemfHCRLQWJ1Wm1Jr8phC3oTaQ6f/s=; b=RhTNRytlTa20t4Y4eQDAbFdSU2B3iJZ1UGQvbDrNgMxM2lZyl06oD16eY7UnwOu7/z lhfBO1aEb+iaxXm7zjPBY7hPV/HGsazWxYGeChIQ5BZqNHrYc42N83Qpez7ydwipu9EJ dl8ebrZJyA2dXTCWIRLJ5KrUEadehbntFp8yZr0t1mcATZxSPZjFq4Ii0bOe708GiDDw sbmlI1kieYrCzo2Qbsl1zLM+PYAlt09SHmpbPtNn98Tc607U0WsJTYx77KWhrtfG5gTM J9JKFlnKyLN5gCahSDRWLwC9lXHkDS1fNn6g8aIOpZaiEnR0eJG9fj8gxoamq0eWdy8p EjpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691406930; x=1692011730; 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=8Rfav5Nxe+GtybemfHCRLQWJ1Wm1Jr8phC3oTaQ6f/s=; b=Kzw1x0js9U6YOIx95Pio0OA4JHq6/bM88HSu/nUrpzrBubH9VfOxWLr++v4FUobiwN t8yk+AksFt/qVg+slXv7J4DBY/aN0oj3ZWrd08xun/gEiqIRmnuLeuIgffBjFYsTtik6 SU5HKJVJuiP0S3W0ZlezZ8TNH+B8oRcmIlivixFKaqCTvSlewUybBUBRba/5ARaiYnV/ n/6Wnjgu5jO/6k5B0q/DfXDHvV4DJrgRkoWMjhRWAuebWEaetDI5gQOmEcK54VE4Gv/C ug4Q1yz0shbfhjt4ML/dE/tkO5f0zAjhjvw3vC+Cb46Kue4WUoPzPLIxtNdIdG/41cWk CXcg== X-Gm-Message-State: AOJu0YyESgqGZrwqdLLgPpo66L1AjwFy9IFGrcRz+pTavijYGex/1AQW sU96Nllwhh6ZBrpEIYRmTq1H0g== X-Received: by 2002:a92:6408:0:b0:349:5c87:e712 with SMTP id y8-20020a926408000000b003495c87e712mr5356429ilb.1.1691406930655; Mon, 07 Aug 2023 04:15:30 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:15:30 -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 26/48] dm: dynamically allocate the dm-bufio shrinker Date: Mon, 7 Aug 2023 19:09:14 +0800 Message-Id: <20230807110936.21819-27-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the dm-bufio 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 dm_bufio_client. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- 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); -- 2.30.2