How to reduce RAM

Asset Tracker Template

tags
Asset Tracker Template

To lower the module's RAM use, apply any of the following measures:

  • Minimize the enabled data types: Disable the modules whose data you do not forward or store, for example with CONFIG_APP_LOCATION=n. This reduces both the slabs and the RAM backend ring buffers, and it shrinks STORAGE_MAX_DATA_SIZE.
  • Reduce the records per type: Set CONFIG_APP_STORAGE_MAX_RECORDS_PER_TYPE=1 when you do not need buffering. This shrinks both the per-type slabs and the RAM ring buffers to a single record each.
  • Shrink the batch pipe buffer: Set the CONFIG_APP_STORAGE_BATCH_BUFFER_SIZE Kconfig option to a lower value, for example from 1024 down to 256 bytes. If you use batch mode, make sure the buffer can still hold at least one item of sizeof(header) + max_item_size.
  • Reduce the thread stack and the queues: Set the CONFIG_APP_STORAGE_THREAD_STACK_SIZE Kconfig option to a lower value, for example from 2048 down to 1024, if your application leaves headroom. You can also reduce the relevant zbus queue sizes in the system configuration if the traffic allows it.
  • Remove the development features: Disable the CONFIG_APP_STORAGE_SHELL and CONFIG_APP_STORAGE_SHELL_STATS Kconfig options to trim the RAM and code footprint.
  • Prefer the LittleFS backend when buffering many records: Use the LittleFS backend when you need a large CONFIG_APP_STORAGE_MAX_RECORDS_PER_TYPE value, because the RAM backend allocates all ring buffers at boot, while the LittleFS backend only uses RAM for the records that are currently stored.
  • Use the ready-made Kconfig fragment: Use overlay-storage-minimal.conf to apply a minimal storage configuration with reduced RAM usage.