access_memory_even.c 809 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Artificial memory access program for testing DAMON.
  4. *
  5. * Receives number of regions and size of each region from user. Allocate the
  6. * regions and repeatedly access even numbered (starting from zero) regions.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. int main(int argc, char *argv[])
  12. {
  13. char **regions;
  14. int nr_regions;
  15. int sz_region;
  16. int i;
  17. if (argc != 3) {
  18. printf("Usage: %s <number> <size (bytes)>\n", argv[0]);
  19. return -1;
  20. }
  21. nr_regions = atoi(argv[1]);
  22. sz_region = atoi(argv[2]);
  23. regions = malloc(sizeof(*regions) * nr_regions);
  24. for (i = 0; i < nr_regions; i++)
  25. regions[i] = malloc(sz_region);
  26. while (1) {
  27. for (i = 0; i < nr_regions; i++) {
  28. if (i % 2 == 0)
  29. memset(regions[i], i, sz_region);
  30. }
  31. }
  32. return 0;
  33. }