Data writing control method and device, electronic equipment and storage medium

By setting the cache area in memory and judging the write strategy based on the remaining space and cache upper limit, the processor resource occupation and operation lag caused by writing data to the storage device is solved, and a more efficient data writing process is achieved.

CN120122882AActive Publication Date: 2025-06-10ZHONGKE FANGDE SOFTWARE CO LTD

Patent Information

Application Number
CN202510190030.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-06-10
Estimated Expiration
2045-02-20

AI Technical Summary

Technical Problem

Continuously occupies processor resources when writing data to storage devices, causing the electronic device to run stutter.

Method used

By setting the cache area in memory, we can judge the remaining space of the cache area and the cache upper limit value of the target storage device, and decide whether to write data directly to the storage device or to the cache area first.

Benefits of technology

This avoids the situation where the cache area is continuously insufficient, reduces the frequency of writing data from the cache area to the storage device, thereby avoiding the continuous occupation of processor resources and preventing the operation of electronic devices from being stuttered.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120122882A_ABST
    Figure CN120122882A_ABST
Patent Text Reader

Abstract

The invention discloses a data writing control method, which comprises the following steps of: in response to a data writing instruction, judging whether a first transfer condition is met or not; the data writing instruction is used for writing target data into target storage equipment from electronic equipment; the first transfer condition comprises that the residual space of a cache region is smaller than the data volume of the target data, or the corresponding cache data volume of the target storage device in the cache region reaches the cache upper limit value corresponding to the target storage device; the cache region is a region deployed in a memory space of the electronic equipment; under the condition that the first transfer condition is met, writing the first data in the cache region into a storage device corresponding to the first data; and under the condition that the first transfer condition is not met, writing the target data into the cache region, and under the condition that a second transfer condition is met, writing the data in the cache region into corresponding storage equipment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and in particular, to a method, apparatus, electronic device, and storage medium for controlling data writing. Background Art

[0002] Currently, when writing data to a storage device, the data is usually first written to a cache area in the memory space, and when conditions permit, the data in the cache area is then written to the storage device.

[0003] However, if continuously writing the data in the cache area to the storage device, it will occupy the processor resources and cause the processor to run in a stuttering manner. Summary of the Invention

[0004] In view of the above problems, this application provides a method, apparatus, electronic device, and storage medium for controlling data writing to avoid the electronic device running in a stuttering manner caused by continuously occupying the resources of the electronic device. The specific solutions are as follows:

[0005] A first aspect of this application provides a method for controlling data writing, the method including:

[0006] In response to a data writing instruction, determining whether a first transfer condition is satisfied; the data writing instruction is used to write target data from an electronic device to a target storage device;

[0007] Wherein, the first transfer condition includes: the remaining space of the cache area is less than the data volume of the target data, or, the cache data volume corresponding to the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device; the cache area is an area deployed in the memory space of the electronic device;

[0008] When the first transfer condition is satisfied, writing first data in the cache area to the storage device corresponding to the first data;

[0009] When the first transfer condition is not satisfied, writing the target data to the cache area, and the data in the cache area is written to the corresponding storage device when a second transfer condition is satisfied.

[0010] In a possible implementation, the method further includes:

[0011] Obtaining the device attributes of the target storage device; the device attributes include at least one of device name, interface type, transmission protocol, and storage capacity;

[0012] According to the device attributes, obtaining a first writing speed corresponding to the target storage device;

[0013] Obtain the cache upper limit value corresponding to the target storage device according to the first writing speed.

[0014] In a possible implementation, the method further includes:

[0015] Obtain a second writing speed, where the second writing speed is the real-time writing speed for writing the data in the cache area to the target storage device;

[0016] Update the cache upper limit value corresponding to the target storage device according to the second writing speed.

[0017] In a possible implementation, the method further includes:

[0018] For each of the storage devices, monitor whether the second transfer condition corresponding to the storage device is satisfied;

[0019] When the second transfer condition corresponding to the storage device is satisfied, screen the second data corresponding to the storage device in the cache area;

[0020] Write the second data to the corresponding storage device;

[0021] Wherein, the second transfer condition corresponding to the storage device includes: the time interval from the current moment to the previous time when the second data corresponding to the storage device is screened in the cache area reaches the interval threshold; the interval thresholds corresponding to different storage devices are the same or different.

[0022] In a possible implementation, screening the second data corresponding to the storage device in the cache area includes:

[0023] Screen the second data in the cache area according to the timeout duration corresponding to the storage device; the duration for which the second data is written to the cache area is greater than or equal to the timeout duration corresponding to the storage device.

[0024] In a possible implementation, the timeout duration corresponding to the storage device is determined based on the device type of the storage device;

[0025] Wherein, the device type indicates whether the storage device can be fixed relative to the electronic device.

[0026] In a possible implementation, when the second transfer condition corresponding to the storage device is satisfied, the method further includes:

[0027] Start a corresponding processing process for the storage device, where the processing process is used to screen the second data corresponding to the storage device in the cache area; write the second data to the corresponding storage device;

[0028] Among them, the second data screened out by the processing process is locked to prohibit other processing processes from processing.

[0029] The second aspect of the present application provides a control device for data writing, and the device includes:

[0030] A transfer judgment unit, configured to judge whether a first transfer condition is satisfied in response to a data writing instruction for writing target data from an electronic device to a target storage device;

[0031] Wherein, the first transfer condition includes: the remaining space in the cache area is less than the data volume of the target data, or the cache data volume corresponding to the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device; the cache area is an area deployed in the memory space of the electronic device;

[0032] A cache writing unit, configured to write the first data in the cache area to the storage device corresponding to the first data when the first transfer condition is satisfied;

[0033] A data writing unit, configured to write the target data to the cache area when the first transfer condition is not satisfied, and the data in the cache area is written to the corresponding storage device when a second transfer condition is satisfied.

[0034] The third aspect of the present application provides a computer program product, including computer-readable instructions, which, when running on an electronic device, enable the electronic device to implement the data writing control method according to the first aspect or any implementation manner of the first aspect.

[0035] The fourth aspect of the present application provides an electronic device, including at least one processor and a memory connected to the processor, wherein:

[0036] The memory is used to store a computer program;

[0037] The processor is configured to execute the computer program so that the electronic device can implement the data writing control method according to the first aspect or any implementation manner of the first aspect.

[0038] The fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the data writing control method according to the first aspect or any implementation manner of the first aspect.

[0039] With the above technical solutions, in a data writing control method, device, electronic device, and storage medium provided by this application, when writing target data to a target storage device, the target data is first written to a cache area in the memory, and then the data in the cache area is written to the target storage device when a second transfer condition is met. In a specific implementation, the target data is written to the cache area only when there is sufficient remaining space in the cache area and the amount of cached data corresponding to the target storage device in the cache area does not reach its corresponding cache upper limit value. Correspondingly, when the remaining space in the cache area is insufficient, the first data in the cache area can be written to the corresponding storage device, or when the amount of cached data corresponding to the target storage device in the cache area reaches its corresponding cache upper limit value, the first data in the cache area can be written to the corresponding storage device. Therefore, in this application, a limit condition that the data written to the cache area cannot exceed the corresponding cache upper limit value of the storage device is added, and an executable condition that the data written from the cache area to the storage device reaches the corresponding cache upper limit value of the storage device is added. This can avoid the situation where the cache area is continuously in a state of insufficient remaining space, and thus will not trigger continuous writing of data from the cache area to the storage device, thereby avoiding the situation where the electronic device runs stuck due to continuous occupation of electronic device resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In combination with the accompanying drawings and with reference to the following specific embodiments, the above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic and that the original elements and elements are not necessarily drawn to scale.

[0041] Figure 1 It is a flowchart of a data writing control method provided by an embodiment of this application;

[0042] Figure 2 It is an example diagram of a storage device in an embodiment of this application;

[0043] Figure 3 It is another example diagram of a storage device in an embodiment of this application;

[0044] Figure 4 It is an example diagram of triggering data writing in an embodiment of this application;

[0045] Figure 5 It is an example diagram of a cache area in an embodiment of this application;

[0046] Figure 6 It is a partial flowchart of a data writing control method provided by an embodiment of this application;

[0047] Figure 7Another part of the flowchart of a data writing control method provided by an embodiment of the present application;

[0048] Figure 8 Another part of the flowchart of a data writing control method provided by an embodiment of the present application;

[0049] Figure 9 Structural schematic diagram of a data writing control device provided by an embodiment of the present application;

[0050] Figure 10 Another structural schematic diagram of a data writing control device provided by an embodiment of the present application;

[0051] Figure 11 Another structural schematic diagram of a data writing control device provided by an embodiment of the present application;

[0052] Figure 12 Structural schematic diagram of an electronic device provided by an embodiment of the present application;

[0053] Figure 13 Flowchart of enabling write cache when an external storage device is accessed in a computer applicable to the Linux operating system according to the present application;

[0054] Figure 14 Flowchart of writing to an external storage device in a computer applicable to the Linux operating system according to the present application;

[0055] Figure 15 Flowchart of calculating the write speed of an external storage device in a computer applicable to the Linux operating system according to the present application;

[0056] Figure 16 Flowchart of writing when the dirty data page of an external storage device times out in a computer applicable to the Linux operating system according to the present application. Detailed implementation manners

[0057] The embodiments of the present application will be described below with reference to the accompanying drawings in the embodiments of the present application. The terms used in the embodiments of the present application are only for explaining the specific embodiments of the present application, rather than aiming to limit the present application.

[0058] The embodiments of the present application will be described below with reference to the accompanying drawings. Those of ordinary skill in the art will know that with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.

[0059] In the description, claims and the above-mentioned drawings of this application, terms such as "first" and "second" are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that such terms can be interchanged under appropriate circumstances, which is only a way of distinguishing objects with the same attributes when describing embodiments of this application. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion, so that a process, method, system, product or device including a series of units does not have to be limited to those units, but may include other units not clearly listed or inherent to these processes, methods, products or devices.

[0060] Referring to Figure 1 , which is a flowchart for implementing a data writing control method provided by an embodiment of this application. This method can be applied to an electronic device deployed with a storage device or an electronic device connected to a storage device. The storage device can be a removable device independent of the electronic device, such as a USB flash drive that can be connected to a notebook through a data interface, as Figure 2 shown; or, the storage device can be a non-removable device integrated inside the electronic device, such as a SATA (Serial Advanced Technology Attachment) hard disk built into the notebook, as Figure 3 shown. The storage device in this embodiment can also be referred to as an external storage device, and this external storage device can be a block device and a device that requires a cache area for data writing. The technical solution in this embodiment is mainly used to solve the situation where the electronic device runs stuck when writing data to the storage device.

[0061] Specifically, the method in this embodiment may include the following steps:

[0062] Step 101: In response to a data writing instruction, determine whether a first transfer condition is satisfied. If the first transfer condition is satisfied, execute Step 102; if the first transfer condition is not satisfied, execute Step 103.

[0063] Among them, the data writing instruction is used to write target data from the electronic device to the target storage device. For example, as Figure 4 shown, the user selects the compressed file a on the notebook screen and selects "Send to Removable Device H". In response to this user operation, a data writing instruction is obtained, and the data writing instruction is used to write the compressed file a from the notebook to the removable device H. In response to this data writing instruction, determine whether the first transfer condition is satisfied.

[0064] Specifically, the first transfer condition may include: the remaining space in the cache area is less than the data volume of the target data, or the cached data volume corresponding to the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device.

[0065] Among them, the cache area is an area deployed in the memory space of the electronic device. For example, as Figure 5 shown, in the memory space of a notebook, the remaining memory area except for the memory occupied by the hardware operation and the memory occupied by the operating system operation is the cache area, and the cache area serves as a transfer storage area for writing the target data from the notebook to the removable device H.

[0066] It should be noted that the remaining space in the cache area being less than the data volume of the target data can be understood as: the remaining space in the cache area is not sufficient to write the target data.

[0067] Among them, in the cache area, each storage device connected to or deployed in the electronic device is configured with a cache upper limit value in the cache area. The cache upper limit value corresponding to the storage device represents the maximum value of the data volume allowed to be stored in the cache area for the corresponding storage device. Correspondingly, the cached data volume corresponding to the target storage device in the cache area reaching the cache upper limit value corresponding to the target storage device can be understood as: the data volume corresponding to the target storage device stored in the cache area reaches the cache upper limit value corresponding to the target storage device.

[0068] It should be noted that the cache upper limit values corresponding to different storage devices may be the same or different.

[0069] Step 102: Write the first data in the cache area to the storage device corresponding to the first data.

[0070] Among them, in this embodiment, when writing data to the storage device, each time the data volume of the minimum write unit is written, such as the minimum data page. If the first data cannot be written in one go, it can be written to the storage device multiple times until the first data is completely written.

[0071] In one implementation, the first data is the data that was first written into the cache area, that is, the data with the longest duration of being written into the cache area. The storage device corresponding to the first data may be the target storage device or other storage devices.

[0072] Step 103: Write the target data into the cache area.

[0073] Among them, in this embodiment, when writing data to the cache area, each time the data volume of the minimum write unit is written, such as the minimum data page.

[0074] It should be noted that the data in the cache area is written to the corresponding storage device when the second transfer condition is met.

[0075] In one implementation, different storage devices correspond to the same or different second transfer conditions. The second transfer condition corresponding to the storage device is a condition based on an interval threshold. Specifically, a processing operation of writing the data in the cache area to the corresponding storage device is performed every interval threshold such as 30 seconds or 10 seconds. The interval thresholds corresponding to different storage devices are the same or different.

[0076] Specifically, the interval threshold corresponding to the storage device can be determined based on the device type of the storage device, and the device type indicates whether the storage device can be fixed relative to the electronic device. For example, a storage device fixed relative to the electronic device is a non-removable device, and a storage device not fixed relative to the electronic device is a removable device. The interval threshold corresponding to the removable device is less than the interval threshold corresponding to the non-removable device.

[0077] For example, for a removable device, a processing operation of writing the data in the cache area to the corresponding storage device is performed every 3 seconds; for another example, for a non-removable device, a processing operation of writing the data in the cache area to the corresponding storage device is performed every 30 seconds.

[0078] By means of the above technical solution, in a data writing control method provided by an embodiment of the present application, when writing target data to a target storage device, the target data is first written to a cache area in the memory, and then the data in the cache area is written to the target storage device when the second transfer condition is met. In a specific implementation, the target data is written to the cache area only when the remaining space in the cache area is sufficient and the amount of cached data corresponding to the target storage device in the cache area does not reach its corresponding cache upper limit value. Correspondingly, when the remaining space in the cache area is insufficient, the first data in the cache area can be written to the corresponding storage device, or when the amount of cached data corresponding to the target storage device in the cache area reaches its corresponding cache upper limit value, the first data in the cache area can be written to the corresponding storage device. Therefore, in the present application, a limit condition that the data written to the cache area cannot exceed the cache upper limit value corresponding to the storage device is added, and an executable condition that reaches the cache upper limit value corresponding to the storage device is added for writing data from the cache area to the storage device, so as to avoid the situation that the cache area is continuously in a state of insufficient remaining space, and thus avoid continuously triggering writing data from the cache area to the storage device, thereby avoiding the situation that the electronic device runs stuck due to continuously occupying the resources of the electronic device.

[0079] In one implementation, for the target storage device, the cache upper limit value corresponding to the target storage device can be obtained through the following processing flow in this embodiment, such asFigure 6 As shown below:

[0080] Step 601: Obtain the device attributes of the target storage device.

[0081] Among them, the device attributes may include at least one of the device name, interface type, transmission protocol, and storage capacity.

[0082] Specifically, in the case where the target storage device is a removable device, during the process of the target storage device being connected to the electronic device, when the electronic device detects the connection of the target storage device, it can read the device attributes of the target storage device through the connection with the target storage device; in the case where the target storage device is a non-removable device, during the startup process of the electronic device, the device attributes of the target storage device can be collected by using a controller such as the Basic Input Output System (BIOS).

[0083] Among them, the interface type refers to the interface type of the connection interface on the target storage device for connecting to the electronic device. The transmission protocol refers to the transmission protocol for data transmission between the electronic device and the target storage device. The storage capacity refers to the maximum amount of data that the target storage device can store.

[0084] Step 602: Obtain the first write speed corresponding to the target storage device according to the device attributes.

[0085] In the specific implementation, in this embodiment, the first write speed corresponding to the target storage device can be determined according to the device attributes of the target storage device based on the mapping relationship between the device attributes and the write speed.

[0086] In one implementation manner, taking the device attribute as the device name as an example, in this embodiment, the corresponding write speed, that is, the first write speed, can be determined according to the device name of the target storage device based on the mapping relationship between the device name and the write speed.

[0087] For example, in this embodiment, the mapping relationship between the device name and the write speed can be established based on the write speed setting operations performed by the user on one or more storage devices. Based on this, in this embodiment, the first write speed can be determined according to the device name of the target storage device.

[0088] In another implementation manner, taking the device attribute as the interface type as an example, in this embodiment, the corresponding write speed, that is, the first write speed, can be determined according to the interface type of the target storage device based on the mapping relationship between the interface type and the write speed.

[0089] For example, in this embodiment, corresponding theoretical writing speeds can be set for one or more interface types in advance to establish a mapping relationship between the interface type and the writing speed. Based on this, in this embodiment, the first writing speed can be determined according to the interface type of the connection interface between the target storage device and the electronic device.

[0090] It should be noted that in actual use, it is difficult for a storage device to achieve the theoretical writing speed of the interface. Therefore, the theoretical writing speed of the storage device in this embodiment can be the average writing speed of storage devices of common similar interface types. For example, a storage device with a USB2.0 interface corresponds to a theoretical writing speed of 20 MB per second; a storage device with a USB3.0 interface corresponds to a theoretical writing speed of 300 M per second. Another example is that a storage device with a gigabit network interface corresponds to a theoretical writing speed of 100 MB per second, and a storage device with a 100-megabit network interface corresponds to a theoretical writing speed of 10 MB per second.

[0091] In another implementation manner, taking the device attribute as the transport protocol as an example, in this embodiment, based on the mapping relationship between the transport protocol and the writing speed, the corresponding writing speed, that is, the first writing speed, can be determined according to the transport protocol between the target storage device and the electronic device.

[0092] For example, in this embodiment, corresponding theoretical writing speeds can be set for one or more transport protocols in advance to establish a mapping relationship between the transport protocol and the writing speed. Based on this, in this embodiment, the first writing speed can be determined according to the transport protocol between the target storage device and the electronic device. For example, a storage device using the SATA protocol corresponds to a theoretical writing speed of 500 MB per second; a storage device using the NVME protocol corresponds to a theoretical writing speed of 1000 MB per second.

[0093] In another implementation manner, taking the device attribute as the storage capacity as an example, in this embodiment, based on the mapping relationship between the storage capacity and the writing speed, the corresponding writing speed, that is, the first writing speed, can be determined according to the storage capacity of the target storage device. For example, a USB flash drive with a size of 64 GB or less corresponds to a theoretical writing speed of 15 MB per second, and a USB flash drive with a size greater than 64 GB and less than 128 GB corresponds to a theoretical writing speed of 25 MB per second.

[0094] Step 603: Obtain the cache upper limit value corresponding to the target storage device according to the first writing speed.

[0095] In a specific implementation, step 603 can multiply the first writing speed by a preset writing duration, and use the obtained product as the cache upper limit value corresponding to the target storage device.

[0096] Taking a removable device such as a USB flash drive as an example, the preset writing duration can be represented by RN; taking a non-removable device such as a SATA hard disk as an example, the preset writing duration can be represented by URN. The preset writing duration corresponding to the removable device can be less than the preset writing duration corresponding to the non-removable device. For example, the preset writing duration corresponding to the removable device can be 3 seconds, and the preset writing duration corresponding to the non-removable device can be 30 seconds.

[0097] It should be noted that in this embodiment, the cache upper limit value corresponding to any other storage device can be obtained through the Figure 6 process shown.

[0098] Based on the above implementation solution, the method in this embodiment may further include the following processing, such as Figure 7 shown in

[0099] Step 701: Obtain the second writing speed.

[0100] Among them, the second writing speed can be the real-time writing speed at which the data in the cache area is written to the target storage device.

[0101] Specifically, in this embodiment, during the process of writing data from the cache area to the target storage device, the amount of data transmitted in each time period can be continuously recorded, and then the amount of data is divided by the duration of the time period to obtain the second writing speed.

[0102] For example, in this embodiment, the amount of data written from the cache area of the notebook memory to the USB flash drive or the SATA hard disk is statistically counted every 0.02 seconds. For each 0.02 seconds, the amount of data written within this 0.02 seconds is divided by 0.02 seconds to obtain the second writing speed.

[0103] Step 702: Update the cache upper limit value corresponding to the target storage device according to the second writing speed.

[0104] Among them, in this embodiment, the second writing speed can be multiplied by the preset writing duration, and the obtained product is used as the updated cache upper limit value corresponding to the target storage device.

[0105] In one implementation, this embodiment may further include the following processing, such as Figure 8 shown in

[0106] Step 801: For each storage device, monitor whether the second transfer condition corresponding to the storage device is satisfied. If the second transfer condition corresponding to the storage device is satisfied, execute Step 802; if the second transfer condition corresponding to the storage device is not satisfied, continue to execute Step 801.

[0107] Step 802: Screen the second data corresponding to the storage device in the cache area.

[0108] Specifically, in this embodiment, the second data can be screened in the cache area according to the timeout duration corresponding to the storage device, and the duration for which the second data is written into the cache area is greater than or equal to the timeout duration corresponding to the storage device. That is to say, in this embodiment, the data in the cache area whose written duration reaches the timeout duration corresponding to the storage device is screened out, that is, the second data.

[0109] Among them, the timeout duration corresponding to the storage device is determined based on the device type of the storage device, and the device type indicates whether the storage device can be fixed relative to the electronic device. Under different device types, the timeout durations corresponding to the storage devices can be the same or different. The timeout duration corresponding to the non-removable device can be greater than the timeout duration corresponding to the removable device. For example, the timeout duration corresponding to the non-removable device can be 30 seconds, and the timeout duration corresponding to the removable device can be 3 seconds.

[0110] Step 803: Write the second data into the corresponding storage device.

[0111] Among them, the second transfer condition corresponding to the storage device includes: the interval duration from the current moment to the previous time when screening the second data corresponding to the storage device in the cache area reaches the interval threshold. The interval thresholds corresponding to different storage devices can be the same or different.

[0112] That is to say, in this embodiment, when detecting whether the second transfer condition is satisfied in step 801, it can be determined whether the interval duration from the current moment to the moment when step 802 was last executed reaches the interval threshold. If so, then steps 802 and 803 are executed again. If not, then continue to wait until the interval duration reaches the interval threshold, and then step 802 is executed once.

[0113] Based on this, in this embodiment, step 802 can be executed once every interval threshold such as 30 seconds or 10 seconds. In the case where the second data is screened out in step 802, step 803 is executed. If no second data is screened out in step 802 (that is, there is no data in the cache area whose written duration reaches the timeout duration corresponding to the corresponding storage device), then step 803 is not executed.

[0114] In a specific implementation, when it is detected in step 801 that the second transfer condition corresponding to the storage device is satisfied, a corresponding processing process can be started for the storage device first. This processing process is used to execute step 802 and step 803. That is to say, in this embodiment, a processing process can be started separately for each storage device whose second transfer condition is detected to be satisfied. The processing process filters the second data corresponding to the storage device in the cache area, and then writes the filtered second data into the corresponding storage device.

[0115] It should be noted that after the processing process corresponding to the storage device filters out the second data, the second data can be locked, thus prohibiting other processing processes. For example, when the second transfer condition corresponding to storage device 1 is satisfied, processing process 1 is started. Processing process 1 filters out the cache data corresponding to storage device 1 in the cache area, that is, the second data. At this time, the second data is locked and will not be processed by the subsequently started processing process 2, thereby avoiding data processing errors.

[0116] The above introduces a data writing control method provided by an embodiment of the present application. Next, a device for executing the above data writing control method will be introduced.

[0117] Reference Figure 9 , which is a schematic structural diagram of a data writing control device provided by an embodiment of the present application. This device can be deployed in an electronic device equipped with a storage device or an electronic device connected to a storage device. The storage device can be a removable device independent of the electronic device, such as a USB flash drive that can be connected to a notebook through a data interface, as Figure 2 shown; or, the storage device can be a non-removable device integrated inside the electronic device, such as a SATA (Serial Advanced Technology Attachment) hard disk built into a notebook, as Figure 3 shown. The technical solution in this embodiment is mainly used to solve the situation that the electronic device runs stuck when writing data to the storage device.

[0118] Specifically, the device in this embodiment may include the following structures:

[0119] A transfer judgment unit 901, configured to judge whether a first transfer condition is satisfied in response to a data writing instruction for writing target data from an electronic device to a target storage device;

[0120] Wherein, the first transfer condition includes: the remaining space in the cache area is less than the data volume of the target data, or, the cache data volume corresponding to the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device; the cache area is an area deployed in the memory space of the electronic device;

[0121] A cache writing unit 902, configured to write first data in the cache area to a storage device corresponding to the first data when the first transfer condition is satisfied;

[0122] A data writing unit 903, configured to write the target data into the cache area when the first transfer condition is not satisfied, and the data in the cache area is written into the corresponding storage device when the second transfer condition is satisfied.

[0123] By means of the above technical solution, in a data writing control device provided in an embodiment of the present application, when writing target data to a target storage device, the target data is first written into a cache area in a memory, and then the data in the cache area is written into the target storage device when the second transfer condition is satisfied. In a specific implementation, the target data is written into the cache area only when the remaining space in the cache area is sufficient and the amount of cache data corresponding to the target storage device in the cache area does not reach its corresponding cache upper limit value. Correspondingly, when the remaining space in the cache area is insufficient, the first data in the cache area can be written into the corresponding storage device, or when the amount of cache data corresponding to the target storage device in the cache area reaches its corresponding cache upper limit value, the first data in the cache area can be written into the corresponding storage device. Therefore, in this application, a limiting condition that the data written into the cache area cannot exceed the cache upper limit value corresponding to the storage device is added, and an executable condition that the cache upper limit value corresponding to the storage device is reached is added for writing data from the cache area to the storage device. This can avoid the situation where the remaining space in the cache area is continuously insufficient, and thus will not trigger continuous writing of data from the cache area to the storage device, thereby avoiding the situation of the electronic device running stuck caused by continuous occupation of electronic device resources.

[0124] In one implementation, the device in this embodiment may further include the following units, such as Figure 10 shown in

[0125] An upper limit setting unit 904, configured to obtain device attributes of the target storage device; the device attributes include at least one of a device name, an interface type, a transmission protocol, and a storage capacity; according to the device attributes, obtain a first writing speed corresponding to the target storage device; and according to the first writing speed, obtain a cache upper limit value corresponding to the target storage device.

[0126] In one implementation, the upper limit setting unit 904 is further configured to: obtain a second writing speed, where the second writing speed is a real-time writing speed for writing the data in the cache area to the target storage device; and update the cache upper limit value corresponding to the target storage device according to the second writing speed.

[0127] In one implementation, the device in this embodiment may further include the following units, as Figure 11 shown in

[0128] A data transfer unit 905, configured to monitor, for each of the storage devices, whether a second transfer condition corresponding to the storage device is satisfied; in a case where the second transfer condition corresponding to the storage device is satisfied, screen second data corresponding to the storage device in the cache area; and write the second data into the corresponding storage device;

[0129] Wherein, the second transfer condition corresponding to the storage device includes: the interval duration from the current moment to the previous time of screening the second data corresponding to the storage device in the cache area reaches an interval threshold; the interval thresholds corresponding to different storage devices are the same or different.

[0130] Based on the above implementation, when the data transfer unit 905 screens the second data corresponding to the storage device in the cache area, it is specifically configured to: screen the second data in the cache area according to the timeout duration corresponding to the storage device; the duration for which the second data is written into the cache area is greater than or equal to the timeout duration corresponding to the storage device.

[0131] Wherein, the timeout duration corresponding to the storage device is determined based on the device type of the storage device; wherein, the device type indicates whether the storage device can be fixed relative to the electronic device.

[0132] In one implementation, when the second transfer condition corresponding to the storage device is satisfied, the data transfer unit 905 is further configured to: start a corresponding processing process for the storage device, where the processing process is configured to screen the second data corresponding to the storage device in the cache area; and write the second data into the corresponding storage device;

[0133] Wherein, the second data screened by the processing process is locked to prohibit other processing processes from processing.

[0134] It should be noted that the specific implementation manners of the units in this embodiment may refer to the corresponding contents in the foregoing, and will not be elaborated herein.

[0135] An embodiment of the present application further provides an electronic device. The electronic device includes at least one processor and a memory connected to the processor, where: the memory is configured to store a computer program; the processor is configured to execute the computer program so that the electronic device can implement the data writing control method described in any one of the foregoing embodiments.

[0136] Reference Figure 12As shown, it shows a schematic structural diagram of an electronic device suitable for implementing the electronic device in the embodiments of the present application. The electronic device in the embodiments of the present application may include, but is not limited to, fixed terminals such as mobile phones, laptop computers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), desktop computers, and the like. Figure 12 The electronic device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present application.

[0137] As Figure 12 shown, the electronic device may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 1201, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1202 or the program loaded from the storage device 1208 into the random access memory (RAM) 1203. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 1203. The processing device 1201, the ROM 1202, and the RAM 1203 are connected to each other through a bus 1204. The input / output (I / O) interface 1205 is also connected to the bus 1204.

[0138] Generally, the following devices may be connected to the I / O interface 1205: an input device 1206 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1207 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1208 including, for example, a memory card, a hard disk, etc.; and a communication device 1209. The communication device 1209 may allow the electronic device to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 12 shown is an electronic device having various devices, it should be understood that it is not required to implement or have all the shown devices. More or fewer devices may be alternatively implemented or had.

[0139] The embodiments of the present application also provide a computer program product including computer-readable instructions. When the computer-readable instructions run on an electronic device, the electronic device is enabled to implement any one of the data writing control methods provided by the embodiments of the present application.

[0140] The embodiments of the present application also provide a computer-readable storage medium. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device is enabled to implement any one of the data writing control methods provided by the embodiments of the present application.

[0141] Taking a computer with the Linux operating system as an example, the technical solution of the present application will be described in detail below:

[0142] First, the purpose of this application is to implement the function of separately adjusting the write cache size and dirty data page timeout of each external storage device (i.e., the storage device mentioned above). In view of this, this application provides a solution for separately adjusting the write cache size and dirty data page timeout of each external storage device on a computer using the Linux kernel operating system. After adding the write cache method of this application to the Linux kernel, the effect of separately adjusting the write cache size and dirty data page timeout of each external storage device can be achieved.

[0143] It should be noted that this application can be modified in the Linux kernel code to achieve the above technical effects. The operating system using this application is the operating system using the Linux kernel, and this application will replace the shared write cache function of the original Linux system.

[0144] As Figure 13 shown, on a computer that has installed an operating system using the Linux kernel of this application and connected one or more external storage devices, after starting the computer, the process of enabling the write cache for the external storage device can be divided into the following steps:

[0145] Step 1: Detect the access of the external storage device and start the following process of setting cache attributes;

[0146] After the computer starts, the operating system will detect the external storage device and generate device structure data by the kernel function and store it in the memory. The device data structure of each external storage device contains various information of the device.

[0147] When this application detects the access of the device, it can detect whether this device is an external access device (also called external storage). After confirming that this device is an external access device (i.e., external storage device), read the relevant information of the external access device of this external storage device and copy it into this device data structure.

[0148] Step 2: Determine whether this device uses the write cache function; if yes, go to Step 3; if no, go to Step 8 to end the process of setting the cache attributes of the external storage device;

[0149] In the process of determining whether to use the write cache function in this application, first determine whether this device is a block device (block devices have random access functions). If it is not a block device, this application is not applicable and the end process is followed. When the external storage device is a block device, determine whether this device uses the write cache function. If this device confirms to use the write cache function, enter the next process.

[0150] Among them, to determine whether this device uses the write cache function, it can be achieved by determining whether this device does not use the "O-SYNC flag". If this device does not use the "O-SYNC flag", it indicates that this device uses the write cache function.

[0151] Step 3: After determining to use the write cache function, read the information of the external storage device such as the device name, interface type, transfer protocol, and storage capacity; then, according to a preset method for calculating the write speed, select one of the methods to calculate the write speed, and then set the write cache size of this external storage device (i.e., the cache upper limit value in the previous text); and, set the dirty data page timeout time of this external storage device (i.e., the timeout duration in the previous text); end the process of setting the cache attributes of this device.

[0152] In the process of determining the write speed calculation method to be used by this device and reading relevant information, first read and confirm the method for calculating the write speed preset by the user. This application allows the user to use one method to calculate the write speed. If the user does not set it in this step, the default processing method can be used: for removable external storage devices, the write speed can be calculated based on the capacity of this device; for non-removable external storage devices, the write speed can be calculated based on the type of the transfer protocol of this device.

[0153] In this step, calculate the write speed (unit: MB per second) of this external storage device in the process of connecting the external storage device, and based on the write speed per second, the write cache size that should be set can be calculated in the subsequent process.

[0154] Step 4: Use a dedicated write cache setting method and start processing according to the device attributes read.

[0155] The first calculation method is based on the preset write speed corresponding to the preset external storage device name by the user. In this calculation method, the user is allowed to set the name and the corresponding write speed for one or more external storage devices in advance. Next, find the name and the corresponding write speed that match this external storage device in the list of corresponding relationships between the preset name and the corresponding write speed, and save this write speed in the data structure of this external storage device.

[0156] The second calculation method is based on the interface type of the external storage device. For example, there are slight differences between USB2.0 and USB3.0 interfaces. The theoretical transfer speed of USB3.0 is 10 times that of USB2.0. In this case, the present application can default to setting a theoretical write speed of 20MB per second for external storage devices with a USB2.0 interface, and a theoretical write speed of 300M per second for external storage devices with a USB3.0 interface. Another example is the interface difference of network external storage devices. Considering that there are gigabit network interfaces and hundred-megabit network interfaces, with the highest transfer speeds of 100MB per second and 10MB per second respectively, the theoretical write speed of the network external storage device is set according to the network interface bandwidth.

[0157] The third calculation method is to calculate the write speed according to the external storage device transfer protocol. For example, for M.2 interface external storage device hard drives, some use the SATA protocol and some use the NVME protocol. In this case, the M.2 interface external storage device using the SATA protocol is default set with a theoretical write speed of 500MB per second, and the M.2 interface external storage device using the NVME protocol is default set with a theoretical write speed of 1000MB per second. Judging from the actual write speed of M.2 interface external storage devices, this setting is basically the normal write speed of external storage devices without built-in cache.

[0158] The fourth calculation method is to calculate the write speed according to the size of the external storage device capacity. For example, USB flash drives with a USB interface are generally below 128GB, and the write speed of flash drives is indeed correlated with the capacity. The larger the capacity, the higher the write speed. Thus, considering that the write speeds of 32GB and 64GB USB flash drives are generally between 10MB per second and 30MB per second, the theoretical write speed of USB flash drives within 64GB can be set to 15MB per second, and the theoretical write speed of USB flash drives larger than 64GB and less than 128G can be set to 25MB per second.

[0159] After the above calculation methods, the external storage device will first be set a speculated write speed per second (unit: MB per second). For example, the speculated write speed of a 32GB USB flash drive is 15MB per second, and the speculated write speed of a solid-state drive with the Non-Volatile Memory Host Controller Interface Specification (NVME) protocol is 1000MB per second.

[0160] The theoretical write speed of each external storage device is temporarily stored in the data structure of the external storage device and recorded as the write speed SPEEDS. This is the individual SPEEDS for each device.

[0161] End the process of setting the theoretical write speed SPEEDS per second of the external storage device, and confirm the value of SPEEDS.

[0162] Step 5: Calculate the write cache size of this external storage device, which can be represented by CURWB. The method is RN * SPEEDS or URN * SPEEDS, and store the result in CURWB. The recommended unit is MB.

[0163] This step calculates the independent write cache size of this external storage device based on the theoretical write speed of this external storage device. Users can set the multiples RN and URN of the dirty data page existence time for removable devices (such as USB flash drives) and non-removable devices (such as SATA hard drives) respectively. Without using the user settings, the default multiples are 3 and 30.

[0164] It should be noted that the reason RN defaults to 3 is that considering the operation of removing a removable device manually or automatically after synchronization, in order to reduce the user waiting time, it is best to control the write time of the entire write cache within 3 seconds. URN defaults to 30, which is the default setting of the dirty data page timeout time in mainstream Linux operating systems.

[0165] The RN set here is the multiple commonly used by each removable external storage device using the write cache, and URN is the multiple commonly used by each non-removable external storage device using the write cache. Based on this algorithm, by default, the write cache size of the removable external storage device with a write cache connected to this system is RN multiplied by the SPEEDS of this device, and the write cache size of the non-removable external storage device with a write cache connected to this system is URN multiplied by the SPEEDS of this device.

[0166] Step 6: Since the dirty data pages must be temporarily stored in memory, the absolute upper limit of the dedicated write cache size of the external storage device cannot exceed the size of all available memory. Therefore, compare CURWB with the size of all available memory. If it exceeds the size of all available memory, set it to the size of all available memory. Set CURWB as the dedicated write cache size of this device.

[0167] Step 7: In the process of setting the dirty data page timeout time in this application, the dirty data page timeout time of the external storage device will be set according to the dirty data page timeout time pre-configured by the user. Set these two types of external storage devices according to the dirty data page timeout time set by the user for removable external storage devices and non-removable external storage devices. This application supports setting different external storage timeout times for these two types of devices, namely removable external storage devices and non-removable external storage devices. By default, the dirty data page timeout time for removable external storage devices is 3 seconds, and the dirty data page timeout time for non-removable external storage devices is 30 seconds.

[0168] Step 8: End the process of setting the dedicated write cache of the external storage device.

[0169] It should be noted that when the CURWB in step 6 exceeds or is equal to the size of all available memory, in this application, the user can directly set the write cache size of this device or calculate the dedicated write cache size according to the transfer protocol. In step 7, generally, the timeout duration of the dirty data pages of the removable external storage device is relatively short and should be set to a duration that is imperceptible to the user.

[0170] Outside the main process of this application, in order to fully compatible this solution with the existing write cache function of the mainstream Linux system, this application also has some process innovations or improvements based on the original write cache solution. The following flowcharts will show the innovations and improvements on the original process.

[0171] As Figure 14 shown, the process of writing to the external storage device when using this application is as follows:

[0172] When copying data to the external storage device that starts to use the cache solution of this application, first judge whether the memory is not exhausted and whether the dedicated write cache space is not exhausted. If the memory is not exhausted and the dedicated write cache space is not exhausted, then data can be written to the dedicated write cache (i.e., the cache area) in the minimum write unit (page). Then judge whether the data to be copied this time is copied completely. If it is copied completely, end. If it is not copied completely, then return and continue to judge whether the memory is not exhausted and whether the dedicated write cache space is not exhausted; if the memory is exhausted or the dedicated write cache space is exhausted, then write the data in the dedicated write cache space to the external storage device according to the first-in, first-out rule (write in the minimum write unit according to the regulations of the external storage device), and then return and continue to judge whether the memory is not exhausted and whether the dedicated write cache space is not exhausted.

[0173] As Figure 15 shown, it is the process of calculating the write speed of the external storage device using this invention. The condition for using this process is that the user manually or the software automatically triggers a batch write (data synchronization operation). As Figure 15 shown, in the process of calculating the write speed of the external storage device using this application, it is divided into the following steps:

[0174] Step 1501: Prepare for batch writing to the external storage device;

[0175] In the process of preparing for batch writing to the external storage device, the data structure and write cache attributes of the external storage device such as the dedicated write cache size and the write cache timeout time will be read. Especially the device node is saved for use when writing to the device.

[0176] Step 1502: Record the start time sTime of this batch write task and initialize the write amount wData.

[0177] In the process of recording the start time sTime and the initial write amount wData of this batch write task, the variable sTime is initialized to the current time, and the write amount wData is initialized to 0.

[0178] Step 1503: Traverse the cache to be written;

[0179] In this step of traversing the cache to be written, the next cache to be written to be processed is selected.

[0180] Step 1504: Determine whether there is still an unprocessed write cache, that is, whether there is still a cache to be written on this external storage device that needs to be processed. If there is an unprocessed write cache, go to step 1505; otherwise, this write operation can be ended.

[0181] In the process of determining whether there is still an unprocessed write cache, it is judged whether the next cache to be written to be processed saved in the previous process is valid. If the write cache is valid, enter the process of writing the cache to the external storage device. If there is no next cache to be written to be processed, end this process of writing to the external storage device.

[0182] Step 1505: Select the next unprocessed cache to be written and write it to this device; update the write amount wData.

[0183] In the process of selecting the next unprocessed cache to be written and writing it to this device, it has been confirmed in the previous process that it can be written. The data is taken out from the cache data structure and written to the device using the write function provided by the device, and the amount of data written this time is recorded. After writing is completed, enter the next process.

[0184] Step 1506: Determine whether the difference cTime between the current time nTime and the start time sTime is greater than 0.02 seconds (the default is 0.02 seconds, which can be adjusted). If cTime is greater than 0.02 seconds, enter the process of calculating the write speed in step 7; otherwise, continue from the process of traversing the cache to be written.

[0185] In the process of determining whether the difference cTime between the current time nTime and the start time sTime is greater than 0.02 seconds, if it is judged that the difference cTime is greater than 0.02 seconds, the action of calculating the write speed starts. The write speed is the value obtained by dividing the write amount wData by the elapsed time cTime, and the unit is MB / s. Then update sTime to the current time and initialize wData to 0. If it is judged that the difference cTime is less than 0.02 seconds, continue to execute the write process without performing the action of calculating the write speed.

[0186] Step 1507: Calculate the write speed = wData / cTime; update sTime to the current time, initialize wData, return to Step 1503, and continue from traversing the cache to be written.

[0187] In the process of updating the write amount wData, add the data amount written in the previous process to wData, with the unit of MB. This process will reach the process exit and end the process when it is determined that there is no unprocessed write cache.

[0188] As Figure 16 shown, use the write process when the dirty data page of the external storage device of the present application times out. The write process when the dirty data page of the external storage device of the present application times out is divided into the following steps:

[0189] Step 1601: A timed task that is started once every 5 to 30 seconds (adjustable);

[0190] In the process of starting the timed task, the kernel sets the end sleep time of the process of traversing the write cache and starts the running process.

[0191] Step 1602: The kernel process traverses the cache to be written;

[0192] In the process of the kernel process traversing the cache to be written, the write cache check process is set up by the kernel after startup.

[0193] Step 1603: Select a cache to be written;

[0194] In the process of selecting a cache to be written, a process for processing the write cache obtains a write cache and locks it (using the unique lock in the data structure of this write cache) to ensure that other processes for processing the write cache will not process this write cache during this processing time.

[0195] Step 1604: Calculate the time difference pTime from the creation time of the selected cache to the current time;

[0196] In the process of calculating the time difference pTime from the creation time of the selected cache to the current time, since the creation time is marked in the data structure of the write cache, the time difference pTime from creation to the current time can be obtained by subtracting the current time from the creation time.

[0197] Step 1605: Read the dedicated dirty data page timeout time eTime of the external storage device to which this cache belongs;

[0198] In the process of reading the dedicated dirty data page timeout time eTime of the external storage device to which this cache belongs, based on the obtained write cache, the external storage device to which this write cache belongs can be determined, and then the dedicated dirty data page timeout time eTime in the structure data of this external storage device can be read.

[0199] Step 1606: Determine whether the existence time of this cache is greater than the dedicated dirty data page timeout time of this device, that is, whether pTime is greater than eTime; if it is determined that this cache has timed out, write this cache to the external storage device, otherwise continue to traverse the next write cache in the cache queue.

[0200] In the process of determining whether the existence time of this cache is greater than the dedicated dirty data page timeout time of this device, judge the result of pTime being greater than eTime, and the unit is 0.01 seconds. Different processes are followed according to different results. In the case where the result is true, execute step 1607;

[0201] Step 1607: Write this write cache to the device, and delete this record, and then return to the step of traversing the write cache. In the case where the result is false, unlock this cache and directly return to the previous step of traversing the write cache.

[0202] For example, give a higher write cache size to a high-speed read-write hard disk that frequently executes write commands; give a higher write cache size to a hard disk that frequently executes write commands; give a lower write cache size to a slow read-write hard disk that frequently executes read commands, and at the same time reduce the time waiting to flush dirty data pages to the external storage device.

[0203] In summary, the present application has the following beneficial effects:

[0204] 1. By configuring the dedicated write cache size and dedicated dirty data page timeout time according to different external storage devices, the performance of external storage devices with different speeds can be significantly optimized, the write consumption of the device can also be reduced, and the lifespan of the external storage device can be optimized.

[0205] 2. It can significantly reduce the situation of lagging other than when performing copy operations.

[0206] 3. A more refined write speed calculation method can make the copy progress bar display accurately, providing a good user experience.

[0207] In addition, it should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the attached drawings of the device embodiments provided in this application, the connection relationships between the modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines.

[0208] Through the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by dedicated hardware including application-specific integrated circuits, dedicated CPUs, dedicated memories, dedicated components, etc. Generally, functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or dedicated circuits. However, for this application, in more cases, software program implementation is a better implementation method. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disc of a computer, and includes several instructions to enable a computer device (which can be a personal computer, training device, or network device, etc.) to execute the methods described in various embodiments of this application.

[0209] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product.

[0210] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or a data center that includes one or more integrated available media. The available medium may be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.

Claims

1. A data writing control method, characterized in that: The method comprises: In response to a data write instruction, determining whether a first transfer condition is satisfied; the data write instruction is used to write target data from the electronic device to the target storage device; The first transfer condition includes: the remaining space of the cache area is less than the data volume of the target data, or the cache data volume of the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device; the cache area is an area of ​​the memory space deployed in the electronic device; When the first transfer condition is satisfied, writing the first data in the cache area to a storage device corresponding to the first data; When the first transfer condition is not satisfied, the target data is written into the cache area, and when the second transfer condition is satisfied, the data in the cache area is written into a corresponding storage device.

2. The method according to claim 1, characterized in that The method further comprises: Obtaining device attributes of the target storage device; the device attributes include at least one of a device name, an interface type, a transmission protocol, and a storage capacity; According to the device attribute, obtaining a first write speed corresponding to the target storage device; According to the first write speed, a cache upper limit value corresponding to the target storage device is obtained.

3. The method according to claim 2, characterized in that The method further comprises: Obtaining a second write speed, where the second write speed is a real-time write speed for writing the data in the cache area into the target storage device; According to the second write speed, the cache upper limit value corresponding to the target storage device is updated.

4. The method according to claim 1, characterized in that The method further comprises: For each of the storage devices, monitoring whether a second transfer condition corresponding to the storage device is satisfied; When a second transfer condition corresponding to the storage device is satisfied, screening second data corresponding to the storage device in the cache area; Writing the second data into the corresponding storage device; Among them, the second transfer condition corresponding to the storage device includes: the interval between the current moment and the previous time of screening the second data corresponding to the storage device in the cache area reaches the interval threshold; the interval thresholds corresponding to different storage devices are the same or different.

5. The method according to claim 4, characterized in that Screening the second data corresponding to the storage device in the cache area includes: The second data is screened in the cache area according to the timeout duration corresponding to the storage device; the duration for which the second data is written into the cache area is greater than or equal to the timeout duration corresponding to the storage device.

6. The method according to claim 5, characterized in that The timeout duration corresponding to the storage device is determined based on the device type of the storage device; The device type indicates whether the storage device can be fixed relative to the electronic device.

7. The method according to claim 4, characterized in that When the second transfer condition corresponding to the storage device is satisfied, the method further includes: Starting a corresponding processing process for the storage device, the processing process is used to screen the second data corresponding to the storage device in the cache area; writing the second data into the corresponding storage device; The second data screened out by the processing process is locked to prohibit other processing processes from processing.

8. A data writing control device, characterized in that: The device comprises: a transfer determination unit, configured to determine whether a first transfer condition is satisfied in response to a data write instruction for writing target data from the electronic device to the target storage device; The first transfer condition includes: the remaining space of the cache area is less than the data volume of the target data, or the cache data volume of the target storage device in the cache area reaches the cache upper limit value corresponding to the target storage device; the cache area is an area of ​​the memory space deployed in the electronic device; a cache writing unit, configured to write the first data in the cache area to a storage device corresponding to the first data when the first transfer condition is satisfied; The data writing unit is used to write the target data into the cache area when the first transfer condition is not met, and the data in the cache area is written into the corresponding storage device when the second transfer condition is met.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the data writing control method as described in any one of claims 1 to 7.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the data writing control method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Data reading and writing method and device based on asynchronous annular buffer area

    CN110704335A

  • Data processing method, terminal and storage medium

    CN112162692A

  • Data recovery method and device, equipment and storage medium

    CN112925672A

  • Data caching method and device, computer equipment and storage medium

    CN116010303A

  • Dynamically controlling a file system write cache

    US20160217078A1

Cited By

  • Data copying method and related device

    CN121523602A