diff mbox series

selftests: hugetlb_dio: Check for initial conditions to skip in the start

Message ID 20241101141557.3159432-1-usama.anjum@collabora.com (mailing list archive)
State New
Headers show
Series selftests: hugetlb_dio: Check for initial conditions to skip in the start | expand

Commit Message

Muhammad Usama Anjum Nov. 1, 2024, 2:15 p.m. UTC
The test should be skipped if initial conditions aren't fulfilled in
the start instead of failing and outputting non-compliant TAP logs. This
kind of failure pollutes the results. The initial conditions are:
- The test should only execute if /tmp file can be allocated.
- The test should only execute if huge pages are free.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
Before:
TAP version 13
1..4
Bail out! Error opening file
: Read-only file system (30)
 # Planned tests != run tests (4 != 0)
 # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0

After:
TAP version 13
1..0 # SKIP Unable to allocate file: Read-only file system
---
 tools/testing/selftests/mm/hugetlb_dio.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Andrew Morton Nov. 1, 2024, 6:54 p.m. UTC | #1
On Fri,  1 Nov 2024 19:15:57 +0500 Muhammad Usama Anjum <usama.anjum@collabora.com> wrote:

> The test should be skipped if initial conditions aren't fulfilled in
> the start instead of failing and outputting non-compliant TAP logs. This
> kind of failure pollutes the results. The initial conditions are:
> - The test should only execute if /tmp file can be allocated.
> - The test should only execute if huge pages are free.

Cc Donet Tom.

I added 

Fixes: 3a103b5315b7 ("selftest: mm: Test if hugepage does not get leaked during __bio_release_pages()")
Cc: <stable@vger.kernel.org>

> ---
> Before:
> TAP version 13
> 1..4
> Bail out! Error opening file
> : Read-only file system (30)
>  # Planned tests != run tests (4 != 0)
>  # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> After:
> TAP version 13
> 1..0 # SKIP Unable to allocate file: Read-only file system
> ---

And I moved this useful information to the changelog.
Donet Tom Nov. 8, 2024, 10:35 a.m. UTC | #2
On 11/1/24 19:45, Muhammad Usama Anjum wrote:
> The test should be skipped if initial conditions aren't fulfilled in
> the start instead of failing and outputting non-compliant TAP logs. This
> kind of failure pollutes the results. The initial conditions are:
> - The test should only execute if /tmp file can be allocated.
> - The test should only execute if huge pages are free.
>
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> Before:
> TAP version 13
> 1..4
> Bail out! Error opening file
> : Read-only file system (30)
>   # Planned tests != run tests (4 != 0)
>   # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
>
> After:
> TAP version 13
> 1..0 # SKIP Unable to allocate file: Read-only file system
> ---
>   tools/testing/selftests/mm/hugetlb_dio.c | 19 ++++++++++++-------
>   1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> index f9ac20c657ec6..60001c142ce99 100644
> --- a/tools/testing/selftests/mm/hugetlb_dio.c
> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> @@ -44,13 +44,6 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
>   	if (fd < 0)
>   		ksft_exit_fail_perror("Error opening file\n");
>   
> -	/* Get the free huge pages before allocation */
> -	free_hpage_b = get_free_hugepages();

Hi Muhammed Usman Anjum

Reading the free pages is required before starting the test. This value will be compared to the free pages after the test. If they are not the same, the test will be considered a failure.

Since reading the free pages before the test was removed,|free_hpage_b|  is always 0, causing the test to fail.

./tools/testing/selftests/mm/hugetlb_dio TAP version 13 1..4 # No. Free 
pages before allocation : 0 # No. Free pages after munmap : 100 not ok 1 
: Huge pages not freed! # No. Free pages before allocation : 0 # No. 
Free pages after munmap : 100 not ok 2 : Huge pages not freed! # No. 
Free pages before allocation : 0 # No. Free pages after munmap : 100 not 
ok 3 : Huge pages not freed! # No. Free pages before allocation : 0 # 
No. Free pages after munmap : 100 not ok 4 : Huge pages not freed! # 
Totals: pass:0 fail:4 xfail:0 xpass:0 skip:0 error:0 I think below 
changes are required. --- a/tools/testing/selftests/mm/hugetlb_dio.c +++ 
b/tools/testing/selftests/mm/hugetlb_dio.c @@ -44,6 +44,9 @@ void 
run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off) if 
(fd < 0) ksft_exit_fail_perror("Error opening file\n"); + /* Get the 
free huge pages before allocation */ + free_hpage_b = 
get_free_hugepages(); + /* Allocate a hugetlb page */ orig_buffer = 
mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0); if (orig_buffer == 
MAP_FAILED) { With this change the tests are passing. 
./tools/testing/selftests/mm/hugetlb_dio TAP version 13 1..4 # No. Free 
pages before allocation : 100 # No. Free pages after munmap : 100 ok 1 : 
Huge pages freed successfully ! # No. Free pages before allocation : 100 
# No. Free pages after munmap : 100 ok 2 : Huge pages freed successfully 
! # No. Free pages before allocation : 100 # No. Free pages after munmap 
: 100 ok 3 : Huge pages freed successfully ! # No. Free pages before 
allocation : 100 # No. Free pages after munmap : 100 ok 4 : Huge pages 
freed successfully ! # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 
error:0 Thank

Donet

> -	if (free_hpage_b == 0) {
> -		close(fd);
> -		ksft_exit_skip("No free hugepage, exiting!\n");
> -	}
> -
>   	/* Allocate a hugetlb page */
>   	orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
>   	if (orig_buffer == MAP_FAILED) {
> @@ -94,8 +87,20 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
>   int main(void)
>   {
>   	size_t pagesize = 0;
> +	int fd;
>   
>   	ksft_print_header();
> +
> +	/* Open the file to DIO */
> +	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
> +	if (fd < 0)
> +		ksft_exit_skip("Unable to allocate file: %s\n", strerror(errno));
> +	close(fd);
> +
> +	/* Check if huge pages are free */
> +	if (!get_free_hugepages())
> +		ksft_exit_skip("No free hugepage, exiting\n");
> +
>   	ksft_set_plan(4);
>   
>   	/* Get base page size */
Donet Tom Nov. 8, 2024, 10:49 a.m. UTC | #3
On 11/8/24 16:05, Donet Tom wrote:
>
> On 11/1/24 19:45, Muhammad Usama Anjum wrote:
>> The test should be skipped if initial conditions aren't fulfilled in
>> the start instead of failing and outputting non-compliant TAP logs. This
>> kind of failure pollutes the results. The initial conditions are:
>> - The test should only execute if /tmp file can be allocated.
>> - The test should only execute if huge pages are free.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
>> ---
>> Before:
>> TAP version 13
>> 1..4
>> Bail out! Error opening file
>> : Read-only file system (30)
>>   # Planned tests != run tests (4 != 0)
>>   # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
>>
>> After:
>> TAP version 13
>> 1..0 # SKIP Unable to allocate file: Read-only file system
>> ---
>>   tools/testing/selftests/mm/hugetlb_dio.c | 19 ++++++++++++-------
>>   1 file changed, 12 insertions(+), 7 deletions(-)
>>
>> diff --git a/tools/testing/selftests/mm/hugetlb_dio.c 
>> b/tools/testing/selftests/mm/hugetlb_dio.c
>> index f9ac20c657ec6..60001c142ce99 100644
>> --- a/tools/testing/selftests/mm/hugetlb_dio.c
>> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
>> @@ -44,13 +44,6 @@ void run_dio_using_hugetlb(unsigned int start_off, 
>> unsigned int end_off)
>>       if (fd < 0)
>>           ksft_exit_fail_perror("Error opening file\n");
>>   -    /* Get the free huge pages before allocation */
>> -    free_hpage_b = get_free_hugepages();
>
> Hi Muhammed Usman Anjum
>
> Reading the free pages is required before starting the test. This 
> value will be compared to the free pages after the test. If they are 
> not the same, the test will be considered a failure.
>
> Since reading the free pages before the test was 
> removed,|free_hpage_b|  is always 0, causing the test to fail.
>
> ./tools/testing/selftests/mm/hugetlb_dio TAP version 13 1..4 # No. 
> Free pages before allocation : 0 # No. Free pages after munmap : 100 
> not ok 1 : Huge pages not freed! # No. Free pages before allocation : 
> 0 # No. Free pages after munmap : 100 not ok 2 : Huge pages not freed! 
> # No. Free pages before allocation : 0 # No. Free pages after munmap : 
> 100 not ok 3 : Huge pages not freed! # No. Free pages before 
> allocation : 0 # No. Free pages after munmap : 100 not ok 4 : Huge 
> pages not freed! # Totals: pass:0 fail:4 xfail:0 xpass:0 skip:0 
> error:0 I think below changes are required. --- 
> a/tools/testing/selftests/mm/hugetlb_dio.c +++ 
> b/tools/testing/selftests/mm/hugetlb_dio.c @@ -44,6 +44,9 @@ void 
> run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off) if 
> (fd < 0) ksft_exit_fail_perror("Error opening file\n"); + /* Get the 
> free huge pages before allocation */ + free_hpage_b = 
> get_free_hugepages(); + /* Allocate a hugetlb page */ orig_buffer = 
> mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0); if (orig_buffer 
> == MAP_FAILED) { With this change the tests are passing. 
> ./tools/testing/selftests/mm/hugetlb_dio TAP version 13 1..4 # No. 
> Free pages before allocation : 100 # No. Free pages after munmap : 100 
> ok 1 : Huge pages freed successfully ! # No. Free pages before 
> allocation : 100 # No. Free pages after munmap : 100 ok 2 : Huge pages 
> freed successfully ! # No. Free pages before allocation : 100 # No. 
> Free pages after munmap : 100 ok 3 : Huge pages freed successfully ! # 
> No. Free pages before allocation : 100 # No. Free pages after munmap : 
> 100 ok 4 : Huge pages freed successfully ! # Totals: pass:4 fail:0 
> xfail:0 xpass:0 skip:0 error:0 Thank
>
> Donet
>
>
Sorry. Please ignore above mail.

Reading the free pages is required before starting the test. This
value will be compared to the free pages after the test. If they are not the same, the test will be considered a failure.

Since reading the free pages before the test was removed,free_hpage_b is always 0, causing the test to fail.

./tools/testing/selftests/mm/hugetlb_dio
TAP version 13
1..4
# No. Free pages before allocation : 0
# No. Free pages after munmap : 100
not ok 1 : Huge pages not freed!
# No. Free pages before allocation : 0
# No. Free pages after munmap : 100
not ok 2 : Huge pages not freed!
# No. Free pages before allocation : 0
# No. Free pages after munmap : 100
not ok 3 : Huge pages not freed!
# No. Free pages before allocation : 0
# No. Free pages after munmap : 100
not ok 4 : Huge pages not freed!
# Totals: pass:0 fail:4 xfail:0 xpass:0 skip:0 error:0

I think below changes are required.

iff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
index 60001c142ce9..4b52106b8124 100644
--- a/tools/testing/selftests/mm/hugetlb_dio.c
+++ b/tools/testing/selftests/mm/hugetlb_dio.c
@@ -44,6 +44,9 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
         if (fd < 0)
                 ksft_exit_fail_perror("Error opening file\n");
  
+       /* Get the free huge pages before allocation */
+       free_hpage_b = get_free_hugepages();
+
         /* Allocate a hugetlb page */

         orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);

         if (orig_buffer == MAP_FAILED) {

  With this change the tests are passing.

./tools/testing/selftests/mm/hugetlb_dio

TAP version 131..4
# No. Free pages before allocation : 100
# No. Free pages after munmap : 100
ok 1 : Huge pages freed successfully !
# No. Free pages before allocation : 100
# No. Free pages after munmap : 100
ok 2 : Huge pages freed successfully !
# No. Free pages before allocation : 100
# No. Free pages after munmap : 100
ok 3 : Huge pages freed successfully !
# No. Free pages before allocation : 100
# No. Free pages after munmap : 100
ok 4 : Huge pages freed successfully !
# Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0

Thanks
Donet


>> -    if (free_hpage_b == 0) {
>> -        close(fd);
>> -        ksft_exit_skip("No free hugepage, exiting!\n");
>> -    }
>> -
>>       /* Allocate a hugetlb page */
>>       orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 
>> 0);
>>       if (orig_buffer == MAP_FAILED) {
>> @@ -94,8 +87,20 @@ void run_dio_using_hugetlb(unsigned int start_off, 
>> unsigned int end_off)
>>   int main(void)
>>   {
>>       size_t pagesize = 0;
>> +    int fd;
>>         ksft_print_header();
>> +
>> +    /* Open the file to DIO */
>> +    fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
>> +    if (fd < 0)
>> +        ksft_exit_skip("Unable to allocate file: %s\n", 
>> strerror(errno));
>> +    close(fd);
>> +
>> +    /* Check if huge pages are free */
>> +    if (!get_free_hugepages())
>> +        ksft_exit_skip("No free hugepage, exiting\n");
>> +
>>       ksft_set_plan(4);
>>         /* Get base page size */
Muhammad Usama Anjum Nov. 8, 2024, 2:13 p.m. UTC | #4
On 11/8/24 3:49 PM, Donet Tom wrote:

> I think below changes are required.
> 
> iff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> index 60001c142ce9..4b52106b8124 100644
> --- a/tools/testing/selftests/mm/hugetlb_dio.c
> +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> @@ -44,6 +44,9 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
>         if (fd < 0)
>                 ksft_exit_fail_perror("Error opening file\n");
>  
> +       /* Get the free huge pages before allocation */
> +       free_hpage_b = get_free_hugepages();
> +
>         /* Allocate a hugetlb page */
> 
>         orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
> 
>         if (orig_buffer == MAP_FAILED) {
Please can you send a fixup patch as you have working test setup?
Otherwise I'll take it up and try to test on working setup before
posting the fixup patch. Please let me know.

> 
>  With this change the tests are passing.
> 
> ./tools/testing/selftests/mm/hugetlb_dio
> 
> TAP version 131..4
> # No. Free pages before allocation : 100
> # No. Free pages after munmap : 100
> ok 1 : Huge pages freed successfully !
> # No. Free pages before allocation : 100
> # No. Free pages after munmap : 100
> ok 2 : Huge pages freed successfully !
> # No. Free pages before allocation : 100
> # No. Free pages after munmap : 100
> ok 3 : Huge pages freed successfully !
> # No. Free pages before allocation : 100
> # No. Free pages after munmap : 100
> ok 4 : Huge pages freed successfully !
> # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> Thanks
> Donet
> 
>
Andrew Morton Nov. 10, 2024, 6:20 a.m. UTC | #5
On Fri, 8 Nov 2024 19:13:04 +0500 Muhammad Usama Anjum <Usama.Anjum@collabora.com> wrote:

> On 11/8/24 3:49 PM, Donet Tom wrote:
> 
> > I think below changes are required.
> > 
> > iff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> > index 60001c142ce9..4b52106b8124 100644
> > --- a/tools/testing/selftests/mm/hugetlb_dio.c
> > +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> > @@ -44,6 +44,9 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
> >         if (fd < 0)
> >                 ksft_exit_fail_perror("Error opening file\n");
> >  
> > +       /* Get the free huge pages before allocation */
> > +       free_hpage_b = get_free_hugepages();
> > +
> >         /* Allocate a hugetlb page */
> > 
> >         orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
> > 
> >         if (orig_buffer == MAP_FAILED) {
> Please can you send a fixup patch as you have working test setup?
> Otherwise I'll take it up and try to test on working setup before
> posting the fixup patch. Please let me know.

I've removed this patch from mm-hotfixes-stable.
Andrew Morton Nov. 10, 2024, 6:34 a.m. UTC | #6
On Sat, 9 Nov 2024 22:20:01 -0800 Andrew Morton <akpm@linux-foundation.org> wrote:

> On Fri, 8 Nov 2024 19:13:04 +0500 Muhammad Usama Anjum <Usama.Anjum@collabora.com> wrote:
> 
> > On 11/8/24 3:49 PM, Donet Tom wrote:
> > 
> > > I think below changes are required.
> > > 
> > > iff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
> > > index 60001c142ce9..4b52106b8124 100644
> > > --- a/tools/testing/selftests/mm/hugetlb_dio.c
> > > +++ b/tools/testing/selftests/mm/hugetlb_dio.c
> > > @@ -44,6 +44,9 @@ void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
> > >         if (fd < 0)
> > >                 ksft_exit_fail_perror("Error opening file\n");
> > >  
> > > +       /* Get the free huge pages before allocation */
> > > +       free_hpage_b = get_free_hugepages();
> > > +
> > >         /* Allocate a hugetlb page */
> > > 
> > >         orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
> > > 
> > >         if (orig_buffer == MAP_FAILED) {
> > Please can you send a fixup patch as you have working test setup?
> > Otherwise I'll take it up and try to test on working setup before
> > posting the fixup patch. Please let me know.
> 
> I've removed this patch from mm-hotfixes-stable.

I changed my mind.  Please send any fixup against the previous patch.
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/hugetlb_dio.c b/tools/testing/selftests/mm/hugetlb_dio.c
index f9ac20c657ec6..60001c142ce99 100644
--- a/tools/testing/selftests/mm/hugetlb_dio.c
+++ b/tools/testing/selftests/mm/hugetlb_dio.c
@@ -44,13 +44,6 @@  void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
 	if (fd < 0)
 		ksft_exit_fail_perror("Error opening file\n");
 
-	/* Get the free huge pages before allocation */
-	free_hpage_b = get_free_hugepages();
-	if (free_hpage_b == 0) {
-		close(fd);
-		ksft_exit_skip("No free hugepage, exiting!\n");
-	}
-
 	/* Allocate a hugetlb page */
 	orig_buffer = mmap(NULL, h_pagesize, mmap_prot, mmap_flags, -1, 0);
 	if (orig_buffer == MAP_FAILED) {
@@ -94,8 +87,20 @@  void run_dio_using_hugetlb(unsigned int start_off, unsigned int end_off)
 int main(void)
 {
 	size_t pagesize = 0;
+	int fd;
 
 	ksft_print_header();
+
+	/* Open the file to DIO */
+	fd = open("/tmp", O_TMPFILE | O_RDWR | O_DIRECT, 0664);
+	if (fd < 0)
+		ksft_exit_skip("Unable to allocate file: %s\n", strerror(errno));
+	close(fd);
+
+	/* Check if huge pages are free */
+	if (!get_free_hugepages())
+		ksft_exit_skip("No free hugepage, exiting\n");
+
 	ksft_set_plan(4);
 
 	/* Get base page size */