Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1339701pxb; Wed, 2 Feb 2022 02:42:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyEgT0aAgLFt49DGGBMHikueum2beEUMr1dnna4GvmPvH4b3K4Iu7ZjmAumXHahn10TkrRc X-Received: by 2002:a17:907:6091:: with SMTP id ht17mr25546277ejc.607.1643798561422; Wed, 02 Feb 2022 02:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643798561; cv=none; d=google.com; s=arc-20160816; b=jJHfvblReNRx7VNs/P+ut4hwMgmPspY1nmUz4b7+o/IdL2JQTBFnUS0oVa/ASIe1C2 H4ceyualqiDoPtTJYs5QMwo5QpIYQcnTyEDbFH/hOv7b73j11fH+JeyKWhAmB9Xgh016 S3jGXUqscANdboKNhAF/irPktO66Z+G6MEjLcQA+HO/dNYygnxvsBNl+NOynGLyNvXCi F4CcY5ry7cc0sYhp8puW5/8J5ksnhXqwx7do+fyuHMPwCK+0A080k6ygcYHbp0E8V6I1 8HdKO5BpI3lE5j4xmYglMlGtX16fcjOaIX07xUN21Wes4PDc876d4yMm3wZbJUihkjsN 5PqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Y6LUyFcnFmJZfl6pUaqznZq25qjWW5IaFFfetEnm8pE=; b=vtoa+VuCqvH0hKT/c+ej013HDoJY5g10PGjOI6gWLrQLrGzlM42+J590x+Y/puSSOz JUenb68tP7XmQ3gXry+Oj6wXDb5ikM+4c4YHki18AHw3z4jRZI5vSupQXcw3nvSnlxwp hdNDaRpN33Z7rFX+MiFAx1ZbgJLJBMcPC8MzdV787SBbfbWBNTyWvrUVjBqTpkRVx4Q/ 0HbUuEwsyK5qvDY7S6OCOWlTuiLrBAT7qup45wcylMGH3VvEe53CLp6FqZXU0B2l6adq x6D74ycHU7w3RpD3lM7xa9o1GqWyaTbWpVLrtLFro18nGnE1DKXphERHAKZ1S6/3WTu7 eEpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OjANnamD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go16si11655984ejc.951.2022.02.02.02.42.15; Wed, 02 Feb 2022 02:42:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OjANnamD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241217AbiBAQqA (ORCPT + 99 others); Tue, 1 Feb 2022 11:46:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241188AbiBAQp7 (ORCPT ); Tue, 1 Feb 2022 11:45:59 -0500 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99E95C061714 for ; Tue, 1 Feb 2022 08:45:59 -0800 (PST) Received: by mail-io1-xd33.google.com with SMTP id z199so21938358iof.10 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=E+JgDv2IT3be90NYa9TzgOvBaSdiEAt4NB+H91gqLYAn+7ImdDNwrVCaHq+yAr900r arpVS5WDWP8gIYSloqL7sblEXh9gc3k3ftsHlnuo0UC4/ukHLWcy3yE/l1FA4pELByck 7eRiQRJe37YSDJFHAYBx/QymUd/Lrb3sy9CSAPx/wLkZ+AQTfq4RFIVwI1YacaDDvqUJ OZNzKcQNjCn9/Bh4SfiEpRBSp/HN6PBnhKhG0JyzTPLbn7K0/jviWEmVbcc2TC9RtoB0 B8DIPekwZOgK6VZc0QwQA52+bgneL4d/Md23WxAoz+vhTtQlS/oVhYEWlVEGgizJW1H4 7fiA== X-Gm-Message-State: AOAM531p97zUfwXpgRu7CFx7/nij4GSwMzRq84yUca9Oog8wuOCQpgGG KhLwSEFOVhemcNZF/H8TdHczZA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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