From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEB3DC19F2D for ; Tue, 9 Aug 2022 09:54:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233151AbiHIJyc (ORCPT ); Tue, 9 Aug 2022 05:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbiHIJya (ORCPT ); Tue, 9 Aug 2022 05:54:30 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B886237CC for ; Tue, 9 Aug 2022 02:54:29 -0700 (PDT) Received: from dev011.ch-qa.sw.ru ([172.29.1.16]) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1oLLv2-00ElXo-EF; Tue, 09 Aug 2022 11:53:59 +0200 From: Alexander Atanasov To: "Michael S. Tsirkin" , David Hildenbrand , Jason Wang Cc: kernel@openvz.org, Alexander Atanasov , Wei Liu , Nadav Amit , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] Drivers: virtio: balloon: Report inflated memory Date: Tue, 9 Aug 2022 12:53:58 +0300 Message-Id: <20220809095358.2203355-1-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220809094933.2203087-1-alexander.atanasov@virtuozzo.com> References: <20220809094933.2203087-1-alexander.atanasov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update the value in page_alloc on balloon fill/leak. Cc: David Hildenbrand Cc: Wei Liu Cc: Nadav Amit Signed-off-by: Alexander Atanasov --- drivers/virtio/virtio_balloon.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) Firts user, other balloons i will do if it is accepted to avoid too much emails. diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index b9737da6c4dd..e2693ffbd48b 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -208,6 +208,16 @@ static void set_page_pfns(struct virtio_balloon *vb, page_to_balloon_pfn(page) + i); } +static void update_meminfo(struct virtio_balloon *vb) +{ + long inflated_kb = vb->num_pages << (VIRTIO_BALLOON_PFN_SHIFT - 10); + + if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) + inflated_kb = -inflated_kb; + + atomic_long_set(&mem_balloon_inflated_kb, inflated_kb); +} + static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num) { unsigned int num_allocated_pages; @@ -250,6 +260,7 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num) } num_allocated_pages = vb->num_pfns; + update_meminfo(vb); /* Did we get any? */ if (vb->num_pfns != 0) tell_host(vb, vb->inflate_vq); @@ -296,6 +307,7 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num) } num_freed_pages = vb->num_pfns; + update_meminfo(vb); /* * Note that if * virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST); @@ -1089,6 +1101,7 @@ static void virtballoon_remove(struct virtio_device *vdev) kern_unmount(balloon_mnt); #endif + update_meminfo(0); kfree(vb); } -- 2.31.1