From patchwork Thu Jun 22 08:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288590 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 2D1E4EB64D8 for ; Thu, 22 Jun 2023 08:55:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB5718D000A; Thu, 22 Jun 2023 04:55:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B644D8D0001; Thu, 22 Jun 2023 04:55:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2BFA8D000A; Thu, 22 Jun 2023 04:55:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 95E768D0001 for ; Thu, 22 Jun 2023 04:55:34 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6747512010E for ; Thu, 22 Jun 2023 08:55:34 +0000 (UTC) X-FDA: 80929775388.29.F411DFC Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 609FA120002 for ; Thu, 22 Jun 2023 08:55:32 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DMwdTIl9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 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=1687424132; 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=Rw+THIB7nYtdEoKFrcRpf+DtRSemfk8nQmXyWQCWLOU=; b=BjYMHkfNyfcDN3e6hFIeDr+Y8h0GCilUkfboHNzJ91pNS5n0n5Jk65/ElEMFEF15aQ20Pc TUsNhqdZFjwjeRghA6SZOeIx23mEpCPaTQK+Ngcf41lYHyzoJO/gU0ZVDjgS4Nb1uuYeBn lx3/Tiz9XjRC/NTmR2qN5L5HnxH3EqQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DMwdTIl9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424132; a=rsa-sha256; cv=none; b=67fPVuEiNdP0K8LGxIkDODrs08HXAPv5DIJQzAclGqeD//SSf52tDnpmvrVkrLnlrI86yk SUwBDZYn/g1gVNWbeixsN6lq6JdXP+gtiEK90CeaJDx9Jcr6AIUwRH6X9yd2RkZsPFI8xm AlOjLaNLJOeIyr0XcDEMYtbWJKW20X8= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-51f64817809so680031a12.1 for ; Thu, 22 Jun 2023 01:55:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424131; x=1690016131; 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=Rw+THIB7nYtdEoKFrcRpf+DtRSemfk8nQmXyWQCWLOU=; b=DMwdTIl9g+okPZHJv8qTrb+gYAPEj9v1sxcSDlzK5ch7N+TuIC/BcFHKohEZo55ND8 XU29tOhBmT8qLwPtzV/wEHQ6iOqaUqSy8YTL9GNxgMKyLojaih+JCKFRV8sA50VDaMhL 4ENhUxcmuP8buO31FrzpXihlkiHbj7xjQ5jQCZ/XAAfjoNJ005ZfE8KQlMXJnunKzCcO Fe2zvwkJ/uki5/MCqM+WcH9ckA1bFEYVaXIUmwP+4s7h2vpQxpmZaq/OfODYIqbWYJLH gNO1EGlemqhIu8SDpgbpJo6kXONx1A4ErgZXcMZMC3KoLi5/PQ7Kas2P+1tIIIXAXu47 3GiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424131; x=1690016131; 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=Rw+THIB7nYtdEoKFrcRpf+DtRSemfk8nQmXyWQCWLOU=; b=TW6mOwnc3VHZ4XPCQ4+q1hhf2KoNJFH0SVCtxpO5pXx0LzYaXgtJewLEyHGxUoKeFN HnzExF/r4Gf1k/jTGgkAQdT/3W5zWbkeTH+/XR87z9aglenW4qwhhnyAYMVqeu5n44iP ZhlUHyeXKyX/7/i9nJgsBFflTsAEFirlu93j5tWBBcNauywVKyNpj0NPQ0N/Ery7Kk3k cYxcnMivWx/swFAsh9eBHpTICt99hBH6mhXN5aYhknzPkD58ORcJKLSCMcYIM/02ovGC pXzdhb+0rrBE7pyxtIXswIOoN0dYJpLEadl4itNXyCJI0ZDwNFOEwZDErmv00VjxvYj5 pp9A== X-Gm-Message-State: AC+VfDwD2WNDqZNlNEaS3+cck/oWpvfkmebwHKktnCNDVP2gUFUZEdM9 DuTPShn0VJX4RB59Ne/E+fkF/w== X-Google-Smtp-Source: ACHHUZ74w6zUyxxONmkdhWFpbjqcQv1Ri8s1BW02LunWtr1K9sXtmODVbQHvvX6jLBNiniDuaX5mmA== X-Received: by 2002:a17:902:d489:b0:1b4:ddef:841e with SMTP id c9-20020a170902d48900b001b4ddef841emr21417877plg.4.1687424131373; Thu, 22 Jun 2023 01:55:31 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:55:31 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.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-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 11/29] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Thu, 22 Jun 2023 16:53:17 +0800 Message-Id: <20230622085335.77010-12-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 4zz4m6pzog17qh85p9d6jfdhwieky41r X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 609FA120002 X-HE-Tag: 1687424132-662456 X-HE-Meta: U2FsdGVkX1+qgqFVVb7WWWzpwWfym/ddJPUP0nz7J8Q7SFeWl8kmxjfxY5Lmh2spJB9G+Cq1MmttQsTCoonBBHcxVDoMtkSqxGO1Xa/drJ8jszHwGsy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YCyV8u+mvoYoAItTLNb/TnbpDNlvAVgoXVQ9YWLKfLGs3lm3TlkzdyBKPD6UYOqLz4NrpyXaymGMDJaezgMhjL6AEH0S26FuMvhE0E+X+s/hVSyaVI6Qma9wE51K1Caq4Ae5+WSBrf9+9XgwbfLa1VYsyItKA459gOUbPmn76NRcScyQN12msiJbrn1I0PJmA8J+b56aYttmP8vnMSomgl2z9ggInWE8idyi0DBV8ASoVbLVLs9Uw== 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, we need 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 --- drivers/virtio/virtio_balloon.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 5b15936a5214..fa051bff8d90 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,24 @@ static int virtio_balloon_oom_notify(struct notifier_block *nb, static void virtio_balloon_unregister_shrinker(struct virtio_balloon *vb) { - unregister_shrinker(&vb->shrinker); + unregister_and_free_shrinker(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; + int ret; + + vb->shrinker = shrinker_alloc_and_init(virtio_balloon_shrinker_count, + virtio_balloon_shrinker_scan, + 0, DEFAULT_SEEKS, 0, vb); + if (!vb->shrinker) + return -ENOMEM; + + ret = register_shrinker(vb->shrinker, "virtio-balloon"); + if (ret) + shrinker_free(vb->shrinker); - return register_shrinker(&vb->shrinker, "virtio-balloon"); + return ret; } static int virtballoon_probe(struct virtio_device *vdev)