SQL Server 2008 R2 未使用分配的内存
SQL Server 2008 R2 not using allocated Memory
我有一个 sql 通过虚拟机 运行 的实例。 VM 分配了 32gb 内存,我已设置为使用 28gb。但是,查看内存使用情况,我只看到 SQL 使用了大约 1gb。它还显示除了 1gb 之外的所有空间都是免费的,但是正在使用的进程加起来不超过 31gb。甚至不接近,我看到总共可能有 3gb。
我附上了一些 TSQL 的内存使用结果。
Memory usage details for SQL Server instance- X64) - Enterprise Edition (64-bit))
----------------------------------------------------------------------------------------------------
--------------------------------------
Memory visible to the Operating System
Physical Memory_MB Physical Memory_GB Virtual Memory GB
--------------------------------------- --------------------------------------- ---------------------------------------
32768 32 8192
-------------------------------
Buffer Pool Usage at the Moment
BPool_Committed_MB BPool_Commit_Tgt_MB BPool_Visible_MB
--------------------------------------- --------------------------------------- ---------------------------------------
28672.000000 28672.000000 28672.000000
---------------------------------------------------------------------------
Total Memory used by SQL Server Buffer Pool as reported by Perfmon counters
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
29360128 28672.000000 28.000000000
-------------------------------------------------------------
Memory needed as per current Workload for SQL Server instance
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
29360128 28672.000000 28.000000000
------------------------------------------------------------------------------
Total amount of dynamic memory the server is using for maintaining connections
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
5288 5.164062 0.005043029
------------------------------------------------------------
Total amount of dynamic memory the server is using for locks
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
31248 30.515625 0.029800415
----------------------------------------------------------------------------
Total amount of dynamic memory the server is using for the dynamic SQL cache
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
40752 39.796875 0.038864135
-------------------------------------------------------------------------
Total amount of dynamic memory the server is using for query optimization
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
2528 2.468750 0.002410888
-------------------------------------------------------------------------------
Total amount of dynamic memory used for hash, sort and create index operations.
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
0 0.000000 0.000000000
------------------------------------------
Total Amount of memory consumed by cursors
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
1832 1.789062 0.001747131
-------------------------------------------------------------------------
Number of pages in the buffer pool (includes database, free, and stolen).
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
3670016 29360128.000000 28672.000000000
---------------------------------------
Number of Data pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
1429714 11437712.000000 11169.640625000
---------------------------------------
Number of Free pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
1887521 15100168.000000 14746.257812500
-------------------------------------------
Number of Reserved pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
0 0.000000 0.000000000
-----------------------------------------
Number of Stolen pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
352781 2822248.000000 2756.101562500
---------------------------------------------
Number of Plan Cache pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
357949 2863592.000000 2796.476562500
-----------------------------------------------------------------------------------------------
Page Life Expectancy - Number of seconds a page will stay in the buffer pool without references
Page Life in seconds PLE Status
-------------------- ------------------
81046 PLE is Healthy
--------------------------------------------------------------
Number of requests per second that had to wait for a free page
Free list stalls/sec
--------------------
77
-----------------------------------------------------------------------------------------------------------------
Number of pages flushed to disk/sec by a checkpoint or other operation that require all dirty pages to be flushed
Checkpoint pages/sec
--------------------
786108
------------------------------------------------------------------------
Number of buffers written per second by the buffer manager"s lazy writer
Lazy writes/sec
--------------------
5157
--------------------------------------------------------------
Total number of processes waiting for a workspace memory grant
Memory Grants Pending
---------------------
0
----------------------------------------------------------------------------------
Total number of processes that have successfully acquired a workspace memory grant
Memory Grants Outstanding
-------------------------
0
根据 Shanky 的请求。
physical_memory_in_use_kb = 30784516
large_page_allocations_kb = 196608
locked_page_allocations_kb = 30285504
total_virtual_address_space_kb = 8589934464
virtual_address_space_reserved_kb = 34544372
virtual_address_space_committed_kb = 31110044
virtual_address_space_available_kb = 8555390092
page_fault_count = 1706349
memory_utilization_percentage = 100
available_commit_limit_kb = 34625996
process_physical_memory_low = 0
process_virtual_memory_low = 0
所以基于此,看起来一切看起来都很棒。但这并不能解释为什么服务器会随着时间的推移开始变慢,就像其他虚拟机的内存被盗一样。看到这些结果,这个问题可能已经完全不同了。
多少内存分配给SQL服务器通过最大服务器内存。您发布的信息不包括该信息。
您还可以添加以下查询的输出吗?请格式化问题,使输出清晰可见
select * from sys.dm_os_process_memory
您永远不应该查看任务管理器以了解 SQL 服务器内存消耗。它是一个 windows 工具,仅提供有关 Working Set memory 的信息,而不是 SQL 服务器消耗的总内存。如果 SQL 服务器服务帐户在本地系统下是 运行 或服务帐户具有锁定内存页权限 (LPIM),任务管理器将不会显示 AWE API 分配的内存(或锁定的内存) 。
任务管理器显示的工作集内存可以被OS调出,但是AWE分配的内存API(当SQL服务器服务帐户有LPIM时)不能被调出这就是为什么它被称为 locked
。在你的情况下,我猜 SQL 服务器服务帐户有 LPIM,所以任务管理器不显示 AWE API 分配的内存,只是工作集
在查询输出中,如果您看到 locked_page_allocations_kb 的某些值,则 SQL 帐户具有 LPIM。
编辑:
来自查询结果
locked_page_allocations_kb = 30285504~ 28 G
这是 SQL 服务器使用的总内存的一部分(锁定的内存),这不会显示在任务管理器下。任务管理器不会显示它,因为它是不可分页的内存,任务管理器只报告可分页的工作集。
现在你问了为什么 SQL 服务器内存消耗在你 运行 大查询时增加,这是因为缓冲池开始获取新页面导致内存消耗增加,因此利用率增加
我有一个 sql 通过虚拟机 运行 的实例。 VM 分配了 32gb 内存,我已设置为使用 28gb。但是,查看内存使用情况,我只看到 SQL 使用了大约 1gb。它还显示除了 1gb 之外的所有空间都是免费的,但是正在使用的进程加起来不超过 31gb。甚至不接近,我看到总共可能有 3gb。
我附上了一些 TSQL 的内存使用结果。
Memory usage details for SQL Server instance- X64) - Enterprise Edition (64-bit))
----------------------------------------------------------------------------------------------------
--------------------------------------
Memory visible to the Operating System
Physical Memory_MB Physical Memory_GB Virtual Memory GB
--------------------------------------- --------------------------------------- ---------------------------------------
32768 32 8192
-------------------------------
Buffer Pool Usage at the Moment
BPool_Committed_MB BPool_Commit_Tgt_MB BPool_Visible_MB
--------------------------------------- --------------------------------------- ---------------------------------------
28672.000000 28672.000000 28672.000000
---------------------------------------------------------------------------
Total Memory used by SQL Server Buffer Pool as reported by Perfmon counters
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
29360128 28672.000000 28.000000000
-------------------------------------------------------------
Memory needed as per current Workload for SQL Server instance
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
29360128 28672.000000 28.000000000
------------------------------------------------------------------------------
Total amount of dynamic memory the server is using for maintaining connections
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
5288 5.164062 0.005043029
------------------------------------------------------------
Total amount of dynamic memory the server is using for locks
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
31248 30.515625 0.029800415
----------------------------------------------------------------------------
Total amount of dynamic memory the server is using for the dynamic SQL cache
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
40752 39.796875 0.038864135
-------------------------------------------------------------------------
Total amount of dynamic memory the server is using for query optimization
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
2528 2.468750 0.002410888
-------------------------------------------------------------------------------
Total amount of dynamic memory used for hash, sort and create index operations.
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
0 0.000000 0.000000000
------------------------------------------
Total Amount of memory consumed by cursors
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
1832 1.789062 0.001747131
-------------------------------------------------------------------------
Number of pages in the buffer pool (includes database, free, and stolen).
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
3670016 29360128.000000 28672.000000000
---------------------------------------
Number of Data pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
1429714 11437712.000000 11169.640625000
---------------------------------------
Number of Free pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
1887521 15100168.000000 14746.257812500
-------------------------------------------
Number of Reserved pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
0 0.000000 0.000000000
-----------------------------------------
Number of Stolen pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
352781 2822248.000000 2756.101562500
---------------------------------------------
Number of Plan Cache pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
357949 2863592.000000 2796.476562500
-----------------------------------------------------------------------------------------------
Page Life Expectancy - Number of seconds a page will stay in the buffer pool without references
Page Life in seconds PLE Status
-------------------- ------------------
81046 PLE is Healthy
--------------------------------------------------------------
Number of requests per second that had to wait for a free page
Free list stalls/sec
--------------------
77
-----------------------------------------------------------------------------------------------------------------
Number of pages flushed to disk/sec by a checkpoint or other operation that require all dirty pages to be flushed
Checkpoint pages/sec
--------------------
786108
------------------------------------------------------------------------
Number of buffers written per second by the buffer manager"s lazy writer
Lazy writes/sec
--------------------
5157
--------------------------------------------------------------
Total number of processes waiting for a workspace memory grant
Memory Grants Pending
---------------------
0
----------------------------------------------------------------------------------
Total number of processes that have successfully acquired a workspace memory grant
Memory Grants Outstanding
-------------------------
0
根据 Shanky 的请求。
physical_memory_in_use_kb = 30784516
large_page_allocations_kb = 196608
locked_page_allocations_kb = 30285504
total_virtual_address_space_kb = 8589934464
virtual_address_space_reserved_kb = 34544372
virtual_address_space_committed_kb = 31110044
virtual_address_space_available_kb = 8555390092
page_fault_count = 1706349
memory_utilization_percentage = 100
available_commit_limit_kb = 34625996
process_physical_memory_low = 0
process_virtual_memory_low = 0
所以基于此,看起来一切看起来都很棒。但这并不能解释为什么服务器会随着时间的推移开始变慢,就像其他虚拟机的内存被盗一样。看到这些结果,这个问题可能已经完全不同了。
多少内存分配给SQL服务器通过最大服务器内存。您发布的信息不包括该信息。
您还可以添加以下查询的输出吗?请格式化问题,使输出清晰可见
select * from sys.dm_os_process_memory
您永远不应该查看任务管理器以了解 SQL 服务器内存消耗。它是一个 windows 工具,仅提供有关 Working Set memory 的信息,而不是 SQL 服务器消耗的总内存。如果 SQL 服务器服务帐户在本地系统下是 运行 或服务帐户具有锁定内存页权限 (LPIM),任务管理器将不会显示 AWE API 分配的内存(或锁定的内存) 。
任务管理器显示的工作集内存可以被OS调出,但是AWE分配的内存API(当SQL服务器服务帐户有LPIM时)不能被调出这就是为什么它被称为 locked
。在你的情况下,我猜 SQL 服务器服务帐户有 LPIM,所以任务管理器不显示 AWE API 分配的内存,只是工作集
在查询输出中,如果您看到 locked_page_allocations_kb 的某些值,则 SQL 帐户具有 LPIM。
编辑:
来自查询结果
locked_page_allocations_kb = 30285504~ 28 G
这是 SQL 服务器使用的总内存的一部分(锁定的内存),这不会显示在任务管理器下。任务管理器不会显示它,因为它是不可分页的内存,任务管理器只报告可分页的工作集。
现在你问了为什么 SQL 服务器内存消耗在你 运行 大查询时增加,这是因为缓冲池开始获取新页面导致内存消耗增加,因此利用率增加