A data writing control method and device, electronic equipment and storage medium

By setting reasonable data write conditions between the cache area and the storage device, the problem of electronic device lag caused by data writing was solved, and efficient resource utilization was achieved.

CN120122882BActive Publication Date: 2025-12-09ZHONGKE FANGDE SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Writing data to storage devices continuously consumes processor resources, causing electronic devices to lag.

Method used

When there is sufficient remaining space in the cache area and the amount of cached data on the target storage device has not reached the cache limit, the data is first written to the cache area. When the second transfer condition is met, the data is then written to the storage device. By limiting the writing to the cache area and the cache limit condition of the storage device, the continuous occupation of electronic device resources is avoided.

Benefits of technology

This avoids insufficient cache space, prevents electronic devices from lag, and improves resource utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120122882B_ABST
    Figure CN120122882B_ABST
Patent Text Reader

Abstract

The application discloses a data writing control method, which comprises the following steps: in response to a data writing instruction, determining whether a first transfer condition is met; the data writing instruction is used for writing target data from an electronic device to a target storage device; the first transfer condition comprises that the remaining space of a cache area is less than the data amount of the target data, or the corresponding cache data amount of the target storage device in the cache area reaches the corresponding cache upper limit value of the target storage device; the cache area is a region arranged in the memory space of the electronic device; in the case where the first transfer condition is met, writing first data in the cache area to the storage device corresponding to the first data; in the case where the first transfer condition is not met, writing the target data to the cache area, and writing the data in the cache area to the corresponding storage device in the case where a second transfer condition is met.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a data writing control method and device, electronic equipment and storage medium. BACKGROUND

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

[0003] However, if the data in the cache area is continuously written to the storage device, processor resources will be occupied, causing the processor to run to be stuck. SUMMARY

[0004] In view of the above problems, the present application provides a data writing control method and device, electronic equipment and storage medium to avoid the electronic equipment running to be stuck caused by continuous occupation of electronic equipment resources. The specific scheme is as follows:

[0005] The first aspect of the present application provides a data writing control method, which comprises:

[0006] In response to a data writing instruction, it is judged whether a first transfer condition is met; 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 amount of the target data, or the corresponding cache data amount of the target storage device in the cache area reaches the corresponding cache upper limit value of the target storage device; the cache area is a region deployed in the memory space of the electronic device;

[0008] In the case where the first transfer condition is met, the first data in the cache area is written to the storage device corresponding to the first data;

[0009] In the case where the first transfer condition is not met, the target data is written to the cache area, and the data in the cache area is written to the corresponding storage device in the case where a second transfer condition is met.

[0010] In one possible implementation, the method further comprises:

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

[0012] According to the device attribute, the first writing speed corresponding to the target storage device is obtained;

[0013] According to the first write speed, a cache upper limit value corresponding to the target storage device is obtained.

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

[0015] A second write speed is obtained, the second write speed being a real-time write speed of writing data in the cache region to the target storage device;

[0016] According to the second write speed, the cache upper limit value corresponding to the target storage device is updated.

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

[0018] For each of the storage devices, it is monitored whether a second transfer condition corresponding to the storage device is met;

[0019] In a case where the second transfer condition corresponding to the storage device is met, second data corresponding to the storage device is screened in the cache region;

[0020] The second data is written to the corresponding storage device.

[0021] The second transfer condition corresponding to the storage device includes that an interval length from a previous time of screening the second data corresponding to the storage device in the cache region reaches an interval threshold value, and interval threshold values 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 region includes:

[0023] The second data is screened in the cache region according to a timeout length corresponding to the storage device, and a duration length for which the second data is written to the cache region is greater than or equal to the timeout length corresponding to the storage device.

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

[0025] The device type represents whether the storage device can be fixed relative to the electronic device.

[0026] In a possible implementation, in a case where the second transfer condition corresponding to the storage device is met, the method further includes:

[0027] A corresponding processing process for the storage device is started, the processing process being used for screening the second data corresponding to the storage device in the cache region, and the second data being written to the corresponding storage device.

[0028] The second data selected by the processing process is locked to prevent other processing processes from processing.

[0029] The second aspect of the application provides a data write control device, the device comprising:

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

[0031] The first transfer condition comprises that a remaining space of a cache region is less than a data amount of the target data, or a corresponding cache data amount of the target storage device in the cache region reaches a corresponding cache upper limit value of the target storage device; and the cache region is a region deployed in a memory space of the electronic device.

[0032] A cache write unit is configured to write first data in the cache region to a storage device corresponding to the first data in a case where the first transfer condition is met.

[0033] A data write unit is configured to write the target data to the cache region in a case where the first transfer condition is not met, and data in the cache region is written to a corresponding storage device in a case where a second transfer condition is met.

[0034] The third aspect of the application provides a computer program product, comprising computer readable instructions, when the computer readable instructions are executed on an electronic device, the electronic device implements the data write control method of the first aspect or any implementation manner of the first aspect.

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

[0036] The memory is configured to store a computer program.

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

[0038] The fifth aspect of the application provides a computer 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 can implement the data write control method of the first aspect or any implementation manner of the first aspect.

[0039] By the technical solution, the data writing control method, device, electronic equipment and storage medium provided by the application are provided. When target data is written to a target storage device, the target data is first written to a cache area in the memory. The data in the cache area is written to the target storage device when the second transfer condition is met. In the specific implementation, the target data is written to the cache area only when the remaining space of the cache area is sufficient and the corresponding cache data amount of the target storage device in the cache area does not reach the corresponding cache upper limit value. Accordingly, the first data in the cache area can be written to the corresponding storage device when the remaining space of the cache area is insufficient, and the first data in the cache area can be written to the corresponding storage device when the corresponding cache data amount of the target storage device in the cache area reaches the corresponding cache upper limit value. Therefore, the application adds the limitation condition that the data written to the cache area cannot exceed the corresponding cache upper limit value of the storage device, and adds the 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. In this way, the situation that the cache area continuously has insufficient remaining space can be avoided, and the continuous writing of data from the cache area to the storage device is not triggered, thereby avoiding the situation that the electronic equipment is running in a lagging manner due to the continuous occupation of the electronic equipment resources. BRIEF DESCRIPTION OF DRAWINGS

[0040] The above and other features, advantages, and aspects of the present disclosure will become more apparent by describing in detail the following specific embodiments with reference to the attached drawings. Throughout the drawings, the same or similar reference numerals refer to the same or similar elements. It should be understood that the drawings are schematic, and the original and elements are not necessarily drawn according to the scale.

[0041] Figure 1 A flowchart of a data writing control method provided by an embodiment of the application;

[0042] Figure 2 An example diagram of a storage device in an embodiment of the application;

[0043] Figure 3 Another example diagram of a storage device in an embodiment of the application;

[0044] Figure 4 An example diagram of triggering data writing in an embodiment of the application;

[0045] Figure 5 An example diagram of a cache area in an embodiment of the application;

[0046] Figure 6 A partial flowchart of a data writing control method provided by an embodiment of the application;

[0047] Figure 7Another part of the flow chart of the data writing control method provided by the embodiment of the present application;

[0048] Figure 8 Another part of the flow chart of the data writing control method provided by the embodiment of the present application;

[0049] Figure 9 The structural schematic diagram of the data writing control device provided by the embodiment of the present application;

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

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

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

[0053] Figure 13 The flow chart of enabling the write cache in the external storage device in the computer using the Linux operating system provided by the embodiment of the present application;

[0054] Figure 14 The flow chart of writing into the external storage device in the computer using the Linux operating system provided by the embodiment of the present application;

[0055] Figure 15 The flow chart of calculating the write speed of the external storage device in the computer using the Linux operating system provided by the embodiment of the present application;

[0056] Figure 16 The flow chart of writing when the dirty data page of the external storage device times out in the computer using the Linux operating system provided by the embodiment of the present application. DETAILED DESCRIPTION

[0057] The embodiments of the present application are described below in conjunction with the drawings of the embodiments of the present application. The terms used in the embodiment part of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0058] The embodiments of the present application are described below in conjunction with the drawings. It is known to those skilled in the art that with the development of technology and the appearance of new scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.

[0059] The terms "first", "second", and the like in the description and in the claims of the present application and above-described drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, and this is merely a way of distinguishing between objects of the same property used in the description of embodiments of the present application. In addition, the terms "comprise" and "have" and any variations thereof are intended to cover non-exclusive inclusion, so that a process, method, system, product or apparatus including a series of units does not have to be limited to those units, but can include other units not clearly listed or inherent to the process, method, product or apparatus.

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

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

[0062] Step 101: In response to a data write instruction, it is determined whether a first transfer condition is met, and in the case that the first transfer condition is met, step 102 is executed; in the case that the first transfer condition is not met, step 103 is executed.

[0063] The data write instruction is used to write target data from the electronic device to the target storage device. For example, as shown in Figure 4 , a user selects a compressed file a on the screen of a notebook and selects "send to removable device H", in response to the user operation, a data write instruction is obtained, which is used to write the compressed file a from the notebook to the removable device H. In response to the data write instruction, it is determined whether the first transfer condition is met.

[0064] Specifically, the first transfer condition can include that a remaining space of the cache region is less than a data amount of the target data, or a corresponding cache data amount of the target storage device in the cache region reaches a corresponding cache upper limit value of the target storage device.

[0065] The cache region is a region deployed in a memory space of the electronic device. For example, as shown in FIG. 1, in a memory space of a notebook computer, a remaining memory region except for a memory occupied by hardware running and a memory occupied by an operating system running is a cache region, and the cache region is a transit storage region for writing target data from the notebook computer to the removable device H. Figure 5

[0066] It should be noted that the remaining space of the cache region is less than the data amount of the target data, which can be understood as that the remaining space of the cache region is insufficient to write the target data.

[0067] In the cache region, each storage device connected to or deployed in the electronic device is configured with a cache upper limit value in the cache region, and the corresponding cache upper limit value of the storage device represents a maximum value of an amount of data corresponding to the storage device allowed to be stored in the cache region. Correspondingly, the corresponding cache data amount of the target storage device in the cache region reaching the corresponding cache upper limit value of the target storage device can be understood as that the amount of data corresponding to the target storage device stored in the cache region reaching the corresponding cache upper limit value of the target storage device.

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

[0069] Step 102: writing first data in the cache region to a storage device corresponding to the first data.

[0070] In the embodiment, when data is written to a storage device, a minimum writing unit of data amount, such as a minimum data page, is written each time. If the first data cannot be written at one time, the first data can be written to the storage device multiple times until the first data is written completely.

[0071] In an implementation manner, the first data is data that is written first in the cache region, that is, data with the maximum continuous writing duration in the cache region. The storage device corresponding to the first data can be the target storage device or another storage device.

[0072] Step 103: writing target data to the cache region.

[0073] In the embodiment, when data is written to the cache region, a minimum writing unit of data amount, such as a minimum data page, is written each time.

[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 an implementation manner, different storage devices correspond to same or different second transfer conditions. The second transfer condition corresponding to a storage device is an interval threshold based condition. Specifically, the processing operation of writing the data in the cache area to the corresponding storage device is performed once per interval of the interval threshold, such as 30 seconds or 10 seconds. The interval threshold corresponding to different storage devices is same or different.

[0076] Specifically, the interval threshold corresponding to a storage device can be determined based on the device type of the storage device, which represents whether the storage device is fixed relative to the electronic device. For example, the storage device fixed relative to the electronic device is a non-removable device, and the 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 the removable device, the processing operation of writing the data in the cache area to the corresponding storage device is performed once per 3 seconds; for example, for the non-removable device, the processing operation of writing the data in the cache area to the corresponding storage device is performed once per 30 seconds.

[0078] By the above technical solution, in the data writing control method provided by the 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 the specific implementation, only when the remaining space of the cache area is sufficient and the corresponding cache data amount of the target storage device in the cache area does not reach the corresponding cache upper limit value, the target data is written to the cache area. Correspondingly, the first data in the cache area can be written to the corresponding storage device when the remaining space of the cache area is insufficient, and the first data in the cache area can be written to the corresponding storage device when the corresponding cache data amount of the target storage device in the cache area reaches the corresponding cache upper limit value. Thus, in the present application, the limitation condition that the data written to the cache area cannot exceed the corresponding cache upper limit value of the storage device is added, and the 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 that the cache area is continuously insufficient in remaining space, and thus the continuous writing of data from the cache area to the storage device is not triggered, thereby avoiding the situation that the electronic device is running in a lagging manner due to the continuous occupation of the electronic device resources.

[0079] In an implementation manner, for the target storage device, the corresponding cache upper limit value of the target storage device can be obtained by the following processing flow in the embodiment, such as:Figure 6 As shown in the figure:

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

[0081] The device attribute can include at least one of a device name, an interface type, a transmission protocol, and a storage capacity.

[0082] Specifically, in the case where the target storage device is a removable device, in the process of accessing the target storage device to the electronic device, the electronic device can read the device attribute of the target storage device through the connection between the electronic device and the target storage device when the target storage device is detected to be accessed; in the case where the target storage device is a non-removable device, the device attribute of the target storage device can be collected by a controller such as a basic input output system (BIOS) during the startup of the electronic device.

[0083] The interface type is the interface type of the connection interface on the target storage device for connecting 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 attribute.

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

[0086] In one implementation, taking the device attribute as an example, the device name, in this embodiment, the corresponding write speed, i.e., 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 operation performed by the user on one or more storage devices, and based on this, the first write speed can be determined according to the device name of the target storage device.

[0088] In another implementation, taking the device attribute as an example, the interface type, in this embodiment, the corresponding write speed, i.e., 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, the theoretical write speed of one or more interface types can be set in advance to establish a mapping relationship between the interface type and the write speed. Based on this, the first write 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 write speed of the interface. Therefore, in this embodiment, the theoretical write speed of the storage device can be the average write speed of a common storage device of the same interface type. For example, a storage device with a USB2.0 interface corresponds to a theoretical write speed of 20 MB per second; a storage device with a USB3.0 interface corresponds to a theoretical write speed of 300 MB per second. For another example, a storage device with a gigabit network interface corresponds to a theoretical write speed of 100 MB per second, and a storage device with a hundred megabit network interface corresponds to a theoretical write speed of 10 MB per second.

[0091] In another implementation, taking the device attribute as the transmission protocol, in this embodiment, the first write speed can be determined according to the transmission protocol between the target storage device and the electronic device based on the mapping relationship between the transmission protocol and the write speed.

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

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

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

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

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

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

[0098] Based on the above implementation scheme, the method in the embodiment can further include the following processing, as shown in Figure 7

[0099] Step 701: Obtain a second write speed.

[0100] The second write speed can be a real-time write speed of writing data in the cache area to the target storage device.

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

[0102] For example, in the embodiment, the amount of data written from the cache area of the notebook memory to the U disk or the SATA hard disk is counted every 0.02 seconds, and for each 0.02 seconds, the amount of data written in the 0.02 seconds is divided by 0.02 seconds to obtain the second write speed.

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

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

[0105] In one implementation mode, the embodiment can further include the following processing, as shown in Figure 8

[0106] Step 801: Monitor whether the second transfer condition corresponding to each storage device is met, and if the second transfer condition corresponding to the storage device is met, execute step 802, and if the second transfer condition corresponding to the storage device is not met, continue to execute step 801.

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

[0108] Specifically, in the 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, in the embodiment, the data whose duration for being written into the cache area reaches the timeout duration corresponding to the storage device, that is, the second data, is screened out.

[0109] The timeout duration corresponding to the storage device is determined based on the device type of the storage device, and the device type represents whether the storage device can be fixed relative to the electronic device. The timeout duration corresponding to the storage device can be the same or different under different device types. 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: writing the second data into the corresponding storage device.

[0111] The second transfer condition corresponding to the storage device includes that the interval duration between the current time and the time when the second data corresponding to the storage device is screened in the cache area last time reaches an interval threshold. The interval thresholds corresponding to different storage devices are the same or different.

[0112] That is, in the embodiment, when detecting whether the second transfer condition is met in step 801, it can be judged whether the interval duration between the current time and the time when step 802 is executed last time reaches the interval threshold. If so, step 802 and step 803 are executed again. If not, it is continued to wait until the interval duration reaches the interval threshold, and then step 802 is executed once.

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

[0114] In a specific implementation, when it is monitored in step 801 that the second transfer condition corresponding to the storage device is satisfied, a corresponding processing process for the storage device can be started first, which is used to execute steps 802 and 803. That is, in the embodiment, a processing process can be started for each storage device for which it is monitored that the second transfer condition is satisfied, and the processing process is used to screen the second data corresponding to the storage device in the cache area and write the screened second data to the corresponding storage device.

[0115] It should be noted that after the processing process corresponding to the storage device screens the second data, the second data can be locked, so as to prohibit other processing processes. For example, when the second transfer condition corresponding to the storage device 1 is satisfied, the processing process 1 is started, the processing process 1 screens the cache data corresponding to the storage device 1, that is, the second data, in the cache area, and 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 the embodiment of the application, and the following introduces a device for executing the data writing control method.

[0117] Reference Figure 9 A structure diagram of a data writing control device provided by the embodiment of the application is shown in the figure, and the device can be deployed in an electronic device in which a storage device is deployed or an electronic device connected with a storage device. The storage device can be a removable device independent of the electronic device, for example, a U disk connected with a notebook through a data interface, as shown in FIG. 1; or the storage device can be a non-removable device integrated in the electronic device, for example, a SATA (Serial Advanced Technology Attachment) hard disk built in a notebook, as shown in FIG. 2. The technical solution in the embodiment is mainly used to solve the situation that the electronic device runs with lag when data is written to the storage device. Figure 2 Figure 3

[0118] Specifically, the device in the embodiment can include the following structure:

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

[0120] The first transfer condition includes that a remaining space of a cache area is less than a data amount of the target data, or a corresponding cache data amount of the target storage device in the cache area reaches a cache upper limit value corresponding to the target storage device; and the cache area is a region of a memory space of the electronic device. ​​

[0121] The cache writing unit 902 is configured to write the first data in the cache region to the storage device corresponding to the first data if the first transfer condition is met.

[0122] The data writing unit 903 is configured to write the target data to the cache region if the first transfer condition is not met, and data in the cache region is written to the corresponding storage device if a second transfer condition is met.

[0123] According to the technical solution described above, in the data writing control device provided by the embodiment of the present application, when writing target data to a target storage device, the target data is first written to a cache region in the memory, and data in the cache region is then written to the target storage device if a second transfer condition is met. In a specific implementation, the target data is written to the cache region only when the remaining space of the cache region is sufficient and the corresponding cache data amount of the target storage device in the cache region does not reach the corresponding cache upper limit value. Accordingly, the first data in the cache region can be written to the corresponding storage device when the remaining space of the cache region is insufficient, and the first data in the cache region can be written to the corresponding storage device when the corresponding cache data amount of the target storage device in the cache region reaches the corresponding cache upper limit value. Thus, the present application adds a restriction condition that the data written to the cache region cannot exceed the corresponding cache upper limit value of the storage device, and adds an executable condition that the data written from the cache region to the storage device reaches the corresponding cache upper limit value of the storage device. In this way, the cache region can be prevented from continuously being in a situation of insufficient remaining space, and continuous writing of data from the cache region to the storage device is thus avoided, thereby avoiding a situation of running lag of the electronic device caused by continuous occupation of resources of the electronic device.

[0124] In an implementation manner, the apparatus in the embodiment can further include the following units, as shown in Figure 10

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

[0126] In an implementation manner, the upper limit setting unit 904 is further configured to obtain a second writing speed, the second writing speed being a real-time writing speed of writing data in the cache region 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 an implementation manner, the apparatus in the embodiment can further include the following units, such as Figure 11 as shown in the following:

[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 met; in the case that the second transfer condition corresponding to the storage device is met, 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 comprises: an interval length from a previous time when the second data corresponding to the storage device is screened in the cache area to a current time reaches an interval threshold; and 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 a timeout length corresponding to the storage device; and a duration for which the second data is written into the cache area is greater than or equal to the timeout length corresponding to the storage device.

[0131] wherein the timeout length corresponding to the storage device is determined based on a device type of the storage device; and wherein the device type represents whether the storage device can be fixed relative to the electronic device.

[0132] In an implementation manner, in the case that the second transfer condition corresponding to the storage device is met, the data transfer unit 905 is further configured to: start a corresponding processing process for the storage device, wherein 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 the embodiment can refer to the corresponding content in the foregoing, which will not be described in detail here.

[0135] In the embodiment of the application, an electronic device is also provided. It includes at least one processor and a memory connected to the processor, wherein: the memory is used to store a computer program; and 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 the above embodiments.

[0136] Reference is made to Figure 12The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 12 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

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

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

[0139] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the data writing control methods provided in this application.

[0140] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the data writing control methods provided in this application.

[0141] The following section uses a Linux operating system computer as an example to illustrate the technical solution of this application in detail:

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

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

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

[0145] Step 1: Detecting the access of the external storage device, start the following process of setting the cache attribute;

[0146] After starting the computer, 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 the present application detects the access of the device, it can detect whether the device is an external access device (also known as external storage). After confirming that the device is an external access device (i.e. an external storage device), the external access device related information of the external storage device is read and copied to the device data structure.

[0148] Step 2: Determine whether the 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 attribute of the external storage device;

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

[0150] If the device does not use the "O-SYNC flag", it indicates that the device uses the write cache function.

[0151] Step 3: After determining that the write cache function is used, read the information of the external storage device, such as device name, interface type, transmission protocol, and storage capacity. Then, according to the pre-set method for calculating the write speed, select one method to calculate the write speed, and set the write cache size of the external storage device (i.e. the cache upper limit value mentioned above). Also, set the dirty data page timeout time of the external storage device (i.e. the timeout time mentioned above). End the process of setting the cache properties of the device.

[0152] In the process of determining the write speed calculation method to be used by the device and reading the related information, first, read and confirm the user's pre-set method for calculating the write speed. 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 according to the capacity size of the device; for non-removable external storage devices, the write speed can be calculated according to the type of transmission protocol of the device.

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

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

[0155] The first calculation method is to set the write speed size corresponding to the user's pre-set external storage device name in advance. In this calculation method, the user is allowed to set the name and the write speed size corresponding to the name for one or more external storage devices in advance. Next, find the matching name and write speed size in the list of pre-set name and corresponding write speed size, and save the write speed in the data structure of the external storage device.

[0156] The second calculation method is according to the interface type of the external storage device. For example, the USB2.0 and USB3.0 interfaces are slightly different, and the theoretical transmission speed of USB3.0 is 10 times that of USB2.0. In this case, the application can set the theoretical write speed of the external storage device with a USB2.0 interface to 20 MB per second, and the theoretical write speed of the external storage device with a USB3.0 interface to 300 MB per second. Another example is the interface difference of network external storage devices. Considering that there are gigabit network interfaces and hundred megabit network interfaces, the maximum transmission speeds are 100 MB per second and 10 MB per second, respectively, so 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 transmission protocol of the external storage device. For example, M.2 interface external storage devices have both SATA protocol and NVME protocol, in which case the M.2 interface external storage device using the SATA protocol is set to a default theoretical write speed of 500 MB per second, and the M.2 interface external storage device using the NVME protocol is set to a default theoretical write speed of 1000 MB per second. In terms of the actual write speed of the M.2 interface external storage device, this setting is basically the normal write speed of an external storage device without self-caching.

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

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

[0160] The theoretical write speed of each external storage device is temporarily recorded in the data structure of the external storage device as the write speed SPEEDS, which is the SPEEDS of each device separately.

[0161] The process of setting the theoretical write speed SPEEDS of the external storage device is ended, and the value of SPEEDS is confirmed.

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

[0163] This step is to calculate the independent write cache size of the external storage device according to the theoretical write speed of the external storage device. Users can set the dirty data page existence time multiplier RN and URN for removable devices (U disks, etc.) and non-removable devices (SATA hard drives) respectively. In the absence of user settings, the default multiplier is 3 and 30.

[0164] It should be noted that the reason for RN defaulting to 3 is that considering the operation of manually or automatically synchronizing and then removing the removable device, in order to reduce user waiting time, the total write cache write time is preferably controlled within 3 seconds. The default URN is 30, which is the default setting of the dirty data page timeout time of the mainstream Linux operating system.

[0165] The RN set here is the multiplier commonly used by each removable external storage device using the write cache, and the URN is the multiplier 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 using the write cache connected to the system is RN multiplied by the SPEEDS of the device, and the write cache size of the non-removable external storage device using the write cache connected to the system is URN multiplied by the SPEEDS of the device.

[0166] Step 6: Because the dirty data page must be temporarily stored in the memory, the absolute upper limit of the write cache size of the external storage device cannot exceed the total available memory size, so compare the size of CURWB with the total available memory size, and set the size that exceeds the total available memory size to the size of the total available memory. Set CURWB as the dedicated write cache size of the 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 user's preconfigured dirty data page timeout time. According to the dirty data page timeout time set by the user for removable external storage devices and the dirty data page timeout time set by the user for non-removable external storage devices, the two types of external storage devices are set. This application supports setting different external storage timeout times for removable external storage devices and non-removable external storage devices. By default, the dirty data page timeout time of the removable external storage device is 3 seconds, and the dirty data page timeout time of the non-removable external storage device 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 in step 6, if CURWB is greater than or equal to the size of all available memory, the user in this application adopts the way of directly setting the device write cache size or the way of calculating the dedicated write cache size according to the transmission protocol. In step 7, the timeout length of the dirty data page of the removable storage device is generally short, and should be set to a length that the user does not perceive.

[0170] In addition to the main process of the present application, in order to make the existing write cache function of the mainstream linux system fully compatible with the present scheme, the present application also has some process innovations or improvements based on the original write cache scheme. The following flowchart will show the innovations and improvements on the original process.

[0171] As shown in Figure 14 , the process of writing to the storage device in the case of using the present application is as follows:

[0172] When copying data in a storage device using the cache scheme of the present application, first determine whether the memory is not used up and whether the dedicated write cache space is not used up. If the memory is not used up and the dedicated write cache space is not used up, then write data to the dedicated write cache (i.e. cache area) in the smallest write unit (page), then determine whether the data to be copied this time is copied, if it is copied, it is ended, if it is not copied, then return to continue to determine whether the memory is not used up and whether the dedicated write cache space is not used up; if the memory is used up or the dedicated write cache space is used up, then write the data in the dedicated write cache space to the storage device according to the first-in-first-out rule (write in the smallest write unit according to the storage device), and then return to continue to determine whether the memory is not used up and whether the dedicated write cache space is not used up.

[0173] As shown in Figure 15 , the process of calculating the write speed of the storage device using the present application is as follows. The condition for using this process is that the user manually or automatically triggers batch writing (data synchronization operation). As shown in Figure 15 , in the process of calculating the write speed of the storage device using the present application, the following steps are included:

[0174] Step 1501: Prepare to write to the storage device in batches;

[0175] In the process of preparing to write to the storage device in batches, the data structure and write cache attributes of the storage device such as the size of the dedicated write cache and the write cache timeout time are read. In particular, the device node is saved for backup when writing to the device.

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

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

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

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

[0180] Step 1504: Determine whether there is still an unprocessed write cache, i.e., the external storage device still has a to-be-written cache to be processed. If there is an unprocessed write cache, go to step 1505, otherwise, the write operation can be ended.

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

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

[0183] In the process of selecting the next unprocessed to-be-written cache and writing it to the device, it has been confirmed that it can be written through the last process, the data is taken out from the cache data structure and written to the device using the write function provided by the device, the data amount of this write is recorded, and after the write is completed, go to 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 (default 0.02 seconds, which can be adjusted). If the difference cTime is greater than 0.02 seconds, go to 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 the difference cTime is greater than 0.02 seconds, the action of calculating the write speed is started. 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 the difference cTime is less than 0.02 seconds, continue the write process without performing the action of calculating the write speed.

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

[0187] In the process of updating the writing amount wData, the data amount recorded in the last process is added to wData, in units of MB. This process will go to the process exit and end the process when it is determined that there is no unprocessed write cache.

[0188] As shown in Figure 16 The external storage device dirty data page timeout writing process of the present application is used. The external storage device dirty data page timeout writing process of the present application is divided into the following steps:

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

[0190] In the process of starting the timing task, the process of traversing the write cache set in the kernel ends the sleep time, and the running process is started.

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

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

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

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

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

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

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

[0198] In the process of reading the special dirty data page timeout time eTime of the external storage device to which the cache belongs, the write cache obtained can be used to determine the external storage device to which the write cache belongs, and then the special dirty data page timeout time eTime in the structure data of the external storage device is read.

[0199] Step 1606: Determine whether the cache existence time is greater than the special dirty data page timeout time of the device, i.e., whether pTime is greater than eTime; if the cache has timed out, write the 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 cache existence time is greater than the special dirty data page timeout time of the device, the result of determining whether pTime is greater than eTime is 0.01 seconds. Different processes are followed according to different results. In the case of true result, step 1607 is executed;

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

[0202] For example, a larger write cache size is given to a high-speed read-write hard disk that frequently executes write commands; a larger write cache size is given to a hard disk that frequently executes write commands; a smaller write cache size is set for a slow-speed read-write hard disk that frequently executes read commands, and the time waiting for flushing dirty data pages to the external storage device is reduced.

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

[0204] 1. Configuring special write cache size and special dirty data page timeout time according to different external storage devices can significantly optimize the performance of external storage devices of different speeds, and can reduce the write consumption of the device and optimize the service life of the external storage device.

[0205] 2. The application can significantly reduce the situation of freezing except for executing the copy operation.

[0206] 3. The more accurate write speed calculation method can make the copy progress bar display accurate and provide a good user experience.

[0207] It should be noted that the apparatus embodiments described above are merely illustrative, and the units described as separate units can or can not be physically separate, and the units displayed as units can or can not be physical units, i.e., can be located in one place, or can be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiment. In addition, the connection relationship between the modules in the apparatus embodiment provided in the present application indicates that there is a communication connection between them, which can be 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 the present application can be realized by means of software and the necessary general hardware, and of course can also be realized by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. Generally, functions completed by computer programs can be easily realized by corresponding hardware, and the specific hardware structure for realizing the same function can also be various, such as analog circuit, digital circuit or special circuit, etc. However, for the present application, software program implementation is a better embodiment. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products, which are stored in readable storage media, such as computer floppy disks, U disks, mobile hard disks, ROM, RAM, magnetic or optical disks, etc., including a plurality of instructions for making a computer device (which can be a personal computer, a training device, or a network device, etc.) execute the methods described in various embodiments of the present application.

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

[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 can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transmitted from one website, computer, training device or data center to another website, computer, training device or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be stored by the computer or a data storage device such as a training device, a data center, etc. integrated with one or more available media sets. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.

Claims

1. A control method of data writing, characterized by, The method comprises: in response to a data write instruction, determining whether a first transfer condition is met; the data write instruction is used to write target data from an electronic device to a target storage device; wherein the first transfer condition comprises: the corresponding cache data amount of the target storage device in the cache region reaches the corresponding cache upper limit value of the target storage device; the cache region is a region deployed in the memory space of the electronic device; in the case where the first transfer condition is met, the first data in the cache region is written to the storage device corresponding to the first data; in the case where the first transfer condition is not met, the target data is written to the cache region, and the data in the cache region is written to the corresponding storage device in the case where a second transfer condition is met; wherein the method further comprises: monitoring whether the corresponding second transfer condition of each storage device is met; in the case where the corresponding second transfer condition of the storage device is met, screening the corresponding second data of the storage device in the cache region; write the second data to the corresponding storage device; wherein the corresponding second transfer condition of the storage device comprises: the interval time length from the last time the corresponding second data of the storage device is screened in the cache region reaches an interval threshold; the interval thresholds corresponding to different storage devices are the same or different.

2. The method of claim 1, wherein, The method further comprises: obtaining the device attribute of the target storage device; the device attribute comprises at least one of device name, interface type, transmission protocol and storage capacity; obtaining the first write speed corresponding to the target storage device according to the device attribute; obtaining the cache upper limit value corresponding to the target storage device according to the first write speed.

3. The method of claim 2, wherein, The method further comprises: obtaining a second write speed, which is a real-time write speed of writing data in the cache region to the target storage device; updating the cache upper limit value corresponding to the target storage device according to the second write speed.

4. The method of claim 1, wherein, Screening the corresponding second data of the storage device in the cache region comprises: screening the second data in the cache region according to the timeout time length corresponding to the storage device; the duration time length of the second data written to the cache region is greater than or equal to the timeout time length corresponding to the storage device.

5. The method of claim 4, wherein, The timeout time length corresponding to the storage device is determined based on the device type of the storage device; wherein the device type represents whether the storage device can be fixed relative to the electronic device.

6. The method of claim 1, wherein, In the case where the corresponding second transfer condition of the storage device is met, the method further comprises: starting a corresponding processing process for the storage device, which is used to screen the corresponding second data of the storage device in the cache region; write the second data to the corresponding storage device; wherein the second data screened by the processing process is locked to prohibit other processing processes.

7. A control device for data writing, characterized by comprising: The device comprises: The transfer judgment unit is configured to judge whether a first transfer condition is met in response to a data write instruction for writing target data from the electronic device to a target storage device; The first transfer condition includes that a corresponding cache data amount of the target storage device in a cache region reaches a corresponding cache upper limit value of the target storage device, and the cache region is a region deployed in a memory space of the electronic device. The cache write unit is configured to write first data in the cache region to a storage device corresponding to the first data in a case where the first transfer condition is met. The data write unit is configured to write the target data to the cache region in a case where the first transfer condition is not met, and data in the cache region is written to a corresponding storage device in a case where a second transfer condition is met. The data transfer unit is configured to monitor, for each of the storage devices, whether a second transfer condition corresponding to the storage device is met, to screen second data corresponding to the storage device in the cache region in a case where the second transfer condition corresponding to the storage device is met, and to write the second data to the corresponding storage device. The second transfer condition corresponding to the storage device includes that an interval time length from a previous screening of the second data corresponding to the storage device in the cache region reaches an interval threshold value, and interval threshold values corresponding to different storage devices are the same or different.

8. An electronic device, comprising: The electronic device includes at least one processor and a memory connected to the processor, wherein: The memory is configured to store a computer program; The processor is configured to execute the computer program to enable the electronic device to implement the data write control method according to any one of claims 1 to 6.

9. 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 the electronic device, the electronic device can implement the data write control method according to any one of claims 1 to 6.

Citation Information

Patent Citations

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

    CN110704335A

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

    CN116010303A