如何减少最小Linux进程的内存占用 [英] How can I reduce the memory footprint of a minimal Linux process

查看:180
本文介绍了如何减少最小Linux进程的内存占用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下C程序'pause.c':

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

void main() { pause(); }

在x64 Linux 3.0.0-16-generic上使用此命令'gcc -Os pause.c -o pause'编译此文件,将生成大小约为〜8KB的可执行文件.当我运行此可执行文件并使用"pmap -d PID"检查其精确的内存占用量时,它显示给我分配给该进程的专用内存为192KB(通常在不同系统之间有所不同,介于128KB和192KB之间).

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).

使用valgrind和massif检查进程无法检测到任何内存分配事件.我对192KB的数字是否准确表示怀疑,但是我发现启动暂停"过程的5个实例确实消耗了大约1MB的系统内存.

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.

推荐答案

减少堆栈限制将减少内存占用:

Reducing the stack limit will lower the memory footprint:

ulimit -s 8

这篇关于如何减少最小Linux进程的内存占用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆