Skip to content

Commit a2c6f9c

Browse files
Ryan Robertsakpm00
authored andcommitted
selftests/mm: speed up split_huge_page_test
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). Link: https://lkml.kernel.org/r/20250318174343.243631-3-ryan.roberts@arm.com Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Acked-by: Peter Xu <peterx@redhat.com> Acked-by: Rafael Aquini <raquini@redhat.com> Cc: Shuah Khan <shuah@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 735b3f7 commit a2c6f9c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tools/testing/selftests/mm/split_huge_page_test.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#define _GNU_SOURCE
8+
#include <assert.h>
89
#include <stdio.h>
910
#include <stdlib.h>
1011
#include <stdarg.h>
@@ -398,18 +399,20 @@ int create_pagecache_thp_and_fd(const char *testfile, size_t fd_size, int *fd,
398399
{
399400
size_t i;
400401
int dummy = 0;
402+
unsigned char buf[1024];
401403

402404
srand(time(NULL));
403405

404406
*fd = open(testfile, O_CREAT | O_RDWR, 0664);
405407
if (*fd == -1)
406408
ksft_exit_fail_msg("Failed to create a file at %s\n", testfile);
407409

408-
for (i = 0; i < fd_size; i++) {
409-
unsigned char byte = (unsigned char)i;
410+
assert(fd_size % sizeof(buf) == 0);
411+
for (i = 0; i < sizeof(buf); i++)
412+
buf[i] = (unsigned char)i;
413+
for (i = 0; i < fd_size; i += sizeof(buf))
414+
write(*fd, buf, sizeof(buf));
410415

411-
write(*fd, &byte, sizeof(byte));
412-
}
413416
close(*fd);
414417
sync();
415418
*fd = open("/proc/sys/vm/drop_caches", O_WRONLY);

0 commit comments

Comments
 (0)