WO2021244155A1 - Inter-process communication method and inter-process communication apparatus - Google Patents

Inter-process communication method and inter-process communication apparatus Download PDF

Info

Publication number
WO2021244155A1
WO2021244155A1 PCT/CN2021/087695 CN2021087695W WO2021244155A1 WO 2021244155 A1 WO2021244155 A1 WO 2021244155A1 CN 2021087695 W CN2021087695 W CN 2021087695W WO 2021244155 A1 WO2021244155 A1 WO 2021244155A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory block
area
information
memory
identification information
Prior art date
Application number
PCT/CN2021/087695
Other languages
French (fr)
Chinese (zh)
Inventor
刘雄成
颉瑞昌
康文军
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021244155A1 publication Critical patent/WO2021244155A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Definitions

  • the embodiments of the present application relate to the computer field, and in particular, to an inter-process communication method and an inter-process communication device.
  • Interprocess communication is a communication method for sharing messages between one process and another process, and is mainly used for message transfer between different processes in a computer system.
  • a process is the smallest unit of computer resource allocation.
  • Each process has its own virtual address space and is isolated from the virtual address space of other processes. That is to say, a process can only access its own virtual address space, but cannot access it.
  • the virtual address space of other processes In order to enable different processes to access each other and coordinate their work, the operating system provides a variety of IPC mechanisms.
  • the IPC mechanism mainly includes pipes, message queues, sockets, and shared memory.
  • the shared memory has the characteristics of high communication efficiency, high reliability, and configurable capacity
  • the shared memory is a common and effective method among many inter-process communication mechanisms.
  • the inter-process communication mechanism based on shared memory is adopted, if the process frequently applies for shared memory to the kernel, a large number of memory fragments will be generated and the utilization of shared memory will be reduced.
  • a shared memory mechanism and a memory pool (memory pool) mechanism are often combined to reduce the generation of memory fragments and improve the utilization of shared memory.
  • the processor needs to run a hypervisor in addition to running two processes.
  • the hypervisor is used to allocate shared memory as a memory pool for the aforementioned two processes.
  • the management program writes the business data into a memory block in the memory pool.
  • the management program obtains the service data in the memory block and sends it to the process B.
  • the embodiments of the present application provide an inter-process communication method and an inter-process communication device, which are used to improve the communication efficiency between processes.
  • an embodiment of the present application provides an inter-process communication method.
  • the inter-process communication method is implemented by running a first process and a second process separately by an inter-process communication device.
  • the first process may select a memory block from the memory pool to write the service data. Take the first memory block in the first memory pool as an example.
  • the first process writes the memory block management information and the first service data in the first memory block in the first memory pool.
  • the memory block management information is information for maintaining the first memory block
  • the first service data is service data that the first process is ready to transmit to the second process.
  • the first process also sends identification information indicating the address of the first memory block to the second process, so that the second process obtains the information in the first memory block according to the identification information and the memory block management information.
  • the first business data is included in the first business data.
  • the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the foregoing identification information may further include first identification information and second identification information.
  • the first identification information is used to indicate the first address of the first memory pool
  • the second identification information is used to indicate the address of the first memory block in the first memory pool.
  • the aforementioned first identification information and second identification information may form a two-tuple, and the two-tuple may be sent to the second process through a pipe, a message queue, or the like.
  • the second process can determine the first memory pool based on the first identification information. address.
  • the first address of the first memory pool is a virtual address mapped to the address space of the second process by the first memory pool.
  • the second identification information is used to indicate the address of the first memory block in the first memory pool, it can also be understood that the second identification information is used to indicate a relative address. Therefore, the second process can find the first memory block from the first memory pool based on the foregoing first identification information and second identification information.
  • the foregoing first memory block includes two areas, where the first area is used for recording the foregoing memory block management information, and the second area is used for recording services.
  • Data for example, the aforementioned first business data
  • the aforementioned first area is also referred to as the head of the first memory block
  • the aforementioned second area is also referred to as the main body of the first memory block.
  • the area in the first memory block for recording memory block management information and the area in the first memory block for recording business data are not specifically limited here.
  • the first area only occupies a few bytes of the first memory block. It can also be understood that the memory block management information only occupies a few bytes of the first memory block.
  • the memory block management information includes first indication information, and the first indication information is used to indicate the second area (ie, the storage area) of the first memory block.
  • the area of the first service data) whether to allow the first process or the second process to access.
  • the first value is used to indicate that the first process is forbidden to access the second area of the first memory block and the second process is allowed to access the second area.
  • the first process after the first process writes the memory block management information and the first service data in the first memory block, before the first process sends the identification information to the second process, the first process returns Set the first indication information to the first value.
  • the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
  • the first process When the aforementioned first process writes the memory block management information and the first service data in the first memory block, the first process adjusts the state information from the idle state to the use state, and the first memory block Move from the idle linked list to the used linked list.
  • the first process when the first process determines that the first memory block needs to be used for communication, when the first process writes memory block management information to the first memory block, the first process can adjust the state information In order to use the state, the first memory block is moved from the free linked list to the used linked list to prevent other processes from using the aforementioned first memory block. In such an implementation manner, other processes can determine whether the first memory block can be used according to the aforementioned status information, and there is no need for a third-party program to feed back the usage status of the first memory block to other processes. Therefore, the efficiency of inter-process communication can be improved.
  • the first process uses the first memory block
  • the state information of is adjusted from the use state to the idle state, and the first memory block is moved from the use linked list to the idle linked list.
  • the first process when the first process no longer uses the first memory block, the first process can release the first memory block by adjusting the state information and adjusting the linked list where the first memory block is located.
  • the method before the first process writes the memory block management information and the first service data in the first memory block, the method further includes: The process applies to the kernel for the first shared memory block.
  • the first process writes memory pool management information at the head of the first shared memory block.
  • the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple initial memory blocks constitute the first memory pool.
  • the size of the first memory block is smaller than or equal to the size of the initial memory block.
  • the first process directly selects an initial memory block from the aforementioned first memory pool as the first memory block, that is, the first process directly sends an initial memory block to the aforementioned first memory pool.
  • the first business data is written into an initial memory block.
  • the size of each initial memory block in the first memory pool is not completely the same, and the initial memory block includes the first initial memory block and the second initial memory block.
  • a memory block, the size of the first initial memory block is smaller than the size of the second initial memory block.
  • the first memory block is obtained by splitting one of the second initial memory blocks; or, the first memory block is obtained by combining at least two of the first initial memory blocks.
  • the aforementioned first memory block can be obtained by combining multiple initial memory blocks, or can be obtained by splitting one initial memory block. In this way, it is beneficial for the foregoing first process to flexibly select memory blocks according to the first service data to be written, and to improve the utilization of the memory blocks in the foregoing first memory pool.
  • the memory block management information further includes second indication information, and the second indication information is used to indicate the connection relationship between the first memory block and other memory blocks .
  • the second indication information may include the address of a memory block adjacent to the first memory block.
  • the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
  • an embodiment of the present application provides an inter-process communication method.
  • the inter-process communication method is implemented by an inter-process communication device running a first process and a second process respectively.
  • the second process receives the identification information sent by the first process.
  • the identification information is used to indicate the address of the first memory block, and the first memory block is located in the first memory pool.
  • the first memory block includes first service data and memory block management information written by the first process, and the memory block management information is information for maintaining the first memory block.
  • the second process reads the first service data from the first memory block according to the identification information and the memory block management information.
  • the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the foregoing identification information may further include first identification information and second identification information.
  • the first identification information is used to indicate the first address of the first memory pool
  • the second identification information is used to indicate the address of the first memory block in the first memory pool.
  • the aforementioned first identification information and second identification information may form a two-tuple, and the two-tuple may be sent to the second process through a pipe, a message queue, or the like.
  • the second process can determine the first memory pool based on the first identification information. address.
  • the first address of the first memory pool is a virtual address mapped to the address space of the second process by the first memory pool.
  • the second identification information is used to indicate the address of the first memory block in the first memory pool, it can also be understood that the second identification information is used to indicate a relative address. Therefore, the second process can find the first memory block from the first memory pool based on the foregoing first identification information and second identification information.
  • the foregoing first memory block includes two areas, where the first area is used for recording the foregoing memory block management information, and the second area is used for recording services.
  • Data for example, the aforementioned first business data
  • the aforementioned first area is also referred to as the head of the first memory block
  • the aforementioned second area is also referred to as the main body of the first memory block.
  • the area in the first memory block for recording memory block management information and the area in the first memory block for recording business data are not specifically limited here.
  • the first area only occupies a few bytes of the first memory block. It can also be understood that the memory block management information only occupies a few bytes of the first memory block.
  • the memory block management information includes first indication information, and the first indication information is used to indicate the second area (ie, the storage area) of the first memory block.
  • the area of the first service data) whether to allow the first process or the second process to access.
  • the first value is used to indicate that the first process is forbidden to access the second area of the first memory block and the second process is allowed to access the second area.
  • the second process reads the first service data from the second area of the first memory block according to the identification information and the memory block management information, including: the second process reads the first service data according to the first identification information and the second identification information Find the first memory block in the first memory pool.
  • the second process When the second process detects that the first indication information is the first value, the second process reads the first service data from the first memory block, and the first value is used to indicate that the first process is prohibited Access to the second area of the first memory block and the second process allows access to the second area.
  • the second process uses the identification information and the memory block management information to read the first service data from the first memory block. After the second process finds the first memory block from the foregoing first memory pool, the second process also needs to detect the value of the foregoing first indication information. When the second process detects that the first indication information is the first value, the second process can read the first service data in the first memory block.
  • the second process reads the first service from the second area of the first memory block according to the identification information and the memory block management information After the data is collected, the method further includes: the second process writes second service data in the second area of the first memory block, and adjusts the first indication information to a second value, the second value being used to indicate The first process allows access to the second area and the second process prohibits access to the second area.
  • the second process does not need to reselect a memory block from the aforementioned first memory pool, but can directly use the first memory block to send or reply service data to the first process.
  • the second process directly writes the second service data in the first memory block, and adjusts the first indication information to the second value. Therefore, when the first process detects that the first indication information is adjusted from the first value to the second value, the first process can read the second service data from the aforementioned first memory block. Therefore, the processes of selecting the memory block and mapping the memory block to the address space by the second process can be saved, thereby saving the efficiency of communication between the first process and the second process.
  • the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
  • the method after the second process reads the first service data from the first memory block according to the identification information and the memory block management information, the method It also includes: the second process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the use linked list to the free linked list.
  • the second process when the second process no longer uses the first memory block, the second process can release the first memory block by adjusting the state information and the linked list where the first memory block is located.
  • the memory block management information further includes second indication information, and the second indication information is used to indicate the connection relationship between the first memory block and other memory blocks .
  • the second indication information may include the address of a memory block adjacent to the first memory block.
  • the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
  • an embodiment of the present application provides an inter-process communication device, the inter-process communication device is located in a processor, the inter-process communication device runs a first process by calling program codes in a memory, and the inter-process communication device includes the following Function module: write module, used to write memory block management information and first business data in the first memory block, the first memory block is located in the first memory pool, and the memory block management information is for maintaining the first memory Block information.
  • the sending module is configured to send identification information to a second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, and the identification information is used to indicate The address of the first memory block.
  • the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
  • the first memory block includes a first area and a second area; the first area is used to record the memory block management information, and the first area The first process or the second process is allowed to access at any time; the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  • the memory block management information includes first indication information.
  • the inter-process communication device also includes:
  • the acquiring module is configured to acquire second service data from the second area of the first memory block when it is detected that the first indication information is a second value, and the second value is used to indicate that the first process is allowed to access the second Area and the second process is forbidden to access the second area.
  • the inter-process communication device further includes: an instruction information adjustment module, configured to set the first instruction information to a first value, and the first value It is used to instruct the first process to prohibit access to the second area of the first memory block and the second process to allow access to the second area.
  • an instruction information adjustment module configured to set the first instruction information to a first value, and the first value It is used to instruct the first process to prohibit access to the second area of the first memory block and the second process to allow access to the second area.
  • the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
  • the state information adjustment module is configured to adjust the state information from the idle state to the used state, and move the first memory block from the idle linked list to the used linked list.
  • the state information adjustment module is further configured to adjust the state information of the first memory block from the use state to the idle state, and The first memory block is moved from the used linked list to the free linked list.
  • an embodiment of the present application provides an inter-process communication device.
  • the inter-process communication device is located in a processor.
  • the inter-process communication device runs a second process by calling program codes in a memory.
  • the inter-process communication device includes the following functional module:
  • the receiving module is configured to receive identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains the first process
  • the written first service data and memory block management information where the memory block management information is information for maintaining the first memory block.
  • the reading module is configured to read the first service data from the first memory block according to the identification information and the memory block management information.
  • the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
  • the first memory block includes a first area and a second area; the first area is used to record the memory block management information, and the first area The first process or the second process is allowed to access at any time; the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  • the memory block management information includes first indication information.
  • the inter-process communication device further includes: a writing module for writing second service data in the second area of the first memory block, and adjusting the first indication information to a second value, the second value being used Instructing the first process to allow access to the second area and the second process to prohibit access to the second area.
  • the reading module includes: a searching unit configured to search in the first memory pool according to the first identification information and the second identification information The first memory block.
  • the reading unit is configured to read the first service data from the second area of the first memory block when it is detected that the first indication information is the first value, and the first value is used to indicate that the first process is prohibited Access to the second area of the first memory block and the second process allows access to the second area.
  • the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
  • the inter-process communication device further includes: a state information adjustment module, configured to adjust the state information of the first memory block from the use state to the In an idle state, the first memory block is moved from the used linked list to the free linked list.
  • a state information adjustment module configured to adjust the state information of the first memory block from the use state to the In an idle state, the first memory block is moved from the used linked list to the free linked list.
  • an embodiment of the present application provides a device, which may be a normal computer or a large-scale server, or other devices with a processor.
  • the device includes an inter-process communication device that runs the first process and an inter-process communication device that runs the second process.
  • the inter-process communication device running the first process is used to implement the function described in any one of the foregoing third aspect; the inter-process communication device running the second process is used to implement any one of the foregoing fourth aspect
  • the inter-process communication device running the first process and the inter-process communication device running the second process are both located in the processor of the aforementioned device.
  • the processor may be a general-purpose central processing unit or a microprocessor; the processor may be a single-core processor or a multi-core processor.
  • the processor may refer to one or more devices, circuits, and/or processing cores for processing data (for example, computer program instructions).
  • the inter-process communication device running the first process and the inter-process communication device running the second process are connected to at least one memory and at least one storage medium, and the storage medium stores a program corresponding to the first process and a program corresponding to the second process. program of.
  • the inter-process communication device running the first process and the inter-process communication device running the second process may be configured to communicate with the storage medium to execute the program in the storage medium.
  • the processor further includes a memory management unit, and the MMU is located between the bus connecting the cache and the memory, and is a kind of computer hardware responsible for processing the memory access request of the CPU.
  • the MMU is used to implement the conversion between physical addresses and virtual addresses.
  • an embodiment of the present application provides a processing system, which includes the inter-process communication device as described in any one of the implementation manners in the foregoing third aspect, and any one of the implementation manners in the foregoing fourth aspect The inter-process communication device introduced.
  • an embodiment of the present application provides a processing chip, and the processing chip includes the processing system described in the sixth aspect.
  • an embodiment of the present application provides a computer-readable storage medium on which a computer program or instruction is stored.
  • the feature is that when the computer program or instruction is executed, the inter-process communication device executes the first aspect and the second aspect.
  • the method introduced in any one of the implementation manners in one aspect, or the method introduced in the second aspect and any one of the implementation manners in the second aspect is executed.
  • Figure 1 is a schematic diagram of inter-process communication based on the shared memory mechanism
  • FIG. 2 is a flowchart of an inter-process communication method in an embodiment of the application
  • FIG. 3 is another flowchart of the inter-process communication method in an embodiment of the application.
  • 4A is a schematic diagram of inter-process communication based on a shared memory mechanism in an embodiment of the application
  • 4B is a schematic diagram of the memory pool in an embodiment of the application.
  • Fig. 5 is a schematic diagram of an embodiment of an inter-process communication device in an embodiment of the application.
  • Fig. 6 is a schematic diagram of another embodiment of an inter-process communication device in an embodiment of the application.
  • FIG. 7 is a schematic structural diagram of a device applicable to the inter-process communication apparatus in an embodiment of the application.
  • the embodiments of the present application provide an inter-process communication method and an inter-process communication device, which are used to improve the communication efficiency between processes.
  • Shared memory mechanism means that the kernel allocates a piece of physical memory for two mutually isolated processes, and maps the physical memory to the address spaces of the aforementioned two processes, so that any one of the aforementioned processes can access the process’s own address space to Read the data stored in the aforementioned physical memory. Therefore, two processes can communicate through a block of memory, and this block of memory is called shared memory. Taking the communication between process A and process B in Figure 1 as an example, shared memory 002 is a part of physical memory 001, the address space of process A is 101, and the address space of process B is 101'.
  • the virtual address of the shared memory 002 in the address space 101 is 102.
  • the memory block 0031 where the data is recorded corresponds to the virtual address 1031 in the process A
  • the memory block 0032 where the address is recorded corresponds to the virtual address 1032 in the process A.
  • the shared memory 002 is mapped to the address space 101' in the process B
  • the virtual address of the shared memory 002 in the address space 101' is 102'.
  • the memory block 0031 where the data is recorded corresponds to the virtual address 1031' in the process B
  • the memory block 0032 where the address is recorded corresponds to the virtual address 1032' in the process B.
  • the virtual addresses of the memory in different address spaces are generally different.
  • the address 1031 of the data-recording memory block 0031 in the address space of the process A is generally different from the address 1031' of the data-recording memory block 0031 in the address space of the process B. Therefore, if process B only knows the virtual address 1031 of the memory block 0031 that records data in the address space of process A, then process B cannot use the virtual address 1031 to find the virtual address 1031' in the address space of process B The data.
  • the same shared memory is read by multiple processes at the same time or written by multiple processes at the same time, it will cause data read and write confusion. Therefore, if process B wants to receive data from process A, process B needs to know the virtual address of the memory block that records the data in the address space of process B, and also needs to know when it is allowed to read the memory block in the aforementioned memory block. data.
  • the current technology is to run another management program in the processor running the process A and the process B, and the management program is responsible for coordinating the communication between the aforementioned process A and the process B.
  • the management program writes the data that the aforementioned process A needs to send to the process B in a certain memory block in the shared memory (for example, the memory block 0031 that records data in Figure 1), and then maps the memory block to the process
  • the virtual address in the address space of A ie, the virtual address 1031
  • is written into another memory block for example, the memory block 0032 where the address is recorded in FIG. 1).
  • the hypervisor When process B needs to access the aforementioned data, the hypervisor will obtain the aforementioned virtual address 1031 from the memory block 0032 of the recording address and convert it into a virtual address in the address space of process B (ie virtual address 1031'), and the management The program will send the virtual address 1031' in the address space of the process B to the process B when the process B is allowed to read the aforementioned memory block (that is, the memory block 0031 where the data is recorded), so that the process B can read through the virtual address 1031' Get the aforementioned data.
  • the management program manages the aforementioned two processes and coordinates the data communication between the aforementioned two processes. If an error occurs in the aforementioned management program, it will affect the communication between process A and process B.
  • this embodiment of the present application proposes to write management information in the shared memory, so that the foregoing two processes can learn the state of the memory by viewing the management information and the timing of allowing the data in the memory to be read, and then modify the management The information informs the opposite process to read or write data.
  • the processor only needs to run the aforementioned process A and process B, and does not need to run a third-party program to coordinate the communication between the aforementioned two processes. Therefore, it is beneficial to improve the efficiency of communication between processes.
  • the following describes the inter-process communication method proposed in the embodiment of the present application with the communication process between the first process and the second process. As shown in FIG. 2, the first process and the second process will perform the following steps:
  • the first process writes memory block management information and first service data in the first memory block.
  • the first service data refers to service data that the first process is ready to transmit to the second process.
  • the memory block management information is information for maintaining the first memory block. It can be understood that the first process implements the management or maintenance of the first memory block by writing the memory block management information in the first memory block. For example, determine the state of the first memory block, define the access rights of the process to the first memory block, define the linked list where the first memory block is located, define the connection relationship between the first memory block and other memory blocks, and define other possible access rights to the first memory block.
  • a memory block realizes the information of management and maintenance functions and so on.
  • the aforementioned memory block management information includes: status information, used to indicate the state of the first memory block; first indication information, used to indicate the access authority of the first process or other processes to the first memory block; second The indication information is used to indicate the connection relationship between the first memory block and other memory blocks.
  • the memory block management information may also include other information used to manage and maintain the first memory block. Specifically, step 303 will be described in detail later, and will not be repeated here.
  • the memory block management information in the foregoing first memory block is modified by the first process, one or more of the foregoing multiple types of information will change, so that the state of the first memory block, the first One or more of the memory block's access rights to other processes and the connection relationship between the first memory block and other memory blocks is changed, so as to realize the management and maintenance of the first memory block, and also help other processes based on the aforementioned Memory block management information makes decisions.
  • the aforementioned first memory block is located in the first memory pool, and the first memory pool may be obtained by initializing the shared memory block allocated by the kernel by the first process, or may be obtained by initializing the shared memory allocated by the kernel by other processes. Obtained, the details are not limited here. In this embodiment and subsequent embodiments, the first memory pool is obtained by initializing the shared memory block of the first process for introduction.
  • the first process applies to the kernel for shared memory and initializes it as the first memory pool, there may be multiple initial memory blocks of different sizes in the first memory pool, and the foregoing multiple initial memory blocks may be used for the foregoing The first process selection.
  • the first process may directly write the memory block management information and the first service data in one of the foregoing multiple initial memory blocks.
  • the aforementioned first memory block is one of the aforementioned multiple initial memory blocks.
  • the foregoing first memory block may also be a memory block obtained after the foregoing one initial memory block is split, or may be a memory block obtained after the foregoing multiple initial memory blocks are merged.
  • the foregoing first memory block may be one of the foregoing multiple initial memory blocks; when the foregoing sum is less than the size of an initial memory block, the foregoing The first memory block may be a memory block obtained after the foregoing initial memory block is split; when the foregoing sum is greater than the size of an initial memory block, the foregoing first memory block may be a memory obtained after the foregoing multiple initial memory blocks are merged piece.
  • the aforementioned first memory pool contains several initial memory blocks of different sizes, there may be multiple initial memory blocks of the same size. In addition, there are certain rules among initial memory blocks of different sizes. Exemplarily, the size of one of the initial memory blocks is an integer multiple of the other initial memory block. For example, the first memory pool contains N initial memory blocks of 8M, Q initial memory blocks of 16M, and R initial memory blocks of 32M.
  • the aforementioned first memory block includes two areas, where the aforementioned first area is an area in the first memory block for recording memory block management information, and the aforementioned second area is an area in the first memory block for recording business data. area.
  • the first area is used for the first process to write the foregoing memory block management information, or for the second process or other processes to modify the foregoing memory block management information;
  • the second area is used for the first process to modify the foregoing memory block management information;
  • the process writes business data (for example, the aforementioned first business data).
  • the aforementioned first area is also referred to as the head of the first memory block
  • the aforementioned second area is also referred to as the main body of the first memory block.
  • the first area only occupies the first few bytes of the first memory block. Since the memory block management information is located in the first area of the aforementioned first memory block, the size of the first area is much smaller than the size of the first memory block. Therefore, the size of the memory block management information is generally small, even far smaller than the size of the first service data.
  • the first process when the first process writes the foregoing memory block management information and the first service data into the first memory block, the first process first writes the memory block management information in the foregoing first area, and then Write the first service data in the aforementioned second area.
  • the first area After the first area is written into the aforementioned memory block management information, the first area allows the first process or other processes to access the first area at any time.
  • the second area does not allow any process other than writing the memory block management information to access it at any time. That is, if the memory block management information in the first memory block is written by the first process, the second area does not allow processes other than the first process to access the second area at any time.
  • the aforementioned first process modifies the memory block management information in the previous first area
  • other processes may be allowed to access the second area.
  • the first process transfers the access authority information in the memory block management information (for example, the information used to indicate the access authority of the process to the first memory block introduced above; for another example, the first memory block will be introduced later.
  • the instruction information is modified, and the modified information can indicate that other processes are allowed to access the second area, so other processes will be able to access the second area. Therefore, before the second process reads the first service data in the first memory block, it needs to read the memory block management information to determine the status of the first memory block and when it can read the first memory block. data.
  • the first process sends identification information to the second process.
  • the identification information is used to indicate the address of the first memory block.
  • the second process can receive the identification information and determine the address of the first memory block according to the identification information. That is, the second process can find the first memory block from the aforementioned first memory pool according to the identification information.
  • the address of the aforementioned first memory block refers to an address that can be recognized by the second process. It can also be understood that the address of the first memory block enables the second process to directly or indirectly find the first memory block through the identification information.
  • the address of the first memory block is a virtual address mapped to the address space of the second process by the first memory block.
  • the address of the first memory block is the physical address of the first memory block, and the second process may determine that the first memory block is in the second process according to the mapping relationship between the physical address and the address space of the second process. The virtual address in the address space of the process.
  • the first process may send the aforementioned identification information to the second process in a manner such as a pipe or a message queue.
  • a manner such as a pipe or a message queue.
  • the identification information includes first identification information and second identification information.
  • the first identification information is associated with the aforementioned first memory pool. Since one process can apply for multiple memory pools from the kernel, there may be multiple memory pools associated with the first process, and the aforementioned first memory pool is one of the aforementioned multiple memory pools. Therefore, the first process needs to send the first identification information indicating the first memory pool to the second process, so that the second process can learn which memory pool the aforementioned first process uses to communicate with the second process.
  • the second identification information is associated with the aforementioned first memory block. Since a memory pool generally includes multiple memory blocks, the aforementioned first memory pool also includes multiple memory blocks. Therefore, the first process needs to send the second identification information indicating the first memory block to the second process, so that the second process can learn that the first process passes through the first memory block in the first memory pool and This second process communicates.
  • the aforementioned first identification information is used to indicate the first address of the first memory pool.
  • the first identification information may be a character (for example, key) agreed between the first process and the second process to indicate the first memory pool, or the ID of the first memory pool, or It is directly the first address of the first memory pool, or other information that can indicate the first address of the first memory pool.
  • the second process may determine the first address of the first memory pool according to the foregoing first identification information.
  • the second identification information is used to indicate the address of the first memory block in the first memory pool, which can also be understood as the relative address of the first memory block in the first memory pool.
  • the second identification information may be represented by an offset (lable) (abbreviation, offset) in the first memory pool.
  • the first process may encapsulate the aforementioned first identification information and the second identification information into a two-tuple, and send it in a way such as a pipe or a message queue. To the second process.
  • the first process may also adopt other forms to encapsulate the aforementioned first identification information and second identification information, which is not specifically limited here.
  • the second process obtains the first service data in the first memory block according to the identification information and the memory block management information.
  • the second process Since the memory block management information is directly written in the first area of the first memory block (that is, the head of the first memory block), after the second process finds the first memory block through the identification information, the The second process will first read the memory block management information in the first area, and determine the access authority of the second process to the second area of the first memory block according to the memory block management information to determine the second process Time to read the first service data in the second area.
  • the second process may read the first service data from the foregoing second area. Therefore, based on the foregoing identification information and the memory block management information, the second process can obtain the first service data written by the first process into the first memory block from the foregoing first memory block.
  • the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the foregoing inter-process communication method is further introduced. As shown in FIG. 3, the communication process between the first process and the second process is still taken as an example. The first process and the second process will execute The following steps:
  • the first process applies to the kernel for the first shared memory block.
  • the first process if the first process needs to communicate with other processes (for example, the second process described in this embodiment), and the first process does not have a usable memory pool, the first process will execute this Step 301.
  • the first process does not have a memory pool that can be used, and it can also be understood that the existing memory pool does not meet the requirements of the first process to send the first data, and the specifics are not limited here.
  • the first process may apply for a shared memory block from the kernel.
  • this shared memory block is referred to as the first shared memory block in this embodiment and subsequent embodiments.
  • the size of the first shared memory block may be indicated to the kernel by the first process when applying for shared memory from the kernel, or may be allocated by the kernel to the first process according to the operating conditions of the system, and the specifics are not limited here.
  • the kernel allocates the aforementioned first shared memory block to the first process
  • the first shared memory block will be mapped into the address space of the first process and the address space of the second process.
  • the first process writes memory pool management information at the head of the first shared memory block to obtain the first memory pool.
  • the first process needs to initialize the first shared memory block, that is, the first shared memory block is initialized to satisfy the The first memory pool for the communication requirements of the first process.
  • the first process may write memory pool management information in the header of the aforementioned first shared memory block, where the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple The initial memory block constitutes the aforementioned first memory pool.
  • FIG. 4A is taken as an example to introduce the structure of the foregoing first memory pool.
  • the header of the first memory pool is memory pool management information, and the size of the header of the first memory pool can be adjusted as needed.
  • the memory pool management information includes the size of the initial memory block in the first memory pool, the number of initial memory blocks, and the like.
  • the first memory pool includes a plurality of initial memory blocks (for example, memory block 1, memory block 2, memory block 3, memory block 4, memory block 5, etc.), wherein the head of each initial memory block reserves a number of Bytes are used to write memory block management information.
  • the first area of the initial memory block is used for writing memory block management information
  • the second area of the initial memory block is used for writing service data. Specifically, reference may be made to the relevant introductions about the first area of the first memory block and the second area of the first memory block in the foregoing step 201 and step 202, which will not be repeated here.
  • the physical memory 011 corresponds to the address space 111 of the first process
  • the physical memory 011 corresponds to the address space 111' of the second process.
  • the first shared memory block will be simultaneously mapped into the address space 111 of the first process and the address space 111' of the second process.
  • the first process initializes the aforementioned first shared memory block as the first memory pool 012
  • the virtual address of the first memory pool 012 in the address space 111 is 112
  • the virtual address of the first memory pool 012 in the address space 111' The address is 112'.
  • the header of the first memory pool 012 is memory pool management information.
  • the first memory pool 012 contains multiple memory blocks (for example, memory block 0131 and memory block 0132). Each memory block is reserved with the first area for filling in the management information of the memory block, that is, the head of each memory block.
  • the memory block 0131 is at the virtual address 113 in the address space 111 of the process A
  • the memory block 0131 is at the virtual address 113' in the address space 111' of the process B.
  • the first area of the memory block 0131 is used to fill in memory block management information
  • the second area of the memory block 0131 is used to fill in business data.
  • step 301 and step 302 are optional steps.
  • the first process will execute step 301 and step 302.
  • the first process can select a memory pool from the multiple memory pools as the first memory pool, and perform step 303 instead of performing the aforementioned steps 301 and 302.
  • the first process writes memory block management information and first service data in the first memory block in the first memory pool.
  • the first memory block may be directly a certain initial memory block in the aforementioned first memory pool, or may be obtained by combining the foregoing multiple initial memory blocks, or may be obtained by splitting a certain initial memory block.
  • the specific step 201 has been introduced in detail in the previous section, and will not be repeated here.
  • the memory block management information is information for maintaining the first memory block.
  • the first service data is data that the first process prepares to send to the second process. Since, when the first process initializes the first memory pool, it reserves a first area in each initial memory block for filling in the memory block management information, therefore, the first process writes the memory block management information The first area of the first memory block writes the first service data into the second area of the first memory block.
  • the memory block management information includes first indication information.
  • the first indication information is used to indicate the access authority of the first process or other processes to the second area of the first memory block. It can also be understood as whether the first memory block currently allows the first process or other processes to be in the first memory block.
  • the second area of a memory block performs read or write operations.
  • the first indication information can be implemented in the following multiple ways:
  • the first indication information includes two values. One value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area; the other value is used to indicate that the first process is allowed to access the second area of the first memory block , The second process prohibits access to the second area.
  • the first indication information includes a first value and a second value.
  • the first value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area;
  • the second value is used to indicate that the first process is allowed to access the first memory block of the first memory block. In the second area, the second process is prohibited from accessing the second area.
  • first value and second value do not limit the value of the first indication information, and only mean that the foregoing first indication information may have two different values.
  • first value when the aforementioned first indication information is represented by binary characters, the first value may be 0, and the second value may be 1.
  • the first value can also be set to 1 and the second value is 0; or, two different characters are used to represent the aforementioned first value and second value. The details are not limited here.
  • the first indication information includes at least N+1 values, which are used to implement communication between N processes through the foregoing first memory block.
  • N is an integer greater than 1, and each value corresponds to a process.
  • the process corresponding to the value can access the second area in the first memory block, while other processes are not allowed to access the first memory block of the first memory block.
  • Two areas When the value indicated by the foregoing first indication information does not correspond to the foregoing N processes, the first memory block prohibits any process from accessing the second area.
  • N 2 as an example.
  • N is equal to 2
  • the communication between the two processes can be realized.
  • the first indication information may include three values, which are 0, 1, and 2, respectively. Among them, 0 indicates that neither process A nor process B is allowed to access the second area; 1 indicates that process A is allowed to access the second area, and process B is not allowed to access the second area; 2 indicates that process A is not allowed to access the second area, and process B Allow access to the second area. For another example, when N is equal to 3, communication between three processes can be realized. At this time, the first indication information may include four values, which are 0, 1, 2 and 3 respectively.
  • 0 means that process A, process B and process C are not allowed to access the second area; 1 means that process A is allowed to access the second area, and process B and process C are not allowed to access the second area; 2 means that process B is allowed to access the second area. In the second area, process A and process C are not allowed to access the second area; 3 means that process C is allowed to access the second area, and process A and process B are not allowed to access the second area.
  • the process can trigger the process of releasing the memory block.
  • the process B can set the value of the aforementioned first indication information to 0, where 0 indicates that none of the process A, the process B, and the process C are allowed to access the second area.
  • the process B can further instruct the process of releasing the memory block. For example, as will be introduced later, the process B can adjust the state information of the memory block from the use state to the idle state, and move the memory block from the use linked list to the free linked list.
  • the memory block management information also includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state.
  • the usage status refers to that service data has been written in the second area of the first memory block, or a certain process is writing memory block management information to the first area of the first memory block.
  • the idle state means that no service data has been written into the second area of the first memory block, and no process writes memory block management information to the first area of the first memory block. If the aforementioned first memory pool is obtained by initializing the first shared memory block requested by the first process, the first process can determine that the state of the first memory block is the idle state, and the first process can directly send the message to the first shared memory block.
  • the initial memory block management information and the first business data into a memory block; if the first memory pool is not obtained by the initialization of the first process, but selected from many memory pools, the first process needs to be based on the status information
  • the state of the initial memory block is determined. When the initial memory block is in an idle state, the initial memory block may be used as the first memory block.
  • the first process When the first process writes the memory block management information and the first service data in the first memory block, the first process also adjusts the state information from the idle state to the use state, and the first memory The block is moved from the free linked list to the used linked list. Therefore, when other processes read the status information, they can know that the first memory block is in use.
  • the memory block management information also includes second indication information.
  • the second indication information is used to indicate the connection relationship between the first memory block and other memory blocks.
  • the second indication information may include the address of a memory block adjacent to the first memory block.
  • the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
  • the memory block management information may also include other information about the first memory block. The details are not limited here.
  • the first process sets the first indication information to a first value.
  • the first value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area. Because, after the first process writes the memory block management information and the first service data into the first memory block, the first process will adjust the aforementioned first indication information to the first value. Therefore, the second process can determine that the aforementioned first process has written the first service data into the first memory block.
  • the first process executes the foregoing step 303, when the first process writes memory block management information to the first memory block, the first process only defines the first indication information, but does not Assign a value to the first indication information. After the first process completely writes the first service data into the first memory block, the first process sets the aforementioned first indication information to the first value.
  • the first process sends the first identification information and the second identification information to the second process.
  • the first identification information is associated with the first memory pool, and the first identification information is used to indicate the first address of the first memory pool.
  • the second identification information is associated with the first memory block, and the second identification information is used to indicate the address of the first memory block in the first memory pool.
  • the first process may send the aforementioned first identification information and second identification information to the second process through a pipe, a message queue, or the like.
  • step 305 after the first process executes step 305, the first process will execute step 311, and the second process will execute step 306.
  • the second process searches for the first memory block in the first memory pool according to the first identification information and the second identification information.
  • the second process detects the first indication information in the memory block management information.
  • the second process finds the first memory block from the previous first memory pool, the second process cannot directly read the data in the second area of the first memory block.
  • the second process also needs to determine whether it is currently allowed to access the first memory block. Then, the second process will read the first memory block management information from the first area of the first memory block, and detect the first indication information in the memory block management information to determine the current value of the first memory block Whether the second area is allowed to visit.
  • the second process executes step 308.
  • the second process When the second process detects that the first indication information is not the first value, the second process will detect the first indication information again after a preset period of time.
  • the second process may start a timer, and when the timer reaches a preset value, the second process detects the first indication information again.
  • the second process reads the first service data from the second area of the first memory block.
  • the second process When the second process detects that the first indication information is the first value, the second process reads the first service data from the second area of the first memory block.
  • the second process finds the first memory block in the first memory pool based on the first identification information and the second identification information, and determines that the first memory block can be obtained from the first memory block based on the first indication information in the memory block management information The timing of reading the first business data in the second area.
  • no program other than the first process and the second process is required to intervene, and the first process and the second process can directly communicate with each other. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the second process before the first memory block is released, if the second process needs to reply data to the first process, or the second process happens to have data that needs to be transmitted to the first process. Then the second process will execute step 309 to step 310, and the first process will execute step 311 to step 312.
  • the second process writes second service data in the second area of the first memory block.
  • the second process since the second process has read the first service data from the aforementioned first memory block, the first memory block is in a state that allows access to the second process. Therefore, the second process can write the second service data that needs to be transmitted to the first process into the second area of the first memory block.
  • the second process adjusts the first indication information to a second value.
  • the second value is used to indicate that the first process is allowed to access the second area of the first memory block, and the second process is forbidden to access the second area. Because, after the second process writes the second service data into the second area of the first memory block, the second process will adjust the aforementioned first indication information to the second value. Therefore, the first process can determine that the aforementioned second process has written the second service data into the second area of the first memory block.
  • the first process has already defined the first indication information when step 303 is executed. Therefore, in this step 310, the second process only needs to adjust the value of the first indication information, that is, set the aforementioned first indication information to the second value.
  • the first process detects the first indication information in the memory block management information.
  • the first process will execute step 311. That is, after the first process will send the first identification information and the second identification information to the second process, the first process will detect the first indication information to determine whether the second process will send the first indication information to the second process. A process transfers data.
  • the first process executes step 312.
  • the first process When the first process detects that the first indication information is the first value, the first process will detect the first indication information again after a preset period of time.
  • the first process may start a timer, and when the timer reaches a preset value, the first process detects the first indication information again.
  • the first process obtains second service data from a second area of the first memory block.
  • the first process when the first process detects that the first indication information is the second value, it means that the second process modifies the first indication information in the memory block management information, and the first process can It is inferred that the second process has second service data that needs to be transmitted to the first process, and the second process has written the second service data into the second area of the first memory block. At this time, the first process may obtain the second service data from the second area of the first memory block.
  • the first process knows the address of the first memory block and can detect the first indication information, the first process can read the first memory block from the second area of the aforementioned first memory block. 2.
  • Business data without using the first identification information to find the first memory pool, nor using the second identification information to find the first memory block from the first memory pool. In such an implementation manner, the process of searching for the address of the first memory block by the first process is saved, which is beneficial to improve the communication efficiency between the first process and the second process.
  • step 312 after the first process executes step 312, if the first process still needs to transmit data to the second process, the first process will write to the second area of the first memory block again Incoming data that needs to be sent to the second process (for example, third service data) is specifically similar to the foregoing step 303 to step 305, and will not be repeated here. It should be noted that when performing steps similar to the foregoing step 303, that is, when the first process uses the first memory block to transfer data again, the first process only needs to modify a part of the memory block management information and write it into the foregoing third memory block. The business data is sufficient, and there is no need to rewrite all the memory block management information to the head of the first memory block.
  • the second process will again read the memory block indication information and service data from the aforementioned first memory block, which are specifically the same as the aforementioned steps 306 to 308, and will not be repeated here.
  • the second process writes the second service data in the first memory block that reads the first service data.
  • the first process detects the first indication information to determine whether the second process sends the data to the The first process replies with business data.
  • the second process does not need to find a memory block from the aforementioned first memory pool to write the second service data, but directly uses the first memory block to communicate with the first process, saving the second process The process of finding other memory blocks to communicate with the first process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • any one of the first process or the second process can initiate the release of the foregoing first memory block.
  • the aforementioned first process may release the first memory block.
  • the first process may adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the linked list to Free linked list. Then, the first process can finish releasing the first memory block.
  • the foregoing second process may release the first memory block.
  • the second process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the linked list of use to the idle state. Linked list.
  • both the aforementioned first process and the second process can view the state information of the header of the first memory block. Therefore, when one process modifies the status information, the other process can learn that the other process does not need to transmit service data. Compared with the solution in the prior art that requires both processes to issue release instructions to the processor, the foregoing implementation manner is more concise and efficient.
  • FIG. 5 a schematic structural diagram of an inter-process communication device 50 provided in this embodiment.
  • the inter-process communication device 50 runs the first process to realize the function of the first process in the foregoing method embodiments corresponding to FIG. 2 and FIG. 3.
  • the inter-process communication device 50 includes:
  • the writing module 501 is configured to write memory block management information and first business data in a first memory block, where the first memory block is located in the first memory pool, and the memory block management information is for maintaining the first memory block information.
  • the sending module 502 is configured to send identification information to a second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, and the identification information is used for Indicates the address of the first memory block.
  • the identification information includes first identification information and second identification information
  • the first identification information is used to indicate the first address of the first memory pool
  • the second identification information is used to indicate that the first memory block is located in the first memory pool.
  • the first memory block includes a first area and a second area.
  • the first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time.
  • the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  • the inter-process communication device 50 running the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block To the second process (that is, the inter-process communication device 60 running the second process in the embodiment corresponding to FIG. 6 hereinafter). Therefore, the inter-process communication device 60 finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the inter-process communication device 60 can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the inter-process communication device 50 further includes:
  • the writing module 501 is also configured to write memory pool management information in the first area of the first shared memory block to obtain the first memory pool.
  • the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple initial memory blocks constitute the first memory pool.
  • the memory block management information includes first indication information.
  • the inter-process communication device 50 also includes an acquisition module 503.
  • the acquiring module 503 is configured to acquire second service data from the second area of the first memory block when it is detected that the first indication information is a second value, and the second value is used to instruct the first process to allow access to the first memory block.
  • the second area and the second process is forbidden to access the second area.
  • the inter-process communication device 50 further includes an indication information adjustment module 504.
  • the instruction information adjustment module 504 is configured to set the first instruction information to a first value.
  • the first value is used to indicate that the first process is forbidden to access the second area of the first memory block and that the second process is allowed to access the second area of the first memory block. The second area.
  • the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state.
  • the inter-process communication device 50 also includes a state information adjustment module 505.
  • the state information adjustment module 505 is configured to adjust the state information from the idle state to the used state, and move the first memory block from the idle linked list to the used linked list.
  • the state information adjustment module 505 is further configured to adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the use linked list to the free linked list.
  • FIG. 6 a schematic structural diagram of an inter-process communication device 60 provided in this embodiment.
  • the inter-process communication device 60 runs the second process to realize the function of the second process in the foregoing method embodiments corresponding to FIG. 2 and FIG. 3.
  • the inter-process communication device 60 includes:
  • the receiving module 601 is configured to receive identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains the first memory block.
  • the reading module 602 is configured to read the first service data from the first memory block according to the identification information and the memory block management information.
  • the identification information includes first identification information and second identification information
  • the first identification information is used to indicate the first address of the first memory pool
  • the second identification information is used to indicate that the first memory block is located in the first memory pool.
  • the first memory block includes a first area and a second area.
  • the first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time.
  • the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  • the inter-process communication device 50 running the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block To the inter-process communication device 60 running the second process. Therefore, the inter-process communication device 60 finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the inter-process communication device 60 can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
  • the memory block management information includes first indication information.
  • the inter-process communication device 60 also includes:
  • the writing module 603 is configured to write second service data in the second area of the first memory block
  • the instruction information adjustment module 604 is adjusted to adjust the first instruction information to a second value, and the second value is used to indicate that the first process is allowed to access the second area and the second process is prohibited from accessing the second area.
  • the reading module 602 includes: a searching unit configured to search for the first memory block in the first memory pool according to the first identification information and the second identification information.
  • the reading unit is configured to read the first service data from the second area of the first memory block when it is detected that the first indication information is the first value, and the first value is used to indicate that the first process prohibits access The second area of the first memory block and the second process allows access to the second area.
  • the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state.
  • the inter-process communication device 60 also includes:
  • the state information adjustment module 605 is configured to adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the use linked list to the free linked list.
  • the device 70 can be an ordinary computer or a large-scale server, or other devices with a processor.
  • the device 70 includes an inter-process communication device 7011 running a first process and an inter-process communication device 7012 running a second process.
  • an inter-process communication device 7011 running a first process
  • an inter-process communication device 7012 running a second process.
  • the specific structure of the inter-process communication device 7011 please refer to the foregoing FIG. 5, and the specific structure of the inter-process communication device 7012 may refer to the foregoing FIG. 6.
  • the inter-process communication device 7011 and the inter-process communication device 7012 are both located in the processor 701. It should be understood that one processor 701 may run multiple inter-process communication devices.
  • the processor 701 includes at least two inter-process communication devices, and the two inter-process communication devices respectively run the aforementioned first process and the aforementioned second process.
  • the inter-process communication device 7011 and the inter-process communication device 7012 can transmit less data to each other in a manner such as a pipe or a message queue.
  • the processor 701 may be a general-purpose central processing unit (central processing unit, CPU) or a microprocessor (microprocessor).
  • the processor 701 may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU).
  • the processor 701 may refer to one or more devices, circuits, and/or processing cores for processing data (for example, computer program instructions).
  • the processor 701 may also include a kernel (not shown) for allocating shared memory for the inter-process communication device 7011 and the inter-process communication device 7012.
  • the inter-process communication device 7011 and the inter-process communication device 7012 are located outside the kernel.
  • the function of allocating shared memory for the inter-process communication device 7011 and the inter-process communication device 7012 may also be implemented by the processor 701, which is not specifically limited here.
  • inter-process communication device 7011 and inter-process communication device 7012 are connected to at least one memory 702 and at least one storage medium 703, and the storage medium 703 stores a program corresponding to the first process and a program corresponding to the second process.
  • the inter-process communication device 7011 and the inter-process communication device 7012 may be configured to communicate with the storage medium 703, and the inter-process communication device 7011 executes the program corresponding to the first process in the storage medium 703 to run the first process.
  • the communication device 7012 executes the program corresponding to the second process in the storage medium 703 to run the second process.
  • the processor 701 further includes a memory management unit (MMU), and the memory management unit is sometimes referred to as a paged memory management unit (PMMU).
  • MMU memory management unit
  • PMMU paged memory management unit
  • the MMU is located between the bus connecting the cache (not shown) and the memory 702, and is a kind of computer hardware responsible for processing the memory access request of the CPU.
  • the MMU is used to implement the conversion between physical addresses and virtual addresses. For example, the physical address of the first memory pool is mapped to the address space of the first process, so that the first process can find the first memory pool through the virtual address in the address space, and then the first process can pass through The offset can be found to the first memory block.
  • the MMU has a small amount of storage space to store a matching table from virtual addresses to physical addresses.
  • the matching table is also called a page table or translation lookaside buffer (translation lookaside buffer, TLB).
  • TLB translation lookaside buffer
  • the matching table records the physical address and The mapping relationship between virtual addresses, that is, each item in the matching table corresponds to a mapping from a virtual address to a physical address.
  • the entries of the matching table also define access permissions and buffer characteristics, which are not specifically limited here.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

Disclosed in the embodiments of the present application are an inter-process communication method and an inter-process communication apparatus. The inter-process communication method is realized by the inter-process communication apparatus respectively running a first process and a second process. In the inter-process communication method, the first process writes memory block management information and first business data in a first memory block in a first memory pool; and the first process also sends identification information used for indicating the address of the first memory block to the second process, so that the second process acquires the first business data in the first memory block according to the identification information and the memory block management information. Because the second process can read the first business data in the first memory block without the intervention of a third-party program, communication between the first process and the second process is achieved. Therefore, the communication efficiency between the first process and the second process can be improved.

Description

一种进程间通信方法以及进程间通信装置Inter-process communication method and inter-process communication device
本申请要求于2020年6月5日提交中国国家知识产权局、申请号为202010505324.6、申请名称为“一种进程间通信方法以及进程间通信装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the State Intellectual Property Office of China, the application number is 202010505324.6, and the application name is "an inter-process communication method and inter-process communication device" on June 5, 2020. The entire content of the application is approved The reference is incorporated in this application.
技术领域Technical field
本申请实施例涉及计算机领域,尤其涉及一种进程间通信方法以及进程间通信装置。The embodiments of the present application relate to the computer field, and in particular, to an inter-process communication method and an inter-process communication device.
背景技术Background technique
进程间通信(interprocess communication,IPC)是一个进程与另一个进程之间共享消息的一种通信方式,主要用于计算机系统中的不同进程之间的消息传递。其中,进程是计算机资源分配的最小单位,每个进程都拥有自己的虚拟地址空间,并与其他进程的虚拟地址空间相互隔离,也就是说,一个进程只能访问自己的虚拟地址空间,不能访问其他进程的虚拟地址空间。为了使不同的进程之间能够互相访问并协调工作,操作系统提供了多种IPC机制。Interprocess communication (IPC) is a communication method for sharing messages between one process and another process, and is mainly used for message transfer between different processes in a computer system. Among them, a process is the smallest unit of computer resource allocation. Each process has its own virtual address space and is isolated from the virtual address space of other processes. That is to say, a process can only access its own virtual address space, but cannot access it. The virtual address space of other processes. In order to enable different processes to access each other and coordinate their work, the operating system provides a variety of IPC mechanisms.
目前,该IPC机制主要包括管道(pipe)、消息队列(message quene)、套接字(socket)以及共享内存(shared memory)。其中,由于共享内存具有通信效率高、可靠性高以及容量可配置等特性,因此,共享内存是众多进程间通信机制中的一种常用且有效的方式。但是,当采用基于共享内存的进程间通信机制时,如果进程频繁向内核申请共享内存,将产生大量内存碎片而降低共享内存的利用率。对此,现有技术中常将共享内存机制和内存池(memory pool)机制结合,以减少内存碎片的产生,提高共享内存的利用率。Currently, the IPC mechanism mainly includes pipes, message queues, sockets, and shared memory. Among them, because the shared memory has the characteristics of high communication efficiency, high reliability, and configurable capacity, the shared memory is a common and effective method among many inter-process communication mechanisms. However, when the inter-process communication mechanism based on shared memory is adopted, if the process frequently applies for shared memory to the kernel, a large number of memory fragments will be generated and the utilization of shared memory will be reduced. In this regard, in the prior art, a shared memory mechanism and a memory pool (memory pool) mechanism are often combined to reduce the generation of memory fragments and improve the utilization of shared memory.
在将共享内存机制和内存池机制结合的方案中,处理器除了运行两个进程之外,还需要运行一个管理程序。该管理程序用于为前述两个进程分配共享内存作为内存池。当其中一个进程A需要发送业务数据给进程B时,该管理程序将该业务数据写入该内存池中的一个内存块中。当进程B需要获取该业务数据时,该管理程序获取该内存块中的业务数据并发送至该进程B。于是,可以实现进程A和进程B之间的通信。In the scheme that combines the shared memory mechanism and the memory pool mechanism, the processor needs to run a hypervisor in addition to running two processes. The hypervisor is used to allocate shared memory as a memory pool for the aforementioned two processes. When one of the processes A needs to send business data to the process B, the management program writes the business data into a memory block in the memory pool. When the process B needs to obtain the service data, the management program obtains the service data in the memory block and sends it to the process B. Thus, the communication between process A and process B can be realized.
在这样的方案中,进程A和进程B之间的通信需要第三方程序进行维护。因此,不利于提高进程A和进程B之间的通信效率。In such a scheme, the communication between process A and process B needs to be maintained by a third-party program. Therefore, it is not conducive to improving the communication efficiency between process A and process B.
发明内容Summary of the invention
本申请实施例提供了一种进程间通信方法以及进程间通信装置,用于提高进程间的通信效率。The embodiments of the present application provide an inter-process communication method and an inter-process communication device, which are used to improve the communication efficiency between processes.
第一方面,本申请实施例提供了一种进程间通信方法,该进程间通信方法由进程间通信装置分别运行第一进程和第二进程实现。其中,当第一进程需要向其他进程(例如,第二进程)传输业务数据时,该第一进程可以从内存池中选择一个内存块写入业务数据。以 第一内存池中的第一内存块为例。该第一进程在第一内存池中的第一内存块中写入内存块管理信息和第一业务数据。其中,该内存块管理信息为维护该第一内存块的信息,该第一业务数据为该第一进程准备传输给第二进程的业务数据。此外,该第一进程还将用于指示该第一内存块的地址的标识信息发送至第二进程,以使得该第二进程根据该标识信息和该内存块管理信息获取该第一内存块中的该第一业务数据。In the first aspect, an embodiment of the present application provides an inter-process communication method. The inter-process communication method is implemented by running a first process and a second process separately by an inter-process communication device. Wherein, when the first process needs to transmit service data to other processes (for example, the second process), the first process may select a memory block from the memory pool to write the service data. Take the first memory block in the first memory pool as an example. The first process writes the memory block management information and the first service data in the first memory block in the first memory pool. Wherein, the memory block management information is information for maintaining the first memory block, and the first service data is service data that the first process is ready to transmit to the second process. In addition, the first process also sends identification information indicating the address of the first memory block to the second process, so that the second process obtains the information in the first memory block according to the identification information and the memory block management information. Of the first business data.
本申请实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In the embodiment of the present application, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施方式,本申请实施例的一种可选的实施方式中,前述标识信息可以进一步包括第一标识信息和第二标识信息。其中,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiments of the present application, the foregoing identification information may further include first identification information and second identification information. The first identification information is used to indicate the first address of the first memory pool, and the second identification information is used to indicate the address of the first memory block in the first memory pool.
示例性的,前述第一标识信息和第二标识信息可以组成一个二元组,该二元组可以通过管道或消息队列等方式发送至第二进程。Exemplarily, the aforementioned first identification information and second identification information may form a two-tuple, and the two-tuple may be sent to the second process through a pipe, a message queue, or the like.
本实施方式中,提供了一种第一进程向第二进程指示第一内存块的地址的具体方式。由于,该第一标识信息是第一进程和第二进程之间约定的用于指示第一内存池的标识,因此,该第二进程根据该第一标识信息可以确定该第一内存池的首地址。可选的,该第一内存池的首地址为该第一内存池映射于该第二进程的地址空间的虚拟地址。又由于,该第二标识信息用于指示第一内存块在第一内存池中的地址,也可以理解为,该第二标识信息用于指示的是一个相对地址。因此,该第二进程可以基于前述第一标识信息和第二标识信息从该第一内存池中查找到该第一内存块。In this embodiment, a specific way for the first process to indicate the address of the first memory block to the second process is provided. Since the first identification information is the identification used to indicate the first memory pool agreed upon between the first process and the second process, the second process can determine the first memory pool based on the first identification information. address. Optionally, the first address of the first memory pool is a virtual address mapped to the address space of the second process by the first memory pool. Also, since the second identification information is used to indicate the address of the first memory block in the first memory pool, it can also be understood that the second identification information is used to indicate a relative address. Therefore, the second process can find the first memory block from the first memory pool based on the foregoing first identification information and second identification information.
基于前述实施方式,本申请实施例的一种可选的实施方式中,前述第一内存块包括两个区域,其中,第一区域用于记录前述内存块管理信息,第二区域用于记录业务数据(例如,前述第一业务数据)。可选的,前述第一区域也被称作第一内存块的头部,前述第二区域也被称作第一内存块的主体。当然,在实际应用中,还可以采用其他称谓表述,第一内存块中用于记录内存块管理信息的区域和第一内存块中用于记录业务数据的区域,具体此处不做限定。Based on the foregoing implementation manner, in an optional implementation manner of the embodiments of the present application, the foregoing first memory block includes two areas, where the first area is used for recording the foregoing memory block management information, and the second area is used for recording services. Data (for example, the aforementioned first business data). Optionally, the aforementioned first area is also referred to as the head of the first memory block, and the aforementioned second area is also referred to as the main body of the first memory block. Of course, in practical applications, other appellation expressions can also be used. The area in the first memory block for recording memory block management information and the area in the first memory block for recording business data are not specifically limited here.
示例性的,该第一区域仅占据该第一内存块的若干字节,也可以理解为,该内存块管理信息仅占据该第一内存块的若干字节。Exemplarily, the first area only occupies a few bytes of the first memory block. It can also be understood that the memory block management information only occupies a few bytes of the first memory block.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息包括第一指示信息,该第一指示信息用于指示该第一内存块的第二区域(即存储第一业务数据的区域)是否允许第一进程或第二进程访问。具体地,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。在本实施方式中,该第一进程在第一内存块中写入该内存块管理信息和该第一业务数据之后,该第一进程将标识信息发送至第二进程之前,该第一进程还将该第一指示信息设置为第一值。Based on the foregoing implementation manners, in an optional implementation manner of the embodiments of the present application, the memory block management information includes first indication information, and the first indication information is used to indicate the second area (ie, the storage area) of the first memory block. The area of the first service data) whether to allow the first process or the second process to access. Specifically, the first value is used to indicate that the first process is forbidden to access the second area of the first memory block and the second process is allowed to access the second area. In this embodiment, after the first process writes the memory block management information and the first service data in the first memory block, before the first process sends the identification information to the second process, the first process returns Set the first indication information to the first value.
本实施方式中,提出前述内存块管理信息中包含第一指示信息,该第一指示信息用于指示该第一内存块的第二区域(即存储第一业务数据的区域)是否允许第一进程或第二进程访问。该第一进程可以将该第一指示信息设置为第一值,此时,该第二进程可以推断该第一进程已将第一业务数据写入该第一内存块,于是该第二进程可以访问前述第一内存块中的第二区域。In this embodiment, it is proposed that the aforementioned memory block management information includes first indication information, and the first indication information is used to indicate whether the second area of the first memory block (that is, the area where the first service data is stored) allows the first process Or access by the second process. The first process may set the first indication information to the first value. At this time, the second process may infer that the first process has written the first service data into the first memory block, so the second process may Access the second area in the aforementioned first memory block.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一进程将标识信息发送至第二进程之后,该第一进程将检测前述第一指示信息。若该第一指示信息一直未发送生变化,则该第一进程将在预设时间段之后再次检测前述第一指示信息。当该第一进程检测到该第一指示信息为第二值时,该第一进程从该第一内存块的第二区域获取第二业务数据,第二值用于指示该第一进程允许访问该第二区域且第二进程禁止访问该第二区域。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, after the first process sends the identification information to the second process, the first process will detect the foregoing first indication information. If the first indication information has not been sent and changed, the first process will detect the aforementioned first indication information again after a preset period of time. When the first process detects that the first indication information is the second value, the first process obtains second service data from the second area of the first memory block, and the second value is used to indicate that the first process allows access The second area and the second process are forbidden to access the second area.
本实施方式中,当该第一进程检测到前述第一指示信息为第二值时,说明该第二进程已将该第二业务数据写入该第一内存块。于是,该第一进程将访问前述第一内存块的第二区域,并从该第一内存块中的第二区域中读取该第二业务数据。由于,在此过程中,第二进程直接在该第一内存块中写入的第二业务数据,没有重新在第一内存池中选取其他的内存块传输业务数据,因此,可以节省第二进程选取内存块以及将内存块映射至地址空间等流程,进而可以节省第一进程与第二进程间通信的效率。In this embodiment, when the first process detects that the aforementioned first indication information is the second value, it indicates that the second process has written the second service data into the first memory block. Then, the first process will access the second area of the aforementioned first memory block, and read the second service data from the second area of the first memory block. Since, in this process, the second process directly writes the second business data in the first memory block without re-selecting other memory blocks in the first memory pool to transmit business data, therefore, the second process can be saved The process of selecting the memory block and mapping the memory block to the address space can save the efficiency of communication between the first process and the second process.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。当前述第一进程在第一内存块中写入内存块管理信息和第一业务数据时,该第一进程将该状态信息由该空闲状态调整为该使用状态,并且,将该第一内存块从空闲链表移动至使用链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state. When the aforementioned first process writes the memory block management information and the first service data in the first memory block, the first process adjusts the state information from the idle state to the use state, and the first memory block Move from the idle linked list to the used linked list.
本实施方式中,当该第一进程确定需要使用该第一内存块进行通信时,该第一进程在向第一内存块写入内存块管理信息时,该第一进程可以将该状态信息调整为使用状态,并将该第一内存块从空闲链表移动至使用链表,以防止其他进程采用前述第一内存块。在这样的实施方式中,其他进程可以根据前述状态信息确定是否可以使用前述第一内存块,无需第三方程序向其他进程反馈该第一内存块的使用状态。因此,可以提高进程间通信的效率。In this embodiment, when the first process determines that the first memory block needs to be used for communication, when the first process writes memory block management information to the first memory block, the first process can adjust the state information In order to use the state, the first memory block is moved from the free linked list to the used linked list to prevent other processes from using the aforementioned first memory block. In such an implementation manner, other processes can determine whether the first memory block can be used according to the aforementioned status information, and there is no need for a third-party program to feed back the usage status of the first memory block to other processes. Therefore, the efficiency of inter-process communication can be improved.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一进程从该第一内存块的第二区域获取第二业务数据之后,该第一进程将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, after the first process obtains the second service data from the second area of the first memory block, the first process uses the first memory block The state information of is adjusted from the use state to the idle state, and the first memory block is moved from the use linked list to the idle linked list.
本实施方式中,提出当该第一进程不再使用该第一内存块时,该第一进程可以通过调整状态信息和调整第一内存块所在的链表的方式,释放该第一内存块。In this embodiment, it is proposed that when the first process no longer uses the first memory block, the first process can release the first memory block by adjusting the state information and adjusting the linked list where the first memory block is located.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一进程在第一内存块中写入内存块管理信息和第一业务数据之前,该方法还包括:该第一进程向内核申请第一共享内存块。该第一进程在该第一共享内存块的头部写入内存池管理信息。其中,该内存池管理信息用于将该第一共享内存块划分为多个初始内存块,该多个初始内存块构成该第一内存池。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, before the first process writes the memory block management information and the first service data in the first memory block, the method further includes: The process applies to the kernel for the first shared memory block. The first process writes memory pool management information at the head of the first shared memory block. Wherein, the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple initial memory blocks constitute the first memory pool.
本实施方式中,提出当第一进程没有可以使用的内存池时,该第一进程可以向内核申请第一共享内存块,然后通过向该第一共享内存块的头部写入内存池管理信息的方式,将前述第一共享内存块分化为由多个初始内存块组成的第一内存池。In this embodiment, it is proposed that when the first process does not have a memory pool that can be used, the first process can apply to the kernel for the first shared memory block, and then write the memory pool management information to the header of the first shared memory block In this way, the aforementioned first shared memory block is divided into a first memory pool composed of multiple initial memory blocks.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一内存块的大小小于或等于该初始内存块的大小。在这种实施方式中,该第一进程是直接从前述第一内存池中选取的一块初始内存块作为第一内存块,也就是说,该第一进程直接向前述第一内存池中的某一块初始内存块中写入第一业务数据。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the size of the first memory block is smaller than or equal to the size of the initial memory block. In this implementation manner, the first process directly selects an initial memory block from the aforementioned first memory pool as the first memory block, that is, the first process directly sends an initial memory block to the aforementioned first memory pool. The first business data is written into an initial memory block.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一内存池中每个初始内存块的大小不完全相同,该初始内存块包括第一初始内存块和第二初始内存块,该第一初始内存块的大小小于该第二初始内存块的大小。该第一内存块由一个该第二初始内存块拆分所得;或者,该第一内存块由至少两个该第一初始内存块组合所得。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the size of each initial memory block in the first memory pool is not completely the same, and the initial memory block includes the first initial memory block and the second initial memory block. A memory block, the size of the first initial memory block is smaller than the size of the second initial memory block. The first memory block is obtained by splitting one of the second initial memory blocks; or, the first memory block is obtained by combining at least two of the first initial memory blocks.
本实施方式中,提出前述第一内存块可以由多个初始内存块组合所得,也可以由一个初始内存块拆分所得。这样,有利于前述第一进程根据待写入的第一业务数据灵活选取内存块,提高前述第一内存池中内存块的利用率。In this embodiment, it is proposed that the aforementioned first memory block can be obtained by combining multiple initial memory blocks, or can be obtained by splitting one initial memory block. In this way, it is beneficial for the foregoing first process to flexibly select memory blocks according to the first service data to be written, and to improve the utilization of the memory blocks in the foregoing first memory pool.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括第二指示信息,该第二指示信息用于指示第一内存块与其他内存块的连接关系。具体地,该第二指示信息可以包括与第一内存块相邻的内存块的地址。当该第一内存块位于链表的两端时,该第二指示信息包括一个相邻内存块的地址;当该一内存块位于链表的中部时,该第二指示信息包括两个相邻内存块的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes second indication information, and the second indication information is used to indicate the connection relationship between the first memory block and other memory blocks . Specifically, the second indication information may include the address of a memory block adjacent to the first memory block. When the first memory block is located at both ends of the linked list, the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
第二方面,本申请实施例提供了一种进程间通信方法,该进程间通信方法由进程间通信装置分别运行第一进程和第二进程实现。在该方法中,第二进程接收第一进程发送的标识信息。其中,该标识信息用于指示第一内存块的地址,该第一内存块位于第一内存池中。该第一内存块中包含该第一进程写入的第一业务数据和内存块管理信息,该内存块管理信息为维护该第一内存块的信息。此外,该第二进程根据该标识信息和该内存块管理信息从该第一内存块中读取该第一业务数据。In the second aspect, an embodiment of the present application provides an inter-process communication method. The inter-process communication method is implemented by an inter-process communication device running a first process and a second process respectively. In this method, the second process receives the identification information sent by the first process. Wherein, the identification information is used to indicate the address of the first memory block, and the first memory block is located in the first memory pool. The first memory block includes first service data and memory block management information written by the first process, and the memory block management information is information for maintaining the first memory block. In addition, the second process reads the first service data from the first memory block according to the identification information and the memory block management information.
本申请实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In the embodiment of the present application, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施方式,本申请实施例的一种可选的实施方式中,前述标识信息可以进一步包括第一标识信息和第二标识信息。其中,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiments of the present application, the foregoing identification information may further include first identification information and second identification information. The first identification information is used to indicate the first address of the first memory pool, and the second identification information is used to indicate the address of the first memory block in the first memory pool.
示例性的,前述第一标识信息和第二标识信息可以组成一个二元组,该二元组可以通过管道或消息队列等方式发送至第二进程。Exemplarily, the aforementioned first identification information and second identification information may form a two-tuple, and the two-tuple may be sent to the second process through a pipe, a message queue, or the like.
本实施方式中,提供了一种第一进程向第二进程指示第一内存块的地址的具体方式。由于,该第一标识信息是第一进程和第二进程之间约定的用于指示第一内存池的标识,因此,该第二进程根据该第一标识信息可以确定该第一内存池的首地址。示例性的,该第一内存池的首地址为该第一内存池映射于该第二进程的地址空间的虚拟地址。又由于,该第二标识信息用于指示第一内存块在第一内存池中的地址,也可以理解为,该第二标识信息用于指示的是一个相对地址。因此,该第二进程可以基于前述第一标识信息和第二标识信息从该第一内存池中查找到该第一内存块。In this embodiment, a specific way for the first process to indicate the address of the first memory block to the second process is provided. Since the first identification information is the identification used to indicate the first memory pool agreed upon between the first process and the second process, the second process can determine the first memory pool based on the first identification information. address. Exemplarily, the first address of the first memory pool is a virtual address mapped to the address space of the second process by the first memory pool. Also, since the second identification information is used to indicate the address of the first memory block in the first memory pool, it can also be understood that the second identification information is used to indicate a relative address. Therefore, the second process can find the first memory block from the first memory pool based on the foregoing first identification information and second identification information.
基于前述实施方式,本申请实施例的一种可选的实施方式中,前述第一内存块包括两个区域,其中,第一区域用于记录前述内存块管理信息,第二区域用于记录业务数据(例如,前述第一业务数据)。可选的,前述第一区域也被称作第一内存块的头部,前述第二区域也被称作第一内存块的主体。当然,在实际应用中,还可以采用其他称谓表述,第一内存块中用于记录内存块管理信息的区域和第一内存块中用于记录业务数据的区域,具体此处不做限定。Based on the foregoing implementation manner, in an optional implementation manner of the embodiments of the present application, the foregoing first memory block includes two areas, where the first area is used for recording the foregoing memory block management information, and the second area is used for recording services. Data (for example, the aforementioned first business data). Optionally, the aforementioned first area is also referred to as the head of the first memory block, and the aforementioned second area is also referred to as the main body of the first memory block. Of course, in practical applications, other appellation expressions can also be used. The area in the first memory block for recording memory block management information and the area in the first memory block for recording business data are not specifically limited here.
示例性的,该第一区域仅占据该第一内存块的若干字节,也可以理解为,该内存块管理信息仅占据该第一内存块的若干字节。Exemplarily, the first area only occupies a few bytes of the first memory block. It can also be understood that the memory block management information only occupies a few bytes of the first memory block.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息包括第一指示信息,该第一指示信息用于指示该第一内存块的第二区域(即存储第一业务数据的区域)是否允许第一进程或第二进程访问。具体地,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。该第二进程根据该标识信息和该内存块管理信息从该第一内存块的第二区域读取该第一业务数据,包括:该第二进程根据该第一标识信息和该第二标识信息在该第一内存池中查找该第一内存块。当该第二进程检测到该第一指示信息为该第一值时,该第二进程从该第一内存块中读取该第一业务数据,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。Based on the foregoing implementation manners, in an optional implementation manner of the embodiments of the present application, the memory block management information includes first indication information, and the first indication information is used to indicate the second area (ie, the storage area) of the first memory block. The area of the first service data) whether to allow the first process or the second process to access. Specifically, the first value is used to indicate that the first process is forbidden to access the second area of the first memory block and the second process is allowed to access the second area. The second process reads the first service data from the second area of the first memory block according to the identification information and the memory block management information, including: the second process reads the first service data according to the first identification information and the second identification information Find the first memory block in the first memory pool. When the second process detects that the first indication information is the first value, the second process reads the first service data from the first memory block, and the first value is used to indicate that the first process is prohibited Access to the second area of the first memory block and the second process allows access to the second area.
本实施方式中,提出了第二进程利用标识信息和内存块管理信息从第一内存块中读取第一业务数据的具体实现方式。在该第二进程从前述第一内存池中查找到该第一内存块之后,该第二进程还需要检测前述第一指示信息的取值。当该第二进程检测到该第一指示信息为第一值时,该第二进程才能读取该第一内存块中的第一业务数据。In this implementation manner, a specific implementation manner in which the second process uses the identification information and the memory block management information to read the first service data from the first memory block is proposed. After the second process finds the first memory block from the foregoing first memory pool, the second process also needs to detect the value of the foregoing first indication information. When the second process detects that the first indication information is the first value, the second process can read the first service data in the first memory block.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第二进程根据该标识信息和该内存块管理信息从该第一内存块的第二区域中读取该第一业务数据之后,该方法还包括:该第二进程在该第一内存块的第二区域中写入第二业务数据,并将该第一指示信息调整为第二值,该第二值用于指示该第一进程允许访问该第二区域且该第二进程禁止访问该第二区域。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the second process reads the first service from the second area of the first memory block according to the identification information and the memory block management information After the data is collected, the method further includes: the second process writes second service data in the second area of the first memory block, and adjusts the first indication information to a second value, the second value being used to indicate The first process allows access to the second area and the second process prohibits access to the second area.
本实施方式中,提出第二进程无需重新从前述第一内存池中选取内存块,而是可以直接采用该第一内存块向该第一进程发送或回复业务数据。此时,该第二进程直接在该第一内存块中写入第二业务数据,并将该第一指示信息调整为第二值。于是,当该第一进程检测到该第一指示信息由第一值调整为第二值时,该第一进程可以从前述第一内存块中读取 第二业务数据。因此,可以节省第二进程选取内存块以及将内存块映射至地址空间等流程,进而可以节省第一进程与第二进程间通信的效率。In this embodiment, it is proposed that the second process does not need to reselect a memory block from the aforementioned first memory pool, but can directly use the first memory block to send or reply service data to the first process. At this time, the second process directly writes the second service data in the first memory block, and adjusts the first indication information to the second value. Therefore, when the first process detects that the first indication information is adjusted from the first value to the second value, the first process can read the second service data from the aforementioned first memory block. Therefore, the processes of selecting the memory block and mapping the memory block to the address space by the second process can be saved, thereby saving the efficiency of communication between the first process and the second process.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第二进程根据该标识信息和内存块管理信息从该第一内存块中读取该第一业务数据之后,该方法还包括:该第二进程将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, after the second process reads the first service data from the first memory block according to the identification information and the memory block management information, the method It also includes: the second process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the use linked list to the free linked list.
本实施方式中,提出当该第二进程不再使用该第一内存块时,该第二进程可以通过调整状态信息和调整第一内存块所在的链表的方式,释放该第一内存块。In this embodiment, it is proposed that when the second process no longer uses the first memory block, the second process can release the first memory block by adjusting the state information and the linked list where the first memory block is located.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括第二指示信息,该第二指示信息用于指示第一内存块与其他内存块的连接关系。具体地,该第二指示信息可以包括与第一内存块相邻的内存块的地址。当该第一内存块位于链表的两端时,该第二指示信息包括一个相邻内存块的地址;当该一内存块位于链表的中部时,该第二指示信息包括两个相邻内存块的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes second indication information, and the second indication information is used to indicate the connection relationship between the first memory block and other memory blocks . Specifically, the second indication information may include the address of a memory block adjacent to the first memory block. When the first memory block is located at both ends of the linked list, the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
第三方面,本申请实施例提供了一种进程间通信装置,该进程间通信装置位于处理器中,该进程间通信装置通过调用存储器中程序代码运行第一进程,该进程间通信装置包括如下功能模块:写入模块,用于在第一内存块中写入内存块管理信息和第一业务数据,该第一内存块位于第一内存池中,该内存块管理信息为维护该第一内存块的信息。发送模块,用于将标识信息发送至第二进程,以使得该第二进程根据该标识信息和该内存块管理信息获取该第一内存块中的该第一业务数据,该标识信息用于指示该第一内存块的地址。In a third aspect, an embodiment of the present application provides an inter-process communication device, the inter-process communication device is located in a processor, the inter-process communication device runs a first process by calling program codes in a memory, and the inter-process communication device includes the following Function module: write module, used to write memory block management information and first business data in the first memory block, the first memory block is located in the first memory pool, and the memory block management information is for maintaining the first memory Block information. The sending module is configured to send identification information to a second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, and the identification information is used to indicate The address of the first memory block.
本申请实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In the embodiment of the present application, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该标识信息包括第一标识信息和第二标识信息,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一内存块包括第一区域和第二区域;该第一区域用于记录该内存块管理信息,该第一区域允许该第一进程或该第二进程随时访问;该第二区域用于记录该第一业务数据,该第二区域不允许该第一进程和该第二进程随时访问。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the first memory block includes a first area and a second area; the first area is used to record the memory block management information, and the first area The first process or the second process is allowed to access at any time; the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息包括第一指示信息。该进程间通信装置还包括:Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information includes first indication information. The inter-process communication device also includes:
获取模块,用于当检测到该第一指示信息为第二值时从该第一内存块的第二区域获取第二业务数据,该第二值用于指示该第一进程允许访问该第二区域且该第二进程禁止访问该第二区域。The acquiring module is configured to acquire second service data from the second area of the first memory block when it is detected that the first indication information is a second value, and the second value is used to indicate that the first process is allowed to access the second Area and the second process is forbidden to access the second area.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该进程间通信装置还包括:指示信息调整模块,用于将该第一指示信息设置为第一值,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the inter-process communication device further includes: an instruction information adjustment module, configured to set the first instruction information to a first value, and the first value It is used to instruct the first process to prohibit access to the second area of the first memory block and the second process to allow access to the second area.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。状态信息调整模块,用于将该状态信息由该空闲状态调整为该使用状态,并且,将该第一内存块从空闲链表移动至使用链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state. The state information adjustment module is configured to adjust the state information from the idle state to the used state, and move the first memory block from the idle linked list to the used linked list.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该状态信息调整模块,还用于将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the state information adjustment module is further configured to adjust the state information of the first memory block from the use state to the idle state, and The first memory block is moved from the used linked list to the free linked list.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该进程间通信装置还包括:资源申请模块,用于向内核申请第一共享内存块。该写入模块,还用于在该第一共享内存块的头部写入内存池管理信息,该内存池管理信息用于将该第一共享内存块划分为多个初始内存块,该多个初始内存块构成该第一内存池。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the inter-process communication device further includes: a resource application module, configured to apply to the kernel for the first shared memory block. The writing module is also used to write memory pool management information at the head of the first shared memory block, where the memory pool management information is used to divide the first shared memory block into a plurality of initial memory blocks, and the plurality of The initial memory block constitutes the first memory pool.
需要说明的是,本申请实施例还有多种具体其他实施方式,具体可参见第一方面的具体实施方式和其有益效果,在此不再赘述。It should be noted that there are many other specific implementation manners in the embodiments of the present application. For details, please refer to the specific implementation manners and beneficial effects of the first aspect, which will not be repeated here.
第四方面,本申请实施例提供了一种进程间通信装置,该进程间通信装置位于处理器中,该进程间通信装置通过调用存储器中程序代码运行第二进程,该进程间通信装置包括如下功能模块:In a fourth aspect, an embodiment of the present application provides an inter-process communication device. The inter-process communication device is located in a processor. The inter-process communication device runs a second process by calling program codes in a memory. The inter-process communication device includes the following functional module:
接收模块,用于接收第一进程发送的标识信息,该标识信息用于指示第一内存块的地址,该第一内存块位于第一内存池中,该第一内存块中包含该第一进程写入的第一业务数据和内存块管理信息,该内存块管理信息为维护该第一内存块的信息。读取模块,用于根据该标识信息和该内存块管理信息从该第一内存块中读取该第一业务数据。The receiving module is configured to receive identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains the first process The written first service data and memory block management information, where the memory block management information is information for maintaining the first memory block. The reading module is configured to read the first service data from the first memory block according to the identification information and the memory block management information.
本申请实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In the embodiment of the present application, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该标识信息包括第一标识信息和第二标识信息,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该第一内存块包括第一区域和第二区域;该第一区域用于记录该内存块管理信息,该第一区域允许该第一进程或 该第二进程随时访问;该第二区域用于记录该第一业务数据,该第二区域不允许该第一进程和该第二进程随时访问。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the first memory block includes a first area and a second area; the first area is used to record the memory block management information, and the first area The first process or the second process is allowed to access at any time; the second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息包括第一指示信息。该进程间通信装置还包括:写入模块,用于在该第一内存块的第二区域中写入第二业务数据,并将该第一指示信息调整为第二值,该第二值用于指示该第一进程允许访问该第二区域且该第二进程禁止访问该第二区域。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information includes first indication information. The inter-process communication device further includes: a writing module for writing second service data in the second area of the first memory block, and adjusting the first indication information to a second value, the second value being used Instructing the first process to allow access to the second area and the second process to prohibit access to the second area.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该读取模块包括:查找单元,用于根据该第一标识信息和该第二标识信息在该第一内存池中查找该第一内存块。读取单元,用于当检测到该第一指示信息为该第一值时从该第一内存块的第二区域读取该第一业务数据,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the reading module includes: a searching unit configured to search in the first memory pool according to the first identification information and the second identification information The first memory block. The reading unit is configured to read the first service data from the second area of the first memory block when it is detected that the first indication information is the first value, and the first value is used to indicate that the first process is prohibited Access to the second area of the first memory block and the second process allows access to the second area.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the memory block management information further includes state information, and the state information is used to indicate that the first memory block is in an idle state or in a use state.
基于前述实施方式,本申请实施例的一种可选的实施方式中,该进程间通信装置还包括:状态信息调整模块,用于将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。Based on the foregoing implementation manner, in an optional implementation manner of the embodiment of the present application, the inter-process communication device further includes: a state information adjustment module, configured to adjust the state information of the first memory block from the use state to the In an idle state, the first memory block is moved from the used linked list to the free linked list.
需要说明的是,本申请实施例还有多种具体其他实施方式,具体可参见第二方面的具体实施方式和其有益效果,在此不再赘述。It should be noted that there are many other specific implementation manners in the embodiments of the present application. For details, please refer to the specific implementation manners of the second aspect and its beneficial effects, which will not be repeated here.
第五方面,本申请实施例提供了一种设备,该可以是普通计算机或大型服务器,也可以其他带有处理器的设备。该设备中包括运行第一进程的进程间通信装置和运行第二进程的进程间通信装置。其中,运行第一进程的进程间通信装置用于实现如前述第三方面中任意一种实施方式所介绍的功能;运行第二进程的进程间通信装置用于实现如前述第四方面中任意一种实施方式所介绍的功能。In the fifth aspect, an embodiment of the present application provides a device, which may be a normal computer or a large-scale server, or other devices with a processor. The device includes an inter-process communication device that runs the first process and an inter-process communication device that runs the second process. Among them, the inter-process communication device running the first process is used to implement the function described in any one of the foregoing third aspect; the inter-process communication device running the second process is used to implement any one of the foregoing fourth aspect The functions described in the various implementations.
示例性的,运行第一进程的进程间通信装置和运行第二进程的进程间通信装置均位于前述设备的处理器中。该处理器可以是通用中央处理器或微处理器;该处理器可以是单核处理器,也可以是多核处理器。此外,该处理器可以指一个或多个装置、电路、和/或用于处理数据(例如计算机程序指令)的处理核。Exemplarily, the inter-process communication device running the first process and the inter-process communication device running the second process are both located in the processor of the aforementioned device. The processor may be a general-purpose central processing unit or a microprocessor; the processor may be a single-core processor or a multi-core processor. In addition, the processor may refer to one or more devices, circuits, and/or processing cores for processing data (for example, computer program instructions).
示例性的,运行第一进程的进程间通信装置和运行第二进程的进程间通信装置与至少一个存储器和至少一个存储介质相连,该存储介质存储有第一进程对应的程序和第二进程对应的程序。更进一步地,运行第一进程的进程间通信装置和运行第二进程的进程间通信装置可以设置为与存储介质通信,以执行存储介质中的程序。Exemplarily, the inter-process communication device running the first process and the inter-process communication device running the second process are connected to at least one memory and at least one storage medium, and the storage medium stores a program corresponding to the first process and a program corresponding to the second process. program of. Furthermore, the inter-process communication device running the first process and the inter-process communication device running the second process may be configured to communicate with the storage medium to execute the program in the storage medium.
示例性的,该处理器还包括存储器管理单元,该MMU位于连接高速缓存以及存储器的总线之间,是一种负责处理CPU的内存访问请求的计算机硬件。该MMU用于实现物理地址到虚拟地址之间的转换。Exemplarily, the processor further includes a memory management unit, and the MMU is located between the bus connecting the cache and the memory, and is a kind of computer hardware responsible for processing the memory access request of the CPU. The MMU is used to implement the conversion between physical addresses and virtual addresses.
第六方面,本申请实施例提供了一种处理系统,该处理系统包括如前述第三方面中任意一种实施方式所介绍的进程间通信装置,以及如前述第四方面中任意一种实施方式所介绍的进程间通信装置。In a sixth aspect, an embodiment of the present application provides a processing system, which includes the inter-process communication device as described in any one of the implementation manners in the foregoing third aspect, and any one of the implementation manners in the foregoing fourth aspect The inter-process communication device introduced.
第七方面,本申请实施例提供了一种处理芯片,该处理芯片包括如第六方面所介绍的处理系统。In a seventh aspect, an embodiment of the present application provides a processing chip, and the processing chip includes the processing system described in the sixth aspect.
第八面,本申请实施例提供了一种计算机可读存储介质,其上存储有计算机程序或指令,其特征在于,该计算机程序或指令被执行时使得进程间通信装置执行第一方面以及第一方面中任意一种实施方式所介绍的方法,或者,执行第二方面以及第二方面中任意一种实施方式所介绍的方法。On the eighth aspect, an embodiment of the present application provides a computer-readable storage medium on which a computer program or instruction is stored. The feature is that when the computer program or instruction is executed, the inter-process communication device executes the first aspect and the second aspect. The method introduced in any one of the implementation manners in one aspect, or the method introduced in the second aspect and any one of the implementation manners in the second aspect is executed.
从以上技术方案可以看出,本申请实施例具有以下优点:It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
本申请实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In the embodiment of the present application, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends the identification information used to determine the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
附图说明Description of the drawings
为了更清楚地说明本申请实施例的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例。In order to explain the technical solutions of the embodiments of the present application more clearly, the accompanying drawings required in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present application.
图1为基于共享内存机制的进程间通信的一个原理图;Figure 1 is a schematic diagram of inter-process communication based on the shared memory mechanism;
图2为本申请实施例中进程间通信方法的一个流程图;Figure 2 is a flowchart of an inter-process communication method in an embodiment of the application;
图3为本申请实施例中进程间通信方法的另一个流程图;FIG. 3 is another flowchart of the inter-process communication method in an embodiment of the application;
图4A为本申请实施例中基于共享内存机制的进程间通信的一个原理图;4A is a schematic diagram of inter-process communication based on a shared memory mechanism in an embodiment of the application;
图4B为本申请实施例中内存池的一个示意图;4B is a schematic diagram of the memory pool in an embodiment of the application;
图5为本申请实施例中进程间通信装置的一个实施例示意图;Fig. 5 is a schematic diagram of an embodiment of an inter-process communication device in an embodiment of the application;
图6为本申请实施例中进程间通信装置的另一个实施例示意图;Fig. 6 is a schematic diagram of another embodiment of an inter-process communication device in an embodiment of the application;
图7为本申请实施例中进程间通信装置适用的设备的一个结构示意图。FIG. 7 is a schematic structural diagram of a device applicable to the inter-process communication apparatus in an embodiment of the application.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects, without having to use To describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments described herein can be implemented in a sequence other than the content illustrated or described herein. In addition, the terms "including" and "having" and any variations of them are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those clearly listed. Those steps or units may include other steps or units that are not clearly listed or are inherent to these processes, methods, products, or equipment.
本申请实施例提供了一种进程间通信方法以及进程间通信装置,用于提高进程间的通信效率。The embodiments of the present application provide an inter-process communication method and an inter-process communication device, which are used to improve the communication efficiency between processes.
为便于理解本申请实施例提出的进程间通信方法,下面先对共享内存机制进行介绍:In order to facilitate the understanding of the inter-process communication method proposed in the embodiment of the present application, the shared memory mechanism is first introduced below:
如图1所示,为共享内存机制的一个原理图。共享内存机制,指内核为两个相互隔离的进程分配一块物理内存,将该物理内存分别映射到前述两个进程的地址空间中,以使得前述任意一个进程可以通过访问该进程自己的地址空间以读取到存储于前述物理内存中的数据。因此,可以使得两个进程通过一块内存进行通信,而这一块内存则被称作共享内存。以图1中的进程A和进程B之间的通信为例,共享内存002为物理内存001中的一部分,进程A的地址空间为101,进程B的地址空间为101’。若将共享内存002映射至进程A中的地址空间101,则共享内存002在地址空间101中的虚拟地址为102。此时,记录数据的内存块0031与进程A中的虚拟地址1031对应,记录地址的内存块0032与进程A中的虚拟地址1032对应。若将共享内存002映射至进程B中的地址空间101’,则共享内存002在地址空间101’中的虚拟地址为102’。此时,记录数据的内存块0031与进程B中的虚拟地址1031’对应,记录地址的内存块0032与进程B中的虚拟地址1032’对应。As shown in Figure 1, it is a schematic diagram of the shared memory mechanism. Shared memory mechanism means that the kernel allocates a piece of physical memory for two mutually isolated processes, and maps the physical memory to the address spaces of the aforementioned two processes, so that any one of the aforementioned processes can access the process’s own address space to Read the data stored in the aforementioned physical memory. Therefore, two processes can communicate through a block of memory, and this block of memory is called shared memory. Taking the communication between process A and process B in Figure 1 as an example, shared memory 002 is a part of physical memory 001, the address space of process A is 101, and the address space of process B is 101'. If the shared memory 002 is mapped to the address space 101 in the process A, the virtual address of the shared memory 002 in the address space 101 is 102. At this time, the memory block 0031 where the data is recorded corresponds to the virtual address 1031 in the process A, and the memory block 0032 where the address is recorded corresponds to the virtual address 1032 in the process A. If the shared memory 002 is mapped to the address space 101' in the process B, the virtual address of the shared memory 002 in the address space 101' is 102'. At this time, the memory block 0031 where the data is recorded corresponds to the virtual address 1031' in the process B, and the memory block 0032 where the address is recorded corresponds to the virtual address 1032' in the process B.
应当理解的是,同一物理内存映射于不同的地址空间时,该内存在不同的地址空间中的虚拟地址一般不同。例如,记录数据的内存块0031在进程A的地址空间中的地址1031与该记录数据的内存块0031在进程B的地址空间中的地址1031’一般不同。因此,若进程B仅知道该记录数据的内存块0031在进程A的地址空间中的虚拟地址1031,则该进程B无法利用该虚拟地址1031在进程B的地址空间中查找到虚拟地址1031’中的数据。此外,若同一块共享内存同时被多个进程读取或同时被多个进程写入,则将导致数据读写错乱。因此,进程B要想收到来自进程A的数据,则该进程B需要获知记录数据的内存块在进程B的地址空间中的虚拟地址,还需要获知何时被允许读取前述内存块中的数据。It should be understood that when the same physical memory is mapped to different address spaces, the virtual addresses of the memory in different address spaces are generally different. For example, the address 1031 of the data-recording memory block 0031 in the address space of the process A is generally different from the address 1031' of the data-recording memory block 0031 in the address space of the process B. Therefore, if process B only knows the virtual address 1031 of the memory block 0031 that records data in the address space of process A, then process B cannot use the virtual address 1031 to find the virtual address 1031' in the address space of process B The data. In addition, if the same shared memory is read by multiple processes at the same time or written by multiple processes at the same time, it will cause data read and write confusion. Therefore, if process B wants to receive data from process A, process B needs to know the virtual address of the memory block that records the data in the address space of process B, and also needs to know when it is allowed to read the memory block in the aforementioned memory block. data.
对此,目前的技术是在运行进程A和进程B的处理器中再运行一个管理程序,由该管理程序负责协调前述进程A和进程B之间的通信。具体地,该管理程序将前述进程A需要发送给进程B的数据写入在共享内存中的某一个内存块(例如图1中记录数据的内存块0031)中,再将该内存块映射于进程A的地址空间中的虚拟地址(即虚拟地址1031)写入另一个内存块(例如图1中记录地址的内存块0032)中。当进程B需要访问前述数据时,该管理程序将从记录地址的内存块0032中获取前述虚拟地址1031并转换为进程B的地址空间中的虚拟地址(即虚拟地址1031’),并且,该管理程序将在进程B被允许读取前述内存块(即记录数据的内存块0031)时将该进程B的地址空间中虚拟地址1031’发送至进程B,以使得进程B通过该虚拟地址1031’读取到前述数据。在这样的方案中,管理程序对前述两个进程进行管理,对前述两个进程之间的数据通信进行协调。若前述管理程序出现错误,则将影响进程A和进程B之间的通信。In this regard, the current technology is to run another management program in the processor running the process A and the process B, and the management program is responsible for coordinating the communication between the aforementioned process A and the process B. Specifically, the management program writes the data that the aforementioned process A needs to send to the process B in a certain memory block in the shared memory (for example, the memory block 0031 that records data in Figure 1), and then maps the memory block to the process The virtual address in the address space of A (ie, the virtual address 1031) is written into another memory block (for example, the memory block 0032 where the address is recorded in FIG. 1). When process B needs to access the aforementioned data, the hypervisor will obtain the aforementioned virtual address 1031 from the memory block 0032 of the recording address and convert it into a virtual address in the address space of process B (ie virtual address 1031'), and the management The program will send the virtual address 1031' in the address space of the process B to the process B when the process B is allowed to read the aforementioned memory block (that is, the memory block 0031 where the data is recorded), so that the process B can read through the virtual address 1031' Get the aforementioned data. In such a scheme, the management program manages the aforementioned two processes and coordinates the data communication between the aforementioned two processes. If an error occurs in the aforementioned management program, it will affect the communication between process A and process B.
为提高进程间通信的效率,本申请实施例提出在共享内存中写入管理信息,以使得前述两个进程通过查看管理信息获知内存的状态以及允许读取内存中的数据的时机,通过修改管理信息通知对方进程读取或写入数据。在此过程中,处理器仅需要运行前述进程A和 进程B,而不需要运行第三方程序以对前述两个进程之间的通信进行协调。因此,有利于提高进程间的通信的效率。In order to improve the efficiency of inter-process communication, this embodiment of the present application proposes to write management information in the shared memory, so that the foregoing two processes can learn the state of the memory by viewing the management information and the timing of allowing the data in the memory to be read, and then modify the management The information informs the opposite process to read or write data. In this process, the processor only needs to run the aforementioned process A and process B, and does not need to run a third-party program to coordinate the communication between the aforementioned two processes. Therefore, it is beneficial to improve the efficiency of communication between processes.
下面以第一进程和第二进程之间的通信流程对本申请实施例提出的进程间通信方法进行介绍,具体如图2所示,该第一进程和第二进程将执行如下步骤:The following describes the inter-process communication method proposed in the embodiment of the present application with the communication process between the first process and the second process. As shown in FIG. 2, the first process and the second process will perform the following steps:
201、第一进程在第一内存块中写入内存块管理信息和第一业务数据。201. The first process writes memory block management information and first service data in the first memory block.
其中,该第一业务数据指该第一进程准备传输给第二进程的业务数据。Wherein, the first service data refers to service data that the first process is ready to transmit to the second process.
该内存块管理信息为维护该第一内存块的信息。可以理解为,该第一进程通过在该第一内存块中写入该内存块管理信息的方式,实现对该第一内存块的管理或维护。例如,确定第一内存块的状态,定义进程对该第一内存块的访问权限,定义第一内存块所在的链表,定义第一内存块与其他内存块的连接关系,以及定义其他可以对第一内存块实现管理维护功能的信息等。The memory block management information is information for maintaining the first memory block. It can be understood that the first process implements the management or maintenance of the first memory block by writing the memory block management information in the first memory block. For example, determine the state of the first memory block, define the access rights of the process to the first memory block, define the linked list where the first memory block is located, define the connection relationship between the first memory block and other memory blocks, and define other possible access rights to the first memory block. A memory block realizes the information of management and maintenance functions and so on.
示例性的,前述内存块管理信息包括:状态信息,用于指示第一内存块的状态;第一指示信息,用于指示第一进程或其他进程对该第一内存块的访问权限;第二指示信息,用于指示第一内存块与其他内存块的连接关系。除了前述多种信息,该内存块管理信息还可以包括其他用于对第一内存块实现管理维护的信息。具体地,后文步骤303将进行详细介绍,此处不再赘述。Exemplarily, the aforementioned memory block management information includes: status information, used to indicate the state of the first memory block; first indication information, used to indicate the access authority of the first process or other processes to the first memory block; second The indication information is used to indicate the connection relationship between the first memory block and other memory blocks. In addition to the foregoing various types of information, the memory block management information may also include other information used to manage and maintain the first memory block. Specifically, step 303 will be described in detail later, and will not be repeated here.
基于前述示例,当前述第一内存块中的内存块管理信息被第一进程修改时,前述多种信息中的一种或多种将发生改变,以使得该第一内存块的状态、第一内存块对于其他进程的访问权限以及第一内存块与其他内存块的连接关系中的一项或多项发生改变,进而实现对该第一内存块的管理和维护,也有助于其他进程基于前述内存块管理信息做决策。Based on the foregoing example, when the memory block management information in the foregoing first memory block is modified by the first process, one or more of the foregoing multiple types of information will change, so that the state of the first memory block, the first One or more of the memory block's access rights to other processes and the connection relationship between the first memory block and other memory blocks is changed, so as to realize the management and maintenance of the first memory block, and also help other processes based on the aforementioned Memory block management information makes decisions.
应当注意的是,除了前述第一进程可以对该内存块管理信息进行修改,其他将与该第一进程进行通信的进程(例如后续将介绍的第二进程)也可以对该内存块管理信息进行修改。It should be noted that, in addition to the aforementioned first process that can modify the memory block management information, other processes that will communicate with the first process (for example, the second process that will be introduced later) can also modify the memory block management information. Revise.
此外,前述第一内存块位于第一内存池中,该第一内存池可以由第一进程对内核分配的共享内存块进行初始化而获得,也可以由其他进程对内核分配的共享内存进行初始化而获得,具体此处不做限定。在本实施例以及后续实施例中,以该第一内存池由第一进程共享内存块进行初始化而获得为例进行介绍。In addition, the aforementioned first memory block is located in the first memory pool, and the first memory pool may be obtained by initializing the shared memory block allocated by the kernel by the first process, or may be obtained by initializing the shared memory allocated by the kernel by other processes. Obtained, the details are not limited here. In this embodiment and subsequent embodiments, the first memory pool is obtained by initializing the shared memory block of the first process for introduction.
示例性的,当第一进程向内核申请了共享内存并初始化为第一内存池之后,该第一内存池中可以有多个不同大小的初始内存块,并且前述多个初始内存块可以供前述第一进程选择。该第一进程可以直接在前述多个初始内存块中的一个初始内存块中写入内存块管理信息和第一业务数据。此时,前述第一内存块为前述多个初始内存块中的一个内存块。此外,前述第一内存块也可以是前述一个初始内存块经拆分之后获得的内存块,也可以是前述多个初始内存块合并之后获得的内存块。具体地,以该第一进程待写入的第一业务数据的大小和内存块管理信息的大小的总和而定。也就是说,当前述总和等于一个初始内存块的大小时,前述第一内存块可以是前述多个初始内存块中的某一个初始内存块;当前述总和小于一个初始内存块的大小时,前述第一内存块可以是前述一个初始内存块经拆分之后 获得的内存块;当前述总和大于一个初始内存块的大小时,前述第一内存块可以是前述多个初始内存块合并之后获得的内存块。Exemplarily, after the first process applies to the kernel for shared memory and initializes it as the first memory pool, there may be multiple initial memory blocks of different sizes in the first memory pool, and the foregoing multiple initial memory blocks may be used for the foregoing The first process selection. The first process may directly write the memory block management information and the first service data in one of the foregoing multiple initial memory blocks. At this time, the aforementioned first memory block is one of the aforementioned multiple initial memory blocks. In addition, the foregoing first memory block may also be a memory block obtained after the foregoing one initial memory block is split, or may be a memory block obtained after the foregoing multiple initial memory blocks are merged. Specifically, it is determined by the sum of the size of the first service data to be written by the first process and the size of the memory block management information. That is to say, when the foregoing sum is equal to the size of an initial memory block, the foregoing first memory block may be one of the foregoing multiple initial memory blocks; when the foregoing sum is less than the size of an initial memory block, the foregoing The first memory block may be a memory block obtained after the foregoing initial memory block is split; when the foregoing sum is greater than the size of an initial memory block, the foregoing first memory block may be a memory obtained after the foregoing multiple initial memory blocks are merged piece.
应当理解的是,虽然前述第一内存池中包含若干个不同大小的初始内存块,但是,同一种大小的初始内存块也可以有多个。此外,不同大小的初始内存块之间具有一定的规律。示例性的,其中一个初始内存块的大小是另一个初始内存块的整数倍。例如,第一内存池中包含N个8M的初始内存块,Q个16M的初始内存块,R个32M的初始内存块。It should be understood that although the aforementioned first memory pool contains several initial memory blocks of different sizes, there may be multiple initial memory blocks of the same size. In addition, there are certain rules among initial memory blocks of different sizes. Exemplarily, the size of one of the initial memory blocks is an integer multiple of the other initial memory block. For example, the first memory pool contains N initial memory blocks of 8M, Q initial memory blocks of 16M, and R initial memory blocks of 32M.
此外,前述第一内存块包括两个区域,其中,前述第一区域为第一内存块中用于记录内存块管理信息的区域,前述第二区域为第一内存块中用于记录业务数据的区域。也可以理解为,第一区域用于供该第一进程写入前述内存块管理信息,或者,用于供第二进程或其他进程修改前述内存块管理信;第二区域用于供该第一进程写入业务数据(例如,前述第一业务数据)。示例性的,前述第一区域也被称作第一内存块的头部,前述第二区域也被称作第一内存块的主体。当然,在实际应用中,还可以采用其他称谓表述,具体此处不做限定。其中,第一区域仅占据该第一内存块靠前的若干字节。由于,该内存块管理信息位于前述第一内存块的第一区域,该第一区域的大小远小于第一内存块的大小。因此,该内存块管理信息的大小也一般较小,甚至远小于第一业务数据的大小。In addition, the aforementioned first memory block includes two areas, where the aforementioned first area is an area in the first memory block for recording memory block management information, and the aforementioned second area is an area in the first memory block for recording business data. area. It can also be understood that the first area is used for the first process to write the foregoing memory block management information, or for the second process or other processes to modify the foregoing memory block management information; the second area is used for the first process to modify the foregoing memory block management information; The process writes business data (for example, the aforementioned first business data). Exemplarily, the aforementioned first area is also referred to as the head of the first memory block, and the aforementioned second area is also referred to as the main body of the first memory block. Of course, in practical applications, other appellation expressions can also be used, and the specific expressions are not limited here. Among them, the first area only occupies the first few bytes of the first memory block. Since the memory block management information is located in the first area of the aforementioned first memory block, the size of the first area is much smaller than the size of the first memory block. Therefore, the size of the memory block management information is generally small, even far smaller than the size of the first service data.
具体地,在该第一进程向该第一内存块中写入前述内存块管理信息和第一业务数据的过程中,该第一进程先在前述第一区域内写入内存块管理信息,再在前述第二区域写入第一业务数据。该第一区域被写入前述内存块管理信息之后,该第一区域允许第一进程或其他进程随时访问该第一区域。但是,该第二区域不允许除写入内存块管理信息之外的进程随时访问。也就是说,若该第一内存块中的内存块管理信息是由第一进程写入的,则该第二区域不允许除了该第一进程之外的进程随时访问该第二区域。但是,若前述第一进程修改了前第一区域中的内存块管理信息,则其他进程可能被允许访问该第二区域。例如,若第一进程将内存块管理信息中关于访问权限的信息(例如,前文介绍的用于指示进程对该第一内存块的访问权限的信息;又例,如后文将介绍的第一指示信息)进行修改,且修改后的信息可以指示允许其他进程访问该第二区域,则其他进程将可以访问该第二区域。因此,第二进程在读取第一内存块中第一业务数据之前,需要先读取内存块管理信息以确定第一内存块的状态以及何时能够读取该第一内存块中的第一数据。Specifically, when the first process writes the foregoing memory block management information and the first service data into the first memory block, the first process first writes the memory block management information in the foregoing first area, and then Write the first service data in the aforementioned second area. After the first area is written into the aforementioned memory block management information, the first area allows the first process or other processes to access the first area at any time. However, the second area does not allow any process other than writing the memory block management information to access it at any time. That is, if the memory block management information in the first memory block is written by the first process, the second area does not allow processes other than the first process to access the second area at any time. However, if the aforementioned first process modifies the memory block management information in the previous first area, other processes may be allowed to access the second area. For example, if the first process transfers the access authority information in the memory block management information (for example, the information used to indicate the access authority of the process to the first memory block introduced above; for another example, the first memory block will be introduced later. The instruction information) is modified, and the modified information can indicate that other processes are allowed to access the second area, so other processes will be able to access the second area. Therefore, before the second process reads the first service data in the first memory block, it needs to read the memory block management information to determine the status of the first memory block and when it can read the first memory block. data.
202、该第一进程将标识信息发送至第二进程。202. The first process sends identification information to the second process.
其中,该标识信息用于指示该第一内存块的地址。当该第一进程将该标识信息发送至第二进程时,该第二进程可以收到该标识信息,并根据该标识信息确定该第一内存块的地址。也就是说,该第二进程可以根据该标识信息从前述第一内存池中查找到该第一内存块。Wherein, the identification information is used to indicate the address of the first memory block. When the first process sends the identification information to the second process, the second process can receive the identification information and determine the address of the first memory block according to the identification information. That is, the second process can find the first memory block from the aforementioned first memory pool according to the identification information.
示例性的,前述第一内存块的地址指第二进程能够识别的地址,也可以理解为,该第一内存块的地址能使该第二进程通过该标识信息直接或间接地查找到该第一内存块。例如,该第一内存块的地址为该第一内存块映射于第二进程的地址空间中的虚拟地址。又例如,该第一内存块的地址为该第一内存块的物理地址,该第二进程可以根据该物理地址与该第二进程的地址空间的映射关系确定该第一内存块在该第二进程的地址空间中的虚拟地址。Exemplarily, the address of the aforementioned first memory block refers to an address that can be recognized by the second process. It can also be understood that the address of the first memory block enables the second process to directly or indirectly find the first memory block through the identification information. A memory block. For example, the address of the first memory block is a virtual address mapped to the address space of the second process by the first memory block. For another example, the address of the first memory block is the physical address of the first memory block, and the second process may determine that the first memory block is in the second process according to the mapping relationship between the physical address and the address space of the second process. The virtual address in the address space of the process.
示例性的,该第一进程可以通过管道(pipe)或消息队列(message quene)等方式将前述标识信息发送至第二进程。具体此处不做限定。Exemplarily, the first process may send the aforementioned identification information to the second process in a manner such as a pipe or a message queue. The details are not limited here.
示例性的,该标识信息包括第一标识信息和第二标识信息。Exemplarily, the identification information includes first identification information and second identification information.
其中,该第一标识信息与前述第一内存池关联。由于,一个进程可以向内核申请多个内存池,因此,与该第一进程关联的内存池可能有多个,而前述第一内存池是前述多个内存池中的一个。因此,该第一进程需要向第二进程发送指示该第一内存池的第一标识信息,以使得该第二进程可以获知前述第一进程采用哪个内存池与该第二进程进行通信。Wherein, the first identification information is associated with the aforementioned first memory pool. Since one process can apply for multiple memory pools from the kernel, there may be multiple memory pools associated with the first process, and the aforementioned first memory pool is one of the aforementioned multiple memory pools. Therefore, the first process needs to send the first identification information indicating the first memory pool to the second process, so that the second process can learn which memory pool the aforementioned first process uses to communicate with the second process.
此外,该第二标识信息与前述第一内存块关联。由于,一个内存池中一般包括多个内存块,因此,前述第一内存池中也包含多个内存块。因此,该第一进程需要向第二进程发送指示该第一内存块的第二标识信息,以使得该第二进程可以获知前述第一进程是通过前述第一内存池中的第一内存块与该第二进程进行通信的。In addition, the second identification information is associated with the aforementioned first memory block. Since a memory pool generally includes multiple memory blocks, the aforementioned first memory pool also includes multiple memory blocks. Therefore, the first process needs to send the second identification information indicating the first memory block to the second process, so that the second process can learn that the first process passes through the first memory block in the first memory pool and This second process communicates.
进一步地,前述第一标识信息用于指示该第一内存池的首地址。可选的,该第一标识信息,可以是第一进程与第二进程之间约定的用于指示第一内存池的字符(例如,key),也可以是第一内存池的ID,也可以直接是第一内存池的首地址,还可以是其他能够指示第一内存池的首地址的信息。该第二进程在收到前述第一标识信息之后,该第二进程可以根据前述第一标识信息确定该第一内存池的首地址。Further, the aforementioned first identification information is used to indicate the first address of the first memory pool. Optionally, the first identification information may be a character (for example, key) agreed between the first process and the second process to indicate the first memory pool, or the ID of the first memory pool, or It is directly the first address of the first memory pool, or other information that can indicate the first address of the first memory pool. After the second process receives the foregoing first identification information, the second process may determine the first address of the first memory pool according to the foregoing first identification information.
此外,该第二标识信息用于指示该第一内存块在该第一内存池中的地址,也可以理解为,该第一内存块在该第一内存池中的相对地址。可选的,该第二标识信息可以由第一内存池内偏移(lable)(简称,偏移量)表示。该第二进程在收到前述第二标识信息之后,该第二进程可以将该第二标识信息结合前述第一标识信息确定该第一内存块的地址。也就是说,当该第二进程确定该第一内存池的首地址和该第一内存块在该第一内存池中的地址之后,该第二进程可以确定该第一内存块的地址。In addition, the second identification information is used to indicate the address of the first memory block in the first memory pool, which can also be understood as the relative address of the first memory block in the first memory pool. Optionally, the second identification information may be represented by an offset (lable) (abbreviation, offset) in the first memory pool. After the second process receives the foregoing second identification information, the second process may determine the address of the first memory block by combining the second identification information with the foregoing first identification information. That is, after the second process determines the first address of the first memory pool and the address of the first memory block in the first memory pool, the second process can determine the address of the first memory block.
示例性的,当前述标识信息包括第一标识信息和第二标识信息时,该第一进程可以将前述第一标识信息和第二标识信息封装为二元组,采用管道或消息队列等方式发送至第二进程。当然,该第一进程也可以采用其他形式封装前述第一标识信息和第二标识信息,具体此处不做限定。Exemplarily, when the aforementioned identification information includes the first identification information and the second identification information, the first process may encapsulate the aforementioned first identification information and the second identification information into a two-tuple, and send it in a way such as a pipe or a message queue. To the second process. Of course, the first process may also adopt other forms to encapsulate the aforementioned first identification information and second identification information, which is not specifically limited here.
203、第二进程根据该标识信息和该内存块管理信息获取该第一内存块中的该第一业务数据。203. The second process obtains the first service data in the first memory block according to the identification information and the memory block management information.
由于,该内存块管理信息是直接写在第一内存块的第一区域(即第一内存块的头部),因此,该第二进程通过该标识信息查找到该第一内存块之后,该第二进程将先读取该第一区域中的内存块管理信息,并根据该内存块管理信息确定该第二进程对该第一内存块的第二区域的访问权限,以确定该第二进程读取第二区域中的第一业务数据的时机。当前述第一内存块允许该第二进程访问该第一内存块时,该第二进程可以从前述第二区域中读取该第一业务数据。因此,基于前述标识信息和内存块管理信息,该第二进程可以从前述第一内存块中获取到该第一进程写入该第一内存块的第一业务数据。Since the memory block management information is directly written in the first area of the first memory block (that is, the head of the first memory block), after the second process finds the first memory block through the identification information, the The second process will first read the memory block management information in the first area, and determine the access authority of the second process to the second area of the first memory block according to the memory block management information to determine the second process Time to read the first service data in the second area. When the foregoing first memory block allows the second process to access the first memory block, the second process may read the first service data from the foregoing second area. Therefore, based on the foregoing identification information and the memory block management information, the second process can obtain the first service data written by the first process into the first memory block from the foregoing first memory block.
本实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程。于是,该第二进程基于标识信 息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该第二进程可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In this embodiment, because the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the second process can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施例,对前述进程间通信方法进行进一步介绍,具体如图3所示,依然以第一进程和第二进程之间的通信流程为例,该第一进程和该第二进程将执行如下步骤:Based on the foregoing embodiment, the foregoing inter-process communication method is further introduced. As shown in FIG. 3, the communication process between the first process and the second process is still taken as an example. The first process and the second process will execute The following steps:
301、第一进程向内核申请第一共享内存块。301. The first process applies to the kernel for the first shared memory block.
本实施例中,若第一进程需要与其他进程进行通信(例如,本实施例将介绍的第二进程),并且,该第一进程没有可以使用的内存池,则该第一进程将执行本步骤301。In this embodiment, if the first process needs to communicate with other processes (for example, the second process described in this embodiment), and the first process does not have a usable memory pool, the first process will execute this Step 301.
应当理解的是,第一进程没有可以使用的内存池,也可以理解为,已存在的内存池不满足第一进程发送第一数据的需求,具体此处不做限定。It should be understood that the first process does not have a memory pool that can be used, and it can also be understood that the existing memory pool does not meet the requirements of the first process to send the first data, and the specifics are not limited here.
此时,该第一进程可以向内核申请一块共享内存块,为便于介绍,在本实施例以及后续实施例中称这一块共享内存块为第一共享内存块。该第一共享内存块的大小可以由第一进程在向内核申请共享内存时向内核指示,也可以由内核根据系统的运行情况为该第一进程分配,具体此处不做限定。At this time, the first process may apply for a shared memory block from the kernel. For ease of introduction, this shared memory block is referred to as the first shared memory block in this embodiment and subsequent embodiments. The size of the first shared memory block may be indicated to the kernel by the first process when applying for shared memory from the kernel, or may be allocated by the kernel to the first process according to the operating conditions of the system, and the specifics are not limited here.
当该内核为该第一进程分配前述第一共享内存块之后,该第一共享内存块将被映射至第一进程的地址空间和第二进程的地址空间中。After the kernel allocates the aforementioned first shared memory block to the first process, the first shared memory block will be mapped into the address space of the first process and the address space of the second process.
302、该第一进程在该第一共享内存块的头部写入内存池管理信息,得到第一内存池。302. The first process writes memory pool management information at the head of the first shared memory block to obtain the first memory pool.
本实施例中,当为前述第一进程分配了第一共享内存块之后,该第一进程需要对该第一共享内存块进行初始化,也就是说,将该第一共享内存块初始化为满足该第一进程的通信需求的第一内存池。具体地,该第一进程可以在前述第一共享内存块的头部写入内存池管理信息,该内存池管理信息用于将该第一共享内存块划分为多个初始内存块,该多个初始内存块构成前述第一内存池。为便于理解,以图4A为例介绍前述第一内存池的结构。其中,该第一内存池的头部为内存池管理信息,该第一内存池的头部的大小可以按需调整。示例性的,该内存池管理信息包括该第一内存池中初始内存块的大小以及初始内存块的数量等。该第一内存池包括多个初始内存块(例如,内存块1、内存块2、内存块3、内存块4以及内存块5等),其中,每个初始内存块的头部均保留了若干字节用于写入内存块管理信息。示例性的,初始内存块的第一区域用于写入内存块管理信息,初始内存块的第二区域用于写入业务数据。具体地,可以参阅前述步骤201和步骤202中关于第一内存块的第一区域和第一内存块的第二区域的相关介绍,此处不再赘述。In this embodiment, after the first shared memory block is allocated to the aforementioned first process, the first process needs to initialize the first shared memory block, that is, the first shared memory block is initialized to satisfy the The first memory pool for the communication requirements of the first process. Specifically, the first process may write memory pool management information in the header of the aforementioned first shared memory block, where the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple The initial memory block constitutes the aforementioned first memory pool. For ease of understanding, FIG. 4A is taken as an example to introduce the structure of the foregoing first memory pool. Wherein, the header of the first memory pool is memory pool management information, and the size of the header of the first memory pool can be adjusted as needed. Exemplarily, the memory pool management information includes the size of the initial memory block in the first memory pool, the number of initial memory blocks, and the like. The first memory pool includes a plurality of initial memory blocks (for example, memory block 1, memory block 2, memory block 3, memory block 4, memory block 5, etc.), wherein the head of each initial memory block reserves a number of Bytes are used to write memory block management information. Exemplarily, the first area of the initial memory block is used for writing memory block management information, and the second area of the initial memory block is used for writing service data. Specifically, reference may be made to the relevant introductions about the first area of the first memory block and the second area of the first memory block in the foregoing step 201 and step 202, which will not be repeated here.
为便于理解,以图4B为例,物理内存011与第一进程的地址空间111对应,物理内存011与第二进程的地址空间111’对应。当前述第一进程申请到第一共享内存块之后,该第一共享内存块将同时被映射至第一进程的地址空间111和第二进程的地址空间111’中。当该第一进程将前述第一共享内存块初始化为第一内存池012之后,第一内存池012在地址空间111中的虚拟地址为112,第一内存池012在地址空间111’中的虚拟地址为112’。其中,该第一内存池012的头部为内存池管理信息。该第一内存池012中包含多个内存块(例如,内存 块0131和内存块0132)。每个内存块均预留有填写内存块管理信息的第一区域,即每个内存块的头部。以内存块0131为例,该内存块0131在进程A的地址空间111中的虚拟地址113,该内存块0131在进程B的地址空间111’中的虚拟地址113’。该内存块0131的第一区域用于填写内存块管理信息,该内存块0131的第二区域用于填写业务数据。For ease of understanding, taking FIG. 4B as an example, the physical memory 011 corresponds to the address space 111 of the first process, and the physical memory 011 corresponds to the address space 111' of the second process. After the aforementioned first process applies for the first shared memory block, the first shared memory block will be simultaneously mapped into the address space 111 of the first process and the address space 111' of the second process. After the first process initializes the aforementioned first shared memory block as the first memory pool 012, the virtual address of the first memory pool 012 in the address space 111 is 112, and the virtual address of the first memory pool 012 in the address space 111' The address is 112'. Wherein, the header of the first memory pool 012 is memory pool management information. The first memory pool 012 contains multiple memory blocks (for example, memory block 0131 and memory block 0132). Each memory block is reserved with the first area for filling in the management information of the memory block, that is, the head of each memory block. Taking the memory block 0131 as an example, the memory block 0131 is at the virtual address 113 in the address space 111 of the process A, and the memory block 0131 is at the virtual address 113' in the address space 111' of the process B. The first area of the memory block 0131 is used to fill in memory block management information, and the second area of the memory block 0131 is used to fill in business data.
应当理解的是,步骤301和步骤302为可选的步骤。当该第一进程没有可使用的内存池时,该第一进程将执行步骤301和步骤302。当存在多个内存池可供该第一进程选择时,该第一进程可以从多个内存池中选择一个内存池作为第一内存池,并执行步骤303,而不用再执行前述步骤301和步骤302。It should be understood that step 301 and step 302 are optional steps. When the first process has no usable memory pool, the first process will execute step 301 and step 302. When there are multiple memory pools for the first process to choose from, the first process can select a memory pool from the multiple memory pools as the first memory pool, and perform step 303 instead of performing the aforementioned steps 301 and 302.
303、该第一进程在该第一内存池中的第一内存块中写入内存块管理信息和第一业务数据。303. The first process writes memory block management information and first service data in the first memory block in the first memory pool.
其中,该第一内存块可以直接是前述第一内存池中的某一个初始内存块,也可以由前述多个初始内存块合并所得,还可以由前述某一个初始内存块拆分所得。具体前文步骤201中已作详细介绍,此处不再赘述。Wherein, the first memory block may be directly a certain initial memory block in the aforementioned first memory pool, or may be obtained by combining the foregoing multiple initial memory blocks, or may be obtained by splitting a certain initial memory block. The specific step 201 has been introduced in detail in the previous section, and will not be repeated here.
该内存块管理信息为维护该第一内存块的信息。该第一业务数据为该第一进程准备发送给第二进程的数据。由于,该第一进程在初始化第一内存池时,便在每个初始内存块中预留了第一区域用于填写内存块管理信息,因此,该第一进程将该内存块管理信息写入该第一内存块的第一区域,将该第一业务数据写入该第一内存块的第二区域。The memory block management information is information for maintaining the first memory block. The first service data is data that the first process prepares to send to the second process. Since, when the first process initializes the first memory pool, it reserves a first area in each initial memory block for filling in the memory block management information, therefore, the first process writes the memory block management information The first area of the first memory block writes the first service data into the second area of the first memory block.
具体地,该内存块管理信息包括第一指示信息。该第一指示信息用于指示第一进程或其他进程对该第一内存块的第二区域的访问权限,也可以理解为,该第一内存块当前是否允许第一进程或其他进程在该第一内存块的第二区域执行读取或写入操作。Specifically, the memory block management information includes first indication information. The first indication information is used to indicate the access authority of the first process or other processes to the second area of the first memory block. It can also be understood as whether the first memory block currently allows the first process or other processes to be in the first memory block. The second area of a memory block performs read or write operations.
具体地,该第一指示信息可以有如下多种实现方式:Specifically, the first indication information can be implemented in the following multiple ways:
在一种可选的实现方式中,该第一指示信息包括两个值。其中一个值用于指示第一进程禁止访问该第一内存块的第二区域,第二进程允许访问该第二区域;另一个值用于指示第一进程允许访问第一内存块的第二区域,第二进程禁止访问该第二区域。In an optional implementation manner, the first indication information includes two values. One value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area; the other value is used to indicate that the first process is allowed to access the second area of the first memory block , The second process prohibits access to the second area.
示例性的,该第一指示信息包括第一值和第二值。其中,第一值用于指示第一进程禁止访问该第一内存块的第二区域,第二进程允许访问该第二区域;第二值用于指示第一进程允许访问第一内存块的第二区域,第二进程禁止访问该第二区域。Exemplarily, the first indication information includes a first value and a second value. Among them, the first value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area; the second value is used to indicate that the first process is allowed to access the first memory block of the first memory block. In the second area, the second process is prohibited from accessing the second area.
应当理解的是,前述第一值和第二值并非对该第一指示信息的取值进行限定,仅表示前述第一指示信息可以是两个不同的取值。例如,当前述第一指示信息由二进制字符进行表示时,该第一值可以为0时,该第二值可以为1。当然,也可以设置第一值为1、第二值为0;或者,采用两个不同的字符表示前述第一值和第二值。具体此处不做限定。It should be understood that the foregoing first value and second value do not limit the value of the first indication information, and only mean that the foregoing first indication information may have two different values. For example, when the aforementioned first indication information is represented by binary characters, the first value may be 0, and the second value may be 1. Of course, the first value can also be set to 1 and the second value is 0; or, two different characters are used to represent the aforementioned first value and second value. The details are not limited here.
在另一种可选的实现方式中,该第一指示信息包括至少N+1个值,用于实现N个进程通过前述第一内存块进行通信。其中,N为大于1的整数,每个值均对应一个进程。当前述第一指示信息指示N个值中的某一个值时,与该值对应的进程可以访问该第一内存块中的第二区域,而其他进程则不允许访问该第一内存块的第二区域。当前述第一指示信息指示的值与前述N个进程均不对应时,该第一内存块禁止任何进程访问该第二区域。为便于理解,以N等于2为例进行介绍。当N等于2时,可以实现两个进程间的通信。此时,该第一指示信 息可以包括三个值,分别为0,1和2。其中,0表示进程A和进程B均不允许访问该第二区域;1表示进程A允许访问第二区域,进程B不允许访问第二区域;2表示进程A不允许访问第二区域,进程B允许访问第二区域。又例如,当N等于3时,可以实现三个进程间的通信。此时,该第一指示信息可以包括四个值,分别为0,1,2和3。其中,0表示进程A、进程B和进程C均不允许访问该第二区域;1表示进程A允许访问第二区域,进程B和进程C不允许访问第二区域;2表示进程B允许访问第二区域,进程A和进程C不允许访问第二区域;3表示进程C允许访问第二区域,进程A和进程B不允许访问第二区域。依次类推,具体此处不再赘述。In another optional implementation manner, the first indication information includes at least N+1 values, which are used to implement communication between N processes through the foregoing first memory block. Among them, N is an integer greater than 1, and each value corresponds to a process. When the aforementioned first indication information indicates one of the N values, the process corresponding to the value can access the second area in the first memory block, while other processes are not allowed to access the first memory block of the first memory block. Two areas. When the value indicated by the foregoing first indication information does not correspond to the foregoing N processes, the first memory block prohibits any process from accessing the second area. For ease of understanding, take N equal to 2 as an example. When N is equal to 2, the communication between the two processes can be realized. At this time, the first indication information may include three values, which are 0, 1, and 2, respectively. Among them, 0 indicates that neither process A nor process B is allowed to access the second area; 1 indicates that process A is allowed to access the second area, and process B is not allowed to access the second area; 2 indicates that process A is not allowed to access the second area, and process B Allow access to the second area. For another example, when N is equal to 3, communication between three processes can be realized. At this time, the first indication information may include four values, which are 0, 1, 2 and 3 respectively. Among them, 0 means that process A, process B and process C are not allowed to access the second area; 1 means that process A is allowed to access the second area, and process B and process C are not allowed to access the second area; 2 means that process B is allowed to access the second area. In the second area, process A and process C are not allowed to access the second area; 3 means that process C is allowed to access the second area, and process A and process B are not allowed to access the second area. By analogy, the details will not be repeated here.
在这种实施方式中,若前述某一个进程将第一指示信息指示的值设置为与前述N个进程均不对应时,该进程可以触发释放内存块的流程。依然以前述N等于3为例进行介绍,若进程B从前述进程A的第二区域中读取了业务数据,并且,该进程B没有需要向进程A回复数据的需求。此时,该进程B可以将前述第一指示信息的取值设置为0,其中,0表示进程A、进程B和进程C均不允许访问该第二区域。然后,该进程B可以进一步指示释放内存块的流程。例如,后文将介绍的,该进程B可以将该内存块的状态信息由该使用状态调整为该空闲状态,并且,将该内存块从使用链表移动至空闲链表。In this embodiment, if one of the foregoing processes sets the value indicated by the first indication information to not correspond to the foregoing N processes, the process can trigger the process of releasing the memory block. Still taking the foregoing N equal to 3 as an example for introduction, if process B reads business data from the second area of process A, and process B does not need to reply to process A with data. At this time, the process B can set the value of the aforementioned first indication information to 0, where 0 indicates that none of the process A, the process B, and the process C are allowed to access the second area. Then, the process B can further instruct the process of releasing the memory block. For example, as will be introduced later, the process B can adjust the state information of the memory block from the use state to the idle state, and move the memory block from the use linked list to the free linked list.
应当理解的是,在实际应用中,除了上述两种实现方式之外,还可以有其他实现方式,此处不再一一列举。It should be understood that in actual applications, in addition to the above two implementation manners, there may also be other implementation manners, which will not be listed here.
此外,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。其中,使用状态指该第一内存块的第二区域中已被写入业务数据,或者,某一个进程正在向该第一内存块的第一区域写入内存块管理信息。空闲状态指该第一内存块的第二区域是没有被写入业务数据的,并且,也没有进程向该第一内存块的第一区域写入内存块管理信息。若前述第一内存池是由第一进程申请的第一共享内存块初始化而得到的,则该第一进程可以确定该第一内存块的状态为空闲状态,该第一进程可以直接向该第一内存块中写入内存块管理信息和第一业务数据;若第一内存池不是第一进程进行初始化而获得的,而是从众多内存池中选取的,则第一进程需要先根据状态信息确定初始内存块的状态,当该初始内存块为空闲状态时,该初始内存块才有可能作为第一内存块。In addition, the memory block management information also includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state. Wherein, the usage status refers to that service data has been written in the second area of the first memory block, or a certain process is writing memory block management information to the first area of the first memory block. The idle state means that no service data has been written into the second area of the first memory block, and no process writes memory block management information to the first area of the first memory block. If the aforementioned first memory pool is obtained by initializing the first shared memory block requested by the first process, the first process can determine that the state of the first memory block is the idle state, and the first process can directly send the message to the first shared memory block. Write the memory block management information and the first business data into a memory block; if the first memory pool is not obtained by the initialization of the first process, but selected from many memory pools, the first process needs to be based on the status information The state of the initial memory block is determined. When the initial memory block is in an idle state, the initial memory block may be used as the first memory block.
当该第一进程在第一内存块中写入内存块管理信息和第一业务数据时,该第一进程还将该状态信息由该空闲状态调整为该使用状态,并且,将该第一内存块从空闲链表移动至使用链表。于是,当其他进程读取到该状态信息时,可以获知该第一内存块为使用状态。When the first process writes the memory block management information and the first service data in the first memory block, the first process also adjusts the state information from the idle state to the use state, and the first memory The block is moved from the free linked list to the used linked list. Therefore, when other processes read the status information, they can know that the first memory block is in use.
此外,该内存块管理信息还包括第二指示信息。该第二指示信息用于指示第一内存块与其他内存块的连接关系。具体地,该第二指示信息可以包括与第一内存块相邻的内存块的地址。当该第一内存块位于链表的两端时,该第二指示信息包括一个相邻内存块的地址;当该一内存块位于链表的中部时,该第二指示信息包括两个相邻内存块的地址。In addition, the memory block management information also includes second indication information. The second indication information is used to indicate the connection relationship between the first memory block and other memory blocks. Specifically, the second indication information may include the address of a memory block adjacent to the first memory block. When the first memory block is located at both ends of the linked list, the second indication information includes the address of an adjacent memory block; when the one memory block is located in the middle of the linked list, the second indication information includes two adjacent memory blocks the address of.
应当理解的是,该内存块管理信息除了包括前述第一指示信息、状态信息和第二指示信息之外,还可以包括其他关于该第一内存块的信息。具体此处不做限定。It should be understood that, in addition to the foregoing first indication information, status information, and second indication information, the memory block management information may also include other information about the first memory block. The details are not limited here.
304、该第一进程将该第一指示信息设置为第一值。304. The first process sets the first indication information to a first value.
其中,该第一值用于指示该第一进程禁止访问该第一内存块的第二区域,第二进程允许访问该第二区域。由于,第一进程向该第一内存块中写入内存块管理信息和第一业务数据之后,该第一进程才会将前述第一指示信息调整为第一值。因此,该第二进程可以确定前述第一进程已将该第一业务数据写入该第一内存块。Wherein, the first value is used to indicate that the first process is forbidden to access the second area of the first memory block, and the second process is allowed to access the second area. Because, after the first process writes the memory block management information and the first service data into the first memory block, the first process will adjust the aforementioned first indication information to the first value. Therefore, the second process can determine that the aforementioned first process has written the first service data into the first memory block.
应当理解的是,当第一进程执行前述步骤303时,该第一进程在向该第一内存块中写入内存块管理信息时,该第一进程仅定义了第一指示信息,但并未对该第一指示信息赋值。当该第一进程将第一业务数据完全写入该第一内存块之后,该第一进程才将前述第一指示信息设置为第一值。It should be understood that when the first process executes the foregoing step 303, when the first process writes memory block management information to the first memory block, the first process only defines the first indication information, but does not Assign a value to the first indication information. After the first process completely writes the first service data into the first memory block, the first process sets the aforementioned first indication information to the first value.
305、该第一进程将该第一标识信息和该第二标识信息发送至第二进程。305. The first process sends the first identification information and the second identification information to the second process.
其中,该第一标识信息与第一内存池关联,该第一标识信息用于指示该第一内存池的首地址。该第二标识信息与第一内存块关联,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。示例性的,该第一进程可以通过管道或消息队列等方式将前述第一标识信息和第二标识信息发送至第二进程。The first identification information is associated with the first memory pool, and the first identification information is used to indicate the first address of the first memory pool. The second identification information is associated with the first memory block, and the second identification information is used to indicate the address of the first memory block in the first memory pool. Exemplarily, the first process may send the aforementioned first identification information and second identification information to the second process through a pipe, a message queue, or the like.
具体地,可以参阅前述步骤202中的相关介绍,此处不再赘述。Specifically, reference may be made to the related introduction in the foregoing step 202, which will not be repeated here.
本实施例中,当第一进程执行步骤305之后,该第一进程将执行步骤311,该第二进程将执行步骤306。In this embodiment, after the first process executes step 305, the first process will execute step 311, and the second process will execute step 306.
306、该第二进程根据该第一标识信息和该第二标识信息在该第一内存池中查找该第一内存块。306. The second process searches for the first memory block in the first memory pool according to the first identification information and the second identification information.
本实施例中,该第二进程可以根据该第一标识信息确定第一内存池的首地址,并且,根据该第二标识信息确定该第一内存块在该第一内存池中的地址。因此,该第二进程可以通过前述第一标识信息和第二标识信息从前述第一内存池中查找到该第一内存块。也就是说,该第二进程可以在该第二进程的地址空间中查找到前述第一内存块。In this embodiment, the second process may determine the first address of the first memory pool according to the first identification information, and determine the address of the first memory block in the first memory pool according to the second identification information. Therefore, the second process can find the first memory block from the first memory pool through the first identification information and the second identification information. That is, the second process can find the aforementioned first memory block in the address space of the second process.
具体地,可以参阅前述步骤202中的相关介绍,此处不再赘述。Specifically, reference may be made to the related introduction in the foregoing step 202, which will not be repeated here.
307、该第二进程检测内存块管理信息中的第一指示信息。307. The second process detects the first indication information in the memory block management information.
当该第二进程从前第一内存池中查找到该第一内存块时,该第二进程还不能直接读取该第一内存块的第二区域中的数据。该第二进程还需要确定当前是否被允许访问该第一内存块。于是,该第二进程将从该第一内存块的第一区域中读取第一内存块管理信息,并检测该内存块管理信息中的第一指示信息,以确定当前该第一内存块的第二区域是否被允许访问。When the second process finds the first memory block from the previous first memory pool, the second process cannot directly read the data in the second area of the first memory block. The second process also needs to determine whether it is currently allowed to access the first memory block. Then, the second process will read the first memory block management information from the first area of the first memory block, and detect the first indication information in the memory block management information to determine the current value of the first memory block Whether the second area is allowed to visit.
当该第二进程检测到该第一指示信息为第一值时,该第二进程执行步骤308。When the second process detects that the first indication information is the first value, the second process executes step 308.
当该第二进程检测到该第一指示信息为并非为第一值时,该第二进程将在预设时间段之后再次检测该第一指示信息。示例性的,该第二进程可以启动计时器,当计时器达到预设值之后,该第二进程再次检测该第一指示信息。When the second process detects that the first indication information is not the first value, the second process will detect the first indication information again after a preset period of time. Exemplarily, the second process may start a timer, and when the timer reaches a preset value, the second process detects the first indication information again.
308、该第二进程从该第一内存块的第二区域中读取该第一业务数据。308. The second process reads the first service data from the second area of the first memory block.
当该第二进程检测到该第一指示信息为该第一值时,该第二进程从该第一内存块的第二区域中读取该第一业务数据。When the second process detects that the first indication information is the first value, the second process reads the first service data from the second area of the first memory block.
本实施例中,由于,第一进程将维护第一内存块的内存块管理信息写入第一内存块的第一区域中,并将第一标识信息和第二标识信息发送至第二进程。于是,该第二进程基于第一标识信息和第二标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息中的第一指示信息确定可以从该第一内存块的第二区域中读取第一业务数据的时机。在此过程中,不需要除第一进程和第二进程之外的程序介入,该第一进程与第二进程之间可以直接进行通信。因此,可以提高第一进程与第二进程之间的通信效率。In this embodiment, because the first process writes the memory block management information for maintaining the first memory block into the first area of the first memory block, and sends the first identification information and the second identification information to the second process. Therefore, the second process finds the first memory block in the first memory pool based on the first identification information and the second identification information, and determines that the first memory block can be obtained from the first memory block based on the first indication information in the memory block management information The timing of reading the first business data in the second area. In this process, no program other than the first process and the second process is required to intervene, and the first process and the second process can directly communicate with each other. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施例,在第一内存块被释放之前,若第二进程需要向第一进程回复数据,或者,该第二进程恰好有数据需要传输给该第一进程。则该第二进程将执行步骤309至步骤310,该第一进程将执行步骤311至步骤312。Based on the foregoing embodiment, before the first memory block is released, if the second process needs to reply data to the first process, or the second process happens to have data that needs to be transmitted to the first process. Then the second process will execute step 309 to step 310, and the first process will execute step 311 to step 312.
309、该第二进程在该第一内存块的第二区域中写入第二业务数据。309. The second process writes second service data in the second area of the first memory block.
本实施例中,由于,该第二进程已从前述第一内存块中读取了第一业务数据,因此,该第一内存块对于该第二进程为允许访问的状态。因此,该第二进程可以将需要传输给第一进程的第二业务数据写入该第一内存块的第二区域中。In this embodiment, since the second process has read the first service data from the aforementioned first memory block, the first memory block is in a state that allows access to the second process. Therefore, the second process can write the second service data that needs to be transmitted to the first process into the second area of the first memory block.
310、该第二进程将该第一指示信息调整为第二值。310. The second process adjusts the first indication information to a second value.
其中,该第二值用于指示第一进程允许访问第一内存块的第二区域,第二进程禁止访问该第二区域。由于,第二进程向该第一内存块的第二区域中写入第二业务数据之后,该第二进程才会将前述第一指示信息调整为第二值。因此,该第一进程可以确定前述第二进程已将该第二业务数据写入该第一内存块的第二区域。Wherein, the second value is used to indicate that the first process is allowed to access the second area of the first memory block, and the second process is forbidden to access the second area. Because, after the second process writes the second service data into the second area of the first memory block, the second process will adjust the aforementioned first indication information to the second value. Therefore, the first process can determine that the aforementioned second process has written the second service data into the second area of the first memory block.
应当理解的是,由于第一进程在执行步骤303时已经定义了第一指示信息。因此,本步骤310中,该第二进程仅需要调整该第一指示信息赋值,即将前述第一指示信息设置为第二值。It should be understood that the first process has already defined the first indication information when step 303 is executed. Therefore, in this step 310, the second process only needs to adjust the value of the first indication information, that is, set the aforementioned first indication information to the second value.
311、该第一进程检测内存块管理信息中的第一指示信息。311. The first process detects the first indication information in the memory block management information.
应当理解的是,当第一进程执行步骤305之后,该第一进程将执行步骤311。也就是说,当第一进程将向第二进程发送该第一标识信息和该第二标识信息之后,该第一进程将检测该第一指示信息,以确定该第二进程是否会向该第一进程传输数据。It should be understood that after the first process executes step 305, the first process will execute step 311. That is, after the first process will send the first identification information and the second identification information to the second process, the first process will detect the first indication information to determine whether the second process will send the first indication information to the second process. A process transfers data.
当该第一进程检测到该第一指示信息为第二值时,该第一进程执行步骤312。When the first process detects that the first indication information is the second value, the first process executes step 312.
当该第一进程检测到该第一指示信息为第一值时,该第一进程将在预设时间段之后再次检测该第一指示信息。示例性的,该第一进程可以启动计时器,当计时器达到预设值之后,该第一进程再次检测该第一指示信息。When the first process detects that the first indication information is the first value, the first process will detect the first indication information again after a preset period of time. Exemplarily, the first process may start a timer, and when the timer reaches a preset value, the first process detects the first indication information again.
312、该第一进程从该第一内存块的第二区域中获取第二业务数据。312. The first process obtains second service data from a second area of the first memory block.
本实施例中,当该第一进程检测到该第一指示信息为第二值时,则说明该第二进程对该内存块管理信息中的第一指示信息进行了修改,该第一进程可以推断该第二进程有第二业务数据需要传输给第一进程,并且,该第二进程已将该第二业务数据写入该第一内存块的第二区域中。此时,该第一进程可以从该第一内存块的第二区域中获取该第二业务数据。In this embodiment, when the first process detects that the first indication information is the second value, it means that the second process modifies the first indication information in the memory block management information, and the first process can It is inferred that the second process has second service data that needs to be transmitted to the first process, and the second process has written the second service data into the second area of the first memory block. At this time, the first process may obtain the second service data from the second area of the first memory block.
应当理解的是,由于该第一进程已知第一内存块的地址,并且能够检测该第一指示信息,因此,该第一进程可以从该前述第一内存块的第二区域中读取第二业务数据,而不需 要采用第一标识信息查找第一内存池,也不需要采用第二标识信息从第一内存池中查找第一内存块。在这样的实施方式中,节省了第一进程查找第一内存块的地址的过程,有利于提高第一进程与第二进程之间的通信效率。It should be understood that, because the first process knows the address of the first memory block and can detect the first indication information, the first process can read the first memory block from the second area of the aforementioned first memory block. 2. Business data, without using the first identification information to find the first memory pool, nor using the second identification information to find the first memory block from the first memory pool. In such an implementation manner, the process of searching for the address of the first memory block by the first process is saved, which is beneficial to improve the communication efficiency between the first process and the second process.
本实施例中,当该第一进程执行了步骤312之后,若该第一进程还需要向第二进程传输数据时,则该第一进程将再次向该第一内存块的第二区域中写入需要发送给第二进程的数据(例如,第三业务数据),具体与前述步骤303至步骤305类似,此处不再赘述。应当注意的是,在执行与前述步骤303类似的步骤时,即该第一进程再次利用该第一内存块传输数据时,该第一进程仅需要修改一部分内存块管理信息并写入前述第三业务数据即可,无需重新向该第一内存块的头部写入所有的内存块管理信息。例如,仅需要修改第一指示信息的取值,而无需重新设置一个新的指示信息。类似的,该第二进程也将再次从前述第一内存块中读取内存块指示信息和业务数据,具体与前述步骤306至308,此处不再赘述。In this embodiment, after the first process executes step 312, if the first process still needs to transmit data to the second process, the first process will write to the second area of the first memory block again Incoming data that needs to be sent to the second process (for example, third service data) is specifically similar to the foregoing step 303 to step 305, and will not be repeated here. It should be noted that when performing steps similar to the foregoing step 303, that is, when the first process uses the first memory block to transfer data again, the first process only needs to modify a part of the memory block management information and write it into the foregoing third memory block. The business data is sufficient, and there is no need to rewrite all the memory block management information to the head of the first memory block. For example, only the value of the first indication information needs to be modified, without resetting a new indication information. Similarly, the second process will again read the memory block indication information and service data from the aforementioned first memory block, which are specifically the same as the aforementioned steps 306 to 308, and will not be repeated here.
本实施方式中,第二进程在读取第一业务数据的第一内存块中写入了第二业务数据,此时,第一进程检测该第一指示信息以确定该第二进程是否向该第一进程回复了业务数据。在此过程中,该第二进程无需重新从前述第一内存池中找内存块以写入第二业务数据,而是直接利用该第一内存块与该第一进程通信,节省了第二进程查找其他内存块来与第一进程进行通信的流程。因此,可以提高第一进程与第二进程之间的通信效率。In this embodiment, the second process writes the second service data in the first memory block that reads the first service data. At this time, the first process detects the first indication information to determine whether the second process sends the data to the The first process replies with business data. In this process, the second process does not need to find a memory block from the aforementioned first memory pool to write the second service data, but directly uses the first memory block to communicate with the first process, saving the second process The process of finding other memory blocks to communicate with the first process. Therefore, the communication efficiency between the first process and the second process can be improved.
基于前述实施例,当第一进程与第二进程之间不需要再传输业务数据时,可以由该第一进程或第二进程中的任意一方发起释放前述第一内存块。Based on the foregoing embodiment, when there is no need to transmit service data between the first process and the second process, any one of the first process or the second process can initiate the release of the foregoing first memory block.
在一种可选的实施方式中,前述第一进程可以释放该第一内存块。例如,当该第一进程执行了步骤312之后,该第一进程可以将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。于是,该第一进程可以完成释放该第一内存块。In an optional implementation manner, the aforementioned first process may release the first memory block. For example, after the first process executes step 312, the first process may adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the linked list to Free linked list. Then, the first process can finish releasing the first memory block.
在另一种可选的实施方式中,前述第二进程可以释放该第一内存块。例如,当该第二进程执行了步骤308之后,该第二进程将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。In another optional implementation manner, the foregoing second process may release the first memory block. For example, after the second process performs step 308, the second process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the linked list of use to the idle state. Linked list.
在这样的实施方式中,由于,在释放该第一内存块之前,前述第一进程和第二进程均可以查看到该第一内存块头部的状态信息。因此,当其中一个进程修改状态信息时,另一个进程可以获知对方进行无需再传输业务数据。相比于现有技术中需要两个进程均向处理器发出释放指示的方案,前述实施方式更加简洁高效。In such an implementation, because, before releasing the first memory block, both the aforementioned first process and the second process can view the state information of the header of the first memory block. Therefore, when one process modifies the status information, the other process can learn that the other process does not need to transmit service data. Compared with the solution in the prior art that requires both processes to issue release instructions to the processor, the foregoing implementation manner is more concise and efficient.
下面将对前述实施例中的进程间通信装置的结构进行介绍:The structure of the inter-process communication device in the foregoing embodiment will be introduced below:
如图5所示,本实施例提供的一种进程间通信装置50的结构示意图。该进程间通信装置50运行第一进程以实现前述图2和图3对应的方法实施例中的第一进程的功能。As shown in FIG. 5, a schematic structural diagram of an inter-process communication device 50 provided in this embodiment. The inter-process communication device 50 runs the first process to realize the function of the first process in the foregoing method embodiments corresponding to FIG. 2 and FIG. 3.
该进程间通信装置50包括:The inter-process communication device 50 includes:
写入模块501,用于在第一内存块中写入内存块管理信息和第一业务数据,该第一内存块位于第一内存池中,该内存块管理信息为维护该第一内存块的信息。The writing module 501 is configured to write memory block management information and first business data in a first memory block, where the first memory block is located in the first memory pool, and the memory block management information is for maintaining the first memory block information.
发送模块502,用于将标识信息发送至第二进程,以使得该第二进程根据该标识信息和该内存块管理信息获取该第一内存块中的该第一业务数据,该标识信息用于指示该第一内存块的地址。The sending module 502 is configured to send identification information to a second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, and the identification information is used for Indicates the address of the first memory block.
其中,该标识信息包括第一标识信息和第二标识信息,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。该第一内存块包括第一区域和第二区域。该第一区域用于记录该内存块管理信息,该第一区域允许该第一进程或该第二进程随时访问。该第二区域用于记录该第一业务数据,该第二区域不允许该第一进程和该第二进程随时访问。Wherein, the identification information includes first identification information and second identification information, the first identification information is used to indicate the first address of the first memory pool, and the second identification information is used to indicate that the first memory block is located in the first memory pool. The address in the memory pool. The first memory block includes a first area and a second area. The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time. The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
本实施例中,由于,运行第一进程的进程间通信装置50将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至第二进程(即后文图6对应的实施例中的运行第二进程的进程间通信装置60)。于是,该进程间通信装置60基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该进程间通信装置60可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In this embodiment, because the inter-process communication device 50 running the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block To the second process (that is, the inter-process communication device 60 running the second process in the embodiment corresponding to FIG. 6 hereinafter). Therefore, the inter-process communication device 60 finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the inter-process communication device 60 can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
在一种可选的实施方式中,该进程间通信装置50还包括:In an optional implementation manner, the inter-process communication device 50 further includes:
该写入模块501,还用于在该第一共享内存块的第一区域写入内存池管理信息,得到第一内存池。其中,该内存池管理信息用于将该第一共享内存块划分为多个初始内存块,该多个初始内存块构成该第一内存池。The writing module 501 is also configured to write memory pool management information in the first area of the first shared memory block to obtain the first memory pool. Wherein, the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple initial memory blocks constitute the first memory pool.
在另一种可选的实施方式中,该内存块管理信息包括第一指示信息。In another optional implementation manner, the memory block management information includes first indication information.
该进程间通信装置50还包括获取模块503。该获取模块503,用于当检测到该第一指示信息为第二值时从该第一内存块的第二区域获取第二业务数据,该第二值用于指示第一进程允许访问该第二区域且第二进程禁止访问该第二区域。The inter-process communication device 50 also includes an acquisition module 503. The acquiring module 503 is configured to acquire second service data from the second area of the first memory block when it is detected that the first indication information is a second value, and the second value is used to instruct the first process to allow access to the first memory block. The second area and the second process is forbidden to access the second area.
在另一种可选的实施方式中,该进程间通信装置50还包括指示信息调整模块504。该指示信息调整模块504,用于将该第一指示信息设置为第一值,第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。In another optional implementation manner, the inter-process communication device 50 further includes an indication information adjustment module 504. The instruction information adjustment module 504 is configured to set the first instruction information to a first value. The first value is used to indicate that the first process is forbidden to access the second area of the first memory block and that the second process is allowed to access the second area of the first memory block. The second area.
在另一种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。该进程间通信装置50还包括状态信息调整模块505。该状态信息调整模块505,用于将该状态信息由该空闲状态调整为该使用状态,并且,将该第一内存块从空闲链表移动至使用链表。该状态信息调整模块505,还用于将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。In another optional implementation manner, the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state. The inter-process communication device 50 also includes a state information adjustment module 505. The state information adjustment module 505 is configured to adjust the state information from the idle state to the used state, and move the first memory block from the idle linked list to the used linked list. The state information adjustment module 505 is further configured to adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the use linked list to the free linked list.
如图6所示,本实施例提供的一种进程间通信装置60的结构示意图。该进程间通信装置60运行第二进程以实现前述图2和图3对应的方法实施例中的第二进程的功能。As shown in FIG. 6, a schematic structural diagram of an inter-process communication device 60 provided in this embodiment. The inter-process communication device 60 runs the second process to realize the function of the second process in the foregoing method embodiments corresponding to FIG. 2 and FIG. 3.
该进程间通信装置60包括:The inter-process communication device 60 includes:
接收模块601,用于接收第一进程发送的标识信息,该标识信息用于指示第一内存块的地址,该第一内存块位于第一内存池中,该第一内存块中包含该第一进程写入的第一业务数据和内存块管理信息,该内存块管理信息为维护该第一内存块的信息。The receiving module 601 is configured to receive identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains the first memory block. The first service data and memory block management information written by the process, where the memory block management information is information for maintaining the first memory block.
读取模块602,用于根据该标识信息和该内存块管理信息从该第一内存块中读取该第一业务数据。The reading module 602 is configured to read the first service data from the first memory block according to the identification information and the memory block management information.
其中,该标识信息包括第一标识信息和第二标识信息,该第一标识信息用于指示该第一内存池的首地址,该第二标识信息用于指示该第一内存块在该第一内存池中的地址。该第一内存块包括第一区域和第二区域。该第一区域用于记录该内存块管理信息,该第一区域允许该第一进程或该第二进程随时访问。该第二区域用于记录该第一业务数据,该第二区域不允许该第一进程和该第二进程随时访问。Wherein, the identification information includes first identification information and second identification information, the first identification information is used to indicate the first address of the first memory pool, and the second identification information is used to indicate that the first memory block is located in the first memory pool. The address in the memory pool. The first memory block includes a first area and a second area. The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time. The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
本实施例中,由于,运行第一进程的进程间通信装置50将维护第一内存块的内存块管理信息写入第一内存块中,并将用于确定第一内存块地址的标识信息发送至运行第二进程的进程间通信装置60。于是,该进程间通信装置60基于标识信息在该第一内存池中找到该第一内存块,基于该内存块管理信息确定读取该第一业务数据的时机。于是,该进程间通信装置60可以在没有第三方程序介入的情况下读取该第一内存块中的第一业务数据,以实现该第一进程与第二进程之间的通信。因此,可以提高第一进程与第二进程之间的通信效率。In this embodiment, because the inter-process communication device 50 running the first process writes the memory block management information for maintaining the first memory block into the first memory block, and sends identification information for determining the address of the first memory block To the inter-process communication device 60 running the second process. Therefore, the inter-process communication device 60 finds the first memory block in the first memory pool based on the identification information, and determines the time to read the first service data based on the memory block management information. Therefore, the inter-process communication device 60 can read the first service data in the first memory block without the intervention of a third-party program, so as to realize the communication between the first process and the second process. Therefore, the communication efficiency between the first process and the second process can be improved.
在一种可选的实施方式中,该内存块管理信息包括第一指示信息。In an optional implementation manner, the memory block management information includes first indication information.
该进程间通信装置60还包括:The inter-process communication device 60 also includes:
写入模块603,用于在该第一内存块的第二区域中写入第二业务数据;The writing module 603 is configured to write second service data in the second area of the first memory block;
指示信息调整模块604,并将该第一指示信息调整为第二值,该第二值用于指示第一进程允许访问该第二区域且第二进程禁止访问该第二区域。The instruction information adjustment module 604 is adjusted to adjust the first instruction information to a second value, and the second value is used to indicate that the first process is allowed to access the second area and the second process is prohibited from accessing the second area.
在一另种可选的实施方式中,该读取模块602包括:查找单元,用于根据该第一标识信息和该第二标识信息在该第一内存池中查找该第一内存块。读取单元,用于当检测到该第一指示信息为该第一值时从该第一内存块的第二区域读取该第一业务数据,第一值用于指示该第一进程禁止访问该第一内存块的第二区域且该第二进程允许访问该第二区域。In an alternative embodiment, the reading module 602 includes: a searching unit configured to search for the first memory block in the first memory pool according to the first identification information and the second identification information. The reading unit is configured to read the first service data from the second area of the first memory block when it is detected that the first indication information is the first value, and the first value is used to indicate that the first process prohibits access The second area of the first memory block and the second process allows access to the second area.
在一另种可选的实施方式中,该内存块管理信息还包括状态信息,该状态信息用于指示该第一内存块处于空闲状态或使用状态。该进程间通信装置60还包括:In an alternative embodiment, the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state. The inter-process communication device 60 also includes:
状态信息调整模块605,用于将该第一内存块的状态信息由该使用状态调整为该空闲状态,并且,将该第一内存块从使用链表移动至空闲链表。The state information adjustment module 605 is configured to adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the use linked list to the free linked list.
如图7所示,本实施例提供的一种设备70的结构示意图。该设备70可以是普通计算机或大型服务器,也可以其他带有处理器的设备。As shown in FIG. 7, a schematic structural diagram of a device 70 provided in this embodiment. The device 70 can be an ordinary computer or a large-scale server, or other devices with a processor.
该设备70中包括运行第一进程的进程间通信装置7011和运行第二进程的进程间通信装置7012。其中,进程间通信装置7011的具体结构可以参阅前述图5,该进程间通信装置7012的具体结构可以参阅前述图6。The device 70 includes an inter-process communication device 7011 running a first process and an inter-process communication device 7012 running a second process. For the specific structure of the inter-process communication device 7011, please refer to the foregoing FIG. 5, and the specific structure of the inter-process communication device 7012 may refer to the foregoing FIG. 6.
可选的,进程间通信装置7011和进程间通信装置7012均位于处理器701中。应当理解的是,一个处理器701中可以运行多个进程间通信装置。在本申请实施例中,该处理器701至少包括两个进程间通信装置,这两个进程间通信装置分别运行前述第一进程和第二进程前述。其中,该进程间通信装置7011和进程间通信装置7012之间可以采用管道或消息队列等方式相互传输较少的数据。Optionally, the inter-process communication device 7011 and the inter-process communication device 7012 are both located in the processor 701. It should be understood that one processor 701 may run multiple inter-process communication devices. In the embodiment of the present application, the processor 701 includes at least two inter-process communication devices, and the two inter-process communication devices respectively run the aforementioned first process and the aforementioned second process. Among them, the inter-process communication device 7011 and the inter-process communication device 7012 can transmit less data to each other in a manner such as a pipe or a message queue.
其中,该处理器701可以是通用中央处理器(central processing unit,CPU)或微处理器(micro processor)。该处理器701可以是单核处理器(single-CPU),也可以是多核处理器(multi-CPU)。此外,该处理器701可以指一个或多个装置、电路、和/或用于处理数据(例如计算机程序指令)的处理核。可选的,该处理器701还可以包括一个用于为进程间通信装置7011和进程间通信装置7012分配共享内存的内核(图未示)。进程间通信装置7011和进程间通信装置7012位于该内核之外。可选的,为进程间通信装置7011和进程间通信装置7012分配共享内存的功能也可以由该处理器701实现,具体此处不做限定。Wherein, the processor 701 may be a general-purpose central processing unit (central processing unit, CPU) or a microprocessor (microprocessor). The processor 701 may be a single-core processor (single-CPU) or a multi-core processor (multi-CPU). In addition, the processor 701 may refer to one or more devices, circuits, and/or processing cores for processing data (for example, computer program instructions). Optionally, the processor 701 may also include a kernel (not shown) for allocating shared memory for the inter-process communication device 7011 and the inter-process communication device 7012. The inter-process communication device 7011 and the inter-process communication device 7012 are located outside the kernel. Optionally, the function of allocating shared memory for the inter-process communication device 7011 and the inter-process communication device 7012 may also be implemented by the processor 701, which is not specifically limited here.
此外,该前述进程间通信装置7011和进程间通信装置7012与至少一个存储器702和至少一个存储介质703相连,该存储介质703存储有第一进程对应的程序和第二进程对应的程序。更进一步地,进程间通信装置7011和进程间通信装置7012可以设置为与存储介质703通信,进程间通信装置7011执行存储介质703中的与第一进程对应的程序以运行第一进程,进程间通信装置7012执行存储介质703中的与第二进程对应的程序以运行第二进程。In addition, the aforementioned inter-process communication device 7011 and inter-process communication device 7012 are connected to at least one memory 702 and at least one storage medium 703, and the storage medium 703 stores a program corresponding to the first process and a program corresponding to the second process. Furthermore, the inter-process communication device 7011 and the inter-process communication device 7012 may be configured to communicate with the storage medium 703, and the inter-process communication device 7011 executes the program corresponding to the first process in the storage medium 703 to run the first process. The communication device 7012 executes the program corresponding to the second process in the storage medium 703 to run the second process.
可选的,该处理器701还包括存储器管理单元(memory management unit,MMU),该存储器管理单元有时也被称作为分页内存管理单元(paged memory management unit,PMMU)。该MMU位于连接高速缓存(图未示)以及存储器702的总线之间,是一种负责处理CPU的内存访问请求的计算机硬件。该MMU用于实现物理地址到虚拟地址之间的转换。例如,将第一内存池的物理地址映射到第一进程的地址空间,以使得该第一进程通过该地址空间中的虚拟地址可以查找到该第一内存池,进而可以使该第一进程通过偏移量可以查找到第一内存块。此外,该MMU具有少量存储空间存放从虚拟地址到物理地址的匹配表,该匹配表也被称作页表或转换旁置缓冲区(translation lookaside buffer,TLB),该匹配表记录有物理地址与虚拟地址之间的映射关系,也就是说,该匹配表的每一项对应于一个虚拟地址到物理地址的映射。可选的,该匹配表的表项除完成虚拟地址到物理地址的映射功能之外,还定义了访问权限和缓冲特性等,具体此处不做限定。Optionally, the processor 701 further includes a memory management unit (MMU), and the memory management unit is sometimes referred to as a paged memory management unit (PMMU). The MMU is located between the bus connecting the cache (not shown) and the memory 702, and is a kind of computer hardware responsible for processing the memory access request of the CPU. The MMU is used to implement the conversion between physical addresses and virtual addresses. For example, the physical address of the first memory pool is mapped to the address space of the first process, so that the first process can find the first memory pool through the virtual address in the address space, and then the first process can pass through The offset can be found to the first memory block. In addition, the MMU has a small amount of storage space to store a matching table from virtual addresses to physical addresses. The matching table is also called a page table or translation lookaside buffer (translation lookaside buffer, TLB). The matching table records the physical address and The mapping relationship between virtual addresses, that is, each item in the matching table corresponds to a mapping from a virtual address to a physical address. Optionally, in addition to completing the function of mapping virtual addresses to physical addresses, the entries of the matching table also define access permissions and buffer characteristics, which are not specifically limited here.
为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。For the convenience and conciseness of the description, the specific working process of the above-described system, device, and unit may refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。The above embodiments are only used to illustrate the technical solutions of the application, not to limit them; although the application has been described in detail with reference to the foregoing embodiments, a person of ordinary skill in the art should understand that: The recorded technical solutions are modified, or some of the technical features are equivalently replaced; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims (32)

  1. 一种进程间通信方法,其特征在于,包括:An inter-process communication method, characterized in that it comprises:
    第一进程在第一内存块中写入内存块管理信息和第一业务数据,所述第一内存块位于第一内存池中,所述内存块管理信息为维护所述第一内存块的信息;The first process writes memory block management information and first service data in a first memory block, the first memory block is located in the first memory pool, and the memory block management information is information for maintaining the first memory block ;
    所述第一进程将标识信息发送至第二进程,以使得所述第二进程根据所述标识信息和所述内存块管理信息获取所述第一内存块中的所述第一业务数据,所述标识信息用于指示所述第一内存块的地址。The first process sends identification information to the second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, so The identification information is used to indicate the address of the first memory block.
  2. 根据权利要求1所述的方法,其特征在于,所述标识信息包括第一标识信息和第二标识信息,所述第一标识信息用于指示所述第一内存池的首地址,所述第二标识信息用于指示所述第一内存块在所述第一内存池中的地址。The method according to claim 1, wherein the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, and the first identification information The second identification information is used to indicate the address of the first memory block in the first memory pool.
  3. 根据权利要求1或2所述的方法,其特征在于,所述第一内存块包括第一区域和第二区域;The method according to claim 1 or 2, wherein the first memory block includes a first area and a second area;
    所述第一区域用于记录所述内存块管理信息,所述第一区域允许所述第一进程或所述第二进程随时访问;The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time;
    所述第二区域用于记录所述第一业务数据,所述第二区域不允许所述第一进程和所述第二进程随时访问。The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  4. 根据权利要求3所述的方法,其特征在于,所述内存块管理信息包括第一指示信息;The method according to claim 3, wherein the memory block management information includes first indication information;
    所述第一进程将标识信息发送至第二进程之后,所述方法还包括:After the first process sends the identification information to the second process, the method further includes:
    当所述第一进程检测到所述第一指示信息为第二值时,所述第一进程从所述第一内存块的第二区域获取第二业务数据,所述第二值用于指示所述第一进程允许访问所述第二区域且所述第二进程禁止访问所述第二区域。When the first process detects that the first indication information is the second value, the first process obtains second service data from the second area of the first memory block, and the second value is used to indicate The first process allows access to the second area and the second process prohibits access to the second area.
  5. 根据权利要求3所述的方法,其特征在于,所述第一进程在第一内存块中写入所述内存块管理信息和所述第一业务数据之后,所述第一进程将标识信息发送至第二进程之前,所述方法还包括:The method according to claim 3, wherein after the first process writes the memory block management information and the first service data in the first memory block, the first process sends identification information Before the second process, the method further includes:
    所述第一进程将所述第一指示信息设置为第一值,所述第一值用于指示所述第一进程禁止访问所述第一内存块的第二区域且所述第二进程允许访问所述第二区域。The first process sets the first indication information to a first value, and the first value is used to indicate that the first process prohibits access to the second area of the first memory block and the second process allows Visit the second area.
  6. 根据权利要求1至5中任意一项所述的方法,其特征在于,所述内存块管理信息还包括状态信息,所述状态信息用于指示所述第一内存块处于空闲状态或使用状态;The method according to any one of claims 1 to 5, wherein the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state;
    所述第一进程在第一内存块中写入内存块管理信息和第一业务数据时,所述方法还包括:When the first process writes the memory block management information and the first service data in the first memory block, the method further includes:
    所述第一进程将所述状态信息由所述空闲状态调整为所述使用状态,并且,将所述第一内存块从空闲链表移动至使用链表。The first process adjusts the state information from the idle state to the use state, and moves the first memory block from the idle linked list to the used linked list.
  7. 根据权利要求6所述的方法,其特征在于,所述第一进程从所述第一内存块的第二区域获取第二业务数据之后,所述方法还包括:The method according to claim 6, wherein after the first process obtains the second service data from the second area of the first memory block, the method further comprises:
    所述第一进程将所述第一内存块的状态信息由所述使用状态调整为所述空闲状态,并且,将所述第一内存块从使用链表移动至空闲链表。The first process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the use linked list to the free linked list.
  8. 根据权利要求1至7中任意一项所述的方法,其特征在于,所述第一进程在第一内存块中写入内存块管理信息和第一业务数据之前,所述方法还包括:The method according to any one of claims 1 to 7, wherein before the first process writes the memory block management information and the first service data in the first memory block, the method further comprises:
    所述第一进程向内核申请第一共享内存块;The first process applies to the kernel for the first shared memory block;
    所述第一进程在所述第一共享内存块的头部写入内存池管理信息,所述内存池管理信息用于将所述第一共享内存块划分为多个初始内存块,所述多个初始内存块构成所述第一内存池。The first process writes memory pool management information at the head of the first shared memory block, where the memory pool management information is used to divide the first shared memory block into multiple initial memory blocks, and the multiple Initial memory blocks constitute the first memory pool.
  9. 一种进程间通信方法,其特征在于,包括:An inter-process communication method, characterized in that it comprises:
    第二进程接收第一进程发送的标识信息,所述标识信息用于指示第一内存块的地址,所述第一内存块位于第一内存池中,所述第一内存块中包含所述第一进程写入的第一业务数据和内存块管理信息,所述内存块管理信息为维护所述第一内存块的信息;The second process receives the identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains the first memory block. First service data and memory block management information written by a process, where the memory block management information is information for maintaining the first memory block;
    所述第二进程根据所述标识信息和所述内存块管理信息从所述第一内存块中读取所述第一业务数据。The second process reads the first service data from the first memory block according to the identification information and the memory block management information.
  10. 根据权利要求9所述的方法,其特征在于,所述标识信息包括第一标识信息和第二标识信息,所述第一标识信息用于指示所述第一内存池的首地址,所述第二标识信息用于指示所述第一内存块在所述第一内存池中的地址。The method according to claim 9, wherein the identification information includes first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, and the first identification information is used to indicate the first address of the first memory pool. The second identification information is used to indicate the address of the first memory block in the first memory pool.
  11. 根据权利要求9或10所述的方法,其特征在于,所述第一内存块包括第一区域和第二区域;The method according to claim 9 or 10, wherein the first memory block includes a first area and a second area;
    所述第一区域用于记录所述内存块管理信息,所述第一区域允许所述第一进程或所述第二进程随时访问;The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time;
    所述第二区域用于记录所述第一业务数据,所述第二区域不允许所述第一进程和所述第二进程随时访问。The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  12. 根据权利要求11所述的方法,其特征在于,所述内存块管理信息包括第一指示信息;The method according to claim 11, wherein the memory block management information includes first indication information;
    所述第二进程根据所述标识信息和所述内存块管理信息从所述第一内存块中读取所述第一业务数据之后,所述方法还包括:After the second process reads the first service data from the first memory block according to the identification information and the memory block management information, the method further includes:
    所述第二进程在所述第一内存块的第二区域写入第二业务数据,并将所述第一指示信息调整为第二值,所述第二值用于指示所述第一进程允许访问所述第二区域且所述第二进程禁止访问所述第二区域。The second process writes second service data in the second area of the first memory block, and adjusts the first indication information to a second value, where the second value is used to indicate the first process Access to the second area is allowed and the second process prohibits access to the second area.
  13. 根据权利要求11所述的方法,其特征在于,所述第二进程根据所述标识信息和所述内存块管理信息从所述第一内存块中读取所述第一业务数据,包括:The method according to claim 11, wherein the second process reading the first service data from the first memory block according to the identification information and the memory block management information comprises:
    所述第二进程根据所述第一标识信息和所述第二标识信息在所述第一内存池中查找所述第一内存块;The second process searches for the first memory block in the first memory pool according to the first identification information and the second identification information;
    当所述第二进程检测到所述第一指示信息为所述第一值时,所述第二进程从所述第一内存块的第二区域中读取所述第一业务数据,所述第一值用于指示所述第一进程禁止访问所述第一内存块的第二区域且所述第二进程允许访问所述第二区域。When the second process detects that the first indication information is the first value, the second process reads the first service data from the second area of the first memory block, and The first value is used to indicate that the first process prohibits access to the second area of the first memory block and the second process allows access to the second area.
  14. 根据权利要求9至13中任意一项所述的方法,其特征在于,所述内存块管理信息还包括状态信息,所述状态信息用于指示所述第一内存块处于空闲状态或使用状态;The method according to any one of claims 9 to 13, wherein the memory block management information further includes status information, and the status information is used to indicate that the first memory block is in an idle state or in a use state;
    所述第二进程根据所述标识信息和内存块管理信息从所述第一内存块中读取所述第一业务数据之后,所述方法还包括:After the second process reads the first service data from the first memory block according to the identification information and the memory block management information, the method further includes:
    所述第二进程将所述第一内存块的状态信息由所述使用状态调整为所述空闲状态,并且,将所述第一内存块从使用链表移动至空闲链表。The second process adjusts the state information of the first memory block from the use state to the idle state, and moves the first memory block from the use linked list to the free linked list.
  15. 一种进程间通信装置,其特征在于,包括:An inter-process communication device, characterized in that it comprises:
    写入模块,用于在第一内存块中写入内存块管理信息和第一业务数据,所述第一内存块位于第一内存池中,所述内存块管理信息为维护所述第一内存块的信息;The writing module is configured to write memory block management information and first business data in a first memory block, where the first memory block is located in a first memory pool, and the memory block management information is for maintaining the first memory Block information;
    发送模块,用于将标识信息发送至第二进程,以使得所述第二进程根据所述标识信息和所述内存块管理信息获取所述第一内存块中的所述第一业务数据,所述标识信息用于指示所述第一内存块的地址。The sending module is configured to send identification information to a second process, so that the second process obtains the first service data in the first memory block according to the identification information and the memory block management information, so The identification information is used to indicate the address of the first memory block.
  16. 根据权利要求15所述的进程间通信装置,其特征在于,所述标识信息包括第一标识信息和第二标识信息,所述第一标识信息用于指示所述第一内存池的首地址,所述第二标识信息用于指示所述第一内存块在所述第一内存池中的地址。The inter-process communication device according to claim 15, wherein the identification information comprises first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
  17. 根据权利要求15或16所述的进程间通信装置,其特征在于,所述第一内存块包括第一区域和第二区域;The inter-process communication device according to claim 15 or 16, wherein the first memory block includes a first area and a second area;
    所述第一区域用于记录所述内存块管理信息,所述第一区域允许所述第一进程或所述第二进程随时访问;The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time;
    所述第二区域用于记录所述第一业务数据,所述第二区域不允许所述第一进程和所述第二进程随时访问。The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  18. 根据权利要求17所述的进程间通信装置,其特征在于,所述内存块管理信息包括第一指示信息;The inter-process communication device according to claim 17, wherein the memory block management information includes first indication information;
    所述进程间通信装置还包括:The inter-process communication device further includes:
    获取模块,用于当检测到所述第一指示信息为第二值时从所述第一内存块的第二区域获取第二业务数据,所述第二值用于指示所述第一进程允许访问所述第二区域且所述第二进程禁止访问所述第二区域。An acquiring module, configured to acquire second service data from a second area of the first memory block when it is detected that the first indication information is a second value, where the second value is used to indicate that the first process allows Access to the second area and the second process prohibits access to the second area.
  19. 根据权利要求17所述的进程间通信装置,其特征在于,所述进程间通信装置还包括:The inter-process communication device according to claim 17, wherein the inter-process communication device further comprises:
    指示信息调整模块,用于将所述第一指示信息设置为第一值,所述第一值用于指示所述第一进程禁止访问所述第一内存块的第二区域且所述第二进程允许访问所述第二区域。An instruction information adjustment module, configured to set the first instruction information to a first value, the first value being used to instruct the first process to prohibit access to the second area of the first memory block and the second The process allows access to the second area.
  20. 根据权利要求15至19中任意一项所述的进程间通信装置,其特征在于,所述内存块管理信息还包括状态信息,所述状态信息用于指示所述第一内存块处于空闲状态或使用状态;The inter-process communication device according to any one of claims 15 to 19, wherein the memory block management information further comprises status information, and the status information is used to indicate that the first memory block is in an idle state or status of use;
    状态信息调整模块,用于将所述状态信息由所述空闲状态调整为所述使用状态,并且,将所述第一内存块从空闲链表移动至使用链表。The state information adjustment module is configured to adjust the state information from the idle state to the use state, and move the first memory block from the idle linked list to the used linked list.
  21. 根据权利要求20所述的进程间通信装置,其特征在于,所述状态信息调整模块,还用于将所述第一内存块的状态信息由所述使用状态调整为所述空闲状态,并且,将所述第一内存块从使用链表移动至空闲链表。The inter-process communication device according to claim 20, wherein the state information adjustment module is further configured to adjust the state information of the first memory block from the use state to the idle state, and, The first memory block is moved from the used linked list to the free linked list.
  22. 根据权利要求15至21中任意一项所述的进程间通信装置,其特征在于,所述进程间通信装置还包括:The inter-process communication device according to any one of claims 15 to 21, wherein the inter-process communication device further comprises:
    资源申请模块,用于向内核申请第一共享内存块;The resource application module is used to apply to the kernel for the first shared memory block;
    所述写入模块,还用于在所述第一共享内存块的头部写入内存池管理信息,所述内存池管理信息用于将所述第一共享内存块划分为多个初始内存块,所述多个初始内存块构成所述第一内存池。The writing module is further configured to write memory pool management information at the head of the first shared memory block, where the memory pool management information is used to divide the first shared memory block into a plurality of initial memory blocks , The multiple initial memory blocks constitute the first memory pool.
  23. 一种进程间通信装置,其特征在于,包括:An inter-process communication device, characterized in that it comprises:
    接收模块,用于接收第一进程发送的标识信息,所述标识信息用于指示第一内存块的地址,所述第一内存块位于第一内存池中,所述第一内存块中包含所述第一进程写入的第一业务数据和内存块管理信息,所述内存块管理信息为维护所述第一内存块的信息;The receiving module is configured to receive identification information sent by the first process, where the identification information is used to indicate the address of the first memory block, the first memory block is located in the first memory pool, and the first memory block contains all The first service data and memory block management information written by the first process, where the memory block management information is information for maintaining the first memory block;
    读取模块,用于根据所述标识信息和所述内存块管理信息从所述第一内存块中读取所述第一业务数据。The reading module is configured to read the first service data from the first memory block according to the identification information and the memory block management information.
  24. 根据权利要求23所述的进程间通信装置,其特征在于,所述标识信息包括第一标识信息和第二标识信息,所述第一标识信息用于指示所述第一内存池的首地址,所述第二标识信息用于指示所述第一内存块在所述第一内存池中的地址。The inter-process communication device according to claim 23, wherein the identification information comprises first identification information and second identification information, and the first identification information is used to indicate the first address of the first memory pool, The second identification information is used to indicate the address of the first memory block in the first memory pool.
  25. 根据权利要求23或24所述的进程间通信装置,其特征在于,所述第一内存块包括第一区域和第二区域;The inter-process communication device according to claim 23 or 24, wherein the first memory block includes a first area and a second area;
    所述第一区域用于记录所述内存块管理信息,所述第一区域允许所述第一进程或所述第二进程随时访问;The first area is used to record the memory block management information, and the first area allows the first process or the second process to access at any time;
    所述第二区域用于记录所述第一业务数据,所述第二区域不允许所述第一进程和所述第二进程随时访问。The second area is used to record the first service data, and the second area does not allow the first process and the second process to access at any time.
  26. 根据权利要求25所述的进程间通信装置,其特征在于,所述内存块管理信息包括第一指示信息;The inter-process communication device according to claim 25, wherein the memory block management information includes first indication information;
    所述进程间通信装置还包括:The inter-process communication device further includes:
    写入模块,用于在所述第一内存块的第二区域写入第二业务数据;A writing module, configured to write second service data in the second area of the first memory block;
    指示信息调整模块,用于将所述第一指示信息调整为第二值,所述第二值用于指示所述第一进程允许访问所述第二区域且所述第二进程禁止访问所述第二区域。The instruction information adjustment module is configured to adjust the first instruction information to a second value, where the second value is used to indicate that the first process is allowed to access the second area and the second process is forbidden to access the The second area.
  27. 根据权利要求25所述的进程间通信装置,其特征在于,所述读取模块包括:The inter-process communication device according to claim 25, wherein the reading module comprises:
    查找单元,用于根据所述第一标识信息和所述第二标识信息在所述第一内存池中查找所述第一内存块;A searching unit, configured to search for the first memory block in the first memory pool according to the first identification information and the second identification information;
    读取单元,用于当检测到所述第一指示信息为所述第一值时从所述第一内存块的第二区域读取所述第一业务数据,所述第一值用于指示所述第一进程禁止访问所述第一内存块的第二区域且所述第二进程允许访问所述第二区域。A reading unit, configured to read the first service data from the second area of the first memory block when it is detected that the first indication information is the first value, and the first value is used to indicate The first process prohibits access to the second area of the first memory block and the second process allows access to the second area.
  28. 根据权利要求23至27中任意一项所述的进程间通信装置,其特征在于,所述内存块管理信息还包括状态信息,所述状态信息用于指示所述第一内存块处于空闲状态或使用状态;The inter-process communication device according to any one of claims 23 to 27, wherein the memory block management information further comprises status information, and the status information is used to indicate that the first memory block is in an idle state or status of use;
    所述进程间通信装置还包括:The inter-process communication device further includes:
    状态信息调整模块,用于将所述第一内存块的状态信息由所述使用状态调整为所述空闲状态,并且,将所述第一内存块从使用链表移动至空闲链表。The state information adjustment module is configured to adjust the state information of the first memory block from the use state to the idle state, and move the first memory block from the use linked list to the idle linked list.
  29. 一种进程间通信装置,其特征在于,所述进程间通信装置位于处理器中,所述进程间通信装置调用存储器中的程序代码运行第一进程,以实现权利要求1至8中任意一项所述的方法。An inter-process communication device, characterized in that the inter-process communication device is located in a processor, and the inter-process communication device calls the program code in the memory to run a first process, so as to implement any one of claims 1 to 8. The method described.
  30. 一种进程间通信装置,其特征在于,所述进程间通信装置位于处理器中,所述进程间通信装置调用存储器中的程序代码运行第二进程,以实现权利要求9至14中任意一项所述的方法。An inter-process communication device, characterized in that the inter-process communication device is located in a processor, and the inter-process communication device calls the program code in the memory to run a second process, so as to implement any one of claims 9 to 14 The method described.
  31. 一种处理系统,其特征在于,所述处理系统包括如权利要求15至22中任意一项所述的进程间通信装置,以及如权利要求23至28中任意一项所述的进程间通信装置;A processing system, characterized in that the processing system comprises the inter-process communication device according to any one of claims 15 to 22, and the inter-process communication device according to any one of claims 23 to 28 ;
    或者,or,
    所述处理系统包括如权利要求27所述的进程间通信装置和如权利要求28所述的进程间通信装置。The processing system includes the inter-process communication device according to claim 27 and the inter-process communication device according to claim 28.
  32. 一种计算机可读存储介质,其上存储有计算机程序或指令,其特征在于,所述计算机程序或指令被执行时使得进程间通信装置执行如权利要求1至8中任意一项所述的方法,或者权利要求9至14中任意一项所述的方法。A computer-readable storage medium having a computer program or instruction stored thereon, wherein when the computer program or instruction is executed, an inter-process communication device executes the method according to any one of claims 1 to 8 , Or the method of any one of claims 9 to 14.
PCT/CN2021/087695 2020-06-05 2021-04-16 Inter-process communication method and inter-process communication apparatus WO2021244155A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010505324.6 2020-06-05
CN202010505324.6A CN113760560A (en) 2020-06-05 2020-06-05 Inter-process communication method and inter-process communication device

Publications (1)

Publication Number Publication Date
WO2021244155A1 true WO2021244155A1 (en) 2021-12-09

Family

ID=78784975

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/087695 WO2021244155A1 (en) 2020-06-05 2021-04-16 Inter-process communication method and inter-process communication apparatus

Country Status (2)

Country Link
CN (1) CN113760560A (en)
WO (1) WO2021244155A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115858184A (en) * 2023-03-03 2023-03-28 浪潮电子信息产业股份有限公司 RDMA memory management method, device, equipment and medium
WO2023221003A1 (en) * 2022-05-18 2023-11-23 北京小米移动软件有限公司 System memory recycling method and apparatus, and electronic device and storage medium

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116361019A (en) * 2021-12-27 2023-06-30 北京罗克维尔斯科技有限公司 Inter-process communication method and device
WO2024060228A1 (en) * 2022-09-23 2024-03-28 华为技术有限公司 Data acquisition method, apparatus and system, and storage medium
CN116737404A (en) * 2022-09-28 2023-09-12 荣耀终端有限公司 Method and terminal device for application connection
CN115878351B (en) * 2023-03-03 2023-07-21 苏州浪潮智能科技有限公司 Message transmission method and device, storage medium and electronic device

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101448018A (en) * 2008-12-26 2009-06-03 中兴通讯股份有限公司 Interprocess communication method and device thereof
CN103838859A (en) * 2014-03-19 2014-06-04 厦门雅迅网络股份有限公司 Method for reducing data copy among multiple processes under linux
CN107193673A (en) * 2017-06-28 2017-09-22 锐捷网络股份有限公司 A kind of message processing method and equipment
CN110399229A (en) * 2018-04-25 2019-11-01 清华大学 Communication means, device, system, medium and terminal between process
CN110618883A (en) * 2019-09-26 2019-12-27 迈普通信技术股份有限公司 Method, device, equipment and storage medium for sharing memory linked list

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101448018A (en) * 2008-12-26 2009-06-03 中兴通讯股份有限公司 Interprocess communication method and device thereof
CN103838859A (en) * 2014-03-19 2014-06-04 厦门雅迅网络股份有限公司 Method for reducing data copy among multiple processes under linux
CN107193673A (en) * 2017-06-28 2017-09-22 锐捷网络股份有限公司 A kind of message processing method and equipment
CN110399229A (en) * 2018-04-25 2019-11-01 清华大学 Communication means, device, system, medium and terminal between process
CN110618883A (en) * 2019-09-26 2019-12-27 迈普通信技术股份有限公司 Method, device, equipment and storage medium for sharing memory linked list

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023221003A1 (en) * 2022-05-18 2023-11-23 北京小米移动软件有限公司 System memory recycling method and apparatus, and electronic device and storage medium
CN115858184A (en) * 2023-03-03 2023-03-28 浪潮电子信息产业股份有限公司 RDMA memory management method, device, equipment and medium
CN115858184B (en) * 2023-03-03 2023-05-02 浪潮电子信息产业股份有限公司 RDMA memory management method, device, equipment and medium

Also Published As

Publication number Publication date
CN113760560A (en) 2021-12-07

Similar Documents

Publication Publication Date Title
WO2021244155A1 (en) Inter-process communication method and inter-process communication apparatus
US6163834A (en) Two level address translation and memory registration system and method
US5961606A (en) System and method for remote buffer allocation in exported memory segments and message passing between network nodes
CN107844267B (en) Buffer allocation and memory management
US20050038941A1 (en) Method and apparatus for accessing a memory
US20070130372A1 (en) I/O address translation apparatus and method for specifying a relaxed ordering for I/O accesses
US20190026225A1 (en) Multiple chip multiprocessor cache coherence operation method and multiple chip multiprocessor
US7002956B2 (en) Network addressing method and system for localizing access to network resources in a computer network
CN113674133A (en) GPU cluster shared video memory system, method, device and equipment
US11989588B2 (en) Shared memory management method and device
US9311044B2 (en) System and method for supporting efficient buffer usage with a single external memory interface
WO2024099448A1 (en) Memory release method and apparatus, memory recovery method and apparatus, and computer device and storage medium
US20030005257A1 (en) Memory table and memory manager for use in managing memory
WO2023040464A1 (en) Bus communication method and related device
US11157191B2 (en) Intra-device notational data movement system
US20210191777A1 (en) Memory Allocation in a Hierarchical Memory System
TW202219773A (en) Method for establishing look-up table and inquiring memory address, method for establishing host memory address look-up table, and method for inquiring host memory address
US10936219B2 (en) Controller-based inter-device notational data movement system
US11281612B2 (en) Switch-based inter-device notational data movement system
US9424227B2 (en) Providing byte enables for peer-to-peer data transfer within a computing environment
JP7204020B2 (en) Control method
JP2003316589A (en) Real memory using method
WO2024061344A1 (en) Data migration method and apparatus, and chip and computer-readable storage medium
JP7167295B2 (en) Memory system and control method
WO2022170452A1 (en) System and method for accessing remote resource

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21817764

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21817764

Country of ref document: EP

Kind code of ref document: A1