Based on little memory system with the method for NOT-AND flash media implementation virtual memory
Technical field
The present invention relates to a kind of implementation method of virtual memory, relate in particular to a kind of based on little memory system with the NOT-AND flash medium on realize the method for virtual memory.
Background technology
In recent years, along with the development of computer operating system, the function that operating system has is more and more abundanter, and most of operating systems have the virtual memory technology.The virtual memory technology is an important techniques on the computing machine development history, and it helps application program to break away from the restriction of " volume ".The management method of virtual memory makes system both can move the volume ratio physical memory and also wants big application program, also can realize " paging as required " strategy, has both satisfied the travelling speed of program, has practiced thrift the physical memory space again.
The basic thought of virtual memory is: the size of program, data, storehouse can surpass the size of internal memory; Operating system is retained in internal memory to the part of the current use of program; And other part for storage on disk, and dynamic exchange between internal memory and disk when needed.When process was moved, earlier with a part of program graftabl, another part was temporarily stayed external memory, when the data of the instruction that will carry out or use during not at internal memory, is accomplished automatically by system they are called in the work of internal memory from external memory.Before process brings into operation, not whole pages of packing into, but pack into one or the zero page, the needs that move according to process afterwards, other page of dynamically packing into; When memory headroom is full, and during the page that need pack into new, then eliminate certain page, so that pack the new page into according to certain algorithm.When memory headroom was nervous, system temporarily moved on to external memory with some process in the internal memory, some process swap-in internal memory in the external memory, occupies the former shared zone, and this technology is the dynamic dispatching of process between internal memory and external memory.
Existing in the prior art have two with the most akin implementation of the present invention:
PC operating system aspect: Windows last with LINUX/UNIX on the virtual memory technology realize with hard disk, but be based on file system, need the certain physical internal memory to come the data that reside permanently of store files system.
The virtual memory technology of embedded OS aspect: LINUX and WINDOWS CE to be realizing with NOT-AND flash, but also is based on file system, and this will have sizable file system data to want memory-resident.
No matter be PC operating system or embedded OS, existing virtual memory technology all realizes on file system, because the data volume that resides in the internal memory is bigger, for little memory system, is worthless.Traditional virtual memory realizes that on file system so this mode resides in the data in EMS memory amount will be very big, and for the very little system of physical memory, it is worthless that yes.
Concerning electron trade, the competition more and more fierce, in order in the competition of industry, to be in the invincible position, quality and price are two aspects of particular importance.For in price, cost control is the basis.The little memory system virtual memory technology under the embedded environment that is based on of native system design.
Summary of the invention
To the objective of the invention is the data volume that resides in the internal memory in order reducing, to improve the speed and the efficient of system, on file system, do not realize virtual memory, directly with NOT-AND flash on realize virtual memory.
The object of the invention can be realized through following scheme: based on little memory system with the method for NOT-AND flash media implementation virtual memory, it is characterized in that, earlier with NOT-AND flash in a virtual storage space as virtual memory; When physical memory does not have the new page of space storage, the page in the physical memory is write on the virtual memory; Then the original page of physical memory was lost efficacy; At last the page that needs computing in the virtual memory is write in the physical memory, realize the page exchange of physical memory and virtual memory.
It is not screen to visit expiration policy at most that described page lost efficacy.
The process by the page or leaf mapping is adopted in the page exchange of described virtual memory and physical memory, promptly wipes a data block and can write a plurality of pages or leaves.
The page of described physical memory writes in the virtual memory process, and three method for optimizing are arranged:
1) if the attribute of physical memory page is read-only, then in virtual memory, deposited this page, the content in this physical memory page need not be written back in the virtual memory, and directly this section physical memory content is removed; Otherwise this physical memory page is write virtual memory.
2) dirty sign minimizing data write-back is write in utilization: if the content of depositing in the physical memory page is a data segment, whether the content that distinguish data segment was modified; Content was not modified, and write dirty sign and was changed to vacation, need not be written back in the virtual memory, directly the content in this section physical memory was removed; If the content of data segment was modified, write dirty being designated very, just the content with this data segment is written back in the virtual memory, then the content in this section physical memory is removed.
3) for idle internal memory, because this internal memory is unavailable, directly from physical memory, remove, also do one section corresponding in virtual memory internal memory abandoning mark simultaneously.
Described physical memory is written back in the process of virtual memory, comprises following content:
The content that a definition mapping table between physical memory and virtual memory, described mapping table write down said physical memory with NOT-AND flash on deposit position.
Page is written back to virtual memory and adopts by data block round-robin process: when the page content of physical memory changes; In order to improve system effectiveness; Not to wipe the corresponding page of this content on the virtual memory, but the page content of physical memory is write on the next empty page of current data block in the virtual memory.
The page of described physical memory writes in the virtual memory process; In order to solve bad piece problem; Improve system reliability; Stand-by block with NOT-AND flash medium reservation some: it is constant to guarantee that the intact back of write-back remains the data block of M (M>=2) individual free time in virtual memory, otherwise the not enough situation of freed data blocks can occur.
The advantage of the relative prior art of the present invention is: adopted by the page or leaf mapping with by the raising of data block round-robin method and write the wiping ratio, reduced the number of times of read/write memory, prolonged the life-span of electron device; The method of utilizing enough stand-by blocks is to improve system reliability, and guaranteeing to write has enough spaces when wiping, reduce the loss of data phenomenon; Utilize the method for dirty sign and internal memory drop mechanism to reduce the data write-back, improved the efficient and the life-span that has prolonged disk of memory buffer.
Description of drawings
Fig. 1 is an internal storage structure synoptic diagram of the present invention;
Fig. 2 is that page of the present invention writes the virtual memory schematic flow sheet from physical memory;
Fig. 3 is that page of the present invention writes the physical memory schematic flow sheet from virtual memory.
Embodiment
As shown in Figure 1; In order to practice thrift cost; Enhance competitiveness; The physical memory that system adopts has only 192K, utilizes memory management unit MMU (Memory Management Unit) to be the virtual memory of 2M the 192K physical memory is virtual, and virtual memory is the 2M space from branching away with the NOT-AND flash medium.Physical memory and virtual memory are a page with 4K all; The physical memory of 192K is divided into 192K/4K=48 page; The method by the page or leaf mapping is adopted in mapping between virtual memory and the physical memory, wipes data block exactly one time, can write a lot of pages or leaves; Native system is to wipe a data block, can write 64 pages or leaves.The purpose that adopts the page or leaf mapping is to improve to write to wipe ratio.In system's operational process physical memory and and NOT-AND flash between carry out exchanges data.
Wherein, physical memory has comprised the bottom of three part: 16k, the middle part of 160k and the top of 16k.Wherein the bottom of 16k is fixedly to be mapped to virtual memory, and structure has comprised data slice, status architecture, driving code and interruption code.The middle part of 160k is not fixedly to be mapped to virtual memory, whether shines upon to depend on whether page is modified, and can be mapped to virtual memory when page is modified; Structure has comprised user stack, the piece with sign-on, code segment and the read-only data section of 8k.The top of 16k is fixedly to be mapped to virtual memory, and structure has comprised the unusual storehouse of 1k, the interrupt stack of 1k, the dynamic data area of 3k, the high frequency code of 8k, the secondary MMU mapping table of 2k and the one-level MMU mapping table of 1k.
Physical memory and and NOT-AND flash between carry out exchanges data two kinds of operations arranged: the page changes to the page and swaps out.Change to exactly and will be loaded into physical memory with corresponding page on the NOT-AND flash.Swap out exactly with page in the physical memory be written back to NOT-AND flash on.
The page writes the virtual memory process from physical memory:
When physical memory does not have the new page of space storage, just need some page be shifted out from physical memory, with page in the physical memory be written back to NOT-AND flash on, make the content inefficacy of this page then.The method that adopts is to utilize not visit expiration policy at most and carry out page fault.For serviceable life of improving system effectiveness and speed and raising and NOT-AND flash (reduce with NOT-AND flash erasable) as far as possible, with page in the physical memory be written back to NOT-AND flash on three kinds of optimization methods are arranged:
1) divides according to the attribute of the content of depositing in the physical memory page; If the attribute of content is read-only, then with in the NOT-AND flash existing deposit the content in this physical memory page; Need not be written back to NOT-AND flash in, directly the content in this section physical memory is removed.
2) utilize and to write dirty sign and reduce the data write-back, write dirty sign and be really just need be written back to NOT-AND flash on.If the content of depositing in the physical memory page is a data segment, whether the content that distinguish data segment was modified.Content was not modified, and write dirty sign and was changed to vacation, need not be written back to NOT-AND flash in, directly the content in this section physical memory is removed; If the content of data segment section was modified, write dirty be designated true, just with the content of this data segment be written back to NOT-AND flash in, then the content in this section physical memory is removed.
3) adopt the internal memory drop mechanism: for the internal memory that has discharged,, directly from physical memory, remove because this internal memory is unavailable, simultaneously also will with NOT-AND flash on one section corresponding internal memory do to abandon mark.
Carry out page fault will the content of physical memory data segment be written back to NOT-AND flash on, be written back to the method for NOT-AND flash following:
1) physical memory and and NOT-AND flash between mapping table of definition, when being written back to, can be while writing revise mapping table with NOT-AND flash, the content that mapping table can be noted down physical memory with NOT-AND flash on deposit position;
2) write-back to and NOT-AND flash, employing be to follow bad method by data block.If physical memory page content changes, in order to improve system effectiveness, be not wipe with NOT-AND flash on the corresponding page of this content, but with the page content of physical memory write with NOT-AND flash on the next empty page of current data block;
3) in order to solve bad piece problem, improve system reliability, keep the stand-by block of some.Guarantee the intact back of write-back with the NOT-AND flash medium in to remain the data block of M (M>=2) individual free time constant, otherwise the not enough situation of freed data blocks can appear;
block?n-1 block?n block?n+M-1 block?n+M
write?over stuffed?with?data |
empty?block to?be?written |
empty?block |
?least?access?block |
Present state is:
Piece n-1: write full data;
Piece n is to piece n+M-1: be M idle data block;
Piece n+M is not empty, might have effective data page, needs to reclaim.
It is as shown in Figure 2 that the page writes the virtual memory flow process:
A) whether inspection piece n-1 writes full;
B) whether be empty if the result that step a returns, then gets next legal piece n for being and detects piece n+M; If the result that step a returns then jumps to step g for not;
C) if the result that step b returns for not, then moves on to piece n with legal page or leaf from piece n+M; And whether inspection moves successfully;
D) if the result that step c returns is for being then to jump to step f; If the result that step c returns then gets next legal piece n for not, and make M from subtracting 1;
E) replace this piece and be labeled as badly, return step c;
F) if the result that step b returns, then wipes piece n+M for being and whether inspection is successfully wiped;
G) if the result that step f returns is that then this piece of mark is not bad piece and returns step c; If the result that step f returns is for being, then page data is write current piece and whether inspection writes success;
H) if the result that step g is returned is for being then to upgrade mapping table; If the result that steps d is returned then gets next legal piece n for not, and make M from subtracting 1;
I) replace this piece and be labeled as badly, return step g.
" M is from subtracting 1 " that occur because occur writing failure in the above-mentioned steps can cause the number M of free block to reduce; Just the piece of subsequent use free time is not enough; Run into this situation, the recovery that after flow process is write in completion, need carry out the piece of a subsequent use free time again could guarantee that idle number of blocks remains unchanged.
The page writes the physical memory process from virtual memory:
Will be as shown in Figure 3 with the flow process that corresponding page on the NOT-AND flash is loaded into physical memory, at first the mapping table on the memory body of inquiry and NOT-AND flash takes out the id corresponding with the NOT-AND flash page or leaf; Read page from memory body then with NOT-AND flash; The mapping table of final updating MMU.
The invention solves on little memory system, directly with NOT-AND flash on realize the method for virtual memory and raising system performance and efficient be provided, improve and the NOT-AND flash method and the method that processing and the bad piece problem of NOT-AND flash are provided in serviceable life.