From patchwork Wed Oct 4 17:11:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13409090 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 C686AE7C4E2 for ; Wed, 4 Oct 2023 17:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E2E36B02B1; Wed, 4 Oct 2023 13:12:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06BB46B02B2; Wed, 4 Oct 2023 13:12:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4E176B02B3; Wed, 4 Oct 2023 13:12:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D18FF6B02B1 for ; Wed, 4 Oct 2023 13:12:10 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9EB171401E6 for ; Wed, 4 Oct 2023 17:12:10 +0000 (UTC) X-FDA: 81308422020.13.4AAA458 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf17.hostedemail.com (Postfix) with ESMTP id 9E54840026 for ; Wed, 4 Oct 2023 17:12:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696439528; a=rsa-sha256; cv=none; b=71X1qhpCyXxBfYindcnNs0NIucL6YuN+VvjRMCHsaT08WpZt6qXtykvP6wja/CebP5dJKz Xbf3sN2cse1DDSOg32h0qHwmyDfMV/rytSjohW8F+HnYTFPbEBl2wSe+G/Mu8JUHHJZeWL HH+wXvxboQRP+kfjiYDQMbEjLSTd7k4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696439528; 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:references; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=SSCvTPRp0qW9TRqy5F6Ein1VmoiJ1MENX0jjtGezGCaWU0XuEo2NEmtEXVe3Iscv+ekc05 dYVwuDMQjbub9YuFZ6suR4ftdHaedCqf7wQtLyd32uQ2lUwRINbYGKniJm2ZIygdH4/U+s +hrXVCTULApHnMRbywKBzKUiLzwzu94= Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-536b39daec1so4245827a12.2 for ; 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=q7bU4uHSrqeSY6wjE9GbtlqF1xtTph76c88czMt6Pb93Yz8IVZwZV5FIUjWqRpLXGf jur0g/5xE4PjDCwWMfWIk9REZLHvCK/ozZ+MpeWRKDAAieokl0uazxlAL/gbh/I4j9mI lcGC9U5kKMzlhla9hIZAQXWclcJxJu06Ybj1bfAZcpl7lL5GYINCgT2BCToSqCj5u2ah WsrskB0rILFIzEDjAYHbVyJf+Upb+/h5lb7Imy8fEtfNDujseq5zY9VHrhUi9qnQRBtt PTOHppXKtdFQDuEpKwuPQFb0i4qkZne74SJi/DtrUHN1VbQ/tcdIcHiHdIrPb/S0MJJ7 KdPQ== X-Gm-Message-State: AOJu0Yyt8I+0Y+1fTi2Lp8vSlnYIIWE8rhEvTu9dB3REzTdPynFtdOJA hN+XZZ+FG1vnrl5ZZvFGBnU= X-Google-Smtp-Source: AGHT+IFSa2P2Gwxf/j1Dt3ypULeuCrhYVFeB7pwFaxDrjEa6p1Xue5WukYkOwB88lN0rbcYG+AQzYw== 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9E54840026 X-Stat-Signature: uzjkfffpnh8aahue1p7tpfh69wduy67g X-HE-Tag: 1696439528-532152 X-HE-Meta: U2FsdGVkX18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q+2LY4rekzhKxiGmWGlJdX/9GigALUtPEK3pZv49bENGZC8heZtJmviAQtBRbtojKNvWz7OFGiSlP7FhP/ZpUGS0/qKTgXM7bH4ymRpeVlQ/BVCIpEeWNqSx+avlB7JJBmgBtck5D2Zk5WdRj6Iy77Cl24HusTOmSXYRf7b+CudH6bdRgEzCiRjR4ltMQuJtXGiZiBFvZPGT7ZTCBvLmFgGWqleuYDfIZnxhnHknz+QTA1yhm2vCTK3VxCkYSUEQFkgWUllGrqr7dH5P4XxLY5OEnRuqDI7QXGSaOkoKjtbEMbjpx4lqN0zjqBYKLkaIz2pHhfu9JqaCUeEFGJXsnIZmjAC3B2tnCjH+KLsoBLkcYlkXN7xzXtwAbO5Xflw5ZrNETT+3qgEb78g0B+2f5WRw== 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 --- 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