Summary of the invention
In order to solve problems of the prior art, the invention provides a kind of input and output (IO) flow control methods and device of SSD buffer memory, it dynamically controls according to the IO flow of external disk the IO flow that enters SSD buffer memory, and the maximized SSD of utilization space and performance are met consumers' demand.
For realizing the iostream amount control method of a kind of SSD buffer memory that the object of the invention provides, comprise the steps:
Step S100, the data in magnetic disk of intercepting and capturing disk read-write process or thread, is cached in SSD buffer storage space data in magnetic disk as data cached;
Whether step S200, detect in SSD buffer storage and by buffer memory, to empty thread and empty outside destination disc by data cached; If so, enter step S500; Otherwise enter step S300;
Step S300, the usage space of the solid state hard disc that statistics is used as buffer memory, obtains SSD buffer memory utilization rate, and when SSD buffer memory utilization rate exceedes the first pre-set ratio, enters step S400;
Step S400, starts buffer memory and empties thread, by buffer memory, empties thread, and the data cached speed that empties of answering by predefined reference factor pair, by the data cached destination disc that empties in SSD buffer storage;
Step S500, calculates and generates scale factor, and according to scale factor, SSD buffer storage is carried out to the data cached speed adjustment that empties, to the flow control of SSD buffer memory, until the buffer memory utilization rate of SSD buffer storage is lower than predefined the second pre-set ratio.
More preferably, as an embodiment, described step S200 comprises the steps:
Step S210, judges whether that data cached in SSD buffer storage emptied to thread by buffer memory empties outside destination disc;
Step S220, empties outside destination disc if judgement does not empty thread by data cached in SSD buffer storage by buffer memory, enters step S300, monitors it and whether reaches buffer memory and empty thread entry condition and notify and start buffer memory and empty thread; Otherwise jump to step S500, monitoring buffer memory empties speed.
More preferably, as an embodiment, described step S500 comprises the steps:
Step S510, by in the data cached process that is written to destination disc, cumulative statistics writes the data cached byte length of writing IO of SSD buffer storage, it is the IO inflow velocity of SSD buffer storage, and accumulative total is write out SSD Cache Statistics flush byte length, be the data cached speed that empties in SSD buffer memory disk, calculate the scale factor generating in SSD buffer storage;
Step S520, the compared proportions factor and the reference factor, adjust buffer memory according to comparative result and empty speed, empties speed, by the data cached destination disc that empties in SSD buffer storage with new buffer memory;
Step 530, writes back to the data in SSD buffer memory after destination disc, continues the each of record statistics SSD buffer storage and writes the byte length writing out, and discharge corresponding SSD buffer storage space, and statistics obtains the buffer memory utilization rate of SSD buffer storage;
Step S540, judges that whether the buffer memory utilization rate of SSD buffer storage is lower than the second pre-set ratio; If so, finishing buffer memory empties thread and returns; Otherwise, return to step S510, loop flow control.
More preferably, as an embodiment, in described step S520, according to comparative result, adjust buffer memory and empty speed, comprise the steps:
Step S521, if proportional factor r atio is more than or equal to reference factor R efRatio, shows that inflow velocity is more than or equal to flush speed, according to the value of proportional factor r atio, adjusts flush speed, makes inflow velocity be less than or equal to flush speed, i.e. vi≤vf;
Step S522, if proportional factor r atio is less than reference factor R efRatio, shows that inflow velocity is less than flush speed, and flush speed v f is constant.
More preferably, as an embodiment, described predefined the first pre-set ratio is 70%~90%;
Described predefined the second pre-set ratio is 20%~30%.
More preferably, as an embodiment, wherein, in described step S510, described according to the byte length of writing IO of cumulative statistics and flush byte length, calculate proportional factor r atio and be:
If inflow velocity is vi, flush speed is vf, reference factor R efRatio:
Ratio=(vi/vf)*RefRatio;
Wherein, in described step S521, if proportional factor r atio is greater than reference factor R efRatio, flush speed v f=vi*(ratio/RefRatio);
Wherein, in described step S522, if proportional factor r atio is less than reference factor R efRatio, flush speed v f remains unchanged.
For realizing the object of the invention, also provide a kind of SSD buffer storage, comprise as being connected to the solid-state hard disk SSD as buffer memory on external disk, also comprise buffer control device;
Described buffer control device, comprises intercepting and capturing module, detection module, and statistical module, empties processing module, calculates and adjusts control module;
Wherein:
Described intercepting and capturing module, for intercepting and capturing the data in magnetic disk of disk read-write process or thread, is cached in solid-state hard disk SSD data in magnetic disk as data cached;
Described detection module, empties thread for detection of whether by buffer memory and empties outside destination disc by data cached; If so, forwarding calculating adjustment control module to processes; Otherwise forwarding statistical module to processes;
Described statistical module, for adding up the usage space of solid state hard disc, obtains SSD buffer memory utilization rate, and when SSD buffer memory utilization rate exceedes the first pre-set ratio, enters and empty processing module;
The described processing module that empties, empties thread for starting buffer memory, by buffer memory, empties thread, and the data cached speed that empties of answering by predefined reference factor pair, by the data cached destination disc that empties in SSD buffer storage;
Control module is adjusted in described calculating, be used for calculating generation scale factor, and according to scale factor, SSD buffer storage is carried out to the data cached speed adjustment that empties, to the flow control of SSD buffer memory, until the buffer memory utilization rate of SSD buffer storage is lower than predefined the second pre-set ratio.
More preferably, as an embodiment, described detection module comprises judgement submodule, and submodule is processed in judgement, wherein:
Described judgement submodule, for judging whether that SSD buffer storage data cached emptied to thread by buffer memory empties outside destination disc;
Submodule is processed in described judgement, if solid state hard disc data cached do not emptied to thread by buffer memory for judgement, empty outside destination disc, forward statistical module to, monitor its whether reach buffer memory empty thread entry condition and notify start buffer memory empty thread; Otherwise jump to calculate, adjust control module, monitoring buffer memory empties speed.
More preferably, as an embodiment, control module is adjusted in described calculating, comprises calculating sub module, relatively adjusts submodule, discharges submodule, and judgement finishes submodule;
Wherein:
Described calculating sub module, for by the data cached process that is written to destination disc, cumulative statistics writes the data cached byte length of writing IO of SSD buffer storage, it is the IO inflow velocity of SSD buffer storage, and accumulative total is write out SSD Cache Statistics flush byte length, be the data cached speed that empties in SSD buffer memory disk, calculate the scale factor generating in SSD buffer storage;
The described submodule of relatively adjusting, for the compared proportions factor and the reference factor, adjusts buffer memory according to comparative result and empties speed, empties speed, by the data cached destination disc that empties in SSD buffer storage with new buffer memory;
Described release submodule, for the data of SSD buffer memory are write back to after destination disc, continue the each of record statistics SSD buffer storage and write the byte length writing out, and discharge corresponding SSD buffer storage space, statistics obtains the buffer memory utilization rate of SSD buffer storage;
Described judgement finishes submodule, for the buffer memory utilization rate that judges SSD buffer storage whether lower than the second pre-set ratio; If so, finishing buffer memory empties thread and returns; Otherwise, return to calculating sub module, loop flow control.
The invention has the beneficial effects as follows:
Input and output (IO) flow control methods and the device of SSD buffer memory of the present invention, it is according to the IO flow of external disk, dynamically control the IO flow that enters SSD buffer memory, it can realize the accurate control of flow between multiple threads, and according to SSD buffer memory free space, automatically adjust the scale factor of control, according to current resource situation, as much as possible meet user and write inbound traffics request, the maximized SSD of utilization space and performance are met consumers' demand.
Embodiment
In order to solve problems of the prior art, to IO, provide better service quality, in the embodiment of the present invention, by service condition and the flush(in monitoring SSD buffer memory (SSD Cache) device space, empty buffer memory) speed, dynamically adjust inflow and outflow IO speed.
The physical space of the SSD buffer storage using as buffer memory is limited, write certain data cached after, this SSD buffer storage space can be fallen by slow consumption, clearance spaces reduces gradually, if do not do any processing, when clearance spaces is zero, just can not do caching process to write request.Therefore, need to monitor and adjust SSD buffer storage space, and by data cached (taking spatial cache) flush of buffer memory in destination disc, in this process, the variation in SSD buffer storage space depends on the write request speed (inflow velocity) that enters and the speed (rate of outflow) of flush, controlled in order to accomplish SSD buffer storage space, just need to control the inflow and outflow speed of SSD buffer storage.
In the embodiment of the present invention, when carrying out the monitoring of SSD buffer storage, consider following 3 kinds of situations: be 1) that SSD buffer storage space is enough, do not need to control SSD buffer storage inflow and outflow IO speed; 2) be that SSD buffer storage space is about to be exhausted, for guaranteeing that flowing into IO speed is less than or equal to the IO speed that flows out, need dynamically to adjust SSD buffer storage inflow and outflow IO speed; 3) having the inflow and outflow of read-write IO(SSD buffer storage to exist simultaneously) in the situation that, guaranteeing under the correct prerequisite of processing of read-write IO, by the data flush of SSD buffer storage to destination disc, guarantee to finish within the limited time.
As a kind of embodiment, as shown in Figure 1, input and output (IO) flow control methods of a kind of SSD buffer memory of the embodiment of the present invention, comprises the steps:
Step S100, the data in magnetic disk of intercepting and capturing disk read-write process or thread, is cached in SSD buffer storage space data in magnetic disk as data cached;
Computer user can utilize multiple processes of user's state or thread by known kernel system API(Application Programming Interface, application programming interface) carry out read-write cache data, and because read-write destination disc speed is relatively slow, therefore can accelerate (uf<us) storage by SSD buffer memory (cache) device space.
Normally, by core A PI, intercept and capture the read-write requests of described multiple processes or thread, can by slow disk, change its destination address into solid state hard disc (SSD) that speed is used as buffer memory (cache), be to carry out buffer memory in SSD buffer storage space, data in magnetic disk is cached in SSD buffer storage space as data cached;
Whether step S200, detect in SSD buffer storage and by buffer memory, to empty thread (flush thread) and empty outside destination disc by data cached; If so, enter step S500; Otherwise enter step S300;
Preferably, as a kind of embodiment, described step S200 comprises the steps:
Step S210, judges whether that data cached in SSD buffer storage emptied to thread (flush thread) by buffer memory empties outside destination disc;
It is a kind of prior art that buffer memory empties thread (flush thread), therefore, in embodiments of the present invention, describes in detail no longer one by one.
Data cached the emptying (flush) occurring in SSD buffer storage includes but not limited to 1 to the situation of outside destination disc) SSD buffer storage insufficient space; 2) user operates to control and starts buffer memory and empty thread to empty (flush) data cached; 3) user preset condition meets, and computer memory system starts buffer memory and empties thread and empty etc.
Step S220, if judgement does not empty thread by data cached in SSD buffer storage by buffer memory and empties (flush) to outside destination disc, enter step S300, the buffer memory of monitoring in its SSD buffer storage that whether reaches the embodiment of the present invention empties thread (flush thread) entry condition and notifies startup buffer memory to empty thread; Otherwise jump to step S500, monitoring buffer memory empties speed.
If SSD buffer storage does not empty thread by buffer memory and empties (flush), this SSD buffer storage does not also need to carry out flow control, but along with the carrying out of continuous buffer memory input and output (IO), the not usage space of SSD buffer storage is slowly occupied, in order to carry out flow control, enter step S300 and continue monitoring.
Step S300, the usage space of the solid state hard disc (SSD) that statistics is used as buffer memory (cache), draw the data cached space of buffer memory and the not ratio of usage space in SSD spatial cache, obtain it and use number percent, it is SSD buffer memory utilization rate, and when SSD buffer memory utilization rate exceedes the first pre-set ratio, enter step S400;
As a kind of embodiment, preferably, predefined the first pre-set ratio is 70%~90%, when SSD buffer memory utilization rate is more than or equal to 70%~90% in step S300, jumps to step S400, starts flush thread; Otherwise circle statistics is usage space.
More preferably, as a kind of embodiment, according to the ratio of the clearance spaces of spatial cache, whether exceed the first pre-set ratio 80%, determine whether to start flush thread, if the i.e. clearance spaces less than 20% of SSD buffer storage, be SSD buffer memory utilization rate while being more than or equal to 80%, notice starts flush thread, enters step S400.
As a kind of embodiment, in monitor procedure, flush thread waits is set, check controlled condition (detect and whether be more than or equal to pre-set ratio), once satisfy condition, notify this flush thread to start.
Step S400, start buffer memory and empty thread (flush thread), by buffer memory, empty thread (flush thread), by the data cached speed (flush) that empties corresponding to predefined reference factor R efRatio, data cached the emptying (flush) in SSD buffer storage arrived to destination disc;
Wherein, as a kind of embodiment, described reference factor R efRatio is default unsigned int constant, and this reference factor R efRatio obtains based on experience value, when it empties corresponding flush speed, read-write is controlled in dynamic balance state.
Step S500, calculate and generate proportional factor r atio, and according to proportional factor r atio, SSD buffer storage is carried out to the data cached speed adjustment that empties, to the flow control of SSD buffer memory, until the buffer memory utilization rate of SSD buffer storage is lower than predefined the second pre-set ratio.
Preferably, predefined the second pre-set ratio is 20%~30%, and when in step S500, SSD buffer memory utilization rate is less than or equal to 20%~30%, result flush thread also returns; Otherwise loop traffic monitoring.
Preferably, as a kind of embodiment, described step S500 comprises the steps:
Step S510, by in the data cached process that is written to destination disc, cumulative statistics writes the data cached byte length of writing IO of SSD buffer storage, it is the IO inflow velocity of SSD buffer storage, and accumulative total is write out SSD Cache Statistics flush byte length, be the data cached speed (flush speed) that empties in SSD buffer memory disk, calculate the scale factor generating in SSD buffer storage;
In the embodiment of the present invention, byte length correspondence writes writes out (IO) transmission bandwidth (speed), by statistics byte length, has also just added up to write and has write out (IO) bandwidth (speed).
In the read/writing control method of the embodiment of the present invention, preferably, as a kind of embodiment, in step S510, according to the byte length of writing IO of cumulative statistics, i.e. the IO inflow velocity of SSD buffer storage, and flush byte length, be the flush speed in SSD buffer memory disk, calculate adjustment proportional factor ratio.
As a kind of embodiment, according to the byte length of writing IO of cumulative statistics and flush byte length, calculate proportional factor r atio:
If inflow velocity is vi, flush speed is vf: and vi/vf=ratio/RefRatio, that is:
Ratio=(vi/vf)*RefRatio。
Due to when starting to carry out traffic monitoring, the rate of outflow can be greater than inflow velocity, and therefore, scale factor is less than reference factor R efRatio.
Step S520, compared proportions factor ratio and reference factor R efRatio, adjust buffer memory according to comparative result and empty speed, empties speed, by the data cached destination disc that empties in SSD buffer storage with new buffer memory.
Preferably, as a kind of embodiment, described step S520 adjusts buffer memory according to comparative result and empties speed, comprises the steps:
Step S521, if proportional factor r atio is more than or equal to reference factor R efRatio, show that inflow velocity (writing IO to SSD buffer storage) is more than or equal to flush speed (flush goes out SSD buffer storage to destination disc), therefore, according to the value of proportional factor r atio, adjust flush speed, make inflow velocity be less than or equal to flush speed, i.e. vi<=vf;
As a kind of embodiment, if proportional factor r atio is greater than reference factor R efRatio, flush speed v f=vi*(ratio/RefRatio), replace original flush speed, continue the data cached destination disc that empties in SSD buffer storage.
Step S522, if proportional factor r atio is less than reference factor R efRatio, show that inflow velocity (writing IO to SSD buffer storage) is less than flush speed (flush goes out SSD buffer storage to destination disc), the free space of SSD buffer storage can bear the pressure that inflow velocity vi is fast brought than flush speed, and flush speed v f is constant.
In the embodiment of the present invention, preferably, if proportional factor r atio is less than reference factor R efRatio, vf remains unchanged, and it is constant that buffer memory empties speed v f, continues the data cached destination disc that empties in SSD buffer storage.
In the embodiment of the present invention, by controlling buffer memory, empty speed v f, thereby effectively empty data cached in SSD buffer storage, until the buffer memory utilization rate of SSD buffer storage is lower than the second pre-set ratio.
Step 530, data in SSD buffer memory are write back to after destination disc, continue the each of record statistics SSD buffer storage and write the byte length that writes out (IO), and discharge corresponding SSD buffer memory (cache) device space, statistics obtains the buffer memory utilization rate of SSD buffer storage;
Step S540, judges that whether the buffer memory utilization rate of SSD buffer storage is lower than the second pre-set ratio; If so, finish flush thread and return; Otherwise, return to step S510, loop flow control.
As a kind of embodiment, can finish flush thread and return by Write IO API, complete the flow control of this SSD buffer storage.
Correspondingly, based on same inventive concept, the embodiment of the present invention also provides a kind of SSD buffer storage.The principle of dealing with problems due to this device and the similar process of aforementioned a kind of SSD cache flow amount control method, therefore, the enforcement of this device can be passed through preceding method specific implementation, repeats part and repeats no more.
As shown in Figure 2, a kind of SSD buffer storage of the embodiment of the present invention, comprises as being connected to the solid state hard disc as buffer memory (SSD) 100 on external disk, also comprises buffer control device 200.
Described buffer control device 200, comprises and intercepts and captures module 210, detection module 220, and statistical module 230, empties processing module 240, calculates and adjusts control module 250;
Wherein:
Described intercepting and capturing module 210, for intercepting and capturing the data in magnetic disk of disk read-write process or thread, is cached in solid-state hard disk SSD data in magnetic disk as data cached;
Described detection module 220, empties thread (flush thread) for detection of whether by buffer memory and empties outside destination disc by data cached; If so, forwarding calculating adjustment control module to processes; Otherwise forwarding statistical module to processes;
Described statistical module 230, for adding up the usage space of solid state hard disc (SSD), obtains SSD buffer memory utilization rate, and when SSD buffer memory utilization rate exceedes the first pre-set ratio, enters and empty processing module;
The described processing module 240 that empties, be used for starting buffer memory and empty thread (flush thread), by buffer memory, empty thread (flush thread), by the data cached speed (flush) that empties corresponding to predefined reference factor R efRatio, data cached the emptying (flush) in SSD buffer storage arrived to destination disc;
Control module 250 is adjusted in described calculating, be used for calculating generation proportional factor r atio, and according to proportional factor r atio, SSD buffer storage is carried out to the data cached speed adjustment that empties, to the flow control of SSD buffer memory, until the buffer memory utilization rate of SSD buffer storage is lower than predefined the second pre-set ratio.
Preferably, as a kind of embodiment, described detection module 220 comprises and judges submodule 221, and submodule 222 is processed in judgement, wherein:
Described judgement submodule 221, for judging whether that SSD buffer storage data cached emptied to thread (flush thread) by buffer memory empties outside destination disc;
Submodule 222 is processed in described judgement, if solid state hard disc data cached do not emptied to thread by buffer memory for judgement, empty (flush) to outside destination disc, forward statistical module to, monitor its whether reach buffer memory empty thread (flush thread) entry condition and notify start buffer memory empty thread; Otherwise jump to calculate, adjust control module, monitoring buffer memory empties speed.
Preferably, as a kind of embodiment, described predefined the first pre-set ratio is 70%~90%, and more preferably, described the first pre-set ratio is 80%.Described predefined the second pre-set ratio is 20%~30%.
Preferably, as a kind of embodiment, control module 250 is adjusted in described calculating, comprises calculating sub module 251, relatively adjusts submodule 252, discharges submodule 253, and judgement finishes submodule 254, wherein:
Described calculating sub module 251, for by the data cached process that is written to destination disc, cumulative statistics writes the data cached byte length of writing IO of SSD buffer storage, it is the IO inflow velocity of SSD buffer storage, and accumulative total is write out SSD Cache Statistics flush byte length, be the data cached speed (flush speed) that empties in SSD buffer memory disk, calculate the scale factor generating in SSD buffer storage;
More preferably, as a kind of embodiment, according to the byte length of writing IO of cumulative statistics and flush byte length, calculate proportional factor r atio:
If inflow velocity is vi, flush speed is vf: and vi/vf=ratio/RefRatio, that is:
Ratio=(vi/vf)*RefRatio。
The described submodule 252 of relatively adjusting, for compared proportions factor ratio and reference factor R efRatio, adjusts buffer memory according to comparative result and empties speed, empties speed, by the data cached destination disc that empties in SSD buffer storage with new buffer memory.
If proportional factor r atio is more than or equal to reference factor R efRatio, show that inflow velocity (writing IO to SSD buffer storage) is more than or equal to flush speed (flush goes out SSD buffer storage to destination disc), therefore, according to the value of proportional factor r atio, adjust flush speed, make inflow velocity be less than or equal to flush speed, i.e. vi<=vf;
As a kind of embodiment, if proportional factor r atio is greater than reference factor R efRatio, flush speed v f=vi*(ratio/RefRatio), replace original flush speed, continue the data cached destination disc that empties in SSD buffer storage.
If proportional factor r atio is less than reference factor R efRatio, show that inflow velocity (writing IO to SSD buffer storage) is less than flush speed (flush goes out SSD buffer storage to destination disc), the free space of SSD buffer storage can bear the pressure that inflow velocity vi is fast brought than flush speed, and flush speed is constant.
In the embodiment of the present invention, preferably, if proportional factor r atio is less than reference factor R efRatio, vf remains unchanged, and it is constant that buffer memory empties speed, by the data cached destination disc that empties in SSD buffer storage.
Described release submodule 253, for the data of SSD buffer memory are write back to after destination disc, continue each byte length that writes out (IO) that writes of record statistics SSD buffer storage, and discharging corresponding SSD buffer memory (cache) device space, statistics obtains the buffer memory utilization rate of SSD buffer storage;
Described judgement finishes submodule 254, for the buffer memory utilization rate that judges SSD buffer storage whether lower than the second pre-set ratio; If so, finish flush thread and return; Otherwise, return to calculating sub module, loop flow control.
Input and output (IO) flow control methods and the device of the SSD buffer memory of the embodiment of the present invention, it is according to the IO flow of external disk, dynamically control the IO flow that enters SSD buffer memory, it can realize the accurate control of flow between multiple threads, and according to SSD buffer memory free space, automatically adjust the scale factor of control, according to current resource situation, as much as possible meet user and write inbound traffics request, the maximized SSD of utilization space and performance are met consumers' demand.
Finally, it should be noted that, in this patent document, the relational terms such as first, second grade is only for an entity or operation are separated with another entity or operational zone, and not necessarily requires or imply and between these entities or operation, have any relation or sequentially.And, in this patent document, term " comprises ", " comprising " or its any other variant, it is intended to contain but not exclusive inclusion, thereby make to comprise process, method, article or the equipment of a series of key elements, not only comprise these key elements, but also comprise and clearly not listing and other key elements that those skilled in the art can know, or be also included as the known requisite key element of these processes, method, article or equipment.
The above embodiment has only expressed several embodiment of the present invention, and it describes comparatively concrete and detailed, but can not therefore be interpreted as the restriction to the scope of the claims of the present invention.It should be pointed out that for the person of ordinary skill of the art, without departing from the inventive concept of the premise, can also make some distortion and improvement, these all belong to protection scope of the present invention.Therefore, the protection domain of patent of the present invention should be as the criterion with claims.