记一次虚拟内存跑满排查:
# free -g
total used free shared buff/cache available
Mem: 46 4 35 3 6 36
Swap: 7 7 0
使用以下命令查看哪个进程占用虚拟内存较高:
# ps aux --sort=-vsz | head -n 2
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 6309 0.1 72.6 44376428 35781496 ? Ss 2022 1399:43 /usr/sbin/abrtd -d -s
/usr/sbin/abrtd是Automatic Bug Reporting Tool Daemon的简称,它是一个自动获取系统错误信息并生成相应报告的守护进程。由于它会捕获系统的错误信息和内存转储文件,因此可能会占用较高的虚拟内存。
如果您发现/usr/sbin/abrtd占用的虚拟内存较高,可以尝试以下方法来解决问题:
禁用Automatic Bug Reporting Tool服务,此方法会禁用此服务并停止所有相关的守护进程。您可以通过运行以下命令来实现:
systemctl stop abrtd.service
systemctl disable abrtd.service
清理abrtd服务缓存,在停止服务后,可以将/var/spool/abrt目录下的缓存文件清理干净,以释放一些虚拟内存。运行以下命令来清理此目录下的所有文件:
rm -rf /var/spool/abrt/*
请注意,禁用或删除Automatic Bug Reporting Tool可能会影响您系统的稳定性和安全性,所以在操作之前,请一定要确保您已了解相关的风险以及相应的后果。
释放Linux虚拟内存通常可以通过以下方法:
- 通过 sync 命令刷写磁盘缓存,以释放一部分虚拟内存。
- 通过 echo 1 > /proc/sys/vm/drop_caches 命令清空页缓存、目录项缓存和 inode 缓存,以释放虚拟内存。
- 通过 sysctl -w vm.drop_caches=3 命令清空页缓存、目录项缓存、inode缓存和swap缓存,以释放虚拟内存。
- 通过 swapoff -a 命令关闭所有的交换分区,并通过 swapon -a 命令重新启用交换分区,以释放虚拟内存。
需要注意的是,释放虚拟内存可能会影响系统性能,因此在操作之前需要慎重考虑。
综合以上方法,先查看abrtd的运行状态看看:
# systemctl status abrtd.service
● abrtd.service - ABRT Automated Bug Reporting Tool
Loaded: loaded (/usr/lib/systemd/system/abrtd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-01-21 04:10:15 CST; 1 years 4 months ago
Main PID: 6309 (abrtd)
CGroup: /system.slice/abrtd.service
└─6309 /usr/sbin/abrtd -d -s
May 31 14:10:32 test abrtd[6309]: fork: Cannot allocate memory
May 31 14:50:32 test abrtd[6309]: fork: Cannot allocate memory
May 31 15:00:39 test abrtd[6309]: fork: Cannot allocate memory
May 31 15:40:32 test abrtd[6309]: fork: Cannot allocate memory
May 31 15:50:31 test abrtd[6309]: fork: Cannot allocate memory
May 31 16:00:31 test abrtd[6309]: fork: Cannot allocate memory
May 31 16:10:32 test abrtd[6309]: fork: Cannot allocate memory
May 31 16:40:31 test abrtd[6309]: fork: Cannot allocate memory
May 31 17:50:32 test abrtd[6309]: fork: Cannot allocate memory
Jun 01 20:00:32 test abrtd[6309]: fork: Cannot allocate memory
发现一直报“fork: Cannot allocate memory”
abrtd 是一个进程崩溃的自动回收和报告系统。fork: Cannot allocate memory 是一个表明内存不足的错误。您可以尝试以下步骤来解决这个问题:
确认系统内存使用情况,使用 free -m 命令可以查看内存使用情况。如果物理内存不足,可以考虑增加内存。如果物理内存充足,可能是因为系统的虚拟内存不足导致的。
检查系统的 ulimit 参数设置,因为这可能会限制当前用户进程能够使用的内存量。您可以使用 ulimit -a 命令来查看当前设置。如果限制太低,您可以使用 ulimit -m
检查系统的进程数限制,您可以使用以下命令来查看当前限制:
cat /proc/sys/kernel/pid_max
cat /proc/sys/kernel/threads-max
如果过低,可以通过修改 /etc/sysctl.conf 文件来增加限制。
如果以上步骤都没有解决问题,可以尝试升级系统内核版本。
您还可以尝试重启 abrtd 服务,以便对系统资源进行优化和重新分配。您可以使用以下命令来重启 abrtd 服务:
systemctl restart abrtd.service
先尝试重启abrtd试试
# systemctl restart abrtd.service
# free -g
total used free shared buff/cache available
Mem: 46 4 35 3 6 36
Swap: 7 0 7
# systemctl status abrtd.service
● abrtd.service - ABRT Automated Bug Reporting Tool
Loaded: loaded (/usr/lib/systemd/system/abrtd.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-06-02 10:11:08 CST; 13s ago
Main PID: 13085 (abrtd)
CGroup: /system.slice/abrtd.service
└─13085 /usr/sbin/abrtd -d -s
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2022-10-21-22:41:42-24216-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2023-02-15-15:40:40-20105-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2022-12-06-04:35:29-13836-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2023-04-15-01:49:22-13670-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2022-12-29-20:13:06-5104-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2023-03-03-23:56:58-28323-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2023-02-17-07:41:46-14301-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2023-03-07-02:31:38-27137-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2022-11-23-19:36:29-10508-0' not reportable (no 'count' item)
Jun 02 10:11:21 test abrtd[13085]: Marking '/var/spool/abrt/oops-2022-10-29-03:27:26-12163-0' not reportable (no 'count' item)
重启后发现,内存确实释放了。