Data storage method and electronic equipment
By using memory disks as cache for the underlying storage device in the terminal device, the problem of slow storage speed of underlying storage devices in the terminal device is solved, and the storage speed is improved and cost savings are achieved.
Patent Information
- Application Number
- CN202311340160.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-16
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2043-10-16
AI Technical Summary
The storage speed of underlying storage devices in terminal devices is slow, resulting in inefficiency of the overall storage system.
The memory disk is used as the target cache for the first storage device with slower storage speed, and the data in the target cache is transferred to the first storage device according to the preset strategy to improve the storage speed.
By using memory disks as cache, the storage speed of the underlying storage devices is significantly improved, and the problem of sharp decline in capacity end performance is alleviated, and the hardware of electronic devices is not required to be changed, saving costs.
Smart Images

Figure CN119883955A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal equipment, and in particular to a data storage method and an electronic device. Background Art
[0002] There are many storage devices stored in the terminal equipment, such as REG, first-level cache (L1 cache), second-level cache (L2 cache), third-level cache (L3 cache), RAM (Random Access Memory), UFS (Univeral Flash Storage), EMMC (Embedded MultiMedia Card). The performance of these storage devices presents a classic pyramid shape. The closer the storage device is to the CPU, the faster it is, the higher the price, and the lower the capacity. Summary of the invention
[0003] In order to solve the above technical problems, the present application provides a data storage method and an electronic device, which can improve the storage speed of the underlying storage device.
[0004] In the first aspect, the present application provides a data storage method, which is applied to an electronic device, wherein the storage system of the electronic device includes a first storage device and a target cache, wherein the target cache is a partial area of a memory disk of the electronic device, and the method includes: receiving first data sent by a file system; determining a data type of the first data; if the data type of the first data is a first type, and the usage of the target cache is less than a first value, storing the first data in the target cache; and transferring the data in the target cache to the first storage device according to a preset first strategy. In this way, by using a memory disk as a target cache of a first storage device with a slower storage speed, the data storage speed of the storage system can be improved. At the same time, the memory disk is original to the electronic device, so the use of this method does not require changing the hardware of the electronic device, which can effectively save costs.
[0005] According to the first aspect, the memory disk is a RAM. Using the RAM as the target cache of the first storage device can not only greatly improve the storage speed of the first storage device, but also greatly alleviate the capacity end problem.
[0006] According to a first aspect, transferring data in a target cache to a first storage device according to a preset first strategy includes: transferring data in the target cache to the first storage device at a fixed time.
[0007] According to the first aspect, according to the preset first strategy, the data in the target cache is transferred to the first storage device, including: determining whether the usage of the target cache is greater than a second value, and the second value is less than the first value; if so, transferring the data in the target cache to the first storage device.
[0008] According to the first aspect, after transferring the data in the target cache to the first storage device, the method further includes: when the usage of the target cache is less than a third value, stopping transferring the data in the target cache to the first storage device, and the third value is less than the second value.
[0009] According to the first aspect, according to the preset first strategy, transferring the data in the target cache to the first storage device includes: when an event that requires the electronic device to be shut down immediately is detected, transferring all the data in the target cache to the first storage device; and performing a shutdown operation. In this way, the loss of stored data can be prevented and the stability of the storage of the first storage device can be maintained.
[0010] According to the first aspect, detecting an event that requires immediate shutdown of an electronic device includes: receiving an instruction to restart the electronic device; or detecting that the electronic device loses power; or receiving a shutdown instruction.
[0011] According to the first aspect, it also includes: receiving second data sent by the file system; determining the data type of the second data; if the data type of the second data is the first type, but the usage of the target cache is greater than or equal to the first value, storing the first data to the first storage device.
[0012] According to the first aspect, it also includes: receiving third data sent by the file system; determining the data type of the third data; if the data type of the third data is the second type, storing the first data to the first storage device.
[0013] According to the first aspect, the data belonging to the second type includes any one or more of the following: metadata; data related to checkpoints; synchronization data; and system-related data of applications.
[0014] According to the first aspect, determining the data type of the first data includes: setting the data type for the first data according to the file type information and / or data source information of the first data.
[0015] According to the first aspect, after setting the data type for the first data, the method further includes: adding a first tag to the first data, where the first tag is used to indicate the data type of the first data.
[0016] According to a first aspect, the first type is user data.
[0017] According to a first aspect, the first storage device is a universal flash memory UFS or an embedded multimedia card EMMC.
[0018] According to the first aspect, it also includes: reading hot data from the first storage device, the hot data being data with an access frequency greater than a first frequency; and storing the hot data in a target cache.
[0019] According to the first aspect, it also includes: receiving a read data instruction sent by the file system; determining whether the target cache includes the target data corresponding to the read data instruction; if so, reading the target data from the target cache.
[0020] According to the first aspect, it also includes: receiving fourth data sent by the file system; detecting an event that requires immediate shutdown of the electronic device; directly storing the fourth data in the first storage device, and transferring all data in the target cache to the first storage device.
[0021] According to the first aspect, the electronic device is a mobile phone or a tablet.
[0022] In a second aspect, the present application provides an electronic device, comprising: a memory and a processor, wherein the memory is coupled to the processor; the memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes any one of the data storage methods of the first aspect.
[0023] In a third aspect, the present application provides a computer-readable storage medium, including a computer program, which, when executed on an electronic device, enables the electronic device to execute any one of the data storage methods of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 is a schematic structural diagram of an illustrative electronic device 100;
[0025] Figure 2 1 is a software structure block diagram of an electronic device 100 according to an embodiment of the present application;
[0026] Figure 3 A storage architecture diagram of an electronic device is shown as an example;
[0027] Figure 4 The figure is a comparative example diagram of storage speed of a memory device and a UFS device;
[0028] Figure 5 A schematic diagram showing the relationship between random write performance and remaining capacity of a standard device as an example;
[0029] Figure 6 A schematic diagram of a data storage method is shown as an example;
[0030] Figure 7 This is a schematic diagram of another data storage method shown as an example;
[0031] Fig. 8A This is a flowchart of a data storage method according to an embodiment of the present invention;
[0032] Figure 8B For example, Fig. 8A A schematic diagram of a data storage path of a data storage method;
[0033] Figure 8C The waterline level example diagram of this embodiment is shown as an example;
[0034] Fig. 9A Another example flow chart of the data storage method in this embodiment is shown as an example;
[0035] Fig. 9B For example, Fig. 9A An example flow chart of step S906;
[0036] Fig. 9C For example, Fig. 9A Another example flow chart of step S906;
[0037] Fig.9D For example, Fig. 9A Another example flow chart of step S906;
[0038] Fig.9E For example, Fig. 9A Another example flow chart of step S906;
[0039] Fig.9F For example, Fig. 9A Another example flow chart of step S906;
[0040] Fig.10 Another example flow chart of the data storage method in this embodiment is shown as an example;
[0041] Fig.11 The figure is a schematic diagram showing another exemplary data storage method. DETAILED DESCRIPTION
[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0043] The term "and / or" in this article is merely a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0044] The terms "first" and "second" in the description and claims of the embodiments of the present application are used to distinguish different objects rather than to describe a specific order of objects. For example, a first target object and a second target object are used to distinguish different target objects rather than to describe a specific order of target objects.
[0045] This embodiment provides a data storage method, which can be applied to electronic devices such as mobile phones and tablets. Of course, it is not limited to these electronic devices.
[0046] In this embodiment, the structure of the electronic device can be as follows Figure 1 shown.
[0047] Figure 1 FIG. 1 is a schematic diagram of the structure of an electronic device 100 exemplarily shown. It should be understood that Figure 1 The illustrated electronic device 100 is merely one example of an electronic device, and the electronic device 100 may have more or fewer components than those shown in the figure, may combine two or more components, or may have a different configuration of components. Figure 1 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0048] See also Figure 1The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0049] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0050] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0051] A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.
[0052] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0053] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0054] Of course, in addition to the above components, the electronic device 100 may also include other hardware components, which are not listed here one by one.
[0055] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0056] Figure 2 1 is a block diagram of the software structure of the electronic device 100 according to an embodiment of the present application.
[0057] The layered architecture of the electronic device 100 divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer, an application framework layer, a system library, and a kernel layer.
[0058] The application layer can include a series of application packages.
[0059] like Figure 2 As shown, the application package may include camera, gallery, map, WLAN, music, short message, call, navigation, Bluetooth, video and other applications. Of course, these applications are only exemplary. In other embodiments, the application layer may include Figure 2 Applications not shown in the figure may also not include Figure 2 One or more applications shown in .
[0060] like Figure 2 As shown, the application framework layer may include a window manager, a resource manager, a view system, a content provider, a data storage module, etc.
[0061] Among them, the data storage module is used to execute the data storage method of the embodiment of the present application.
[0062] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0063] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0064] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0065] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0066] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0067] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0068] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0069] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0070] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.
[0071] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0072] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0073] A 2D graphics engine is a drawing engine for 2D (two-dimensional) drawing.
[0074] The kernel layer is the layer between hardware and software.
[0075] like Figure 2 As shown, the kernel layer may include display driver, Wi-Fi driver, audio driver, sensor driver, Bluetooth driver, etc.
[0076] Understandably, Figure 2 The layers in the software structure shown and the components included in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown, and each layer may include more or fewer components, which is not limited in the present application.
[0077] Figure 3 FIG. 1 is a storage architecture diagram of an electronic device shown as an example. Figure 3 As shown in the figure, the arrow points away from the CPU, and the upper storage device is closer to the CPU than the lower storage device. Figure 3 It can be seen that as the distance from the CPU increases, the capacity of storage devices increases, the speed decreases, and the price decreases. Low-level storage devices, such as UFS and EMMC, are the farthest from the CPU and have the slowest storage speed.
[0078] Compared with RAM devices and UFS NAND (Nand flash) devices, the maximum difference in reading and writing speed is more than 4 times, and there is a serious storage speed mismatch problem.
[0079] Figure 4 The figure is an example diagram showing the comparison of storage speeds of a memory device and a UFS device. Figure 4 In the disk file system, NAND Block devices (UFS devices) are used for storage, and memory file system is stored in memory Block devices (memory devices). Figure 4 It can be seen that memory blocks are far superior to NAND block devices in terms of both read speed and write speed.
[0080] In addition, for NAND media, due to the media properties of NAND itself, there has always been a problem of a sharp drop in performance at the end of capacity, such as Figure 5 As shown, Figure 5 The figure is a schematic diagram showing the relationship between the random write performance and the remaining capacity (i.e., free space) of a standard device. The upper-layer software optimization alone can only alleviate the problem of the capacity end performance but cannot fundamentally solve the problem of the capacity end performance drop. For RAM type storage media, there is no such capacity end performance drop problem.
[0081] Figure 6 FIG. 1 is a schematic diagram showing an exemplary data storage method. Figure 6 As shown, in this storage method, the data writing process is: after the data generated by the application layer is stored in the file system FS (File System), the file system FS defragments the data and then stores the defragmented data in the backup disk UFS. In this method, the data reading process is: the file system FS reads data from the backup disk UFS and then returns the read data to the application layer. Among them, the backup disk UFS includes GC (Garbage Collection) and WB (WriteBooster).
[0082] The underlying disk storage speed of this storage method is slow, and the underlying disk UFS has the problem of a sharp drop in performance at the end of capacity.
[0083] In one example, a technology increases the storage speed of the underlying storage device by adding a new cache device to the electronic device. In this technology, the electronic device has at least three storage hardware devices, namely: a memory disk, an underlying storage device, and a new cache device. Among them, the memory disk and the underlying storage device are the original hardware of the electronic device, and the new cache device is the newly added hardware in the electronic device. This technology is applied to large devices such as servers, and the new cache device is a non-volatile memory. This technology requires adding new hardware to the electronic device and modifying the hardware of the electronic device, so the cost is relatively high.
[0084] In order to solve the above problems, the embodiment of the present invention proposes a new data storage method, such as Figure 7 The embodiment of the present invention can accelerate the storage speed of the underlying device through RAM cache.
[0085] Furthermore, the embodiments of the present application optimize storage by using part of the original memory disk in electronic devices such as RAM as cache for underlying storage devices, which can not only greatly improve the storage speed of NAND media (such as UFS), but also greatly alleviate the capacity end problem.
[0086] Figure 7 FIG. 1 is a schematic diagram showing another exemplary data storage method. Figure 7 As shown, the storage system of this storage method includes a backup disk UFS and a memory disk, and the memory disk serves as a cache disk of the backup disk UFS. The data writing process of this storage method is: after the data generated by the application layer is stored in the file system FS (File System), the file system FS defragments the data and then caches the defragmented data to the cache disk of the backup disk UFS, that is, the memory disk. The memory disk flushes the data in the memory disk back to the backup disk UFS according to the preset flushing strategy.
[0087] It should be noted that Figure 7 The memory disk shown in should be understood as a part of the original memory disk in the electronic device. In this embodiment, no hardware is added to the electronic device, but the use method of a part of the original memory disk in the electronic device is changed, and the memory disk in this part of the area is used as a cache of the underlying disk such as UFS. Therefore, it can be said that the memory disk is a cache disk of the backup disk UFS.
[0088] It should be noted that Figure 7 The memory disk in the embodiment shown in is a volatile memory. Therefore, this embodiment subsequently provides a stability strategy to ensure that in the event of an unexpected power failure of the electronic device, the data in the memory disk as the cache of the underlying storage device is promptly flushed back to the underlying storage device to prevent data loss and ensure the stability of data storage in the hybrid storage system of this embodiment.
[0089] Figure 7 In the storage method shown, the data reading process is: the file system FS pre-reads hot data from the backup disk UFS to the memory disk, and then when receiving a read instruction for hot data, it reads the hot data from the memory disk to the file system FS, and the file system FS returns the data to the application layer. For cold data, the file system FS reads directly from the backup disk UFS without pre-reading from the memory disk.
[0090] Here, hot data and cold data are determined based on a preset hot and cold data classification strategy. For example, in one example, the hot and cold data classification strategy may be: data is classified into different categories based on the access frequency and importance of the data. Data determined to be hot data based on the hot and cold data classification strategy refers to data with a high access frequency and important to the business and applications, and such data usually needs to be accessed and processed quickly and efficiently. Data determined to be cold data based on the hot and cold data classification strategy refers to data with a low access frequency and not very important to the business and applications, and such data usually needs to be stored for a long time, but does not need to be frequently accessed and processed.
[0091] It should be understood that the above hot and cold data classification strategies are merely examples, rather than limitations on the hot and cold data classification strategies. In addition to the above hot and cold data classification strategies, this embodiment may also adopt other hot and cold data classification strategies.
[0092] In the above example, data is divided into two categories: cold data and hot data. In other examples, data can also be divided into three categories: cold data, warm data, and hot data.
[0093] In this article, data flushing or back flushing refers to transferring data from the current storage device (such as Figure 7 Memory disk in the memory) to other storage devices (such as Figure 7 UFS in , that is, reading data from the current storage device, storing it in another storage device, and then deleting the data from the current storage device.
[0094] Below Figure 7 The target cache in each embodiment shown below refers to Figure 7 The memory disk (ramdisk) in .
[0095] Fig. 8A FIG. 1 is a flowchart of a data storage method according to an embodiment of the present invention. The method is applied to Figure 7 Storage system including cache disks shown. See Fig. 8A In this embodiment, the data storage method may include the following steps:
[0096] S801, receiving first data sent by a file system.
[0097] S802: Determine the data type of the first data.
[0098] S803: If the data type of the first data is the first type and the usage of the target cache is less than the first value, store the first data in the target cache.
[0099] The target cache is a partial area of the memory disk of the electronic device.
[0100] S804: According to a preset first strategy, transfer the data in the target cache to a first storage device.
[0101] The first storage device may be, for example, Figure 7 Alternatively, the first storage device may be EMMC, but is certainly not limited thereto.
[0102] The target cache can be Figure 7The memory disk in the memory, such as RAM, is of course not limited to this. When RAM is used as the target cache, since RAM type storage media does not have the problem of steep performance drop at the end of capacity, at the end of capacity, the read and write data are preferentially written to the cache device, which can greatly improve the end storage performance, especially the end storage performance of the underlying storage system.
[0103] Figure 8B For example, Fig. 8A Schematic diagram of the data storage path of the data storage method in FIG. Figure 8B As shown, in this embodiment, in the process of writing data in the file system to the backup device disk USF, the data is first written to the memory disk (such as a RAM cache disk) used as a cache, and then the data in the cache is transferred to the backup device disk USF. In this way, due to the fast reading and writing speed of the memory disk, the matching degree of the storage speed of the memory used by the file system and the memory disk used as the backup device disk USF cache is improved, and the speed of writing data from the file system to the backup device disk USF can be accelerated, thereby improving the storage speed.
[0104] The data types can be divided into user data and non-user data. Non-user data can be, for example, metadata, Checkpoint-related data, Sync data (synchronization data), some special data, etc. The first type in step S803 can be user data.
[0105] The first value is preset, and the first value is less than 100%. For example, in one example, the first value may be 90%.
[0106] The first value is usually a higher value, and the first value is the third waterline mentioned in the subsequent content. When the usage of the target cache is less than the first value, the target cache can continue to cache a larger amount of data. At this time, storing the first data in the target cache can improve the storage speed of the entire underlying storage system. When the usage of the target cache is greater than or equal to the first value, it means that the remaining capacity of the target cache is very small. At this time, if the amount of data to be written is large, the remaining capacity of the target cache is insufficient to accommodate the amount of data to be written. Continuing to write data to the target cache will cause data overwrite and loss. Therefore, when the usage of the target cache is greater than or equal to the first value, the first data is not allowed to be stored in the target cache. Instead, the first data is directly stored in the first storage device to avoid data loss.
[0107] The first strategy may also be called a flush strategy, that is, a strategy for transferring the data in the target cache to the first storage device. The flush strategy is described here.
[0108] It should be noted that when the first storage device is performing a read operation, the electronic device prohibits the target cache from flushing data back to the first storage device.
[0109] When the first storage device is performing a read operation, the data flushing operation is prohibited. This is because: concurrent read and write operations with large amounts of data have a great impact on the performance of the electronic device, especially on the speed of reading data (reducing the speed of reading data), and the upper-layer application is very aware of this. Therefore, when the first storage device performs a read operation, the flushing operation is prohibited in most cases. However, there is an exception, that is, when the electronic device fails, in this case, even if the first storage device is performing a read operation, the electronic device will definitely write all the contents of the target cache back to the underlying device (the first storage device).
[0110] In one example, the flush policy may be:
[0111] All the data in the target cache are flushed back to the first storage device periodically, that is, a flush operation is performed at a preset time interval.
[0112] In this example, every time the preset time interval expires, all data in the target cache except the pre-read data (i.e., data pre-read from the first storage device to the target cache) is flushed back to the first storage device at one time. The flushed back data refers to non-pre-read data (there is non-pre-read data in the target cache, but there is no non-pre-read data in the first storage device). For the pre-read data, one copy of the pre-read data is stored in the target cache, and one copy of the pre-read data is stored in the underlying first storage device.
[0113] In another example, the refresh policy can also be based on Figure 8C The waterlines (Level 1 and Level 2) shown control the flushing of cached data in the target cache.
[0114] See also Figure 8C , this embodiment also proposes a cache waterline control strategy.
[0115] Figure 8C FIG. 2 is an exemplary diagram of the waterline level in this embodiment. Figure 8C As shown in the example, the waterline level is divided into 3 levels, from low to high, Level 1 (called the first waterline), Level 2 (called the second waterline), and Level 3 (called the third waterline), where:
[0116] Level 3: When the usage of the cache device exceeds this waterline, a passthrough (i.e. bypassing the cache and writing directly to the underlying device) method is used to store all data from the file system directly to the first storage device (backup device disk), and no longer cached through the target cache.
[0117] Level 2: When the target cache usage exceeds the waterline, the flush operation is started.
[0118] Level 1: When the target cache usage is lower than this value, the flush operation is stopped.
[0119] In one example, the value of Level 1 may be 25%, the value of Level 2 may be 50%, and the value of Level 3 may be 90%. Of course, this is only exemplary, and the embodiment does not limit the specific values of each waterline.
[0120] This embodiment also adopts some strategies to ensure the stability of storage, and these strategies are called stability strategies.
[0121] (1) Data storage
[0122] In one example, when the data to be stored is metadata, the metadata is directly stored in the first storage device (i.e., the backup device disk) without being cached via the target cache. In other words, the basic file system only exists in the backup device disk. In this way, metadata loss can be prevented. For example, if the electronic device loses power unexpectedly, the data in the target cache cannot be flushed back to the backup device disk in time, resulting in the loss of the data.
[0123] In one example, the data in the target cache is periodically flushed back to the backup device disk. In this way, the data in the target cache can be cleaned up in time, so that the target cache has enough remaining capacity for the next data storage, ensuring the normal operation of the cache mechanism.
[0124] (2) Normal power on and off
[0125] When rebooting (restarting) through the normal process, the write-back mechanism is triggered in the shutdown process, and the write mode is switched to the passthrough mode. After all the data in the target cache is written to the backup device disk, the shutdown process is performed again. Therefore, when the electronic device receives the instruction to restart the electronic device, all the data in the target cache is flushed back to the first storage device, and then the shutdown operation is performed.
[0126] In addition, in other scenarios where the electronic device needs to be shut down immediately, all data in the target cache must be written to the backup device disk (first storage device) before the shutdown operation is performed. For example, other scenarios where the electronic device needs to be shut down immediately may include: detecting that the electronic device loses power, receiving a shutdown command, etc.
[0127] (3) Special treatment
[0128] a. When a checkpoint event is triggered, the electronic device writes the data related to the checkpoint directly to the backup device disk without passing through the target cache.
[0129] b. When the Sync event is triggered, the electronic device directly stores the synchronization data in the backup device disk without passing through the target cache.
[0130] c. When some special data is processed by the f2fs file system and passed to the block device layer, it is determined whether it needs to pass through the cache device. If necessary, the special data is first stored in the target cache and then flushed from the target cache to the backup device disk. If not, the special data is directly stored in the backup device disk without passing through the target cache.
[0131] For example, the special data that does not pass through the target cache and needs to be directly stored in the backup device disk may be system-related data of the application.
[0132] (4) Data recovery
[0133] In some scenarios, if power is off abnormally, the data in the backup device disk can be restored through the checkpoint area in the backup device disk.
[0134] By adopting the above stability strategy, this embodiment can use the original memory disk in the electronic device as the underlying storage device cache to improve the storage speed of the underlying storage device, and can also avoid data loss due to the memory disk being a volatile memory.
[0135] It can be seen from the above embodiments that Fig. 8A The illustrated embodiment uses a hybrid storage architecture including using a memory disk as a cache to store data to a backup device disk (e.g. Figure 7 When writing data, the UFS in the storage system will give priority to writing data to the cache device, which greatly improves the read and write speed of the storage system and doubles the basic IO (input / output) performance in some scenarios.
[0136] Fig. 9A FIG. 1 is another example flow chart of the data storage method in this embodiment. The method is applied to Figure 7 Storage system including cache disks shown. See Fig. 9A In this embodiment, the data storage method may include the following steps:
[0137] S901, receiving data a sent by the file system.
[0138] S902, determine the data type of data a.
[0139] S903, determine whether the data type of data a is the first type, if yes, execute step S904, otherwise execute step S907.
[0140] S904, determining whether the usage of the target cache is less than the third waterline, if so, executing step S905, otherwise executing step S907.
[0141] For example, the third waterline here may be 90%.
[0142] It should be noted that the value of the third waterline can be a percentage or a capacity value.
[0143] In this document, “target cache usage” may be a percentage of the used capacity in the target cache to the total capacity of the target cache, or may be a used capacity value in the target cache.
[0144] For example, when the value of the third waterline is a percentage, "target cache usage" refers to the percentage of the used capacity in the target cache to the total capacity of the target cache. For example, if the value of the third waterline is 90%, the total capacity of the target cache is 100GB, and the used capacity in the target cache is 80GB, then the target cache usage is 80%, and the target cache usage (80%) is less than the third waterline (90%).
[0145] For example, when the value of the third waterline is a capacity value, "target cache usage" refers to the used capacity value of the target cache. For example, if the total capacity of the target cache is 100GB, the value of the third waterline is 90GB, and the used capacity of the target cache is 80GB, then the target cache usage is 80GB, which is less than the value of the third waterline (90GB).
[0146] The waterline division standards based on this step can be found in Figure 8C .
[0147] S905, store data a into the target cache.
[0148] S906: According to a preset first strategy, transfer the data in the target cache to the first storage device, and end.
[0149] S907, directly store data a in the first storage device, and end.
[0150] Fig. 9B For example, Fig. 9A An example flow chart of step S906 in FIG. Fig. 9B In this embodiment, step S906 may include the following steps:
[0151] S1, determine whether the timing time has reached the preset time, if yes, execute step S2, otherwise execute step S1.
[0152] S2, transfer all the data in the target cache to the first storage device, and restart the timing.
[0153] Fig. 9C For example, Fig. 9A Another example of the process of step S906 in FIG. Fig. 9C In this embodiment, step S906 may include the following steps:
[0154] S1, determine whether the timing time has reached the preset time, if yes, execute step S2, otherwise execute step S1.
[0155] S2, determine whether the first storage device is executing a read operation, if not, execute step S3, if yes, wait until the read operation is completed and then execute step S3.
[0156] S3, transferring all the data in the target cache to the first storage device, and returning to step S1.
[0157] Fig.9D For example, Fig. 9A Another example of the process of step S906 in FIG. Fig.9D In this embodiment, step S906 may include the following steps:
[0158] S1, determine whether the usage of the target cache is greater than the second waterline, if so, execute step S2, otherwise execute step S1.
[0159] In this embodiment, if it is determined that the usage of the target cache is not greater than the second waterline, step S1 may be executed after waiting for a time period of 1.
[0160] The size relationship between the second waterline and the first waterline in this embodiment can be found in the above Figure 8C .
[0161] S2, transferring the data in the target cache to the first storage device.
[0162] Transferring is the same as brushing back.
[0163] S3, determine whether the usage of the target cache is less than the first waterline, if so, execute step S4, otherwise execute step S2.
[0164] S4, stop transferring the data in the target cache to the first storage device.
[0165] Fig.9E For example, Fig. 9A Another example of the process of step S906 in FIG. Fig.9E In this embodiment, step S906 may include the following steps:
[0166] S1, determine whether the usage of the target cache is greater than the second waterline, if so, execute step S2, otherwise execute step S1.
[0167] In this embodiment, when the judgment result is no, it is also possible to wait for a period of time before executing step S1.
[0168] The size relationship between the second waterline and the first waterline in this embodiment can be found in the above Figure 8C .
[0169] S2, determine whether the first storage device is executing a read operation, if not, execute step S3, if yes, wait until the read operation is completed and then execute step S3.
[0170] S3: Transfer the data in the target cache to the first storage device.
[0171] S4, determine whether the usage of the target cache is less than the first waterline, if so, execute step S5, otherwise execute step S3.
[0172] S5, stop transferring the data in the target cache to the first storage device.
[0173] Fig.9F For example, Fig. 9A Another example of the process of step S906 in FIG. Fig.9F In this embodiment, step S906 may include the following steps:
[0174] S1, an event is detected that requires the immediate shutdown of electronic equipment.
[0175] In this embodiment, detecting an event that requires immediate shutdown of the electronic device may include:
[0176] Receiving an instruction to restart the electronic device; or,
[0177] A power failure of an electronic device is detected; or,
[0178] Received shutdown command.
[0179] S2, transferring all the data in the target cache to the first storage device.
[0180] S3, execute shutdown operation.
[0181] Fig.10 FIG. 1 is another example flow chart of the data storage method in this embodiment. The method can be applied to Figure 7 Storage system including cache disks shown. See Fig.10 In this embodiment, the data storage method may include the following steps:
[0182] S1001, receiving data c sent by the file system.
[0183] S1002: An event requiring immediate shutdown of an electronic device is detected.
[0184] S1003, directly store the data c in the first storage device, and transfer all the data in the target cache to the first storage device.
[0185] Among them, the command to immediately shut down the electronic device may include:
[0186] Receiving an instruction to restart the electronic device; or,
[0187] A power failure of an electronic device is detected; or,
[0188] Received shutdown command.
[0189] S1004, execute shutdown operation, end.
[0190] Fig.11 The figure is a schematic diagram showing another exemplary data storage method. Fig.11 In the example, the backup disk can be Figure 7 In the UFS, the cache disk is a partial area of the memory disk of the electronic device, for example, the cache disk can be a partial area in the RAM.
[0191] See also Fig.11 In this embodiment, the data storage method may include the following steps:
[0192] S1, the data generated by the application layer is stored in the f2fs file system.
[0193] The data generated by the application layer may include file type information and / or data source information.
[0194] In one example, the data may include a tag 1 , and the file type information and / or data source information of the data may be located in the tag 1 .
[0195] S2 reads data from the f2fs file system, classifies the data, and tags the data with corresponding data labels based on the classification results.
[0196] Among them, the data label is passed from BIO (Basic Input Output) to the block device layer.
[0197] In this step, the data is classified and labeled accordingly according to the classification results, that is, the data type is set for the data.
[0198] The data label marked according to the classification result can be recorded as label 2. That is, the data type of the data recorded in label 2.
[0199] The data may be classified in such a way that: the data type to which the data belongs is determined according to the file type information and / or data source information included in the tag 1 of the data.
[0200] For example, Fig.11 As shown, the data type may be metadata, synchronization data (sync data), Checkpoint related data, some special data, other data, and the like.
[0201] Part of the special data may be, for example, system-related data of an application, but is certainly not limited thereto.
[0202] S3, storing the data according to the data type corresponding to the data.
[0203] For example, if the data type corresponding to the data is any one of metadata, synchronization data, Checkpoint-related data, and some special data, the data is directly stored in the backup disk without being cached by the cache disk.
[0204] For another example, if the data type corresponding to the data is other data, the data is first stored in the cache disk, and then the data is flushed from the cache disk back to the backup disk.
[0205] The strategy for flushing data from the cache disk to the backup disk may adopt any one of the following strategies (of course not limited to the following strategies):
[0206] Strategy 1: Regularly flush data from the cache disk to the backup disk.
[0207] Strategy 2: Use waterline control to flush data from the cache disk to the backup disk (see Fig.9D or Fig.9E Embodiment shown).
[0208] Strategy 3: When the electronic device enters the normal power-off process (such as restart), flush the data from the cache disk to the backup disk (see Fig.9F Embodiment shown).
[0209] It can be seen from the above embodiments that the data storage method of this embodiment can improve the data storage speed of the storage system by using a memory disk as a cache device of a first storage device with a slower storage speed. In addition, the memory disk as a cache device of the first storage device is already in the electronic device, so this embodiment does not need to add new hardware in the electronic device, saving costs.
[0210] An embodiment of the present application also provides an electronic device, which includes a memory and a processor, wherein the memory is coupled to the processor, and the memory stores program instructions. When the program instructions are executed by the processor, the electronic device implements the data storage method executed by the aforementioned electronic device.
[0211] It is understandable that, in order to realize the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.
[0212] This embodiment also provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the data storage method in the above-mentioned embodiment.
[0213] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement the data storage method in the above-mentioned embodiment.
[0214] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes the data storage method in the above-mentioned method embodiments.
[0215] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above and will not be repeated here.
[0216] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0217] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0218] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0219] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0220] Any content of each embodiment of the present application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of the present application.
[0221] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0222] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0223] The steps of the method or algorithm described in conjunction with the disclosure of the embodiments of the present application can be implemented in a hardware manner, or can be implemented by a processor executing a software instruction. The software instruction can be composed of corresponding software modules, and the software module can be stored in a random access memory (Random Access Memory, RAM), a flash memory, a read-only memory (Read Only Memory, ROM), an erasable programmable read-only memory (Erasable Programmable ROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, EEPROM), a register, a hard disk, a mobile hard disk, a read-only compact disk (CD-ROM) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0224] Those skilled in the art should be aware that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented with hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of a computer program from one place to another. The storage medium can be any available medium that a general or special-purpose computer can access.
[0225] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A data storage method, characterized in that: Applied to an electronic device, the storage system of the electronic device includes a first storage device and a target cache, the target cache is a partial area of a memory disk of the electronic device, and the method includes: Receiving first data sent by the file system; determining a data type of the first data; If the data type of the first data is the first type and the usage of the target cache is less than a first value, storing the first data in the target cache; According to a preset first strategy, the data in the target cache is transferred to the first storage device.
2. The method according to claim 1, characterized in that The memory disk is RAM.
3. The method according to claim 1, characterized in that According to a preset first strategy, transferring the data in the target cache to the first storage device includes: The data in the target cache is transferred to the first storage device at a regular interval.
4. The method according to claim 1, characterized in that: According to a preset first strategy, transferring the data in the target cache to the first storage device includes: Determine whether the usage of the target cache is greater than a second value, the second value being less than the first value; If yes, the data in the target cache is transferred to the first storage device.
5. The method according to claim 4, characterized in that After transferring the data in the target cache to the first storage device, the method further includes: When the usage of the target cache is less than a third value, stop transferring the data in the target cache to the first storage device, and the third value is less than the second value.
6. The method according to claim 1, characterized in that According to a preset first strategy, transferring the data in the target cache to the first storage device includes: When an event requiring immediate shutdown of the electronic device is detected, all data in the target cache is transferred to the first storage device; Perform a shutdown operation.
7. The method according to claim 6, characterized in that Events that require immediate shutdown of the electronic device are detected, including: Receiving an instruction to restart the electronic device; or, It is detected that the electronic device loses power; or, Received shutdown command.
8. The method according to claim 1, characterized in that Also includes: receiving second data sent by the file system; determining a data type of the second data; If the data type of the second data is the first type, but the usage of the target cache is greater than or equal to the first value, the first data is stored in the first storage device.
9. The method according to claim 1, characterized in that: Also includes: receiving third data sent by the file system; determining a data type of the third data; If the data type of the third data is the second type, the first data is stored in the first storage device.
10. The method according to claim 9, characterized in that The data belonging to the second type includes any one or more of the following: Metadata; Data related to checkpoints; Synchronize data; System-related data for the application.
11. The method according to claim 1, characterized in that: Determining the data type of the first data includes: A data type is set for the first data according to the file type information and / or data source information of the first data.
12. The method according to claim 11, characterized in that After setting the data type for the first data, the method further includes: adding a first tag to the first data, where the first tag is used to indicate the data type of the first data.
13. The method according to claim 1, characterized in that The first type is user data.
14. The method according to claim 1, characterized in that The first storage device is a universal flash memory UFS or an embedded multimedia card EMMC.
15. The method according to claim 1, characterized in that Also includes: Reading hot data from the first storage device, the hot data being data with an access frequency greater than a first frequency; The hot data is stored in the target cache.
16. The method according to claim 1 or 15, characterized in that Also includes: Receiving a data read instruction sent by the file system; Determining whether the target cache includes target data corresponding to the read data instruction; If yes, the target data is read from the target cache.
17. The method according to claim 1, characterized in that Also includes: receiving fourth data sent by the file system; An event requiring immediate shutdown of the electronic device is detected; The fourth data is directly stored in the first storage device, and all the data in the target cache is transferred to the first storage device.
18. The method according to claim 1, characterized in that The electronic device is a mobile phone or a tablet.
19. An electronic device, characterized in that: include: a memory and a processor, the memory being coupled to the processor; The memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the data storage method according to any one of claims 1 to 18.
20. A computer-readable storage medium comprising a computer program, characterized in that: When the computer program is executed on an electronic device, the electronic device is enabled to execute the data storage method according to any one of claims 1 to 18.
Citation Information
Patent Citations
Data storing method and device and solid state disc
CN105117180A
Data storage method and electronic equipment
CN105302478A
Method for accelerating starting of application program and electronic equipment
CN112783564A
Data storage method and device, equipment and medium
CN113064553A
Data storage method and related equipment
CN113590501A
Cited By
Data storage method, storage medium, electronic device and program product
CN120723174A
Data storage method, storage medium, electronic device, and program product
CN120723174B
Data storage state display method and device, storage system and storage medium
CN120950028A