An oplock is a performance-enhancing technique used in Microsoft networking (SMB) environments. It enables applications to speed up file access and minimize network traffic by caching all or part of a file locally. As the data is kept on the client, read and write operations can be performed locally, without involving the server.
The server supports three categories of oplocks:
- Exclusive. An Exclusive oplock enables a single client to cache a file for both reading and writing. As the client that owns the oplock is the only client accessing the file, it can read and modify all or part of the file locally. The client does not need to post any changes to the server until it closes the file and releases the oplock.
- Batch. A Batch oplock enables a single client to cache a file for both reading and writing, as in the case of an exclusive oplock. In addition, the client can preserve the cached information even after closing the file; file open and close operations are also performed locally. The client does not need to post any changes back to the server until it releases the oplock.
- Level II. A Level II oplock enables multiple clients to cache a file for reading only. The clients owning the oplock can read file data and attributes from local information, cached or read-ahead. If one client makes any changes to the file, all the oplocks are broken.
When dealing with oplocks, the server acts in accordance with the SMB specification. Whether operating in a pure Windows environment or with a mix of SMB and NFS clients, the server allows applications to take advantage of local caches while preserving data integrity.