CN103106147B - Memory allocation method and system - Google Patents

Memory allocation method and system Download PDF

Info

Publication number
CN103106147B
CN103106147B CN201310074180.3A CN201310074180A CN103106147B CN 103106147 B CN103106147 B CN 103106147B CN 201310074180 A CN201310074180 A CN 201310074180A CN 103106147 B CN103106147 B CN 103106147B
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.)
Active
Application number
CN201310074180.3A
Other languages
Chinese (zh)
Other versions
CN103106147A (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

Landscapes

  • Memory System (AREA)

Abstract

The invention provides a kind of memory allocation method and system.According to method of the present invention, each memory block that each memory block comprising 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 and be more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer, and set up corresponding free block index record based on the relevant information of each free block in free memory block group, to inquire about, thus can providing package containing the free memory block of the non-power side of 2 page, to satisfy the demands, greatly improve internal memory service efficiency.

Description

Memory allocation method and system
Technical field
The present invention relates to 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 whole system delay of response, and even collapse.So, set up stable, efficiently memory management scheme be one very important and must faced by problem.
In the buddy algorithm of existing (SuSE) Linux OS, first all free page are divided into 10 block groups, often in group, each memory block comprises power side's free page of 2, and such as, in the 0th group, each memory block all comprises 2 separately 0=1 free page, in the 1st group, each memory block all comprises 2 separately 1=2 free page ... in 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.Visible, in this kind of algorithm, the free page quantity that in each memory block group, each memory block comprises is identical.
The course of work of the buddy algorithm of this (SuSE) Linux OS will be described by a simple example below:
If existing operating system needs one comprise the memory block of 128 free page, then this buddy algorithm system is first searched in the chained list of memory block group comprising 128 free page, to determine whether the memory block comprising 128 free page, if had, just directly this operating system is provided to use; If do not had, search in the chained list of the memory block group that this buddy algorithm system can be formed at the memory block comprising 256 free page, if have available free memory block in this memory block group, this buddy algorithm system can be divided into two equal portions 256 of this free memory block free page, portion is supplied to operating system and uses, and another part is inserted in the memory block group of the memory block formation comprising 128 free page.If do not find available free page block in the chained list of memory block group comprising 256 free page yet, just continue in larger block group, namely comprise 256 free page memory block form memory block group chained list in search, if have available free memory block in this memory block group, this buddy algorithm system can separate 128 pages 512 of this free memory block free page and be supplied to operating system use, then from remaining 384 pages, taking-up 256 pages are inserted into block size is in the chained list of 256 pages, then remaining 128 pages being inserted into block size is in the chained list of 128 pages, if also do not have 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 distributed, and also can be regarded as the merging process of partner.When a release occupied memory block, first examine or check in the chained list of its correspondence and whether have partner's memory block to exist, if there is no partner's memory block, just directly this memory block that will discharge is linked into linked list head; If had, then from chained list, take partner's memory block, and be merged into formation merge memory block, then continue the merge memory block after examination merging and whether also have 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 partner's memory block each other met the following conditions:
(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 to be distributed and recovery speed is fast, algorithm simple, when a size is 2 nafter the memory block release of byte, storage management system only needs search 2 nthe memory block of byte-sized is to determine whether to need to merge.
Although buddy algorithm is famous classic algorithm, also not flawless; First, from buddy algorithm principle, all memory request all must in units of power side's size of 2, if desired one when comprising the memory block of 129 pages, system must use, because reality only uses 129 pages containing the free memory block of 256 pages by providing package, remaining 127 pages have obviously been wasted, namely the memory source of nearly 50% is wasted, visible, and this kind of algorithm easily causes memory usage lower.
In addition, the efficiency of buddy algorithm also easily goes wrong: because buddy algorithm relates to the operation of many calculating and chained list and bitmap, cause expense larger; Such as, if each 2 npartner's merged block of size is to 2 n+1chained list queue in, so 2 nmemory block in the chained list of size will reduce because of union operation, thus, when system needs 2 nduring the memory block of size, just need 2 n+1the memory block of size splits again, visible, and the process that merging like this splits again is inefficient.
Thus, how to propose a kind of new memory allocation method, the advantage well can inheriting buddy algorithm can overcome again the deficiency of buddy algorithm, realizes fast allocation, reclaims internal memory, improve internal memory service efficiency, real is practitioner in the art's problem demanding prompt solution simultaneously.
Summary of the invention
The shortcoming of prior art in view of the above, the object of the present invention is to provide memory allocation method and system that a kind of internal memory service efficiency is high.
For achieving the above object and other relevant objects, the invention provides a kind of memory allocation method, it at least comprises:
-each memory block that each memory block comprising 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, comprise free page quantity and be more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer; And set up corresponding free block index record, to inquire about based on the relevant information of each free block in free memory block group.
Preferably, described memory allocation method also comprises step:
-determine free memory block group to be checked based on memory requirements;
-inquire about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block, and revise the index record of available free memory block.
Preferably, when the memory capacity of this available free memory block exceedes described memory requirements, then this available free memory block is split as the first partner's memory block meeting described memory requirements and second partner's memory block, the free page quantity comprised based on second partner's memory block again determines this free memory block group belonging to the 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, relevant information based on second partner's memory block sets up new free memory block index record, 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, there is provided this available free memory block to meet described memory requirements, and free block index record corresponding for available free memory block is deleted, and add the corresponding record of allocation index of this memory block.
Preferably, when this available free memory block only comprises a free page, if when its memory capacity exceedes described memory requirements, directly provide this available free memory block to meet described memory requirements, and deleted by free block index record corresponding for this available free memory block, and add the corresponding record of allocation index of this memory block.Preferably, described memory allocation method also comprises step:
-determine whether there is partner's memory block based on the index record of memory block to be recycled;
There is partner's memory block in-Ruo, then determine that whether this partner's memory block is occupied, if, the page quantity then comprised based on this memory block to be recycled determines the free memory block group belonging to it, and in corresponding free memory block group, increase the corresponding free block index record of this memory block to be recycled, and delete the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block are merged, and determine the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the record of allocation index of memory block to be recycled and the corresponding free block index record of this partner's memory block.
The present invention also provides a kind of Memory Allocation system, and it at least comprises:
Grouping module, for each memory block that each memory block comprising 1 free page is classified as one group of free memory block group, comprise 2 free page being classified as one group of free memory block group, comprising free page quantity and is more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer; And set up corresponding free block index record, to inquire about based on the relevant information of each free block in free memory block group.
Preferably, described Memory Allocation system also comprises:
Determination module, for determining free memory block group to be checked based on memory requirements;
There is provided module, for inquiring about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block.
Preferably, when the memory capacity of this available free memory block exceedes described memory requirements, the first partner's memory block and second partner's memory block that then provide module to be split as by this available free memory block to meet described memory requirements, the free page quantity that grouping module comprises based on second partner's memory block again determines this free memory block group belonging to the 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, relevant information based on second partner's memory block sets up new free memory block index record, 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, module is provided to provide this available free memory block to meet described memory requirements, free block index record corresponding for this available free memory block is deleted by grouping module, and adds the corresponding record of allocation index of this memory block.
Preferably, when this available free memory block only comprises a free page, if when its memory capacity exceedes described memory requirements, module is provided directly to provide this available free memory block to meet described memory requirements, free block index record corresponding for this available free memory block is deleted by grouping module, and adds the corresponding record of allocation index of this memory block.
Preferably, described Memory Allocation system also comprises:
Recycling module, for determining whether there is partner's memory block based on the index record of memory block to be recycled;
If there is partner's memory block, then recycling module determines whether this partner's memory block distributes, if, then grouping module determines belonging to it based on the page quantity that this memory block to be recycled comprises free memory block group, in corresponding free memory block group, increase the free block index record that this memory block to be recycled is corresponding, and delete the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block merge by recycling module, grouping module determines the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the corresponding record of allocation index of memory block to be recycled 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 the fast allocation of internal memory, recovery, improves internal memory service efficiency simultaneously.
Accompanying drawing explanation
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 meet 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 the preferred schematic diagram of one of Memory Allocation system of the present invention.
Fig. 5 is shown as another preferred schematic diagram of Memory Allocation system of the present invention.
Fig. 6 is shown as another preferred schematic diagram of Memory Allocation system of the present invention.
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 way of specific instantiation, embodiments of the present invention are described, those skilled in the art the content disclosed by this instructions can understand other advantages of the present invention and effect easily.The present invention can also be implemented or be applied by embodiments different in addition, and the every details in this instructions also can based on different viewpoints and application, carries out various modification or change not deviating under spirit of the present invention.
Refer to Fig. 1 to Fig. 6.It should be noted that, the diagram provided in the present embodiment only illustrates basic conception of the present invention in a schematic way, then only the assembly relevant with the present invention is shown in graphic but not component count, shape and size when implementing according to reality is drawn, it is actual when implementing, and the kenel of each assembly, quantity and ratio can be a kind of change arbitrarily, 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, method according to the present invention has been come mainly through the Memory Allocation system in computer equipment, and this Memory Allocation system to include but not limited to be arranged in computer equipment and can realize the such as application module, operating system, processing controller etc. of 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 the server group that single network server, multiple webserver form or the cloud be made up of a large amount of computing machine or the webserver based on cloud computing (CloudComputing), wherein, cloud computing is the one of Distributed Calculation, the super virtual machine be made up of a group loosely-coupled computing machine collection.
In step s 11, each memory block that each memory block comprising 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 and be more than or equal to 2 by described Memory Allocation system i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer, and set up corresponding free block index record, to inquire about based on the relevant information of each free block in free memory block group.
Wherein, the relevant information of described free memory block comprises the information be associated with free memory block, preferably, includes but not limited to: the free page quantity that free memory block comprises and start address etc.
Such as, described Memory Allocation system each memory block that each memory block comprising 1 free page is classified as the 0th group, comprise 2 free page is classified as the 1st group, each memory block of comprising 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 the 0th group of each self-contained free page quantity of each memory block comprised and start address set up the 0th group free memory block index record, to set up based on the 1st group of each self-contained free page quantity of each memory block comprised and start address the 0th group free memory block index record ... the free memory block index record of the 9th group is set up based on the 9th group of each self-contained free page quantity of each memory block comprised and start address.
Preferably, the free page quantity of the free memory block index record of each group free memory block group according to each self-recording free memory block arranges in ascending order mode by described Memory Allocation system.
Such as, 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, then the index record X14 of the index record X13 of the index record X12 free memory block A13 of the index record X11 of free memory block A11, free memory block A12, free memory block A14 arranges by following ascending order order by described Memory Allocation system:
X11;
X14;
X12;
X13。
Refer to Fig. 2, it is for providing the process flow diagram of correspondence memory block based on memory requirements.
In the step s 21, described Memory Allocation system determines free memory block group to be checked based on memory requirements.
Such as, application program system L11 needs the memory block comprising 8 free page, then based on this memory requirements, described Memory Allocation system determines that the memory block comprising 8 free page belongs to the 3rd group, then using 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 inquired about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block, and revises the index record of corresponding memory block.
Such as, application program system L21 needs the memory block comprising 3 free page, based on the memory requirements of this application program system L21, described Memory Allocation system determines that the 2nd group of free memory block group is free memory block group to be checked, then by the 2nd group, inquire about the memory block whether existing and comprise 3 free page, if exist, the memory block then this being comprised 3 free page is directly supplied to this application program system L21, and the free block index record deletion that the memory block this being comprised 3 free page is corresponding, then the record of allocation index that this memory block comprising 3 free page is corresponding is added again.
Again such as, application program system L22 needs the memory block comprising 0.5 free page, based on the memory requirements of this application program system L22, described Memory Allocation system determines that free memory block group to be checked is the 0th group, then inquire about by the 0th group, and determine that the free memory block A21 comprising 1 free page in the 0th group can use, the free memory block A21 then this being comprised 1 free page is directly supplied to this application program system L22, and free block index corresponding for this free memory block A21 is deleted, then the record of allocation index that this memory block A21 is corresponding is added again.
Again such as, application program system L23 needs the memory block comprising 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, then inquire about by the 3rd group, and determine in the 3rd group without any available free memory block, then described Memory Allocation system continues to inquire about in next group (being such as the 4th group), and determine that the free memory block A22 comprising 12 free page in the 4th group can use, then this free memory block A22 is split as the first partner's memory block A221 comprising 7 free page and comprises second partner's memory block A222 of 5 free page, and first partner's memory block A221 is supplied to application program system L23 uses, comprising 5 free page based on second partner's memory block A222 determines that this second partner memory block A222 belongs to the 3rd group of free memory block group simultaneously, then the corresponding record of allocation index of memory block A221 is set up based on the relevant information of described first partner's memory block A221 again, relevant information based on second partner's memory block A222 sets 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 be associated with partner's memory block, preferably, include but not limited to: the free memory block group belonging to partner's memory block of the self-contained free page quantity of partner's memory block, start address and correspondence and start address etc.
Such as, in the index record of aforementioned first partner's memory block A221, record the free memory block group belonging to partner's memory block A222 and the start address of the first page quantity, start address and correspondence that partner's memory block A221 is assigned with, it comprises; In the index record of second partner's memory block A222, record the free memory block group belonging to partner's memory block A221 and the start address of the page quantity, start address and the correspondence that comprise of second partner's memory block A222.
Refer to Fig. 3, it is the process flow diagram reclaiming memory block.
In step S31, described Memory Allocation system determines whether there is partner's memory block based on the index record of memory block to be recycled.
Then, in step s 32, if there is partner's memory block, then described Memory Allocation system determines whether this partner's memory block distributes, if, the page quantity then comprised based on this memory block to be recycled determines the free memory block group belonging to it, and in corresponding free memory block group, increase the corresponding free block index record of this memory block to be recycled, and deletes the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block are merged, and determine the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the corresponding record of allocation index of memory block to be recycled and the corresponding free block index record of this partner's memory block.
Such as, described Memory Allocation system determines to there is not partner's memory block based on the index record of memory block A31 to be recycled, then comprise 18 pages based on memory block A31 to be recycled and determine that it belongs to the 5th group, then in the free memory block record of the 5th group, increase the corresponding free block index record of memory block A31, and delete the corresponding record of allocation index of this memory block A31 to be recycled.
Again such as, described Memory Allocation system determines to there is 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, then described Memory Allocation system is inquired about and is determined that partner's memory block A33 distributes in the memory block index record of the 2nd group, then described Memory Allocation system comprises 2 pages based on memory block A32 to be recycled and determines that it belongs to the 1st group, then in the free memory block record of the 1st group, increase the corresponding free block index record of memory block A32, and delete the corresponding record of allocation index of this memory block A32 to be recycled.
Again such as, described Memory Allocation system determines to there is 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, then described Memory Allocation system is inquired about and is determined that partner's memory block A35 is not assigned with in the memory block index record of the 5th group, then memory block A34 to be recycled and partner's memory block A35 merges and forms merge memory block A36 by described Memory Allocation system, and comprise 68 pages based on this memory block merge memory block A36 and determine that it belongs to the 7th group, in the free memory block record of the 7th group, then increase the corresponding free block index record of merge memory block A36, and delete the corresponding record of allocation index of this memory block A34 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 at least comprises: grouping module 11.
Each memory block that each memory block comprising 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 by described grouping module 11, comprise free page quantity is more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer; Corresponding free block index record is set up, to inquire about based on the relevant information of each free block in free memory block group.
Wherein, the relevant information of described free memory block comprises the information be associated with free memory block, preferably, includes but not limited to: the free page quantity that free memory block comprises and start address etc.
Such as, described grouping module 11 each memory block that each memory block comprising 1 free page is classified as the 0th group, comprise 2 free page is classified as the 1st group, each memory block of comprising 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 the 0th group of each self-contained free page quantity of each memory block comprised and start address set up the 0th group free memory block index record, to set up based on the 1st group of each self-contained free page quantity of each memory block comprised and start address the 1st group free memory block index record ... the free memory block index record of the 9th group is set up based on the 9th group of each self-contained free page quantity of each memory block comprised and start address.
Preferably, the free page quantity of the free memory block index record of each group free memory block group according to each self-recording free memory block arranges in ascending order mode by described grouping module 11.
Such as, 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, then the index record X14 of the index record X13 of the index record X12 free memory block A13 of the index record X11 of free memory block A11, free memory block A12, free memory block A14 arranges by following ascending order order by described grouping module 11:
X11;
X14;
X12;
X13。
Refer to Fig. 5, described Memory Allocation system 1 also comprises: determination module 12 and provide module 13.
Described determination module 12 determines free memory block group to be checked based on memory requirements.
Such as, application program system L11 needs the memory block comprising 8 free page, then based on this memory requirements, described determination module 12 determines that the memory block comprising 8 free page belongs to the 3rd group, then using the 3rd group of free memory block group as free memory block group to be checked.
Then, described in provide module 13 to inquire about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block, and revise the index record of corresponding memory block.
Such as, application program system L21 needs the memory block comprising 3 free page, based on the memory requirements of this application program system L21, described determination module 12 determines that the 2nd group of free memory block group is free memory block group to be checked, module 13 is then provided to inquire about the memory block whether existing and comprise 3 free page by the 2nd group, if exist, the memory block then this being comprised 3 free page is directly supplied to this application program system L21, the free block index note that this is comprised the memory block of 3 free page corresponding by grouping module 11 is deleted, then the record of allocation index that this memory block is corresponding is added again.
Again such as, application program system L22 needs the memory block comprising 0.5 free page, based on the memory requirements of this application program system L22, described determination module 12 determines that free memory block group to be checked is the 0th group, module 13 is then provided to inquire about by the 0th group, and determine that the free memory block A21 comprising 1 free page in the 0th group can use, the free memory block A21 then this being comprised 1 free page is directly supplied to this application program system L22, the corresponding free block index record of this free memory block A21 is deleted by grouping module 11, then the record of allocation index that this memory block is corresponding is added again.
Again such as, application program system L23 needs the memory block comprising 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, module 13 is then provided to inquire about by the 3rd group, and determine in the 3rd group without any available free memory block, module 13 is provided to continue to inquire about in next group (being such as the 4th group) then, and determine that the free memory block A22 comprising 12 free page in the 4th group can use, then this free memory block A22 is split as the first partner's memory block A221 comprising 7 free page and comprises second partner's memory block A222 of 5 free page, and first partner's memory block A221 is supplied to application program system L23 uses, simultaneously 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 sets 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 sets up new free memory block index record in the 3rd group, and delete the corresponding free block index record of available free memory block A22.
Wherein, the relevant information of partner's memory block comprises the information be associated with partner's memory block, preferably, include but not limited to: the free memory block group belonging to partner's memory block of the self-contained free page quantity of partner's memory block, start address and correspondence and start address etc.
Such as, in the index record of aforementioned first partner's memory block A221, record the free memory block group belonging to partner's memory block A222 and the start address of the first page quantity, start address and correspondence that partner's memory block A221 distributes, it comprises; In the index record of second partner's memory block A222, record the free memory block group belonging to partner's memory block A221 and the start address of the page quantity, start address and the correspondence that comprise of second partner's memory block A222.
Refer to Fig. 6, described Memory Allocation system 1 also comprises: recycling module 14.
Described recycling module 14 determines whether there is partner's memory block based on the index record of memory block to be recycled.
Then, if there is partner's memory block, then described recycling module 14 determines whether this partner's memory block is assigned with, if, then grouping module 11 determines belonging to it based on the page quantity that this memory block to be recycled comprises free memory block group, and in corresponding free memory block group, increase the corresponding free block index record of this memory block to be recycled, and delete the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block merge by recycling module 14, grouping module 11 determines the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the corresponding record of allocation index of memory block to be recycled and the corresponding free block index record of this partner's memory block.
Such as, described recycling module 14 determines to there is not partner's memory block based on the index record of memory block A31 to be recycled, then grouping module 11 comprises 18 pages based on memory block A31 to be recycled and determines that it belongs to the 5th group, then in the free memory block record of the 5th group, increase the corresponding free block index record of memory block A31, and delete the corresponding record of allocation index of this memory block A31 to be recycled.
Again such as, described recycling module 14 based on memory block A32 to be recycled index record determines to there is partner's memory block A33, partner's memory block A33 belongs to the 2nd group, then described recycling module 14 is inquired about and is determined that partner's memory block A33 is assigned with in the memory block index record of the 2nd group, then described grouping module 11 comprises 2 pages based on memory block A32 to be recycled and determines that it belongs to the 1st group, then in the free memory block record of the 1st group, increase the corresponding free block index record of memory block A32, and delete the corresponding record of allocation index of this memory block A32 to be recycled.
Again such as, described recycling module 14 determines to there is 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, then described recycling module 14 is inquired about further and is determined that partner's memory block A35 is not assigned with in the memory block index record of the 5th group, then memory block A34 to be recycled and partner's memory block A35 merges and forms merge memory block A36 by described recycling module 15 again, grouping module 11 comprises 68 pages based on this memory block merge memory block A36 and determines that it belongs to the 7th group, in the free memory block record of the 7th group, then increase the corresponding free block index record of merge memory block A36, and delete the corresponding record of allocation index of this memory block A34 and the corresponding free block index record of partner's memory block A35.
In sum, memory allocation method of the present invention and system take the page as management unit, the varying number page will be comprised, especially the free memory block grouping of the non-power side of 2 page is comprised, even if thus in the face of needing the memory requirements of the non-power side of 2 page, also can providing package containing the free memory block of the non-power side of 2 page, to satisfy the demands, greatly improve internal memory service efficiency.So the present invention effectively overcomes various shortcoming of the prior art and tool high industrial utilization.
Above-described embodiment is illustrative principle of the present invention and effect thereof only, but not for limiting the present invention.Any person skilled in the art scholar all without prejudice under spirit of the present invention and category, can modify above-described embodiment or changes.Therefore, such as have in art usually know the knowledgeable do not depart from complete under disclosed spirit and technological thought all equivalence modify or change, must be contained by claim of the present invention.

Claims (12)

1. a memory allocation method, is characterized in that, described memory allocation method at least comprises:
-each memory block that each memory block comprising 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, comprise free page quantity and be more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer, and set up corresponding free block index record, to inquire about based on the relevant information of each free block in free memory block group; Wherein, the relevant information of free block comprises the free page quantity and start address that free block comprises; And the free page quantity that the free memory block index record of each group free memory block group comprises according to each self-recording free memory block arranges in ascending order mode;
-determine free memory block group to be checked based on memory requirements;
-inquire about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block, and revise the index record of available free memory block.
2. memory allocation method according to claim 1, is characterized in that:
-when the memory capacity of this available free memory block exceedes described memory requirements, then this available free memory block is split as the first partner's memory block meeting described memory requirements and second partner's memory block, the free page quantity comprised based on second partner's memory block again determines this free memory block group belonging to the 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, relevant information based on second partner's memory block sets up new free memory block index record, and delete the corresponding free block index record of this available free memory block.
3. memory allocation method according to claim 1, is characterized in that:
-when the memory capacity of this available free memory block equals described memory requirements, there is provided this available free memory block to meet described memory requirements, and deleted by free block index record corresponding for this available free memory block, and add the corresponding record of allocation index of this memory block.
4. memory allocation method according to claim 1, is characterized in that:
-when this available free memory block only comprises a free page, if when its memory capacity exceedes described memory requirements, directly provide this available free memory block to meet described memory requirements, and free block index record corresponding for this available free memory block is deleted, then add the record of allocation index that this memory block is corresponding again.
5. memory allocation method according to claim 1, characterized by further comprising step:
-determine whether there is partner's memory block based on the index record of memory block to be recycled;
There is partner's memory block in-Ruo, then determine whether this partner's memory block distributes, if, the page quantity then comprised based on this memory block to be recycled determines the free memory block group belonging to it, and in corresponding free memory block group, increase the corresponding free block index record of this memory block to be recycled, and delete the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block are merged, and determine the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the corresponding record of allocation index of memory block to be recycled and the corresponding free block index record of this partner's memory block.
6. memory allocation method according to claim 1, is characterized in that: 2≤i≤9.
7. a Memory Allocation system, is characterized in that, described Memory Allocation system at least comprises:
Grouping module, for each memory block that each memory block comprising 1 free page is classified as one group of free memory block group, comprise 2 free page being classified as one group of free memory block group, comprising free page quantity and is more than or equal to 2 i-1+ 1 and be less than or equal to 2 ieach memory block be classified as one group of free memory block group, i be more than or equal to 2 integer; And set up corresponding free block index record, to inquire about based on the relevant information of each free block in free memory block group; Wherein, the relevant information of free block comprises the free page quantity and start address that free block comprises, and the free page quantity that free memory block index record of each group free memory block group comprises according to each self-recording free memory block arranges in ascending order mode;
Determination module, for determining free memory block group to be checked based on memory requirements;
There is provided module, for inquiring about by free memory block group to be checked, to provide the available free that can meet memory requirements memory block.
8. Memory Allocation system according to claim 7, is characterized in that:
When the memory capacity of this available free memory block exceedes described memory requirements, the first partner's memory block and second partner's memory block that then provide module to be split as by this available free memory block to meet described memory requirements, the free page quantity that grouping module comprises based on second partner's memory block again determines this free memory block group belonging to the 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, relevant information based on second partner's memory block sets up new free memory block index record, and delete the corresponding free block index record of this available free memory block.
9. Memory Allocation system according to claim 7, is characterized in that:
When the memory capacity of this available free memory block equals described memory requirements, module is provided to provide this available free memory block to meet described memory requirements, the index record of free block corresponding for this available free memory block is deleted by grouping module, and adds the corresponding record of allocation index of this memory block.
10. Memory Allocation system according to claim 7, is characterized in that:
When this available free memory block only comprises a free page, if when its memory capacity exceedes described memory requirements, module is provided directly to provide this available free memory block to meet described memory requirements, free block index record corresponding for this available free memory block is deleted by grouping module, and adds the corresponding record of allocation index of this memory block.
11. Memory Allocation systems according to claim 7, characterized by further comprising:
Recycling module, for determining whether there is partner's memory block based on the index record of memory block to be recycled;
If there is partner's memory block, then recycling module determines whether this partner's memory block is assigned with, if, then grouping module determines belonging to it based on the page quantity that this memory block to be recycled comprises free memory block group, in corresponding free memory block group, increase the corresponding free block index record of this memory block to be recycled, and delete the corresponding record of allocation index of this memory block to be recycled; If not, then this memory block to be recycled and partner's memory block merge by recycling module, grouping module determines the free memory block group belonging to it based on the page quantity that the memory block after this merging comprises, and in corresponding free memory block group, increase the corresponding free block index record of memory block after merging, and delete the corresponding index record distributed of memory block to be recycled and the corresponding free block index record of this partner's memory block.
12. Memory Allocation systems according to claim 7, 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 CN103106147A (en) 2013-05-15
CN103106147B true 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)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104598385B (en) * 2013-10-30 2019-05-10 华为技术有限公司 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
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
CN112380004B (en) * 2020-11-04 2023-06-13 成都佰维存储科技有限公司 Memory management method, memory management device, computer readable storage medium and electronic equipment

Citations (2)

* 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
CN101859279A (en) * 2010-05-21 2010-10-13 北京星网锐捷网络技术有限公司 Memory allocation and release method and device

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8151086B2 (en) * 2008-10-09 2012-04-03 Lsi Corporation Early detection of an access to de-allocated memory

Patent Citations (2)

* 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
CN101859279A (en) * 2010-05-21 2010-10-13 北京星网锐捷网络技术有限公司 Memory allocation and release method and device

Also Published As

Publication number Publication date
CN103106147A (en) 2013-05-15

Similar Documents

Publication Publication Date Title
CN103106147B (en) Memory allocation method and system
CN101968750B (en) Computer system and working method thereof
CN103902593B (en) A kind of method and apparatus of Data Migration
CN105183764B (en) A kind of data paging method and device
CN104731569A (en) Data processing method and relevant equipment
CN112948439B (en) Method, device, medium and equipment for processing GIS data query request in real time
CN111651453A (en) User historical behavior query method and device, electronic equipment and storage medium
CN112685333B (en) Heap memory management method and device
CN108268503B (en) Database storage and query method and device
CN103294799B (en) A kind of data parallel batch imports the method and system of read-only inquiry system
CN105045670A (en) Method and system for balancing loads of central processing units and graphic processing units
CN114185895A (en) Data import and export method and device, electronic equipment and storage medium
GB2502076A (en) Managing memory in a computer system
CN105469173A (en) Method of optimal management on static memory
US8543722B2 (en) Message passing with queues and channels
CN106156049A (en) A kind of method and system of digital independent
CN112650577A (en) Memory management method and device
CN114398346A (en) Data migration method, device, equipment and storage medium
CN103713953A (en) Device and method for transferring data in memory
CN112256472A (en) Distributed data calling method and device, electronic equipment and storage medium
CN205899536U (en) Geographic information service system based on tile map
CN111858612A (en) Data accelerated access method and device based on graph database and storage medium
CN117271162A (en) Request processing method, device, equipment and storage medium
CN115599790B (en) Data storage system, data processing method, electronic equipment and storage medium
CN106980673A (en) Main memory database table index updating method and system

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