From patchwork Thu Oct 5 16:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13410434 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 F06FEE7AD45 for ; Thu, 5 Oct 2023 16:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7620A6B02AB; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 739446B02AD; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 564246B02AE; Thu, 5 Oct 2023 12:39:36 -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 498BF6B02AB for ; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0C2B34022A for ; Thu, 5 Oct 2023 16:39:35 +0000 (UTC) X-FDA: 81311968752.29.781E3C7 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf10.hostedemail.com (Postfix) with ESMTP id 2E344C001A for ; Thu, 5 Oct 2023 16:39:32 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696523973; 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; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=UaW6k2BIfc3cwTRWI1GiuRmFWBJUT40VO35ABKz6Ap6kRWmvqBILidPyxJyEla7PcZFNf8 YUipXd2L8JZC/d6GrWszm8XZx6uFn0BZJxPq8RnoulHrq3UOncYDhAxQ4nFVAq9H7HXmAz L8U/3IThYtay33XlXukPC2QKdvpV4rA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696523973; a=rsa-sha256; cv=none; b=Dfi9wRI/giecKA81RdyrC2q3AtejfUHNqz9hVtP0L217GQbGuJW1daOpuS+sqMLRW7h0lW Au9UWK8t8ki9eCR66gwftt3jNjnw9TUOAzjvzRFntU+tDVaFFh+iKqSuhWBQRTcih+vutb brqXdGTz7CNME5CGx6YGSdZLt6Lxu2s= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-9ad8a822508so235558766b.0 for ; Thu, 05 Oct 2023 09:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696523972; x=1697128772; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=D94jXsS88f+cDXT3TjeJXGn6SLJ7JgTDIPbrB8NCBLvxY9KV9wdmWVAnRz+1k//sxT v3y+s/IhRS+2kaYJ0ReNAYs0JDDCLNELNRcbcTYGvMerHkOMfJbCYcF807yQZDfbJO2O 2Enly6yi6RLGFwjEgDfB1xVJsfJxxG/XWzn1SySZUxUrkABJz02eUZfGHxgic5fZ5ast pXAnEYDeIpD8hsBMBIHksmHMEutmVpBAwTKK24ic94nP2HKwyD8C3WJo45LA620USvzJ JjKMRnbdHbgBjuH4cnSCvFQ5jqMGJxfR4SeCq+P7HA43Bj7GpcjQhqIFpG8bC+6P6X8o GiWw== X-Gm-Message-State: AOJu0Yz+FT9cr7YwX2XORAPEdbKuQqX7S/pRXzZi7H7roANjE6SNo1Qn CQGZmUqQcuJA+6GanI0jnVY= X-Google-Smtp-Source: AGHT+IGYDnp74cV0Byj3XwLIm6spdtkEqH5f+zeVjCF1kcvzcQHqph+sJjv4ryOmfqgXWAqfOPwhPg== X-Received: by 2002:a17:906:2191:b0:9ae:5246:233a with SMTP id 17-20020a170906219100b009ae5246233amr4855817eju.20.1696523971836; Thu, 05 Oct 2023 09:39:31 -0700 (PDT) Received: from localhost (fwdproxy-cln-001.fbsv.net. [2a03:2880:31ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id v24-20020a1709067d9800b009b2c5363ebasm1441273ejo.26.2023.10.05.09.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:39:31 -0700 (PDT) From: Breno Leitao To: mike.kravetz@oracle.com, muchun.song@linux.dev, akpm@linux-foundation.org, Shuah Khan Cc: linux-mm@kvack.org, riel@surriel.com, linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/2] selftests/mm: export get_free_hugepages() Date: Thu, 5 Oct 2023 09:39:21 -0700 Message-Id: <20231005163922.87568-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005163922.87568-1-leitao@debian.org> References: <20231005163922.87568-1-leitao@debian.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E344C001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: kyfxs9geb773o7aguu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C12J8dZ4ac4jSzZCDSHM/OWjZlmcRl2CnyiWWDPP6z2GF+BrJ9/82IAJcobY7ix7bhxRqYtqP+/DuQlT5tevoryEeAqQYv3F61mH+yCgQzWLBLO4UXT5Xm/mOWThO9ON0ah7C9/pdAb3zudgopBw4JsI26N2go0J8MUxX1fvAs/BPq5ntq5ixo5XK++TyMH5ARbtU6OE2iiB6IJpfSh+4u1mNpW5i04rBtLoGDQMe0ShOdcKneWCi9gFRRBdptrjfpcn8l0i5oSx1GKYHy1bCus0EsX24Yugg0a5zEF4QlzN+GPDuuodqq5CgTugilrqqNiM0Zwpg+1cHZeROPuYBR0UUvxDX/NzK69v/17IfhLzPfPm1tu4ectJOFm8uoUol4Y967QdooAE3PI7NP0Y7u52Re7jj9M9PeugcaJDoviqWZ+6oqER8+ft6c5DYB1QdFCIyyd1CDbmxNQ== 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: get_free_hugepages() is helpful for other hugepage tests. Export it to the common file (vm_util.c) to be reused. Signed-off-by: Breno Leitao Reviewed-by: Rik van Riel --- tools/testing/selftests/mm/hugetlb-madvise.c | 19 ------------------- tools/testing/selftests/mm/vm_util.c | 19 +++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c index d55322df4b73..f32d99565c5e 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -36,25 +36,6 @@ unsigned long huge_page_size; unsigned long base_page_size; -unsigned long get_free_hugepages(void) -{ - unsigned long fhp = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return fhp; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "HugePages_Free: %lu", &fhp) == 1) - break; - } - - free(line); - fclose(f); - return fhp; -} - void write_fault_pages(void *addr, unsigned long nr_pages) { unsigned long i; diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 558c9cd8901c..3082b40492dd 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -269,3 +269,22 @@ int uffd_unregister(int uffd, void *addr, uint64_t len) return ret; } + +unsigned long get_free_hugepages(void) +{ + unsigned long fhp = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return fhp; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "HugePages_Free: %lu", &fhp) == 1) + break; + } + + free(line); + fclose(f); + return fhp; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index c7fa61f0dff8..c02990bbd56f 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -51,6 +51,7 @@ int uffd_register(int uffd, void *addr, uint64_t len, int uffd_unregister(int uffd, void *addr, uint64_t len); int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls); +unsigned long get_free_hugepages(void); /* * On ppc64 this will only work with radix 2M hugepage size