Method for determining memory access information, storage medium, and program product

By maintaining a memory cache array in the host machine to record memory allocation information, and using the physical address of reserved memory and the virtual machine process to query cache entries, the problem of the host machine quickly determining virtual machine memory access information is solved, thereby improving the efficiency of virtual machine operation and the performance of host machine management.

CN114780246BActive Publication Date: 2026-03-20ALIBABA (CHINA) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-11
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

In virtualization scenarios, the host machine cannot quickly and lock-free determine the memory access information of the virtual machine, resulting in high latency in virtual machine operations and affecting operating efficiency.

Method used

By maintaining a memory cache array in the host machine to record memory allocation information, the system can retrieve memory allocation information by querying cache entries using the physical address of reserved memory and the virtual machine process, and determine memory access information through page tables, thus avoiding the use of operation locks that hold memory allocation information.

Benefits of technology

It enables rapid determination of virtual machine memory access information in the absence of locks or with minimal locks, reduces lock contention, and improves the efficiency of the host machine in managing virtual machines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114780246B_ABST
    Figure CN114780246B_ABST
Patent Text Reader

Abstract

The application provides a memory access information determination method, a storage medium and a program product. The memory access information determination method comprises the following steps: obtaining a physical address of a reserved memory in a host computer, and obtaining a virtual machine process to which the reserved memory belongs; querying a cache item corresponding to the reserved memory from a memory cache array according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, to obtain memory allocation information stored in the cache item corresponding to the reserved memory, wherein the memory cache array comprises a plurality of cache items; and determining memory access information of the reserved memory according to a page table associated with the memory allocation information corresponding to the reserved memory.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and in particular, to a memory access information determination method, a storage medium, and a program product. BACKGROUND

[0002] In a host memory allocation architecture in a virtualization scenario, most of the memory of the host is reserved for allocation to virtual machines. This part of the reserved memory is not available to the kernel of the host, and the kernel of the host cannot directly determine the access of this part of the memory.

[0003] Generally, the host can traverse the memory allocation information of the virtual machine to query the page table corresponding to the memory, so as to determine the access information corresponding to the memory. However, this process needs to lock the memory allocation information to avoid conflicts between the query operation on the memory allocation information and other update and release operations on the memory. However, this will cause the operation of the virtual machine on the memory to be unable to complete or to have a high delay, which greatly affects the operation of the virtual machine.

[0004] Therefore, the prior art needs to solve the technical problem of how to reduce or avoid lock contention between the memory access information determination process and other operations on the memory. SUMMARY

[0005] Therefore, embodiments of the present application provide a memory access information determination method to at least partially solve the above problems.

[0006] According to a first aspect of embodiments of the present application, a memory access information determination method is provided, including: obtaining a physical address of a reserved memory in a host, and obtaining a virtual machine process to which the reserved memory belongs; querying a cache item corresponding to the reserved memory from a memory cache array according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, to obtain memory allocation information stored in the cache item corresponding to the reserved memory, wherein the memory cache array includes a plurality of cache items; and determining memory access information of the reserved memory according to a page table associated with the memory allocation information corresponding to the reserved memory.

[0007] According to a second aspect of embodiments of the present application, a computer storage medium is provided, which stores a computer program. The program is executed by a processor to implement the method described above.

[0008] According to a third aspect of embodiments of the present application, a computer program product is provided, which includes computer instructions. The computer instructions instruct a computing device to perform operations corresponding to the method described above.

[0009] According to the scheme provided in the embodiment of the present application, the physical address of the reserved memory in the host computer is obtained, and the virtual machine process to which the reserved memory belongs is obtained; the cache item corresponding to the reserved memory is queried from the memory cache array according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, and the memory allocation information stored in the cache item corresponding to the reserved memory is obtained, wherein the memory cache array includes a plurality of cache items, thereby the memory cache data for recording the memory allocation information can be increased, and the memory allocation information of the reserved memory can be obtained by querying the memory cache array without holding the operation lock of the memory allocation information; and the memory access information of the reserved memory is determined according to the page table associated with the memory allocation information corresponding to the reserved memory, the memory access information of the reserved memory can be determined while holding the operation lock of the memory allocation information is reduced as much as possible, and the scheme can quickly determine the memory allocation information corresponding to the reserved memory by querying in the memory cache array, and then the access information of the reserved memory can be quickly determined. BRIEF DESCRIPTION OF DRAWINGS

[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments described in the embodiments of the present application, and other drawings can also be obtained by those skilled in the art according to these drawings.

[0011] Figure 1A A structural schematic diagram of a host computer is provided for the embodiments of the present application.

[0012] Figure 1B A flowchart of a memory access information determination method is provided for the embodiments of the present application.

[0013] Figure 2 A flowchart of a memory access information determination method is provided for the embodiments of the present application.

[0014] Figure 3 A structural schematic diagram of a host computer is provided for the embodiments of the present application.

[0015] Figure 4 A flowchart of a memory access information determination method is provided for the embodiments of the present application.

[0016] Figure 5 A structural schematic diagram of an electronic device according to the embodiments of the present application. DETAILED DESCRIPTION

[0017] In order for those skilled in the art to better understand the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the embodiments of the present application, all other embodiments obtained by those skilled in the art should belong to the scope of protection of the embodiments of the present application.

[0018] In order to more specifically describe the solutions provided by the embodiments, the use scenarios in the present application will be exemplarily described first.

[0019] Figure 1A The structural schematic diagram of the host computer is shown in the figure. Multiple virtual machines VM1, VM2, …, VMn can run on a host computer.

[0020] The memory of the host computer can be divided into two categories according to different users, one is the memory used by the host computer itself, and the other is the reserved memory for virtual machines. In order to better manage the memory used by the virtual machines (such as reducing metadata overhead), the host computer generally divides a predetermined size of reserved memory from the memory, and the reserved memory is only used by the virtual machines and is not allowed to be used by the host computer itself. When a new virtual machine is created in the host computer, part of the memory can be divided from the reserved memory for the newly created virtual machine.

[0021] In the process of allocating memory for the virtual machine, memory allocation information can be generated, which can include the physical address distribution of the reserved memory, the corresponding virtual address, and the associated page table information. The memory allocation information is generally stored in the form of a linked list.

[0022] Since the management of the reserved memory is organized in the form of physical memory, if the memory access information of the reserved memory is needed, all existing memory allocation information needs to be traversed to obtain the virtual address corresponding to the physical memory, and the page table corresponding to the virtual machine process is queried according to the virtual address to determine the access information corresponding to the physical memory. However, this process needs to hold the operation lock of the linked list composed of the memory allocation information to avoid the conflict between the query operation and other memory update and release operations.

[0023] However, in the traversal process of obtaining the physical memory access situation, if the operation lock of the memory allocation information is held for a long time or frequently, other memory operations on the virtual machine cannot or are difficult to obtain the operation lock, thereby affecting or even blocking various management operations of the host computer on the virtual machine.

[0024] To this end, the embodiment of the present application provides a method for determining memory access information, which can obtain the virtual address corresponding to the physical address to be traversed and the page table thereof under the premise of taking as few locks as possible.

[0025] Figure 1B A flowchart of a method for determining memory access information is provided in the embodiment of the present application. The steps provided by the embodiment can be executed by the host computer, as shown in the figure, and the steps include:

[0026] S101, obtaining the physical address of the reserved memory in the host computer, and obtaining the virtual machine process to which the reserved memory belongs.

[0027] The reserved memory is the memory that can be allocated to the virtual machine, and the virtual machine is a service or process deployed on the host computer through virtualization technology.

[0028] In the embodiment, the physical memory in the host computer can be divided into two types of memory, one part is the memory used by the host computer, and the other part is the reserved memory for the virtual machine. The host computer can determine the memory address that can be used by itself, and determine the reserved memory except for the memory that can be used by itself.

[0029] In the embodiment, when the reserved memory is allocated to the virtual machine, the physical address of the reserved memory and the corresponding virtual machine process are generally recorded. In the embodiment, the physical address and the corresponding virtual machine process can be obtained according to the record. Of course, if the physical address of the reserved memory whose access information needs to be determined has been obtained, the virtual machine process corresponding to the reserved memory can be obtained according to the record of the physical address of the reserved memory, which is not limited in the embodiment.

[0030] S102, querying the cache item corresponding to the reserved memory from the memory cache array according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, and obtaining the memory allocation information stored in the cache item corresponding to the reserved memory.

[0031] The memory allocation information can be generated when the reserved memory is allocated to the virtual machine. The memory allocation information can be used to record the virtual machine process to which the reserved memory is allocated, the physical address of the allocated reserved memory and the virtual address mapped thereto, and the associated page table, and the memory allocation information can be updated synchronously with the use of the reserved memory by the virtual machine.

[0032] In the embodiment, the memory cache array is used to record the memory allocation information. The memory cache array can include a plurality of cache items, and each cache item can record the memory allocation information, the physical address of the reserved memory corresponding to the memory allocation information, and the virtual machine process to which the reserved memory is allocated, etc.

[0033] In this embodiment, the corresponding cache item can be queried according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, and the memory allocation information stored in the cache item can be obtained. Since the above process is a query operation through the memory cache array, rather than an operation on the memory allocation information, it is not necessary to hold the operation lock of the linked list composed of the memory allocation information.

[0034] S103, memory access information of the reserved memory is determined according to the page table associated with the memory allocation information corresponding to the reserved memory.

[0035] The page table is a special data structure used to provide mapping from a virtual page to a physical page. More specifically, the mapping relationship between the virtual address and the physical address can be recorded in the page table. A virtual machine process can correspond to one or more page tables, and the page table corresponding to the virtual machine can be single-level or multi-level. One page table can be mapped to multiple discontinuous physical addresses, and one continuous physical address can be mapped to different page tables.

[0036] The memory allocation information can record the page table information corresponding to the reserved memory allocated each time for the virtual machine process.

[0037] In this embodiment, when allocating the reserved memory for the virtual machine, the memory address can be mapped to the virtual address in the MMAP manner, that is, the mapping relationship between the physical address and the virtual address of the reserved memory is generated as the memory allocation information corresponding to MMAP. The page table is created for the virtual machine according to the information of MMAP, and the virtual address of the reserved memory is mapped to the corresponding physical address. The virtual machine can operate the memory according to the virtual address, and the established page table is also recorded in MMAP.

[0038] After determining the page table corresponding to the reserved memory, the access bit in the page table can be used to determine the access condition of the reserved memory, that is, to determine the memory access information of the reserved memory. The memory access information corresponding to the reserved memory is used to indicate whether the reserved memory is accessed. Specifically, the virtual address corresponding to the physical address of the reserved memory can be determined according to MMAP, and the access bit of the page table is queried according to the virtual address to determine the memory access information of the reserved memory.

[0039] The scheme provided by the embodiment comprises the following steps: obtaining a physical address of reserved memory in a host computer and a virtual machine process to which the reserved memory belongs; querying a cache item corresponding to the reserved memory from a memory cache array according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, to obtain memory allocation information stored in the cache item corresponding to the reserved memory, wherein the memory cache array comprises a plurality of cache items; thereby, memory cache data used for recording memory allocation information can be increased, and the memory allocation information of the reserved memory can be obtained by querying the memory cache array without holding an operation lock of the memory allocation information; and memory access information of the reserved memory is determined according to a page table associated with the memory allocation information corresponding to the reserved memory, so that the memory access information of the reserved memory can be determined while holding the operation lock of the memory allocation information is reduced as much as possible, and the memory allocation information corresponding to the reserved memory can be quickly determined by querying the memory cache array, and then the access information of the reserved memory can be quickly determined.

[0040] The memory access information determination method of the embodiment can be executed by any appropriate electronic device with data processing capability, including but not limited to a server, a mobile terminal (such as a mobile phone, a PAD, etc.) and a PC, etc.

[0041] Figure 2 A flowchart of a memory access information determination method provided by the embodiment is shown in the figure, which comprises the following steps:

[0042] S201, obtaining a physical address of reserved memory in a host computer and a virtual machine process to which the reserved memory belongs.

[0043] In the embodiment, the reserved memory to which the access information needs to be determined can be all or part of the reserved memory allocated, which is not limited in the embodiment.

[0044] Optionally, in the embodiment, the step S201 can comprise the following steps: querying a cold-hot aging array to obtain the physical address of the reserved memory in the host computer and the virtual machine process to which the reserved memory belongs, wherein the cold-hot aging array stores the physical address of the reserved memory, the memory size of the reserved memory and the virtual machine process to which the reserved memory belongs.

[0045] In the field of virtual machines, a host machine generally allocates reserved memory in a certain granularity, that is, the reserved memory is sliced according to a 2M granularity, and the reserved memory is allocated to a virtual machine in multiples of 2M. In the lightweight metadata design of the host machine, only one state bit of the memory slice of the reserved memory is maintained, and no other additional metadata overhead is maintained. However, this also leads to no metadata that can be used to represent the cold and hot states of the memory slice. Therefore, the applicant designs a new memory aging management architecture to record the cold and hot changes of the reserved memory, that is, the cold and hot aging array.

[0046] Specifically, refer to Figure 3 , which shows a structural schematic diagram of a host machine. A plurality of virtual machines VM1, VM2… can be deployed in the host machine, and the host machine kernel kernel can maintain a cold and hot memory management structure, which includes cold and hot aging information for determining the reserved memory Reserved Memory that has been allocated to the virtual machine. The cold and hot memory management structure can specifically include a plurality of cold and hot node structures and various control fields of the total aging function.

[0047] The various control fields of the aging function can be, for example, a field for controlling whether the entire cold and hot scanning function is enabled, a cache pool of a commonly used structure body for statistical information and repeated allocation and release. Each node can include a plurality of cold and hot aging data. After updating the data in the node each time, the various control fields of the aging function can be updated.

[0048] One cold and hot node structure can correspond to one or more virtual machines, and one virtual machine can correspond to one or more cold and hot node structures. The present embodiment does not limit this.

[0049] Refer to Figure 3 , taking node node0 and node node1 as examples, each node can include a plurality of cold and hot aging arrays. The cold and hot aging array can be divided into four categories: inactive (inactive, cold), active (active, hot), paused (temporarily not participating in scanning), or pinned (permanently not participating in scanning), corresponding to the four states of the memory. Of course, the present embodiment only takes these four categories as examples for illustration, and is not limited by the present application.

[0050] Each cold and hot aging array can include a plurality of cold and hot items item. The plurality of cold and hot items can be sorted by time, so that the cold and hot aging array after time sedimentation can represent the aging of the memory.

[0051] Each cold-hot item can include a physical address idx of the allocated reserved memory and a size size of the allocated reserved memory, wherein a next for indicating a next cold-hot item and a virtual machine process pid to which the allocated reserved memory belongs are also included.

[0052] Thus, according to the physical address of the reserved memory, the cold-hot aging array can be queried to obtain the virtual machine process pid to which the reserved memory belongs.

[0053] It should be noted that in the embodiment, part of the memory can be focused on, and for the physical address of the part of the reserved memory, the cold-hot memory array can be queried to determine the virtual machine process to which each belongs.

[0054] S202, determine the address range of the storage space for storing the memory cache array.

[0055] In the embodiment, the memory cache array can be initialized in the host machine, and in the process of allocating the reserved memory for the virtual machine, the information of each reserved memory allocation process can be written into the memory cache array.

[0056] Suppose the size of each cache item is n, then the size of the initialized storage space of the memory cache array lmap can be a*n+b*n, a and b are greater than 1. The part corresponding to a*n is used as normal storage space for storing the memory cache array, used to write cache items, and the part corresponding to b*n is used to expand the memory cache array, a can be the same as b. In the specific use process, if the part corresponding to b*n has already started to be used, before the next time the memory access information of the reserved memory is determined, the memory cache array can be expanded to a*n+b*n+c*n, c is greater than 1, and the following c*n is used for subsequent emergency expansion, preferably, c=a+b.

[0057] Optionally, in the embodiment, the memory cache array includes a plurality of cache items, and the cache items are used to store the memory allocation information generated in a reserved memory allocation process, the physical address of the allocated reserved memory, and the virtual machine process to which the allocated reserved memory belongs.

[0058] The cache item in the memory cache array can be updated in the following way:

[0059] 1) Obtain the memory allocation information generated in the process of allocating the reserved memory to the virtual machine; determine the reserved cache item in the memory cache array, and write the memory allocation information, the physical address of the reserved memory corresponding to the memory allocation information, and the virtual machine process information to which the reserved memory belongs into the reserved cache item, to update the memory cache array.

[0060] Specifically, when newly allocating reserved memory for a virtual machine, memory allocation information mmap of the newly allocated reserved memory can be obtained. If scanning of the allocated reserved memory is needed to determine corresponding memory access information, the memory allocation information can be added to the memory cache array lmap when scanning, and the adding method can be:

[0061] a) judging whether the array of lmap is full; if not, performing step c; otherwise, performing step b;

[0062] b) judging whether the part for expansion is used, if not, expanding directly for use and updating the shadow mark as used; otherwise, reporting an error that lmap is full;

[0063] c) finding an idle entry from the lmap array, the idle entry being a pre-generated empty cache item;

[0064] d) recording the memory allocation information mmap in the entry, and recording the virtual machine process pid corresponding to the memory allocation information and the like. In the embodiment, the memory allocation information copy mmap2 corresponding to the memory allocation information mmap and the vma corresponding to the memory allocation information mmap and the like can also be recorded;

[0065] e) updating the statistical information of lmap, for example, updating the number of entries in lmap that have been written with data, the remaining number, the next space entry to be written with data, and the like.

[0066] 2) receiving a release operation of the reserved memory, determining the memory allocation information corresponding to the memory release operation; determining the cache item corresponding to the memory allocation information from the memory cache array and clearing it to update the memory cache array.

[0067] Specifically, when logging off the reserved memory for a virtual machine, the vma corresponding to the memory allocation information mmap of the logged-off reserved memory can be obtained, the cache item of the logged-off reserved memory is found according to the vma, and the cache item is cleared to obtain an idle entry. The statistical information of lmap can be updated, and the updated statistical information can refer to step e described above.

[0068] In the embodiment, since the memory cache data needs to be traversed to obtain the memory allocation information corresponding to the reserved memory in the subsequent step, the address range of the storage space for storing the memory cache data can be determined in this step, so as to traverse the memory cache array according to the determined address range in the subsequent step.

[0069] Therefore, in this embodiment, before step S203 is performed, it is determined whether the memory of the remaining part of the memory cache array is used, and if it is used, new memory for expansion of the memory cache array needs to be allocated.

[0070] Specifically, it can be determined whether the memory for expansion of the memory cache array is used, and if it is used, new memory for expansion of the memory cache array can be allocated to the memory cache data to expand the storage space of the memory cache array; or it can also be determined whether the size of the memory used by the memory cache array is less than a*n, and if it is, the storage space of the memory cache array is reduced to a*n+b*n, wherein a*n corresponds to the part used as the normal storage space for storing the memory cache array, for writing cache items, and b*n corresponds to the part used for expansion of the memory cache array.

[0071] In this way, sufficient space can be reserved for the memory cache array, and during the subsequent execution of step S203, cache items can still be written into the memory cache array, that is, during the scanning process, the memory for expansion determined in advance can be used to timely expand the memory cache array; and the allocation of memory can fail, therefore, by determining the memory for expansion before scanning, the situation that no memory can be allocated when real expansion is needed during scanning can be avoided.

[0072] In addition, it should be noted that in this embodiment, when the memory cache array is operated, an operation lock of the memory cache array needs to be held, and the operation of taking the lock can be, for example, writing cache items into the memory cache array, deleting cache items, updating the memory cache array, pre-expanding the memory cache array, etc.; in addition, a read lock needs to be taken when the memory cache array is accessed.

[0073] In this embodiment, by determining the memory for expansion as shadow (for example, the part of memory corresponding to b*n or c*n described above) before traversal (i.e., before step S203), when real expansion is needed, the flag bit of the shadow used can be directly set to realize expansion, without holding the operation lock, and lock contention is avoided.

[0074] Generally, the scanning process for performing steps S203-S204 holds an operation lock of the memory cache array, and does not allow other processes to perform related operations on the cache array. The operations of other processes can be buffered and then performed when the process does not hold the operation lock. Further, in this embodiment, the scanning process for performing steps S203-S204 can perform update operations on the memory cache array, so that the process of accessing the cache array and updating the cache array is serial, and thus the process does not need to hold the operation lock of the memory cache array during the scanning process. For example, when it is determined that the searched cache item does not exist in the memory cache array, a corresponding cache item is added to the memory cache array, or when it is determined that the memory allocation information stored in the searched cache item is invalid, the cache item is updated. The update operations of these cache items are not performed in parallel with the searching process.

[0075] S203, according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, querying the cache item corresponding to the reserved memory from the memory cache array to obtain the memory allocation information stored in the cache item corresponding to the reserved memory.

[0076] Optionally, in this embodiment, step S203 can include: according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, traversing the cache items in the memory cache array, and determining whether the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs are stored in the cache item; if stored in the cache item, obtaining the memory allocation information stored in the cache item as the memory allocation information corresponding to the reserved memory.

[0077] Specifically, after obtaining the virtual machine process pid to which the reserved memory belongs from the cold-hot aging array according to the physical address idx of the reserved memory, the multiple cache items in the memory cache array can be traversed using idx and pid to obtain the cache item matching idx and pid, and the memory allocation information mmap stored in the cache item can be obtained.

[0078] In this embodiment, since multiple memory allocation operations can be performed for one virtual machine process, each memory allocation operation corresponds to one memory allocation information mmap, therefore, the corresponding memory allocation information cannot be accurately determined by pid, and one memory allocation operation can allocate multiple reserved memory slices, which can correspond to multiple idx, therefore, it is difficult to determine the corresponding memory allocation information by idx. Therefore, in this embodiment, when traversing the multiple cache items in the memory cache array using idx and pid, the multiple cache items can be first determined using pid, and then the memory allocation information recorded in the multiple cache items is queried to accurately determine the cache item corresponding to the reserved memory from the multiple cache items, and to obtain accurate memory allocation information.

[0079] It should be noted that, since the memory allocation information recorded in the plurality of cache items is queried by using the idx, the operation lock of the linked list composed of the memory allocation information needs to be held temporarily, and further preferably, in the embodiment, the memory allocation information copy can be stored in the cache item, and then the memory allocation information copy recorded in the plurality of cache items can be queried by using the idx, so as to further avoid locking.

[0080] Optionally, in the embodiment, if it is determined that the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs are not stored in any cache item of the memory cache array, an operation lock of a linked list composed of memory allocation information is obtained; and the memory allocation information included in the linked list is traversed according to the physical address, so as to obtain the memory allocation information corresponding to the reserved memory therefrom.

[0081] For some virtual machines, for example, the virtual machines established before the memory cache array is applied, or the virtual machines that do not participate in the scanning and traversal at the beginning but participate in the scanning and traversal after the strategy changes, there may be a case that the memory allocation information is not recorded in the memory cache array. If it is determined that the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs are not stored in any cache item of the memory cache array after the cache items in the memory cache information lmap are traversed, it is indicated that the memory allocation information corresponding to the memory allocation is not recorded in the lmap, and then the operation lock of the linked list composed of the memory allocation information can be obtained; and the memory allocation information included in the linked list is traversed according to the physical address, so as to obtain the memory allocation information corresponding to the reserved memory therefrom.

[0082] S204, according to the page table associated with the memory allocation information corresponding to the reserved memory, the memory access information of the reserved memory is determined.

[0083] Optionally, in the embodiment, since the operation lock of the memory allocation information is still needed to be held temporarily according to the page table associated with the memory allocation information corresponding to the reserved memory, in the embodiment, in order to further shorten the time of holding the operation lock, the step S204 can include: obtaining a memory allocation information copy of the memory allocation information corresponding to the reserved memory; determining the page table associated with the memory allocation information according to the memory allocation information copy; and determining the memory access information of the reserved memory according to the page table. The determination of the memory access information is realized by the copy, and the operation lock of the memory allocation information does not need to be held, that is, the locking is further avoided.

[0084] Specifically, in this embodiment, in order to ensure the validity of the copy, the method further comprises: judging whether the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs exist in the obtained memory allocation information according to the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, and the memory allocation information obtained from the memory cache array; if yes, it is determined that the memory allocation information copy is valid, and the step of determining the page table associated with the memory allocation information according to the memory allocation information copy is continued.

[0085] Specifically, since the process of determining the memory access information according to the copy is a lock-free operation, the memory access information (the source file corresponding to the copy) may be updated, resulting in inconsistency between the copy and the source file. Therefore, in this embodiment, the idx and pid corresponding to the reserved memory can be used to check the found memory access information mmap (the source structure corresponding to the copy). If the idx and pid information cannot be obtained in the mmap, it means that the source structure has been changed, and at this time, the copy can be updated and the cache item corresponding to the reserved memory can be found again.

[0086] If it is determined that the copy is consistent with the source file, the memory access information of the reserved memory can be determined according to the copy. The specific method for determining the memory access information can refer to related technologies, which will not be described here.

[0087] For example, referring to Figure 4 , a step flowchart of a memory access information determination method according to an embodiment of the present application is shown, as shown in the figure, which comprises:

[0088] S401, judging whether the memory used for expanding the memory cache array lmap needs to be adjusted.

[0089] If yes, after adjustment, step S402 is executed to traverse and scan. If no, step S402 is directly executed to traverse and scan.

[0090] S402, using the idx and pid corresponding to the reserved memory in the cold and hot aging information, traversing the cache items in the memory cache array lmap in a lock-free manner.

[0091] S403, judging whether the idx and pid belong to the cache item.

[0092] If no, step S404 is executed to judge whether the traversal is completed. If yes, step S406 is executed.

[0093] S404, judging whether the traversal of the cache item is completed.

[0094] If the traversal is not completed, the step S403 is returned to continue the execution, if the traversal is completed, it is determined that the memory allocation information desired to be searched is not stored in the memory cache array, and the step S408 is executed.

[0095] S405, an operation lock of the mmap chain table is obtained, the corresponding mmap is found from the chain table according to the idx and the pid, and the information is updated to the memory cache array.

[0096] Then, the step S408 is continued to be executed.

[0097] S406, the mmap in the cache item is returned.

[0098] S407, the mmap copy corresponding to the mmap is obtained, and whether the mmap is consistent with the mmap copy is judged according to the idx and the pid.

[0099] In the embodiment, since the memory cache array is traversed without lock, it is needed to judge whether the mmap is consistent with the mmap copy according to the idx and the pid after the query, and then judge whether the query result is valid.

[0100] If the consistency is consistent, the step S408 is executed, if the consistency is not consistent, the mmap copy is updated, and the step S403 is executed again.

[0101] S408, the memory access information of the reserved memory is obtained.

[0102] Specifically, the virtual address vaddr corresponding to the reserved memory can be obtained according to the idx corresponding to the reserved memory and the mmap copy obtained through the step S407, and the information whether the memory where the idx is located is accessed recently is obtained by querying the page table recorded in the vma managed according to the mmap by the vaddr.

[0103] The determination method of the memory access information in the embodiment can be executed by any appropriate electronic device with data processing capability, including but not limited to: server, mobile terminal (such as mobile phone, PAD, etc.) and PC, etc.

[0104] Referring to Figure 5 , a structure schematic diagram of an electronic device provided by the embodiment of the application is shown, and the specific implementation of the electronic device is not limited by the embodiment of the application.

[0105] As Figure 5 shown, the electronic device can include: a processor 502, a communications interface 504, a memory 506, and a communications bus 508.

[0106] Among them:

[0107] The processor 502, the communication interface 504, and the memory 506 communicate with each other through a communication bus 508.

[0108] The communication interface 504 is configured to communicate with other electronic devices or servers.

[0109] The processor 502 is configured to execute the program 510, and specifically can execute the related steps in the above-described memory access information determination method embodiments.

[0110] Specifically, the program 510 can include program code, which includes computer operation instructions.

[0111] The processor 502 can be a processor CPU, or an application specific integrated circuit ASIC, or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the smart device can be the same type of processor, such as one or more CPUs; or can be different types of processors, such as one or more CPUs and one or more ASICs.

[0112] The memory 506 is configured to store the program 510. The memory 506 can include a high-speed RAM memory, and can also include a non-volatile memory, for example, at least one disk memory.

[0113] The specific implementation of each step in the program 510 can refer to the corresponding description in the corresponding steps and units of the above-described memory access information determination method embodiments, and will not be described here. Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the foregoing method embodiments, and will not be described here.

[0114] The embodiments of the present application also provide a computer program product, which includes computer instructions instructing a computing device to perform the operations corresponding to the memory access information determination method in any of the above-described method embodiments.

[0115] It should be noted that, according to the needs of implementation, each component / step described in the embodiments of the present application can be split into more components / steps, or two or more components / steps or part of the operations of the components / steps can be combined into a new component / step, to achieve the purpose of the embodiments of the present application.

[0116] The above-described methods according to embodiments of the present application can be implemented in hardware, firmware, or software, or any combination thereof, and can be stored in a recording medium such as CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk, or be downloaded from network in raw storage in a remote recording medium or non-transitory machine-readable medium and stored in a local recording medium, so that the methods described herein can be processed by such software using a general purpose computer, a special purpose processor, or programmable or dedicated hardware such as ASIC or FPGA. It can be understood that the computer, processor, microprocessor controller, or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code, when the software or computer code is accessed and executed by the computer, processor, or hardware, the determination method of memory access information described herein is implemented. Furthermore, when a general purpose computer accesses code for implementing the determination method of memory access information shown herein, the execution of the code will convert the general purpose computer into a special purpose computer for executing the determination method of memory access information shown herein.

[0117] Those skilled in the art can realize that the units and method steps of the examples described in combination with the embodiments disclosed herein can be realized in electronic hardware or in combination of computer software and electronic hardware. Whether the functions are realized in hardware or software manner depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of the present application.

[0118] The above embodiments are only used to illustrate but not limit the embodiments of the present application, and the ordinary skilled person in the relevant art can make various changes and modifications without departing from the spirit and scope of the embodiments of the present application, therefore all equivalent technical solutions belong to the scope of the embodiments of the present application, and the patent protection scope of the embodiments of the present application should be defined by the claims.

Claims

1. A method for determining memory access information, comprising: Obtain the physical address of the reserved memory in the host machine, and obtain the virtual machine process to which the reserved memory belongs; Determine the address range of the storage space used to store the memory cache array; The memory cache array is initialized in the host machine, and during the process of allocating reserved memory for the virtual machine, the memory allocation information of each reserved memory allocation process is written into the memory cache array; Based on the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, the cache entry corresponding to the reserved memory is queried from the memory cache array to obtain the memory allocation information stored in the cache entry corresponding to the reserved memory. This allows the memory allocation information of the reserved memory to be obtained by querying the memory cache array without holding the operation lock of the memory allocation information. The memory cache array includes multiple cache entries, which are used to store the memory allocation information generated during a reserved memory allocation process, the physical address of the allocated reserved memory, and the virtual machine process to which the allocated reserved memory belongs. The memory access information of the reserved memory is determined based on the page table associated with the memory allocation information corresponding to the reserved memory.

2. The method according to claim 1, wherein, The step of querying the cache entry corresponding to the reserved memory from the memory cache array based on the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, to obtain the memory allocation information stored in the cache entry corresponding to the reserved memory, includes: Based on the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, traverse the cache entries in the memory cache array to determine whether the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs are stored in the cache entries; If it is stored in the cache item, the memory allocation information stored in the cache item is obtained as the memory allocation information corresponding to the reserved memory.

3. The method according to claim 2, wherein, The method further includes: If it is determined that the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs are not stored in any cache item in the memory cache array, then an operation lock is obtained for the linked list composed of memory allocation information. Based on the physical address, traverse the memory allocation information included in the linked list to obtain the memory allocation information corresponding to the reserved memory.

4. The method according to claim 1, wherein, The step of determining the memory access information of the reserved memory based on the page table associated with the memory allocation information corresponding to the reserved memory includes: Obtain a copy of the memory allocation information corresponding to the reserved memory; Determine the page table associated with the memory allocation information based on the copy of the memory allocation information; The memory access information for the reserved memory is determined based on the page table.

5. The method according to claim 4, wherein, After obtaining a copy of the memory allocation information corresponding to the reserved memory, the method further includes: Based on the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs, as well as the memory allocation information obtained from the memory cache array, determine whether the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs exist in the obtained memory allocation information; If it exists, the copy of the memory allocation information is determined to be valid, and the step of determining the page table associated with the memory allocation information based on the copy of the memory allocation information continues.

6. The method according to claim 1, wherein, The method further includes: Obtain memory allocation information generated during the process of allocating the reserved memory to the virtual machine; The reserved cache entries in the memory cache array are determined, and the memory allocation information, the physical address of the reserved memory corresponding to the memory allocation information, and the virtual machine process information to which the reserved memory belongs are written into the reserved cache entries to update the memory cache array.

7. The method according to claim 1, wherein, The method further includes: Receive a memory release operation and determine the memory allocation information corresponding to the memory release operation; The cache entry corresponding to the memory allocation information is determined from the memory cache array and cleared to update the memory cache array.

8. The method according to claim 1, wherein, Obtaining the physical address of the reserved memory in the host machine, and obtaining the virtual machine process to which the reserved memory belongs, includes: The cold and hot aging array is queried to obtain the physical address of the reserved memory and the virtual machine process to which the reserved memory belongs. The cold and hot aging array stores the physical address of the reserved memory, the size of the reserved memory, and the virtual machine process to which the reserved memory belongs.

9. A computer storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any one of claims 1-8.

10. A computer program product comprising computer instructions that instruct a computing device to perform the method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Memory access information acquisition method, computing device and storage medium

    CN113434371A