world leader in high performance signal processing
Trace: » reduce_kernel_memory_footprint

Frequently people ask whether Blackfin uClinux can run with N MB RAM. The answer depends on what features are considered necessary for your system. You can remove “unnecessary” features from kernel. Then you can further configure kernel to optimize memory usage, thus spare more RAM for your application. Bellow is a list of suggestions:

Before we start

Bellow test is done using BF537 STAMP board, which has 64MB SDRAM. And we use “mem” and “memmap” kernel boot options to set different memory layout managed by kernel:

linux/Documentation/kernel-parameters:

        mem=nn[KMG]     [KNL,BOOT] Force usage of a specific amount of memory
                        Amount of memory to be used when the kernel is not able
                        to see the whole system memory or for test.

        memmap=nn[KMG]@ss[KMG]
                        [KNL] Force usage of a specific region of memory
                        Region of memory to be used, from ss to ss+nn.

        memmap=nn[KMG]$ss[KMG]
                        [KNL,ACPI] Mark specific memory as reserved.
                        Region of memory to be used, from ss to ss+nn.

As the BF537 HWR mentioned, in order to connect SDRAM less than 16MB to Blackfin, the SDRAM has to be mapped into non-contiguous regions of the processor’s memory space. In our case, we want to test with 8MB SDRAM, the memory address space will be organized as:

- 0x0000 0000 (zero) to 0x0040 0000 (4Meg)
- 0x0080 0000 (8Meg) to 0x00C0 0000 (12Meg)

We will add “mem=12M memmap=4M$4M” to kernel boot option.

Disable unused components

The components include device drivers, file systems, network protocols. Use kernel modules if possible.

Put rootfs in flash

If rootfs has to reside in RAM, its size is also need to be reduced. However, here the rootfs is put into flash.

Using JFFS2

Please refer to jffs. Here is a sample memory usage with 8MB memory (“mem=12M memmap=4M$4M”) configuration, while the TCP/IP and jffs2 are supported.

root:/> dmesg
Kernel command line: root=/dev/mtdblock2 rw rootfstype=jffs2 mem=12M memmap=4M$4M                                                                           
Memory available: 6400k/12288k RAM, (64k init code, 1029k kernel code, 401k data, 0k dma, 4396k reserved) 
[snip]

root:/> cat /proc/meminfo                                                                                   
MemTotal:         6464 kB                                                                                   
MemFree:          1764 kB                                                                                   
Buffers:             0 kB                                                                                   
Cached:            800 kB                                                                                   
SwapCached:          0 kB                                                                                   
Active:            444 kB                                                                                   
Inactive:          356 kB                                                                                   
SwapTotal:           0 kB                                                                                   
SwapFree:            0 kB                                                                                   
Dirty:               0 kB                                                                                   
Writeback:           0 kB                                                                                   
AnonPages:           0 kB                                                                                   
Mapped:              0 kB                                                                                   
Slab:             1204 kB                                                                                   
SReclaimable:      200 kB                                                                                   
SUnreclaim:       1004 kB                                                                                   
PageTables:          0 kB                                                                                   
NFS_Unstable:        0 kB                                                                                   
Bounce:              0 kB                                                                                   
CommitLimit:      3232 kB                                                                                   
Committed_AS:        0 kB                                                                                   
VmallocTotal:        0 kB                                                                                   
VmallocUsed:         0 kB                                                                                   
VmallocChunk:        0 kB                                                                                   

root:/> cat /proc/buddyinfo                                                                                 
Node 0, zone      DMA      3      1      1      0      1      1      0      1      1      0      0      0 

root:/> cat /proc/maps                                                                                      
00158000-0015f000 r-xs 00000000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
00161000-00162000 rw-p 00002000 1f:02 154        /bin/init                                                  
00164000-00167000 r-xs 00000000 1f:02 154        /bin/init                                                  
001d4000-001d5000 rw-p 00000000 00:00 0                                                                     
001ea000-001eb000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
001f4000-001f7000 r-xs 00000000 1f:02 205        /lib/libcrypt-0.9.29.so                                    
00200000-00216000 rw-p 00000000 00:00 0                                                                     
00220000-00240000 rwxp 00000000 00:00 0                                                                     
0024c000-0024d000 rw-p 00000000 00:00 0                                                                     
0024e000-00250000 rw-p 00000000 00:00 0                                                                     
00250000-0025d000 rw-p 00056000 1f:02 35         /bin/busybox                                               
00800000-00857000 r-xs 00000000 1f:02 35         /bin/busybox                                               
008be000-008bf000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
008bf000-008c0000 rw-p 00000000 00:00 0                                                                     
008c0000-008cd000 rw-p 00056000 1f:02 35         /bin/busybox                                               
008d0000-008d5000 rw-p 00000000 00:00 0                                                                     
008e0000-00900000 rwxp 00000000 00:00 0                                                                     
00900000-00920000 rwxp 00000000 00:00 0                                                                     
00928000-0092d000 rw-p 00000000 00:00 0                                                                     
00930000-00933000 r-xs 00000000 1f:02 153        /bin/inetd                                                 
00936000-00938000 rw-p 00000000 00:00 0                                                                     
00940000-00960000 rwxp 00000000 00:00 0                                                                     
00967000-00968000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
00973000-00974000 rw-p 00000000 00:00 0                                                                     
00974000-00975000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
00975000-00976000 rw-p 00000000 00:00 0                                                                     
00977000-00978000 rw-p 00000000 00:00 0                                                                     
00978000-0097a000 rw-p 00000000 00:00 0                                                                     
0097b000-0097c000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
0097e000-00980000 rw-p 00000000 00:00 0                                                                     
00980000-0098d000 rw-p 00056000 1f:02 35         /bin/busybox                                               
00990000-00995000 rw-p 00000000 00:00 0                                                                     
00998000-00999000 rw-p 00000000 00:00 0                                                                     
00999000-0099a000 rw-p 00000000 00:00 0                                                                     
0099a000-0099b000 rw-p 00000000 00:00 0                                                                     
0099c000-0099e000 rw-p 00000000 00:00 0                                                                     
0099f000-009a0000 rw-p 00000000 00:00 0                                                                     
009a2000-009a3000 rw-p 00000000 00:00 0                                                                     
009a3000-009a4000 rw-p 00002000 1f:02 153        /bin/inetd                                                 
009b0000-009bd000 rw-p 00056000 1f:02 35         /bin/busybox                                               
009c0000-009e0000 rwxp 00000000 00:00 0                                                                     
009e0000-009e5000 rw-p 00000000 00:00 0                                                                     
009e8000-009ea000 rw-p 00000000 00:00 0                                                                     
009ea000-009eb000 rw-p 00006000 1f:02 202        /lib/ld-uClibc-0.9.29.so                                   
009eb000-009ec000 rw-p 00000000 00:00 0                                                                     
009ef000-009f0000 rw-p 00000000 00:00 0                                                                     
009f0000-009f5000 rw-p 00000000 00:00 0                                                                     
00a00000-00a20000 rwxp 00000000 00:00 0                                                                     
00a20000-00a32000 rw-p 00000000 00:00 0                                                                     
00a40000-00a4b000 r-xs 00000000 1f:02 209        /lib/libgcc_s.so.1                                         
00a54000-00a56000 rw-p 00000000 00:00 0                                                                     
00a80000-00ab8000 r-xs 00000000 1f:02 224        /lib/libuClibc-0.9.29.so                                   
00ad0000-00ad5000 rw-p 00000000 00:00 0                                                                     
00ade000-00adf000 rw-p 00000000 00:00 0   

root:/proc> ps -ef
  PID  Uid        VSZ Stat Command
    1 root        564 S   /sbin/init 
    2 root            SW< [kthreadd]
    3 root            RWN [ksoftirqd/0]
    4 root            SW< [events/0]
    5 root            SW< [khelper]
   13 root            SW< [kblockd/0]
   25 root            SW  [pdflush]
   26 root            SW  [pdflush]
   27 root            SW< [kswapd0]
   28 root            SW< [aio/0]
   38 root            SW< [mtdblockd]
   54 root            SWN [jffs2_gcd_mtd2]
   73 root        480 S   inetd 
   75 root        964 S   -/bin/sh 
   76 root        864 S   /sbin/syslogd -n 
   77 root        864 S   /sbin/klogd -n 
   92 root        868 R   ps -ef                                                                     

From the information above, we can see among the 8MB total memory, about 2000K is used by applications (busybox, inetd), 1430K used by kernel image, 800K for pagecache, 1204K for slab.

Advanced configurations

Configure standard kernel features (for small systems)

The kernel configure options under “General setup” --> “Configure standard kernel features (for small systems)” are interesting to us.

Slab, Slub, Slob?

Limiting pagecache size

XIP

Add more

Complete Table of Contents/Topics