Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reduce the memory footprint of a minimal Linux process

Consider the following C program, 'pause.c':

void main() { pause(); }

Compiling this on x64 Linux 3.0.0-16-generic using this command 'gcc -Os pause.c -o pause' produces an executable of size ~8KB. When I run this executable and examine its precise memory footprint using 'pmap -d PID', it shows me that the private memory allocated to the process is 192KB (it varies across different systems usually, between 128KB and 192KB).

Examining the process using valgrind and massif fails to detect any memory allocation events. I was sceptical that the 192KB figure was accurate but I found that starting 5 instances of the 'pause' process did consume approximately 1MB of system memory.

I'm at a loss to explain the origin of this memory, can anyone provide some insight on why this memory is being allocated and any potential actions which could reduce it?, cheers.

like image 351
Gearoid Murphy Avatar asked Mar 27 '12 10:03

Gearoid Murphy


1 Answers

Reducing the stack limit will lower the memory footprint:

ulimit -s 8
like image 194
strkol Avatar answered Oct 19 '22 18:10

strkol