Summary of the invention
The embodiment of the present invention provides a kind of method of E-Packeting and device, in order to realize in the process E-Packeted, can avoid the copy of message from kernel spacing to application space, thus while raising message transferring speed, also can improve the resource utilization of system.
The embodiment of the present invention provides a kind of method E-Packeted, and the method comprises: the packet storage that network interface card receives by kernel state receiving process is in shared drive and notify User space process;
Described User space process, by after the physical address map of described shared drive to the virtual address of described User space process, is extracted described message and processes described message from described shared drive;
Described User space process by process after packet storage in described shared drive and notify kernel state send process;
Described kernel state is sent process and is sent by corresponding network interface card by the message after described process.
Preferably, the packet storage that network interface card receives by described kernel state receiving process is in shared drive and notify User space process, is specially:
Described kernel state receiving process applies for memory block from memory pool, and receiving queue tail of the queue in described memory block, and is inserted in the address of described memory block by the described packet storage received by network interface card;
Receiving queue described in described User space process poll, reads the address of described memory block from receiving queue head, until described receiving queue is empty;
When described receiving queue is empty, described User space process enters sleep state, until wake described User space process during described receiving queue non-NULL up.
Preferably, receiving queue is inserted in the address of described memory block, is specially:
Hash operation is carried out according to the source IP address of described message and object IP address;
According to the value obtained after Hash operation, determine the queue value of kernel state receiving queue;
According to the queue value of the kernel receiving queue determined, the block address memory of described message is stored in corresponding receiving queue.
Preferably, described User space process is extracted described message and is processed described message from described shared drive, be specially: described User space process reads the address of the memory block storing described message from the receiving queue team head of described shared drive, and the address according to described memory block is read the content of described message to the corresponding position of memory pool and processes described message.
Preferably, described User space process by process after packet storage in described shared drive and notify described kernel state send process, be specially:
The address of the memory block of the message after described process is inserted into transmit queue tail of the queue by described User space process, and calling system function notifies that described kernel state sends process.
Preferably, described shared drive is that described kernel state distributes when initialization, comprising:
The memory pool be made up of many memory blocks;
For the internal memory that the receiving queue and transmit queue of preserving the address of described memory block use;
For preserving the internal memory that the head pointer of described receiving queue and tail pointer and head pointer and tail pointer for preserving described transmit queue use.
The embodiment of the present invention provides a kind of device E-Packeted, and device comprises:
Receiver module, being used to indicate packet storage that network interface card receives by kernel state receiving process in shared drive notifies User space process;
Processing module, for after described User space process is by the physical address map of described shared drive to the virtual address of described User space process, extracts described message and processes described message from described shared drive;
Notification module, for described User space process by process after packet storage after described shared drive, notice kernel state send process;
Sending module, is used to indicate described kernel state transmission process and is sent by corresponding network interface card by the message after described process.
Preferably, described receiver module, specifically for:
Indicate described kernel state receiving process to apply for memory block from memory pool, receiving queue tail of the queue in described memory block, and is inserted in the address of described memory block by the described packet storage received by network interface card;
Indicate receiving queue described in described User space process poll, read described block address memory from receiving queue head, until described receiving queue is empty;
When described receiving queue is empty, described User space process is indicated to enter sleeping eyes state, until wake described User space process during described receiving queue non-NULL up.
Preferably, described receiver module, specifically for:
Hash operation is carried out according to the source IP address of described message and object IP address;
According to the value obtained after Hash operation, determine the queue value of kernel state receiving queue;
According to the queue value of the kernel receiving queue determined, the block address memory of described message is stored in corresponding receiving queue.
Preferably, described processing module, specifically for:
Indicate described User space process from the receiving queue team head of described shared drive, read the address saving the memory block of described message, according to the content reading described message in described block address memory to memory pool, described message is processed.
Preferably, described notification module, specifically for:
Indicate described User space process that the block address memory of the message after described process is inserted into transmit queue tail of the queue, and calling system function notify that described kernel state sends process.
Preferably, described shared drive is that described kernel state distributes when initialization, comprising:
The memory pool be made up of multiple described memory block;
For the internal memory that the receiving queue and transmit queue of preserving the address of described memory block use;
For preserving the internal memory that the head pointer of described receiving queue and tail pointer and head pointer and tail pointer for preserving described transmit queue use.
The method E-Packeted that above-described embodiment provides and device, comprising: the packet storage that network interface card receives by kernel state receiving process is in shared drive and notify User space process; Described User space process, by after the physical address map of described shared drive to the virtual address of described User space process, is extracted described message and processes described message from described shared drive; Described User space process by process after packet storage in described shared drive and notify kernel state send process; Described kernel state is sent process and is sent by corresponding network interface card by the message after described process.Can find out, first, the packet storage that network interface card receives by kernel state receiving process is in shared drive; Then, the virtual address of the physical address of shared drive and User space process is set up mapping relations by User space process, User space process processes the message that network interface card receives according to set up mapping relations, and by the packet storage after process in shared drive; Finally, send process by kernel state and the message after process is sent by corresponding network interface card, therefore, avoid the copy of message from kernel spacing to application space, thus while raising message transferring speed, also can improve the resource utilization of system.
Embodiment
In order to make the object, technical solutions and advantages of the present invention clearly, below in conjunction with accompanying drawing, the present invention is described in further detail, and obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on the embodiment in the present invention, those of ordinary skill in the art, not making other embodiments all obtained under creative work prerequisite, belong to the scope of protection of the invention.
Fig. 1 is a kind of method flow diagram E-Packeted that the embodiment of the present invention provides.As shown in Figure 1, the method can comprise:
The packet storage that network interface card receives by S101, kernel state receiving process is in shared drive and notify User space process.
S102, User space process, by after the physical address map of shared drive to the virtual address of User space process, are extracted message and process message from shared drive.
S103, User space process by process after packet storage in shared drive and notify kernel state send process.
S104, kernel state are sent process and are sent by corresponding network interface card by the message after process.
Wherein, shared drive is that kernel state distributes when initialization.Concrete, kernel state, when initialization, can distribute first piece of continuous print physical memory of certain capacity for building shared drive, and can be divided by distribute continuous print physical memory further.Such as, kernel state is when initialization, can allocated size be that the continuous physical memory of 16M is for building shared drive, further, also the continuous physical memory of distributed 16M can be divided into 8K memory block, the size that can calculate each memory block is like this 2K, and is the message that the memory block of 2K is used for storing kernel state receiving process and receives by size.
Kernel state, when initialization, except distributing the continuous print physical memory of certain capacity for building except shared drive, also distributes second piece of continuous print physical memory for building receiving queue and transmit queue.Wherein, the block address memory of message of constructed receiving queue for storing kernel state receiving process and receiving, constructed transmit queue sends the block address memory of the message after process process for storing kernel state.Such as, suppose that kernel state is when initialization, allocated size is that the continuous physical memory of 16M is for building shared drive, and the continuous physical memory of distributed 16M is divided into 8K memory block, the address of further hypothesis 1K memory block needs to preserve with a queue, at this moment, kernel state is when initialization, except allocated size is that the continuous physical memory of 16M is for building except shared drive, also need to distribute another block internal memory for preserving 8 receiving queues and 8 transmit queues, wherein, 8 receiving queues can be: be qos [1], qos [2], qos [3], qos [4], qos [5], qos [6], qos [7], qos [8], 8 transmit queues can be: qos [9], qos [10], qos [11], qos [12], qos [13], qos [14], qos [15], qos [16].
Concrete, when being stored in receiving queue by the block address memory of message, Hash operation is carried out in source IP address and the object IP address of the message that can receive according to kernel state receiving process; According to the value obtained after Hash operation, determine the queue value of kernel state receiving queue; According to the queue value of the kernel receiving queue determined, the block address memory of message is stored in corresponding receiving queue, to ensure the homology chummage of message.
Wherein, Hash operation is exactly after receiving message, first from 32 bits of the source IP address of message, object IP address, extract respectively the binary number of fixed position, fixed qty, such as 12 to 20 totally 9 figure places, then this group number is carried out xor operation, and carry out the operation of remainder number according to number of queues.Like this, just by different packet storages in different receiving queues, the homology chummage of message can be also ensure that simultaneously.
In addition, kernel state is when initialization, except distributing first piece of continuous print physical memory of certain capacity for building shared drive and second piece of continuous print physical memory for building except receiving queue, transmit queue, also can distribute the 3rd piece of continuous print physical memory, for head pointer and the tail pointer of the head pointer and tail pointer and transmit queue that store receiving queue.
Such as, suppose that kernel state is when initialization, allocated size is that the continuous physical memory of 16M is for building shared drive with another block internal memory for preserving 8 receiving queues and 8 transmit queues.Further hypothesis 8 receiving queues are respectively: qos [1], qos [2], qos [3], qos [4], qos [5], qos [6], qos [7], qos [8], 8 transmit queues are respectively: qos [9], qos [10], qos [11], qos [12], qos [13], qos [14], qos [15], qos [16], head pointer and the tail pointer of above-mentioned 8 receiving queues of further hypothesis are respectively: be qos [1] .head, qos [2] .head, qos [3] .head, qos [4] .head, qos [5] .head, qos [6] .head, qos [7] .head, qos [8] .head, qos [1] .tail, qos [2] .tail, qos [3] .tail, qos [4] .tail, qos [5] .tail, qos [6] .tail, qos [7] .tail, qos [8] .tail, head pointer and the tail pointer of above-mentioned 8 transmit queues are respectively: be qos [9] .head, qos [10] .head, qos [11] .head, qos [12] .head, qos [13] .head, qos [14] .head, qos [15] .head, qos [16] .head, qos [9] .tail, qos [10] .tail, qos [11] .tail, qos [12] .tail, qos [13] .tail, qos [14] .tail, qos [15] .tail, qos [16] .tail.
At this moment, kernel state, when initialization, also needs to distribute another block continuous print physical memory, for head pointer and the tail pointer of the head pointer and tail pointer and above-mentioned 8 transmit queues of depositing above-mentioned 8 receiving queues.
Kernel state is when initialization, not only distribute first piece of continuous print physical memory for building shared drive, second piece of continuous print physical memory for building receiving queue and transmit queue and the 3rd piece of continuous print physical memory for the head pointer of the head pointer and tail pointer and transmit queue that store up receiving queue and tail pointer, but also records the first address of the first address of first piece of continuous print physical memory, the first address of second piece of continuous print physical memory and the 3rd piece of continuous print physical memory distributed.Like this, the first address of distribute first piece continuous print physical memory of User space process by record, the first address of the first address of second piece of continuous print physical memory and the 3rd piece of continuous print physical memory, can read the first address of first piece of continuous print physical memory and size, the first address of second piece of continuous print physical memory and the first address of size and the 3rd piece of continuous print physical memory thereof and size thereof.And, first address and the size thereof of first piece of continuous print physical memory is read in User space process, after the first address of the first address of second piece of continuous print physical memory and size and the 3rd piece of continuous print physical memory and size thereof, the virtual address of the address of first piece of continuous print physical memory and User space process is made to set up mapping relations by calling system function, like this, the mapping relations of User space process by setting up, the message stored in memory block is processed, therefore, User space process directly can have access to the message that kernel state receives, thus avoid the copy of message from kernel state to User space, improve the forwarding speed of message, simultaneously, also save system resource.
In above-mentioned steps S101, the packet storage that network interface card receives by kernel state receiving process is in shared drive and notify User space process, be specially: kernel state receiving process applies for memory block from memory pool, the address of the memory block applied in the memory block applied for, and is inserted into the tail of the queue of receiving queue by the packet storage received by network interface card; User space process poll receiving queue, reads the address of memory block from receiving queue head, until receiving queue is empty; When receiving queue is empty, User space process enters sleep state, until wake User space process up during receiving queue non-NULL.Can find out, adopt wake-up waiting mechanism and interrupt the mode that combines of poll, the expense of CPU when deducting idle, thus improve forwarding speed and the resource utilization ratio of message.
In above-mentioned steps S102, User space process is extracted message and is processed message from shared drive, be specially: User space process reads the address of the memory block of stored messages from the receiving queue team head of shared drive, the address according to memory block is read the content of message to the corresponding position of memory pool and processes message.
In above-mentioned steps S103, User space process by process after packet storage in shared drive and notify kernel state send process, be specially: the address of the memory block of the message after process is inserted into transmit queue tail of the queue by User space process, and calling system function notice kernel state sends process.
Below by a concrete example, detailed explanation explanation is carried out to above-mentioned content.
In order to describe for simplicity, suppose that receiving queue only has a queue to be qos [M] and this queue is current for empty.Further hypothesis kernel state receiving process is message 1, message 2, message 3 according to the message that time order and function is received sequentially, then kernel state receiving process is after receiving message 1, message 2, message 3, from shared drive application to memory block 1 for stored messages 1, apply for memory block 2 for stored messages 2 and application to memory block 3 for stored messages.The physical address of the memory block 1 that further hypothesis is applied for is 001, the physical address of memory block 2 is 002 (binary system is 0010), the physical address of memory block 3 is 003 (binary system is 0011).Then, be 001 by the physical address of memory block 1, the physical address of memory block 2 is 002, the physical address of memory block 3 is 003 be stored in receiving queue qos [M] successively, then the physical address 001 of message 1 is stored in the head of receiving queue qos [M], and the physical address 003 of message 3 is stored in the afterbody of receiving queue qos [M].Now, User space process by calling system function, and according to the head pointer of receiving queue qos [M] and tail pointer, makes physical address 001, physical address 002, physical address 003 set up mapping relations with the virtual address of User space process.Like this, User space process, according to set up mapping relations, can process message 1, message 2, message 3, therefore, User space process directly can have access to the message that kernel state receives, thus avoids the copy of message from kernel state to User space, has saved system resource.
On basis based on above-mentioned example, suppose that transmit queue is qos [N] and current for empty.After User space process processes message 1, message 2, message 3, successively the physical address 002 of the physical address 001 of message 1, message 2, the physical address 003 of message 3 are stored to transmit queue qos [N], kernel state sends and carries out by arriving transmit queue qos [N], and according to physical address 001, the physical address 002 of message 2, the physical address 003 of message 3 of message 1 in transmit queue qos [N], read message 1, message 2, message 3, and message 1, message 2, message 3 are sent on corresponding network interface card.After message 1, message 2, message 3 are sent to corresponding network interface card by kernel state transmission process, memory block 1, memory block 2, memory block 3 are discharged, at this moment, kernel state sends physical address 001, the physical address 002 of memory block 2, the physical address 003 of memory block 3 of memory block 1 that process reclaims memory block 1, memory block 2, memory block 3 and distributes.
The mode of first in first out that what above-mentioned receiving queue qos [M], transmit queue qos [N] adopted is, in the specific implementation, receiving queue and transmit queue also can adopt mode first-in last-out, no longer describe in detail mode first-in last-out at this.
Message in the embodiment of the present invention can be 5 tuple messages, also can be the message of other type.
According to above content, can find out that the method E-Packeted that above-described embodiment provides comprises: the packet storage that network interface card receives by kernel state receiving process is in shared drive and notify User space process; Described User space process, by after the physical address map of described shared drive to the virtual address of described User space process, is extracted described message and processes described message from described shared drive; Described User space process by process after packet storage in described shared drive and notify kernel state send process; Described kernel state is sent process and is sent by corresponding network interface card by the message after described process.Can find out, first, the packet storage that network interface card receives by kernel state receiving process is in shared drive; Then, the virtual address of the physical address of shared drive and User space process is set up mapping relations by User space process, User space process processes the message that network interface card receives according to set up mapping relations, and by the packet storage after process in shared drive; Finally, send process by kernel state and the message after process is sent by corresponding network interface card, therefore, avoid the copy of message from kernel spacing to application space, thus while raising message transferring speed, also can improve the resource utilization of system.
Based on identical technical conceive, the embodiment of the present invention also provides a kind of device E-Packeted, and this device can perform said method embodiment.The device E-Packeted that the embodiment of the present invention provides as shown in Figure 2.Comprise:
Receiver module 21, being used to indicate packet storage that network interface card receives by kernel state receiving process in shared drive notifies User space process;
Processing module 22, for after described User space process is by the physical address map of described shared drive to the virtual address of described User space process, extracts described message and processes described message from described shared drive;
Notification module 23, for described User space process by process after packet storage after described shared drive, notice kernel state send process;
Sending module 24, is used to indicate described kernel state transmission process and is sent by corresponding network interface card by the message after described process.
Preferably, receiver module 21, specifically for:
Indicate described kernel state receiving process to apply for memory block from memory pool, receiving queue tail of the queue in described memory block, and is inserted in the address of described memory block by the described packet storage received by network interface card;
Indicate receiving queue described in described User space process poll, read described block address memory from receiving queue head, until described receiving queue is empty;
When described receiving queue is empty, described User space process is indicated to enter sleeping eyes state, until wake described User space process during described receiving queue non-NULL up.
Preferably, receiver module 21, specifically for:
Hash operation is carried out according to the source IP address of described message and object IP address;
According to the value obtained after Hash operation, determine the queue value of kernel state receiving queue;
According to the queue value of the kernel receiving queue determined, the block address memory of described message is stored in corresponding receiving queue.
Preferably, processing module 22, specifically for:
Indicate described User space process from the receiving queue team head of described shared drive, read the address saving the memory block of described message, according to the content reading described message in described block address memory to memory pool, described message is processed.
Preferably, notification module 23, specifically for:
Indicate described User space process that the block address memory of the message after described process is inserted into transmit queue tail of the queue, and calling system function notify that described kernel state sends process.
Preferably, described shared drive is that described kernel state distributes when initialization, comprising:
The memory pool be made up of multiple described memory block;
For the internal memory that the receiving queue and transmit queue of preserving the address of described memory block use;
For preserving the internal memory that the head pointer of described receiving queue and tail pointer and head pointer and tail pointer for preserving described transmit queue use.
To sum up, the method E-Packeted that the embodiment of the present invention provides and device, comprising: the packet storage that network interface card receives by kernel state receiving process is in shared drive and notify User space process; Described User space process, by after the physical address map of described shared drive to the virtual address of described User space process, is extracted described message and processes described message from described shared drive; Described User space process by process after packet storage in described shared drive and notify kernel state send process; Described kernel state is sent process and is sent by corresponding network interface card by the message after described process.Can find out, first, the packet storage that network interface card receives by kernel state receiving process is in shared drive; Then, the virtual address of the physical address of shared drive and User space process is set up mapping relations by User space process, User space process processes the message that network interface card receives according to set up mapping relations, and by the packet storage after process in shared drive; Finally, send process by kernel state and the message after process is sent by corresponding network interface card, therefore, avoid the copy of message from kernel spacing to application space, thus while raising message transferring speed, also can improve the resource utilization of system.
The present invention describes with reference to according to the flow chart of the method for the embodiment of the present invention, equipment (system) and computer program and/or block diagram.Should understand can by the combination of the flow process in each flow process in computer program instructions realization flow figure and/or block diagram and/or square frame and flow chart and/or block diagram and/or square frame.These computer program instructions can being provided to the processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing device to produce a machine, making the instruction performed by the processor of computer or other programmable data processing device produce device for realizing the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
These computer program instructions also can be stored in can in the computer-readable memory that works in a specific way of vectoring computer or other programmable data processing device, the instruction making to be stored in this computer-readable memory produces the manufacture comprising command device, and this command device realizes the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
These computer program instructions also can be loaded in computer or other programmable data processing device, make on computer or other programmable devices, to perform sequence of operations step to produce computer implemented process, thus the instruction performed on computer or other programmable devices is provided for the step realizing the function of specifying in flow chart flow process or multiple flow process and/or block diagram square frame or multiple square frame.
Although describe the preferred embodiments of the present invention, those skilled in the art once obtain the basic creative concept of cicada, then can make other change and amendment to these embodiments.So claims are intended to be interpreted as comprising preferred embodiment and falling into all changes and the amendment of the scope of the invention.
Obviously, those skilled in the art can carry out various change and modification to the present invention and not depart from the spirit and scope of the present invention.Like this, if these amendments of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.