Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5767032rwb; Tue, 9 Aug 2022 03:54:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR5oB1KosSFipp0FW8ChgEcnWwwjw9wZwQm6HrkW+j4ynEiUtXn5cAX7F1d1USx19sdH6CgZ X-Received: by 2002:a05:6402:3907:b0:431:6776:64e7 with SMTP id fe7-20020a056402390700b00431677664e7mr21066272edb.0.1660042455454; Tue, 09 Aug 2022 03:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660042455; cv=none; d=google.com; s=arc-20160816; b=E/gC3t5YP87or9AAVelWNLzHI/5xGt3T6cHwQ1xRjK9hhy+W8RhC/Ea5wq7cSYESlN 2Y2U6HBUQSzwsNRySjCDMMp4rVULt0fL8qt0Hsz81pPEqLCv/8R+sh3/2o/RdRPtxvsK klForfEyaJU0YJpIz7N0cjUub4VqiK/jsYbOGIQ07fbFXoU555nnoGK/bi5dySPtkAs+ E4J0HWSV3twaCSABSssnDoYkkHMw3rU/dl8we2IPErsSNbDtKcWJd0iZQ8Tv0jbmfkZo iXRoO6ugsJE1ePAofGlqXrR/4qxvOGR4RfTRqE8ZtX+jxZxQWRP8EoITnu+oS46MdwMZ jPWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hroc99sZtiIPpz5PfR74Yti+LAwaySygUVpkWG7K1lM=; b=RP0deWEfox/soHex2mhFyoBoHeWnvS9sDuQvV7sun3+E3FS1R1IS5ysGHEbBQovuRA 5nQWfhD4GHwr03OOonV8UL6GxmM3414NWy/w+iKNY9dExCph7voTD0tn1sGbUCiDspxg b4pTQqOIoTSvolbdLBsKvsZlVMl75gdU1sSqwMRBdw8rJgfMLFsYO2ao98rwZYWrwv0w C2Uaz+EzSSXu+CyE6mDb1ENRAAJgxMga2dxlGddtKK7sFeuo54p++GQLgo4F73fyzfjR DmcdjNqK+n20yKv05xuSp6kEfQc0v59gaIyK66jochKmXOdc9vnsZZmmMkv1pydd+LBS pw5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a50f60a000000b0043d556dd041si8031110edn.446.2022.08.09.03.53.51; Tue, 09 Aug 2022 03:54:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbiHIJyc (ORCPT + 99 others); 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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