PREEMPTIVE_OS File Operation Wait Types in SQL Server

⏳Part of the SQL Server Wait Types Library, every wait type explained.Related deep dive: SOS_SCHEDULER_YIELD Wait TypeRelated pillar: Performance & Troubleshooting

Many PREEMPTIVE_OS_* waits each track one Windows file call, and this page covers them together: PREEMPTIVE_OS_CLOSEHANDLE, COPYFILE, CREATEDIRECTORY, DELETEFILE, FINDFILE, GETCOMPRESSEDFILESIZE, GETFILEATTRIBUTES, GETFILESIZE, GETFINALFILEPATHBYHANDLE, GETLONGPATHNAME, GETVOLUMENAMEFORVOLUMEMOUNTPOINT, GETVOLUMEPATHNAME, MOVEFILE, OPENDIRECTORY, REMOVEDIRECTORY, SETENDOFFILE, SETFILEPOINTER, WRITEFILE, plus PREEMPTIVE_FILESIZEGET and PREEMPTIVE_OS_BACKUPREAD.

Microsoft lists them as internal use only, so the names are the guide: each is the Windows function, or group of functions, SQL Server was calling. While a call runs, the thread is in preemptive mode, outside SQL Server’s scheduler, and it shows as RUNNING.

Two are worth naming. PREEMPTIVE_OS_SETFILEVALIDDATA is the call made when a data file is created or grown under instant file initialization, so time there is the feature working. PREEMPTIVE_OS_BACKUPREAD is the Windows BackupRead function.


Are They a Problem?

One at a time, almost never; none of them is a known contention point. Together they measure your file infrastructure. When several rise at once, the file system under SQL Server, or a filter driver on top of it such as antivirus, is slow, and the same slowness can be reproduced with ordinary file operations from Windows on those volumes. Get Wait Statistics does not filter them out.


When They Do Matter

When they rise together, match them to the file activity at the time, such as backups, FILESTREAM work or file growth, and see who is in the call:

SELECT
    r.session_id,
    r.wait_type,
    r.wait_time AS wait_ms,
    s.login_name,
    s.program_name,
    t.text AS running_sql
FROM sys.dm_exec_requests AS r
JOIN sys.dm_exec_sessions AS s ON s.session_id = r.session_id
OUTER APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.wait_type LIKE N'PREEMPTIVE_OS_%'
ORDER BY r.wait_time DESC;

Check that antivirus excludes the data, log, backup and FILESTREAM paths, since filter drivers add to every one of these calls. If the calls are genuinely slow, show it from Windows and take it to the platform team. The baseline to monitor is the family’s wait time per interval. The query needs VIEW SERVER STATE.


The PREEMPTIVE_OS File Waits

Each of these is SQL Server calling a Windows file API and waiting for it to return, so the time is spent in the operating system and the storage underneath it. If one is near the top of your waits, read it next to the waits that usually matter.

  • PREEMPTIVE_OS_WRITEFILEGATHERZeroing file space. Writing zeros into new file space when a file is created or grows without instant file initialization.Worth investigating
  • PREEMPTIVE_OS_CREATEFILEOpening files. The Windows CreateFile call, used to open existing files as well as create new ones.Worth a look when it climbs
  • PREEMPTIVE_OS_FLUSHFILEBUFFERSFlushing to disk. Forcing buffered writes for a file down to durable storage.Worth a look when it climbs
  • PREEMPTIVE_OS_FILEOPSOther file calls. A catch-all for Windows file functions without a wait type of their own.Worth a look when it climbs
  • PREEMPTIVE_OS_GETDISKFREESPACEFree space checks. Asking Windows how much space a volume has, often from monitoring queries.Usually noise
  • File Operation waitsThe rest of the file APIs. The smaller file calls covered together on one page.Worth a look when it climbs. This page.

Where To Go Next

These file waits are usually small. If you are chasing a real problem, start with the waits that cost you time.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *