Data storage method and electronic device
By using RAM as a cache in terminal devices, combined with preset and stability strategies, the problem of poor performance at the end of storage speed and capacity was solved, achieving improved storage speed and cost savings.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HONOR DEVICE CO LTD
- Filing Date
- 2023-10-16
- Publication Date
- 2026-04-24
AI Technical Summary
The performance of storage devices in existing terminal devices is distributed in a pyramid shape, resulting in a sharp drop in performance at the end of storage speed and capacity. In particular, the storage speed of underlying storage devices such as UFS is slow and the performance at the end of capacity is poor, which cannot be effectively solved by existing software optimization.
It uses RAM as the target cache of the underlying storage device, and uses a portion of the memory disk as a cache. Combined with preset strategies and stability strategies, it optimizes storage speed and prevents data loss.
It significantly improves the storage speed of the underlying storage device, alleviates performance issues at the end of the capacity, saves costs without changing the hardware, and ensures the stability of data storage.
Smart Images

Figure CN119883955B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of terminal equipment, and more particularly to a data storage method and an electronic device. Background Technology
[0002] Terminal devices store various storage devices, such as REG, L1 cache, L2 cache, L3 cache, RAM (Random Access Memory), UFS (Universal Flash Storage), and eMMC (Embedded Multimedia Card). The performance of these storage devices follows a classic pyramid shape: the closer the storage device is to the CPU, the faster it is, the higher its price, and the lower its capacity. Summary of the Invention
[0003] To address the aforementioned technical problems, this application provides a data storage method and electronic device that can improve the storage speed of underlying storage devices.
[0004] Firstly, this application provides a data storage method applied to an electronic device. The storage system of the electronic device includes a first storage device and a target cache, where the target cache is a portion of the electronic device's memory disk. The method includes: receiving first data sent by a file system; determining the 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. Thus, by using a memory disk as the target cache for the slower-moving first storage device, the data storage speed of the storage system can be improved. Furthermore, since the memory disk is already present in the electronic device, this method does not require any changes to the electronic device's hardware, effectively saving costs.
[0005] According to the first aspect, the memory disk is RAM. Using RAM as the target cache for the first storage device can not only significantly improve the storage speed of the first storage device, but also greatly alleviate the capacity-end problem.
[0006] According to the first aspect, in accordance with the preset first strategy, the data in the target cache is transferred to the first storage device, including: periodically transferring the data in the target cache to the first storage device.
[0007] According to the first aspect, in accordance with 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, the data in the target cache is transferred 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 the transfer of the data in the target cache to the first storage device, where the third value is less than the second value.
[0009] According to the first aspect, following a preset first strategy, the data in the target cache is transferred to the first storage device, including: 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; and a shutdown operation is performed. This prevents data loss and maintains the stability of the storage on the first storage device.
[0010] According to the first aspect, events that require immediate shutdown of electronic devices are detected, including: receiving a command to restart the electronic device; or detecting a power outage of the electronic device; or receiving a power-off command.
[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 a first type, but the usage of the target cache is greater than or equal to a first value, storing the first data in 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; and if the data type of the third data is a second type, storing the first data in the first storage device.
[0013] According to the first aspect, 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 the application.
[0014] According to the first aspect, determining the data type of the first data includes: setting the data type of 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 label to the first data, the first label being used to indicate the data type of the first data.
[0016] According to the first aspect, the first type is user data.
[0017] According to the first aspect, the first storage device is a general-purpose 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, wherein the hot data is data accessed more frequently than a first frequency; and storing the hot data in the 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 contains 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 into 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, this application provides an electronic device, including: 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 performs the data storage method of any one of the first aspects.
[0023] Thirdly, this application provides a computer-readable storage medium including a computer program that, when run on an electronic device, causes the electronic device to execute any of the data storage methods described in the first aspect above. Attached Figure Description
[0024] Figure 1 This is a schematic diagram of the structure of an electronic device 100 as an example.
[0025] Figure 2 This is a software structure block diagram of an electronic device 100 according to an embodiment of this application, which is an example shown.
[0026] Figure 3 This is a storage architecture diagram of an electronic device as an example.
[0027] Figure 4 This is an example diagram comparing the storage speeds of memory devices and UFS devices.
[0028] Figure 5 This is a schematic diagram illustrating the relationship between random write performance and remaining capacity of a standard device as an example.
[0029] Figure 6 This is a schematic diagram illustrating an exemplary data storage method;
[0030] Figure 7 This is a schematic diagram illustrating another data storage method as an example;
[0031] Figure 8A This is an example flowchart illustrating a data storage method in this embodiment.
[0032] Figure 8B As shown in the example Figure 8A A schematic diagram of the data storage path in the data storage method;
[0033] Figure 8C This is an example diagram of waterline levels in this embodiment, shown as an example.
[0034] Figure 9A This is an example flowchart illustrating another data storage method in this embodiment.
[0035] Figure 9B As shown in the example Figure 9A A flowchart illustrating step S906;
[0036] Figure 9C As shown in the example Figure 9A Another example flowchart of step S906;
[0037] Figure 9D As shown in the example Figure 9A Another example flowchart of step S906;
[0038] Figure 9E As shown in the example Figure 9A Another example flowchart of step S906;
[0039] Figure 9F As shown in the example Figure 9A Another example flowchart of step S906;
[0040] Figure 10 This is an example flowchart illustrating another data storage method in this embodiment.
[0041] Figure 11 This is a schematic diagram illustrating another data storage method as an example. Detailed Implementation
[0042] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0043] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.
[0044] The terms "first" and "second," etc., used in the specification and claims of this application are used to distinguish different objects, not to describe a specific order of objects. For example, "first target object" and "second target object," etc., are used to distinguish different target objects, not to describe a specific order of target objects.
[0045] This embodiment provides a data storage method that can be applied to electronic devices such as mobile phones and tablets. However, it is not limited to these electronic devices.
[0046] In this embodiment, the structure of the electronic device can be as follows: Figure 1 As shown.
[0047] Figure 1 This is a schematic diagram illustrating the structure of an electronic device 100 as an example. It should be understood that... Figure 1 The electronic device 100 shown is merely an 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 different component configurations. Figure 1 The various components shown can 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] Please see 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, a headphone jack 170D, a sensor module 180, buttons 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, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity 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] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0050] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.
[0051] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.
[0052] The external storage 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 storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0053] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of electronic device 100 by running the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 100 (such as audio data, phonebook, etc.). Furthermore, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc.
[0054] Of course, in addition to the components mentioned above, the electronic device 100 may also include other hardware components, which will not be listed here.
[0055] The software system of electronic device 100 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. This application embodiment uses the layered architecture Android system as an example to exemplify the software structure of electronic device 100.
[0056] Figure 2 The above is a software structure block diagram of an electronic device 100 according to an embodiment of this application.
[0057] The layered architecture of the electronic device 100 divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer, an application framework layer, system libraries, and a kernel layer, etc.
[0058] The application layer can include a series of application packages.
[0059] like Figure 2 As shown, the application package may include applications such as camera, gallery, map, WLAN, music, SMS, call, navigation, Bluetooth, and video. Of course, these applications are merely exemplary; in other embodiments, the application layer may include... Figure 2 Applications not shown in the text may also be excluded. Figure 2 One or more applications are shown in the figure.
[0060] like Figure 2 As shown, the application framework layer may include a window manager, resource manager, view system, content provider, data storage module, etc.
[0061] The data storage module is used to execute the data storage method of the embodiments of this application.
[0062] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0063] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0064] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0065] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0066] The Android Runtime consists of core libraries and a virtual machine. The Android Runtime is responsible for scheduling and managing the Android system.
[0067] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.
[0068] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0069] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGL ES), 2D graphics engines (e.g., SGL), etc.
[0070] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0071] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
[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 graphics 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 can include display drivers, Wi-Fi drivers, audio drivers, sensor drivers, Bluetooth drivers, etc.
[0076] Understandable Figure 2 The layers in the illustrated software structure and the components contained in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer layers than illustrated, and each layer may include more or fewer components; this application does not impose any limitations.
[0077] Figure 3 This is a storage architecture diagram of an electronic device as an example. Figure 3 As shown, the arrows point away from the CPU, indicating that the upper storage devices are closer to the CPU than the lower ones. Figure 3 It is evident that as storage devices are located further away from the CPU, their capacity increases, their speed decreases, and their price decreases. Low-level storage devices, such as UFS and eMMC, are furthest from the CPU and have the slowest storage speeds.
[0078] Compared to UFS NAND (Nand flash) devices, RAM devices have read and write speeds that differ by more than four times, indicating a significant mismatch in storage speeds.
[0079] Figure 4 This is an example diagram comparing the storage speeds of memory devices and UFS devices. Figure 4 In this context, disk file systems use NAND block devices (part of UFS devices) for storage, while memory file systems use memory block devices (part of memory devices). Figure 4 It is evident that memory blocks are far superior to NAND block devices in both read and write speeds.
[0080] Furthermore, due to the inherent properties of NAND media, there has always been a problem of sharp performance degradation at the end of the capacity range, such as... Figure 5 As shown, Figure 5 This diagram illustrates the relationship between random write performance and remaining capacity (i.e., free space) of a standard device. Simple upper-level software optimization can only alleviate the performance drop-off at the end of the capacity range; it cannot fundamentally solve the problem. This performance drop-off issue does not exist for RAM-type storage media.
[0081] Figure 6 This is a schematic diagram illustrating an exemplary data storage method. For example... Figure 6 As shown, in this storage method, the data writing process is as follows: After the data generated by the application layer is stored in the file system (FS), the file system (FS) defragments the data and then stores the defragmented data in the backing disk UFS. In this method, the data reading process is as follows: The file system (FS) reads data from the backing disk UFS and then returns the read data to the application layer. The backing disk UFS includes GC (Garbage Collection) and WB (WriteBooster).
[0082] This storage method has a slow underlying disk storage speed, and the underlying UFS disk has a problem of sharp performance drop at the end of the capacity range.
[0083] In one example, a technique improves the storage speed of the underlying storage device by adding a new cache device to an electronic device. In this technique, the electronic device has at least three storage hardware devices: a memory disk, the underlying storage device, and the new cache device. The memory disk and the underlying storage device are existing hardware in the electronic device, while the new cache device is added. This technique is used in large devices such as servers, and the new cache device is non-volatile memory. This technique requires adding new hardware to the electronic device, modifying its hardware, and therefore is costly.
[0084] To address the aforementioned problems, embodiments of the present invention propose a novel data storage method, such as... Figure 7 As shown. Embodiments of the present invention can accelerate the storage speed of underlying devices through RAM caching.
[0085] Furthermore, this application embodiment optimizes storage by using a portion of the original memory disk in electronic devices such as RAM as a cache for the underlying storage device. This not only significantly improves the storage speed of NAND media (such as UFS) but also greatly alleviates the capacity end problem.
[0086] Figure 7 This is a schematic diagram illustrating another data storage method as an example. For example... Figure 7 As shown, the storage system of this storage method includes a backup disk UFS and a memory disk, with the memory disk serving as a cache disk for the backup disk UFS. The data writing process of this storage method is as follows: After the data generated by the application layer is stored in the file system (FS), the file system (FS) defragments the data and caches the defragmented data in the cache disk of the backup disk UFS, i.e., the memory disk. The memory disk then flushes the data in the memory disk back to the backup disk UFS according to a preset flush strategy.
[0087] It should be noted that, Figure 7 The memory disk shown should be understood as a portion of the existing memory disk in the electronic device. In this embodiment, no new hardware is added to the electronic device; only the usage of a portion of the existing memory disk in the electronic device is changed, using this portion of the memory disk as a cache for the underlying disk, such as UFS. Therefore, the memory disk can be considered a cache disk for the backup disk UFS.
[0088] It should be noted that, Figure 7 The memory disk in the illustrated embodiment is a volatile memory. Therefore, this embodiment subsequently provides a stability strategy to ensure that in the event of an unexpected power outage of the electronic device, the data in the memory disk, which serves as a cache for 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 as follows: the file system (FS) pre-reads hot data from the backing disk (UFS) to the memory disk. Then, when a read command for hot data is received, the hot data is read from the memory disk and returned to the file system (FS). The file system (FS) then returns the data to the application layer. For cold data, the file system (FS) reads directly from the backing disk (UFS) without pre-reading from the memory disk.
[0090] Here, hot and cold data are determined based on a pre-defined hot and cold data classification strategy. For example, in one scenario, the hot and cold data classification strategy might be to categorize data according to its access frequency and importance. Data classified as hot data according to this strategy refers to data with high access frequency and importance to the business and application; this data typically requires fast and efficient access and processing. Data classified as cold data according to this strategy refers to data with low access frequency and less importance to the business and application; this data typically needs to be stored long-term but does not require frequent access and processing.
[0091] It should be understood that the above-mentioned hot and cold data classification strategies are merely examples and not limitations on hot and cold data classification strategies. In addition to the above-mentioned hot and cold data classification strategies, other hot and cold data classification strategies may also be adopted in this embodiment.
[0092] In the example above, the data is divided into two categories: cold data and hot data. In other examples, the data may also be divided into three categories: cold data, warm data, and hot data.
[0093] In this article, data flushing or reflow refers to removing data from the current storage device (e.g., [the storage device]). Figure 7 Transferring the memory disk in the memory to other storage devices (e.g., RAM disk) Figure 7 The UFS (Unified Storage Service) in this context refers to reading data from the current storage device, storing it on another storage device, and then deleting the data from the current storage device.
[0094] The following is about Figure 7 The process of the storage method shown will be explained. The target cache in each embodiment shown below refers to... Figure 7 The ramdisk in the memory.
[0095] Figure 8A This is a flowchart illustrating an example of a data storage method in this embodiment. The method is applied to, for example... Figure 7 The storage system shown includes a cache disk. Please refer to [link / reference]. Figure 8A In this embodiment, the data storage method may include the following steps:
[0096] S801 receives the first data sent by the 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 portion of the electronic device's memory disk.
[0100] S804, according to the preset first strategy, transfers the data in the target cache to the first storage device.
[0101] The first storage device may be, for example, Figure 7 The UFS in the storage device, or the primary storage device, can also be EMMC, but it is not limited to these.
[0102] The target cache can be Figure 7This includes memory disks, such as RAM, but is not limited to these. When RAM is used as the target cache, since RAM-type storage media does not have the problem of performance drop-off at the end of capacity, at the end of capacity, read and write data is preferentially written to the cache device, which can greatly improve the end-of-capacity storage performance, especially the end-of-capacity storage performance of the underlying storage system.
[0103] Figure 8B For example Figure 8A A schematic diagram of the data storage path in the data storage method. For example... Figure 8B As shown, in this embodiment, during the process of writing data from the file system to the backup device disk (USF), the data is first written to a memory disk (e.g., 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, because the read / write speed of the memory disk is fast, the matching degree between the memory used by the file system and the storage speed of the memory disk used as a cache for the backup device disk (USF) is improved, which can speed up the writing of data from the file system to the backup device disk (USF), thereby improving storage speed.
[0104] The data types can be divided into user data and non-user data. Non-user data can include, for example, metadata, Checkpoint-related data, Sync data, and some special data. The first type in step S803 can be user data.
[0105] The first value is pre-set and is less than 100%. For example, in one example, the first value could be 90%.
[0106] The first value is usually a high value, and it is the third watermark mentioned later. 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. In this case, 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. If a large amount of data needs to be written at this time, the remaining capacity of the target cache is insufficient to accommodate the data to be written. Continuing to write data to the target cache will cause data overwriting and loss. Therefore, when the usage of the target cache is greater than or equal to the first value, the first data should not be stored in the target cache. Instead, the first data should be stored directly in the first storage device to avoid data loss.
[0107] The first strategy, also known as the flush strategy, involves transferring data from the target cache to the first storage device. The flush strategy will be explained 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 primary storage device performs a read operation, flushing data is prohibited. This is because concurrent read and write operations with large amounts of data significantly impact the performance of electronic devices, especially read speed (reducing read speed), a fact that upper-layer applications are highly aware of. Therefore, flushing is generally disabled when the primary storage device performs a read operation. However, there is an exception: when the electronic device malfunctions. In this case, even if the primary 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 primary storage device).
[0110] In one example, the flush strategy could be:
[0111] Periodically flush all data from the target cache back to the primary storage device. That is, perform a flush operation every preset time interval.
[0112] In this example, at each preset time interval, all data in the target cache except for pre-read data (i.e., data pre-read from the first storage device into the target cache) is flushed back to the first storage device at once. This flushed data refers to non-pre-read data (non-pre-read data exists in the target cache but not in the first storage device). For pre-read data, one copy is stored in the target cache and another copy is stored in the underlying first storage device.
[0113] In another example, the flush strategy could also be based on Figure 8C The waterlines shown (Level 1 and Level 2) control the flushing of cached data in the target cache.
[0114] Please see Figure 8C This embodiment also proposes a cache waterline control strategy.
[0115] Figure 8C This is an example diagram illustrating the waterline levels in this embodiment. Figure 8C As shown, in this example, the waterline levels are divided into three levels, from lowest to highest: Level 1 (referred to as the first waterline), Level 2 (referred to as the second waterline), and Level 3 (referred to as the third waterline).
[0116] Level 3: When the usage of the cache device exceeds this level, a passthrough (i.e., bypassing the cache and writing directly to the underlying device) method is used to directly store all data from the file system to the first storage device (backup disk), without caching it through the target cache.
[0117] Level 2: When the usage of the target cache exceeds this threshold, initiate a flush operation.
[0118] Level 1: Stop flushing when the usage of the target cache falls below this value.
[0119] In one example, the value of Level 1 can be 25%, the value of Level 2 can be 50%, and the value of Level 3 can be 90%. Of course, this is only an example, and this embodiment does not limit the specific values of each waterline.
[0120] This embodiment also employs several strategies to ensure storage stability, which are referred to as stability strategies.
[0121] (1) Data storage
[0122] In one example, when the data to be stored is metadata, the metadata is stored directly on the first storage device (i.e., the backup device disk) without being cached through the target cache. In other words, the underlying file system exists only on the backup device disk. This prevents metadata loss, for example, in the event of an unexpected power outage where data in the target cache cannot be flushed back to the backup device disk in time.
[0123] In one example, data in the target cache is periodically flushed back to the backup disk. This ensures that the target cache has sufficient remaining capacity for the next data storage, guaranteeing the proper functioning of the caching mechanism.
[0124] (2) Normal power on / off
[0125] During a normal reboot, a write-back mechanism is triggered during the shutdown process. The write mode switches to passthrough mode, and all data in the target cache is written to the backup device disk before the shutdown process begins. Therefore, when an electronic device receives a reboot command, it flushes all data in the target cache back to the primary storage device before performing the shutdown operation.
[0126] In addition, in other scenarios where electronic devices need to be shut down immediately, all data in the target cache should be written to the backup device disk (primary storage device) before performing the shutdown operation. For example, other scenarios that require immediate shutdown of electronic devices may include: detecting a power failure of the electronic device, receiving a shutdown command, etc.
[0127] (3) Special treatment
[0128] a. When the Checkpoint event is triggered, the electronic device writes the Checkpoint-related data directly to the backup device disk without going through the target cache.
[0129] b. When the Sync event is triggered, the electronic device directly stores the synchronization data to the backup device disk without going through the target cache.
[0130] c. When certain special data is processed by the f2fs file system and passed to the block device layer, it is determined whether it needs to go through the cache device. If so, the special data is first stored in the target cache and then flushed back from the target cache to the backup device disk. If not, the special data is directly stored in the backup device disk without going through the target cache.
[0131] For example, special data that needs to be stored directly on the backup device disk without going through the target cache can be system-related data of the application.
[0132] (4) Data recovery
[0133] In some scenarios, if there is an abnormal power failure, the data on the backup device disk can be recovered through the checkpoint area in the backup device disk.
[0134] By adopting the above-mentioned stability strategy, this embodiment can both utilize the original memory disk in the electronic device as a cache for the underlying storage device to improve the storage speed of the underlying storage device, and avoid data loss due to the volatile nature of the memory disk.
[0135] As can be seen from the above embodiments, Figure 8A The illustrated embodiment employs a hybrid storage architecture that includes using a memory disk as a cache to provide data to a backup device disk (e.g., Figure 7 When writing data to UFS, the system prioritizes writing the data to the cache device, which greatly improves the read and write speed of the storage system and makes the basic IO (input / output) performance multiply in some scenarios.
[0136] Figure 9A This is an exemplary flowchart illustrating another data storage method in this embodiment. The method is applied to, for example... Figure 7 The storage system shown includes a cache disk. Please refer to [link / reference]. Figure 9A In this embodiment, the data storage method may include the following steps:
[0137] S901 receives 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 it is, proceed to step S904; otherwise, proceed to step S907.
[0140] S904. Determine if the usage of the target cache is less than the third watermark. If yes, proceed to step S905; otherwise, proceed to step S907.
[0141] For example, the third water line here can be 90%.
[0142] It should be noted that the value of the third water line can be a percentage or a volume value.
[0143] In this article, "target cache usage" can be either the percentage of the target cache's total capacity that has been used, or the actual amount of the target cache that has been used.
[0144] For example, when the third watermark is a percentage, "target cache usage" refers to the percentage of the target cache's total capacity that has been used. For instance, if the third watermark is 90%, the total target cache capacity is 100GB, and the target cache has 80GB of used capacity, then the target cache usage is 80%, which is less than the third watermark (90%).
[0145] For example, when the value of the third watermark is a capacity value, "target cache usage" refers to the capacity value already used in the target cache. For instance, if the total capacity of the target cache is 100GB, the value of the third watermark is 90GB, and the capacity already used in the target cache is 80GB, then the target cache usage is 80GB, which is less than the value of the third watermark (90GB).
[0146] Please refer to the waterline classification standards used in this step. Figure 8C .
[0147] S905, store data a in the target cache.
[0148] S906, following the preset first strategy, transfers the data in the target cache to the first storage device, and ends.
[0149] S907, store data a directly to the first storage device, end.
[0150] Figure 9B For example Figure 9A A flowchart illustrating step S906. Please refer to [link / reference]. Figure 9B In this embodiment, step S906 may include the following steps:
[0151] S1. Determine if the preset duration has been reached. If yes, proceed to step S2; otherwise, proceed to step S1.
[0152] S2, transfer all the data in the target cache to the first storage device and restart the timing.
[0153] Figure 9C For example Figure 9A Another example flow chart for step S906. Please refer to [link / reference]. Figure 9C In this embodiment, step S906 may include the following steps:
[0154] S1. Determine if the preset duration has been reached. If yes, proceed to step S2; otherwise, proceed to step S1.
[0155] S2, determine whether the first storage device is performing a read operation. If not, proceed to step S3. If yes, wait for the read operation to complete before proceeding to step S3.
[0156] S3, transfer all the data in the target cache to the first storage device, and return to step S1.
[0157] Figure 9D For example Figure 9A Another example flow chart for step S906. Please refer to [link / reference]. Figure 9D In this embodiment, step S906 may include the following steps:
[0158] S1. Determine if the usage of the target cache is greater than the second watermark. If yes, proceed to step S2; otherwise, proceed to 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 can be executed after waiting for 1 hour.
[0160] The size relationship between the second waterline and the first waterline in this embodiment is described above. Figure 8C .
[0161] S2, transfers the data in the target cache to the first storage device.
[0162] Transferring the data is equivalent to retrieving it.
[0163] S3. Determine if the usage of the target cache is less than the first waterline. If yes, proceed to step S4; otherwise, proceed to step S2.
[0164] S4, stop transferring data from the target cache to the first storage device.
[0165] Figure 9E For example Figure 9A Another example flow chart for step S906. Please refer to [link / reference]. Figure 9E In this embodiment, step S906 may include the following steps:
[0166] S1. Determine if the usage of the target cache is greater than the second watermark. If yes, proceed to step S2; otherwise, proceed to step S1.
[0167] In this embodiment, if the determination result is negative, 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 is described above. Figure 8C .
[0169] S2, determine whether the first storage device is performing a read operation. If not, proceed to step S3. If yes, wait for the read operation to complete before proceeding to step S3.
[0170] S3, transfers the data in the target cache to the first storage device.
[0171] S4. Determine if the usage of the target cache is less than the first waterline. If yes, proceed to step S5; otherwise, proceed to step S3.
[0172] S5, stop transferring data from the target cache to the first storage device.
[0173] Figure 9F For example Figure 9A Another example flow chart for step S906. Please refer to [link / reference]. Figure 9F In this embodiment, step S906 may include the following steps:
[0174] S1 detects an event that requires the electronic device to be turned off immediately.
[0175] In this embodiment, detecting an event that requires the immediate shutdown of the electronic device may include:
[0176] Received a command to restart the electronic device; or,
[0177] The electronic device was detected to have lost power; or,
[0178] Power off command received.
[0179] S2, transfer all the data in the target cache to the first storage device.
[0180] S3, execute the shutdown operation.
[0181] Figure 10 This is an exemplary flowchart illustrating another data storage method in this embodiment. This method can be applied to, for example... Figure 7 The storage system shown includes a cache disk. Please refer to [link / reference]. Figure 10 In this embodiment, the data storage method may include the following steps:
[0182] S1001, receives data c sent by the file system.
[0183] S1002, An event requiring the immediate shutdown of electronic devices has been detected.
[0184] S1003, directly store data c to the first storage device, and transfer all data in the target cache to the first storage device.
[0185] Among them, the detected instruction that requires the immediate shutdown of electronic devices may include:
[0186] Received a command to restart the electronic device; or,
[0187] The electronic device was detected to have lost power; or,
[0188] Power off command received.
[0189] S1004, Execute shutdown operation, end.
[0190] Figure 11 This is a schematic diagram illustrating another data storage method as an example. Figure 11 In the middle, the backup disk can be, for example, Figure 7 In UFS, a cache disk is a portion of the memory disk of an electronic device; for example, a cache disk can be a portion of RAM.
[0191] Please see Figure 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 label 1, where the file type information and / or data source information can be located.
[0195] S2 reads data from the f2fs file system, categorizes the data, and assigns corresponding data tags based on the categorization results.
[0196] The data tags are passed from the BIO (Basic Input Output) layer to the block device layer.
[0197] In this step, the data is categorized, and the corresponding labels are assigned to the data based on the categorization results, which is the data data type setting.
[0198] The data labels assigned based on the classification results can be denoted as Label 2. That is, Label 2 records the data type.
[0199] One method for classifying data is to determine the data type based on the file type information and / or data source information included in the data's label 1.
[0200] For example, such as Figure 11 As shown, the data types can be metadata, synchronization data, checkpoint-related data, some special data, other data, etc.
[0201] Some of the special data may be system-related data of the application, but it is not limited to this.
[0202] S3 stores the data according to the data type.
[0203] For example, if the data type is any of the following: metadata, synchronization data, checkpoint related data, or some special data, the data will be stored directly in the backup disk without being cached by the cache disk.
[0204] For example, if the data corresponds to a different data type, 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 back to the standby disk can be any of the following strategies (but is not limited to the following strategies):
[0206] Strategy 1: Periodically flush data from the cache disk back to the backup disk.
[0207] Strategy 2: Use waterline control to flush data from the cache disk back to the backup disk (see [link]). Figure 9D or Figure 9E (Example shown).
[0208] Strategy 3: When electronic devices enter a normal power-down process (e.g., reboot), data is flushed from the cache disk to the backup disk (see [link to relevant documentation]). Figure 9F (Example shown).
[0209] As can be seen from the foregoing embodiments, the data storage method of this embodiment improves the data storage speed of the storage system by using a memory disk as a cache device for the slower first storage device. Furthermore, since the memory disk serving as the cache device for the first storage device is already present in the electronic device, this embodiment does not require adding new hardware to the electronic device, thus saving costs.
[0210] This application also provides an electronic device, which includes a memory and a processor. The memory is coupled to the processor and stores program instructions. When the program instructions are executed by the processor, the electronic device performs a data storage method.
[0211] It is understood that, in order to achieve the above-mentioned functions, electronic devices include hardware and / or software modules that perform the respective functions. Based on the algorithmic steps of the examples described in the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed by hardware or by 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 conjunction with the embodiments, but such implementation should not be considered beyond the scope of this application.
[0212] This embodiment also provides a computer storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the aforementioned related method steps to implement the data storage method in the above embodiment.
[0213] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the data storage method in the above embodiment.
[0214] In addition, this application also provides an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory to cause the chip to execute the data storage methods in the above-described method embodiments.
[0215] In this embodiment, the electronic device, computer storage medium, computer program product or chip are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can be referred to the beneficial effects of the corresponding method provided above, and will not be repeated here.
[0216] Through the above description of the embodiments, those skilled in the art will understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above 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 this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0218] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0219] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0220] Any content in the various embodiments of this application, as well as any content in the same embodiment, can be freely combined. Any combination of the above content is within the scope of this application.
[0221] If the integrated unit is implemented as 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 solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0222] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
[0223] The steps of the methods or algorithms described in conjunction with the embodiments of this application can be implemented in hardware or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, CD-ROMs, or any other form of storage medium well known in the art. An exemplary storage medium is coupled to a processor, enabling the processor to read information from and 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 reside in an ASIC.
[0224] Those skilled in the art will recognize that the functions described in the embodiments of this application in one or more of the above examples can be implemented using 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 code on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transfer of a computer program from one place to another. Storage media can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0225] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A data storage method, characterized in that, The method is applied to an electronic device, wherein the storage system of the electronic device includes a first storage device and a target cache, the target cache being a portion of the memory disk of the electronic device, the first storage device being a general-purpose flash memory (UFS) or an embedded multimedia card (EMMC), and the read / write speed of the target cache being superior to that of the first storage device. Receive first data sent by the file system; wherein the first data is data generated by the application layer and stored in the file system; Determine the data type of the first data; If the first data is user data and the usage of the target cache is less than a first value, the first data is stored in the target cache; According to the preset first strategy, the data in the target cache is transferred to the first storage device; The method further includes: Receive third-party data sent by the file system; Determine the data type of the third data; If the third data is metadata, checkpoint-related data, synchronization data, or system-related data of the application, the third data is stored in the first storage device; The method further includes: Read fifth data from the first storage device, wherein the fifth data is data accessed more frequently than the first data. The fifth data is stored in the target cache; wherein, after the fifth data is stored in the target cache, the first storage device also stores the fifth data. Upon receiving a read instruction for the fifth data sent by the file system, the fifth data is read from the target cache to improve the reading speed of the fifth data.
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, the data in the target cache is transferred to the first storage device, including: The data in the target cache is periodically transferred to the first storage device.
4. The method according to claim 1, characterized in that, According to a preset first strategy, the data in the target cache is transferred to the first storage device, including: Determine whether the usage of the target cache is greater than a second value, where the second value is less than the first value; If so, 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, the transfer of data in the target cache to the first storage device is stopped, where 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, the data in the target cache is transferred to the first storage device, including: When an event requiring the 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 the immediate shutdown of the electronic device are detected, including: Received an instruction to restart the electronic device; or, The electronic device was detected to have lost power; or, Power off command received.
8. The method according to claim 1, characterized in that, Also includes: Receive the second data sent by the file system; Determine the data type of the second data; If the second data is user data, but the usage of the target cache is greater than or equal to the first value, the second data is stored in the first storage device.
9. The method according to claim 1, characterized in that, Determining the data type of the first data includes: Set the data type for the first data based on the file type information and / or data source information of the first data.
10. The method according to claim 9, characterized in that, After setting the data type for the first data, the method further includes: adding a first label to the first data, wherein the first label is used to indicate the data type of the first data.
11. The method according to claim 1, characterized in that, Also includes: Receives a read data command sent by the file system; Determine whether the target cache contains the target data corresponding to the read data instruction; If so, read the target data from the target cache.
12. The method according to claim 1, characterized in that, Also includes: Receive the fourth piece of data sent by the file system; An event was detected that required the immediate shutdown of the electronic device; 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.
13. The method according to claim 1, characterized in that, The electronic device is a mobile phone or tablet.
14. An electronic device, characterized in that, include: A memory and a processor, wherein the memory is coupled to the processor; The memory stores program instructions that, when executed by the processor, cause the electronic device to perform the data storage method as described in any one of claims 1 to 13.
15. A computer-readable storage medium comprising a computer program, characterized in that, When the computer program is run on an electronic device, it causes the electronic device to perform the data storage method as described in any one of claims 1 to 13.
Citation Information
Patent Citations
Data storing method and device and solid state disc
CN105117180A
Data storage method and electronic equipment
CN105302478A
Data storage method and related equipment
CN113590501A