Subsystem memory management method and device

By generating a linked list of pages to be allocated and adopting targeted memory allocation and recycling methods, the problems of frequent system calls and low efficiency in traditional memory management are solved, and the self-management and security of subsystem memory are achieved.

CN116049023BActive Publication Date: 2025-08-29SHENZHEN CHAOFAN INTELLIGENT COMPUTING TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211666381.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-23
Publication Date
2025-08-29
Estimated Expiration
2042-12-23

AI Technical Summary

Technical Problem

Traditional memory management methods lead to frequent system calls in the subsystem, resulting in frequent switching of user and kernel states, high system overhead, low memory allocation and recycling efficiency, affecting the operating environment security of trusted software bases.

Method used

By generating a linked list of pages to be allocated, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to recycle memory, avoid frequent calls to the operating system and realize self-management of subsystem memory.

Benefits of technology

Reduces system overhead, improves the efficiency of memory allocation and recycling, and provides a more secure and trustworthy software-based operating environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116049023B_ABST
    Figure CN116049023B_ABST
Patent Text Reader

Abstract

The present application relates to the field of memory management, and provides a subsystem memory management method and device. The method includes: applying for memory to be allocated from the operating system; the memory to be allocated is composed of multiple pages to be allocated; generating a linked list of pages to be allocated based on the multiple pages to be allocated; the nodes of the linked list of pages to be allocated correspond one-to-one with the multiple pages to be allocated; according to the linked list of pages to be allocated, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim the memory occupied by different types of data. The subsystem memory management method and device provided in the embodiment of the present application can realize self-management of subsystem memory and improve the efficiency of memory allocation and recycling, thereby providing a more secure operating environment for trusted software bases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory management technology, and in particular to a subsystem memory management method and device. Background Art

[0002] my country's independently developed Trusted Computing 3.0 technology is a trusted computing technology based on the Trusted Platform Control Module (TPCM) and an active immune dual-system architecture based on a independently developed symmetric and asymmetric cryptographic system. At the system device hardware layer, the TPCM is implanted as the root of trust, and the trusted cryptography module (TCM) is built in to implement trusted control functions. This combines cryptography and control to build a trusted computing node that performs both computing and protection. The root of trust implements active control of the trusted computing platform. At the device software layer, a dual system core consisting of the host operating system and the trusted software base is constructed by deploying a trusted software base. This allows for active trusted measurement of the system's execution environment and process behavior without changing the application layer software, building active immune defense capabilities for the system. At the system network layer, trusted connection technology is used to implement trusted verification and control of network access sources and target platforms, ensuring the trustworthiness of network connections and extending trustworthiness from a single point to the entire network.

[0003] To achieve the above technical functions, it is necessary to ensure the security of the trusted software base's operating environment. By constructing a secure subsystem as a process, the trusted software base can be securely operated within the operating system. However, the traditional subsystem involves memory allocation and usage for different types of data during operation. On the one hand, the traditional malloc and free functions are used, requesting memory from the operating system each time data is allocated. This method generates frequent system calls, leading to frequent switching between user and kernel states and high system overhead. On the other hand, the same memory allocation and deallocation methods are used for different types of data, resulting in low allocation and deallocation efficiency. The emergence of these problems will affect the security of the trusted software base's operating environment. Summary of the Invention

[0004] The embodiments of the present application provide a subsystem memory management method and device to solve the technical problem that the security of the trusted software base operating environment is reduced due to the high memory application overhead and low memory allocation and recovery efficiency under traditional methods.

[0005] In a first aspect, an embodiment of the present application provides a subsystem memory management method, comprising:

[0006] Applying to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0007] Generate a to-be-allocated page linked list based on the plurality of to-be-allocated pages; wherein the nodes of the to-be-allocated page linked list correspond one-to-one to the plurality of to-be-allocated pages;

[0008] According to the to-be-allocated page linked list, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim memory occupied by different types of data.

[0009] In one embodiment, allocating memory for different types of data using different allocation methods includes:

[0010] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the static data to be stored, allocating static memory for the static data to be stored in the remaining memory;

[0011] If the remaining memory size of the current page to be allocated is less than the memory size required for the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and static memory is allocated for the static data to be stored in the first free page.

[0012] In one embodiment, allocating memory for different types of data using different allocation methods includes:

[0013] Generate an index linked list; the nodes in the index linked list correspond one-to-one to different preset data sizes of allocated memory, and the nodes record the number of pages to be allocated occupied by the corresponding preset data size, the current page of the page to be allocated, and the number of free slots of the page to be allocated; the slot is the memory space in the available memory of any page to be allocated that is equal to the corresponding preset data size, and the available memory is the memory after removing the header record information of any page to be allocated;

[0014] Traversing the index linked list, if a matching preset data size exists among all preset data sizes corresponding to nodes in the index linked list, querying whether the number of to-be-allocated pages corresponding to the matching preset data size is zero; the matching preset data size is a preset data size equal to the size of the fixed-size data to be stored;

[0015] If the number of to-be-allocated pages corresponding to the matching preset data size is not zero, querying whether there is an idle slot in the current page of the to-be-allocated pages corresponding to the matching preset data size;

[0016] If the number of to-be-allocated pages corresponding to the matching preset data size is zero, obtaining a first free page corresponding to the node from the to-be-allocated page linked list, and allocating a fixed-size memory in the first free page for the fixed-size data to be stored;

[0017] If there is a free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the free slot is allocated as a fixed-size memory to the fixed-size data to be stored;

[0018] If there is no free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the first free page corresponding to the node is obtained from the to-be-allocated page linked list, and a fixed-size memory is allocated in the first free page for the fixed-size data to be stored.

[0019] In one embodiment, allocating memory for different types of data using different allocation methods includes:

[0020] If a matching to-be-allocated page exists among the plurality of to-be-allocated pages, dynamic memory is allocated in the matching to-be-allocated page for the dynamic data to be stored; the matching to-be-allocated page is a to-be-allocated page whose remaining memory size is greater than or equal to the memory size required by the dynamic data to be stored;

[0021] If there is no matching page to be allocated among the multiple pages to be allocated, query whether the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored;

[0022] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored, allocating dynamic memory for the dynamic data to be stored in the current page to be allocated;

[0023] If the remaining memory size of the current page to be allocated is smaller than the memory size required for the dynamic data to be stored, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and dynamic memory is allocated to the dynamic data to be stored in the first free page.

[0024] In one embodiment, allocating memory for different types of data using different allocation methods includes:

[0025] According to user needs, temporary memory is allocated in the preset temporary memory for temporary data to be stored; the preset temporary memory is a memory space pre-divided in the memory to be allocated for temporary memory allocation.

[0026] In one embodiment, the memory occupied by different types of data is reclaimed using different reclaiming methods, including:

[0027] Obtaining an offset of the page to be allocated in the slot to be reclaimed relative to the first page according to the logical address of the slot to be reclaimed, the first page logical address of the plurality of pages to be allocated, and the size of a single page to be allocated;

[0028] Obtaining the page to be allocated where the slot to be reclaimed is located according to the offset;

[0029] If the memory type of the page to be allocated where the slot to be reclaimed is located is fixed-size memory, query whether the slot to be reclaimed is occupied;

[0030] If the slot to be recycled is occupied, the memory of the slot to be recycled is cleared and recycled.

[0031] In one embodiment, the memory occupied by different types of data is reclaimed using different reclaiming methods, including:

[0032] Obtaining an offset of the to-be-allocated page where the to-be-allocated area is located relative to the to-be-allocated page based on the logical address of the to-be-allocated area, the home logical address of the plurality of to-be-allocated pages, and the size of a single to-be-allocated page; the to-be-allocated area is an area of ​​the to-be-allocated page that has occupied memory and has been freed by the user;

[0033] Obtaining the page to be allocated where the area to be reclaimed is located according to the offset;

[0034] If the memory type of the page to be allocated where the area to be reclaimed is located is dynamic memory, query whether the area to be reclaimed is adjacent to an unallocated area in the same page;

[0035] If the area to be reclaimed is adjacent to an unallocated area in the same page, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area;

[0036] If the area to be reclaimed is not adjacent to the unallocated area in the same page, query whether there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated;

[0037] If there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area;

[0038] If there is no unallocated area adjacent to the to-be-reclaimed area in other to-be-allocated pages corresponding to the node in the to-be-allocated page linked list, the memory of the to-be-reclaimed area is reclaimed, the to-be-reclaimed area is used as the to-be-allocated page corresponding to the new node, and the new node is inserted into the to-be-allocated page linked list.

[0039] In one embodiment, applying to the operating system for memory to be allocated includes:

[0040] If the subsystem runs in user space, it calls the malloc function to request the operating system to allocate memory;

[0041] If the subsystem runs in the kernel, it calls the kmalloc function to request the operating system to allocate memory.

[0042] In a second aspect, an embodiment of the present application provides a subsystem memory management device, comprising:

[0043] A memory application module is used to apply to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0044] a linked list generating module, configured to generate a linked list of pages to be allocated according to the plurality of pages to be allocated; wherein the nodes of the linked list of pages to be allocated correspond to the plurality of pages to be allocated in a one-to-one manner;

[0045] The memory allocation and recycling module is used to: allocate memory to different types of data using different allocation methods according to the to-be-allocated page linked list, and to reclaim memory occupied by different types of data using different recycling methods.

[0046] In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory storing a computer program, wherein when the processor executes the program, the steps of the subsystem memory management method described in the first aspect are implemented.

[0047] The subsystem memory management method and device provided by the present application first applies to the operating system for memory to be allocated, and generates a linked list of pages to be allocated based on multiple pages to be allocated, and then uses different allocation methods to allocate memory for different types of data based on the linked list of pages to be allocated, and uses different recovery methods to recover the memory occupied by different types of data. The present application first applies to the operating system for memory to be allocated once, and then allocates or recovers memory for different types of data within the subsystem, and only calls the operating system once in the initial state, avoiding frequent state switching between user state and kernel state, realizing self-management of subsystem memory, and greatly reducing system overhead; at the same time, since different methods are used for memory allocation and memory recovery for different types of data, memory allocation and recovery can be made more targeted, and the efficiency of allocation and recovery can be improved. Since the subsystem memory realizes self-management and the efficiency of memory allocation and recovery is improved, it can provide a more secure operating environment for trusted software bases. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0049] Figure 1 This is one of the flow charts of the subsystem memory management method provided in the embodiment of the present application;

[0050] Figure 2 This is the second flow chart of the subsystem memory management method provided in the embodiment of the present application;

[0051] Figure 3 This is the third flow chart of the subsystem memory management method provided in the embodiment of the present application;

[0052] Figure 4 This is the fourth flow chart of the subsystem memory management method provided in the embodiment of the present application;

[0053] Figure 5 A schematic diagram of the structure of a subsystem memory management device provided in an embodiment of the present application;

[0054] Figure 6 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0055] To make the objectives, technical solutions, and advantages of this application more clear, the technical solutions in this application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this application.

[0056] Figure 1 This is one of the flow charts of the subsystem memory management method provided in the embodiment of the present application. Figure 1 , an embodiment of the present application provides a subsystem memory management method, which may include:

[0057] 101. Apply to the operating system for memory to be allocated;

[0058] The memory to be allocated consists of multiple pages to be allocated;

[0059] 102. Generate a to-be-allocated page linked list based on multiple to-be-allocated pages;

[0060] The nodes of the to-be-allocated page linked list correspond one-to-one to the multiple to-be-allocated pages;

[0061] 103. According to the linked list of pages to be allocated, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim the memory occupied by different types of data.

[0062] In step 101, when the subsystem starts running, it applies for memory space of sufficient size from the operating system. The memory space is isolated from the host operating system memory. The pages to be allocated obtained in the application are all free pages in the initial state. After the application, the memory space is self-managed by the subsystem until the subsystem-specific program ends, and no more memory application and release requests are made to the operating system.

[0063] In step 102, if the application for the memory to be allocated is successful, the subsystem starts memory initialization. During the initialization process, a linked list of pages to be allocated is generated, and the home page data structure of multiple pages to be allocated is initialized, memory space for temporary memory allocation is allocated, and the linked list of pages to be allocated and the nodes are initialized.

[0064] Among them, the home page data structure is used to record the overall memory distribution of the subsystem and the specific information of the memory occupied by different types of data allocation, which can be shown in the following table:

[0065] Table 1 Home page data structure table

[0066]

[0067] When initializing the nodes in the linked list of pages to be allocated, each node is made to record three key pieces of information: a pointer to the previous page to be allocated, a pointer to the next page to be allocated, and the type of the current page to be allocated. The type of each node can be represented by the type of its corresponding page. The type of the page corresponds to the type of memory to which the page belongs. In this embodiment, the memory type can be static memory, fixed-size memory, dynamic memory, and temporary memory. The page type corresponding to the node (i.e., the node type) can be represented by the following values:

[0068] EMPTY_PAGE represents an idle page, FIRST_PAGE represents the first page, PAGE_TABLE represents the page table, TEMP_PAGE represents a temporary page, STATIC_PAGE represents a static page, CACHE_PAGE represents a fixed-size page, and DYNAMIC_PAGE represents a dynamic page, where the dynamic page can be a dynamic-size page.

[0069] The head node of the to-be-allocated page linked list points to the first unallocated to-be-allocated page and records information of all unallocated to-be-allocated pages.

[0070] In addition, when initializing the nodes in the linked list of pages to be allocated, the page type corresponding to the node defaults to EMPTY_PAGE. The type field of the node corresponding to the home page is initialized to FIRST_PAGE. The type field of the node corresponding to the memory page used for temporary memory allocation is initialized to TEMP_PAGE. The type field of the node corresponding to the page that stores all node information is initialized to PAGE_TABLE.

[0071] It should be noted that if the application for allocated memory fails, the subsystem process terminates.

[0072] Programs typically use the malloc and free functions to allocate and release memory. The malloc function calls the mmap function to request memory from the operating system. Once the memory is used up, the free function is called to release the memory. While typical processes only need to provide memory for users, subsystems require not only user memory but also memory for the subsystem itself. This memory allocated to the subsystem runs underlying functional modules, maintains the subsystem's operation, and provides a foundation for upper-level user-level operations. This memory is invisible to users and is released upon process termination. Using traditional malloc and free functions requires requesting memory from the operating system every time data is allocated. This approach generates frequent system calls, leading to frequent switching between user and kernel modes and high system overhead. Furthermore, this approach lacks tailored memory allocation and deallocation for different types of data, resulting in low allocation and deallocation efficiency.

[0073] The subsystem memory management method provided in this embodiment first applies to the operating system for memory to be allocated, and generates a linked list of pages to be allocated based on multiple pages to be allocated, and then uses different allocation methods to allocate memory for different types of data based on the linked list of pages to be allocated, and uses different recovery methods to recover the memory occupied by different types of data. This embodiment first applies to the operating system for memory to be allocated once, and then allocates or recovers memory for different types of data within the subsystem, and only calls the operating system once in the initial state, avoiding frequent state switching between user mode and kernel mode, realizing self-management of subsystem memory, and greatly reducing system overhead; at the same time, since different methods are used for memory allocation and memory recovery for different types of data, memory allocation and recovery can be made more targeted, and the efficiency of allocation and recovery can be improved. Since the subsystem memory realizes self-management and the efficiency of memory allocation and recovery is improved, it can provide a more secure operating environment for trusted software bases.

[0074] In one embodiment, different allocation methods are used to allocate memory for different types of data, which may include allocating memory for static data:

[0075] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the static data to be stored, static memory is allocated in the remaining memory for the static data to be stored;

[0076] curr_offset records the address already used by the current page to be allocated, that is, the memory size already used by the current page to be allocated. If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the static data to be stored, that is, the current page to be allocated has enough space to be allocated to the static data to be stored, then the space is used to allocate static memory for the static data to be stored, and the curr_offset value is updated, that is, the address already used by the current page to be allocated and the memory size already used are updated, and the total size occupied by the static memory is updated at the same time, and the first address of the allocated address in the static memory is returned to the upper-level calling function.

[0077] If the remaining memory size of the current page to be allocated is less than the memory size required for the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and static memory is allocated for the static data to be stored in the first free page.

[0078] If the remaining memory size of the current page to be allocated is less than the memory size required for the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, that is, the current page to be allocated does not have enough space to be allocated to the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, then the get_page function is used to obtain the first free page corresponding to the node from the page to be allocated list, allocate static memory for the static data to be stored in the first free page, and update the node type corresponding to the first free page to STATIC_PAGE, insert the node into the static memory page list, and use the first free page corresponding to the node as the current page to be allocated of the static memory page, and then update the relevant information of curr_offset and static_sys according to the current page to be allocated.

[0079] It should be noted that the static memory allocated for storing static data will not be released once allocated until the subsystem specific program ends. The static memory is mainly used to store the key data of the subsystem itself.

[0080] Before determining the relationship between the remaining memory size of the current page to be allocated and the memory size required for the static data to be stored, it is necessary to first determine the memory size required for the static data to be stored. Based on compatibility considerations, the memory size required for the static data to be stored is not its actual size, but should be a multiple of 4 bytes. Therefore, the memory size required for the static data to be stored should be the value obtained by rounding up the actual size of the static data to be stored divided by 4, and then multiplying it by 4. For example, the actual size of the static data to be stored is 6 bytes, and the required memory size is 2, which is the value obtained by rounding up the value of 6 divided by 4, and then multiplied by 4, which is 8 bytes.

[0081] This embodiment adopts the static memory allocation function to allocate static memory to static data according to its characteristics, thereby improving memory allocation efficiency.

[0082] Figure 2 This is the second flow chart of the subsystem memory management method provided in the embodiment of the present application. Figure 2 In one embodiment, different allocation methods are used to allocate memory for different types of data, which may include allocating memory for fixed-size data:

[0083] 201. Generate an index linked list;

[0084] The nodes in the index linked list correspond one-to-one to different preset data sizes of allocated memory, and the nodes record the number of pages to be allocated occupied by the corresponding preset data size, the current page of the page to be allocated, and the number of free slots of the page to be allocated; the slot is the memory space in the available memory of any page to be allocated that is equal to the corresponding preset data size, and the available memory is the memory after removing the header record information of any page to be allocated;

[0085] 202. Traverse the index linked list. If a matching preset data size exists among all preset data sizes corresponding to the nodes in the index linked list, check whether the number of to-be-allocated pages corresponding to the matching preset data size is zero.

[0086] Matching the preset data size to a preset data size that is equal to the fixed-size data to be stored;

[0087] 203. If the number of to-be-allocated pages corresponding to the matching preset data size is not zero, query whether there is an idle slot in the current page of the to-be-allocated pages corresponding to the matching preset data size;

[0088] 204. If the number of to-be-allocated pages corresponding to the preset data size is zero, obtain the first free page corresponding to the node from the to-be-allocated page linked list, and allocate fixed-size memory in the first free page for the fixed-size data to be stored;

[0089] 205. If there is a free slot in the current page of the to-be-allocated page corresponding to the preset data size, allocate the free slot as a fixed-size memory to the fixed-size data to be stored;

[0090] 206. If there is no free slot in the current page of the to-be-allocated page corresponding to the preset data size, obtain the first free page corresponding to the node from the to-be-allocated page linked list, and allocate fixed-size memory in the first free page for the fixed-size data to be stored.

[0091] In step 201, fixed-size memory allocation is mainly used to store data of commonly used data sizes within the subsystem. Since the commonly used data sizes within the subsystem are 16 bytes, 28 bytes, 32 bytes, etc., 16 bytes, 28 bytes, 32 bytes, etc. can be used as preset data sizes. The number of preset data sizes is not limited here. In this embodiment, the number of preset data sizes can be set to 16 (corresponding to the number of fixed data sizes in Table 1), that is, there are a total of 16 preset data size values ​​of different byte sizes, and there are at most 16 nodes in the index linked list, each node corresponding to a preset data size value and the preset data size value. The number of occupied pages to be allocated, the current page of the page to be allocated, and the number of free slots of the page to be allocated. For example, the first node corresponds to 16 bytes, and the number of pages to be allocated occupied by the 16 bytes is 5 pages, which means that these 5 pages to be allocated are all used to allocate memory for 16-byte data. The current page of the page to be allocated is the current page of the 5 occupied pages to be allocated. The first node can correspond to the current page by the page number corresponding to the current page. The first node can also correspond to the first page of the 5 pages to be allocated by the page number corresponding to the first page. The number of free slots of the page to be allocated is the number of free slots in the 5 occupied pages to be allocated.

[0092] Among them, the memory space after removing the header record information of any page among the 5 pages to be allocated is divided into slots according to the preset data size, that is, 16 bytes, that is, every 16 bytes is a slot, and the number of slots in any page to be allocated among the 5 pages to be allocated is the value obtained by dividing the memory space after removing the header record information of the page by 16 bytes. The free slot is the slot that has not yet been allocated.

[0093] In addition, the starting position of each of the five pages to be allocated will record the information of the page, such as the memory size of the page, the number of free slots of the page, and the bitmap. The bitmap records the usage of each slot of the page, 1 represents allocated, and 0 represents unallocated.

[0094] The preset data size information corresponding to the other 15 nodes can be obtained similarly.

[0095] In step 202, for example, if the fixed-size data to be stored is 16 bytes, then it is queried in the nodes of the index linked list whether there is a node corresponding to the preset data size of 16 bytes. If so, 16 bytes matches the preset data size, and then it is queried whether the number of pages to be allocated corresponding to 16 bytes is zero.

[0096] In step 203 , for example, if the number of pages to be allocated corresponding to 16 bytes is 5 pages and is not zero, it is checked whether there is a free slot in the current page of the 5 pages.

[0097] In step 204, for example, if the number of pages to be allocated corresponding to 16 bytes is 0 pages, that is, no memory is allocated for 16 bytes of data, the first free page corresponding to the node is obtained from the to-be-allocated page list through the get_page function, and a fixed-size memory is allocated for the fixed-size data to be stored in the first free page, and the node type corresponding to the first free page is updated to CACHE_PAGE, and the node is inserted into the corresponding fixed-size memory page list. The first free page corresponding to the node is used as the current to-be-allocated page of the fixed-size memory page, that is, the node is inserted into the linked list corresponding to 16 bytes. This node corresponds to the current to-be-allocated page, and then the header information of the current to-be-allocated page is initialized. The index linked list and the relevant information of cache_sys are updated according to the current to-be-allocated page.

[0098] In step 205, the free slot is allocated as a fixed-size memory to the fixed-size data to be stored, and the header information of the current page to be allocated corresponding to the preset data size is updated, including the number of slots and the bitmap, where the bitmap is set to 1. In addition, it is necessary to return the address of the free slot, update the index node information and cache_sys, and calculate the return address of the allocation function.

[0099] In step 206, the first free page corresponding to the node is obtained from the list of pages to be allocated through the get_page function, a fixed-size memory is allocated for the fixed-size data to be stored in the first free page, and the node type corresponding to the first free page is updated to CACHE_PAGE, and the node is inserted into the corresponding fixed-size memory page list. The first free page corresponding to the node is used as the current page to be allocated of the fixed-size memory page, that is, the node is inserted into the list corresponding to 16 bytes. This node corresponds to the current page to be allocated, and then the header information of the current page to be allocated is initialized. The index list and the relevant information of cache_sys are updated according to the current page to be allocated.

[0100] It should be noted that since the index linked list is generated synchronously with the fixed-size memory allocation, when the number of linked list nodes increases to the upper limit of 16 and the to-be-allocated page corresponding to the 16th node has been allocated, it means that the current fixed-size memory allocation resources have been exhausted. If there is further fixed-size data requesting memory allocation, an allocation error will be returned.

[0101] This embodiment adopts a fixed-size memory allocation function, and can allocate fixed-size memory to fixed-size data according to its characteristics, thereby improving memory allocation efficiency.

[0102] In one embodiment, different allocation methods are used to allocate memory for different types of data, which may include allocating memory for dynamic data:

[0103] If there is a matching page to be allocated among the multiple pages to be allocated, dynamic memory is allocated for the dynamic data to be stored in the matching page to be allocated, and the address of the allocated memory area is returned;

[0104] The matching to-be-allocated page is a to-be-allocated page whose remaining memory size is greater than or equal to the memory size required for storing the dynamic data;

[0105] If there is no matching page to be allocated among the multiple pages to be allocated, then check whether the remaining memory size of the current page to be allocated is greater than or equal to the memory size required to store the dynamic data;

[0106] Among them, curr_offset records the address of the current page to be allocated that has been used, that is, the memory size of the current page to be allocated that has been used;

[0107] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored, dynamic memory is allocated for the dynamic data to be stored in the current page to be allocated, the address of the allocated memory area is returned, and the dmem_sys and curr_offset values ​​are updated;

[0108] If the remaining memory size of the current page to be allocated is smaller than the memory size required for the dynamic data to be stored, the get_page function is used to obtain the first free page corresponding to the node from the page list to be allocated, dynamic memory is allocated for the dynamic data to be stored in the first free page, and the node type corresponding to the first free page is updated to DYNAMIC_PAGE. The node is inserted into the corresponding dynamic memory page list, and the first free page corresponding to the node is used as the current page to be allocated of the dynamic memory page. Then, the relevant information of curr_offset and dmem_sys is updated according to the current page to be allocated.

[0109] The purpose of the dynamic memory allocation function is to complement the fixed-size memory allocation function. Since the fixed-size memory allocation function sets an upper limit of 16 data types, dynamic memory allocation is used for data allocation of uncommon size types.

[0110] It should be noted that before determining the relationship between the current remaining memory size of the page to be allocated and the memory size required for the dynamic data to be stored, it is necessary to first determine the memory size required for the dynamic data to be stored. Based on compatibility considerations, the memory size required for the dynamic data to be stored is not its actual size, but should be a multiple of 4 bytes. Therefore, the memory size required for the dynamic data to be stored should be the actual size of the dynamic data to be stored divided by 4, rounded up, and then multiplied by 4 to obtain the value. For example, the actual size of the dynamic data to be stored is 6 bytes, and the required memory size is 2, the value obtained by rounding up the value of 6 divided by 4, and then multiplied by 4, which is 8 bytes.

[0111] This embodiment adopts the dynamic memory allocation function to allocate dynamic memory to dynamic data according to its characteristics, thereby improving memory allocation efficiency.

[0112] In one embodiment, different allocation methods are used to allocate memory for different types of data, which may include allocating memory for temporary data:

[0113] Allocate temporary memory for temporary data to be stored in the preset temporary memory according to user needs;

[0114] The preset temporary memory is a memory space that is pre-allocated from the memory to be allocated and used for temporary memory allocation, that is, the memory space that is allocated for temporary memory allocation when the subsystem memory is initialized.

[0115] Static memory allocation, fixed-size memory allocation, and dynamic memory allocation are applicable to system-level memory allocation in subsystems. For users, the implementation of the temporary memory allocation function only requires calling the preset temporary memory to allocate memory for temporary data. The usage of temporary memory allocation is the same as the malloc function provided by the operating system.

[0116] This embodiment adopts the temporary memory allocation function to allocate temporary memory to temporary data according to its characteristics, thereby improving memory allocation efficiency.

[0117] Figure 3 This is the third flow chart of the subsystem memory management method provided in the embodiment of this application. Figure 3 In one embodiment, different recycling methods are used to reclaim memory occupied by different types of data, which may include recycling memory occupied by fixed-size data:

[0118] 301. Obtain an offset of the to-be-allocated page in the to-be-allocated slot relative to the to-be-allocated page based on the logical address of the to-be-allocated slot, the logical address of the first page of the plurality of to-be-allocated pages, and the size of a single to-be-allocated page.

[0119] 302. Obtain the page to be allocated where the slot to be reclaimed is located according to the offset;

[0120] 303. If the memory type of the page to be allocated where the slot to be reclaimed is located is fixed-size memory, check whether the slot to be reclaimed is occupied.

[0121] 304. If the slot to be recycled is occupied, clear and recycle the memory of the slot to be recycled.

[0122] In step 301 , the offset of the page to be allocated where the slot to be reclaimed is located relative to the home page is equal to the value obtained by subtracting the logical address of the home page from the logical address of the slot to be reclaimed, divided by the size of a single page to be allocated.

[0123] In step 303, it is checked whether the slot to be recycled is occupied to prevent secondary release.

[0124] In step 304, it is also necessary to set the bitmap to 0 and update the header information of the page to be allocated where the slot to be reclaimed is located.

[0125] It should be noted that if the memory type of the page to be allocated where the slot to be reclaimed is located is not fixed-size memory, or the slot to be reclaimed is not occupied, a reclaim error message is returned.

[0126] This embodiment adopts the fixed-size memory recycling function to reclaim memory based on the characteristics of fixed-size data, thereby improving memory recycling efficiency.

[0127] Figure 4 This is the fourth flow chart of the subsystem memory management method provided in the embodiment of the present application. Figure 4 In one embodiment, different recycling methods are used to reclaim memory occupied by different types of data, which may include reclaiming memory occupied by dynamic data:

[0128] 401. Obtain an offset of the to-be-allocated page in the to-be-allocated area relative to the first page based on the logical address of the to-be-allocated area, the first logical address of the plurality of to-be-allocated pages, and the size of a single to-be-allocated page.

[0129] The area to be reclaimed is the area of ​​memory that has been occupied in the page to be allocated and has been released by the user;

[0130] 402. Obtain the page to be allocated where the area to be reclaimed is located according to the offset;

[0131] 403. If the memory type of the page to be allocated where the area to be reclaimed is located is dynamic memory, check whether the area to be reclaimed is adjacent to an unallocated area in the same page;

[0132] 404. If the area to be reclaimed is adjacent to an unallocated area in the same page, reclaim the memory of the area to be reclaimed and merge the area to be reclaimed and the unallocated area into a new unallocated area.

[0133] 405. If the area to be reclaimed is not adjacent to the unallocated area in the same page, then query whether there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the node in the linked list of pages to be allocated;

[0134] 406. If there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the node in the linked list of pages to be allocated, reclaim the memory of the area to be reclaimed, and merge the area to be reclaimed and the unallocated area into a new unallocated area.

[0135] 407. If there is no unallocated area adjacent to the to-be-reclaimed area in other to-be-allocated pages corresponding to the node in the to-be-allocated page linked list, reclaim the to-be-reclaimed area memory, use the to-be-allocated area as the to-be-allocated page corresponding to the new node, and insert the new node into the to-be-allocated page linked list.

[0136] In step 403, if the memory type of the page to be allocated where the area to be reclaimed is located is not dynamic memory, a reclaim error message is returned.

[0137] In step 407, dmem_sys also needs to be updated.

[0138] It should be noted that for the area to be reclaimed that is not adjacent to the unallocated area, curr_offset is updated only after all addresses higher than the area to be reclaimed are released. In this application, the default memory allocation starts from the lowest address.

[0139] This embodiment adopts the dynamic memory recycling function to reclaim memory based on the characteristics of dynamic data, thereby improving memory recycling efficiency.

[0140] In one embodiment, requesting the operating system to allocate memory may include:

[0141] If the subsystem runs in user space, it calls the malloc function to request the operating system to allocate memory;

[0142] If the subsystem runs in the kernel, it calls the kmalloc function to request the operating system to allocate memory.

[0143] This embodiment calls corresponding functions to apply for memory to be allocated from the operating system according to different subsystem operating environments, which can improve the success rate of memory application.

[0144] The subsystem memory management device provided in an embodiment of the present application is described below. The subsystem memory management device described below and the subsystem memory management method described above can be referenced to each other.

[0145] Figure 5 This is a schematic diagram of the structure of the subsystem memory management device provided in the embodiment of the present application. Figure 5 , an embodiment of the present application provides a subsystem memory management device, which may include:

[0146] The memory application module 501 is used to apply to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0147] The linked list generating module 502 is configured to generate a linked list of pages to be allocated based on the plurality of pages to be allocated; wherein the nodes of the linked list of pages to be allocated correspond to the plurality of pages to be allocated in a one-to-one manner;

[0148] The memory allocation and recycling module 503 is used to: allocate memory to different types of data using different allocation methods according to the to-be-allocated page linked list, and reclaim memory occupied by different types of data using different recycling methods.

[0149] The subsystem memory management device provided in this embodiment first applies to the operating system for memory to be allocated, and generates a linked list of pages to be allocated based on multiple pages to be allocated, and then uses different allocation methods to allocate memory for different types of data based on the linked list of pages to be allocated, and uses different recovery methods to recover the memory occupied by different types of data. This embodiment first applies to the operating system for memory to be allocated once, and then allocates or recovers memory for different types of data within the subsystem, and only calls the operating system once in the initial state, avoiding frequent state switching between user mode and kernel mode, realizing self-management of subsystem memory, and greatly reducing system overhead; at the same time, since different methods are used for memory allocation and memory recovery for different types of data, memory allocation and recovery can be made more targeted, and the efficiency of allocation and recovery can be improved. Since the subsystem memory realizes self-management and the efficiency of memory allocation and recovery is improved, it can provide a more secure operating environment for trusted software bases.

[0150] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0151] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the static data to be stored, allocating static memory for the static data to be stored in the remaining memory;

[0152] If the remaining memory size of the current page to be allocated is less than the memory size required for the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and static memory is allocated for the static data to be stored in the first free page.

[0153] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0154] Generate an index linked list; the nodes in the index linked list correspond one-to-one to different preset data sizes of allocated memory, and the nodes record the number of pages to be allocated occupied by the corresponding preset data size, the current page of the page to be allocated, and the number of free slots of the page to be allocated; the slot is the memory space in the available memory of any page to be allocated that is equal to the corresponding preset data size, and the available memory is the memory after removing the header record information of any page to be allocated;

[0155] Traversing the index linked list, if a matching preset data size exists among all preset data sizes corresponding to nodes in the index linked list, querying whether the number of to-be-allocated pages corresponding to the matching preset data size is zero; the matching preset data size is a preset data size equal to the size of the fixed-size data to be stored;

[0156] If the number of to-be-allocated pages corresponding to the matching preset data size is not zero, querying whether there is an idle slot in the current page of the to-be-allocated pages corresponding to the matching preset data size;

[0157] If the number of to-be-allocated pages corresponding to the matching preset data size is zero, obtaining a first free page corresponding to the node from the to-be-allocated page linked list, and allocating a fixed-size memory in the first free page for the fixed-size data to be stored;

[0158] If there is a free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the free slot is allocated as a fixed-size memory to the fixed-size data to be stored;

[0159] If there is no free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the first free page corresponding to the node is obtained from the to-be-allocated page linked list, and a fixed-size memory is allocated in the first free page for the fixed-size data to be stored.

[0160] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0161] If a matching to-be-allocated page exists among the plurality of to-be-allocated pages, dynamic memory is allocated in the matching to-be-allocated page for the dynamic data to be stored; the matching to-be-allocated page is a to-be-allocated page whose remaining memory size is greater than or equal to the memory size required by the dynamic data to be stored;

[0162] If there is no matching page to be allocated among the multiple pages to be allocated, query whether the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored;

[0163] If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored, allocating dynamic memory for the dynamic data to be stored in the current page to be allocated;

[0164] If the remaining memory size of the current page to be allocated is smaller than the memory size required for the dynamic data to be stored, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and dynamic memory is allocated to the dynamic data to be stored in the first free page.

[0165] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0166] According to user needs, temporary memory is allocated in the preset temporary memory for temporary data to be stored; the preset temporary memory is a memory space pre-divided in the memory to be allocated for temporary memory allocation.

[0167] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0168] Obtaining an offset of the page to be allocated in the slot to be reclaimed relative to the first page according to the logical address of the slot to be reclaimed, the first page logical address of the plurality of pages to be allocated, and the size of a single page to be allocated;

[0169] Obtaining the page to be allocated where the slot to be reclaimed is located according to the offset;

[0170] If the memory type of the page to be allocated where the slot to be reclaimed is located is fixed-size memory, query whether the slot to be reclaimed is occupied;

[0171] If the slot to be recycled is occupied, the memory of the slot to be recycled is cleared and recycled.

[0172] In one embodiment, the memory allocation and recycling module 503 is specifically configured to:

[0173] Obtaining an offset of the to-be-allocated page where the to-be-allocated area is located relative to the to-be-allocated page based on the logical address of the to-be-allocated area, the home logical address of the plurality of to-be-allocated pages, and the size of a single to-be-allocated page; the to-be-allocated area is an area of ​​the to-be-allocated page that has occupied memory and has been freed by the user;

[0174] Obtaining the page to be allocated where the area to be reclaimed is located according to the offset;

[0175] If the memory type of the page to be allocated where the area to be reclaimed is located is dynamic memory, query whether the area to be reclaimed is adjacent to an unallocated area in the same page;

[0176] If the area to be reclaimed is adjacent to an unallocated area in the same page, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area;

[0177] If the area to be reclaimed is not adjacent to the unallocated area in the same page, query whether there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated;

[0178] If there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area;

[0179] If there is no unallocated area adjacent to the to-be-reclaimed area in other to-be-allocated pages corresponding to the node in the to-be-allocated page linked list, the memory of the to-be-reclaimed area is reclaimed, the to-be-reclaimed area is used as the to-be-allocated page corresponding to the new node, and the new node is inserted into the to-be-allocated page linked list.

[0180] In one embodiment, the memory application module 501 is specifically configured to:

[0181] If the subsystem runs in user space, it calls the malloc function to request the operating system to allocate memory;

[0182] If the subsystem runs in the kernel, it calls the kmalloc function to request the operating system to allocate memory.

[0183] Figure 6 An example of a physical structure diagram of an electronic device is shown below. Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other via the communication bus 640. The processor 610 may call a computer program in the memory 630 to execute the steps of the subsystem memory management method, for example, including:

[0184] Applying to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0185] Generate a to-be-allocated page linked list based on the plurality of to-be-allocated pages; wherein the nodes of the to-be-allocated page linked list correspond one-to-one to the plurality of to-be-allocated pages;

[0186] According to the to-be-allocated page linked list, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim memory occupied by different types of data.

[0187] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0188] On the other hand, embodiments of the present application further provide a computer program product, comprising a computer program. The computer program may be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the steps of the subsystem memory management method provided in each of the above embodiments, for example, including:

[0189] Applying to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0190] Generate a to-be-allocated page linked list based on the plurality of to-be-allocated pages; wherein the nodes of the to-be-allocated page linked list correspond one-to-one to the plurality of to-be-allocated pages;

[0191] According to the to-be-allocated page linked list, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim memory occupied by different types of data.

[0192] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, wherein the computer program is configured to cause a processor to execute the steps of the methods provided in the above embodiments, for example, including:

[0193] Applying to the operating system for memory to be allocated; the memory to be allocated is composed of multiple pages to be allocated;

[0194] Generate a to-be-allocated page linked list based on the plurality of to-be-allocated pages; wherein the nodes of the to-be-allocated page linked list correspond one-to-one to the plurality of to-be-allocated pages;

[0195] According to the to-be-allocated page linked list, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim memory occupied by different types of data.

[0196] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO)), optical storage (such as CDs, DVDs, BDs, HVDs, etc.), and semiconductor storage (such as ROMs, EPROMs, EEPROMs, non-volatile memories (NANDFLASH), solid-state drives (SSDs)), etc.

[0197] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.

[0198] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.

[0199] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A subsystem memory management method, characterized in that: include: Apply to the operating system for memory to be allocated; The memory to be allocated is composed of a plurality of pages to be allocated; Generate a to-be-allocated page linked list according to the plurality of to-be-allocated pages; The nodes of the to-be-allocated page linked list correspond one-to-one to the multiple to-be-allocated pages; According to the to-be-allocated page linked list, different allocation methods are used to allocate memory for different types of data, and different recycling methods are used to reclaim the memory occupied by different types of data, including: Generate an index linked list; the nodes in the index linked list correspond one-to-one to different preset data sizes of allocated memory, and the nodes record the number of pages to be allocated occupied by the corresponding preset data size, the current page of the page to be allocated, and the number of free slots of the page to be allocated; the slot is the memory space in the available memory of any page to be allocated that is equal to the corresponding preset data size, and the available memory is the memory after removing the header record information of any page to be allocated; Traversing the index linked list, if a matching preset data size exists among all preset data sizes corresponding to nodes in the index linked list, querying whether the number of to-be-allocated pages corresponding to the matching preset data size is zero; the matching preset data size is a preset data size equal to the size of the fixed-size data to be stored; If the number of to-be-allocated pages corresponding to the matching preset data size is not zero, querying whether there is an idle slot in the current page of the to-be-allocated pages corresponding to the matching preset data size; If the number of to-be-allocated pages corresponding to the matching preset data size is zero, obtaining a first free page corresponding to the node from the to-be-allocated page linked list, and allocating a fixed-size memory in the first free page for the fixed-size data to be stored; If there is a free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the free slot is allocated as a fixed-size memory to the fixed-size data to be stored; If there is no free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the first free page corresponding to the node is obtained from the to-be-allocated page linked list, and a fixed-size memory is allocated in the first free page for the fixed-size data to be stored.

2. The subsystem memory management method according to claim 1, characterized in that: The different allocation methods used to allocate memory for different types of data include: If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the static data to be stored, allocating static memory for the static data to be stored in the remaining memory; If the remaining memory size of the current page to be allocated is less than the memory size required for the static data to be stored or the number of pages to be allocated occupied by the static data to be stored is zero, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and static memory is allocated for the static data to be stored in the first free page.

3. The subsystem memory management method according to claim 1, characterized in that: The different allocation methods used to allocate memory for different types of data include: If a matching to-be-allocated page exists among the plurality of to-be-allocated pages, dynamic memory is allocated in the matching to-be-allocated page for the dynamic data to be stored; the matching to-be-allocated page is a to-be-allocated page whose remaining memory size is greater than or equal to the memory size required by the dynamic data to be stored; If there is no matching page to be allocated among the multiple pages to be allocated, query whether the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored; If the remaining memory size of the current page to be allocated is greater than or equal to the memory size required for the dynamic data to be stored, allocating dynamic memory for the dynamic data to be stored in the current page to be allocated; If the remaining memory size of the current page to be allocated is smaller than the memory size required for the dynamic data to be stored, the first free page corresponding to the node is obtained from the linked list of pages to be allocated, and dynamic memory is allocated to the dynamic data to be stored in the first free page.

4. The subsystem memory management method according to claim 1, wherein: The different allocation methods used to allocate memory for different types of data include: According to user needs, temporary memory is allocated in the preset temporary memory for temporary data to be stored; the preset temporary memory is a memory space pre-divided in the memory to be allocated for temporary memory allocation.

5. The subsystem memory management method according to claim 1, wherein: The memory occupied by different types of data is reclaimed using different recycling methods, including: Obtaining an offset of the page to be allocated in the slot to be reclaimed relative to the first page according to the logical address of the slot to be reclaimed, the first page logical address of the plurality of pages to be allocated, and the size of a single page to be allocated; Obtaining the page to be allocated where the slot to be reclaimed is located according to the offset; If the memory type of the page to be allocated where the slot to be reclaimed is located is fixed-size memory, query whether the slot to be reclaimed is occupied; If the slot to be recycled is occupied, the memory of the slot to be recycled is cleared and recycled.

6. The subsystem memory management method according to claim 3, characterized in that: The memory occupied by different types of data is reclaimed using different recycling methods, including: Obtaining an offset of the to-be-allocated page where the to-be-allocated area is located relative to the to-be-allocated page based on the logical address of the to-be-allocated area, the home logical address of the plurality of to-be-allocated pages, and the size of a single to-be-allocated page; the to-be-allocated area is an area of ​​the to-be-allocated page that has occupied memory and has been freed by the user; Obtaining the page to be allocated where the area to be reclaimed is located according to the offset; If the memory type of the page to be allocated where the area to be reclaimed is located is dynamic memory, query whether the area to be reclaimed is adjacent to an unallocated area in the same page; If the area to be reclaimed is adjacent to an unallocated area in the same page, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area; If the area to be reclaimed is not adjacent to the unallocated area in the same page, query whether there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated; If there is an unallocated area adjacent to the area to be reclaimed in other pages to be allocated corresponding to the nodes in the linked list of pages to be allocated, reclaiming the memory of the area to be reclaimed, and merging the area to be reclaimed and the unallocated area into a new unallocated area; If there is no unallocated area adjacent to the to-be-reclaimed area in other to-be-allocated pages corresponding to the node in the to-be-allocated page linked list, the memory of the to-be-reclaimed area is reclaimed, the to-be-reclaimed area is used as the to-be-allocated page corresponding to the new node, and the new node is inserted into the to-be-allocated page linked list.

7. The subsystem memory management method according to claim 1, characterized in that: The step of requesting the operating system for memory to be allocated includes: If the subsystem runs in user space, it calls the malloc function to request the operating system to allocate memory; If the subsystem runs in the kernel, it calls the kmalloc function to request the operating system to allocate memory.

8. A subsystem memory management device, characterized in that: include: Memory application module, used to: apply for memory to be allocated from the operating system; The memory to be allocated is composed of a plurality of pages to be allocated; a linked list generating module, configured to generate a linked list of pages to be allocated according to the plurality of pages to be allocated; wherein the nodes of the linked list of pages to be allocated correspond to the plurality of pages to be allocated in a one-to-one manner; The memory allocation and recycling module is used to allocate memory for different types of data using different allocation methods according to the to-be-allocated page linked list, and to reclaim memory occupied by different types of data using different recycling methods, including: Generate an index linked list; the nodes in the index linked list correspond one-to-one to different preset data sizes of allocated memory, and the nodes record the number of pages to be allocated occupied by the corresponding preset data size, the current page of the page to be allocated, and the number of free slots of the page to be allocated; the slot is the memory space in the available memory of any page to be allocated that is equal to the corresponding preset data size, and the available memory is the memory after removing the header record information of any page to be allocated; Traversing the index linked list, if a matching preset data size exists among all preset data sizes corresponding to nodes in the index linked list, querying whether the number of to-be-allocated pages corresponding to the matching preset data size is zero; the matching preset data size is a preset data size equal to the size of the fixed-size data to be stored; If the number of to-be-allocated pages corresponding to the matching preset data size is not zero, querying whether there is an idle slot in the current page of the to-be-allocated pages corresponding to the matching preset data size; If the number of to-be-allocated pages corresponding to the matching preset data size is zero, obtaining a first free page corresponding to the node from the to-be-allocated page linked list, and allocating a fixed-size memory in the first free page for the fixed-size data to be stored; If there is a free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the free slot is allocated as a fixed-size memory to the fixed-size data to be stored; If there is no free slot in the current page of the to-be-allocated page corresponding to the matching preset data size, the first free page corresponding to the node is obtained from the to-be-allocated page linked list, and a fixed-size memory is allocated in the first free page for the fixed-size data to be stored.

9. An electronic device comprising a processor and a memory storing a computer program, characterized in that: When the processor executes the computer program, the steps of the subsystem memory management method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Embedded software memory management system

    CN108132842A

  • Memory management method, system and device and readable storage medium

    CN113010453A