README 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ==================
  2. Memblock simulator
  3. ==================
  4. Introduction
  5. ============
  6. Memblock is a boot time memory allocator[1] that manages memory regions before
  7. the actual memory management is initialized. Its APIs allow to register physical
  8. memory regions, mark them as available or reserved, allocate a block of memory
  9. within the requested range and/or in specific NUMA node, and many more.
  10. Because it is used so early in the booting process, testing and debugging it is
  11. difficult. This test suite, usually referred as memblock simulator, is
  12. an attempt at testing the memblock mechanism. It runs one monolithic test that
  13. consist of a series of checks that exercise both the basic operations and
  14. allocation functionalities of memblock. The main data structure of the boot time
  15. memory allocator is initialized at the build time, so the checks here reuse its
  16. instance throughout the duration of the test. To ensure that tests don't affect
  17. each other, region arrays are reset in between.
  18. As this project uses the actual memblock code and has to run in user space,
  19. some of the kernel definitions were stubbed by the initial commit that
  20. introduced memblock simulator (commit 16802e55dea9 ("memblock tests: Add
  21. skeleton of the memblock simulator")) and a few preparation commits just
  22. before it. Most of them don't match the kernel implementation, so one should
  23. consult them first before making any significant changes to the project.
  24. Usage
  25. =====
  26. To run the tests, build the main target and run it:
  27. $ make && ./main
  28. A successful run produces no output. It is possible to control the behavior
  29. by passing options from command line. For example, to include verbose output,
  30. append the `-v` options when you run the tests:
  31. $ ./main -v
  32. This will print information about which functions are being tested and the
  33. number of test cases that passed.
  34. For the full list of options from command line, see `./main --help`.
  35. It is also possible to override different configuration parameters to change
  36. the test functions. For example, to simulate enabled NUMA, use:
  37. $ make NUMA=1
  38. For the full list of build options, see `make help`.
  39. Project structure
  40. =================
  41. The project has one target, main, which calls a group of checks for basic and
  42. allocation functions. Tests for each group are defined in dedicated files, as it
  43. can be seen here:
  44. memblock
  45. |-- asm ------------------,
  46. |-- lib |-- implement function and struct stubs
  47. |-- linux ------------------'
  48. |-- scripts
  49. | |-- Makefile.include -- handles `make` parameters
  50. |-- tests
  51. | |-- alloc_api.(c|h) -- memblock_alloc tests
  52. | |-- alloc_helpers_api.(c|h) -- memblock_alloc_from tests
  53. | |-- alloc_nid_api.(c|h) -- memblock_alloc_try_nid tests
  54. | |-- basic_api.(c|h) -- memblock_add/memblock_reserve/... tests
  55. | |-- common.(c|h) -- helper functions for resetting memblock;
  56. |-- main.c --------------. dummy physical memory definition
  57. |-- Makefile `- test runner
  58. |-- README
  59. |-- TODO
  60. |-- .gitignore
  61. Simulating physical memory
  62. ==========================
  63. Some allocation functions clear the memory in the process, so it is required for
  64. memblock to track valid memory ranges. To achieve this, the test suite registers
  65. with memblock memory stored by test_memory struct. It is a small wrapper that
  66. points to a block of memory allocated via malloc. For each group of allocation
  67. tests, dummy physical memory is allocated, added to memblock, and then released
  68. at the end of the test run. The structure of a test runner checking allocation
  69. functions is as follows:
  70. int memblock_alloc_foo_checks(void)
  71. {
  72. reset_memblock_attributes(); /* data structure reset */
  73. dummy_physical_memory_init(); /* allocate and register memory */
  74. (...allocation checks...)
  75. dummy_physical_memory_cleanup(); /* free the memory */
  76. }
  77. There's no need to explicitly free the dummy memory from memblock via
  78. memblock_free() call. The entry will be erased by reset_memblock_regions(),
  79. called at the beginning of each test.
  80. Known issues
  81. ============
  82. 1. Requesting a specific NUMA node via memblock_alloc_node() does not work as
  83. intended. Once the fix is in place, tests for this function can be added.
  84. 2. Tests for memblock_alloc_low() can't be easily implemented. The function uses
  85. ARCH_LOW_ADDRESS_LIMIT marco, which can't be changed to point at the low
  86. memory of the memory_block.
  87. References
  88. ==========
  89. 1. Boot time memory management documentation page:
  90. https://www.kernel.org/doc/html/latest/core-api/boot-time-mm.html