From patchwork Thu Aug 24 03:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363491 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 2D606C3DA6F for ; Thu, 24 Aug 2023 03:48:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C16EF2800A1; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA0208E0011; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1A5D2800A1; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 88D088E0011 for ; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 68B2D1401B0 for ; Thu, 24 Aug 2023 03:48:01 +0000 (UTC) X-FDA: 81157614762.27.4E7DDBD Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf22.hostedemail.com (Postfix) with ESMTP id A2CE8C0007 for ; Thu, 24 Aug 2023 03:47:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=S7PJEhTB; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848879; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=wI+FARaAik+c6S+JqKOXCSfeShayThMzt/z0gJ4VMfiJ6z83WenWlU7wuY5pt1ErcuygYF zZXO/AC0X/KynPLYK/lgz8Dh8loELQC0NVhDkedKjDW1lpydrCh/biQt+Krm0CfK7CXmBQ e8TMNYSiwLrKEURTM1R2+aX5OcXypDk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=S7PJEhTB; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848879; a=rsa-sha256; cv=none; b=8CiHT+hd8s5ExETBd4+AgKjZVSTP9CFW1uHC4NI/68Uzq4BoPBY62lFaphxY+2FF9Pt0v6 N3J5W0OfoiXpHFRWacAUjQtvBal2dHB7iY4Ts9kJvm71yYuN0lOIJt2z08jRRt821rp+9S SIRmynyDkC4mc5HU1t2E5MLhvEdU8Yw= Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3a86b1114ceso349492b6e.1 for ; Wed, 23 Aug 2023 20:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848879; x=1693453679; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=S7PJEhTBlU2ptzdizLOxfCUewX7SiUVXbnwlSYN2yOHNvAoStUJTI1eiOSL7rG56BH Lkt4aTffxFuu0wUyb3306dIpVQZ165605uSpyYO/jhILMu6ZQDf4Tgv0Sz+dN089wZwi 9MiPQoX3n2iBc0xXxBVtNs+dbNzAVP1eVgBKzKWyi1Dqgq9N7qukpvI07cbnyHlHwwR6 rSYkx5l0RXfmz5M6SQxpzqA/q37t0/Fle2uHU7Mbba0q0AloR2InD9pLWhiEHZxOwLsU Fti+OAi7IhueuRvVApFDNMDYIN5jErjkaa4mxwyJFA4LjJ5dva6v5WoeRZyJ3mtuwz44 +sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848879; x=1693453679; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=cY86oJ3zq44jAazTEiUJ9SCqNBdDRG6ha07G+yPYYf1L37mZa6dhoXjxzchahfnr8K O96QB++LlxGnUzRfNTeEW4Q7Q0m8+TPjFcDEKL9RD4OeS7QFJKTaV9/9uOvgn+WXB2iK f/6w3hEBRPduzBcO2nSrC4OiFS1FitDaWlyjc6pe3Q87PxmfEKbQy/mnN19z7QMwE5Cv SeD//J3ZJyAW4cN6DZ8zOKk8G1oZA4x9fx6sp411Xz3Z6jlsVJUGFrFX1crv2gZ/90h4 kwW/OWtFCySGMikSp/Qh1hM88mTVfYDvVgUrQEuAbVAxBPqXmp/+NTf70Xmd/wOXOxGW P3Zg== X-Gm-Message-State: AOJu0Yz2JRyl3RWXJPjjda9VHcVhYjvprpnA9mPgcJfw+73iQ/be90Ic jb9NHl3Wf1zsC+l1r5KN6d6aCg== X-Google-Smtp-Source: AGHT+IE+WG5PH7wniJfO5JcJbhNOS2WEVVvbmj+rtjyhc6DhOoBfaOm021n0CLUAVkQksyHeF+Z9Ig== X-Received: by 2002:a05:6808:bc8:b0:3a8:f3e7:d66b with SMTP id o8-20020a0568080bc800b003a8f3e7d66bmr424249oik.4.1692848878915; Wed, 23 Aug 2023 20:47:58 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:58 -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 v5 28/45] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Thu, 24 Aug 2023 11:42:47 +0800 Message-Id: <20230824034304.37411-29-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A2CE8C0007 X-Rspam-User: X-Stat-Signature: barjxgu4hcatqbkuknsb754o86bbsksq X-Rspamd-Server: rspam01 X-HE-Tag: 1692848879-100959 X-HE-Meta: U2FsdGVkX18iyggoNVt+VS4dX/XtSfi3Ogp3uy3cvyfomlzR1YgrruLls8D11+noHYXZs8goZiLd0hPkXzxHEunm6dar/vWoz7vE3EG5Bk61f76QaIzPZbCWcBzQJlDmAfUpmJ+zsgh8ZOxnIZJUUPncfNpIhVwKxDYLri80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/YPecQNcwvWgfDIJWrNnrhBkCG5/dkA6JRSEBkbYxvdnsHYyUjGlTk+u1NNiFry9Cv8Nb/dBDOkdFebvzSowpVXWGirzfqmvGbv76wAUMy/WwpprFS78uH3U1Tj/FsN7i+x9NmVtr44k2xSF16OcAWyIDdJxs9xnSMSdMelYLFTF6PVIknFAW7gPv01em6cTykIIDm7BFF5RKOtSsQo0sZgenv8KaHvCXFIwJ3Wlg8+pgQd34rAj9pytMnkbAlyAFMXrbuZ7Tb4Ip2mSw5dScjVK2QYtRiESkV6eBHpcB0WZVCuyFMHo7V+sMHgKpEAyKIzDoYyu3VqCDd 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 | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.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]; /* 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,23 @@ 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->seeks = DEFAULT_SEEKS; + vb->shrinker->private_data = vb; + + shrinker_register(vb->shrinker); + + return 0; } static int virtballoon_probe(struct virtio_device *vdev)