Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1072418imw; Tue, 5 Jul 2022 03:21:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u3+LTTKa+Ia0lxth2H72YR7AzUaeGJsqeK2ZvcrExgEzxjBNk8h304FRgukKVOzkYmoma2 X-Received: by 2002:a17:907:d26:b0:726:6d3a:a336 with SMTP id gn38-20020a1709070d2600b007266d3aa336mr33695377ejc.469.1657016468849; Tue, 05 Jul 2022 03:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657016468; cv=none; d=google.com; s=arc-20160816; b=cTFBhpcqmoU0SXUQhX9ZRQVCj6SWVQ6aOxO3xmEQd/os8xzSb3oHi+04ndtLdKQdNN x78UcodwtE3EvvuvFry+IppEiJtG7W/9/3SiJ7Kdjl0Aw+2PiavBogaWD0ObY2asYM/T wbOEoHdDrH0+LO1aSsXawouFdSXMVuEjpCELYuRCT0A8Ejo9n0cGqlmgsE5sKiBmlTfi R5674q/iTSCcZmmQfIMMMwADtxvxwDV/mFElqtQ/VgtxSWFM7fQP/ai8c9m/5Pj16q0s JbK0oI0NWS32RI+WlzI0gioeTJbMcTVa4iWSXKrDdRaLKxuFOXgEeJuQqUKoi8FOS8qg 8+4w== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2bv4Qa1JijZagoYaDRFxFSllxGwvGd5BuOhB4LGXUdQ=; b=lM5RW6O6VYdna1A53/GidugnSZRpNQfXBZvvJjM9e8BX18xvoUN0jVP81cWB826uDj c+7fWmtprmUdiI6pTjigxCjj0GEhOfl5njt9CVkS3mpZu2hbirW8nf4uASOxVhdCxusc D/daUsdVrMNRYdnyTz6ngjF3HThNwb8zpz1M22N9KBAUclcQs2hEOual9vGmLuF8OfuD VKWz8tl9SlrycIZO6OmEe5YjJZ1tkElL0IiSLLwhBpFtH07U5Ptz7ulYW7uXVgtAlGG8 m22aKcfhWF7hyTg5sDxzMx2DeAHXV164s29NEqVyXvXtG1PoUGNyY+/46muy1sXAaTq9 fSeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=y2bocfdD; 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=pass (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 nc3-20020a1709071c0300b00722dbb8f74esi12799207ejc.960.2022.07.05.03.20.43; Tue, 05 Jul 2022 03:21:08 -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; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=y2bocfdD; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230403AbiGEJos (ORCPT + 99 others); Tue, 5 Jul 2022 05:44:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbiGEJor (ORCPT ); Tue, 5 Jul 2022 05:44:47 -0400 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB872714 for ; Tue, 5 Jul 2022 02:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=2bv4Qa1JijZagoYaDRFxFSllxGwvGd5BuOhB4LGXUdQ=; b=y2bocfdDQxZK k820Is17UxapFIH87Egr+2fS3mSilxlRmVwIkU0ibzn05TangdXeDLP8VKL2uQzfsgEbsQHOZReGm evPxqc7asK1WUf7VpZ3+m8GccVY+sCKLKPfsa4CsVn6pgQhZu0zgcT4PwCrfT9ZUe4Sa5OXVs6DDg y2bmM=; Received: from [192.168.16.236] (helo=vzdev.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.95) (envelope-from ) id 1o8f6W-008lVt-WF; Tue, 05 Jul 2022 11:44:25 +0200 From: Alexander Atanasov To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui Cc: kernel@openvz.org, Alexander Atanasov , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/1] Create debugfs file with hyper-v balloon usage information Date: Tue, 5 Jul 2022 09:44:09 +0000 Message-Id: <20220705094410.30050-1-alexander.atanasov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Allow the guest to know how much it is ballooned by the host. It is useful when debugging out of memory conditions. When host gets back memory from the guest it is accounted as used memory in the guest but the guest have no way to know how much it is actually ballooned. Expose current state, flags and max possible memory to the guest. While at it - fix a 10+ years old typo. Signed-off-by: Alexander Atanasov --- drivers/hv/hv_balloon.c | 127 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 126 insertions(+), 1 deletion(-) Note - no attempt to handle guest vs host page size difference is made - see ballooning_enabled. Basicly if balloon page size != guest page size balloon is off. diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c index 91e8a72eee14..b7b87d168d46 100644 --- a/drivers/hv/hv_balloon.c +++ b/drivers/hv/hv_balloon.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -248,7 +249,7 @@ struct dm_capabilities_resp_msg { * num_committed: Committed memory in pages. * page_file_size: The accumulated size of all page files * in the system in pages. - * zero_free: The nunber of zero and free pages. + * zero_free: The number of zero and free pages. * page_file_writes: The writes to the page file in pages. * io_diff: An indicator of file cache efficiency or page file activity, * calculated as File Cache Page Fault Count - Page Read Count. @@ -567,6 +568,14 @@ struct hv_dynmem_device { __u32 version; struct page_reporting_dev_info pr_dev_info; + +#ifdef CONFIG_DEBUG_FS + /* + * Maximum number of pages that can be hot_add-ed + */ + __u64 max_dynamic_page_count; +#endif + }; static struct hv_dynmem_device dm_device; @@ -1078,6 +1087,9 @@ static void process_info(struct hv_dynmem_device *dm, struct dm_info_msg *msg) pr_info("Max. dynamic memory size: %llu MB\n", (*max_page_count) >> (20 - HV_HYP_PAGE_SHIFT)); +#ifdef CONFIG_DEBUG_FS + dm->max_dynamic_page_count = *max_page_count; +#endif } break; @@ -1807,6 +1819,115 @@ static int balloon_connect_vsp(struct hv_device *dev) return ret; } +/* + * DEBUGFS Interface + */ +#ifdef CONFIG_DEBUG_FS + +/** + * virtio_balloon_debug_show - shows statistics of balloon operations. + * @f: pointer to the &struct seq_file. + * @offset: ignored. + * + * Provides the statistics that can be accessed in virtio-balloon in the debugfs. + * + * Return: zero on success or an error code. + */ +static int hv_balloon_debug_show(struct seq_file *f, void *offset) +{ + struct hv_dynmem_device *dm = f->private; + unsigned long num_pages_committed; + char *sname; + + seq_printf(f, "%-22s: %u.%u\n", "host_version", + DYNMEM_MAJOR_VERSION(dm->version), + DYNMEM_MINOR_VERSION(dm->version)); + + seq_printf(f, "%-22s:", "capabilities"); + if (ballooning_enabled()) + seq_puts(f, " enabled"); + + if (hot_add_enabled()) + seq_puts(f, " hot_add"); + + seq_puts(f, "\n"); + + seq_printf(f, "%-22s: %u", "state", dm->state); + switch (dm->state) { + case DM_INITIALIZING: + sname = "Initializing"; + break; + case DM_INITIALIZED: + sname = "Initialized"; + break; + case DM_BALLOON_UP: + sname = "Balloon Up"; + break; + case DM_BALLOON_DOWN: + sname = "Balloon Down"; + break; + case DM_HOT_ADD: + sname = "Hot Add"; + break; + case DM_INIT_ERROR: + sname = "Error"; + break; + default: + sname = "Unknown"; + } + seq_printf(f, " (%s)\n", sname); + + /* HV Page Size */ + seq_printf(f, "%-22s: %ld\n", "page_size", HV_HYP_PAGE_SIZE); + + /* Pages added with hot_add */ + seq_printf(f, "%-22s: %u\n", "pages_added", dm->num_pages_added); + + /* pages that are "onlined"/used from pages_added */ + seq_printf(f, "%-22s: %u\n", "pages_onlined", dm->num_pages_onlined); + + /* pages we have given back to host */ + seq_printf(f, "%-22s: %u\n", "pages_ballooned", dm->num_pages_ballooned); + + num_pages_committed = vm_memory_committed(); + num_pages_committed += dm->num_pages_ballooned + + (dm->num_pages_added > dm->num_pages_onlined ? + dm->num_pages_added - dm->num_pages_onlined : 0) + + compute_balloon_floor(); + seq_printf(f, "%-22s: %lu\n", "total_pages_commited", + num_pages_committed); + + seq_printf(f, "%-22s: %llu\n", "max_dynamic_page_count", + dm->max_dynamic_page_count); + + return 0; +} + +DEFINE_SHOW_ATTRIBUTE(hv_balloon_debug); + +static void hv_balloon_debugfs_init(struct hv_dynmem_device *b) +{ + debugfs_create_file("hv-balloon", 0444, NULL, b, + &hv_balloon_debug_fops); +} + +static void hv_balloon_debugfs_exit(struct hv_dynmem_device *b) +{ + debugfs_remove(debugfs_lookup("hv-balloon", NULL)); +} + +#else + +static inline void hv_balloon_debugfs_init(struct hv_dynmem_device *b) +{ +} + +static inline void hv_balloon_debugfs_exit(struct hv_dynmem_device *b) +{ +} + +#endif /* CONFIG_DEBUG_FS */ + static int balloon_probe(struct hv_device *dev, const struct hv_vmbus_device_id *dev_id) { @@ -1854,6 +1975,8 @@ static int balloon_probe(struct hv_device *dev, goto probe_error; } + hv_balloon_debugfs_init(&dm_device); + return 0; probe_error: @@ -1879,6 +2002,8 @@ static int balloon_remove(struct hv_device *dev) if (dm->num_pages_ballooned != 0) pr_warn("Ballooned pages: %d\n", dm->num_pages_ballooned); + hv_balloon_debugfs_exit(dm); + cancel_work_sync(&dm->balloon_wrk.wrk); cancel_work_sync(&dm->ha_wrk.wrk); -- 2.25.1