Memory management method and device, equipment and storage medium
By adding hot identification to the call stack in each process and allocating memory access addresses based on these identifications, the problem of insufficient memory management accuracy in the prior art is solved, and more refined memory management and higher memory utilization efficiency are achieved.
Patent Information
- Application Number
- CN202311815996.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2025-06-27
AI Technical Summary
In the prior art, the memory management method has poor accuracy, especially when the random arrangement and number of accesses of memory pages are close to the preset number, it is easy to cause the memory page that has just been recycled to be called again.
By obtaining memory access information for each process within a preset time, the number of accesses of its allocated target access address is determined for each call stack, and a heat identification is added to the call stack based on these access times. In response to the memory call request of the call stack, the memory access address is allocated from the corresponding memory area according to its heat.
Improve the accuracy of memory management. By managing the call stack in each process as a dimension, the granularity of memory management is refined, and the probability that the memory page that has just been recycled is called again is reduced.
Smart Images

Figure CN120216152A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the technical field of electronic devices, and in particular, to a memory management method, apparatus, device, and storage medium. Background Art
[0002] When starting a process of an application, memory needs to be allocated for the process. When the memory is insufficient, the running speed of the process will be affected, resulting in the application becoming stuck. Therefore, in order to achieve reasonable allocation and recycling of memory, the memory of the electronic device needs to be managed.
[0003] In the related art, the methods for memory management include: establishing a memory hot and cold linked list according to the access times of memory pages. Among them, the hot linked list includes multiple memory pages with access times greater than a preset number of times, and the cold linked list includes multiple memory pages with access times less than the preset number of times. When the memory is tight, the memory pages in the cold linked list are recycled.
[0004] However, the inventors found that the prior art has at least the following technical problems: Since the multiple memory pages on the same cold linked list are randomly arranged, some memory pages with access times close to the preset number of times may be recycled preferentially, and in this way, it is easy to have the situation where the just recycled memory pages are called again. Therefore, the accuracy of the memory management method in the prior art is relatively poor. Summary of the Invention
[0005] Embodiments of the present disclosure provide a memory management method, apparatus, device, and storage medium, which can improve the accuracy of memory management.
[0006] In a first aspect, embodiments of the present disclosure provide a memory management method, which is applied to an electronic device. At least one process runs in the electronic device, and each process includes multiple call stacks. The method includes:
[0007] Obtain the memory access information of each process within a preset time period. The memory access information includes the access times respectively corresponding to multiple memory access addresses;
[0008] For each call stack corresponding to the process, determine the access times of multiple target access addresses allocated to the call stack, and add a heat mark to the call stack according to the access times of the multiple target access addresses, where the heat mark is used to represent the call frequency of the call stack;
[0009] In response to a memory call request of any call stack, allocate a memory access address for the call stack from the memory area corresponding to the heat mark according to the heat mark corresponding to the call stack.
[0010] Second aspect, embodiments of the present disclosure provide a memory management device, which is applied to an electronic device. At least one process runs in the electronic device, and each process includes multiple call stacks. The device includes:
[0011] An acquisition module, configured to acquire the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to multiple memory access addresses;
[0012] A determination module, configured to, for each call stack corresponding to the process, determine the access times of multiple target access addresses allocated to the call stack, and add a heat mark to the call stack according to the access times of the multiple target access addresses, where the heat mark is used to characterize the call frequency of the call stack;
[0013] An allocation module, configured to, in response to a memory call request of any call stack, allocate a memory access address for the call stack from the memory area corresponding to the heat mark according to the heat mark corresponding to the call stack.
[0014] Third aspect, embodiments of the present disclosure provide an electronic device, including:
[0015] A processor and a memory communicatively connected to the processor;
[0016] The memory stores computer execution instructions;
[0017] The processor executes the computer execution instructions stored in the memory to implement the memory management method as described in the first aspect above.
[0018] Fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium, in which computer execution instructions are stored. When the processor executes the computer execution instructions, the memory management method as described in the first aspect above is implemented.
[0019] Fifth aspect, embodiments of the present disclosure provide a computer program product, including a computer program, where when the computer program is executed by a processor, the memory management method as described in the first aspect above is implemented.
[0020] The memory management method, apparatus, device, and storage medium provided in this embodiment include: obtaining the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to multiple memory access addresses; for each call stack corresponding to a process, determining the access times of multiple target access addresses allocated to the call stack, and adding a heat mark to the call stack according to the access times of the multiple target access addresses, where the heat mark is used to represent the call frequency of the call stack; in response to a memory call request of any call stack, allocating a memory access address for the call stack from the memory area corresponding to the heat mark according to the heat mark corresponding to the call stack. In the embodiments of the present application, since cold and hot marks are added to multiple call stacks in each process, in this way, when calling a certain call stack, a memory address is directly allocated from the memory pool corresponding to the cold and hot marks, realizing memory management with each call stack in a process as a dimension, thereby improving the accuracy of memory management. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are some embodiments of the present disclosure. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0022] Figure 1 It is a schematic diagram of an application scenario of a memory management method provided in an embodiment of the present disclosure;
[0023] Figure 2 It is a flowchart of a memory management method provided in an embodiment of the present disclosure;
[0024] Figure 3 It is a schematic diagram of a method for obtaining memory access information provided in an embodiment of the present disclosure;
[0025] Figure 4 It is a schematic diagram of a memory management method provided in an embodiment of the present disclosure;
[0026] Figure 5 It is a block diagram of the structure of a memory management apparatus provided in an embodiment of the present disclosure;
[0027] Figure 6 It is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0028] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without making creative efforts shall fall within the protection scope of the present disclosure.
[0029] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards, and corresponding operation entrances are provided for users to choose to authorize or reject.
[0030] Currently, multiple application programs are generally installed on an electronic device. When starting the process of a certain application program, memory needs to be allocated for the process of this application program. When the memory is insufficient, it will affect the running speed of the process, resulting in the application program becoming stuck. Therefore, in order to achieve reasonable allocation and recycling of memory, the memory of the electronic device needs to be managed.
[0031] In the related art, the memory is managed through a hot-cold linked list. The specific method includes: establishing a hot-cold linked list of memory according to the access times of memory pages. Among them, the hot (active) linked list includes multiple memory pages with access times greater than a preset number, and the cold (inactive) linked list includes multiple memory pages with access times less than this preset number. When the memory is in short supply, the memory pages in the cold linked list are recycled. During recycling, the memory pages in the hot (active) linked list are migrated to the cold (inactive) linked list, and the memory pages in the cold linked list are swapped out or released to achieve dynamic memory recycling.
[0032] However, since multiple memory pages on the same cold linked list are randomly arranged, some memory pages with access times close to the preset number may be recycled preferentially, and it is easy to have the situation where the just-recycled memory pages are called again. Moreover, a memory page includes multiple memory access addresses, and the access times of the memory access addresses within the same memory page may also be different. Therefore, some memory pages include both hot (active) memory access addresses and cold (inactive) memory access addresses, resulting in poor accuracy of the memory management method in the prior art.
[0033] Therefore, it can be seen that how to reasonably allocate and recycle memory to improve the accuracy of memory management is an urgent problem to be solved currently.
[0034] To solve the above problems, the present embodiment provides the following technical concept: manage the memory based on the call stack in each process, refine the granularity of memory management, and thus improve the accuracy of memory management.
[0035] The specific steps may include: First, obtain the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to multiple memory access addresses. Then, for each call stack corresponding to the process, determine the access times of multiple target access addresses allocated to the call stack, and add a heat label to the call stack according to the access times of the multiple target access addresses, where the heat label is used to represent the call frequency of the call stack. Finally, in response to a memory call request of any call stack, allocate a memory access address for the call stack from the memory area corresponding to the heat label according to the heat label corresponding to the call stack.
[0036] Here, since for each process, cold and hot labels are added to multiple call stacks in the process, in this way, when calling a certain call stack, directly allocate a memory address from the memory pool corresponding to the cold and hot labels, realizing memory management based on the call stack in each process, thereby improving the accuracy of memory management.
[0037] The application scenario of the present disclosure embodiment is explained below:
[0038] The memory management method provided by the present disclosure embodiment can be applied to the scenario of managing the system memory of an electronic device. Figure 1 It is a schematic diagram of the application scenario of a memory management method provided by the present disclosure embodiment. As Figure 1 shown, the system memory of the electronic device can be divided into a first memory pool 101 and a second memory pool 102. The memory access addresses corresponding to the hot label (active) memory stacks can be stored in the first memory pool 101. The memory access addresses corresponding to the cold label (inactive) memory stacks can be stored in the second memory pool 102. Thus, it is convenient to manage the system memory based on the memory access addresses of the call stacks, refine the granularity of memory management, and thus improve the accuracy of memory management. The memory management method provided by the present disclosure embodiment is described in detail below with detailed embodiments.
[0039] Figure 2 It is a flowchart of a memory management method provided by the present disclosure embodiment. The memory management method is applied to an electronic device in which at least one process is running, and each process includes multiple call stacks. As Figure 2 shown, the method includes:
[0040] S201. Obtain the memory access information of each process within a preset duration, where the memory access information includes the number of accesses corresponding to each of multiple memory access addresses respectively.
[0041] In the embodiments of the present disclosure, the preset duration can be a set time period or the life cycle of the process. Among them, the life cycle of the process includes: the time period from the start of the process to the stop of the process. Among them, the stop of the process can be the exit of the process or the suspension of the process. Exemplarily, as Figure 3 shown, the stop of the process is to suspend the operation of the process. After the process starts, a call stack can be opened to implement a certain function (for example, displaying a chat interface). Among them, when opening the call stack, a memory access address will be applied, and the data required by the call stack is called through the memory access address.
[0042] In some embodiments, continue to refer to Figure 3 , the number of accesses to the memory access address can be counted through a hook function. Correspondingly, obtaining the memory access information of each process within a preset duration may include: for each process, obtaining the memory allocation requests of multiple call stacks corresponding to the process received within the preset duration, allocating memory access addresses to each function in each call stack; calling the hook function, and counting the number of accesses to the memory access addresses corresponding to each function in each call stack through the hook function; establishing a mapping relationship between the memory access address and the number of accesses to obtain the memory access information of the process. It should be noted that the call stack can include a memory allocation call stack and a memory access call stack. Among them, the memory allocation call stack is used to record the source of memory allocation, and the memory access call stack is used to count the number of address accesses. For example, by inserting a hook function into the memory access call stack, the counting of the number of address accesses is realized.
[0043] Exemplarily, the memory access address can be represented by addr, and the number of accesses can be represented by count. The mapping relationship between the memory access address and the number of accesses can be expressed as (addr, count).
[0044] It should be noted that the method of counting the address allocation information and access information can also be through the object (object-oriented programming) dimension in addition to the call stack dimension. The embodiments of the present disclosure do not specifically limit the method of counting the address allocation information and access information.
[0045] S202. For each call stack corresponding to the process, determine the number of accesses to the multiple target access addresses allocated by the call stack, and add a heat label to the call stack according to the number of accesses to the multiple target access addresses, where the heat label is used to characterize the call frequency of the call stack.
[0046] In an embodiment of the present disclosure, a mapping relationship between a process identifier, a call stack identifier, and multiple access addresses can be stored in an electronic device. Correspondingly, for each call stack corresponding to a process, determining the access times of multiple target access addresses allocated to the call stack can include: for each call stack corresponding to a process, according to the process identifier of the process and the call stack identifier of the call stack, determining multiple target access addresses allocated to the call stack from the stored mapping relationship between the process identifier, the call stack identifier, and the multiple access addresses; for each target access address, determining the access times of the target access address from the memory access information including the access times respectively corresponding to the multiple memory access addresses.
[0047] Among them, the more the access times of a target access address are, the higher the call frequency of the call stack is. On the contrary, the fewer the access times of the target access address are, the lower the call frequency of the call stack is.
[0048] Optionally, as Figure 3 shown, after a process is started in an electronic device, the memory allocation information of each call stack can be recorded, and a mapping relationship between a process identifier, a call stack identifier, and multiple access addresses can be established.
[0049] In some embodiments, the access times of multiple target access addresses corresponding to a call stack are similar. Correspondingly, adding a heat identifier to the call stack according to the access times of the multiple target access addresses includes: if the access times of the multiple target access addresses are all greater than a first preset number of times, adding a first identifier to the call stack; if the access times of the multiple target access addresses are all less than a second preset number of times, adding a second identifier to the call stack; where the call frequency corresponding to the first identifier is greater than the call frequency corresponding to the second identifier.
[0050] Exemplarily, as Figure 4 shown, the first identifier is a hot (HOT) identifier, and the second identifier is a cold (COLD) identifier. Optionally, the heat identifier can be added to the call stack by performing secondary coding on the code corresponding to the call stack.
[0051] In other embodiments, a call stack includes multiple functions, and one function corresponds to one target access address; the access times of the multiple target access addresses vary greatly (for example, there are local peaks in the access times). In this case, the multiple target access addresses corresponding to the call stack can be split into hot (active) access addresses and cold (inactive) access addresses, and a heat identifier can be added to each function in the call stack.
[0052] Accordingly, heat identifiers are added to the call stack according to the access counts of multiple target access addresses, including: for each target access address, if the access count of the target access address is greater than a first preset count, a first identifier is added to the function corresponding to the target access address; if the access count of the target access address is less than a second preset count, a second identifier is added to the function corresponding to the target access address, where the call frequency corresponding to the first identifier is greater than the call frequency corresponding to the second identifier.
[0053] Exemplarily, as Figure 4 shown, for the case where there are local peaks in the access counts, heat identifiers can be added to each function in the call stack. Optionally, heat identifiers can be added to the functions by performing secondary encoding on the code corresponding to the functions.
[0054] It should be noted that in the embodiments of the present disclosure, the values of the first preset count and the second preset count are not specifically limited and can be set and modified as needed. In some embodiments, the first preset count and the second preset count can be determined according to the ratio of hot addresses to cold addresses. Accordingly, the method for determining the first preset count is: determining that the ratio of the number of memory access addresses with access counts greater than the first preset count to the total number of multiple memory access addresses is the first preset ratio. Accordingly, the method for determining the second preset count is: determining that the ratio of the number of memory access addresses with access counts less than the second preset count to the total number of multiple memory access addresses is the second preset ratio.
[0055] S203. In response to a memory call request of any call stack, according to the heat identifier corresponding to the call stack, a memory access address is allocated for the call stack from the memory area corresponding to the heat identifier.
[0056] In the embodiments of the present disclosure, when a certain call stack needs to be started, the call stack issues a memory call request.
[0057] In some embodiments, the access counts of the multiple target access addresses corresponding to the call stack are similar. Accordingly, allocating a memory access address for the call stack from the memory area corresponding to the heat identifier of the call stack includes: if the heat identifier corresponding to the call stack is the first identifier, allocating a memory access address for the call stack from the first memory pool; if the heat identifier corresponding to the call stack is the second identifier, allocating a memory access address for the call stack from the second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0058] Exemplarily, as Figure 4As shown, the first memory pool is a hot cache pool and the second memory pool is a cold cache pool. When the heat identifier corresponding to the call stack is the first identifier (for example, a hot identifier), a memory access address is allocated for the call stack from the hot cache pool. When the heat identifier corresponding to the call stack is the second identifier (for example, a cold identifier), a memory access address is allocated for the call stack from the cold cache pool.
[0059] In some other embodiments, the call stack includes multiple functions, and one function corresponds to one target access address; the access times of the multiple target access addresses vary greatly. Accordingly, in response to a memory call request of any call stack, according to the heat identifier corresponding to the call stack, a memory access address is allocated for the call stack from the memory area corresponding to the heat identifier, including: in response to a memory call request of any call stack, determining the heat identifier corresponding to each function in the call stack; if the heat identifier corresponding to the function is the first identifier, allocating a memory access address for the function from the first memory pool, and if the heat identifier corresponding to the function is the second identifier, allocating a memory access address for the function from the second memory pool, where the first memory pool is a non-recyclable memory area in the memory and the second memory pool is a recyclable memory area in the memory.
[0060] Exemplarily, as Figure 4 shown, when the heat identifier corresponding to the function is the first identifier (for example, a hot identifier), a memory access address is allocated for the function from the hot cache pool. When the heat identifier corresponding to the function is the second identifier (for example, a cold identifier), a memory access address is allocated for the function from the cold cache pool.
[0061] The memory management method provided in this embodiment: obtaining the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to multiple memory access addresses; for each call stack corresponding to the process, determining the access times of the multiple target access addresses allocated to the call stack, and adding a heat identifier to the call stack according to the access times of the multiple target access addresses, where the heat identifier is used to represent the call frequency of the call stack; in response to a memory call request of any call stack, according to the heat identifier corresponding to the call stack, allocating a memory access address for the call stack from the memory area corresponding to the heat identifier. In the embodiments of the present application, since for each process, hot and cold identifiers are added to multiple call stacks in the process, in this way, when calling a certain call stack, a memory address is directly allocated from the memory pool corresponding to the hot and cold identifiers, realizing memory management with each call stack in each process as a dimension, thereby improving the accuracy of memory management.
[0062] It should be noted that, continue to refer to Figure 4When memory recycling is required, the memory access addresses in the second memory pool (such as the hot cache pool) are preferentially recycled. At the same time, the memory access addresses in the first memory pool (such as the cold cache pool) can also be protected to prevent the memory access addresses in the first memory pool from being recycled.
[0063] Correspondingly, the method further includes:
[0064] S204. In response to meeting a preset memory recycling condition, perform a recycling process on the memory access addresses in the second memory pool.
[0065] In some embodiments, if the memory occupancy rate is greater than a preset value, it is determined that the preset memory recycling condition is met, and a recycling process is performed on the memory access addresses in the second memory pool.
[0066] In the embodiments of the present disclosure, the value of the preset value is not specifically limited and can be set and modified as needed. Exemplarily, the preset value can be 60%, 70%, 80%, etc.
[0067] In other embodiments, if the time interval between the current time and the last recycling time is greater than a preset duration, it is determined that the preset memory recycling condition is met, and a recycling process is performed on the memory access addresses in the second memory pool.
[0068] In the embodiments of the present disclosure, the value of the preset duration is not specifically limited and can be set and modified as needed. Exemplarily, the preset duration can be 5 minutes, 20 minutes, 30 minutes, etc.
[0069] In the embodiments of the present disclosure, since the memory access addresses in the second memory pool are allocated for each process in the dimension of the call stack in each process, it is ensured that the memory access addresses in the second memory pool are cold addresses with a low number of accesses, greatly reducing the probability that the memory pages just recycled are called again, improving the memory recycling accuracy, and further improving the accuracy of the memory management method.
[0070] Figure 5 The block diagram of a memory management device provided by the embodiments of the present disclosure. This memory management device is applied to an electronic device, and at least one process runs in the electronic device, and each process includes a plurality of call stacks; refer to Figure 5 This device includes: an acquisition module 501, a determination module 502, and an allocation module 503.
[0071] Among them, the acquisition module 501 is used to acquire the memory access information of each process within a preset duration, and the memory access information includes the number of accesses respectively corresponding to a plurality of memory access addresses.
[0072] A determination module 502, configured to determine, for each call stack corresponding to the process, the access times of multiple target access addresses allocated to the call stack, and add a heat flag to the call stack according to the access times of the multiple target access addresses, where the heat flag is used to characterize the call frequency of the call stack;
[0073] An allocation module 503, configured to, in response to a memory call request of any call stack, allocate a memory access address for the call stack from a memory area corresponding to the heat flag of the call stack.
[0074] According to one or more embodiments of the present disclosure, the determination module 502 adding a heat flag to the call stack according to the access times of the multiple target access addresses specifically includes: if the access times of the multiple target access addresses are all greater than a first preset number of times, adding a first flag to the call stack; if the access times of the multiple target access addresses are all less than a second preset number of times, adding a second flag to the call stack; where the call frequency corresponding to the first flag is greater than the call frequency corresponding to the second flag.
[0075] According to one or more embodiments of the present disclosure, the allocation module 503 allocating a memory access address for the call stack from a memory area corresponding to the heat flag of the call stack specifically includes: if the heat flag is the first flag, allocating a memory access address for the call stack from a first memory pool; if the heat flag is the second flag, allocating a memory access address for the call stack from a second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0076] According to one or more embodiments of the present disclosure, the call stack includes multiple functions, and one function corresponds to one target access address; correspondingly, the determination module 502 adding a heat flag to the call stack according to the access times of the multiple target access addresses specifically includes: for each target access address, if the access times of the target access address are greater than a first preset number of times, adding a first flag to the function corresponding to the target access address; if the access times of the target access address are less than a second preset number of times, adding a second flag to the function corresponding to the target access address, where the call frequency corresponding to the first flag is greater than the call frequency corresponding to the second flag.
[0077] According to one or more embodiments of the present disclosure, the allocation module 503, in response to a memory call request of any call stack, allocates a memory access address for the call stack from the memory area corresponding to the heat identification, specifically including: in response to a memory call request of any call stack, determining the heat identification corresponding to each function in the call stack; if the heat identification corresponding to the function is the first identification, allocating a memory access address for the function from the first memory pool, and if the heat identification corresponding to the function is the second identification, allocating a memory access address for the function from the second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0078] According to one or more embodiments of the present disclosure, the ratio of the number of memory access addresses with the access times greater than the first preset number of times to the total number of the multiple memory access addresses is the first preset ratio, and / or, the ratio of the number of memory access addresses with the access times less than the second preset number of times to the total number of the multiple memory access addresses is the second preset ratio.
[0079] According to one or more embodiments of the present disclosure, the device further includes: a recycling module; the recycling module is used to perform a recycling process on the memory access addresses in the second memory pool in response to meeting a preset memory recycling condition.
[0080] According to one or more embodiments of the present disclosure, the obtaining module 501 obtains the memory access information of each process within a preset duration, specifically including: for each process, obtaining the memory allocation requests of multiple call stacks corresponding to the process received within the preset duration, allocating memory access addresses for each function in each of the call stacks; calling a hook function, and counting the access times of the memory access addresses corresponding to each function in each of the call stacks through the hook function; establishing a mapping relationship between the memory access addresses and the access times to obtain the memory access information of the process.
[0081] Among them, the obtaining module 501, the determining module 502, and the allocation module 503 are connected in sequence. The memory management device provided in this embodiment can execute the technical solutions of the above method embodiments, and its implementation principles and technical effects are similar, which will not be elaborated here in this embodiment.
[0082] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present disclosure. Refer to Figure 6, the electronic device 600 can be a terminal device or a server. Among them, the terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (PADs), portable media players (PMPs), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not impose any limitations on the functions and scope of use of the embodiments of the present disclosure.
[0083] As Figure 6 shown, the electronic device 600 can include a processing device (such as a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage device 608 into the random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.
[0084] Generally, the following devices can be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 can allow the electronic device 600 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 6 the electronic device 600 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. More or fewer devices can be implemented or had alternatively.
[0085] In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network via the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above functions defined in the method of the embodiment of the present disclosure are performed.
[0086] It should be noted that the above computer-readable medium in the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, the computer-readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable signal medium can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0087] The above computer-readable medium can be included in the above electronic device; or it can exist separately and not be assembled into the electronic device.
[0088] The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by the electronic device, the electronic device is caused to execute the method shown in the above embodiment.
[0089] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system that performs the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0091] The units described in the embodiments of the present disclosure may be implemented in software or in hardware. Among them, the name of the unit does not constitute a limitation to the unit itself in some cases. For example, the first acquisition unit may also be described as "the unit for acquiring at least two Internet protocol addresses".
[0092] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.
[0093] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0094] In a first aspect, according to one or more embodiments of the present disclosure, there is provided a memory management method applied to an electronic device in which at least one process is running, and each process includes a plurality of call stacks; the method includes:
[0095] Obtaining memory access information of each process within a preset duration, where the memory access information includes the number of accesses respectively corresponding to a plurality of memory access addresses;
[0096] For each call stack corresponding to the process, determining the number of accesses to a plurality of target access addresses allocated to the call stack, and adding a heat identifier to the call stack according to the number of accesses to the plurality of target access addresses, where the heat identifier is used to characterize the call frequency of the call stack;
[0097] In response to a memory call request of any call stack, allocating a memory access address for the call stack from the memory area corresponding to the heat identifier according to the heat identifier corresponding to the call stack.
[0098] According to one or more embodiments of the present disclosure, adding a heat identifier to the call stack according to the number of accesses to the plurality of target access addresses includes: if the number of accesses to the plurality of target access addresses is greater than a first preset number, adding a first identifier to the call stack, and if the number of accesses to the plurality of target access addresses is less than a second preset number, adding a second identifier to the call stack; wherein, the call frequency corresponding to the first identifier is greater than the call frequency corresponding to the second identifier.
[0099] According to one or more embodiments of the present disclosure, allocating a memory access address for the call stack from the memory area corresponding to the heat identification includes: if the heat identification is a first identification, allocating a memory access address for the call stack from a first memory pool; if the heat identification is a second identification, allocating a memory access address for the call stack from a second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0100] According to one or more embodiments of the present disclosure, the call stack includes multiple functions, and one function corresponds to one target access address; correspondingly, adding a heat identification to the call stack according to the access times of the multiple target access addresses includes: for each target access address, if the access times of the target access address are greater than a first preset number of times, adding a first identification to the function corresponding to the target access address; if the access times of the target access address are less than a second preset number of times, adding a second identification to the function corresponding to the target access address, where the call frequency corresponding to the first identification is greater than the call frequency corresponding to the second identification.
[0101] According to one or more embodiments of the present disclosure, responding to a memory call request of any call stack and allocating a memory access address for the call stack from the memory area corresponding to the heat identification of the call stack includes: responding to a memory call request of any call stack, and determining the heat identification corresponding to each function in the call stack; if the heat identification corresponding to the function is a first identification, allocating a memory access address for the function from a first memory pool; if the heat identification corresponding to the function is a second identification, allocating a memory access address for the function from a second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0102] According to one or more embodiments of the present disclosure, the ratio of the number of memory access addresses with access times greater than a first preset number of times to the total number of the multiple memory access addresses is a first preset ratio, and / or the ratio of the number of memory access addresses with access times less than a second preset number of times to the total number of the multiple memory access addresses is a second preset ratio.
[0103] According to one or more embodiments of the present disclosure, it further includes: responding to meeting a preset memory recycling condition, and performing a recycling process on the memory access addresses in the second memory pool.
[0104] According to one or more embodiments of the present disclosure, the obtaining of the memory access information of each process within a preset duration includes: for each process, obtaining the memory allocation requests of a plurality of call stacks corresponding to the process received within the preset duration, and allocating memory access addresses to each function in each of the call stacks; invoking a hook function, and counting the access times of the memory access addresses corresponding to each function in each of the call stacks through the hook function; establishing a mapping relationship between the memory access addresses and the access times to obtain the memory access information of the process.
[0105] In a second aspect, according to one or more embodiments of the present disclosure, there is provided a memory management device applied to an electronic device, where at least one process is running in the electronic device, and each process includes a plurality of call stacks; the device includes:
[0106] An obtaining module, configured to obtain the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to a plurality of memory access addresses;
[0107] A determining module, configured to, for each call stack corresponding to the process, determine the access times of a plurality of target access addresses allocated to the call stack, and add a heat mark to the call stack according to the access times of the plurality of target access addresses, where the heat mark is used to characterize the call frequency of the call stack;
[0108] An allocation module, configured to, in response to a memory call request of any call stack, allocate a memory access address for the call stack from the memory area corresponding to the heat mark according to the heat mark corresponding to the call stack.
[0109] According to one or more embodiments of the present disclosure, the determining module adding a heat mark to the call stack according to the access times of the plurality of target access addresses specifically includes: if the access times of the plurality of target access addresses are all greater than a first preset number of times, adding a first mark to the call stack; if the access times of the plurality of target access addresses are all less than a second preset number of times, adding a second mark to the call stack; where the call frequency corresponding to the first mark is greater than the call frequency corresponding to the second mark.
[0110] According to one or more embodiments of the present disclosure, the allocation module allocating a memory access address for the call stack from the memory area corresponding to the heat mark according to the heat mark corresponding to the call stack specifically includes: if the heat mark is the first mark, allocating a memory access address for the call stack from a first memory pool; if the heat mark is the second mark, allocating a memory access address for the call stack from a second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0111] According to one or more embodiments of the present disclosure, the call stack includes multiple functions, and one function corresponds to one target access address; accordingly, the determining module adds a heat identifier to the call stack according to the access times of the multiple target access addresses, specifically including: for each target access address, if the access times of the target access address are greater than a first preset number of times, adding a first identifier to the function corresponding to the target access address, and if the access times of the target access address are less than a second preset number of times, adding a second identifier to the function corresponding to the target access address, where the call frequency corresponding to the first identifier is greater than the call frequency corresponding to the second identifier.
[0112] According to one or more embodiments of the present disclosure, the allocation module, in response to a memory call request of any call stack, allocates a memory access address for the call stack from the memory area corresponding to the heat identifier, specifically including: in response to a memory call request of any call stack, determining the heat identifier corresponding to each function in the call stack; if the heat identifier corresponding to the function is the first identifier, allocating a memory access address for the function from the first memory pool, and if the heat identifier corresponding to the function is the second identifier, allocating a memory access address for the function from the second memory pool, where the first memory pool is a non-recyclable memory area in the memory, and the second memory pool is a recyclable memory area in the memory.
[0113] According to one or more embodiments of the present disclosure, the ratio of the number of memory access addresses whose access times are greater than the first preset number of times to the total number of the multiple memory access addresses is a first preset ratio, and / or the ratio of the number of memory access addresses whose access times are less than the second preset number of times to the total number of the multiple memory access addresses is a second preset ratio.
[0114] According to one or more embodiments of the present disclosure, the device further includes: a recycling module; the recycling module is used to perform a recycling process on the memory access addresses in the second memory pool in response to meeting a preset memory recycling condition.
[0115] According to one or more embodiments of the present disclosure, the obtaining module obtains the memory access information of each process within a preset duration, specifically including: for each process, obtaining the memory allocation requests of multiple call stacks corresponding to the process received within the preset duration, allocating memory access addresses for each function in each of the call stacks; calling a hook function, and counting the access times of the memory access addresses corresponding to each function in each of the call stacks through the hook function; establishing a mapping relationship between the memory access addresses and the access times to obtain the memory access information of the process.
[0116] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, including: a processor, and a memory communicatively connected to the processor;
[0117] The memory stores computer-executable instructions;
[0118] The processor executes the computer-executable instructions stored in the memory to implement the memory management method as described in the first aspect above and various possible designs of the first aspect.
[0119] In a fourth aspect, according to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium storing computer-executable instructions, and when the processor executes the computer-executable instructions, the memory management method as described in the first aspect above and various possible designs of the first aspect is implemented.
[0120] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, and when the computer program is executed by a processor, the memory management method as described in the first aspect above and various possible designs of the first aspect is implemented.
[0121] The above description is only a preferred embodiment of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, the technical solutions formed by mutually replacing the above features with the technical features (but not limited to) having similar functions disclosed in the present disclosure.
[0122] In addition, although the operations are depicted in a specific order, this should not be construed as requiring that the operations be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments may also be implemented in combination in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented separately or in any suitable sub-combination in multiple embodiments.
[0123] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. On the contrary, the specific features and acts described above are merely example forms for implementing the claims.
Claims
1. A memory management method, characterized in that, Applied to an electronic device, at least one process runs in the electronic device, and each process includes multiple call stacks; the method includes: Obtain the memory access information of each process within a preset time period, where the memory access information includes the access times respectively corresponding to multiple memory access addresses; For each call stack corresponding to the process, determine the access times of multiple target access addresses allocated to the call stack, and add a heat label to the call stack according to the access times of the multiple target access addresses, where the heat label is used to characterize the call frequency of the call stack; In response to a memory call request of any call stack, allocate a memory access address for the call stack from the memory area corresponding to the heat label according to the heat label corresponding to the call stack.
2. The method according to claim 1, characterized in that, The adding a heat label to the call stack according to the access times of the multiple target access addresses includes: If the access times of the multiple target access addresses are all greater than a first preset number of times, add a first label to the call stack; if the access times of the multiple target access addresses are all less than a second preset number of times, add a second label to the call stack; Wherein, the call frequency corresponding to the first label is greater than the call frequency corresponding to the second label.
3. The method according to claim 2, wherein The allocating a memory access address for the call stack from the memory area corresponding to the heat label according to the heat label corresponding to the call stack includes: If the heat label is the first label, allocate a memory access address for the call stack from the first memory pool; if the heat label is the second label, allocate a memory access address for the call stack from the second memory pool, where the first memory pool is a non-reclaimable memory area in the memory, and the second memory pool is a reclaimable memory area in the memory.
4. The method according to claim 1, wherein The call stack includes multiple functions, and one function corresponds to one target access address; Correspondingly, the adding a heat label to the call stack according to the access times of the multiple target access addresses includes: For each target access address, if the access times of the target access address are greater than a first preset number of times, add a first label to the function corresponding to the target access address; if the access times of the target access address are less than a second preset number of times, add a second label to the function corresponding to the target access address, where the call frequency corresponding to the first label is greater than the call frequency corresponding to the second label.
5. The method according to claim 4, characterized in that, The allocating a memory access address for the call stack from the memory area corresponding to the heat label according to the heat label corresponding to the call stack in response to a memory call request of any call stack includes: In response to a memory call request of any call stack, determine the heat label corresponding to each function in the call stack; If the heat label corresponding to the function is the first label, allocate a memory access address for the function from the first memory pool; if the heat label corresponding to the function is the second label, allocate a memory access address for the function from the second memory pool, where the first memory pool is a non-reclaimable memory area in the memory, and the second memory pool is a reclaimable memory area in the memory.
6. The method according to claim 2 or 4, wherein the ratio of the number of memory access addresses with the access times greater than a first preset number of times to the total number of the multiple memory access addresses is a first preset ratio, and / or the ratio of the number of memory access addresses with the access times less than a second preset number of times to the total number of the multiple memory access addresses is a second preset ratio.
7. The method according to claim 3 or 5, characterized in that, It further includes: responding to meeting a preset memory recovery condition, and performing a recovery process on the memory access addresses in the second memory pool.
8. The method according to claim 1, wherein The obtaining the memory access information of each process within a preset duration includes: for each process, obtaining memory allocation requests of multiple call stacks corresponding to the process received within a preset duration, and allocating memory access addresses for each function in each of the call stacks; invoking a hook function, and counting the access times of the memory access addresses corresponding to each function in each of the call stacks through the hook function; establishing a mapping relationship between the memory access addresses and the access times, and obtaining the memory access information of the process.
9. A memory management device, characterized in that, Applied to an electronic device, at least one process runs in the electronic device, and each process includes multiple call stacks; the device includes: an obtaining module, configured to obtain the memory access information of each process within a preset duration, where the memory access information includes the access times respectively corresponding to multiple memory access addresses; a determining module, configured to, for each call stack corresponding to the process, determine the access times of multiple target access addresses allocated to the call stack, and add a heat mark to the call stack according to the access times of the multiple target access addresses, where the heat mark is used to characterize the call frequency of the call stack; an allocation module, configured to, in response to a memory call request of any call stack, allocate a memory access address for the call stack from a memory area corresponding to the heat mark according to the heat mark corresponding to the call stack.
10. An electronic device, characterized in that, It includes: a processor, and a memory communicatively connected to the processor; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory to implement the memory management method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, Computer-execution instructions are stored in the computer-readable storage medium, and when the processor executes the computer-execution instructions, the memory management method according to any one of claims 1 to 8 is implemented.
12. A computer program product, characterized in that, It includes a computer program, and when the computer program is executed by the processor, the memory management method according to any one of claims 1 to 8 is implemented.