From patchwork Fri May 19 10:27:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13248151 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 C8CBEC77B7F for ; Fri, 19 May 2023 10:27:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EFC2280001; Fri, 19 May 2023 06:27:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DFD0900004; Fri, 19 May 2023 06:27:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 180E8280001; Fri, 19 May 2023 06:27:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 04CC6900003 for ; Fri, 19 May 2023 06:27:35 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A87371A0A14 for ; Fri, 19 May 2023 10:27:34 +0000 (UTC) X-FDA: 80806628028.29.FC1E151 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id B42C72000F for ; Fri, 19 May 2023 10:27:32 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Mzsq6O/H"; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684492053; a=rsa-sha256; cv=none; b=S6z3cvtymVUC2wGFtE2Xb/SNXOtzzgG1WqZC6h2oR4dkuBMmq4YshKAZr7VZmTDVk35kid +MUrcVN1AhhsCYOVWB8/5JpHt7d3E2BiwJwWGnUfgEfq7Oq+kyFDnLikm5BicvD/E2wUxD y2CXO4rZlUwAoLT90VAblr9Xze7lR7k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Mzsq6O/H"; spf=pass (imf13.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684492053; 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:dkim-signature; bh=wLvUTdqG6kUaomJpPJAHiks49sHH2kzed8PToxtufB8=; b=f9yefkpwNhnfNNKLlmSD0IEUhanhDqqF7HLVAizfgSrmH/Z7CY0YekfYILMgKpjdKIny9a qFyk5cxGa4cYgx9XkVc9JJt8ShsjxwfltkNQiuB5nmytNOl01Itor0SWS3+YkLAJqajdIg qfRMTJNeltUZyqSVPXjrbT+Eu8jIICk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684492052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wLvUTdqG6kUaomJpPJAHiks49sHH2kzed8PToxtufB8=; b=Mzsq6O/HoSRdTWA6T1sXSFedcSUiob02WxM6T+VET/5Fm7KpOrSWjd2If+2n4rzuJ4dGSG bchTZH5BXhMI1fOnzyspNagyzqORQvh1mCwsyujzHdlwoT9nbzZ+YYr2BTznaKkzIVmJYJ TAM3dHHVZFm98NwAgBePGd6WEGwWYvU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-9-9sijunIrNxO-3wCpyPKkqg-1; Fri, 19 May 2023 06:27:30 -0400 X-MC-Unique: 9sijunIrNxO-3wCpyPKkqg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 172C7185A792; Fri, 19 May 2023 10:27:30 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA9222166B25; Fri, 19 May 2023 10:27:26 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, David Hildenbrand , Andrew Morton , Shuah Khan , Lorenzo Stoakes , Jens Axboe , Peter Xu , Jason Gunthorpe , John Hubbard , Jan Kara Subject: [PATCH v1 1/3] selftests/mm: factor out detection of hugetlb page sizes into vm_util Date: Fri, 19 May 2023 12:27:21 +0200 Message-Id: <20230519102723.185721-2-david@redhat.com> In-Reply-To: <20230519102723.185721-1-david@redhat.com> References: <20230519102723.185721-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B42C72000F X-Stat-Signature: powp5hcz4xtjuof4qsbj7yrnjoms5o8n X-Rspam-User: X-HE-Tag: 1684492052-163075 X-HE-Meta: U2FsdGVkX1/pQEXYuMvNACeHbT0hxbciawNpsddpy/6uDv2ReGFC3mypy4ajI6LDzmA9Znh76i+uMtHdYWvi8ZGCsNHOpgXvYjy1SXQ6NWgidkA1bRv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y+wUlt+ssu83flHIhWTfUg6tk7MD8gYDzLusXCG 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: Let's factor detection out into vm_util, to be reused by a new test. Signed-off-by: David Hildenbrand Reviewed-by: Lorenzo Stoakes --- tools/testing/selftests/mm/cow.c | 29 ++-------------------------- tools/testing/selftests/mm/vm_util.c | 27 ++++++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index dc9d6fe86028..7f3b620d9cb7 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -70,31 +69,6 @@ static void detect_huge_zeropage(void) close(fd); } -static void detect_hugetlbsizes(void) -{ - DIR *dir = opendir("/sys/kernel/mm/hugepages/"); - - if (!dir) - return; - - while (nr_hugetlbsizes < ARRAY_SIZE(hugetlbsizes)) { - struct dirent *entry = readdir(dir); - size_t kb; - - if (!entry) - break; - if (entry->d_type != DT_DIR) - continue; - if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1) - continue; - hugetlbsizes[nr_hugetlbsizes] = kb * 1024; - nr_hugetlbsizes++; - ksft_print_msg("[INFO] detected hugetlb size: %zu KiB\n", - kb); - } - closedir(dir); -} - static bool range_is_swapped(void *addr, size_t size) { for (; size; addr += pagesize, size -= pagesize) @@ -1717,7 +1691,8 @@ int main(int argc, char **argv) if (thpsize) ksft_print_msg("[INFO] detected THP size: %zu KiB\n", thpsize / 1024); - detect_hugetlbsizes(); + nr_hugetlbsizes = detect_hugetlb_page_sizes(hugetlbsizes, + ARRAY_SIZE(hugetlbsizes)); detect_huge_zeropage(); ksft_print_header(); diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 9b06a5034808..5cf84d860076 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -198,6 +199,32 @@ unsigned long default_huge_page_size(void) return hps; } +int detect_hugetlb_page_sizes(size_t sizes[], int max) +{ + DIR *dir = opendir("/sys/kernel/mm/hugepages/"); + int count = 0; + + if (!dir) + return 0; + + while (count < max) { + struct dirent *entry = readdir(dir); + size_t kb; + + if (!entry) + break; + if (entry->d_type != DT_DIR) + continue; + if (sscanf(entry->d_name, "hugepages-%zukB", &kb) != 1) + continue; + sizes[count++] = kb * 1024; + ksft_print_msg("[INFO] detected hugetlb page size: %zu KiB\n", + kb); + } + closedir(dir); + return count; +} + /* If `ioctls' non-NULL, the allowed ioctls will be returned into the var */ int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls) diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index b950bd16083a..99b795528716 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -44,6 +44,7 @@ bool check_huge_file(void *addr, int nr_hpages, uint64_t hpage_size); bool check_huge_shmem(void *addr, int nr_hpages, uint64_t hpage_size); int64_t allocate_transhuge(void *ptr, int pagemap_fd); unsigned long default_huge_page_size(void); +int detect_hugetlb_page_sizes(size_t sizes[], int max); int uffd_register(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor);