diff mbox series

[v1,3/3] selftests/mm: Speed up split_huge_page_test

Message ID 20250318174343.243631-3-ryan.roberts@arm.com (mailing list archive)
State New
Headers show
Series [v1,1/3] selftests/mm: Fix half_ufd_size_MB calculation | expand

Commit Message

Ryan Roberts March 18, 2025, 5:43 p.m. UTC
create_pagecache_thp_and_fd() was previously writing a file sized at
twice the PMD size by making a per-byte write syscall. This was quite
slow when the PMD size is 4M, but completely intolerable for 32M (PMD
size for arm64's 16K page size), and 512M (PMD size for arm64's 64K page
size).

The byte pattern has a 256 byte period, so let's create a 1K buffer and
fill it with exactly 4 periods. Then we can write the buffer as many
times as is required to fill the file. This makes things much more
tolerable.

The test now passes for 16K page size. It still fails for 64K page size
because MAX_PAGECACHE_ORDER is too small for 512M folio size (I think).

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
 tools/testing/selftests/mm/split_huge_page_test.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Peter Xu March 18, 2025, 7:54 p.m. UTC | #1
On Tue, Mar 18, 2025 at 05:43:41PM +0000, Ryan Roberts wrote:
> create_pagecache_thp_and_fd() was previously writing a file sized at
> twice the PMD size by making a per-byte write syscall. This was quite
> slow when the PMD size is 4M, but completely intolerable for 32M (PMD
> size for arm64's 16K page size), and 512M (PMD size for arm64's 64K page
> size).
> 
> The byte pattern has a 256 byte period, so let's create a 1K buffer and
> fill it with exactly 4 periods. Then we can write the buffer as many
> times as is required to fill the file. This makes things much more
> tolerable.
> 
> The test now passes for 16K page size. It still fails for 64K page size
> because MAX_PAGECACHE_ORDER is too small for 512M folio size (I think).
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>

Acked-by: Peter Xu <peterx@redhat.com>
Rafael Aquini March 18, 2025, 9:53 p.m. UTC | #2
On Tue, Mar 18, 2025 at 05:43:41PM +0000, Ryan Roberts wrote:
> create_pagecache_thp_and_fd() was previously writing a file sized at
> twice the PMD size by making a per-byte write syscall. This was quite
> slow when the PMD size is 4M, but completely intolerable for 32M (PMD
> size for arm64's 16K page size), and 512M (PMD size for arm64's 64K page
> size).
> 
> The byte pattern has a 256 byte period, so let's create a 1K buffer and
> fill it with exactly 4 periods. Then we can write the buffer as many
> times as is required to fill the file. This makes things much more
> tolerable.
> 
> The test now passes for 16K page size. It still fails for 64K page size
> because MAX_PAGECACHE_ORDER is too small for 512M folio size (I think).
> 
> Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
>  tools/testing/selftests/mm/split_huge_page_test.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
> index 3f353f3d070f..499333d75fff 100644
> --- a/tools/testing/selftests/mm/split_huge_page_test.c
> +++ b/tools/testing/selftests/mm/split_huge_page_test.c
> @@ -5,6 +5,7 @@
>   */
>  
>  #define _GNU_SOURCE
> +#include <assert.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <stdarg.h>
> @@ -361,6 +362,7 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
>  {
>  	size_t i;
>  	int dummy = 0;
> +	unsigned char buf[1024];
>  
>  	srand(time(NULL));
>  
> @@ -368,11 +370,12 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
>  	if (*fd == -1)
>  		ksft_exit_fail_msg("Failed to create a file at %s\n", testfile);
>  
> -	for (i = 0; i < fd_size; i++) {
> -		unsigned char byte = (unsigned char)i;
> +	assert(fd_size % sizeof(buf) == 0);
> +	for (i = 0; i < sizeof(buf); i++)
> +		buf[i] = (unsigned char)i;
> +	for (i = 0; i < fd_size; i += sizeof(buf))
> +		write(*fd, buf, sizeof(buf));
>  
> -		write(*fd, &byte, sizeof(byte));
> -	}
>  	close(*fd);
>  	sync();
>  	*fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
> -- 
> 2.43.0
> 
> 

Acked-by: Rafael Aquini <raquini@redhat.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index 3f353f3d070f..499333d75fff 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -5,6 +5,7 @@ 
  */
 
 #define _GNU_SOURCE
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -361,6 +362,7 @@  int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
 {
 	size_t i;
 	int dummy = 0;
+	unsigned char buf[1024];
 
 	srand(time(NULL));
 
@@ -368,11 +370,12 @@  int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
 	if (*fd == -1)
 		ksft_exit_fail_msg("Failed to create a file at %s\n", testfile);
 
-	for (i = 0; i < fd_size; i++) {
-		unsigned char byte = (unsigned char)i;
+	assert(fd_size % sizeof(buf) == 0);
+	for (i = 0; i < sizeof(buf); i++)
+		buf[i] = (unsigned char)i;
+	for (i = 0; i < fd_size; i += sizeof(buf))
+		write(*fd, buf, sizeof(buf));
 
-		write(*fd, &byte, sizeof(byte));
-	}
 	close(*fd);
 	sync();
 	*fd = open("/proc/sys/vm/drop_caches", O_WRONLY);