Background technology
Along with the continuous lifting of physical interface speed, in route system, the forwarding core (core) of CPU number also increases thereupon.In route system, each of CPU forwards core by concurrent working mode parallel processing message repeating, to improving message forwarding performance.But, when a plurality of forwarding core is accessed identical code district (being designated as shared resource) simultaneously, for avoiding conflict, need to realize the exclusive reference that shared resource is checked in a plurality of forwardings, this exclusive reference can not embody the advantage that multi-core parallel concurrent is carried out.
In order to embody the advantage of multi-core parallel concurrent execution, just need to avoid the exclusive reference of shared resource.Prior art provides following methods to replace the exclusive reference of shared resource: by resource pointer, control the access of shared resource.During this access specific implementation by resource pointer control shared resource, can be: when reading shared resource, without mutual exclusion, can directly access by resource pointer; And when writing shared resource also without mutual exclusion, first copy a shared resource, then on the shared resource of copy, carry out write operation, new resources pointer more after write operation completes, allows it point to the shared resource of new copy.
As for original shared resource, it needs to discharge.Wherein, this releasing resource is time-based delay memory method for releasing, from the time point of above-mentioned more new resources pointer, counts, and after postponing a period of time, discharges original shared resource.The time of this delay is static appointment, as 1 second or 10 seconds etc.
But, this time-based delay memory method for releasing is poor efficiency or even insecure, because the time postponing is static appointment, if the time of delay of appointment is too short, so when arrive in this time of delay, also can exist this resource to be discharged to also have accessed possibility, this affects resource access; If the time of delay of appointment is long, will certainly within a period of time, reduce so the quantity of the available free memory of system, cause the waste of resource.
Summary of the invention
The invention provides memory release method and route system, with the poor efficiency of avoiding time-based delay memory method for releasing to be brought, even not reliable defect.
Technical scheme provided by the invention comprises:
A memory release method, comprising:
All forwarding cores in route system are organized successively according to the rule of setting;
Each forwards core after the resource of new resources pointed more, and the resource that the resource that this resource pointer was pointed to before upgrading discharges as needs is deposited and to the next one, forwarded the resource that core is assigned with and discharge in queue;
The resource that each forwarding nuclear inspection self is assigned with discharges queue and whether has the resource that needs release, if, take out successively the resource that each need to discharge, and judge that whether this resource is due to self the more resource of new resources pointed and resource that definite needs discharge, if, discharge this resource, otherwise the resource that this resource is continued to discharge as needs is deposited the resource being assigned with to next one forwarding core and is discharged in queue.
A route system, comprising: organizational unit, dispensing unit and a plurality of forwarding core, wherein,
Described organizational unit, for organizing according to the rule of setting all forwarding cores of route system;
Described dispensing unit, is used to each to forward core and distributes independently resource to discharge queue;
Each forwards core and comprises: the first processing unit and the second processing unit, wherein,
Described the first processing unit, for at its residing forwarding core more after the resource of new resources pointed, the resource that the resource that this resource pointer was pointed to before upgrading discharges as needs, deposits the resource being assigned with to the next one forwarding core of this forwarding core and discharges in queue;
Described the second processing unit, for checking whether the resource release queue that its residing forwarding core is assigned with exists the resource that needs release, if, take out successively the resource that each need to discharge, and judge that whether this resource is due to its residing forwarding core more resource of new resources pointed and resource that definite needs discharge, if, discharge this resource, otherwise the resource that this resource is continued to discharge as needs is deposited the resource being assigned with to the next one forwarding core of this forwarding core and is discharged in queue.
As can be seen from the above technical solutions, in the present invention, each forwards core and through after all forwarding core, just discharges this resource in its resource that definite needs discharge due to the resource of new resources pointed more, when not accessing this resource, all forwarding core just discharges in time this resource, this can not affect resource access on the one hand, also releasing resource in time on the other hand, can not cause the waste of resource, the poor efficiency of avoiding time-based delay memory method for releasing to bring, even not reliable defect, the poor efficiency of having avoided time-based delay memory method for releasing to bring completely, even not reliable defect.
Embodiment
In order to make the object, technical solutions and advantages of the present invention clearer, below in conjunction with the drawings and specific embodiments, describe the present invention.
Referring to Fig. 1, the basic flow sheet that Fig. 1 provides for the embodiment of the present invention.As shown in Figure 1, this flow process can comprise the following steps:
Step 101, organizes according to the rule of setting successively to all forwarding cores in route system.
During this step 101 specific implementation, can be all forwarding core is formed to a ring successively according to the order of setting.
Wherein, all forwarding core is formed to a ring successively according to the order of setting specifically be can be: all forwarding cores in route system are numbered in order, if all forwarding cores in route system are: core-1, core-2, ... core-N, can to this all forwarding core, number in order since a predefined initial value such as 1, such as, be numbered from 1 to N, afterwards all forwarding core formed to a ring successively according to numbering size.Wherein, all forwarding core is formed to a ring successively according to numbering size and can comprise following arbitrary situation:
Situation 1: the order ascending according to the numbering that forwards core forms a ring by all forwarding core clockwise.All forwarding cores of take in route system are core-1, core-2 ... core-N, this each forward core be numbered 1,2 ... N, based on this, according to the ascending order of numbering, clockwise all forwarding core being formed to a ring can be as shown in Figure 2.
Situation 2: the order descending according to the numbering that forwards core forms a ring by all forwarding core clockwise.All forwarding cores of take in route system are core-1, core-2 ... core-N, this each forward core be numbered 1,2 ... N, based on this, according to the descending order of numbering, clockwise all forwarding core being formed to a ring can be as shown in Figure 3.
Step 102, each forwards core after the resource of new resources pointed more, and the resource that the resource that this resource pointer was pointed to before upgrading discharges as needs is deposited and to the next one, is forwarded the resource that core is assigned with and discharge in queue.
Based on above-described, all forwarding cores in route system are organized according to the rule of setting, that all forwarding core is formed to a ring successively according to the order of setting, can obtain, the next one in this step 102 forward core be current forwarding core in ring along clockwise direction or anticlockwise adjacent forwarding core.
In addition, in this step 102, the resource release queue that forwarding core is assigned with is pre-assigned, and resource discharges queue for depositing the resource that needs release, and the resource of the needs that it is deposited according to first in first out (FIFO:First In First Out) tissue release.Wherein, it is separate that the resource that each forwarding core is assigned with discharges queue.
Take Fig. 2 as example, if in this step 102, core-1 is the resource of new resources pointed more, and the resource that the resource that this core-1 pointed to this resource pointer before upgrading discharges as needs is deposited the resource being assigned with to the core-2 shown in Fig. 2 and discharged in queue.
Step 103, the resource that each forwarding nuclear inspection self is assigned with discharges queue and whether has the resource that needs release, if, take out successively the resource that each need to discharge, and judge this resource be whether due to self more new resources pointed resource and resource that definite needs discharge if so, discharges this resource, otherwise the resource that this resource is continued to discharge as needs is deposited the resource being assigned with to next one forwarding core and is discharged in queue.
In this step 103, the resource that each forwarding nuclear inspection self is assigned with discharges the operation whether queue exists the resource that needs release, is to carry out before processing message or after processing message, and the present invention does not specifically limit.
So far, complete the flow process shown in Fig. 1.
From the flow process shown in Fig. 1, can find out, in the present invention, each forwards core and through after all forwarding core, just discharges this resource in its resource that definite needs discharge due to the resource of new resources pointed more, when not accessing this resource, all forwarding core just discharges in time this resource, this can not affect resource access on the one hand, also releasing resource in time on the other hand, can not cause the waste of resource, poor efficiency, the even not reliable defect of avoiding time-based delay memory method for releasing to bring.
So far, complete method provided by the invention and describe, below route system provided by the invention is described:
Referring to Fig. 4, the route system structure chart that Fig. 4 provides for the embodiment of the present invention.As shown in Figure 4, this route system comprises: organizational unit, dispensing unit and a plurality of forwarding core, wherein,
Described organizational unit, for organizing according to the rule of setting all forwarding cores of route system;
Described dispensing unit, is used to each to forward core and distributes independently resource to discharge queue; Particularly, each resource release queue is the resource discharging according to the needs of the mode organize of FIFO.
Each forwards core and comprises: the first processing unit and the second processing unit, wherein,
Described the first processing unit, for at its residing forwarding core more after the resource of new resources pointed, the resource that the resource that this resource pointer was pointed to before upgrading discharges as needs, deposits the resource being assigned with to the next one forwarding core of this forwarding core and discharges in queue;
Described the second processing unit, for checking whether the resource release queue that its residing forwarding core is assigned with exists the resource that needs release, if, take out successively the resource that each need to discharge, and judge that whether this resource is due to its residing forwarding core more resource of new resources pointed and resource that definite needs discharge, if, discharge this resource, otherwise, the resource that this resource is continued to discharge as needs deposit to this forwardings core the next one forward in the resource release queue that core is assigned with.Wherein, described the second processing unit is before processing message or after processing message, to check whether the resource release queue that its residing forwarding core is assigned with exists the resource that needs release.
Particularly, in the present invention, described organizational unit is organized according to the rule of setting all forwarding cores in route system, is that all forwarding core is formed to a ring successively according to the order of setting; Correspondingly, described next forward core be current forwarding core in ring along clockwise direction or anticlockwise adjacent forwarding core.
Preferably, in the present invention, described organizational unit is organized according to the rule of setting all forwarding cores in route system, refers to:
The order ascending according to the numbering that forwards core forms a ring by all forwarding core clockwise; Or,
The order descending according to the numbering that forwards core forms a ring by all forwarding core clockwise.
So far, completing route system structure provided by the invention describes.
As can be seen from the above technical solutions, in the present invention, each in ring forwards core and through after all forwarding cores of whole ring, just discharges this resource in its resource that definite needs discharge due to the resource of new resources pointed more, when not accessing this resource, all forwarding core just discharges in time this resource, this can not affect resource access on the one hand, also releasing resource in time on the other hand, can not cause the waste of resource, poor efficiency, the even not reliable defect of avoiding time-based delay memory method for releasing to bring.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of making, be equal to replacement, improvement etc., within all should being included in the scope of protection of the invention.