Video memory management method and device, equipment, storage medium and program product
By dynamically managing the video memory of the virtual GPU client and adjusting it according to the remaining video memory capacity and threshold, the problem of low video memory utilization of physical GPU is solved and efficient utilization of video memory resources is achieved.
Patent Information
- Application Number
- CN202411977270.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
AI Technical Summary
In the prior art, the video memory utilization rate of physical GPUs is low because each part of the video memory can only be used by the virtual GPU that exclusively occupies the video memory, resulting in wasted resources.
By dynamically managing the client's video memory, adjusting it according to the capacity of the remaining video memory and the video memory capacity threshold. The specific method includes reclaiming part of the video memory when the remaining video memory capacity is greater than the threshold, and allocating new video memory when the remaining video memory capacity is less than the threshold, thereby improving the overall utilization of the video memory.
By dynamically adjusting the video memory, the video memory utilization rate of the physical GPU is improved, ensuring that the video memory utilization rate of each client in the virtual machine system is within a reasonable range, and avoiding insufficient or wasteful video memory.
Smart Images

Figure CN119902890A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of virtualization technology, and in particular to a video memory management method, device, equipment, storage medium and program product. Background Art
[0002] Graphics Processing Unit (GPU) virtualization is a technology that shares the computing and memory resources of a physical GPU in multiple virtual environments.
[0003] In the related art, GPU virtualization can be controlled by a hypervisor. Specifically, the hypervisor can create virtual GPUs (abbreviated as vGPUs) in different clients, and the vGPU in each client will exclusively occupy a fixed portion of the video memory of the physical GPU.
[0004] However, in the above solution, each portion of the video memory of the physical GPU can only be used by the vGPU that exclusively occupies this portion of the video memory, resulting in a low utilization rate of the video memory of the physical GPU. Summary of the invention
[0005] The embodiments of the present application provide a video memory management method, apparatus, device, storage medium and program product, which can improve the utilization rate of the video memory of a physical GPU. The technical solution is as follows.
[0006] In one aspect, a video memory management method is provided, the method being executed by a computer device, wherein one or more clients are running in the computer device; each of the clients is allocated a portion of the video memory in the physical GPU of the computer device as the video memory of the virtual GPU in the client; the method comprising:
[0007] Acquire a first remaining video memory of a first client in a computer device; the first client is one of the one or more clients; the first remaining video memory is unoccupied video memory in the video memory allocated to the first client;
[0008] The capacity of the video memory of the first client is adjusted according to the capacity of the first remaining video memory and the video memory capacity threshold.
[0009] In one aspect, a video memory management device is provided, the device comprising:
[0010] A remaining video memory acquisition module is used to acquire a first remaining video memory of a first client in a computer device; one or more clients are running in the computer device; each of the clients is allocated a portion of video memory in a physical GPU of the computer device as video memory of a virtual GPU in the client; the first client is one of the one or more clients; the first remaining video memory is unoccupied video memory in the video memory allocated to the first client;
[0011] The video memory allocation module is used to adjust the capacity of the video memory of the first client according to the capacity of the first remaining video memory and the video memory capacity threshold.
[0012] In a possible implementation, the video memory allocation module is used to:
[0013] When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, reclaiming part of the video memory from the video memory allocated to the first client;
[0014] When the capacity of the first remaining video memory is less than the second video memory capacity threshold, additionally allocating new video memory for the first client;
[0015] The first video memory capacity threshold is greater than the second video memory capacity threshold.
[0016] In a possible implementation, a management program is also running in the computer device, and the video memory allocation module is used to:
[0017] When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, sending a first video memory management request to the management program through the first client, wherein the first video memory management request includes a first video memory address; the first video memory address is all or part of the address of the first remaining video memory;
[0018] The management program adds the first video memory corresponding to the first video memory address to a video memory pool, where the video memory pool is used to store video memory that is not allocated to the client.
[0019] In a possible implementation manner, the device further includes:
[0020] an address locking module, configured to lock the first video memory address through the first client before the video memory allocation module sends the first video memory management request to the management program through the first client, if the capacity of the first remaining video memory is greater than a first video memory capacity threshold; the video memory address locked by the first client is a video memory address that is prohibited from being accessed by a program or process in the first client;
[0021] The video memory allocation module is used to send the first video memory management request to the management program through the first client when the first video memory address is successfully locked.
[0022] In a possible implementation, the video memory allocation module is used to:
[0023] querying a second video memory address according to the first video memory address through the management program; the second video memory address is the address of the first video memory in the management program;
[0024] The second video memory address is added to the video memory pool by the hypervisor.
[0025] In a possible implementation, the hypervisor maintains a mapping relationship between the client and an address of a video memory allocated to the client in the hypervisor; the device further includes:
[0026] A mapping cancellation module is used to cancel the mapping relationship between the first client and the second video memory address through the management program.
[0027] In a possible implementation, a management program is also running in the computer device, and the video memory allocation module is used to:
[0028] When the capacity of the first remaining video memory is less than a second video memory capacity threshold, sending a second video memory management request to the management program through the first client;
[0029] The management program allocates the second video memory in the video memory pool to the first client according to the second video memory management request, wherein the video memory pool is used to store the video memory that is not allocated to the client.
[0030] In a possible implementation, the video memory allocation module is configured to send the second video memory management request to the hypervisor through the first client when the video memory allocated to the first client does not meet the exchange condition;
[0031] The exchange conditions include the following:
[0032] There is no swappable video memory in the video memory allocated to the first client, and the swappable video memory is a video memory that has been occupied and can be replaced by the system memory; or,
[0033] There is exchangeable video memory in the video memory allocated to the first client, and the sum of the capacity of the exchangeable video memory and the capacity of the first remaining video memory is less than the second video memory capacity threshold.
[0034] In a possible implementation, the video memory allocation module is used to:
[0035] When the video memory in the video memory pool is sufficient, removing a third video memory address from the video memory pool through the management program; the third video memory address is the address of the second video memory in the management program;
[0036] Sending a video memory management response to the first client through the management program, wherein the video memory management response is used to indicate that the first client is allocated the second video memory;
[0037] unlocking, by the first client, a fourth video memory address according to the video memory management response; the fourth video memory address is an address of the second video memory in the first client;
[0038] sending the fourth video memory address to the management program through the first client;
[0039] A mapping relationship between the third video memory address and the fourth video memory address is established through the management program.
[0040] In a possible implementation, the hypervisor maintains a mapping relationship between the client and an address of a video memory allocated to the client in the hypervisor; the device further includes:
[0041] A mapping relationship establishing module is used to establish a mapping relationship between the first client and the third video memory address through the management program.
[0042] In a possible implementation manner, the device further includes:
[0043] a video memory recycling module, configured to send a video memory recycling request to a second client through the management program when the video memory in the video memory pool is insufficient; the second client is a client other than the first client among the clients running in the computer device;
[0044] The video memory allocation module is further used to send a third video memory management request to the management program through the second client according to the video memory recovery request, wherein the third video memory management request includes a fifth video memory address; the fifth video memory address is all or part of the address of the second remaining video memory of the second client; and the third video memory corresponding to the fifth video memory address is added to the video memory pool through the management program.
[0045] In a possible implementation, the video memory allocation module is configured to send a third video memory management request to the management program through the second client according to the video memory recycling request when the capacity of the second remaining video memory is greater than a third video memory capacity threshold.
[0046] In a possible implementation, the video memory allocation module is further configured to:
[0047] When the capacity of the second remaining video memory is not greater than the third video memory capacity threshold, querying the capacity of the swappable video memory in the video memory of the second client through the second client; the swappable video memory is the video memory that has been occupied and can be replaced by the system memory;
[0048] When the sum of the capacity of the swappable video memory in the video memory of the second client and the capacity of the second remaining video memory is greater than the third video memory capacity threshold, the swappable video memory in the video memory of the second client is replaced by the system memory.
[0049] In a possible implementation, the video memory allocation module is used to reclaim part of the video memory allocated to the first client when the capacity of the first remaining video memory is greater than the first video memory capacity threshold and the capacity of the video memory allocated to the first client is greater than the video memory capacity lower limit.
[0050] In a possible implementation, the video memory allocation module is used to allocate additional video memory to the first client when the capacity of the first remaining video memory is less than the second video memory capacity threshold and the video memory capacity allocated to the first client is less than the video memory capacity upper limit.
[0051] On the other hand, a computer device is provided, the computer device comprising a processor and a memory, the memory storing instructions, the instruction set being loaded and executed by the processor to implement the video memory management method as described above.
[0052] On the other hand, a computer-readable storage medium is provided, wherein instructions are stored in the storage medium, and the instructions are loaded and executed by a processor to implement the video memory management method as described above.
[0053] In another aspect, a computer program product is provided, which includes computer instructions stored in a computer-readable storage medium; the computer instructions are read and executed by a processor of a computer device, so that the computer device implements the video memory management method as described above.
[0054] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:
[0055] The present application provides a scheme for dynamically managing the video memory of a vGPU according to the capacity of the remaining video memory of the client where the vGPU is located. Specifically, for a client, when the occupancy rate of the video memory allocated to the client is low (more remaining video memory), it means that the utilization rate of the video memory exclusively occupied by the vGPU of the client is low, and at this time, a part of the video memory allocated to the client can be recovered; when the occupancy rate of the video memory allocated to the client is high (less remaining video memory), it means that the utilization rate of the video memory exclusively occupied by the vGPU of the client is high, and at this time, new video memory can be additionally allocated to the client; through the above scheme, the capacity of the remaining video memory of each client can be controlled within a certain capacity range. From the perspective of the entire virtual machine system, the above scheme can achieve the effect of transferring a part of the video memory exclusively occupied by the client with insufficient video memory utilization to the client with higher video memory utilization, thereby improving the overall utilization rate of the video memory of the physical GPU. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0057] Figure 1 It is an architectural diagram of a virtualization system involved in this application;
[0058] Figure 2 It is a method flow chart of a video memory management method involved in this application;
[0059] Figure 3 It is a method flow chart of a video memory management method involved in this application;
[0060] Figure 4 It is a framework diagram of a video memory management involved in an embodiment of the present application;
[0061] Figure 5 It is a method flow chart of a video memory management method involved in this application;
[0062] Figure 6 It is a framework diagram of a video memory management involved in an embodiment of the present application;
[0063] Figure 7 It is a method flow chart of a video memory management method involved in this application;
[0064] Figure 8 It is a framework diagram of a video memory management involved in an embodiment of the present application;
[0065] Fig. 9It is a framework diagram of a video memory management involved in an embodiment of the present application;
[0066] Fig.10 It is a framework diagram of the client actively requesting video memory management involved in this application;
[0067] Fig.11 It is a framework diagram of the management program involved in this application performing video memory management;
[0068] Fig.12 It is a framework diagram of the client involved in this application releasing video memory according to the request of the management program;
[0069] Fig.13 is a block diagram of a video memory management device provided by an exemplary embodiment of the present application;
[0070] Fig.14 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0071] In order to make the purpose, technical solution and advantages of this application clearer, the following will further describe the implementation methods of this application in detail with reference to the accompanying drawings. First, some concepts involved in this application are introduced:
[0072] 1) GPU
[0073] GPU, also known as display core, visual processor, display chip, is a microprocessor that performs graphics processing-related computing work on computer devices (such as personal computers, workstations, game consoles, mobile devices, etc.). In some scenarios, GPU can also be used for other computing work besides graphics processing, such as artificial intelligence (AI) training and reasoning-related computing work, blockchain-related computing work, etc.
[0074] 2) Virtualization
[0075] In the computer field, virtualization is a resource management technology that abstracts and transforms various physical resources of computer devices, such as processors, networks, memory, and storage, to break down barriers between physical structures and allow users to use these resources in a better way than the original configuration. The virtual part of these resources (also called virtualized resources) is not limited by the existing resource setup, region, or physical configuration. Generally speaking, virtualized resources include virtualized computing resources and storage resources.
[0076] GPU virtualization is a technology that shares the computing and memory resources of a physical GPU in multiple virtual environments. It has the characteristics of convenient resource sharing, high cost-effectiveness, good isolation and flexible deployment.
[0077] Please refer to Figure 1 , which shows an architecture diagram of a virtualization system involved in this application. Figure 1 As shown, the virtualization system includes a host 100 in which a hypervisor 200 and one or more clients 300 are running.
[0078] The host 100 may include computer hardware, such as a physical central processing unit (CPU), a physical memory, a physical GPU, a physical bus, etc. These computer hardware constitute a physical computer system. An operating system (which may be called Host OS) may run on the host 100.
[0079] The management program 200 is also called a virtual machine manager (Hypervisor), which can be run in the operating system of the host 100, or can also be directly run based on the computer hardware of the host 100.
[0080] The hypervisor 200 is responsible for creating and managing the client 300. The hypervisor 200 is a system software that can act as an intermediary between the computer hardware of the host 100 and the client 300, and is responsible for effectively allocating and utilizing the hardware resources used by each client 300.
[0081] The client 300 is a virtual machine, which may include a virtual GPU; optionally, the client 300 may also include other virtual resources such as a virtual CPU, virtual memory, and a virtual bus; the client 300 may have an independently running operating system (which may be called a Guest OS) to support the client 300 to work independently on the host 100.
[0082] The virtualization system may further include one or more user terminals 400, and the host 100 and the user terminals 400 are connected via a wired or wireless network. Different clients 300 may be allocated to different user terminals 400 for use, and multiple user terminals 400 share the hardware resources of the host 100 through different clients 300.
[0083] Based on Figure 1In a virtualization scheme of the architecture shown, the computing resources of the vGPU are time-shared, while the storage resources are exclusive. That is to say, when a portion of the video memory in the physical GPU is allocated to a vGPU, this portion of the video memory cannot be used by other clients regardless of whether the client corresponding to the vGPU uses it, resulting in insufficient utilization of the video memory resources of the physical GPU.
[0084] In addition, video memory is an important resource for GPUs, and GPUs often use video memory for better performance and higher efficiency than system memory. In the above virtualization solution, the video memory allocated to vGPU cannot be shared between different vGPUs. When some vGPUs are idle and the rest are busy (using more video memory), these busy vGPUs cannot effectively use the video memory of the idle vGPUs and can only use the client's system memory. This results in the physical GPU frequently accessing the system memory when the vGPU calls the physical GPU to perform tasks, while some of the video memory cannot be effectively used. The performance of the physical GPU accessing the system memory is lower than the performance of accessing the video memory. Therefore, in this scenario, the work efficiency of the physical GPU will also decrease.
[0085] The solution shown in the subsequent embodiments of the present application provides a solution for dynamically managing the video memory allocated to the client in a virtualization scenario, which can flexibly adjust the video memory allocated to each client.
[0086] Please refer to Figure 2 , which shows a method flow chart of a video memory management method involved in the present application. The video memory management method can be executed by a computer device, in which a hypervisor and one or more clients are running; each client is allocated a portion of the video memory in the physical GPU of the computer device as the video memory of the virtual GPU in the client; for example, the computer device can be Figure 1 In the virtualized system shown in FIG. 1 , the hypervisor may be Figure 1 In the framework shown in FIG. 200 , the client may be Figure 1 The client 300 in the framework shown. Figure 2 As shown, the video memory management method may include the following steps:
[0087] Step 210: Obtain a first remaining video memory of a first client in a computer device; the first client is one of one or more clients; the first remaining video memory is unoccupied video memory in the video memory allocated to the first client.
[0088] The first remaining video memory is the video memory allocated to the first client and not occupied by programs or processes in the first client.
[0089] In an embodiment of the present application, each client can work independently, and the program or process running in the operating system (GuestOS) of each client can call the vGPU in the current client to perform tasks. In the process of the program or process calling the vGPU to perform tasks, a portion of the video memory allocated to the current client can be occupied to store data read or output when the vGPU performs tasks; optionally, when the program or process calls the vGPU to perform a task, the previously occupied video memory can be released.
[0090] In one possible implementation, the first remaining video memory is the remaining video memory in the video memory allocated to the first client, excluding the video memory that meets the current application requirements of the first client; specifically, when calling the vGPU to execute a task, the program or process in the first client will apply to the first client for occupying the video memory required for the task, and at a certain moment in the task execution process, only a portion of the video memory applied for by the program or process may be written with the task data; and in the above-mentioned embodiment of the present application, the video memory occupied by the program or process in the first client refers to the video memory applied for by the program or process in the first client, which includes the video memory in which the task data has been written, and a portion of the video memory in which the task data has not been written. Therefore, the capacity of the video memory occupied by the program or process in the first client will usually be larger than the capacity of the video memory in which the task data has been written.
[0091] For example, assuming that the video memory capacity allocated to the first client is 10Mb, at a certain moment, 6Mb of the video memory capacity of the 10Mb video memory is occupied by applications or processes, and 4Mb of the video memory capacity of the 6Mb video memory has been written with task data. At this time, 6Mb of the video memory allocated to the first client has been occupied, not 4Mb.
[0092] The obtaining of the first remaining video memory of the first client in the computer device may refer to obtaining the capacity of the first remaining video memory of the first client.
[0093] Alternatively, the obtaining of the first remaining video memory of the first client in the computer device may also refer to obtaining a video memory address corresponding to the first remaining video memory of the first client.
[0094] The first remaining video memory of the first client may be the remaining video memory of the first client at the current moment.
[0095] Alternatively, the first remaining video memory of the first client may be an average value of the remaining video memory of the first client at each time point in a time period of a specified length before the current time point.
[0096] Alternatively, the first remaining video memory of the first client may be a weighted average of the remaining video memory of the first client at each time point in a time period of a specified length before the current time point.
[0097] Step 220: adjusting the capacity of the video memory of the first client according to the capacity of the first remaining video memory and the video memory capacity threshold.
[0098] In the embodiment of the present application, when the computer device adjusts the capacity of the video memory of the first client, the capacity of the remaining video memory of the first client can be controlled within a specified capacity range.
[0099] Among them, if the remaining video memory capacity of the first client is too large, it means that there are more video memories in the first client in an idle state, which affects the utilization of the video memory of the first client. Conversely, if the remaining video memory capacity of the first client is too small, it means that the video memory of the first client is insufficient, which affects the performance of the first client. In this regard, the solution shown in the embodiment of the present application controls the capacity of the remaining video memory of the first client within a specified capacity range, which can avoid the client (i.e., virtual machine) from having too low video memory utilization or insufficient video memory, thereby taking into account both the video memory utilization and the operating performance of the virtual machine.
[0100] Specifically, in the embodiments of the present application, the video memory allocated to each client is not fixed but dynamically adjusted; during the process of each client using the video memory, if the remaining capacity of the video memory of client 1 increases and the remaining capacity of the video memory of client 2 decreases, it means that client 1 is currently "idle" (video memory utilization is low, and there is surplus video memory), while client 2 is currently "busy" (video memory utilization is high, and there is insufficient video memory). At this time, the computer device can adjust the capacity of the video memory of client 1 and client 2 respectively, which is equivalent to "lending" part of the video memory of client 1 to client 2.
[0101] In an embodiment of the present application, the computer device can determine whether to adjust the capacity of the video memory of the first client and the method of adjusting the capacity of the video memory of the first client based on the relationship between the capacity of the first remaining video memory and the video memory capacity threshold.
[0102] When it is determined that the capacity of the video memory of the first client needs to be adjusted, the capacity of the video memory of the first client is increased or decreased according to the corresponding adjustment method. For example, when the capacity of the remaining video memory of the first client is large, the capacity of the video memory of the first client can be reduced, and when the capacity of the remaining video memory of the first client is small, the capacity of the video memory of the first client can be increased, so that the remaining capacity of the video memory of the first client can be limited within a suitable capacity range; performing corresponding processing on multiple clients through the above scheme is equivalent to dynamically transferring the video memory of the client with a larger remaining video memory capacity to the client with a smaller remaining video memory capacity.
[0103] Among them, the above-mentioned specified capacity interval can be a capacity interval pre-set by developers or managers; or, the above-mentioned specified capacity interval can also be a capacity interval dynamically set by the computer device. For example, the above-mentioned specified capacity interval can be a capacity interval set by the computer device based on the capacity of the video memory of the physical GPU that has not yet been allocated to each client.
[0104] In summary, the embodiment of the present application provides a scheme for dynamically managing the video memory of a vGPU according to the capacity of the remaining video memory of the client where the vGPU is located. For a client, when the occupancy rate of the video memory allocated to the client is low (more remaining video memory), it means that the utilization rate of the video memory exclusively occupied by the vGPU of the client is low, and at this time, a part of the video memory allocated to the client can be recovered; when the occupancy rate of the video memory allocated to the client is high (less remaining video memory), it means that the utilization rate of the video memory exclusively occupied by the vGPU of the client is high, and at this time, new video memory can be allocated to the client; through the above scheme, the capacity of the remaining video memory of each client can be controlled within a certain capacity range. From the perspective of the entire virtual machine system, the above scheme can achieve the effect of transferring a part of the video memory exclusively occupied by the client with insufficient video memory utilization to the client with higher video memory utilization, thereby improving the overall utilization rate of the video memory of the physical GPU.
[0105] Furthermore, because the solution provided in the embodiment of the present application improves the overall utilization of the video memory of the physical GPU, in a scenario where some vGPUs are idle and the rest of the vGPUs are busy, the physical GPU can access more video memory rather than system memory, thereby improving the work efficiency of the physical GPU.
[0106] based on Figure 2 For the examples shown, please refer to Figure 3 , which shows a method flow chart of a video memory management method involved in an embodiment of the present application. Figure 3 As shown, the above step 220 may include the following steps.
[0107] Step 220a: When the capacity of the first remaining video memory is greater than the first video memory capacity threshold, reclaim part of the video memory from the video memory allocated to the first client.
[0108] In an embodiment of the present application, when the capacity of the first remaining video memory is greater than the first video memory capacity threshold, it can be considered that the utilization rate of the video memory allocated to the first client is insufficient, and a large amount of video memory is in an idle state. At this time, a portion of the video memory allocated to the first client can be recovered to reduce the capacity of the video memory allocated to the first client, thereby releasing a portion of the video memory previously allocated to the first client, thereby preventing the first client from occupying this portion of the video memory for a long time.
[0109] The above-mentioned reclaiming part of the video memory from the video memory allocated to the first client may refer to releasing part of the video memory of the physical GPU that has been allocated to the first client, that is, setting it as unallocated video memory.
[0110] In some embodiments, the capacity of the first remaining video memory being greater than the first video memory capacity threshold may mean that the capacity of the first remaining video memory most recently acquired is greater than the first video memory capacity threshold; or, the capacity of the first remaining video memory being greater than the first video memory capacity threshold may mean that the capacity of the first remaining video memory acquired for the last N times is greater than the first video memory capacity threshold, where N is an integer greater than or equal to 2.
[0111] Step 220b: when the capacity of the first remaining video memory is less than the second video memory capacity threshold, additionally allocate new video memory for the first client; wherein the first video memory capacity threshold is greater than the second video memory capacity threshold.
[0112] Optionally, the capacity interval between the first video memory capacity threshold and the second video memory capacity threshold is the specified capacity interval. Alternatively, the capacity interval between the first video memory capacity threshold and the second video memory capacity threshold may also be a subset of the specified capacity interval.
[0113] In an embodiment of the present application, when the capacity of the first remaining video memory is less than the second video memory capacity threshold, it can be considered that the utilization rate of the video memory allocated to the first client is high, and the first client may have insufficient video memory. At this time, new video memory can be additionally allocated to the first client to increase the capacity of the video memory allocated to the first client, so that the first client can use more video memory.
[0114] The additional allocation of new video memory to the first client may refer to additional allocation of an unallocated portion of the video memory of the physical GPU to the first client.
[0115] In some embodiments, the capacity of the first remaining video memory being less than the second video memory capacity threshold may mean that the capacity of the first remaining video memory most recently acquired is less than the second video memory capacity threshold; or, the capacity of the first remaining video memory being less than the second video memory capacity threshold may mean that the capacity of the first remaining video memory acquired for the last N times is less than the second video memory capacity threshold.
[0116] The first video memory capacity threshold and the second video memory capacity threshold may be thresholds preset by a developer.
[0117] Alternatively, the first video memory capacity threshold and the second video memory capacity threshold may also be thresholds set by a computer device. For example, the computer device may set the first video memory capacity threshold and the second video memory capacity threshold according to the capacity of the unallocated video memory in the video memory of the physical GPU; for example, the computer device may query the capacity of the unallocated video memory in the video memory of the physical GPU, and determine the first video memory capacity threshold and the second video memory capacity threshold by the corresponding relationship between the capacity of the unallocated video memory in the video memory of the physical GPU and the first video memory capacity threshold and the second video memory capacity threshold; for another example, the computer device may input the capacity of the unallocated video memory in the video memory of the physical GPU into a preset calculation formula to obtain the first video memory capacity threshold and the second video memory capacity threshold.
[0118] based on Figure 3 For the examples shown, please refer to Figure 4 , which shows a framework diagram of a video memory management involved in an embodiment of the present application. Figure 4 As shown, a hypervisor, a client 410 and a client 420 are running in the computer device, and the client 410 and the client 420 have respective allocated video memories.
[0119] At time 1, among the video memory allocated to client 410, the capacity of the remaining video memory 410a is less than the second video memory capacity threshold, and among the video memory allocated to client 420, the capacity of the remaining video memory 420a is greater than the first video memory capacity threshold. At this time, the video memory allocated to client 410 and client 420 is adjusted. Specifically, the unallocated video memory in video memory 430 is allocated to client 410, and a portion of the video memory allocated to client 420 is released.
[0120] At time 2 after the video memory is adjusted, the video memory capacity allocated to client 410 is increased compared to that at time 1, while the video memory capacity allocated to client 420 is decreased compared to that at time 1.
[0121] In a possible implementation, step 220a may be implemented as follows: when the capacity of the first remaining video memory is greater than the first video memory capacity threshold and the capacity of the video memory allocated to the first client is greater than the video memory capacity lower limit, reclaim part of the video memory from the video memory allocated to the first client.
[0122] In an embodiment of the present application, in order to avoid the first client having insufficient video memory after releasing the video memory, a lower limit of the video memory capacity can be set in advance. When the capacity of the video memory of the first client is greater than the lower limit of the video memory capacity, a portion of the video memory allocated to the first client is released.
[0123] For example, assuming that the above-mentioned video memory capacity lower limit is 100M, when the capacity of the first remaining video memory is greater than the first video memory capacity threshold, if the capacity of the video memory allocated to the first client is greater than 100M (for example, the capacity of the video memory allocated to the first client is 150M), the computer device can release a portion of the video memory allocated to the first client (for example, release 50M). Optionally, if the capacity of the video memory allocated to the first client is not greater than 100M (for example, the capacity of the video memory allocated to the first client is equal to 100M), the computer device will no longer release the video memory allocated to the first client.
[0124] In a possible implementation, step 220b may be implemented as follows: when the capacity of the first remaining video memory is less than the second video memory capacity threshold and the video memory capacity allocated to the first client is less than the video memory capacity upper limit, additional video memory is allocated to the first client.
[0125] In an embodiment of the present application, in order to prevent the first client from obtaining video memory without restriction, thereby squeezing the video memory capacity of other clients, an upper limit of the video memory capacity can be set in advance. When the video memory capacity of the first client is less than the upper limit of the video memory capacity, a new portion of video memory is allocated to the first client.
[0126] For example, assuming that the above-mentioned upper limit of the video memory capacity is 200M, when the capacity of the first remaining video memory is less than the second video memory capacity threshold, if the capacity of the video memory allocated to the first client is less than 200M (for example, the capacity of the video memory allocated to the first client is 150M), the computer device may newly allocate a portion of the video memory for the first client (for example, newly allocate 50M). Optionally, if the capacity of the video memory allocated to the first client is not less than 200M (for example, the capacity of the video memory allocated to the first client is equal to 200M), the computer device will no longer allocate new video memory to the first client.
[0127] based on Figure 3 For the examples shown, please refer to Figure 5 , which shows a method flow chart of a video memory management method involved in this application. Figure 5 As shown, the above step 220a may include step 220a1 and step 220a2.
[0128] Step 220a1: when the capacity of the first remaining video memory is greater than the first video memory capacity threshold, send a first video memory management request to the management program through the first client, the first video memory management request includes a first video memory address; the first video memory address is all or part of the address of the first remaining video memory.
[0129] Herein, step 220a1 may be executed by the first client in the computer device; for example, step 220a1 may be executed by a client-side video memory management process running in the first client.
[0130] In an embodiment of the present application, dynamic management of video memory can be achieved through interaction between a client and a hypervisor; for example, when a first client detects that the utilization rate of the video memory allocated to it is insufficient, it can actively request to release a portion of the video memory that it exclusively uses. At this time, the first client can send a request to the hypervisor (i.e., the above-mentioned first video memory management request) to notify the hypervisor of the address of the video memory that needs to be released.
[0131] Step 220a2: adding the first video memory corresponding to the first video memory address to a video memory pool through the management program, where the video memory pool is used to store video memory that is not allocated to the client.
[0132] In the embodiment of the present application, the video memory pool is used to store video memory that is not allocated to the client, which may refer to the video memory pool being used to store identifiers (such as addresses) of video memory that is not allocated to the client.
[0133] The step 220a2 may be executed by a hypervisor in the computer device; for example, the step 220a1 may be executed by a hypervisor-side video memory management process running in the hypervisor.
[0134] In the embodiment of the present application, after receiving the first video memory management request sent by the first client, the management program can add the video memory corresponding to the video memory address carried in the first video memory management request to the video memory pool.
[0135] The adding of the first video memory to the video memory pool may refer to adding an identifier (such as an address) of the first video memory to the video memory pool.
[0136] Optionally, the capacity of the first video memory may be a capacity preset by a developer or administrator.
[0137] Alternatively, the capacity of the first video memory may also be a capacity determined by the first client according to the capacity of the first remaining video memory. For example, the first client may query the corresponding relationship between the capacity of the remaining video memory and the capacity of the released video memory according to the capacity of the first remaining video memory to obtain the capacity of the first video memory; for another example, the first client may input the capacity of the first remaining video memory into a preset calculation formula to obtain the capacity of the first video memory output by the calculation formula. Optionally, in the case where the capacity of the first video memory is determined by the first client according to the capacity of the first remaining video memory, the capacity of the first video memory may be positively correlated with the capacity of the first remaining video memory, that is, the larger the capacity of the first remaining video memory is, the larger the capacity of the first video memory is.
[0138] Through the scheme shown in the embodiment of the present application, dynamic release of video memory can be achieved through interaction between the first client and the hypervisor. Specifically, when the first client detects that the utilization rate of the video memory allocated to it is insufficient, it notifies the hypervisor to release a part of the video memory of the first client. The hypervisor does not need to obtain the information of the first remaining video memory from the first client. This can simplify the interaction between the hypervisor and the first client in dynamic management of video memory and simplify the calculation process on the hypervisor side, thereby improving the operating efficiency of the virtual machine system.
[0139] Based on the above Figure 4 In the solution shown, in a possible implementation manner, before sending the first video memory management request to the hypervisor through the first client, the method further includes:
[0140] When the capacity of the first remaining video memory is greater than the first video memory capacity threshold, the first video memory address is locked by the first client; the video memory address locked by the first client is a video memory address that is prohibited from being accessed by a program or process in the first client.
[0141] In the embodiment of the present application, the process of the first client locking the first video memory address may be as follows:
[0142] When the capacity of the first remaining video memory is greater than the first video memory capacity threshold, the first client / the client-side video memory management process running in the first client may apply for video memory from the first operating system; the first operating system is the operating system running in the first client; when the video memory of the first capacity is applied for, the first client / the client-side video memory management process requests the first operating system to lock the first video memory address corresponding to the applied video memory; wherein the video memory address locked by the first operating system is a video memory address that is prohibited from being accessed by applications or processes in the first operating system.
[0143] Taking the above steps being performed by the client-side video memory management process in the first client as an example, since multiple applications or processes can be run simultaneously in the first client, these applications or processes may occupy new video memory at any time. In order to avoid the first video memory being occupied by other applications or processes in the first client during the process in which the client-side video memory management process requests to release the first video memory, the following steps may be performed:
[0144] S1, before requesting to release the video memory, the client-side video memory management process may first apply to the first operating system for a certain capacity (ie, the first capacity) of video memory as the first video memory to be released.
[0145] S2, the first operating system may simultaneously process multiple requests for video memory sent by different applications or processes. When processing the request of the client-side video memory management process, the video memory of the first capacity mentioned above can be allocated to the client-side video memory management process from the video memory unused by the first client. If the capacity of the video memory currently unused by the first client is greater than or equal to the first capacity, it can be determined that the allocation is successful, for example, a mapping relationship between the address of the video memory of the first capacity and the client-side video memory management process is established, and a response of successful application is returned to the client-side video memory management process. If the capacity of the video memory currently unused by the first client is less than the first capacity, it can be determined that the allocation has failed, and a response of failed application is returned to the client-side video memory management process.
[0146] Alternatively, if the capacity of the currently unused video memory of the first client is smaller than the first capacity, the first operating system may first allocate the currently unused video memory of the first client to the client-side video memory management process, and the client-side video memory management process may subsequently continue to apply for the remaining required video memory; for example, the above-mentioned first capacity is 50M, and when the first operating system processes the application of the client-side video memory management process, the capacity of the currently unused video memory of the first client is 30M, then the first operating system may first allocate 30M of video memory to the client-side video memory management process, and then the client-side video memory management process may again apply to the first operating system for the remaining 20M of video memory.
[0147] S3: If the client-side video memory management process applies for video memory of sufficient capacity, it may request the first operating system in the first client to lock the video memory address of the applied video memory.
[0148] S4, if the client-side video memory management process fails to apply for sufficient video memory, it can continue to apply for video memory until sufficient video memory is applied for; if sufficient video memory cannot be applied for for a long time, the client-side video memory management process can stop applying for video memory.
[0149] Accordingly, the above step 220a1 may be implemented as follows: when the first video memory address is locked successfully, sending a first video memory management request to the hypervisor through the first client.
[0150] In an embodiment of the present application, if the first operating system successfully locks the first video memory address, it means that the first video memory address will not be occupied by other applications or processes in the first client. At this time, the client-side video memory management process in the first client can send a first video memory management request to the management program.
[0151] Optionally, if the first video memory address is not locked successfully, the client-side video memory management process in the first client may release the previously applied video memory and reapply for video memory.
[0152] For example, when locking the first video memory address, the first operating system can detect whether there is data in the first video memory address, or detect whether the video memory corresponding to the first video memory address is occupied by other applications or processes. If yes, it is determined that the locking of the first video memory address has failed, otherwise, the first video memory address is locked. Afterwards, the first operating system sends a response of locking success or failure to the client-side video memory management process, so that the client-side video memory management process sends a first video memory management request to the management program according to the response of locking success, or releases the previously applied video memory according to the response of locking failure.
[0153] The first operating system locks the first video memory address by marking the first video memory address as locked. Accordingly, the first operating system can process the video memory application of the application or process in the first client according to the state of the local video memory address (locked state / unlocked state).
[0154] For example, when the first operating system receives an application or process in the first client for a video memory application, it can query the video memory addresses in the unlocked state for the video memory addresses that are not currently occupied, and then allocate video memory to the application or process based on the video memory addresses that are not currently occupied. For example, a mapping relationship is established between all or part of the video memory addresses that are not currently occupied and the application or process (indicating that the application or process has applied for and occupied the video memory corresponding to this part of the video memory addresses), and this part of the video memory addresses is indicated to the application or process so that the application or process can access (such as write, modify or read, etc.) this part of the video memory addresses.
[0155] Based on the solutions shown in the above embodiments, please refer to Figure 6 , which shows a framework diagram of a video memory management involved in an embodiment of the present application. Figure 6As shown, the first client 610 maintains a video memory address 610a, in which a portion of the addresses in an unlocked state correspond to the addresses of the video memory allocated to the first client 610; the hypervisor side maintains a video memory pool 620a, in which the addresses of the video memory not allocated to the client are stored; when the video memory utilization rate of the first client 610 is not high, the process of releasing the video memory may be as follows:
[0156] S1, the client-side video memory management process in the first client 610 applies to the first operating system for the video memory to be released, and requests to lock the video memory address (ie, the first video memory address) corresponding to the video memory to be released.
[0157] S2: The first operating system locks the first video memory address in the video memory address 610a.
[0158] S3, the client-side video memory management process sends a first video memory management request to the hypervisor-side video memory management process in the hypervisor 620, wherein the request includes a first video memory address of the video memory to be released.
[0159] S4, the video memory management process of the hypervisor end adds the address of the corresponding video memory to the video memory pool 620a according to the first video memory address.
[0160] Through the scheme shown in the embodiment of the present application, the first client can lock the part of the video memory that needs to be released in the operating system of the first client before applying to the management program to release the video memory, thereby avoiding errors caused by the first video memory being occupied by other applications or processes in the first client during the process of the client-side video memory management process requesting to release the first video memory, thereby ensuring the accuracy of video memory release.
[0161] Based on the solutions shown in the above embodiments, in a possible implementation, the first video memory address is the address of the first video memory in the first client, and the above step 220a2 can be implemented as follows:
[0162] Step 220a2-1: query the second video memory address according to the first video memory address through the management program; the second video memory address is the address of the first video memory in the management program.
[0163] In an embodiment of the present application, the video memory addresses corresponding to the same video memory may be different in the hypervisor and the client. For example, in the client, the video memory can be represented by a logical address (or linear address), so that the application or process can access the video memory according to the logical address; while in the hypervisor, since it is necessary to call the physical GPU to access the real video memory, the hypervisor needs to know the physical address corresponding to the video memory. To this end, the hypervisor can pre-set the mapping relationship between the address of the video memory in the client (logical address) and the address of the video memory in the hypervisor (physical address). After obtaining the above-mentioned first video memory address, the hypervisor can query the corresponding second video memory address through the above-mentioned mapping relationship.
[0164] Step 220a2-2: Add the second video memory address to the video memory pool through the hypervisor.
[0165] After the hypervisor queries the second video memory address, the second video memory address may be added to the video memory pool.
[0166] Optionally, the management program may also delete the mapping relationship between the first video memory address and the second video memory address.
[0167] Through the scheme shown in the embodiment of the present application, when the addresses of the same video memory in the client and the hypervisor are different, the hypervisor can first convert the address of the video memory indicated by the client to be released into the address of the video memory in the hypervisor, and put the converted address into a video memory pool, thereby uniformly managing the addresses of the video memories of different clients on the hypervisor side, thereby ensuring the accuracy and efficiency of dynamic management of video memory.
[0168] In the scheme shown in the above embodiment of the present application, the management program queries the second video memory address corresponding to the first video memory address. Optionally, in other embodiments, the above scheme of querying the second video memory address corresponding to the first video memory address can also be executed by the first client. For example, the first client maintains a mapping relationship between the first video memory address and the second video memory address. Before sending the first video memory management request, the first client can query the mapping relationship between the first video memory address and the second video memory address to obtain the second video memory address, and carry the second video memory address in the first video memory management request to the management program. After receiving the above first video memory management request, the management program adds the second video memory address carried in the first video memory management request to the video memory pool.
[0169] Based on the solutions shown in the above embodiments, in a possible implementation, the hypervisor maintains a mapping relationship between the client and the address of the video memory assigned to the client in the hypervisor; the above method may also include: canceling the mapping relationship between the first client and the second video memory address through the hypervisor.
[0170] Since different clients work independently, they may use the same address system. That is to say, different video memories may correspond to the same address in different clients. At this time, if the hypervisor only maintains the mapping relationship between the address of the video memory in the client (such as the logical address) and the address of the video memory in the hypervisor (such as the physical address), the same logical address may correspond to multiple physical addresses, resulting in subsequent business errors.
[0171] With regard to the above-mentioned problem, in an embodiment of the present application, in addition to maintaining the mapping relationship between the logical address of the video memory in the client and the physical address of the video memory, the hypervisor may also maintain the mapping relationship between the physical address of the video memory and the client corresponding to the video memory. Subsequently, when the client requests the hypervisor to call the physical GPU to access a certain video memory A, the call request carries the client's identifier and the logical address of video memory A; the hypervisor may first query the mapping relationship between the physical address of the video memory and the client corresponding to the video memory through the identifier of the client (such as the client's ID) to obtain the physical address of the video memory corresponding to the client, and then query the physical address of video memory A from the physical address of the video memory corresponding to the client based on the mapping relationship between the logical address of the video memory in the client and the physical address of the video memory, as well as the logical address of video memory A.
[0172] Correspondingly, when the hypervisor adds the second video memory address to the video memory pool, it means that the first client can no longer call the physical GPU to access the first video memory. At this time, the hypervisor needs to cancel the mapping relationship between the first client and the second video memory address (for example, delete the mapping relationship) to avoid errors in the subsequent tasks of the first client calling the physical GPU to access the video memory.
[0173] Based on the solutions shown in one or more of the above embodiments, please refer to Figure 7 , which shows a method flow chart of a video memory management method involved in this application. Figure 7 As shown, the above step 220b may include step 220b1 and step 220b2.
[0174] Step 220b1: when the capacity of the first remaining video memory is less than the second video memory capacity threshold, send a second video memory management request to the hypervisor through the first client.
[0175] Herein, step 220b1 may be executed by the first client in the computer device; for example, step 220b1 may be executed by a client-side video memory management process running in the first client.
[0176] In an embodiment of the present application, when the first client detects that the utilization rate of the video memory allocated to it is high and the video memory is insufficient, it can actively request more video memory. At this time, the first client can send a request to the hypervisor (i.e., the above-mentioned second video memory management request) to request the hypervisor to allocate more video memory to the first client.
[0177] Step 220b2: through the management program, additionally allocate the second video memory in the video memory pool to the first client according to the second video memory management request, and the video memory pool is used to store the video memory that is not allocated to the client.
[0178] Herein, step 220b2 may be executed by a hypervisor in the computer device; for example, step 220b2 may be executed by a hypervisor-side video memory management process running in the hypervisor.
[0179] In the embodiment of the present application, after receiving the second video memory management request sent by the first client, the management program can additionally allocate a portion of the video memory in the video memory pool to the first client.
[0180] Optionally, the capacity of the second video memory may be a capacity preset by a developer or administrator.
[0181] Alternatively, the capacity of the second video memory may also be the capacity determined and requested by the first client according to the capacity of the first remaining video memory. For example, the first client may query the corresponding relationship between the capacity of the remaining video memory and the capacity of the newly requested video memory according to the capacity of the first remaining video memory to obtain the capacity of the second video memory; for another example, the first client may input the capacity of the first remaining video memory into a preset calculation formula to obtain the capacity of the second video memory output by the calculation formula. Optionally, in the case where the capacity of the second video memory is determined by the first client according to the capacity of the first remaining video memory, the capacity of the second video memory may be inversely correlated with the capacity of the first remaining video memory, that is, the smaller the capacity of the first remaining video memory is, the larger the capacity of the second video memory is.
[0182] Alternatively, the capacity of the second video memory may also be a capacity determined by the management program based on the available video memory in the video memory pool. For example, the management program may query the corresponding relationship between the capacity of the available video memory in the video memory pool and the capacity of the second video memory based on the capacity of the available video memory in the video memory pool to obtain the capacity of the second video memory; for another example, the management program may input the capacity of the available video memory in the video memory pool into a preset calculation formula to obtain the capacity of the second video memory output by the calculation formula. Optionally, in the case where the capacity of the second video memory is determined by the management program based on the capacity of the available video memory in the video memory pool, the capacity of the second video memory may be positively correlated with the capacity of the available video memory in the video memory pool, that is, the larger the capacity of the available video memory in the video memory pool, the larger the capacity of the second video memory.
[0183] Through the scheme shown in the embodiment of the present application, dynamic allocation of video memory can be achieved through the interaction between the first client and the hypervisor. Specifically, when the first client detects that the utilization rate of the video memory allocated to it is high, it notifies the hypervisor to allocate more video memory to the first client. The hypervisor does not need to obtain the information of the first remaining video memory from the first client. The interaction between the hypervisor and the first client in the dynamic management of video memory can be simplified, and the calculation process on the hypervisor side can be simplified, thereby improving the operating efficiency of the virtual machine system.
[0184] Based on the above Figure 7 In the solution provided by the embodiment shown, in a possible implementation manner, the above step 220b2 can be implemented as the following steps:
[0185] Step 220b2-1: when the video memory in the video memory pool is sufficient, remove the third video memory address from the video memory pool through the hypervisor; the third video memory address is the address of the second video memory in the hypervisor.
[0186] In an embodiment of the present application, after receiving the second video memory management request, the hypervisor may first determine whether the video memory in the video memory pool is sufficient; for example, whether the capacity of the video memory in the video memory pool is greater than a certain threshold. Optionally, the threshold may be a pre-set threshold. If the hypervisor determines that the video memory in the video memory pool is sufficient, the second video memory corresponding to the third video memory address in the video memory address may be additionally allocated to the first client. At this time, the third video memory address needs to be removed from the video memory pool to prevent the third video memory address from being reallocated to other clients.
[0187] Step 220b2-2: Send a video memory management response to the first client through the management program, where the video memory management response is used to indicate that the first client is allocated the second video memory.
[0188] In an embodiment of the present application, the hypervisor may notify the first client of the newly allocated video memory via a video memory management response.
[0189] The video memory management response may include one or more of the following information:
[0190] A video memory allocation success indication, used to indicate that the first client successfully requested the new video memory; capacity information of the second video memory; and a third video memory address of the second video memory.
[0191] When the capacity of the second video memory is a preset capacity and the video memory management response carries a video memory allocation success indication, the first client can determine the video memory with the preset capacity allocated according to the video memory allocation success indication.
[0192] When the video memory management response carries the capacity information of the second video memory, the first client may determine the video memory to which the capacity indicated by the capacity information is allocated based on the capacity information of the second video memory.
[0193] When the video memory management response carries the third video memory address of the second video memory, the first client can determine, based on the third video memory address, that the video memory corresponding to the third video memory address is allocated.
[0194] Step 220b2-3: unlocking the fourth video memory address according to the video memory management response through the first client; the fourth video memory address is the address of the second video memory in the first client.
[0195] In the embodiment of the present application, after the first client receives the above-mentioned video memory management response, the first operating system in the first client can allocate the fourth video memory address that was previously locked to the second video memory, and unlock the fourth video memory address, so that the application or process in the first client can subsequently apply for the use of the second video memory through the fourth video memory address. The video memory capacity corresponding to the fourth video memory address is the same as the video memory capacity corresponding to the third video memory address.
[0196] The unlocking of the fourth video memory address may refer to marking the fourth video memory address as being in an unlocked state, or may refer to deleting a locking mark of the fourth video memory address.
[0197] Optionally, in a case where the video memory management response carries the third video memory address of the second video memory, the first client may also establish a mapping relationship between the third video memory address and the fourth video memory address in the first client.
[0198] Step 220b2-4: Send the fourth video memory address to the management program through the first client.
[0199] After the first client allocates the fourth video memory address to the second video memory, it is also necessary to notify the management program of the fourth video memory address so that the management program can subsequently determine the second video memory that the first client calls the physical GPU to access through the fourth video memory address.
[0200] Step 220b2-5: Establish a mapping relationship between the third video memory address and the fourth video memory address through the management program.
[0201] After the hypervisor receives the fourth video memory address sent by the first client, it can establish a mapping relationship between the third video memory address and the fourth video memory address. When an application or process in the first client subsequently uses the second video memory, the first client can send a call request containing the fourth video memory address to the hypervisor. At this time, the hypervisor can query the corresponding third video memory address according to the fourth video memory address, and call the physical GPU to access the second video memory based on the third video memory address.
[0202] Based on the solutions shown in the above embodiments, please refer to Figure 8 , which shows a framework diagram of a video memory management involved in an embodiment of the present application. Figure 8 As shown, the first client 810 maintains a video memory address 810a, in which a portion of the address in an unlocked state corresponds to the address of the video memory allocated to the first client 810; the hypervisor side maintains a video memory pool 820a, and the video memory pool 820a stores the address of the video memory that is not allocated to the client; when the video memory utilization rate is high, the process of the first client 810 requesting allocation of new video memory can be as follows:
[0203] S1, the client-side video memory management process in the first client 810 sends a second video memory management request to the hypervisor-side video memory management process in the hypervisor 820.
[0204] S2, when the video memory pool of the hypervisor end video memory management process is sufficient, removes a certain capacity of video memory from the video memory pool corresponding to the video memory address in the management process (ie, the third video memory address, which may be a physical address, for example).
[0205] S3, the hypervisor-side video memory management process sends a video memory management response to the client-side video memory management process to indicate that a new video memory (ie, the second video memory) is allocated to the first client 810.
[0206] S4, the client-side video memory management process instructs the first operating system to unlock the new video memory at video memory address 810a, corresponding to the video memory address in the first client 810 (ie, the fourth video memory address, which may be a logical address, for example).
[0207] S5, the client-side video memory management process notifies the hypervisor-side video memory management process of the video memory address (fourth video memory address) corresponding to the new video memory in the first client 810.
[0208] S6, the memory management process of the hypervisor side establishes a mapping relationship 820b between the third memory address and the fourth memory address.
[0209] Through the scheme shown in the embodiment of the present application, when the hypervisor classifies new video memory for the first client, the hypervisor and the first client can interact to unlock the address of the newly allocated video memory in the first client on the first client side, and establish a mapping relationship between the address of the newly allocated video memory in the first client and the address of the newly allocated video memory in the hypervisor in the hypervisor, so that the first client can subsequently accurately access this part of the newly allocated video memory through the hypervisor, thereby ensuring the accuracy of subsequent video memory allocation.
[0210] Based on the solutions shown in the above embodiments, in a possible implementation, the hypervisor maintains a mapping relationship between the client and the address of the video memory assigned to the client in the hypervisor; the above method also includes: establishing a mapping relationship between the first client and the third video memory address through the hypervisor.
[0211] For the problem that different video memories may correspond to the same address in different clients, in the embodiment of the present application, after the hypervisor allocates the second video memory in the video memory pool to the first client, it is necessary to establish a mapping relationship between the first client and the third video memory address to avoid errors in the subsequent task of the first client calling the physical GPU to access the video memory.
[0212] Based on the solutions shown in the above embodiments, in a possible implementation, the above step 220b1 can be implemented as the following steps: when the video memory allocated to the first client does not meet the exchange condition, the first client sends a second video memory management request to the hypervisor. The exchange condition includes the following conditions:
[0213] There is no swappable video memory in the video memory allocated to the first client, and the swappable video memory is the video memory that has been occupied and can be replaced by the system memory; or,
[0214] There is exchangeable video memory in the video memory allocated to the first client, and the sum of the capacity of the exchangeable video memory and the capacity of the first remaining video memory is less than the second video memory capacity threshold.
[0215] In an embodiment of the present application, different applications or processes may be run in the first client, and different applications or processes may have different requirements for video memory and system memory. For example, some applications or processes can only use video memory, some applications or processes can use both video memory and system memory, and some applications or processes can only use system memory. When the video memory occupancy rate in the first client is high and the video memory is insufficient, the first client may first consider exchanging the occupied video memory through the system memory managed by the first operating system, thereby releasing a portion of the video memory in the first client. Specifically, for example, for some applications or processes that can use both video memory and system memory, when the application or process occupies the video memory, if the remaining video memory of the first client is insufficient, and more video memory can be released after exchanging the video memory occupied by the application or process through the system memory, then there is no need to request new video memory from the hypervisor (that is, sending a second video memory management request to the hypervisor), thereby avoiding frequent application for new video memory and ensuring the accuracy of video memory allocation. On the contrary, if the application or process that can use both video memory and system memory currently does not occupy video memory, or only occupies less video memory, it needs to request new video memory from the hypervisor.
[0216] Based on the solutions shown in the above embodiments, in a possible implementation, the method further includes: when the video memory in the video memory pool is insufficient, sending a video memory recovery request to the second client through the hypervisor; the second client is a client other than the first client among the clients running in the computer device; through the second client, sending a third video memory management request to the hypervisor according to the video memory recovery request, the third video memory management request including a fifth video memory address; the fifth video memory address is all or part of the address of the second remaining video memory of the second client; and adding the third video memory corresponding to the fifth video memory address to the video memory pool through the hypervisor.
[0217] In an embodiment of the present application, when the video memory in the video memory pool is insufficient, the management program can also actively reclaim video memory with low utilization rate from each client, thereby improving the success rate of allocating new video memory to the first client, and further ensuring the effect of dynamic allocation of video memory.
[0218] Specifically, when the video memory in the video memory pool is insufficient, the management program can send a video memory recovery request to other clients other than the first client, and the video memory recovery request can trigger other clients to request the release of their unused video memory. The manner in which other clients request the release of their unused video memory is similar to the manner in which the first client actively requests the release of its unused first video memory, which will not be repeated here.
[0219] Correspondingly, if the second client successfully releases the video memory to the hypervisor and there is sufficient video memory in the video memory pool, the hypervisor can allocate the second video memory to the first client.
[0220] The second client is a client other than the first client among the clients running in the computer device, and the capacity of the allocated video memory is greater than the third video memory capacity threshold. That is to say, when the video memory in the video memory pool is insufficient during the process of allocating video memory for the first client by the computer device, it can request to reclaim the video memory from other clients that have been allocated more video memory (also called over-allocated video memory). For clients that have over-allocated video memory, the probability that they can release video memory is also higher. Therefore, the above scheme can improve the success rate of reclaiming video memory from other clients, thereby ensuring the efficiency of dynamic management of video memory.
[0221] Optionally, the step of sending a video memory recovery request to the second client through the hypervisor when the video memory in the video memory pool is insufficient may also be performed independently by the hypervisor, that is, regardless of whether there is a client requesting allocation of new video memory, as long as the hypervisor detects that the video memory in the video memory pool is insufficient (the video memory capacity in the video memory pool is lower than a certain threshold), the hypervisor may send the video memory recovery request to each client. In this case, the second client may be a client running in the computer device, the capacity of which is allocated to a video memory greater than the third video memory capacity threshold.
[0222] Based on the solutions shown in the above embodiments, in a possible implementation manner, the process of sending the third video memory management request to the hypervisor according to the video memory recycling request through the second client may include:
[0223] When the capacity of the second remaining video memory is greater than the third video memory capacity threshold, a third video memory management request is sent to the management program through the second client according to the video memory recycling request.
[0224] In an embodiment of the present application, after the second client receives a video memory recovery request, if its own remaining video memory capacity is sufficient, it can directly send a third video memory management request to the management program, thereby releasing the video memory while ensuring that its own video memory usage is not affected, thereby achieving the dynamic allocation effect of the client's video memory and the client's operating efficiency.
[0225] Based on the solutions shown in the above embodiments, in a possible implementation, the method further includes: when the capacity of the second remaining video memory is not greater than a third video memory capacity threshold, querying the capacity of the exchangeable video memory in the video memory of the second client through the second client; the exchangeable video memory is the video memory that has been occupied and allows replacement by the system memory; when the sum of the capacity of the exchangeable video memory in the video memory of the second client and the capacity of the second remaining video memory is greater than the third video memory capacity threshold, replacing the exchangeable video memory in the video memory of the second client through the system memory.
[0226] In the embodiment of the present application, after the second client receives the video memory recycling request, if the capacity of its own remaining video memory is insufficient, it can try to replace the swappable cache locally through the system memory. Optionally, if the capacity of the remaining video memory after the second client replaces the swappable video memory is sufficient, a third video memory management request can be sent to the hypervisor; conversely, if the capacity of the remaining video memory after the second client replaces the swappable video memory is still insufficient, a response of recycling failure can be fed back to the hypervisor.
[0227] Through the scheme shown in the embodiment of the present application, after the second client receives a video memory recovery request, if its own remaining video memory capacity is insufficient, it can try to perform memory swapping, that is, swapping the occupied video memory with the system memory, thereby improving the success rate of video memory release while ensuring that its own video memory usage is not affected, thereby improving the effect of dynamic video memory management.
[0228] Through the solutions shown in the above embodiments of the present application, a solution for dynamic management of video memory in a GPU virtualization scenario can be implemented. Specifically, when some vGPUs are idle, these vGPUs (a) are allowed to "lend" the video memory allocated to them to the Hypervisor again. The Hypervisor can allocate this part of the video memory to the vGPU (b) with a heavier load. When the load of vGPU (a) increases and more video memory is required, the Hypervisor reclaims the video memory from vGPU (b) and "returns" it to vGPU (a) to meet its video memory needs. While making full use of hardware resources, the fairness of vGPU resource use can also be guaranteed.
[0229] Unlike the solution that allocates and fixes the video memory when creating a vGPU, the above solution of this application allows the vGPU to dynamically adjust its video memory during operation. When a vGPU is idle, the unused video memory is "lent" to the Hypervisor. When a vGPU is busy and the Hypervisor has remaining video memory, the vGPU can use excess video memory. While making full use of hardware resources, it can also prevent the computing units in the GPU from using system memory, thereby affecting its computing performance.
[0230] For example, the above solution may include the following steps:
[0231] Step 1: When creating a vGPU, you can specify three parameters: minimum video memory (SizeA), default video memory (SizeB), and maximum video memory (SizeC). These three values increase in sequence. By default, the size of the video memory available to the vGPU is SizeB. When the vGPU load is light, try to reduce its available video memory to SizeA. When the vGPU load is heavy, try to increase its available video memory to SizeC.
[0232] Step 2: When the available video memory needs to be reduced (SizeB->SizeA), the driver running in the guest tries to apply for video memory (the size is SizeB-SizeA). If it can be applied for, the driver will keep this part of the video memory to ensure that it will not be allocated to other applications. The driver then notifies the address of this part of the video memory to the hypervisor for its recovery.
[0233] Step 3: When the available video memory needs to be increased (SizeB->SizeC), the driver running in the Guest (corresponding to the video memory management process on the client side) sends a message to the Hypervisor to query the remaining video memory. If there is enough video memory on the Hypervisor, the address of this part of the video memory is notified to the Guest driver for its use.
[0234] Step 4: The Hypervisor periodically checks the Guest's load. If it needs to forcibly reclaim video memory from the Guest (the video memory used by the Guest exceeds SizeB), the Hypervisor sends a request for forced reclaim to the Guest, and the Guest driver will try to allocate system memory and migrate / swap the excess video memory to the system memory to release video memory resources.
[0235] Based on the solutions shown in the above embodiments, please refer to Fig. 9 , which shows a framework diagram of a video memory management involved in an embodiment of the present application. Fig. 9 As shown, a hypervisor 910, a client 920 and a client 930 are running in the host, wherein vGPUs are respectively established in the client 920 and the client 930, and video memory is respectively allocated to the client 920 and the client 930, wherein there are three types of video memory capacities, from small to large, Size A, Size B and Size C. Taking the client 920 initiating a video memory management request as an example, the process of video memory management involved in the present application can be as follows:
[0236] S1, the client 920 determines to initiate video memory management according to the relationship between the capacity of the remaining video memory in the currently allocated video memory and the video memory capacity threshold, and requests the hypervisor 910 to release or allocate video memory.
[0237] For example, when the video memory capacity allocated to the client 920 is Size B or Size C, and the remaining video memory capacity is greater than the first video memory capacity threshold, the client 920 may request the hypervisor 910 to release the video memory.
[0238] For another example, when the video memory capacity allocated to the client 920 is SizeA or SizeB, and the capacity of the remaining video memory is less than the second video memory capacity threshold, the client 920 may request the hypervisor 910 to allocate video memory.
[0239] S2 , the hypervisor 910 releases a portion of the video memory allocated to the client 920 according to the request of the client 920 , or allocates new video memory to the client 920 .
[0240] For example, when the client 920 requests the hypervisor 910 to release the video memory, the hypervisor 910 releases a portion of the video memory of the client 920 to the video memory pool 910a.
[0241] For another example, when the client 920 requests the hypervisor 910 to allocate video memory, the hypervisor 910 may allocate part of the video memory in the video memory pool 910 a to the client 920 .
[0242] S3: When the video memory in the video memory pool 910a is insufficient, the hypervisor 910 sends a video memory reclaim request to the client 930 to request the client 930 to release the video memory.
[0243] S4, the client 930 determines whether to release the video memory to the video memory pool according to the usage of the currently allocated video memory.
[0244] For example, if the video memory capacity allocated to the client 930 is Size B or Size C, and the remaining video memory capacity is sufficient, the video memory can be directly released to the video memory pool.
[0245] For another example, if the video memory capacity allocated to client 930 is Size B or Size C, and the remaining video memory capacity is insufficient, you can try to use memory to swap out the video memory. If the remaining video memory capacity is sufficient after the swap, you can release the video memory to the video memory pool. If the remaining video memory capacity is still insufficient after the swap, you can refuse to release the video memory.
[0246] For another example, if the video memory capacity allocated to the client 930 is SizeA, the video memory may be directly refused to be released.
[0247] The execution processes of the client and the hypervisor are respectively as follows: Figures 10 to 12 shown.
[0248] Please refer to Fig.10 , which shows a framework diagram of the client actively requesting video memory management involved in this application.
[0249] like Fig.10 As shown, the process of the client side actively requesting to release or allocate video memory can be as follows:
[0250] S1001, collecting statistics on the video memory usage of the client.
[0251] For example, the client-side video memory management process in the client can obtain the capacity of the remaining video memory in the video memory allocated to the client, and when the capacity of the remaining video memory is greater than a certain threshold (the above-mentioned first video memory capacity threshold), enter step S1002; when the capacity of the remaining video memory is less than a certain threshold (the above-mentioned second video memory capacity threshold), enter step S1006.
[0252] S1002, requesting video memory from the operating system in the client.
[0253] The client-side video memory management process may apply to the operating system in the client for the video memory to be released. If not enough video memory is applied for, then continue to execute step S1002, otherwise, execute step S1003.
[0254] S1003, requesting the operating system to lock the requested video memory. If the locking is successful, executing step S1004, otherwise, executing step S1005.
[0255] S1004, sending the address information of the requested video memory to the management program in the host.
[0256] For example, the client-side video memory management process may send a first video memory management request including a first video memory address (logical address) to the management program to request the release of the video memory corresponding to the first video memory address, and return to step S1001.
[0257] S1005, release the requested video memory and return to step S1001.
[0258] The client-side video memory management process can return the previously released video memory to the first operating system in the client.
[0259] S1006, determining whether the exchange conditions are met.
[0260] The client-side video memory management process can determine whether the occupied video memory can be swapped out through the system memory, and whether the remaining video memory after the swap is still less than the second video memory capacity threshold. If so, proceed to step S1007, otherwise, return to step S1001.
[0261] S1007, apply for new video memory from the hypervisor in the host.
[0262] The client-side video memory management process may send a second video memory management request to the management program. If a response indicating successful allocation is received from the management program, the process proceeds to step S1008, otherwise the process returns to step S1001.
[0263] S1008, searching for the previously locked video memory address (logical address) according to the information returned by the management program.
[0264] S1009, releasing the locked video memory addresses to the operating system, allowing the operating system to allocate these video memory addresses to applications or processes in the client.
[0265] Optionally, the client-side video memory management process may also notify the management program of the released video memory addresses, and the management program establishes a mapping relationship between the released video memory addresses and the physical addresses of the video memory newly allocated to the client.
[0266] Please refer to Fig.11 , which shows a framework diagram of the management program involved in this application performing video memory management. Fig.11 As shown, the process of releasing or allocating video memory according to the client's request is as follows:
[0267] S1101, receiving a video memory management request from a client.
[0268] S1102, receiving a request to release video memory, proceeding to step S1103.
[0269] S1103, query the corresponding physical address according to the address information (logical address) in the request.
[0270] S1104, cancel the mapping relationship between this part of logical addresses and physical addresses.
[0271] S1105, saving the queried physical address to the video memory pool.
[0272] S1106, complete video memory release and return to step S1101.
[0273] S1107, receiving a request for allocating video memory, proceeding to step S1108.
[0274] S1108, determine whether the video memory pool has enough video memory, if so, go to step S1109, otherwise, go to step S1113.
[0275] S1109, searching the video memory pool for video memory that meets the allocated capacity.
[0276] S1110, mapping the video memory found in the video memory pool to the client.
[0277] For example, the hypervisor in the host establishes a mapping relationship between the physical address of this part of the video memory and the client.
[0278] S1111, synchronize the mapping information to the client.
[0279] For example, the hypervisor in the host notifies the client of the allocation request of this part of the video memory, so that the client knows that it is allocated new video memory.
[0280] S1112, video memory allocation is completed, and return to step S1101.
[0281] S1113, searching for a client computer that uses excessive video memory in the host computer.
[0282] For example, the hypervisor may query the host for clients (such as client 930) that have been allocated a video memory capacity of SizeC.
[0283] S1114, sending a video memory reclaim request to the queried client, and returning to step S1101.
[0284] Please refer to Fig.12 , which shows a framework diagram of the client involved in this application releasing video memory according to the request of the management program. Fig.12 As shown, the process of the client releasing the video memory according to the request of the hypervisor can be as follows:
[0285] S1201, receiving a message from a management program.
[0286] S1202, receiving a video memory recycling request sent by the hypervisor, if the remaining video memory is sufficient, proceed to S1203, otherwise, proceed to S1204.
[0287] S1203, releasing video memory to the video memory pool. For the execution process, please refer to Fig.10 Steps S1002 to S1005 in .
[0288] S1204, try to replace the occupied video memory with system memory.
[0289] The client may attempt to replace the occupied video memory with the system memory so that the remaining video memory meets the release condition. If the replacement is successful and the remaining video memory meets the release condition after the replacement, the process proceeds to step S1203; otherwise, the process proceeds to step S1205.
[0290] S1205, sending a response of recycling failure to the hypervisor in the host.
[0291] The above solution can realize the time-sharing utilization of GPU resources by vGPUs in different clients, and can effectively utilize video memory resources when different clients are running different loads at the same time. Specifically, by dynamically adjusting the video memory of each client, resource utilization can be effectively improved and the total cost of ownership (TCO) can be reduced; and when multiple clients are running different loads, the heavily loaded client can obtain better performance; at the same time, adjusting the video memory according to the client's load can avoid client performance loss.
[0292] Please refer to Fig.13 , which shows a block diagram of a video memory management device provided by an exemplary embodiment of the present application, and the video memory management device can implement all or part of the steps in the above-mentioned various method embodiments. Fig.13 As shown, the video memory management device may include:
[0293] The remaining video memory acquisition module 1301 is used to acquire a first remaining video memory of a first client in a computer device; a hypervisor and one or more clients are running in the computer device; each of the clients is allocated a portion of the video memory in the physical GPU of the computer device as the video memory of the virtual GPU in the client; the first client is one of the one or more clients; the first remaining video memory is the unoccupied video memory allocated to the first client;
[0294] The video memory allocation module 1302 is used to adjust the capacity of the video memory of the first client according to the capacity of the first remaining video memory and the video memory capacity threshold.
[0295] In a possible implementation, the video memory allocation module 1302 is used to:
[0296] When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, reclaiming part of the video memory from the video memory allocated to the first client;
[0297] When the capacity of the first remaining video memory is less than the second video memory capacity threshold, additionally allocating new video memory for the first client;
[0298] The first video memory capacity threshold is greater than the second video memory capacity threshold.
[0299] In a possible implementation, the video memory allocation module 1302 is used to:
[0300] When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, sending a first video memory management request to the management program through the first client, wherein the first video memory management request includes a first video memory address; the first video memory address is all or part of the address of the first remaining video memory;
[0301] The management program adds the first video memory corresponding to the first video memory address to a video memory pool, where the video memory pool is used to store video memory that is not allocated to the client.
[0302] In a possible implementation manner, the device further includes:
[0303] an address locking module, configured to lock the first video memory address through the first client before the video memory allocation module 1302 sends the first video memory management request to the hypervisor through the first client, if the capacity of the first remaining video memory is greater than a first video memory capacity threshold; the video memory address locked by the first client is a video memory address that is prohibited from being accessed by a program or process in the first client;
[0304] The video memory allocation module 1302 is configured to send the first video memory management request to the management program through the first client when the first video memory address is successfully locked.
[0305] In a possible implementation, the video memory allocation module 1302 is used to:
[0306] querying a second video memory address according to the first video memory address through the management program; the second video memory address is the address of the first video memory in the management program;
[0307] The second video memory address is added to the video memory pool by the management program.
[0308] In a possible implementation, the hypervisor maintains a mapping relationship between the client and an address of a video memory allocated to the client in the hypervisor; the device further includes:
[0309] A mapping cancellation module is used to cancel the mapping relationship between the first client and the second video memory address through the management program.
[0310] In a possible implementation, the video memory allocation module 1302 is used to:
[0311] When the capacity of the first remaining video memory is less than a second video memory capacity threshold, sending a second video memory management request to the management program through the first client;
[0312] The management program allocates the second video memory in the video memory pool to the first client according to the second video memory management request, wherein the video memory pool is used to store the video memory that is not allocated to the client.
[0313] In a possible implementation, the video memory allocation module 1302 is configured to send the second video memory management request to the hypervisor through the first client when the video memory allocated to the first client does not meet the exchange condition;
[0314] The exchange conditions include the following:
[0315] There is no swappable video memory in the video memory allocated to the first client, and the swappable video memory is a video memory that has been occupied and can be replaced by the system memory; or,
[0316] There is exchangeable video memory in the video memory allocated to the first client, and the sum of the capacity of the exchangeable video memory and the capacity of the first remaining video memory is less than the second video memory capacity threshold.
[0317] In a possible implementation, the video memory allocation module 1302 is used to:
[0318] When the video memory in the video memory pool is sufficient, removing a third video memory address from the video memory pool through the management program; the third video memory address is the address of the second video memory in the management program;
[0319] Sending a video memory management response to the first client through the management program, wherein the video memory management response is used to indicate that the first client is allocated the second video memory;
[0320] unlocking, by the first client, a fourth video memory address according to the video memory management response; the fourth video memory address is an address of the second video memory in the first client;
[0321] sending the fourth video memory address to the management program through the first client;
[0322] A mapping relationship between the third video memory address and the fourth video memory address is established through the management program.
[0323] In a possible implementation, the hypervisor maintains a mapping relationship between the client and an address of a video memory allocated to the client in the hypervisor; the device further includes:
[0324] A mapping relationship establishing module is used to establish a mapping relationship between the first client and the third video memory address through the management program.
[0325] In a possible implementation manner, the device further includes:
[0326] a video memory recycling module, configured to send a video memory recycling request to a second client through the management program when the video memory in the video memory pool is insufficient; the second client is a client other than the first client among the clients running in the computer device;
[0327] The video memory allocation module 1302 is further used to send a third video memory management request to the management program through the second client according to the video memory recovery request, wherein the third video memory management request includes a fifth video memory address; the fifth video memory address is all or part of the address of the second remaining video memory of the second client; and the third video memory corresponding to the fifth video memory address is added to the video memory pool through the management program.
[0328] In a possible implementation, the video memory allocation module 1302 is configured to send a third video memory management request to the management program through the second client according to the video memory recycling request when the capacity of the second remaining video memory is greater than a third video memory capacity threshold.
[0329] In a possible implementation, the video memory allocation module 1302 is further configured to:
[0330] When the capacity of the second remaining video memory is not greater than the third video memory capacity threshold, querying the capacity of the swappable video memory in the video memory of the second client through the second client; the swappable video memory is the video memory that has been occupied and can be replaced by the system memory;
[0331] When the sum of the capacity of the swappable video memory in the video memory of the second client and the capacity of the second remaining video memory is greater than the third video memory capacity threshold, the swappable video memory in the video memory of the second client is replaced by the system memory.
[0332] In a possible implementation, the video memory allocation module 1302 is used to reclaim part of the video memory from the video memory allocated to the first client when the capacity of the first remaining video memory is greater than the first video memory capacity threshold and the capacity of the video memory allocated to the first client is greater than the video memory capacity lower limit.
[0333] In a possible implementation, the video memory allocation module 1302 is used to allocate additional video memory to the first client when the capacity of the first remaining video memory is less than the second video memory capacity threshold and the video memory capacity allocated to the first client is less than the video memory capacity upper limit.
[0334] Please refer to Fig.14 , Fig.1414 is a schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application. The computer device 1400 includes a central processing unit (CPU) 1401, a system memory 1404 including a random access memory (RAM) 1402 and a read-only memory (ROM) 1403, and a system bus 1405 connecting the system memory 1404 and the central processing unit 1401. The computer device 1400 also includes a basic input / output system (I / O system) 1406 that helps transmit information between various devices in the computer, and a large-capacity storage device 1407 for storing an operating system 1413, application programs 1414 and other program modules 1415.
[0335] The basic input / output system 1406 includes a display 1408 for displaying information and an input device 1409 such as a mouse and a keyboard for user inputting information. The display 1408 and the input device 1409 are connected to the central processing unit 1401 through an input / output controller 1410 connected to the system bus 1405. The basic input / output system 1406 may also include an input / output controller 1410 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 1410 also provides output to a display screen, a printer, or other types of output devices.
[0336] The mass storage device 1407 is connected to the central processing unit 1401 through a mass storage controller (not shown) connected to the system bus 1405. The mass storage device 1407 and its associated computer readable medium provide non-volatile storage for the computer device 1400. That is, the mass storage device 1407 may include a computer readable medium (not shown) such as a hard disk or a CD-ROM (Compact Disc Read-Only Memory) drive.
[0337] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM (Random Access Memory), ROM (Read-Only Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electrically Erasable Programmable Read-Only Memory), flash memory or other solid-state storage technologies, CD-ROM, DVD (Digital Video Disc) or other optical storage, cassettes, tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the above. The above-mentioned system memory 1404 and mass storage device 1407 can be collectively referred to as memory.
[0338] The computer device 1400 can be connected to the Internet or other network devices through a network interface unit 1411 connected to the system bus 1405 .
[0339] The memory also includes one or more programs / instructions, which are stored in the memory. The central processing unit 1401 implements all or part of the steps in the methods shown in the above-mentioned embodiments of the present application by executing the one or more programs / instructions.
[0340] In an exemplary embodiment, a computer program product is also provided, the computer program product includes computer instructions, the computer instructions are stored in a computer-readable storage medium. The processor of the computer device reads and executes the computer instructions from the computer-readable storage medium to implement all or part of the steps of the method shown in the above embodiments of the present application.
[0341] In an exemplary embodiment, a computer-readable storage medium is further provided, in which instructions are stored. The instructions are loaded and executed by a processor to implement all or part of the steps of the method shown in the above-mentioned embodiments of the present application.
[0342] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0343] The above are only optional embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A video memory management method, characterized in that: The method is performed by a computer device, wherein one or more clients are running in the computer device; each of the clients is allocated a portion of the video memory in the physical graphics processor GPU of the computer device as the video memory of the virtual GPU in the client; The method comprises: Acquire a first remaining video memory of a first client; the first client is one of the one or more clients; the first remaining video memory is an unoccupied video memory in the video memory allocated to the first client; The capacity of the video memory of the first client is adjusted according to the capacity of the first remaining video memory and the video memory capacity threshold.
2. The method according to claim 1, characterized in that The step of adjusting the capacity of the video memory of the first client according to the capacity of the first remaining video memory and the video memory capacity threshold comprises: When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, reclaiming part of the video memory from the video memory allocated to the first client; When the capacity of the first remaining video memory is less than the second video memory capacity threshold, additionally allocating new video memory for the first client; The first video memory capacity threshold is greater than the second video memory capacity threshold.
3. The method according to claim 2, characterized in that The computer device further runs a management program, and when the capacity of the first remaining video memory is greater than a first video memory capacity threshold, reclaiming part of the video memory from the video memory allocated to the first client comprises: When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, sending a first video memory management request to the management program through the first client, wherein the first video memory management request includes a first video memory address; the first video memory address is all or part of the address of the first remaining video memory; The management program adds the first video memory corresponding to the first video memory address to a video memory pool, where the video memory pool is used to store video memory that is not allocated to the client.
4. The method according to claim 3, characterized in that Before sending the first video memory management request to the management program through the first client, the method further includes: When the capacity of the first remaining video memory is greater than a first video memory capacity threshold, locking the first video memory address through the first client; the video memory address locked by the first client is a video memory address that is prohibited from being accessed by a program or process in the first client; The sending a first video memory management request to the hypervisor through the first client comprises: When the first video memory address is locked successfully, the first video memory management request is sent to the management program through the first client.
5. The method according to claim 3, characterized in that: The first video memory address is an address of the first video memory in the first client, and adding the first video memory corresponding to the first video memory address to a video memory pool through the hypervisor includes: querying a second video memory address according to the first video memory address through the management program; the second video memory address is the address of the first video memory in the management program; The second video memory address is added to the video memory pool by the management program.
6. The method according to claim 2, characterized in that The computer device further runs a management program, and when the capacity of the first remaining video memory is less than the second video memory capacity threshold, additionally allocating new video memory to the first client includes: When the capacity of the first remaining video memory is less than a second video memory capacity threshold, sending a second video memory management request to the management program through the first client; The management program allocates the second video memory in the video memory pool to the first client according to the second video memory management request, wherein the video memory pool is used to store the video memory that is not allocated to the client.
7. The method according to claim 6, characterized in that The sending of the second video memory management request to the hypervisor through the first client comprises: When the video memory allocated to the first client does not satisfy the exchange condition, sending the second video memory management request to the hypervisor through the first client; The exchange conditions include the following: There is no swappable video memory in the video memory allocated to the first client, and the swappable video memory is a video memory that has been occupied and can be replaced by the system memory; or, There is exchangeable video memory in the video memory allocated to the first client, and the sum of the capacity of the exchangeable video memory and the capacity of the first remaining video memory is less than the second video memory capacity threshold.
8. The method according to claim 6, characterized in that The additionally allocating the second video memory in the video memory pool to the first client according to the second video memory management request by the management program includes: When the video memory in the video memory pool is sufficient, removing a third video memory address from the video memory pool through the management program; the third video memory address is the address of the second video memory in the management program; Sending a video memory management response to the first client through the management program, wherein the video memory management response is used to indicate that the first client is allocated the second video memory; unlocking, by the first client, a fourth video memory address according to the video memory management response; the fourth video memory address is an address of the second video memory in the first client; sending the fourth video memory address to the management program through the first client; A mapping relationship between the third video memory address and the fourth video memory address is established through the management program.
9. The method according to claim 6, characterized in that The method further comprises: When the video memory in the video memory pool is insufficient, sending a video memory reclaim request to a second client through the management program; the second client is a client other than the first client among the clients running in the computer device; Sending, by the second client, a third video memory management request to the management program according to the video memory recycling request, wherein the third video memory management request includes a fifth video memory address; the fifth video memory address is all or part of the address of the second remaining video memory of the second client; The third video memory corresponding to the fifth video memory address is added to the video memory pool through the management program.
10. The method according to claim 9, characterized in that The sending, through the second client, a third video memory management request to the management program according to the video memory recycling request comprises: When the capacity of the second remaining video memory is greater than a third video memory capacity threshold, a third video memory management request is sent to the management program through the second client according to the video memory recycling request.
11. The method according to claim 10, characterized in that The method further comprises: When the capacity of the second remaining video memory is not greater than the third video memory capacity threshold, querying the capacity of the swappable video memory in the video memory of the second client through the second client; the swappable video memory is the video memory that has been occupied and can be replaced by the system memory; When the sum of the capacity of the swappable video memory in the video memory of the second client and the capacity of the second remaining video memory is greater than the third video memory capacity threshold, the swappable video memory in the video memory of the second client is replaced by the system memory.
12. The method according to any one of claims 2 to 10, characterized in that: The step of reclaiming part of the video memory from the video memory allocated to the first client when the capacity of the first remaining video memory is greater than the first video memory capacity threshold comprises: When the capacity of the first remaining video memory is greater than the first video memory capacity threshold and the capacity of the video memory allocated to the first client is greater than the video memory capacity lower limit, part of the video memory is recovered from the video memory allocated to the first client.
13. The method according to any one of claims 2 to 10, characterized in that: The method of additionally allocating new video memory to the first client when the capacity of the first remaining video memory is less than the second video memory capacity threshold comprises: When the capacity of the first remaining video memory is less than the second video memory capacity threshold and the video memory capacity allocated to the first client is less than the video memory capacity upper limit, additional video memory is allocated to the first client.
14. A video memory management device, characterized in that: The device comprises: A remaining video memory acquisition module is used to acquire a first remaining video memory of a first client in a computer device; one or more clients are running in the computer device; each of the clients is allocated a portion of video memory in a physical GPU of the computer device as video memory of a virtual GPU in the client; the first client is one of the one or more clients; the first remaining video memory is unoccupied video memory allocated to the first client; The video memory allocation module is used to adjust the capacity of the video memory of the first client according to the capacity of the first remaining video memory and the video memory capacity threshold.
15. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores instructions, and the instructions are executed by the processor to implement the video memory management method according to any one of claims 1 to 13.
16. A computer-readable storage medium, characterized in that: The storage medium stores instructions, and the instructions are executed by a processor of a computer device to implement the video memory management method according to any one of claims 1 to 13.
17. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium; the computer instructions are read and executed by a processor of a computer device to implement the video memory management method according to any one of claims 1 to 13.
Citation Information
Cited By
GPU video memory management method, system and equipment based on excess subscription and storage medium
CN120670175A
Video memory management method and apparatus, and device, storage medium and program product
WO2026145346A1