Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2748944rdb; Wed, 4 Oct 2023 10:12:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFx6wJ5ZQ9s4bW03hQ27IJ/Xw1AGDDZyEeY5WTE9E48/ATvXIvNLTCYoYo26eixIq9g2f01 X-Received: by 2002:a05:6808:23d0:b0:3a7:5557:16c2 with SMTP id bq16-20020a05680823d000b003a7555716c2mr3741168oib.0.1696439536805; Wed, 04 Oct 2023 10:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696439536; cv=none; d=google.com; s=arc-20160816; b=MbjTx191YDrSm2vx7xpCMpPulLolWr0ToeYVb/bs+EdGXF4WW+SgYFQf1RXTuKu/Bn v04ydoGkDtKoMtm4biL0Zjc2By3FOSKCW7KH5gpFPB6F2ofXgvYQG2YBWu3Z8AeWA3Ed OoV8aN3EPh7gfLrecDEDgZhZrucavmwBZEMsUpYAwaOmG8phU7RGot7ROKQfu2Ec2Gco l6GObKSxGj9yxespFFl/P+zx8ke9o8PN1vmXGg28XmyxpRUve8bCp0i5PpgxC6mOg84B oTNa3YMEF+wtlf5QeahIDGdbVAkw5xLMAmwMLbHrU2ZumVM1Mv4H5h1VMgyDbDvw6kKM I5Zg== 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; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; fh=oPccr6L1xYOfJzG3Pt1mbPWtnzp0+sBJjQoU+6uugjU=; b=g8aoFtqpxF1ZKk4W+jaIwg2hot9pVHTiCA0eAIHj/HHJIbTF7q8JBM5h7WRkC2S+Ut NFIf2v5B+tNyheHRVE56A320ISNPdiXENLbaaGUH3yTAAYgGF1NmVg5/+HYHGk5vK2ES vrIwiUo7NgazLL759zPDYCtkNDOmmT2SJWL+DmzfvxpM+hqJq3HhSRUg1XWGnSVibHQ1 5bwkARcPPeRvPxGw0p6Xk2VUIcbMxQnKfMj8OvychGuVsMZ3PW1yl8JWT1N+WSrE5gCV RWC1Ud8lV27gawix+9ixrMq/dsCkcehY5GmkQUrcoGnjtmIuMUGypn7i4urbqKPpdV73 1dVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t71-20020a63814a000000b00578d7a3a4fdsi3851811pgd.563.2023.10.04.10.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 10:12:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A33BD802E6E3; Wed, 4 Oct 2023 10:12:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243641AbjJDRMN (ORCPT + 99 others); Wed, 4 Oct 2023 13:12:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243627AbjJDRMN (ORCPT ); Wed, 4 Oct 2023 13:12:13 -0400 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6B2395; Wed, 4 Oct 2023 10:12:08 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso9467166b.2; Wed, 04 Oct 2023 10:12:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696439527; x=1697044327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=dIBrDsv/omajYDcjt1S5VMcxAxF4ASg9WRLTFh/+Py2WjDs5Icqm2AeLklLYUJh1O8 OX+siDAx/6jYsJw4zOhsVPopKGaL3jzX90IEN9LIUIzJkXVqr4fS80l2gkXi3KIAiDoz U7UKYlxZRhcuqeS8jNLAUgWLvwtNSBc+D9Pop29+x00Ys4M306b3dXRn2Dv9tycxEnr2 Y/CdeNtWF6kCzihYNqnPlBmInZ6lSTWLTnYeowS/uL0aowYKrYJpHS/krP9koy+YgZW9 VINY4byV0dbQea91wMtJ+VASfFjlS0qWyldYmnWHRtWPf4PDY5ozfWEkZwOl0uRb/7M7 oLkA== X-Gm-Message-State: AOJu0Yynvpmr7y/ZV5NlusQqLY8AJKQrgf6VITN2SaS+B4AOAlXcRKoY KX9pbut6iGAQwp5BeWj9P04ZaoiqxXo= X-Received: by 2002:a17:906:5357:b0:9ae:7681:f62a with SMTP id j23-20020a170906535700b009ae7681f62amr3072085ejo.44.1696439527012; Wed, 04 Oct 2023 10:12:07 -0700 (PDT) Received: from localhost (fwdproxy-cln-006.fbsv.net. [2a03:2880:31ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id z25-20020a1709067e5900b0099bccb03eadsm3064093ejr.205.2023.10.04.10.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 10:12:06 -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 1/2] selftests/mm: export get_free_hugepages() Date: Wed, 4 Oct 2023 10:11:25 -0700 Message-Id: <20231004171127.106056-1-leitao@debian.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 10:12:15 -0700 (PDT) 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 --- 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 -- 2.34.1