配置swap、dump文件

自定义powershell 配置 swap的函数

创建下述名为AdjustVirtualMemoryPagingFileSize.ps1文件

  1. #---------------------------------------------------------------------------------
  2. #The sample scripts are not supported under any Microsoft standard support
  3. #program or service. The sample scripts are provided AS IS without warranty
  4. #of any kind. Microsoft further disclaims all implied warranties including,
  5. #without limitation, any implied warranties of merchantability or of fitness for
  6. #a particular purpose. The entire risk arising out of the use or performance of
  7. #the sample scripts and documentation remains with you. In no event shall
  8. #Microsoft, its authors, or anyone else involved in the creation, production, or
  9. #delivery of the scripts be liable for any damages whatsoever (including,
  10. #without limitation, damages for loss of business profits, business interruption,
  11. #loss of business information, or other pecuniary loss) arising out of the use
  12. #of or inability to use the sample scripts or documentation, even if Microsoft
  13. #has been advised of the possibility of such damages
  14. #---------------------------------------------------------------------------------
  15. #requires -Version 2.0
  16. Function Set-OSCVirtualMemory
  17. {
  18. <#
  19. .SYNOPSIS
  20. Set-OSCVirtualMemory is an advanced function which can be used to adjust virtual memory page file size.
  21. .DESCRIPTION
  22. Set-OSCVirtualMemory is an advanced function which can be used to adjust virtual memory page file size.
  23. .PARAMETER <InitialSize>
  24. Setting the paging file's initial size.
  25. .PARAMETER <MaximumSize>
  26. Setting the paging file's maximum size.
  27. .PARAMETER <DriveLetter>
  28. Specifies the drive letter you want to configure.
  29. .PARAMETER <SystemManagedSize>
  30. Allow Windows to manage page files on this computer.
  31. .PARAMETER <None>
  32. Disable page files setting.
  33. .PARAMETER <Reboot>
  34. Reboot the computer so that configuration changes take effect.
  35. .PARAMETER <AutoConfigure>
  36. Automatically configure the initial size and maximumsize.
  37. .EXAMPLE
  38. C:\PS> Set-OSCVirtualMemory -InitialSize 1024 -MaximumSize 2048 -DriveLetter "C:","D:"
  39. Execution Results: Set page file size on "C:" successful.
  40. Execution Results: Set page file size on "D:" successful.
  41. Name InitialSize(MB) MaximumSize(MB)
  42. ---- --------------- ---------------
  43. C:\pagefile.sys 1024 2048
  44. D:\pagefile.sys 1024 2048
  45. E:\pagefile.sys 2048 2048
  46. .LINK
  47. Get-WmiObject
  48. http://technet.microsoft.com/library/hh849824.aspx
  49. #>
  50. [cmdletbinding(SupportsShouldProcess=$true,DefaultParameterSetName="SetPageFileSize")]
  51. Param
  52. (
  53. [Parameter(Mandatory=$true,Position=0,ParameterSetName="SetPageFileSize")]
  54. [Alias('is')]
  55. [Int32]$InitialSize,
  56. [Parameter(Mandatory=$true,Position=1,ParameterSetName="SetPageFileSize")]
  57. [Alias('ms')]
  58. [Int32]$MaximumSize,
  59. [Parameter(Mandatory=$true,Position=2)]
  60. [Alias('dl')]
  61. [String[]]$DriveLetter,
  62. [Parameter(Mandatory=$true,Position=3,ParameterSetName="None")]
  63. [Switch]$None,
  64. [Parameter(Mandatory=$true,Position=4,ParameterSetName="SystemManagedSize")]
  65. [Switch]$SystemManagedSize,
  66. [Parameter(Mandatory=$false,Position=5)]
  67. [Switch]$Reboot,
  68. [Parameter(Mandatory=$true,Position=6,ParameterSetName="AutoConfigure")]
  69. [Alias('auto')]
  70. [Switch]$AutoConfigure
  71. )
  72. If($PSCmdlet.ShouldProcess("Setting the virtual memory page file size"))
  73. {
  74. Foreach($DL in $DriveLetter)
  75. {
  76. If($None)
  77. {
  78. $PageFile = Get-WmiObject -Query "Select * From Win32_PageFileSetting Where Name='$DL\\pagefile.sys'" -EnableAllPrivileges
  79. If($PageFile -ne $null)
  80. {
  81. $PageFile.Delete()
  82. }
  83. Else
  84. {
  85. Write-Warning """$DL"" is already set None!"
  86. }
  87. }
  88. ElseIf($SystemManagedSize)
  89. {
  90. $InitialSize = 0
  91. $MaximumSize = 0
  92. Set-PageFileSize -DL $DL -InitialSize $InitialSize -MaximumSize $MaximumSize
  93. }
  94. ElseIf($AutoConfigure)
  95. {
  96. $InitialSize = 0
  97. $MaximumSize = 0
  98. #Getting total physical memory size
  99. Get-WmiObject -Class Win32_PhysicalMemory | Where-Object{$_.DeviceLocator -ne "SYSTEM ROM"} | `
  100. ForEach-Object{$TotalPhysicalMemorySize += [Double]($_.Capacity)/1GB}
  101. <#
  102. By default, the minimum size on a 32-bit (x86) system is 1.5 times the amount of physical RAM if physical RAM is less than 1 GB,
  103. and equal to the amount of physical RAM plus 300 MB if 1 GB or more is installed. The default maximum size is three times the amount of RAM,
  104. regardless of how much physical RAM is installed.
  105. #>
  106. If($TotalPhysicalMemorySize -lt 1)
  107. {
  108. $InitialSize = 1.5*1024
  109. $MaximumSize = 1024*3
  110. Set-PageFileSize -DL $DL -InitialSize $InitialSize -MaximumSize $MaximumSize
  111. }
  112. Else
  113. {
  114. $InitialSize = 1024+300
  115. $MaximumSize = 1024*3
  116. Set-PageFileSize -DL $DL -InitialSize $InitialSize -MaximumSize $MaximumSize
  117. }
  118. }
  119. Else
  120. {
  121. Set-PageFileSize -DL $DL -InitialSize $InitialSize -MaximumSize $MaximumSize
  122. }
  123. If($Reboot)
  124. {
  125. Restart-Computer -ComputerName $Env:COMPUTERNAME -Force
  126. }
  127. }
  128. #get current page file size information
  129. Get-WmiObject -Class Win32_PageFileSetting -EnableAllPrivileges|Select-Object Name, `
  130. @{Name="InitialSize(MB)";Expression={if($_.InitialSize -eq 0){"System Managed"}else{$_.InitialSize}}}, `
  131. @{Name="MaximumSize(MB)";Expression={if($_.MaximumSize -eq 0){"System Managed"}else{$_.MaximumSize}}}| `
  132. Format-Table -AutoSize
  133. }
  134. }
  135. Function Set-PageFileSize
  136. {
  137. Param($DL,$InitialSize,$MaximumSize)
  138. #The AutomaticManagedPagefile property determines whether the system managed pagefile is enabled.
  139. #This capability is not available on windows server 2003,XP and lower versions.
  140. #Only if it is NOT managed by the system and will also allow you to change these.
  141. $IsAutomaticManagedPagefile = Get-WmiObject -Class Win32_ComputerSystem |Foreach-Object{$_.AutomaticManagedPagefile}
  142. If($IsAutomaticManagedPagefile)
  143. {
  144. #We must enable all the privileges of the current user before the command makes the WMI call.
  145. $SystemInfo=Get-WmiObject -Class Win32_ComputerSystem -EnableAllPrivileges
  146. $SystemInfo.AutomaticManagedPageFile = $false
  147. [Void]$SystemInfo.Put()
  148. }
  149. Write-Verbose "Setting pagefile on $DL"
  150. #configuring the page file size
  151. $PageFile = Get-WmiObject -Class Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $DL'"
  152. Try
  153. {
  154. If($PageFile -ne $null)
  155. {
  156. $PageFile.Delete()
  157. }
  158. Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{name="$DL\pagefile.sys"; InitialSize = 0; MaximumSize = 0} `
  159. -EnableAllPrivileges |Out-Null
  160. $PageFile = Get-WmiObject Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ $DL'"
  161. $PageFile.InitialSize = $InitialSize
  162. $PageFile.MaximumSize = $MaximumSize
  163. [Void]$PageFile.Put()
  164. Write-Host "Execution Results: Set page file size on ""$DL"" successful."
  165. Write-Warning "Pagefile configuration changed on computer '$Env:COMPUTERNAME'. The computer must be restarted for the changes to take effect."
  166. }
  167. Catch
  168. {
  169. Write-Host "Execution Results: No Permission - Failed to set page file size on ""$DL"""
  170. }
  171. }

导入函数:
import /path/AdjustVirtualMemoryPagingFileSize.ps1

注:如需开机启动可将其置放在C:\Users\user\Documents\WindowsPowerShell\ 路径下,powershell将开机自动加载改脚本.

示例:
Set-OSCVirtualMemory -InitialSize 1024 -MaximumSize 2048 -DriveLetter "C:","D:"
参考

配置dump文件

控制面板\系统和安全\系统->高级->设置->转储文件

下载win10 SDK

下载链接
win10 SDK 安装包中包含WinDbg

WinDbg是在windows平台下,强大的用户态和内核态调试工具。它能够通过dmp文件轻松的定位到问题根源,可用于分析蓝屏、程序崩溃(IE崩溃)原因,是我们日常工作中必不可少的一个有力工具,学会使用它,将有效提升我们的问题解决效率和准确率。

  1. 运行WinDbg软件,然后按【Ctrl+S】弹出符号表设置窗
  2. 将符号表地址:SRVC:\Symbolshttp://msdl.microsoft.com/download/symbols 粘贴在输入框中,点击确定即可。
  3. 使用【Ctrl+D】快捷键来导入一个dmp文件
  4. 键入!analyze -v

案例参考