CN114077480B - Method, device, equipment and medium for sharing memory between host and virtual machine - Google Patents

Method, device, equipment and medium for sharing memory between host and virtual machine Download PDF

Info

Publication number
CN114077480B
CN114077480B CN202210057387.9A CN202210057387A CN114077480B CN 114077480 B CN114077480 B CN 114077480B CN 202210057387 A CN202210057387 A CN 202210057387A CN 114077480 B CN114077480 B CN 114077480B
Authority
CN
China
Prior art keywords
host
virtual machine
physical address
address
virtual
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210057387.9A
Other languages
Chinese (zh)
Other versions
CN114077480A (en
Inventor
张伟韬
傅唯威
邹懋
陈飞
王鲲
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Vita Technology Beijing Co ltd
Original Assignee
Vita Technology Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Vita Technology Beijing Co ltd filed Critical Vita Technology Beijing Co ltd
Priority to CN202210057387.9A priority Critical patent/CN114077480B/en
Publication of CN114077480A publication Critical patent/CN114077480A/en
Application granted granted Critical
Publication of CN114077480B publication Critical patent/CN114077480B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2596Translation of addresses of the same type other than IP, e.g. translation from MAC to MAC addresses
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45583Memory management, e.g. access or allocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45595Network integration; Enabling network access in virtual machine instances

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Power Engineering (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a method, a device, equipment and a medium for sharing a memory between a host and a virtual machine. The method comprises the following steps: establishing a communication channel between a client process of a virtual machine and a server process of a host machine, wherein the host machine is a host machine of the virtual machine; in the communication channel, completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address; and mapping the physical address of the host machine to the virtual address space of the server process. The method can perform transmission and conversion of the shared memory address based on the established communication channel, and map the physical address of the host machine to the virtual address space of the server process, thereby effectively avoiding many problems in the prior art.

Description

Method, device, equipment and medium for sharing memory between host and virtual machine
Technical Field
The embodiment of the invention relates to the technical field of virtual machines, in particular to a method, a device, equipment and a medium for sharing a memory between a host and a virtual machine.
Background
At present, high-performance distributed computing and storage are more widely used, and in combination with the mature development of cloud computing, a virtual cloud host becomes the first choice of a large number of service cloud service providers. For a large number of applications in the client/server model, a service program on the host manages real physical devices and provides virtual services for applications deployed in the virtual machine, which involve high-performance data interaction between the virtual machine and the host, and is usually done using shared memory.
In the prior art, the mainstream solutions for sharing the memory between the virtual machine and the host include two solutions: the method comprises the steps of realizing memory sharing between the virtual machine and the host machine based on a transmission channel of a virtio protocol, and realizing memory sharing between the virtual machine and the host machine based on ivshmem, namely special equipment for sharing memory between the host machine and the virtual machine or between a plurality of virtual machines.
In the first scheme, the key of the I/O virtualization is to establish an I/O request and data transmission channel between a host and a virtual machine, a virtio-pci device is presented in the virtual machine to serve as a virtual disk or a virtual network card, and a user-mode virtio, a user-mode ghost-user or a kernel-mode ghost module is used in the host to provide real I/O service, so that the I/O virtualization is realized. According to the protocol, a fixed size of memory, called vring, is shared between the virtual machine and the host for transferring I/O requests and data. However, the solution cannot be directly applied to the shared memory service, because the size of the segment of memory is fixed, the allocation and the recovery cannot be flexibly performed. And only fixed protocols can be used for transmitting I/O information, and the I/O information cannot be directly accessed to a virtual machine or a host computer at will.
In the second scheme, the ivshmem is represented as a PCI device inside the virtual machine, the shared memory area exists in the form of a PCI BAR, and the memory is shared between the construction host and the virtual machine. Firstly, the ivshmem consumes the memory space of the host machine for data transmission, so that the cost calculation is difficult, in a public cloud scene, a user usually pays according to the resource configuration of the virtual machine, and the memory space of the host machine consumed by the ivshmem cannot be embodied in the virtual machine, so that the cost calculation is difficult; secondly, the size of the ivshmem is limited, and under a large data volume scene, a virtual machine needs a large continuous memory, so that the ivshmem cannot meet the requirements of a user; furthermore, ivshmem appears as a PCI device inside the virtual machine, which limits the number of ivshmem and may lead to contention with other PCI devices due to the limited number of PCI slots.
Disclosure of Invention
The embodiment of the invention provides a method, a device, equipment and a medium for sharing a memory between a host and a virtual machine, wherein the method can be used for transmitting and converting a shared memory address based on an established communication channel and mapping a physical address of the host to a virtual address space of a server process, so that various problems in the prior art can be effectively avoided.
In a first aspect, an embodiment of the present invention provides a method for sharing a memory between a host and a virtual machine, where the method includes:
establishing a communication channel between a client process of a virtual machine and a server process of a host machine, wherein the host machine is a host machine of the virtual machine;
in the communication channel, completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address;
and mapping the physical address of the host machine to the virtual address space of the server process.
In a second aspect, an embodiment of the present invention further provides a device for sharing a memory between a host and a virtual machine, including:
the system comprises an establishing module, a processing module and a processing module, wherein the establishing module is used for establishing a communication channel between a client process of a virtual machine and a server process of a host machine, and the host machine is a host machine of the virtual machine;
the conversion module is used for completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address in the communication channel;
and the mapping module is used for mapping the physical address of the host machine to the virtual address space of the server process.
In a third aspect, an embodiment of the present invention further provides a computer device, where a virtual machine is installed on a host in the computer device, the virtual machine includes a client program, the host includes a server program, and a host deploys a vhost-vsock kernel module and an address mapping kernel module;
the computer device further comprises:
one or more processors;
storage means for storing one or more programs;
the one or more programs are executed by the one or more processors such that the one or more processors are configured to perform the method of sharing memory between a host and a virtual machine according to any embodiment of the invention.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for sharing a memory between a host and a virtual machine according to any embodiment of the present invention.
The embodiment of the invention provides a method, a device, equipment and a medium for sharing a memory between a host and a virtual machine, which comprises the steps of firstly establishing a communication channel between a client process of the virtual machine and a server process of the host, wherein the host is a host of the virtual machine; then, in the communication channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed; and finally mapping the physical address of the host machine to the virtual address space of the server process. The method can transmit and convert the shared memory address based on the established communication channel, and map the physical address of the host machine to the virtual address space of the server process, thereby effectively avoiding the problems of inflexible allocation, use and release of the shared memory, occupation of extra resources and difficult charging caused by sharing the physical memory allocated by the host machine to the virtual machine, and the problems of occupation and limited size of the virtual machine PCI slot by using the ivshmem shared memory in the prior art.
Drawings
Fig. 1 is a flowchart illustrating a method for sharing a memory between a host and a virtual machine according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating a software structure of a host in a method for sharing a memory between the host and a virtual machine according to a second embodiment of the present invention;
fig. 3 is a schematic structural diagram of a memory sharing device between a host and a virtual machine according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention.
Detailed Description
Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and the embodiments of the present invention are illustrative only and are not intended to limit the scope of the present invention.
It should be understood that the various steps recited in the method embodiments of the present invention may be performed in a different order and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the invention is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present invention are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in the present invention are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that reference to "one or more" unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present invention are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Example one
Fig. 1 is a flowchart illustrating a method for sharing a memory between a host and a virtual machine according to an embodiment of the present invention, where the method is applicable to a case of high performance data interaction between the host and the virtual machine, and the method can be executed by a memory sharing device between the host and the virtual machine, where the memory sharing device can be implemented by software and/or hardware and is generally integrated on a terminal device, where the terminal device includes, but is not limited to, a computer device in this embodiment.
As shown in fig. 1, a method for sharing a memory between a host and a virtual machine according to an embodiment of the present invention includes the following steps:
s110, establishing a communication channel between the client process of the virtual machine and the server process of the host machine.
And the host is the host of the virtual machine.
The host refers to a main body part of the computer except for input and output devices, and is also a control box for placing a motherboard and other main components, and generally includes a CPU, a memory, a motherboard, an optical drive, a power supply, and other input and output controllers and interfaces. The virtual machine is installed on a host machine and can only run on the host machine, and after the virtual machine is installed on the host machine, the host machine is a host machine of the virtual machine relative to the virtual machine.
The client process can be a program for interfacing the server, and the client can be any computer, and the server can use the service of the server as long as the client is connected with the server and authorized by the server. In the virtual machine, a user mode client program, namely a client process, with a shared memory function used by a user exists.
The server is a targeted service program, the server serves the client, and the content of the service can include providing resources for the client and protecting client data.
The communication channel can be understood as a channel for data interaction between the client process and the server process. In this embodiment, a communication channel between the client process and the server process may be established through a standard socket API, and the communication channel may be used to transmit a control signal and a shared memory address between the client process of the virtual machine and the server process of the host, and complete address translation.
In this embodiment, the communication channel may be established by a vhost-vsock kernel module.
Further, the client process of the virtual machine is a client program, the server process of the host is a server program, and the communication channel is a Socket channel, and correspondingly, establishing the communication channel between the client process of the virtual machine and the server process of the host includes: and establishing a Socket channel between the client program and the server program through a vhost-vsock kernel module.
In the client/server communication mode, Socket is abstract encapsulation of a communication channel of two parties, and a user can complete connection of the two parties by configuring parameters of the Socket and constructing the Socket and perform network communication through the channel. The core module of the vsost-vsock can be understood as a code module, and the vsost-vsock is a socket communication mode between the virtual machine and the host, similar to a standard TCP/IP protocol.
In this embodiment, a Socket connection, i.e., a Socket channel, may be established through a standard Socket API. Specifically, Socket connection may include: using a standard socket API communication interface, the host and each virtual machine have a globally unique cid as an identifier, similar to an IP address; the method comprises the steps that monitoring is carried out after cid is bound by a server process of a host, a client process of a virtual machine is connected with the server process of the host, the client process of the virtual machine receives connection, three-way handshake is realized, and then bidirectional data interaction can be carried out through a Socket channel.
Further, the establishing a Socket channel between the client program and the server program through the vhost-vsock kernel module includes: establishing a vsock server through the server program; binding a cid address for the vsock server; monitoring a vsock port bound with the cid address; and starting the client program, and connecting the vsock port bound with the cid address through the vsost-vsock kernel module to complete the establishment of a Socket channel between the client program and the server program.
Wherein, the vsock server can be understood as the vsock server. The cid address can be understood as a port address, the cid is a content identifier, and after the port of the vsock server is bound to the cid address, the port can be identified through the cid address, so that the port can be monitored. At this time, the server program in the host computer is in a state of waiting for connection until the client program in the virtual machine is started, and then the client program can be connected with the vsock port through the vsost-vsock kernel module to establish Socket connection.
And S120, completing the conversion from the physical address of the virtual machine of the shared memory page to the physical address of the host machine in the communication channel.
The shared memory page may be understood as a page that can be shared by the virtual machine and the host machine. The shared memory page may also be understood as a memory page that can be simultaneously accessed by the virtual machine and the host, and the shared memory page may include multiple anonymous pages aligned with each other, where the number of the multiple anonymous pages is not specifically limited herein. The creation of the shared memory page may be initiated by a client process of the virtual machine.
The physical address of the virtual machine can be understood as the physical address of the virtual machine, and the physical address of the host machine can be understood as the physical address of the host machine.
Specifically, the manner of completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address in the communication channel may be: and in the Socket channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed through a vhost-vsock kernel module.
In this embodiment, a message transmitted in a Socket channel may be intercepted in a vhost-vsock kernel module to complete the conversion from a virtual machine physical address to a host machine physical address.
Specifically, in the Socket channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed through the vhost-vsock kernel module, and the conversion includes: transmitting a virtual memory allocation message to the server program through the Socket channel, wherein the message comprises the size of a shared memory page; allocating a plurality of anonymous pages with aligned pages as shared memory pages through the client program; obtaining a virtual machine physical address of the shared memory page through an address conversion interface of the client program; transmitting the virtual machine physical addresses of the shared memory pages through the Socket channels according to the distribution sequence; intercepting a first message containing the physical address of the virtual machine through a vhost-vsock kernel module; after the first message is received, the virtual machine physical address contained in the first message is analyzed through the vhost-vsock kernel module, and the virtual machine physical address is converted into a host machine physical address.
The client program in the virtual machine can send a message to the server program in the host machine through the Socket channel, and the server program in the host machine can know the memory size of the shared memory page required to be allocated by the client program in the virtual machine after receiving the message.
Obtaining the physical addresses of the virtual machines of the shared memory page may be understood as obtaining the physical addresses of the virtual machines corresponding to all anonymous pages in the shared memory page.
The distribution sequence can be a sequence for distributing a plurality of anonymous pages for the client program, and the client program in the virtual machine can correspondingly transmit the virtual machine physical addresses of all the pages according to the distribution sequence of each anonymous page through the Socket channel.
The first message can be understood as a message containing a physical address of the virtual machine, and the vhost-vsock kernel module can intercept the message containing the physical address of the virtual machine and complete the conversion from the physical address of the virtual machine to the physical address of the host machine.
S130, mapping the physical address of the host machine to the virtual address space of the server process.
In this embodiment, the shared memory page may be mapped by a server process of the host.
In this embodiment, the mapping the host physical address to the virtual address space of the server process includes: and mapping the physical address of the host machine to the virtual address space of the process of the server side through an address mapping kernel module.
The address mapping kernel module may be a module in the host, and the address mapping kernel module may be configured to map a physical address of the host to a virtual address. Here, the detailed process of mapping the host physical address to the virtual address space of the server process by the address mapping kernel module is not described in detail, and this part is not the content of the important concern of the present invention.
Specifically, the mapping the physical address of the host to the virtual address space of the server process by the address mapping kernel module includes: acquiring a second message containing a host machine physical address through the server program; and mapping the physical address of the host machine in the second message to the virtual address space of the server process through the address mapping kernel module.
The second message can be understood as a message containing a physical address of the host, and the server process of the host can acquire the second message and map the physical address of the host to a virtual address space of the host through an address mapping kernel module in the host.
The embodiment of the invention provides a method for sharing a memory between a host and a virtual machine, which comprises the steps of firstly establishing a communication channel between a client process of the virtual machine and a server process of the host; then, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed based on the communication channel; and finally mapping the host machine physical address to the virtual address space of the virtual machine. The method can transmit the shared memory address based on the established communication channel; the conversion of the shared memory address is completed through a vhost-vsock kernel module; the physical address of the host machine is mapped to the virtual address space of the server process through the address mapping kernel module, so that a plurality of problems in the prior art can be effectively avoided.
Example two
The embodiment of the invention provides a specific implementation mode on the basis of the technical scheme of each embodiment.
Fig. 2 is a schematic diagram of a software structure of a host in a method for sharing a memory between the host and a virtual machine according to a second embodiment of the present invention, as shown in fig. 2, a virtual machine 100 is installed on a host 106, and the virtual machine 100 includes a client 101; the host 106 includes a server program 102 and a Socket channel 103, and also deploys a vhost-vsock kernel module 104 and an address mapping kernel module 105.
In this embodiment, a Socket channel 103 between the client program 101 and the server program 102 may be established through a standard Socket API, the Socket channel 103 may be used to transmit control signals and share memory addresses, and complete address conversion, and the Socket channel 103 is established through a vhost-vsock kernel module 104; the shared memory page 107 can be distributed by the user side program 101, and the conversion from GPA (general purpose address), namely a virtual machine physical address, to HPA (host machine physical address), namely a host machine physical address, is completed in a kernel mode by the vhost-vsock kernel module 104 through the Socket channel 103; server-side program 102 may map the received HPAs to the virtual address space of server-side program 102 through address mapping kernel module 105.
After the host, i.e., host machine, deploys the vsost-vsock kernel module 104 and the address mapping kernel module 105, the method for sharing memory between the host machine and the virtual machine may be executed, and the method includes the following steps:
step 1, a server program 102 in a host machine establishes a vsock server, binds cid addresses and then monitors a vsock port;
step 2, starting a client program 101 in the virtual machine, connecting a vsock port through a vsost-vsock kernel module 104, and establishing a Socket channel 103;
step 3, the client program 101 sends a message to the server program 102 through the Socket channel 103, and informs the size of the virtual memory to be allocated, namely the size of the shared memory page;
step 4, the client program 101 allocates anonymous pages with aligned pages as the shared memory page 107, and obtains GPA of all pages of the shared memory page 107 through the address translation API;
step 5, the client program 101 sequentially transmits the GPA of each page through the Socket channel 103;
step 6, intercepting a message containing GPA by the vhost-vsock kernel module 104, analyzing the GPA and performing conversion from the GPA to HPA;
and step 7, the service-side program 102 acquires the message containing the HPA, and maps the HPA to the virtual address space of the service-side program through the address mapping kernel module 105.
To this end, the shared memory page 107 can be shared by the client program 101 and the server program 102.
According to the method for sharing the memory between the host and the virtual machine, which is provided by the embodiment II of the invention, the problem of flexibility of the scheme for using the shared memory in the traditional I/O virtualization is solved, and support is provided for efficient data communication of a client-server model in the host in the virtual machine; the shared memory is distributed by the virtual machines according to needs, so that the occupation of additional host machine memory and the charging difficulty are avoided; the shared memory is flexible to manage, and the number and the size of the shared memory are not limited by the outside; after the shared memory is established, the using method is the same as that of the traditional shared memory, and no extra loss is introduced.
EXAMPLE III
Fig. 3 is a schematic structural diagram of a memory sharing apparatus between a host and a virtual machine according to a third embodiment of the present invention, which is suitable for a case of high performance data interaction between the host and the virtual machine, wherein the apparatus can be implemented by software and/or hardware and is generally integrated on a computer device.
As shown in fig. 3, the apparatus includes: a setup module 110, a conversion module 120, and a mapping module 130.
An establishing module 110, configured to establish a communication channel between a client process of a virtual machine and a server process of a host machine, where the host machine is a host machine of the virtual machine;
a translation module 120, configured to complete, in the communication channel, translation from a virtual machine physical address of a shared memory page to a host machine physical address, where the shared memory page is shared by the virtual machine and the host machine;
a mapping module 130, configured to map the host physical address to a virtual address space of the server process.
In this embodiment, the apparatus first establishes a communication channel between a client process of a virtual machine and a server process of a host machine through an establishing module 110, where the host machine is a host machine of the virtual machine; then, the conversion module 120 completes the conversion from the virtual machine physical address of the shared memory page to the host machine physical address in the communication channel; and finally, mapping the physical address of the host machine to the virtual address space of the server process through a mapping module 130.
The embodiment provides a device for sharing a memory between a host and a virtual machine, which is based on an establishing module, a converting module and a mapping module, and can effectively avoid the problems of inflexible allocation, use and release of a shared memory, occupation of extra resources and difficulty in charging caused by sharing of a physical memory allocated by the host to the virtual machine, and the problems of occupation and limited size of a virtual machine PCI slot by using an ivshmem shared memory in the prior art.
Further, a client process of the virtual machine is a client program, a server process of the host is a server program, the communication channel is a Socket channel, and correspondingly, the establishing module 110 is specifically configured to: and establishing a Socket channel between the client program and the server program through a vhost-vsock kernel module.
On the basis of the optimization, establishing a Socket channel between the client program and the server program through a vhost-vsock kernel module comprises the following steps: establishing a vsock server through the server program; binding a cid address for the vsock server; monitoring a vsock port bound with the cid address; and starting the client program, and connecting the vsock port bound with the cid address through the vsost-vsock kernel module to complete the establishment of a Socket channel between the client program and the server program.
Further, the conversion module 120 is specifically configured to: and in the Socket channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed through the vhost-vsock kernel module.
Based on the above technical solution, in the Socket channel, the completing, by the vhost-vsock kernel module, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address includes: transmitting a virtual memory allocation message to the server program through the Socket channel, wherein the message comprises the size of a shared memory page; allocating a plurality of anonymous pages with aligned pages as shared memory pages through the client program; obtaining a virtual machine physical address of the shared memory page through an address conversion interface of the client program; transmitting the virtual machine physical addresses of the shared memory page through the Socket channel according to the distribution sequence; intercepting a first message containing the physical address of the virtual machine through a vhost-vsock kernel module; after the first message is received, the virtual machine physical address contained in the first message is analyzed through the vhost-vsock kernel module, and the virtual machine physical address is converted into a host machine physical address.
Further, the mapping module 130 is specifically configured to: and mapping the physical address of the host machine to the virtual address space of the server process through an address mapping kernel module.
Based on the above technical solution, the mapping the physical address of the host to the virtual address space of the server process by the address mapping kernel module includes: acquiring a second message containing a host machine physical address through the server process; and mapping the physical address of the host machine in the second message to the virtual address space of the server process through the address mapping kernel module.
The device for sharing the memory between the host and the virtual machine can execute the method for sharing the memory between the host and the virtual machine provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
Example four
Fig. 4 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention. As shown in fig. 4, a computer device provided in the fourth embodiment of the present invention includes: one or more processors 41 and storage 42; the processor 41 in the computer device may be one or more, and fig. 4 illustrates one processor 41 as an example; storage 42 is used to store one or more programs; the one or more programs are executed by the one or more processors 41, so that the one or more processors 41 implement the method for sharing memory between a host and a virtual machine according to any one of the embodiments of the present invention.
In the host 45 of the computer device, a virtual machine is installed on the host 45, the virtual machine includes a client program, the host 45 includes a server program, and a vhost-vsock kernel module and an address mapping kernel module are deployed in the host 45.
The computer device may further include: an input device 43 and an output device 44.
The processor 41, the storage device 42, the input device 43, the output device 44, and the host 45 in the computer apparatus may be connected by a bus or other means, and the bus connection is exemplified in fig. 4.
The storage device 42 in the computer apparatus is used as a computer-readable storage medium for storing one or more programs, which may be software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the method for sharing memory between a host and a virtual machine according to one or both embodiments of the present invention (for example, the modules in the memory sharing device between a host and a virtual machine shown in fig. 3 include the establishing module 110, the converting module 120, and the mapping module 130). The processor 41 executes various functional applications and data processing of the computer device by executing software programs, instructions and modules stored in the storage device 42, that is, implements the memory sharing method between the host and the virtual machine in the above method embodiments.
The storage device 42 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the computer device, and the like. Further, the storage 42 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some examples, storage 42 may further include memory located remotely from processor 41, which may be connected to the device over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 43 may be used to receive input numeric or character information and to generate key signal inputs related to user settings and function controls of the computer apparatus. The output device 44 may include a display device such as a display screen.
And, when one or more programs included in the above-described computer apparatus are executed by the one or more processors 41, the programs perform the following operations:
establishing a communication channel between a client process of a virtual machine and a server process of a host machine, wherein the host machine is a host machine of the virtual machine;
in the communication channel, completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address;
and mapping the physical address of the host machine to the virtual address space of the server process.
EXAMPLE five
An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program is used, when executed by a processor, to execute a method for sharing a memory between a host and a virtual machine, where the method includes:
establishing a communication channel between a client process of a virtual machine and a server process of a host machine, wherein the host machine is a host machine of the virtual machine;
in the communication channel, completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address;
and mapping the physical address of the host machine to the virtual address space of the server process.
Optionally, the program, when executed by the processor, may be further configured to execute the method for sharing a memory between a host and a virtual machine according to any embodiment of the present invention.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read Only Memory (ROM), an Erasable Programmable Read Only Memory (EPROM), a flash Memory, an optical fiber, a portable CD-ROM, an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. A computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take a variety of forms, including, but not limited to: an electromagnetic signal, an optical signal, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, Radio Frequency (RF), etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing description is only exemplary of the invention and that the principles of the technology may be employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (9)

1. A method for sharing a memory between a host and a virtual machine, the method comprising:
establishing a communication channel between a client process of a virtual machine and a server process of a host machine, wherein the host machine is a host machine of the virtual machine;
in the communication channel, completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address;
mapping the host machine physical address to a virtual address space of the server process;
the communication channel is a Socket channel, and correspondingly, in the communication channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed, including: and in the Socket channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed through a vhost-vsock kernel module.
2. The method according to claim 1, wherein the client process of the virtual machine is a client program, the server process of the host machine is a server program, and accordingly, establishing a communication channel between the client process of the virtual machine and the server process of the host machine comprises:
and establishing a Socket channel between the client program and the server program through a vhost-vsock kernel module.
3. The method of claim 2, wherein establishing a Socket channel between the client program and the server program through a vhost-vsock kernel module comprises:
establishing a vsock server through the server program;
binding a cid address for the vsock server;
monitoring a vsock port bound with the cid address;
and starting the client program, and connecting the vsock port bound with the cid address through the vsost-vsock kernel module to complete the establishment of a Socket channel between the client program and the server program.
4. The method of claim 1, wherein the completing, in the Socket channel, the translation from the virtual machine physical address of the shared memory page to the host machine physical address by the vhost-vsock kernel module comprises:
transmitting a virtual memory allocation message to a server program through the Socket channel, wherein the message comprises the size of a shared memory page;
allocating a plurality of anonymous pages with aligned pages as shared memory pages through a client program;
obtaining a virtual machine physical address of the shared memory page through an address conversion interface of the client program;
transmitting the virtual machine physical addresses of the shared memory page through the Socket channel according to the distribution sequence;
intercepting a first message containing the physical address of the virtual machine through a vhost-vsock kernel module;
after the first message is received, the virtual machine physical address contained in the first message is analyzed through the vhost-vsock kernel module, and the virtual machine physical address is converted into a host machine physical address.
5. The method of claim 1, wherein mapping the host physical address to the virtual address space of the server process comprises:
and mapping the physical address of the host machine to the virtual address space of the server process through an address mapping kernel module.
6. The method of claim 5, wherein mapping the host physical address to the virtual address space of the server process by an address mapping kernel module comprises:
acquiring a second message containing a host machine physical address through the server process;
and mapping the physical address of the host machine in the second message to the virtual address space of the server process through the address mapping kernel module.
7. An apparatus for sharing memory between a host and a virtual machine, the apparatus comprising:
the system comprises an establishing module, a processing module and a processing module, wherein the establishing module is used for establishing a communication channel between a client process of a virtual machine and a server process of a host machine, and the host machine is a host machine of the virtual machine;
the conversion module is used for completing the conversion from the virtual machine physical address of the shared memory page to the host machine physical address in the communication channel;
the mapping module is used for mapping the physical address of the host machine to the virtual address space of the server process;
wherein, the communication channel is a Socket channel, and correspondingly, the conversion module is specifically configured to: and in the Socket channel, the conversion from the virtual machine physical address of the shared memory page to the host machine physical address is completed through a vhost-vsock kernel module.
8. A computer device is characterized in that a virtual machine is installed on a host machine in the computer device, the virtual machine comprises a client program, the host machine comprises a server program, and a vhost-vsock kernel module and an address mapping kernel module are deployed in the host machine;
the computer device further comprises:
one or more processors;
storage means for storing one or more programs;
the one or more programs being executable by the one or more processors to cause the one or more processors to perform the method of any of claims 1-6 for sharing memory between a host and a virtual machine.
9. A computer-readable storage medium on which a computer program is stored, which, when executed by a processor, implements the method of sharing memory between a host and a virtual machine according to any one of claims 1 to 6.
CN202210057387.9A 2022-01-19 2022-01-19 Method, device, equipment and medium for sharing memory between host and virtual machine Active CN114077480B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210057387.9A CN114077480B (en) 2022-01-19 2022-01-19 Method, device, equipment and medium for sharing memory between host and virtual machine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210057387.9A CN114077480B (en) 2022-01-19 2022-01-19 Method, device, equipment and medium for sharing memory between host and virtual machine

Publications (2)

Publication Number Publication Date
CN114077480A CN114077480A (en) 2022-02-22
CN114077480B true CN114077480B (en) 2022-05-13

Family

ID=80284557

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210057387.9A Active CN114077480B (en) 2022-01-19 2022-01-19 Method, device, equipment and medium for sharing memory between host and virtual machine

Country Status (1)

Country Link
CN (1) CN114077480B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114625481B (en) * 2022-03-22 2024-04-05 北京有竹居网络技术有限公司 Data processing method and device, readable medium and electronic equipment
CN115033339B (en) * 2022-05-09 2024-08-20 阿里巴巴(中国)有限公司 Address mapping method, device, equipment and storage medium
CN115190167B (en) * 2022-06-29 2024-04-09 深圳市联软科技股份有限公司 Proxy system and method based on shared memory communication
CN115686889B (en) * 2023-01-04 2023-03-28 麒麟软件有限公司 Method for using Ivshmem by Jailhouse based on ACPI
CN116662037B (en) * 2023-07-24 2023-10-20 杭州鉴智机器人科技有限公司 Processing method and device for shared memory, electronic equipment and storage medium
CN116991543B (en) * 2023-09-26 2024-02-02 阿里云计算有限公司 Host, virtualized instance introspection method and storage medium
CN118445030B (en) * 2024-07-04 2024-09-06 麒麟软件有限公司 OpenCL computing and unloading method and device and storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10078528B2 (en) * 2015-10-06 2018-09-18 Centurylink Intellectual Property Llc Virtual machine-to-port peripheral device driver for implementing communications between virtual machines and client devices
CN106874128B (en) * 2017-01-22 2020-11-20 广州华多网络科技有限公司 Data transmission method and device
CN108932170A (en) * 2018-06-06 2018-12-04 华东师范大学 A kind of mechanism with shared memory file system efficient between virtual machine
CN111813584A (en) * 2020-08-05 2020-10-23 Oppo广东移动通信有限公司 Memory sharing method and device, electronic equipment and storage medium
CN112532585A (en) * 2020-11-02 2021-03-19 杭州迪普科技股份有限公司 Method, device and medium for inter-process message transmission
CN113867993B (en) * 2021-12-03 2022-03-04 维塔科技(北京)有限公司 Virtualized RDMA method, system, storage medium and electronic device

Also Published As

Publication number Publication date
CN114077480A (en) 2022-02-22

Similar Documents

Publication Publication Date Title
CN114077480B (en) Method, device, equipment and medium for sharing memory between host and virtual machine
CN107566541B (en) Container network resource allocation method, system, storage medium and electronic device
CN109561171B (en) Configuration method and device of virtual private cloud service
CN110149388B (en) Method, device and equipment for connecting HTTPDNS (hypertext transport protocol version transport protocol DNS) server
CN113688072A (en) Data processing method and device
CN109218356B (en) Method and apparatus for managing stateful applications on a server
CN107547474A (en) A kind of graphic display method and equipment of heterogeneous dual system
CN114201317B (en) Data transmission method and device, storage medium and electronic equipment
WO2023174013A1 (en) Video memory allocation method and apparatus, and medium and electronic device
CN115686875A (en) Method, apparatus and program product for transferring data between multiple processes
CN115237589A (en) SR-IOV-based virtualization method, device and equipment
CN110430478B (en) Networking communication method, device, terminal equipment and storage medium
CN116383127A (en) Inter-node communication method, inter-node communication device, electronic equipment and storage medium
EP3913488B1 (en) Data processing method and device
CN112367362B (en) Data processing method, device, equipment and computer storage medium
CN115914389A (en) Cloud service control system, method and device, electronic equipment and storage medium
CN109240602B (en) Data access method
CN101441661A (en) System and method for sharing file resource between multiple embedded systems
CN113328874B (en) Data acceleration method, device and system applied to NFV system
CN113626160B (en) Network data packet high-concurrency processing method and system based on cavium processor
CN111107663B (en) Data transmission method and device, storage medium and electronic device
CN118509398B (en) Virtual machine communication method, system, device, equipment and storage medium based on RDMA
CN117215730B (en) Data transmission method, device, equipment and storage medium
CN111782268B (en) Method, apparatus, device and computer readable medium for allocating hardware resources
CN113542412B (en) Data transmission method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant