CN111078587A - Memory allocation method and device, storage medium and electronic equipment - Google Patents

Memory allocation method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN111078587A
CN111078587A CN201911261643.0A CN201911261643A CN111078587A CN 111078587 A CN111078587 A CN 111078587A CN 201911261643 A CN201911261643 A CN 201911261643A CN 111078587 A CN111078587 A CN 111078587A
Authority
CN
China
Prior art keywords
memory
page
continuous
idle
demand
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
CN201911261643.0A
Other languages
Chinese (zh)
Other versions
CN111078587B (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.)
Oppo Chongqing Intelligent Technology Co Ltd
Original Assignee
Oppo Chongqing Intelligent Technology Co Ltd
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 Oppo Chongqing Intelligent Technology Co Ltd filed Critical Oppo Chongqing Intelligent Technology Co Ltd
Priority to CN201911261643.0A priority Critical patent/CN111078587B/en
Publication of CN111078587A publication Critical patent/CN111078587A/en
Application granted granted Critical
Publication of CN111078587B publication Critical patent/CN111078587B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/10Address translation
    • G06F12/1009Address translation using page tables, e.g. page table structures

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The embodiment of the application discloses a memory allocation method, a memory allocation device, a storage medium and electronic equipment, wherein when a memory allocation request is received, the memory demand corresponding to the memory allocation request is determined; detecting whether continuous idle memory pages matched with the memory demand exist in the memory space; when no continuous idle memory pages matched with the memory demand exist in the memory space, determining a target memory page and a neighborhood range of the target memory page; releasing non-idle memory pages within the neighborhood range of the target memory page to obtain a continuous idle memory space; based on the continuous free memory space responding to the memory allocation request, the scheme releases non-free pages in a certain range around the free memory pages to form continuous free memory pages, so that the application requirement of the memory can be met, and the memory allocation efficiency is improved.

Description

Memory allocation method and device, storage medium and electronic equipment
Technical Field
The present application relates to the field of communications technologies, and in particular, to a memory allocation method and apparatus, a storage medium, and an electronic device.
Background
All the programs in the computer are executed in the memory, and the memory is also a medium for temporarily storing the operation data in the central processing unit and exchanging data with an external storage such as an external disk. Therefore, the use of memory has a significant impact on computer performance. This is especially true for embedded terminals, where the Android system is a Linux kernel-based mobile terminal-oriented operating system, and all available memory is limited to system ram.
As the system operates, free frames of memory become scattered over multiple allocation release requests, making it difficult to find physically contiguous frames when memory needs to be allocated. Once too many fragments are generated, even if the total free memory pages meet the demand, the allocation of the memory is low when allocating high-level contiguous memory due to the fact that the needed contiguous memory is not allocated.
Disclosure of Invention
The embodiment of the application provides a memory allocation method, a memory allocation device, a storage medium and an electronic device, which can improve the success rate of memory allocation.
In a first aspect, an embodiment of the present application provides a memory allocation method, including:
when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request;
detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
when no continuous idle memory pages matched with the memory demand exist in the memory space, determining a target memory page and a neighborhood range of the target memory page;
releasing non-idle memory pages within the neighborhood range of the target memory page to obtain a continuous idle memory space;
and responding the memory allocation request based on the continuous free memory space.
In a second aspect, an embodiment of the present application further provides a memory allocation apparatus, including:
the request receiving module is used for determining the memory demand corresponding to the memory allocation request when the memory allocation request is received;
the memory detection module is used for detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
a neighborhood determining module, configured to determine a target memory page and a neighborhood range of the target memory page when there is no continuous idle memory page matching the memory demand in the memory space;
a memory releasing module, configured to release a non-idle memory page within the neighborhood range of the target memory page, so as to obtain a continuous idle memory space;
and the memory allocation module is used for responding the memory allocation request based on the continuous free memory space.
In a third aspect, an embodiment of the present application further provides a storage medium, where a computer program is stored, and when the computer program runs on a computer, the computer is caused to execute the memory allocation method provided in any embodiment of the present application.
In a fourth aspect, an embodiment of the present application further provides an electronic device, which includes a processor and a storage, where the storage has a computer program, and the processor is configured to execute the memory allocation method provided in any embodiment of the present application by calling the computer program.
According to the technical scheme provided by the embodiment of the application, when a memory allocation request is received, the memory demand amount corresponding to the memory allocation request is determined, if it is detected that no continuous idle memory page matched with the memory demand amount exists in a memory space, an idle target memory page and the neighborhood range of the target memory page are determined, non-idle memory pages in the neighborhood range of the target memory page are released, a continuous memory space is obtained, and memory release is performed based on the continuous memory space. By the scheme, when memory allocation is carried out, if continuous idle memory pages capable of meeting the request do not exist in the idle memory space, the service condition of the memory pages around the idle memory pages is checked, and non-idle pages in a certain range around the idle memory pages are released to form continuous idle memory pages, so that the application requirement of a large-block memory is met, and the high-order continuous large-block memory allocation efficiency is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a first flowchart of a memory allocation method according to an embodiment of the present disclosure.
Fig. 2 is a first schematic diagram of memory management in the memory allocation method provided in the present application.
Fig. 3 is a second schematic diagram of memory management in the memory allocation method according to the present application.
Fig. 4 is a second flowchart of the memory allocation method according to the embodiment of the present application.
Fig. 5 is a third schematic diagram of memory management in the memory allocation method according to the present application.
Fig. 6 is a fourth schematic diagram of memory management in the memory allocation method according to the present application.
Fig. 7 is a schematic structural diagram of a memory allocation apparatus according to an embodiment of the present application.
Fig. 8 is a schematic structural diagram of a first electronic device according to an embodiment of the present application.
Fig. 9 is a schematic structural diagram of a second electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without inventive step, are within the scope of the present application.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
An execution main body of the memory allocation method may be the memory allocation device provided in the embodiment of the present application, or an electronic device integrated with the memory allocation device, where the memory allocation device may be implemented in a hardware or software manner. The electronic device may be a smart phone, a tablet computer, a palm computer, a notebook computer, or a desktop computer.
Referring to fig. 1, fig. 1 is a first flowchart illustrating a memory allocation method according to an embodiment of the present disclosure. The specific process of the memory allocation method provided by the embodiment of the application can be as follows:
101. when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request.
When an application program in the electronic device runs, a certain memory space needs to be allocated for a process of the application program. Along with the operation of the system, the memory pages in the memory space generate a plurality of discontinuous and scattered memory pages through a plurality of allocation and release operations, and such memory pages are the memory fragments. And the more memory fragmentation as the runtime of the system is longer. When the amount of memory requested by the process is large, even if the total free memory pages in the memory space meet the requirement, continuous memory cannot be allocated due to the existence of a large amount of memory fragments, so that memory allocation fails, particularly when the process requests high-level memory. At this time, the memory fragments need to be sorted first to obtain a continuous allocable memory space, and then the memory allocation can be continued.
The order (order) of the memory is explained as follows: since memory allocation is typically in accordance with an integral power of 2, e.g., memory with order 2 is allocated, the actual allocation is 4K 22A memory of 16KB, wherein a memory page is 4KB in size. Generally, a request with an order of a memory demand corresponding to a memory allocation request greater than a certain order is called a high-order allocation request, that is, a request is a high-order memory. For example, a memory with order ≧ 2 is referred to as a high-level memory, and vice versa as a low-level memory. Of memory pages corresponding to higher-order memoriesA large number, for example, a process requesting 32KB of memory, requires 8 contiguous memory pages to be allocated. The request may be considered a high-level allocation request.
Because defragmentation requires a certain amount of time, and defragmentation of memory needs to involve relocation of memory page data, which takes a long time, in addition, when some memory pages cannot be relocated (for example, kernel pages), recovery needs to be continued, and if a memory allocation request is received each time, memory allocation can be performed by advanced defragmentation of memory, which results in low memory allocation efficiency.
102. And detecting whether continuous idle memory pages matched with the memory demand exist in the memory space.
According to the scheme of the embodiment of the application, when a memory allocation request is received and the memory demand carried in the memory allocation request is acquired, whether continuous idle memory pages matched with the memory demand exist in the current remaining memory space is detected, wherein when the size of the continuous idle memory pages in the remaining memory space is larger than or equal to the memory demand, it is determined that continuous idle memory pages matched with the memory demand exist in the memory space, and otherwise, it is determined that no continuous idle page memory matched with the memory demand exists in the memory space. The remaining memory space refers to memory space in an unallocated state, for example, 100MB of memory space is total for the electronic device, 60MB of the memory space is already allocated to some processes for use, and the 60MB of memory space is in an allocated state, so that the remaining memory space is 40MB and is in an unallocated state. Non-free memory pages are memory pages that are in an allocated state.
103. When there are no continuous idle memory pages in the memory space that match the memory demand, the target memory page and the neighborhood range of the target memory page are determined.
104. And releasing the non-idle memory pages in the neighborhood range of the target memory page to obtain a continuous idle memory space.
And if the memory space does not have continuous idle memory pages matched with the memory demand, determining the target memory page from the idle memory segments in the memory space.
Referring to fig. 2, fig. 2 is a first schematic diagram of memory management in the memory allocation method of the present application. Each rectangular box represents a memory page, and the number represents the page frame number of the memory page. The grey rectangle boxes indicate that the memory page is occupied, i.e. the memory page is in an allocated state, and the white rectangle boxes indicate that the free memory page is in an unallocated state. Assume that the memory requirement carried in the received memory allocation request is 24KB, i.e. 6 consecutive memory pages are required. However, after the system is operated for a period of time, as shown in the figure, the maximum number of continuous free memory pages is 3, which is insufficient for allocation for the current request. The electronic device takes these free memory pages as target memory pages.
Next, a neighborhood range is determined, where, in some embodiments, neighborhood range N may be a preset fixed value, e.g., preset N-4.
Alternatively, in some embodiments, determining the neighborhood range of the target memory page includes: and calculating the neighborhood range of the target memory page according to the memory demand.
That is, the neighborhood range N may be a value determined according to the memory requirement, for example, N is the number of pages/2 corresponding to the memory requirement. For example, if the current memory demand is 24KB, that is, 6 consecutive memory pages are needed, N is 6/2 is 3. That is, the neighborhood range is 3 memory pages.
And then releasing the memory pages in the range with the neighborhood of the target memory page being 3, namely releasing 3 non-idle memory pages adjacent to the target memory page. In some embodiments, the neighborhood may be a number of adjacent memory pages on one side of the target memory page equal to the neighborhood range. Alternatively, please refer to fig. 3, in which fig. 3 is a second schematic diagram of memory management in the memory allocation method of the present application. In some embodiments, a neighborhood may be a number of adjacent memory pages on either side of a target memory page equal to the neighborhood range.
As shown in fig. 2, the non-idle pages in the neighborhood with the range of 3 of the target memory page formed by three pages with the page frame numbers 12, 13, and 14 are released, and three idle memory pages with the page frame numbers 15, 16, and 17 are obtained. At this time, 12, 13, 14, 15, 16, 17 and 18, 19 constitute 8 consecutive free memory pages, i.e., consecutive free memory spaces.
105. The memory allocation request is responded to based on the continuous free memory space.
After obtaining the above-mentioned continuous free memory space, the memory allocation request may be responded based on 6 pages of the continuous free memory pages with page frame numbers of 12, 13, 14, 15, 16, 17, 18, and 19, for example, 12, 13, 14, 15, 16, and 17 are allocated to the process sending the memory allocation request.
In particular implementation, the present application is not limited by the execution sequence of the described steps, and some steps may be performed in other sequences or simultaneously without conflict.
As can be seen from the above, in the memory allocation method provided in this embodiment of the present application, when a memory allocation request is received, a memory demand corresponding to the memory allocation request is determined, if it is detected that there is no continuous idle memory page matching the memory demand in a memory space, an idle target memory page and a neighborhood range of the target memory page are determined, a non-idle memory page in the neighborhood range of the target memory page is released, a continuous memory space is obtained, and memory release is performed based on the continuous memory space. By the scheme, when memory allocation is carried out, if continuous idle memory pages capable of meeting the request do not exist in the idle memory space, the service condition of the memory pages around the idle memory pages is checked, and non-idle pages in a certain range around the idle memory pages are released to form continuous idle memory pages, so that the application requirement of a large-block memory is met, and the high-order continuous large-block memory allocation efficiency is improved.
In some embodiments, after releasing the non-idle memory pages in the neighborhood range of the target memory page to obtain the continuous idle memory space, the method further includes: judging whether the non-idle memory pages are successfully released or not; if the non-idle page release failure is detected, judging whether the non-idle page successfully released and the target memory page form a continuous idle memory space capable of meeting the memory demand; if yes, responding to the memory allocation request based on the continuous free memory space obtained after the releasing operation; and if not, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained through the memory defragmentation.
Since some non-free memory pages in the memory space cannot be released, e.g., memory pages occupied by the kernel. Therefore, the operation of releasing the non-idle memory pages in the neighborhood range of the target memory page may fail, if after the release operation, it is detected that the non-idle page release fails, it is determined whether the successfully released non-idle page and the target memory page constitute a continuous idle memory space capable of meeting the memory demand, if so, 105 is executed, otherwise, the memory fragmentation in the memory space is sorted, for example, the memory fragmentation sorting thread is awakened to perform the memory fragmentation sorting, so as to obtain a continuous memory space with a size not smaller than the memory demand, and 105 is executed.
In some embodiments, before determining the target memory page and the neighborhood range of the target memory page, further includes: when no continuous idle memory pages matched with the memory demand exist in the memory space, determining an application program corresponding to the memory allocation request; detecting whether the application program is a preset application program or not; if yes, determining a target memory page and a neighborhood range of the target memory page; and if not, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained through the memory defragmentation.
In this embodiment, different memory allocation manners are adopted according to different application programs. When detecting that there is no continuous free memory page matched with the memory demand in the memory space, judging an application program sending the memory allocation request, if the application program is a preset application program, acquiring the continuous free memory space by adopting a mode of releasing non-free memory pages around a target memory page, and if the application program is not the preset application program, acquiring the continuous free memory space by adopting a memory defragmentation mode. Part of the application programs can be selected as preset application programs according to needs, for example, application programs such as a camera, a WeChat and a browser are set as the preset application programs.
The method according to the preceding embodiment is illustrated in further detail below by way of example.
Referring to fig. 4, fig. 4 is a second flow chart of the memory allocation method according to the embodiment of the invention.
The method comprises the following steps:
201. when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request.
According to the scheme of the embodiment of the application, when the memory allocation request is received and the memory demand carried in the memory allocation request is obtained, the memory demand carried in the memory allocation request is obtained.
202. And detecting whether the current free memory amount is larger than or equal to a preset threshold value.
Then, before memory allocation, whether the current free memory amount is larger than or equal to a preset threshold value is detected, and if not, memory recovery is carried out. The preset threshold is a memory waterline of the system, and the memory waterline is used for ensuring that the system has enough memory space for operation.
If the current free memory amount is larger than or equal to a preset threshold value, executing 203;
203. detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
204. and when no continuous free memory page matched with the memory demand exists in the memory space, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained by the memory defragmentation.
When the free memory amount is larger than the preset threshold value, directly detecting whether continuous free memory pages matched with the memory demand amount exist in the memory space, if so, directly performing memory allocation, and if not, performing memory defragmentation, for example, moving the data of non-free pages adjacent to one free memory segment to other free pages to obtain a plurality of continuous free pages, which can meet the memory allocation at this time.
205. And if the current idle memory amount is smaller than the preset threshold value, performing memory recovery based on the memory allocation linked list to obtain the idle memory amount larger than or equal to the preset threshold value.
If the current free memory amount is smaller than a preset threshold, for example, the preset threshold is 200MB, and the current free memory amount is only 100MB, advanced memory recycling is performed, and the free memory amount after the recycling operation is not smaller than the preset threshold, for example, 100MB of memory is recycled, so that the free memory amount reaches 200 MB.
Referring to fig. 5, fig. 5 is a third schematic diagram illustrating memory management in the memory allocation method according to the present application. Assume that the memory requirement carried in the received memory allocation request is 24KB, i.e. 6 consecutive memory pages are required. Assuming that the predetermined threshold is 28KB and the current free memory amount is only 20KB, 8KB of memory needs to be recycled. After recycling, as shown in fig. 5, memory pages with page frame numbers of 5 and 14 are obtained.
206. And detecting whether continuous idle memory pages matched with the memory demand exist in the memory space.
207. And when no continuous idle memory pages matched with the memory demand exist in the memory space, taking the memory pages released by the memory recovery operation as target memory pages, and determining the neighborhood range of the target memory pages.
208. And releasing the non-idle memory pages in the neighborhood range of the target memory page to obtain a continuous idle memory space.
And after memory pages with page frame numbers of 5 and 14 are obtained, detecting whether continuous idle memory pages matched with the memory demand exist in the memory space, and if so, responding to the memory allocation request based on the continuous idle memory pages. Otherwise, the memory pages 5 and 14 just released and the continuous idle memory pages around the memory pages are respectively used as the target memory pages, and the memory pages in the neighborhood range are released. Please refer to the above embodiments, which are not described herein.
209. And judging whether the continuous free memory space meets the memory demand.
210. And if so, responding to the memory allocation request based on the continuous free memory space.
211. And if not, performing memory defragmentation based on the memory demand to obtain a continuous free memory space capable of meeting the memory demand.
212. The memory allocation request is responded based on the continuous free memory space obtained through the memory defragmentation.
After the release operation, it is determined whether the continuous free memory space obtained after the release operation satisfies the memory demand, as shown in fig. 5, 12, 13, 14, 15, 16, 17, 18, and 19, which are obtained after the release operation, constitute 8 continuous free memory pages, and can satisfy the memory demand. However, in some other cases, even after the release, the obtained continuous free memory space still does not meet the memory requirement, as shown in fig. 6, it is assumed that the process requests 8 memory pages, but after the release, the maximum continuous free memory pages are only 6. At this time, the memory can be defragmented to obtain a continuous free memory space which can meet the memory demand, and then memory allocation is performed.
As can be seen from the above, in the memory allocation method provided in the embodiment of the present invention, when performing memory allocation, if there is no continuous idle memory page that can satisfy the request in the idle memory space, the usage of the memory pages around the idle memory page is checked, and non-idle pages in a certain range around the idle memory page are released to form continuous idle memory pages, so as to satisfy the application requirement of the large block of memory and improve the efficiency of high-order continuous large block of memory allocation.
In one embodiment, a memory allocation apparatus is also provided. Referring to fig. 7, fig. 7 is a schematic structural diagram of a memory allocation apparatus 300 according to an embodiment of the present disclosure. The memory allocation apparatus 300 is applied to an electronic device, and the memory allocation apparatus 300 includes a request receiving module 301, a memory detecting module 302, a neighborhood determining module 303, a memory releasing module 304, and a memory allocating module 305, as follows:
a request receiving module 301, configured to determine, when a memory allocation request is received, a memory demand corresponding to the memory allocation request;
a memory detection module 302, configured to detect whether there are consecutive idle memory pages in a memory space that match the memory demand;
a neighborhood determining module 303, configured to determine a target memory page and a neighborhood range of the target memory page when there is no continuous idle memory page matching the memory demand in the memory space;
a memory releasing module 304, configured to release a non-idle memory page in the neighborhood range of the target memory page, so as to obtain a continuous idle memory space;
a memory allocation module 305, configured to respond to the memory allocation request based on the continuous free memory space.
In some embodiments, the memory detection module 302 is further configured to: when a memory allocation request is received, after the memory demand corresponding to the memory allocation request is determined, whether the current idle memory amount is larger than or equal to a preset threshold value is detected;
the memory allocation apparatus 300 further includes a memory recycling module, and the memory recycling module is further configured to: performing memory recovery based on a memory allocation linked list to obtain an idle memory amount larger than or equal to the preset threshold;
neighborhood determination module 303 is further operable to: and taking the memory page released by the memory recovery operation as a target memory page.
In some embodiments, the memory allocation apparatus 300 further includes a first sorting module;
the memory detection module 302 is further configured to: if the current free memory amount is larger than or equal to a preset threshold value, detecting whether continuous free memory pages matched with the memory demand amount exist in the memory space;
the first sorting module is used for: when no continuous idle memory pages matched with the memory demand exist in the memory space, performing memory defragmentation based on the memory demand;
the memory allocation module 305 is further configured to: and responding the memory allocation request based on the continuous free memory space obtained by memory defragmentation.
In some embodiments, neighborhood determination module 303 is further configured to: and calculating the neighborhood range of the target memory page according to the memory demand.
In some embodiments, the memory allocation apparatus 300 further includes a second sorting module;
the memory detection module 302 is further configured to: after the memory releasing module 304 releases the non-idle memory pages in the neighborhood range of the target memory page to obtain a continuous idle memory space, determining whether the continuous idle memory space meets the memory demand;
the memory allocation module 305 is further configured to: if the continuous free memory space meets the memory demand, responding to the memory allocation request based on the continuous free memory space;
if the continuous free memory space does not meet the memory demand, a second sorting module performs memory defragmentation based on the memory demand to obtain the continuous free memory space capable of meeting the memory demand;
the memory allocation module 305 is further configured to: and responding the memory allocation request based on the continuous free memory space obtained by memory defragmentation.
In some embodiments, the memory allocation apparatus 300 further includes a third sorting module;
the memory release module 304 is further configured to: judging whether the non-idle memory page is released successfully or not; if the non-idle page release failure is detected, judging whether the successfully released non-idle page and the target memory page form a continuous idle memory space capable of meeting the memory demand;
the memory allocation module 305 is further configured to: if yes, responding to the memory allocation request based on the continuous free memory space obtained after the releasing operation;
the third arrangement module is used for: if not, performing memory defragmentation based on the memory demand;
the memory allocation module 305 is further configured to: and responding the memory allocation request based on the continuous free memory space obtained by memory defragmentation.
In some embodiments, the memory allocation device 300 further comprises a program identification module;
the program identification module is used for: when no continuous idle memory pages matched with the memory demand exist in the memory space, determining an application program corresponding to the memory allocation request; detecting whether the application program is a preset application program or not;
neighborhood determination module 303 is further operable to: when the application program is a preset application program, determining a target memory page and a neighborhood range of the target memory page.
In specific implementation, the above modules may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and specific implementation of the above modules may refer to the foregoing method embodiments, which are not described herein again.
It should be noted that the memory allocation device provided in the embodiment of the present application and the memory allocation method in the foregoing embodiment belong to the same concept, and any method provided in the embodiment of the memory allocation method may be executed on the memory allocation device, and a specific implementation process thereof is described in detail in the embodiment of the memory allocation method, and is not described herein again.
As can be seen from the above, the memory allocation device provided in this embodiment of the present application determines, when a memory allocation request is received, a memory demand amount corresponding to the memory allocation request, determines, if it is detected that there is no continuous idle memory page matching the memory demand amount in a memory space, an idle target memory page and a neighborhood range of the target memory page, releases a non-idle memory page within the neighborhood range of the target memory page, obtains a continuous memory space, and releases a memory based on the continuous memory space. By the scheme, when memory allocation is carried out, if continuous idle memory pages capable of meeting the request do not exist in the idle memory space, the service condition of the memory pages around the idle memory pages is checked, and non-idle pages in a certain range around the idle memory pages are released to form continuous idle memory pages, so that the application requirement of a large-block memory is met, and the high-order continuous large-block memory allocation efficiency is improved.
The embodiment of the application also provides the electronic equipment. The electronic device can be a smart phone, a tablet computer and the like. Referring to fig. 8, fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure. The electronic device 400 comprises a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.
The processor 401 is a control center of the electronic device 400, connects various parts of the entire electronic device using various interfaces and lines, and performs various functions of the electronic device and processes data by running or calling a computer program stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the electronic device.
Memory 402 may be used to store computer programs and data. The memory 402 stores computer programs containing instructions executable in the processor. The computer program may constitute various functional modules. The processor 401 executes various functional applications and data processing by calling a computer program stored in the memory 402. The memory 402 includes an internal memory providing a memory space for the operation of the electronic device and an external memory, which is a memory other than a computer memory and a CPU cache, and such memories can still store data after being powered off, such as a hard disk, a floppy disk, and a usb disk.
In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to one or more processes of the computer program into the memory 402 according to the following steps, and the processor 401 runs the computer program stored in the memory 402, so as to implement various functions:
when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request;
detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
when no continuous idle memory pages matched with the memory demand exist in the memory space, determining a target memory page and a neighborhood range of the target memory page;
releasing non-idle memory pages within the neighborhood range of the target memory page to obtain a continuous idle memory space;
and responding the memory allocation request based on the continuous free memory space.
In some embodiments, please refer to fig. 9, and fig. 9 is a second structural diagram of an electronic device according to an embodiment of the present disclosure. The electronic device 400 further comprises: radio frequency circuit 403, display 404, control circuit 405, input unit 406, audio circuit 407, sensor 408, and power supply 409. The processor 401 is electrically connected to the radio frequency circuit 403, the display 404, the control circuit 405, the input unit 406, the audio circuit 407, the sensor 408, and the power source 409.
The radio frequency circuit 403 is used for transceiving radio frequency signals to communicate with a network device or other electronic devices through wireless communication.
The display screen 404 may be used to display information entered by or provided to the user as well as various graphical user interfaces of the electronic device, which may be comprised of images, text, icons, video, and any combination thereof.
The control circuit 405 is electrically connected to the display screen 404, and is configured to control the display screen 404 to display information.
The input unit 406 may be used to receive input numbers, character information, or user characteristic information (e.g., fingerprint), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control. The input unit 406 may include a fingerprint recognition module.
The audio circuit 407 may provide an audio interface between the user and the electronic device through a speaker, microphone. Wherein the audio circuit 407 comprises a microphone. The microphone is electrically connected to the processor 401. The microphone is used for receiving voice information input by a user.
The sensor 408 is used to collect external environmental information. The sensors 408 may include one or more of ambient light sensors, acceleration sensors, gyroscopes, etc.
The power supply 409 is used to power the various components of the electronic device 400. In some embodiments, the power source 409 may be logically connected to the processor 401 through a power management system, so that functions of managing charging, discharging, and power consumption are implemented through the power management system.
Although not shown in fig. 9, the electronic device 400 may further include a camera, a bluetooth module, and the like, which are not described in detail herein.
In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to one or more processes of the computer program into the memory 402 according to the following steps, and the processor 401 runs the computer program stored in the memory 402, so as to implement various functions:
when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request;
detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
when no continuous idle memory pages matched with the memory demand exist in the memory space, determining a target memory page and a neighborhood range of the target memory page;
releasing non-idle memory pages within the neighborhood range of the target memory page to obtain a continuous idle memory space;
and responding the memory allocation request based on the continuous free memory space.
As can be seen from the above, an embodiment of the present application provides an electronic device, where the electronic device determines a memory demand amount corresponding to a memory allocation request when receiving the memory allocation request, determines an idle target memory page and a neighborhood range of the target memory page if it is detected that there is no continuous idle memory page matching the memory demand amount in a memory space, releases a non-idle memory page within the neighborhood range of the target memory page, obtains a continuous memory space, and releases a memory based on the continuous memory space. By the scheme, when memory allocation is carried out, if continuous idle memory pages capable of meeting the request do not exist in the idle memory space, the service condition of the memory pages around the idle memory pages is checked, and non-idle pages in a certain range around the idle memory pages are released to form continuous idle memory pages, so that the application requirement of a large-block memory is met, and the high-order continuous large-block memory allocation efficiency is improved.
An embodiment of the present application further provides a storage medium, where a computer program is stored in the storage medium, and when the computer program runs on a computer, the computer executes the memory allocation method according to any of the above embodiments.
It should be noted that, all or part of the steps in the methods of the above embodiments may be implemented by hardware related to instructions of a computer program, which may be stored in a computer-readable storage medium, which may include, but is not limited to: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Furthermore, the terms "first", "second", and "third", etc. in this application are used to distinguish different objects, and are not used to describe a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or modules is not limited to only those steps or modules listed, but rather, some embodiments may include other steps or modules not listed or inherent to such process, method, article, or apparatus.
The memory allocation method, the memory allocation device, the storage medium and the electronic device provided by the embodiments of the present application are described in detail above. The principle and the implementation of the present application are explained herein by applying specific examples, and the above description of the embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (10)

1. A method for allocating memory, comprising:
when a memory allocation request is received, determining the memory demand corresponding to the memory allocation request;
detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
when no continuous idle memory pages matched with the memory demand exist in the memory space, determining a target memory page and a neighborhood range of the target memory page;
releasing non-idle memory pages within the neighborhood range of the target memory page to obtain a continuous idle memory space;
and responding the memory allocation request based on the continuous free memory space.
2. The memory allocation method according to claim 1, wherein after determining the memory demand amount corresponding to the memory allocation request when the memory allocation request is received, the method further comprises:
detecting whether the current free memory amount is larger than or equal to a preset threshold value or not;
if not, performing memory recovery based on a memory allocation linked list to obtain an idle memory amount larger than or equal to the preset threshold value, and performing detection on whether continuous idle memory pages matched with the memory demand amount exist in the memory space;
the determining the target memory page includes:
and taking the memory page released by the memory recovery operation as a target memory page.
3. The method according to claim 2, wherein after detecting whether the current amount of free memory is greater than or equal to a preset threshold, the method further comprises:
if yes, detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
and when no continuous free memory page matched with the memory demand exists in the memory space, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained through the memory defragmentation.
4. The method according to claim 1, wherein the determining the neighborhood range of the target memory page comprises:
and calculating the neighborhood range of the target memory page according to the memory demand.
5. The method according to claim 1, wherein after releasing the non-free memory pages in the neighborhood range of the target memory page to obtain a continuous free memory space, the method further comprises:
judging whether the continuous free memory space meets the memory demand quantity;
if yes, executing the memory allocation request responding based on the continuous free memory space;
if not, performing memory defragmentation based on the memory demand to obtain a continuous free memory space capable of meeting the memory demand;
and responding the memory allocation request based on the continuous free memory space obtained by memory defragmentation.
6. The method according to claim 1, wherein after releasing the non-free memory pages in the neighborhood range of the target memory page to obtain a continuous free memory space, the method further comprises:
judging whether the non-idle memory page is released successfully or not;
if the non-idle page release failure is detected, judging whether the non-idle page successfully released and the target memory page form a continuous idle memory space capable of meeting the memory demand;
if yes, responding to the memory allocation request based on the continuous free memory space obtained after the releasing operation;
and if not, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained through the memory defragmentation.
7. The memory allocation method according to any one of claims 1 to 6, wherein before determining the target memory page and the neighborhood range of the target memory page, further comprising:
when no continuous idle memory pages matched with the memory demand exist in the memory space, determining an application program corresponding to the memory allocation request;
detecting whether the application program is a preset application program or not;
if yes, determining a target memory page and a neighborhood range of the target memory page;
and if not, performing memory defragmentation based on the memory demand, and responding to the memory allocation request based on the continuous free memory space obtained through the memory defragmentation.
8. A memory allocation apparatus, comprising:
the request receiving module is used for determining the memory demand corresponding to the memory allocation request when the memory allocation request is received;
the memory detection module is used for detecting whether continuous idle memory pages matched with the memory demand exist in the memory space;
a neighborhood determining module, configured to determine a target memory page and a neighborhood range of the target memory page when there is no continuous idle memory page matching the memory demand in the memory space;
a memory releasing module, configured to release a non-idle memory page within the neighborhood range of the target memory page, so as to obtain a continuous idle memory space;
and the memory allocation module is used for responding the memory allocation request based on the continuous free memory space.
9. A storage medium having stored thereon a computer program, characterized in that, when the computer program runs on a computer, it causes the computer to execute the memory allocation method according to any one of claims 1 to 7.
10. An electronic device comprising a processor and a memory, the memory storing a computer program, wherein the processor is configured to execute the memory allocation method according to any one of claims 1 to 7 by calling the computer program.
CN201911261643.0A 2019-12-10 2019-12-10 Memory allocation method and device, storage medium and electronic equipment Active CN111078587B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911261643.0A CN111078587B (en) 2019-12-10 2019-12-10 Memory allocation method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911261643.0A CN111078587B (en) 2019-12-10 2019-12-10 Memory allocation method and device, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN111078587A true CN111078587A (en) 2020-04-28
CN111078587B CN111078587B (en) 2022-05-06

Family

ID=70313994

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911261643.0A Active CN111078587B (en) 2019-12-10 2019-12-10 Memory allocation method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111078587B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590509A (en) * 2020-04-30 2021-11-02 华为技术有限公司 Page exchange method, storage system and electronic equipment
CN113986559A (en) * 2021-12-24 2022-01-28 荣耀终端有限公司 Memory management method and related device
CN114564315A (en) * 2022-03-15 2022-05-31 维沃移动通信有限公司 Memory allocation method and device, electronic equipment and medium
CN117724991A (en) * 2023-12-21 2024-03-19 北京凯思昊鹏软件工程技术有限公司 Dynamic memory management method, system, terminal and storage medium of embedded system

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101093455A (en) * 2006-06-21 2007-12-26 中兴通讯股份有限公司 Allocation method for internal memory pool in embedded type operation system
CN101976224A (en) * 2010-10-13 2011-02-16 清华大学 Memory management method of embedded system
US20110113195A1 (en) * 2009-11-10 2011-05-12 Guy Riddle Systems and methods for avoiding performance degradation due to disk fragmentation in a network caching device
CN102122268A (en) * 2010-01-07 2011-07-13 华为技术有限公司 Virtual machine memory allocation access method, device and system
CN102289453A (en) * 2011-06-20 2011-12-21 北京星网锐捷网络技术有限公司 TCAM (ternary content addressable memory) rule storing method, device and network equipment
CN104375899A (en) * 2014-11-21 2015-02-25 北京应用物理与计算数学研究所 Thread for high-performance computer NUMA perception and memory resource optimizing method and system
CN105446814A (en) * 2014-09-30 2016-03-30 青岛海信移动通信技术股份有限公司 Cache recovery method and device
CN105975398A (en) * 2015-12-07 2016-09-28 国家电网公司 Method for memory fragmentation management
CN106294190A (en) * 2015-05-25 2017-01-04 中兴通讯股份有限公司 A kind of memory space management and device
US20190018595A1 (en) * 2017-07-17 2019-01-17 International Business Machines Corporation Avoid out of space outage in a thinly provisioned box
CN109992402A (en) * 2017-12-29 2019-07-09 广东欧珀移动通信有限公司 Internal memory processing method and device, electronic equipment, computer readable storage medium
CN110209595A (en) * 2018-02-28 2019-09-06 贵州白山云科技股份有限公司 A kind of method and device for managing internal memory page

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101093455A (en) * 2006-06-21 2007-12-26 中兴通讯股份有限公司 Allocation method for internal memory pool in embedded type operation system
US20110113195A1 (en) * 2009-11-10 2011-05-12 Guy Riddle Systems and methods for avoiding performance degradation due to disk fragmentation in a network caching device
CN102122268A (en) * 2010-01-07 2011-07-13 华为技术有限公司 Virtual machine memory allocation access method, device and system
CN101976224A (en) * 2010-10-13 2011-02-16 清华大学 Memory management method of embedded system
CN102289453A (en) * 2011-06-20 2011-12-21 北京星网锐捷网络技术有限公司 TCAM (ternary content addressable memory) rule storing method, device and network equipment
CN105446814A (en) * 2014-09-30 2016-03-30 青岛海信移动通信技术股份有限公司 Cache recovery method and device
CN104375899A (en) * 2014-11-21 2015-02-25 北京应用物理与计算数学研究所 Thread for high-performance computer NUMA perception and memory resource optimizing method and system
CN106294190A (en) * 2015-05-25 2017-01-04 中兴通讯股份有限公司 A kind of memory space management and device
CN105975398A (en) * 2015-12-07 2016-09-28 国家电网公司 Method for memory fragmentation management
US20190018595A1 (en) * 2017-07-17 2019-01-17 International Business Machines Corporation Avoid out of space outage in a thinly provisioned box
CN109992402A (en) * 2017-12-29 2019-07-09 广东欧珀移动通信有限公司 Internal memory processing method and device, electronic equipment, computer readable storage medium
CN110209595A (en) * 2018-02-28 2019-09-06 贵州白山云科技股份有限公司 A kind of method and device for managing internal memory page

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
孙凌宇: "一种基于多哈希表的堆式动态存储管理方法", 《井冈山师范学院学报》 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590509A (en) * 2020-04-30 2021-11-02 华为技术有限公司 Page exchange method, storage system and electronic equipment
WO2021218502A1 (en) * 2020-04-30 2021-11-04 华为技术有限公司 Page swapping method, storage system, and electronic device
CN113590509B (en) * 2020-04-30 2024-03-26 华为技术有限公司 Page exchange method, storage system and electronic equipment
CN113986559A (en) * 2021-12-24 2022-01-28 荣耀终端有限公司 Memory management method and related device
CN114564315A (en) * 2022-03-15 2022-05-31 维沃移动通信有限公司 Memory allocation method and device, electronic equipment and medium
CN117724991A (en) * 2023-12-21 2024-03-19 北京凯思昊鹏软件工程技术有限公司 Dynamic memory management method, system, terminal and storage medium of embedded system

Also Published As

Publication number Publication date
CN111078587B (en) 2022-05-06

Similar Documents

Publication Publication Date Title
CN111078587B (en) Memory allocation method and device, storage medium and electronic equipment
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
CN111078406B (en) Memory management method and device, storage medium and electronic equipment
CN110888746B (en) Memory management method and device, storage medium and electronic equipment
EP3514684B1 (en) Memory recovery method and apparatus
KR102114388B1 (en) Method and apparatus for compressing memory of electronic device
CN111078410B (en) Memory allocation method and device, storage medium and electronic equipment
CN111475299B (en) Memory allocation method and device, storage medium and electronic equipment
CN114096953A (en) Memory management method and device, electronic equipment and computer readable medium
US20140013032A1 (en) Method and apparatus for controlling writing data in storage unit based on nand flash memory
CN111274039B (en) Memory recycling method and device, storage medium and electronic equipment
EP3926466A1 (en) Electronic device which prefetches application and method therefor
CN111078586B (en) Memory recovery method and device, storage medium and electronic equipment
KR101598727B1 (en) Techniques for moving data between memory types
CN108073358B (en) User equipment including storage device and trimming management method of storage device
WO2019196878A1 (en) Method for memory management and related device
CN112445766A (en) Terminal fragment sorting method and device and terminal
EP4328705A1 (en) Storage space arrangement method and electronic device
CN111309267A (en) Storage space allocation method and device, storage equipment and storage medium
CN113625973A (en) Data writing method and device, electronic equipment and computer readable storage medium
CN113590509A (en) Page exchange method, storage system and electronic equipment
CN110609748A (en) Memory allocation method, electronic equipment and storage medium
CN111338745A (en) Deployment method and device of virtual machine and intelligent equipment
WO2019128542A1 (en) Application processing method, electronic device, computer readable storage medium
CN109561134B (en) Electronic device, distributed cluster service distribution method and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant