CN103106147A - Memory allocation method and system - Google Patents

Memory allocation method and system Download PDF

Info

Publication number
CN103106147A
CN103106147A CN2013100741803A CN201310074180A CN103106147A CN 103106147 A CN103106147 A CN 103106147A CN 2013100741803 A CN2013100741803 A CN 2013100741803A CN 201310074180 A CN201310074180 A CN 201310074180A CN 103106147 A CN103106147 A CN 103106147A
Authority
CN
China
Prior art keywords
memory block
free
memory
group
block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2013100741803A
Other languages
Chinese (zh)
Other versions
CN103106147B (en
Inventor
李顺芬
陈小刚
周密
宋志棠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Institute of Microsystem and Information Technology of CAS
Original Assignee
Shanghai Institute of Microsystem and Information Technology of CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Institute of Microsystem and Information Technology of CAS filed Critical Shanghai Institute of Microsystem and Information Technology of CAS
Priority to CN201310074180.3A priority Critical patent/CN103106147B/en
Publication of CN103106147A publication Critical patent/CN103106147A/en
Application granted granted Critical
Publication of CN103106147B publication Critical patent/CN103106147B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Memory System (AREA)

Abstract

The invention provides a memory allocation method and a memory allocation system. The method comprises the steps as follows: dividing memory blocks each with one free page, memory blocks each with two free pages and memory blocks each with not less than 2i-1+1 and not more than 2i free pages into free memory block groups, wherein i is an integer which not less than 2; and building corresponding free block index records based on the related information of the free blocks in the free memory block groups for the convenience of query. Therefore, the free memory blocks each with power-of-non-2 pages can be provided to meet the requirement, so that the memory utilization efficiency is greatly improved.

Description

Memory allocation method and system
Technical field
The present invention relates to the memory management field, particularly relate to a kind of memory allocation method and system.
Background technology
Internal memory is the critical piece of save command code and various data in computer system, if memory starvation or miscarriage will cause the whole system delay of response, and even collapse.So setting up stable, efficient memory management scheme is very important and must a face problem.
In the buddy algorithm of existing (SuSE) Linux OS, first all free page are divided into 10 piece groups, in every group, each memory block comprises power side's free page of 2, and for example, each memory block all comprises 2 separately in the 0th group 0=1 free page, each memory block all comprises 2 separately in the 1st group 1=2 free page ... in the 9th group, each memory block all comprises 2 separately 9=512 free page, and the memory block of each memory block group forms a chained list.As seen, in this kind algorithm, the free page quantity that in each memory block group, each memory block comprises is identical.
Below the course of work of the buddy algorithm of this (SuSE) Linux OS will be described by a simple example:
If show the memory block that operating system needs one comprise 128 free page, this buddy algorithm system first searches in the chained list of the memory block group that comprises 128 free page, to determine whether to comprise the memory block of 128 free page, if having, just directly provide this operating system to use; If do not have, this buddy algorithm system can search in the chained list of the memory block group that the memory block that comprises 256 free page consists of, if in this memory block group, available free memory block is arranged, this buddy algorithm system can be divided into two equal portions to 256 free page of this free memory block, portion offers operating system and uses, and another part is inserted in the memory block group of the memory block formation that comprises 128 free page.if do not find available free page piece in the chained list of the memory block group that comprises 256 free page yet, just continue in larger piece group, namely search in the chained list of the memory block group that the memory block that comprises 256 free page consists of, if in this memory block group, available free memory block is arranged, this buddy algorithm system can tell 128 pages to 512 free page of this free memory block and offer operating system and use, then taking out 256 pages from remaining 384 pages is inserted in the chained list that block size is 256 pages, then remaining 128 pages are inserted in the chained list that block size is 128 pages, if also there is no available free memory block in the chained list of 512 pages, this buddy algorithm system just abandons inquiry, and sends error signal.
The release of internal memory is the inverse process that distributes, and also can be regarded as partner's merging process.When discharging an occupied memory block, first whether examination has partner's memory block to exist in its corresponding chained list, if there is no partner's memory block, just directly this memory block that will discharge is hung into linked list head; If have, take partner's memory block from chained list, and be merged into formation merge memory piece, whether the merge memory piece that then continues after examination merges also has the existence of partner's memory block in the chained list of affiliated memory block group, comprise 2 until be incorporated into 9Till=512 pages.Wherein, two memory blocks that meet the following conditions are partner's memory block each other:
(1) two each self-contained page quantity of memory block is identical;
The physical address of (2) two memory blocks is continuous.
The advantage of above-mentioned buddy algorithm is to distribute and recovery speed is fast, algorithm is simple, when a size is 2 nAfter the memory block of byte discharged, storage management system only need to search for 2 nThe memory block of byte-sized needs to merge to determine whether.
Although buddy algorithm is famous classic algorithm, be not flawless yet; At first, from the buddy algorithm principle as can be known, all memory request all must be take power side's size of 2 as unit, if when one of needs comprised the memory block of 129 pages, system must provide the free memory block that comprises 256 pages to use, because reality is only used 129 pages, remaining 127 pages obviously have been wasted, namely nearly 50% memory source is wasted, and as seen, this kind algorithm easily causes memory usage lower.
In addition, the efficient of buddy algorithm also easily goes wrong: relate to the operation of many calculating and chained list and bitmap due to buddy algorithm, cause expense larger; For example, if each 2 nPartner's piece of size merges to 2 n+1The chained list formation in, so 2 nMemory block in the chained list of size will reduce because of union operation, thus, and when system needs 2 nThe size memory block the time, just need to be with 2 n+1The memory block of size splits again, and as seen, it is inefficient so merging the process that splits again.
Thereby, how to propose a kind of new memory allocation method, the advantage that can well inherit buddy algorithm can overcome the deficiency of buddy algorithm again, realizes fast allocation, reclaims internal memory, improve simultaneously the internal memory service efficiency, real is practitioner in the art's problem demanding prompt solution.
Summary of the invention
The shortcoming of prior art in view of the above the object of the present invention is to provide a kind of internal memory service efficiency high memory allocation method and system.
Reach for achieving the above object other relevant purposes, the invention provides a kind of memory allocation method, it comprises at least:
Each memory block that-each memory block that will comprise 1 free page is classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2; And set up corresponding free block index record based on the relevant information of each free block in the free memory block group, so that inquiry.
Preferably, described memory allocation method also comprises step:
-determine free memory block group to be checked based on memory requirements;
-begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided, and revise the index record of available free memory block.
preferably, when the memory capacity of this available free memory block surpasses described memory requirements, this available free memory block is split as first partner's memory block and the second partner's memory block that satisfies described memory requirements, the free page quantity that comprises based on second partner's memory block is again determined the free memory block group under this second partner memory block, and set up the corresponding record of allocation index of this memory block based on the relevant information of described first partner's memory block, set up new free memory block index record based on the relevant information of second partner's memory block, and delete the corresponding free block index record of this available free memory block.
Preferably, when the memory capacity of this available free memory block equals described memory requirements, provide this available free memory block satisfying described memory requirements, and the free block index record that the available free memory block is corresponding deletion, and add the corresponding record of allocation index of this memory block.
Preferably, when this available free memory block only comprises a free page, when if its memory capacity surpasses described memory requirements, directly provide this available free memory block to satisfy described memory requirements, and the free block index record that this available free memory block is corresponding deletion, and add the corresponding record of allocation index of this memory block.Preferably, described memory allocation method also comprises step:
-determine whether to exist partner's memory block based on the index record of memory block to be recycled;
There is partner's memory block in-Ruo, determine whether this partner's memory block is occupied, if, the page quantity that comprises based on this memory block to be recycled is determined the free memory block group under it, and increase the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and delete the corresponding record of allocation index of this memory block to be recycled; If not, should memory block to be recycled and partner's memory block merge, and determine free memory block group under it based on the page quantity that the memory block after this merging comprises, and increase the corresponding free block index record of memory block after merging in corresponding free memory block group, and delete the record of allocation index and the corresponding free block index record of this partner's memory block of memory block to be recycled.
The present invention also provides a kind of Memory Allocation system, and it comprises at least:
Each memory block that grouping module, each memory block that is used for comprising 1 free page be classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2; And set up corresponding free block index record based on the relevant information of each free block in the free memory block group, so that inquiry.
Preferably, described Memory Allocation system also comprises:
Determination module is used for determining free memory block group to be checked based on memory requirements;
Module is provided, is used for being begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided.
preferably, when the memory capacity of this available free memory block surpasses described memory requirements, provide module this available free memory block to be split as first partner's memory block and the second partner's memory block that satisfies described memory requirements, the free page quantity that grouping module comprises based on second partner's memory block is again determined the free memory block group under this second partner memory block, and set up the corresponding record of allocation index of this memory block based on the relevant information of described first partner's memory block, set up new free memory block index record based on the relevant information of second partner's memory block, and delete the corresponding free block index record of this available free memory block.
Preferably, when the memory capacity of this available free memory block equals described memory requirements, provide module to provide this available free memory block to satisfy described memory requirements, the free block index record deletion that grouping module is corresponding with this available free memory block, and add the corresponding record of allocation index of this memory block.
Preferably, when this available free memory block only comprises a free page, when if its memory capacity surpasses described memory requirements, provide module directly to provide this available free memory block to satisfy described memory requirements, the free block index record deletion that grouping module is corresponding with this available free memory block, and add the corresponding record of allocation index of this memory block.
Preferably, described Memory Allocation system also comprises:
Recycling module is used for determining whether to exist partner's memory block based on the index record of memory block to be recycled;
If there is partner's memory block, recycling module determines whether this partner's memory block distributes, if, the page quantity that comprises based on this memory block to be recycled of grouping module is determined the free memory block group under it, increase the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and delete the corresponding record of allocation index of this memory block to be recycled; If not, recycling module should memory block to be recycled and partner's memory block merge, the page quantity that the memory block of grouping module after based on this merging comprises is determined the free memory block group under it, and the corresponding free block index record of memory block increase merging in corresponding free memory block group after, and delete the memory block to be recycled corresponding record of allocation index and the corresponding free block index record of this partner's memory block.
As mentioned above, memory allocation method of the present invention and system have following beneficial effect: can realize fast allocation, the recovery of internal memory, improve simultaneously the internal memory service efficiency.
Description of drawings
Fig. 1 is shown as the memory block grouping process flow diagram of memory allocation method of the present invention.
What Fig. 2 was shown as memory allocation method of the present invention provides memory block to satisfy the process flow diagram of memory requirements.
Fig. 3 is shown as the process flow diagram of the recovery memory block of memory allocation method of the present invention.
Fig. 4 is shown as a kind of preferred schematic diagram of Memory Allocation of the present invention system.
Fig. 5 is shown as another preferred schematic diagram of Memory Allocation of the present invention system.
Fig. 6 is shown as another preferred schematic diagram of Memory Allocation of the present invention system.
The element numbers explanation
1 Memory Allocation system
11 grouping module
12 determination modules
13 provide module
14 recycling modules
S11, S21, S22, S31, S32 step
Embodiment
Below by specific instantiation explanation embodiments of the present invention, those skilled in the art can understand other advantages of the present invention and effect easily by the disclosed content of this instructions.The present invention can also be implemented or be used by other different embodiment, and the every details in this instructions also can be based on different viewpoints and application, carries out various modifications or change under spirit of the present invention not deviating from.
See also Fig. 1 to Fig. 6.Need to prove, the diagram that provides in the present embodiment only illustrates basic conception of the present invention in a schematic way, satisfy only show in graphic with the present invention in relevant assembly but not component count, shape and size drafting when implementing according to reality, during its actual enforcement, kenel, quantity and the ratio of each assembly can be a kind of random change, and its assembly layout kenel also may be more complicated.
As shown in the figure, the invention provides a kind of memory allocation method.Wherein, the method according to this invention is mainly completed by the Memory Allocation system in computer equipment, such as application module, operating system, processing controller etc. that this Memory Allocation system includes but not limited to be arranged in computer equipment and can realize the present invention program.Wherein, this computer equipment includes but not limited to: 1) subscriber equipment; 2) network equipment.Described subscriber equipment includes but not limited to computing machine, smart mobile phone, PDA etc.; The described network equipment includes but not limited to server group that single network server, a plurality of webserver form or based on the cloud that is made of a large amount of computing machines or the webserver of cloud computing (Cloud Computing), wherein, cloud computing is a kind of of Distributed Calculation, a super virtual machine that is comprised of the loosely-coupled computing machine collection of a group.
In step S11, each memory block that each memory block that described Memory Allocation system will comprise 1 free page is classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2, and sets up corresponding free block index record based on the relevant information of each free block in the free memory block group, so as the inquiry.
Wherein, the relevant information of described free memory block comprises the information that is associated with free memory block, preferably, includes but not limited to: the free page quantity that free memory block comprises and start address etc.
For example, each memory block that described Memory Allocation system each memory block that will comprise 1 free page is classified as the 0th group, each memory block of comprising 2 free page is classified as the 1st group, comprise 3 or 4 free page be classified as the 2nd group ... comprise 2 9-1+ 1=257,258 ... or 2 9Each memory block of=512 free page is classified as the 9th group; And based on each self-contained free page quantity of the 0th group of each memory block that comprises and start address set up the 0th group the free memory block index record, based on each self-contained free page quantity of the 1st group of each memory block that comprises and start address set up the 0th group the free memory block index record ... set up the free memory block index record of the 9th group based on each self-contained free page quantity of the 9th group of each memory block that comprises and start address.
Preferably, described Memory Allocation system arranges according to the free page quantity of each self-recording free memory block free memory block index record of each group free memory block group in the ascending order mode.
For example, in one group of free memory block group, comprise free memory block A11, A12, A13, A14, wherein, free memory block A11 comprises 5 free page, free memory block A12 comprises 7 free page, free memory block A13 comprises 8 free page, free memory block A14 comprises 6 free page, and described Memory Allocation system is arranged sequentially by following ascending order with the index record X14 of index record X13, the free memory block A14 of the index record X12 free memory block A13 of index record X11, the free memory block A12 of free memory block A11:
X11;
X14;
X12;
X13。
See also Fig. 2, it is for providing the process flow diagram of correspondence memory piece based on memory requirements.
In step S21, described Memory Allocation system determines free memory block group to be checked based on memory requirements.
For example, application program system L11 need to comprise the memory block of 8 free page, described Memory Allocation system determines that based on this memory requirements the memory block that comprises 8 free page belongs to the 3rd group, with the 3rd group of free memory block group as free memory block group to be checked.
Then, in step S22, described Memory Allocation system is begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided, and revises the index record of corresponding memory block.
for example, application program system L21 need to comprise the memory block of 3 free page, described Memory Allocation system determines that based on the memory requirements of this application program system L21 the 2nd group of free memory block group is free memory block group to be checked, begin to inquire about whether have a memory block that comprises 3 free page by the 2nd group, if exist, the memory block that this is comprised 3 free page directly offers this application program system L21, and this is comprised the corresponding free block index record deletion of memory block of 3 free page, then add again the corresponding record of allocation index of this memory block that comprises 3 free page.
again for example, application program system L22 need to comprise the memory block of 0.5 free page, described Memory Allocation system determines that based on the memory requirements of this application program system L22 free memory block group to be checked is the 0th group, begin inquiry by the 0th group, and the free memory block A21 that comprises 1 free page in determining the 0th group can use, the free memory block A21 that this is comprised 1 free page directly offers this application program system L22, and the free block index that this free memory block A21 is corresponding deletion, then add again the corresponding record of allocation index of this memory block A21.
again for example, application program system L23 need to comprise the memory block of 7 free page, described Memory Allocation system determines that the 3rd group of free memory block group is free memory block group to be checked, begin inquiry by the 3rd group, and in determining the 3rd group without any available free memory block, described Memory Allocation system continues to inquire about in next group (being for example the 4th group), and the free memory block A22 that comprises 12 free page in determining the 4th group can use, this free memory block A22 is split as the first partner's memory block A221 that comprises 7 free page and comprises second partner's memory block A222 of 5 free page, and first partner's memory block A221 is offered application program system L23 use, simultaneously comprise 5 free page based on second partner's memory block A222 and determine that this second partner memory block A222 belongs to the 3rd group of free memory block group, then set up the corresponding record of allocation index of memory block A221 based on the relevant information of described first partner's memory block A221 again, relevant information based on second partner's memory block A222 is set up new free memory block index record in the 3rd group, and delete the corresponding free block index record of this available free memory block A22.
Wherein, the relevant information of partner's memory block comprises the information that is associated with partner's memory block, preferably, include but not limited to: the free memory block group under partner's memory block of the self-contained free page quantity of partner's memory block, start address and correspondence and start address etc.
For example, in the index record of aforementioned first partner's memory block A221, record the first page quantity that partner's memory block A221 is assigned with, it comprises, start address and corresponding affiliated free memory block group and the start address of partner's memory block A222; In the index record of second partner's memory block A222, record the page quantity that comprises, start address and corresponding affiliated free memory block group and the start address of partner's memory block A221 of second partner's memory block A222.
See also Fig. 3, it is for reclaiming the process flow diagram of memory block.
In step S31, described Memory Allocation system determines whether to exist partner's memory block based on the index record of memory block to be recycled.
Then, in step S32, if there is partner's memory block, described Memory Allocation system determines whether this partner's memory block distributes, if, the page quantity that comprises based on this memory block to be recycled is determined the free memory block group under it, and increases the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and deletes the corresponding record of allocation index of this memory block to be recycled; If not, should memory block to be recycled and partner's memory block merge, and determine free memory block group under it based on the page quantity that the memory block after this merging comprises, and the corresponding free block index record of memory block increase merging in corresponding free memory block group after, and delete the memory block to be recycled corresponding record of allocation index and the corresponding free block index record of this partner's memory block.
For example, described Memory Allocation system determines not exist partner's memory block based on the index record of memory block A31 to be recycled, comprise 18 pages based on memory block A31 to be recycled and determine that it belongs to the 5th group, increase the corresponding free block index record of memory block A31 in the free memory block record of the 5th group, and delete the corresponding record of allocation index of this memory block A31 to be recycled.
Again for example, described Memory Allocation system determines to exist partner's memory block A33 based on the index record of memory block A32 to be recycled.Partner's memory block A33 belongs to the 2nd group, described Memory Allocation system inquires about in the memory block index record of the 2nd group and determines that partner's memory block A33 distributes, described Memory Allocation system comprises 2 pages based on memory block A32 to be recycled and determines that it belongs to the 1st group, increase the corresponding free block index record of memory block A32 in the free memory block record of the 1st group, and delete the corresponding record of allocation index of this memory block A32 to be recycled.
again for example, described Memory Allocation system determines to exist partner's memory block A35 based on the index record of memory block A34 to be recycled, partner's memory block A35 belongs to the 5th group, described Memory Allocation system inquires about in the memory block index record of the 5th group and determines that partner's memory block A35 is not assigned with, described Memory Allocation system merges memory block A34 to be recycled and partner's memory block A35 and forms merge memory piece A36, and comprise 68 pages based on this memory block merge memory piece A36 and determine that it belongs to the 7th group, increase the corresponding free block index record of merge memory piece A36 in the free memory block record of the 7th group, and delete the corresponding allocation index of this memory block A34 and record and the corresponding free block index record of partner's memory block A35.
As shown in Figure 4, the invention provides a kind of Memory Allocation system.Wherein, this Memory Allocation system 1 comprises at least: grouping module 11.
Each memory block that each memory block that described grouping module 11 will comprise 1 free page is classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2; Set up corresponding free block index record based on the relevant information of each free block in the free memory block group, so that inquiry.
Wherein, the relevant information of described free memory block comprises the information that is associated with free memory block, preferably, includes but not limited to: the free page quantity that free memory block comprises and start address etc.
For example, each memory block that described grouping module 11 each memory block that will comprise 1 free page is classified as the 0th group, each memory block of comprising 2 free page is classified as the 1st group, comprise 3 or 4 free page be classified as the 2nd group ... comprise 2 9-1+ 1=257,258 ... or 2 9Each memory block of=512 free page is classified as the 9th group; And based on each self-contained free page quantity of the 0th group of each memory block that comprises and start address set up the 0th group the free memory block index record, based on each self-contained free page quantity of the 1st group of each memory block that comprises and start address set up the 1st group the free memory block index record ... set up the free memory block index record of the 9th group based on each self-contained free page quantity of the 9th group of each memory block that comprises and start address.
Preferably, described grouping module 11 is arranged according to the free page quantity of each self-recording free memory block the free memory block index record of each group free memory block group in the ascending order mode.
For example, in one group of free memory block group, comprise free memory block A11, A12, A13, A14, wherein, free memory block A11 comprises 5 free page, free memory block A12 comprises 7 free page, free memory block A13 comprises 8 free page, free memory block A14 comprises 6 free page, and described grouping module 11 is arranged sequentially by following ascending order with the index record X14 of index record X13, the free memory block A14 of the index record X12 free memory block A13 of index record X11, the free memory block A12 of free memory block A11:
X11;
X14;
X12;
X13。
See also Fig. 5, described Memory Allocation system 1 also comprises: determination module 12 and module 13 is provided.
Described determination module 12 is determined free memory block group to be checked based on memory requirements.
For example, application program system L11 need to comprise the memory block of 8 free page, described determination module 12 determines that based on this memory requirements the memory block that comprises 8 free page belongs to the 3rd group, with the 3rd group of free memory block group as free memory block group to be checked.
Then, the described module 13 that provides is begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided, and revises the index record of corresponding memory block.
for example, application program system L21 need to comprise the memory block of 3 free page, described determination module 12 determines that based on the memory requirements of this application program system L21 the 2nd group of free memory block group is free memory block group to be checked, provide module 13 to begin to inquire about whether have a memory block that comprises 3 free page by the 2nd group, if exist, the memory block that this is comprised 3 free page directly offers this application program system L21, grouping module 11 comprises the corresponding free block index note deletion of memory block of 3 free page with this, then add again the corresponding record of allocation index of this memory block.
again for example, application program system L22 need to comprise the memory block of 0.5 free page, described determination module 12 determines that based on the memory requirements of this application program system L22 free memory block group to be checked is the 0th group, provide module 13 to begin inquiry by the 0th group, and the free memory block A21 that comprises 1 free page in determining the 0th group can use, the free memory block A21 that this is comprised 1 free page directly offers this application program system L22, grouping module 11 is with the corresponding free block index record deletion of this free memory block A21, then add again the corresponding record of allocation index of this memory block.
again for example, application program system L23 need to comprise the memory block of 7 free page, described determination module 12 determines that the 3rd group of free memory block group is free memory block group to be checked, provide module 13 to begin inquiry by the 3rd group, and in determining the 3rd group without any available free memory block, the described module 13 that provides continues to inquire about in next group (being for example the 4th group), and the free memory block A22 that comprises 12 free page in determining the 4th group can use, this free memory block A22 is split as the first partner's memory block A221 that comprises 7 free page and comprises second partner's memory block A222 of 5 free page, and first partner's memory block A221 is offered application program system L23 use, while grouping module 11 comprises 5 free page based on second partner's memory block A222 and determines that this second partner memory block A222 belongs to the 3rd group of free memory block group, then grouping module 11 is set up the corresponding record of allocation index based on the relevant information of described first partner's memory block A221 again, relevant information based on second partner's memory block A222 is set up new free memory block index record in the 3rd group, and the corresponding free block index record of deletion available free memory block A22.
Wherein, the relevant information of partner's memory block comprises the information that is associated with partner's memory block, preferably, include but not limited to: the free memory block group under partner's memory block of the self-contained free page quantity of partner's memory block, start address and correspondence and start address etc.
For example, in the index record of aforementioned first partner's memory block A221, record the first page quantity that partner's memory block A221 distributes, it comprises, start address and corresponding affiliated free memory block group and the start address of partner's memory block A222; In the index record of second partner's memory block A222, record the page quantity that comprises, start address and corresponding affiliated free memory block group and the start address of partner's memory block A221 of second partner's memory block A222.
See also Fig. 6, described Memory Allocation system 1 also comprises: recycling module 14.
Described recycling module 14 determines whether to exist partner's memory block based on the index record of memory block to be recycled.
Then, if there is partner's memory block, described recycling module 14 determines whether this partner's memory block is assigned with, if, the page quantity that comprises based on this memory block to be recycled of grouping module 11 is determined the free memory block group under it, and increase the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and delete the corresponding record of allocation index of this memory block to be recycled; If not, recycling module 14 should memory block to be recycled and partner's memory block merge, the page quantity that the memory block of grouping module 11 after based on this merging comprises is determined the free memory block group under it, and the corresponding free block index record of memory block increase merging in corresponding free memory block group after, and delete the memory block to be recycled corresponding record of allocation index and the corresponding free block index record of this partner's memory block.
For example, described recycling module 14 determines not exist partner's memory block based on the index record of memory block A31 to be recycled, grouping module 11 comprises 18 pages based on memory block A31 to be recycled and determines that it belongs to the 5th group, increase the corresponding free block index record of memory block A31 in the free memory block record of the 5th group, and delete the corresponding record of allocation index of this memory block A31 to be recycled.
Again for example, described recycling module 14 determines to exist partner's memory block A33, partner's memory block A33 to belong to the 2nd group based on the index record of memory block A32 to be recycled, described recycling module 14 is inquired about in the memory block index record of the 2nd group and is determined that partner's memory block A33 is assigned with, described grouping module 11 comprises 2 pages based on memory block A32 to be recycled and determines that it belongs to the 1st group, increase the corresponding free block index record of memory block A32 in the free memory block record of the 1st group, and delete the corresponding record of allocation index of this memory block A32 to be recycled.
again for example, described recycling module 14 determines to exist partner's memory block A35 based on the index record of memory block A34 to be recycled, partner's memory block A35 belongs to the 5th group, described recycling module 14 is further inquired about in the memory block index record of the 5th group and is determined that partner's memory block A35 is not assigned with, described recycling module 15 merges formation merge memory piece A36 with memory block A34 to be recycled and partner's memory block A35 again, grouping module 11 comprises 68 pages based on this memory block merge memory piece A36 and determines that it belongs to the 7th group, increase the corresponding free block index record of merge memory piece A36 in the free memory block record of the 7th group, and delete the corresponding allocation index of this memory block A34 and record and the corresponding free block index record of partner's memory block A35.
In sum, memory allocation method of the present invention and system are take the page as management unit, to comprise the varying number page, especially comprise the free memory block grouping of non-2 a power side page, even if thus in the face of needing the memory requirements of non-2 a power side page, the free memory block that comprises non-2 a power side page also can be provided, to satisfy the demands, greatly improve the internal memory service efficiency.So the present invention has effectively overcome various shortcoming of the prior art and the tool high industrial utilization.
Above-described embodiment is illustrative principle of the present invention and effect thereof only, but not is used for restriction the present invention.Any person skilled in the art scholar all can under spirit of the present invention and category, modify or change above-described embodiment.Therefore, have in technical field under such as and know that usually the knowledgeable modifies or changes not breaking away from all equivalences of completing under disclosed spirit and technological thought, must be contained by claim of the present invention.

Claims (16)

1. a memory allocation method, is characterized in that, described memory allocation method comprises at least:
Each memory block that-each memory block that will comprise 1 free page is classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2, and sets up corresponding free block index record based on the relevant information of each free block in the free memory block group, so as the inquiry.
2. memory allocation method according to claim 1 characterized by further comprising step:
-determine free memory block group to be checked based on memory requirements;
-begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided,
And the index record of modification available free memory block.
3. memory allocation method according to claim 2 is characterized in that:
-when the memory capacity of this available free memory block surpasses described memory requirements, this available free memory block is split as first partner's memory block and the second partner's memory block that satisfies described memory requirements, the free page quantity that comprises based on second partner's memory block is again determined the free memory block group under this second partner memory block, and set up the corresponding record of allocation index of this memory block based on the relevant information of described first partner's memory block, set up new free memory block index record based on the relevant information of second partner's memory block, and delete the corresponding free block index record of this available free memory block.
4. memory allocation method according to claim 2 is characterized in that:
-when the memory capacity of this available free memory block equals described memory requirements, provide this available free memory block to satisfy described memory requirements, and the free block index record that this available free memory block is corresponding deletion, and add the corresponding record of allocation index of this memory block.
5. memory allocation method according to claim 2 is characterized in that:
-when this available free memory block only comprises a free page, when if its memory capacity surpasses described memory requirements, directly provide this available free memory block to satisfy described memory requirements, and the free block index record that this available free memory block is corresponding deletion, then add again the corresponding record of allocation index of this memory block.
6. memory allocation method according to claim 1 characterized by further comprising step:
-determine whether to exist partner's memory block based on the index record of memory block to be recycled;
There is partner's memory block in-Ruo, determine whether this partner's memory block distributes, if, the page quantity that comprises based on this memory block to be recycled is determined the free memory block group under it, and increase the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and delete the corresponding record of allocation index of this memory block to be recycled; If not, should memory block to be recycled and partner's memory block merge, and determine free memory block group under it based on the page quantity that the memory block after this merging comprises, and the corresponding free block index record of memory block increase merging in corresponding free memory block group after, and delete the memory block to be recycled corresponding record of allocation index and the corresponding free block index record of this partner's memory block.
7. memory allocation method according to claim 1 is characterized in that: the free memory block index record of each group free memory block group is arranged in the ascending order mode according to the free page quantity that each self-recording free memory block comprises.
8. memory allocation method according to claim 1, is characterized in that: 2≤i≤9.
9. a Memory Allocation system, is characterized in that, described Memory Allocation system comprises at least:
Each memory block that grouping module, each memory block that is used for comprising 1 free page be classified as one group of free memory block group, comprise 2 free page is classified as one group of free memory block group, comprises free page quantity more than or equal to 2 i-1+ 1 and less than or equal to 2 iEach memory block be classified as one group of free memory block group, i is the integer more than or equal to 2; And set up corresponding free block index record based on the relevant information of each free block in the free memory block group, so that inquiry.
10. Memory Allocation according to claim 9 system characterized by further comprising:
Determination module is used for determining free memory block group to be checked based on memory requirements;
Module is provided, is used for being begun to inquire about by free memory block group to be checked, so that the available free that can satisfy memory requirements memory block to be provided.
11. Memory Allocation according to claim 10 system is characterized in that:
when the memory capacity of this available free memory block surpasses described memory requirements, provide module this available free memory block to be split as first partner's memory block and the second partner's memory block that satisfies described memory requirements, the free page quantity that grouping module comprises based on second partner's memory block is again determined the free memory block group under this second partner memory block, and set up the corresponding record of allocation index of this memory block based on the relevant information of described first partner's memory block, set up new free memory block index record based on the relevant information of second partner's memory block, and delete the corresponding free block index record of this available free memory block.
12. Memory Allocation according to claim 10 system is characterized in that:
When the memory capacity of this available free memory block equals described memory requirements, provide module to provide this available free memory block to satisfy described memory requirements, the index record deletion of the free block that grouping module is corresponding with this available free memory block, and add the corresponding record of allocation index of this memory block.
13. Memory Allocation according to claim 10 system is characterized in that:
When this available free memory block only comprises a free page, when if its memory capacity surpasses described memory requirements, provide module directly to provide this available free memory block to satisfy described memory requirements, the free block index record deletion that grouping module is corresponding with this available free memory block, and add the corresponding record of allocation index of this memory block.
14. Memory Allocation according to claim 9 system characterized by further comprising:
Recycling module is used for determining whether to exist partner's memory block based on the index record of memory block to be recycled;
If there is partner's memory block, recycling module determines whether this partner's memory block is assigned with, if, the page quantity that comprises based on this memory block to be recycled of grouping module is determined the free memory block group under it, increase the corresponding free block index record of this memory block to be recycled in corresponding free memory block group, and delete the corresponding record of allocation index of this memory block to be recycled; If not, recycling module should memory block to be recycled and partner's memory block merge, the page quantity that the memory block of grouping module after based on this merging comprises is determined the free memory block group under it, and the corresponding free block index record of memory block increase merging in corresponding free memory block group after, and delete the corresponding index record that has distributed of memory block to be recycled and the corresponding free block index record of this partner's memory block.
15. Memory Allocation according to claim 9 system is characterized in that: the free memory block index record of each group free memory block group is arranged in the ascending order mode according to the free page quantity that each self-recording free memory block comprises.
16. Memory Allocation according to claim 9 system is characterized in that: 2≤i≤9.
CN201310074180.3A 2013-03-08 2013-03-08 Memory allocation method and system Active CN103106147B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310074180.3A CN103106147B (en) 2013-03-08 2013-03-08 Memory allocation method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310074180.3A CN103106147B (en) 2013-03-08 2013-03-08 Memory allocation method and system

Publications (2)

Publication Number Publication Date
CN103106147A true CN103106147A (en) 2013-05-15
CN103106147B CN103106147B (en) 2016-03-16

Family

ID=48314022

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310074180.3A Active CN103106147B (en) 2013-03-08 2013-03-08 Memory allocation method and system

Country Status (1)

Country Link
CN (1) CN103106147B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103970680A (en) * 2014-04-28 2014-08-06 上海华为技术有限公司 Memory management method and device and embedded system
WO2015062371A1 (en) * 2013-10-30 2015-05-07 华为技术有限公司 Memory allocation method and device
CN105302737A (en) * 2015-11-24 2016-02-03 浪潮(北京)电子信息产业有限公司 Memory allocation management method and memory allocation management system
CN105589809A (en) * 2014-10-24 2016-05-18 中国科学院深圳先进技术研究院 Memory management method and device
CN106294198A (en) * 2016-08-05 2017-01-04 浪潮(北京)电子信息产业有限公司 The memory allocation method of a kind of (SuSE) Linux OS and method for releasing
CN108920276A (en) * 2018-06-27 2018-11-30 郑州云海信息技术有限公司 Linux system memory allocation method, system and equipment and storage medium
CN112380004A (en) * 2020-11-04 2021-02-19 成都佰维存储科技有限公司 Memory management method and device, computer readable storage medium and electronic equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1963788A (en) * 2005-11-08 2007-05-16 中兴通讯股份有限公司 A managing method for EMS memory
US20100095081A1 (en) * 2008-10-09 2010-04-15 Mcdavitt Ben Early detection of an access to de-allocated memory
CN101859279A (en) * 2010-05-21 2010-10-13 北京星网锐捷网络技术有限公司 Memory allocation and release method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1963788A (en) * 2005-11-08 2007-05-16 中兴通讯股份有限公司 A managing method for EMS memory
US20100095081A1 (en) * 2008-10-09 2010-04-15 Mcdavitt Ben Early detection of an access to de-allocated memory
CN101859279A (en) * 2010-05-21 2010-10-13 北京星网锐捷网络技术有限公司 Memory allocation and release method and device

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015062371A1 (en) * 2013-10-30 2015-05-07 华为技术有限公司 Memory allocation method and device
CN103970680A (en) * 2014-04-28 2014-08-06 上海华为技术有限公司 Memory management method and device and embedded system
CN105589809A (en) * 2014-10-24 2016-05-18 中国科学院深圳先进技术研究院 Memory management method and device
CN105302737A (en) * 2015-11-24 2016-02-03 浪潮(北京)电子信息产业有限公司 Memory allocation management method and memory allocation management system
CN106294198A (en) * 2016-08-05 2017-01-04 浪潮(北京)电子信息产业有限公司 The memory allocation method of a kind of (SuSE) Linux OS and method for releasing
CN106294198B (en) * 2016-08-05 2018-12-07 浪潮(北京)电子信息产业有限公司 A kind of memory allocation method and method for releasing of (SuSE) Linux OS
CN108920276A (en) * 2018-06-27 2018-11-30 郑州云海信息技术有限公司 Linux system memory allocation method, system and equipment and storage medium
CN112380004A (en) * 2020-11-04 2021-02-19 成都佰维存储科技有限公司 Memory management method and device, computer readable storage medium and electronic equipment
CN112380004B (en) * 2020-11-04 2023-06-13 成都佰维存储科技有限公司 Memory management method, memory management device, computer readable storage medium and electronic equipment

Also Published As

Publication number Publication date
CN103106147B (en) 2016-03-16

Similar Documents

Publication Publication Date Title
CN103106147B (en) Memory allocation method and system
CN101968750B (en) Computer system and working method thereof
CN101901248B (en) Method and device for creating and updating Bloom filter and searching elements
CN105183764B (en) A kind of data paging method and device
CN103995855B (en) The method and apparatus of data storage
WO2013078583A1 (en) Method and apparatus for optimizing data access, method and apparatus for optimizing data storage
CN103440208A (en) Data storage method and device
CN104731569A (en) Data processing method and relevant equipment
CN103246549B (en) A kind of method and system of data conversion storage
CN103365784B (en) The method of Memory recycle and distribution and device
CN104539708A (en) Capacity reduction method, device and system for cloud platform resources
CN106406762A (en) A repeated data deleting method and device
CN102298618B (en) Method for obtaining matching degree to execute corresponding operations and device and equipment
CN105718319A (en) Memory pool territory analysis method and memory pool device
CN105930354B (en) Storage model conversion method and device
CN105469173A (en) Method of optimal management on static memory
CN112650577A (en) Memory management method and device
CN103164492A (en) File copying method between electronic devices and electronic devices
CN103713953A (en) Device and method for transferring data in memory
CN104050189B (en) The page shares processing method and processing device
CN106980673A (en) Main memory database table index updating method and system
CN104391735A (en) Method and system for scheduling virtual machines in virtualized all-in-one machine cluster
CN111427887A (en) Method, device and system for rapidly scanning HBase partition table
CN105677583A (en) Cache management method and device
CN106547625B (en) Memory allocation method and device of financial terminal

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant