Method and apparatus for recording memory state, and computer device and storage medium
By adopting a multi-level array structure and capacity expansion mechanism in memory management, the problem of inappropriate array size caused by changes in memory block state is solved, data replication overhead is reduced, and memory management efficiency is improved.
Patent Information
- Application Number
- PCT/CN2024/088059
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-23
- Filing Date
- 2024-04-16
- Publication Date
- 2024-11-28
AI Technical Summary
In the existing memory management technology, when the hot and cold state of the memory block changes, fixed-sized arrays may become insufficient or too idle, resulting in the need to recreate larger arrays and copy information in the old arrays. The overhead of the copying process is relatively high. big.
Adopt a multi-level array structure, including a first-level array and a second-level array. Each element in the first-level array records the memory address information of the second-level array. When the array is full, create a new first-level array and copy the address information through expansion to avoid Copy the memory block information in the basic elements to achieve array expansion of non-fixed size.
It significantly reduces the data copy overhead during the expansion process and improves the efficiency and flexibility of memory management.
Smart Images

Figure CN2024088059_28112024_PF_FP_ABST
Abstract
Description
Method, device, computer equipment and storage medium for recording memory status
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on May 23, 2023, with application number 202310595047.6 and invention name “Method, device, computer equipment and storage medium for recording memory status”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present disclosure relates to the field of memory management technology, and in particular to a method, apparatus, computer equipment, and storage medium for recording memory status. Background Art
[0003] In the field of memory management, the operating system's memory management module has a memory block hot and cold state scanning function. This function scans the hot and cold state information of each allocated memory block and records it; for example, the information of each cold state memory block is recorded in a cold state set, and the information of each hot state memory block is recorded in a hot state set. These sets can be used by subsequent processes such as memory swapping.
[0004] In related technologies, a fixed-size array is typically created for each state, with each element in the array used to record information about one or more contiguous memory blocks in that state. A limitation of this approach is that the hot and cold states of memory blocks fluctuate, and the fixed-size array may become insufficient or completely idle. In this case, a larger array must be created and the information recorded by each element in the old array must be copied to the new array, which incurs significant overhead.
[0005] Summary of the Invention
[0006] To overcome the problems existing in the related art, the present disclosure provides a method, apparatus, computer device and storage medium for recording memory status.
[0007] According to a first aspect of an embodiment of the present application, a method for recording a memory state is provided, the method being used to record, through an array, information of a memory block in a state corresponding to the array;
[0008] The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, the primary element records the memory address information of the secondary array, and the secondary array includes at least one basic element, the basic element is used to record memory block information;
[0009] The method comprises:
[0010] When it is necessary to record the target memory block information into the free basic elements of the array, if it is determined that there are no free basic elements in the array, the following expansion steps are performed:
[0011] Create a new first-level array, copy the memory address information recorded by each first-level element in the current first-level array to the first-level element of the new first-level array, and release the current first-level array; wherein the number of first-level elements in the new first-level array is greater than the number of first-level elements in the current first-level array;
[0012] Creating a new secondary array, and recording the memory address information of the new secondary array into the idle primary elements of the new primary array;
[0013] The target memory block information is recorded in the free basic elements of the new secondary array.
[0014] According to a second aspect of an embodiment of the present application, there is provided a device for recording a memory state, the device being configured to record, through an array, information of memory blocks in a state corresponding to the array;
[0015] The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, the primary element records the memory address information of the secondary array, and the secondary array includes at least one basic element, the basic element is used to record memory block information;
[0016] The device comprises:
[0017] a determination module configured to trigger a capacity expansion module if it is determined that no free basic elements exist in the array when it is necessary to record target memory block information into the free basic elements of the array;
[0018] Expansion module, used for:
[0019] Create a new first-level array, copy the memory address information recorded by each first-level element in the current first-level array to the first-level element of the new first-level array, and release the current first-level array; wherein the number of first-level elements in the new first-level array is greater than the number of first-level elements in the current first-level array;
[0020] Creating a new secondary array, and recording the memory address information of the new secondary array into the idle primary elements of the new primary array;
[0021] The target memory block information is recorded in the free basic elements of the new secondary array.
[0022] According to a third aspect of an embodiment of the present application, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the method embodiment described in the first aspect are implemented.
[0023] According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method embodiment described in the first aspect are implemented.
[0024] The technical solutions provided by the embodiments of the present application may have the following beneficial effects:
[0025] In the embodiment of the present application, a multi-level array structure is designed. The top layer is a first-level array, which includes at least one first-level element. Each first-level element is used to store the memory address information of the second-level array corresponding to the element, that is, each first-level element points to a second-level array; each second-level array includes at least one basic element. Each second-level array can be understood as a collection of basic elements it includes. The basic elements at the bottom are used to record memory block information. Therefore, the solution of this embodiment can be used to realize an array of non-fixed size, and the capacity can be expanded when the basic elements in the array are used up. When expanding, a new first-level array is created. Based on the array structure designed in this embodiment, since the first-level elements in the old first-level array store the address information of the second-level array, it is only necessary to copy the address information stored in the first-level elements to the new first-level array, without copying the memory block information stored in the basic elements, thus avoiding the copying of large amounts of data and significantly reducing overhead.
[0026] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present disclosure.
[0028] FIG1A is a schematic diagram illustrating a reserved memory scenario according to an exemplary embodiment of the present application.
[0029] FIG1B is a schematic diagram of another reserved memory scenario according to an exemplary embodiment of the present application.
[0030] FIG2A is a flowchart of a method for recording memory status according to an exemplary embodiment of the present application.
[0031] FIG2B is a schematic diagram of a NUMA architecture according to an exemplary embodiment of the present application.
[0032] FIG2C is a schematic diagram of array expansion according to an exemplary embodiment of the present application.
[0033] FIG3 is a block diagram of a device where an apparatus for recording memory status is located according to an exemplary embodiment of the present application.
[0034] FIG4 is a block diagram of a device for recording memory status according to an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0035] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0036] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. As used in this application and the appended claims, the singular forms "a," "an," "the," and "the" are intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
[0037] It should be understood that although the terms first, second, third, etc. may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0038] 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, stored data, displayed data, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0039] The memory management module of the operating system divides the memory according to the set management granularity, where each management granularity can be called a page or a block. In some examples, the computer device can adopt a traditional memory management architecture, that is, the operating system manages the entire memory. In other scenarios, such as the virtual machine scenario, the computer device can adopt a memory allocation architecture of reserved memory. As shown in Figure 1A, it is a schematic diagram of an exemplary reserved memory scenario shown in this application. In this architecture, the host machine's memory can include multiple storage spaces. As shown in Figure 1A, two of the storage spaces in the memory are shown in different filling methods, including a non-reserved storage space a for use by the kernel (filled with diagonal lines in the figure), and a reserved storage space b for use by the virtual machine (filled with grid lines in the figure). That is, the non-reserved storage space a is used for use by the kernel in the figure, and the kernel's division granularity of this storage space is usually small, such as 4KB (Kilobyte); applications running on the operating system (such as applications 1 to 3 in the example in the figure) can use this non-reserved storage space a. The reserved storage space b is available for use by virtual machines (VMs), such as the n virtual machines shown in the figure, VM1 through VMn. The two storage spaces can use different management granularities, meaning the memory can be divided differently. For ease of illustration, the two storage spaces are shown as continuous in Figure 1A. It is understood that in actual applications, the two storage spaces can be discontinuous. In actual applications, more storage spaces can be divided within the memory to implement a wider range of functions.
[0040] The reserved storage space occupies a large portion of the memory and is unavailable to the host kernel. Therefore, a module can be inserted into the operating system kernel to manage the reserved storage space. To facilitate the management of this range of memory while avoiding the large amount of metadata occupying the memory, and considering that memory allocation to virtual machines often starts at at least hundreds of megabytes (MB), the reserved storage space is divided into larger granularity, such as dividing the reserved storage space into memory sections (MS) of 2MB for management. In some scenarios, larger granularity is also commonly used, such as 1GB (Gigabyte), which is optional and is not limited in this embodiment.
[0041] The memory management module in the operating system is used to manage memory. When applied to the reserved memory scenario, the operating system can use different memory management modules to manage the reserved storage space and the unreserved storage space respectively. For example, the reserved memory management module of the operating system manages the reserved storage space, and the kernel memory management module manages the unreserved storage space.
[0042] Because a computer's physical memory is limited and a process's memory usage is uncertain, there's always the possibility of running out of physical memory. Operating systems use memory swapping to address this issue. The kernel selects cold memory blocks for release, merging the data stored in those blocks, compressing them into other blocks, or swapping them out to disk. The memory blocks are then allocated to more urgent processes. When the original process needs them again, the data is swapped into new blocks and returned to the original process.
[0043] The memory management module scans the hot and cold states of the allocated memory blocks. Specifically, the memory management module can continuously obtain information such as the time or frequency of each memory block being accessed by the process to determine the hot and cold states of the memory blocks. The hot state (active) means that the memory block has been recently accessed by the process, and the cold state (inactive) means that the memory block has not been recently accessed by the process. The memory management module will record each memory block in a hot state through a hot page set, and each memory block in a cold state through a cold page set. The cold page set records a set of memory blocks that have not been accessed recently. When memory is tight, this part of the memory blocks can be migrated to the secondary storage to free up more memory for active virtual machines.
[0044] As shown in FIG1B , this is a schematic diagram of a reserved memory scenario according to an exemplary embodiment of the present application. The figure shows various data stored in the memory, such as an area of user space, where the user space refers to the memory area allocated by the operating system to each user program for storing the data and code required by the user program (such as the n virtual machines shown in the figure) during execution. The figure also shows an area for kernel use, which can include a KVM (Kernel-based Virtual Machine) for managing virtual machines and at least one NUMA (Non Uniform Memory Access Architecture) node within the kernel space. The figure takes two nodes (Node0 and Node 1) as an example.
[0045] The figure also shows the reserved memory area in the memory. This embodiment takes Linux (an operating system) as an example, where "vem.ko" is a module in the Linux kernel that is used to manage virtual machines. The module also includes the " / dev / vmem" module and the "vmem_mm_x.ko" module, both of which represent the virtual memory module in Linux. The " / dev / vmem" module points to "cdev.ops", which is a structure variable in the character device driver in Linux. It contains the function address of the character device operation. Metadata is connected to the " / dev / vmem" module, such as the "**mm" and "nobjs" fields shown in the figure. Metadata for managing each node is linked to this metadata, including fields such as "**ms", "mmap" and "Lru". Among them, the "mmap" field is used to link metadata for recording the allocation status of each memory block in the reserved memory area, and the metadata connected to the "Lru" field contains various control fields for the overall aging function, as well as the hot and cold node structure of each node.
[0046] Each node has metadata, such as the metadata for node0 and node1 in the diagram. Each node also includes metadata for various memory block states, such as the metadata for active and inactive states in the diagram. For example, the metadata for the active state includes the starting memory block number (idx), size (size), process ID, and the next field, which points to the next memory range. The same applies to the metadata for the inactive state.
[0047] For each state of a memory block, the memory management module can create a fixed-size array, where each element in the array is used to record information about one or more contiguous memory blocks in that state. The limitation of the above solution is that the hot and cold states of memory blocks are constantly changing, and the fixed-size array may become insufficient or may become completely idle. In this case, a larger array must be created and the information recorded by each element in the old array must be copied to the new array, which is a very costly process.
[0048] Based on this, an embodiment of the present application provides a solution for recording memory status information, as shown in FIG2A . FIG2A is a flowchart of a method for recording memory status according to an exemplary embodiment of the present application. The method of this embodiment is used to record memory block information in a state corresponding to the array through an array. The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, each of the primary elements records the memory address information of a secondary array, and the secondary array includes at least one basic element, and the basic element is used to record memory block information.
[0049] The method may include the following steps:
[0050] In step 202, when it is necessary to record the target memory block information into the free basic elements of the array, if it is determined that there are no free basic elements in the array, the expansion step is performed:
[0051] In step 204, a new first-level array is created, the memory address information recorded in each first-level element in the current first-level array of the array is copied to the first-level element of the new first-level array, and the current first-level array is released.
[0052] The number of first-level elements in the new first-level array is greater than the number of first-level elements in the current first-level array.
[0053] In step 206, a new secondary array is created, and the memory address information of the new secondary array is recorded in the idle primary elements of the new primary array.
[0054] In step 208, the target memory block information is recorded into the free basic elements of the new secondary array.
[0055] The solution of this embodiment can be applied to any computer device. The computer device can be a single-core CPU (Central Processing Unit) device or a device including multiple physical CPUs. A non-uniform memory access architecture (NUMA) architecture can be adopted as needed. The NUMA architecture includes at least two NUMA nodes. As shown in FIG2B , taking two NUMA nodes as an example, the host machine can include NUMA node 1 and NUMA node 2. Under the NUMA architecture, the multiple physical CPUs and multiple memories of the host machine belong to different NUMA nodes. Each NUMA node includes at least one physical CPU and at least one physical memory. FIG2B takes the example of a NUMA node including one physical CPU and one physical memory. Within the NUMA node, the physical CPU and the physical memory communicate using an integrated memory controller bus (IMC Bus), while the NUMA nodes communicate using a Quick Path Interconnect (QPI). Because the latency of the QPI is higher than that of the IMC Bus, the physical CPUs on the host machine have different access distances (remote / local) to the memory. The physical CPU has a faster access speed to the physical memory of the local node, but has a slower access speed to the physical memory of other NUMA nodes.
[0056] In a NUMA architecture scenario, the memory of this embodiment may include any of the aforementioned physical memories. Optionally, any of the physical memories in the NUMA architecture may also employ a reserved memory architecture. Based on this, the storage space managed by this embodiment may also refer to the reserved storage space in any of the physical memories in the NUMA architecture.
[0057] It is understandable that in actual applications, computer devices can also adopt other architectures. According to actual needs, the memory referred to in this embodiment can be implemented in multiple ways according to actual application scenarios, which will not be listed one by one here.
[0058] The method of this embodiment can be applied to any memory management module of the operating system of any computer device. For example, in the aforementioned reserved memory scenario, it can be applied to the reserved memory management module of the operating system.
[0059] In actual applications, the memory management module can create multiple arrays of different types, and memory block information in different states is recorded in different types of arrays. The states here can be configured according to actual needs, and as examples may include: active state, inactive state, paused state or pinned state, etc. Optionally, each state can also be graded as needed, with each level corresponding to an array. The memory block information recorded under each array forms a set. Each array can be managed using the method of this embodiment.
[0060] In NUMA scenarios, each NUMA node has a corresponding memory array. Each node also has a series of different sets of arrays. Each node can create a structure called node to manage its arrays. These memory sets form a node structure. Alternatively, the higher-level structure called lru can be used to manage the node structures under each NUMA node.
[0061] This embodiment designs a multi-level array structure. The top layer is a primary array, which includes at least one primary element (the number can be configured as needed). Each primary element is used to store the address pointer (i.e., the memory address information of the secondary array) of the corresponding secondary array. In other words, each primary element points to a secondary array. Each secondary array includes at least one basic element. Each secondary array can be understood as a collection of basic elements. The basic elements at the bottom layer are used to record memory block information. Utilizing the solution of this embodiment, an array of variable size can be implemented, which can be expanded when the basic elements in the array are used up. When expanding, a new primary array is created. Based on the array structure designed in this embodiment, since the primary elements in the old primary array store the address information of the secondary array, only the address information stored in the primary elements can be copied to the new primary array, eliminating the need to copy the memory block information stored in the basic elements. This avoids copying large amounts of data and significantly reduces overhead. After the primary array is expanded, the number of primary elements in the new primary array increases, so a new secondary array can be created. Free basic elements can be obtained from the new secondary array, and the target memory block information can be recorded in these free basic elements.
[0062] As shown in Figure 2C, the first-level array in the figure includes three first-level elements, each storing three addresses: Address A, Address B, and Address C. These respectively represent the addresses of the three created second-level arrays (second-level array A, second-level array B, and second-level array C) in memory. Each second-level array is taken as an example to include 10 basic elements oarr_item. In actual applications, the number of basic elements in each second-level array can be different, and this embodiment does not limit this. If all basic elements have been recorded, the first-level array is full and there are no free basic elements. The solution of this embodiment can be used to expand the capacity of the expanded first-level array. Here, the new first-level array after expansion has one more first-level element than the old first-level array. In actual applications, the number of first-level elements added to the new first-level array relative to the old first-level array can be flexibly configured as needed, and this embodiment does not limit this. Since the first-level elements store the address information of the second-level array, only the three addresses stored in the old first-level array need to be copied to the new first-level array, without copying the memory block information stored in each basic element. This avoids copying large amounts of data and can significantly reduce overhead. The new first-level array adds a first-level element, so more second-level arrays can be created to obtain more basic elements. As shown in the figure, a new second-level array D is created, and the address information of the second-level array D in the memory (that is, address D in the figure) can be written to the added first-level element in the first-level array.
[0063] In some examples, the method further includes: if it is determined that there are free basic elements in the array, recording the target memory block information in the free basic elements. Through this embodiment, when there are still free basic elements in the array, the free basic elements can be used to record the target memory block information.
[0064] In some examples, whether there are free basic elements in the array is determined as follows:
[0065] Determining whether a secondary array in the array has free basic elements;
[0066] If yes, determine whether there is an idle basic element in the array; if not, determine whether there is an idle first-level element in the first-level array of the array;
[0067] If there is an idle first-level element, a new second-level array is created, and after recording the memory address information in the idle first-level element, it is determined whether there is an idle basic element;
[0068] If there is no idle first-level element, it is determined that there is no idle basic element in the array.
[0069] Through this embodiment, it can be determined whether the first-level elements of the first-level array are full. If not, the second-level array can be expanded first. If the first-level elements are full, the first-level array can be expanded again.
[0070] In some examples, the memory management module can manage the entire array by creating array metadata (i.e., a structure). The array metadata can be designed with one or more fields as needed to record various array information. The fields here can be configured as needed. In this embodiment, basic elements are used to record memory block information. In this embodiment, basic elements that do not record information are referred to as free basic elements, and basic elements that record information are referred to as recorded basic elements. An array is a linear table data structure that occupies continuous memory space in memory. Each element in the array is stored sequentially and numbered in the same order as the elements are stored. For example, an array consisting of five elements is created, and each element is stored sequentially in memory, numbered from 0 to 4. In this embodiment, the memory management module creates array metadata for recording the array information during initialization. The array metadata includes: a header field for pointing to the first recorded basic element; the fields of the basic element include: a next field, the initial value of which is an idle flag indicating that the basic element is a free basic element; when the basic element changes from a free basic element to a recorded basic element, the next field is used to point to the next recorded basic element of the basic element or to itself. Through the above embodiment, the link relationship between recorded basic elements can be recorded in the array, facilitating subsequent updates of basic elements. For example, after recording the target memory block information into the idle basic element, the method may further include updating the next field of the recorded idle basic element. Based on this, the recorded basic elements can be linked together in the above manner, facilitating subsequent use.
[0071] Optionally, all basic elements in all secondary arrays can be numbered, so that all basic elements in the entire array have their own numbers, and the head field and the next field can both record the numbers of the basic elements.
[0072] In the hot and cold state scenario, the next field of the target basic element that records the target memory block information can be updated in the following way:
[0073] If the header field does not point to the first recorded basic element, update the header field to point to the target basic element, and update the next field of the target basic element to point to itself;
[0074] If the header field points to the first recorded basic element, find the last recorded basic element pointing to itself according to the header field, update the next field of the last recorded basic element pointing to itself to point to the target basic element, and update the next field of the target basic element to point to itself.
[0075] In this embodiment, the array is used to record the state of the memory block. In this embodiment, each recorded basic element can be managed in a disordered manner, that is, each recorded basic element under the array is disordered. The disorder here means that the basic element includes a next field. For the recorded basic element, the next field is used to point to the next recorded basic element, so that each recorded basic element is connected in a specific order. Among them, the head field in the array structure is used to point to the first recorded basic element. Based on this, the recording of hot and cold memory blocks can be realized. The basic elements of the newly inserted data will be inserted from the tail position, so that the older memory blocks are at the head and the newer memory blocks are at the tail. Therefore, for the cold state set, the memory block closer to the head is colder; for the hot state set, the memory block closer to the tail is hotter. When performing a memory swap operation, it is only necessary to retrieve the memory block information from the head of the cold state set and release the corresponding basic element.
[0076] For example, when the memory management module is initialized, an array structure for managing an array can be created, in which the head field does not yet point to any basic element. For example, the initial value of the head field can be empty or an idle mark, etc., to indicate that it does not point to a basic element. The initialization values of other fields can be configured accordingly. A first-level array (including olen first-level elements) and a second-level array (including len basic elements, such as basic element [0] to basic element [len-1]) are created. In actual applications, multiple second-level arrays are also optional, and this embodiment does not limit this. The first first-level element stores the address pointer of the second-level array, and the other first-level elements are idle elements. The initial value of the next field of each basic element is an idle mark indicating that the basic element is an idle element. At this time, all basic elements are idle elements. After completing the initialization, the memory management module can write memory block information to the idle basic elements in the array when needed. Through the above embodiment, a smaller array can be created during initialization to reduce the occupation of memory space.
[0077] Taking the cold state set as an example, the memory management module scans a memory range that belongs to the cold state. The memory range refers to a total of 3 memory blocks from memory block idx_A to memory block idx_C. In some examples, the memory block information recorded by the basic element includes: memory range information represented by the starting memory block number and the number of memory blocks; based on this, the memory range information range (starting memory block number idx_A and memory block number size3) can be written to one of the free basic elements. In some examples, if it is determined that there are free basic elements in the array, the target memory block information is recorded in the free basic element. This embodiment does not limit the selection method of the free basic element. For example, the basic element [0] is selected to record the above-mentioned memory range information. Optionally, the process pid_p to which these memory blocks belong can also be recorded. Since the basic element [0] is changed to a recorded basic element after the information is written, the head field of the array structure is updated to point to the basic element [0]. Since there is only one recorded basic element at present, the next field of basic element [0] is updated from the idle mark to point to itself, for example, updated to the number of its own basic element, thereby indicating that basic element [0] is not idle, and also indicating that it is the last recorded basic element in the array.
[0078] The memory management module continues to scan, obtains the next cold state memory range, and uses the idle basic element [1] to record it. After recording, the basic element [1] is inserted into the tail of the array (this embodiment is referred to as the insertion of the basic element, that is, a new recorded basic element is obtained and inserted into the link of the recorded basic element in the array); specifically, it can be traversed from the head field of the array structure. Since the head points to the basic element [0], and the next of the basic element [0] points to itself, it can be determined that it has reached the tail of the array, and the next field of the basic element [0] is modified to point to the basic element [1], and the next field of the basic element [1] is modified to point to itself.
[0079] Assuming that the memory management module continuously scans cold memory blocks and continuously writes memory block information into the array, and assuming that no recorded basic elements are released during this stage, the record R1 of the current array can be expressed as follows to represent the links formed by the recorded basic elements:
[0080] head→next of basic element [0]→next of basic element [1]→…basic element [len-1]; next of basic element [len-1] points to itself; wherein, the link relationship between the basic elements here is exactly the same as the numbering order of the basic elements. This is only an example. In actual application, as mentioned in the above embodiment, the "numbers" in the link relationship of each recorded basic element can be out of order.
[0081] At this point, all free basic elements have been used up. The memory management module continues scanning and needs to use free basic elements to store memory block information. Since there are still olen-1 free first-level elements in the first-level array, a second second-level array can be created and the address information can be stored in the second first-level element in the first-level array. And so on. For example, if there are 2*len basic elements, and the current array record R2 is:
[0082] head → next of basic element [0] → next of basic element [1] → ... basic element [len-1] → basic element [len] → ... basic element [2len]; next of basic element [2len] points to itself.
[0083] In actual applications, the recorded basic element may be released. Optionally, the method further includes: determining that the first recorded basic element needs to be changed to an idle basic element, and performing the following steps:
[0084] If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, the next field of the previous basic element pointing to the first recorded basic element is updated to the basic element pointed to by the next field of the first recorded basic element;
[0085] If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element points to itself, update the next field of the previous basic element pointing to the first recorded basic element to point to itself;
[0086] If the header field points to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, updating the header field to point to the basic element pointed to by the next field of the first recorded basic element;
[0087] If the header field points to the first recorded basic element and the next field of the first recorded basic element points to itself, when the current first-level array has been expanded, the following shrinking process is executed: a shrunken first-level array is created to replace the current first-level array; wherein, the number of first-level elements in the shrunken first-level array is less than the number of first-level elements in the current first-level array.
[0088] There are many ways to create a reduced first-level array to replace the current first-level array. For example, a new reduced first-level array can be created and the current first-level array can be released. Alternatively, the first-level elements can be directly deleted from the current first-level array, and the new first-level array obtained after the deletion is used to replace the first-level array before deletion.
[0089] For the aforementioned array record R2, if the memory swap function of the memory management module determines that a cold memory block needs to be swapped out, the head field of the array structure can be used to take it out, because the coldest memory block is at the head of the array. According to the basic element [0] pointed to by the head, the memory range information (the starting memory block number idx_A and the number of memory blocks size3) recorded in the basic element [0] can be used. Assuming that only one memory block is taken out each time, for example, only the memory block idx_A is taken out, the memory range information recorded in the basic element [0] is updated to the starting memory block number idx_B and the number of memory blocks size2. Assuming that all three memory blocks are taken out, the basic element [0] is released and changed to an idle basic element. It needs to be deleted from the link of the recorded basic elements. Specifically, the head field is updated to point to the next of the basic element [0], that is, the head is updated to point to the basic element [1], that is, the record in the array is updated to the following record R3:
[0090] head → next of basic element [1] → ... basic element [len-1] → basic element [len] → ... basic element [2len]; next of basic element [2len] points to itself.
[0091] The release of recorded basic elements is triggered by memory swapping. In practice, there are other occasions when recorded basic elements are released. For example, if a cold memory block originally recorded in an array changes to a hot state due to access by a process, the record must be removed from the cold state set. Alternatively, if a process terminates and the memory block allocated to it is reclaimed, the cold memory block recorded in the array must be removed from the array. The same applies to hot state arrays.
[0092] When it is determined that the target memory block information needs to be written into the array, it is possible to overwrite the target memory block information by updating the recorded basic elements in the array without allocating a new free basic element for recording. For example, in some examples, determining that the target memory block information needs to be written into the free basic elements in the array may include:
[0093] Traversing the memory range information of each recorded basic element record in the array;
[0094] If the number of the target memory block is not adjacent to each of the recorded memory range information, it is determined that the information of the target memory block needs to be recorded into the idle basic element of the array.
[0095] For example, assuming the target memory block information is idxK, the memory range recorded by any recorded basic element in the array is not adjacent to idxK, so a free basic element is needed to record it. In this embodiment, only when the target memory block number is not adjacent to any of the recorded memory range information is a new free basic element allocated for recording, which can reduce memory usage.
[0096] In other examples, the method may also include: if the number of the target memory block is adjacent to the target memory range information, modifying the number of memory blocks recorded in the basic element recording the target memory range information so that the modified target memory range information covers the target memory block.
[0097] For example, assuming that the target memory block information is idxK, the memory range of a certain recorded basic element in the array is (idx1, 2), i.e. the scope of 2 memory block sizes starting from idx1, because idxK is adjacent to this scope (after this scope), therefore, update the memory range information of this recorded basic element so that it covers idxK. For example, the memory range information of this basic element is updated to (idx1, 3). By the present embodiment, the recorded basic element can be utilized to record the memory block information of current required record, and the occupancy of internal memory can be reduced. Optionally, the recorded basic element may further include a process identification field pid, which is used to indicate the process to which the memory range belongs. If the memory range recorded in a basic element covers multiple memory blocks, then these multiple memory blocks belong to the same process; when recording the number of the target memory block in the array, if the number of the target memory block is adjacent to the target memory range information, it can also be that the target memory block and the target memory range information belong to the same process; if they do not belong to the same process, the target memory block can also be recorded using a new basic element instead of being recorded in the same basic element as the target memory range; that is, the memory blocks of different processes are not recorded in the same basic element, so that the memory blocks of different processes can be distinguished.
[0098] In actual applications, memory block information may be deleted. For example, the hot or cold state of a memory block may change, or the process containing the memory block may be released, or a cold memory block may be swapped out. Based on this, the memory range to be deleted is determined, and each recorded basic element of the array is traversed to determine the second recorded basic element corresponding to the memory range to be deleted. For example, the memory range to be deleted is two consecutive memory blocks from idxK to idxL. It is possible to determine which recorded basic element in the array covers the memory range to be deleted, and determine different deletion methods based on different situations.
[0099] (1) When the memory range to be deleted is the same as the recorded memory range recorded by the second recorded basic element, it is determined that the second recorded basic element is changed to an idle basic element, that is, the second recorded basic element is directly deleted; the update of the header field and the next field after deletion can be seen in the above embodiment.
[0100] (2) When the memory range to be deleted is different from the recorded memory range:
[0101] ① If the memory range to be deleted is located in the middle of the recorded memory range, the recorded memory range is divided into a front part before the memory range to be deleted, a part of the memory range to be deleted, and a back part after the memory range to be deleted according to the memory range to be deleted, and the memory range information recorded by the second recorded basic element is updated to represent the front part, and after obtaining the free basic element record for representing the memory range information of the back part, it is linked to the back of the second recorded basic element. For example, if the range to be deleted is idxK to idxL, and the recorded memory range is idxH to idxN, it is divided into idxH to idxK, idxK to idxL, and idxL to idxN; idxK to idxL are deleted, and the second recorded basic element is updated to record idxH to idxK, and a new free basic element is allocated to record idxL to idxN, and it is linked to the second recorded basic element.
[0102] ② If one of the boundaries of the memory range to be deleted is the same as a boundary of the recorded memory range, the memory range information recorded in the second recorded basic element is updated to include the difference between the memory range to be deleted and the recorded memory range. For example, if the range to be deleted is idxK to idxL, and the recorded memory range is idxK to idxN, the second recorded basic element is updated to record idxL to idxN.
[0103] Next, the following examples will be used to illustrate.
[0104] (1) Example of a dynamically scalable out-of-order array
[0105] This embodiment can be applied to a memory management module, specifically to a hot / cold scanning function; the hot / cold scanning function module can create one or more structures oarray for recording memory block sets in various states; for example,
[0106] 1. In this embodiment, the element of the array is called oarr_item, and the fields of the element include:
[0107] The next field is used to point to the position of the next element in the entire array;
[0108] Memory range information field, which may include idx information and size information, i.e., it is used to record the number idx of the starting memory block of the memory range and the size of the memory blocks contained in the memory range. A memory range can be determined by idx and size;
[0109] The reserved field data is optional and should be configured as needed in actual applications. This field can be used for subsequent expansion; that is, when subsequent expansion is needed, new fields can be added starting from the data position to record the aforementioned pid and other information.
[0110] 2. On the upper layer of oarr_item is an array oarr_items of a preset size. Each array contains ilen oarr_items, which is called a secondary array in this embodiment.
[0111] If an oarr_items is full, you can apply for new oarr_items and mount them in the first-level array mentioned later.
[0112] 3. Above the secondary array oarr_items is the primary array oarr_array;
[0113] The first-level array is an array of pointers to each second-level array oarr_items; that is, each element in the first-level array is used to store the address pointer of the second-level array corresponding to the element;
[0114] The size of the first-level array is alen (the original unexpanded length is olen), which is the number of first-level elements in the first-level array; the number of used elements is anum; the used part means that the array element has been assigned an address pointing to the second-level array oarr_items;
[0115] If the first-level array is full, the capacity of oarr_array can be expanded (for example, by a multiple of twice, which is not limited in this embodiment), and the contents of the old first-level array are copied to the new array in sequence; this avoids copying a large amount of out-of-order array data;
[0116] All oarr_items in the oarr_items array will be sorted in order. The total number of basic elements in the array is len, and the number of used elements is num. The next of each oarr_item will be initialized to a special value of ITEM_FREE, which is an idle mark. If it is this value, it means that the item is free, otherwise it has been used.
[0117] The oarray structure can record any array information. For example, it can include the aforementioned primary array fields, the original unexpanded length olen, the number of used primary elements anum, the total number of basic elements len, and the number of used basic elements num. In addition, the structure has a head field, which points to the sequence number of the first oarr_item in the entire array.
[0118] 4. This embodiment provides the following insert function for inserting recorded basic elements into an array:
[0119] a) First, check the entire array. If the array is full when checked, enter the expansion process, otherwise proceed to the next step b. The expansion process is as follows:
[0120] i. If the random array is full, you can try to allocate a new secondary array oarr_items first, but before that, you will check whether the primary array oarr_array is full; for example, by checking whether anum and alen in the structure oarray are the same;
[0121] ii. If oarr_array is full, create a new oarr_array first, then copy the old oarr_array data to the new oarr_array, and then release the old oarr_array;
[0122] iii. If there is enough space in oarr_array to record the new oarr_items, a new oarr_items is allocated and then recorded in oarr_array;
[0123] iv. The new total length len of the newly created expanded array is: the length len of the old array + the number of first-level elements in the newly allocated first-level array, ilen;
[0124] b) Select a free element position from the array. There will be a field cur in the structure oarray to record the free position. Its initial value is 0. When allocating free basic elements to record memory block information, the field cur can point to the serial number of the next free basic element. When released, it will be updated to the release position, that is, the number of the released basic element. If they are all full, the field cur can be set to a specific mark. If it is a specific mark, oarr will be traversed in sequence to find a free basic element.
[0125] c) Get the free basic element item2 and update the next free position cur in the array. If the next element of item2 is a free basic element, it will directly point to the element. Otherwise, cur will traverse the search from the beginning.
[0126] d) Determine how to insert the new element item2 based on the insertion position pos specified by the array;
[0127] i. If the insertion position is at the beginning, the starting position head of the structure oarray will point to the new element item2; and if head originally has a value (that is, it points to a recorded basic element), then item2's next will point to the value in head, that is, the basic element pointed to by head;
[0128] ii. If the insertion position is not the beginning, the basic element item1 corresponding to pos, if item1 points to the next basic element post_next, then point item2's next to post_next, and the element item1 where pos is located next to item2;
[0129] iii. If there is no next element, item2's next will point to itself, indicating that item2 is the tail of the recorded basic elements in the array.
[0130] 5. This embodiment provides the following deletion function del, which is used to delete the recorded basic elements of the array:
[0131] Deleting an element here means clearing an element that has information written to it to change it into an idle element, and clearing the association between it and other elements that have information written to them.
[0132] a) When deleting, you can specify the element to be deleted (pos) and the previous element position (prev);
[0133] b) If the deleted item is neither the head nor the tail of oarr, then the next of prev points to the next of pos; otherwise, the next of prev points to itself;
[0134] c) If the head of oarr is deleted, the head of oarr must point to the next of pos; and if it is the tail (that is, the last element), the next free position cur of oarr is updated to 0, otherwise it will be updated to pos;
[0135] d) If the oarr array is empty after deletion, the shrinking process will be triggered, and the first-level array will release the oarr_items second-level array except for the original length olen; of course, the first-level array can also be reduced to its original size as needed.
[0136] 6. This embodiment provides the following traversal function for traversing the recorded basic elements in the array;
[0137] A variety of situations can trigger a traversal. For example, a cold or hot array requires periodic scanning of each recorded element to see if the memory blocks in the cold array are still cold, or if the memory blocks in the hot array are still hot. In this case, a full traversal is required. Furthermore, deleting a specific memory range also requires a traversal search within the array. Other search scenarios can also trigger a traversal.
[0138] a) Starting from the point pointed by the head of the random array oarr, the basic element pointed by the head is used as the first element cur;
[0139] b) To find the next element item_next to be traversed, first record and determine whether the current position cur is the tail. If not, prev is recorded as cur, cur is updated to the next element next of cur, and next is updated to the next element pointed to by cur after the update (recording in advance is because element deletion operations may be performed during the traversal process);
[0140] For example, the first element itemA pointed to by head is recorded as cur;
[0141] The next field in itemA points to itemB, and the next field in itemB points to itemC. The itemA currently recorded in cur is not the tail. Therefore, the prev in cur is recorded as itemA, cur is updated to itemB, and then the next of cur points to itemC.
[0142] c) Whether the traversal is finished can be determined based on whether cur is a free element, or cur is the tail and prev is the same element.
[0143] (2) Using an array to record a memory range
[0144] 1. The basic element oarr_item includes a memory range information field, which is used to record the starting memory block sequence number and length (ie, the number of memory blocks) of the memory range.
[0145] 2. Determine the position of the recorded basic element pos and insert a new memory range range;
[0146] There are two cases corresponding to the insertion function range_add function:
[0147] a) If the insertion position is adjacent to the memory range range0 recorded by pos, then the memory range recorded by pos can be expanded forward or backward directly;
[0148] b) Otherwise, call the aforementioned insert function insert to insert a basic element, so as to assign rid and rlen to the inserted item;
[0149] 3. This embodiment also provides a range_del function for deleting a memory range. When a range of data needs to be deleted at the pos position, the range_del function needs to handle it according to different situations.
[0150] a) If the starting position of the deletion range is the same as the starting address of pos, and the ending position is greater than or equal to the ending address of pos, then directly call the aforementioned deletion function del to delete the recorded basic elements; otherwise, if it is less than the ending address, it is necessary to reduce the range recorded in pos.
[0151] b) If the starting address of the deletion range is different, but the ending address is equal to or equal to the original range, the range recorded in pos needs to be reduced forward;
[0152] c) If the deletion range is in the middle of the original range, the original range needs to be split into three parts. The first part is the range directly reduced forward from pos, the second part is the deletion part, and the third part is the deletion remaining part, which needs to be inserted after pos.
[0153] 4. Since oarr is similar to a one-way linked list, if you want to delete a range of data, you often need to call the basic oarr traversal function and combine it with the check_del function to determine whether the position is to be deleted, thereby determining the prev and pos positions in the previous step and performing specific operations;
[0154] 5. Of course, searching for elements is similar to the previous step. It also generally requires traversal, and then the function check_find is used to determine whether it is the function you are looking for.
[0155] (3) Using arrays to record hot and cold data
[0156] 1. Characteristics of hot and cold data: In addition to using the above-mentioned record range data, another characteristic is that the older data is at the head, and the newer data is at the tail. That is, the head is colder, and the tail is hotter.
[0157] 2. Therefore, for hot and cold data, newly inserted data will be inserted from the tail position of oarr, and the above range_add function can be called directly;
[0158] 3. For the hot and cold data to be swapped out by the exchange medium, it is also relatively simple. You only need to delete the data directly from the head of oarr, directly call the range_del function, and set the deletion position to the head of oarr;
[0159] 4. However, for data that needs to exit the lru cold and hot scan (for example, data is released and is already idle), it is more troublesome. The deleted data may be located anywhere in oarr. It is necessary to determine the location by traversing oarr and then call the range_del function to operate.
[0160] Corresponding to the aforementioned embodiment of the method for recording memory status, the present application also provides an embodiment of an apparatus for recording memory status and a computer device to which it is applied.
[0161] The embodiment of the device for recording the memory state of the present application can be applied to a computer device, such as a server or a terminal device. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor for file processing in which it is located to read the corresponding computer program instructions in the non-volatile memory into the memory for execution. From the hardware level, as shown in Figure 3, it is a hardware structure diagram of the computer device where the device for recording the memory state of the embodiment of the present application is located. In addition to the processor 310, memory 330, network interface 320, and non-volatile memory 340 shown in Figure 3, the computer device where the device 331 for recording the memory state in the embodiment is located, usually according to the actual function of the computer device, may also include other hardware, which will not be described in detail.
[0162] As shown in FIG4 , FIG4 is a block diagram of a device for recording memory status according to an exemplary embodiment of the present application, wherein the device is configured to record memory block information in a state corresponding to the array through an array;
[0163] The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, the primary element records the memory address information of the secondary array, and the secondary array includes at least one basic element, the basic element is used to record memory block information;
[0164] The device comprises:
[0165] The determination module 41 is configured to: when it is necessary to record the target memory block information into the free basic elements of the array, trigger the expansion module if it is determined that there are no free basic elements in the array;
[0166] The expansion module 42 is used to:
[0167] Create a new first-level array, copy the memory address information recorded by each first-level element in the current first-level array to the first-level element of the new first-level array, and release the current first-level array; wherein the number of first-level elements in the new first-level array is greater than the number of first-level elements in the current first-level array;
[0168] Creating a new secondary array, and recording the memory address information of the new secondary array into the idle primary elements of the new primary array;
[0169] The target memory block information is recorded in the free basic elements of the new secondary array.
[0170] In some examples, the device is applied to a memory management module of an operating system, and the arrays created by the memory management module during initialization are: a first-level array and a second-level array, and the address information of the second-level array is recorded in one of the first-level elements of the first-level array.
[0171] In some examples, the apparatus further includes a recording module configured to:
[0172] If it is determined that there is an idle basic element in the array, the target memory block information is recorded in the idle basic element.
[0173] In some examples, whether there are free basic elements in the array is determined as follows:
[0174] Determining whether a secondary array in the array has free basic elements;
[0175] If yes, determine whether there is an idle basic element in the array; if not, determine whether there is an idle first-level element in the first-level array of the array;
[0176] If there is an idle first-level element, a new second-level array is created, and after recording the memory address information in the idle first-level element, it is determined whether there is an idle basic element;
[0177] If there is no idle first-level element, it is determined that there is no idle basic element in the array.
[0178] In some examples, the memory management module creates array metadata for recording the array information during initialization, the array metadata including: a header field for pointing to a first recorded basic element;
[0179] The fields of the basic element include: a next field, wherein the initial value of the next field is an idle flag indicating that the basic element is an idle basic element; when the basic element is changed from an idle basic element to a recorded basic element, the next field is used to point to the next recorded basic element of the basic element or to itself;
[0180] After recording the target memory block information into the free basic elements of the new secondary array, the method further includes:
[0181] Update the next field of the recorded idle basic element.
[0182] In some examples, updating the next field of the recorded idle basic element includes:
[0183] If the header field does not point to the first recorded basic element, update the header field to point to the target basic element, and update the next field of the target basic element to point to itself;
[0184] If the header field points to the first recorded basic element, find the last recorded basic element pointing to itself according to the header field, update the next field of the last recorded basic element pointing to itself to point to the target basic element, and update the next field of the target basic element to point to itself.
[0185] In some examples, the apparatus further includes an updating module configured to:
[0186] To determine that the first recorded basic element needs to be changed to an idle basic element, perform the following steps:
[0187] If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, the next field of the previous basic element pointing to the first recorded basic element is updated to the basic element pointed to by the next field of the first recorded basic element;
[0188] If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element points to itself, update the next field of the previous basic element pointing to the first recorded basic element to point to itself;
[0189] If the header field points to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, updating the header field to point to the basic element pointed to by the next field of the first recorded basic element;
[0190] If the header field points to the first recorded basic element and the next field of the first recorded basic element points to itself, when the current first-level array has been expanded, the following shrinking process is executed: a shrunken first-level array is created to replace the current first-level array; wherein, the number of first-level elements in the shrunken first-level array is less than the number of first-level elements in the current first-level array.
[0191] In some examples, the memory block information recorded by the basic element includes: memory range information represented by a starting memory block number and a number of memory blocks;
[0192] The determining module is further configured to:
[0193] Traversing the memory range information of each recorded basic element record in the array;
[0194] If the number of the target memory block is not adjacent to each of the recorded memory range information, it is determined that the information of the target memory block needs to be recorded into the idle basic element of the array.
[0195] In some examples, the determining module is further configured to:
[0196] If the number of the target memory block is adjacent to the target memory range information, the number of memory blocks recorded in the basic element recording the target memory range information is modified so that the modified target memory range information covers the target memory block.
[0197] In some examples, the apparatus further includes a deletion module configured to:
[0198] Determine the memory range to be deleted, traverse each recorded basic element of the array, determine the second recorded basic element corresponding to the memory range to be deleted, and then perform the following steps:
[0199] In a case where the memory range to be deleted is the same as the recorded memory range recorded by the second recorded basic element, determining to change the second recorded basic element to an idle basic element;
[0200] In the case where the memory range to be deleted is different from the recorded memory range:
[0201] If the memory range to be deleted is located in the middle of the recorded memory range, the recorded memory range is divided into a front portion before the memory range to be deleted, a portion of the memory range to be deleted, and a back portion after the memory range to be deleted according to the memory range to be deleted, the memory range information of the second recorded basic element record is updated to represent the front portion, and a free basic element record is obtained for use in representing the memory range information of the back portion, and the free basic element record is linked to the back portion of the second recorded basic element;
[0202] If one of the boundaries of the memory range to be deleted is the same as the boundary of the recorded memory range, the memory range information recorded by the second recorded basic element is updated to: the different parts of the memory range to be deleted and the recorded memory range.
[0203] The implementation process of the functions and effects of each module in the above-mentioned device for recording memory status is specifically described in the implementation process of the corresponding steps in the above-mentioned method for recording memory status, and will not be repeated here.
[0204] Correspondingly, an embodiment of the present application further provides a computer program product, including a computer program, which implements the steps of the aforementioned method embodiment for recording memory status when executed by a processor.
[0205] Accordingly, an embodiment of the present application also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of an embodiment of a method for recording memory status when executing the program.
[0206] Accordingly, an embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the method embodiment for recording memory status are implemented.
[0207] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can be referred to the partial description of the method embodiment. The device embodiment described above is merely illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present application scheme. Those of ordinary skill in the art can understand and implement it without paying any creative work.
[0208] The above embodiments can be applied to one or more computer devices, where the computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The hardware of the computer device includes but is not limited to a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.
[0209] The computer device may be any electronic product that can interact with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0210] 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 consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers.
[0211] The network where the computer device is located includes but is not limited to the Internet, wide area network, metropolitan area network, local area network, virtual private network (VPN), etc.
[0212] The foregoing description describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0213] The steps of the various methods above are divided only for the purpose of clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications or introducing insignificant designs to the algorithm or process without changing the core design of the algorithm and process are all within the scope of protection of this application.
[0214] The phrases "specific examples" or "some examples" mean that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this application, schematic representations of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
[0215] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the inventions claimed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of this application and include common knowledge or customary techniques in the art not claimed herein. The description and examples are to be considered as exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0216] It should be understood that the present application is not limited to the exact structures described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0217] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A method for recording a memory state, the method being used to record memory block information in a state corresponding to the array through an array; in, The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, the primary element records the memory address information of the secondary array, the secondary array includes at least one basic element, the basic element is used to record the memory block information; the method includes: When it is necessary to record the target memory block information into the free basic elements of the array, if it is determined that there are no free basic elements in the array, the following expansion steps are performed: Create a new first-level array, copy the memory address information recorded in each first-level element in the current first-level array of the array to the first-level element of the new first-level array, and release the current first-level array; wherein the number of first-level elements of the new first-level array is greater than the number of first-level elements of the current first-level array; Create a new secondary array, and record the memory address information of the new secondary array into the free primary elements of the new primary array; The target memory block information is recorded into the free basic elements of the new secondary array.
2. According to the method described in claim 1, the method is applied to the memory management module of the operating system, and the arrays created by the memory management module during initialization are: a first-level array and a second-level array, and the address information of the second-level array is recorded in one of the first-level elements of the first-level array.
3. The method according to claim 1, further comprising: If it is determined that there is an idle basic element in the array, the target memory block information is recorded in the idle basic element.
4. According to any one of the methods of claims 1 to 3, whether there are free basic elements in the array is determined by: Determine whether a secondary array in the array has free basic elements; If yes, determine whether there are free basic elements in the array; if no, determine whether there are free first-level elements in the first-level array of the array; If there is an idle primary element, a new secondary array is created, and after the memory address information of the new secondary array is recorded in the idle primary element, it is determined that there is an idle basic element; If there is no idle first-level element, it is determined that there is no idle basic element in the array.
5. According to any one of the methods of claims 1 to 3, the memory management module creates array metadata for recording the array information during initialization, the array metadata comprising: Header field used to point to the first recorded base element; The fields of the basic element include: a next field, the initial value of which is an idle mark indicating that the basic element is an idle basic element; when the basic element is changed from an idle basic element to a recorded basic element, the next field is used to point to the next recorded basic element of the basic element or to itself; After recording the target memory block information into the free basic elements of the new secondary array, the method further includes: Update the next field of the recorded free basic element.
6. The method according to claim 5, wherein updating the next field of the recorded idle basic element comprises: If the header field does not point to the first recorded basic element, update the header field to point to the target basic element, and update the next field of the target basic element to point to itself; If the header field points to the first recorded basic element, search for the last recorded basic element pointing to itself according to the header field, update the next field of the last recorded basic element pointing to itself to point to the target basic element, and update the next field of the target basic element to point to itself.
7. The method according to claim 5, further comprising: Determine that the first recorded basic element needs to be changed to an idle basic element, and perform the following steps: If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, the next field pointing to the previous basic element of the first recorded basic element is updated to the basic element pointed to by the next field of the first recorded basic element; If the header field does not point to the first recorded basic element, and the next field of the first recorded basic element points to itself, update the next field of the previous basic element pointing to the first recorded basic element to point to itself; If the header field points to the first recorded basic element, and the next field of the first recorded basic element does not point to itself, updating the header field to point to the basic element pointed to by the next field of the first recorded basic element; If the header field points to the first recorded basic element and the next field of the first recorded basic element points to itself, and when the current first-level array has been expanded, the following reduction process is performed: create a reduced first-level array to replace the current first-level array; wherein the number of first-level elements in the reduced first-level array is less than the number of first-level elements in the current first-level array.
8. The method according to claim 1, wherein the memory block information recorded by the basic element includes: Memory range information represented by the starting memory block number and the number of memory blocks; The step of determining that target memory block information needs to be written into an idle basic element in the array includes: Traversing the memory range information of each recorded basic element record in the array; If the serial number of the target memory block is not adjacent to each of the recorded memory range information, it is determined that the information of the target memory block needs to be recorded into the free basic element of the array.
9. The method according to claim 8, further comprising: If the serial number of the target memory block is adjacent to the target memory range information, the number of memory blocks recorded in the basic element recording the target memory range information is modified so that the modified target memory range information covers the target memory block.
10. The method according to claim 8, further comprising: Determine the memory range to be deleted, traverse each recorded basic element of the array, determine the second recorded basic element corresponding to the memory range to be deleted, and then perform the following steps: In a case where the memory range to be deleted is the same as the recorded memory range recorded by the second recorded basic element, determining to change the second recorded basic element to an idle basic element; When the memory range to be deleted is different from the recorded memory range: If the memory range to be deleted is located in the middle of the recorded memory range, the recorded memory range is divided into a front part before the memory range to be deleted, a part of the memory range to be deleted, and a rear part after the memory range to be deleted according to the memory range to be deleted, the memory range information of the second recorded basic element record is updated to represent the front part, and after obtaining the memory range information of the free basic element record used to represent the rear part, it is linked to the rear of the second recorded basic element; If one of the boundaries of the memory range to be deleted is the same as the boundary of the recorded memory range, the memory range information recorded by the second recorded basic element is updated to: the different parts of the memory range to be deleted and the recorded memory range.
11. A device for recording memory status, the device being used to record memory block information in a state corresponding to the array through an array; in, The array includes a primary array and at least one secondary array, the primary array includes at least one primary element, the primary element records the memory address information of the secondary array, the secondary array includes at least one basic element, the basic element is used to record the memory block information; The device comprises: A determination module, configured to trigger a capacity expansion module if it is determined that no free basic elements exist in the array when it is necessary to record target memory block information into the free basic elements of the array; Expansion module, used for: Create a new first-level array, copy the memory address information recorded in each first-level element in the current first-level array of the array to the first-level element of the new first-level array, and release the current first-level array; wherein the number of first-level elements of the new first-level array is greater than the number of first-level elements of the current first-level array; Create a new secondary array, and record the memory address information of the new secondary array into the free primary elements of the new primary array; The target memory block information is recorded into the free basic elements of the new secondary array.
12. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.
13. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any one of the methods of claims 1 to 10.
Citation Information
Patent Citations
Composition of data objects
CN103124959A
Method and device for data processing
CN103870259A
Queue container implementation method and device
CN112860371A
Method and device for recording cold and hot states of memory
CN114661557A
Method and device for recording memory state, computer equipment and storage medium
CN116661690A
