From patchwork Thu Mar 30 16:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13194488 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 222EAC761A6 for ; Thu, 30 Mar 2023 16:07:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 802326B007E; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B2E66B0080; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 655C16B0081; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 559D06B007E for ; Thu, 30 Mar 2023 12:07:18 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 1A195A08DD for ; Thu, 30 Mar 2023 16:07:18 +0000 (UTC) X-FDA: 80626044156.27.D70AF93 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id B106E4001C for ; Thu, 30 Mar 2023 16:07:15 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KUGHufjb; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@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=1680192435; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=ShbSo1jokkUTGbK6RISl2ZvtyCvut2fmBbWTLzhasqHFiUp45hJ8AcK+GgIQ4IXiAA9P8J 0WLZOPK3sCX10aoATw0ZVb5sD0K2BLh0qHn6ivAETJsUJ4SdwdQzbyPgndQ63I+sBjctQp ZTNIHrD1QwYDqOMgfBkm19czKpJ0/2I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KUGHufjb; spf=pass (imf12.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680192435; a=rsa-sha256; cv=none; b=fGU5jE3+J1hqB4GaaNpi/mervsQxy7INH1oumP5LDBo/y1elkK96YovAvcLiZ00GJ8xo2J qttNxanvggnBikb5oHeMJm5XgJHkYVhtY1KRR9JroNa0atYYe8YD05oTbxHg3mwET8+QaD ZZFZl6M0/l5CD1X2J2phb6+1MrNjnyU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680192435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=KUGHufjbz12DD9DKVFtYSGkI3e7xTAsGheCkUeYmsZc+DJUOmGCBu1TwsGs6Ay8eSN+F9x aho0VhlfItLo8kPsXyMU1o+mwQgAhjMgwst/1M+R/6LOjj+lsnhvaSZkxQcZRw5+w9IVvV MWOz+nx1mR5tg8A2N4NbIR26S2vLCII= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-fgSrd5RmO-u7cBx9InYHlQ-1; Thu, 30 Mar 2023 12:07:13 -0400 X-MC-Unique: fgSrd5RmO-u7cBx9InYHlQ-1 Received: by mail-qk1-f200.google.com with SMTP id c186-20020a379ac3000000b007484744a472so8807274qke.22 for ; Thu, 30 Mar 2023 09:07:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680192428; 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=3OY41FoDSXIz8Px4DR5ueHfK5qhzGwiU30swTtCORuo=; b=7sXwHgQS3JlX2Qi+3IXT+O/OlbquewYvduSuXIMZZicdZl7/S4Scp8EtlcSgoZGmqo l88yc4fWYPNRflReCCQaguq/CzJGdK9J96mJ8F5fXAaITmlsRFbQ8xkX6I3u5e4tAzE8 gpQDkCKmAMJFWBebDUqCAxtU/Yo/pYkxR/8JG3XDE8VxFdiwbWw0cbincKOA0unp1suH +zDVW4wtpHDrIVENl+bYl41lVI8aQcOd9TqUpGD8aLDC98VaVuCFkbS/FMqUm1JHSieP 2yQfDH+bVexpWShfp8yzUI5TfjsFNfX6AuREUVKGKugx8Iw03DsvxtrxYue7d7kSfm+r OKBA== X-Gm-Message-State: AAQBX9fSOIO6eYD/CYQLwtsnLfYBvWLGe22r6SHPhaarEAtbZkDuObgp 4XChtHlLw5V+7PbBYta+y9TX6mY9118Pjge8smJGjjeKb3yK77e5NwR3KsaIF9QQ++unE3k5xq1 HfZIOCm333E2m4goYHVb7PKtzouGkErDhFVlxwiCYcwtnxsfLKk7tx6+M+wfh6XAzqwvp X-Received: by 2002:a05:6214:5090:b0:532:141d:3750 with SMTP id kk16-20020a056214509000b00532141d3750mr3688762qvb.2.1680192428362; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) X-Google-Smtp-Source: AKy350Ys6fX7rmt9YD/vVT9J8araJkwcE6MiBOgwawHwu2UT8IpOsYcMasH6fyTBBFlM3DCctSA8FA== X-Received: by 2002:a05:6214:5090:b0:532:141d:3750 with SMTP id kk16-20020a056214509000b00532141d3750mr3688715qvb.2.1680192428056; Thu, 30 Mar 2023 09:07:08 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-40-70-52-229-124.dsl.bell.ca. [70.52.229.124]) by smtp.gmail.com with ESMTPSA id r6-20020a0cf806000000b005dd8b93457asm5582136qvn.18.2023.03.30.09.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 09:07:07 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Andrew Morton , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen , Mike Kravetz , Leonardo Bras Soares Passos , Mike Rapoport , Nadav Amit Subject: [PATCH 07/29] selftests/mm: Merge default_huge_page_size() into one Date: Thu, 30 Mar 2023 12:07:05 -0400 Message-Id: <20230330160705.3106966-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230330155707.3106228-1-peterx@redhat.com> References: <20230330155707.3106228-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: wfa5uudmukymsbx7fzyrnrhh45e76468 X-Rspamd-Queue-Id: B106E4001C X-HE-Tag: 1680192435-164279 X-HE-Meta: U2FsdGVkX1+Fv7W3Xp028Byp03wTiGXroPhtcr1xvUy/w6c4uqIxPKAH97z4zTkvWfVEgKveFcJcH1ENdsXyHnQ4g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OzovAr0ivRaK133LSNuJFYdtkIwqnucPdIE4TbHQ96Sy+Tz1Vz0Dt/KX0aqXBnS5DSY6qazZf+Ke4yvDZBYmEbur58qc4yKCjhvJQzTHspnsyvuau4F46bxb0CJJtnjV9mLHYFg9o9AN0KaKuFISLv9gMryvXgl+XREb3OCu5PLnWwYcbYDmRrYGQwjGLvvaOzCi2X2EX5Aeg31CEsScYcRnXwLvzdS0u/+H1kRWVVNPmHjW2MM73bL7vjXe1I8ulPDHQMaXBnp8OXVdTMtSsXgIVHSEwJQfPfE46u5iNAPQk+NRH8eYDoiCl9WcviGdSEcUmltYFPz2UwSdHWDTJZSjWr6vDdAI1q2Uk= 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: There're already 3 same definitions of the three functions. Move it into vm_util.[ch]. Signed-off-by: Peter Xu Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) --- tools/testing/selftests/mm/hugetlb-madvise.c | 25 +------------------- tools/testing/selftests/mm/thuge-gen.c | 19 +-------------- tools/testing/selftests/mm/userfaultfd.c | 24 ------------------- tools/testing/selftests/mm/vm_util.c | 21 ++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 5 files changed, 24 insertions(+), 66 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c index 9a127a8fe176..28426e30d9bc 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -18,6 +18,7 @@ #include #include #include +#include "vm_util.h" #define MIN_FREE_PAGES 20 #define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */ @@ -35,30 +36,6 @@ unsigned long huge_page_size; unsigned long base_page_size; -/* - * default_huge_page_size copied from mlock2-tests.c - */ -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - unsigned long get_free_hugepages(void) { unsigned long fhp = 0; diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c index 361ef7192cc6..380ab5f0a534 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -24,6 +24,7 @@ #include #include #include +#include "vm_util.h" #define err(x) perror(x), exit(1) @@ -74,24 +75,6 @@ void find_pagesizes(void) globfree(&g); } -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - free(line); - return hps; -} - void show(unsigned long ps) { char buf[100]; diff --git a/tools/testing/selftests/mm/userfaultfd.c b/tools/testing/selftests/mm/userfaultfd.c index a96d126cb40e..4cc80a0e8955 100644 --- a/tools/testing/selftests/mm/userfaultfd.c +++ b/tools/testing/selftests/mm/userfaultfd.c @@ -1703,30 +1703,6 @@ static int userfaultfd_stress(void) || userfaultfd_events_test() || userfaultfd_minor_test(); } -/* - * Copied from mlock2-tests.c - */ -unsigned long default_huge_page_size(void) -{ - unsigned long hps = 0; - char *line = NULL; - size_t linelen = 0; - FILE *f = fopen("/proc/meminfo", "r"); - - if (!f) - return 0; - while (getline(&line, &linelen, f) > 0) { - if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { - hps <<= 10; - break; - } - } - - free(line); - fclose(f); - return hps; -} - static void set_test_type(const char *type) { if (!strcmp(type, "anon")) { diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 0204c469be43..12dc654b5be3 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -180,3 +180,24 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd) return -1; } + +unsigned long default_huge_page_size(void) +{ + unsigned long hps = 0; + char *line = NULL; + size_t linelen = 0; + FILE *f = fopen("/proc/meminfo", "r"); + + if (!f) + return 0; + while (getline(&line, &linelen, f) > 0) { + if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) { + hps <<= 10; + break; + } + } + + free(line); + fclose(f); + return hps; +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 6edeb531afc6..d7163fff8fb7 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -35,6 +35,7 @@ bool check_huge_anon(void *addr, int nr_hpages, uint64_t hpage_size); 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); /* * On ppc64 this will only work with radix 2M hugepage size