A data storage method and related apparatus
Patent Information
- Application Number
- CN202110560361.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-21
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2041-05-21
AI Technical Summary
然而,触发存储设备复位会对存储设备进行下电复位,导致存储设备内的易失性存储器的数据丢失,进而影响终端的正常运行
Smart Images

Figure CN115373908B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data storage method and related apparatus. Background Technology
[0002] In the field of data storage, factors such as unstable transmission links, malfunctions in the storage device's internal controller, or abnormal storage media can cause storage devices to malfunction. When a storage device malfunctions, the terminal's operating system cannot interact with the storage device, thus affecting the terminal's normal operation.
[0003] In the server field, redundancy backups are generally used to address the issue of storage device malfunctions. A server includes primary and secondary storage devices. If the primary storage device fails, data exchange operations are migrated to the secondary storage device, ensuring uninterrupted data exchange.
[0004] For portable devices such as smartphones or tablets, redundancy backup methods are typically not feasible due to cost and size limitations. Therefore, portable devices usually resolve storage device malfunctions by triggering a storage device reset. However, triggering a storage device reset powers down the storage device, causing data loss in the volatile memory within the device, thus affecting the normal operation of the device. Summary of the Invention
[0005] This application provides a data storage method in which, when a terminal needs to write target data to an external storage device, it stores the target data in its internal storage device. This way, when the external storage device is powered off and reset, the terminal can resend the target data backed up in the internal storage device to the external storage device, avoiding data loss caused by the external storage device being powered off and reset, and ensuring the normal operation of the terminal.
[0006] This application provides a data storage method, applied to a terminal including internal memory and external memory. The method includes: when the terminal needs to store target data long-term, the operating system in the terminal stores the target data in a first memory, where the first memory is internal memory. The target data is non-temporarily stored data. That is, the storage requirement for the target data is that the target data can still be stored in the terminal after power failure. The terminal may include one or more internal memories, and the first memory can be any one of the internal memories in the terminal. Internal memory is also called main memory or RAM, and it is typically used to temporarily store computational data from the processor.
[0007] The operating system sends a first instruction to the second memory, the first instruction including the target data, the first instruction being used to instruct the second memory to write the target data. The second memory is an external memory used for long-term data storage.
[0008] The second memory includes volatile memory and non-volatile memory. The volatile memory is used to temporarily store the target data to be written to the non-volatile memory, and the non-volatile memory is used to store the target data permanently. The volatile memory has a faster data write speed, but it cannot retain data after power failure. The non-volatile memory has a slower data write speed, but it can still retain data after power failure. Therefore, the process of writing target data to the second memory includes: the second memory first writes the target data to the volatile memory, and then writes the target data from the volatile memory to the target address in the non-volatile memory. By setting volatile memory in the second memory, it can be ensured that data issued by the operating system can be quickly written to the volatile memory, and then written from the volatile memory to the non-volatile memory. This avoids the situation where the operating system's data is directly written to the non-volatile memory, which would be too slow and affect the normal issuance of data write commands by the operating system.
[0009] After the second memory is reset, the data stored in the volatile memory in the second memory is lost, and the operating system can recover the data in the second memory based on the target data in the first memory.
[0010] In this embodiment, when the terminal needs to write target data to the external storage, it stores the target data in the internal storage. This way, when the external storage is powered off and reset, the terminal can resend the target data backed up in the internal storage to the external storage, avoiding data loss caused by the external storage being powered off and reset, thus ensuring the normal operation of the terminal.
[0011] In one possible implementation, the step of restoring data in the second memory based on the target data in the first memory after the second memory is reset specifically includes: the operating system acquiring a first message sent by the second memory, the first message indicating that the second memory reset was successful. The operating system sending a second instruction to the second memory. The second instruction is generated based on the target data in the first memory. After confirming the successful reset of the second memory, the operating system can acquire the target data in the first memory and generate the second instruction based on the target data. The second instruction includes the target data and is used to instruct the second memory to write the target data. Thus, after receiving the second instruction, the second memory writes the target data from the second instruction to volatile memory, and then writes the target data from volatile memory to non-volatile memory.
[0012] In this solution, after the second memory is reset, the operating system resends the target data stored in the first memory to the second memory, which can effectively avoid the data loss problem caused by the power-down reset of the second memory and ensure the normal operation of the terminal.
[0013] In one possible implementation, the method further includes: during the operation of the second memory, when an anomaly occurs in the second memory causing it to be unable to write data normally, the second memory sends a second message to the operating system, the second message indicating that the second memory has encountered an anomaly. The operating system receives the second message sent by the second memory, the second message indicating that the second memory has encountered an anomaly. The operating system then sends a third instruction to the second memory, the third instruction instructing the second memory to perform a reset operation.
[0014] After receiving a third instruction instructing the second memory to perform a reset operation, the second memory executes the reset operation according to the third instruction to eliminate the abnormality that occurred in the second memory. After the second memory performs the reset operation, the data in the volatile memory of the second memory is lost due to power failure.
[0015] In one possible implementation, the method further includes: the operating system receiving a third message sent by the second memory. The third message is a response message to the first instruction, indicating that the target data has been written to the non-volatile memory. The operating system then deletes the target data from the first memory.
[0016] In this scheme, since the storage space in the first memory for storing data to be written to the second memory is limited, after the data has been written to the non-volatile memory of the second memory, the terminal can delete the target data stored in the first memory to ensure that there is enough free storage space in the first memory.
[0017] In one possible implementation, the operating system stores the target data in a first memory, including: the operating system stores the target data in a target storage space within the first memory, where the target storage space is a pre-allocated storage space. The target storage space is used to temporarily store data to be written to a second memory.
[0018] Specifically, during the terminal's startup process, the terminal allocates a storage space of a specific size in the first memory and designates this storage space as the target storage space for temporarily storing data to be written to the second memory. Since the target storage space is a smaller storage space in the internal memory, the terminal's allocation of the target storage space in the internal memory does not affect the normal storage of processor's computational data by the internal memory.
[0019] In this scheme, by allocating an independent target storage space in the first memory to store the data to be written to the second memory, the computational data to be written to the second memory can be effectively isolated from the data to be processed by the processor, thus ensuring the independence between the data.
[0020] In one possible implementation, the capacity of the target storage space is greater than or equal to the capacity of the volatile memory, so as to ensure that all data in the volatile memory of the second memory can be backed up in the target storage space.
[0021] In one possible implementation, the method further includes: the operating system sending a fourth instruction to the second memory, the fourth instruction being used to query data stored in the volatile memory; the operating system receiving a fourth message sent by the second memory, the fourth message being used to indicate first data stored in the volatile memory; and the operating system deleting second data from the first memory. Wherein, both the second data and the first data are included in the target data, and the first data and the second data are different.
[0022] In this solution, the terminal deletes data that is no longer in the volatile memory from the first memory by querying the data that is still stored in the volatile memory of the second memory, thereby ensuring that there is enough free storage space in the first memory.
[0023] In one possible implementation, sending the fourth instruction to the second memory includes: if the second memory executes instructions out of order, and the amount of data stored in the target storage space is greater than or equal to a preset threshold, then the operating system sends the fourth instruction to the second memory.
[0024] When the instructions executed by the second memory are executed out of order, the second memory does not process the instructions in the order they are received. That is, the second memory may process later-received instructions first, thus writing the later-received data from volatile memory to non-volatile memory first; for some earlier-received instructions, the second memory may not execute them, causing the earlier-received data to remain stored in volatile memory. In this situation, the operating system can query the data stored in volatile memory to delete some data in the target memory space, effectively ensuring that the target memory space in the first memory retains all the data stored in volatile memory.
[0025] In one possible implementation, the method further includes: if the second memory executes instructions sequentially, and the amount of data stored in the target storage space is greater than or equal to a preset threshold, then the operating system deletes third data in the target storage space, wherein the third data is the data first written into the target storage space.
[0026] In simple terms, the operating system uses a first-in, first-out (FIFO) approach to delete data that has been successfully written to non-volatile memory in the target storage space, thereby ensuring that there is enough free space in the target storage space.
[0027] A second aspect of this application provides a terminal, comprising: a processing unit and a transceiver unit. The processing unit is configured to store target data in a first memory, wherein the first memory is internal memory; the transceiver unit is configured to send a first instruction to a second memory, the first instruction including the target data, the first instruction instructing the second memory to write the target data, the second memory being an external memory, the second memory including volatile memory and non-volatile memory, the volatile memory being used to temporarily store the target data to be written to the non-volatile memory, and the non-volatile memory being used to store the target data; the transceiver unit is further configured to, after the second memory is reset, recover data in the second memory based on the target data in the first memory.
[0028] In one possible implementation, the transceiver unit is further configured to acquire a first message sent by the second memory, the first message indicating that the second memory has been successfully reset; the transceiver unit is further configured to send a second instruction to the second memory, the second instruction being generated based on the target data in the first memory, the second instruction including the target data, and the second instruction instructing the second memory to write the target data.
[0029] In one possible implementation, the transceiver unit is further configured to acquire a second message sent by the second memory, the second message indicating that an abnormality has occurred in the second memory; the transceiver unit is further configured to send a third instruction to the second memory, the third instruction instructing the second memory to perform a reset operation.
[0030] In one possible implementation, the transceiver unit is further configured to acquire a third message sent by the second memory, the third message indicating that the target data has been written to the non-volatile memory; the processing unit is further configured to delete the target data in the first memory.
[0031] In one possible implementation, the processing unit is further configured to store the target data in a target storage space in the first memory, wherein the target storage space is a pre-allocated storage space.
[0032] In one possible implementation, the capacity of the target storage space is greater than or equal to the capacity of the volatile memory.
[0033] In one possible implementation, the transceiver unit is further configured to send a fourth instruction to the second memory, the fourth instruction being used to query data stored in the volatile memory; the transceiver unit is further configured to acquire a fourth message sent by the second memory, the fourth message being used to indicate first data stored in the volatile memory; the processing unit is further configured to delete second data in the first memory; wherein the second data and the first data are both included in the target data, and the first data and the second data are different.
[0034] In one possible implementation, the transceiver unit is further configured to send the fourth instruction to the second memory if the second memory executes instructions out of order and the amount of data stored in the target storage space is greater than or equal to a preset threshold.
[0035] In one possible implementation, the processing unit is further configured to delete third data in the target storage space if the second memory executes instructions sequentially and the amount of data stored in the target storage space is greater than or equal to a preset threshold. The third data is the data that was first written into the target storage space.
[0036] A third aspect of this application provides a terminal comprising: an internal memory, an external memory, and a processor; the external memory stores code, and the processor is configured to execute the code, wherein when the code is executed, the terminal performs a method as described in any of the implementations of the first aspect.
[0037] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform a method as described in any of the implementations of the first aspect.
[0038] The fifth aspect of this application provides a computer program product that, when run on a computer, causes the computer to perform a method as described in any of the implementations in the first aspect.
[0039] A sixth aspect of this application provides a chip including one or more processors. Part or all of the processors are configured to read and execute a computer program stored in memory to perform the methods in any possible implementation of any of the above aspects.
[0040] Optionally, the chip includes a memory, which is connected to the processor via a circuit or wire. Optionally, the chip also includes a communication interface, to which the processor is connected. The communication interface is used to receive data and / or information that needs to be processed. The processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing result through the communication interface. The communication interface can be an input / output interface. The method provided in this application can be implemented by a single chip or by multiple chips working together. Attached Figure Description
[0041] Figure 1 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application;
[0042] Figure 2 This is a schematic diagram of the structure of a terminal 101 provided in an embodiment of this application;
[0043] Figure 3 A schematic diagram of an application scenario provided in this application embodiment;
[0044] Figure 4A schematic flowchart of a data storage method 400 provided in an embodiment of this application;
[0045] Figure 5 Another schematic diagram of the data storage method 400 provided in the embodiments of this application;
[0046] Figure 6 This is a schematic diagram of the application architecture of the data storage method provided in the embodiments of this application;
[0047] Figure 7 A schematic flowchart of a data storage method 700 provided in an embodiment of this application;
[0048] Figure 8 This is a schematic diagram of the structure of a terminal 800 provided in an embodiment of this application;
[0049] Figure 9 This is a schematic diagram of the structure of a computer-readable storage medium 900 provided in an embodiment of this application. Detailed Implementation
[0050] The embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. As those skilled in the art will recognize, with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0051] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in this application does not imply that the steps in the method flow must be performed in the chronological / logical order indicated by the naming or numbering. The execution order of named or numbered process steps can be changed according to the desired technical purpose, as long as the same or similar technical effect is achieved.
[0052] In the field of data storage, factors such as unstable transmission links, malfunctions in the storage device's internal controller, or abnormal storage media can cause storage devices to malfunction. When a storage device malfunctions, the terminal's operating system cannot interact with the storage device, thus affecting the terminal's normal operation.
[0053] In the server field, redundancy backups are generally used to address the issue of storage device malfunctions. A server includes primary and secondary storage devices. If the primary storage device fails, data exchange operations are migrated to the secondary storage device, ensuring uninterrupted data exchange.
[0054] For portable devices such as smartphones or tablets, redundancy backup methods are typically not feasible due to cost and size limitations. Therefore, portable devices usually resolve storage device malfunctions by triggering a storage device reset. However, triggering a storage device reset powers down the storage device, causing data loss in the volatile memory within the device, thus affecting the normal operation of the device.
[0055] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the structure of a storage device provided in an embodiment of this application. Figure 1 As shown, the operating system in the terminal interacts with the storage device through driver components. The storage device includes volatile memory and non-volatile memory. Volatile memory has a faster data write speed, but it cannot retain data after power failure. Non-volatile memory has a slower data write speed, but it can still retain data after power failure. Therefore, during the process of the operating system in the terminal writing data to the storage device, the data is first written to the volatile memory of the storage device, and then written from the volatile memory to the non-volatile memory.
[0056] When an anomaly occurs during data writing to a storage device, the operating system triggers a power-down reset, resulting in the loss of data in the storage device's volatile memory. Since the data in the volatile memory had not yet been written to the non-volatile memory, and the volatile memory lost its data upon power failure, some data written by the operating system to the storage device is lost. If the lost data in the volatile memory is critical, it may corrupt the terminal's file system, affecting the terminal's normal operation.
[0057] In view of this, embodiments of this application provide a data storage method that can be applied to a terminal. When the terminal needs to write target data to external storage, it stores the target data in internal storage. Thus, when the external storage is powered off and reset, the terminal can resend the target data backed up in internal storage to the external storage, avoiding data loss caused by power-off and reset of the external storage, and ensuring the normal operation of the terminal.
[0058] The terminal involved in the embodiments of this application can be a terminal with internal memory and external memory. Exemplarily, the terminal can be, for example, a personal computer (PC), laptop computer, server, mobile phone, tablet computer, mobile internet device (MID), wearable device, virtual reality (VR) device, augmented reality (AR) device, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical surgery, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, etc. The terminal can be a device running Android, iOS, Windows, or other systems. For ease of understanding, the following will use a smartphone as an example to describe the data storage method provided in the embodiments of this application.
[0059] Please refer to Figure 2 , Figure 2 This is a schematic diagram of the structure of a terminal 101 provided in an embodiment of this application. Figure 2As shown, terminal 101 includes a processor 103, which is coupled to a system bus 105. The processor 103 can be one or more processors, each of which can include one or more processor cores. A video adapter 107 drives a display 109, which is coupled to the system bus 105. The system bus 105 is coupled to an input / output (I / O) bus via a bus bridge 111. An I / O interface 115 is coupled to the I / O bus. The I / O interface 115 communicates with various I / O devices, such as input devices 117 (e.g., touchscreens), external storage 121 (e.g., hard disks, floppy disks, optical disks, or USB flash drives), multimedia interfaces, etc. A transceiver 123 (capable of sending and / or receiving radio communication signals), a camera 155 (capable of capturing still and moving digital video images), and an external USB port 125. Optionally, the interface connected to the I / O interface 115 can be a USB interface.
[0060] The processor 103 can be any conventional processor, including a reduced instruction set computing (RISC) processor, a complex instruction set computing (CISC) processor, or a combination thereof. Optionally, the processor can be a special-purpose device such as an ASIC.
[0061] Terminal 101 can communicate with software deployment server 149 via network interface 129. Exemplarily, network interface 129 is a hardware network interface, such as a network interface card (NIC). Network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Optionally, network 127 can also be a wireless network, such as a WiFi network or a cellular network.
[0062] Hard disk drive interface 131 is coupled to system bus 105. Hardware driver interface is connected to hard disk drive 133. Internal memory 135 is coupled to system bus 105. Data running in internal memory 135 may include operating system (OS) 137, applications 143, and scheduling tables of terminal 101.
[0063] An operating system consists of the Shell 139 and the kernel 141. The Shell 139 is an interface between the user and the operating system kernel. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: waiting for user input, interpreting user input for the operating system, and processing various operating system outputs.
[0064] Kernel 141 consists of the parts of the operating system used to manage memory, files, peripherals, and system resources. Kernel 141 interacts directly with the hardware. The operating system kernel typically runs processes and provides inter-process communication, CPU time-slice management, interrupts, memory management, I / O management, and so on.
[0065] For example, when terminal 101 is a smartphone, application 143 includes instant messaging related programs. In one embodiment, when application 143 needs to be executed, terminal 101 can download application 143 from software deployment server 149.
[0066] Please refer to Figure 3 , Figure 3 This is a schematic diagram of an application scenario provided by an embodiment of this application. For example... Figure 3 As shown, taking a smartphone as an example, the software in the terminal runs in both user mode and the operating system, while the hardware is the storage device. In the terminal, applications run in user mode, while the file system (FS), block layer, and storage device drivers run in the operating system.
[0067] The file system is a software component within the operating system responsible for managing and storing file information; it is also known as a file management system. From a system perspective, the file system organizes and allocates space on file storage devices, and is responsible for storing, protecting, and retrieving files. Specifically, it is responsible for creating files for users, storing, reading, modifying, and dumping files, controlling file access, and deleting files when the user no longer needs them.
[0068] The block layer is the interface for the file system to access storage devices, and it serves as a bridge connecting the file system and driver components.
[0069] A driver component is a special program added to the operating system. It contains information about the hardware device and is used to enable communication between the software in the terminal and the storage device.
[0070] During terminal operation, when a user-mode application needs to read or write data to the storage device, it sends a data read request or data write request to the file system. The file system, based on the received data read or write request, issues a corresponding data processing request to the block layer. The block layer, based on the issued data processing request, generates a corresponding I / O request and sends it to the driver component. The driver component then communicates with the storage device based on the received I / O request to realize the data reading or writing.
[0071] Please refer to Figure 4 , Figure 4 This is a flowchart illustrating a data storage method 400 provided in an embodiment of this application. Figure 4 As shown, the method 400 includes the following steps 401-407.
[0072] Step 401: The operating system stores the target data in the first memory, which is internal memory.
[0073] When a terminal needs to store target data for a long period of time, the operating system in the terminal can store the target data in the first memory, which serves as internal memory, to achieve backup of the target data.
[0074] The target data is non-temporary stored data. That is, the storage requirement for the target data is that it can still be stored in the terminal after the terminal is powered off.
[0075] A terminal may include one or more internal memories, where the first memory can be any one of the internal memories within the terminal. Internal memory, also known as RAM or main memory, is typically used to temporarily store processing data from the processor. Internal memory acts as a bridge between external memory and the processor; all programs in the terminal run in RAM. For example, in the case of a computer, the internal memory may be a storage device such as a memory module. In the case of a smartphone, the internal memory may be a storage device such as RAM.
[0076] Step 402: The operating system sends a first instruction to the second memory, the first instruction including the target data, the first instruction being used to instruct the second memory to write the target data.
[0077] After acquiring the target data to be written to the second memory, the operating system generates a first instruction based on the target data and sends the first instruction to the second memory through the driver component. The first instruction includes the target data and a target address, and is used to instruct the second memory to write the target data to the target address.
[0078] In this embodiment, the operating system may execute steps 401 and 402 sequentially, that is, the operating system executes step 401 first and then step 402; the operating system may also execute steps 401 and 402 in parallel, and this embodiment does not specifically limit this.
[0079] The second memory is an external memory used for long-term data storage. The terminal may include one or more external memories, and the second memory can be any one of the external memories in the terminal. External memory refers to memory in the terminal other than internal memory and processor cache. For example, if the terminal is a computer, the external memory can be a storage device such as a hard disk, floppy disk, optical disk, or USB flash drive. If the terminal is a smartphone, the external memory can be a storage device such as built-in memory or an SD card. For example, the first memory can be 8 gigabytes (GB) of RAM in a smartphone, and the second memory can be 256GB of built-in memory in a smartphone.
[0080] The second memory includes volatile memory and non-volatile memory. The volatile memory is used to temporarily store the target data to be written to the non-volatile memory, and the non-volatile memory is used to store the target data permanently. The volatile memory has a faster data write speed, but it cannot retain data after power failure. The non-volatile memory has a slower data write speed, but it can still retain data after power failure. Therefore, the process of writing target data to the second memory includes: the second memory first writes the target data to the volatile memory, and then writes the target data from the volatile memory to the target address in the non-volatile memory.
[0081] For example, suppose the first instruction is used to instruct that target data of size 4 bytes (kB) be written into address segment 0-3. Then, the second memory first writes the 4kB target data into volatile memory according to the first instruction, and then writes the target data stored in volatile memory into address segment 0-3 of non-volatile memory.
[0082] In this embodiment, the volatile memory can be Static Random-Access Memory (SRAM) or Dynamic Random-Access Memory (DRAM). The non-volatile memory can be Universal Flash Storage (UFS), an Embedded Multi Media Card (eMMC), or Non-Volatile Memory Express (NVMe).
[0083] Step 403: The operating system obtains a second message sent by the second memory, which indicates that an abnormality has occurred in the second memory.
[0084] During the operation of the secondary memory, if an anomaly occurs that prevents normal data writing, the secondary memory sends a second message to the operating system. This second message indicates that the secondary memory has encountered an anomaly. The causes of the anomaly include, but are not limited to, factors such as unstable transmission links, malfunctions in the secondary memory's internal controller, or abnormalities in the storage medium.
[0085] Step 404: The operating system sends a third instruction to the second memory, the third instruction being used to instruct the second memory to perform a reset operation.
[0086] After receiving the second message reported by the second memory, the operating system sets the state of the second memory to an exception to block data read and write requests submitted by the application. That is, the operating system interrupts the sending of write or read instructions to the second memory. Then, the operating system sends a third instruction to the second memory, instructing it to perform a reset operation.
[0087] After receiving a third instruction instructing the second memory to perform a reset operation, the second memory executes the reset operation according to the third instruction to eliminate the abnormality that occurred in the second memory. After the second memory performs the reset operation, the data in the volatile memory of the second memory is lost due to power failure.
[0088] Step 405: The operating system obtains the first message sent by the second memory.
[0089] After the second memory successfully performs a reset operation, it sends a first message to the operating system. This first message indicates that the second memory reset was successful. By receiving the first message, the operating system can confirm that the second memory has returned to normal.
[0090] Step 406: The operating system sends a second instruction to the second memory.
[0091] The second instruction sent by the operating system to the second memory is generated based on the target data in the first memory. After confirming a successful reset of the second memory, the operating system can retrieve the target data from the first memory and generate the second instruction based on the target data. The second instruction includes the target data and is used to instruct the second memory to write the target data.
[0092] Step 407: The second memory writes the target data according to the second instruction.
[0093] In this way, after receiving the second instruction, the second memory writes the target data in the second instruction into the volatile memory, and then writes the target data from the volatile memory into the non-volatile memory.
[0094] It should be understood that the second instruction includes the target address where the target data needs to be written. Therefore, after receiving the second instruction, the second memory will rewrite the target data to the target address. In other words, even if the second memory has already written the target data to the non-volatile memory before performing the reset operation, the second memory will simply overwrite the target data at the target address without causing data corruption.
[0095] In this embodiment, after the second memory is reset, the operating system resends the target data stored in the first memory to the second memory, which can effectively avoid the data loss problem caused by the power-down reset of the second memory and ensure the normal operation of the terminal.
[0096] Optionally, to ensure that the first memory can properly store the processor's computational data, the terminal can pre-allocate a target storage space in the first memory. This target storage space is used to temporarily store data to be written to the second memory. For example, during the terminal's startup process, the terminal allocates a storage space of a specific size in the first memory and designates this space as the target storage space for temporarily storing data to be written to the second memory. Since the target storage space is a smaller storage space in the internal memory, allocating the target storage space in the internal memory will not affect the internal memory's normal storage of the processor's computational data. Furthermore, by allocating a separate target storage space in the first memory to store the data to be written to the second memory, the computational data to be written to the second memory can be effectively isolated from the processor's computational data, ensuring the independence of the data.
[0097] The capacity of the target storage space allocated in the first memory is greater than or equal to the capacity of the volatile memory in the second memory, so as to ensure that all data in the volatile memory of the second memory can be backed up in the target storage space. For example, if the capacity of the volatile memory in the second memory is 1MB, the capacity of the target storage space in the first memory can be 1MB, 2MB, or 10MB.
[0098] When the terminal has pre-allocated target storage space, and the operating system obtains the target data to be written to the second memory, the operating system can store the target data in the target storage space of the first memory.
[0099] It should be understood that, since the storage space in the first memory for storing data to be written to the second memory is limited, after the data has been written to the non-volatile memory of the second memory, the terminal can delete the target data stored in the first memory to ensure that there is enough free storage space in the first memory.
[0100] In this embodiment, the terminal can delete data in the first memory in a variety of ways.
[0101] Method 1: The terminal deletes the data in the first memory based on the message that the instruction has been completed fed back from the second memory.
[0102] For example, the method 400 may further include: the operating system receiving a third message sent by the second memory. The third message is a response message to the first instruction, indicating that the target data has been written to the non-volatile memory. The operating system then deletes the target data from the first memory.
[0103] In simple terms, after the second memory completes the first instruction issued by the operating system (i.e., completes the task of writing the target data into the non-volatile memory), it returns a third message to the operating system to indicate that the writing of the target data is complete. The operating system can then delete the target data from the first memory based on the third message.
[0104] Method 2: The terminal queries the data still stored in the volatile memory of the second memory, thereby deleting the data that is no longer in the volatile memory from the first memory.
[0105] For example, see Figure 5 , Figure 5 This is another schematic flowchart of the data storage method 400 provided in an embodiment of this application. For example... Figure 5 As shown, the method 400 further includes the following steps 408-410.
[0106] Step 408: The operating system sends a fourth instruction to the second memory, the fourth instruction being used to query the data stored in the volatile memory.
[0107] The operating system can periodically send instructions to the secondary memory to query data in the volatile memory. For example, the operating system can send an instruction to the secondary memory to query data in the volatile memory every 1 ms.
[0108] The operating system can also send an instruction to the second memory to query data in the volatile memory when the target storage space in the first memory, used to store the data to be written, is about to be saturated. For example, when the amount of data stored in the target storage space in the first memory is greater than or equal to a preset threshold, the operating system sends the fourth instruction to the second memory. The preset threshold can be determined based on the capacity of the target storage space and the capacity of the volatile memory in the second memory. For example, if the capacity of the target storage space is 10MB and the capacity of the volatile memory in the second memory is 1MB, the preset threshold can be set to 9MB. In this way, after each query of data in the volatile memory, the operating system can delete at least 8MB of data from the target storage space. Furthermore, with a preset threshold of 9MB, there is still 1MB of free space remaining in the target storage space, the size of which is the same as the capacity of the volatile memory. Thus, the operating system can ensure that there is sufficient free space in the target storage space to store subsequent data before deleting other data from it.
[0109] Step 409: The operating system obtains the fourth message sent by the second memory.
[0110] After receiving the fourth instruction from the operating system, the second memory generates a fourth message based on the data stored in the volatile memory and sends the fourth message to the operating system. The fourth message indicates the first data stored in the volatile memory. For example, the fourth message indicates that the first data stored in the volatile memory is data to be written to address segment 10-19.
[0111] Step 410: The operating system deletes the second data from the first memory.
[0112] In this context, both the second data and the first data are included in the target data, but the first data and the second data are different. The second data is the data in the target data that has been written from volatile memory to non-volatile memory. For example, suppose the target data stored in the first memory is data to be written to address segment 0-19, the first data is data to be written to address segment 10-19, and the second data is data to be written to address segment 0-9. The second data has already been written from volatile memory to non-volatile memory. Therefore, the operating system can delete the second data to be written to address segment 0-9 according to the fourth message. In other words, the operating system can delete data that is no longer in volatile memory from the first memory according to the fourth message.
[0113] Optionally, the operating system can delete a portion of the data in the target memory space using Method Two when the instructions are executed out of order in the second memory. When the instructions are executed out of order in the second memory, the second memory does not process the instructions in the order they are received. That is, the second memory may process the later-received instructions first, thus writing the later-received data from volatile memory to non-volatile memory first; for some earlier-received instructions, the second memory may not execute them, causing the earlier-received data to remain stored in volatile memory. In this case, the operating system can effectively ensure that the target memory space in the first memory retains all the data stored in volatile memory by deleting a portion of the data in the target memory using Method Two.
[0114] Furthermore, when the instructions are executed sequentially in the second memory, the operating system can also delete part of the data in the target memory space using method two. When the instructions are executed sequentially in the second memory, the second memory processes the instructions in the order they are received. That is, data received first in the second memory is written to the non-volatile memory first, and data received later in the second memory is written to the non-volatile memory later.
[0115] Method 3: If the target storage space already contains a large amount of data, the terminal deletes the data that was written to the target storage space first.
[0116] For example, if the second memory executes instructions sequentially, and the amount of data stored in the target storage space is greater than or equal to a preset threshold, the operating system in the terminal deletes the third data in the target storage space, which is the data that was first written into the target storage space.
[0117] Optionally, to avoid accidentally deleting data still stored in the volatile memory, the operating system can delete a portion of the data in the target storage space to ensure that, after deleting this portion, the amount of data remaining in the target storage space is greater than or equal to the capacity of the volatile memory. That is, after the operating system deletes the third piece of data in the target storage space, the amount of data remaining in the target storage space is greater than or equal to the capacity of the volatile memory. For example, if the target storage space has a capacity of 10MB and the volatile memory has a capacity of 1MB, the operating system can delete the first 8MB of data written to the target storage space if 9MB of data has already been stored there. In this way, after the operating system deletes 8MB of data, 1MB of data remains in the target storage space, ensuring that all the data stored in the volatile memory is still stored in the target storage space.
[0118] In simple terms, in method three, the operating system uses a first-in, first-out (FIFO) approach to delete data that has been successfully written to non-volatile memory in the target storage space, thereby ensuring that there is enough free space in the target storage space.
[0119] Generally, the method of executing instructions in the second memory of a terminal is usually fixed and only changes when the terminal's firmware is upgraded. Furthermore, firmware upgrades often require a reboot. Therefore, in practical applications, the terminal can obtain the method of executing instructions in the second memory after startup and select the method to delete data in the first memory based on this method. For example, when the second memory execution method is sequential, the terminal deletes data in the first memory using method three described above; when the second memory execution method is out-of-order, the terminal deletes data in the first memory using method two described above.
[0120] To facilitate understanding, the data storage method provided in the embodiments of this application will be described in detail below with specific examples.
[0121] Please refer to Figure 6 , Figure 6 This is a schematic diagram of the application architecture for the data storage method provided in the embodiments of this application. For example... Figure 6 As shown, the terminal's operating system includes a file system, a block layer, a target storage space in the first memory, a data recovery module, an exception handling module, and driver components (not shown in the figure); the terminal's device layer includes a second memory. The file system, block layer, and driver components can be found in [reference needed]. Figure 3 The corresponding architecture will not be described in detail here. Furthermore, in this embodiment, the driver component is used to transmit interaction information between the operating system and the second memory. For ease of description, this embodiment omits the process of the driver component transmitting interaction information between modules in the operating system and the second memory, and directly describes the interaction between modules in the operating system and the second memory.
[0122] exist Figure 6 In this process, when data needs to be written to the second memory, the block layer sends a data write command containing the target data to the second memory and stores the target data in the target memory space. If an exception occurs during the data write process in the second memory, the second memory reports an exception to the exception handling module. The exception handling module then triggers a reset of the second memory and, upon successful reset, notifies the data recovery module of the successful reset. The data recovery module then retrieves the target data from the target memory space and resends the target data to the second memory.
[0123] Please refer to Figure 7 , Figure 7 This is a flowchart illustrating a data storage method 700 provided in an embodiment of this application. The method 700 includes the following steps 701-710.
[0124] Step 701: The block layer stores the target data in the target storage space of the first memory.
[0125] After the block layer receives a data write request from the file system, it stores the target data indicated in the data write request in the target storage space of the first memory to achieve backup of the target data.
[0126] Step 702: The block layer sends a first instruction, including the target data, to the second memory.
[0127] After storing the target data in the target storage space, the block layer generates a first instruction based on the target data and sends the first instruction to the second memory through the driver component. The first instruction includes the target data and a target address, and is used to instruct the second memory to write the target data to the target address in the non-volatile memory.
[0128] Step 703: The second memory sends a second message indicating that an exception has occurred to the exception handling module.
[0129] During the process of writing target data to the second memory according to the first instruction, an error occurred in the second memory, causing it to be unable to write the target data normally. The second memory then sent a second message to the error handling module, indicating that an error had occurred in the second memory.
[0130] Step 704: The exception handling module sends a third instruction to the second memory to perform a reset operation.
[0131] After receiving the second message reported by the second memory, the exception handling module sets the state of the second memory to an exception to block data read and write requests submitted by the application. Then, the exception handling module sends a third instruction to the second memory to instruct it to perform a reset operation.
[0132] Step 705: The second memory performs a reset operation.
[0133] The second memory performs a reset operation based on the received third instruction to eliminate any abnormalities that occur in the second memory.
[0134] Step 706: The second memory sends a first message indicating successful reset to the exception handling module.
[0135] After the reset operation is performed, the second memory sends a first message to the exception handling module, which indicates that the second memory has been successfully reset.
[0136] Step 707: The exception handling module sends a message to the data recovery module instructing it to perform data recovery.
[0137] After the exception handling module receives the first message, it sends a message to the data recovery module to notify it to perform data recovery.
[0138] Step 708: The data recovery module generates a second instruction based on the target data.
[0139] Based on the message sent by the exception handling module instructing the execution of data recovery, the data recovery module obtains the target data from the target storage space and generates a second instruction based on the target data. The second instruction includes the target data and is used to instruct the second memory to write the target data.
[0140] Step 709: The data recovery module sends a second instruction, including the target data, to the second memory.
[0141] Step 710: The second memory writes the target data according to the second instruction.
[0142] After receiving the second instruction, the second memory rewrites the target data into the volatile memory according to the target data in the second instruction, and then writes the target data from the volatile memory into the non-volatile memory.
[0143] After successfully writing the target data to the second memory, the second memory can return a message to the data recovery module indicating that the target data was successfully written. This allows the data recovery module to notify the exception handling module that data recovery has been successfully performed. Finally, the exception handling module sets the state of the second memory to normal, allowing the block layer to continue processing data read and write requests submitted by the application.
[0144] exist Figures 1 to 7 Based on the corresponding embodiments, in order to better implement the above-described solutions of the embodiments of this application, related equipment for implementing the above-described solutions is also provided below.
[0145] For details, please refer to [link / reference]. Figure 8 , Figure 8This is a schematic diagram of the structure of a terminal 800 provided in an embodiment of this application. The terminal 800 includes a processing unit 801 and a transceiver unit 802. The processing unit 801 is used to store target data in a first memory, which is an internal memory. The transceiver unit 802 is used to send a first instruction to a second memory, the first instruction including the target data. The first instruction instructs the second memory to write the target data. The second memory is an external memory, which includes volatile memory and non-volatile memory. The volatile memory is used to temporarily store the target data to be written to the non-volatile memory, and the non-volatile memory is used to store the target data. The transceiver unit 802 is also used to restore the data in the second memory based on the target data in the first memory after the second memory is reset.
[0146] In one possible implementation, the transceiver unit 802 is further configured to acquire a first message sent by the second memory, the first message indicating that the second memory has been successfully reset; the transceiver unit 802 is further configured to send a second instruction to the second memory, the second instruction being generated based on the target data in the first memory, the second instruction including the target data, and the second instruction instructing the second memory to write the target data.
[0147] In one possible implementation, the transceiver unit 802 is further configured to acquire a second message sent by the second memory, the second message indicating that the second memory has encountered an abnormality; the transceiver unit 802 is further configured to send a third instruction to the second memory, the third instruction instructing the second memory to perform a reset operation.
[0148] In one possible implementation, the transceiver unit 802 is further configured to acquire a third message sent by the second memory, the third message indicating that the target data has been written to the non-volatile memory; the processing unit 801 is further configured to delete the target data in the first memory.
[0149] In one possible implementation, the processing unit 801 is further configured to store the target data into a target storage space in the first memory, wherein the target storage space is a pre-allocated storage space.
[0150] In one possible implementation, the capacity of the target storage space is greater than or equal to the capacity of the volatile memory.
[0151] In one possible implementation, the transceiver unit 802 is further configured to send a fourth instruction to the second memory, the fourth instruction being used to query the data stored in the volatile memory; the transceiver unit 802 is further configured to obtain a fourth message sent by the second memory, the fourth message being used to indicate the first data stored in the volatile memory; the processing unit 801 is further configured to delete the second data in the first memory; wherein the second data and the first data are both included in the target data, and the first data and the second data are different.
[0152] In one possible implementation, the transceiver unit 802 is further configured to send the fourth instruction to the second memory if the second memory executes instructions out of order and the amount of data stored in the target storage space is greater than or equal to a preset threshold.
[0153] In one possible implementation, the processing unit 801 is further configured to delete third data in the target storage space if the second memory executes instructions sequentially and the amount of data stored in the target storage space is greater than or equal to a preset threshold. The third data is the data that was first written into the target storage space.
[0154] The data storage method provided in this application embodiment can be specifically executed by a chip in a terminal. This chip includes a processing unit and a communication unit. The processing unit may be, for example, a processor, and the communication unit may be, for example, an input / output interface, pins, or circuitry. The processing unit can execute computer execution instructions stored in the storage unit, causing the chip in the server to execute the aforementioned... Figures 1 to 7 The data storage method described in the illustrated embodiment is as follows. Optionally, the storage unit is an on-chip storage unit, such as a register or cache. Alternatively, the storage unit can be an off-chip storage unit within the wireless access device, such as a read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions, such as random access memory (RAM).
[0155] Reference Figure 9 This application also provides a computer-readable storage medium, in some embodiments of which the above-described... Figure 4 The disclosed method can be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of art.
[0156] Figure 9A conceptual partial view of an example computer-readable storage medium arranged according to at least some of the embodiments shown herein is illustrated schematically. The example computer-readable storage medium includes a computer program for executing computer processes on a computing device.
[0157] In one embodiment, the computer-readable storage medium 900 is provided using a signal bearer medium 901. The signal bearer medium 901 may include one or more program instructions 902, which, when executed by one or more processors, can provide the above-mentioned... Figure 2 The described function or part of the function. Therefore, for example, refer to... Figure 4 In the embodiment shown, one or more features of steps 401-407 can be provided by one or more instructions associated with the signal carrying medium 901. Furthermore, Figure 9 The program instruction 902 in the document also describes example instructions.
[0158] In some examples, the signal carrying medium 901 may include a computer-readable medium 903, such as, but not limited to, a hard disk drive, a compact disc (CD), a digital video optical disc (DVD), a digital magnetic tape, a memory, ROM, or RAM, etc.
[0159] In some embodiments, the signal-bearing medium 901 may comprise a computer-recordable medium 904, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal-bearing medium 901 may comprise a communication medium 905, such as, but not limited to, digital and / or analog communication media (e.g., fiber optic cables, waveguides, wired communication links, wireless communication links, etc.). Therefore, for example, the signal-bearing medium 901 may be transmitted by a wireless communication medium 905 (e.g., a wireless communication medium conforming to the IEEE 802.9 standard or other transmission protocols).
[0160] One or more program instructions 902 may be, for example, computer-executable instructions or logical implementation instructions. In some examples, the computing device may be configured to provide various operations, functions, or actions in response to one or more program instructions 902 conveyed to the computing device via a computer-readable medium 903, a computer-recordable medium 904, and / or a communication medium 905.
[0161] It should be understood that the arrangements described herein are for illustrative purposes only. Therefore, those skilled in the art will understand that other arrangements and other elements (e.g., machines, interfaces, functions, sequences, and functional groups, etc.) can be used instead, and some elements may be omitted depending on the desired outcome. Furthermore, many of the described elements are functional entities that can be implemented as discrete or distributed components, or in any suitable combination and location with other components.
[0162] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0163] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of 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 system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.
[0164] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0165] 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.
[0166] 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 computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in 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, random access memory, magnetic disks, or optical disks.
Claims
1. A data storage method, characterized in that, include: The target data is stored in the first memory, which is internal memory; A first instruction is sent to a second memory, the first instruction including the target data. The first instruction is used to instruct the second memory to write the target data. The second memory is an external memory, and the second memory includes volatile memory and non-volatile memory. The volatile memory is used to temporarily store the target data to be written to the non-volatile memory, and the non-volatile memory is used to store the target data. Obtain a second message sent by the second memory, the second message indicating that the second memory has encountered an abnormality; Send a third instruction to the second memory, the third instruction being used to instruct the second memory to perform a reset operation; After the second memory is reset, the data in the second memory is recovered based on the target data in the first memory; Obtain a fourth message sent by the second memory, the fourth message being used to indicate that first data is stored in the volatile memory; Delete the second data in the first memory, where both the second data and the first data are contained in the target data, and the first data and the second data are different.
2. The method according to claim 1, characterized in that, The step of restoring the data in the second memory based on the target data in the first memory after the second memory is reset includes: Obtain the first message sent by the second memory, the first message being used to indicate that the second memory has been successfully reset; Send a second instruction to the second memory, the second instruction being generated based on the target data in the first memory, the second instruction including the target data, the second instruction being used to instruct the second memory to write the target data.
3. The method according to claim 1 or 2, characterized in that, The method further includes: Obtain a third message sent by the second memory, the third message being used to indicate that the target data has been written to the non-volatile memory; Delete the target data from the first memory.
4. The method according to claim 1 or 2, characterized in that, The step of storing the target data in the first memory includes: The target data is stored in the target storage space in the first memory, and the target storage space is a pre-allocated storage space.
5. The method according to claim 4, characterized in that, The capacity of the target storage space is greater than or equal to the capacity of the volatile memory.
6. The method according to claim 4, characterized in that, The method further includes: A fourth instruction is sent to the second memory, the fourth instruction being used to query the data stored in the volatile memory.
7. The method according to claim 6, characterized in that, Sending the fourth instruction to the second memory includes: If the second memory executes instructions out of order, and the amount of data stored in the target storage space is greater than or equal to a preset threshold, then the fourth instruction is sent to the second memory.
8. The method according to claim 4, characterized in that, The method further includes: If the second memory executes instructions sequentially, and the amount of data stored in the target storage space is greater than or equal to a preset threshold, then the third data in the target storage space is deleted. The third data is the data that was written to the target storage space first.
9. A terminal, characterized in that, The device includes internal memory, external memory, and a processor; the external memory or the internal memory stores code, and the processor is configured to execute the code, wherein when the code is executed, the terminal performs the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, It includes computer-readable instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1 to 8.
11. A computer program product, characterized in that, Includes computer-readable instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Power failure safeguard method and device for nonvolatile memory
CN106933706A