Linux memory

目录

linux监控命令各字段含义详解:

Linux 了解内存使用:

proc.txt:

Malloc internal:

程序的虚拟内存

Openssl内存分配


Linux监控命令各字段含义详解:

linux监控命令各字段含义详解_weixin_34277853的博客-CSDN博客

voidcn.com/article/p-egpecvnq-yk.html

Linux 了解内存使用:

Linux 了解内存使用_黄规速博客:学如逆水行舟,不进则退-CSDN博客

proc.txt

Linux Kernel Documentation / filesystems / proc.txt

Linux中程序详细的内存使用查看_panderan的博客-CSDN博客

Malloc internal:

https://sourceware.org/glibc/wiki/MallocInternals

程序的虚拟内存

每个线程维护自己的heap用于malloc。机制的介绍:https://kushal.fedorapeople.org/siddhesh/posts/malloc-per-thread-arenas-in-glibc.html

Heap的大小可以用mallopt改变(M_MMAP_MAX)。

可以用pmap看到

# pmap 1
1:   /usr/lib/systemd/systemd --system --deserialize 18
0000561240af8000   1412K r-x-- systemd
0000561240e58000    140K r---- systemd
0000561240e7b000      4K rw--- systemd
00005612418e9000   1856K rw---   [ anon ]
00007f5534000000    164K rw---   [ anon ]
00007f5534029000  65372K -----   [ anon ]
00007f553c000000    164K rw---   [ anon ]    used heap for thread *
00007f553c029000  65372K -----   [ anon ]    unused heap for thread * (used + unused = 64M)

00007f5540dc7000      4K -----   [ anon ]
00007f5540dc8000   8192K rw---   [ anon ]     stack for thread x
00007f55415c8000      4K -----   [ anon ]
00007f55415c9000   8192K rw---   [ anon ]     stack for thread y
00007f5541dc9000      4K -----   [ anon ]
00007f5541dca000   8192K rw---   [ anon ]
00007f55425ca000     16K r-x-- libuuid.so.1.3.0

pmap就是将/proc/$pid/smaps内容打印出来。

each thread stack size configuration can be found:

# ulimit -a
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 256778
 

strace命令可以发现虚拟内存的堆分配:

#strace -f -ff -tt -e trace=all -o ~/systemcall.log <pid> 

-f   Trace child processes as they are created by currently traced processes as a result of the fork(2), vfork(2) and clone(2) system calls.

-ff    If  the  -o  filename  option is in effect, each processes trace is written to filename.pid

#cat systemcall.log

....

mmap(0x7efcbc000000, 67108864, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x7efcb4000000

.....

Dump memory:

dd if=/proc/12987/mem bs=1 skip=$((0x7f521effe000)) count=$((4*1024)) status=none

dd if=/proc/6744/mem bs=1 skip=$((0x01bb7000)) count=$((0x01c3e000-0x01bb7000)) status=none | strings | less

valgrind

valgrind能够查看内存的分配,但无法区分那个线程分配的内存。而且会改变原有的内存分配机制。因此主要是查看实际使用内存的分配和free的情况,无法查看实际虚拟内存的分配情况。当然也可以查看调用栈。

#valgrind --keep-stacktraces=alloc-and-free --trace-children=yes <command & args> 

#valgrind --tool=callgrind --track-origins=yes --separate-threads=yes <command & args>

Openssl内存分配

OpenSSL学习笔记——内存分配 _mm350670610的专栏-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值