Skip to content

Commit fbb230a

Browse files
committed
test: avoid memsetting in favor of just touching one byte per page
To bring down the overhead of the testing script, only touch a single byte on each page (as that's enough to fault in the entire page), instead of memsetting everything. Signed-off-by: Patrick Roy <[email protected]>
1 parent 2f8228f commit fbb230a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

resources/overlay/usr/local/bin/fast_page_fault_helper.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919

2020
#define MEM_SIZE_MIB (128 * 1024 * 1024)
2121
#define NANOS_PER_SEC 1000000000
22+
#define PAGE_SIZE 4096
23+
24+
void touch_memory(void *mem, size_t size, char val) {
25+
void *end = mem + size;
26+
for (; mem < end; mem += PAGE_SIZE) {
27+
*((char *)mem) = val;
28+
}
29+
}
2230

2331
int main() {
2432
sigset_t set;
@@ -45,12 +53,12 @@ int main() {
4553
return 1;
4654
}
4755

48-
memset(ptr, 1, MEM_SIZE_MIB);
56+
touch_memory(ptr, MEM_SIZE_MIB, 1);
4957

5058
sigwait(&set, &signal);
5159

5260
clock_gettime(CLOCK_BOOTTIME, &start);
53-
memset(ptr, 2, MEM_SIZE_MIB);
61+
touch_memory(ptr, MEM_SIZE_MIB, 2);
5462
clock_gettime(CLOCK_BOOTTIME, &end);
5563

5664
duration_nanos = (end.tv_sec - start.tv_sec) * NANOS_PER_SEC + end.tv_nsec - start.tv_nsec;

0 commit comments

Comments
 (0)