From patchwork Sun May 12 19:36:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13662841 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 2335FC25B5F for ; Sun, 12 May 2024 19:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0A046B01F1; Sun, 12 May 2024 15:37:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D93816B01F2; Sun, 12 May 2024 15:37:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B97E76B01F3; Sun, 12 May 2024 15:37:08 -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 9AB766B01F1 for ; Sun, 12 May 2024 15:37:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 43B961605F4 for ; Sun, 12 May 2024 19:37:08 +0000 (UTC) X-FDA: 82110752136.15.091E58A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf24.hostedemail.com (Postfix) with ESMTP id 9389518000E for ; Sun, 12 May 2024 19:37:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="e+J22fH/"; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715542626; 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=NkNPmUrhueWtYL66O2BZcuzr0aj9MLsurBwxaoHW6ao=; b=KTkwB4VnuZS++9wvwAtqhyJrjE6l+rd7+0lRxFguaW5sxxNIEeqsq9f3kOtDckCaQ6O5Oi ZAPrOO79XQt6MUjWitZk24wqJFX3JnZPyKtVzAF27HM2l3cw0hRh/BgTUS9qI/ri0Kr3/v yyhPEftgzwp1cMy6S+LXlYFGkyF0p+M= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="e+J22fH/"; spf=pass (imf24.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715542626; a=rsa-sha256; cv=none; b=pSyyzze5cOEGcelpB4CNdx5oBe9KdKQ+9kYgdbgfNZ3obMkUt4VNcYB/upKt3nyhNL+jSw F7pueE/SJlrrkLujKdwoVGz8HBw6ebbPg4hbKqbojsAePF6gzuRG7keM0sDKwd7OmA7gtj xoYOkTL+9VodU5z7Tv1nAtTQ6PjlVLs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C010A60B97; Sun, 12 May 2024 19:37:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 081B8C32783; Sun, 12 May 2024 19:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715542625; bh=qXYTRSugt7rwl/3A7n+cY924/FHphURhvhYWI9AMXzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+J22fH/4YnyP8x5FrAEpo47lsNbj13oV2jS+1bItSJLZScow+ISz0erPzyq51tDX omRw3NzuQiO1RBpqmHWxZkNdG/C3JpIBRCJRCbdigcjcQA99HuS1zHzIBjLEjyvLM/ kwq3wZLGlKZW9tGsCgDmoFB0XF9ZVchI0zsqHmkv96mGBGcdzYb+wpO4wWv7zIZLUT e0crt2XhymhE1BsA7nONdVsfepGmV7Jk3FLLgaOEUqReDaQPf3eJt2SsfUKoYypJLN FXf9Xgi9xcMVJdrj3qSs3ai2k7adxPQmN4NKNo1MKgwJi/TTmrrNUkoh3eJ0gORigB +mWlKI7cGWgbg== From: SeongJae Park To: Cc: SeongJae Park , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Xuan Zhuo , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, damon@lists.linux.dev, linux-mm@kvack.org Subject: [RFC IDEA v2 6/6] drivers/virtio/virtio_balloon: integrate ACMA and ballooning Date: Sun, 12 May 2024 12:36:57 -0700 Message-Id: <20240512193657.79298-7-sj@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240512193657.79298-1-sj@kernel.org> References: <20240512193657.79298-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9389518000E X-Stat-Signature: mheuebkniwiiwys78tx3xek7u6ggbf5i X-Rspam-User: X-HE-Tag: 1715542626-976232 X-HE-Meta: U2FsdGVkX19VWBJNZXOR7dKc5/25jdHQk0iHEkGRFs7IyjUSK7rTWmqwoE2lGSrj0Ny0ZL2W5avA8YsPP+FutykHvjGZza2es7w8HwWTrrA+u0xeg1+/qCfwnIMr3h0sFC8kYloAyz/B+Ot23j/VqwyI7QiUHuH3HhCZXpRIh8WjzLJ1aULUi4BfR/Hd9K0IIwNG9D/a2D491upXm2894VBKn2f5uIjyxKZxO2EygRqLVQjaYYOirduaVkhWIKVVSo5mTlZztcJdvAgu2exDsMe2XDRcPomol6uJOr/Qg91gwRKAp2G7elOR6wa0Pv8uM3jcoMgQZ3BedtAFnY3ThBGMtIlsG+OuxjWSJJIP0Fef1NVATotzWuJzB/wORKD8d/oiiH/1Hly4yHqcZPshT3o7s9yPCRwDE9buhYlc7CApCf314eHSdG0XrwcwNMTUgEKSp2c32PjAZrbwlpP9rUemxfO54Dn/0JitrIuCk9APqPK4regj3z9hIwexgyrHcG8QHmQCm54069EikDR26C6DuqrA5nM9KchWBdRa6Us+7OxNKoazA8GWM5UVTs9PUJrLbulUNybxHud17qHkfSDqoKtEKmP9UFuLNYXgixGQQe5ATKTTYNABngrxFE43g/fXf1OVVD5b+BORbi48MiGjobwINqxGfz3gxVWunNc8s1PMcL94hV2Bw2oW24i5zysyJlCONqJQ2u8cdB1aNlWdXjr+yxLEq1QSJ+ApiXbdn3Nm8+pA3Kwz6XWxD0jj09SKh7JzOqdOemm9iNBzaiLLYMzR02357vnJDcZtCUxBFnPgcI3KAnmRXNSx5synWJGhAeovrhlyaTEAi1W1unyG9pcaxv/OvdrRsSdCTkOL6hylZ9ZnrKCgBxF0mUpXHvCZS6hwKwZyxXRTTo4CrJTNuHMseT7SRlg8eLhkPoGZaNxYO4hvrqqCWJSDPCjEt8ENBWU12PNuRJB6RVX 731nlhAH XIXyFK6rd8J8Dy24m2mH4V/h2el1yjubi/jkFga5uTfLQ5yadKB/3hwk6FUOWbxy8WMyoXYG4nesKa0C4yf3tAL7jc/mY46L/LbkaQC/rorAo9pPEJO/aBtlbi5sVZ5M00Zp8M+K6OwP0yeaIdHRy1KsnrhsbaJPyqcl5/Y90JMQqSh46uRDL3jgywjwdjIndr9kIFQ8PrlSFsBZON74ypv1oNiRiiBByWON2xkdkBTL1wH4w/K2o0pxpf46moWXFzzASCDesWOZ+a06bgw+43x+Z0tKwGVY8Ms+l 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: List-Subscribe: List-Unsubscribe: Let the host effectively inflate the balloon in access/contiguity-aware way when the guest kernel is compiled with specific kernel config. When the config is enabled and the host requests balloon size change, virtio-balloon adjusts ACMA's max-mem parameter instead of allocating guest pages and put it into the balloon. As a result, the host can use the requested amount of guest memory, so from the host's perspective, the ballooning just works, but in transparent and access/contiguity-aware way. Signed-off-by: SeongJae Park --- drivers/virtio/virtio_balloon.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 1f5b3dd31fcf..a954d75789ae 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -472,6 +472,32 @@ static void virtballoon_changed(struct virtio_device *vdev) struct virtio_balloon *vb = vdev->priv; unsigned long flags; +#ifdef CONFIG_ACMA_BALLOON + s64 target; + u32 num_pages; + + + /* Legacy balloon config space is LE, unlike all other devices. */ + virtio_cread_le(vb->vdev, struct virtio_balloon_config, num_pages, + &num_pages); + + /* + * Aligned up to guest page size to avoid inflating and deflating + * balloon endlessly. + */ + target = ALIGN(num_pages, VIRTIO_BALLOON_PAGES_PER_PAGE); + + /* + * If the given new max mem size is larger than current acma's max mem + * size, same to normal max mem adjustment. + * If the given new max mem size is smaller than current acma's max mem + * size, strong aggressiveness is applied while memory for meeting the + * new max mem is met is stolen. + */ + acma_set_max_mem_aggressive(totalram_pages() - target); + return; +#endif + spin_lock_irqsave(&vb->stop_update_lock, flags); if (!vb->stop_update) { start_update_balloon_size(vb);