The described subject matter relates to nonvolatile memory, and more particularly to systems and methods of nonvolatile memory management.
Electronic devices are often provided with nonvolatile memory to retain data even after power is removed from the device. Exemplary nonvolatile memory includes, e.g., battery-backed or nonvolatile random access memory (NVRAM) and flash memory, and may be used to store program code and/or data such as, e.g., firmware, device configuration data, event logs, and application data (collectively referred to herein as “device data”). Accessing device data requires an understanding of the nonvolatile memory layout.
The layout of nonvolatile memory is typically defined in a common definition file, such as, e.g., a C or C++.h (“dot-h”) file. During development multiple software designers may need access to the common definition file, but the software designers must each wait until the common definition file is released by other software designers editing the common definition file before they can make changes to it. Serializing efforts of the software designers as such is inefficient and increases the cost of development.
In addition, changes to the nonvolatile memory layout may be required when the device data is updated (e.g., increasing, decreasing, and/or adding memory blocks). A special piece of program code known as a conversion module is typically provided to read existing content of the nonvolatile memory, update old device data, and then write the updated device data back to nonvolatile memory. In order to effect these changes the conversion module needs an understanding of the old and new layouts of the nonvolatile memory (e.g., memory block location and offset). Accordingly, the conversion module does not conform to object oriented design (OOD) principles for software development, which require objects to be self-contained. In addition, the conversion module may simply overwrite device data in nonvolatile memory if the conversion module does not recognize it.
In an exemplary embodiment, nonvolatile memory management may be implemented as a method, comprising: allocating via a memory manager at least one memory block in nonvolatile memory, initializing via the memory manager the at least one allocated memory block for storing device data, and generating a handle for the memory manager to provide to a client object for accessing the at least one initialized memory block.
In another exemplary embodiment, a system for nonvolatile memory management may be provided. The system may include a nonvolatile memory and a memory manager operatively associated with the nonvolatile memory. A plurality of management functions may be provided by the memory manager for accessing device data stored in the nonvolatile memory.
Another exemplary embodiment of nonvolatile memory management may be implemented as a program code product for executing a process comprising: executing an initialize function for initializing at least one memory block in nonvolatile memory, executing a write function for storing device data in the at least one initialized memory block, and generating a handle to the device data stored in the at least one memory block.
Briefly, systems and methods described herein may be implemented for nonvolatile memory management. In an exemplary embodiment, a memory manager is provided with management functions for dynamically managing nonvolatile memory. Client objects (e.g., operating system modules) access nonvolatile memory via the memory manager eliminating the need for a common definition file. Accordingly, software designers may develop object code in parallel with one another without having to each update a single common definition file.
In addition, the client objects may update device data in nonvolatile memory without depending on external conversion modules. Accordingly, the subject matter described herein complies with OOD principles for software design.
It is noted that although the subject matter described herein is illustrated with regard to nonvolatile memory, the memory management systems and methods may be extended to other forms of electronic memory, as will be readily understood by one having ordinary skill in the art after having become familiar with the teachings herein.
Exemplary System
Memory manager 120 may be implemented as one or more execution modules for accessing device data in the memory blocks 110. Memory manager 120 may also retrieve device data from nonvolatile memory 100 and pass the device data to a run-time call stack (e.g., for execution). In an exemplary embodiment memory manager 120 generates and maintains a memory block layout 130, e.g., a map for locating device data stored in nonvolatile memory 100.
Memory manager 120 may cooperate with client objects 140a-e (hereinafter generally referred to as clients 140) to provide access to device data stored in nonvolatile memory 100, e.g., to load firmware for operation of the device. As used herein, the terms “client object” and “client” refer to software or object code used to perform various computing services for the device. For example, clients 140 may include operating systems, device drivers, and applications. Clients 140 may also be responsible for evaluating the version of the device data and updating the device data as needed.
Memory manager 120 may broker memory management services for the clients 140 via a management application programming interface (API) 150. Management API 150 may be implemented to perform various operations on the memory blocks, such as, e.g., allocate/deallocate, open/close, and read/write/delete operations, as described in more detail below.
In an exemplary embodiment, memory block layout 200 may be implemented as a data structure including a number of data fields, as illustrated in Table 1.
The data structure may be populated, e.g., by the memory manager. In an exemplary embodiment the memory manager may “walk” the memory blocks of nonvolatile memory, gathering information on the memory blocks and using this information to generate a memory block layout. The memory manager may also update the memory block layout when changes are made to the nonvolatile memory.
In an exemplary embodiment, management API 300 may include the following management functions: Allocate, Reallocate, Delete, Open, Close, Read, and Write. It is noted, however, that management API 300 is not limited to any particular management functions 350. For example, management API 300 does not need to include each of the management functions 350 shown in
In an exemplary embodiment, client 440 may attempt to open a memory block 410 in nonvolatile memory 400 to access device data. Memory manager 420 may access memory block layout 430 to determine if a memory block 410 is allocated for client 440. If the memory block is not allocated for client 440 (e.g., the time client 440 executes), client 440 may initialize a new memory block 410c for the device data as follows.
Client 440 may initialize a new memory block as follows. Client 440 calls the nvmAlloc function, passing an ID string and block size for the new memory block to the memory manager 420. Memory manager 420 locates available memory block(s) (e.g., 410c) in nonvolatile memory 400 and returns a success or failure for the available memory block(s) 410c.
Client 440 may then open the memory block 410c by calling the nvmOpen function. Client 440 passes the ID string and a pointer to the handle to the memory manager 420. Memory manager 420 may then open the memory block 410c and return a handle for the open memory block 410c to the client 340.
Client 440 may then initialize the memory block 410 by calling the nvmWrite function. Client 440 passes the handle and a pointer 460 to a buffer 470 containing initialization data, an offset relative to the memory block opened by the client, and the buffer size to the memory manager 420. Memory manager 420 accesses the initialization data from the buffer 470 and writes it in open memory block 410c, as illustrated by new memory block 412c in the updated nonvolatile memory 402.
Client 440 may optionally close the memory block 412c after it is initialized by calling the nvmClose function. Client 440 passes the handle for open memory block 412c to the memory manager 420 which closes the open memory block 410.
Memory manager 420 may also update memory block layout 430 with a handle to memory block 412c. Memory manager 420 may then return a handle for device data in memory block 412c when client 440 requests access thereto.
In an exemplary embodiment, client 540 may access a memory block 510a-d (hereinafter generally referred to as memory blocks 510) to read device data in nonvolatile memory 500 as follows. Client 540 calls the nvmOpen function if the memory block 510 is not already open. Memory manager 520 locates the memory block 510 (e.g., using memory block layout 530) and returns a handle for the memory block 510. If the memory block 510 is already open this operation may be skipped.
When the memory block 510 is open, client 540 may call the nvmRead function. Client 540 passes the handle for the memory location 510, a pointer 560 to a buffer 570, an offset relative to the memory block opened by the client, and the buffer size. Memory manager 520 retrieves device data from the memory block 510 and writes it to the buffer 570 for access by the client 540. After reading the device data, client 540 may optionally close the memory block 510 by calling the nvmClose function.
In an exemplary embodiment, memory manager 520 may also include a compression module 580. Memory manager 520 may access compression module to compress device data before storing the compressed device data in nonvolatile memory 500. Memory manager 520 may also access compression module to decompress device data retrieved from nonvolatile memory 500 before returning the device data to the client 540.
In an exemplary embodiment, client 640 may change device data in nonvolatile memory 600 by calling the nvmRealloc function. Client 640 passes the ID string for the existing device data to the memory manager 620, along with a new block size.
If the new block size is larger for the updated device data, the nvmRealloc function may allocate a new memory block from a pool 610c of available memory blocks in nonvolatile memory 600 and copy the contents of the old memory block 610a into the new memory block 612b. The remainder of the new memory block 612b may be filled with zeros until client 640 calls the nvmWrite function to write the new device data to new memory block 612b. The nvmRealloc function may also include a function to release the old memory block.
If the new block size is smaller for the updated device data, nvmRealloc may allocate a new memory block from a pool 610c of available memory blocks in nonvolatile memory 600 and copy the contents of the old memory block 610b into the new memory block 612b up to the size of the new memory block 612b. Client 640 may then call the nvmWrite function to write the new device data to the new memory block 612b. The nvmRealloc function may also include a function to release the old memory block.
Defragmenting nonvolatile memory 700 may be initiated by the memory manager 720. Memory manager 720 may allocate a new memory block 712a and copy the contents of another memory block 710d into the new memory block 712a. Memory manager 720 may then delete the contents of the old memory block 710d and return the old memory block 710d to a flee pool 712c. This process may be repeated until the nonvolatile memory 700 is defragmented.
It is noted that the memory manager described herein may dynamically manage nonvolatile memory. Device data may be stored at any location(s) in nonvolatile memory and need not be stored in contiguous memory blocks because the clients do not need specific information concerning the physical location of device data in nonvolatile memory. Indeed, the physical location of device data may change (e.g., during a defragmenting operation), and clients are still able to access device data in nonvolatile memory via management functions provided by the memory manager.
It is noted that the exemplary embodiments discussed above are provided for purposes of illustration. Still other embodiments of the described subject matter are also contemplated.
Exemplary Operations
In operation 810, an ID string may be received from a client. For example, the ID string may identify device data residing in nonvolatile memory. A determination is made whether there is a corresponding handle for the ID string in operation 820. For example, an update may include new device data that needs to be written to nonvolatile memory on the first operation after installing the update. If there are no corresponding handles, nonvolatile memory may be initialized in operation 830 and the new device data may be written to nonvolatile memory in operation 832. A data structure may also be updated with a handle for the new device data in operation 834.
In operation 840, the handle is passed to the client. For example, the handle may include a memory block location in nonvolatile memory to access device data corresponding to the ID string. A determination is made whether the version is current in operation 850. For example, the client may make this determination based on version information included in the handle. The device data may be updated in operation 860 if the version is not current. For example, the client may update device data in nonvolatile memory using the management functions provided at the memory manager. In operation 870 nonvolatile memory may be accessed if the version is current. For example, the client may access device data residing in nonvolatile memory using the handle and management functions provided at the memory manager.
The operations shown and described herein are provided to illustrate exemplary embodiments of nonvolatile memory management. It is noted that the operations are not limited to those shown and described with reference to