内存紧张导致磁盘空间“消失”排查笔记

物理内存 8 GB,空闲仅 1.3 GB,发现 C 盘随开机时间持续减少,重启后恢复。
怀疑 pagefile.sys 自动膨胀引起,遂记录排查与恢复步骤。


检查 pagefile 当前配置

1
wmic pagefile list /format:list

关键字段含义

  • AllocatedBaseSize 系统已分配大小(MB)
  • CurrentUsage   实时占用(MB)
  • PeakUsage   历史峰值(MB)
  • AutomaticManagedPagefile 是否自动管理(TRUE/FALSE)

检查实时交换率

1
typeperf "\Paging File(_Total)\% Usage" -sc 1

返回示例

1
"10/09/2025 17:39:58.297","14.693229"

14.7 % 确认当前仅用到 1 GB 左右,但系统已预分配 7 GB。


关闭自动管理并锁定上限(应急止血)

1
2
3
4
5
6
7
8
:: 关闭自动管理
wmic computersystem where name="%computername%" set AutomaticManagedPagefile=False

:: 删除原有大文件
wmic pagefileset where name="C:\\pagefile.sys" delete

:: 新建最大 4 GB 的 pagefile
wmic pagefileset create name="C:\\pagefile.sys" InitialSize=2048 MaximumSize=4096

重启后生效,C 盘不再“预留”7 GB。


恢复默认(自动管理)

1
2
3
4
5
:: 重新打开自动管理
wmic computersystem where name="%computername%" set AutomaticManagedPagefile=True

:: 可选:删除手动规则,让系统重建
wmic pagefileset where name="C:\\pagefile.sys" delete

重启验证:

1
wmic pagefile list /format:list

AutomaticManagedPagefile = TRUEAllocatedBaseSize 回到 ~7118 MB 即恢复完成。


一键重启命令

1
shutdown /r /t 0

小结:磁盘“消失”空间=pagefile.sys预分配;锁上限可止血,加内存才是根本。