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: 96369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1133155vqo; Fri, 19 May 2023 03:41:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7d1YfrLBTeEKcqgk3/A8Wxy8cPwtTBGJpwfsPZ6YT0RbI0nZXOW8JZrJs7jG+4i7V5hfXa X-Received: by 2002:a05:6a20:914c:b0:100:6863:8be7 with SMTP id x12-20020a056a20914c00b0010068638be7mr1700017pzc.62.1684492866449; Fri, 19 May 2023 03:41:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684492866; cv=none; d=google.com; s=arc-20160816; b=bIGaG8KoqZ+uhELMxKiaeCv7bCzQitmNMXQlazLwMXCDQqUUP3Jdci+D+MQY3rhKIC 2WOu5kbXMe1XPlClpPj3bjpIco5qtLN1T9jEmC5OG08caULBPqem+MhVxxQxhmmJooPq mMkqPsXgpWEzFQKxRoHRITamTIAjGfUV/OSgbDfqPYR/UMISFtEcOafzJkC8YHgnVOsg b14MD32mrfccd3Oj6OoeocGG7UBCmatuQDrFFjbDa/IecLQLC4qWbe7RYM+rOFKiaDde E8cv96/0i09Kx8k+kMfGhaMEWA2iTRczNqQqaWIbLnExAzLQuDxILUGCkYurNIZXlxka wFug== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wLvUTdqG6kUaomJpPJAHiks49sHH2kzed8PToxtufB8=; b=qUrHj0w9upAQGVJ0u4LRlv+qE9cCuDS+g+S93d5GFWIGv9hSsc9ZzROUrZNC8zSftX G0eMdFUT6cCZRd3K/ujm4DII07t60DUyglMqd/4+1/mUAheynMj7VcyncZ1xxJ1z8xSo GyGhstH/CYHiJEmCixGYmi4hmNgZverxOyW3cSndF0CYQBuuKn7cWYsDNGmIyvWKDf0v JWAdxB2rEjqhA1waEGq8H1OimKgOxBS6yimZ8+KdbMDth+eX4dGkrLlRHxq2kZepTdoG QIeOsYwsyOcK+j4oLoULfF1hnUOnuTXDDo0HP/QCfSoTIyGepGg+UqnkG9uqU+K+crhJ 2kRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gv5vF6Pt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s22-20020a17090ad49600b002498408b1c5si1599757pju.39.2023.05.19.03.40.50; Fri, 19 May 2023 03:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gv5vF6Pt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231603AbjESK2R (ORCPT + 99 others); Fri, 19 May 2023 06:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbjESK2P (ORCPT ); Fri, 19 May 2023 06:28:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7582E6E for ; Fri, 19 May 2023 03:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684492053; 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=gv5vF6Ptj7/8B1R0r3gW7sJUT2xhLEgkZs5xKEwQZbgqqlVJnF4C4kWltrV95DzuA1yV15 vs/bkbBdE8H1QPxt+vRcZYUj6rDioQ9pkDvn/QGXI+xdv6b5jZvAcJHb/wN1K4+23G5v8z gdNUOGtBxvzbyiO3LfZkzSB0fkG3Sck= 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766318791779113333?= X-GMAIL-MSGID: =?utf-8?q?1766318791779113333?= 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);