大网数据广告活动
服务器运维问答

Long TCPDUMP capture taking slowly but surely all available memory in RAM

· 52CE 我爱测

When I tcpdump the network traffic on my ubuntu server, I see the free memory decreasing with time. It seems that the captures are stored in memory. At first, I noticed the problem because i was saving the captures in /tmp folder…

问题原文

原帖链接 · Franck · CC BY-SA 4.0

When I tcpdump the network traffic on my ubuntu server, I see the free memory decreasing with time.

It seems that the captures are stored in memory. At first, I noticed the problem because i was saving the captures in /tmp folder which is stored in RAM.

I then stored the capture on disk but I see the same issue; And as soon as I delete the on-disk captures, the RAM memory is freed !

Here is the tcpdump command

sudo tcpdump -i lo -W 300 -C 100 -s0 -w /home/user/file.pcap &
// BEFORE
free -m
              total        used        free      shared  buff/cache   available
Mem:          14683        3422        6709         153        4551       10745
Swap:             0           0           0
// DELETING THE CAPTURES
rm /home/user/file.pcap*
// AFTER
free -m
              total        used        free      shared  buff/cache   available
Mem:          14683        3399        8267         153        3016       10768

How can I make sure the captures are not taking all the free memory available ?

The goal is to let the tcpdump run during several days.

已采纳解答

原帖链接 · wurtel · CC BY-SA 4.0

Don't look at the free column when determining available memory; look at available.

Linux will use unused memory as buffer cache for files, to speed up access to those files. You're writing lots of tcpdump packet capture data to the filesystem, so that also gets buffered in memory. When you stop the capture process and delete the file, the buffer cache used for that file also gets freed.

If the system really needs the memory e.g. for process data, then the buffer cache will also be freed up, which will mean that accessing the data in the file will cause the file to be read from disk instead of from the buffer cache.

That is why the available column adds the free and buff/cache columns to give available.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-08-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。