Memory User Guide
1. Configuring Memory¶
1.1. Compile time¶
On the Pcupid platform, the memory is divided into multiple areas from a software perspective. This article mainly describes the MMA Heap area and the Linux system memory area.
-
MMA Heap area: The memory pool when the MI module is running. The memory used by the MI module to cache image data is requested from the MMA Heap.
-
Linux system memory: The memory required for Linux system operation.
make menuconfig in the project directory to enter the configuration interface, enter DRAM_LAYOUT, as shown in the following figure:

The meanings of the main options are:
-
dram_size: The size of physical memory; -
LX Memory Size: The memory size managed by the Linux system; -
MMA Memory Size: The size of the MMA Heap (maximum 512MByte);
According to the example in the figure, dram_size is 0x40000000, which is 1G byte, and LX Memory Size is also 1G byte, indicating that Linux manages the entire physical memory. MMA Memory Size is 0x10000000, which is 256M byte, indicating that a 256M byte memory is divided from the 1G byte physical memory as the MMA Heap area, and Linux will not request memory from the MMA Heap area in the future.
So in this example, the memory size of the MMA Heap is 256M bytes, and the memory size available to the Linux system is 768M bytes.
Developers can modify these configuration options, then execute make image-fast to repackage the image and then re-burn it to the chip.
1.2. Runtime¶
If you don't want to recompile the image, you can modify the UBOOT startup parameters at runtime to modify the MMA Heap size .
After entering UBOOT, modify the value of the bootargs environment variable and change value of sz in mma_heap=mma_heap_name0,miu=0,sz=0x8000000 to 0x8000000 to change the MMA Heap size to 128M:
setenv bootargs ubi.mtd=ubia,2048 root=/dev/mtdblock5 rootfstype=squashfs ro init=/linuxrc LX_MEM=0x1000000000,0x40000000 mma_heap=mma_heap_name0,miu=0,sz=0x8000000 mma_memblock_remove=1 cma=10M mtdparts=$(mtdparts) nohz=off saveenv reset
2. Insufficient memory¶
2.1. Insufficient MMA Heap¶
When the MMA Heap memory is insufficient, the MI module will not be able to request enough memory when running, and the following log will appear:
[MI ERR] _MI_SYS_Mma_MapVpaToPa [mi_sys][ 244 ]: PA Slice count 105 less than require count 158 [MI WRN] MI_SYS_Pass_AllocBufDefaultPolicy [mi_sys][ 1003 ]: Can 't Find Buf Allocation Error
When Sigmastar MMU is enabled, the memory in MMA Heap is managed in units of pages. The log above indicates that 158 pages are needed, but MMA Heap has only 105 free pages, which makes it impossible for the MI module to apply for a buffer to store data, then you need to increase the size of the MMA Heap.
2.2. Linux Out of Memory¶
When Linux runs out of memory, an OOM killer error will occur, killing some processes. For example, in the following example, the pipeline is destroyed due to insufficient Linux memory:
<4>preview invoked oom-killer: gfp_mask=0x1100cca(GFP_HIGHUSER_MOVABLE), order=0, oom_score_adj=0 <3>CPU: 0 PID: 812 Comm: preview Tainted: P O 5.10.117 #128 <3>Hardware name: SStar Soc (Flattened Device Tree) <3>[<c00113bd>] (unwind_backtrace) from [<c000ee27>] (show_stack+0xb/0xc) <3>[<c000ee27>] (show_stack) from [<c032a55d>] (dump_stack_lvl+0x61/0x74) <3>[<c032a55d>] (dump_stack_lvl) from [<c0328f0b>] (dump_header+0x37/0x184) <3>[<c0328f0b>] (dump_header) from [<c007f48f>] (oom_kill_process+0x53/0x1b8) <3>[<c007f48f>] (oom_kill_process) from [<c007faf9>] (out_of_memory+0x22d/0x278) <3>[<c007faf9>] (out_of_memory) from [<c009fa1b>] (__alloc_pages_nodemask+0x4c9/0x5e6) <3>[<c009fa1b>] (__alloc_pages_nodemask) from [<c007decd>] (pagecache_get_page+0x91/0xfc) <3>[<c007decd>] (pagecache_get_page) from [<c007e0bf>] (filemap_fault+0x167/0x2c4) <3>[<c007e0bf>] (filemap_fault) from [<c009345f>] (__do_fault+0x27/0x3e) <3>[<c009345f>] (__do_fault) from [<c00945cd>] (handle_mm_fault+0x2bb/0x50a) <3>[<c00945cd>] (handle_mm_fault) from [<c0013c73>] (do_page_fault+0x127/0x19c) <3>[<c0013c73>] (do_page_fault) from [<c0013e43>] (do_PrefetchAbort+0x27/0x58) <3>[<c0013e43>] (do_PrefetchAbort) from [<c000947b>] (__pabt_usr+0x5b/0x5c) <3>Exception stack(0xc1b2bfb0 to 0xc1b2bff8) <3>bfa0: 005e57d0 00537008 005e6f46 005e57d0 <3>bfc0: 004e1000 005e5860 005e58a0 be969798 00000000 00000000 b6f5e000 00000000 <3>bfe0: 00000007 be969798 0019cb43 0019beb6 80000030 ffffffff <3>Mem-Info: <3>active_anon:3 inactive_anon:336 isolated_anon:0 <3> active_file:2 inactive_file:0 isolated_file:0 <3> unevictable:0 dirty:0 writeback:0 <3> slab_reclaimable:235 slab_unreclaimable:2261 <3> mapped:4 shmem:0 pagetables:21 bounce:0 <3> free:794 free_pcp:0 free_cma:177 <3>Node 0 active_anon:12kB inactive_anon:1344kB active_file:8kB inactive_file:0kB unevictable:0kB isolated(anon):0kB isolated(file):0kB mapped:16kB dirty:0kB writeback:0kB shmem:0kB writeback_tmp:0kB kernel_stack:624kB all_unreclaimable? no <3>Normal free:3176kB min:644kB low:804kB high:964kB reserved_highatomic:2048KB active_anon:12kB inactive_anon:1344kB active_file:40kB inactive_file:32kB unevictable:0kB writepending:0kB present:32768kB managed:26084kB mlocked:0kB pagetables:84kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:708kB <3>lowmem_reserve[]: 0 0 0 <3>Normal: 52*4kB (UMCH) 33*8kB (UMH) 20*16kB (M) 15*32kB (M) 11*64kB (MC) 8*128kB (MC) 1*256kB (M) 0*512kB 0*1024kB 0*2048kB = 3256kB <3>3 total pagecache pages <3>8192 pages RAM <3>0 pages HighMem/MovableOnly <3>1671 pages reserved <3>512 pages cma reserved <6>Tasks state (memory values in pages): <6>[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name <6>[ 618] 0 618 697 23 8192 0 0 telnetd <6>[ 795] 0 795 697 30 8192 0 0 sh <6>[ 812] 0 812 4761 257 20480 0 0 preview <6>oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),task=preview,pid=812,uid=0 <3>Out of memory: Killed process 812 (preview) total-vm:19044kB, anon-rss:1028kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:20kB oom_score_adj:0 <6>oom_reaper: reaped process 812 (preview), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB
In this case, you need to reduce the size of the MMA Heap.
3. Adjust the most suitable MMA Heap¶
When the maximum scenario is determined, in order to prevent the MMA Heap from occupying excess memory, you can view the usage of the MMA Heap through cat /proc/mi_modules/mi_sys_mma/mma_heap_name0 when the maximum scenario is running:
/ # cat /proc/mi_modules/mi_sys_mma/mma_heap_name0 heap_info: heap_name pa_start length avail mma_heap_name0 102f600000 10000000 f373180
The above output indicates that the MMA Heap is 256 MB, and avail indicates that 243 MB is left. By appropriately reducing the size of the MMA Heap, more memory can be left for Linux.