From patchwork Mon Sep 11 09:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379104 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 7997BEE57DF for ; Mon, 11 Sep 2023 09:49:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20DB76B0213; Mon, 11 Sep 2023 05:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BDAB6B0246; Mon, 11 Sep 2023 05:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AD286B0248; Mon, 11 Sep 2023 05:49:29 -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 F11FE6B0213 for ; Mon, 11 Sep 2023 05:49:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CA5A4C02D9 for ; Mon, 11 Sep 2023 09:49:28 +0000 (UTC) X-FDA: 81223844016.17.1936A0F Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf01.hostedemail.com (Postfix) with ESMTP id EEBFD40009 for ; Mon, 11 Sep 2023 09:49:26 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GDdBf59D; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 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=1694425767; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=Vpi+wOnkmZWoLvldaarDjaC9Dv0jDj0ZKJJ0BNLsF0hTYKcN5x1fjmwdCE1FWHicgvjfdZ vdyenX2yR1oz1ENh89kfLNo4WYN0UuruV9yLNR8RPDRi0iWEhx4kaI5/cTPU/ZSltcsqjX icYk9RjfiSDlRotV/ZZOT03dnP8USyM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GDdBf59D; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425767; a=rsa-sha256; cv=none; b=AZUNwbaMzzVFUt/EkL380sqG3YzM2QNH2ku+Y/nOCIQ2oLHs9nyE0E7Oi152qIhh2XudXz HpoC++cV65NjU878fr/phUVMmMdrYryBv35UVzXIgeMSrOrLlWwy7pBZ4qYDrfiSACgJYM wi2HJNCCDbel+DQYjo18vAwlGWNV3qQ= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1c3c4eafe95so468395ad.1 for ; Mon, 11 Sep 2023 02:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425766; x=1695030566; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=GDdBf59DOGmk2Gtzgj23iH2o3ql82lXlogFzSTVczOXZQJcXW5ElCsqfh9f/n8sYop eS0HKAuJrrbjq67xWsfVN2DyT8UcLnQLn7zB782xgb4ZXGwFnTJf3ZTHa0uNpfLt7kwP hHA0fLs+NtHVRWwThXsHSM3mZ4tAJ6dHUPRrp0QYGyBBKtY6IENtGNOgb7qbUW731gme yLMbeYYQGwNHTNMLMSlAzfp4PbnLE8PcOog5PgkvyZp+2N29Zyn6aciUPx0Dte4g1Mra 4RQjlY0NkJ0qJLHsQyFnij0Po8jRp00HJnaWQJ8czAWps3+bMcPLNIVosUWWKvy2sj0z Jk5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425766; x=1695030566; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=W7mMm0pgPk/jqpHSQwVGOX1VNRf3vs7W24dzdxHQKzRxSalR1Z1O+Yx5HkDuH4j5U4 nesn/ldmJZphfcBkSpmIXdp7sBzpBcOxjBgf3yHZGSxl9nsFm3Igl8pVlv0793lhK3hP PEPO3SdLqQohxj78BaC7l6bmz/04k0BtREmzUgbO1L07dc+leRpMZwA6YDDI6HqT4kSz 8WXHVpJ9YnLscnLyVdL0RpjJrZzwnRzX6Z85KwQSy5DOxkLzEtSDtZd1XVDFTqt6fR4l 1t7HvzTf/NwgcFcMhn9EXR2EZJPIW7zrjpr9kjrJ3XR1b4bOnC1N9cnymNH/ulS3skKx XDTg== X-Gm-Message-State: AOJu0YxNXO8p1qptw3+ZNoIHgIe79AbxiZtnel3H1IKA1k02NjjBL4Xb WtpBDbWhidjeWWcIObWT7B4XtQ== X-Google-Smtp-Source: AGHT+IFDkXMADJzJ5jjUq9PfJV9F8/TFu1J7WhBiuuPnpwyRrr8PIbDWnsDRVAoYbT3X6OqKjBwp8A== X-Received: by 2002:a17:90a:6d26:b0:26b:5fad:e71c with SMTP id z35-20020a17090a6d2600b0026b5fade71cmr8202972pjj.2.1694425765927; Mon, 11 Sep 2023 02:49:25 -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.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:25 -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 , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org Subject: [PATCH v6 28/45] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Mon, 11 Sep 2023 17:44:27 +0800 Message-Id: <20230911094444.68966-29-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: EEBFD40009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: iiega8c7myh9zaxidenjrkp18w8oujyo X-HE-Tag: 1694425766-486795 X-HE-Meta: U2FsdGVkX188AMgtZtE5M0BeZnrE0rOqNWLdOc9tHbjBh2CNhOJQkDREsspFmhmjjA8ql9XQQUk1dKKurvAf4r0Ucta68cuseiYWROi1X4+8mavO2MKtLGZy54DcrsvgUcLrfIBy3coe95So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8kzo+veAqqBKgz2aKMhNRZoHVYEv4fKuqhM3Evl8tEJJwrZnEzVRTfDbmijXLKsYnnMHQRABiOS0EfR1/Nnc+W/FAcxac5ki9REAdTrzqiDAWCoteRt8usspc1a9xPv+m3xqn1f8nlOujI1lOMdVE2S2is6Zz0ye53oAn6JcoalRjj79xZyq6S67P33PjDhyYuTtJ/mLia5T4g+48tZAHtIeUKM+DV1SlB+axXi3KpV71rZXFBDEbc4UwZY8P2ncrHj44i/+YLG1YhE+GjN2FXKcGpUiADEG9tuOV1/JCsTlpm+MXpdx+qbQsCoU5HlGYvco/dV1++IeZYwCpGHomQlVcAoI2 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 virtio-balloon 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 virtio_balloon. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: "Michael S. Tsirkin" CC: David Hildenbrand CC: Jason Wang CC: Xuan Zhuo CC: virtualization@lists.linux-foundation.org --- drivers/virtio/virtio_balloon.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 5b15936a5214..5cdc7b081baa 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]; /* Shrinker to return free pages - VIRTIO_BALLOON_F_FREE_PAGE_HINT */ - struct shrinker shrinker; + struct shrinker *shrinker; /* 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_balloon *vb, static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return shrink_free_pages(vb, sc->nr_to_scan); } @@ -825,8 +824,7 @@ static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; } @@ -847,16 +845,22 @@ static int virtio_balloon_oom_notify(struct notifier_block *nb, static void virtio_balloon_unregister_shrinker(struct virtio_balloon *vb) { - unregister_shrinker(&vb->shrinker); + shrinker_free(vb->shrinker); } static int virtio_balloon_register_shrinker(struct virtio_balloon *vb) { - vb->shrinker.scan_objects = virtio_balloon_shrinker_scan; - vb->shrinker.count_objects = virtio_balloon_shrinker_count; - vb->shrinker.seeks = DEFAULT_SEEKS; + vb->shrinker = shrinker_alloc(0, "virtio-balloon"); + if (!vb->shrinker) + return -ENOMEM; - return register_shrinker(&vb->shrinker, "virtio-balloon"); + vb->shrinker->scan_objects = virtio_balloon_shrinker_scan; + vb->shrinker->count_objects = virtio_balloon_shrinker_count; + vb->shrinker->private_data = vb; + + shrinker_register(vb->shrinker); + + return 0; } static int virtballoon_probe(struct virtio_device *vdev)