1. Field of the Invention
The present invention relates generally to computer systems and more specifically to a method and apparatus for storing non-volatile configuration information in a flash memory and accessing this information in a manner which does not negatively impact system performance.
2. Description of Related Art
Traditionally, hardware configuration in computer systems was handled using special protocols which were implemented in the hardware itself. Hardware components were manually configured, and it was likely that a particular system would need to be reconfigured only infrequently. Components for modem computer systems, however, are increasingly designed in a modular fashion which allows the hardware configurations of individual computer systems to be very flexible. Demand for custom configurations has grown along with the flexibility of computer hardware.
As a result of the flexibility of computer hardware, the configuration of computer systems is becoming an increasingly complex task. This has in turn resulted in a need for special configuration parameters that can be manipulated to control the setup and functionality of both the computer hardware and the software that utilizes the hardware. These configuration parameters are used both by the operating system in automatically configuring the system and by the user in manually configuring the system.
While the configuration parameters allow system configurations to be easily changed, it is desirable to maintain the current values of the parameters, even when the system is powered down. By maintaining the values of the configuration parameters, the need to entirely reconfigure the system every time it is powered down or rebooted is eliminated. Because the configuration parameters need to be maintained through power cycles, they are referred collectively as non-volatile configuration information, or simply NVCI.
Many of the configuration parameters are critical to the basic boot process of a computer system. The NVCI must therefore be stored in a manner which is persistent and reliable. It is also desirable to make the NVCI available with the greatest possible performance. Typically, NVCI has been stored in a battery-powered SRAM. Battery-powered SRAM, however, is relatively expensive and data stored in the SRAM may be lost as a result of battery failure. It would therefore be desirable to use a more reliable system for storing NVCI.
Another problem with traditional implementations of NVCI storage systems is that they typically use either a fixed data format or a table of contents that contains pointers to data objects that comprise the NVCI. Neither of these solutions is able to handle dynamic data types very well. Because the fixed format storage cannot be modified, it simply cannot support dynamic data types. The sizes of data objects are also limited by the original space allocations for the data objects. Although systems that use a table of contents and pointers are more flexible than the fixed-data systems, if dynamic data types are to be supported, they require the use of complicated algorithms to determine space allocations for the data objects.
One or more of the problems outlined above may be solved by the various embodiments of the present invention. Broadly speaking, the invention comprises storing the NVCI in a flash memory and retrieving a copy of the NVCI into a working memory so that it can be quickly accessed.
In one embodiment, a computer system includes a processor, a working memory (RAM) and a flash memory. NVCI is stored in the flash memory. When the computer system is booted up, the NVCI is read from the flash memory into the working memory. When the computer system needs to read particular values from the NVCI, the copy of the NVCI in the working memory is read. When the computer system needs to write new values to the NVCI, the system writes to both the copy of the NVCI in the working memory and the copy of the NVCI in the flash memory.
In one embodiment, the system is configured to store the NVCI in the flash memory in a format which both maximizes the lifetime of the flash memory and enables the system to handle dynamic data types efficiently. The NVCI comprises a plurality of key-value pairs. The key-value pairs are stored serially in the flash memory. In other words, a key is followed by its corresponding value, which is followed by another key, and so on. The key-value pairs may also contain data indicating the size of the key and corresponding value, as well as a checksum which is used to detect errors in the key-value pairs. When the value corresponding to a key is updated, the key and the new value are written to the next available space in the flash memory. The next time the flash memory is read into the working memory, the key-value pairs are read serially from the flash memory. When a second or subsequent occurrence of a key is read, the value previously read into the working memory for that key is overwritten with the subsequent value. The working memory therefore contains only one copy of each key and its corresponding value, even though there may be several different values corresponding to the key in the flash memory.
In one embodiment, the flash memory comprises a segmented flash memory. Each of the segments of the flash memory can be erased independently of the other segments. The NVCI is stored in one of the segments. When additional key-value pairs are written to the segment and it reaches a predetermined capacity, a new segment is selected and the current NVCI (i.e., each key and its most recent value) are written to the new segment. If each of the segments has previously been used (without being erased), a least-recently used segment is selected and is erased before the current NVCI is written to it.
One embodiment comprises a method implemented in a computer system for storing NVCI which uses less expensive memory, yet provides higher performance than conventional methods. In this embodiment, NVCI is stored in one or more active segments of a segmented flash memory. The NVCI consists of a series of key-value pairs which are stored in contiguous locations in the flash memory, beginning with the lowest address. When the computer system is started, the key-value pairs are read from the flash memory, beginning with the least recently stored and ending with the most recently stored (in most instances, the key-value pairs are read beginning with the lowest memory address and ending with the highest.) The key-value pairs are inserted into a hash table in working memory. Later-read key-value pairs replace earlier-read key-value pairs which have the same key in the hash table. Read accesses to the NVCI are made to the hash table. Write accesses to the NVCI are made to both the hash table and the flash memory. Write accesses to the hash table replace the values which are already stored in the table. Write accesses to the flash memory are stored in xe2x80x9cloggingxe2x80x9d fashion (i.e., they are stored in the next available memory location.) When an active segment of the flash memory is filled to a threshold capacity, the key-value pairs stored in the hash table are written to a new segment, which then becomes the active segment.
The present invention includes many other embodiments which will be apparent from this disclosure.