From patchwork Thu Oct 5 16:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13410434 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 F06FEE7AD45 for ; Thu, 5 Oct 2023 16:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7620A6B02AB; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 739446B02AD; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 564246B02AE; Thu, 5 Oct 2023 12:39:36 -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 498BF6B02AB for ; Thu, 5 Oct 2023 12:39:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0C2B34022A for ; Thu, 5 Oct 2023 16:39:35 +0000 (UTC) X-FDA: 81311968752.29.781E3C7 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf10.hostedemail.com (Postfix) with ESMTP id 2E344C001A for ; Thu, 5 Oct 2023 16:39:32 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696523973; 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; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=UaW6k2BIfc3cwTRWI1GiuRmFWBJUT40VO35ABKz6Ap6kRWmvqBILidPyxJyEla7PcZFNf8 YUipXd2L8JZC/d6GrWszm8XZx6uFn0BZJxPq8RnoulHrq3UOncYDhAxQ4nFVAq9H7HXmAz L8U/3IThYtay33XlXukPC2QKdvpV4rA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf10.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696523973; a=rsa-sha256; cv=none; b=Dfi9wRI/giecKA81RdyrC2q3AtejfUHNqz9hVtP0L217GQbGuJW1daOpuS+sqMLRW7h0lW Au9UWK8t8ki9eCR66gwftt3jNjnw9TUOAzjvzRFntU+tDVaFFh+iKqSuhWBQRTcih+vutb brqXdGTz7CNME5CGx6YGSdZLt6Lxu2s= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-9ad8a822508so235558766b.0 for ; Thu, 05 Oct 2023 09:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696523972; x=1697128772; 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=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=D94jXsS88f+cDXT3TjeJXGn6SLJ7JgTDIPbrB8NCBLvxY9KV9wdmWVAnRz+1k//sxT v3y+s/IhRS+2kaYJ0ReNAYs0JDDCLNELNRcbcTYGvMerHkOMfJbCYcF807yQZDfbJO2O 2Enly6yi6RLGFwjEgDfB1xVJsfJxxG/XWzn1SySZUxUrkABJz02eUZfGHxgic5fZ5ast pXAnEYDeIpD8hsBMBIHksmHMEutmVpBAwTKK24ic94nP2HKwyD8C3WJo45LA620USvzJ JjKMRnbdHbgBjuH4cnSCvFQ5jqMGJxfR4SeCq+P7HA43Bj7GpcjQhqIFpG8bC+6P6X8o GiWw== X-Gm-Message-State: AOJu0Yz+FT9cr7YwX2XORAPEdbKuQqX7S/pRXzZi7H7roANjE6SNo1Qn CQGZmUqQcuJA+6GanI0jnVY= X-Google-Smtp-Source: AGHT+IGYDnp74cV0Byj3XwLIm6spdtkEqH5f+zeVjCF1kcvzcQHqph+sJjv4ryOmfqgXWAqfOPwhPg== X-Received: by 2002:a17:906:2191:b0:9ae:5246:233a with SMTP id 17-20020a170906219100b009ae5246233amr4855817eju.20.1696523971836; Thu, 05 Oct 2023 09:39:31 -0700 (PDT) Received: from localhost (fwdproxy-cln-001.fbsv.net. [2a03:2880:31ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id v24-20020a1709067d9800b009b2c5363ebasm1441273ejo.26.2023.10.05.09.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:39:31 -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 v2 1/2] selftests/mm: export get_free_hugepages() Date: Thu, 5 Oct 2023 09:39:21 -0700 Message-Id: <20231005163922.87568-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005163922.87568-1-leitao@debian.org> References: <20231005163922.87568-1-leitao@debian.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E344C001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: kyfxs9geb773o7aguu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C12J8dZ4ac4jSzZCDSHM/OWjZlmcRl2CnyiWWDPP6z2GF+BrJ9/82IAJcobY7ix7bhxRqYtqP+/DuQlT5tevoryEeAqQYv3F61mH+yCgQzWLBLO4UXT5Xm/mOWThO9ON0ah7C9/pdAb3zudgopBw4JsI26N2go0J8MUxX1fvAs/BPq5ntq5ixo5XK++TyMH5ARbtU6OE2iiB6IJpfSh+4u1mNpW5i04rBtLoGDQMe0ShOdcKneWCi9gFRRBdptrjfpcn8l0i5oSx1GKYHy1bCus0EsX24Yugg0a5zEF4QlzN+GPDuuodqq5CgTugilrqqNiM0Zwpg+1cHZeROPuYBR0UUvxDX/NzK69v/17IfhLzPfPm1tu4ectJOFm8uoUol4Y967QdooAE3PI7NP0Y7u52Re7jj9M9PeugcaJDoviqWZ+6oqER8+ft6c5DYB1QdFCIyyd1CDbmxNQ== 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 Reviewed-by: Rik van Riel --- 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 From patchwork Thu Oct 5 16:39:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13410435 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 4315AE71D4F for ; Thu, 5 Oct 2023 16:39:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C942C6B02AD; Thu, 5 Oct 2023 12:39:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1B716B02AE; Thu, 5 Oct 2023 12:39:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABD766B02AF; Thu, 5 Oct 2023 12:39:38 -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 9AD816B02AD for ; Thu, 5 Oct 2023 12:39:38 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7D63DB40A2 for ; Thu, 5 Oct 2023 16:39:38 +0000 (UTC) X-FDA: 81311968836.02.91EC3E5 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf06.hostedemail.com (Postfix) with ESMTP id 80DD6180018 for ; Thu, 5 Oct 2023 16:39:36 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.53 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=1696523976; 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; bh=aeCkyhaoVtwv2wfDF/uieHTmRe6erji0RQ2H7V1G/pc=; b=OGqAW9ZZCWijtzyDB88IDo5bwFJfNu9eR+g5CYPRU+zQp6DIikdQ6tdODJSScAiiVCM0tS Pk3nTMhXxg+uV3HNYlpBSfla3Dxc/PkcgLCGDVzWAML5gxA/nL1ONdgBEruakezJUY2GCx Q6BkuCHc7skBUanFLHgHAQytLmblzk8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696523976; a=rsa-sha256; cv=none; b=egcZ9qUdarQzGkiabR8sxRHjqFXckEp99jiMAHZvFY29Rsel/SZO8C9KKVt0XOO/jg1Qlf 837PZEYl3NZzw/etLKZX/BWTcTJ5uYExlVh0mUZIACPhdXBNzSUSkkG3vmb4Bzbj833Vap /Na0MpRtRtOOaynVfvik9raqiVMTefE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-9b29186e20aso209563466b.2 for ; Thu, 05 Oct 2023 09:39:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696523975; x=1697128775; 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=aeCkyhaoVtwv2wfDF/uieHTmRe6erji0RQ2H7V1G/pc=; b=b9jkF/14OaCyUNub8zEpNoaKbyqHY1Wbv+G8SbLV85Xdjj9mML9wrslFZRbucUpyeZ N8GrkTGnWJ73nPYdJ5PWtdo+fFzcgapGSaF36WDbrV/fF+JZlwWoDScg5i6AQoJgHFhq hKsQ1lUixnKOr10gBh2GsfHsJDC1O3fv0TzSfDyW+fCdAx+tjdoBdkW4dbu0L/0GCwNm 340OHFO80wDOYUnW2EXjPuW6ukCKMI7p1Y1GxieW52VSLO+uqwmjS25PiBAQsIyvoA3W aUkbMB7N3aHRWdnXCFvJhu1Xqm4wt4HbFXFPX91bwVca7HZ6E5ia3O5690twdgfG54g6 +kTg== X-Gm-Message-State: AOJu0YxeE6RJBjVaO77W4OH8TBL9v6mQKExmXZiX0Ti/v6lPqSqVjrju 7LuK6oSwK9D9jHxyEocU9Ic= X-Google-Smtp-Source: AGHT+IFXpAGpAAJi5gJLJd/ylndngGVZYM9m0IP6Ma0EXz8nnBppGgbm8KmKKvk2XKyTTj6Y5Uz/ww== X-Received: by 2002:a17:906:cc2:b0:9ae:5db5:149 with SMTP id l2-20020a1709060cc200b009ae5db50149mr5073326ejh.35.1696523974869; Thu, 05 Oct 2023 09:39:34 -0700 (PDT) Received: from localhost (fwdproxy-cln-021.fbsv.net. [2a03:2880:31ff:15::face:b00c]) by smtp.gmail.com with ESMTPSA id w13-20020a170906480d00b0099b76c3041csm1447289ejq.7.2023.10.05.09.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:39:34 -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-kernel@vger.kernel.org (open list), linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK) Subject: [PATCH v2 2/2] selftests/mm: Add a new test for madv and hugetlb Date: Thu, 5 Oct 2023 09:39:22 -0700 Message-Id: <20231005163922.87568-3-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231005163922.87568-1-leitao@debian.org> References: <20231005163922.87568-1-leitao@debian.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 80DD6180018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zzbny5eixbj66pdxi81iuujykx3eiqoq X-HE-Tag: 1696523976-662783 X-HE-Meta: U2FsdGVkX1/BNtwN+F8Ni3p+RxJKwNsNYv/rSYU2h6gb6dwvRG9TUcrDZ/dGkpDGD3t48PuyK6v1bXMyKvNCCkkwizvZbaxQEXc2FVehD+IS7Gn95NRSjmCCc9c0YGnjnyWHePHCBG8pCX5fZmUTtQHr1ZK8RkfIZOGh+VKc1bdGGSNgBlgof3JWvOSeb8haH7Gk8COyAJrxZ5dqUe2jv5c5gKxI4XgQygnJwwMe26AOgLPeXcSkeQgF2245xv+Ar1rZiYfKaOVmg0ccUviXthjovj+YkWxrK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qc+Xtsa20peKeMgCXsCWv7ymuuJod72KYTwvrIv4xO8GkA6XEBLc9mzKur20XVRGvF8J0UyLFnbT+c2aoCxfP7Iax/6oCmjynWaZyHXs2DWBIre9nhv4QE+h7g2NBhyT9BRJu75+YvmbA7UmzhbuIRRRyxuzL7csshpeo92yMjvGMkmLQGBUYLI+V2fEYo88lp0lqDZ0IVvgj1+VRH6eMSStA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Create a selftest that exercises the race between page faults and madvise(MADV_DONTNEED) in the same huge page. Do it by running two threads that touches the huge page and madvise(MADV_DONTNEED) at the same time. In case of a SIGBUS coming at pagefault, the test should fail, since we hit the bug. The test doesn't have a signal handler, and if it fails, it fails like the following ---------------------------------- running ./hugetlb_fault_after_madv ---------------------------------- ./run_vmtests.sh: line 186: 595563 Bus error (core dumped) "$@" [FAIL] This selftest goes together with the fix of the bug[1] itself. [1] https://lore.kernel.org/all/20231001005659.2185316-1-riel@surriel.com/#r Signed-off-by: Breno Leitao --- tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb_fault_after_madv.c | 73 +++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 3 files changed, 78 insertions(+) create mode 100644 tools/testing/selftests/mm/hugetlb_fault_after_madv.c diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 6a9fc5693145..e71ec9910c62 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -68,6 +68,7 @@ TEST_GEN_FILES += split_huge_page_test TEST_GEN_FILES += ksm_tests TEST_GEN_FILES += ksm_functional_tests TEST_GEN_FILES += mdwe_test +TEST_GEN_FILES += hugetlb_fault_after_madv ifneq ($(ARCH),arm64) TEST_GEN_PROGS += soft-dirty diff --git a/tools/testing/selftests/mm/hugetlb_fault_after_madv.c b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c new file mode 100644 index 000000000000..73b81c632366 --- /dev/null +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include + +#include "vm_util.h" +#include "../kselftest.h" + +#define MMAP_SIZE (1 << 21) +#define INLOOP_ITER 100 + +char *huge_ptr; + +/* Touch the memory while it is being madvised() */ +void *touch(void *unused) +{ + char *ptr = (char *)huge_ptr; + + for (int i = 0; i < INLOOP_ITER; i++) + ptr[0] = '.'; + + return NULL; +} + +void *madv(void *unused) +{ + usleep(rand() % 10); + + for (int i = 0; i < INLOOP_ITER; i++) + madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED); + + return NULL; +} + +int main(void) +{ + unsigned long free_hugepages; + pthread_t thread1, thread2; + /* + * On kernel 6.4, we are able to reproduce the problem with ~1000 + * interactions + */ + int max = 10000; + + srand(getpid()); + + free_hugepages = get_free_hugepages(); + if (free_hugepages != 1) { + ksft_exit_skip("This test needs one and only one page to execute. Got %lu\n", + free_hugepages); + } + + while (max--) { + huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, + -1, 0); + + if ((unsigned long)huge_ptr == -1) + ksft_exit_skip("Failed to allocated huge page\n"); + + pthread_create(&thread1, NULL, madv, NULL); + pthread_create(&thread2, NULL, touch, NULL); + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + munmap(huge_ptr, MMAP_SIZE); + } + + return KSFT_PASS; +} diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 3e2bc818d566..9f53f7318a38 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -221,6 +221,10 @@ CATEGORY="hugetlb" run_test ./hugepage-mremap CATEGORY="hugetlb" run_test ./hugepage-vmemmap CATEGORY="hugetlb" run_test ./hugetlb-madvise +# For this test, we need one and just one huge page +echo 1 > /proc/sys/vm/nr_hugepages +CATEGORY="hugetlb" run_test ./hugetlb_fault_after_madv + if test_selected "hugetlb"; then echo "NOTE: These hugetlb tests provide minimal coverage. Use" echo " https://github.com/libhugetlbfs/libhugetlbfs.git for"