A memory management method and apparatus

CN122924969APending Publication Date: 2026-10-16JD DIGITS HAIYI INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510405477.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-01
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

但是在使用该函数进行分配时,会存在明显的内存碎片的问题,严重影响内存的分配、回收,造成qemu效率的降低,以及内存资源的浪费

Benefits of technology

[0035] One embodiment of the above invention has the following advantages or beneficial effects: it enables memory allocation through memory pools containing memory block sizes. A target memory pool is selected based on memory demand information, a target memory linked list is further selected, and then a linked list item is selected. Based on the usage status of the memory blocks in the linked list item, unoccupied memory blocks are selected for memory allocation. The introduction of linked lists and linked list items reduces memory fragmentation, improves memory utilization, and reduces waste. Simultaneously, using memory pools corresponding to memory blocks of different sizes also improves the efficiency of memory allocation management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122924969A_ABST
    Figure CN122924969A_ABST
Patent Text Reader

Abstract

The application discloses a memory management method and device, and relates to the technical field of computers. A specific implementation of the method comprises the following steps: analyzing received memory information to obtain a target memory capacity, selecting a target memory pool according to the memory capacity, further selecting a target memory linked list and a target linked list item in the linked list from the memory pool, determining a target memory block according to a use state of the memory block in the target linked list item, and performing a memory allocation operation. The implementation can avoid memory waste caused by memory fragmentation during memory allocation, and improves the memory management efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a memory management method and apparatus. Background Technology

[0002] In the field of virtualization technology, QEMU (Qerman Virtual Machine Emulator) is a widely used open-source emulator and hypervisor. Its advantages, including support for multiple architectures, scalability, open source, portability, and fast simulation speed, have led to its widespread adoption. During operation, QEMU often needs to allocate memory to implement different functions. Currently, the `g_malloc` function is primarily used for dynamic memory allocation. `g_malloc` is a memory allocation function in the GLib library (programming language function library) and is widely used in various C language projects. However, using this function for allocation results in significant memory fragmentation, severely impacting memory allocation and reclamation, leading to reduced QEMU efficiency and wasted memory resources. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a memory management method and apparatus that can effectively reduce the generation of memory fragmentation and ensure the efficient execution of the memory allocation process.

[0004] To achieve the above objectives, according to one aspect of the present invention, a memory management method is provided, comprising:

[0005] Receive memory requirement information, parse the memory requirement information, and obtain the target memory capacity;

[0006] The target memory pool is selected from the set of memory pools based on the target memory capacity. The set of memory pools includes multiple memory pools with different memory block sizes.

[0007] Select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size.

[0008] Based on the usage status of memory blocks in the target linked list, select an unoccupied memory block from the target linked list as the target memory block, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

[0009] Optionally, after allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method further includes:

[0010] Update the usage status of the target memory block to show that it is occupied.

[0011] Optionally, a target memory list is selected from the target memory pool, including:

[0012] Select the first state memory list in the target memory pool as the target memory list. The list entries in the first state list are partially occupied memory blocks.

[0013] Based on the usage status of memory blocks in the target linked list, after selecting an unoccupied memory block from the target linked list as the target memory block and allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method also includes:

[0014] In response to the fact that all memory blocks in the target linked list are occupied, the first state of the target linked list is updated to the second state, and the target linked list is moved from the target memory linked list to the memory linked list in the second state.

[0015] Optionally, the method further includes:

[0016] If the target memory list does not have any entries, then the memory list in the third state of the target memory pool is selected as the target memory list. The entries in the third state list are all memory blocks that are not occupied.

[0017] Based on the usage status of memory blocks in the target linked list, after selecting an unoccupied memory block from the target linked list as the target memory block and allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method also includes:

[0018] Update the state of the target linked list item to the first state, and transfer the linked list item from the target memory linked list to the memory linked list in the first state.

[0019] Optionally, the method further includes:

[0020] When receiving a memory release request corresponding to the target memory block, the address of the memory to be released is obtained by parsing the release request;

[0021] The target linked list entry corresponding to the target memory block is determined based on the address;

[0022] Update the usage status of the target memory block in the target linked list to unoccupied.

[0023] Optionally, in response to the target list item being located in the memory list of the second state, the target list item is transferred to the memory list of the first state;

[0024] In response to the target list item being located in the memory list in the first state, and the memory block usage state of the target list item being that all memory blocks are unoccupied, the target list item is transferred to the memory list in the third state.

[0025] Optionally, the method further includes:

[0026] Perform memory release processing on the linked list items in the memory linked list that have been transferred to the third state.

[0027] According to another aspect of the present invention, a memory management apparatus is provided, comprising:

[0028] The parsing module is used to receive memory requirement information, parse the memory requirement information, and obtain the target memory capacity;

[0029] The selection module is used to select a target memory pool from a set of memory pools based on the target memory capacity. The set of memory pools includes multiple memory pools with different memory block sizes.

[0030] The selection module is used to select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size.

[0031] The allocation module is used to select an unoccupied memory block from the target linked list item as the target memory block based on the usage status of the memory blocks in the target linked list item, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

[0032] According to another aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the memory management method provided in the embodiments of the present invention.

[0033] According to another aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the memory management method provided in the embodiments of the present invention.

[0034] According to another aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the memory management method provided in the embodiments of the present invention.

[0035] One embodiment of the above invention has the following advantages or beneficial effects: it enables memory allocation through memory pools containing memory block sizes. A target memory pool is selected based on memory demand information, a target memory linked list is further selected, and then a linked list item is selected. Based on the usage status of the memory blocks in the linked list item, unoccupied memory blocks are selected for memory allocation. The introduction of linked lists and linked list items reduces memory fragmentation, improves memory utilization, and reduces waste. Simultaneously, using memory pools corresponding to memory blocks of different sizes also improves the efficiency of memory allocation management.

[0036] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0037] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0038] Figure 1 This is a schematic diagram illustrating the main steps of a memory management method according to an embodiment of the present invention;

[0039] Figure 2 This is a schematic diagram of the structure of a linked list item;

[0040] Figure 3 This is a schematic diagram of the data structure of the memory pool;

[0041] Figure 4 This is a schematic diagram of the main modules of a memory management device according to an embodiment of the present invention;

[0042] Figure 5 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0043] Figure 6 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0044] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0045] It should be noted that the technical solutions disclosed in this invention, regarding the collection, updating, analysis, processing, use, transmission, and storage of user personal information, all comply with relevant laws and regulations, are used for legitimate purposes, and do not violate public order and good morals. Necessary measures are taken to prevent unauthorized access to user personal information data and to safeguard user personal information security, network security, and national security.

[0046] It should be noted that the collection, use, storage, sharing and transfer of user personal information involved in the technical solution of the present invention all comply with the provisions of relevant laws and regulations, and require notification to users and obtaining their consent or authorization. When applicable, user personal information is subjected to de-identification and / or anonymization and / or encryption technical processing.

[0047] Currently, memory allocation via `g_malloc` generates significant memory fragmentation, leading to memory waste and preventing proper reclamation. The fragmentation process is as follows: `g_malloc` is a wrapper around the `malloc` function, which allocates memory on the heap. Assuming an application allocates 32 times (4KB each), totaling 128KB, the heap grows upwards. If the application releases the 128KB, the heap shrinks back to its original state. However, if the application allocates another 1KB after the 32 allocations and doesn't release it, the heap gets stuck and cannot shrink back. The application considers the 128KB released, but the kernel cannot reclaim it, resulting in memory fragmentation. As the number of allocations and releases increases, fragmentation accumulates, affecting normal allocation. This invention, by referencing a user-space slab allocator, effectively reduces memory fragmentation.

[0048] Figure 1 This is a memory management method according to an embodiment of the present invention, such as... Figure 1 As shown, the memory management method of this embodiment includes the following steps S101 to S104.

[0049] Step S101: Receive memory requirement information and parse the memory requirement information to obtain the target memory capacity.

[0050] The memory requirement information of the obtained application is parsed to obtain the target memory capacity, which is the size of the memory to be allocated.

[0051] Step S102: Select a target memory pool from the memory pool set based on the target memory capacity. The memory pool set includes multiple memory pools with different memory block sizes.

[0052] The pre-created set of memory pools includes multiple memory pools, each containing memory blocks of the same size, but with different block sizes between different memory pools. This allows for direct determination of the memory pool to allocate based on the required memory size. For example, memory pool 1 may contain memory blocks of 1 byte (1B), while memory pool 2 may contain memory blocks of 8 bytes (8B).

[0053] Once the required memory size, i.e., the target memory capacity, is determined, a memory pool corresponding to a memory block of the same size as the target memory capacity can be selected as the target memory pool. For example, if the target memory capacity is 8B, then memory pool 2 is selected as the target memory pool. By setting memory pools with different memory block sizes, this method can be applied to the scheme of this invention, which allows for the allocation and management of memory blocks of different sizes, when the slab (a memory allocation mechanism) method can only allocate memory blocks of a fixed size.

[0054] Step S103: Select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size.

[0055] After determining the target memory pool, the next step is to select memory blocks within that pool. The memory pool comprises multiple linked lists with different usage states; for example, there are partial, empty, and full linked lists. Each list contains entries with the same usage state: the partial list contains entries where some memory blocks are occupied, the empty list contains entries where all memory blocks are unoccupied, and the full list contains entries where all memory blocks are occupied. Each entry contains multiple memory blocks of the same size, connected end-to-end. Each memory block is categorized into occupied and unoccupied states based on its allocation status.

[0056] Therefore, after determining the target memory pool, you can choose either a partial linked list or an empty linked list from the pool, with the partial linked list being the preferred target memory linked list. After determining the target memory linked list, select one linked list item as the target linked list item based on the storage order of the linked list items.

[0057] Optionally, to further improve the multi-threading capability of memory allocation in this invention, multiple memory pools with the same memory block size can be divided, and multiple memory table chains with the same usage status can also be divided within each memory pool.

[0058] Step S104: Based on the usage status of memory blocks in the target linked list, select an unoccupied memory block from the target linked list as the target memory block, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

[0059] After determining the target linked list item, it is necessary to further select a memory block within it for memory allocation. Specifically, based on the usage status of each memory block recorded in the bitmap (a bit-based data structure) of the target linked list item, a memory block is selected as the target memory block. The memory corresponding to the target memory block is then allocated to the object requiring the memory.

[0060] Optionally, the structure of the linked list item (slab_list) is as follows: Figure 2 As shown, the system includes multiple memory blocks. Memory block number 1 in the diagram represents the occupied memory block, and memory block number 2 represents the unoccupied memory block. Each slab_list, in addition to the linked list pointers and bitmap, manages a complete 4k page. Moreover, this 4k page is divided into smaller blocks according to a fixed memory block size, and the memory block usage is recorded by the bitmap.

[0061] Optionally, the data structure of each memory pool is as follows: Figure 3 As shown. For each size of memory block, there is a main management structure, umem_cache, that manages a memory pool. Its core consists of three linked lists: partial, empty, and full, representing partially occupied memory, unoccupied memory, and fully occupied memory, respectively.

[0062] The memory management method provided by this invention can allocate memory using memory pools containing memory block sizes. It selects a target memory pool based on memory demand information, further selects a target memory list, and then selects a list item. Based on the usage status of memory blocks in the list item, it selects unoccupied memory blocks for memory allocation. The introduction of the list and list items reduces memory fragmentation, improves memory utilization, and reduces waste. Furthermore, using memory pools corresponding to memory blocks of different sizes also improves the efficiency of memory allocation and management.

[0063] Optionally, after allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the memory management method further includes: updating the usage status of the target memory block to show that it is occupied. After memory allocation, updating the usage status of the allocated memory block to show that it is occupied prevents subsequent duplicate allocation.

[0064] Optionally, selecting a target memory list in the target memory pool includes: selecting a memory list in a first state as the target memory list, where the list entries in the first state indicate that some memory blocks are occupied; based on the usage state of the memory blocks in the target list entries, selecting an unoccupied memory block from the target list entries as the target memory block, and allocating the memory corresponding to the target memory block to the object corresponding to the memory demand information; the method further includes: in response to the usage state of the memory blocks in the target list entries being that all memory blocks are occupied, updating the first state of the target list entries to a second state, and transferring the target list entries from the target memory list to the memory list in the second state.

[0065] When selecting a memory list, the first-state memory list, i.e., the partial list, is chosen. Prioritizing the partial list for memory allocation helps to quickly release memory in subsequent list entries. After selecting the first-state memory list as the target memory list and allocating memory based on it, the state of the selected target list item needs to be determined. Specifically, the usage status of the memory blocks in the target list item is checked. If all memory blocks are occupied, it means that the list item has changed from the partial state to the full state, and the list item needs to be moved from the target memory list to the second-state memory list (the full list).

[0066] The memory management method provided by the embodiments of the present invention can quickly determine memory blocks based on memory linked lists in different states in different memory pools, thereby improving the speed and efficiency of memory allocation. It also facilitates multi-threaded memory allocation.

[0067] Optionally, the memory management method further includes: if the target memory list does not have any list entries, then selecting the memory list in the third state of the target memory pool as the target memory list, where the list entries in the third state list are all unoccupied memory blocks; based on the usage status of the memory blocks in the target list entries, selecting an unoccupied memory block from the target list entries as the target memory block, and allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the memory management method further includes: updating the state of the target list entries to the first state, and transferring the list entries from the target memory list to the memory list in the first state.

[0068] If no item exists in the partial list, the empty list must be selected as the target memory list, and an item must be selected from the empty list. After selecting the target item based on the empty list and performing memory allocation, the state of the target item must be updated to the first state, i.e., the partial state, and the target item must be transferred to the memory list in the first state.

[0069] Optionally, the memory management method further includes: when receiving a memory release request corresponding to the target memory block, obtaining the address of the memory to be released by parsing the release request; determining the target linked list item corresponding to the target memory block based on the address; and updating the usage status of the target memory block in the target linked list item to be unoccupied.

[0070] When releasing memory, the address of the memory to be released is first parsed from the release request. Based on this address, the linked list entry containing the memory block is determined, and the usage status of the memory block is updated to unoccupied. Subsequently, the status of the linked list entry is determined based on the updated usage status of the memory block. If the linked list needs to be moved, the corresponding memory is released after the linked list movement operation is completed.

[0071] Optionally, by aligning the address to be freed with 4KB and calculating some offsets, the slab_list containing this memory block can be obtained. When a slab_list structure 'a' (a linked list item) is created, 4KB of memory is allocated directly using mmap (a method of memory-mapped files). The memory allocated by mmap is aligned to 4KB, and the memory in mmap is the memory managed by the slab_list, slightly smaller than 4KB. If the memory in mmap is aligned to 4KB, it will be exactly 'a'. For example, if the address of 'a' is 10000000, the memory in mmap might be 10000010 or 10000018. Regardless of the specific address, as long as it is aligned to 4KB in mmap, it will be 10000000, and the corresponding slab_list can be found.

[0072] Optionally, the memory management method further includes: in response to the target linked list item being located in the memory linked list of the second state, transferring the target linked list item to the memory linked list of the first state; in response to the target linked list item being located in the memory linked list of the first state, and the usage state of the memory blocks in the target linked list item being that all memory blocks are unoccupied, transferring the target linked list item to the memory linked list of the third state. When releasing memory, if after updating the state of the memory block, the linked list item containing the memory block is located in the full linked list, then the linked list item needs to be transferred to the partial linked list; if the memory block is located in the partial linked list, and the usage state of all memory blocks in the linked list item is unoccupied, then the linked list item is transferred to the empty linked list.

[0073] The determination of whether all memory blocks in the linked list are unoccupied can be made based on the updated memory block usage status, or it can be made based on the bitmap's recorded numbers before the update. Specifically, a usign long (an integer variable) in the bitmap is represented by 64 bits. Therefore, 000…0000001 and 000…0000011 correspond to the numbers 1 and 3, respectively, representing the first, first, and second memory blocks being used. If the size exceeds 64 bits, more long (a data type) can be used. For example, if a memory block is 8 bytes in size, and a 4KB block contains 512 8-byte blocks, it requires 8 longs to store. When all the long bits are 1, it indicates that the memory block is fully occupied.

[0074] Optionally, the memory management method further includes: releasing memory for linked list items in the memory linked list that have transitioned to the third state. Memory is released for linked list items that have transitioned to the empty linked list. This can be implemented using `munmap` (a function to unmap the starting address of memory). For QEMU, most memory allocations occur when the virtual machine first starts, so releasing the empty linked list after the virtual machine starts can improve performance and save memory.

[0075] The memory management method provided by the embodiments of the present invention can realize memory allocation through the introduced memory management mechanism. Specifically, it achieves the allocation of memory of different sizes by using a memory pool containing memory blocks of different sizes, thus overcoming the limitation that slab memory allocation can only allocate memory blocks of fixed sizes. Furthermore, it realizes the multi-threading capability of memory through multiple memory linked lists in different states in the memory pool, improving memory allocation efficiency. At the same time, it can improve memory release efficiency.

[0076] Figure 4 This is a schematic diagram of a memory management device 400 provided in an embodiment of the present invention, as shown below. Figure 4 As shown, the memory management device 400 includes:

[0077] The parsing module 401 is used to receive memory requirement information, parse the memory requirement information, and obtain the target memory capacity.

[0078] Selection module 402 is used to select a target memory pool from a set of memory pools based on the target memory capacity. The set of memory pools includes multiple memory pools with different memory block sizes.

[0079] Selection module 402 is used to select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size.

[0080] The allocation module 403 is used to select an unoccupied memory block from the target linked list item as the target memory block based on the usage status of the memory blocks in the target linked list item, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

[0081] The memory management device provided by the embodiments of the present invention can allocate memory through memory pools containing memory block sizes. It selects a target memory pool based on memory demand information, further selects a target memory list, and selects a list item. Based on the usage status of memory blocks in the list item, it selects unoccupied memory blocks for memory allocation. The introduction of the list and list items reduces memory fragmentation, improves memory utilization, and reduces waste. Furthermore, using memory pools corresponding to memory block sizes also improves the efficiency of memory allocation management.

[0082] Optionally, the device further includes an update module 404 (not shown) for updating the usage status of the target memory block to indicate that it is occupied.

[0083] Optionally, the selection module 402 is further configured to select a memory list in a first state as the target memory list in the target memory pool, wherein the list entries in the first state indicate that some memory blocks are occupied; the device further includes: an update module 404, which is further configured to update the first state of the target list entry to a second state in response to the usage state of the memory blocks in the target list entry being that all memory blocks are occupied, and to transfer the target list entry from the target memory list to the memory list in the second state.

[0084] Optionally, the device further includes: a selection module 402, which is further configured to select a memory list in the third state of the target memory pool as the target memory list if the target memory list does not have a list item, wherein the list item in the third state list is that all memory blocks are not occupied; the device further includes: an update module 404, which is further configured to update the state of the target list item to the first state and transfer the list item from the target memory list to the memory list in the first state.

[0085] Optionally, the device further includes: a parsing module 405 (not shown in the figure), used to obtain the address of the memory to be released by parsing the release request when receiving the memory release request corresponding to the target memory block; a determining module 406 (not shown in the figure), used to determine the target linked list item corresponding to the target memory block based on the address; and an updating module 404, used to update the usage status of the target memory block in the target linked list item to be unoccupied.

[0086] Optionally, the device further includes: a transfer module 407 (not shown in the figure), configured to transfer the target list item to the memory list in the first state in response to the target list item being located in the memory list in the second state; and to transfer the target list item to the memory list in the third state in response to the target list item being located in the memory list in the first state and the memory blocks in the target list item being in the usage state of all memory blocks being unoccupied.

[0087] Optionally, the device further includes a release module 408 (not shown) for performing memory release processing on linked list entries in the memory linked list that have been transferred to the third state.

[0088] The memory management device provided by the embodiments of the present invention can realize memory allocation through the introduced memory management mechanism. Specifically, it achieves the allocation of memory of different sizes by using a memory pool containing memory blocks of different sizes, thus overcoming the limitation that slab memory allocation can only allocate memory blocks of fixed sizes. Furthermore, it realizes the multi-threading capability of memory through multiple memory linked lists in different states in the memory pool, thereby improving memory allocation efficiency. At the same time, it can improve memory release efficiency.

[0089] Figure 5 An exemplary system architecture 500 is shown where the memory management method or memory management device of the present invention can be applied.

[0090] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, and 503, a network 504, and a server 505. Network 504 serves as the medium for providing communication links between terminal devices 501, 502, and 503 and server 505. Network 504 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.

[0091] Users can use terminal devices 501, 502, and 503 to interact with server 505 via network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, and 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).

[0092] Terminal devices 501, 502, and 503 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0093] Server 505 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 501, 502, and 503 (for example only). The backend management server can analyze and process data such as received management requests, and feed back the processing results (e.g., memory usage – for example only) to the terminal devices.

[0094] It should be noted that the memory management method provided in this embodiment of the invention is generally executed by server 505, and correspondingly, the memory management device is generally located in server 505.

[0095] It should be understood that Figure 5 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.

[0096] The following is for reference. Figure 6 It shows a schematic diagram of the structure of a computer system 600 suitable for implementing terminal devices or servers of the present invention. Figure 6 The terminal device or server shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.

[0097] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage section 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the system 600. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0098] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.

[0099] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs the functions defined above in the system of this invention.

[0100] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. 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 thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0101] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0102] The units or modules described in the embodiments of the present invention can be implemented in software or hardware. The described units or modules can also be located in a processor; for example, a processor can be described as including a parsing module, a selection module, and an allocation module. The names of these units or modules do not necessarily limit the specific unit or module itself; for example, a parsing module can also be described as "a module that receives memory requirement information, parses the memory requirement information, and obtains the target memory capacity."

[0103] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include:

[0104] Receive memory requirement information, parse the memory requirement information, and obtain the target memory capacity;

[0105] The target memory pool is selected from the set of memory pools based on the target memory capacity. The set of memory pools includes multiple memory pools with different memory block sizes.

[0106] Select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size.

[0107] Based on the usage status of memory blocks in the target linked list, select an unoccupied memory block from the target linked list as the target memory block, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

[0108] According to the technical solution of this invention, memory allocation can be performed using memory pools containing memory block sizes. A target memory pool and a target memory list are selected based on memory demand information, and then a list item is selected. Based on the usage status of the memory blocks in the list item, unoccupied memory blocks are selected for memory allocation. The introduction of the list and list items reduces memory fragmentation, improves memory utilization, and reduces waste. Furthermore, using memory pools corresponding to memory blocks of different sizes also improves the efficiency of memory allocation management.

[0109] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A memory management method, characterized in that, include: Receive memory requirement information and parse the memory requirement information to obtain the target memory capacity; A target memory pool is selected from a set of memory pools based on the target memory capacity. The set of memory pools includes multiple memory pools with different memory block sizes. Select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size. Based on the usage status of memory blocks in the target linked list item, an unoccupied memory block is selected from the target linked list item as the target memory block, and the memory corresponding to the target memory block is allocated to the object corresponding to the memory requirement information.

2. The method according to claim 1, characterized in that, After allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method further includes: Update the usage status of the target memory block to show that it is occupied.

3. The method according to claim 2, characterized in that, The step of selecting the target memory list in the target memory pool includes: In the target memory pool, a memory list in a first state is selected as the target memory list, and the list entries in the memory list in the first state are partially occupied memory blocks; After selecting an unoccupied memory block from the target linked list as the target memory block based on the usage status of the memory blocks in the target linked list, and allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method further includes: In response to the fact that the memory blocks in the target linked list item are occupied, the first state of the target linked list item is updated to the second state, and the target linked list item is transferred from the target memory linked list to the memory linked list in the second state.

4. The method according to claim 3, characterized in that, The method further includes: If the target memory list does not have any list entries, then the memory list in the third state of the target memory pool is selected as the target memory list, and the list entries in the third state list are all memory blocks that are not occupied; After selecting an unoccupied memory block from the target linked list as the target memory block based on the usage status of the memory blocks in the target linked list, and allocating the memory corresponding to the target memory block to the object corresponding to the memory requirement information, the method further includes: Update the state of the target linked list item to the first state, and transfer the linked list item from the target memory linked list to the memory linked list in the first state.

5. The method according to any one of claims 1-4, characterized in that, The method further includes: When a memory release request corresponding to the target memory block is received, the address of the memory to be released is obtained by parsing the release request; The target linked list entry corresponding to the target memory block is determined based on the address; Update the usage status of the target memory block in the target linked list to "unoccupied".

6. The method according to claim 5, characterized in that, The method further includes: In response to the target linked list item being located in the memory linked list of the second state, the target linked list item is transferred to the memory linked list of the first state; In response to the target linked list item being located in the memory linked list in the first state, and the memory block usage state of the target linked list item being that all memory blocks are unoccupied, the target linked list item is transferred to the memory linked list in the third state.

7. The method according to claim 6, characterized in that, The method further includes: Memory release is performed on the linked list items in the memory linked list that have been transferred to the third state.

8. A memory management device, characterized in that, include: The parsing module is used to receive memory requirement information and parse the memory requirement information to obtain the target memory capacity; The selection module is used to select a target memory pool from a set of memory pools based on the target memory capacity, wherein the set of memory pools includes multiple memory pools with different memory block sizes; The selection module is used to select a target memory list in the target memory pool and determine the target list item in the target memory list. The target memory pool includes multiple memory lists, each memory list includes multiple list items, and each list item includes a memory block of the same size. The allocation module is used to select an unoccupied memory block from the target linked list item as the target memory block based on the usage status of the memory blocks in the target linked list item, and allocate the memory corresponding to the target memory block to the object corresponding to the memory requirement information.

9. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.

10. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-7.

11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-7.