CN116204309A - Memory exchange method, memory exchange device, computer equipment and storage medium - Google Patents
Memory exchange method, memory exchange device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN116204309A CN116204309A CN202310153441.4A CN202310153441A CN116204309A CN 116204309 A CN116204309 A CN 116204309A CN 202310153441 A CN202310153441 A CN 202310153441A CN 116204309 A CN116204309 A CN 116204309A
- Authority
- CN
- China
- Prior art keywords
- memory
- memory blocks
- target
- exchange
- swap
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5016—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
- G06F9/5022—Mechanisms to release resources
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/50—Indexing scheme relating to G06F9/50
- G06F2209/5021—Priority
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System Of A Hierarchy Structure (AREA)
Abstract
The present disclosure provides a memory exchange method, apparatus, computer device and storage medium, where the method includes: determining the target number of memory blocks needing memory exchange; acquiring the priority of each currently running process; in the case of a swap-out, the priority is inversely related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time; and selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
Description
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a memory exchange method, a memory exchange device, a computer device, and a storage medium.
Background
Since the physical memory of a computer is limited and the use of memory by processes is uncertain, there is always a possibility that the physical memory will be used up. The operating system adopts memory exchange to solve the problem of insufficient physical memory. The kernel selects and recovers the memory block in a cold state, and performs memory block merging, data compression to other memory blocks or swapping out to a disk and the like on the data stored by the memory block. And then the memory block is distributed to other more urgent processes for use, and when the original process is used, the data is replaced into a new memory block and is returned to the original process.
The prior art generally uses a least recently used (LRU, least Recently Used) algorithm to determine which memory blocks are reclaimed, the algorithm scans the most recently used of each memory block allocated, and the memory blocks that have not been accessed for a certain period of time are considered cold. However, the above scheme only considers the most recently used condition of the memory block from the dimension of the memory block, and the processing flexibility of the memory swap is poor.
Disclosure of Invention
In order to overcome the problems in the related art, the present disclosure provides a memory exchange method, apparatus, computer device, and storage medium.
According to a first aspect of an embodiment of the present disclosure, there is provided a memory swap method, including:
determining the target number of memory blocks needing memory exchange;
acquiring the priority of each currently running process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time;
And selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
According to a second aspect of an embodiment of the present disclosure, there is provided a memory exchange device, including:
a determining module for: determining the target number of memory blocks needing memory exchange;
a priority acquisition module, configured to: acquiring the priority of each currently running process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time;
a switching module for: and selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
According to a third aspect of embodiments of the present disclosure, there is provided a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the steps of the method embodiments of the first aspect described above are implemented when the processor executes the computer program.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method embodiments of the first aspect described above.
The technical scheme provided by the embodiment of the disclosure can comprise the following beneficial effects:
in the embodiment of the disclosure, determining the target number of memory blocks needing to be subjected to memory exchange, and firstly acquiring the priority of each currently running process from the aspect of the process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the time of the latest memory block swap-out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the time of the latest memory block swap-in and the current time; because at least one target process is selected according to the priority, and then the memory blocks with the target number are selected from the memory blocks of the at least one target process for memory exchange, the memory exchange scheme of the embodiment can consider each process and stably adjust the memory distribution of the exchange.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure.
Fig. 1 is a schematic diagram of a reserved memory scenario according to an exemplary embodiment of the present disclosure.
Fig. 2A is a flow chart illustrating a memory swap method according to an example embodiment of the present disclosure.
FIG. 2B is a diagram of a NUMA architecture shown in accordance with an exemplary embodiment of the specification.
Fig. 3 is a block diagram of an apparatus in which a memory switching device is located according to an exemplary embodiment of the present disclosure.
Fig. 4 is a block diagram of a memory switching device according to an exemplary embodiment of the present disclosure.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the present specification. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present description as detailed in the accompanying claims.
The terminology used in the description presented herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the description. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, the first information may also be referred to as second information, and similarly, the second information may also be referred to as first information, without departing from the scope of the present description. The word "if" as used herein may be interpreted as "at … …" or "at … …" or "responsive to a determination", depending on the context.
The memory management unit of the os divides the memory according to a set management granularity, and each management granularity may be called a page (page) or a block. In some examples, the computer device may employ a conventional memory management architecture, i.e., the entire memory is managed by the operating system. In other scenarios, for example, in a virtual machine scenario, a computer device may employ a memory allocation architecture of reserved memory, as shown in fig. 1, which is a schematic diagram of a reserved memory scenario according to an exemplary embodiment of the present disclosure, where a memory of a host may include multiple storage spaces, where two storage spaces of the memory are shown in fig. 1 with different filling manners, including unreserved storage space a (with diagonal filling in the drawing) for a kernel, and reserved storage space b (with grid lines filling in the drawing) for a virtual machine. That is, the unreserved storage space a is used for the kernel in the figure, and applications running on the operating system (e.g., application 1 to application 3 illustrated in the figure) can use the unreserved storage space a. The reserved storage space b is available for Virtual Machines (VM), such as VM1 to VMn as shown in the figure. The two storage spaces may be managed with different granularity, i.e. the memory may be partitioned differently. For ease of illustration in fig. 1, two storage spaces are illustrated in a continuous fashion in the figure. It will be appreciated that in practice, the two storage spaces may be non-contiguous. In practical applications, the memory may be divided into more storage spaces to implement more different functions.
The reserved storage space occupies most of the memory and is not available to the host kernel, and a module can be inserted into the kernel of the operating system to be specially used for managing the reserved storage space. In order to facilitate management of the series of memories and avoid occupation of a large amount of metadata on the memories, and considering that when the memories are allocated to the virtual machines, the minimum time is hundreds of MB (megabytes), the reserved storage space is managed by dividing the reserved storage space into Memory blocks (MS) with the size of 2MB, for example; in some scenarios, large granularity is also commonly used, such as 1GB (GigaByte) is optional, and this embodiment is not limited thereto.
When the method is applied to the reserved memory scene, the operating system can adopt different modules to respectively manage the reserved memory space and the unreserved memory space, for example, a reserved memory management module of the operating system manages the reserved memory space, and a memory management module of the kernel manages the unreserved memory space.
Since the physical memory of a computer is limited and the use of memory by processes is uncertain, there is always a possibility that the physical memory will be used up. The operating system adopts memory exchange to solve the problem of insufficient physical memory. The kernel selects the memory block in cold state for releasing, and performs memory block combination, data compression to other memory blocks or swap out to disk, etc. on the data stored in the memory block. And then the memory block is distributed to other more urgent processes for use, and when the original process is used, the data is replaced into a new memory block and is returned to the original process.
The prior art generally uses a least recently used (LRU, least Recently Used) algorithm to determine which memory blocks are released, which scans the most recent usage of each allocated memory block, and the memory blocks that have not been accessed for the most recent period of time are considered cold. However, the above scheme only considers the most recently used condition of the memory block from the dimension of the memory block, and the processing flexibility of the memory swap is poor.
Based on this, in the memory exchange scheme of the embodiment of the present disclosure, the target number of memory blocks that need to be exchanged is determined, and from the view point of the process, the priority of each currently running process is first obtained; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the time of the latest memory block swap-out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the time of the latest memory block swap-in and the current time; because at least one target process is selected according to the priority, and then the memory blocks with the target number are selected from the memory blocks of the at least one target process for memory exchange, the memory exchange scheme of the embodiment can consider each process and stably adjust the memory distribution of the exchange. The following detailed description is given.
Fig. 2A is a schematic diagram of a memory swap method according to an exemplary embodiment of the present disclosure, including the following steps:
in step 202, a target number of memory blocks that require memory swapping is determined.
In step 204, the priorities of the processes currently running are obtained.
Wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks swapped out, or the time difference between the last time the memory block was swapped in and the current time.
In step 206, at least one target process is selected according to the priority, and the memory blocks with the target number are selected from the memory blocks of the at least one target process for memory exchange.
The solution of this embodiment may be applied to any computer device, where the computer device may be a single-core CPU (Central Processing Unit ) device, or may also include a device with multiple physical CPUs, and may employ a non-uniform memory access (Non Uniform Memory Access Architecture, NUMA) architecture according to needs, where the NUMA architecture includes at least two NUMA nodes (NUMA nodes), as shown in fig. 2B, and the host may include a NUMA node 1 and a NUMA node 2, taking two NUMA nodes as an example. Under a NUMA architecture, the host's multiple physical CPUs and multiple memories are subordinate to different NUMA nodes. Each NUMA node includes at least one physical CPU and at least one physical memory, and fig. 2B exemplifies that the NUMA node includes one physical CPU and one physical memory. Within NUMA nodes, the physical CPUs communicate with the physical memory using an integrated memory controller Bus (Integrated Memory Controller Bus, IMC Bus), while NUMA nodes communicate using a fast path interconnect (Quick Path Interconnect, QPI). Because QPI has a higher latency than IMC Bus, the host has a far and near (remote/local) access to memory by the physical CPU. The physical CPU has a faster physical memory access speed to the node, and has a slower physical memory access speed to other NUMA nodes.
In a NUMA architecture scenario, the memory of this embodiment may include any of the physical memories described above. Optionally, any physical memory in the NUMA architecture may also use a reserved memory architecture. Based on this, the storage space managed in this embodiment may also refer to a reserved storage space in any physical memory in the NUMA architecture.
It can be understood that in practical application, the computer device may also adopt other architectures, and according to actual needs, the memory referred to in this embodiment may have various implementation manners according to actual application scenarios, which are not listed here.
The method of the embodiment can be applied to an operating system of any computer device. The reserved memory scenario described above may be applied to a reserved memory management module of an operating system. The method can continuously run after the computer equipment is started, and the decision of memory exchange is continuously carried out; the operation can also be started when needed, for example, the operation can be performed after the start instruction is received, and the start instruction can be initiated by a technician, can be automatically initiated according to a preset rule, and the like.
The process in this embodiment may include any process running in a computer device, such as the aforementioned virtual machine, and the like.
The memory swap of the present embodiment may include various swap methods, such as memory merge (or memory block merge), memory compression (or memory block data compression), and data swap with secondary memory. As an example, the memory merging refers to that after the memory merging module of the operating system is started, the memory block to be released in a cold state is taken out and is initially taken as a candidate memory block; and then, comparing the retrieved memory blocks to be released with data stored in each candidate memory block to determine whether there are combinable memory blocks until the combinable candidate memory blocks are found or the traversal of all the candidate memory blocks is finished. If the combinable candidate memory block is found, the virtual address of the memory block to be released is mapped to the physical address of the found candidate memory block, so that the physical address of the memory block to be released is released. The memory compression refers to compressing data of an original memory block by a compression algorithm and storing the compressed data into a smaller memory block, thereby releasing the original memory block. Exchanging data with the secondary storage means that the data of the memory block is stored in the secondary storage such as a disk, so that the memory block is released, and then taken out from the secondary storage when needed, and stored in the memory block for the process.
The memory exchange in this embodiment includes memory swap-out and memory swap-in, where memory swap-out refers to releasing a memory block allocated to a process and recovering the memory block by a memory management module of an operating system; memory swap-in refers to storing the data of the memory block to the memory block and giving the data to the process when swapping out.
In this embodiment, the priority of the process indicates the priority of the memory block of the process being swapped out. Wherein, in the case of a swap-out, the priority of a process is negatively related to any one of the following information of the process: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; that is, the coldest, least swapped out, and longest un-swapped out processes take precedence.
In the case of a swap-in, the priority of a process is being related to any of the following information for that process: the memory usage activity of the process, the number of memory blocks swapped out, or the time difference between the last time the memory block was swapped in and the current time. That is, the hottest, most swapped out, and longest non-swapped in processes take precedence over the swap-in.
In this embodiment, the memory exchange policy is designed from the dimension of the process during the memory exchange. For the swap-out, the higher the memory usage activity of the process is, the lower the priority of the process for swapping out the memory blocks is, the memory blocks are prevented from being swapped in a short time after being swapped out, the frequency of swapping out and swapping in of the process is reduced, and therefore the processing cost is reduced. The larger the number of the swapped out memory blocks of the process is, the lower the priority is, so that the process with fewer swapped out memory blocks of other memory blocks can be preferentially selected, and the swapped out memory blocks can be uniformly distributed among a plurality of processes. The longer the time from the last swap-out of a process, the higher the priority of the process selected, and the more evenly distributed the swapped-out memory blocks among multiple processes.
And the same principle is changed, the higher the memory use activity of the process is, the more frequently the process uses the memory blocks, and the memory blocks of the process need to be changed in preferentially so as to meet the use requirement of the process. The larger the number of the swapped-out memory blocks of the process is, the higher the priority of the swapped-in memory blocks is, so that the memory blocks of the process can be preferentially selected and timely swapped in, and the use requirement of the process is met. The longer the last time a process is swapped in, the higher the probability that the process accesses a memory block, and therefore the higher the priority that the process is selected to meet the use requirement of the process.
In practical applications, any information may be selected according to the need to determine the priority, for example, only one, or any two or three of the information may be selected, or if two or three of the information are selected, different weights may be set according to the need for the two or three of the information, and the priority may be determined by combining the weights, which is not limited in this embodiment.
In practical applications, the memory usage activity of a process may be determined in a plurality of ways, for example, based on a ratio of a size of a cold state memory of the process to a total memory size occupied by the process, and the memory usage activity and the ratio are in a negative correlation. Based on the method, the memory use activity of the process can be accurately determined through the size of the cold state memory.
In practical application, whether memory exchange is needed or not and the number of the memory exchanges can be determined according to the use condition of the memory. In some examples, whether the memory swap is needed may be determined according to the preset overall swap ratio of the current remaining space and the memory; for example, the determining the target number of memory blocks that need to be swapped includes:
acquiring the current residual space of the memory;
if the proportion of the current residual space to the total size of the memory is lower than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged;
and if the proportion of the current residual space to the total size of the memory is higher than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged.
For example, the preset overall swap ratio in this embodiment represents the ratio of free space in the memory, where the ratio is used to ensure at least the free space required when the computer device starts a new process, for example, the total memory size is M, and the preset overall swap ratio k represents the ratio of memory swap-out required, where the space size obtained by multiplying M by N is the free space of the memory required to be ensured. If N/M is smaller than k, determining that the memory is currently needed to be swapped out, and further determining the target number of memory blocks needed to be swapped out; if N/M is greater than k, it can be determined that memory swap-in is currently required, and further the target number of memory blocks that need swap-in can be determined. The target number of the memory blocks to be swapped out and the target number of the memory blocks to be swapped in can be flexibly configured according to actual needs. For example, both may be preset values, such as a preset number of taps or a preset number of taps, in which case taps or taps may be performed at all times according to a fixed value, reducing processing overhead. Alternatively, a non-fixed value may be set as needed, for example, the target number may be determined based on a difference between the current and the preset overall swap ratio of the memory.
Based on this, the embodiment can monitor the use condition of the memory, and timely perform memory swap-out to make a space, or timely perform memory swap-in to improve the efficiency of using the memory block by the process when the memory is in a relatively idle state.
In some examples, in the case of a swap-out, the determining the target number of memory blocks that need to be swapped out includes:
if the number of the exchanged memory blocks in the memory in the emergency state is smaller than the first exchange number, or the number of the exchanged memory blocks in the non-emergency state is smaller than the second exchange number, determining the target number as the first preset number, otherwise, determining the target number as the second preset number;
wherein the first preset number is greater than the second preset number; the non-emergency state refers to that the current residual space of the memory is larger than a preset size, and the emergency state refers to that the current residual space of the memory is smaller than the preset space.
In this embodiment, two states are set at the time of swap-out: emergency state and non-emergency state, the emergency state shows that the current residual space of the memory is less, and the memory needs to be changed to make the memory space free. The preset size for indicating whether the emergency state is an emergency state can be flexibly configured according to the requirement, and the embodiment does not limit the emergency state; illustratively, the number of memory blocks may be represented, and may be a value of 0, 1, 3, or the like. Through the setting of the two states, different target numbers can be respectively determined so as to meet the memory use requirements under different states. If the number of memory blocks which are in an emergency state and have been swapped out is not too large (smaller than the first swap number), or if the number of memory blocks which are in a non-emergency state and have been swapped out is relatively low (smaller than the second swap number), more memory blocks (the number is the first preset number) can be swapped out.
Otherwise, the second preset number of memory blocks can be swapped out under other conditions; for example, the number of memory blocks that have been swapped out in the emergency state is also larger (larger than the first swap number), which indicates that more memory blocks have been swapped out in the memory; or the number of the exchanged memory blocks is larger than the second exchange number in the non-emergency state, and the exchanged memory blocks are exchanged by a second smaller preset number because the exchanged memory blocks are in the non-emergency state and are exchanged by a certain number currently. Through the embodiment, based on different use states of the memory, different numbers of memory blocks needing to be exchanged can be determined, and memory use requirements in different states can be met.
Optionally, the first exchange number and the second exchange number may be configured as needed, where the first exchange number corresponds to a process in an emergency state, and the second exchange number corresponds to a process in a non-emergency state, and based on this, the first exchange number may be smaller than or equal to the second exchange number.
Optionally, the preset overall swap ratio in this embodiment may correspond to the memory. Alternatively, under a non-NUMA architecture, there may be a preset overall exchange ratio; under the NUMA architecture, the computer device has a plurality of NUMA nodes, each of the NUMA nodes may correspond to a preset overall exchange ratio, and the preset overall exchange ratios corresponding to the respective NUMA nodes may be the same or different. The specific numerical value of the preset integral exchange proportion can be flexibly configured according to the requirement, and the preset integral exchange proportion can represent the proportion of the exchangeable memory size in the memory to the total memory size; the preset overall exchange ratio may be one or more. Taking one example as an illustration, a swap ratio is uniformly used to determine the number of memory blocks that can be swapped. Taking two examples, the two ratios are different in size, the smaller one representing the ratio of memory expected to be swappable and the larger one representing the highest exchangeable ratio of memory. Taking a plurality of examples, each preset integral exchange proportion can be adopted when the memory is in different running states, so that different target numbers are determined.
As an example, the preset overall swap proportion takes three examples, including a first swap proportion, a second swap proportion, and a third swap proportion, where each swap proportion is multiplied by a memory size, i.e., a different number of swappable memory blocks. The first exchange ratio refers to the desired exchange ratio min. The second exchange proportion low is larger than the first exchange proportion min, the second exchange proportion can be set in various modes, taking a virtual machine reserved memory scene as an example, the computer equipment corresponds to the preset number of virtual machines, the second exchange proportion can be set based on the condition that the idle space after memory exchange can meet the condition that the computer equipment can start the last virtual machine, and the memory space required for starting the virtual machine is determined according to actual service needs, and of course, the second exchange proportion can also be other more guaranteed values. The third switching ratio high is used to control the upper limit of the switching ratio, and may be the same as the second switching ratio (in this case, two switching ratios may be set), or may be an ideal value determined according to the operation condition of the computer device.
Based on this, the preset overall swap proportion in this embodiment includes a first swap proportion and a second swap proportion, where the first swap proportion is smaller than the second swap proportion, the first swap number may be determined based on the first swap proportion and the total memory size, and the second swap number may be determined based on the second swap proportion and the total memory size, for example, the swap number may be obtained by multiplying the proportion and the total memory size.
For example, for each NUMA node, determining a current mode according to the number of memory block idles of the NUMA node, where the embodiment takes a general mode and an emergency mode as an example, the emergency mode indicates that the memory is in an emergency state, and the general mode indicates that the memory is in a non-emergency state; for example, a memory block idle number greater than zero in the memory of the NUMA node is a GENERAL mode GENERAL, otherwise it is an emergency mode URGENT.
In this embodiment, if the number of exchanged blocks is smaller than k (k is the number of memory blocks determined by multiplying the first exchange ratio min by the memory size of the node) in the emergency mode urent, or if the number of exchanged blocks is smaller than m (m is the number of memory blocks determined by multiplying the second exchange ratio low by the memory size of the node) in the GENERAL mode GENERAL, a first preset number (e.g. 20) of memory blocks are exchanged at a time; otherwise, only 10 memory blocks are exchanged, and the exchanged values can be optimized according to the service.
The swapped values, i.e. the first preset number and the second preset number, may also be compared with a swap difference value (which refers to the current desired swap-out number minus the number that has been swapped out), taking a small value to prevent the determined number from being larger than the preset upper limit. For example, the currently desired number of exchanges may be calculated in the emergency mode urent at the second exchange rate low, otherwise the exchanged number is calculated at the third exchange rate high.
In practical application, under the condition of swapping in, the number of the swapped-in memory blocks can be determined according to service requirements. Under the condition that the proportion of the current residual space to the total size of the memory is higher than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged, wherein the memory has enough free space at the moment, a fixed value can be set, the embodiment determines the target number of the memory blocks to be exchanged currently as the preset exchange number, the value of the number can be flexibly configured according to actual needs, and the value can be free from adopting larger number, such as 10 memory blocks and the like, so that the exchange process can be stably carried out.
In practical application, there may be one or more selected target processes according to the priority, where the priority of the selected target process is greater than that of other unselected processes, and then the memory blocks of the target number are selected from the memory blocks of the at least one target process to perform memory exchange. Alternatively, one or more target processes may be selected first, and then the memory blocks of the target number may be selected.
In other examples, the selecting at least one target process according to the priority, and selecting the target number of memory blocks from the memory blocks of the at least one target process for memory swap may include:
According to the priority order of each process, taking the process with the highest priority as a target process, and circularly executing the following steps until the execution is stopped, and performing memory exchange on the selected memory blocks:
acquiring the current exchangeable memory block number of the target process, determining whether the current exchangeable memory block number is greater than or equal to the target number, if so, selecting the memory block of the target number from the target process and stopping execution;
if not, selecting the memory blocks with the current exchangeable memory block number, updating the target process into the process with the next priority as the target process, updating the target number into the difference value between the target number and the current exchangeable memory block number, and returning.
In this embodiment, each running process may be ordered according to the priority from high to low. And selecting memory blocks from the process with the highest priority according to the priority of the process until the target number of memory blocks are selected. For example, the determined target number is t, the process p1 with the highest priority is selected for the first time, the memory blocks are selected from the process p1 for memory exchange, the selection can be determined according to the number of exchangeable memory blocks of the process p1, for example, the number d1 of cold state memory blocks of the process is obtained, the sizes of d1 and t are determined, and if d1 is greater than t, the process can be finished by taking out t coldest memory blocks. If d1 is smaller than t, taking out d1 memory blocks in cold state. Then, t-d1 memory blocks are selected, and the steps are executed again for the process p2 of the next priority according to the priority order until t memory blocks are finally taken out for memory block exchange. Through the above embodiment, the number of the memory blocks meeting the current need can be sequentially selected from high to low based on the priority.
The foregoing embodiment may determine the quota of the memory overall exchange in the computer device according to the total memory size of the computer device by the foregoing preset overall exchange ratio, for example, may determine the total number of memory blocks that can be exchanged in the computer device. In this embodiment, the number of memory blocks that can be exchanged by a process is determined by analyzing the situation of each process, and optionally, each process may also correspond to an expected exchange proportion, where the expected exchange proportion of a process is used to represent a proportion of the number of memory blocks that can be exchanged by a process to the total size of the memory of the process. The desired exchange ratio of the processes may be the same or different, or may be changed as needed during execution of the method of the present embodiment.
Under the non-NUMA architecture, memory blocks allocated by the process are all in the same memory, and the process corresponds to an expected exchange proportion. Under the NUMA architecture, memory blocks allocated by a process can be distributed in a plurality of memories under a plurality of NUMA nodes, so that each NUMA node corresponding to the process corresponds to an expected exchange proportion respectively, the expected exchange proportion respectively corresponding to each NUMA node can be the same or different, under the same condition, the management of the memory can be facilitated, and under different conditions, the exchange proportion of the memory under different NUMA nodes can be flexibly set according to the needs. For example, in a virtual machine reserved memory scenario, each virtual machine corresponds to a piece of metadata, where the metadata mmap is a special structure for managing memory information allocated to the virtual machine, the mmap structure records information such as a physical memory range allocated this time, a corresponding virtual address, a process to which the virtual address belongs, and all reserved memories allocated out are placed in a linked list of the mmap structure, and through the structure, functions of searching for the virtual address through the physical address can be realized. Under the NUMA architecture, if the memory allocated to the virtual machine is distributed among a plurality of NUMA nodes, the number of mmap structures of the virtual machine is multiple, each NUMA node where the virtual machine is located corresponds to one mmap, and each mmap corresponds to one expected exchange proportion, namely, each NUMA node corresponds to one expected exchange proportion.
As an example, the expected swap proportion of the process may be the same as the low proportion in the foregoing preset overall swap proportion, for example, the expected swap proportion is set to be the low proportion in the preset overall swap proportion by default, that is, after the memory swap scheme of this embodiment is started, the expected swap proportion is set to be the low proportion first; the low ratio may also change during continuous operation of the computer device, for example, when a change of the upstream scheduling system is received or a technician manually changes the configuration, etc., the embodiment may trigger a desired exchange ratio of the synchronization adjustment process.
In other examples, the desired exchange ratio may also be set in consideration of various policies:
a default policy, wherein the policy indicates that the expected exchange proportion can be determined by an upstream memory total scheduling system, and can be determined by acquiring the service of each process in the computer equipment;
an averaging strategy that represents that the difference between the current desired exchange ratio of each mmap and the low ratio can be automatically averaged to each mmap;
advanced policies that indicate that the current desired exchange proportion for each mmap can be brought as close together as possible to the low proportion.
In practical application, other strategies may be used to set the desired exchange proportion, which is not limited in this embodiment.
Based on the design of the expected exchange proportion of the process, when the memory blocks of the target process are selected for memory exchange aiming at the exchanged target process, the number of exchangeable memory blocks of the target process can be determined according to the expected exchange proportion of the target process, and the memory blocks are selected for memory exchange based on the number of exchangeable memory blocks of the target process. In some examples, to more quickly determine the current number of swappable memory blocks for a process, the process corresponds to a desired swap proportion; in the case of a swap-out, the obtaining the current exchangeable memory block number of the target process includes:
determining the total number of exchangeable memory blocks of the target process according to the total memory size occupied by the target process and the expected exchange proportion;
determining the number of the remaining exchangeable memory blocks of the target process according to the difference between the total number and the number of the exchanged memory blocks of the process;
and acquiring the quantity of the cold state memory blocks of the target process, and taking the smaller value of the quantity of the residual exchangeable memory blocks and the quantity of the cold state memory blocks as the current exchangeable memory block quantity.
The expected exchange proportion of the process in this embodiment may be flexibly configured according to needs, where the expected exchange proportion may represent a proportion of a memory size that may be exchanged in a memory of the process to a total memory size. The total number of exchangeable memory blocks of a process can be determined by multiplying the desired exchange proportion by the total memory size occupied by the process. The remaining number of swappable memory blocks for the target process may be determined by the difference between the total number and the number of swapped memory blocks for the process. And finally, taking the smaller value of the residual exchangeable memory block number and the cold state memory block number as the current exchangeable memory block number based on the cold state memory block number of the process. By the embodiment, the number of the current exchangeable memory blocks of the target process can be accurately and rapidly determined.
In practice, a computer device may employ a NUMA architecture, and thus memory allocated to a process may be distributed among multiple NUMA nodes, based on which, in order to be able to swap memory blocks more reasonably, in some examples, the computer device includes multiple non-uniform memory access NUMA nodes that include at least one memory. In the case where the memory blocks of the target process are distributed among the memories of the plurality of NUMA nodes, the obtaining the current exchangeable memory block number of the target process includes:
acquiring the distribution proportion of the memory blocks of the target process in the memory of each NUMA node, and determining exchangeable memory block quota of the memory of the target process in each NUMA node according to the distribution proportion and the expected exchange proportion of the memory of the target process in each NUMA node;
and determining the number of exchangeable memory blocks of the target process in each NUMA node according to the exchangeable memory block quota of the target process in the memory of each NUMA node.
In this embodiment, when a target process has a plurality of memory blocks that can be exchanged, by analyzing the distribution of the memory blocks of the target process in each NUMA node, determining the exchangeable memory block quota of the process in the memory of each NUMA node based on the distribution proportion of the memory in each NUMA node, so that the exchanged memory blocks of the target process can be uniformly distributed in each NUMA node, and the exchanged memory blocks are prevented from being concentrated in part of the NUMA nodes, thereby affecting the operation of the NUMA nodes.
In practical application, the memory exchange can comprise multiple modes of memory block combination, memory block data compression, data exchange with the secondary memory and the like, and the needed modes can be flexibly selected according to the needs in practical application. In order to improve efficiency of memory swap in, under a swap-out condition, selecting a memory block from memory blocks to which the target process belongs to perform memory swap, including:
after selecting a memory block from memory blocks to which the target process belongs, determining a mode to perform memory exchange by the following method: and performing memory exchange on the selected memory blocks by adopting a memory block merging mode, performing memory exchange by adopting a memory block data compression mode if the selected memory blocks fail to merge the memory blocks, and performing memory exchange by adopting a data exchange mode with the secondary memory if the data compression ratio of the selected memory blocks is higher than a preset compression threshold. When data is compressed, the compression ratio of the compressed data is still larger because of the characteristics of the data in the memory block, the data compression ratio is the ratio of the compressed data to the original data, the better the compression effect is, the smaller the data compression ratio is, and if the data compression ratio is larger, the better promotion is not brought to the use of the memory space, so that the preset compression threshold value can be flexibly set based on the data compression ratio, and whether the data is not compressed but is replaced by adopting a two-level storage mode is determined.
In this embodiment, the priority ranking is performed for the three memory exchange modes, that is, the memory merging is preferentially selected, the memory compression is performed, and finally the memory is exchanged to the secondary memory, where the efficiency of memory exchange is from high to low, and the speed of memory exchange can be improved by the above manner.
An embodiment will be described. The embodiment is described by taking a reserved memory scenario applied to a host as an example, and memory exchange can be performed based on the following multi-level memory exchange policy.
1. First, the overall switching ratio (also referred to as the overall switching water level) of the overall switching architecture may be set.
Taking a computer device comprising multiple NUMA nodes as an example, the overall switching water level can be set per NUMA node, each NUMA node can have a set of identical water level values of min/low/high:
a) min: the desired exchange ratio.
b) low: at least the exchange proportion after integer division operation, and the exchanged idle memory is enough to pull up the last virtual machine; other more guaranteed values are also possible.
c) high: controlling the upper limit of the proportion of the exchange; can be the same as low; or determined based on the operating conditions of the computer device.
Alternatively, each time the low proportion is changed, the expected exchange proportion in each mmap of each virtual machine can be triggered to be synchronously adjusted, and the proportion can be set to be low by default.
The mmap structure of the embodiment is a special structure for managing memory information allocated to a virtual machine, where the information such as the physical memory range allocated this time, the corresponding virtual address, the process to which the virtual address belongs is recorded in the mmap structure, and all allocated reserved memories are placed in a linked list of the mmap structure. In the case where a process is allocated memory for multiple NUMA nodes, for each NUMA node, the process will have a corresponding mmap structure. Each mmap of a process corresponds to a desired swap proportion, and the desired swap proportions of the respective mmaps of the processes may be the same or different.
2. Second, a desired swap proportion per mmap of each Virtual Machine (VM) needs to be set, and the desired swap proportion can be flexibly configured according to needs, for example, can be determined according to a control policy:
a) Default policy: setting an external interface swap_mmap;
the interface can be named as a swap_mmap, is set by an upstream total scheduling system, and determines the proportion according to the service of the virtual machine by the upstream total scheduling system;
b) Average policy: automatically averaging the difference value of the expected swap proportion and the low proportion of each current mmap to each mmap;
c) Advanced strategy: and (5) the expected swap proportion of each mmap at present is closed as much as possible to the low proportion.
In practical application, there may be other control strategies, and this embodiment is not limited thereto. Wherein, if the average policy or the advanced policy is adopted, the swap_mmap interface setting operation can automatically trigger the synchronous adjustment of each mmap.
3. Determining a target number of each exchange:
a) For active handoff, it may be determined according to traffic needs:
i. if the exchange proportion of a mmap of a certain VM is obviously larger than that of other VMs and the exchange proportion of other VMs has an obvious gap from the expected exchange proportion, the memory of the VM which is excessively exchanged is actively exchanged, and the exchange quantity can be configured according to the requirement; for example, it may be performed in a low value, i.e., 10 memory blocks, of the general pattern to smoothly select and adjust the memory distribution of the swap.
For example, in this embodiment, the number of memory blocks swapped in may be determined by the swapped condition of each process. For example, currently, if the swapped proportion of a mmap of a process is significantly greater than the swapped proportion of other processes, the swapped proportion may be the proportion of the swapped memory blocks of a process to the total number of memory blocks expected to be swapped out (the number may be determined by multiplying the expected swap proportion min by the total size of memory), and there is a significant gap between the swapped proportion of other processes and the expected swap proportion, the memory blocks of the process that is excessively swapped out may be actively swapped in, and the number of swapped in may be flexibly configured; for example, 10 memory blocks, etc., to smoothly select and adjust the memory distribution of the swap.
if the monitoring finds that the memory of a certain mmap has frequent swap-out and swap-in, the expected swap number of the mmap is reduced by a certain proportion, such as 5 percent, according to a strategy, the number of the 5 percent is averaged to the mmap of other virtual machines or the home virtual machine, and then the reduced memory block number is actively swapped in.
if some memory specifying a certain mmap is received as unsuitable for swap-out instructions, then the part of memory needs to be actively swapped in. The instruction may be issued by a module upstream in the system.
b) For a swap-out, the target number of each swap may be determined by the mode of each NUMA node:
if not the FORCE mode FORCE (the FORCE mode can be set by the technician, in which case the target number can be specified by the technician, in which case the target number can obtain the user's set instruction, read from the instruction), determine the mode according to the free number of memory blocks of the NUMA node, determine that the free memory blocks are the GENERAL mode GENERAL, otherwise the URGENT mode ugent;
if the GENERAL mode GENERAL is adopted and the number of swapped out swaps is smaller than min, or the mode is larger than the emergency mode GENERAL and the number of swapped out swaps is smaller than low, the number of swapped out 20 memory blocks at a time; otherwise, only 10 memory blocks of the wap are swapped; (actual concrete values can be flexibly configured according to business)
The swapped values may also be compared to the swapped difference (currently expected swapped out number-minus the number that has been swapped out), taking a small value; the number of currently desired swaps is calculated in the emergency mode ugent according to the low water level, otherwise according to the high water level.
4. Then, in the case where there are a plurality of switching methods, it is necessary to select the method of the present switching:
a) For active swap-in, all swap modes are currently traversed directly:
i. performing active swap-in operation on the swap memory conforming to the determination in the previous step;
if the idle memory does not meet the requirement of the active swap-in memory, temporarily recording the requirement, and increasing the quota of the active swap-out, and continuously executing the requirement of suspension when the active swap-in is performed next time;
b) For active switching, the desired switching device is selected, and multiple types of devices exist at present, and the priority can be selected according to the respective characteristics:
i. default merging of memory blocks; for example, selecting zero pages and merging memory blocks of the same page;
secondly, if the combined memory block fails in a large scale, starting a memory compression mode;
and thirdly, finally, if the compression effect of the memory compression mode is not good, starting the disk exchange equipment to support the bottom.
5. Determining the identification pid of the target process of the optimal exchange; selecting an optimal value according to the pid of the candidate VM which needs to be exchanged at the time:
a) Firstly, checking whether each mmap of each VM reaches the proportion of the expected swap, and selecting out the materials which do not reach the proportion;
b) All candidate mmaps are then ordered:
i. for the switching-out, sequencing according to the descending order of the cold and hot modes and the ascending order of the expected swap proportion and the ascending order of the time of the last switching-out; i.e. the coldest, least swapped out, and least recently swapped out processes take precedence;
ii, for the replacement, according to the ascending order of the cold and hot modes and the descending order of the proportion of the expected swaps, the time of the last replacement is ascending order, and the sequencing is carried out; i.e. the hottest, most swapped out, and longest not swapped in processes take precedence;
c) Selecting the pid of the first sequenced mmap;
d) However, additional judgment is needed for the swap-out situation, if the candidate pid is swapped out, but the swap-out quota on the node is full, the next node is directly entered for continuous judgment;
6. finally, selecting the memory blocks to be according to
a) For active swap-in, the swapped-in memory block is directly confirmed according to the requirement combined with the third step:
i. for the third step, the memory blocks are explicitly designated to be replaced, and the memory blocks are directly replaced;
Step ii, for the third step, only the replacement proportion is confirmed, if the replacement time is larger, the memory block which is replaced latest can be replaced; (because the longer the swap-out time, the cooler the possibility that a passive swap-in has not been triggered, the lower the priority may be)
if the swap-out time is almost the same, the memory blocks can be randomly selected according to the proportion for swap-in;
b) For active swap-out, selecting a specific page needing to be swap out from the set of cold page memory blocks:
i. preparing a cold page set (the cold page set comprises all memory blocks in a cold state, the first preparation can be directly satisfied without distinguishing specific process pid, and the second retry can be prepared for pid):
1. firstly checking the number of pages in a cold page set; if yes, the next step is performed, otherwise, the following refreshing is performed;
2. if the scanning quantity is insufficient, forcedly refreshing a hot page set;
3. if not, forcedly moving part of pages of the hot page set to the cold page set;
selecting a first oldest cold page set, and checking whether the memory page corresponding to the process pid selected in the fifth step is selected;
1. if yes, finding;
2. deny, continue with the next;
3. if the end is not found, retrying the process from the last step again, and preparing cold pages for pages of the specific process pid;
if the size of a section of cold page corresponding to one process pid is smaller than the quota of one swap, selecting the cold page from the cold page set for multiple times until the exchange quota is met, or more cold pages corresponding to the pid cannot be found;
7. if the step 6 is completed with all exchange quotas, the step 9 is skipped and the process is finished; otherwise, returning to the step 5, continuing to select the next priority pid;
8. if the step 7 is completed with all exchange quotas, the step 9 is skipped and the process is finished; otherwise, returning to the step 4, continuing to select the next candidate switching device;
9. and finishing the exchange task.
Corresponding to the foregoing embodiments of the memory exchange method, the present disclosure further provides embodiments of the memory exchange device and a computer apparatus to which the memory exchange device is applied.
The embodiments of the memory exchange device in this specification may be applied to a computer device, for example, a server or a terminal device. The apparatus embodiments may be implemented by software, or may be implemented by hardware or a combination of hardware and software. Taking software implementation as an example, the device in a logic sense is formed by reading corresponding computer program instructions in the nonvolatile memory into the memory through a processor of the file processing where the device is located. In terms of hardware, as shown in fig. 3, a hardware structure diagram of a computer device where the memory exchange device in this specification is located is shown in fig. 3, and in addition to the processor 310, the memory 330, the network interface 320, and the nonvolatile memory 340 shown in fig. 3, the computer device where the memory exchange device 331 in this embodiment is located may further include other hardware according to the actual function of the computer device, which is not described herein.
As shown in fig. 4, fig. 4 is a block diagram of a memory exchange device according to an exemplary embodiment of the present disclosure, where the device includes:
a determining module 41 for: determining the target number of memory blocks needing memory exchange;
a priority acquisition module 42 for: acquiring the priority of each currently running process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time;
a switching module 43 for: and selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
In some examples, the selecting at least one target process according to the priority, selecting the target number of memory blocks from the memory blocks of the at least one target process for memory swap includes:
And (3) taking the process with the highest priority as a target process according to the priority sequence of each process, and circularly executing the following steps until the execution is stopped, and performing memory exchange on the selected memory block:
acquiring the current exchangeable memory block number of the target process, determining whether the current exchangeable memory block number is greater than or equal to the target number, if so, selecting the memory block of the target number from the target process and stopping execution;
if not, selecting the memory blocks with the number of the current exchangeable memory blocks, updating the target process to the process with the next priority, updating the target number to the difference value between the target number and the number of the current exchangeable memory blocks, and returning.
In some examples, the process corresponds to a desired exchange ratio; in the case of a swap-out, the obtaining the current exchangeable memory block number of the target process includes:
determining the total number of exchangeable memory blocks of the target process according to the total memory size occupied by the target process and the expected exchange proportion;
determining the number of the remaining exchangeable memory blocks of the target process according to the difference between the total number and the number of the exchanged memory blocks of the process;
And acquiring the quantity of the cold state memory blocks of the target process, and taking the smaller value of the quantity of the residual exchangeable memory blocks and the quantity of the cold state memory blocks as the current exchangeable memory block quantity.
In some examples, the method is applied to a computer device that includes a plurality of non-uniform memory access (NUMA) nodes that include at least one memory;
in the case where the memory blocks of the target process are distributed among the memories of the plurality of NUMA nodes, the obtaining the current exchangeable memory block number of the target process includes:
acquiring the distribution proportion of the memory blocks of the target process in the memory of each NUMA node, and determining exchangeable memory block quota of the memory of the target process in each NUMA node according to the distribution proportion and the expected exchange proportion of the memory of the target process in each NUMA node;
and determining the current exchangeable memory block quantity of the target process in each NUMA node according to the exchangeable memory block quota of the target process in the memory of each NUMA node.
In some examples, the determining the target number of memory blocks for which memory swap is required includes:
Acquiring the current residual space of the memory;
if the proportion of the current residual space to the total size of the memory is lower than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged;
and if the proportion of the current residual space to the total size of the memory is higher than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged.
In some examples, the determining the target number of memory blocks for which memory swap is required includes:
if the number of the exchanged memory blocks in the memory in the emergency state is smaller than the first exchange number, or the number of the exchanged memory blocks in the non-emergency state is smaller than the second exchange number, determining the target number as the first preset number, otherwise, determining the target number as the second preset number;
wherein the first preset number is greater than the second preset number; the non-emergency state refers to the fact that the current residual space of the memory is larger than a preset size, and the emergency state refers to the fact that the current residual space of the memory is smaller than the preset size;
and/or the number of the groups of groups,
the determining the target number of the memory blocks to be swapped in includes:
and determining the target number of the memory blocks which need to be swapped in currently as the preset swap-in number.
In some examples, the memory swap includes the following three modes: merging memory blocks, compressing memory block data and exchanging data with a secondary memory;
under the condition of swapping out, selecting the memory block from the memory blocks to which the target process belongs to perform memory exchange, including:
after selecting a memory block from memory blocks to which the target process belongs, determining a mode to perform memory exchange by the following method: and performing memory exchange on the selected memory blocks by adopting a memory block merging mode, performing memory exchange by adopting a memory block data compression mode if the selected memory blocks fail to merge the memory blocks, and performing memory exchange by adopting a data exchange mode with the secondary memory if the data compression ratio of the selected memory blocks is higher than a preset compression threshold.
In some examples, the memory usage activity of the process is determined based on a ratio of a size of cold state memory of the process to a total memory size occupied by the process, and the memory usage activity is inversely related to the ratio.
The implementation process of the functions and roles of each module in the memory exchange device is specifically shown in the implementation process of the corresponding steps in the memory exchange method, and will not be described herein.
Accordingly, embodiments of the present disclosure also provide a computer program product comprising a computer program which, when executed by a processor, implements the steps of the foregoing memory exchange method embodiments.
Accordingly, the embodiments of the present disclosure further provide a computer device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where the processor implements the steps of the embodiments of the memory exchange method when executing the program.
Accordingly, the present embodiments also provide a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the memory swap method embodiments.
For the device embodiments, reference is made to the description of the method embodiments for the relevant points, since they essentially correspond to the method embodiments. The apparatus embodiments described above are merely illustrative, wherein the modules illustrated as separate components may or may not be physically separate, and the components shown as modules may or may not be physical, i.e., may be located in one place, or may be distributed over a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purposes of the present description. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
The above-described embodiments may be applied to one or more computer devices, which are devices capable of automatically performing numerical calculations and/or information processing according to preset or stored instructions, the hardware of which include, but are not limited to, microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASICs), programmable gate arrays (fields-Programmable Gate Array, FPGAs), digital processors (Digital Signal Processor, DSPs), embedded devices, etc.
The computer device may be any electronic product that can interact with a user in a human-computer manner, such as a personal computer, tablet computer, smart phone, personal digital assistant (Personal Digital Assistant, PDA), game console, interactive internet protocol television (Internet Protocol Television, IPTV), smart wearable device, etc.
The computer device may also include a network device and/or a user device. Wherein the network device includes, but is not limited to, a single network server, a server group composed of a plurality of network servers, or a Cloud based Cloud Computing (Cloud Computing) composed of a large number of hosts or network servers.
The network in which the computer device is located includes, but is not limited to, the internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (Virtual Private Network, VPN), and the like.
The foregoing describes specific embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
The above steps of the methods are divided, for clarity of description, and may be combined into one step or split into multiple steps when implemented, so long as they include the same logic relationship, and they are all within the protection scope of this patent; it is within the scope of this application to add insignificant modifications to the algorithm or flow or introduce insignificant designs, but not to alter the core design of its algorithm and flow.
Where a description of "a specific example", or "some examples", etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present description. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
Other embodiments of the present description will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This specification is intended to cover any variations, uses, or adaptations of the specification following, in general, the principles of the specification and including such departures from the present disclosure as come within known or customary practice within the art to which the specification pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the specification being indicated by the following claims.
It is to be understood that the present description is not limited to the precise arrangements and instrumentalities shown in the drawings, which have been described above, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
The foregoing description of the preferred embodiments is provided for the purpose of illustration only, and is not intended to limit the scope of the disclosure, since any modifications, equivalents, improvements, etc. that fall within the spirit and principles of the disclosure are intended to be included within the scope of the disclosure.
Claims (11)
1. A memory swap method, the method comprising:
determining the target number of memory blocks needing memory exchange;
acquiring the priority of each currently running process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time;
and selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
2. The method of claim 1, wherein selecting at least one target process according to the priority, and selecting the target number of memory blocks from the memory blocks of the at least one target process for memory swap comprises:
According to the priority order of each process, taking the process with the highest priority as a target process, and circularly executing the following steps until the execution is stopped, and performing memory exchange on the selected memory blocks:
acquiring the current exchangeable memory block number of the target process, determining whether the current exchangeable memory block number is greater than or equal to the target number, if so, selecting the memory block of the target number from the target process and stopping execution;
if not, selecting the memory blocks with the number of the current exchangeable memory blocks, updating the target process to the process with the next priority, updating the target number to the difference value between the target number and the number of the current exchangeable memory blocks, and returning.
3. The method of claim 2, the process corresponding to a desired exchange proportion; in the case of a swap-out, the obtaining the current exchangeable memory block number of the target process includes:
determining the total number of exchangeable memory blocks of the target process according to the total memory size occupied by the target process and the expected exchange proportion;
determining the number of the remaining exchangeable memory blocks of the target process according to the difference between the total number and the number of the exchanged memory blocks of the process;
And acquiring the quantity of the cold state memory blocks of the target process, and taking the smaller value of the quantity of the residual exchangeable memory blocks and the quantity of the cold state memory blocks as the current exchangeable memory block quantity.
4. A method as claimed in claim 3, the method being applied to a computer device comprising a plurality of non-uniform memory access, NUMA, nodes comprising at least one memory;
in the case where the memory blocks of the target process are distributed among the memories of the plurality of NUMA nodes, the obtaining the current exchangeable memory block number of the target process includes:
acquiring the distribution proportion of the memory blocks of the target process in the memory of each NUMA node, and determining exchangeable memory block quota of the memory of the target process in each NUMA node according to the distribution proportion and the expected exchange proportion of the memory of the target process in each NUMA node;
and determining the current exchangeable memory block quantity of the target process in each NUMA node according to the exchangeable memory block quota of the target process in the memory of each NUMA node.
5. The method of claim 1, wherein determining the target number of memory blocks for which memory swapping is required comprises:
Acquiring the current residual space of the memory;
if the proportion of the current residual space to the total size of the memory is lower than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged;
and if the proportion of the current residual space to the total size of the memory is higher than the preset integral exchange proportion of the memory, determining the target number of memory blocks to be exchanged.
6. The method of claim 5, wherein determining the target number of memory blocks to swap out comprises:
if the number of the exchanged memory blocks in the current emergency state and the memory is smaller than the first exchange number, or the number of the exchanged memory blocks in the current non-emergency state and the memory is smaller than the second exchange number, determining that the target number of the memory blocks which need to be exchanged currently is the first preset number, otherwise, determining that the target number of the memory blocks which need to be exchanged currently is the second preset number;
wherein the first preset number is greater than the second preset number; the non-emergency state refers to the fact that the current residual space of the memory is larger than a preset size, and the emergency state refers to the fact that the current residual space of the memory is smaller than the preset size;
and/or the number of the groups of groups,
the determining the target number of the memory blocks to be swapped in includes:
And determining the target number of the memory blocks which need to be swapped in currently as the preset swap-in number.
7. The method of claim 1, wherein in the swap-out situation, the memory swap includes three modes: merging memory blocks, compressing memory block data and exchanging data with a secondary memory;
the selecting the memory block from the memory blocks of the target process for memory exchange includes:
after selecting a memory block from memory blocks to which the target process belongs, determining a mode to perform memory exchange by the following method: and performing memory exchange on the selected memory blocks by adopting a memory block merging mode, performing memory exchange by adopting a memory block data compression mode if the selected memory blocks fail to merge the memory blocks, and performing memory exchange by adopting a data exchange mode with the secondary memory if the data compression ratio of the selected memory blocks is higher than a preset compression threshold.
8. The method of claim 1, wherein the memory usage activity of the process is determined based on a ratio of a size of cold state memory of the process to a total memory size occupied by the process, and wherein the memory usage activity is inversely related to the ratio.
9. A memory swap apparatus, the apparatus comprising:
a determining module for: determining the target number of memory blocks needing memory exchange;
an acquisition module for: acquiring the priority of each currently running process; wherein, in the case of a swap-out, the priority is inversely related to any one of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping out and the current time; in case of a swap-in, the priority is positively related to any of the following information: the memory usage activity of the process, the number of memory blocks which are swapped out or the time difference between the last time of memory block swapping-in and the current time;
a switching module for: and selecting at least one target process according to the priority, and selecting the memory blocks with the target number from the memory blocks of the at least one target process for memory exchange.
10. A computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of any of claims 1 to 8.
11. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method of any of claims 1 to 8 when the computer program is executed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310153441.4A CN116204309A (en) | 2023-02-10 | 2023-02-10 | Memory exchange method, memory exchange device, computer equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310153441.4A CN116204309A (en) | 2023-02-10 | 2023-02-10 | Memory exchange method, memory exchange device, computer equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116204309A true CN116204309A (en) | 2023-06-02 |
Family
ID=86516908
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310153441.4A Pending CN116204309A (en) | 2023-02-10 | 2023-02-10 | Memory exchange method, memory exchange device, computer equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116204309A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116680142A (en) * | 2022-11-15 | 2023-09-01 | 荣耀终端有限公司 | Memory resource monitoring method, electronic device, program product and medium |
-
2023
- 2023-02-10 CN CN202310153441.4A patent/CN116204309A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116680142A (en) * | 2022-11-15 | 2023-09-01 | 荣耀终端有限公司 | Memory resource monitoring method, electronic device, program product and medium |
CN116680142B (en) * | 2022-11-15 | 2024-05-07 | 荣耀终端有限公司 | Memory resource monitoring method, electronic device, program product and medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110134514B (en) | Extensible memory object storage system based on heterogeneous memory | |
US10990540B2 (en) | Memory management method and apparatus | |
US10114749B2 (en) | Cache memory system and method for accessing cache line | |
CN107526546B (en) | Spark distributed computing data processing method and system | |
US9430388B2 (en) | Scheduler, multi-core processor system, and scheduling method | |
CN108900626B (en) | Data storage method, device and system in cloud environment | |
CN106372007B (en) | Cache utilization estimation | |
JP5681527B2 (en) | Power control apparatus and power control method | |
CN111813710B (en) | Method and device for avoiding Linux kernel memory fragmentation and computer storage medium | |
CN113778662B (en) | Memory recovery method and device | |
CN110727517A (en) | Memory allocation method and device based on partition design | |
KR101587579B1 (en) | Memory balancing method for virtual system | |
CN111597125B (en) | Wear balancing method and system for index nodes of nonvolatile memory file system | |
CN107341114B (en) | Directory management method, node controller and system | |
CN113590045B (en) | Data hierarchical storage method, device and storage medium | |
US20220206944A1 (en) | Cache allocation method and device, storage medium, and electronic device | |
CN116204309A (en) | Memory exchange method, memory exchange device, computer equipment and storage medium | |
CN109144714A (en) | EMS memory management process and device | |
CN106534308A (en) | Method and device for solving data block access hotspot problem in distributed storage system | |
EP4369191A1 (en) | Memory scanning method and apparatus | |
CN1985245A (en) | Disable write back on atomic reserved line in a small cache system | |
CN115421924A (en) | Memory allocation method, device and equipment | |
EP3249539A1 (en) | Method and device for accessing data visitor directory in multi-core system | |
US9052903B2 (en) | Operating system support for memory power management | |
CN111475099A (en) | Data storage method, device and equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |