Disclosure of Invention
The invention aims to solve the technical problems that the prior art has the defects, and provides a data writing control method, a system, a terminal and a medium, so that the problems that all data in a cache can be refreshed at one time in the prior art, the performance of data writing is reduced, the efficiency of data writing is also reduced and the like are solved.
In order to solve the technical problems, the technical scheme adopted by the invention is as follows:
In a first aspect, the present invention provides a data writing control method, where the method includes:
receiving a data writing request, and determining a request terminal corresponding to the data writing request;
based on the request terminal, determining a request type corresponding to the data writing request, wherein the request type comprises a write-back request or a write-through request;
And acquiring the write-in data corresponding to the data write-in request, and updating the data based on the request type and the write-in data.
In one implementation, receiving a data writing request, determining a request terminal corresponding to the data writing request, and including:
receiving a data writing request, and analyzing the data writing request to obtain equipment information carried in the data writing request;
and determining the request terminal based on the equipment information.
In one implementation, before receiving a data writing request and determining a request terminal corresponding to the data writing request, the method includes:
acquiring equipment information of the request terminal in advance;
And generating the data writing request based on the equipment information and the writing data.
In one implementation, determining, based on the request terminal, a request type corresponding to the data writing request includes:
The marking information corresponding to the request terminal is obtained, wherein the marking information is used for marking the writing data of the data writing request;
determining a writing type of the writing data based on the mark information, wherein the writing type comprises write-through writing or write-back writing;
Based on the write type, the request type is determined.
In one implementation, obtaining the write data corresponding to the data write request, and updating the data based on the request type and the write data, includes:
acquiring write data in the data write request;
acquiring first cache data in a buffer memory and second cache data in a preset random access memory;
when the request type is a write-through request, updating the first cache data and the second cache data based on the write-in data;
When the request type is a write-back request, updating only the first cache data based on the write-in data.
In one implementation, obtaining the write data corresponding to the data write request, and updating the data based on the request type and the write data, further includes:
When the request type is a write-back request and the updating of the first cache data is finished, acquiring the running state of a data writing process;
and if the running state is idle, updating the second cache data in the random access memory based on the written data.
In one implementation, obtaining the write data corresponding to the data write request, and updating the data based on the request type and the write data, further includes:
if the running state is non-idle, determining the residual storage capacity of the random access memory;
If the residual storage capacity is larger than or equal to the data volume of the written data, determining to-be-outputted data in the second cache data based on a first-in first-out principle;
and replacing the data to be output in the second cache data with the write-in data.
In a second aspect, an embodiment of the present invention further provides a data writing control system, where the system is configured to implement the steps of the data writing control method described in the foregoing solution, and the system includes:
The request terminal determining module is used for receiving a data writing request and determining a request terminal corresponding to the data writing request;
The request type determining module is used for determining a request type corresponding to the data writing request based on the request terminal, wherein the request type comprises a write-back request or a write-through request;
And the data updating module is used for acquiring the write-in data corresponding to the data write-in request and updating the write-in data based on the request type.
In a third aspect, an embodiment of the present invention further provides a terminal, where the terminal includes a memory, a processor, and a data write control program stored in the memory and capable of running on the processor, and when the processor executes the data write control program, the processor implements the steps of the data write control method in any one of the above schemes.
In a fourth aspect, an embodiment of the present invention further provides a computer readable storage medium, where a data writing control program is stored on the computer readable storage medium, where the data writing control program, when executed by a processor, implements the steps of the data writing control method according to any one of the above schemes.
Compared with the prior art, the data writing control method has the advantages that the data writing control method is provided, firstly, the data writing request is received, and the request terminal corresponding to the data writing request is determined. Then, based on the request terminal, a request type corresponding to the data writing request is determined, wherein the request type comprises a write-back request or a write-through request. And finally, acquiring the write-in data corresponding to the data write-in request, and updating the data based on the request type and the write-in data. The invention can determine whether the request type of the data writing request is a write-back request or a write-through request, thus updating the data based on the request type and improving the data updating efficiency.
Detailed Description
In order to make the objects, technical solutions and effects of the present invention clearer and more specific, the present invention will be described in further detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
The flow diagrams depicted in the figures are merely illustrative and not necessarily all the elements and operations or steps are included or performed in the order described. For example, some operations or steps may be further divided, combined, or partially combined, so that the order of actual execution may be changed according to actual situations.
It is to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be understood that, in order to clearly describe the technical solutions of the embodiments of the present invention, in the embodiments of the present invention, the words "first", "second", etc. are used to distinguish identical items or similar items having substantially the same function and effect. For example, the first control information and the second control information are merely for distinguishing different control information, and the order of the different control information is not limited.
It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
It should also be understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
In order to solve the problems in the prior art, the present embodiment provides a data writing control method, which can identify a data writing request based on the method of the present embodiment, determine whether a request type is a write-back request or a write-through request, and further perform targeted refreshing for different request types when refreshing data, thereby improving the data refreshing efficiency. In a specific application, the embodiment may first receive a data writing request, and determine a request terminal corresponding to the data writing request. Then, based on the request terminal, a request type corresponding to the data writing request is determined, wherein the request type comprises a write-back request or a write-through request. And finally, acquiring the write-in data corresponding to the data write-in request, and updating the data based on the request type and the write-in data.
The data writing control method of the embodiment can be applied to a terminal, and the terminal can be an intelligent product terminal such as a mobile phone, a computer and an intelligent television. As shown in fig. 1, the data write control method includes the steps of:
Step S100, a data writing request is received, and a request terminal corresponding to the data writing request is determined.
When data writing or data refreshing is performed, the terminal receives a data writing request and requests to write the data into the terminal, and when the method is actually applied, the embodiment can analyze the data writing request and determine the request terminal corresponding to the data writing request, namely, determine which client the data writing request is sent.
In one implementation, when determining the request terminal, the embodiment includes the following steps:
step S101, a data writing request is received, and the data writing request is analyzed to obtain equipment information carried in the data writing request;
step S102, determining the request terminal based on the equipment information.
Specifically, the embodiment obtains, in advance, device information of the request terminal, where the device information may be a model number of the request terminal or a device name of the request terminal, and then generates the data write request based on the device information and write data, that is, data to be updated for the terminal. The data write request generated at this time carries the device information. After receiving the data writing request, the terminal can analyze the data writing request, and then obtain the content carried in the data writing request, and also obtain the equipment information, so that the request terminal can be determined based on the equipment information. The embodiment determines that the request terminal can conveniently determine the request type of the data writing request based on the request terminal in the subsequent step.
Step 200, determining a request type corresponding to the data writing request based on the request terminal, wherein the request type comprises a write-back request or a write-through request.
When the request terminal is determined, the embodiment can determine the request type of the issued data writing request based on the request terminal, wherein the request type comprises a write-back request or a write-through request, thereby realizing the identification of the request type and facilitating the realization of data refreshing based on the request type in the subsequent steps.
In one implementation, when determining a request type of a data write request, the present embodiment includes the following steps:
step S201, marking information corresponding to the request terminal is obtained, wherein the marking information is used for marking the writing data of the data writing request;
Step S202, determining the writing type of the writing data based on the mark information, wherein the writing type comprises direct writing or write-back writing;
step S203, determining the request type based on the write type.
Specifically, in this embodiment, the request terminals are divided in advance into a first terminal for sending a write-through request and a second terminal for sending a write-back request, and different marking information is used for the first terminal and the second terminal, for example, a first mark is used for the first terminal, and a second mark is used for the second terminal. Meanwhile, when the first terminal or the second terminal generates the data writing request, the writing data in the data writing request can be marked by adopting corresponding marking information. In this embodiment, after determining the request terminal, the tag information corresponding to the request terminal may be determined, for example, if the request terminal is a first terminal, the tag information is a first tag, and if the request terminal is a second terminal, the tag information is a second tag. Since the write data in the data write request has been marked using the corresponding mark information, it is determined whether the write data corresponds to the first mark or the second mark at this time, and based on this, it is determined whether the write type of the write data is write-through type write or write-back type write. Correspondingly, if the written data corresponds to the first mark, the writing type of the written data is direct writing, and if the written data corresponds to the second mark, the writing type of the written data is write-back writing. Thus, the request type is also determined based on the write type. The method and the device can determine the request type more conveniently by analyzing the marking information of the request terminal.
Step S300, obtaining the write-in data corresponding to the data write-in request, and updating the data based on the request type and the write-in data.
After determining the request type corresponding to the data writing request, the embodiment can acquire the corresponding writing data, and then update the data in the terminal based on the request type and the writing data. Since different request types are different for the data updating manner, the embodiment can update the data in a targeted manner based on the request types, thereby improving the data updating efficiency.
In one implementation, the method in this embodiment includes the following steps when performing data update:
step S301, obtaining write data in the data write request;
Step S302, obtaining first cache data in a cache memory and second cache data in a preset random access memory;
Step S303, when the request type is a direct write request, updating the first cache data and the second cache data based on the write data;
and step S304, when the request type is a write-back request, updating only the first cache data based on the write-in data.
In the embodiment, the direct writing request and the write-back request are different for all data cached on the terminal, and the write-back request is for part of data cached on the terminal, and the embodiment determines that the request type is to update the data to be updated in a targeted manner, for example, if the request type is the direct writing request, all the data cached in the terminal can be updated, and if the request type is the write-back request, part of the data cached in the terminal can be updated, but not all the data can be updated, so that the data updating efficiency can be improved.
In order to better realize updating of data, the embodiment can distinguish data cached in the terminal, specifically, the buffer memory of the terminal stores first cached data, the terminal is further provided with a random access memory, and the random access memory stores second cached data, wherein the first cached data and the second cached data form all data cached on the terminal. In practical application, when the request type is determined to be a direct write request, the embodiment may update the first cache data in the buffer memory and the second cache data in the random access memory based on the write data, that is, implement the overall update of the data. When the request type is determined to be a write-back request, the embodiment may update only the first cache data in the buffer memory based on the write-in data. Therefore, when the request type is a write-back request, all data does not need to be updated, so that the data updating efficiency is improved.
In one implementation, when the request type is a direct write request, since all data needs to be updated based on the write data, a certain time is required, and in order to increase the data update speed and shorten the data update time, the embodiment may be implemented in a manner of simultaneous storage when all data is updated. Specifically, in this embodiment, the write data may be compared with the first cache data of the buffer memory of the terminal and the second cache data of the random access memory of the terminal, to determine whether the write data is partially identical to the first cache data or the second cache data, and if the write data is partially identical to the first cache data or the second cache data, it is determined that the difference data is partially identical, and in this embodiment, the data update may be completed only by updating the difference data to the terminal. Meanwhile, in order to find out the difference data as soon as possible, the embodiment may set a data type tag for the write-in data, and the first cache data and the second cache data also set data type tags, when the write-in data is compared with the first cache data of the buffer memory of the terminal and the second cache data of the random access memory of the terminal respectively, it may be determined whether the data type tags are the same first, if the data type tags are different, it is indicated that the write-in data and the first cache data or the second cache data do not have the same data, and at this time, the write-in data needs to be updated to the terminal entirely, that is, the write-in data needs to be updated to the first cache data of the buffer memory and the second cache data of the random access memory entirely. If the data type labels are the same, further determining whether the data content is the same, finding out the part with the difference of the data content to obtain difference data, and updating the data of the terminal based on the difference data, namely updating the difference data into the first cache data of the buffer memory and the second cache data of the random access memory. Based on the update mode of the copy-save, the data update efficiency when the request type is the write-through request can be effectively improved.
Further, in this embodiment, only the first cache data in the buffer memory of the terminal is updated when the request type is a write-back request, so as to ensure the consistency of the data, in this embodiment, after the request type is the write-back request and the update of the first cache data is finished, the running state of the data writing process may be obtained, and then whether the update of the second cache data is required is determined based on the running state. Specifically, if the running state is idle, it indicates that a data update thread of the system is available at the moment, so that at the moment, the second cache data in the random access memory can be updated based on the written data, thereby implementing peak-shifting update of the first cache data and the second cache data and improving the efficiency of data update. And when the running state is not idle, determining the residual storage capacity of the random access memory. If the remaining storage capacity is greater than or equal to the data amount of the write data, it indicates that the capacity of the random access memory is sufficient at this time, and there may be enough space to accommodate the write data. However, since the running state of the data writing process at this time is not idle, which means that the data is being updated at this time, in order to reduce occupation of the data writing process, the embodiment may determine the to-be-output data in the second cache data based on the principle of first-in first-out, where the to-be-output data may be the data stored first in the second cache data, and these data may have been stored in the random access memory for a longer time, and the embodiment may use this portion of data as the to-be-output data, and then replace the to-be-output data in the second cache data with the written data. Because the data to be output is only a part of the second cache data, and the determined data quantity of the data to be output is the same as that of the written data, too many data updating threads are not occupied when the data is updated, and the implementation is convenient. In addition, the embodiment can shift the determined data to be output to other memories so as to facilitate the tracing when the data is needed later. In addition, when the second cache data is updated based on the write data, the embodiment can also be realized based on the mode of removing the coexistence difference in the scheme, so that the data updating efficiency is further improved.
In other implementations, when there are multiple clients sending data writing requests at the same time, the embodiment may analyze each data writing request and determine a request type corresponding to each data writing request, and when the request types are inconsistent, for example, there is a write-back request and a write-through request, the embodiment may change a data writing policy of the write-through request to ensure normal operation of a data writing process. Specifically, if the write-through request and the write-back request exist simultaneously, the data writing process is crowded, so that in order to reduce occupation of the data writing process, the embodiment can preferably select to update the first cache data of the buffer memory, so that when the write-through request is processed, the embodiment also ensures update of the first cache data of the buffer memory first, and updates the second cache data of the random memory first, the embodiment can adopt a mapping synchronization mode, specifically, the writing data can be mapped into the random memory from the buffer memory, thereby enabling the writing data to be updated into the random memory data. Similarly, the write-back request is also to update only the first cache data of the buffer memory until the data writing process is idle, and then determine a proper time to consider whether to update the second cache data of the random access memory. In practical application, when processing a write-back request, the embodiment only needs to ensure the update of the first cache data in the buffer memory, and whether the write-back request updates the second cache data of the random access memory or not can be selectively executed based on the importance degree of the write-back data. Therefore, in this embodiment, the importance level tag may be set in advance for the write data, and when it is determined that the importance level of the write data is high based on the importance level tag, the second cache data of the random access memory may be selectively updated, or otherwise, the second cache data of the random access memory may be selectively not updated.
In summary, the present embodiment first receives a data writing request, and determines a request terminal corresponding to the data writing request. Then, based on the request terminal, a request type corresponding to the data writing request is determined, wherein the request type comprises a write-back request or a write-through request. And finally, acquiring the write-in data corresponding to the data write-in request, and updating the data based on the request type and the write-in data. The embodiment can determine whether the request type of the data writing request is a write-back request or a write-through request, so that the data can be updated based on the request type, and the data updating efficiency is improved.
Based on the above embodiment, the present invention also provides a data writing control system, which can be used to implement the steps of the data writing control method in the above embodiment, as shown in fig. 2, and includes a request terminal determining module 10, a request type determining module 20, and a data updating module 30. Specifically, the request terminal determining module 10 is configured to receive a data writing request, and determine a request terminal corresponding to the data writing request. The request type determining module 20 is configured to determine, based on the request terminal, a request type corresponding to the data writing request, where the request type includes a write-back request or a write-through request. The data updating module 30 is configured to obtain write data corresponding to the data write request, and update the write data based on the request type.
In one implementation, the request terminal determining module 10 includes:
the information determining unit is used for receiving a data writing request, analyzing the data writing request and obtaining equipment information carried in the data writing request;
and the terminal determining unit is used for determining the request terminal based on the equipment information.
In one implementation, the request terminal determining module 10 further includes:
an equipment information setting unit, configured to obtain equipment information of the request terminal in advance;
And the write request generation unit is used for generating the data write request based on the equipment information and the write data.
In one implementation, the request type determination module 20 includes:
A tag information obtaining unit, configured to obtain tag information corresponding to the request terminal, where the tag information is used to tag write data of the data write request;
a writing type determining unit configured to determine a writing type of writing data based on the mark information, the writing type including write-through writing or write-back writing;
and the request type determining unit is used for determining the request type based on the writing type.
In one implementation, the data update module 30 includes:
a write data acquisition unit configured to acquire write data in the data write request;
the cache data acquisition unit is used for acquiring first cache data in the cache memory and second cache data in the preset random access memory;
The first data updating unit is used for updating the first cache data and the second cache data based on the writing data when the request type is a direct writing request;
And the second data updating unit is used for updating only the first cache data based on the write-in data when the request type is a write-back request.
In one implementation, the data update module 30 further includes:
the running state determining unit is used for obtaining the running state of the data writing process after the request type is a write-back request and the updating of the first cache data is finished;
And the third data updating unit is used for updating the second cache data in the random access memory based on the written data if the running state is idle.
In one implementation, the data update module 30 further includes:
A remaining capacity determining unit, configured to determine a remaining storage capacity of the random access memory if the running state is not idle;
the to-be-output data determining unit is used for determining to-be-output data in the second cache data based on a first-in first-out principle if the residual storage capacity is larger than or equal to the data quantity of the written data;
and the data replacement unit is used for replacing the data to be output in the second cache data with the write data.
The working principle of each module in the data writing control system of this embodiment is the same as that of each step in the above method embodiment, and will not be described here again.
The various modules in the data writing control system described above may be implemented in whole or in part by software, hardware, or a combination thereof. The above modules may be embedded in hardware or independent of a processor in the terminal, or may be stored in software in a memory in the terminal, so that the processor may call and execute operations corresponding to the above modules.
Based on the above embodiment, the present invention also provides a terminal, and a schematic block diagram of the terminal may be shown in fig. 3. The terminal may include one or more processors 100 (only one shown in fig. 3), a memory 101, and a computer program 102 stored in the memory 101 and executable on the one or more processors 100, for example, a sleep analysis program based on multi-sensor data. The one or more processors 100, when executing the computer program 102, may implement the various steps in an embodiment of a sleep analysis method based on multi-sensor data. Or the one or more processors 100, when executing the computer program 102, may implement the functions of the various modules/units in the multi-sensor data based sleep analysis system embodiment, without limitation.
In one embodiment, the Processor 100 may be a central processing unit (Central Processing Unit, CPU), but may also be other general purpose processors, digital signal processors (DIGITAL SIGNAL processors, DSPs), application SPECIFIC INTEGRATED Circuits (ASICs), off-the-shelf Programmable gate arrays (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In one embodiment, the memory 101 may be an internal storage unit of the electronic device, such as a hard disk or a memory of the electronic device. The memory 101 may also be an external storage device of the electronic device, such as a plug-in hard disk provided on the electronic device, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, a flash memory card (FLASH CARD), or the like. Further, the memory 101 may also include both an internal storage unit and an external storage device of the electronic device. The memory 101 is used to store computer programs and other programs and data required by the terminal. The memory 101 may also be used to temporarily store data that has been output or is to be output.
It will be appreciated by those skilled in the art that the functional block diagram shown in fig. 3 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the terminal to which the present inventive arrangements may be applied, as a specific terminal may include more or less components than those shown, or may be combined with some components, or may have a different arrangement of components.
Those skilled in the art will appreciate that implementing all or part of the above-described methods may be accomplished by way of a computer program, which may be stored on a non-transitory computer readable storage medium, that when executed may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, operational database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual operation data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (SYNCHLINK) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
It should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention, and not for limiting the same, and although the present invention has been described in detail with reference to the above-mentioned embodiments, it should be understood by those skilled in the art that the technical solution described in the above-mentioned embodiments may be modified or some technical features may be equivalently replaced, and these modifications or substitutions do not make the essence of the corresponding technical solution deviate from the spirit and scope of the technical solution of the embodiments of the present invention.