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 91BDFC433EF for ; Wed, 2 Feb 2022 19:35:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D83BD6B02B3; Wed, 2 Feb 2022 14:35:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D33E48D0118; Wed, 2 Feb 2022 14:35:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFBB98D00F9; Wed, 2 Feb 2022 14:35:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id B27416B02B3 for ; Wed, 2 Feb 2022 14:35:13 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6F784181B364B for ; Wed, 2 Feb 2022 19:35:13 +0000 (UTC) X-FDA: 79098843306.05.E17FA3A Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf19.hostedemail.com (Postfix) with ESMTP id 101C71A000B for ; Wed, 2 Feb 2022 19:35:12 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id e16so366492pgn.4 for ; Wed, 02 Feb 2022 11:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ry7R53YO4Swsz3TJJ6ZarkYxXNRWHuwvQe9nMVYuVs0=; b=r6cB2T4aE39Ps0ylMioXXq9SALw1BvuPcBWEl/4H+cg6K2WdOmWY3GiourqMvhuoI3 ULxM7VP9jzNXG2kVx/TABeBX0aUCadg0GWzT41WL7+qV2CSMsVgMX3FIhP7zYNCwA6Tn iTelUp1Kq2301f3uyu5kCxv78/fVy9NagOvDYXjiPpXK5MS6V8GtQk9+BLFISiICTktF QvIb9kkKijBrMw2i3JfwdmlnDLBqZYDW7zeNca5BlMqjRXksT2mhO/3WI7vZPvSwE083 +8Vj/94qedsElVZUXu2ZIvSqLmtMm6C7tp+dpxTVPmLbOE1iaz00HogzVyUWlu9QZL3a Uo0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ry7R53YO4Swsz3TJJ6ZarkYxXNRWHuwvQe9nMVYuVs0=; b=4s2xuDR5R560KpBqY2PpXe0Uh3ySQH3vJwcp7CH/rd92pTxrlvgB37vEXrGWrZJtLd q+ZktbFSaQmCtPOEzAlWLk2l1DieojkuMBp1i4fvk1AVhm3y1MJVBb//aT9R8S9vPItU h21ermG/CvGjShRHM4cm7e3nTvGc6R54up8GWLcXwjAOsa8lD25ltn/Ma0HDusFIzn65 tFJNbJfS2DKtmT34xEv8PgYqXDaTIt8HRFCJbpNXBbc5y73slyex1tVAotvR1BH4upzB OUKfGvSNmb7qRKCxtRkbuFOfd6LMj3opMqZOMlVQaWjryYPzfJuCq0SmEnhQRdAdBM9I mDew== X-Gm-Message-State: AOAM533xg9Fr07ShUWO9GDGwwb+o4p/Fj+Z9gdc3uTeFhzfUL346VbLd KStGXeBiUY9XO5WtFimNxApv8aEIYTFOzG4yAK8zIw== X-Google-Smtp-Source: ABdhPJzb95+FoAtSkMReBfzCigoxXQ3Bj6IuL4csArRCLMMY0YQ6crm3Cj55TtssS2otEMUnlAFXR6PXN7s3YXzrslc= X-Received: by 2002:a63:2d86:: with SMTP id t128mr25717072pgt.200.1643830511679; Wed, 02 Feb 2022 11:35:11 -0800 (PST) MIME-Version: 1.0 References: <20220201033459.156944-1-mike.kravetz@oracle.com> In-Reply-To: <20220201033459.156944-1-mike.kravetz@oracle.com> From: Yosry Ahmed Date: Wed, 2 Feb 2022 11:34:35 -0800 Message-ID: Subject: Re: [PATCH] selftests/vm: cleanup hugetlb file after mremap test To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mina Almasry , Muchun Song , Shuah Khan , Andrew Morton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 101C71A000B X-Stat-Signature: inemp9ck5p4j35jum4mqzmymjjfytdpb X-Rspam-User: nil Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=r6cB2T4a; spf=pass (imf19.hostedemail.com: domain of yosryahmed@google.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1643830512-119556 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: Thanks Mike for working on this! On Mon, Jan 31, 2022 at 7:35 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. > The hugepage-mmap test also uses a hugetlb file in the same fashion. I think the missing close() and unlink() calls were the only difference (thanks for catching that). I would suggest for consistency purposes to either make both tests take the filename as an argument or not, fine either way. > 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; I think the ternary operator is not needed here as it will always be true if we enter the if block. Otherwise, LGTM. Acked-by: Yosry Ahmed > > 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" > -- > 2.34.1 >