Why is it so slow to copy from a CBFS Connect drive as opposed to a regular disk?

1. Context switches


CBFS Connect consists of a kernel-mode file system driver and a user-mode portion of code linked to your application. When the OS sends the file system request to the file system, the kernel-mode driver invokes the user-mode code, thus causing a context switch back to the user mode and one more context switch back to the kernel mode when the callback is handled. If your user-mode code calls a system function, chances are that you again switch to kernel mode and back, as shown on the diagram. This process involves several threads and several synchronization objects as well.

Extra context switches cause a significant slowdown for all operations. This is especially true when copying or another file system operation is done in small chunks (e.g., 64Kb as Explorer does for copying or even several bytes as some applications do). CBFS Connect includes several caches including a cache for file operations. Having the cache enabled slightly improves operations, but context switching is inevitable.

2. Global locks

During the Open and Close callbacks, there exist certain disk-wide resources that need to be guarded. This requires the use of a global lock (i.e., the lock that blocks any operations on the drive until it's removed). Such locks, of course, slow down operations, but they are required to protect resources from concurrent modifications from different threads. So, the faster your code handles the OnCreateFile/OnOpenFile and OnCloseFile requests, the less time is wasted waiting for global locks to be released.

Ready to get started?

Learn more about Callback Technologies or download a free trial.

Download Now