Database/MS-SQL

MSSQL 2012 메모리 구조 변경 (single page / multi page)

99iberty 2018. 1. 18. 16:57



요새 MSSQL 공부를 다시 하고 있는데..


2012 에서부터 변경된 메모리 구조 관련하여 궁금한 점이 있습니다..!


https://support.microsoft.com/en-us/help/2663912/memory-configuration-and-sizing-considerations-in-sql-server-2012-and


 


Starting with SQL Server 2012, Multi-Page allocations and CLR allocations are also included in memory limits that are controlled by max server memory (MB) and min server memory (MB). This change provides a more accurate sizing ability for all memory requirements that go through the SQL Server memory manager.


 


그 동안 SQL Server에서 사용하는 메모리는 Buffer Pool(single page) + non-Buffer Pool(multi page, CLR, Linked Serever, Thread stacks memory)


이라고 알고 있었는데, 2012부터는 single page multipage의 구분이 사라지고, multipage CLR allocation SQL 메모리 관리자에 의해 할당되는 것 같더라구요..


 


    Q1. 그렇다면 이제 버퍼풀/nonbuffer pool 구분이 사라지는 건가요?


        : 아니요.. SQL Server 2004부터 Buffer Pool에서 할당하는 메모리 영역이 확장됐다고 이해하시면 됩니다.


          이전에 signle page(8Kb 이하) buffer pool에서 할당했는데 sql server 2014부터는 Multi-page allocations buffer pool에서 할당합니다.


 


    Q2. 그동안 버퍼풀=single page 로 알고 있었는데 이제 버퍼풀 영역=any size page+CLR allocation인건가요?


         (최대/최소로 제어되는 메모리 제한 범위가 버퍼풀 영역인건지요?)


         NO, CLR allocation은 여전히  memory_to_reserve(MTL) 에서 할당합니다.


 


    Q3. 아래 MemtoLeave 내용 (기존 nonbuffer pool) 을 보면 여기에도 CLR allocation이 들어가서 헷갈립니다...ㅜㅜ


         (CLR 할당은 버퍼풀 영역인지 논버퍼풀 영역인지...)


        CLR은 여전히 MTL에서 할당하고 Windows API를 가지고 메모리 할당을 받습니다.


        이 영역은 아시는 것처럼 SQL Server가 당당하는 것이 아니라 OS가 담당하게 됩니다.


 


        The following table indicates whether a specific type of memory allocation falls into the memory_to_reserve region of virtual address space for the SQL Server process.


Type of memory allocation

SQL Server 2005, SQL Server 2008, SQL Server 2008 R2

SQL Server 2012, SQL Server 2014

Single-page allocations

No

No, consolidated into "any size" page allocations

Multi-page allocations

Yes

No, consolidated into "any size" page allocations

CLR allocations

Yes

Yes

Thread stacks memory

Yes

Yes

Direct allocations from Windows

Yes

Yes


 


    Q4. OS의 작업관리자에서 보이는 Sqlserver.exe working set non buffer pool 영역으로 알면 될까요?


         SQL 서버가 현재 사용하고 있는 총 물리메모리 양은


         total server memory + sqlservere.exe working set 으로만 계산하면 될지요?


        아니면 다른 항목이 더 있는지요?


 


        working set SQL Server가 할당받아 사용중이 물리적 메모리 양을 의미하며 받드시 non buffer pool이라고 생각하시면 안됩니다.


       모든 Application Virtual Address를 사용하게 됩니다. 물리적 메모리를 직접 Access하지 않습니다.


       사용하는 Addrss 영역이라고 표현하는게 맞는 듯합니다. total server memory  + Non Buffer Pool( Thread Stack, CLR allocations, Direct allocations from Windows - 실제 DBCC Memory status로 보시면 구할 수 있습니다. )


       


 


    Q5. 사실 이 의문점을 가지게 된 계기가 sql server의 메모리 사용 관련해서였습니다..


         메모리 사용량이 거의 100% SQL 서버의 적정 최대 메모리 설정을 수정해야 하는 경우가 있었는데,


         total server memory target과 같다고 해서 계속 쓰고 있는 상황이 아니니, 어느정도까지 최대치를 낮춰야 할지 감이 안 잡히더라구요....


         SQL server total server memory 항목의 경우 한번 최대치까지 도달하면 OS에서 반환요구를 하지 않는 이상


         계속 잡고 있게 되는데 실제 해당 메모리 사용량 중 SQL에서 얼마만큼 사용하고 있는지에 대해서 알 수 있는 지표가 있는지요?


 


         OS Available MBtye가 최소 2GB 이상이 되도록 잡아 줄것을 권장합니다.


         예를 들어 x64 같은 경우 OS가 최소 4GB 이상의 메모리를 갖을 것을 권장합니다.


         그래서 SQL Server Max Server Memory <= 물리적 메모리 양 - 4GB 로 잡아 주시면 되고..


         OS에서 동작하는 프로그램과 솔루션들이 Memory를 사요하기 때문에 Available MBtye 를 모니터링해서 조정해 주시면 됩니다.