1. Field of the Invention
The present invention relates generally to disk drives, and more particularly, to improving caching techniques used in disk drives.
2. Description of the Related Art
Typical interactions between a host computer and a disk drive involve the host computer issuing read and write commands to the disk drive in order to access current data stored on the disk drive or store new data generated during computation by the host computer. Write commands that are received by a disk drive from the host computer contain specific information including the location on the disk where data is to be written.
Streams of read and write commands transmitted by a host computer to a disk drive can result in inefficiencies due to the mechanical limitations of disk drives if such commands are executed and completed in the order they are received by the disk drive. For example, switching between read and write operations can be time consuming and inefficient. Additionally, sequentially received write commands may require writing to different disk sectors that are physically distant from one another on the disk. Executing such write commands in the order they are received can thus result in significant inefficiencies.
Typical disk drives contain and utilize a “write-cache” to address the foregoing inefficiencies and enable the disk drive to immediately inform the host computer that a write command issued by the host computer has completed. The write-cache is a volatile memory component in the disk drive such as DRAM. When a write command is received from a host computer, the disk drive stores the data in the write-cache, instead of the appropriate locations on the disk, and informs the host computer that the write command has completed. The data in the write-cache is written to the disk sectors at a more efficient and appropriate time as determined by the disk drive.
However, such write-cache techniques may generate data integrity problems. For example, a loss of power before the disk drive is able to write data from the write-cache to its appropriate disk sector results in a loss of all data in the write-cache because the write-cache is a volatile memory (despite the disk drive having informed the host computer that the write command was successful). As such, disk drives also support a “flush-cache” command. A disk drive receiving a flush-cache command from a host computer writes all the data in the write-cache to their designated disk sectors before informing the host computer that the command has been completed. Because executing flush-cache commands can also be time consuming, techniques have been developed to more efficiently execute these commands. One such technique is described in co-pending U.S. Patent Application Publication 2007/0226411, entitled “Disk Drive Write Method,” which is hereby incorporated by reference (referred to herein as the “Ehrlich-Zayas Publication”). As further described therein, a special non-volatile memory location in the disk drive, referred to as a flush-cache location, may be used in response to a flush-cache command. Rather than immediately writing the data in the write-cache to its correct locations on disk, data in the write-cache is written to the flush-cache location, from which data can be recovered in the event of loss of power. This enables the disk drive to quickly inform the host computer that the flush-cache command has been completed and simultaneously provides the disk drive some additional time (in the future when writing the data to the correct locations on disk is more efficient and timely) to write the data to disk without concern that loss of power will cause loss of data. In the event that loss of power occurs, during recovery, the data in the flush-cache location is restored into the write-cache and the disk drive can continue committing the data from the write-cache to its correct location in memory.
Nevertheless, because the host computer has discretion in issuing flush-cache commands to the disk drive, data integrity issues may still arise in certain situations. For example, a host computer may issue a flush-cache command (thereby causing the data in the write-cache to be saved to the flush-cache location) and then not issue another flush-cache command for some time. In the meanwhile, the host may continue to issue write commands to the disk drive, including writing data to the same disk locations several times over. In such a scenario, if loss of power occurs, during recovery, the disk drive will attempt to restore stale data from the flush-cache location.
One or more embodiments of the invention provide techniques to maintain data integrity between a write-cache and flush-cache location of a disk drive in order to prevent stale data in the flush-cache location from being restored into the write-cache upon power loss.
A method for managing a write-cache of a disk drive according to an embodiment of the invention includes the steps of writing data stored in the write-cache onto a flush cache location on disk upon receiving a flush cache command, setting a dirty flag corresponding to the flush cache location, writing data stored in the write-cache onto locations on disk corresponding to the data when a predetermined amount of time has elapsed since execution of the flush cache command, and clearing the dirty flag corresponding to the flush cache location.
A disk drive according to an embodiment of the invention includes a disk, a volatile memory write-cache, a non-volatile memory flush-cache location, and a controller that is configured to: (a) write data stored in the write-cache into the flush-cache location upon receiving a flush cache command and set a dirty flag corresponding to the flush-cache, and (b) write data stored in the write-cache onto locations on the disk when a predetermined amount of time has elapsed since execution of the flush cache command and clear the dirty flag.
The present invention also provides a computer readable storage medium that has stored therein computer readable instruction for execution by a controller of a disk drive having a disk and a write-cache. The controller executing the instructions carries out the steps of writing data stored in the write-cache onto a flush cache location on disk upon receiving a flush cache command, setting a dirty flag corresponding to the flush cache location, writing data stored in the write-cache onto locations on disk corresponding to the data when a predetermined amount of time has elapsed since execution of the flush cache command, and clearing the dirty flag corresponding to the flush cache location.
As depicted in
In order for the host to retrieve data from magnetic disk 220, data is read from magnetic disk 220 by read/write head 304, conditioned by pre-amplifier 307, and carried as an analog signal by electrical connection 306A to SoC 375. This analog signal is conditioned by an analog signal conditioning circuitry (not shown) and a phase-locked loop (not shown) before it is supplied to an analog-to-digital converter 382. Analog-to-digital converter 382 converts the analog signal to a digital signal 386, which is transmitted to a splitter block 383. A phase-locked loop is included so that analog-to-digital converter 382 samples the analog signal at proper intervals. From digital signal 386, splitter block 383 sends the appropriate servo-related data to servo block 385 for optimal control of spindle motor 302 and arm actuator 303 using motor 305. Splitter block 385 sends the data requested by the host to read/write channel 380, which routes the data through error correction block 381 to DRAM 352 for buffering until said data can be decrypted and transmitted to the host.
For storage of data on magnetic disk 220 by the host, data is buffered in DRAM 352 as necessary and routed through error correction block 381 and then to read/write channel 380. Read/write channel 380 then sends a digital signal via electrical connection 306B to pre-amplifier 307, which conditions and amplifies the digital signal for reads/write head 304 to write the encrypted data onto magnetic disk 220. One of skill in the art will appreciate that encrypted data resides in the storage media contained in disk drive 300, i.e., DRAM 352 and magnetic disk 220.
If, instead, in step 425, the received command is a flush-cache command, all entries in the write cache that have their dirty flags set are written into data component 205 of flush-cache location 200 (step 430). In step 435, dirty flag 210 of flush-cache location 200 is set and in step 440, the current location pointed to by fill pointer 105 is stored in memory used by the disk drive, e.g., RAM illustrated in
During normal operations, the drive may determine that it is timely to write certain data entries in write-cache 100 to their correct locations on disk, for example, because the disk head is currently near relevant tracks or sectors corresponding to such entries or read commands have been completed or there is generally idle time. The data in a chosen entry in write-cache 100 is written to its correct location on the disk and the dirty flag of the entry is cleared. If the cleared data entry is the entry pointed to by free pointer 110, then the free pointer 110 is incremented. If the location pointed to by free pointer 110 now equals the fill pointer location stored in fill pointer 215 of flush-cache location 200, then the dirty flag 210 of flush-cache location 200 is cleared, indicating that all data stored in flush-cache location 200 has been written to their correct locations on disk.
It may be the case, however, that during normal operations, the flush cache timer of step 445 expires before all the data stored in flush cache location 200 has been written to their correct locations on disk (i.e., flush cache location 200 is still dirty). In such an scenario, upon expiration of the flush cache timer, the disk drive gives priority to writing any remaining data in flush-cache location 200 that has not yet been written to its correct location on disk.
If it is determined in step 505 that the free pointer 110 has not passed the fill pointer location stored in memory, steps 540, 550, and 560 are carried out. In step 540, the disk drive writes the data entry of write-cache 100 pointed to by free pointer 110 to its correct location on disk. The dirty flag of the data entry is cleared in step 550 and the free pointer 110 is incremented in step 560. Steps 540, 550, and 560 are repeated until the free pointer 110 passes the fill pointer location stored in memory. In an alternative embodiment, the disk drive may write the dirty data entries of write cache 100 to their correct locations on disk out of sequential order (i.e., not incrementing free pointer 110, as in step 560) to increase efficiencies, for example, by leveraging the mechanical state of the drive (e.g., writing data for disk locations that are currently closest to the disk head, etc.).
The foregoing techniques provide assurances that data stored in flush-cache location 200 will be timely committed to their correct locations on disk within a predetermined amount of time (e.g., as indicated by the timer of step 445). This time period can be set in a number of different ways including: by the disk drive manufacturer, by the host computer or software running on the host computer, etc. In situations where a flush-cache command is not followed by a subsequent flush-cache command for a long period of time, the foregoing techniques prevent stale data stored in flush-cache location 200 from overwriting more current data stored on disk in the case when the disk drive loses power unexpectedly.
In the embodiments of the invention described above, the flush-cache timer is set after the flush-cache command has completed execution. In alternative embodiments, the flush-cache timer may be set at the beginning of flush-cache command execution or even during the flush-cache command execution.
It should also be recognized that alternative embodiments other than those depicted in the foregoing may be implemented without departing from the spirit of the invention. For example, rather than comparing the current free pointer 110 to a stored fill pointer 215 in step 520 to determine when all data in flush-cache location 200 has been written to their correct locations on disk, an alternative embodiment may track fill pointer 105 to determine when it cycles back to the same location in the circular buffer structure when dirty flag 210 in flush-cache location 200 had been set. Other alternatives may implement write-cache using data structures other than a circular buffer and the disk drive may have additional and/or alternative memory components, data structures and control logic to keep track of which data entries in write-cache 100 correspond to the data stored in flush-cache location 200. For example, in an alternative embodiment, each entry in write-cache 100 may also include an additional field indicating whether the entry is also currently stored in flush-cache location 200. Upon a scan of write-cache 100, the disk drive can then determine whether all data in flush-cache location 200 has been committed to their correct location in memory (e.g., by confirming that each entry whose flush-cache location field is set also has its dirty flag cleared). Similarly, the foregoing techniques may be utilized with multiple flush-cache locations such as described in Ehrlich-Zayas Publication.
Although one or more embodiments of the present invention have been described in some detail for clarity of understanding, it will be apparent that certain changes and modifications may be made within the scope of the claims. Accordingly, the described embodiments are to be considered as illustrative and not restrictive, and the scope of the claims is not to be limited to details given herein, but may be modified within the scope and equivalents of the claims. In the claims, elements and/or steps do not imply any particular order of operation, unless explicitly stated in the claims.