Block device sharing system based on shared memory and virtual interruption and control method thereof

CN122547531APending Publication Date: 2026-08-11BEIJING YIHUI INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-18
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

第二种是基于hypervisor的虚拟磁盘后端(例如QEMU的virtio-blk):由宿主机统一管理磁盘镜像,多个虚拟机通过virtio接口访问同一镜像,但通常不支持并发写入,且需要依赖特定hypervisor实现

Benefits of technology

1)本发明提供基于共享内存与虚拟中断的块设备共享系统及其控制方法,通过设置有共享内存模块,可以实现零拷贝高效传输,命令与数据直接在共享内存模块中实现交换,避免虚拟模块之间多次内存复制,显著降低 CPU 开销与延迟。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122547531A_ABST
    Figure CN122547531A_ABST
Patent Text Reader

Abstract

This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts, comprising: a service virtual module, which responds to commands and data from a shared memory module to perform corresponding operations on an internal image file; and after completing the corresponding operations on the internal image file, sends a corresponding response and / or data to the shared memory module; a client virtual module, which registers block devices, converts requests from block devices into commands for the shared memory module, and sends them to the shared memory module; and a shared memory module, which is located between the service virtual module and the client virtual module and is data-connected to both the service virtual module and the client virtual module. By setting up a shared memory module, zero-copy high-efficiency transmission can be achieved, with commands and data directly exchanged within the shared memory module, avoiding multiple memory copies between virtual modules and significantly reducing CPU overhead and latency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of block device sharing, and more specifically to a block device sharing system and control method based on shared memory and virtual interrupts. Background Technology

[0002] In virtualized environments, there is a lack of an efficient, low-overhead, and directly mountable shared storage mechanism among multiple virtual machines. Existing solutions typically rely on network protocol stacks or generic virtual disk interfaces, which suffer from significant performance degradation, high latency, and complex integration.

[0003] Currently, cross-virtual machine storage sharing is mainly achieved through the following two methods: The first type is network-based block device sharing (such as iSCSI or NBD): a virtual machine acts as a storage server, providing block device services to the outside world through the TCP / IP protocol stack, and other virtual machines access it through network connections; The second type is a hypervisor-based virtual disk backend (such as QEMU's virtio-blk): the host machine manages the disk image uniformly, and multiple virtual machines access the same image through the virtio interface, but it usually does not support concurrent writing and requires a specific hypervisor implementation.

[0004] These solutions all require protocol encapsulation / decapsulation, kernel network stack, or virtual device emulation layer, introducing additional overhead.

[0005] The shortcomings and deficiencies of the above-mentioned prior art are as follows: 1) High performance overhead: Network protocol stacks or virtual device simulations introduce multiple memory copies, context switches, and protocol parsing, significantly increasing I / O latency; 2) Zero-copy is not possible: Data needs to be copied multiple times between user space, kernel space, and virtual device layer, and physical memory cannot be directly shared; 3) Complex synchronization mechanism: It lacks an efficient cross-virtual machine event notification mechanism and often relies on polling or high-latency interrupts, which affects real-time performance.

[0006] Therefore, there is an urgent need to provide a new solution to address the defects and shortcomings of the existing technologies. Summary of the Invention

[0007] To address the deficiencies and shortcomings of the existing technologies, this invention provides a block device sharing system and its control method based on shared memory and virtual interrupts.

[0008] The specific solution provided by this invention is as follows: A block device sharing system based on shared memory and virtual interrupts, characterized in that: the system includes: A service virtual module that responds to commands or commands and data from a shared memory module to perform corresponding operations on an internal image file; and after completing the corresponding operations on the internal image file, sends a corresponding response or response and data to the shared memory module. A client virtual module registers block devices, converts requests from block devices into commands for the shared memory module, and sends them to the shared memory module. A shared memory module is configured between the service virtual module and the client virtual module and is data-connected to both the service virtual module and the client virtual module. After the client virtual module sends a command or command and data to the shared memory module, it triggers a semaphore block and an interrupt service routine. During the interrupt service routine, the service virtual module reads the command or command and data sent by the shared memory module and performs the corresponding operation. After executing the command and operation data, the service virtual module sends a response or response and data to the shared memory module. After the service virtual module sends a response or response and data to the shared memory module, it triggers a secondary interrupt service routine and releases a semaphore. During the secondary interrupt service routine, the client virtual module reads the response or response and data sent by the shared memory module and returns it to the block device that initiated the request.

[0009] As a further preferred embodiment of the present invention, the service virtual module includes a service module shared memory driver unit and an image file management unit that are interconnected, wherein... The service module shared memory driver unit is data connected to the shared memory module. It can receive commands or commands and data from the shared memory module and send them to the image file management unit; and after completing the corresponding operation on the image file, it sends the corresponding response or response and data to the shared memory module. The image file management unit has several image files internally. It can receive commands or commands and data from the shared memory driver unit of the service module and perform corresponding operations on the internal image files. After completing the corresponding operations on the internal image files, it sends corresponding responses or responses and data to the shared memory driver unit of the service module.

[0010] In a further preferred embodiment of the present invention, the client virtual module includes a block device registration unit and a client module shared memory driver unit that are interconnected by data, wherein... The block device registration unit registers the block device to be shared, converts the block device request into a command for the shared memory module, and sends it to the client module shared memory driver unit. The client module shared memory driver unit is data connected to the shared memory module. It can send corresponding commands or commands and data to the shared memory module, and receive responses or responses and data from the shared memory module, and send them to the block device registration unit.

[0011] In a further preferred embodiment of the present invention, the shared memory module internally includes a command unit, a data unit, and a response unit, wherein... The command unit stores commands in a preset format. The data unit provides cache space for transmitting data that has passed through the shared memory module; The response unit stores the corresponding response after the operation is completed.

[0012] As a further preferred embodiment of the present invention, the command includes at least a verification field, a request sequence number field, a command type field, a data length field, and a parameter field; wherein... The verification field verifies whether the data structure in the verification command belongs to a data structure that the shared memory module can process; The request sequence number field will match the request with the response; The command type field includes at least read commands, write commands, and control commands; The data length field indicates the length of the transmitted data; The parameter fields include the sector parameters and operation parameters to be obtained.

[0013] As a further preferred embodiment of the present invention, the interrupt service routine disconnects the service virtual module from the current working thread.

[0014] As a further preferred embodiment of the present invention, the secondary interrupt service routine disconnects the client virtual module from the read / write request interface.

[0015] As a further preferred embodiment of the present invention, when the request from the block device is a read operation request: The client virtual module sends read commands to the service virtual module through the shared memory module; The service virtual module reads the data to be shared from the corresponding image file, sends the data to be shared to the shared memory module, and returns a read completion response to the shared memory module. The client virtual module obtains the read completion response and the data to be shared through the shared memory module, and returns the data to be shared to the block device that initiated the read operation request.

[0016] As a further preferred embodiment of the present invention, when the request from the block device is a write operation request: The client virtual module sends write commands and write data to the service virtual module through the shared memory module; The service virtual module obtains write data through the shared memory module, writes the write data to the image file, and returns a write completion response to the shared memory module. The client virtual module obtains the write completion response through the shared memory module and returns the write completion response to the block device that initiated the write operation request.

[0017] Furthermore, the present invention also provides a control method for a block device sharing system based on shared memory and virtual interrupts, characterized by comprising the following steps: S100: The client virtual module sends commands or commands and data to the shared memory module; S200: Triggers semaphore blocking and triggers an interrupt service routine; S300: The service virtual module reads commands or commands and data sent by the shared memory module and performs corresponding operations during an interrupt service routine; after executing the commands and operation data, it sends a response or a response and data to the shared memory module. S400: The service virtual module sends a response or response and data to the shared memory module; S500: Triggers the secondary interrupt service routine and triggers semaphore release; S600: When the client virtual module is interrupted during the secondary interrupt service routine, it reads the response or response and data sent by the shared memory module and returns it to the block device that initiated the request.

[0018] Compared with existing technologies, the technical effects that this invention can achieve include: 1) This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts. By setting up a shared memory module, zero-copy high-efficiency transmission can be achieved. Commands and data are directly exchanged in the shared memory module, avoiding multiple memory copies between virtual modules and significantly reducing CPU overhead and latency.

[0019] 2) This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts. By triggering a primary interrupt service routine and a secondary interrupt service routine, low-latency interrupt synchronization can be achieved. By utilizing the interrupt mechanism, microsecond-level response can be achieved, which is superior to polling or network interrupt methods.

[0020] 3) This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts. Block device registration is achieved through a client virtual module. It is compatible with standard block devices, can directly mount file systems such as FAT, and does not require modification of upper-layer applications. It has a wide range of applications and strong compatibility.

[0021] 4) This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts. The shared memory module realizes data communication through commands in a preset format. The corresponding fields ensure that the commands and responses strictly correspond to each other, preventing out-of-order or fake packet interference, and ensuring safe and reliable matching.

[0022] 5) This invention provides a block device sharing system and its control method based on shared memory and virtual interrupts, which supports complete block device semantics: in addition to reading and writing, it can also support IOCTL (device control interface function) operations such as FIOFLUSH (flush file cache function) and FIOTRIM (notify SSD to delete unused data blocks), thus meeting the complete requirements of the file system. Attached Figure Description

[0023] Figure 1 The diagram shown is a structural schematic of the sharing system provided by the present invention.

[0024] Figure 2 The diagram shows a flowchart illustrating the process of reading and writing operations performed by the shared system provided by this invention. Detailed Implementation

[0025] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0026] In the description of this invention, it should be noted that the terms "upper," "lower," "inner," "outer," "front end," "rear end," "both ends," "one end," and "the other end," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0027] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installed," "equipped with," "connected," etc., should be interpreted broadly. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium; it can be a connection within two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.

[0028] [First Embodiment] like Figure 1 The figure shown is a block device sharing system based on shared memory and virtual interrupts provided in the first embodiment of the present invention. The system includes: The service virtual module responds to commands or commands and data from the shared memory module to perform corresponding operations on the internal image file; and after completing the corresponding operations on the internal image file, it sends the corresponding response or response and data to the shared memory module. like Figure 1 As shown, the service virtual module provided in this embodiment includes a service module shared memory driver unit and an image file management unit that are interconnected, wherein... The service module shared memory driver unit is connected to the shared memory module via data connection. It can receive commands or commands and data from the shared memory module and send them to the image file management unit; and after completing the corresponding operation on the image file, it sends the corresponding response or response and data to the shared memory module. The image file management unit contains several image files. It can receive commands or commands and data from the shared memory driver unit of the service module and perform corresponding operations on the internal image files. After completing the corresponding operations on the internal image files, it sends corresponding responses or responses and data to the shared memory driver unit of the service module.

[0029] The system also includes a client virtual module, which registers block devices, translates block device requests into commands for the shared memory module, and sends them to the shared memory module. like Figure 1 As shown, the client virtual module provided in this embodiment includes a block device registration unit and a client module shared memory driver unit that are interconnected. The block device registration unit registers the block devices to be shared, converts the block device requests into commands for the shared memory module, and sends them to the client module shared memory driver unit. Block device registration is achieved through the client virtual module, which is compatible with standard block devices, can directly mount file systems such as FAT, does not require modification of the upper-layer application, has a wide range of applications, and strong compatibility. As a further preferred option, the client virtual module can actively read the necessary parameters such as the total number of sectors, sector size, and block size returned by the service virtual module during the initialization phase. This is used to obtain the parameters of the internal image file of the service virtual module, which facilitates the creation of a matching block device and the registration of the local block device, thus achieving automatic adaptation without configuration.

[0030] The specific process is as follows: During the initialization phase, the client virtual module proactively initiates IOCTL requests (such as BLKGETSIZE64, BLKSSZGET, etc.) to the service virtual module to obtain parameters such as the total number of sectors, sector size, and logical block size of the image file inside the service virtual module, and dynamically registers the local block device accordingly. This process requires no manual configuration and achieves plug-and-play functionality.

[0031] The client module shared memory driver unit is connected to the shared memory module via data connection. It can send corresponding commands or commands and data to the shared memory module, and receive responses or responses and data from the shared memory module, and send them to the block device registration unit.

[0032] It is worth noting that the system provided in this embodiment also includes a shared memory module. The shared memory module is set between the service virtual module and the client virtual module and is connected to both the service virtual module and the client virtual module for data transmission. By setting up the shared memory module, zero-copy high-efficiency transmission can be achieved. Commands and data are directly exchanged in the shared memory module, avoiding multiple memory copies between virtual modules and significantly reducing CPU overhead and latency.

[0033] In this embodiment, the client virtual module and the service virtual module pre-determine their respective shared memory regions through fixed address mapping and DMA attribute marking, so as to serve as the client module shared memory driver unit inside the client virtual module and the client module shared memory driver unit inside the service virtual module, respectively. Initialization operations are performed on the client module shared memory driver unit and the client module shared memory driver unit to ensure the matching degree between the client module shared memory driver unit and the shared memory module and the efficiency of command and data transmission. After the client virtual module sends a command or command and data to the shared memory module, it triggers a semaphore block and triggers an interrupt service routine. During the interrupt service routine, the service virtual module reads the command or command and data sent by the shared memory module and performs the corresponding operation. After executing the command and operation data, the service virtual module sends a response or response and data to the shared memory module. After the service virtual module sends an acknowledgment or acknowledgment and data to the shared memory module, it triggers a secondary interrupt service routine and releases a semaphore. During the secondary interrupt service routine, the client virtual module reads the acknowledgment or acknowledgment and data sent by the shared memory module and returns it to the block device that initiated the request.

[0034] By triggering a single interrupt service routine and a second interrupt service routine, low-latency interrupt synchronization can be achieved. By utilizing the interrupt mechanism, microsecond-level response can be achieved, which is superior to polling or network interrupt methods.

[0035] One interrupt service routine disconnects the service virtual module from the current working thread and can also remain at the current position by triggering a semaphore block, further achieving microsecond-level response. The second interrupt service routine disconnects the client virtual module from the read / write request interface and can also help the client service module resume the initial process by triggering a semaphore release. By triggering the semaphore release through the interrupt service routine, the request and response are strictly synchronized, avoiding polling overhead.

[0036] The shared memory module provided in this embodiment internally includes a command unit, a data unit, and a response unit. The command unit contains commands in a preset format; each command includes at least a validation field, a request sequence number field, a command type field, a data length field, and a parameter field. Verify whether the data structure in the field verification command belongs to a data structure that the shared memory module can process; The request sequence number field matches the request with the response; The command type field must include at least read commands, write commands, and control commands; The data length field indicates the length of the transmitted data (i.e., the number of bytes). The parameter fields include the sector parameters to be obtained (such as sector size and sector position) and control parameters (such as relevant parameters in the IOCTRL operation command). The IOCTL commands involved in this embodiment include, but are not limited to: FIOSYNC / FIODATASYNC / FIOFLUSH / FIOSYNCMETA (synchronization / refresh cache commands); GET_SECNUM / GET_SECSIZE / GET_BLKSIZE (sector operation commands); and TRIM command (internal delete command), etc.

[0037] The field `magic` is of type `uint32`. It is a preset magic number that can quickly identify illegal access or memory corruption. It is used to verify whether the data structure in the command belongs to the data structure that the shared memory module can handle, and to prevent data written outside the system from being processed incorrectly.

[0038] The field `seq` is of type `uint32` and represents the request sequence number used to match requests and responses. The field is cmd; its type is uint32; it is a command type, including READ, WRITE and IOCTRL commands; READ is a read operation command, WRITE is a write operation command, and IOCTRL is a control command, which includes file system operation instructions such as getting the number of block device sectors, the size of the sectors, and sync. The field `len` is of type `uint32` and represents the data length, i.e., the number of bytes. The field arg1 is of type uint64 and is the first parameter, representing the starting sector number or offset. In the IOCTL command, arg1 also represents the specific control code, such as BLKFLSBUF, BLKDISCARD, etc. The field arg2 is of type uint64 and is the second parameter, representing the operation flag or a reserved field. The shared memory module communicates data through commands in a preset format. It ensures that commands and responses strictly correspond through corresponding fields, preventing out-of-order or fake packet interference, and ensuring safe and reliable matching. The data unit provides buffer space for data transmitted through the shared memory module; The response unit stores the corresponding response after the operation is completed.

[0039] like Figure 2 As shown, When the block device request is a read operation request: The client virtual module sends read commands to the service virtual module through the shared memory module; The service virtual module reads the data to be shared from the corresponding image file, sends the data to be shared to the shared memory module, and returns a read completion response to the shared memory module. The client virtual module obtains the read completion response and the data to be shared through the shared memory module, and returns the data to be shared to the block device that initiated the read operation request.

[0040] When the block device request is a write operation request: The client virtual module sends write commands and write data to the service virtual module through the shared memory module; The service virtual module obtains write data through the shared memory module, writes the write data to the image file, and returns a write completion response to the shared memory module. The client virtual module obtains the write completion response through the shared memory module and returns the write completion response to the block device that initiated the write operation request.

[0041] [Second Embodiment] The second embodiment of the present invention also provides a control method for a block device sharing system based on shared memory and virtual interrupts, comprising the following steps: S100: The client virtual module sends commands or commands and data to the shared memory module; S200: Triggers semaphore blocking and triggers an interrupt service routine; S300: The service virtual module reads commands or commands and data sent by the shared memory module and performs corresponding operations during an interrupt service routine; after executing the commands and operation data, it sends a response or a response and data to the shared memory module. S400: The service virtual module sends a response or response and data to the shared memory module; S500: Triggers the secondary interrupt service routine and triggers semaphore release; S600: When the client virtual module is interrupted during the secondary interrupt service routine, it reads the response or response and data sent by the shared memory module and returns it to the block device that initiated the request.

[0042] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

Claims

1. A block device sharing system based on shared memory and virtual interruption, characterized in that: The system includes: A service virtual module that responds to commands or commands and data from a shared memory module to perform corresponding operations on an internal image file; and after completing the corresponding operations on the internal image file, sends a corresponding response or response and data to the shared memory module. A client virtual module registers block devices, converts requests from block devices into commands for the shared memory module, and sends them to the shared memory module. A shared memory module is configured between the service virtual module and the client virtual module and is data-connected to both the service virtual module and the client virtual module. After the client virtual module sends a command or command and data to the shared memory module, it triggers a semaphore block and an interrupt service routine. During the interrupt service routine, the service virtual module reads the command or command and data sent by the shared memory module and performs the corresponding operation. After executing the command and operation data, the service virtual module sends a response or response and data to the shared memory module. After the service virtual module sends a response or response and data to the shared memory module, it triggers a secondary interrupt service routine and releases a semaphore. During the secondary interrupt service routine, the client virtual module reads the response or response and data sent by the shared memory module and returns it to the block device that initiated the request.

2. The shared memory and virtual interrupt based block device sharing system according to claim 1, wherein: The service virtual module includes a service module shared memory driver unit and an image file management unit that are interconnected, wherein... The service module shared memory driver unit is data connected to the shared memory module. It can receive commands or commands and data from the shared memory module and send them to the image file management unit; and after completing the corresponding operation on the image file, it sends the corresponding response or response and data to the shared memory module. The image file management unit has several image files internally. It can receive commands or commands and data from the shared memory driver unit of the service module and perform corresponding operations on the internal image files. After completing the corresponding operations on the internal image files, it sends corresponding responses or responses and data to the shared memory driver unit of the service module.

3. The shared memory and virtual interrupt based block device sharing system according to claim 1, wherein: The client virtual module includes a block device registration unit and a client module shared memory driver unit that are interconnected by data. The block device registration unit registers the block device to be shared, converts the block device request into a command for the shared memory module, and sends it to the client module shared memory driver unit. The client module shared memory driver unit is data connected to the shared memory module. It can send corresponding commands or commands and data to the shared memory module, and receive responses or responses and data from the shared memory module, and send them to the block device registration unit.

4. The shared memory and virtual interrupt based block device sharing system of claim 1, wherein: The shared memory module internally includes a command unit, a data unit, and a response unit, wherein... The command unit stores commands in a preset format. The data unit provides cache space for transmitting data that has passed through the shared memory module; The response unit stores the corresponding response after the operation is completed.

5. The block device sharing system based on shared memory and virtual interrupts according to claim 1, characterized in that: The command includes at least a validation field, a request sequence number field, a command type field, a data length field, and a parameter field; wherein... The verification field verifies whether the data structure in the verification command belongs to a data structure that the shared memory module can process; The request sequence number field will match the request with the response; The command type field includes at least read commands, write commands, and control commands; The data length field indicates the length of the transmitted data; The parameter fields include the sector parameters and operation parameters to be obtained.

6. The block device sharing system based on shared memory and virtual interrupts according to claim 1, characterized in that: The interrupt service routine disconnects the service virtual module from the current working thread.

7. The block device sharing system based on shared memory and virtual interrupts according to claim 1, characterized in that: The secondary interrupt service routine disconnects the client virtual module from the read / write request interface.

8. The block device sharing system based on shared memory and virtual interrupts according to claim 1, characterized in that: When the block device request is a read operation request: The client virtual module sends read commands to the service virtual module through the shared memory module; The service virtual module reads the data to be shared from the corresponding image file, sends the data to be shared to the shared memory module, and returns a read completion response to the shared memory module. The client virtual module obtains the read completion response and the data to be shared through the shared memory module, and returns the data to be shared to the block device that initiated the read operation request.

9. The block device sharing system based on shared memory and virtual interrupts according to claim 1, characterized in that: When the block device request is a write operation request: The client virtual module sends write commands and write data to the service virtual module through the shared memory module; The service virtual module obtains write data through the shared memory module, writes the write data to the image file, and returns a write completion response to the shared memory module. The client virtual module obtains the write completion response through the shared memory module and returns the write completion response to the block device that initiated the write operation request.

10. The control method for a block device sharing system based on shared memory and virtual interrupts according to any one of claims 1-9, characterized in that: Includes the following steps: S100: The client virtual module sends commands or commands and data to the shared memory module; S200: Triggers semaphore blocking and triggers an interrupt service routine; S300: The service virtual module reads commands or commands and data sent by the shared memory module and performs corresponding operations during an interrupt service routine; after executing the commands and operation data, it sends a response or a response and data to the shared memory module. S400: The service virtual module sends a response or response and data to the shared memory module; S500: Triggers the secondary interrupt service routine and triggers semaphore release; S600: When the client virtual module is interrupted during the secondary interrupt service routine, it reads the response or response and data sent by the shared memory module and returns it to the block device that initiated the request.