Re: [PATCH v5 03/10] selftests/mm: test splitting file-backed THP to any lower order.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 2025/1/17 05:10, Zi Yan wrote:
Now split_huge_page*() supports shmem THP split to any lower order.
Test it.

The test now reads file content out after split to check if the split
corrupts the file data.

Signed-off-by: Zi Yan <ziy@xxxxxxxxxx>

LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
Tested-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>

---
  .../selftests/mm/split_huge_page_test.c       | 30 ++++++++++++++-----
  1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c
index eccaa347140b..766c1f3a1d78 100644
--- a/tools/testing/selftests/mm/split_huge_page_test.c
+++ b/tools/testing/selftests/mm/split_huge_page_test.c
@@ -261,14 +261,16 @@ void split_pte_mapped_thp(void)
  	close(kpageflags_fd);
  }
-void split_file_backed_thp(void)
+void split_file_backed_thp(int order)
  {
  	int status;
  	int fd, shmem_sysctl_fd;
  	ssize_t num_written, num_read;
  	char tmpfs_template[] = "/tmp/thp_split_XXXXXX";
  	const char *tmpfs_loc = mkdtemp(tmpfs_template);
-	char testfile[INPUT_MAX], sysctl_buf[INPUT_MAX] = {0};
+	char testfile[INPUT_MAX];
+	char sysctl_buf[INPUT_MAX] = {0};
+	char file_buf[INPUT_MAX] = {0};
  	uint64_t pgoff_start = 0, pgoff_end = 1024;
  	const char *shmem_sysctl = "/sys/kernel/mm/transparent_hugepage/shmem_enabled";
  	char *opt1, *opt2;
@@ -314,7 +316,7 @@ void split_file_backed_thp(void)
  		ksft_exit_fail_msg("Fail to create file-backed THP split testing file\n");
  	}
- fd = open(testfile, O_CREAT|O_WRONLY, 0664);
+	fd = open(testfile, O_CREAT|O_RDWR, 0664);
  	if (fd == -1) {
  		ksft_perror("Cannot open testing file");
  		goto cleanup;
@@ -322,7 +324,6 @@ void split_file_backed_thp(void)
/* write something to the file, so a file-backed THP can be allocated */
  	num_written = write(fd, tmpfs_loc, strlen(tmpfs_loc) + 1);
-	close(fd);
if (num_written < 1) {
  		ksft_perror("Fail to write data to testing file");
@@ -330,8 +331,22 @@ void split_file_backed_thp(void)
  	}
/* split the file-backed THP */
-	write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, 0);
+	write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end, order);
+
+	/* check file content after split */
+	num_read = lseek(fd, 0, SEEK_SET);
+	if (num_read == -1) {
+		ksft_perror("Cannot lseek file");
+		goto cleanup;
+	}
+ num_read = read(fd, file_buf, num_written);
+	if (num_read < 1 || strncmp(file_buf, tmpfs_loc, num_read)) {
+		ksft_print_msg("File content changed, origin: %s, now: %s\n", tmpfs_loc, file_buf);
+		goto cleanup;
+	}
+
+	close(fd);
  	status = unlink(testfile);
  	if (status) {
  		ksft_perror("Cannot remove testing file");
@@ -520,7 +535,7 @@ int main(int argc, char **argv)
  	if (argc > 1)
  		optional_xfs_path = argv[1];
- ksft_set_plan(1+8+2+9);
+	ksft_set_plan(1+8+1+9+9);
pagesize = getpagesize();
  	pageshift = ffs(pagesize) - 1;
@@ -537,7 +552,8 @@ int main(int argc, char **argv)
  			split_pmd_thp_to_order(i);
split_pte_mapped_thp();
-	split_file_backed_thp();
+	for (i = 0; i < 9; i++)
+		split_file_backed_thp(i);
created_tmp = prepare_thp_fs(optional_xfs_path, fs_loc_template,
  			&fs_loc);




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux