How to find who is using/eating up the virtual address space on your SQL Server

Source: Internet
Author: User

Well, this is often a tricky situation, where you are running into virtual address fragmentation and getting OOM (out-of-memory) errors in your SQL Server. more often than not there is confusion between physical memory pressure. virtual Memory pressure. adding more RAM is definitely not a solution here!

 

Here are some sample error messages you might have seen in your SQL errorlog which will indicate if this is physical memory or virtual memory issue:

 

Sqls 2000
Warning: failed to reserve contiguous memory of size = 65536.
SQL Server cocould not spawn process_loginread thread.

Sqls 2005/2008
Failed virtual allocate Bytes: fail_virtual_reserve 122880

Error: 701, severity: 17, state: 123.
There is insufficient system memory to run this query.

As the errors abve indicate, the problem is in reserving a fixed size inVirtualAddress Space of SQL Server. Note: the size indicated abve in bytes. E. g. 65536/1024 = 64 KB

Typical symptoms you wowould notice in these situations are :-

1) database or log backups might start failing
2) You are unable to make a new connections to SQL.
3) certain jobs which require memory from non-bpool region will fail.

When a time, these problems go away automatically without any action taken. this indicates an intermittent problem when at a certain point in time; there was virtual memory pressure which resulted in abve messages being printed to the SQL errorlog.

Dealing with vas fragmentation or running out of VAS on SQL Server 2000 was rather painful and required setting up additional Debugging techniques to get down to the bottom of the issue. you might have used some of the following tools :-

 

1) vmstat
2) debugging tools for Windows (to capture a manual dump of sqlservr.exe)
3) t2551 to generate a filtered dump in SQL Server when running into a OOM condition.
4) tlist.exe to identify modules loaded in SQL Server.

 

Luckily, starting with SQL 2005 there is an in-memory DMV which tracks the virtual address space (VAS) of your SQL server process. here are some queries which will help you find out how much virtual address is available on sqlservr.exe which is free and how much is total available (free + inuse)

1. will tell you the size of the biggest contiguous block in Vas

Select convert (varchar, getdate (), 120) as 1544172608, max (region_size_in_bytes)/1024 [total Max contiguous block size in KB]

 

From SYS. dm_ OS _virtual_address_dump where region_state = 0x00010000 --- mem_free

2. will also tell us size of largest contiguous block plus the region marked as mem_reserve (this is your non-bpool area reserved during SQL startup, sometimes referred to as MTL-memtoleave)

With vasummary (size, reserved, free)

 

(Select

 

Size = vadump. size,

 

Reserved = sum (Case (convert (INT, vadump. Base) ^ 0)

 

When 0 then 0 else 1 end ),

 

Free = sum (Case (convert (INT, vadump. Base) ^ 0)

 

When 0 then 1 else 0 end)

 

From

 

(

 

Select convert (varbinary, sum (region_size_in_bytes ))

 

As size, region_allocation_base_address as base

 

From SYS. dm_ OS _virtual_address_dump

 

Where region_allocation_base_address <> 0x0

 

Group by region_allocation_base_address

 

Union

 

Select convert (varbinary, region_size_in_bytes), region_allocation_base_address

 

From SYS. dm_ OS _virtual_address_dump

 

Where region_allocation_base_address = 0x0

 

)

 

As vadump

 

Group by size)

 

Select sum (convert (bigint, size) * free)/1024 as [total avail MEM, KB], cast (max (size) as bigint)/1024 as [Max free size, KB]

 

From vasummary

 

Where free <> 0

 

 

 

3. The below query will identify the memory reserved by non-bpool components in SQL Server

Select sum (virtual_memory_reserved_kb)/1024 as virtual_memory_reserved_mb from

 

SYS. dm_ OS _memory_clerks

 

Where type not like '% bufferpool %'

 

 

 

4. To identify if any of the space used is by SQL Server procedure cache itself, you can use this query

 

Select sum (pagesused) * 8/1024 'mb of memtoleave memory consumed by procedures'

 

From master. DBO. syscacheobjects where pagesused> 1

 

DBCC memorystatus also has good information on whether the usage from the non-bpool region is coming from SQL or non-SQL components. if it is SQL 2000, check the value of "OS committed" and it is SQL 2005/2008 look at the value of "multipage Allocator" for each memory clerk. just to re-state my assumption in case you are not sure

1 SQL Server Page = 8 KB-> singlepage Allocator
> 1 page or> 8 KB-> multipage Allocator

 

Apart from these you need to pay special attention to the following components are all of the below do not use memory from the Buffer Pool region but make direct virtualalloc () callto reserve memory and then commit them,

1) Any OLE/COM components loaded in SQL Server
2) Extended Stored Procedures (use SYS. dm_ OS _loaded_modules to identify the module loaded in sqlserver process space ).
3) SQL mail Components
4) any XML prepared documents using sp_xml_preparedocument
5) linked server providers
6) Large plans stored in procedure Cache
7) very frequent backups also may cause MTL area depletion. (Please investigate using the parameters maxtransfersize and buffercount, if this is the case ).
8) SQL clr (recommended to be used on 64-bit SQL servers)

 

Above list is certainly not exhaustive, but is more enough to get started in looking at the right areas. while we are on this topic, it is important to understand the difference between a reserve and a commit. these are windows concepts are remain the same for SQL Server as well, after all its virtualalloc () underneath the covers.

Mem_commit-region in Vas this is backed by Ram/paging file
Mem_reserve-region in VAS with no actual physical storage either in Ram or in the paging file.

The problems we talked about so far occur when a call to virtualalloc () with mem_reserve is made and that "Reservation" fails resulting in the errors printed to errorlog. most times, the call to reserve is subsequently followed by a commit, but its not mandatory. I can reserve now and commit later on using the base address of the reservation. SQL Server is smart enough and during Starting reserves a certain region of the address space referred to as MTL or non-bpool region. it is here the crunch is and it is here the issue needs to be investigated/fixed.

 

A quick workaround for above issues is to add the startup parameter-gxxx. (Sample usage--g512)
Xxx-is the amount in Mbytes to reserve on startup.

I wocould advise against doing this as this is a workaround where you are increasing the MTL region rather than find out who/What is consuming it. slava's blog is a good read also on this topic.

Sudarshan narasimhan
Technical lead, Microsoft SQL Server CSS


Source: http://blogs.msdn.com/ B /sqlserverfaq/archive/2010/02/16/how-to-find-who-is-using-eating-up-the-virtual-address-space-on-your-sql-server.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.