From nobody Wed Nov 27 21:38:36 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=1690445913; cv=none; d=zohomail.com; s=zohoarc; b=QD0HWxdHP/I0jO0T6/hEcvHULYV6k4o4ypLUXC4hDZPHRfdl2o+wRd09gDHw11Lrrzo8lHIO5dT1bl6AgjeG9SaZAmupsaeeVHa0Y/62/mAifBpo0Z10lAZx1HGLxzYax9ft0dWXxK5QfZ5kcik5zCJ7GDGMAYKvd3CfTRVEobI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445913; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=U+pAaEB2A0aKeZ4H7ea0akybM/MTPKDLq7rFK0p+tP8KydOHyq27PpH4sbadK1CgmU97GJmv/oDcg+TdemyCkGa4RPfS0Nk5gk1kjtks49gfA1IAGZqizn4JROQ+wjwp6qbu5kk1VWFdQBIioIBYH7kR2swu9rlQgt3TdVU/MAM= 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 1690445913523407.52846623003825; Thu, 27 Jul 2023 01:18:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570882.893313 (Exim 4.92) (envelope-from ) id 1qOwBY-00077v-Sy; Thu, 27 Jul 2023 08:17:24 +0000 Received: by outflank-mailman (output) from mailman id 570882.893313; Thu, 27 Jul 2023 08:17:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOwBY-000770-PC; Thu, 27 Jul 2023 08:17:24 +0000 Received: by outflank-mailman (input) for mailman id 570882; Thu, 27 Jul 2023 08:17:23 +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 1qOw6d-0001DS-QO for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:12:19 +0000 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [2607:f8b0:4864:20::432]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4dcc8253-2c55-11ee-b247-6b7b168915f2; Thu, 27 Jul 2023 10:12:19 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-682eef7d752so204692b3a.0 for ; Thu, 27 Jul 2023 01:12: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.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:12: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: 4dcc8253-2c55-11ee-b247-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445538; x=1691050338; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=P3BNYmrnn+aNeQX6tJNAWjBR47qoFVwe6V1hXSSWwFyS61HuOjfx1CldC/bVPLDS4b tBSPVcIpokpC1gG54dPeypV2gv1H1PsrEki/AFkEglXm+WyAmzSAHFAjlypTbwzHUkTv XwwWUlwnKhA8sSKQw+cOvBa/dT3CBu+sYvYNSpbwNT6pp20knmU+insJC0lJR8d7KNA/ XFw3RfaoZY9/IU0U207vkdiCmyduxENHuADRmTAqpUtqVvF1N7pwLKXyEsFC4IstCLHw nMtpKLIm0n/1aYuhmB1FsTVe4JczwGUa2wEUGkSK8KQu0Fafs8lJ3mpNN+7ETdaWOSMf 16qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445538; x=1691050338; 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=nhs5C6wYTK112tB0Y3rKeCsMBEmGx3fQoCnqZ3HCCLA=; b=lWYg4m5M1/yVa45hyldKI6h7ePuCbU6nDbI/Bw/WF75WmyVFWieuT1Csku2dVpj0FB YtJpZO9t7/J5/w09xJ5HuVBx4VfIFQhYYbr3B2UCg14UXJ0b4vIJ5Ps5B57Bo7xqgkS2 iXde+DYz3lqWkyrqxBzgkD39PNC4DOhCFDlDGX7vSb95aSZz4dGnxe9t/i82K3ugxo8S VrJ5aDn3lA4rSHAaco+4y8uX32kttjjYfvDIrqkQy1ZCC8TA3gJxUx2x4zM+BcRuOjtc 1rUkbpo9d0RSQmJgZS8c5UKbKdswgpSgqii3OdhSllS3Glg3CMpI91EZgWpKG2YbTCAv JtZg== X-Gm-Message-State: ABy/qLb8iurP0mJldCPcu2GVZbForD2uWoAKrTpdzOStgvWE79kTjDNi 63Wa5wp5G96h+jkrPpI9mzvYsw== X-Google-Smtp-Source: APBJJlELYJ+VP3jkb44itFX28rq7UhufR3zr/NDN3xCao+bv4nVfpqzapahZiZsalg40ZmAEO1GP5Q== X-Received: by 2002:a05:6a00:13a3:b0:676:2a5c:7bc5 with SMTP id t35-20020a056a0013a300b006762a5c7bc5mr5236670pfg.1.1690445537850; Thu, 27 Jul 2023 01:12: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 32/49] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Thu, 27 Jul 2023 16:04:45 +0800 Message-Id: <20230727080502.77895-33-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: 1690445915621100001 Content-Type: text/plain; charset="utf-8" In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the virtio-balloon 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 virtio_balloon. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/virtio/virtio_balloon.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 5b15936a5214..82e6087073a9 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -111,7 +111,7 @@ struct virtio_balloon { struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR]; =20 /* Shrinker to return free pages - VIRTIO_BALLOON_F_FREE_PAGE_HINT */ - struct shrinker shrinker; + struct shrinker *shrinker; =20 /* OOM notifier to deflate on OOM - VIRTIO_BALLOON_F_DEFLATE_ON_OOM */ struct notifier_block oom_nb; @@ -816,8 +816,7 @@ static unsigned long shrink_free_pages(struct virtio_ba= lloon *vb, static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinke= r, struct shrink_control *sc) { - struct virtio_balloon *vb =3D container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb =3D shrinker->private_data; =20 return shrink_free_pages(vb, sc->nr_to_scan); } @@ -825,8 +824,7 @@ static unsigned long virtio_balloon_shrinker_scan(struc= t shrinker *shrinker, static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrink= er, struct shrink_control *sc) { - struct virtio_balloon *vb =3D container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb =3D shrinker->private_data; =20 return vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; } @@ -847,16 +845,23 @@ static int virtio_balloon_oom_notify(struct notifier_= block *nb, =20 static void virtio_balloon_unregister_shrinker(struct virtio_balloon *vb) { - unregister_shrinker(&vb->shrinker); + shrinker_free(vb->shrinker); } =20 static int virtio_balloon_register_shrinker(struct virtio_balloon *vb) { - vb->shrinker.scan_objects =3D virtio_balloon_shrinker_scan; - vb->shrinker.count_objects =3D virtio_balloon_shrinker_count; - vb->shrinker.seeks =3D DEFAULT_SEEKS; + vb->shrinker =3D shrinker_alloc(0, "virtio-balloon"); + if (!vb->shrinker) + return -ENOMEM; =20 - return register_shrinker(&vb->shrinker, "virtio-balloon"); + vb->shrinker->scan_objects =3D virtio_balloon_shrinker_scan; + vb->shrinker->count_objects =3D virtio_balloon_shrinker_count; + vb->shrinker->seeks =3D DEFAULT_SEEKS; + vb->shrinker->private_data =3D vb; + + shrinker_register(vb->shrinker); + + return 0; } =20 static int virtballoon_probe(struct virtio_device *vdev) --=20 2.30.2