PREEMPTIVE_OS_CREATEFILE Wait Type 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

Is It a Problem?

Modest background amounts, no; our SQL Server 2025 lab had about 400 waits totalling 0.7 seconds in a day. Get Wait Statistics does not filter it out, so if it ranks, you will see it. It is usually not a problem unless the workload creates many files, for example with FILESTREAM.


What It Means

Microsoft lists it as internal use only. It is the Windows CreateFile function, which is also used to open files for reading, not only to create them. While the call runs, the thread is in preemptive mode, outside SQL Server’s scheduler.


When It Does Matter

When file opens are slow enough to hurt a workload, and FILESTREAM is the usual one. Slow CreateFile calls usually have Windows-side causes, none of them SQL Server issues: SMB problems, authentication failures, a slow I/O subsystem and NTFS flushing its caches. Antivirus filter drivers on the FILESTREAM containers are the other common miss. Catch the caller while it happens:

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;

If a plain file open is slow from Windows on the same path, the fix is in the infrastructure. The baseline to monitor is its average wait per call. 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. This page.
  • 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

Where To Go Next

PREEMPTIVE_OS_CREATEFILE is background noise on most instances. 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 *