Memory management method, electronic device, storage medium, and computer program product

By performing hot and cold state scanning and detailed partitioning of the virtual memory space, generating sets of hot and cold pages, the problems of low memory management flexibility and poor memory swapping performance in existing technologies are solved, achieving more efficient memory management and system stability.

WO2026012104A1PCT designated stage Publication Date: 2026-01-15CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2025/102537
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-07-10
Filing Date
2025-06-20
Publication Date
2026-01-15

AI Technical Summary

Technical Problem

Existing memory management mechanisms based on the LRU algorithm suffer from low flexibility in application scenarios, poor memory swapping performance, and low operating system stability.

Method used

By scanning the virtual memory space for hot and cold memory status, multiple sets of hot pages and cold pages are generated. Based on this information, memory pages to be swapped are selected for memory swapping, thereby improving the flexibility of memory management and system stability.

Benefits of technology

It enables efficient memory swapping of the operating system's virtual memory space, enhancing the system's memory management flexibility and stability, and improving the system's elasticity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025102537_15012026_PF_FP_ABST
    Figure CN2025102537_15012026_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computers. Disclosed are a memory management method, an electronic device, a storage medium, and a computer program product. The method comprises: in response to a memory cold / hot-state scanning instruction, determining, from a virtual memory space, a memory segment to be scanned; performing cold / hot state scanning on a plurality of memory pages in said memory segment, so as to generate target memory information, wherein the target memory information is used for determining a plurality of hot page sets and a plurality of cold page sets, the plurality of hot page sets are arranged in the order of access hotness, and the plurality of cold page sets are arranged in the order of access hotness; on the basis of the target memory information, selecting, from the virtual memory space, a memory page to be swapped; and performing memory swap on the memory page to be swapped. The present application solves the technical problems, in a memory management solution provided in the related art, of the memory management flexibility being low and the system memory swap performance being poor.
Need to check novelty before this filing date? Find Prior Art

Description

Memory management methods, electronic devices, storage media, and computer program products Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a memory management method, electronic device, storage medium, and computer program product. Background Technology

[0002] In operating systems, memory swapping typically relies on page replacement schemes or space swapping schemes based on the Least Recently Used (LRU) algorithm. To implement this LRU-based memory management mechanism, the operating system kernel maintains two linked lists: an active list and an inactive list. The active list contains frequently accessed memory pages. During system operation, when a memory page is accessed, it is moved to the head of the active list, indicating that it has been used recently. The inactive list contains memory pages that have not been frequently accessed over a period of time. Pages in the inactive list are the primary targets for memory swapping. When the system needs a new memory page, it will select a page from the inactive list (e.g., the page at the tail of the inactive list) for reclamation. Clearly, this LRU-based memory management mechanism suffers from several technical drawbacks, including low flexibility in application scenarios, poor memory swapping performance, and low operating system stability.

[0003] There is currently no effective solution to the above problems. Summary of the Invention

[0004] This application provides a memory management method, electronic device, storage medium, and computer program product to at least solve the technical problems of low memory management flexibility and poor system memory swapping performance of memory management solutions provided in related technologies.

[0005] According to one aspect of the embodiments of this application, a memory management method is provided, comprising: in response to a memory hot / cold scan instruction, determining a memory segment to be scanned from a virtual memory space; performing a hot / cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages being arranged in order of access frequency, and the multiple sets of cold pages being arranged in order of access frequency; selecting memory pages to be swapped from the virtual memory space based on the target memory information; and performing memory swapping on the memory pages to be swapped.

[0006] According to another aspect of the embodiments of this application, a memory management method is also provided, comprising: obtaining a memory management request through a first application programming interface, wherein the request data carried in the memory management request is used to determine: a memory segment to be scanned in a virtual memory space; and returning a memory management response through a second application programming interface, wherein the response data carried in the memory management response is used to determine a memory page to be swapped in the virtual memory space, the memory page to be swapped is selected from the virtual memory space through target memory information, the target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0007] According to another aspect of the embodiments of this application, a memory management method is also provided, comprising: acquiring a currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: a memory segment to be scanned in a virtual memory space; responding to the memory management dialog request, returning a memory management dialog response, wherein the information carried in the memory management dialog response includes: a memory swapping processing result, the memory swapping processing result being obtained by swapping memory pages to be swapped in the virtual memory space, the memory pages to be swapped being selected from the virtual memory space through target memory information, the target memory information being generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information including multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages being arranged in order of access popularity, and the multiple sets of cold pages being arranged in order of access popularity; and displaying the memory swapping processing result in a graphical user interface.

[0008] According to another aspect of the embodiments of this application, an electronic device is also provided, including: a memory storing an executable program; and a processor configured to run the program, wherein the program executes the memory management method of any one of the above-mentioned methods when it runs.

[0009] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored executable program, wherein, when the executable program is running, it controls the device where the computer-readable storage medium is located to execute any of the above-mentioned memory management methods.

[0010] According to another aspect of the embodiments of this application, a computer program product is also provided, including a computer program that, when executed by a processor, implements any of the above-described memory management methods.

[0011] In this embodiment, in response to a memory hot / cold scan instruction, a memory segment to be scanned is determined from the virtual memory space; multiple memory pages in the memory segment to be scanned are scanned for hot / cold status to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency; based on the target memory information, memory pages to be swapped are selected from the virtual memory space; and memory swapping is performed on the memory pages to be swapped.

[0012] It is noteworthy that, compared with related technologies that simply divide memory pages into active and inactive categories and perform memory swapping accordingly, the embodiments of this application not only perform memory swapping on the virtual memory space in the virtualization architecture, enabling the operating system to enable memory swapping online, but also further refine the hotness and coldness of memory pages by using multiple sets of hot pages and multiple sets of cold pages. Based on this, it is possible to select memory pages to be swapped more appropriately and accurately, thereby improving the flexibility of the operating system's memory management, enhancing system elasticity and stability.

[0013] In summary, the embodiments of this application achieve the purpose of scanning the cold and hot status of memory pages in the virtual memory space of the operating system and thereby realizing memory swapping, thus achieving the technical effects of improving the flexibility of system memory management, enhancing system elasticity and system stability, and solving the technical problems of low memory management flexibility and poor system memory swapping performance of memory management schemes provided in related technologies.

[0014] It is worth noting that the general description above and the detailed description that follow are merely for illustrative purposes and do not constitute a limitation on this application. Attached Figure Description

[0015] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0016] Figure 1 shows a hardware structure block diagram of a computer terminal (or mobile device) configured to implement a memory management method;

[0017] Figure 2 illustrates a schematic diagram of an embodiment using a computer terminal (or mobile device) as a transmitter or receiver;

[0018] Figure 3 is a flowchart of a memory management method according to Embodiment 1 of this application;

[0019] Figure 4 is a flowchart of a memory management method according to Embodiment 2 of this application;

[0020] Figure 5 is a flowchart of a memory management method according to Embodiment 3 of this application;

[0021] Figure 6 is a schematic diagram of a memory management device according to Embodiment 4 of this application;

[0022] Figure 7 is a schematic diagram of another memory management device according to Embodiment 4 of this application;

[0023] Figure 8 is a schematic diagram of another memory management device according to Embodiment 4 of this application;

[0024] Figure 9 is a structural block diagram of an electronic device according to Embodiment 5 of this application. Detailed Implementation

[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows.

[0028] Virtualization architecture: refers to the architecture obtained by virtualizing the operating system using virtualization technology. In a virtualization architecture, multiple virtual instances can run on a single physical server, and each virtual instance has independent computing resources (such as processor resources and memory resources).

[0029] Lightweight virtualization architecture refers to the process of performing lightweight virtualization on a running physical host machine to obtain a corresponding virtual machine. Lightweight virtualization involves converting the physical processor in the physical host machine into a virtual processor, thus eliminating the need for virtualization of unnecessary functions (such as device functions). Furthermore, lightweight virtualization strives to keep registers in pass-through mode (i.e., inputs and outputs are connected to a common path). In other words, the lightweight virtualization architecture in this application can be customized according to application scenario requirements, selecting specific functions in the host machine for virtualization.

[0030] Memory hot / cold status refers to the state of data in a memory unit (such as a memory segment, memory block, or memory page) being accessed frequently or infrequently. Specifically, when data in a memory unit is accessed frequently, that memory unit is considered hot, while when data in a memory unit is accessed infrequently, that memory unit is considered cold. In application scenarios, access frequency thresholds can be customized according to the needs of the scenario to determine whether the current data is being accessed frequently or infrequently.

[0031] Memory swapping is a memory management mechanism used by the operating system (which can be a virtualization architecture) to move data from temporarily inactive or infrequently used memory locations to the swap space on disk when the operating system's memory is insufficient. This frees up memory space for new data or processes to use. Memory swapping provides a solution for extending memory usage.

[0032] Example 1

[0033] According to an embodiment of this application, a memory management method embodiment is also provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Although a logical order is shown in the flowchart, in some cases, steps shown or described may be executed in a different order than that shown here.

[0034] The method embodiment provided in Embodiment 1 of this application can be executed in a mobile terminal, computer terminal, or similar computing device. Figure 1 shows a hardware structure block diagram of a computer terminal (or mobile device) configured to implement a memory management method. As shown in Figure 1, the computer terminal 10 (or mobile device) may include one or more processors 102 (shown as 102a, 102b, ..., 102n in the figure) (processor 102 may include, but is not limited to, a microprocessor (MCU) or a field programmable gate array (FPGA), etc.), a memory 104 configured to store data, and a transmission device 106 configured to have communication functions. In addition, the computer terminal 10 may also include: a display, an input / output interface (I / O interface), a Universal Serial Bus (USB) port (which may be included as one of the ports of a computer bus), a network interface, a cursor control device (such as a mouse, touchpad, etc.), a keyboard, a power supply, and / or a camera.

[0035] Those skilled in the art will understand that the structure shown in FIG1 is merely illustrative and does not limit the structure of the electronic device described above. For example, the computer terminal 10 may also include more or fewer components than shown in FIG1, or have a different configuration than that shown in FIG1.

[0036] It should be noted that the aforementioned one or more processors 102 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 10 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).

[0037] The memory 104 can be configured to store software programs and modules for application software, such as the program instructions / data storage device corresponding to the memory management method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the aforementioned memory management method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0038] The transmission device 106 is configured to connect to a network via a network interface to receive or send data. Specific examples of the network described above may include wired and / or wireless networks provided by the communication provider of the computer terminal 10. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, configured to communicate with the Internet wirelessly.

[0039] The display shown in Figure 1 can be, for example, a touchscreen liquid crystal display (LCD), which allows the user to interact with the user interface of the computer terminal 10 (or mobile device).

[0040] The hardware structure block diagram shown in Figure 1 can serve as an exemplary block diagram not only for the aforementioned computer terminal 10 (or mobile device) but also for the aforementioned server. In one optional embodiment, Figure 2 illustrates a schematic diagram of an embodiment using a computer terminal (or mobile device) as a sender or receiver. As shown in Figure 2, the computer terminal 10 (or mobile device) can be connected to one or more servers (e.g., security servers, resource servers, game servers, etc.) via a data network connection or electronically. In one optional embodiment, the aforementioned computer terminal 10 (or mobile device) can be any mobile computing device, etc. The data network connection can be a local area network (LAN) connection, a wide area network (WAN) connection, an Internet connection, or other types of data network connections. The computer terminal 10 (or mobile device) can perform network services to connect to a network service performed by a server (e.g., a security server) or a group of servers 20. The network server is a network-based user service, such as social networks, cloud resources, email, online payments, or other online applications.

[0041] In the above operating environment, this application provides a memory management method as shown in Figure 3. Figure 3 is a flowchart of a memory management method according to Embodiment 1 of this application. As shown in Figure 3, the memory management method includes:

[0042] Step S31: In response to the memory cold and hot scan instruction, determine the memory segment to be scanned from the virtual memory space;

[0043] Step S32: Perform a hot and cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information. The target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0044] Step S33: Based on the target memory information, select the memory page to be swapped from the virtual memory space;

[0045] Step S34: Perform memory swapping on the memory pages to be swapped.

[0046] The aforementioned virtual memory space can be the memory space of a virtualization architecture, and more particularly, it can be the memory space of a lightweight virtualization architecture. In application scenarios, the memory swapping function of the operating system is usually determined during installation. It is difficult to enable the memory swapping function online for an existing operating system (i.e., an operating system that already exists and is running) (which may lead to system instability or crashes). Therefore, the memory management method provided in this application can be applied to virtualization architectures. That is, the existing operating system is converted into a virtualization architecture in virtual mode, and then the memory swapping function is enabled online for this virtualization architecture according to the above method steps. After performing a memory cold / hot status scan on the virtual memory space of the virtualization architecture, memory page swapping is completed, enhancing the elasticity and system stability of the existing operating system.

[0047] The aforementioned memory hot / cold scan command is used to trigger a memory hot / cold status scan of the virtual memory space. This memory hot / cold scan command can be triggered by a periodically executed scan task, or it can be actively triggered by technicians or running programs.

[0048] The aforementioned memory hot / cold scan command can be used to specify a memory segment to be scanned in the virtual memory space. This memory segment includes multiple memory pages. The process of swapping memory in the virtual memory space can be viewed as: selecting memory pages to be swapped based on their hot / cold status. The memory segment to be scanned can be a portion or the entire virtual memory space. In application scenarios, multiple rounds of traversal scanning of multiple portions of the virtual memory space can be used to achieve a full scan of the virtual memory space.

[0049] The aforementioned target memory information can be used to characterize the memory information of each of multiple hot page sets and multiple cold page sets. This memory information may include data such as the address and space size of the memory pages contained in the set. The aforementioned access heat is used to characterize the hot and cold status of memory pages. The higher the access heat, the more frequently the memory data is accessed within a certain time range (which may include one or more scan cycles).

[0050] For example, each of the multiple hot page sets and multiple cold page sets mentioned above can be an array structure. Depending on the application scenario, some sets can be set as ordered array structures, and some sets as unordered array structures. Each element in the array structure is used to represent information such as the starting position and length of a memory segment (including one or more memory pages) in the virtual memory space.

[0051] It should be noted that, in this embodiment, after scanning the hot and cold states of multiple memory pages, the multiple memory pages are stored in corresponding sets. Multiple sets of hot pages correspond to memory hot zones, and multiple sets of cold pages correspond to memory cold zones. The memory hot zones store memory pages accessed during the current scan cycle, and the memory cold zones store memory pages not accessed during the current scan cycle.

[0052] Specifically, the access frequency of the aforementioned multiple hot page sets varies, and each hot page set can include at least two hot page sets. Therefore, when storing multiple memory pages into multiple hot page sets, it is possible to distinguish which memory pages are "hotter" and which are relatively "colder" among the hot pages. Similarly, the access frequency of the aforementioned multiple cold page sets varies, and each cold page set can include at least two cold page sets. Therefore, when storing multiple memory pages into multiple cold page sets, it is possible to distinguish which memory pages are "colder" (stored in the set with lower access frequency) and which are relatively "hotter" among the cold pages (stored in the cold page set with higher access frequency). Furthermore, within each cold page set or each hot page set, the order in which memory pages are added to the set can also be used to distinguish which memory pages are "hotter" or which are "colder."

[0053] Furthermore, depending on the application scenario requirements, the number of the aforementioned hot page set can also be set to 1, while the number of the aforementioned cold page set can be set to greater than 2; or the number of the aforementioned cold page set can also be set to 1, while the number of the aforementioned hot page set can be set to greater than 2; or the number of both the hot page set and the cold page set can be set to 1, that is, the memory pages in the system are divided into hot pages and cold pages.

[0054] In one application scenario, the target memory information above identifies multiple sets of hot pages, sorted in descending order of access popularity. When scanning these sets, the system iterates through them in descending order of access popularity (starting from the hottest), continuously transferring memory pages that have been accessed in consecutive scan cycles to the next set of hot pages with higher access popularity. Similarly, multiple sets of cold pages are also sorted in descending order of access popularity. When scanning these sets, the system iterates through them in ascending order of access popularity (starting from the coldest), continuously transferring memory pages that have not been accessed in consecutive scan cycles to the next set of cold pages with lower access popularity.

[0055] In another application scenario, the multiple cold page sets in the target memory information mentioned above can also be sorted in ascending order of access popularity. When scanning multiple cold page sets, the multiple cold page sets are still traversed in order of access popularity from low to high (that is, starting from the coldest), and memory pages that have not been accessed in multiple consecutive scanning cycles are continuously passed to cold page sets with lower access popularity.

[0056] It's important to note that, in terms of traversing and scanning multiple cold page sets, these sets can be arranged in ascending order of access frequency. In terms of storage, these cold page sets can be linked together using linked lists, with the linking order from the most accessed set to the least accessed set. Furthermore, multiple hot page sets can be linked to multiple cold page sets, with the linking order sequentially from the most accessed set among both sets to the least accessed set.

[0057] During the hot / cold state scan, the target memory information is updated in real time. Based on the operating system's memory space requirements, memory pages to be swapped can be selected at any time using the current target memory information. For example, based on the target memory information, the memory page with the lowest access frequency is selected from the virtual memory space as the memory page to be swapped, and the data in that memory page is swapped out to the swap space.

[0058] In this embodiment, in response to a memory hot / cold scan instruction, a memory segment to be scanned is determined from the virtual memory space; multiple memory pages in the memory segment to be scanned are scanned for hot / cold status to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency; based on the target memory information, memory pages to be swapped are selected from the virtual memory space; and memory swapping is performed on the memory pages to be swapped.

[0059] It is noteworthy that, compared with related technologies that simply divide memory pages into active and inactive categories and perform memory swapping accordingly, the embodiments of this application not only perform memory swapping on the virtual memory space in the virtualization architecture, enabling the operating system to enable memory swapping online, but also further refine the hotness and coldness of memory pages by using multiple sets of hot pages and multiple sets of cold pages. Based on this, it is possible to select memory pages to be swapped more appropriately and accurately, thereby improving the flexibility of the operating system's memory management, enhancing system elasticity and stability.

[0060] In summary, the embodiments of this application achieve the purpose of scanning the cold and hot status of memory pages in the virtual memory space of the operating system and thereby realizing memory swapping, thus achieving the technical effects of improving the flexibility of system memory management, enhancing system elasticity and system stability, and solving the technical problems of low memory management flexibility and poor system memory swapping performance of memory management schemes provided in related technologies.

[0061] In one optional embodiment, the memory management method further includes the following method steps:

[0062] Step S351: Establish a memory hot / cold detection task for the target processor. The memory hot / cold detection task is an asynchronous background task executed by the target processor according to a preset period and a preset duration. The memory hot / cold detection task is used to detect the hot / cold status of memory pages in the virtual memory space.

[0063] Step S352: During the execution of the memory hot / cold detection task by the target processor, the update task mounted in the asynchronous task cache of the target processor is processed. The update task includes at least a scan task. The scan task is used to scan the hot / cold status of multiple memory pages in the memory segment to be scanned and generate target memory information.

[0064] In the above optional embodiments, the virtual memory space can be the memory space of a lightweight virtualization architecture, and the target processor can be any virtual processor in the lightweight virtualization architecture (derived from a physical processor in the physical host machine).

[0065] As an example implementation, a memory hot / cold detection task is established for the target processor. This task can handle the asynchronous task cache for hot / cold updates on the target processor. This memory hot / cold detection task is an asynchronous background task. Furthermore, this task will be automatically executed periodically according to a preset period and a preset duration (e.g., it will be executed in a loop according to a preset period until the preset duration is reached). The preset period can be determined by technicians based on application scenario requirements, and the preset duration is determined by a time slice input by the technicians. During execution, the memory hot / cold detection task will process the update tasks attached to the asynchronous task cache for hot / cold updates on the target processor.

[0066] Specifically, the aforementioned memory hot / cold detection task can at least handle the scanning task of the virtual memory space corresponding to the target processor. It performs a hot / cold status scan on multiple memory pages in the memory segment to be scanned in the virtual memory space, generating target memory information. It should be noted that the target memory information is constructed during the initial processing of the scan task corresponding to the target processor, and updated during subsequent processing of the same scan task.

[0067] Based on the above method steps, in the application scenario, a corresponding memory hot / cold detection task is created for each CPU in the virtual architecture. Furthermore, the scan results (i.e., the target memory information mentioned above) after the memory hot / cold status scan is completed for the CPU through the memory hot / cold detection task can be stored in the CPU's cache. This avoids the lock contention and waiting caused by multiple CPUs in the virtual architecture performing hot / cold status scans to update the hot page set and cold page set at the same time, improves the scanning efficiency of hot / cold status scans in the virtual architecture, and enhances system stability.

[0068] Specifically, the cold page set and hot page set can be locked during each read and update to ensure data correctness. However, according to relevant technologies, each CPU needs to read and write to the cold page set and hot page set when retrieving scan tasks or updating scan results, requiring frequent lock acquisition operations. Therefore, multiple CPUs in the virtual architecture may simultaneously acquire locks (i.e., "lock contention"), which can lead to system congestion. This means multiple CPUs need to spend a significant amount of time waiting for each other, resulting in low efficiency and poor stability during cold / hot state scanning. In this embodiment, during cold / hot state scanning, the reading of the cold page set and hot page set (one lock acquisition) is performed in batches over multiple scan cycles. Then, the cold / hot state scanning operation is performed based on the CPU's own cache until the cold page set and hot page set need to be updated based on the scan results, at which point the lock is acquired again (if the lock has not been successfully acquired at this point, the scan results can be temporarily stored in the CPU's own cache, avoiding "lock contention"). In other words, the solution provided in this application can greatly reduce the lock acquisition frequency of multiple CPUs in the virtual architecture, thereby avoiding lock contention and waiting, improving the scanning efficiency of cold and hot state scanning in the virtual architecture, and enhancing system stability.

[0069] It should be noted that, to further ensure data integrity, each CPU adopts a lock-free data mode, meaning that each CPU's hot / cold status scanning task does not need to acquire a lock when reading data from its own cache; and multiple CPUs cannot access each other's data, meaning that each CPU cannot access the cache data of other CPUs. Furthermore, a globally asynchronous cache linked list with locks can be set up to achieve cache data synchronization between multiple CPUs. Through steps S351 to S352 of this embodiment, in a lightweight virtualization architecture, periodic hot / cold status detection of the virtual memory space corresponding to each virtual processor can be achieved. During the hot / cold status detection process, users can flexibly specify the execution method of the above-mentioned hot / cold status detection task. Therefore, this embodiment provides a memory hot / cold status detection scheme for a lightweight virtualization architecture, further helping each virtual processor in the lightweight virtualization architecture to realize memory swapping functionality. The scheme is highly flexible and significantly improves the elasticity and stability of the operating system.

[0070] In an optional embodiment, the memory management method further includes update tasks categorized as add tasks, delete tasks, control tasks, and exception tasks. The add task is used to add a specified memory page to a specified set and update the target memory information. The specified set can be any one of multiple hot page sets and multiple cold page sets. The delete task is used to delete a specified memory page from the specified set and update the target memory information. The control task is used to change the attributes of the specified set and update the target memory information. The exception task is used to handle and repair faults occurring in the multiple hot page sets and multiple cold page sets and update the target memory information.

[0071] It should be noted that the scan, add, delete, control, and exception tasks in the above update tasks can have different processing priorities, which can be determined according to a pre-set processing strategy. Correspondingly, in application scenarios, each CPU's cache can be configured with different types of caches, such as control operation cache, update cache, and scan cache, and different processing priorities can be set between these different types of caches.

[0072] In the optional embodiments described above, the specified memory page can be a memory segment in the virtual memory space with a known hot or cold state. The specified memory page is added to a specified set, determined by the new task, by attaching a new task to the asynchronous task cache of the target processor. Similarly, the specified memory page is removed from the specified set by attaching a delete task to the asynchronous task cache of the target processor.

[0073] Specifically, by attaching a control task to the asynchronous task cache of the target processor, specific control is applied to the update task attached to the asynchronous task cache on the overall controller. This overall controller is a virtual controller on the control plane corresponding to multiple hot page sets and multiple cold page sets as a whole. Specific control of the update task can be applied to change the attributes of a specified set. For example, a target control task can be configured to change the number of hot page sets and cold page sets, and this target control task can be attached to the asynchronous task cache of the target processor. When the memory hot / cold detection task starts processing the target control task, the memory hot / cold detection tasks corresponding to multiple virtual processors in the virtualization architecture are first suspended, and then the above target control task is executed to change the number of hot page sets and cold page sets, and further, the memory hot / cold detection tasks corresponding to multiple virtual processors in the virtualization architecture are resumed.

[0074] Furthermore, when an anomaly (such as data loss or data error) occurs in at least one of the multiple hot page sets and multiple cold page sets, a target anomaly task is configured and attached to the asynchronous task cache of the target processor. For example, when a data error anomaly occurs, a target anomaly task is configured to reset the multiple hot page sets and multiple cold page sets. When the memory hot / cold detection task begins processing the target anomaly task, the memory hot / cold detection tasks corresponding to the multiple virtual processors in the virtualization architecture are first suspended. Then, the aforementioned target anomaly task is executed to clean up and reset the data corresponding to all multiple hot page sets and multiple cold page sets, and an updated scanning task is reissued to the memory hot / cold detection tasks corresponding to the multiple virtual processors. This further controls the memory hot / cold detection tasks corresponding to the multiple virtual processors in the virtualization architecture to resume operation.

[0075] It should be noted that the target processor's memory hot / cold detection task prioritizes processing update tasks (excluding scanning tasks) mounted in the asynchronous task cache before processing scanning tasks. When starting a scanning task, it first checks if an existing scanning task exists. This existing task corresponds to the unfinished portion of memory segments from the previous scanning cycle. If an existing scanning task exists, it is processed first, or the remaining time slice is estimated based on the existing task, and a new scanning task is retrieved according to the remaining time slice. If no existing scanning task exists, the memory segment to be scanned is retrieved from the virtual memory space and scanned again according to the scan time slice.

[0076] Through the above optional embodiments of this application, the memory hot / cold detection task can handle various types of update tasks corresponding to the target processor, so as to realize the flexibility and operability in the virtual memory space hot / cold scanning process, and make the memory management scheme provided by the embodiments of this application more widely applicable to more application scenarios and meet the needs of application scenarios.

[0077] In one optional embodiment, the memory segment to be scanned in the memory management method includes one of the following: a memory segment allocated for initialization of the target processor, or a memory segment corresponding to at least a portion of the memory pages in a plurality of hot page sets and a plurality of cold page sets obtained by executing a scanning task during a historical scanning cycle.

[0078] In the above optional embodiments, the memory segment to be scanned corresponding to the scanning task in the virtual memory space can be initialized and allocated by technicians for the target processor according to the application scenario requirements, or it can be specified by a pre-set program or process from multiple hot page sets and multiple cold page sets obtained in the historical scanning cycle.

[0079] For example, depending on the application scenario, the hot page region (i.e., all sets of hot pages) can be set as the memory segment to be scanned, the cold page region (i.e., all sets of cold pages) can be set as the memory segment to be scanned, or all sets of hot pages and sets of cold pages can be set as the memory segment to be scanned. In particular, the set of hot pages with the highest access frequency among the sets of hot pages and the set of cold pages with the lowest access frequency among the sets of cold pages can also be set as the memory segment to be scanned.

[0080] Through the above optional embodiments of this application, the memory hot / cold detection task can be flexibly configured to scan the virtual memory space for hot / cold status. Depending on the application scenario requirements, the memory segments to be scanned can be set with emphasis, thereby enhancing the memory elasticity performance of the virtualization architecture.

[0081] In an optional embodiment, in step S32, a cold / hot status scan is performed on multiple memory pages in the memory segment to be scanned to generate target memory information, including the following method steps:

[0082] Step S3211: Traverse multiple memory pages. For the target memory page being traversed, query the access flag bit of the target memory page from the memory page table.

[0083] Step S3212: Based on the access flag, store the target memory page into the target set in the target memory information to generate the target memory information.

[0084] In one application scenario, during operating system operation, the system kernel sets a corresponding access flag (called the access bit) for each memory page in the memory page table. When the target processor accesses a memory page, the access flag for that memory page in the page table will be set (for example, the access flag will be set to 1). Based on this, in each scan cycle, the memory page table can be traversed to identify memory pages with the access flag set as hot pages and memory pages with the access flag not set as cold pages.

[0085] In the optional embodiments described above, the memory page table corresponding to the multiple memory pages records the access bit corresponding to each memory page. Memory pages with an access bit of 1 are determined to be stored in multiple hot page sets, and memory pages with an access bit of 0 are determined to be stored in multiple cold page sets. It should be noted that, within each scan cycle, for a scanned memory page, the access bit of that memory page is set to 0 so that the hot / cold page determination can be performed in the next scan cycle.

[0086] Through steps S3211 to S3212 of this embodiment, based on the access flag of the memory page, the hot / cold status (i.e., whether it has been accessed) of each memory page in the current scan cycle is determined, and further, it is determined which set the memory page will be stored in. Thus, after scanning the memory segment to be scanned in the current scan cycle, multiple memory pages will be distributed in multiple hot page sets and multiple cold page sets. That is, the hot / cold status of multiple memory pages is determined, facilitating the subsequent selection and swapping of memory pages according to their hot / cold status.

[0087] In an exemplary application scenario of the memory management scheme provided in this application embodiment, the set of hot pages with the highest access frequency among multiple hot page sets is denoted as the "hot set," and the set of hot pages with the lowest access frequency among multiple hot page sets is denoted as the "active set" (i.e., the "coldest hot page set"). There may also be at least one transitional hot page set between the hot set and the active set; in this example, a transitional hot page set is set as the "warm set." Similarly, the set of cold pages with the lowest access frequency among multiple cold page sets is denoted as the "cold set," and the set of cold pages with the highest access frequency among multiple cold page sets is denoted as the "inactive set" (i.e., the "hottest cold page set"). There may also be at least one transitional cold page set between the cold set and the inactive set; in this example, a transitional cold page set is set as the "cool set."

[0088] Furthermore, in the aforementioned exemplary application scenario, multiple hot page sets and multiple cold page sets are connected sequentially using linked lists. Specifically, according to the linked list connection order, from front to back, they are: hot set, warm set, active set, inactive set, cool set, and cold set. Based on this, when a memory page moves towards the hot set, it is called moving upwards; when a memory page moves towards the cold set, it is called moving downwards.

[0089] It should be noted that although the multiple hot page sets and multiple cold page sets are arranged in descending order of access popularity according to the linked list connection order, when considering multiple hot page sets in the target memory information, they are considered in descending order of access popularity. That is, when traversing and scanning multiple hot page sets, the order is hot set, warm set, active set. When considering multiple cold page sets in the target memory information, they are considered in ascending order of access popularity. That is, when traversing and scanning multiple cold page sets, the order is cold set, cool set, inactive set.

[0090] The following description further illustrates the hot and cold state scanning scheme of this application embodiment based on the above exemplary application scenarios.

[0091] In an optional embodiment, the memory segment to be scanned includes a set of multiple hot pages determined by scanning tasks executed during historical scanning cycles; in step S32, a cold / hot status scan is performed on the multiple memory pages in the memory segment to be scanned to generate target memory information, including the following method steps:

[0092] Step S3221: Traverse and scan multiple sets of hot pages in descending order of access popularity;

[0093] Step S3222: For the target memory page in the current hot page set being traversed and scanned, query the access flag bit of the target memory page from the memory page table;

[0094] Step S3223: Determine the target set to be stored from the target memory information based on the access flag bit;

[0095] Step S3224: Store the target memory page into the target set to obtain the updated target memory information.

[0096] Based on the above exemplary application scenario, and according to the above method steps, when scanning the hot and cold status of multiple memory pages corresponding to multiple hot page sets, the scan is performed sequentially in the order of hot set, warm set, and active set. Further, multiple memory pages in each hot page set are scanned. For a target memory page during the scan, the access flag of the target memory page is obtained. Based on the access flag, the target set to which the target memory page should be stored is determined. The target memory page is then stored in the target set, and the target memory information is updated in real time.

[0097] Through steps S3221 to S3224 of the embodiments of this application, when performing a hot / cold state scan of the virtual memory space corresponding to the target processor in the current scan cycle, the set position of each memory page is updated according to the access flag value of each memory page in the current scan cycle. This achieves real-time updating of the target memory information and enables the target memory information to characterize which memory pages are "hotter" and which memory pages are "relatively cold" hot pages, refining the division of the hot / cold degree of memory pages so that the virtualization architecture can select the memory pages to be swapped appropriately and accurately according to the target memory information at any time.

[0098] In an optional embodiment, in step S3223, the target set to be stored is determined from the target memory information according to the access flag bit, including the following method steps:

[0099] Step S3224: In response to the access flag bit being set to the first value, the target set is determined to be the first cold page set with the highest access frequency among multiple cold page sets, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle;

[0100] Step S3225: When the current hot page set is the first hot page set, in response to the access flag bit taking the value of the second value, the target set is determined to be the current hot page set. The first hot page set is the hot page set with the highest access frequency among multiple hot page sets, and the second value is used to characterize that the target memory page is accessed in the current scan cycle.

[0101] Step S3226: When the current hot page set is any hot page set other than the first hot page set among multiple hot page sets, in response to the access flag bit being set to the second value, the target set is determined to be the hot page set among multiple hot page sets whose access popularity is higher than the current hot page set and which is adjacent to the current hot page set.

[0102] In the above optional embodiments, the first value is set to 0, and the first value is set to 1.

[0103] Based on the above exemplary application scenario, and according to the above method steps, for the target memory page currently being traversed in the hot and cold state scan, if the access bit of the target memory page is 0, then the target set is determined to be the inactive set (i.e., the "hottest cold page set"); when the access bit of the target memory page is 1, if the target memory page is currently located in the hot set, then the target set is determined to still be the hot set (i.e., the position of the target memory page remains unchanged); if the target memory page is currently located in another hot page set outside the hot set (i.e., the warm set or the active set), then the target set is determined to be the previous hot page set of the hot page set where the target memory page is currently located. That is, the target memory page in the warm set is moved to the hot set, and the target memory page in the active set is moved to the warm set.

[0104] It should be noted that the hot set mentioned above can be an ordered array structure, while the warm set and active set mentioned above can be unordered array structures. Based on this, when moving a target memory page from the warm set to the hot set, the target memory page is merged into the array corresponding to the hot set; when moving a target memory page from the active set to the warm set, the target memory page is moved to the end of the array corresponding to the warm set.

[0105] It is easy to notice that when a memory page is found to be unaccessed in the current scan cycle within any set of hot pages, that memory page instantly becomes "cold" and is moved to the "hottest cold page set" inactive set.

[0106] Through steps S3224 to S3226 of the embodiments of this application, the access popularity of memory pages can be determined by using multiple hot page sets corresponding to multiple levels of access popularity. For example, the memory pages stored in the hot set are those that have been accessed in at least three consecutive scan cycles before the current scan cycle (which can be considered the hottest pages); the memory pages stored in the warm set are those that have been accessed in two consecutive scan cycles before the current scan cycle; and the memory pages stored in the active set are those that have been accessed in one scan cycle before the current scan cycle. Furthermore, if more transitional hot page sets (i.e., multiple warm sets with different access popularity) are set in the multiple hot page sets, the hot and cold status of memory pages can be distinguished more precisely.

[0107] Furthermore, since the hot set uses an ordered array structure, this ordered array can reflect the order of memory page address numbers. By using the order of the memory page address numbers corresponding to each element in the ordered array, it is easy to combine adjacent memory pages into the same hot page memory segment, thereby saving storage space.

[0108] In an optional embodiment, the memory segment to be scanned includes a set of multiple cold pages determined by scanning tasks executed during historical scanning cycles; in step S32, a cold / hot status scan is performed on the multiple memory pages in the memory segment to be scanned to generate target memory information, including the following method steps:

[0109] Step S3231: Traverse and scan multiple cold page sets in ascending order of access popularity;

[0110] Step S3232: For the target memory page in the current cold page set being traversed and scanned, query the access flag bit of the target memory page from the memory page table;

[0111] Step S3233: Determine the target set to be stored from the target memory information based on the access flag bit;

[0112] Step S3234: Store the target memory page into the target set to obtain the updated target memory information.

[0113] Based on the above exemplary application scenario, and according to the above method steps, when scanning the cold and hot status of multiple memory pages corresponding to multiple cold page sets, the scan is performed sequentially in the order of cold set, cool set, and inactive set. Further, the multiple memory pages in each cold page set are scanned. For a target memory page during the scan, the access flag of the target memory page is obtained. Based on the access flag, the target set to which the target memory page should be stored is determined. The target memory page is then stored in the target set, and the target memory information is updated in real time.

[0114] Through steps S3231 to S3234 of the embodiments of this application, when scanning the cold and hot status of the virtual memory space corresponding to the target processor in the current scan cycle, the set position of the memory page is updated according to the access flag value of each memory page in the current scan cycle. This realizes the real-time update of the target memory information and enables the target memory information to characterize which memory pages are "colder" and which memory pages are "relatively hot", refining the division of the cold and hot degree of memory pages so that the virtualization architecture can select the memory pages to be swapped appropriately and accurately according to the target memory information at any time.

[0115] In an optional embodiment, in step S3233, the target set to be stored is determined from the target memory information according to the access flag bit, including the following method steps:

[0116] Step S3235: In response to the access flag bit being set to the second value, the target set is determined to be the second hot page set with the lowest access frequency among multiple hot page sets, wherein the second value is used to characterize that the target memory page is accessed in the current scan cycle;

[0117] Step S3236: When the current cold page set is the second cold page set, in response to the access flag bit taking the value of the first value, the target set is determined to be the current cold page set, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle;

[0118] Step S3237: When the current cold page set is any of the cold page sets other than the second cold page set, in response to the access flag bit being set to the first value, the target set is determined to be the cold page set among the multiple cold page sets whose access popularity is lower than the current cold page set and which is adjacent to the current cold page set.

[0119] In the above optional embodiments, the first value is set to 0, and the second cold page set is set to 1. The second cold page set is the cold page set with the lowest access popularity among multiple cold page sets.

[0120] Based on the above exemplary application scenario, and according to the above method steps, for the target memory page currently being traversed in the hot and cold state scan, if the access bit of the target memory page is 1, then the target set is determined to be the active set (i.e., the "coldest hot page set"); when the access bit of the target memory page is 0, if the target memory page is currently located in the cold set (i.e., the second cold page set mentioned above), then the target set is determined to still be the cold set (i.e., the position of the target memory page remains unchanged); if the target memory page is currently located in another cold page set outside the cold set (i.e., the cool set or the inactive set), then the target set is determined to be the next cold page set of the cold page set where the target memory page is currently located, that is, the target memory page in the cool set is moved to the cold set, and the target memory page in the inactive set is moved to the cool set.

[0121] It should be noted that the cold set mentioned above can be an ordered array structure, while the cool set and the inactive set mentioned above can be unordered array structures. Based on this, when moving a target memory page from the cool set to the cold set, the target memory page is merged into the array corresponding to the cold set; when moving a target memory page from the inactive set to the cool set, the target memory page is moved to the end of the array corresponding to the cool set.

[0122] It is easy to notice that when a memory page is accessed in the current scan cycle within any cold page set, that memory page instantly "becomes hot" and is moved to the "coldest hot page set," the active set.

[0123] It should be noted that the active and inactive sets can be set as ordered array structures. When a memory page is moved from the cold page set to the active set, it is also moved to the end of the array corresponding to the active set. Similarly, when a memory page is moved from the hot page set to the inactive set, it is also moved to the end of the array corresponding to the inactive set.

[0124] Through steps S3235 to S3237 of this embodiment, the access heat of memory pages can be determined by using multiple cold page sets corresponding to multiple access heat levels. For example, the memory pages stored in the cold set are those that have not been accessed in at least three consecutive scan cycles before the current scan cycle (which can be considered the coldest pages); the memory pages stored in the cool set are those that have not been accessed in two consecutive scan cycles before the current scan cycle; and the memory pages stored in the inactive set are those that have not been accessed in one scan cycle before the current scan cycle. Furthermore, if more transitional cold page sets (i.e., multiple cool sets with different access heat) are set in the multiple cold page sets, the hot and cold status of memory pages can be distinguished more precisely.

[0125] Furthermore, since the cold set uses an ordered array structure, this ordered array can reflect the order of memory page address numbers. By using the order of the memory page address numbers corresponding to each element in the ordered array, it is easy to combine adjacent memory pages into the same cold page memory segment, thereby saving storage space.

[0126] In an optional embodiment, in the memory management method, after storing the target memory page into the target set, the access flag is set to a first value.

[0127] In the above optional embodiments, during the cold / hot state scanning process, after the target memory page is moved, the access bit of the target memory page in the memory page table is set to 0. Based on this, if the access bit of the target memory page is set to 1 in the next scan cycle, it can accurately indicate that the target memory page was accessed in the next scan cycle.

[0128] Through the optional embodiments of this application, based on the access flag setting mechanism, it can be determined that when performing a hot / cold state scan on multiple hot page sets, the scan proceeds from the hot page set with the highest access frequency to the hot page set with the lowest access frequency. Similarly, when performing a hot / cold state scan on multiple cold page sets, the scan proceeds from the cold page set with the lowest access frequency to the cold page set with the highest access frequency. This ensures that the data recorded in the target memory information generated after the cold / cold state scan accurately reflects the hot / cold state of the memory pages.

[0129] In an optional embodiment, step S31, determining the memory segment to be scanned from the virtual memory space, includes the following method steps:

[0130] Step S311: Based on the memory cold and hot scan instructions, determine the memory region to be scanned and the scan time slice in the virtual memory space;

[0131] Step S312: Calculate the scan length based on the scan time slice and preset scan rules;

[0132] Step S313: Select a memory segment to be scanned from the memory region to be scanned using the scan length.

[0133] In the above optional embodiments, the preset scanning rules can be determined by technicians according to the application scenario requirements. The preset scanning rules are used to determine the scan length. The preset scanning rules can be related to the computing resources of the virtualization architecture and are determined by the computing power level of the target processor.

[0134] Based on the aforementioned exemplary application scenario and according to the above method steps, during the hot and cold state scanning process, the scanning task can record the current scanning position, that is, record the current set of hot pages or cold pages in real time. When determining the memory to be scanned, the scan length can be calculated based on the scan time slice, and a segment of memory corresponding to that scan length can be extracted from the current set of hot pages or cold pages as the memory to be scanned.

[0135] It should be noted that if the currently scanned hot or cold page set does not contain a memory segment of the aforementioned scan length, it is considered that the currently scanned hot or cold page set has been emptied, and the next set's hot / cold status scan is performed according to the traversal scan order. In application scenarios, the hot / cold status scan starts from the hot set, and when the currently scanned set becomes the hot set again, it is considered that a full round of hot / cold status scan of the virtual memory space has been completed.

[0136] Furthermore, for the retrieved memory segment to be scanned with a length equal to the scan length, the scan result corresponding to the memory segment is mounted to the cold and hot update asynchronous task cache on the target processor in an asynchronous task manner. For example, if a memory page is found to be a hot page and needs to be moved to the previous hot page set, the starting position and length of the memory segment corresponding to the memory page are recorded in the new task mounted in the asynchronous task cache of the target processor, and the new task adds the memory page to the previous hot page set.

[0137] Through steps S311 to S313 of the embodiments of this application, the memory hot and cold scanning instructions, preset scanning rules, pre-established memory hot and cold detection tasks, and various types of update tasks to be mounted can automatically realize the hot and cold status scanning of the virtual memory space corresponding to multiple virtual processors in the virtualization architecture, thereby improving the memory management efficiency and system memory elasticity performance of the virtualization architecture.

[0138] In one optional embodiment, the memory management method further includes the following method steps:

[0139] Step S36: In response to the incomplete cold and hot state scanning of the memory segment to be scanned within the scanning time slice, determine the unscanned memory segment from the memory segment to be scanned, and schedule the unscanned memory segment to the asynchronous cache of the scanning task corresponding to the target processor.

[0140] Based on the above exemplary application scenario, and following the above method steps, the specific implementation of the scanning process for the memory segment to be scanned is described. The sequence number of the memory segment to be scanned is denoted as idx. The scan granularity corresponding to cold and hot state scanning can be 1GB, 2MB, or 4kB. Based on the scan granularity, the memory space addresses of multiple memory pages within the memory segment to be scanned are determined. The memory space address includes physical space address and virtual space address. The mapping relationship between physical space address and virtual space address is recorded in the Extended Page Tables (EPT). The EPT also records the access flag bit (i.e., access bit) corresponding to each memory page. Based on this, in cold and hot state scanning, for the currently traversed target memory page, the EPT page table is used to check whether the access bit of the target memory page is set to 1. Based on the setting of the access bit, the virtual space address of the target memory page is moved to the target set.

[0141] It should be noted that during the current scan cycle, the hot / cold status changes of memory pages can also be recorded using a scan bitmap. If a memory page changes from a hot page to a cold page or vice versa, the corresponding bit in the scan bitmap is set to 1. If the state of a memory page remains unchanged during the current scan cycle, the corresponding bit in the scan bitmap remains 0. Based on this, when moving memory pages between multiple sets of cold pages and multiple sets of hot pages, the data recorded in the scan bitmap can be used to configure update tasks to achieve the movement.

[0142] Furthermore, during the cold / hot scanning of the memory segment to be scanned, after the movement of a memory page is completed, it is determined whether the scan duration of the current scan cycle exceeds the scan time slice. If the scan duration exceeds the scan time slice, the unscanned portion of the memory segment to be scanned is actively scheduled to the asynchronous task cache, and cold / hot scanning of that portion of the memory segment can continue at the start of the next scan cycle. If the scan duration does not exceed the scan time slice and the memory segment to be scanned is not completely scanned, the scanning of the next memory page in the memory segment to be scanned continues. If the memory segment to be scanned has been scanned but the scan duration does not exceed the scan time slice, a new memory segment to be scanned is retrieved from the virtual memory space according to the remaining time slice of the current scan cycle.

[0143] It should be noted that the memory segments to be scanned may include memory pages allocated by the virtualization layer of the virtualization architecture and not marked as reserved. Among them, the space memory pages and the preset reserved memory pages in the virtual memory space will be marked as reserved. These memory pages will not participate in the cold and hot state scan.

[0144] Through the above-described step S36 of this application embodiment, during the scanning process in both hot and cold states, the part of the memory segment to be scanned that has not been scanned within the scanning time slice is also considered, and the part of the memory segment is actively scheduled to avoid the situation of missing the scanning of the virtual memory space and reduce the risk of system failure.

[0145] In one optional embodiment, the memory management method further includes the following method steps:

[0146] Step S371: Count the number of accesses to multiple memory pages in the first hot page set and obtain the statistical results;

[0147] Based on the statistical results, multiple memory pages are segmented and aggregated to obtain multiple aggregated memory segments;

[0148] Step S372: Using a preset memory length threshold, perform a memory hot / cold status scan on multiple aggregated memory segments and update the first hot page set.

[0149] Based on the aforementioned exemplary application scenarios, since memory hot / cold state scanning incurs significant system overhead, scanning multiple hot page sets can be made optional. For example, scanning multiple hot page sets can be triggered when the number of memory pages in the cold set (i.e., the "coldest cold page set") is small, the total number of all multiple cold page sets is small, or multiple hot page sets have not been scanned for a long period. Furthermore, according to the principle of locality of reference in memory access, memory pages that have accumulated into the hot set over multiple scan cycles may remain hot pages for a considerable period afterward. Multiple memory pages in the hot page set can be aggregated, and the aggregated results can be selectively scanned for hot / cold states to save scanning time.

[0150] Taking the hot page set as an example, the process of selective hot and cold page scanning is explained. For a memory page newly moved to the hot page set, the memory page is stored in the corresponding position in the access record table according to its physical space address, and the access count of the memory page is recorded in the access record table. It should be noted that if there are n hot page sets, the access count of the memory page newly entering the hot page set is set to n in the access record table. If these memory pages in the hot page set are still in the hot page state in subsequent scan cycles, the access count is accumulated on the basis of n to obtain the updated access count, and the average access count is calculated based on these updated access counts.

[0151] Furthermore, during the hot / cold status scan of the hot set, multiple memory pages within the hot set are aggregated and split to obtain multiple memory page sets. The average number of accesses for multiple memory pages in each memory page set is calculated to obtain the average access count for each memory page set. Based on the average access count, the multiple memory page sets are merged. For example, if the difference in the average access counts of two memory page sets is less than a first preset threshold, then these two memory page sets are considered to be merged, and the average access count of the merged memory page set is recalculated.

[0152] Furthermore, based on the length of the memory page set (i.e., how many memory pages it contains), the merged memory page set is further split and merged. Specifically, if the length of a memory page set is greater than a second preset threshold (e.g., 10 memory pages), the memory page set is split so that the length of the split set is less than or equal to the second preset threshold.

[0153] Furthermore, the memory page set after the secondary split and merge is traversed and scanned. For the current memory page set being scanned, a memory page is randomly selected from the current memory page set for scanning. If it is determined that the memory page is still a hot page (i.e., the access bit is set to 1 during the current scan cycle), then multiple memory pages in the current memory set are considered hot pages, and the average access count of the current memory set is updated. If the randomly selected memory page is a cold page, then the randomly selected memory page is moved to the end of the array corresponding to the inactive set, and the current memory page set is split into two memory page subsets using the randomly selected memory page. The two resulting memory page subsets are then updated in the hot set.

[0154] Furthermore, a memory page is randomly selected from either of the two resulting memory page subsets for a cold / hot status scan, and the above steps for processing the randomly selected memory page are repeated. This continues until the current memory page set is split to the point where there are no memory pages or all memory pages in the current memory page set are removed, at which point the current memory page set is deleted from the hot set.

[0155] By performing steps S371 to S372 in the embodiments of this application, the hot page set with the highest popularity among multiple hot page sets (i.e., the hot set) can be optionally scanned for hot and cold states (without necessarily traversing and scanning all memory pages in the hot set). This can reduce the overhead of hot and cold state scanning, lower system memory management costs, and improve system memory swapping efficiency when the computing resources of the virtualization architecture are limited.

[0156] In summary, through the method steps provided in the embodiments of this application, this application can provide an asynchronous multi-level aging scheme for scanning the hot and cold states of memory in the virtual memory space of a virtualization architecture. This scheme can more finely classify the hot and cold states of memory pages, thereby enabling the system to select more suitable and accurate memory pages to be swapped. As a result, the embodiments of this application can improve the flexibility of memory swapping control, enhance the system's elasticity and stability.

[0157] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0158] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0159] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as read-only memory (ROM), random access memory (RAM), magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0160] Example 2

[0161] In the operating environment as described in Embodiment 1, this application provides another memory management method as shown in Figure 4. Figure 4 is a flowchart of a memory management method according to Embodiment 2 of this application. As shown in Figure 4, the memory management method includes:

[0162] Step S41: Obtain a memory management request through the first application programming interface, wherein the request data carried in the memory management request is used to determine: the memory segment to be scanned in the virtual memory space;

[0163] Step S42: A memory management response is returned through the second application programming interface. The response data carried in the memory management response is used to determine the memory pages to be swapped in the virtual memory space. The memory pages to be swapped are selected from the virtual memory space through target memory information. The target memory information is generated by scanning the hot and cold states of multiple memory pages in the memory segment to be scanned. The target memory information includes multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0164] Based on the above steps, a method for implementing a memory management cloud service is provided, which runs on a cloud server. The cloud server obtains a memory management request from a service caller through a first application programming interface (API). Based on the request data carried in the memory management request, it determines the memory segment to be scanned in the virtual memory space, and then executes the memory management process to obtain the memory pages to be swapped in the virtual memory space. Further, the cloud server returns a memory management response to the service caller through a second API to provide the memory pages to be swapped in the virtual memory space to the service caller, enabling the service caller to implement the memory swapping function in the virtual memory space.

[0165] The first and second application programming interfaces (APIs) mentioned above can be the same or different APIs. In an optional embodiment, the interface parameters in the first and second APIs may include, but are not limited to: the interface global identifier (interface signature key), the interface timestamp, the interface request identifier, and the system call credential identifier. The first API can use either a GET or POST method to request a file processing request. The second API can use JavaScript Object Notation (JSON) format to return the file processing response.

[0166] The aforementioned virtual memory space can be the memory space of a virtualization architecture, and more particularly, the memory space of a lightweight virtualization architecture. In application scenarios, the memory swapping function of an operating system is usually determined during installation, and it is difficult to enable the memory swapping function online for an existing operating system (which may lead to system instability or crashes). Therefore, the memory management method provided in this application can be applied to virtualization architectures. That is, the existing operating system is converted into a virtualization architecture in virtual mode, and then the memory swapping function is enabled online for this virtualization architecture according to the above method steps. After performing a memory cold / hot status scan on the virtual memory space of the virtualization architecture, memory page swapping is completed, enhancing the elasticity and stability of the existing operating system.

[0167] The aforementioned memory hot / cold scan command is used to trigger a memory hot / cold status scan of the virtual memory space. This memory hot / cold scan command can be triggered by a periodically executed scan task, or it can be actively triggered by technicians or running programs.

[0168] The aforementioned memory hot / cold scan command can be used to specify a memory segment to be scanned in the virtual memory space. This memory segment includes multiple memory pages. The process of swapping memory in the virtual memory space can be viewed as: selecting memory pages to be swapped based on their hot / cold status. The memory segment to be scanned can be a portion or the entire virtual memory space. In application scenarios, multiple rounds of traversal scanning of multiple portions of the virtual memory space can be used to achieve a full scan of the virtual memory space.

[0169] The aforementioned target memory information can be used to characterize the memory information of each of multiple hot page sets and multiple cold page sets. This memory information may include data such as the address and space size of the memory pages contained in the set. The aforementioned access heat is used to characterize the hot and cold status of memory pages. The higher the access heat, the more frequently the memory data is accessed within a certain time range (which may include one or more scan cycles).

[0170] For example, each of the multiple hot page sets and multiple cold page sets mentioned above can be an array structure. Depending on the application scenario, some sets can be set as ordered array structures, and some sets as unordered array structures. Each element in the array structure is used to represent information such as the starting position and length of a memory segment (including one or more memory pages) in the virtual memory space.

[0171] It should be noted that, in this embodiment, after scanning the hot and cold states of multiple memory pages, the multiple memory pages are stored in corresponding sets. Multiple sets of hot pages correspond to memory hot zones, and multiple sets of cold pages correspond to memory cold zones. The memory hot zones store memory pages accessed during the current scan cycle, and the memory cold zones store memory pages not accessed during the current scan cycle.

[0172] Specifically, the access frequency of the multiple hot page sets mentioned above varies, and each hot page set can include at least two hot page sets. Therefore, when storing multiple memory pages into multiple hot page sets, it is possible to distinguish which memory pages are "hotter" and which are relatively "colder" among the hot pages. Similarly, the access frequency of the multiple cold page sets mentioned above also varies, and each cold page set can include at least two cold page sets. Therefore, when storing multiple memory pages into multiple cold page sets, it is possible to distinguish which memory pages are "colder" and which are relatively "hotter" among the cold pages.

[0173] Furthermore, within the target memory information, multiple hot page sets are determined and sorted in descending order of access popularity. When scanning these hot page sets, they are traversed in descending order of access popularity (i.e., starting from the hottest), and memory pages that have been accessed in consecutive scan cycles are continuously moved to hot page sets with higher access popularity. Similarly, multiple cold page sets are sorted in ascending order of access popularity. When scanning these cold page sets, they are traversed in ascending order of access popularity (i.e., starting from the coldest), and memory pages that have not been accessed in consecutive scan cycles are continuously moved to cold page sets with lower access popularity.

[0174] During the hot / cold state scan, the target memory information is updated in real time. Based on the operating system's memory space requirements, memory pages to be swapped can be selected at any time using the current target memory information. For example, based on the target memory information, the memory page with the lowest access frequency is selected from the virtual memory space as the memory page to be swapped, and the data in that memory page is swapped out to the swap space.

[0175] In this embodiment, a memory management request is obtained through a first application programming interface (API), wherein the request data carried in the memory management request is used to determine the memory segment to be scanned in the virtual memory space; a memory management response is returned through a second API, wherein the response data carried in the memory management response is used to determine the memory page to be swapped in the virtual memory space. The memory page to be swapped is selected from the virtual memory space through target memory information, which is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned. The target memory information includes multiple sets of hot pages and multiple sets of cold pages, with the multiple sets of hot pages arranged in order of access frequency and the multiple sets of cold pages arranged in order of access frequency.

[0176] It is noteworthy that, compared with related technologies that simply divide memory pages into active and inactive categories and perform memory swapping accordingly, the embodiments of this application not only perform memory swapping on the virtual memory space in the virtualization architecture, enabling the operating system to enable memory swapping online, but also further refine the hotness and coldness of memory pages by using multiple sets of hot pages and multiple sets of cold pages. Based on this, it is possible to select memory pages to be swapped more appropriately and accurately, thereby improving the flexibility of the operating system's memory management, enhancing system elasticity and stability.

[0177] In summary, the embodiments of this application achieve the purpose of scanning the cold and hot status of memory pages in the virtual memory space of the operating system and thereby realizing memory swapping, thus achieving the technical effects of improving the flexibility of system memory management, enhancing system elasticity and system stability, and solving the technical problems of low memory management flexibility and poor system memory swapping performance of memory management schemes provided in related technologies.

[0178] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Embodiment 1, and will not be repeated here.

[0179] Example 3

[0180] In the operating environment as described in Embodiment 1, this application provides another memory management method as shown in Figure 5. Figure 5 is a flowchart of a memory management method according to Embodiment 3 of this application. As shown in Figure 5, the memory management method includes:

[0181] Step S51: Obtain the currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: the memory segment to be scanned in the virtual memory space;

[0182] Step S52: In response to the memory management dialog request, a memory management dialog reply is returned. The information carried in the memory management dialog reply includes: memory swapping processing result, which is obtained by swapping memory pages to be swapped in the virtual memory space. The memory pages to be swapped are selected from the virtual memory space through target memory information. The target memory information is generated by scanning the hot and cold status of multiple memory pages in the memory segment to be scanned. The target memory information includes multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0183] Step S53: Display the memory swapping results within the graphical user interface.

[0184] Based on the above method steps, a visualization scheme for memory management functions is provided. The terminal device provides a graphical user interface (GUI), which displays at least one memory management scenario. The GUI's display content also includes input components (such as text input boxes, voice input controls, etc.) and display components (such as text display windows). The user inputs a memory management dialog request through the input components to specify the memory segment to be scanned in the virtual memory space of the memory management task. After detecting the user's input, a memory management process is executed based on the memory segment to be scanned in the virtual memory space to obtain the memory swapping result. Furthermore, the memory swapping result is displayed through the display components within the GUI.

[0185] The aforementioned virtual memory space can be the memory space of a virtualization architecture, and more particularly, the memory space of a lightweight virtualization architecture. In application scenarios, the memory swapping function of the operating system is usually determined during installation, and it is difficult to enable the memory swapping function online for an existing operating system (which may lead to system instability or crashes). Therefore, the memory management method provided in this application can be applied to virtualization architectures. That is, the existing operating system is converted into a virtualization architecture in virtual mode, and then the memory swapping function is enabled online for this virtualization architecture according to the above method steps. After performing a memory cold / hot status scan on the virtual memory space of the virtualization architecture, memory page swapping is completed, enhancing the elasticity and stability of the existing operating system.

[0186] The aforementioned memory hot / cold scan command is used to trigger a memory hot / cold status scan of the virtual memory space. This memory hot / cold scan command can be triggered by a periodically executed scan task, or it can be actively triggered by technicians or running programs.

[0187] The aforementioned memory hot / cold scan command can be used to specify a memory segment to be scanned in the virtual memory space. This memory segment includes multiple memory pages. The process of swapping memory in the virtual memory space can be viewed as: selecting memory pages to be swapped based on their hot / cold status. The memory segment to be scanned can be a portion or the entire virtual memory space. In application scenarios, multiple rounds of traversal scanning of multiple portions of the virtual memory space can be used to achieve a full scan of the virtual memory space.

[0188] The aforementioned target memory information can be used to characterize the memory information of each of multiple hot page sets and multiple cold page sets. This memory information may include data such as the address and space size of the memory pages contained in the set. The aforementioned access heat is used to characterize the hot and cold status of memory pages. The higher the access heat, the more frequently the memory data is accessed within a certain time range (which may include one or more scan cycles).

[0189] For example, each of the multiple hot page sets and multiple cold page sets mentioned above can be an array structure. Depending on the application scenario, some sets can be set as ordered array structures, and some sets as unordered array structures. Each element in the array structure is used to represent information such as the starting position and length of a memory segment (including one or more memory pages) in the virtual memory space.

[0190] It should be noted that, in this embodiment, after scanning the hot and cold states of multiple memory pages, the multiple memory pages are stored in corresponding sets. Multiple sets of hot pages correspond to memory hot zones, and multiple sets of cold pages correspond to memory cold zones. The memory hot zones store memory pages accessed during the current scan cycle, and the memory cold zones store memory pages not accessed during the current scan cycle.

[0191] Specifically, the access frequency of the multiple hot page sets mentioned above varies, and each hot page set can include at least two hot page sets. Therefore, when storing multiple memory pages into multiple hot page sets, it is possible to distinguish which memory pages are "hotter" and which are relatively "colder" among the hot pages. Similarly, the access frequency of the multiple cold page sets mentioned above also varies, and each cold page set can include at least two cold page sets. Therefore, when storing multiple memory pages into multiple cold page sets, it is possible to distinguish which memory pages are "colder" and which are relatively "hotter" among the cold pages.

[0192] Furthermore, within the target memory information, multiple hot page sets are determined and sorted in descending order of access popularity. When scanning these hot page sets, they are traversed in descending order of access popularity (i.e., starting from the hottest), and memory pages that have been accessed in consecutive scan cycles are continuously moved to hot page sets with higher access popularity. Similarly, multiple cold page sets are sorted in ascending order of access popularity. When scanning these cold page sets, they are traversed in ascending order of access popularity (i.e., starting from the coldest), and memory pages that have not been accessed in consecutive scan cycles are continuously moved to cold page sets with lower access popularity.

[0193] During the hot / cold state scan, the target memory information is updated in real time. Based on the operating system's memory space requirements, memory pages to be swapped can be selected at any time using the current target memory information. For example, based on the target memory information, the memory page with the lowest access frequency is selected from the virtual memory space as the memory page to be swapped, and the data in that memory page is swapped out to the swap space.

[0194] In this embodiment, a currently input memory management dialog request is obtained, wherein the information carried in the memory management dialog request includes: a memory segment to be scanned in the virtual memory space; in response to the memory management dialog request, a memory management dialog reply is returned, wherein the information carried in the memory management dialog reply includes: a memory swapping processing result, which is obtained by swapping memory pages to be swapped in the virtual memory space, the memory pages to be swapped are selected from the virtual memory space through target memory information, the target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; the memory swapping processing result is displayed in a graphical user interface.

[0195] It is noteworthy that, compared with related technologies that simply divide memory pages into active and inactive categories and perform memory swapping accordingly, the embodiments of this application not only perform memory swapping on the virtual memory space in the virtualization architecture, enabling the operating system to enable memory swapping online, but also further refine the hotness and coldness of memory pages by using multiple sets of hot pages and multiple sets of cold pages. Based on this, it is possible to select memory pages to be swapped more appropriately and accurately, thereby improving the flexibility of the operating system's memory management, enhancing system elasticity and stability.

[0196] In summary, the embodiments of this application achieve the purpose of scanning the cold and hot status of memory pages in the virtual memory space of the operating system and thereby realizing memory swapping, thus achieving the technical effects of improving the flexibility of system memory management, enhancing system elasticity and system stability, and solving the technical problems of low memory management flexibility and poor system memory swapping performance of memory management schemes provided in related technologies.

[0197] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Embodiment 1, and will not be repeated here.

[0198] Example 4

[0199] According to an embodiment of this application, an apparatus embodiment configured to implement the above-described memory management method is also provided. Figure 6 is a schematic structural diagram of a memory management apparatus according to Embodiment 4 of this application. As shown in Figure 6, the apparatus includes:

[0200] The determination module 601 is configured to determine the memory segment to be scanned from the virtual memory space in response to a memory hot / cold scan instruction.

[0201] The generation module 602 is configured to perform a hot and cold state scan on multiple memory pages in the memory segment to be scanned and generate target memory information. The target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0202] Module 603 is configured to select memory pages to be swapped from the virtual memory space based on target memory information;

[0203] The recycling module 604 is configured to perform memory swapping on memory pages to be swapped.

[0204] Optionally, in addition to all the modules mentioned above, the memory management device also includes: a task processing module 605 (not shown in the figure), used to: establish a memory hot / cold detection task for the target processor, wherein the memory hot / cold detection task is an asynchronous background task executed by the target processor according to a preset period and a preset duration, and the memory hot / cold detection task is used to detect the hot / cold status of memory pages in the virtual memory space; during the execution of the memory hot / cold detection task by the target processor, the update task mounted in the asynchronous task cache of the target processor is processed, wherein the task category of the update task includes at least a scan task, and the scan task is used to scan the hot / cold status of multiple memory pages in the memory segment to be scanned, and generate target memory information.

[0205] Optionally, in the memory management device described above, the update task categories also include add tasks, delete tasks, control tasks, and exception tasks. The add task is used to add a specified memory page to a specified set and update the target memory information. The specified set can be any one of multiple hot page sets and multiple cold page sets. The delete task is used to delete a specified memory page from the specified set and update the target memory information. The control task is used to change the attributes of the specified set and update the target memory information. The exception task is used to handle and repair faults occurring in multiple hot page sets and multiple cold page sets and update the target memory information.

[0206] Optionally, in the memory management device described above, the memory segment to be scanned includes one of the following: a memory segment allocated for the initialization of the target processor, or a memory segment corresponding to at least a portion of the memory pages in a set of multiple hot pages and a set of multiple cold pages obtained by performing a scan task during a historical scan cycle.

[0207] Optionally, the generation module 602 is further configured to: traverse multiple memory pages, for the target memory page currently being traversed, query the access flag bit of the target memory page from the memory page table; and, based on the access flag bit, store the target memory page into the target set in the target memory information to generate the target memory information.

[0208] Optionally, the memory segment to be scanned includes multiple hot page sets determined by the scanning task executed within the historical scanning cycle; the generation module 602 is further configured to: traverse and scan the multiple hot page sets in descending order of access popularity; for the target memory page in the current hot page set being traversed and scanned, query the access flag bit of the target memory page from the memory page table; determine the target set to be stored from the target memory information based on the access flag bit; and store the target memory page into the target set to obtain the updated target memory information.

[0209] Optionally, the generation module 602 is further configured to: in response to the access flag bit being set to a first value, determine the target set as the first cold page set with the highest access frequency among multiple cold page sets, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle; when the current hot page set is the first hot page set, in response to the access flag bit being set to a second value, determine the target set as the current hot page set, wherein the first hot page set is the hot page set with the highest access frequency among multiple hot page sets, and the second value is used to indicate that the target memory page has been accessed in the current scan cycle; when the current hot page set is any other hot page set among multiple hot page sets besides the first hot page set, in response to the access flag bit being set to a second value, determine the target set as the hot page set among multiple hot page sets with access frequency higher than the current hot page set and adjacent to the current hot page set.

[0210] Optionally, the memory segment to be scanned includes multiple sets of cold pages determined by scanning tasks executed during historical scanning cycles; the generation module 602 is further configured to: traverse and scan the multiple sets of cold pages in ascending order of access popularity; for the target memory page in the current set of cold pages being traversed and scanned, query the access flag bit of the target memory page from the memory page table; determine the target set to be stored from the target memory information based on the access flag bit; and store the target memory page into the target set to obtain the updated target memory information.

[0211] Optionally, the generation module 602 is further configured to: in response to the access flag bit being set to a second value, determine the target set as the second hot page set with the lowest access popularity among multiple hot page sets, wherein the second value is used to indicate that the target memory page is accessed in the current scan cycle; when the current cold page set is the second cold page set, in response to the access flag bit being set to a first value, determine the target set as the current cold page set, wherein the first value is used to indicate that the target memory page is not accessed in the current scan cycle; when the current cold page set is any other cold page set among multiple cold page sets besides the second cold page set, in response to the access flag bit being set to a first value, determine the target set as the cold page set among multiple cold page sets whose access popularity is lower than that of the current cold page set and which is adjacent to the current cold page set.

[0212] Optionally, in addition to all the modules mentioned above, the memory management device also includes: a setting module 606 (not shown in the figure), which is configured to: after storing the target memory page into the target set, set the access flag bit to a first value.

[0213] Optionally, the determination module 601 is further configured to: determine the memory region to be scanned and the scan time slice in the virtual memory space based on the memory cold and hot scan instructions; calculate the scan length according to the scan time slice and the preset scan rules; and select the memory segment to be scanned from the memory region to be scanned using the scan length.

[0214] Optionally, in addition to all the modules mentioned above, the memory management device also includes a scheduling module 607 (not shown in the figure), which is configured to: in response to a cold / hot state scan of a memory segment to be scanned that has not been completed within the scan time slice, determine the unscanned portion of the memory segment from the memory segment to be scanned, and schedule the portion of the memory segment to the asynchronous cache of the scan task corresponding to the target processor.

[0215] Optionally, in addition to all the modules mentioned above, the memory management device also includes: an update module 608 (not shown in the figure), which is configured to: count the number of accesses to multiple memory pages in the first hot page set and obtain statistical results; segment and aggregate the multiple memory pages according to the statistical results to obtain multiple aggregated memory segments; and scan the memory cold and hot status of the multiple aggregated memory segments using a preset memory length threshold to update the first hot page set.

[0216] It should be noted that the above-mentioned determining module 601, generating module 602, selecting module 603 and recycling module 604 correspond to steps S31 to S34 in Embodiment 1. The four modules and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1.

[0217] According to an embodiment of this application, an apparatus embodiment configured to implement the memory management method in Embodiment 2 above is also provided. Figure 7 is a schematic diagram of another memory management apparatus according to Embodiment 4 of this application. As shown in Figure 7, the apparatus includes:

[0218] The acquisition module 701 is configured to acquire a memory management request through a first application programming interface, wherein the request data carried in the memory management request is used to determine: the memory segment to be scanned in the virtual memory space;

[0219] Return module 702 is configured to return a memory management response via a second application programming interface. The response data carried in the memory management response is used to determine the memory pages to be swapped in the virtual memory space. The memory pages to be swapped are selected from the virtual memory space through target memory information. The target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned. The target memory information includes multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency.

[0220] It should be noted that the above-mentioned acquisition module 701 and return module 702 correspond to steps S41 to S42 in embodiment 2. The two modules and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in embodiment 2 above.

[0221] According to an embodiment of this application, an apparatus embodiment configured to implement the memory management method in embodiment 3 above is also provided. Figure 8 is a schematic diagram of another memory management apparatus according to embodiment 4 of this application. As shown in Figure 8, the apparatus includes:

[0222] The acquisition module 801 is configured to acquire the currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: the memory segment to be scanned in the virtual memory space;

[0223] The response module 802 is configured to respond to a memory management dialog request and return a memory management dialog response. The memory management dialog response carries information including: a memory swapping result, which is obtained by swapping memory pages in the virtual memory space. The memory pages to be swapped are selected from the virtual memory space using target memory information. The target memory information is generated by scanning multiple memory pages in the memory segment to be scanned for hot and cold status. The target memory information includes multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency.

[0224] Display module 803 is configured to display the results of memory swapping within a graphical user interface.

[0225] It should be noted that the above-mentioned acquisition module 801, response module 802 and display module 803 correspond to steps S51 to S53 in embodiment 3. The three modules and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in embodiment 3 above.

[0226] It should be noted that the above-mentioned modules or units may be hardware or software components stored in memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n). The above-mentioned modules may also be part of the device and may run in the computer terminal 10 provided in Embodiment 1.

[0227] It should be noted that the preferred implementation of this embodiment can be found in the relevant descriptions in Embodiment 1, Embodiment 2 or Embodiment 3, and will not be repeated here.

[0228] Example 5

[0229] According to an embodiment of this application, an electronic device is also provided, which can be any terminal device in a group of computer terminals. Optionally, in this embodiment, the above-mentioned electronic device can also be replaced by a mobile terminal or other terminal device.

[0230] Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.

[0231] In this embodiment, the above-mentioned electronic device can execute the program code of the following steps in the memory management method: in response to a memory hot / cold scan instruction, determine the memory segment to be scanned from the virtual memory space; perform a hot / cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; based on the target memory information, select memory pages to be swapped from the virtual memory space; and perform memory swapping on the memory pages to be swapped.

[0232] Optionally, FIG9 is a structural block diagram of an electronic device according to Embodiment 5 of the present application. As shown in FIG9, the electronic device 90 may include: one or more (only one is shown in the figure) processors 902, memory 904, memory controller 906, and peripheral interface 908, wherein the peripheral interface 908 is connected to a radio frequency module, an audio module, and a display.

[0233] The memory 904 can be configured to store software programs and modules, such as the program instructions / modules corresponding to the memory management method and apparatus in this embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the aforementioned memory management method. The memory 904 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 904 may further include memory remotely located relative to the processor, and these remote memories can be connected to the electronic device 90 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0234] The processor 902 can invoke information and application programs stored in the memory via the transmission device to perform the following steps: in response to a memory hot / cold scan instruction, determine a memory segment to be scanned from the virtual memory space; perform a hot / cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency; based on the target memory information, select memory pages to be swapped from the virtual memory space; and perform memory swapping on the memory pages to be swapped.

[0235] Optionally, the processor 902 may also execute program code that performs the following steps: establishing a memory hot / cold detection task for the target processor, wherein the memory hot / cold detection task is an asynchronous background task executed by the target processor according to a preset period and a preset duration, and the memory hot / cold detection task is used to detect the hot / cold status of memory pages in the virtual memory space; during the execution of the memory hot / cold detection task by the target processor, processing the update task mounted in the asynchronous task cache of the target processor, wherein the update task's task category includes at least a scan task, and the scan task is used to scan the hot / cold status of multiple memory pages in the memory segment to be scanned, and generate target memory information.

[0236] Optionally, the processor 902 may also execute program code with the following steps: The task categories for updating tasks also include adding tasks, deleting tasks, control tasks, and exception tasks. Among them, adding tasks are used to add specified memory pages to specified sets and update target memory information. The specified sets are any one of multiple hot page sets and multiple cold page sets. Deleting tasks are used to delete specified memory pages from the specified sets and update target memory information. Control tasks are used to change the attributes of the specified sets and update target memory information. Exception tasks are used to handle and repair faults that occur in multiple hot page sets and multiple cold page sets and update target memory information.

[0237] Optionally, the processor 902 may also execute program code that includes the following steps: the memory segment to be scanned includes one of the following: a memory segment allocated for initialization of the target processor, or a memory segment corresponding to at least a portion of the memory pages in a set of multiple hot pages and a set of multiple cold pages obtained by performing a scan task during a historical scan cycle.

[0238] Optionally, the processor 902 may also execute program code that performs the following steps: traversing multiple memory pages; for the target memory page being traversed, querying the access flag bit of the target memory page from the memory page table; and storing the target memory page into the target set in the target memory information according to the access flag bit, thereby generating the target memory information.

[0239] Optionally, the processor 902 may also execute program code with the following steps: the memory segment to be scanned includes multiple hot page sets determined by the scanning task executed in the historical scanning cycle; the multiple hot page sets are traversed and scanned in descending order of access popularity; for the target memory page in the current hot page set being traversed and scanned, the access flag bit of the target memory page is queried from the memory page table; based on the access flag bit, the target set to be stored is determined from the target memory information; the target memory page is stored into the target set to obtain the updated target memory information.

[0240] Optionally, the processor 902 may also execute program code with the following steps: in response to the access flag bit being set to a first value, the target set is determined to be the first cold page set with the highest access frequency among multiple cold page sets, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle; when the current hot page set is the first hot page set, in response to the access flag bit being set to a second value, the target set is determined to be the current hot page set, wherein the first hot page set is the hot page set with the highest access frequency among multiple hot page sets, and the second value is used to indicate that the target memory page has been accessed in the current scan cycle; when the current hot page set is any other hot page set among multiple hot page sets besides the first hot page set, in response to the access flag bit being set to a second value, the target set is determined to be the hot page set among multiple hot page sets with access frequency higher than the current hot page set and adjacent to the current hot page set.

[0241] Optionally, the processor 902 may also execute program code with the following steps: the memory segment to be scanned includes multiple sets of cold pages determined by the scanning task executed in the historical scanning cycle; the multiple sets of cold pages are traversed and scanned in ascending order of access popularity; for the target memory page in the current set of cold pages being traversed and scanned, the access flag bit of the target memory page is queried from the memory page table; based on the access flag bit, the target set to be stored is determined from the target memory information; the target memory page is stored into the target set to obtain the updated target memory information.

[0242] Optionally, the processor 902 may also execute program code with the following steps: in response to the access flag bit being set to a second value, the target set is determined to be the second hot page set with the lowest access frequency among the multiple hot page sets, wherein the second value is used to indicate that the target memory page is accessed in the current scan cycle; when the current cold page set is the second cold page set, in response to the access flag bit being set to a first value, the target set is determined to be the current cold page set, wherein the first value is used to indicate that the target memory page is not accessed in the current scan cycle; when the current cold page set is any other cold page set among the multiple cold page sets besides the second cold page set, in response to the access flag bit being set to the first value, the target set is determined to be the cold page set among the multiple cold page sets whose access frequency is lower than that of the current cold page set and which is adjacent to the current cold page set.

[0243] Optionally, the processor 902 may also execute program code that performs the following steps: after storing the target memory page into the target set, sets the access flag to a first value.

[0244] Optionally, the processor 902 may also execute program code that performs the following steps: determining the memory region to be scanned and the scan time slice in the virtual memory space based on memory cold and hot scan instructions; calculating the scan length according to the scan time slice and preset scan rules; and selecting the memory segment to be scanned from the memory region to be scanned using the scan length.

[0245] Optionally, the processor 902 may also execute program code that performs the following steps: in response to a cold / hot state scan of a memory segment to be scanned that has not been completed within the scan time slice, it determines the unscanned portion of the memory segment from the memory segment to be scanned and schedules the portion of the memory segment to the asynchronous cache of the scan task corresponding to the target processor.

[0246] Optionally, the processor 902 may also execute program code that performs the following steps: counts the number of accesses to multiple memory pages in the first hot page set and obtains the statistical results; aggregates the multiple memory pages into multiple aggregated memory segments based on the statistical results and obtains multiple aggregated memory segments; scans the memory hot and cold status of the multiple aggregated memory segments using a preset memory length threshold and updates the first hot page set.

[0247] The processor 902 can invoke information and application programs stored in the memory via the transmission device to perform the following steps: obtaining a memory management request through a first application programming interface, wherein the request data carried in the memory management request is used to determine: a memory segment to be scanned in the virtual memory space; returning a memory management response through a second application programming interface, wherein the response data carried in the memory management response is used to determine a memory page to be swapped in the virtual memory space, the memory page to be swapped is selected from the virtual memory space through target memory information, the target memory information is generated by performing a hot and cold state scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency.

[0248] The processor 902 can invoke information and application programs stored in the memory via the transmission device to perform the following steps: obtaining a currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: a memory segment to be scanned in the virtual memory space; responding to the memory management dialog request, returning a memory management dialog reply, wherein the information carried in the memory management dialog reply includes: a memory swapping processing result, which is obtained by swapping memory pages to be swapped in the virtual memory space, the memory pages to be swapped are selected from the virtual memory space through target memory information, the target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; and displaying the memory swapping processing result in the graphical user interface.

[0249] According to the embodiments of this application, an electronic device configured to implement the above-described memory management method is provided. In response to a memory hot / cold scan instruction, a memory segment to be scanned is determined from the virtual memory space; multiple memory pages in the memory segment to be scanned are scanned for their hot / cold status to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages being arranged in order of access frequency, and the multiple sets of cold pages being arranged in order of access frequency; based on the target memory information, memory pages to be swapped are selected from the virtual memory space; and memory swapping of the memory pages to be swapped is performed.

[0250] It is noteworthy that, compared to related technologies that simply categorize memory pages into active and inactive types and perform memory swapping accordingly, this embodiment not only performs memory swapping on the virtual memory space within the virtualization architecture, enabling online memory swapping for the operating system, but also more finely classifies the hotness and coldness of memory pages through multiple sets of hot pages and multiple sets of cold pages. Based on this, it can more appropriately and accurately select memory pages to be swapped, improving the flexibility of the operating system's memory management, enhancing system resilience, and improving system stability. Therefore, this embodiment achieves the goal of scanning the hot and cold states of memory pages in the operating system's virtual memory space and thereby realizing memory swapping, thus achieving the technical effects of improving system memory management flexibility, enhancing system resilience, and improving system stability. This solves the technical problems of low memory management flexibility and poor system memory swapping performance in related memory management schemes.

[0251] It will be understood by those skilled in the art that the structure shown in Figure 9 is merely illustrative, and the electronic device may also be a smartphone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, or a mobile internet device (MID), etc. Figure 9 does not limit the structure of the aforementioned electronic device. For example, the electronic device 90 may also include more or fewer components (such as a network interface, a display device, etc.) than shown in Figure 9, or have a different configuration than that shown in Figure 9.

[0252] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, ROM, RAM, disk or optical disk, etc.

[0253] Example 6

[0254] According to an embodiment of this application, a computer-readable storage medium is also provided. Optionally, in this embodiment, the storage medium may be configured to store the program code executed by the memory management method provided in Embodiment 1, Embodiment 2, or Embodiment 3.

[0255] Optionally, in this embodiment, the storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.

[0256] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: in response to a memory hot / cold scan instruction, determining a memory segment to be scanned from a virtual memory space; performing a hot / cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages being arranged in order of access frequency, and the multiple sets of cold pages being arranged in order of access frequency; selecting memory pages to be swapped from the virtual memory space based on the target memory information; and performing memory swapping on the memory pages to be swapped.

[0257] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: establishing a memory hot / cold detection task for the target processor, wherein the memory hot / cold detection task is an asynchronous background task executed by the target processor according to a preset period and a preset duration, and the memory hot / cold detection task is used to detect the hot / cold status of memory pages in the virtual memory space; during the execution of the memory hot / cold detection task by the target processor, processing update tasks mounted in the asynchronous task cache of the target processor, wherein the task category of the update task includes at least a scan task, and the scan task is used to scan the hot / cold status of multiple memory pages in the memory segment to be scanned, and generate target memory information.

[0258] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: the task categories for updating tasks further include adding tasks, deleting tasks, control tasks, and exception tasks, wherein adding tasks are used to add specified memory pages to specified sets and update target memory information, and the specified sets are any one of multiple hot page sets and multiple cold page sets; deleting tasks are used to delete specified memory pages from the specified sets and update target memory information; control tasks are used to change the attributes of the specified sets and update target memory information; exception tasks are used to process and repair faults occurring in multiple hot page sets and multiple cold page sets and update target memory information.

[0259] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: the memory segment to be scanned includes one of the following: a memory segment allocated for initialization of the target processor, a memory segment corresponding to at least a portion of the memory pages in a plurality of hot page sets and a plurality of cold page sets obtained by performing a scanning task during a historical scanning cycle.

[0260] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: traversing multiple memory pages; for the target memory page currently being traversed, querying the access flag bit of the target memory page from the memory page table; and storing the target memory page into the target set in the target memory information according to the access flag bit, thereby generating target memory information.

[0261] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: the memory segment to be scanned includes multiple hot page sets determined by scanning tasks executed during historical scanning cycles; the multiple hot page sets are traversed and scanned in descending order of access popularity; for the target memory page in the current hot page set being traversed and scanned, the access flag bit of the target memory page is queried from the memory page table; based on the access flag bit, the target set to be stored is determined from the target memory information; the target memory page is stored into the target set to obtain the updated target memory information.

[0262] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: In response to an access flag bit being set to a first value, determining the target set as the first cold page set with the highest access frequency among multiple cold page sets, wherein the first value indicates that the target memory page has not been accessed in the current scan cycle; when the current hot page set is the first hot page set, in response to an access flag bit being set to a second value, determining the target set as the current hot page set, wherein the first hot page set is the hot page set with the highest access frequency among multiple hot page sets, and the second value indicates that the target memory page has been accessed in the current scan cycle; when the current hot page set is any other hot page set among multiple hot page sets besides the first hot page set, in response to an access flag bit being set to the second value, determining the target set as the hot page set among multiple hot page sets with higher access frequency than the current hot page set and adjacent to the current hot page set.

[0263] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: the memory segment to be scanned includes multiple sets of cold pages determined by scanning tasks performed during historical scanning cycles; the multiple sets of cold pages are traversed and scanned in ascending order of access popularity; for the target memory page in the current set of cold pages being traversed and scanned, the access flag bit of the target memory page is queried from the memory page table; based on the access flag bit, the target set to be stored is determined from the target memory information; the target memory page is stored in the target set to obtain the updated target memory information.

[0264] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: in response to the access flag bit being a second value, determining the target set as the second hot page set with the lowest access frequency among a plurality of hot page sets, wherein the second value is used to characterize that the target memory page is accessed in the current scan cycle; when the current cold page set is the second cold page set, in response to the access flag bit being a first value, determining the target set as the current cold page set, wherein the first value is used to characterize that the target memory page is not accessed in the current scan cycle; when the current cold page set is any other cold page set among a plurality of cold page sets besides the second cold page set, in response to the access flag bit being a first value, determining the target set as the cold page set among a plurality of cold page sets whose access frequency is lower than that of the current cold page set and which is adjacent to the current cold page set.

[0265] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: after storing the target memory page into the target set, setting the access flag bit to a first value.

[0266] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: determining the memory region to be scanned and the scan time slice in the virtual memory space based on memory cold and hot scan instructions; calculating the scan length according to the scan time slice and preset scan rules; and selecting a memory segment to be scanned from the memory region to be scanned using the scan length.

[0267] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: in response to a cold / hot state scan of a memory segment to be scanned that has not been completed within the scan time slice, determining an unscanned portion of the memory segment from the memory segment to be scanned, and scheduling the portion of the memory segment to the asynchronous cache of the scan task corresponding to the target processor.

[0268] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: counting the number of accesses to multiple memory pages in the first hot page set to obtain statistical results; segmenting and aggregating the multiple memory pages according to the statistical results to obtain multiple aggregated memory segments; and using a preset memory length threshold, scanning the memory hot and cold status of the multiple aggregated memory segments to update the first hot page set.

[0269] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: obtaining a memory management request through a first application programming interface, wherein the request data carried in the memory management request is used to determine: a memory segment to be scanned in the virtual memory space; returning a memory management response through a second application programming interface, wherein the response data carried in the memory management response is used to determine a memory page to be swapped in the virtual memory space, the memory page to be swapped is selected from the virtual memory space through target memory information, the target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity.

[0270] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: obtaining a currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: a memory segment to be scanned in the virtual memory space; responding to the memory management dialog request, returning a memory management dialog response, wherein the information carried in the memory management dialog response includes: a memory swapping processing result, which is obtained by swapping memory pages to be swapped in the virtual memory space, the memory pages to be swapped are selected from the virtual memory space using target memory information, the target memory information is generated by performing a hot and cold status scan on multiple memory pages in the memory segment to be scanned, the target memory information includes multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; and displaying the memory swapping processing result in a graphical user interface.

[0271] According to embodiments of this application, a computer-readable storage medium configured to implement the above-described memory management method is provided. In response to a memory hot / cold scan instruction, a memory segment to be scanned is determined from the virtual memory space; multiple memory pages in the memory segment to be scanned are scanned for their hot / cold status to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages being arranged in order of access frequency, and the multiple sets of cold pages being arranged in order of access frequency; based on the target memory information, memory pages to be swapped are selected from the virtual memory space; and memory swapping of the memory pages to be swapped is performed.

[0272] It is noteworthy that, compared to related technologies that simply categorize memory pages into active and inactive types and perform memory swapping accordingly, this embodiment not only performs memory swapping on the virtual memory space within the virtualization architecture, enabling online memory swapping for the operating system, but also more finely classifies the hotness and coldness of memory pages through multiple sets of hot pages and multiple sets of cold pages. Based on this, it can more appropriately and accurately select memory pages to be swapped, improving the flexibility of the operating system's memory management, enhancing system resilience, and improving system stability. Therefore, this embodiment achieves the goal of scanning the hot and cold states of memory pages in the operating system's virtual memory space and thereby realizing memory swapping, thus achieving the technical effects of improving system memory management flexibility, enhancing system resilience, and improving system stability. This solves the technical problems of low memory management flexibility and poor system memory swapping performance in related memory management schemes.

[0273] According to an embodiment of this application, a computer program product is also provided. Optionally, in this embodiment, the computer program product can provide memory management services based on the memory management method provided in Embodiment 1, Embodiment 2, or Embodiment 3.

[0274] Optionally, in this embodiment, the computer program product described above may be a set of instructions and code pre-written according to the memory management method described above. This computer program product can run on various computer platforms, including personal computers, servers, mobile devices, etc.

[0275] Optionally, in this embodiment, the instructions and code corresponding to the computer program product are used to implement the following method steps: in response to a memory hot / cold scan instruction, determining a memory segment to be scanned from the virtual memory space; performing a hot / cold status scan on multiple memory pages in the memory segment to be scanned to generate target memory information, wherein the target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages, the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; selecting memory pages to be swapped from the virtual memory space based on the target memory information; and performing memory swapping on the memory pages to be swapped.

[0276] The aforementioned computer program product provides memory management services for application scenarios involving memory swapping in virtualized computing environments. In this embodiment, the computer program product not only performs memory swapping on the virtual memory space within the virtualized architecture, enabling online memory swapping for the operating system, but also allows for more detailed classification of memory pages based on their hot and cold page status using multiple sets of hot and cold pages. This allows for more appropriate and accurate selection of memory pages to be swapped, improving the operating system's memory management flexibility, enhancing system resilience, and improving system stability. Therefore, this embodiment achieves the goal of scanning the hot and cold status of memory pages in the operating system's virtual memory space and thereby enabling memory swapping. This achieves the technical effects of improving system memory management flexibility, enhancing system resilience, and improving system stability, thus solving the technical problems of low memory management flexibility and poor system memory swapping performance in related technologies.

[0277] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0278] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0279] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.

[0280] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0281] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0282] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, ROM, RAM, portable hard drives, magnetic disks, or optical disks.

[0283] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. A memory management method, comprising: In response to a memory hot / cold scan command, determine the memory segment to be scanned from the virtual memory space; A hot and cold status scan is performed on multiple memory pages in the memory segment to be scanned to generate target memory information. The target memory information is used to determine multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency. Based on the target memory information, select memory pages to be swapped from the virtual memory space; The memory pages to be swapped are swapped.

2. The memory management method according to claim 1, wherein, The memory management method further includes: A memory hot / cold detection task is established for the target processor, wherein the memory hot / cold detection task is an asynchronous background task executed by the target processor according to a preset period and a preset duration, and the memory hot / cold detection task is used to detect the hot / cold status of memory pages in the virtual memory space. During the execution of the memory hot / cold detection task by the target processor, the update task mounted in the asynchronous task cache of the target processor is processed. The update task includes at least a scan task, which is used to perform a hot / cold status scan on the plurality of memory pages in the memory segment to be scanned, and generate the target memory information.

3. The memory management method according to claim 2, wherein, The update task categories also include adding tasks, deleting tasks, control tasks, and exception tasks. The newly added task is used to add a specified memory page to a specified set and update the target memory information, wherein the specified set is any one of the multiple hot page sets and the multiple cold page sets; The deletion task is used to delete a specified memory page from the specified set and update the target memory information; The control task is used to change the attributes of the specified set and update the target memory information; The exception task is used to process and repair faults that occur in the multiple hot page sets and the multiple cold page sets, and to update the target memory information.

4. The memory management method according to any one of claims 1 to 3, wherein, The memory segment to be scanned includes one of the following: a memory segment allocated for the initialization of the target processor, or a memory segment corresponding to at least a portion of the memory pages in the plurality of hot page sets and the plurality of cold page sets obtained by executing scanning tasks during historical scanning cycles.

5. The memory management method according to claim 1, wherein, Performing a cold / hot status scan on the plurality of memory pages in the memory segment to be scanned, and generating the target memory information includes: The multiple memory pages are traversed, and for the target memory page being traversed, the access flag of the target memory page is retrieved from the memory page table; Based on the access flag, the target memory page is stored in the target set in the target memory information to generate the target memory information.

6. The memory management method according to claim 1, wherein, The memory segment to be scanned includes the multiple hot page sets determined by the scanning tasks executed during historical scanning cycles; Performing a cold / hot status scan on the plurality of memory pages in the memory segment to be scanned, and generating the target memory information includes: The multiple sets of hot pages are traversed and scanned in descending order of access popularity. For the target memory page in the current hot page set being traversed and scanned, the access flag of the target memory page is retrieved from the memory page table; Based on the access flag, determine the target set to be stored from the target memory information; The target memory page is stored in the target set to obtain the updated target memory information.

7. The memory management method according to claim 6, wherein, Based on the access flag, the target set to be stored is determined from the target memory information as follows: In response to the access flag bit being set to a first value, the target set is determined to be the first cold page set with the highest access frequency among the plurality of cold page sets, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle; When the current hot page set is the first hot page set, in response to the access flag bit taking the value of the second value, the target set is determined to be the current hot page set, wherein the first hot page set is the hot page set with the highest access frequency among the plurality of hot page sets, and the second value is used to characterize that the target memory page is accessed in the current scan cycle; When the current hot page set is any hot page set other than the first hot page set among the plurality of hot page sets, in response to the access flag bit being set to the second value, the target set is determined to be the hot page set among the plurality of hot page sets whose access popularity is higher than the current hot page set and which is adjacent to the current hot page set.

8. The memory management method according to claim 1, wherein, The memory segment to be scanned includes the multiple sets of cold pages determined by scanning tasks executed during historical scanning cycles; Performing a cold / hot status scan on the plurality of memory pages in the memory segment to be scanned, and generating the target memory information includes: The multiple cold page sets are traversed and scanned in ascending order of access popularity; For the target memory page in the current cold page set being traversed and scanned, the access flag of the target memory page is retrieved from the memory page table; Based on the access flag, determine the target set to be stored from the target memory information; The target memory page is stored in the target set to obtain the updated target memory information.

9. The memory management method according to claim 8, wherein, Based on the access flag, the target set to be stored is determined from the target memory information as follows: In response to the access flag bit taking the value of the second value, the target set is determined to be the second hot page set with the lowest access frequency among the plurality of hot page sets, wherein the second value is used to characterize that the target memory page is accessed in the current scan cycle; When the current cold page set is the second cold page set, in response to the access flag bit taking the value of the first value, the target set is determined to be the current cold page set, wherein the first value is used to indicate that the target memory page has not been accessed in the current scan cycle; When the current cold page set is any other cold page set among the plurality of cold page sets besides the second cold page set, in response to the access flag bit being set to the first value, the target set is determined to be the cold page set among the plurality of cold page sets whose access popularity is lower than that of the current cold page set and which is adjacent to the current cold page set.

10. The memory management method according to claim 7 or 9, wherein, The memory management method further includes: After storing the target memory page into the target set, the access flag is set to the first value.

11. The memory management method according to any one of claims 5 to 9, wherein, Determining the memory segment to be scanned from the virtual memory space includes: Based on the memory hot and cold scan instructions, the memory region to be scanned and the scan time slice in the virtual memory space are determined; The scan length is calculated based on the scan time slice and the preset scan rules; Using the scan length, the memory segment to be scanned is selected from the memory region to be scanned.

12. The memory management method according to claim 11, wherein, The memory management method further includes: In response to the failure to complete the cold and hot state scan of the memory segment to be scanned within the scan time slice, the unscanned portion of the memory segment to be scanned is determined from the memory segment to be scanned, and the portion of the memory segment is scheduled to the asynchronous cache of the scan task corresponding to the target processor.

13. The memory management method according to claim 7, wherein, The memory management method further includes: The number of accesses to multiple memory pages in the first hot page set is counted, and the statistical results are obtained. Based on the statistical results, the multiple memory pages are segmented and aggregated to obtain multiple aggregated memory segments; Using a preset memory length threshold, the memory cold and hot status of the multiple aggregated memory segments is scanned, and the first hot page set is updated.

14. A memory management method, comprising: A memory management request is obtained through a first application programming interface, wherein the request data carried in the memory management request is used to determine: the memory segment to be scanned in the virtual memory space; A memory management response is returned through a second application programming interface. The response data carried in the memory management response is used to determine the memory pages to be swapped in the virtual memory space. The memory pages to be swapped are selected from the virtual memory space through target memory information. The target memory information is generated by scanning multiple memory pages in the memory segment to be scanned for hot and cold status. The target memory information includes multiple sets of hot pages and multiple sets of cold pages. The multiple sets of hot pages are arranged in order of access frequency, and the multiple sets of cold pages are arranged in order of access frequency.

15. A memory management method, comprising: Obtain the currently input memory management dialog request, wherein the information carried in the memory management dialog request includes: the memory segment to be scanned in the virtual memory space; In response to the memory management dialog request, a memory management dialog response is returned, wherein the information carried in the memory management dialog response includes: a memory swapping processing result, which is obtained by swapping memory pages to be swapped in the virtual memory space, wherein the memory pages to be swapped are selected from the virtual memory space through target memory information, wherein the target memory information is generated by scanning multiple memory pages in the memory segment to be scanned for hot and cold status, wherein the target memory information includes multiple sets of hot pages and multiple sets of cold pages, wherein the multiple sets of hot pages are arranged in order of access popularity, and the multiple sets of cold pages are arranged in order of access popularity; The memory swapping results are displayed within a graphical user interface.

16. An electronic device comprising: Memory, which stores executable programs; A processor is configured to run the program, wherein the program, when running, performs the memory management method according to any one of claims 1 to 15.

17. A computer-readable storage medium comprising a stored executable program, wherein, When the executable program is executed, it controls the device containing the computer-readable storage medium to perform the memory management method according to any one of claims 1 to 15.

18. A computer program product comprising a computer program that, when executed by a processor, implements the memory management method according to any one of claims 1 to 15.

Citation Information

Patent Citations

  • Cold and hot memory page identification method, memory recovery method and related equipment

    CN116860662A

  • Asynchronous page faults for virtual machines

    US20110107007A1

  • Method and System for Frequent Checkpointing

    US20110167194A1