pw_allocator: Track requested sizes in blocks

Previously, TrackingAllocator allocated extra space to store the
requested layout when it was requested to be tracked. This allowed it to
work with any allocator, but prevented the allocators it wrapped from
being able to make any adjustments to allocations, e.g. for
fragmentation purposes.

Moreover, all the usages of Block designed to address more than 64K of
memory are already wasting 2 bytes, since the offset type would be at
least 4 bytes, and the "info" field only 2.

Finally, the difference between the requested and allocated sizes are
guaranteed to be less than a block overhead, which is much less than
64K.

As a result, this CL:
 * Stores the excess bytes in a uint16_t "padding" field.
 * Implements GetRequestLayout for block allocators using that padding.
 * Simplifies TrackingAllocator by only support request_bytes metrics
   for allocators that implement GetRequestLayout.

Change-Id: I0303667afeadf90a8f44cd8866fb1adbf8f8b6d6
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/210395
Reviewed-by: Taylor Cramer <cramertj@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Aaron Green <aarongreen@google.com>
9 files changed
tree: b2d9a58eaa6ef55d0a1b0d37b233ecb7bf5d34e7
  1. .allstar/
  2. .github/
  3. .vscode/
  4. build_overrides/
  5. docker/
  6. docs/
  7. kudzu/
  8. pw_alignment/
  9. pw_allocator/
  10. pw_analog/
  11. pw_android_toolchain/
  12. pw_arduino_build/
  13. pw_assert/
  14. pw_assert_basic/
  15. pw_assert_log/
  16. pw_assert_tokenized/
  17. pw_assert_zephyr/
  18. pw_async/
  19. pw_async2/
  20. pw_async2_basic/
  21. pw_async2_epoll/
  22. pw_async_basic/
  23. pw_base64/
  24. pw_bloat/
  25. pw_blob_store/
  26. pw_bluetooth/
  27. pw_bluetooth_hci/
  28. pw_bluetooth_profiles/
  29. pw_bluetooth_proxy/
  30. pw_bluetooth_sapphire/
  31. pw_boot/
  32. pw_boot_cortex_m/
  33. pw_build/
  34. pw_build_android/
  35. pw_build_info/
  36. pw_build_mcuxpresso/
  37. pw_bytes/
  38. pw_channel/
  39. pw_checksum/
  40. pw_chre/
  41. pw_chrono/
  42. pw_chrono_embos/
  43. pw_chrono_freertos/
  44. pw_chrono_rp2040/
  45. pw_chrono_stl/
  46. pw_chrono_threadx/
  47. pw_chrono_zephyr/
  48. pw_cli/
  49. pw_clock_tree/
  50. pw_compilation_testing/
  51. pw_config_loader/
  52. pw_console/
  53. pw_containers/
  54. pw_cpu_exception/
  55. pw_cpu_exception_cortex_m/
  56. pw_cpu_exception_risc_v/
  57. pw_crypto/
  58. pw_digital_io/
  59. pw_digital_io_linux/
  60. pw_digital_io_mcuxpresso/
  61. pw_digital_io_rp2040/
  62. pw_dma_mcuxpresso/
  63. pw_docgen/
  64. pw_doctor/
  65. pw_emu/
  66. pw_env_setup/
  67. pw_env_setup_zephyr/
  68. pw_file/
  69. pw_format/
  70. pw_function/
  71. pw_fuzzer/
  72. pw_grpc/
  73. pw_hdlc/
  74. pw_hex_dump/
  75. pw_i2c/
  76. pw_i2c_linux/
  77. pw_i2c_mcuxpresso/
  78. pw_i2c_rp2040/
  79. pw_ide/
  80. pw_interrupt/
  81. pw_interrupt_cortex_m/
  82. pw_interrupt_xtensa/
  83. pw_interrupt_zephyr/
  84. pw_intrusive_ptr/
  85. pw_json/
  86. pw_kvs/
  87. pw_libc/
  88. pw_libcxx/
  89. pw_log/
  90. pw_log_android/
  91. pw_log_basic/
  92. pw_log_null/
  93. pw_log_rpc/
  94. pw_log_string/
  95. pw_log_tokenized/
  96. pw_log_zephyr/
  97. pw_malloc/
  98. pw_malloc_freelist/
  99. pw_malloc_freertos/
  100. pw_metric/
  101. pw_minimal_cpp_stdlib/
  102. pw_module/
  103. pw_multibuf/
  104. pw_multisink/
  105. pw_package/
  106. pw_perf_test/
  107. pw_persistent_ram/
  108. pw_polyfill/
  109. pw_preprocessor/
  110. pw_presubmit/
  111. pw_protobuf/
  112. pw_protobuf_compiler/
  113. pw_random/
  114. pw_result/
  115. pw_ring_buffer/
  116. pw_router/
  117. pw_rpc/
  118. pw_rpc_transport/
  119. pw_rust/
  120. pw_sensor/
  121. pw_snapshot/
  122. pw_software_update/
  123. pw_span/
  124. pw_spi/
  125. pw_spi_linux/
  126. pw_spi_mcuxpresso/
  127. pw_spi_rp2040/
  128. pw_status/
  129. pw_stm32cube_build/
  130. pw_stream/
  131. pw_stream_shmem_mcuxpresso/
  132. pw_stream_uart_linux/
  133. pw_stream_uart_mcuxpresso/
  134. pw_string/
  135. pw_symbolizer/
  136. pw_sync/
  137. pw_sync_baremetal/
  138. pw_sync_embos/
  139. pw_sync_freertos/
  140. pw_sync_stl/
  141. pw_sync_threadx/
  142. pw_sync_zephyr/
  143. pw_sys_io/
  144. pw_sys_io_ambiq_sdk/
  145. pw_sys_io_arduino/
  146. pw_sys_io_baremetal_lm3s6965evb/
  147. pw_sys_io_baremetal_stm32f429/
  148. pw_sys_io_emcraft_sf2/
  149. pw_sys_io_mcuxpresso/
  150. pw_sys_io_rp2040/
  151. pw_sys_io_stdio/
  152. pw_sys_io_stm32cube/
  153. pw_sys_io_zephyr/
  154. pw_system/
  155. pw_target_runner/
  156. pw_thread/
  157. pw_thread_embos/
  158. pw_thread_freertos/
  159. pw_thread_stl/
  160. pw_thread_threadx/
  161. pw_thread_zephyr/
  162. pw_tls_client/
  163. pw_tls_client_boringssl/
  164. pw_tls_client_mbedtls/
  165. pw_tokenizer/
  166. pw_toolchain/
  167. pw_toolchain_bazel/
  168. pw_trace/
  169. pw_trace_tokenized/
  170. pw_transfer/
  171. pw_uart/
  172. pw_unit_test/
  173. pw_unit_test_zephyr/
  174. pw_varint/
  175. pw_watch/
  176. pw_web/
  177. pw_work_queue/
  178. seed/
  179. targets/
  180. third_party/
  181. ts/
  182. zephyr/
  183. .bazelignore
  184. .bazelrc
  185. .bazelversion
  186. .black.toml
  187. .clang-format
  188. .clang-tidy
  189. .eslintrc.cjs
  190. .git-blame-ignore-revs
  191. .gitattributes
  192. .gitignore
  193. .gn
  194. .mypy.ini
  195. .prettierignore
  196. .prettierrc.cjs
  197. .pw_ide.yaml
  198. .pylintrc
  199. activate.bat
  200. Android.bp
  201. AUTHORS
  202. bootstrap.bat
  203. bootstrap.sh
  204. BUILD.bazel
  205. BUILD.gn
  206. BUILDCONFIG.gn
  207. CMakeLists.txt
  208. jest.config.ts
  209. Kconfig.zephyr
  210. LICENSE
  211. modules.gni
  212. OWNERS
  213. package-lock.json
  214. package.json
  215. pigweed.json
  216. PIGWEED_MODULES
  217. README.md
  218. rollup.config.js
  219. tsconfig.json
  220. WORKSPACE
  221. WORKSPACE_OWNERS
README.md

Pigweed

Pigweed is an open source collection of embedded-targeted libraries–or as we like to call them, modules. These modules are building blocks and infrastructure that enable faster and more reliable development on small-footprint MMU-less 32-bit microcontrollers like the STMicroelectronics STM32L452 or the Nordic nRF52832.

For more information please see our website: https://pigweed.dev/.

Links