5. 跟蹤標記 (Trace Flag) 834, 845 對內存頁行爲的影響

跟蹤標記:834sql

功能:windows

在64位的windows環境下,爲SQL Server開啓這個跟蹤標記,那麼SQL Server 會使用大頁(Large pages)爲內存緩衝區(buffer pool)分配內存,從而能夠提升CPU轉換檢測緩衝區(TLB: Translation Lookaside Buffer)的效率得以提高性能;安全

大頁(Large Pages): 正常狀況下windows內存是4KB的頁,而大頁的最小空間是2MB,也就是說分配的時候可能大於2MB;服務器

轉換檢測緩衝區(TLB: Translation Lookaside Buffer):是一個內存管理單元,用於改進虛擬地址到物理地址轉換速度;ide

SQLOS有4種內存分配方式:單頁(Single Page), 多頁(Multi Page),這裏的頁都是SQLOS的頁,同數據頁大小同樣爲8KB,大頁(Large Page), 保留頁(Reserved Page);默認狀況下Buffer Pool使用Single Page的分配方式,Buffer Pool以外使用Multi Page的分配方式,而834跟蹤標記改變的就是Buffer Pool的分配方式。性能

如何開啓?spa

跟蹤標記834只能在啓動SQL Server時開啓code

1. 打開SQL Server Configuration Manger;orm

2. 右擊SQL Server實例選擇屬性(Properties);server

3. 在啓動參數 (Startup Parameters) 裏添加-T834;

4. 保存並重啓SQL Server實例的服務以生效;

5. 開啓成功的話,在SQL Server errorlog裏能夠看到相似字樣:Using large pages in the memory manager.

備註:

1. 大頁 (Large Pages) 分配只在SQL Server 64位+企業版+大於8GB內存的SQLOS有效;

2. 須要爲SQL Server開啓了Lock Pages In Memory (LPIM);

3. 建議只在SQL Server的專用服務器上開啓,不然若是內存碎片太多或者內存不足沒法分配大頁,可能會致使SQL Server沒法啓動;另外在使用columnstore index的服務器上,也不建議開啓這個跟蹤標記;

 

跟蹤標記:845

功能:

Locked Pages In Memory(LPIM)是一個windows特性,用於控制Windows進程不使用虛擬內存;

在SQL Server 2012前,若是要對SQL Server進程開啓這一特性,根據版本不一樣,可能會須要用到跟蹤標記845,詳見下表:

SQL Server 2012起,如何開啓LPIM

1. 開始菜單 - 運行 - 輸入gpedit.msc  - 回車,以打開組策略;

2. 計算機配置 - Windows 設置 - 安全設置 - 本地策略 - 用戶權利指派

3. 雙擊「鎖定內存中的頁」,在「本地安全策略設置」對話框中,單擊「添加」按鈕添加SQL Server服務帳號並確認;

4. 重啓SQL Server服務以使配置生效;

5. 成功開啓LPIM後,在SQL Server errorlog裏能夠看到相似字樣:Using locked pages in the memory manager.;未開啓LPIM的話,在SQL Server errorlog裏能夠看到相似字樣:Using conventional memory in the memory manager.;

備註:

1. 不難發現,在SQL Server 2012前,64位的標準版裏開啓LPIM會可能會用到跟蹤標記845,從SQL Server 2012以後就不再須要了;

2. 若是同時開啓834跟蹤標記和LPIM,那麼errorlog只會顯示:Using large pages in the memory manager.,並不會顯示:Using locked pages in the memory manager.,由於開啓跟蹤標記834的前提是開啓了LPIM;

 

注意:

1. 是否是不開啓834跟蹤標記,就徹底不使用大頁分配?不是。在開啓了LPIM的環境裏,注意看errorlog就會發現,會有相似:Large Page Allocated: 32MB的字樣;但若是沒有開啓LPIM,就不會使用大頁分配;

2. 能夠經過DMV查看Large page和Locked page的分配大小,在僅開啓了LPIM的環境裏,Locked Page Allocation會比較大,Large Page Allocation較小甚至爲0;在開啓了834跟蹤標記的服務器上Large Page Allocation會較大,有少許Locked Page Allocation;若是834和LPIM都未開啓,這兩個列值均爲0,腳本以下:

--開啓了834跟蹤標記 (errorlog: Using large pages in the memory manager.)
select large_page_allocations_kb+locked_page_allocations_kb as large_and_locked_pages_kb,physical_memory_in_use_kb,large_page_allocations_kb,locked_page_allocations_kb 
from sys.dm_os_process_memory
--large_and_locked_pages_kb    physical_memory_in_use_kb    large_page_allocations_kb    locked_page_allocations_kb
--194122560    194387600    194101248    21312

--僅開啓了LPIM (errorlog: Using locked pages in the memory manager.)
select large_page_allocations_kb+locked_page_allocations_kb as large_and_locked_pages_kb,physical_memory_in_use_kb,large_page_allocations_kb,locked_page_allocations_kb 
from sys.dm_os_process_memory
--large_and_locked_pages_kb    physical_memory_in_use_kb    large_page_allocations_kb    locked_page_allocations_kb
--255167036    256325340    1718272    253448764

--兩個都沒開啓 (errorlog: Using conventional memory in the memory manager.)
select large_page_allocations_kb+locked_page_allocations_kb as large_and_locked_pages_kb,physical_memory_in_use_kb,large_page_allocations_kb,locked_page_allocations_kb 
from sys.dm_os_process_memory
--large_and_locked_pages_kb    physical_memory_in_use_kb    large_page_allocations_kb    locked_page_allocations_kb
--0    1688278640    0    0

 

參考:

Trace Flag 834 and When to Use It

https://blogs.technet.microsoft.com/sql_server_isv/2010/11/30/temenos-t24-trace-flag-834-and-when-to-use-it/

 

Tuning options for SQL Server when running in high performance workloads

https://support.microsoft.com/en-us/help/920093/tuning-options-for-sql-server-when-running-in-high-performance-workloa

 

SQL Server and Large Pages Explained

https://blogs.msdn.microsoft.com/psssql/2009/06/05/sql-server-and-large-pages-explained/

 

Server Memory Server Configuration Options

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/server-memory-server-configuration-options#lock-pages-in-memory-lpim

 

How to enable the "locked pages" feature in SQL Server 2012

https://support.microsoft.com/en-us/help/2659143/how-to-enable-the-locked-pages-feature-in-sql-server-2012

 

DBCC TRACEON - Trace Flags (Transact-SQL)

https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql

 

SQLOS’s memory manager and SQL Server’s Buffer Pool

https://blogs.msdn.microsoft.com/slavao/2005/02/11/sqloss-memory-manager-and-sql-servers-buffer-pool/

相關文章
相關標籤/搜索