前言
本篇内容大体由GPT代写,个人技术不是很好,全程由GPT带着排查
个人使用这台设备用于基本的NAS需求与运行一个Minecraft服务器,但是遇到了一个严重的内存泄漏问题,只要开机内存就会不断被侵蚀,大约1小时就能吃满我全部的32G内存
尝试关闭过能关的所有程序,系统应用:相册、影视、虚拟机、快照等,以及MCSM里的所有实例(一些Java程序),Docker,但都不会影响这个泄漏,还是会直接吃满,这会导致我自己在运行的软件被OOM kill,严重的时候内核都会直接卡住,没办法正常使用,有没有大佬遇到过这个问题,有解决方法吗?
以下内容来自GPT
我觉得关键信息由GPT提供比我自己自作主张更靠谱一些
各位好,最近我的 FNOS(版本 9.0.47 / kernel 6.6.38-trim)突然出现离谱的内存占用:
# free -h
total used free shared buff/cache available
Mem: 31Gi 30Gi 270Mi 64Mi 473Mi 255Mi
Swap: 5.0Gi 548Mi 4.5Gi
查了一圈发现 Slab这块儿有问题:
# slabtop -o | head
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
505685184 505685184 100% 0.06K 7901331 64 31605324K kmalloc-64
kmalloc-64
一个 cache 就吃掉 31 GiB,而且是 SUnreclaim,echo 2 > drop_caches
完全不会降。
我尝试过的
- 重启:重启后一小时又被吃光。
- 怀疑 nf_conntrack,但
/proc/sys/net/netfilter/nf_conntrack_count
只有几十。
- 看到网上有人说 ext4/POSIX-ACL 泄漏内存,试着在
/etc/fstab
给根分区加 noacl
——结果系统直接起不来,报 Unknown parameter 'noacl'。
现有环境
项目 |
版本 / 说明 |
FNOS |
9.0.47 |
内核 |
6.6.38-trim |
根分区 |
nvme0n1p2, ext4 |
数据卷 |
/vol1 & /vol2, btrfs |
服务 |
MCSManager(java)、qbittorrent、postgres、libvirt(偶尔),Docker |
求助想知道
- 是不是 6.6.38-trim 自带的 ext4 ACL 漏洞?
上游好像在 6.6.39 修了,但 FNOS 目前仓库里还没有 6.6.40-trim。
- 如果真是内核问题,官方有没有计划推修复版?
自己换 Debian 官方内核怕会遇到兼容性问题。
- 暂时有没有 不换内核就能缓解 的方法?(kpatch? 关闭 ACL 的正确姿势?)
一些日志信息补充
关于Slab的
root@PINGFNOS:~# dmesg -T | grep -E "Out of memory|Killed process"
[Fri Apr 25 17:10:47 2025] Out of memory: Killed process 9827 (java) total-vm:21299440kB, anon-rss:4278364kB, file-rss:4576kB, shmem-rss:0kB, UID:0 pgtables:13916kB oom_score_adj:0
root@PINGFNOS:~# # 1-1 先看看 Slab 总额
grep -E 'Slab|SReclaimable|SUnreclaim' /proc/meminfo
# > 如果 Slab 数字就已经二十几 GiB,那几乎铁定是它
# 1-2 现场排行:到底哪个 slab 在吞内存(每秒刷新一次)
sudo slabtop -o
# 把最上面 10 行贴给我
Slab: 31851616 kB
SReclaimable: 48808 kB
SUnreclaim: 31802808 kB
Active / Total Objects (% used) : 508246312 / 508324882 (100.0%)
Active / Total Slabs (% used) : 7933116 / 7933116 (100.0%)
Active / Total Caches (% used) : 151 / 193 (78.2%)
Active / Total Size (% used) : 31804408.55K / 31835897.19K (99.9%)
Minimum / Average / Maximum Object : 0.01K / 0.06K / 8.94K
OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
505685184 505685184 100% 0.06K 7901331 64 31605324K kmalloc-64
1977856 1977850 99% 0.03K 15452 128 61808K kmalloc-32
82768 80654 97% 0.14K 2956 28 11824K kernfs_node_cache
39468 39381 99% 0.10K 1012 39 4048K btrfs_free_space
38658 36703 94% 0.04K 379 102 1516K vma_lock
38276 15944 41% 0.57K 1367 28 21872K radix_tree_node
37532 36075 96% 0.18K 853 44 6824K vm_area_struct
34608 22006 63% 0.19K 824 42 6592K dentry
28416 28223 99% 0.02K 111 256 444K kmalloc-16
27712 26612 96% 0.06K 433 64 1732K anon_vma_chain
27048 24051 88% 0.07K 483 56 1932K vmap_area
20512 18184 88% 0.50K 641 32 10256K kmalloc-512
19680 17607 89% 0.25K 615 32 4920K filp
17408 17381 99% 0.01K 34 512 136K kmalloc-8
14859 14618 98% 0.10K 381 39 1524K anon_vma
12684 12684 100% 0.19K 302 42 2416K kmalloc-192
12546 4359 34% 0.23K 369 34 2952K btrfs_extent_buffer
9744 8530 87% 0.09K 232 42 928K kmalloc-96
9568 6804 71% 0.25K 299 32 2392K kmalloc-256
8800 5188 58% 0.25K 275 32 2200K maple_node
8800 8637 98% 1.00K 275 32 8800K kmalloc-1k
8755 8755 100% 0.05K 103 85 412K shared_policy_node
8500 8162 96% 0.02K 50 170 200K lsm_file_cache
8192 8192 100% 0.01K 16 512 64K kmalloc-cg-8
7025 4116 58% 0.62K 281 25 4496K inode_cache
6935 6935 100% 0.05K 95 73 380K ftrace_event_field
4968 2325 46% 1.16K 184 27 5888K ext4_inode_cache
4320 3640 84% 0.12K 135 32 540K pid
4096 4096 100% 0.02K 16 256 64K ep_head
4096 4096 100% 0.02K 16 256 64K kmalloc-cg-16
3876 3468 89% 0.04K 38 102 152K extent_status
3840 3340 86% 0.03K 30 128 120K fsnotify_mark_connector
3772 3772 100% 0.09K 82 46 328K blkdev_ioc
3248 3024 93% 2.00K 203 16 6496K kmalloc-2k
3136 2422 77% 0.06K 49 64 196K dmaengine-unmap-2
2880 2364 82% 0.06K 45 64 180K kmalloc-rcl-64
2880 2880 100% 0.12K 90 32 360K kmalloc-128
2680 2680 100% 0.78K 67 40 2144K shmem_inode_cache
2668 1533 57% 0.70K 58 46 1856K proc_inode_cache
2652 2652 100% 0.10K 68 39 272K buffer_head
2632 1482 56% 1.11K 94 28 3008K btrfs_inode
2560 2560 100% 0.03K 20 128 80K kmalloc-cg-32
2418 2232 92% 0.81K 62 39 1984K sock_inode_cache
2400 2323 96% 0.13K 80 30 320K btrfs_delayed_ref_head
2310 2310 100% 0.09K 55 42 220K trace_event_file
2112 2112 100% 0.50K 66 32 1056K pool_workqueue
2048 1920 93% 0.25K 64 32 512K bio-192
1980 1980 100% 0.11K 55 36 220K btrfs_path
1974 1974 100% 0.19K 47 42 376K cred_jar
1792 1792 100% 0.03K 14 128 56K jbd2_revoke_record_s
1752 1752 100% 0.05K 24 73 96K jbd2_journal_handle
1680 1680 100% 0.19K 40 42 320K bio-152
1680 1680 100% 0.19K 40 42 320K proc_dir_entry
1664 1408 84% 0.06K 26 64 104K ext4_io_end
1650 1378 83% 0.31K 66 25 528K xfrm_dst_cache
1632 1632 100% 0.04K 16 102 64K khugepaged_mm_slot
1575 1575 100% 0.31K 63 25 504K mnt_cache
1482 1482 100% 0.41K 39 38 624K btrfs_ordered_extent
1480 1257 84% 6.38K 296 5 9472K task_struct
1472 1472 100% 0.25K 46 32 368K skbuff_head_cache
1470 1470 100% 0.09K 35 42 140K kmalloc-rcl-96
1428 1428 100% 0.12K 42 34 168K jbd2_journal_head
1428 1306 91% 0.38K 34 42 544K bio-368
1408 1408 100% 0.06K 22 64 88K kmalloc-cg-64
1250 1127 90% 0.62K 50 25 800K skbuff_small_head
1184 1136 95% 0.25K 37 32 296K bio-248
1134 1104 97% 0.09K 27 42 108K kmalloc-cg-96
1105 1105 100% 0.05K 13 85 52K ip_fib_trie
1092 1092 100% 0.19K 26 42 208K bio-128
1080 937 86% 0.70K 24 45 768K ovl_inode
1071 1071 100% 0.08K 21 51 84K Acpi-State
1064 1064 100% 1.12K 38 28 1216K signal_cache
1056 1030 97% 4.00K 132 8 4224K biovec-max
1050 1040 99% 1.06K 35 30 1120K UNIX
992 992 100% 0.12K 31 32 124K kmalloc-cg-128
960 960 100% 0.50K 30 32 480K kmalloc-cg-512
918 918 100% 0.08K 18 51 72K sigqueue
876 876 100% 0.05K 12 73 48K ip_fib_alias
848 827 97% 4.00K 106 8 3392K kmalloc-4k
840 840 100% 0.07K 15 56 60K nsproxy
832 832 100% 0.06K 13 64 52K kmem_cache_node
828 828 100% 0.69K 18 46 576K files_cache
800 640 80% 0.12K 25 32 100K kmalloc-rcl-128
798 798 100% 0.19K 19 42 152K kmalloc-cg-192
768 768 100% 0.25K 24 32 192K nf_conntrack
720 684 95% 2.06K 48 15 1536K sighand_cache
714 714 100% 0.19K 17 42 136K dmaengine-unmap-16
704 691 98% 2.00K 44 16 1408K kmalloc-cg-2k
672 672 100% 1.00K 21 32 672K kmalloc-cg-1k
608 608 100% 0.12K 19 32 76K scsi_sense_cache
608 608 100% 0.25K 19 32 152K dquot
602 602 100% 0.74K 14 43 448K sw_flow
592 592 100% 0.21K 16 37 128K file_lock_cache
592 592 100% 0.42K 16 37 256K taskstats
576 576 100% 0.11K 16 36 64K ext4_prealloc_space
552 552 100% 1.38K 24 23 768K mm_struct
544 544 100% 0.12K 16 34 64K seq_file
540 540 100% 0.27K 18 30 144K tw_sock_TCPv6
528 528 100% 0.18K 12 44 96K ext4_groupinfo_4k
512 512 100% 1.00K 16 32 512K biovec-64
512 512 100% 0.25K 16 32 128K kmalloc-cg-256
480 480 100% 0.27K 16 30 128K tw_sock_TCP
480 480 100% 0.12K 15 32 60K skbuff_ext_cache
480 480 100% 0.27K 16 30 128K numa_policy
480 480 100% 0.25K 15 32 120K kmem_cache
475 475 100% 0.62K 19 25 304K task_group
416 416 100% 0.15K 16 26 64K ext4_allocation_context
416 416 100% 0.30K 16 26 128K request_sock_TCP
400 400 100% 1.23K 16 25 512K perf_event
392 392 100% 0.56K 14 28 224K kioctx
384 384 100% 1.31K 16 24 512K UDPv6
375 375 100% 0.31K 15 25 120K bio-256
336 224 66% 1.12K 12 28 384K drm_i915_gem_object
325 325 100% 2.38K 25 13 800K TCPv6
312 312 100% 0.30K 12 26 96K request_sock_TCPv6
296 296 100% 0.42K 8 37 128K uts_namespace
280 280 100% 4.00K 35 8 1120K kmalloc-cg-4k
256 256 100% 0.02K 1 256 4K jbd2_revoke_table_s
256 256 100% 2.00K 16 16 512K biovec-128
252 252 100% 0.19K 6 42 48K kmalloc-rcl-192
240 240 100% 0.66K 10 24 160K tracefs_inode_cache
224 224 100% 2.25K 16 14 512K TCP
210 210 100% 0.91K 6 35 192K request_queue
208 208 100% 8.00K 52 4 1664K kmalloc-8k
204 204 100% 0.94K 6 34 192K mqueue_inode_cache
182 182 100% 1.19K 7 26 224K RAWv6
170 170 100% 0.05K 2 85 8K bio_post_read_ctx
168 168 100% 0.75K 4 42 128K xfrm_state
168 168 100% 0.14K 6 28 24K task_delay_info
160 160 100% 1.56K 8 20 256K bdev_cache
128 128 100% 4.00K 16 8 512K names_cache
117 117 100% 0.81K 3 39 96K dax_cache
96 96 100% 0.65K 4 24 64K hugetlbfs_inode_cache
84 84 100% 0.19K 2 42 16K bio-168
82 82 100% 0.77K 2 41 64K fat_inode_cache
78 78 100% 0.81K 2 39 64K QIPCRTR
76 76 100% 8.00K 19 4 608K kmalloc-cg-8k
49 49 100% 4.38K 7 7 224K net_namespace
46 46 100% 0.69K 1 46 32K rpc_inode_cache
46 46 100% 0.69K 1 46 32K i915_request
36 36 100% 0.44K 1 36 16K bio-384
36 36 100% 0.44K 1 36 16K bio-440
32 32 100% 1.00K 1 32 32K RAW
30 30 100% 1.06K 1 30 32K dmaengine-unmap-128
26 26 100% 0.61K 1 26 16K user_namespace
25 25 100% 0.31K 1 25 8K bio-304
24 24 100% 0.64K 1 24 16K trimafs_inode
21 21 100% 1.50K 1 21 32K x86_lbr
15 15 100% 2.06K 1 15 32K dmaengine-unmap-256
12 12 100% 2.59K 1 12 32K x86_emulator
3 3 100% 8.94K 1 3 32K kvm_vcpu
0 0 0% 0.20K 0 39 0K nf_conntrack_expect
0 0 0% 0.04K 0 102 0K fat_cache
0 0 0% 0.12K 0 32 0K i915_dependency
0 0 0% 0.06K 0 64 0K execute_cb
0 0 0% 0.15K 0 26 0K fuse_request
0 0 0% 0.88K 0 36 0K fuse_inode
0 0 0% 0.09K 0 42 0K ext4_fc_dentry_update
0 0 0% 3.16K 0 10 0K kcopyd_**
0 0 0% 2.82K 0 11 0K dm_uevent
0 0 0% 0.27K 0 30 0K fsverity_info
0 0 0% 0.12K 0 32 0K fscrypt_info
0 0 0% 0.18K 0 44 0K ip6-frags
0 0 0% 1.19K 0 26 0K PINGv6
0 0 0% 0.25K 0 32 0K io_kiocb
0 0 0% 0.19K 0 42 0K userfaultfd_ctx_cache
0 0 0% 0.03K 0 128 0K dnotify_struct
0 0 0% 0.20K 0 40 0K ip4-frags
0 0 0% 1.00K 0 32 0K PING
0 0 0% 0.17K 0 46 0K fscache_cookie_jar
0 0 0% 0.12K 0 32 0K iint_cache
0 0 0% 8.00K 0 4 0K dma-kmalloc-8k
0 0 0% 4.00K 0 8 0K dma-kmalloc-4k
0 0 0% 2.00K 0 16 0K dma-kmalloc-2k
0 0 0% 1.00K 0 32 0K dma-kmalloc-1k
0 0 0% 0.50K 0 32 0K dma-kmalloc-512
0 0 0% 0.25K 0 32 0K dma-kmalloc-256
0 0 0% 0.19K 0 42 0K dma-kmalloc-192
0 0 0% 0.12K 0 32 0K dma-kmalloc-128
0 0 0% 0.09K 0 42 0K dma-kmalloc-96
0 0 0% 0.06K 0 64 0K dma-kmalloc-64
0 0 0% 0.03K 0 128 0K dma-kmalloc-32
0 0 0% 0.02K 0 256 0K dma-kmalloc-16
0 0 0% 0.01K 0 512 0K dma-kmalloc-8
0 0 0% 8.00K 0 4 0K kmalloc-rcl-8k
0 0 0% 4.00K 0 8 0K kmalloc-rcl-4k
0 0 0% 2.00K 0 16 0K kmalloc-rcl-2k
0 0 0% 1.00K 0 32 0K kmalloc-rcl-1k
0 0 0% 0.50K 0 32 0K kmalloc-rcl-512
0 0 0% 0.25K 0 32 0K kmalloc-rcl-256
0 0 0% 0.03K 0 128 0K kmalloc-rcl-32
0 0 0% 0.02K 0 256 0K kmalloc-rcl-16
0 0 0% 0.01K 0 512 0K kmalloc-rcl-8
root@PINGFNOS:~#
root@PINGFNOS:~# # 2-1 HugePages 是否被划走
grep Huge /proc/meminfo
# 2-2(如果你用了 ZFS)ARC 占用情况
test -r /proc/spl/kstat/zfs/arcstats && \
cat /proc/spl/kstat/zfs/arcstats | grep -E 'c_max|size' | head
AnonHugePages: 143360 kB
ShmemHugePages: 8192 kB
FileHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
root@PINGFNOS:~# # 当前已记录的连接数 / 系统上限
cat /proc/sys/net/netfilter/nf_conntrack_count
cat /proc/sys/net/netfilter/nf_conntrack_max
39
262144
root@PINGFNOS:~#
top
top - 17:27:20 up 1:08, 1 user, load average: 8.53, 8.65, 9.91
Tasks: 396 total, 2 running, 387 sleeping, 0 stopped, 7 zombie
%Cpu(s): 0.7 us, 6.0 sy, 0.0 ni, 86.1 id, 7.0 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem : 31893.9 total, 261.6 free, 31827.5 used, 158.7 buff/cache
MiB Swap: 5120.0 total, 4009.1 free, 1110.9 used. 66.4 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1282 root 10 -10 1638280 198864 13568 S 0.0 0.6 0:06.68 ovs-vswitchd
1743 root 20 0 3208288 23072 6152 S 0.3 0.1 0:08.09 trim
2455 PingGai 20 0 1151708 14364 13184 S 0.0 0.0 0:09.57 trim-qbittorren
1068 root 20 0 940124 13764 5376 S 0.0 0.0 0:21.52 node
1745 root 20 0 1232732 10100 9472 S 0.0 0.0 0:10.96 dlcenter
1758 root 20 0 376700 9144 6480 S 0.7 0.0 0:28.75 resmon_service
2950 root 20 0 2049184 9016 8320 S 0.0 0.0 0:10.28 vm
1454 postgres 20 0 239912 8576 7936 S 0.0 0.0 0:00.36 postgres
1392 root 20 0 1564248 7900 7296 S 0.0 0.0 0:04.11 libvirtd
1390 root 20 0 308160 7744 5760 S 0.0 0.0 0:12.25 coolercontrold
10818 root 20 0 18100 7420 6656 S 0.0 0.0 0:03.93 sshd
1112 root 20 0 259808 7040 5632 S 0.0 0.0 0:03.89 NetworkManager
1936 root 20 0 469700 6528 5632 S 0.0 0.0 0:00.73 uploadsrv
10836 root 20 0 18140 6404 6016 S 0.0 0.0 0:02.63 sshd
1420 root 20 0 15420 6272 5888 S 0.0 0.0 0:00.00 sshd
2427 postgres 20 0 243492 6136 5248 S 0.0 0.0 0:03.72 postgres
2352 root 20 0 1066364 6080 5760 S 0.0 0.0 0:02.71 dockermgr
486 root 20 0 70268 5760 5248 S 0.0 0.0 0:06.94 systemd-journal
1755 root 20 0 1940100 5656 4480 S 0.0 0.0 0:02.95 network_service
2896 root 20 0 2403852 5536 3196 S 0.3 0.0 0:25.75 trim-media
1101 root 10 -10 15444 5508 4864 S 0.0 0.0 0:01.69 ovsdb-server
1744 root 20 0 354080 5504 4480 S 0.0 0.0 0:00.33 backup_service
2112 postgres 20 0 252784 5228 4224 S 0.0 0.0 0:00.04 postgres
2556 postgres 20 0 253664 5164 4352 S 0.0 0.0 0:00.08 postgres
1751 root 20 0 506572 5152 4224 S 0.0 0.0 0:00.49 imagesrv
1759 root 20 0 350912 5120 4864 S 0.7 0.0 0:12.41 security_servic
root@PINGFNOS:~# ps -eo pid,ppid,user,cmd,%mem,rss --sort=-%mem | head -20
PID PPID USER CMD %MEM RSS
1282 1 root ovs-vswitchd unix:/var/run/ 0.6 198864
1743 1 root /usr/trim/bin/trim 0.0 23072
1068 1 root /opt/node-v16.20.2-linux-x6 0.0 15096
2455 1745 PingGai /usr/trim/bin/trim-qbittorr 0.0 12828
2896 1 root /usr/local/apps/@appcenter/ 0.0 10784
1745 1 root /usr/trim/bin/dlcenter 0.0 9332
1454 1 postgres /usr/lib/postgresql/15/bin/ 0.0 8704
1758 1 root /usr/trim/bin/resmon_servic 0.0 7992
10818 1420 root sshd: root@pts/3 0.0 7548
2950 1 root /usr/local/apps/@appcenter/ 0.0 7224
1392 1 root /usr/sbin/libvirtd --timeou 0.0 7132
2427 1454 postgres postgres: 15/main: postgres 0.0 7032
10836 1420 root sshd: root@notty 0.0 6916
1936 1 root /usr/trim/bin/uploadsrv 0.0 6528
1112 1 root /usr/sbin/NetworkManager -- 0.0 6400
1101 1 root ovsdb-server /etc/openvswit 0.0 6276
1420 1 root sshd: /usr/sbin/sshd -D [li 0.0 6272
1 0 root /sbin/init 0.0 6100
1390 1 root /usr/bin/coolercontrold 0.0 5824
root@PINGFNOS:~#
root@PINGFNOS:~# dmesg -T | grep -E "Out of memory|Killed process"
[Fri Apr 25 17:10:47 2025] Out of memory: Killed process 9827 (java) total-vm:21299440kB, anon-rss:4278364kB, file-rss:4576kB, shmem-rss:0kB, UID:0 pgtables:13916kB oom_score_adj:0