From nobody Wed Nov 27 21:42:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445889; cv=none; d=zohomail.com; s=zohoarc; b=OGmw/Zd6NVGk8Iy1M4R0sH+O1AEopmH2u+5AlvTdIfpgxol19JrORV28F2CWHuJjCWEXxZ3ddv2KXY8l01GGuRUUWudh/tNOB4q24p+d74dTQbigqp02bvcNvasrjLmzRNknWUaHBNuGBT6vb/rxR1+nU9tVyCZJta3tZu2A8aY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445889; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=Plp96AkBxB/z0WT1DsrDsPYaRZGFDCjHnkZCYXEywysp5DB3jyu846ZsI5kp0YVEhUKnLRNCtR+t36KwCG4qyzmaTBhWgQ7faD/PHhPT97/GGA2OOmIPJsxOjDnU+7bBqsIJRWlw5hNcttaeBCgYOAFp6y3xpAenSJb585cTEpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445889455607.2993336889698; Thu, 27 Jul 2023 01:18:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570902.893436 (Exim 4.92) (envelope-from ) id 1qOwBm-00025P-34; Thu, 27 Jul 2023 08:17:38 +0000 Received: by outflank-mailman (output) from mailman id 570902.893436; Thu, 27 Jul 2023 08:17:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOwBl-00023g-3F; Thu, 27 Jul 2023 08:17:37 +0000 Received: by outflank-mailman (input) for mailman id 570902; Thu, 27 Jul 2023 08:17:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw5f-0001DS-KL for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:11:19 +0000 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [2607:f8b0:4864:20::436]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 29ec020c-2c55-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 10:11:19 +0200 (CEST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686f74a8992so78040b3a.1 for ; Thu, 27 Jul 2023 01:11:19 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:11:17 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 29ec020c-2c55-11ee-b247-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445477; x=1691050277; 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=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=XMYYvlyXrTmu7TBUMUrS0fAERGM3ULbRWCn4in2BRNinhRwId1ryL35VoKr2h4Rx+U HjLlRWIKGbBKN0lkokdfiXe7DL4/cW8JhUixM/OhO46u6zDYby/ZSHvD4zMfuAy6v0wa kMUIVYEZOCmoajTRWB9O5pPKf2KXDL1RA9QX/iWGDKdd+7AiEQpaXll5+7XF5hXMtboW QGfdfOEZoiLr6B07ra4S8ESol/cU0lfuHqis0vxsY6ajpZNCyt33YYUETwhkXmLJyVVM wWI0H3b2jkyty5FrIH3eGt0u2K+zpCq6JQc2FhUeW7es/kOOMNTlHxQiuG1Uqt5RUvfA 07oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445477; x=1691050277; 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=/uDURfJnJhgp6SdQN0dR835bsVpn4QFEXgmrOE/fnW4=; b=F/IPUh+LYugWmlMW9u+M8jnegfgyxuv8903p141VoeIGN1F2ke5xmha8DLk9Pgpbud 69bWMEyE0H2RyT78EsLT28bMfhOAFBnlLTrHTk6/BPseUNhQPFJsB7qnXpaAAZ/P09iJ O4lcTEvrbknmcLj1/HwbwkiIKLbIbP+dqp9x52mocmdjyU8qFMy2vOdu9aXQgHSp9Sui cKYsKLWu1WJC4TWRK/nhqFemfN0OGoFnetfzq52fPTfXv/kqZEcfBN5UFeeRhTlolXgj 4zClKPmeYUYHqy7FkWWUlT23oaC8ejV2ANevHjUIM1N2wumsEtMI4rt9btXfctAs5LSv EBPg== X-Gm-Message-State: ABy/qLY6/8YD4uqHjQymnJoiq8oLlNIhpM+5m5mUInuvWN4cEHNR481a A0OIInZHZ/1vwngzDmwLmB6bVg== X-Google-Smtp-Source: APBJJlG87NINI+/+i4SJ1KgSTM1EJ+JwVd/Dy5o7cICQ6coQ1cuBExOC2izM/xbO/Jy48XOYsOKRHA== X-Received: by 2002:a05:6a00:2b90:b0:67d:308b:97ef with SMTP id dv16-20020a056a002b9000b0067d308b97efmr4590349pfb.2.1690445477689; Thu, 27 Jul 2023 01:11:17 -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, 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 v3 27/49] dm: dynamically allocate the dm-bufio shrinker Date: Thu, 27 Jul 2023 16:04:40 +0800 Message-Id: <20230727080502.77895-28-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445891562100001 Content-Type: text/plain; charset="utf-8" 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 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index bc309e41d074..5a9124b83d53 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -963,7 +963,7 @@ struct dm_bufio_client { =20 sector_t start; =20 - struct shrinker shrinker; + struct shrinker *shrinker; struct work_struct shrink_work; atomic_long_t need_shrink; =20 @@ -2368,7 +2368,7 @@ static unsigned long dm_bufio_shrink_scan(struct shri= nker *shrink, struct shrink { struct dm_bufio_client *c; =20 - c =3D container_of(shrink, struct dm_bufio_client, shrinker); + c =3D shrink->private_data; atomic_long_add(sc->nr_to_scan, &c->need_shrink); queue_work(dm_bufio_wq, &c->shrink_work); =20 @@ -2377,7 +2377,7 @@ static unsigned long dm_bufio_shrink_scan(struct shri= nker *shrink, struct shrink =20 static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct= shrink_control *sc) { - struct dm_bufio_client *c =3D container_of(shrink, struct dm_bufio_client= , shrinker); + struct dm_bufio_client *c =3D shrink->private_data; unsigned long count =3D cache_total(&c->cache); unsigned long retain_target =3D get_retain_buffers(c); unsigned long queued_for_cleanup =3D atomic_long_read(&c->need_shrink); @@ -2490,15 +2490,19 @@ struct dm_bufio_client *dm_bufio_client_create(stru= ct block_device *bdev, unsign INIT_WORK(&c->shrink_work, shrink_work); atomic_long_set(&c->need_shrink, 0); =20 - c->shrinker.count_objects =3D dm_bufio_shrink_count; - c->shrinker.scan_objects =3D dm_bufio_shrink_scan; - c->shrinker.seeks =3D 1; - c->shrinker.batch =3D 0; - r =3D register_shrinker(&c->shrinker, "dm-bufio:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (r) + c->shrinker =3D shrinker_alloc(0, "dm-bufio:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); + if (!c->shrinker) goto bad; =20 + c->shrinker->count_objects =3D dm_bufio_shrink_count; + c->shrinker->scan_objects =3D dm_bufio_shrink_scan; + c->shrinker->seeks =3D 1; + c->shrinker->batch =3D 0; + c->shrinker->private_data =3D c; + + shrinker_register(c->shrinker); + mutex_lock(&dm_bufio_clients_lock); dm_bufio_client_count++; list_add(&c->client_list, &dm_bufio_all_clients); @@ -2537,7 +2541,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *= c) =20 drop_buffers(c); =20 - unregister_shrinker(&c->shrinker); + shrinker_free(c->shrinker); flush_work(&c->shrink_work); =20 mutex_lock(&dm_bufio_clients_lock); --=20 2.30.2