Abstract:
A method and system of managing virtual memory for a flash-memory system. Logical blocks in a buffer are used to store data copied from a physical block in a flash-memory. An operating system searches data in the buffer first. If the data is in the buffer, it is accessed. If not, the operating system searches for the data in the flash memory, meanwhile writing a logical block having a dirty flag back to a logical block.

Description:
BACKGROUND OF THE INVENTION 
   1. Field of the Invention 
   The present invention relates to a method and system for managing virtual memory, and particularly for flash memory. 
   2. Description of the Related Art 
   Non-volatile semiconductor memory, such as flash memory, is useful for relatively long-term storage in computer systems, more particularly, for pocket PC. Spare regions of flash memories have an advantage of storing various extensions of software, for example, CPQ OPTION JACKET, important documents or data, and others. 
   It is not easy to access flash memory. Flash memories, like a hard disk, are divided into pages and blocks. Rather than writing to just one word in a page, the entire page must be written to at the same time, and individual bytes cannot be written. The page must be cleared of any previous data before being written, clearing is accomplished by a flash erase cycle. An entire block pages is erased at once. For example, if a block has 16 pages, the entire block of 16 pages must be erased at once, while all 512 bytes on a page must also be written together. 
   To make flash memory easy for users to store code and data, there is a need for a virtual memory management system and method to realize a flash-file system. 
   SUMMARY OF THE INVENTION 
   It is therefore an object of the present invention to take advantage of spare regions in flash memory to implement a flash file system. 
   To achieve the above objects, the present invention discloses a method and system of managing virtual memory for a flash-memory system. Logical blocks in a buffer are used to store data copied from physical blocks in a flash-memory. 
   An input-output apparatus requests an operating system to access first data. The operating system searches data of logical blocks in the buffer. If the data address matches, the logical block storing the first data is in the buffer and is then accessed. If the data address does not match, the logical block storing the first data is not in the buffer and execution proceeds to search data of physical blocks in flash memory. 
   Before searching data of physical blocks, the operating system checks if a dirty flag of the logical block has been enabled. If so, the operating system writes the logical block back to the physical block in the flash memory. If not, a write-back process is saved when the operating system gets rid of the logical block in the buffer. 
   The operating system searches data of physical blocks in the flash memory. If the data address matches, the physical block storing the first data is in the flash memory and then copied to a logical block. If the data address does not match, the physical block storing the first data is not in the flash memory. Execution goes back to the start to access data. 

   
     BRIEF DESCRIPTION OF THE DRAWINGS 
     The aforementioned objects, features and advantages of this invention will become apparent by referring to the following detailed description of the preferred embodiment with reference to the accompanying drawings, wherein: 
       FIG. 1  is a block diagram of a system for managing virtual memory. 
       FIG. 2A  shows virtual memory and flash memory. 
       FIG. 2B  shows contents of a logical block. 
       FIG. 3  is a flowchart for managing input data of the virtual memory. 
       FIG. 4  is a flowchart for managing output data of the virtual memory. 
   

   DETAILED DESCRIPTION OF THE INVENTION 
     FIG. 1  is a block diagram of a system for managing virtual memory. The system includes an input device  10 , an output device  20 , an OS (operating system) file system  30 , a buffer  40 , and a flash memory  50 . 
     FIG. 2A  shows virtual memory and flash memory. The buffer  40  includes logical blocks m 1 -mA. The flash memory includes physical block n 1 -nB. Logical blocks m 1 -ma and physical blocks n 1 -nB are all accessed by addresses.  FIG. 2B  shows contents of a logical block. A logical block includes data and address copied from a physical block and a dirty flag for indicating write-back. Logical blocks are updated according to a range in which their addresses are located. 
   The dirty flag tells the operating system  30  if the logical block has been modified. If it has been, then the logical block is discarded and must be written back to the flash memory  50 . If it has not been, a write-back process is saved when the operating system  30  gets rid of the logical block in the buffer  40 . 
     FIG. 3  is a flowchart for managing input data of the virtual memory. 
   At step S 301 , input data process starts. 
   At step S 302 , data Dx 1  is input from the input device  10 . 
   At step S 303 , the input device  10  requests the operating system  30  to write the data Dx 1 . 
   At step S 304 , the operating system  30  searches data Dx 1  in logical blocks in the buffer  40 . 
   At step S 305 , if the data address matches that of data Dx 1 , a logical block mx 1  storing the data Dx 1  is in the buffer  40  and execution proceeds to step S 306 . If the data address does not match that of data Dx 1 , there is no logical block storing the data Dx 1  in the buffer  40  and execution proceeds to step S 307 . 
   At step S 306 , the logical block mx 1  storing the data Dx 1  in the buffer  40  is updated. The dirty flag of the logical block mx 1  is enabled. 
   At step S 307 , if there is a logical block mk 1  in which the dirty flag is enabled, execution proceeds to step S 308 . If there is no logical block in which the dirty flag is disabled, execution proceeds to step S 309 . 
   At step S 308 , the data of the physical block nkl in the flash memory  50  is updated by the data of the logical block mk 1 , in which the dirty flag is enabled, in the buffer  40 . 
   At step S 309 , the operating system  30  searches the physical block which stores the data Dx 1  in the flash memory  50 . 
   At step S 310 , if the data address matches, a physical block nx 1  storing the data Dx 1  is in the flash memory  50  and execution proceeds to step S 311 . If the data address does not match, there is no physical block storing the data Dx 1  in the flash memory  50  and execution goes back to step S 301 . 
   At step S 311 , the operating system  30  copies the physical block nx 1  in the flash memory  50  to a logical block mz 1  in the buffer  40  and execution proceeds to step S 306 . The logical block mz 1  is updated by the data Dx 1 . 
     FIG. 4  is a flowchart for managing output data of the virtual memory. 
   At step S 401 , the output data process starts. 
   At step S 402 , data Dx 2  is required from the output device  20 . 
   At step S 403 , the output device  20  requests the operating system  30  to return the data Dx 2 . 
   At step S 404 , the operating system  30  searches data Dx 2  in the logical blocks in the buffer  40 . 
   At step S 405 , if the data address matches that of data Dx 2 , a logical block mx 2  storing the data Dx 2  is in the buffer  40  and execution proceeds to step S 406 . If the data address does not match that of data Dx 2 , there is no logical block storing the data Dx 2  in the buffer  40  and execution proceeds to step S 407 . 
   At step S 406 , the data Dx 2  stored in the logical block mx 2  in the buffer  40  is returned. 
   At step S 407 , if there is a logical block mk 2  in which the dirty flag is enabled, execution proceeds to step S 408 . If there is no logical block in which the dirty flag is disabled, execution proceeds to step S 409 . 
   At step S 408 , the data of the physical block nk 2  in the flash memory  50  is updated by the data of the logical block mk 2 , in which the dirty flag is enabled, in the buffer  40 . 
   At step S 409 , the operating system  30  searches the physical block which stores the data Dx 2  in the flash memory  50 . 
   At step S 410 , if the data address matches, a physical block nx 2  storing the data Dx 2  is in the flash memory  50  and execution proceeds to step S 411 . If the data address does not match, there is no physical block storing the data Dx 2  in the flash memory  50  and execution goes back to step S 401 . 
   At step S 411 , the operating system  30  copies the physical block nx 2  in the flash memory  50  to a logical block mz 2  in the buffer  40  and execution proceeds to step S 406 . The logical block mz 2  is updated by the data Dx 2 . 
   Although the present invention has been described in its preferred embodiments, it is not intended to limit the invention to the precise embodiments disclosed herein. Those who are skilled in this technology can still make various alterations and modifications without departing from the scope and spirit of this invention. Therefore, the scope of the present invention shall be defined and protected by the following claims and their equivalents.