Data transmission method and device, electronic equipment and storage medium

By maintaining record tables and reference count values ​​in the user process and kernel state, and using data identification comparison and red-black tree storage, the problem of high system overhead in data transmission between user state and kernel state is solved, and the data transmission efficiency is improved.

CN118567879AActive Publication Date: 2024-08-30NANJING ILUVATAR COREX TECH CO LTD (DBA ILUVATAR COREX INC NANJING)
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410678068.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2024-08-30
Estimated Expiration
2044-05-29

Smart Images

  • Figure CN118567879A
    Figure CN118567879A
Patent Text Reader

Abstract

The invention provides a data transmission method and device, electronic equipment and a storage medium. The method comprises the following steps: calculating through a user process to obtain a first data identifier of data; if the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to a kernel mode; querying whether the kernel mode resource pool contains the first data identifier, and if the kernel mode query resource pool contains the first data identifier, not transmitting data in the user process to the kernel mode; and if the kernel mode query resource pool does not contain the first data identifier, acquiring data from the user process according to a pointer, and transmitting the data to the kernel mode. According to the method and the device, a first data identifier comparison mode is adopted instead of a data comparison mode, so that the overhead of the system is reduced, and in addition, the overhead of the system is further reduced by reducing the transmission of repeated data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data transmission method, device, electronic device and storage medium. Background Art

[0002] For program development on the Linux platform, there are two main ways for user processes to pass data to kernel processes: one is through system calls, and the other is through shared memory.

[0003] Among them, the system call method is to use the system call interface to implement the method of switching from user state to kernel state, and then complete the task of transferring data from user state to kernel state through specific system call functions. The specific implementation is actually a process of copying data from user space mem to kernel space mem. For scenarios with large amounts of data and frequent data interactions, there will be a large system overhead, which will seriously affect the performance of the program. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a data transmission method, device, electronic device and storage medium, which are used to reduce system overhead when transmitting data in user mode and kernel mode.

[0005] In a first aspect, an embodiment of the present application provides a data transmission method, including:

[0006] Obtaining a first data identifier of the data through user process calculation;

[0007] If the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to the kernel state; wherein the pointer is used to represent the location information of the data storage;

[0008] Query whether the kernel state resource pool contains the first data identifier. If the kernel state query resource pool contains the first data identifier, there is no need to transfer the data in the user process to the kernel state; if the kernel state query resource pool does not contain the first data identifier, obtain the data from the user process according to the pointer and transfer the data to the kernel state.

[0009] The embodiment of the present application maintains a record table in the user process to record which data the user state has sent to the kernel state, thereby determining whether it is necessary to send data to the kernel state. In addition, data maintenance is also performed in the kernel state. For a specific data, if the user state has not sent the data to the kernel state before, but it is determined according to the first data identifier that the data already exists in the kernel state, then the user state does not need to send the data again. Therefore, when determining whether the data exists in the kernel state, the present application adopts the method of comparing the first data identifier instead of using the method of comparing data, which reduces the overhead of the system. In addition, the overhead of the system is further reduced by reducing the transmission of duplicate data.

[0010] In any embodiment, if the resource pool includes the first data identifier, the method further includes:

[0011] Acquire a second data identifier and a first reference count value corresponding to the first data identifier in the kernel state; wherein the second data identifier is used to uniquely represent the data;

[0012] Updating the first reference count value, and returning the second data identifier to the user process;

[0013] The second data identifier and the first data identifier are correspondingly stored in the record table through the user process.

[0014] In an embodiment of the present application, if the first data identifier does not exist in the record table but is included in the resource pool, it means that the data already exists in the kernel state and there is no need to transmit the data again. To facilitate data management, the reference count value of the data is maintained in both the resource pool and the record table. On the one hand, it is convenient to monitor the processing status of each data, and on the other hand, it can avoid repeated processing of the data.

[0015] In any embodiment, the method further comprises:

[0016] If the first data identifier exists in the record table corresponding to the user process, obtaining a second data identifier corresponding to the first data identifier from the record table;

[0017] Sending the second data identifier to the kernel state;

[0018] Acquire a corresponding first reference count value from the resource pool in the kernel state according to the second data identifier;

[0019] The first reference count value is updated.

[0020] In an embodiment of the present application, in the case where the first data identifier exists in the record table, there is no need to send the data to the kernel state. Instead, the second data identifier is sent to the kernel state, and the kernel state updates the first reference count value to indicate that the data is to be processed.

[0021] In any embodiment, the kernel state resource pool includes a red-black tree; and the transferring the data to the kernel state includes:

[0022] generating a second data identifier corresponding to the data;

[0023] The data, as well as a first data identifier, a second data identifier and a first reference count value corresponding to the data are stored in the red-black tree.

[0024] In the embodiment of the present application, since the kernel state includes multiple processes, the same process may use the same data twice, and the first data identifier, the second data identifier and the first reference count value are stored in the red-black tree. Therefore, by comparing the second data identifiers of the data to be used twice, there is no need to compare the content of the data, thereby reducing the system overhead.

[0025] In any embodiment, the method further comprises:

[0026] If the kernel process in the kernel state uses the data, the first reference count value of the data is updated.

[0027] The embodiment of the present application updates the first reference count value, thereby being able to monitor the usage of data in the kernel state.

[0028] In any embodiment, the user process calculates and obtains the first data identifier of the data, including:

[0029] The first data identifier of the data is obtained by calculating through the user process using the MD5 algorithm.

[0030] The embodiment of the present application calculates the first data identifier of the data through the MD5 algorithm, so that it can be determined from the record table through the first data identifier whether the user process has sent the data to the kernel state, and it can be determined from the resource pool whether the data exists in the kernel state, and then it can be determined whether the data needs to be sent to the kernel state, thereby reducing redundant transmission of data.

[0031] In any embodiment, the record table includes a second reference count value; the second reference count value is used to represent the number of times the corresponding data is to be processed; the method further includes:

[0032] If the amount of data recorded in the record table is greater than a preset value, the data to be removed is obtained from the record table based on the least recently used strategy; the data to be removed includes a first data identifier to be removed and a second data identifier to be removed;

[0033] Deleting the data to be removed from the record table, and sending the data to be removed to the kernel state;

[0034] Check whether the second data identifier to be removed exists in the resource pool in the kernel state. If so, and the reference count value corresponding to the second data identifier to be removed is 0, delete the data corresponding to the second data identifier to be removed from the resource pool.

[0035] In the embodiment of the present application, the data in the record table and the resource pool are deleted according to preset rules, thereby reducing the data pressure in the record table and the resource pool.

[0036] In a second aspect, an embodiment of the present application provides a data transmission device, including:

[0037] An identification calculation module, used for obtaining a first data identification of the data through user process calculation;

[0038] A first data sending module, configured to send the first data identifier and a pointer corresponding to the data to the kernel state if the first data identifier does not exist in the record table corresponding to the user process; the pointer is used to represent the location information of the data storage;

[0039] The second data sending module is used to query whether the kernel state resource pool contains the first data identifier. If it does, there is no need to transfer the data in the user process to the kernel state; if not, the data is obtained from the user process according to the pointer and the data is transferred to the kernel state.

[0040] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a bus, wherein:

[0041] The processor and the memory communicate with each other via the bus;

[0042] The memory stores program instructions that can be executed by the processor, and the processor can execute the method of the first aspect by calling the program instructions.

[0043] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, including:

[0044] The non-transitory computer-readable storage medium stores computer instructions that cause the computer to execute the method of the first aspect.

[0045] In a fifth aspect, an embodiment of the present application provides a computer program product, comprising computer program instructions, wherein when the computer program instructions are read and executed by a processor, the method of the first aspect is executed.

[0046] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0048] Figure 1 Schematic diagram of data transmission in user mode and kernel mode provided for comparison;

[0049] Figure 2 A schematic diagram of a data transmission method flow chart provided in an embodiment of the present application;

[0050] Figure 3 A schematic diagram of another data transmission method flow chart provided in an embodiment of the present application;

[0051] Figure 4 A data transmission principle diagram provided for an embodiment of the present application;

[0052] Figure 5 A schematic diagram of the structure of a data transmission device provided in an embodiment of the present application;

[0053] Figure 6 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.

[0055] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.

[0056] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.

[0057] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0058] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0059] In the description of the embodiments of the present application, the term "multiple" refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple pieces" refers to more than two pieces (including two pieces).

[0060] In the description of the embodiments of the present application, unless otherwise clearly specified and limited, technical terms such as "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense. For example, it 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, and it can be the internal connection of two elements or the interaction relationship between two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present application can be understood according to the specific circumstances.

[0061] In order to facilitate the understanding of the embodiments of the present application, the relevant terms involved in the embodiments of the present application are now explained:

[0062] Linux system: Linux system is an open source operating system. Linux system is popular for its stability, security, efficiency, flexibility and strong portability, especially in the field of servers and high-performance computing.

[0063] The main features of the Linux system include:

[0064] Multitasking: The Linux system supports multitasking, which means that multiple programs can be executed at the same time, and each program runs independently of each other.

[0065] Good user interface: Linux system provides two interfaces for users: user interface and system call. At the same time, Linux also provides users with a graphical user interface (GUI), which presents users with an intuitive, easy-to-operate, and highly interactive friendly graphical interface through facilities such as mouse, menu, window, and scroll bar.

[0066] Device independence: The Linux system treats all external devices as files. As long as the driver is installed, any user can operate and use these devices like files. This device independence makes the Linux system highly flexible and scalable.

[0067] Rich network functions: The Linux system has built-in comprehensive network functions, which can easily realize network communication and data sharing.

[0068] Reliable security system: The Linux system has adopted many security technical measures, including read / write control, protected subsystems, audit tracking, core authorization, etc., providing the necessary security protection for users in a network multi-user environment.

[0069] Good portability: The Linux system has good portability, and the operating system can be easily transferred from one platform to another while maintaining its original functions and performance.

[0070] User state: User state is a low-level execution state set by the operating system to limit user access to system resources. When a user program is running, it is usually in user state. In user state, the program can only access limited system resources and cannot perform certain privileged operations, such as accessing hardware, modifying the memory of other processes, etc.

[0071] User process: A user-mode process is a process running in an operating system. The process is executed in user mode and is subject to the permissions and restrictions provided by the operating system. In most modern operating systems, including Unix, Linux, and Windows, processes are designed to switch between user mode and kernel mode.

[0072] Kernel state: Kernel state is the highest level of privilege in the operating system. When the operating system kernel program is running, it is usually in kernel state. In kernel state, the program can access all system resources and perform any privileged operations. These privileged operations include accessing hardware, allocating memory, managing processes and threads, and managing system files.

[0073] Kernel process: A process running in kernel state.

[0074] MD5 algorithm: MD5 (Message-Digest Algorithm 5) is a widely used cryptographic hash function that can generate a 128-bit (16-byte) hash value to ensure the integrity and consistency of information transmission. MD5 was designed by Ronald Linn Rivest, made public in 1992, and is widely used in the field of cryptography.

[0075] Main features of the MD5 algorithm

[0076] Fixed-length output: Regardless of the length of the input data, the output of the MD5 algorithm is a fixed-length hash value (128 bits).

[0077] High sensitivity: For small changes in the input data, the hash value output by the MD5 algorithm will also be very different.

[0078] Irreversibility: The original data cannot be restored from the MD5 hash value.

[0079] Collision avoidance: Ideally, two different input data should produce different hash values.

[0080] Hash algorithm: Hash algorithm, also known as hash function or summary function, is a mathematical function or algorithm that converts data of any length (called "message") into a string of fixed length (called "hash value" or simply "hash"). Hash algorithm can convert input of any length (also called message, plaintext) into output of fixed length (also called hash value, hash value, summary) through hash operation.

[0081] Red-black tree: Red-black tree is a specialized AVL tree (balanced binary tree). They all use specific operations to keep the binary search tree balanced, thereby achieving higher search performance. Although the red-black tree has a complex structure, its worst-case running time is still very good, and it can complete search, insertion, and deletion operations in O(log n), where n is the number of elements in the tree.

[0082] The main characteristics of red-black trees include:

[0083] Each node is either red or black.

[0084] The root node is black.

[0085] Every red node has two black children (there cannot be two consecutive red nodes on any path from every leaf to the root).

[0086] All paths from any node to each of its leaf nodes contain the same number of black nodes.

[0087] These characteristics ensure the key property of the red-black tree: the longest possible path from the root to the leaf is no longer than twice the shortest possible path. Therefore, the tree is roughly balanced, making the red-black tree efficient when performing operations such as insertion, deletion, and search.

[0088] Least Recently Used (LRU) strategy is a commonly used memory management strategy, especially in cache replacement algorithms. The core idea is that if a piece of data has not been accessed in the recent period, then it is unlikely to be accessed in the future. Therefore, when there is not enough space to accommodate new data, the data that has not been used for the longest time will be eliminated first.

[0089] The implementation of the LRU strategy usually relies on a data structure, such as a linked list or a combination of a hash table and a linked list. In a linked list implementation, the most recently accessed data is moved to the head of the linked list, while the least recently accessed data is at the tail of the linked list. When data needs to be eliminated, it can be directly deleted from the tail of the linked list.

[0090] IDR (Indexed Directly Readable) is a technology used in the Linux kernel to manage data sets of limited size. It provides a compact and efficient way to store and access data. The basic principle of IDR is to organize data into an array and use indexes to access elements in the array. Each element has a unique index, through which the corresponding data can be quickly obtained or modified. In the Linux kernel, IDR is often used to manage various resources or objects, such as device numbers, file descriptors, network sockets, etc. By using IDR, you can avoid using dynamically allocated memory to store this data, thereby reducing memory overhead and the complexity of memory management.

[0091] Figure 1 The schematic diagram of data transmission in user mode and kernel mode provided for comparison is as follows: Figure 1 As shown. There are many processes in user state handling the same business, and each process will write certain data to the kernel state resource pool. These data may be the same or different, and the kernel process will read data from the resource pool. The data used by each process may be the same or different, and even the data used twice in the same process may be the same or different, and then use these data to perform business work. Therefore, in the prior art, the user process may write the same data to the kernel state resource pool multiple times, resulting in a large system overhead.

[0092] In order to solve this technical problem, the embodiment of the present application provides a data transmission method, device, electronic device and storage medium. Before transmitting data, the user process determines whether the data has been sent to the kernel state before. If it has been sent, it will not continue to send it. If it is determined in the user process that the data has not been sent to the kernel state before, it will query whether the data already exists in the kernel state. If it already exists, it will not continue to send the data. Thereby, the transmission of redundant data can be reduced and the system overhead can be reduced.

[0093] It is understandable that the data transmission method provided in the embodiment of the present application can be applied to electronic devices, and the electronic devices can be Linux systems, windows systems, Unix systems, etc. The embodiment of the present application is described below with Linux systems as an example. The Linux system includes a central processing unit (CPU), and the CPU switches kernel state and user state by executing specific instructions or specific events (such as interruptions). When the user program needs to execute a system call or an exception occurs, the CPU will switch to the kernel state to execute the corresponding processing program. After the processing is completed, the CPU will switch back to the user state and continue to execute the user program.

[0094] Figure 2 A data transmission method flow chart provided in an embodiment of the present application is as follows: Figure 2 As shown, the method includes:

[0095] Step 201: Obtain a first data identifier of data through user process calculation.

[0096] Before sending data to the kernel state through the user process, the Linux system will calculate the first data identifier of the data through the user process. For example, the summary (key value) of the data can be calculated according to the MD5 algorithm, and the calculated summary is used as the first data identifier. The first data identifier can be used to indicate the uniqueness of the data. It is understandable that in addition to the MD5 algorithm, a hash algorithm or the like can also be used for calculation, and the embodiments of the present application do not specifically limit this.

[0097] Step 202: If the first data identifier does not exist in the record table corresponding to the user process, the first data identifier and a pointer corresponding to the data are sent to the kernel state; the pointer is used to represent the location information of the data storage.

[0098] Multiple user processes can be run in the Linux system, and each user process maintains its own record table, which is used to record relevant information of data sent by the user process to the kernel state, for example: including the first data identifier of the sent data.

[0099] After calculating and obtaining the first data identifier, the Linux system queries the corresponding user process record table for the first data identifier. If the first data identifier does not exist, it means that the user process has not sent the data before. In order to achieve the purpose of sending data to the kernel state, the first data identifier and the pointer corresponding to the data are sent to the kernel state. The pointer is used to represent the memory address where the data is stored in the user state, and the corresponding data can be obtained from the user state based on the pointer.

[0100] Step 203: Query whether the resource pool of the kernel state contains the first data identifier. If so, there is no need to transfer the data in the user process to the kernel state; if not, obtain the data from the user process according to the pointer and transfer the data to the kernel state.

[0101] The kernel state resource pool is used to store data sent from the user state, and the data is stored in a certain data structure, for example, in a red-black tree manner.

[0102] The Linux system queries whether the resource pool in the kernel state contains the first data identifier. If the first data identifier is contained, it means that the data is stored in the kernel state, and there is no need to resend the data from the user state to the kernel state. If the first data identifier is not in the resource pool, it means that the data is not in the kernel state. The Linux system can obtain the data from the user state memory based on the pointer and write the data to the resource pool in the kernel state to complete the data transmission from the user state to the kernel state.

[0103] The embodiment of the present application maintains a record table in the user process to record which data the user state has sent to the kernel state, thereby determining whether it is necessary to send data to the kernel state. In addition, data maintenance is also performed in the kernel state. For a specific data, if the user state has not sent the data to the kernel state before, but it is determined according to the first data identifier that the data already exists in the kernel state, then the user state does not need to send the data again. Therefore, when determining whether the data exists in the kernel state, the present application adopts the method of comparing the first data identifier instead of using the method of comparing data, which reduces the overhead of the system. In addition, the overhead of the system is further reduced by reducing the transmission of duplicate data.

[0104] Based on the above embodiment, for the case where the resource pool contains the first data identifier, the method further includes:

[0105] Acquire a second data identifier and a first reference count value corresponding to the first data identifier in the kernel state; wherein the second data identifier is used to uniquely represent the data;

[0106] Updating the first reference count value, and returning the second data identifier to the user process;

[0107] The second data identifier and the first data identifier are correspondingly stored in the record table through the user process.

[0108] In the specific implementation process, if the resource pool contains the first data identifier, the second data identifier and the first reference count value corresponding to the first data identifier can be obtained from the resource pool. Among them, the second data identifier is also used to characterize the uniqueness of the data. The second data identifier is used because for the scenario where the first data identifier is the md5 value (16 bytes) and the second data identifier is an int type (4 bytes) id, since in the red-black tree in the kernel state, both search and deletion are judged by key, then the function of comparing whether the key is the same is as short as possible, and comparing an int type data is better than comparing the md5 value. Therefore, the second data identifier is introduced in the kernel state, and both data identifiers can be used to express a unique data. The first reference count value is used to characterize the situation in which the data is processed (or used) in the kernel state. If the first reference count value is a positive number, it means that the data still needs to be processed. If the first reference count is 0, it means that the data has been processed.

[0109] In the kernel state, after the first data identifier is queried, it indicates that the data corresponding to the first data identifier needs to be processed, and the first reference count value corresponding to the data should be updated, for example, by adding 1 to it.

[0110] After the second data identifier is obtained, the second data identifier is returned to the user process, and the second data identifier and the first data identifier are correspondingly stored in a record table through the user process to indicate that the data has been sent to the kernel state.

[0111] It should be noted that if the kernel process in the kernel state uses the data, the first reference count value corresponding to the data is reduced by 1.

[0112] In an embodiment of the present application, if the first data identifier does not exist in the record table but is included in the resource pool, it means that the data already exists in the kernel state and there is no need to transmit the data again. To facilitate data management, the reference count value of the data is maintained in both the resource pool and the record table. On the one hand, it is convenient to monitor the processing status of each data, and on the other hand, it can avoid repeated processing of the data.

[0113] Based on the above embodiment, in view of the situation where the first data identifier exists in the record table, the method further includes:

[0114] If the first data identifier exists in the record table corresponding to the user process, obtaining a second data identifier corresponding to the first data identifier from the record table;

[0115] Sending the second data identifier to the kernel state;

[0116] Acquire a corresponding first reference count value from the resource pool in the kernel state according to the second data identifier;

[0117] The first reference count value is updated.

[0118] In a specific implementation process, if the first data identifier exists in the record table corresponding to the user process, it means that the user process has sent the data to the kernel state, and will not send data to the kernel state this time. The record table stores relevant information about the data that the user process has sent to the kernel state, for example, including the first data identifier and the second data identifier corresponding to the data. Therefore, the corresponding second data identifier can be obtained from the record table based on the first data identifier.

[0119] After obtaining the second data identifier, the second data identifier is sent to the kernel state, thereby updating the first reference count value corresponding to the data in the kernel state, specifically, the first reference count value is increased by 1, and the purpose of increasing by 1 is to indicate the number of times the data corresponding to the second data identifier is to be processed.

[0120] In an embodiment of the present application, in the case where the first data identifier exists in the record table, there is no need to send the data to the kernel state. Instead, the second data identifier is sent to the kernel state, and the kernel state updates the first reference count value to indicate that the data is to be processed.

[0121] Based on the above embodiment, the resource pool in the kernel state includes a red-black tree; and the transmitting the data to the kernel state includes:

[0122] generating a second data identifier corresponding to the data;

[0123] The data, as well as a first data identifier, a second data identifier and a first reference count value corresponding to the data are stored in the red-black tree.

[0124] In the specific implementation process, the data in the kernel-state resource pool is stored in a red-black tree data structure. Therefore, after acquiring data from the user state to the kernel state, the acquired data, the first data identifier corresponding to the data, the second data identifier and the first reference count value can be stored as a piece of data in the red-black tree of the resource pool.

[0125] The method of inserting data in a red-black tree is as follows:

[0126] 1. Define the nodes of the red-black tree:

[0127] Each node contains at least the following attributes:

[0128] Key value (md5): used for search storage using md5 as the key.

[0129] Key value (id): used to search and delete using id as key.

[0130] Reference count (refcount): indicates the count of data being used by multiple processes.

[0131] Data pointer (data): Memory address information that stores real data.

[0132] Color: red or black.

[0133] Left child (left): A pointer to the left child node.

[0134] Right child (right): A pointer to the right child node.

[0135] parent: A pointer to the parent node (may be needed in some implementations to allow fast access to the parent node when recoloring or rotating).

[0136] 2. Insert operation:

[0137] Perform a normal binary search tree insertion: First, like a normal binary search tree, find the position where the new node should be inserted.

[0138] Set the color of new nodes to red: Newly inserted nodes are always red to maintain the properties of red-black trees.

[0139] Fixing the properties of red-black trees: After inserting a new node, you may need to perform some operations to maintain the five properties of red-black trees:

[0140] Each node is either red or black.

[0141] The root node is black.

[0142] Each leaf node (NIL node, empty node) is black.

[0143] If a node is red, both of its children are black.

[0144] For each node, the simple paths from that node to all of its descendant leaf nodes contain the same number of black nodes.

[0145] To fix these properties, you may need to do one or more of the following:

[0146] Color Flip: Swap the color of a red node with its black parent node.

[0147] Left rotation: Rotate left around a node.

[0148] Right rotation: Perform a right rotation around a node.

[0149] In the embodiment of the present application, since the kernel state includes multiple processes, the same process may use the same data twice, and the first data identifier, the second data identifier and the first reference count value are stored in the red-black tree. Therefore, by comparing the second data identifiers of the data to be used twice, there is no need to compare the content of the data, thereby reducing the system overhead.

[0150] Based on the above embodiment, the method further includes:

[0151] If the kernel process in the kernel state uses the data, the first reference count value of the data is updated.

[0152] In the specific implementation process, if it is monitored that the kernel process in the kernel state has used the data once, the first reference count value corresponding to the data can be updated, for example, the first reference count value can be reduced by 1. The first reference count value indicates how many user processes notify the kernel process to use this data when performing business operations; the second reference count value indicates the number of times the same data is used multiple times in the same process. When there is only one user process, even if the user process uses the same data multiple times, since it first searches the hash table in the user state each time, it only needs to increase the second reference count value once. When there are multiple processes in the user state executing the same business, since the resources of different processes are isolated from each other, they will all go to the kernel state for a unified search, so there will be a scenario where the same data is used by multiple processes. At this time, each process adds 1 to the first reference count value before using it, and subtracts 1 after use.

[0153] When the first reference count value corresponding to the data is 0, it means that the data has been completely used or processed.

[0154] The embodiment of the present application updates the first reference count value, thereby being able to monitor the usage of data in the kernel state.

[0155] Based on the above embodiment, the user process calculates and obtains the first data identifier of the data, including:

[0156] The first data identifier of the data is obtained by calculating through the user process using the MD5 algorithm.

[0157] In the specific implementation process, in order to obtain an identifier for characterizing the uniqueness of data, the MD5 algorithm can be used to calculate the content of the data to obtain the first data identifier. It should be noted that the specific method of calculating the first data identifier of data using the MD5 algorithm is not specifically limited in this embodiment of the application.

[0158] In addition to using the MD5 algorithm, other methods can also be used, such as hashing the data.

[0159] The embodiment of the present application calculates the first data identifier of the data through the MD5 algorithm, so that it can be determined from the record table through the first data identifier whether the user process has sent the data to the kernel state, and it can be determined from the resource pool whether the data exists in the kernel state, and then it can be determined whether the data needs to be sent to the kernel state, thereby reducing redundant transmission of data.

[0160] Based on the above embodiment, the record table includes a second reference count value; the second reference count value is used to represent the number of times the corresponding data is to be processed; the method further includes:

[0161] If the amount of data recorded in the record table is greater than a preset value, the data to be removed is obtained from the record table based on the least recently used strategy; the data to be removed includes a first data identifier to be removed and a second data identifier to be removed;

[0162] Deleting the data to be removed from the record table, and sending the data to be removed to the kernel state;

[0163] Check whether the second data identifier to be removed exists in the resource pool in the kernel state. If so, and the reference count value corresponding to the second data identifier to be removed is 0, delete the data corresponding to the second data identifier to be removed from the resource pool.

[0164] In the specific implementation process, in order to prevent the storage of too much data in the kernel state, the data in the kernel state can be deleted according to certain rules. In addition, a certain capacity is also pre-set in the record table in the user state, and when the stored content is greater than the preset amount, the deletion operation is also performed.

[0165] The data volume refers to the number of a piece of data consisting of the first data identifier, the second data identifier and the second reference count value stored in the record table. Assuming the preset value is 128, when the amount of data in the record table corresponding to the user process is greater than 128, the data removal operation is triggered. When performing data removal, the least recently used strategy (LRU) is adopted to select the data to be removed. It can be understood that the number of data to be removed can be 1 or more. It can be understood that the second reference count value corresponding to the data to be removed is 0, indicating that the data to be removed has been processed.

[0166] After the data to be removed is determined, the data to be removed is deleted from the record table. The second data identifier of the data to be processed can be sent to the kernel state, and the first reference count value corresponding to the second data identifier in the kernel state resource pool is queried to see if it is 0. If it is 0, it means that the data corresponding to the second data identifier has been processed and can be deleted. At this time, the data can be deleted. If it is not 0, it means that the data has not been processed and the data will not be deleted.

[0167] In the embodiment of the present application, the data in the record table and the resource pool are deleted according to preset rules, thereby reducing the data pressure in the record table and the resource pool.

[0168] In another embodiment, a data deletion operation can also be initiated in the kernel state, that is, the data to be deleted is determined from the kernel state resource pool using the LRU strategy, the data to be deleted is deleted, and the second data identifier corresponding to the data to be deleted is sent to each user state. If the second data identifier is included in the record table of the user state, and the second reference count value corresponding to the second data identifier is 0, the data corresponding to the second data identifier is deleted.

[0169] Figure 3 A flowchart of another data transmission method provided in an embodiment of the present application is shown below. Figure 4 A data transmission principle diagram provided in an embodiment of the present application, such as Figure 3 and Figure 4 As shown, the method includes:

[0170] Step 301: Calculate the key value of the data; before writing data to the kernel process through the user process, first calculate a digest based on the content of the data through the MD5 algorithm to obtain a key value (first data identifier).

[0171] Step 302: Check whether the key value exists in the hash table; check whether the key value exists in the hash table maintained in the user process to determine whether the data has been used. If the key value exists in the hash table, obtain the corresponding ID (second data identifier) ​​according to the key value and execute step 308, otherwise execute step 303.

[0172] Step 303: If the key value does not exist in the hash table, the key value and the pointer of the data are sent to the kernel process.

[0173] Step 304: Check whether the key value exists in the red-black tree; the kernel process uses the key value to find it from the red-black tree. If it is found, it means that this set of data already exists in the resource pool, and step 305 is executed; otherwise, step 307 is executed;

[0174] Step 305: Increase the first reference count value Ref of the data corresponding to the key value, indicating that the data will be used, and return the id corresponding to the key value to the user state process, so that the user state process does not need to pass the content of the specific data Data to the kernel state.

[0175] Step 306: After obtaining the id, the user state process inserts the key value and the id into the hash table maintained by the user state process.

[0176] Step 307: If not found, it means that the data set is not in the resource pool. The kernel process obtains the data from the user state based on the pointer, generates an id corresponding to the data, and stores the data, key value, id and first reference count value in the red-black tree. The key value and id of the data are returned to the user state. It should be noted that when the kernel state generates the id of the data, it can be generated based on the IDR, that is, a unique id is generated for the data by incrementing the IDR.

[0177] Step 308: If the id exists in the record table, the id is sent to the kernel process, and the kernel process searches from the resource pool according to the id. Generally, the id stored in the user state record table can find the corresponding id in the resource pool. After finding the corresponding id, the first reference count value corresponding to the id is increased by 1.

[0178] In the embodiment of the present application, since the kernel state also obtains the data to be used from the red-black tree by multiple processes, the data used last time and the data used this time may be the same. At this time, it is only necessary to compare whether the corresponding IDs are the same twice, and there is no need to compare the data content, thereby reducing the system overhead. In addition, in order to prevent too much data from being stored in the kernel state, when the data reaches a certain amount, the data with the first reference count value of 0 will be deleted. Therefore, through the above scheme, in the process of data transmission between the user state process and the kernel state process, the total overhead is reduced due to the reduction of data copying of the same data transmitted multiple times and the reduction of the overhead of the kernel state process when using the same data twice to compare data, and finally the purpose of optimizing performance is achieved.

[0179] Figure 5 This is a schematic diagram of a data transmission device provided in an embodiment of the present application. The device may be a module, program segment or code on an electronic device. It should be understood that the device is similar to the above Figure 2 The method embodiment corresponds to and can be executed Figure 2 The various steps involved in the method embodiment and the specific functions of the device can be found in the above description. To avoid repetition, detailed description is appropriately omitted here. The device includes: an identification calculation module 501, a first data sending module 502 and a second data sending module 503, wherein:

[0180] The identification calculation module 501 is used to obtain the first data identification of the data through user process calculation;

[0181] The first data sending module 502 is used for sending the first data identifier and a pointer corresponding to the data to the kernel state if the first data identifier does not exist in the record table corresponding to the user process; the pointer is used to represent the location information of the data storage;

[0182] The second data sending module 503 is used to query whether the resource pool contains the first data identifier through the kernel state. If it is contained, there is no need to transfer the data in the user process to the kernel state; if not, the data is obtained from the user process according to the pointer and the data is transferred to the kernel state.

[0183] Based on the above embodiment, the device further includes a first updating module, which is used to:

[0184] If the resource pool contains the first data identifier, obtaining a second data identifier and a first reference count value corresponding to the first data identifier in the kernel state; wherein the second data identifier is used to uniquely represent the data;

[0185] Updating the first reference count value, and returning the second data identifier to the user process;

[0186] The second data identifier and the first data identifier are correspondingly stored in the record table through the user process.

[0187] Based on the above embodiment, the device further includes a second updating module, which is used to:

[0188] If the first data identifier exists in the record table corresponding to the user process, obtaining a second data identifier corresponding to the first data identifier from the record table;

[0189] Sending the second data identifier to the kernel state;

[0190] Acquire a corresponding first reference count value from the resource pool in the kernel state according to the second data identifier;

[0191] The first reference count value is updated.

[0192] On the basis of the above embodiment, the kernel state resource pool includes a red-black tree; the second data sending module 503 is specifically used for:

[0193] generating a second data identifier corresponding to the data;

[0194] The data, as well as a first data identifier, a second data identifier and a first reference count value corresponding to the data are stored in the red-black tree.

[0195] Based on the above embodiment, the device further includes a third updating module, which is used to:

[0196] If the kernel process in the kernel state uses the data, the first reference count value of the data is updated.

[0197] Based on the above embodiment, the identification calculation module 501 is specifically used for:

[0198] The first data identifier of the data is obtained by calculating through the user process using the MD5 algorithm.

[0199] Based on the above embodiment, the record table includes a second reference count value; the second reference count value is used to represent the number of times the corresponding data is to be processed; the device also includes a deletion module, which is used to:

[0200] If the amount of data recorded in the record table is greater than a preset value, the data to be removed is obtained from the record table based on the least recently used strategy; the data to be removed includes a first data identifier to be removed and a second data identifier to be removed;

[0201] Deleting the data to be removed from the record table, and sending the data to be removed to the kernel state;

[0202] Check whether the second data identifier to be removed exists in the resource pool in the kernel state. If so, and the first reference count value corresponding to the second data identifier to be removed is 0, delete the data corresponding to the second data identifier to be removed from the resource pool.

[0203] Figure 6 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 6 As shown, the electronic device includes: a processor (processor) 601, a memory (memory) 602 and a bus 603; wherein,

[0204] The processor 601 and the memory 602 communicate with each other via the bus 603;

[0205] The processor 601 is used to call the program instructions in the memory 602 to execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a first data identifier of the data through calculation by a user process; if the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to the kernel state; the pointer is used to represent the location information of the data storage; querying whether the resource pool of the kernel state contains the first data identifier, if it does, there is no need to transfer the data in the user process to the kernel state; if it does not, obtaining the data from the user process according to the pointer, and transferring the data to the kernel state.

[0206] The processor 601 may be an integrated circuit chip with signal processing capabilities. The processor 601 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0207] The memory 602 may include but is not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable read-only memory (EEPROM), etc.

[0208] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a first data identifier of data through calculation by a user process; if the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to a kernel state; the pointer is used to represent the location information of the data storage; querying whether the resource pool of the kernel state contains the first data identifier, if it does, there is no need to transfer the data in the user process to the kernel state; if it does not, obtaining the data from the user process according to the pointer, and transferring the data to the kernel state.

[0209] The present embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments, for example, including: obtaining a first data identifier of the data through calculation by a user process; if the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to the kernel state; the pointer is used to represent the location information of the data storage; querying whether the resource pool of the kernel state contains the first data identifier, if it does, there is no need to transfer the data in the user process to the kernel state; if it does not, obtaining the data from the user process according to the pointer, and transferring the data to the kernel state.

[0210] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0211] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0212] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0213] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0214] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A data transmission method, characterized in that: include: Obtaining a first data identifier of the data through user process calculation; If the first data identifier does not exist in the record table corresponding to the user process, sending the first data identifier and a pointer corresponding to the data to the kernel state; the pointer is used to represent the location information of the data storage; Query whether the resource pool of the kernel state contains the first data identifier. If so, there is no need to transfer the data in the user process to the kernel state; if not, obtain the data from the user process according to the pointer and transfer the data to the kernel state.

2. The method according to claim 1, characterized in that If the resource pool contains the first data identifier, the method further includes: Acquire a second data identifier and a first reference count value corresponding to the first data identifier in the kernel state; wherein the second data identifier is used to uniquely represent the data; Updating the first reference count value, and returning the second data identifier to the user process; The second data identifier and the first data identifier are correspondingly stored in the record table through the user process.

3. The method according to claim 1, characterized in that The method further comprises: If the first data identifier exists in the record table corresponding to the user process, obtaining a second data identifier corresponding to the first data identifier from the record table; Sending the second data identifier to the kernel state; Acquire a corresponding first reference count value from the resource pool in the kernel state according to the second data identifier; The first reference count value is updated.

4. The method according to claim 1, characterized in that: The resource pool of the kernel state includes a red-black tree; and the transmitting the data to the kernel state includes: generating a second data identifier corresponding to the data; The data, as well as a first data identifier, a second data identifier and a first reference count value corresponding to the data are stored in the red-black tree.

5. The method according to claim 1, characterized in that The method further comprises: If the kernel process in the kernel state uses the data, the first reference count value of the data is updated.

6. The method according to claim 1, characterized in that The first data identifier of the data obtained by the user process calculation includes: The first data identifier of the data is obtained by calculating through the user process using the MD5 algorithm.

7. The method according to claim 1, characterized in that The record table includes a second reference count value; the second reference count value is used to represent the number of times the corresponding data is to be processed; the method also includes: If the amount of data recorded in the record table is greater than a preset value, the data to be removed is obtained from the record table based on the least recently used strategy; the data to be removed includes a first data identifier to be removed and a second data identifier to be removed; Deleting the data to be removed from the record table, and sending the data to be removed to the kernel state; Check whether the second data identifier to be removed exists in the resource pool in the kernel state. If so, and the first reference count value corresponding to the second data identifier to be removed is 0, delete the data corresponding to the second data identifier to be removed from the resource pool.

8. A data transmission device, characterized in that: include: An identification calculation module, used for obtaining a first data identification of the data through user process calculation; A first data sending module, configured to send the first data identifier and a pointer corresponding to the data to the kernel state if the first data identifier does not exist in the record table corresponding to the user process; the pointer is used to represent the location information of the data storage; The second data sending module is used to query whether the resource pool contains the first data identifier through the kernel state. If it is contained, there is no need to transfer the data in the user process to the kernel state; if not, the data is obtained from the user process according to the pointer and the data is transferred to the kernel state.

9. An electronic device, characterized in that: include: processor, memory and bus, wherein, The processor and the memory communicate with each other via the bus; The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which, when executed by a computer, cause the computer to perform the method according to any one of claims 1 to 7.

11. A computer program product, characterized in that The method comprises computer program instructions, and when the computer program instructions are read and executed by a processor, the method according to any one of claims 1 to 7 is executed.

Citation Information

Patent Citations

  • Kernel-mode data access method, device and system

    CN103544324A

  • Method and system for accessing distributed block storage system in kernel mode

    CN112039999A

  • Data transmission method and device, storage medium and electronic equipment

    CN114201317A

  • Method and device for obtaining router online terminal list, equipment and storage medium

    CN115022226A

  • Data acquisition method and device and electronic equipment

    CN116302171A