Microsoft Game Technology Group
April 2006
Today, a high percentage of Windows computers have a DVD drive and many upcoming Windows games are shipping on DVD. It is important for game developers to ensure they use the DVD drive to its full advantage. By understanding how data is read from a DVD and how the data's location affects the read time, the developer can reduce load times and help improve the overall game performance during game play.
The sequence that a DVD drive executes upon receiving a read request is as follows:
Data on a DVD is stored as a continuous spiral like a CD; however the files are broken up into blocks and sectors. Files are spread over Error Correction Code (ECC) blocks and each block is divided into sixteen 2KB DVD sectors (32KB of data in each block). Files are aligned along the DVD sector boundaries with any unused space in sector left empty. If a file is only 10 bytes then the rest of the 2KB is wasted, so when possible bundle files into 2KB increments to get the best data density. Be aware that these specifications are for DVD only, and CD and HD-DVD have different specifications.
Drive reads are quantized differently, depending on whether they are logical drive reads or physical drive reads. Logical drives reads can only read an integer number of DVD sectors, while a physical drive read request can only read an integer number of ECC blocks. Typically, physical drive receives a read request; it will try to fill its cache. The DVD drive cache size depends on the individual drive's specifications.
When a DVD drive gets a read request exceeding the cache size, the request is broken down into cache sized requests. The drive seeks to the ECC block containing the first sector of the request and reads the whole ECC block. The drive firmware decodes the ECC block and then reads the next ECC block. The process is repeated till the drive cache is filled or all requests are fulfilled. The kernel then reads the decoded data from the drive cache. It then flushes the cache and starts the next read, if any read requests are left. It is important to note that every uncached read will flush the drive cache.
DVDs and DVD drives are not perfect and errors can occur during reading. Like CDs, portions of a DVD can become unreadable from dust or scratches. If any part of the block is unreadable the whole block is considered unreadable. If a read error occurs the drive will retry reading the ECC block. If the block is still unreadable, the drive aborts the read and returns a value to the kernel indicating that the block was unreadable. The kernel then decides what step to take next. The kernel can either reissue the read request, abort the read altogether, or spin the drive down and reissue the request.
The throughput of a DVD drive depends on multiple factors. The location(s) of requested data, how clean/scratched the disk is, how many streams are reading from the disk, the size of the buffers associated with those streams, and the specifications of the individual drive all affect the throughput performance of the drive. Throughput also depends on whether the drive has constant angular velocity (CAV) or constant linear velocity (CLV). If a drive spins with CAV, the disc spins at the same speed regardless of where the drive head is located. This means that the data track moves past the drive head faster the closer the drive head is to the edge of the disc. In a CLV drive the disc spins down as the drive head moves outward, so the data track moves past the drive head at a constant speed. Most PC DVD drives are CLV drives.
While the drive is seeking and changing layers data can't be read from the disc. It is a good practice to minimize these operations, especially during an initial load screen.
Let's assume that a file in the middle of the disc needs to be read. This means that the throughput from that area of the disc is approximately 8.25MB/sec. If the seek stroke is 1/2 to 1/3 then the average seek time is 150ms. In this example, 1.2MB could have been read in the time it took just to get the drive head to where it can read (150ms * 8.25MB/sec = 1.2MB). Adding a layer change raises the wasted throughput to 1.8MB (225ms * 8.25MD/sec = 1.8MB).
Another example that demonstrates wasted throughput is loading 20 poorly located files on startup, in a 12x CAV drive with no layer changes. If each seek plus read latency per seek takes approximately 200ms, 4 seconds are spent just seeking for the data (20 seeks * 200ms/seek = 4 sec). If the files were located on the outer diameter and read at 11x DVD speed, the throughput would average 15.2MB/sec (11 speed/12 speed * 16MB/sec = 15.2MB/sec). The wasted throughput in this example would be approximately 60.8MB (15.2MB/sec * 4 sec = 60.8MB).
Asynchronous reads are more efficient than synchronous reads. When a synchronous read is performed, one or more ECC block of data is read into system memory before being copied into application memory. Asynchronous reads copy decoded ECC blocks directly to application memory with the advantage of avoiding L2 caching and less CPU overhead. To perform asynchronous reads, the developer should use the FILE_FLAG_OVERLAPPED flag when using the CreateFile function to open files. The ReadFile function also needs a valid OVERLAPPED structure passed in to perform asynchronous I/O.
More information on asynchronous I/O can be found at Synchronous and Asynchronous I/O
The best principle in reading from a DVD is to avoid small reads and seeks. When reads are smaller than an ECC block, 32KB or less, the rest of the block is being wasted. Since drive cache sizes vary from drive to drive, developers will have to decide on a minimum read size and not make read requests smaller than that amount. The minimum request size should also be some integer multiple of ECC blocks to avoid wasting data that has to be read and decoded. It is also important to avoid seeks at all costs as any time spent seeking is time spent not reading data.
There are some important compatibility issues to be aware of when releasing on DVD. First, DVD drives in Windows computers can vary in performance so if a specific DVD throughput or higher, it is important to make sure your users will meet those requirements. Also multilayer DVDs can cause compatibility issues on the some DVD drives. To avoid these issues, it is advisable to use single layer DVDs or thoroughly test on a majority of DVD drives before releasing on multilayer DVDs.
To improve DVD performance some general rules can be applied. The following techniques can help maximize throughput and reduce wasted data: