Lazy write
- Lazy write is an effect caused by the use of a write-back cache. In a write-back cache, data is first written to the cache and then is later (during a particular time such as an idle machine cycle) is written to the disk or memory.
- This type of cache is more complex to implement, due to the need to track each locations that have been written over and what needs to be marked as dirty to fix later.
Lazy writer in Memory
- Lazy writer is a thread which is present for each NUMA node (and every instance has at least one) that scans through the buffer cache associated with that node.
- The lazy writer thread sleeps for a specific interval of time, and when it wakes up, it examines the size of the free buffer list.
- If the list is below a certain threshold, which depends on the total size of the buffer pool, the lazy writer thread scans the buffer pool to repopulate the free list.
- As buffers are added to the free list, they are also written to disk if they are dirty.
- So if there is no memory pressure and memory notification is stable it sleeps
- The sole purpose of Lazy Writer is to maintain some free buffers in the SQL Server Buffer Pool.
- Lazy writer runs periodically and check which buffers can be flushed and returned to the free pool.
- So even SQL Server is not under memory pressure, it will also work regularly.