From patchwork Fri Nov 11 01:42:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Annapurve X-Patchwork-Id: 13039505 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 13B5FC433FE for ; Fri, 11 Nov 2022 01:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232813AbiKKBnV (ORCPT ); Thu, 10 Nov 2022 20:43:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbiKKBnO (ORCPT ); Thu, 10 Nov 2022 20:43:14 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4769763CDC for ; Thu, 10 Nov 2022 17:43:04 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id s15-20020a170902ea0f00b00187050232fcso2528578plg.3 for ; Thu, 10 Nov 2022 17:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=k4x/ZOtSpWk9/3ogowMPSnEkswUrYlJBht55aGP6vlw=; b=TJGAJEvpGOatam2eQMAYKoLHifGaCKcgJ8RPGSg+GXW2tqhAlddReaZHE/EKUpB/tx wjBR+3fkVuz5yXDC3v0NzMfaMkv2C+uXqhDrFlw9iL37AzlIQdssxZgqr4y5+ezJy9KR IGL9cS+FdQPPMmyeCQT+IIERkTkpC7c6Z2i51BEsaPh+mKQ8ctl+6nfK3X4QpbWqHbE3 WwUKGXkYBcRy+rkkT9p+dt2ShAwGDdwHm6+sZD0REr1/vQfkXzc/5f9Yb9cOYN+KQikL 7M1RLkXjbhCoOocrZWjPma3UEXdsVvYchcMh+jKKc7dzFmX2/imWhcLvUEsJdE4IXiAg YiCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k4x/ZOtSpWk9/3ogowMPSnEkswUrYlJBht55aGP6vlw=; b=TKuQ61iARcAvUvbRrMhgE3iqiDyW736+lR1hQO3B3kzqJwPpC8yKfSfjaZd+WunN3v OxaZZm6Vl/+eU4onAMwQgzaHrGct8cEWxlo2AzvuEv9zVsfMbzk/pI1dQ9BFWRYOm6O+ an90j0v43HbBI+WUHFHtD5/ly2ps4gDv1j8Sma5JZG40eXCe/I0FFXjuYkkiEPEasU5D fmTOAx63pZJbGD0daB9vt21hBObossHS253pcYuLvNBbMy+vSV/40Ot2l2zwQi5gBGyD X0oLMUHpE7BEnFsLtfj1QTBgQVZci82oSGuzeY0O7HPR1DytbH30gUl5vp71sZ+IB92U Q95g== X-Gm-Message-State: ANoB5pl3suJzuJX3mnLA24utjcAGCBCS1o4TB8DVg9odxPM4SmNZ/fdJ 6Qrn7mO2wcEnUDUEDKUV54Q4iU+/lhR2j2TM X-Google-Smtp-Source: AA0mqf467VSoly0Pym2TsVrqMJzRUABw5L6WkuXLvTk+pZVpwyNu+Jak6Hp2K4udCnAfjs2qiA538m2BwRv5AKP+ X-Received: from vannapurve2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:41f8]) (user=vannapurve job=sendgmr) by 2002:a05:6a00:3022:b0:560:e4d1:8df5 with SMTP id ay34-20020a056a00302200b00560e4d18df5mr337333pfb.39.1668130983874; Thu, 10 Nov 2022 17:43:03 -0800 (PST) Date: Fri, 11 Nov 2022 01:42:43 +0000 In-Reply-To: <20221111014244.1714148-1-vannapurve@google.com> Mime-Version: 1.0 References: <20221111014244.1714148-1-vannapurve@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221111014244.1714148-6-vannapurve@google.com> Subject: [V1 PATCH 5/6] KVM: selftests: Add get_free_huge_2m_pages From: Vishal Annapurve To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, shuah@kernel.org, yang.zhong@intel.com, ricarkol@google.com, aaronlewis@google.com, wei.w.wang@intel.com, kirill.shutemov@linux.intel.com, corbet@lwn.net, hughd@google.com, jlayton@kernel.org, bfields@fieldses.org, akpm@linux-foundation.org, chao.p.peng@linux.intel.com, yu.c.zhang@linux.intel.com, jun.nakajima@intel.com, dave.hansen@intel.com, michael.roth@amd.com, qperret@google.com, steven.price@arm.com, ak@linux.intel.com, david@redhat.com, luto@kernel.org, vbabka@suse.cz, marcorr@google.com, erdemaktas@google.com, pgonda@google.com, nikunj@amd.com, seanjc@google.com, diviness@google.com, maz@kernel.org, dmatlack@google.com, axelrasmussen@google.com, maciej.szmigiero@oracle.com, mizhang@google.com, bgardon@google.com, ackerleytng@google.com, Vishal Annapurve Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add an API to query free 2MB hugepages in the system. Signed-off-by: Vishal Annapurve --- .../testing/selftests/kvm/include/test_util.h | 1 + tools/testing/selftests/kvm/lib/test_util.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h index 140a61f68fe5..f4df49c8b5ba 100644 --- a/tools/testing/selftests/kvm/include/test_util.h +++ b/tools/testing/selftests/kvm/include/test_util.h @@ -115,6 +115,7 @@ struct vm_mem_backing_src_alias { bool thp_configured(void); size_t get_trans_hugepagesz(void); size_t get_def_hugetlb_pagesz(void); +size_t get_free_huge_2mb_pages(void); const struct vm_mem_backing_src_alias *vm_mem_backing_src_alias(uint32_t i); size_t get_backing_src_pagesz(uint32_t i); bool is_backing_src_hugetlb(uint32_t i); diff --git a/tools/testing/selftests/kvm/lib/test_util.c b/tools/testing/selftests/kvm/lib/test_util.c index ebbac8246016..4f28ae73f150 100644 --- a/tools/testing/selftests/kvm/lib/test_util.c +++ b/tools/testing/selftests/kvm/lib/test_util.c @@ -145,6 +145,24 @@ size_t get_trans_hugepagesz(void) return size; } +size_t get_free_huge_2mb_pages(void) +{ + size_t free_pages; + FILE *f; + int ret; + + f = fopen("/sys/kernel/mm/hugepages/hugepages-2048kB/free_hugepages", "r"); + TEST_ASSERT(f != NULL, "Error in opening hugepages-2048kB/free_hugepages"); + + do { + ret = fscanf(f, "%ld", &free_pages); + } while (errno == EINTR); + TEST_ASSERT(ret < 1, "Error reading hugepages-2048kB/free_hugepages"); + fclose(f); + + return free_pages; +} + size_t get_def_hugetlb_pagesz(void) { char buf[64];