Fundamentals 13 min read

How to Squeeze Extra RAM on a Resource‑Constrained Embedded Linux Device

This article examines memory usage on a Junzheng T31ZC embedded Linux board, breaks down physical and kernel allocations, and presents practical techniques—such as trimming kernel symbols, stripping ELF files, optimizing rootfs, and manually dropping caches—to reclaim valuable RAM without adding hardware.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Squeeze Extra RAM on a Resource‑Constrained Embedded Linux Device

Background

Embedded systems often have very limited RAM, especially consumer products that aim to minimize cost. When the running memory is already near 90% utilization, adding new features (e.g., a small algorithm, OTA updates, large dynamic buffers, or temporary files) can degrade performance or cause system crashes. The article explores software‑only methods to reclaim a few megabytes of RAM on a Junzheng T31ZC board.

Device Overview

The T31ZC is a MIPS‑based SOC with 512 Mbit (64 MiB) DDR2 memory, running a Linux kernel. The physical memory is split into two regions: rmem – reserved for multimedia (audio/video encoding, OSD, etc.) mem – used by the Linux system

Boot parameters (shown by cat /proc/cmdline) allocate 40 MiB to mem and 24 MiB to rmem. The kernel reports a total usable size of 40 MiB, but only 20 680 KiB is actually free after boot, leaving about 20 280 KiB unaccounted for.

Memory: 20680k/40960k

Further inspection of /proc/meminfo reveals that the missing memory is consumed by kernel code, data, init sections, and a large ramfs reservation (≈13 MiB) used for the root filesystem.

Optimization Directions

Reduce loaded kernel modules and system services.

Strip debugging symbols from the kernel image via menuconfig (disable "Load all symbols for debugging/ksymoops").

Optimize the rootfs: compress it, strip ELF binaries, and consider moving large libraries to a separate partition.

Consider deleting files from ramfs after they have been executed.

Rootfs Compression and Packaging

The rootfs is built by archiving _rootfs_camera with cpio and compressing it with lzop -9 -f. The mark_rootfs_pc utility writes the compressed size into the file header.

cd ./_rootfs_camera
find . | cpio -H newc -o > ../rootfs_camera.cpio
cd ..
lzop -9 -f rootfs_camera.cpio -o rootfs_camera.cpio.lzo
./mark_rootfs_pc rootfs_camera.cpio.lzo

After compression, the rootfs occupies about 6 MiB on flash, but 13 MiB is reserved in RAM for ramfs. This discrepancy arises because the flash image is compressed while the RAM copy is uncompressed.

Stripping ELF Files

ELF binaries (e.g., cywdhd.ko) contain debug symbols that increase their size. Using strip reduces the on‑disk size from ~1 MiB to ~658 KiB, and the kernel reports a smaller loaded size (671 KiB) after stripping.

Deleting Files After Use

Since ramfs resides entirely in RAM, files such as the main executable ( main, 6.2 MiB) can be removed after they have been launched, freeing the occupied memory. However, deleting kernel modules or firmware (e.g., fw_bcm43438a1.bin) may be risky because they might be needed later.

Manual Cache Dropping

Linux allows explicit cache reclamation with:

echo 1 > /proc/sys/vm/drop_caches

Consult man proc for details.

Risk Assessment

Removing a loaded ELF file is safe only if the program has already been fully loaded into memory.

Kernel modules shown as Live in /proc/modules are actively used; deleting their source files does not affect the running module but may prevent re‑loading.

Firmware files required by drivers (e.g., fw_bcm43438a1.bin) should generally remain on flash to avoid driver failures.

Conclusion

When RAM is scarce on an embedded Linux system, the following measures can be combined to reclaim space:

Disable kernel debug symbols in menuconfig.

Strip unnecessary symbols from ELF binaries and kernel modules.

Compress and trim the rootfs, moving large libraries to a non‑RAM partition if possible.

Delete temporary executables or drivers from ramfs after they have been used (with caution).

Manually drop caches when needed.

The appropriate mix of these techniques depends on the specific device constraints and application requirements.

memory optimizationLinuxembeddedstriprootfsdrop_cachesramfs
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.