Shared memory management method, device, computer equipment and storage medium

By applying for large memory blocks in shared memory management and registering them to the network card, and directly sending messages using DMA, the inefficient execution caused by frequent system calls and memory copies in traditional technology is solved, and more efficient data transmission is achieved.

CN113485834BActive Publication Date: 2024-11-01ARCHFORCE FINANCIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110782884.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-12
Publication Date
2024-11-01
Estimated Expiration
2041-07-12

AI Technical Summary

Technical Problem

Frequent system calls and memory copying in traditional shared memory management technology lead to reduced process execution efficiency, especially in memory sharing scenarios between multi-processes and multi-threads.

Method used

By applying for large memory blocks and registering them to the network card, the application messages are directly sent to the data receiver using the Direct Memory Access Interface (DMA), which avoids the central processor driver and multiple system calls, and reduces the memory copy operation.

Benefits of technology

It improves process execution efficiency, reduces system calls and memory copy overhead, and improves data transmission efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113485834B_ABST
    Figure CN113485834B_ABST
Patent Text Reader

Abstract

The present application relates to a shared memory management method, device, computer equipment and storage medium. The method comprises: applying for memory through an application calling the first interface of the operating system, obtaining a memory block of a specified size from a constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for a business processing; sending the address of the memory block to a network card, so that the network card directly reads the memory block according to the address through a direct memory access interface, and sends the application message on the memory block to a data recipient; wherein the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool. The use of this method can improve the process execution efficiency to a certain extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory management technology, and in particular to a shared memory management method, apparatus, computer equipment and storage medium. Background Art

[0002] With the development of memory management technology, shared memory management technology has emerged in order to achieve memory sharing between multiple processes and multiple threads, improve data transmission efficiency, and reduce memory usage.

[0003] In traditional technology, data is sent to the target module or application through common inter-thread communication or inter-process communication mechanisms. The whole process involves system calls, and memory copying is inevitable. The negative impact of memory copying is mainly the additional overhead and delay caused by memory application and release and copying process. Specifically, when an application requests memory from the system, it can obtain it by calling a general function interface that manages a certain amount of memory, and then copy the data to the obtained memory. The data in the obtained memory is then sent out through the kernel.

[0004] However, in the traditional method, the memory managed by the general function interface is not very large, so it is often necessary to obtain memory through system calls, and system calls are also required when the kernel sends data. Since the memory managed by the general function interface is small, the number of memory applications occurs more frequently, and the corresponding kernel sends data more frequently. Frequent memory applications and kernel data sending lead to relatively frequent system calls, which brings additional overhead and delay to the system, and reduces the execution efficiency of the process to a certain extent. Summary of the invention

[0005] Based on this, it is necessary to provide a shared memory management method, device, computer equipment and storage medium that can improve the process execution efficiency to a certain extent in response to the above technical problems.

[0006] A shared memory management method, the method comprising:

[0007] Calling the first interface of the operating system through the application to apply for memory, obtaining a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing;

[0008] The address of the memory block is sent to the network card, so that the network card directly reads the memory block according to the address through the direct memory access interface, and sends the application message on the memory block to the data recipient; wherein the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0009] In one embodiment, the application message on the memory block is sent to a data recipient, and the method further includes:

[0010] The offset address of the memory block in the shared memory pool is forwarded to the message landing subprocess for landing, so that the memory block is backed up locally.

[0011] In one embodiment, forwarding the offset address of the memory block in the shared memory pool to the message landing subprocess for landing includes:

[0012] Obtain the virtual address of the memory block mapped to the message landing subprocess;

[0013] Obtaining the offset address of the memory block in the shared memory pool sent by the application calling the sending interface of the operating system;

[0014] According to the virtual address and the offset address, the message landing subprocess obtains the memory address of the memory block;

[0015] According to the memory address, the message landing subprocess lands.

[0016] In one embodiment, the method further comprises:

[0017] Define the structure of the shared memory pool;

[0018] Create a shared memory pool through the memory sharing function;

[0019] Define a pointer to a shared memory structure and get the definition pointer;

[0020] The created shared memory pool is mapped to the definition pointer through a file mapping function to obtain a constructed shared memory pool.

[0021] In one embodiment, the method further comprises:

[0022] The network card receives an external message and writes the external message into the memory block;

[0023] When the network card completes writing to the memory block, the memory block is handed over to the application for data reading and processing;

[0024] The shared memory pool has been registered with the network card, so that the network card has the write permission of the shared memory pool.

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

[0026] The memory margin of the shared memory pool is read into the register corresponding to the thread in real time, and the memory margin of the shared memory pool is checked to see whether it meets the memory requirements of the thread operation;

[0027] When the memory margin satisfies the memory required for the thread to run, the required memory is allocated to the thread from the shared memory pool, and a compare and swap instruction is obtained, and the memory margin is compared with a memory variable in a register corresponding to the thread according to the compare and swap instruction;

[0028] When the memory margin is equal to the memory variable in the register corresponding to the thread, the required memory is subtracted from the memory variable to obtain a new memory variable, and the new memory variable is stored in the register corresponding to the thread.

[0029] In one embodiment, a process includes a first thread and a second thread, wherein after the first thread completes the step of reading the memory balance of the shared memory pool into the register corresponding to the thread in real time, the second thread executes the step of reading the memory balance of the shared memory pool into the register corresponding to the thread in real time.

[0030] A shared memory management device, the device comprising:

[0031] A memory application module, used to apply for memory by calling the first interface of the operating system through the application, and obtain a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing;

[0032] An application message sending module is used to send the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through a direct memory access interface, and sends the application message on the memory block to a data recipient; wherein the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0033] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:

[0034] Calling the first interface of the operating system through the application to apply for memory, obtaining a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing;

[0035] Sending the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through a direct memory access interface, and sends the application message on the memory block to a data receiver;

[0036] The shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0037] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the following steps:

[0038] Calling the first interface of the operating system through the application to apply for memory, obtaining a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing;

[0039] Sending the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through a direct memory access interface, and sends the application message on the memory block to a data receiver;

[0040] The shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0041] The above-mentioned shared memory management method, device, computer equipment and storage medium, the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool. The application applies for memory by calling the first interface of the operating system, and obtains a memory block of a specified size from the constructed shared memory pool. When the memory block is specified, the memory required for at least one business processing can be set, that is, the memory block of the specified size is a very large memory block. The application can construct an application message on the memory block; the network card directly reads the memory block through the direct memory access interface according to the address of the memory block. This process does not require the memory to be sent to the network card through the central processing unit driver. The network card then sends the application message to the data recipient. By applying for a large memory, there is no need to call the operating system interface multiple times, and by setting the network card to read the memory, there is no need to copy the memory back and forth for each process. Therefore, this application can improve the process execution efficiency to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 An application environment diagram of a shared memory management method in one embodiment;

[0043] Figure 2 A schematic diagram of a shared memory management method in one embodiment;

[0044] Figure 3 is a structural block diagram of a shared memory management device in one embodiment;

[0045] Figure 4 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0047] The shared memory management method provided in this application can be applied to Figure 1 In the application environment shown. It includes a data sending end 102, a server 104 and a data receiving end 106. The data sending end 102 writes the application message to the memory block through the application. The memory block is located on the server 104. The data receiving end 106 is used to receive the application message sent by the server 104. The server 104 can be implemented by an independent server 104 or a server 104 cluster composed of multiple servers 104. The application runs on the server 104, the operating system runs in the CPU, and the CPU runs in the server 104. The application calls the interface of the operating system in the CPU to apply for memory and obtain a memory block of a certain size. Different from the traditional data sending process, by registering the network card and the direct memory access interface, the network card can directly read the application message on the memory block and send it to the data recipient.

[0048] In one embodiment, Figure 2 As shown, a shared memory management method is provided, which is applied to Figure 1 The terminal in is used as an example to illustrate, including the following steps:

[0049] Step 202, the application calls the first interface of the operating system to apply for memory, and obtains a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing.

[0050] Among them, the application is a program on the server, which is an instance of a process running on the server. In this application, all software programs run in the CPU, and the kernel is the operating system, which also runs in the CPU. There are multiple cores running on a server. Since a CPU may be configured with 4 cores or 8 cores, the number of cores on the server is not consistent with the number of CPUs. The constructed shared memory pool is a large memory block, and several small memory blocks can be divided from this large memory block. A memory block of a specified size belongs to a memory block in the shared memory pool.

[0051] The first interface of the operating system is the interface for the application to call the operating system to request memory from the background server. By calling the first interface of the operating system, the application can request a larger memory, and the memory obtained is a memory block of a specified size, wherein the specified size is set according to business needs during initialization, for example, the specified size can be 1G. Since a large amount of memory is requested during initialization, the memory will be occupied by the memory management structure during operation and will not be released to the operating system under normal circumstances. Therefore, the system call will not be triggered at a high frequency, and the application performance (latency) will not be affected.

[0052] After obtaining the memory block of the specified size, the data sender can construct on the memory block through the application, that is, write the application message, which is a "write" process of writing data to the memory block. Among them, the application message is the message input by the user through the application. For example, in the financial industry, buying and selling stocks includes users who buy and sell stocks and data service processing providers that collect statistics on the user's stock trading. Every time the user makes a transaction, the data service processing provider will record, analyze and calculate the user and the user's transaction behavior. Here, the analysis data generated for the user and the user's transaction behavior is a message input by the application. Since the actual application scenario is more complex, the message input by the application should not be limited to the one given as an example.

[0053] Step 204, sending the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through the direct memory access interface, and sends the application message on the memory block to the data recipient; wherein, the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0054] The direct memory access interface, namely DMA (Direct Memory Access), is a hardware device, through which the network card can directly read the application message and send it.

[0055] Specifically, when the application triggers the network card to perform DMA reading, the server sends the address of the memory block to the network card, so that the network card directly reads the application message through the direct memory access interface according to the address of the memory block, and sends it from the server to the data recipient.

[0056] When creating a shared memory pool, register the memory of the shared memory pool to the network card, so that the network card has the read permission of all the memory in the entire shared memory pool. Since all the memory of the shared memory pool has been registered to the network card, the memory block of the specified size is also registered to the network card along with all the memory. The network card has the permission to read the memory block of the specified size, and there is no need to register the memory block to the network card separately.

[0057] When the network card has the read permission of the memory block, when sending data, the network card no longer needs the CPU driver. It can send the data to the data recipient by calling the direct memory access interface of the operating system to read the memory block and then sending the memory block to the network card connected to the memory bus on the server.

[0058] In summary, the present application fundamentally reduces the number of calls to the operating system by applying for a sufficiently large memory block, and by registering the memory to the network card, the network card itself can send data without the need for the CPU to drive the network card when sending data. By improving both the application of memory and the sending of data, the present application can improve the execution efficiency of the process to a certain extent.

[0059] In the above-mentioned shared memory management method, the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool. The application applies for memory by calling the first interface of the operating system, and obtains a memory block of a specified size from the constructed shared memory pool. When the memory block is specified, the memory required for at least one business processing can be set, that is, the memory block of the specified size is a very large memory block. The application can construct an application message on the memory block; and enable the network card to directly read the memory block through the direct memory access interface. This process does not require the memory to be sent to the network card through the central processing unit driver. The network card then sends the application message to the data recipient. By applying for a large memory, there is no need to call the operating system interface multiple times, and by setting the network card to read the memory, there is no need to copy the memory back and forth for each process. Therefore, this application can improve the process execution efficiency to a certain extent.

[0060] In one embodiment, the application message on the memory block is sent to a data recipient, and the method further includes:

[0061] The offset address of the memory block in the shared memory pool is forwarded to the message landing subprocess for landing, so that the memory block is backed up locally.

[0062] The offset address of the memory block in the shared memory pool is obtained according to the virtual address of the memory block mapped to the main process for sending messages and the memory address of the memory block. The main process for sending messages is the process by which the network card sends application messages.

[0063] A process is a program running on the CPU. The message landing subprocess is a program on the CPU. The message landing subprocess is a process that performs local backup of application messages in the main message sending process. The landing of the message landing subprocess means that the relevant operations of the message landing subprogram have been executed, and the application messages in the memory block are equivalent to a local backup. After the message landing subprocess is landed, the memory block can be accessed and read locally and the corresponding data processing can be performed according to business needs.

[0064] Specifically, the application calls the sending interface of the operating system to send the offset address of the memory block in the shared memory pool to the message landing sub-process, which can locally access the memory block for reading and processing.

[0065] In this embodiment, the application calls the sending interface of the operating system to forward the offset address of the memory block in the shared memory pool to the message landing subprocess for landing, so that the memory block is backed up locally. The message landing subprocess can also access the memory block and read and process the data.

[0066] In one embodiment, the offset address of the memory block in the shared memory pool is forwarded to the message landing sub-process for landing, including: obtaining the virtual address of the memory block mapped to the message landing sub-process; obtaining the offset address of the memory block in the shared memory pool sent by the application calling the sending interface of the operating system; according to the virtual address and the offset address, the message landing sub-process obtains the memory address of the memory block; according to the memory address, the message landing sub-process lands.

[0067] The offset address is an address that indicates the offset relationship between the virtual address and the memory address. The virtual address is the address obtained by mapping the memory block to each process space. The memory block itself has a real physical address, that is, a memory address, which does not change for each process. In different processes, the virtual address of the memory block of the specified size mapped to each process space is different, while the memory address of the memory block in each process is the same.

[0068] The application calls the sending interface of the operating system to send the offset address of the memory block of the specified size in the shared memory pool to the message landing sub-process for landing. Specifically, the process of the network card sending the application message to the data recipient is regarded as a complete first process, and the message landing sub-process is regarded as the second process. The memory block can be mapped to the first process and the second process. When the memory block is mapped to the first process, its virtual address is the first virtual address. When the memory block is mapped to the second process, its virtual address is the second virtual address (referring to the virtual address of the memory block mapped to the message landing sub-process).

[0069] In the first process, the first offset address can be known according to the memory address and virtual address of the memory block. The first process sends the first offset address to the second process, and the second process can determine the memory address of the memory block according to the first offset address and the second virtual address. It should be noted here that the first process is a process that is successfully connected to the memory management structure, and the second process is a process that is not successfully connected to the memory management structure. Therefore, the first process can see the memory address of the memory block, while the second process cannot see the memory address of the memory block. The second process can only see the second virtual address of the memory block, but not the memory address of the memory block. Therefore, in order to know the memory address of the memory block, the first offset address forwarded by the first process is needed to determine the memory address of the memory block.

[0070] Furthermore, the first process is not limited to the process in which the network card sends an application message to a data receiver, but may be other processes; similarly, the second process is not limited to the message landing subprocess, but may be other processes.

[0071] In this embodiment, it is only necessary to obtain the virtual address of the memory block mapped to the message landing subprocess and the offset address of the memory block in the shared memory pool sent by the application calling the sending interface of the operating system, so that the message landing subprocess can know the memory address of the memory block, and then access the memory block according to the memory address of the memory block, without copying the memory block. Compared with the memory copy requiring at least several megabytes of memory, this forwarding offset address only requires about a few bytes of memory, which further improves the execution efficiency of the process to a certain extent.

[0072] In one embodiment, the shared memory management method further includes: defining a structure of a shared memory pool; creating a shared memory pool through a memory sharing function; defining a pointer pointing to the shared memory structure to obtain a definition pointer; mapping the created shared memory pool to the definition pointer through a file mapping function to obtain a constructed shared memory pool.

[0073] Among them, the structure combines different types of data into an organic whole, and the memory sharing function can be the CreateFileMapping function, through which a shared memory pool is created. After the structure is defined, the pointer pShareMem pointing to the shared memory structure is used to obtain the definition pointer, which can be used to allocate space, release space and initialize. Finally, the created shared memory pool is mapped to the definition pointer through the file mapping function MapViewOfFile, so that the constructed shared memory pool can be obtained.

[0074] In this embodiment, by defining the structure of a shared memory pool, creating a shared memory pool through a memory sharing function, defining a pointer to the shared memory structure, obtaining a definition pointer, and mapping the created shared memory pool to the definition pointer through a file mapping function, a constructed shared memory pool is obtained.

[0075] In one embodiment, the shared memory management method further includes: the network card receives an external message and writes the external message into the memory block; when the network card completes writing to the memory block, the memory block is handed over to the application for data reading and processing; wherein the shared memory pool has been registered with the network card, so that the network card has write permission for the shared memory pool.

[0076] The shared memory pool includes a sending shared pool and a receiving shared pool. The shared memory pool is a large memory, and several small memories can be divided from the large memory. In order to manage the use of the shared memory pool, a memory management structure for managing the shared memory pool is also created. The memory management structure is a program used to manage and register the memory status of the shared memory pool. For example, when multiple threads are running, when each thread requests memory from the shared memory pool, the memory management structure will show the current usage status of the shared memory pool to each thread, and the memory management structure will allocate the memory of each thread, and change and register the memory usage of the shared memory pool in time after the allocation is completed. Since the memory management structure does not involve the disassembly and merging logic of complex memory blocks, it can make the release application of multiple threads more efficient.

[0077] External messages are data input during business processing. The messages received by the network card include not only application messages of the application, but also external messages. After receiving the external message, the network card writes the external message into the memory block, which is the memory block of the specified size mentioned above. Every time the network card receives a new external message, it notifies the application so that the application knows that the external message has been written in time. When the memory block has been completely written and the network card has completed writing to the memory block, it submits the memory block to the application. The application can read and process the data read from the memory block according to the business processing requirements.

[0078] In this embodiment, the network card is given write permission for the shared memory pool, so that when the network card receives an external message, it can write the external message into the memory block. When the writing is completed, the memory block is handed over to the application, so that the application can read and process the data without calling the operating system interface multiple times. Moreover, by setting the network card to write to the memory, there is no need to copy the memory back and forth for each process.

[0079] In one embodiment, the shared memory management method further includes: reading the memory margin of the shared memory pool into the register corresponding to the thread in real time, and checking whether the memory margin of the shared memory pool meets the memory required for the thread to run; when the memory margin meets the memory required for the thread to run, allocating the required memory to the thread from the shared memory pool, and obtaining a comparison and exchange instruction, and comparing the memory margin with the memory variable in the register corresponding to the thread according to the comparison and exchange instruction; when the memory margin and the memory variable in the register corresponding to the thread are equal, subtracting the required memory from the memory variable to obtain a new memory variable, and storing the new memory variable in the register corresponding to the thread.

[0080] The CPU instruction here refers to the compare and exchange instruction, which is an instruction about atomic operations provided by the CPU. A process corresponds to multiple threads. The process is a program running on the CPU. The register is located in the CPU. The register stores the memory margin of the shared memory pool. The memory margin is the remaining memory of the shared memory pool released by the memory management structure. Assuming that the shared memory pool is 1G at initialization, the process of releasing memory from the shared memory pool is the process of 1G continuously decreasing. When the shared memory pool releases memory, there will be users who need to obtain memory accordingly, and the user can be each thread. When the thread local queue of each thread cannot meet its own needs, each thread will apply for memory from the shared memory pool, so that the memory margin of the shared memory pool will continue to decrease.

[0081] The memory variables stored in the registers of each CPU can be modified by each CPU. The modification process is as follows:

[0082] Check whether the memory margin of the shared memory pool meets the memory required for the thread to run. When the memory margin meets the memory required for the thread to run, allocate the required memory to the thread from the shared memory pool, obtain the comparison and exchange instructions, and compare the memory variables in the registers corresponding to the thread according to the comparison and exchange instructions. When the memory margin does not meet the memory required for the thread to run, that is, it is less than the memory required for the thread to run, the system will stop at the current step and prompt an error. When the memory margin is equal to the memory variable in the register corresponding to the thread, subtract the required memory from the memory variable to obtain a new memory variable, and store the new memory variable in the register corresponding to the thread. For example, when thread A needs 10M memory, it first applies for 10M memory from the shared memory pool through the memory management structure. The memory management structure compares the memory margin of the shared memory pool with the applied 10M. If the memory margin is greater than 10M, it means that the memory margin can meet the memory required for the current thread to run. At this time, the memory management structure allocates 10M memory from the shared memory pool to the thread, and accordingly, the memory of the shared memory pool is reduced by 10M. At the same time, the compare and exchange instructions are obtained to compare the memory margin and the memory variable corresponding to the register. When the two are equal, the memory variable in the register corresponding to the thread is modified, and the memory variable is subtracted from the memory variable to obtain a new memory variable, and then the new memory variable is stored in the register corresponding to the thread. For example: the memory margin of the shared memory pool is assumed to be 100M. Now, because thread A has applied for 10M memory, only 90M memory is left. Before getting 10M memory, the memory variable read in the register corresponding to thread A is 100M. After getting 10M memory, since thread A was 100M before the division, the memory variable in the register is 100M, and the two values ​​are the same, according to the compare and exchange instructions, the memory variable stored in the register corresponding to thread A will be modified to 90M.

[0083] In this embodiment, when a thread applies for memory from the shared memory pool, it first checks whether the memory margin of the shared memory pool meets the memory required for its operation. When the memory required by the thread is met, the memory required by the thread is allocated from the shared memory pool. The memory of the shared memory pool is released, and the memory of the thread is increased. Then, according to the compare and exchange instruction, the memory margin and the memory variable in the register corresponding to the thread are compared. When they are equal, the memory variable is modified to obtain a new memory variable, and the new memory variable is stored in the register corresponding to the thread, so that the memory variable stored in the register is updated in time.

[0084] In one embodiment, a process includes a first thread and a second thread, wherein after the first thread completes reading the memory margin of a shared memory pool into a register corresponding to the thread in real time, the second thread executes the step of reading the memory margin of the shared memory pool into a register corresponding to the thread in real time.

[0085] Wherein, a process includes multiple threads, and the first thread and the second thread are both threads, but are different threads.

[0086] Specifically, the steps executed by each thread in sequence are the same. Using a lock-free algorithm, each thread will execute the first step: reading the memory balance of the shared memory pool into the register corresponding to the thread in real time. There is a time gap in this step. Due to the time gap in the first step, there is a corresponding time gap in the subsequent steps, which can improve the efficiency of multi-threaded memory application.

[0087] In this embodiment, after the first thread completes the step of reading the memory remaining amount of the shared memory pool into the register corresponding to the thread in real time, the second thread executes the step of reading the memory remaining amount of the shared memory pool into the register corresponding to the thread in real time, thereby making each thread as parallel as possible on the basis of avoiding thread conflicts, thereby improving the efficiency of multi-threaded memory application.

[0088] It should be understood that, although the steps in each flow chart involved in the above-described embodiment are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a portion of the steps in each flow chart involved in the above-described embodiment may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.

[0089] In one embodiment, Figure 3 As shown, a shared memory management device is provided, including: a memory application module 301 and an application message sending module 302, wherein:

[0090] The memory application module 301 is used to apply for memory by calling the first interface of the operating system through the application, and obtain a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing;

[0091] The application message sending module 302 is used to send the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through the direct memory access interface, and sends the application message on the memory block to the data recipient; wherein the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool.

[0092] In one embodiment, the shared memory management device further includes: a local backup module, which is used to forward the offset address of the memory block in the shared memory pool to the message landing sub-process for landing, so that the memory block is backed up locally.

[0093] In one embodiment, the local backup module includes: a virtual address acquisition module, an offset address acquisition module, a memory address acquisition module and a child process landing module, wherein:

[0094] A virtual address acquisition module, used to acquire the virtual address of the memory block mapped to the message landing subprocess;

[0095] An offset address acquisition module, used for acquiring an offset address of the memory block in the shared memory pool sent by the application calling the sending interface of the operating system;

[0096] A memory address acquisition module, used for obtaining a module, used for enabling the message landing subprocess to obtain the memory address of the memory block according to the virtual address and the offset address;

[0097] The sub-process landing module is used to land the message in the sub-process according to the memory address.

[0098] In one embodiment, the shared memory management device further includes: a structure definition module, a shared memory pool creation module, a definition pointer acquisition module, and a shared memory pool acquisition module, wherein:

[0099] The structure definition module is used to define the structure of the shared memory pool;

[0100] A shared memory pool creation module is used to create a shared memory pool through a memory sharing function;

[0101] Define a pointer acquisition module, which is used to define a pointer pointing to a shared memory structure and obtain a defined pointer;

[0102] The shared memory pool acquisition module is used to map the created shared memory pool to the definition pointer through a file mapping function to obtain the constructed shared memory pool.

[0103] In one embodiment, the shared memory management device further includes: an external message writing module and a memory block submission module, wherein:

[0104] An external message writing module, used for the network card to receive an external message and write the external message into the memory block;

[0105] A memory block submission module, used for submitting the memory block to the application for data reading and processing when the network card completes writing to the memory block;

[0106] The shared memory pool has been registered with the network card, so that the network card has the write permission of the shared memory pool.

[0107] In one embodiment, the shared memory management device further includes: a memory margin reading module, a memory comparison module, and a memory variable storage module, wherein:

[0108] The memory margin reading module is used to read the memory margin of the shared memory pool into the register corresponding to the thread in real time, and to verify whether the memory margin of the shared memory pool meets the memory required for the thread to run;

[0109] A memory comparison module, configured to allocate the required memory to the thread from the shared memory pool when the memory margin satisfies the memory required for the thread to run, obtain a comparison and exchange instruction, and compare the memory margin with a memory variable in a register corresponding to the thread according to the comparison and exchange instruction;

[0110] A memory variable storage module is used to, when the memory margin is equal to the memory variable in the register corresponding to the thread, subtract the required memory from the memory variable to obtain a new memory variable, and store the new memory variable in the register corresponding to the thread.

[0111] For the specific definition of the shared memory management device, please refer to the definition of the shared memory management method above, which will not be repeated here. Each module in the above-mentioned shared memory management device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0112] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store memory management data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a shared memory management method is implemented.

[0113] Those skilled in the art will understand that Figure 4The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0114] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.

[0115] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0116] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0117] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0118] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A shared memory management method, characterized in that: The method comprises: Calling the first interface of the operating system through the application to apply for memory, obtaining a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing; Sending the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through a direct memory access interface, and sends the application message on the memory block to a data receiver; The shared memory pool has been registered with the network card, so that the network card has read permission for the shared memory pool. The application includes a first process and a second process. The first process is a process that is successfully connected to a memory management structure, and the second process is a process that is not successfully connected to a memory management structure. The first process sends a first offset address to the second process. The address of the memory block is determined by the second process based on the first offset address and a second virtual address. The first offset address is obtained based on the first virtual address and the physical address of the memory block. The first virtual address is a virtual address of the memory block mapped to the first process, and the second virtual address is a virtual address of the memory block mapped to the second process.

2. The method according to claim 1, characterized in that: Sending the application message on the memory block to a data receiver, the method further comprising: The offset address of the memory block in the shared memory pool is forwarded to the message landing subprocess for landing, so that the memory block is backed up locally.

3. The method according to claim 2, characterized in that Forwarding the offset address of the memory block in the shared memory pool to the message landing subprocess for landing, including: Obtain the virtual address of the memory block mapped to the message landing subprocess; Obtaining the offset address of the memory block in the shared memory pool sent by the application calling the sending interface of the operating system; According to the virtual address and the offset address, the message landing subprocess obtains the memory address of the memory block; According to the memory address, the message landing subprocess lands.

4. The method according to claim 1, characterized in that: The method further comprises: Define the structure of the shared memory pool; Create a shared memory pool through the memory sharing function; Define a pointer to a shared memory structure and get the definition pointer; The created shared memory pool is mapped to the definition pointer through a file mapping function to obtain a constructed shared memory pool.

5. The method according to claim 1, characterized in that The method further comprises: The network card receives an external message and writes the external message into the memory block; When the network card completes writing to the memory block, the memory block is handed over to the application for data reading and processing; The shared memory pool has been registered with the network card, so that the network card has the write permission of the shared memory pool.

6. The method according to claim 1, characterized in that The method further comprises: The memory margin of the shared memory pool is read into the register corresponding to the thread in real time, and the memory margin of the shared memory pool is checked to see whether it meets the memory requirements of the thread operation; When the memory margin satisfies the memory required for the thread to run, the required memory is allocated to the thread from the shared memory pool, and a compare and swap instruction is obtained, and the memory margin is compared with a memory variable in a register corresponding to the thread according to the compare and swap instruction; When the memory margin is equal to the memory variable in the register corresponding to the thread, the required memory is subtracted from the memory variable to obtain a new memory variable, and the new memory variable is stored in the register corresponding to the thread.

7. The method according to claim 6, characterized in that A process includes a first thread and a second thread, wherein after the first thread completes the step of reading the memory margin of a shared memory pool into a register corresponding to the thread in real time, the second thread executes the step of reading the memory margin of the shared memory pool into the register corresponding to the thread in real time.

8. A shared memory management device, characterized in that: The device comprises: A memory application module, used to apply for memory by calling the first interface of the operating system through the application, and obtain a memory block of a specified size from the constructed shared memory pool, wherein the memory block is used to construct an application message, and the memory block is not less than the memory required for one business processing; An application message sending module is used to send the address of the memory block to the network card, so that the network card directly reads the memory block according to the address through the direct memory access interface, and sends the application message on the memory block to a data recipient; wherein the shared memory pool has been registered with the network card, so that the network card has the read permission of the shared memory pool, wherein the application includes a first process and a second process, the first process is a process that is successfully connected to the memory management structure, and the second process is a process that is not successfully connected to the memory management structure, the first process sends a first offset address to the second process, the address of the memory block is determined by the second process according to the first offset address and the second virtual address, the first offset address is obtained according to the first virtual address and the physical address of the memory block, the first virtual address is the virtual address of the memory block mapped to the first process, and the second virtual address is the virtual address of the memory block mapped to the second process.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.