A data sharing system and control method thereof
By using shared memory management module and application program interface module in the data sharing system, using index to generate file descriptors, the problem of poor data sharing performance and inability to share data between multiple processes and driver modules in the prior art is solved. , realizes efficient memory sharing and fast data processing.
Patent Information
- Application Number
- CN202411833688.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-12-13
AI Technical Summary
The existing data sharing method has poor performance when the data volume is large and the transmission delay requirements are high, and data cannot be shared between multiple processes and driver modules.
It provides a data sharing system, through the shared memory management module and the application program interface module, and uses index to generate file descriptors to realize memory sharing between multiple processes and driver modules.
Reduces data copying process, improves processing speed, reduces processing delays, and ensures uniqueness and efficiency of resource management.
Smart Images

Figure CN119311440B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data interaction between processes, and in particular to a data sharing system and a control method thereof. Background Art
[0002] When a computer system processes various data, it is inevitable to share data between various processes. Traditional data sharing methods include: memory sharing, pipeline sharing, and message queue sharing, such as Figure 1-3 shown.
[0003] The defects and shortcomings of the existing data sharing methods are:
[0004] 1) The pipe sharing method and the message queue sharing method involve two data copy operations between the user space and the kernel space. When the data volume is large and the transmission delay requirement is high, the performance cannot meet the requirements. In addition, these two data sharing methods cannot share data between multiple processes and driver modules.
[0005] 2) Although the memory sharing method does not require multiple data copying processes and can share data between multiple processes, it cannot share data between user space and kernel space.
[0006] Therefore, it is urgent to provide a new solution to solve the defects and shortcomings in the above-mentioned prior art. Summary of the invention
[0007] In order to solve the defects and shortcomings in the prior art, the present invention provides a data sharing system and a control method thereof.
[0008] The specific scheme provided by the present invention is:
[0009] A data sharing system, characterized in that: the system includes
[0010] A shared memory management module, wherein the shared memory management module includes a resource management pool, wherein the resource management pool is provided with a plurality of shared memory management nodes for allocating shared memory. After the first application obtains the index of the required shared memory management node:
[0011] The first application can generate a file descriptor through the index, and the first application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor;
[0012] The first application can pass the index to the second application, the second application can generate a file descriptor through the index, and the second application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor;
[0013] The first application and the second application can both pass the generated file descriptor to the driver, and the driver uses the shared memory corresponding to the shared memory information through the acquired shared memory information;
[0014] An application program interface module, wherein the application program interface module is registered with a character device node, wherein the character device node can provide a control command, and an application program can use the control command to perform control operations on a shared memory and a file descriptor through a shared memory management module;
[0015] The kernel interface module exports a kernel interface function, and the driver can implement control operations on the shared memory by calling the corresponding kernel interface function.
[0016] As a further preferred embodiment of the present invention, a number of shared memory management nodes are set in the resource management pool, and the first application or the second application can pass the memory size information to be applied for to the shared memory management module through a control command. The shared memory management module finds the node in the resource management pool and bitmap marks it, and allocates a memory management data structure and the memory required for the application to the node, wherein the memory management data structure records the shared memory information allocated to the application, and the idle node found by the shared memory management module in the resource management pool corresponds to the memory management data structure, and returns the index value of the idle node to the first application or the second application.
[0017] As a further preferred embodiment of the present invention, a reference count value is also set in the memory management data structure, and the reference count value indicates the current number of operations of the shared memory. When the reference count value is 0, it indicates that the shared memory is idle and not in use. The shared memory is released and its bitmap mark is set to 0.
[0018] As a further preferred implementation manner of the present invention, the shared memory management node points to shared memory information, and the shared memory information at least includes address information of the shared memory and size information of the shared memory.
[0019] As a further preferred implementation manner of the present invention, the file descriptor corresponds to the shared memory information included in the index of the shared memory management node.
[0020] As a further preferred embodiment of the present invention, the second application implements a creation mapping operation by performing an mmap operation on a file descriptor.
[0021] As a further preferred embodiment of the present invention, in the application interface module, the application can use the control command to perform control operations on the shared memory and file descriptors through the shared memory management module, including at least the creation and destruction of shared memory, and the creation operation of shared memory file descriptors.
[0022] As a further preferred implementation manner of the present invention, in the application program interface module, the control command provided by the character device node is an IOCTL command.
[0023] As a further preferred embodiment of the present invention, in the kernel interface module, the driver can implement control operations on the shared memory by calling the corresponding interface, which at least include the acquisition and use of the shared memory and the modification operation of the reference count.
[0024] Furthermore, the present invention also provides a control method for a data sharing system, characterized in that it comprises the following steps:
[0025] S1: The first application opens the character device node through the application program interface module and uses the control command to create a shared memory;
[0026] S2: Find an idle node in the resource management pool, allocate a memory management data structure and the memory required by the application to the node, and return the index value of the idle node to the second application;
[0027] S3: The second application generates a corresponding file descriptor using the index, and directly accesses the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor;
[0028] S4: The second application passes the generated file descriptor to the driver;
[0029] S5: The driver uses the file descriptor to obtain the shared memory information, and uses the shared memory corresponding to the shared memory information to store data;
[0030] S6: The second application can share the data stored in the corresponding shared memory by the driver program, and the driver program can also share the data stored in the corresponding shared memory by the second application program.
[0031] Compared with the prior art, the present invention can achieve the following technical effects:
[0032] 1) The present invention provides a data sharing system and a control method thereof, wherein a first application program transmits an index corresponding to a shared memory management node to a second application program, and the second application program generates a file descriptor through the index. The second application program can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor, and can also transmit the generated file descriptor to a driver program, so that the driver program uses the shared memory corresponding to the shared memory information through the acquired shared memory information, thereby realizing memory sharing between multiple processes and a driver module by using file descriptors.
[0033] 2) The present invention provides a data sharing system and a control method thereof. By adopting an index, compared with the method of directly adopting a file descriptor, since the index of a shared memory management node uniquely corresponds to the shared memory management node, the uniqueness of the shared memory management node obtained by the application can be ensured, and the occurrence of duplicate records of multiple applications calling the same shared memory management node can be avoided; at the same time, the connection efficiency between the application and the shared memory corresponding to the index and the retrieval efficiency of the data therein can be accelerated, the query and grouping time can be reduced, and the system performance can be improved.
[0034] 3) The present invention provides a data sharing system and a control method thereof, which can reduce the data copying process in complex data processing flows, increase processing speed, and reduce processing delays.
[0035] 4) The present invention provides a data sharing system and a control method thereof, which provides a reference count value in the memory management data structure to indicate the current number of operations and whether the current shared memory is being used, thereby effectively protecting the shared memory in the resource management pool and avoiding unexpected failures that may be caused by the shared memory being released. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 The figure shows a logic diagram of a memory-sharing data sharing method in the prior art;
[0037] Figure 2 The figure shows a logical diagram of a pipeline sharing data sharing method in the prior art;
[0038] Figure 3 The figure shows a logical diagram of a message queue sharing data sharing method in the prior art;
[0039] Figure 4 Shown is a logical structure diagram of a data sharing system provided by the present invention. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] In the description of the present invention, it should be noted that the terms "upper", "lower", "inner", "outer", "front end", "rear end", "two ends", "one end", "the other end" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance.
[0042] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "provided with", "connected", etc. should be understood in a broad sense. For example, "connected" 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 it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0043] [First embodiment]
[0044] like Figure 4 The first embodiment of the present invention is shown, which provides a data sharing system, including
[0045] A shared memory management module includes a resource management pool, in which a number of shared memory management nodes for allocating shared memory are arranged. After the first application obtains the index (i.e., handle) of the required shared memory management node;
[0046] The first application can generate a file descriptor through the index, and the file descriptor corresponds to the shared memory information contained in the index of the shared memory management node, so that the corresponding shared memory information can be obtained through the file descriptor. The first application can perform an mmap operation through the generated file descriptor to create a mapping and directly access the shared memory corresponding to the shared memory information;
[0047] The first application can pass the index to the second application, and the second application can generate a file descriptor through the index, and the file descriptor corresponds to the shared memory information contained in the index of the shared memory management node, so that the corresponding shared memory information can be obtained through the file descriptor, and the second application can perform an mmap operation through the generated file descriptor to create a mapping and directly access the shared memory corresponding to the shared memory information;
[0048] The first application and the second application can both pass the generated file descriptor to the driver, and the driver uses the shared memory corresponding to the shared memory information through the acquired shared memory information;
[0049] That is, it can be achieved that: the first application generates a file descriptor through the index, and the first application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor; or the first application passes the index to a second application, and the second application generates a file descriptor through the index, and the second application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor; the first application or the second application can also pass the generated file descriptor to the driver program, so that the driver program uses the shared memory corresponding to the shared memory information through the acquired shared memory information, thereby realizing memory sharing between multiple processes and the driver module by using file descriptors.
[0050] It is worth noting that: in the present embodiment, there are multiple application programs. To facilitate the detailed description of the present application, only the first application program and the second application program are extracted for exemplary description.
[0051] like Figure 1 As shown, a number of shared memory management nodes are provided in the resource management pool in this embodiment. The first application or the second application can pass the memory size information to be applied for to the shared memory management module through a control command. The shared memory management module finds the node in the resource management pool and performs a bitmap mark on it. At the same time, a memory management data structure and the memory required by the application are allocated to the node, wherein the memory management data structure records the shared memory information allocated to the application. The idle node found by the shared memory management module in the resource management pool corresponds to the memory management data structure, and returns the index value of the idle node to the first application or the second application.
[0052] A reference count value is also set in the memory management data structure. The reference count value indicates the current number of operations of the shared memory, indicating the number of operations currently existing in the shared memory. After each user obtains the shared memory, the reference count will be +1. When it is not in use, the reference count of the shared memory will be -1. When the reference count value is 0, it means that the shared memory is idle and not in use. At this time, the shared memory is released and its bitmap mark is set to 0.
[0053] In this embodiment, the shared memory management node points to the shared memory information, and the shared memory information includes at least the address information of the shared memory and the size information of the shared memory. By adopting an index, since the index of the shared memory management node uniquely corresponds to the shared memory management node, the uniqueness of the shared memory management node obtained by the application can be ensured, and the occurrence of duplicate records of multiple applications calling the same shared memory management node can be avoided; at the same time, the connection efficiency between the application and the shared memory corresponding to the index and the retrieval efficiency of the data therein can be accelerated, the query and grouping time can be reduced, and the system performance can be improved.
[0054] The system provided in this embodiment also includes:
[0055] An application program interface module, the application program interface module is registered with a character device node, the character device node can provide a control command, which is an IOCTL command in this embodiment, and the application program can use the control command to perform control operations on the shared memory and file descriptors through the shared memory management module, including at least the creation and destruction of shared memory, and the creation operation of the shared memory file descriptor. For example, the specific steps for creating the file descriptor are: the application program uses the IOCTL command to pass in the index handle that uniquely corresponds to the shared memory management node, and then creates the file descriptor in the shared memory management module through the IOCTL command.
[0056] Kernel interface module, the kernel interface module exports kernel interface functions, the driver can implement control operations on shared memory by calling the corresponding kernel interface functions. Shared memory is not only directly shared between multiple applications, but also may be used by drivers. The way drivers use shared memory is different from that of applications. They do not need to perform mmap operations on file descriptors to access shared memory like applications. After obtaining the file descriptor, the driver can directly call the above-mentioned exported kernel interface function to obtain the address of shared memory for direct access.
[0057] The driver's control operations on shared memory at least include the acquisition, use and reference count modification operations of shared memory. The applied shared memory can be used by multiple users, and the creation and destruction of shared memory and the creation and destruction of file descriptors are all part of the operation. Therefore, the reference count value is used to represent the number of shared memory operations currently in existence in the memory management data structure related to shared memory. After each user acquires the shared memory, the reference count will be +1, when a file operator is created, the reference count will be +1, when it is not used, the reference count will be -1, and when the file operator is destroyed, the reference count will be -1. When the reference count is reduced to 0, it means that the shared memory is no longer in use and is in an idle state. The memory will be released and its bitmap mark will be set to 0.
[0058] By such configuration, the second application can share the data stored in the corresponding shared memory by the driver program without copying the data, and the driver program can also share the data stored in the corresponding shared memory by the second application program.
[0059] When using, take the video decoding process as an example:
[0060] 1) The decoding application (i.e., the first application) opens the character device node of the application interface module and uses the IOCTL command to create shared memory;
[0061] 2) The decoding application passes the file descriptor corresponding to the shared memory to the decoding driver (i.e., the driver);
[0062] 3) The decoding driver uses the file descriptor to obtain the corresponding shared memory address information, and sets the memory address to the hardware decoding module register for the hardware decoding module to store the decoded data;
[0063] 4) The decoding application passes the handle of the shared memory to the graphics acceleration application (i.e., the second application);
[0064] 5) The graphics acceleration application generates a file descriptor using handle and passes the file descriptor to the graphics acceleration driver (another driver). The driver obtains the shared memory information through the file descriptor and configures the memory address to the graphics acceleration hardware module as input data;
[0065] 6) The graphics acceleration application also applies for shared memory to store the data processed by the graphics acceleration hardware module. The application accesses the data processed by the hardware through the file descriptor corresponding to the shared memory.
[0066] In the above processing, the decoded data can be used by the graphics acceleration hardware module without being copied, and the data processed by the graphics acceleration hardware module can be used by the application without being copied to the user space.
[0067] [Second embodiment]
[0068] The second embodiment of the present invention further provides a control method for the data sharing system mentioned in the first embodiment, comprising the following steps:
[0069] S1: The first application opens the character device node through the application program interface module and uses the control command to create a shared memory;
[0070] S2: Find an idle node in the resource management pool, allocate a memory management data structure and the memory required by the application to the node, and return the index value of the idle node to the second application;
[0071] S3: The second application generates a corresponding file descriptor using the index, and directly accesses the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor;
[0072] S4: The second application passes the generated file descriptor to the driver;
[0073] S5: The driver uses the file descriptor to obtain the shared memory information, and uses the shared memory corresponding to the shared memory information to store data;
[0074] S6: The second application can share the data stored in the corresponding shared memory by the driver program, and the driver program can also share the data stored in the corresponding shared memory by the second application program.
[0075] It will be apparent to those skilled in the art that the 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 the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
Claims
1. A data sharing system, characterized in that: The system comprises A shared memory management module, wherein the shared memory management module includes a resource management pool, wherein the resource management pool is provided with a plurality of shared memory management nodes for allocating shared memory. After the first application obtains the index of the required shared memory management node: The first application can generate a file descriptor through the index, and the first application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor; The first application can pass the index to the second application, the second application can generate a file descriptor through the index, and the second application can directly access the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor; The first application and the second application can both pass the generated file descriptor to the driver, and the driver uses the shared memory corresponding to the shared memory information through the acquired shared memory information; An application program interface module, wherein the application program interface module is registered with a character device node, wherein the character device node can provide a control command, and an application program can use the control command to perform control operations on a shared memory and a file descriptor through a shared memory management module; A kernel interface module, wherein the kernel interface module exports a kernel interface function, and the driver can implement control operations on the shared memory by calling the corresponding kernel interface function; The shared memory management node points to the shared memory information, and the shared memory information at least includes the address information of the shared memory and the size information of the shared memory; The file descriptor corresponds to the shared memory information contained in the index of the shared memory management node.
2. A data sharing system according to claim 1, characterized in that: Several shared memory management nodes are set in the resource management pool. The first application or the second application can pass the memory size information to be applied for to the shared memory management module through a control command. The shared memory management module finds the node in the resource management pool and marks it with a bitmap. At the same time, a memory management data structure and the memory required for the application are allocated to the node. The memory management data structure records the shared memory information allocated to the application. The idle node found by the shared memory management module in the resource management pool corresponds to the memory management data structure, and the index value of the idle node is returned to the first application or the second application.
3. A data sharing system according to claim 2, characterized in that: The memory management data structure is also provided with a reference count value, which indicates the current number of operations of the shared memory. When the reference count value is 0, it indicates that the shared memory is idle and not in use. The shared memory is released and its bitmap mark is set to 0.
4. A data sharing system according to claim 1, characterized in that: The second application program creates a mapping operation by performing an mmap operation on the file descriptor.
5. A data sharing system according to claim 1, characterized in that: In the application program interface module, the application program can use the control command to perform control operations on the shared memory and file descriptors through the shared memory management module, including at least the creation and destruction of the shared memory, and the creation operation of the shared memory file descriptor.
6. A data sharing system according to claim 1, characterized in that: In the application program interface module, the control command provided by the character device node is an IOCTL command.
7. A data sharing system according to claim 3, characterized in that: In the kernel interface module, the driver can implement control operations on the shared memory by calling the corresponding interface, which at least include the acquisition and use of the shared memory and the modification operation of the reference count.
8. A control method for a data sharing system according to any one of claims 1 to 7, characterized in that: The following steps are involved: S1: The first application opens the character device node through the application program interface module and uses the control command to create a shared memory; S2: Find an idle node in the resource management pool, allocate a memory management data structure and the memory required by the application to the node, and return the index value of the idle node to the second application; S3: The second application generates a corresponding file descriptor using the index, and directly accesses the shared memory corresponding to the shared memory information after creating a mapping through the generated file descriptor; S4: The second application passes the generated file descriptor to the driver; S5: The driver uses the file descriptor to obtain the shared memory information, and uses the shared memory corresponding to the shared memory information to store data; S6: The second application can share the data stored in the corresponding shared memory by the driver program, and the driver program can also share the data stored in the corresponding shared memory by the second application program.
Citation Information
Patent Citations
Method, device and system for communication among multiple processes
CN111897666A
Audio playing method and system, electronic equipment and storage medium
CN116028007A