From mboxrd@z Thu Jan 1 00:00:00 1970 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 3056EC433F5 for ; Tue, 1 Feb 2022 16:46:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A32D28D0074; Tue, 1 Feb 2022 11:46:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E1308D006D; Tue, 1 Feb 2022 11:46:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A8ED8D0074; Tue, 1 Feb 2022 11:46:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 7D5318D006D for ; Tue, 1 Feb 2022 11:46:00 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 40C3790950 for ; Tue, 1 Feb 2022 16:46:00 +0000 (UTC) X-FDA: 79094788080.10.0F45725 Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) by imf15.hostedemail.com (Postfix) with ESMTP id BCBC6A000D for ; Tue, 1 Feb 2022 16:45:59 +0000 (UTC) Received: by mail-io1-f42.google.com with SMTP id 9so22033346iou.2 for ; Tue, 01 Feb 2022 08:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Y6LUyFcnFmJZfl6pUaqznZq25qjWW5IaFFfetEnm8pE=; b=OjANnamDd2aLy28kxdbVFCYfF+KDlBQv2VxjReEVGzrTFODEIREmBLTVW+b6Qf7oSw T9wtJi5mozJG0bnXrwHX0E3s97iAa4Z0Exhoh2nyZPfP6jxaRKsZQcBBus5RRrAk+Qwa Gpyz9UpUyvan+ufyeYSl6CuK04Rg0H3StZbpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Y6LUyFcnFmJZfl6pUaqznZq25qjWW5IaFFfetEnm8pE=; b=sqNkF3swx4SR4aafzTQVrfsMVHHT2DAoxsA3ekUlODPjHPSMbQvjFZXQmwClfGFBJ5 wDSzuEqOGdSIVtaNiP3VYKg1jfNtS9tHB/7aIklsI9D1xM1zyiban95AwsLy//ExxTsh 7xY5BjmjLtfwb5qoZ6+HARR0OaJgPxPhh/SHPRmzL0ONQczA0xrmBV3ug1PWravTFtOU A5HJ2DAk5LSxkr/nh3bfq43N0SSG2E5u4uru0Lo/X12pVvKpvgou3VNOxMTwm+dYIY4Y pUiwSetLimbJUpcx0/4t1Ok3U6W20F4DOwi/8axi8QpjnpuMl9i0IwJ0Q70RWhm7veCK +haQ== X-Gm-Message-State: AOAM533a2AvMVeAwn5N3bY1kptDQonfGqympLXyOlQeKFJCk2cOO035s ULggtV8IZGAxz8RnDb6A5QMKQQ== X-Google-Smtp-Source: ABdhPJygx01PVOP0KxGWme2ti0XbibVoM5Wf/kSbQtNwoU5OnjEpa3gPqn39prvUbQzoEDREyUa2fw== X-Received: by 2002:a5e:8a45:: with SMTP id o5mr13965842iom.169.1643733958960; Tue, 01 Feb 2022 08:45:58 -0800 (PST) Received: from [192.168.1.128] ([71.205.29.0]) by smtp.gmail.com with ESMTPSA id h3sm20058598ild.11.2022.02.01.08.45.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Feb 2022 08:45:58 -0800 (PST) Subject: Re: [PATCH] selftests/vm: cleanup hugetlb file after mremap test To: Mike Kravetz , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mina Almasry , Yosry Ahmed , Muchun Song , Shuah Khan , Andrew Morton , Shuah Khan References: <20220201033459.156944-1-mike.kravetz@oracle.com> From: Shuah Khan Message-ID: <33568901-8ef9-1461-0907-217634b3b989@linuxfoundation.org> Date: Tue, 1 Feb 2022 09:45:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220201033459.156944-1-mike.kravetz@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: BCBC6A000D X-Stat-Signature: hxrd5mr1dxkbphna8aqee76wwrc8snju Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b=OjANnamD; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf15.hostedemail.com: domain of skhan@linuxfoundation.org designates 209.85.166.42 as permitted sender) smtp.mailfrom=skhan@linuxfoundation.org X-Rspam-User: nil X-HE-Tag: 1643733959-439885 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: On 1/31/22 8:34 PM, Mike Kravetz wrote: > The hugepage-mremap test will create a file in a hugetlb filesystem. > In a default 'run_vmtests' run, the file will contain all the hugetlb > pages. After the test, the file remains and there are no free hugetlb > pages for subsequent tests. This causes those hugetlb tests to fail. > > Change hugepage-mremap to take the name of the hugetlb file as an > argument. Unlink the file within the test, and just to be sure remove > the file in the run_vmtests script. > > Signed-off-by: Mike Kravetz > --- > tools/testing/selftests/vm/hugepage-mremap.c | 26 ++++++++++++++------ > tools/testing/selftests/vm/run_vmtests.sh | 3 ++- > 2 files changed, 21 insertions(+), 8 deletions(-) > > diff --git a/tools/testing/selftests/vm/hugepage-mremap.c b/tools/testing/selftests/vm/hugepage-mremap.c > index 2a7c33631a29..1d689084a54b 100644 > --- a/tools/testing/selftests/vm/hugepage-mremap.c > +++ b/tools/testing/selftests/vm/hugepage-mremap.c > @@ -3,9 +3,10 @@ > * hugepage-mremap: > * > * Example of remapping huge page memory in a user application using the > - * mremap system call. Code assumes a hugetlbfs filesystem is mounted > - * at './huge'. The amount of memory used by this test is decided by a command > - * line argument in MBs. If missing, the default amount is 10MB. > + * mremap system call. The path to a file in a hugetlbfs filesystem must > + * be passed as the last argument to this test. The amount of memory used > + * by this test in MBs can optionally be passed as an argument. If no memory > + * amount is passed, the default amount is 10MB. > * > * To make sure the test triggers pmd sharing and goes through the 'unshare' > * path in the mremap code use 1GB (1024) or more. > @@ -25,7 +26,6 @@ > #define DEFAULT_LENGTH_MB 10UL > #define MB_TO_BYTES(x) (x * 1024 * 1024) > > -#define FILE_NAME "huge/hugepagefile" > #define PROTECTION (PROT_READ | PROT_WRITE | PROT_EXEC) > #define FLAGS (MAP_SHARED | MAP_ANONYMOUS) > > @@ -107,17 +107,26 @@ static void register_region_with_uffd(char *addr, size_t len) > > int main(int argc, char *argv[]) > { > + size_t length; > + > + if (argc != 2 && argc != 3) { > + printf("Usage: %s [length_in_MB] \n", argv[0]); > + exit(1); > + } > + > /* Read memory length as the first arg if valid, otherwise fallback to > - * the default length. Any additional args are ignored. > + * the default length. > */ > - size_t length = argc > 1 ? (size_t)atoi(argv[1]) : 0UL; > + if (argc == 3) > + length = argc > 2 ? (size_t)atoi(argv[1]) : 0UL; > Looks like getopt() might be useful - we have a few arguments now. Makes it easier to maintain the test. > length = length > 0 ? length : DEFAULT_LENGTH_MB; > length = MB_TO_BYTES(length); > > int ret = 0; > > - int fd = open(FILE_NAME, O_CREAT | O_RDWR, 0755); > + /* last arg is the hugetlb file name */ > + int fd = open(argv[argc-1], O_CREAT | O_RDWR, 0755); > > if (fd < 0) { > perror("Open failed"); > @@ -169,5 +178,8 @@ int main(int argc, char *argv[]) > > munmap(addr, length); > > + close(fd); > + unlink(argv[argc-1]); > + > return ret; > } > diff --git a/tools/testing/selftests/vm/run_vmtests.sh b/tools/testing/selftests/vm/run_vmtests.sh > index e09040a3dc08..e10d50e0b8e8 100755 > --- a/tools/testing/selftests/vm/run_vmtests.sh > +++ b/tools/testing/selftests/vm/run_vmtests.sh > @@ -111,13 +111,14 @@ fi > echo "-----------------------" > echo "running hugepage-mremap" > echo "-----------------------" > -./hugepage-mremap 256 > +./hugepage-mremap $mnt/huge_mremap > if [ $? -ne 0 ]; then > echo "[FAIL]" > exitcode=1 > else > echo "[PASS]" > fi > +rm -f $mnt/huge_mremap > > echo "------------------------" > echo "running hugepage-vmemmap" > Reviewed-by: Shuah Khan thanks, -- Shuah