How, in future, SQL determine if page, which Storage Engine asks, is already in memory?
To balance CPU and I/O throughput to achieve good performance and maximize hardware utilization, SQL Server includes 2 asynchronous I/O mechanisms - sequential read ahead and random prefetching
When SQL Server has to scan a large table, the storage engine will initiate the read ahead mechanism to ensure that pages are in memory and they are ready to scan before they are needed by the Query Optimizer.
If you are using Enterprise edition, then there is a mechanism called advanced scanning or merry-go-round scanning that will allow multiple tasks to share full table scans. This advance scanning avoids users to compete for buffer space and taxing other resources on the server.
And which algorithm it uses to keep some free space for new pages?
SQL Server (and Sybase as well :-) ) uses LRU (Least Recently Used) algorithm to keep track of pages that are aged in the buffer pool. It increments a counter every time a page is referenced and decrements the counter every time the lazy writer process sweeps the page.
Any worker thread will check the memory status of Buffer Pool to make sure that there are healthy number of Free pages to honor incoming new requests.
Note that : SQL Server will always keep a minimum number of free pages on the free list, so that it can serve incoming requests without any significant delay. The amount of free space is calculated based on Buffer Pool and amount of incoming requests.
IF there are no free buffers or very little left then :
- If Max Memory is reached then
- If Max Memory is not reached then
- SQL Server will commit more reserved pages into the buffer pool.
You can use DMV (in 2005 and up) - sys.dm_os_buffer_descriptors
to find the pages in the buffer pool.
Also, there are Memory Manager surface area changes in SQL Server 2012.
KB 2663912 :
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. Carefully review your current max server memory (MB) and min server memory (MB) values after you upgrade to SQL Server 2012.
Highly recommend to read :
Best Answer
The page you reference talks about monitoring a system running SQL Server, but it does not make any implicit or explicit promise that
Memory:Pages/sec
will be available specifically in the DMVsys.dm_os_performance_counters
. This is more about general system monitoring using performance monitor, 3rd party tools, etc.The DMV only exposes a specific subset of counters that are SQL Server-specific (according to someone, since it can be subjective).
Memory:Pages/sec
is, at least currently, not one of them - primarily because it measures for the whole operating system, not for the current instance of SQL Server. You can see what counters are available simply by querying the DMV. If the DMV is empty, Erik's link is a good one.You can also look directly at the
perf-{instance}sqlctr.ini
in your instance'sBinn
folder. You may be tempted to hack the ini file to stuff your desired counters into the DMV, but I haven't tried this, don't recommend it, and am sure you will be on your own in terms of support. Better solution is to use a different method to monitor performance counters (both those you can get from the DMVs and those you can't).