From patchwork Wed Oct 4 17:11:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13409090 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 C686AE7C4E2 for ; Wed, 4 Oct 2023 17:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E2E36B02B1; Wed, 4 Oct 2023 13:12:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06BB46B02B2; Wed, 4 Oct 2023 13:12:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4E176B02B3; Wed, 4 Oct 2023 13:12:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D18FF6B02B1 for ; Wed, 4 Oct 2023 13:12:10 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9EB171401E6 for ; Wed, 4 Oct 2023 17:12:10 +0000 (UTC) X-FDA: 81308422020.13.4AAA458 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf17.hostedemail.com (Postfix) with ESMTP id 9E54840026 for ; Wed, 4 Oct 2023 17:12:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=breno.debian@gmail.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696439528; a=rsa-sha256; cv=none; b=71X1qhpCyXxBfYindcnNs0NIucL6YuN+VvjRMCHsaT08WpZt6qXtykvP6wja/CebP5dJKz Xbf3sN2cse1DDSOg32h0qHwmyDfMV/rytSjohW8F+HnYTFPbEBl2wSe+G/Mu8JUHHJZeWL HH+wXvxboQRP+kfjiYDQMbEjLSTd7k4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.43 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=1696439528; 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:references; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=SSCvTPRp0qW9TRqy5F6Ein1VmoiJ1MENX0jjtGezGCaWU0XuEo2NEmtEXVe3Iscv+ekc05 dYVwuDMQjbub9YuFZ6suR4ftdHaedCqf7wQtLyd32uQ2lUwRINbYGKniJm2ZIygdH4/U+s +hrXVCTULApHnMRbywKBzKUiLzwzu94= Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-536b39daec1so4245827a12.2 for ; Wed, 04 Oct 2023 10:12:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696439527; x=1697044327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CXe2b1SQetsxvQIMHBxAgfGGNR39eEXqqOWXi1pgTdY=; b=q7bU4uHSrqeSY6wjE9GbtlqF1xtTph76c88czMt6Pb93Yz8IVZwZV5FIUjWqRpLXGf jur0g/5xE4PjDCwWMfWIk9REZLHvCK/ozZ+MpeWRKDAAieokl0uazxlAL/gbh/I4j9mI lcGC9U5kKMzlhla9hIZAQXWclcJxJu06Ybj1bfAZcpl7lL5GYINCgT2BCToSqCj5u2ah WsrskB0rILFIzEDjAYHbVyJf+Upb+/h5lb7Imy8fEtfNDujseq5zY9VHrhUi9qnQRBtt PTOHppXKtdFQDuEpKwuPQFb0i4qkZne74SJi/DtrUHN1VbQ/tcdIcHiHdIrPb/S0MJJ7 KdPQ== X-Gm-Message-State: AOJu0Yyt8I+0Y+1fTi2Lp8vSlnYIIWE8rhEvTu9dB3REzTdPynFtdOJA hN+XZZ+FG1vnrl5ZZvFGBnU= X-Google-Smtp-Source: AGHT+IFSa2P2Gwxf/j1Dt3ypULeuCrhYVFeB7pwFaxDrjEa6p1Xue5WukYkOwB88lN0rbcYG+AQzYw== X-Received: by 2002:a17:906:5357:b0:9ae:7681:f62a with SMTP id j23-20020a170906535700b009ae7681f62amr3072085ejo.44.1696439527012; Wed, 04 Oct 2023 10:12:07 -0700 (PDT) Received: from localhost (fwdproxy-cln-006.fbsv.net. [2a03:2880:31ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id z25-20020a1709067e5900b0099bccb03eadsm3064093ejr.205.2023.10.04.10.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 10:12:06 -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 1/2] selftests/mm: export get_free_hugepages() Date: Wed, 4 Oct 2023 10:11:25 -0700 Message-Id: <20231004171127.106056-1-leitao@debian.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9E54840026 X-Stat-Signature: uzjkfffpnh8aahue1p7tpfh69wduy67g X-HE-Tag: 1696439528-532152 X-HE-Meta: U2FsdGVkX18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q+2LY4rekzhKxiGmWGlJdX/9GigALUtPEK3pZv49bENGZC8heZtJmviAQtBRbtojKNvWz7OFGiSlP7FhP/ZpUGS0/qKTgXM7bH4ymRpeVlQ/BVCIpEeWNqSx+avlB7JJBmgBtck5D2Zk5WdRj6Iy77Cl24HusTOmSXYRf7b+CudH6bdRgEzCiRjR4ltMQuJtXGiZiBFvZPGT7ZTCBvLmFgGWqleuYDfIZnxhnHknz+QTA1yhm2vCTK3VxCkYSUEQFkgWUllGrqr7dH5P4XxLY5OEnRuqDI7QXGSaOkoKjtbEMbjpx4lqN0zjqBYKLkaIz2pHhfu9JqaCUeEFGJXsnIZmjAC3B2tnCjH+KLsoBLkcYlkXN7xzXtwAbO5Xflw5ZrNETT+3qgEb78g0B+2f5WRw== 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 --- 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 Wed Oct 4 17:11:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13409091 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 794CFE7C4E7 for ; Wed, 4 Oct 2023 17:12:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4F986B02B3; Wed, 4 Oct 2023 13:12:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD8F96B02B4; Wed, 4 Oct 2023 13:12:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2C226B02B5; Wed, 4 Oct 2023 13:12:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AC6196B02B3 for ; Wed, 4 Oct 2023 13:12:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6F7FE40365 for ; Wed, 4 Oct 2023 17:12:15 +0000 (UTC) X-FDA: 81308422230.12.BDA722A Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf30.hostedemail.com (Postfix) with ESMTP id 8AD1E80013 for ; Wed, 4 Oct 2023 17:12:13 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.51 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=1696439533; 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=v8ih6B2Rlcxp81srnkWek1jGwJ1l7RM9hd1ykDQtxDA=; b=uSly4E7ROXidqKOyIp+I4d/m5wROdzScEnWL+iiuaCFyyWdlAh8h87wCC4M/P7fRPeHZHY byEgppzNBVtm8WX2dEQriZpYOxeM0M+78n+JdwxnzyixW7lFxNyjsylcvypPjyEvXCDPpM XnpKfngkxNzZfOp5eF1ocgRQVSRT09o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf30.hostedemail.com: domain of breno.debian@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=breno.debian@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696439533; a=rsa-sha256; cv=none; b=3GqIHq1XJnqnkjWZCWkkgdppnUsULoL3x1S/k7+x2nR4aLElZuLk4Ll+m+XOL8HLeA97q+ fL0cS1cXiUFNEdKVCuI5lsJL0SP+BMPz7zczWT/NBJ0misbjIiQjM9Uqq9nRa0IhXz/2pN WaC82KP0um5qZ7IcOgsKYnSmtZ3OAl0= Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-533d31a8523so4539449a12.1 for ; Wed, 04 Oct 2023 10:12:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696439532; x=1697044332; 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=v8ih6B2Rlcxp81srnkWek1jGwJ1l7RM9hd1ykDQtxDA=; b=b0P3e/G4ABP4rYoTZGzocYU9ZJ7BMtqFmrKJMXbLIj6mtlrKvuDZehsoryguWQMu6N 7suRL6JKmJ79mEuSqoQcK3YY4/8GarYZyuHFV+09jNzceAgpRA34ryYfVnNt9D1WWzmV Fu6RZpaIwbctJynvx5jz9/skmUtdP+2ubdtgYR9YlcMerLSRLDMnW+1rA1tIo733DOhs SRSjkog22MX8CnFRGaitJL+Ov7DXNDIbHvE4ulDoX3go14VPijhZKX4W1S2GWtZrTpXe RiMMZEoPka/juq3orF1/Pptj75ItKpb/p3cEB5OKhP+tf5EDqXJmV48NvGvkby1cdqQM WwRw== X-Gm-Message-State: AOJu0YzKxv6byR4/HMQ1cnXqmDw2SFLNg1U8pxTg8w99cxjDQI6By72K uZ0GBkiqsVam85vZQ6mByLg= X-Google-Smtp-Source: AGHT+IGBToqvNL/hEcJArvik0DADNV1zdswIJEVmop94ejSDsVbBAfm79zjk87sbIoIzygWd/MmBMQ== X-Received: by 2002:a17:906:309a:b0:9b7:1e26:e2de with SMTP id 26-20020a170906309a00b009b71e26e2demr2388918ejv.21.1696439532120; Wed, 04 Oct 2023 10:12:12 -0700 (PDT) Received: from localhost (fwdproxy-cln-025.fbsv.net. [2a03:2880:31ff:19::face:b00c]) by smtp.gmail.com with ESMTPSA id g10-20020a170906348a00b0099bd0b5a2bcsm3108543ejb.101.2023.10.04.10.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 10:12:11 -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 2/2] selftests/mm: Add a new test for madv and hugetlb Date: Wed, 4 Oct 2023 10:11:26 -0700 Message-Id: <20231004171127.106056-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231004171127.106056-1-leitao@debian.org> References: <20231004171127.106056-1-leitao@debian.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8AD1E80013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 599ci63oy1me7xtpymz1dzkzz93pqs3u X-HE-Tag: 1696439533-237354 X-HE-Meta: U2FsdGVkX18oM9B9gDmOyawHWnB/2msAY+/kYFfpYy+7Jpu4xbAq2/9Bkzp2TnervUzfwq0Rg8D81DimKpBydAbqBD+pO/Jpu0UIfYNe8s9TqzE0HSu3JHHMMXGRzRwsyPao9TsSKiiemI+V9tcZoA9TSCmWqbgkuhpTYrETYeRUA7auC0MjQkxZRDvQYxe9HHSugs5nVvkkl5MSkxuozK91YSItNV36xXZYsqqFrm4TI7oj9OrlVDySiObEhrHTXplkFxgzsALKp/ictWZVw4hAR9zEaaZnvDndFnjO2B7cZjTY5BjdxSVSmEF30cNFBd4yExkTDvNKXFHztjiZzSZWt6tEn743glZVrA01RiRm3uP1sR7M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vMCa5N99V09lIpTWIzdYKDaFtdfK0/Mle/WATlBTDd9wvi3pUTPbzBwGyLMtThY8/eqj9Kl6Vx+IDdOdeKVOvbiC7qaig9wa6KXDScqSbnc99OUWC1ezV40nAx80SQnAWMRQVa4wT7Oiu9s6U9yFxjgF6D2KQ== 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: Create a selftest that exercises the conflict 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 | 82 +++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 3 files changed, 87 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..d6d38d443840 --- /dev/null +++ b/tools/testing/selftests/mm/hugetlb_fault_after_madv.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include + +#include "vm_util.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; + + if (!ptr) { + fprintf(stderr, "Failed to allocate memory\n"); + perror(""); + } + + for (int i = 0; i < INLOOP_ITER; i++) + ptr[0] = '.'; + + return NULL; +} + +void *madv(void *unused) +{ + usleep(rand() % 10); + if (!huge_ptr) + return NULL; + + 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) { + fprintf(stderr, + "This test needs one and only one page to execute. Got %lu\n", + free_hugepages); + exit(1); + } + + 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) { + perror("Failed to allocate\n"); + continue; + } + + 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 0; +} 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"