Skip to content

[FEATURE] Improve reporting about memory allocation through IPC4 #10570

Open

Description

@wjablon1

While handling LARGE_CONFIG_GET->MEMORY_STATE_INFO_GET, SOF FW always reports the total amount of pages (compile time constants) instead of the current usage. Usefulness of this information is limited. It would be nice to have the real data that gets updated after topology load. Benefits:

  1. Allow HW/Architecture teams to optimize memory (size/provision)
  2. Allow clients (e.g. Topology designers) to experiment and assess memory footprints of individual components/features
  3. Check for memory leaks (e.g. reloading topology in a loop and checking the allocation size)

I discovered this gap some time ago. But recently there was an ask about SOF memory footprint. So maybe it's time to properly handle this IPC.

Activity

  1. lgirdwood commented on Feb 24, 2026

    @lgirdwood
    Member

    Ack @wjablon1 - we should also be able to get

    1. thread heap/stack usage - all threads.
    2. virtual memory usage
    3. phy memory usage
    4. imr usage.
  2. wjablon1 commented on Apr 16, 2026

    @wjablon1
    ContributorAuthor

    After research, I think this message is not as useful as I thought.

    The free pages counter is somewhat useful for assessing the overall memory usage. However, it's not that useful for assessing sizes of individual audio components or detecting memory leaks (page size resolution is too low).

    Theoretically we could implement this, but IMO it would be problematic. Zephyr has a generic statistic solution for all implementations based on block allocators (including L2 paging). The issue here is that this solution can only be enabled for all such allocators (not just L2 paging) through SYS_MEM_BLOCKS_RUNTIME_STATS Kconfig option. So from SOF perspective it makes more sense to have a separate build/overlay with statistics rather than this IPC.

    In addition to the free pages counter, the MEMORY_STATE_INFO_GET IPC contains other statistics that are not even implemented in reference FW (a comment says that those IPC fields are for backward compatibility as the driver doesn’t use them):

    1. Memory Banks stats (I think this is useful mostly for power management)
    2. Page bitmap (TLB). This could be useful only in the event of memory fragmentation issue. I did some testing (with AI generated code) and couldn't observe such an issue. I found only transient fragmentations (for example if I deleted 2n pipelined before 1st) but other than that the physical page allocation looks dense and hence it's not an interesting statistic.

    All in all, I think we should keep the IPC as is and add memory statistics into a separate build target/overlay.

  3. lgirdwood commented on Apr 21, 2026

    @lgirdwood
    Member

    @wjablon1 I think this idea has a lot of merit. I would encourage you to continue because we do need a method to extract runtime memory usage and core utilization and having a IPC4 class to accommodate this would be essential. e.g. it would be goot to have a dsptop command like top for CPU or nvtop for GFX.

    Please see the SOF qemu repo intel_ace branch as I've added a lot of these utility commands to the qemu monitor e.g.

    (qemu) info ace-sram -s
    Intel ADSP ACE HP SRAM Banks (36 total):
      HP Bank  0: Base 0xa0020000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0020000: [ffffffffffffffffffffffffffffffff]
      HP Bank  1: Base 0xa0040000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0040000: [ffffffffffffffffffffffffffffffff]
      HP Bank  2: Base 0xa0060000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0060000: [ffffffffffffffffffffffffffffffff]
      HP Bank  3: Base 0xa0080000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0080000: [ffffffffffffffffffffffffffffefff]
      HP Bank  4: Base 0xa00a0000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa00a0000: [fffffffffffffffffffffffffeffeeff]
      HP Bank  5: Base 0xa00c0000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa00c0000: [ffffffffffefffffffffffffffffffef]
      HP Bank  6: Base 0xa00e0000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa00e0000: [fefffffffffffffffffffffffffffffe]
      HP Bank  7: Base 0xa0100000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0100000: [feffffffffefefffffffffffffffffff]
      HP Bank  8: Base 0xa0120000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0120000: [ffffffffffffffffffffffffffffffff]
      HP Bank  9: Base 0xa0140000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0140000: [ffffffffffffffffffffffffffffffff]
      HP Bank 10: Base 0xa0160000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0160000: [ffffffffffffffffffffffffffffffff]
      HP Bank 11: Base 0xa0180000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa0180000: [ffffffffffffffffffffffffffffffff]
      HP Bank 12: Base 0xa01a0000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa01a0000: [ffffffffffffffffffffffffffffffff]
      HP Bank 13: Base 0xa01c0000, Size 128KB, State: ON           (PGCTL=0x00, RMCTL=0x01)
        Usage: (32/32 pages used)
          0xa01c0000: [ffffffffffffffffffffffffffffffff]
      HP Bank 14: Base 0xa01e0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (1/32 pages used)
          0xa01e0000: [00000000100000000000000000000000]
      HP Bank 15: Base 0xa0200000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0200000: [00000000000000000000000000000000]
      HP Bank 16: Base 0xa0220000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0220000: [00000000000000000000000000000000]
      HP Bank 17: Base 0xa0240000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0240000: [00000000000000000000000000000000]
      HP Bank 18: Base 0xa0260000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0260000: [00000000000000000000000000000000]
      HP Bank 19: Base 0xa0280000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0280000: [00000000000000000000000000000000]
      HP Bank 20: Base 0xa02a0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa02a0000: [00000000000000000000000000000000]
      HP Bank 21: Base 0xa02c0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa02c0000: [00000000000000000000000000000000]
      HP Bank 22: Base 0xa02e0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa02e0000: [00000000000000000000000000000000]
      HP Bank 23: Base 0xa0300000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0300000: [00000000000000000000000000000000]
      HP Bank 24: Base 0xa0320000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0320000: [00000000000000000000000000000000]
      HP Bank 25: Base 0xa0340000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0340000: [00000000000000000000000000000000]
      HP Bank 26: Base 0xa0360000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0360000: [00000000000000000000000000000000]
      HP Bank 27: Base 0xa0380000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0380000: [00000000000000000000000000000000]
      HP Bank 28: Base 0xa03a0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa03a0000: [00000000000000000000000000000000]
      HP Bank 29: Base 0xa03c0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa03c0000: [00000000000000000000000000000000]
      HP Bank 30: Base 0xa03e0000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa03e0000: [00000000000000000000000000000000]
      HP Bank 31: Base 0xa0400000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0400000: [00000000000000000000000000000000]
      HP Bank 32: Base 0xa0420000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0420000: [00000000000000000000000000000000]
      HP Bank 33: Base 0xa0440000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0440000: [00000000000000000000000000000000]
      HP Bank 34: Base 0xa0460000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0460000: [00000000000000000000000000000000]
      HP Bank 35: Base 0xa0480000, Size 128KB, State: OFF          (PGCTL=0x01, RMCTL=0x01)
        Usage: (0/32 pages used)
          0xa0480000: [00000000000000000000000000000000]
      HP Summary: 14 ON, 22 OFF, Mem Usage: 449 / 1152 pages used (39.0%)
    
    Intel ADSP ACE LP SRAM Banks (8 total):
      LP Bank  0: Base 0xa0000000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa0000000: [ff]
      LP Bank  1: Base 0xa0002000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa0002000: [ff]
      LP Bank  2: Base 0xa0004000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa0004000: [ff]
      LP Bank  3: Base 0xa0006000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa0006000: [ff]
      LP Bank  4: Base 0xa0008000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa0008000: [ff]
      LP Bank  5: Base 0xa000a000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa000a000: [ff]
      LP Bank  6: Base 0xa000c000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa000c000: [ff]
      LP Bank  7: Base 0xa000e000, Size   8KB, State: ON           (PGCTL=0x00, RMCTL=0x00)
        Usage: (2/2 pages used)
          0xa000e000: [ff]
      LP Summary: 8 ON, 0 OFF, Mem Usage: 16 / 16 pages used (100.0%)
    
  4. wjablon1 commented on Apr 22, 2026

    @wjablon1
    ContributorAuthor

    @lgirdwood Then I guess we should implement both options:

    1. For the overall memory usage use the IPC4 message.
    2. For fine-grained memory statistics I see two solutions:
    • Just print logs
    • Use a memory window space to create a file or even proc-like directory structure. Then we can have some higher-level tools for dumping/polling that data (like e.g. top command does).

    One question regarding the MEMORY_STATE_INFO_GET: Do you want to have all the mentioned IPC fields implemented, including the ones that are not even supported by the reference FW (like e.g. Page/TLB bitmap)?

  5. lgirdwood commented on Apr 22, 2026

    @lgirdwood
    Member

    @lgirdwood Then I guess we should implement both options:

    1. For the overall memory usage use the IPC4 message.
    2. For fine-grained memory statistics I see two solutions:

    Yes - for 1 we would also need core utilization % - i.e. this would give us a very high level view

    • Just print logs
    • Use a memory window space to create a file or even proc-like directory structure. Then we can have some higher-level tools for dumping/polling that data (like e.g. top command does).

    One question regarding the MEMORY_STATE_INFO_GET: Do you want to have all the mentioned IPC fields implemented, including the ones that are not even supported by the reference FW (like e.g. Page/TLB bitmap)?

    Yes, more is better here, especially when we have fine grained control of what data we need.

    Btw, we also have shell support now, so there will be the ability to have a DSP shell and execute commands

  6. wjablon1 commented on Apr 22, 2026

    @wjablon1
    ContributorAuthor

    Yes, the shell is also a good point. Looks like some useful commands are already there and if anything is missing, we can just enhance Zephyr using the already present infrastructure instead of reinventing the wheel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions