前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >配置Dynamic Cache解决2008R2 Cache WS / Metafile占用内存过多的问题

配置Dynamic Cache解决2008R2 Cache WS / Metafile占用内存过多的问题

原创
作者头像
Windows技术交流
修改2024-01-17 12:30:59
3.5K0
修改2024-01-17 12:30:59
举报
文章被收录于专栏:Windows技术交流Windows技术交流

【背景介绍】

某用户4G内存的2008R2机器,经常内存跑满,但是一点也不卡,就是感觉很奇怪,任务管理器里显示的内存加一起也没多少,怎么就快满了呢?需要定位原因

一、初步排查

1、查看任务管理器,内存大小倒序排列,前4的都是IIS相关进程

任务管理器里显示的是“专用工作集”,一般是小于物理内存的,加和这个没有意义,要通过其他方式来查看内存使用。一般通过powershell里的get-process的ws来评估内存使用量

get-process里的PM和WS解释如下:

PM(K): The amount of pageable memory that the process is using, in kilobytes.

WS(K): The size of the working set of the process, in kilobytes. The working set consists of the pages of memory that were recently referenced by the process.

这里有篇帖子有相关概念的汇总

一开始对powershell不熟练,写了个循环算加和

第一次

$arr=get-process|select ws|findstr "[0-9]"

$sum=0;$i=0;

while($i -lt $arr.Length){

$sum+=$arr[$i];

$i++

}

echo $sum

后来发现有现成的命令measure,使用了几次发现代码可以更精简

第二次

get-process|select ws|findstr "[0-9]"|measure -sum

get-process|select pm|findstr "[0-9]"|measure -sum

第三次

(get-process|measure -property ws -sum).sum

(get-process|measure -property pm -sum).sum

一般情况下,WS总和(∑WS)是大于PM总和(∑PM)的,但是多次测试,用户的情况都是∑WS<∑PM,这很奇怪,到底是为什么呢?

2、用FullEventLogView过滤Error级别日志,发现跟dotnet4和dotnet2相关

3、一般情况下,跟dotnet4和dotnet2最密切相关的就是IIS,结合问题现象,进一步想到了IIS应用程序池,因为这个跟内存有些关系

固定时间间隔(分钟)默认1740=29小时,用户这里设置的是0

根据上次重启到这次间隔h小时,内存就跑到80%多的实际情况,设置固定时间间隔(分钟)值为60*h,比如8小时设置480,设置完毕重启服务器观察

结果:用户反馈不起作用

这里我其实是有点疑问的,用户设置回收时间后并未重启服务器观察,甚至都没有iisreset,只是手动回收了应用池,发现内存占用还是高。这里调整回收时间也只是从日志报错联想猜测,逻辑并不严谨,用户没有完全按照我的想法验证,我也没再深究,尝试换别的证据确凿的思路。

二、利用sysinternals工具排查

https://download.sysinternals.com/files/SysinternalsSuite.zip

1、process explorer (procexp.exe)

2、rammap (RAMMap.exe)

通过 process explorer、rammap看到的Cache WS(缓存工作集)和Metafile呈正相关。到这里,明白之前的问题了:

"一般情况下,WS总和(∑WS)是大于PM总和(∑PM)的,但是多次测试,用户的情况都是∑WS<∑PM,这很奇怪,到底是为什么呢?"

∑WS<∑PM,差异主要是Cache WS造成。WS(K): The working set consists of the pages of memory that were recently referenced by the process. 注意里面有个"recently",严格讲get-process的WS要叫Recent WS,之前的WS如果没有回收是没计算在内的。整体来说,不论是一般情况还是二般情况,内存占用量≈Total WS ≈ (get-process显示的WS) + (process explorer显示的Cache WS),而(get-proces显示的PM)可以理解为Total WS的一部分。

三、根据第二步排查到的Cache WS/Metafile占用内存过高的现象,搜到了微软的方案

首先安装kb979223补丁,参考https://support.microsoft.com/en-us/help/979223

其次安装DynCache服务

英文步骤(中文步骤在下面)

Disclaimer: The following steps are derived from ReadMe.docx document provided by Microsoft with DynCache utility.

  1. Open the Windows Registry Editor using regedit and take a backup of the entire Windows registry.
  2. Download DynCache.zip from http://www.microsoft.com/en-in/download/details.aspx?id=9258  and extract the .zip file to a folder.
  3. Open the folder and navigate to DynCache\Retail\amd64.
  4. Copy DynCache.exe and DynCache.pdb to %SystemRoot%\System32.
  5. Navigate to DynCache\Retail\amd64 and run the following command from the elevated command prompt: sc create DynCache binpath= %SystemRoot%\System32\DynCache.exe start= auto type= own DisplayName= "Dynamic Cache Service" The above command output displays "creation successful" and it creates Dynamic Cache Service in services.msc console.
  6. To import DynCache.reg registry file, double-click the DynCache\DynCache.reg file and click OK.  
  7. Open registry editor using regedit and navigate to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DynCache\Parameters] and set the below values (Hexadecimal) to Limit Dynamic caching to 1 GB: "MaxSystemCacheMBytes"=dword:00000400 "MinSystemCacheMBytes"=dword:00000064
  8. Launch Services console (Start > Run > Services.msc) and start the Dynamic Cache Service.

中文步骤

1 、下载DynCache,微软官网地址

2、解压文件,将\DynCache\Retail\AMD64\DynCache.exe 和DynCache.pdb复制到 C:\Windows\System32下

3、 创建服务:cmd命令执行sc create DynCache binpath= %SystemRoot%\System32\DynCache.exe start= auto type= own DisplayName= "Dynamic Cache Service" 4、双击执行DynCache.reg 5、打开注册表路径:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\DynCache\Parameters,设置MaxSystemCacheMBytes的值为“注意事项”(单位MB),注意是十进制

【注意事项】这里列举几个要点一般就够用了,但还是建议详阅ReadMe.docx

①MaxSystemCacheMBytes默认值是0,0代表占物理内存90%

②1-99代表MaxSystemCacheMBytes占物理内存的百分比

③MinSystemCacheMBytes默认是0,0代表100MB,非0则可设置100≤MinSystemCacheMBytes<MaxSystemCacheMBytes

④200≤MaxSystemCacheMBytes≤1024、[MaxSystemCacheMBytes-MinSystemCacheMBytes]≥100

英文说明如下

RegValue: MaxSystemCacheMBytes Type: REG_DWORD Values: 0 = Limit to 90% of Physical RAM (default) 1-99 = Limit the maximum size of the System File Cache to this percentage of Physical RAM > 200 = Limit the maximum size of the System File Cache to x Mbytes

How this works: This setting is the absolute maximum that the System File Cache’s working set could be set to.  The default is 0, limiting it to 90% of physical RAM with an upper limit of total Physical RAM minus 300 Mbytes.  The lower limit for absolute values is 200 Mbytes and it must be at least 100 Mbytes greater than the MinSystemCacheMBytes value, which defaults to 100 Mbytes.

5、启动服务DynCache

sc start DynCache 6、重启计算机

------------如需卸载---------------- sc stop DynCache sc delete DynCache

第三步后问题解决未再复发。

注:>2008R2的Windows系统在内存管理方面已经比较好了,不要尝试DynCache方案,否则很可能会引发性能问题

This service will only run on Windows Server 2008 R2 or earlier versions of Windows.  Do not attempt to run this service on a version of Windows after Windows Server 2008 R2 as it will most likely cause performance problems.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 【背景介绍】
  • 一、初步排查
  • 二、利用sysinternals工具排查
  • 三、根据第二步排查到的Cache WS/Metafile占用内存过高的现象,搜到了微软的方案
  • 注:>2008R2的Windows系统在内存管理方面已经比较好了,不要尝试DynCache方案,否则很可能会引发性能问题
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档