Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/raidz_test/raidz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ main(int argc, char **argv)
err = run_test(NULL);
}

mprotect(rand_data, SPA_MAXBLOCKSIZE, PROT_READ | PROT_WRITE);
Copy link
Member

@robn robn Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right about using mprotect() on memory obtained from libc (technically, wherever umem_alloc() got it from, which is kinda worse maybe?). POSIX explicitly says calling it on a pointer you didn't get from mmap() is unspecified, so.

I don't care for this PR, since we were already doing and your change is an improvement, but if you like we could just use an anonymous mapping:

diff --git a/cmd/raidz_test/raidz_test.c b/cmd/raidz_test/raidz_test.c
index 4839e909e4..eb1d6a562a 100644
--- a/cmd/raidz_test/raidz_test.c
+++ b/cmd/raidz_test/raidz_test.c
@@ -820,7 +820,8 @@ main(int argc, char **argv)
 	kernel_init(SPA_MODE_READ);
 
 	/* setup random data because rand() is not reentrant */
-	rand_data = (int *)umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
+	rand_data = (int *)mmap(NULL, SPA_MAXBLOCKSIZE, PROT_READ|PROT_WRITE,
+	    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
 	srand((unsigned)time(NULL) * getpid());
 	for (i = 0; i < SPA_MAXBLOCKSIZE / sizeof (int); i++)
 		rand_data[i] = rand();
@@ -835,7 +836,7 @@ main(int argc, char **argv)
 		err = run_test(NULL);
 	}
 
-	umem_free(rand_data, SPA_MAXBLOCKSIZE);
+	munmap(rand_data, SPA_MAXBLOCKSIZE);
 	kernel_fini();
 
 	return (err);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, assuming using an anonymous mapping works as hoped this does seems preferable. Still I don't think we need to hold up this PR on that. We can always follow up with this.


umem_free(rand_data, SPA_MAXBLOCKSIZE);
kernel_fini();

Expand Down
Loading