Linux-mm Archive mirror
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Dev Jain <dev.jain@arm.com>, akpm@linux-foundation.org, shuah@kernel.org
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, Anshuman.Khandual@arm.com
Subject: Re: [PATCH] selftests/mm: hugetlb_madv_vs_map: Avoid test skipping by querying hugepage size at runtime
Date: Fri, 10 May 2024 16:43:56 +0500	[thread overview]
Message-ID: <79677d57-379e-4cdc-ab89-899817a72206@collabora.com> (raw)
In-Reply-To: <20240509095447.3791573-1-dev.jain@arm.com>

On 5/9/24 2:54 PM, Dev Jain wrote:
> Currently, the size used in mmap() is statically defined, leading to
> skipping of the test on a hugepage size other than 2 MB, since munmap()
> won't free the hugepage for a size greater than 2 MB. Hence, query the
> size at runtime.
> 
> Also, there is no reason why a hugepage allocation should fail, since we
> are using a simple mmap() using MAP_HUGETLB; hence, instead of skipping
> the test, make it fail.
>  
> Signed-off-by: Dev Jain <dev.jain@arm.com>
LGTM
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  tools/testing/selftests/mm/hugetlb_madv_vs_map.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> index d01e8d4901d0..8f122a0f0828 100644
> --- a/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> +++ b/tools/testing/selftests/mm/hugetlb_madv_vs_map.c
> @@ -27,9 +27,9 @@
>  #include "vm_util.h"
>  #include "../kselftest.h"
>  
> -#define MMAP_SIZE (1 << 21)
>  #define INLOOP_ITER 100
>  
> +size_t mmap_size;
>  char *huge_ptr;
>  
>  /* Touch the memory while it is being madvised() */
> @@ -44,7 +44,7 @@ void *touch(void *unused)
>  void *madv(void *unused)
>  {
>  	for (int i = 0; i < INLOOP_ITER; i++)
> -		madvise(huge_ptr, MMAP_SIZE, MADV_DONTNEED);
> +		madvise(huge_ptr, mmap_size, MADV_DONTNEED);
>  
>  	return NULL;
>  }
> @@ -59,7 +59,7 @@ void *map_extra(void *unused)
>  	void *ptr;
>  
>  	for (int i = 0; i < INLOOP_ITER; i++) {
> -		ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE,
> +		ptr = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
>  			   MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB,
>  			   -1, 0);
>  
> @@ -93,14 +93,16 @@ int main(void)
>  			       free_hugepages);
>  	}
>  
> +	mmap_size = default_huge_page_size();
> +
>  	while (max--) {
> -		huge_ptr = mmap(NULL, MMAP_SIZE, PROT_READ | PROT_WRITE,
> +		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");
> -			return KSFT_SKIP;
> +			ksft_test_result_fail("Failed to allocate huge page\n");
> +			return KSFT_FAIL;
>  		}
>  
>  		pthread_create(&thread1, NULL, madv, NULL);
> @@ -117,7 +119,7 @@ int main(void)
>  		}
>  
>  		/* Unmap and restart */
> -		munmap(huge_ptr, MMAP_SIZE);
> +		munmap(huge_ptr, mmap_size);
>  	}
>  
>  	return KSFT_PASS;

-- 
BR,
Muhammad Usama Anjum


  reply	other threads:[~2024-05-10 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-09  9:54 [PATCH] selftests/mm: hugetlb_madv_vs_map: Avoid test skipping by querying hugepage size at runtime Dev Jain
2024-05-10 11:43 ` Muhammad Usama Anjum [this message]
2024-05-27 13:39 ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=79677d57-379e-4cdc-ab89-899817a72206@collabora.com \
    --to=usama.anjum@collabora.com \
    --cc=Anshuman.Khandual@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=dev.jain@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).