From patchwork Wed Apr 12 16:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13209343 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 006DFC77B6F for ; Wed, 12 Apr 2023 16:42:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91D7F280003; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A557280001; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7465E280003; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 62886280001 for ; Wed, 12 Apr 2023 12:42:32 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 152BF12019B for ; Wed, 12 Apr 2023 16:42:32 +0000 (UTC) X-FDA: 80673307344.19.EED080A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id DD1164000F for ; Wed, 12 Apr 2023 16:42:29 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRLdUtfW; spf=pass (imf11.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=1681317750; 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=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=SENw2cL51uuomjQbVtae7py0A3K4znJDZSNtD/27ojlridTJmdLkJFwB+bgSQn/dOcppg3 29mALe2aOQwdWYecpbVXmzt+PFV1Oqysm/dSrHo6edP/4axN5fXe55FVthqPWQAEoX+m0a v8XvFSMpx0i9JAokcNjiALYofBdzjsg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TRLdUtfW; spf=pass (imf11.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=1681317750; a=rsa-sha256; cv=none; b=HawW3jnH/uU4x7pKYuM2x8KIITGflTMRUQh6fWhtreKTJpHfc4M2lj80kSp6IcvnTESCoN H2rJ8cMFDcFEJbY+LmjmiEa0sErJtKkBoKEapZisHYyuBzVqFD7/DFXMrLN3RsqTJNhcON MvJbxg0SOiIgUIxV9bfq2Zor1l7Wi4w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681317749; 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=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=TRLdUtfWznFfy8alUCMg8n4Bghq2QDBoZc1DHsQmlJtqmkWf1NSF+lqmUBjS+3rodHs9q8 hOomwb8+NM8R2VG2LAarKJ1NT9cQwQeCe5HWjgZAuducmwxyEH99sJy42NUi8ew9mPQbcU ZIVGib4d47jDVoWdQPepf1q5WzzTGQ4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-296-nKj9ndCpPki6pFLRDWg3sQ-1; Wed, 12 Apr 2023 12:42:28 -0400 X-MC-Unique: nKj9ndCpPki6pFLRDWg3sQ-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74a25fcda05so77595985a.1 for ; Wed, 12 Apr 2023 09:42:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681317747; x=1683909747; 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=9w4FTeM4b1xfAgG4y96DPCrYEWea1Mc83v+smBNR1Gs=; b=ScZIQWoKVl/H2GThl0rZbyM1oaJ2+W0Dz/D84MIpwQKgE2Exs+rg8XjRdWoivcrr67 NpIDbaq4ltBpUWqt3sYhtvBxWoUIVar76mUzztap78nF9SsNlhUMWqjLoaFQy9yGOdrI P4RRKT4qJebnIb1V9nZBeyo9pRYfDS6hPVELH3alkGNFz14hHX2TPay7d6JEy0LJgZyy txE+wgWZUgJwsjdsFK1GZGK8FZyyON3W4wUlcjq/z6bWBrXq0DCOhIXqM2hbvxwFXmmz BanI8df+hIBPEqVBW/wMfWwi3/mH+eJfCsLXZPpGhySsorYFITUwc2AZxkzP/v8nYdEF mkvA== X-Gm-Message-State: AAQBX9fPjry1re8zL1xeJtWXvElXLkfvMIjyQ6s9E6EWITLDF6WmFF36 eOqMgt+4mj/JYJ1jVQu9VL7zASf+pXPhAJDWdTQTG3e7naf56cH+9Q8Y43/NmsIYyjyt55sLm1P wWABoHHc3az/zcxidoL8= X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5012771qta.0.1681317747115; Wed, 12 Apr 2023 09:42:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YVvSHn+CiNqMbEanS4Hm6vnJ4+dDPCuFu7aqhBaI35sD13aR8Lht4vPI828Te9foEW+WzjQg== X-Received: by 2002:ac8:5cc8:0:b0:3e6:707e:d3b1 with SMTP id s8-20020ac85cc8000000b003e6707ed3b1mr5012723qta.0.1681317746702; Wed, 12 Apr 2023 09:42:26 -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 c24-20020ac85198000000b003e3c23dd2cfsm4353889qtn.84.2023.04.12.09.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 09:42:25 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Andrea Arcangeli , Mike Kravetz , Nadav Amit , David Hildenbrand , Mike Rapoport , Axel Rasmussen , Leonardo Bras Soares Passos , peterx@redhat.com, Mike Rapoport Subject: [PATCH v2 07/31] selftests/mm: Merge default_huge_page_size() into one Date: Wed, 12 Apr 2023 12:42:23 -0400 Message-Id: <20230412164223.328134-1-peterx@redhat.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230412163922.327282-1-peterx@redhat.com> References: <20230412163922.327282-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: utsyhykkdwy59en5cyy6tdtecydbmuwh X-Rspamd-Queue-Id: DD1164000F X-HE-Tag: 1681317749-466198 X-HE-Meta: U2FsdGVkX19ABWDiKI1K7unG0r1rz83ieaui9wvImLZNd26RnBuPOx/mX0ZCpLtllVZrYPA76h97CR+gXHC8Zmqofzp1WM+0o9DnvlguiKCTEDDk52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+e5tFqpbPgyG4Y7vxZ2GZDcQcO3JGy8k+Oi2aVu1p2lp/HOeqG5sLGITgDl2MBALH8HEQg3OhMOxzZ4IMcigduVa80YD47cevfH7zL/1MBSWBfAwWgcUFWOrgrlb2eXdlgF8sKyDLN9S0z6fWeMpWBm9waxn3ok90Ka6hrODnvkM6fBqoW8EL/fC/4K9Elq0a45de44hTHFbkxVZTUFPbllHK2QJWFmBfO46VfmnQblBCUVdEFYjJ8Lgh0O+IFFkUZ5fxZeGeOXbS9VvRBE18X2ILKJ3+/fUjn207qQYP+aq4SsFdHMHQWZ/fpcCiVoYqmupyTx0TtDwoXSescMuDy9a3nBa0Kg98r0FAxtcUGZH2InpO4Xy47MrC6x7f18wj+pVoPPJdbQI0GvITVuGJ6LZHbc4m2PzYq3FBevnkkULaGxCBnLjtmuymMxYyx 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]. Reviewed-by: Axel Rasmussen Reviewed-by: Mike Kravetz Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Peter Xu --- 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 85411ee7ff8b..7ffad87aa7e8 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