[go: up one dir, main page]

WO2022261823A1 - Data storage method and related device - Google Patents

Data storage method and related device Download PDF

Info

Publication number
WO2022261823A1
WO2022261823A1 PCT/CN2021/100100 CN2021100100W WO2022261823A1 WO 2022261823 A1 WO2022261823 A1 WO 2022261823A1 CN 2021100100 W CN2021100100 W CN 2021100100W WO 2022261823 A1 WO2022261823 A1 WO 2022261823A1
Authority
WO
WIPO (PCT)
Prior art keywords
storage
memory
data
area
storage unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2021/100100
Other languages
French (fr)
Chinese (zh)
Inventor
何彪
李点刚
王法
茹一帆
刘毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN202180099157.2A priority Critical patent/CN117501247A/en
Priority to PCT/CN2021/100100 priority patent/WO2022261823A1/en
Publication of WO2022261823A1 publication Critical patent/WO2022261823A1/en
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation

Definitions

  • the present application relates to the field of information technology, in particular to a data storage method and related equipment.
  • a storage unit can store more and more data, that is, the storage cost per unit of data is getting lower and lower, but what follows is More storage devices corresponding to storage devices have storage exceptions, and more complex software technologies.
  • a volatile storage medium such as random access storage ( Random Access Memory, RAM) buffer (buffer)
  • RAM Random Access Memory
  • buffer buffer
  • SOC System on Chip
  • the most effective method is to reset the storage device.
  • this buffer is composed of volatile storage media, when the storage device is reset due to an abnormality, the data in the volatile storage medium will be lost. Lost, resulting in the loss of users.
  • Embodiments of the present application provide a data storage method and related equipment, so as to avoid data loss after a memory is reset.
  • the embodiment of the present application provides a data storage method, which is characterized in that it is applied to an electronic device, and the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit, a second Two storage units, the first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the method may include:
  • the write instruction is used to instruct writing target data in the first memory into the second memory; and writing the target data into the first storage unit based on the write instruction Afterwards, retain the target data in the backup area of the first memory; when the first storage unit in the second memory is reset, reset part or all of the data in the backup area writing into the first storage unit; writing the data written into the first storage unit into the second storage unit.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the storing the target data in the first memory
  • the backup area includes: saving the target data from the storage area to the backup area, and releasing the target data in the storage area.
  • the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data.
  • the target data to be written in the second memory is saved from the storage area to the backup area, and at the same time, the target data in the original storage area is released (that is, erased), so that the original storage area can be rewritten with new data.
  • the second memory is reset, part or all of the data in the backup area is sent to the second memory again, so as to avoid data loss after the second memory is reset.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the storing the target data in the first memory In the backup area, including: not releasing the target data in the storage area, and adding the storage area to the backup area.
  • the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. After the target data in the storage area is written into the second memory, the data in the storage area is not released, but the storage area is added to the backup area, that is, the original storage area becomes the backup area and cannot be recreated. Write new data.
  • the target data can be backed up without being referenced or copied again, which greatly saves hardware computing resources while avoiding data loss after the second memory is reset.
  • the not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1, and add the storage area to the backup area, the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0 , releasing the target data in the storage area.
  • adding 1, and add the storage area to the backup area the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0 , releasing the target data in the storage area.
  • the method before generating the write instruction, further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate the The number of times the target data is referenced, wherein when the number of references of the storage area is 0, the target data in the storage area is released.
  • the number of references corresponding to all storage areas that can be used to store the target data in the first memory is increased by 1, so that the target data in the storage area is written through after the write command is completed.
  • Increasing the number of references to the target data in the storage area to ensure that the data in the storage area is not released can ensure that the target data can be rewritten into the second memory after the second memory is reset.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit.
  • the storage space of the backup area in the first memory is not smaller than the storage space of the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the backup area. Re-acquire the data in the file to avoid data loss.
  • the method further includes: when the size of data stored in the backup area exceeds a storage threshold, releasing target data that is stored in the backup area earliest.
  • the storage threshold such as the storage size of the first storage unit
  • the data that is stored in the backup area at the earliest has been written by the first storage unit. to the second storage unit, and because the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.
  • the method further includes: when the size of data stored in the backup area exceeds a storage threshold, releasing the target storage area that entered the backup area the earliest and the data in the target storage area .
  • the storage threshold such as the storage size of the first storage unit
  • the data stored in the storage area that was added to the backup area at the earliest has been saved by the first
  • the storage unit is written into the second storage unit, and since the second storage unit is a non-volatile storage unit, data will not be lost even when the second memory is reset.
  • the storage area that is, new data can be re-written
  • the data in the storage area that was added to the backup area in the current backup area at the earliest can be released, which can alleviate the storage in the first storage area.
  • Pressure guarantee storage space in the first memory.
  • the method further includes: when receiving a notification that the storage space of the first storage unit is insufficient, generating an output instruction, the output instruction is used to instruct that the first storage unit Write all data in the second storage unit; after writing all data in the first storage unit to the second storage unit, release all storage areas in the backup area and all storage areas in the backup area data.
  • an output command (such as a flush command) can be issued to the second storage device to make all the first storage units in the second memory Data is written into the second storage unit. After all the data is written into the second storage unit, all the storage areas in the backup area and the data in all the storage areas can be released to relieve memory pressure.
  • an embodiment of the present application provides a data storage device, which is applied to an electronic device, where the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit and a second storage unit,
  • the first memory is a volatile memory
  • the first storage unit is a volatile storage unit
  • the second storage unit is a non-volatile storage unit
  • the device includes: a generating unit configured to generate a write an instruction, the write instruction is used to instruct to write the target data in the first memory into the second memory;
  • a backup unit is used to write the target data into the second memory based on the write instruction After one storage unit, retaining the target data in the backup area of the first storage;
  • the first writing unit is used for when the first storage unit in the second storage is reset, Rewrite part or all of the data in the backup area to the first storage unit;
  • the second writing unit is used to write the data written in the first storage unit to the second storage in the unit.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically configured to: save the target data from saving the storage area to the backup area, and releasing the target data in the storage area.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically configured to: not release the storage area The target data in , and add the storage area to the backup area.
  • the backup unit is specifically configured to: add 1 to the current reference count of the storage area, and add the storage area to the backup area, and the reference count It is used to indicate the number of references of the target data in the storage area, wherein when the reference count of the storage area is 0, the target data in the storage area is released.
  • the device further includes: a reference management unit, configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used to indicate The number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.
  • a reference management unit configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used to indicate The number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit.
  • the apparatus further includes: a first releasing unit, configured to release target data stored in the backup area earliest when the size of data stored in the backup area exceeds a storage threshold.
  • the device further includes: a second release unit, configured to release the target storage area that entered the backup area the earliest and all data in the target storage area.
  • the device further includes: an output unit, configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to indicate that the writing all the data in the first storage unit into the second storage unit; a third release unit, configured to release the backup area after all the data in the first storage unit is written into the second storage unit All storage areas in and the data in all storage areas.
  • an output unit configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to indicate that the writing all the data in the first storage unit into the second storage unit
  • a third release unit configured to release the backup area after all the data in the first storage unit is written into the second storage unit All storage areas in and the data in all storage areas.
  • an embodiment of the present application provides a data storage device, which is applied to an electronic device, and the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit and a second storage unit, so The first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the device includes a processor, and the processor is configured To support the electronic device to realize the corresponding functions in the data storage method provided in the first aspect.
  • an embodiment of the present application provides an electronic device, the electronic device includes a processor, a first memory, and a second memory, and the processor is coupled to the first memory and the second memory; the The second storage unit includes a first storage unit and a second storage unit, the first storage unit is a volatile storage unit, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit unit; wherein, the first memory or the memory coupled to the processor stores necessary program instructions and data of the electronic device, so that the electronic device realizes corresponding functions in the data storage method provided in the first aspect.
  • an embodiment of the present application provides a computer program, the computer program includes instructions, and when the computer program is executed by a computer, the computer can execute the process performed by the data storage device in the second aspect above.
  • an embodiment of the present application provides a computer-readable storage medium for storing computer software instructions used for the data storage device provided in the second aspect above, which includes a program designed to execute the above aspect.
  • FIG. 1 is a schematic diagram of several storage units provided by an embodiment of the present application.
  • FIG. 2 is a schematic structural diagram of a storage device provided by an embodiment of the present application.
  • FIG. 3 is a schematic diagram of a data storage system architecture provided by an embodiment of the present application.
  • FIG. 4 is a schematic structural diagram of a data storage device provided by an embodiment of the present application.
  • FIG. 5 is a schematic diagram of copying target data to a first storage provided by an embodiment of the present application.
  • FIG. 6 is a schematic diagram of writing back target data from a first memory to a second memory according to an embodiment of the present application.
  • FIG. 7 is a schematic diagram of data reserved in a backup area provided by an embodiment of the present application.
  • FIG. 8 is a schematic diagram of releasing target data in a storage area in a prior art provided by an embodiment of the present application.
  • FIG. 9 is a schematic diagram of a management backup area provided by an embodiment of the present application.
  • FIG. 10 is a schematic diagram of another management backup area provided by the embodiment of the present application.
  • FIG. 11 is a schematic diagram of rewriting target data into a second memory according to an embodiment of the present application.
  • FIG. 12 is a schematic flowchart of a data storage method provided by an embodiment of the present application.
  • Fig. 13 is a schematic structural diagram of a data storage device provided by an embodiment of the present application.
  • At least one (item) means one or more, and “multiple” means two or more.
  • “And/or” is used to describe the association relationship of associated objects, indicating that there can be three types of relationships, for example, “A and/or B” can mean: only A exists, only B exists, and A and B exist at the same time , where A and B can be singular or plural.
  • the character “/” generally indicates that the contextual objects are an “or” relationship.
  • At least one of the following” or similar expressions refer to any combination of these items, including any combination of single or plural items.
  • At least one item (piece) of a, b or c can mean: a, b, c, "a and b", “a and c", “b and c", or "a and b and c ", where a, b, c can be single or multiple.
  • a component may be, but is not limited to being, a process running on a processor, a processor, an object, an executable, a thread of execution, a program, and/or a computer.
  • an application running on a computing device and the computing device can be components.
  • One or more components can reside within a process and/or thread of execution and a component can be localized on one computer and/or distributed between two or more computers.
  • these components can execute from various computer readable media having various data structures stored thereon.
  • a component may, for example, be based on a system having one or more packets of data (e.g., data from two components interacting with another component between a local system, a distributed system, and/or a network, such as the Internet interacting with other systems through signals). Signals are communicated through local and/or remote processes.
  • packets of data e.g., data from two components interacting with another component between a local system, a distributed system, and/or a network, such as the Internet interacting with other systems through signals.
  • Signals are communicated through local and/or remote processes.
  • NAND Flash is a non-volatile storage technology.
  • the storage unit of NAND Flash is divided into cell, die, block, page, cell, etc.
  • Cell is the smallest memory unit, multiple cells form a page (page); multiple pages form a block (block); multiple blocks form a die.
  • NAND Flash can still save data after power failure, it also has the following hardware features: After a memory unit is written (program), the data represented can change from logic 1 to logic 0, but this unit can no longer be written into. Return to logic 1, need to be erased (erase) before returning to logic 1.
  • the smallest unit of erasing in a flash memory is called a block.
  • SSD Solid State Drive
  • flash chip flash memory
  • DRAM Dynamic Random Access Memory
  • Its appearance can be made into various shapes, such as: notebook hard disk, micro hard disk, memory card, U disk and other styles.
  • Double rate DDR Double Data Rate
  • double rate synchronous dynamic random access memory DDR SDRAM, usually called DDR, where SDRAM is the abbreviation of (Synchronous Dynamic Random Access Memory), that is, synchronous dynamic random access memory , and DDR SDRAM is the abbreviation of Double Data Rate SDRAM, which means double-rate synchronous dynamic random access memory.
  • DDR memory is developed on the basis of SDRAM memory and still uses the SDRAM production system. Therefore, for memory manufacturers, it is only necessary to slightly improve the equipment for manufacturing ordinary SDRAM to realize the production of DDR memory, which can effectively reduce cost.
  • a storage unit can store more and more data, that is, the storage cost per unit of data continues to decrease.
  • the accompanying drawing 1 is a schematic diagram of several storage units provided by the embodiment of the present application.
  • the flash memory particles of most storage devices can be divided into single-level storage cells (Single-Level Cell, SLC), double-layer storage cells (Multi-Level Cell, MLC), triple-level storage cells (Trinary-Level Cell, Cell, TLC) and Quadruple-Level Cell (QLC), and even multi-layer storage units may appear; among them, each storage unit of STC can store 1 bit of data, and each storage unit of MTC can store 2 bits of data. For data, each storage unit of TTC can store 3 bits of data, and each storage unit of QTC can store 4 bits of data.
  • SLC single-level storage cells
  • MLC double-layer storage cells
  • Triple-Level Cell, Cell, TLC triple-level storage cells
  • QLC Quadruple-Level Cell
  • FIG. 2 is a schematic structural diagram of a storage device provided by an embodiment of the present application.
  • a Random Access Memory (RAM) buffer buffer
  • SOC System on Chip
  • the embodiments of the present application can provide a data storage method and related equipment that avoid data loss when the storage device is reset, and the method has little impact on users and improves user experience.
  • the data storage system architecture includes a host (host) 100 and a second storage 103 .
  • the host 100 can be any computing device that generates data, such as servers, personal computers, tablet computers, mobile phones, personal digital assistants, smart wearable devices, and other devices; wherein, the host 100 also includes a processing unit 101 and a first memory 102 .
  • the second memory 103 (equivalent to the above-mentioned storage device) may be any memory that provides the host 100 with the function of storing/reading data.
  • the second memory 103 and the host 100 may be co-located in one electronic device, or may be located in different electronic devices, which is not specifically limited in the present application.
  • the host 100 or the second memory 103 may specifically be a chip or a chipset or a circuit board equipped with a chip or a chipset, and the chip or a chipset or a circuit board equipped with a chip or a chipset can work under the necessary software drive. specifically,
  • the host 100 may include a processing unit (central processing unit, CPU) 101 and a first memory 102.
  • CPU central processing unit
  • Processing unit 101 can run a file system (such as a flash file system F2FS), an operating system or related application programs, etc., to control multiple hardware or software components connected to the processing unit 101, and can process various data and perform operations.
  • a file system such as a flash file system F2FS
  • an operating system or related application programs, etc. to control multiple hardware or software components connected to the processing unit 101, and can process various data and perform operations.
  • the processing unit 101 may run the file system to issue relevant read and write and erase instructions.
  • the processing unit 101 may include a central processing unit (CPU), an application processing unit (application processor, AP), a modem processing unit, a graphics processing unit (graphics processing unit, GPU), an image signal processing unit (image signal processor, ISP), video codec unit, digital signal processing unit (digital signal processor, DSP), baseband processing unit and neural-network processing unit (neural-network processing unit, NPU), etc. one or more.
  • the processing unit 101 may include one or more operation processing units (also referred to as processing cores), where different operation processing units may be independent devices, or may be integrated in one or more devices.
  • a memory may also be set in the processing unit 101 for storing related instructions and data.
  • the memory in the processing unit 101 is a cache memory (Cache).
  • the Cache may store instructions or data that have just been used or are recycled by the processing unit 101 . If the processing unit 101 needs to use the instruction or data again, it can be called directly from the Cache. Repeated access is avoided, and the waiting time of the processing unit 101 is reduced, thereby improving the efficiency of the system. Further, the processing unit 101 may also be implemented as a system on chip (System on Chip, SoC).
  • SoC System on Chip
  • the processing unit 101 may generate a write instruction, and the write instruction is used to instruct to write the target data in the first memory 102 into the second memory 103; based on the write After the instruction writes the target data into the first storage unit 1031, keep the target data in the backup area 1022 of the first memory 102; when the first memory in the second memory 103 When the storage unit 1031 is reset, rewrite part or all of the data in the backup area 1022 to the first storage unit 1031; write the data written into the first storage unit 1031 to the In the second storage unit 1032 mentioned above.
  • the processing unit 101 can load the instruction or data stored in the second memory 103 into the first memory 102, and transfer the instruction or data that needs to be calculated to the processing unit 101 to perform the operation. After the operation is completed, the processing unit 101 can then The results are temporarily stored in the first memory 102 , and instructions or data that need long-term storage can be stored in the second memory 103 .
  • the processing unit 101 can load the instruction or data stored in the second memory 103 into the first memory 102, and transfer the instruction or data that needs to be calculated to the processing unit 101 to perform the operation. After the operation is completed, the processing unit 101 can then The results are temporarily stored in the first memory 102 , and instructions or data that need long-term storage can be stored in the second memory 103 .
  • the first storage 102 which can also be referred to as a memory (Memory) or an internal storage, is a volatile storage.
  • the first memory 102 in the embodiment of the present application includes a readable and writable running memory, which can be used to temporarily store the calculation data in the processing unit 101, and exchange data with the second memory 103 or other external memory, and can be used as a file system or other temporary data storage media for running programs.
  • the file system running on the processing unit 101 transfers the data to be calculated from the first memory 102 to the processing unit 101 for calculation, and the processing unit 101 transmits the result after the calculation is completed.
  • the first storage 102 includes a storage area 1021 and a backup area 1022 .
  • the storage area 1021 is used to store temporary data or instruction programs of a file system or other running programs.
  • the backup area 1022 is used to store data stored in the second memory 103 from the storage area 1021 .
  • the first memory 102 may include a plurality of blocks (Block), each Block includes a plurality of pages (pages), and each page includes a certain number of cells (cells), and these Blocks, pages, and cells Both are used to store data, and the page cache Page is the smallest addressing unit, that is, the smallest unit of reading/writing. Therefore, the storage area 1021 in the first memory 102 includes one or more page caches for receiving read/write instructions, and reading or storing data. The backup area 1022 also includes one or more page caches for backing up data in response to write commands in the storage area.
  • the storage area 1021 and the backup area 1022 in the first memory 102 may be equivalent to a single page cache, or may be equivalent to a block composed of multiple page caches, or may be equivalent to a data storage area composed of multiple blocks.
  • the composition form of the storage area 1021 and the backup area 1022 is not specifically limited.
  • the first memory forms an SLC type memory.
  • the first memory forms an MLC/TLC type memory.
  • the first memory 102 may be one or more of dynamic random access memory (DRAM), static random access memory (SRAM), synchronous dynamic random access memory (SDRAM), and the like.
  • DRAM includes double data rate synchronous dynamic random access memory (Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM) referred to as DDR, second generation double rate synchronous dynamic random access memory (DDR2), third generation double rate synchronous dynamic random access memory (DDR SDRAM) DDR3), four generations of low power double data rate synchronous DRAM (Low Power Double Data Rate 4, LPDDR4) and five generations of low power double data rate synchronous DRAM (Low Power Double Data Rate 5, LPDDR5), etc. , which is not specifically limited in this embodiment of the present application.
  • DDR SDRAM Double Data Rate Synchronous Dynamic Random Access Memory
  • DDR SDRAM second generation double rate synchronous dynamic random access memory
  • DDR SDRAM third generation double rate synchronous dynamic random access memory
  • LPDDR4 Low Power Double Data Rate 4
  • LPDDR5 Low Power Double
  • the second memory 103 (for example: the storage device mentioned in FIG. 2 above) includes a first storage unit (for example: the buffer mentioned in FIG. 2 above), a second storage unit (for example: the flash memory NAND mentioned in FIG. 2 above) , wherein, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; including the first storage unit 1031 for asynchronously writing the received data in the second storage unit 1032; the second The storage unit 1032 can be used for long-term storage of instructions and data involved in the operation of the host 100, such as startup programs, operating systems, application programs and data, and so on.
  • the second memory 103 can be Flash flash memory (such as NAND flash memory, NOR flash memory, etc.), universal flash memory (universal flash storage, UFS), embedded multimedia card eMMC, universal flash storage multi-chip package uMCP memory, The embedded multimedia card multi-chip packages one or more of eMCP memory, solid-state drive (SSD), etc., which is not specifically limited in this embodiment of the present application.
  • Flash flash memory such as NAND flash memory, NOR flash memory, etc.
  • universal flash memory universal flash storage, UFS
  • embedded multimedia card eMMC embedded multimedia card
  • uMCP memory universal flash storage multi-chip package uMCP memory
  • the embedded multimedia card multi-chip packages one or more of eMCP memory, solid-state drive (SSD), etc., which is not specifically limited in this embodiment of the present application.
  • the data that needs to be erased is saved in the backup area of the first memory.
  • the data in the volatile memory unit i.e., the first memory unit
  • the second memory storage resend part or all of the data in the backup area to the second memory storage (rewrite data to the first storage unit), so as to avoid data loss in the first storage unit after the second storage is reset.
  • the structure of the host 100 or the second storage 103 in FIG. 3 is only some exemplary implementations provided by the embodiment of the present application, and the structure of the host 100 or the second storage 103 in the embodiment of the present application includes but not only Limited to the above implementations.
  • the processing unit 101 and the first memory 102, and the host 100 and the second memory 103 may communicate with each other through a system bus, or through other connection methods, which are not specifically described in this embodiment of the present application. limited.
  • the structure shown in the embodiment of the present application does not constitute a specific limitation of the host 100 or the second storage 103 .
  • the host 100 or the second memory 103 may include more or fewer components than shown in the figure, or combine certain components, or separate certain components, or arrange different components.
  • the illustrated components can be realized in hardware, software or a combination of software and hardware.
  • a data storage device provided by the embodiment of the present application.
  • the data storage device mainly takes the host 100 as the main body, and is described from the perspective of the processing unit 101 writing data into the second memory 103 .
  • the data storage method proposed in this application can be applied to the system architecture shown in FIG. 3 above to avoid data loss when the storage device is reset.
  • the processing unit 101 includes: a file system, a write data backup module 101 , a backup area management module 102 , and an abnormal retransmission module 103 ;
  • the second memory 103 includes: a first storage unit 1031 and a second storage unit 1032 .
  • the processing unit 101 is configured to generate a write instruction; after the target data is written into the first storage unit based on the write instruction, the target data is retained in the backup area of the first memory; when the first storage unit in the second memory is reset In the case of , rewrite part or all of the data in the backup area to the first storage unit; write the data written in the first storage unit to the second storage unit.
  • the file system is used to generate a write instruction
  • the write instruction is used to instruct to write the target data in the first memory 102 into the second memory 103 .
  • Fig. 5 is a schematic diagram of copying target data into the first storage provided by the embodiment of the present application
  • Fig. 6 is a schematic diagram of copying the target data from the first storage provided by the embodiment of the present application
  • target data such as: user data
  • the target data written into the page cache of the storage area will be written back into the second memory 103 to complete the write command.
  • Write data backup module 101 for after the write command is completed, that is, after the target data in the first memory 102 is written to the first storage unit 1031 in the second memory 103, keep the target data in the first In the backup area of the memory 102, the target data in the first memory 102 can be prevented from being released.
  • Fig. 7 is a schematic diagram of a reserved data in the backup area provided by the embodiment of the application
  • Fig. 8 is a release storage area in the prior art provided by the embodiment of the application Schematic representation of the target data in . As shown in FIG.
  • the target data in the page cache of the storage area is saved to the page cache of the backup area of the first memory 102 .
  • the release of the page cache data at this time refers to erasing the data in the page cache, so that the page cache can be written with new data. Before the data in the page cache is released, the page cache cannot be written with new data.
  • storing the target data in the backup area of the first memory includes: saving the target data from the storage area to the backup area, and releasing the target data.
  • the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data.
  • the target data to be written in the second memory is saved from the storage area to the backup area, and at the same time, the target data in the original storage area is released (that is, erased), so that the original storage area can be rewritten with new data.
  • storing the target data in a backup area of the first memory includes: not releasing the target data in the storage area, and adding the storage area to the backup area.
  • the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. After the target data in the storage area is written into the second memory, the data in the storage area is not released, but the storage area is added to the backup area, that is, the original storage area becomes the backup area and cannot be recreated. Write new data. For example: as shown in Figure 7, the page cache of the target data is stored in the storage area.
  • the page cache After the target data in the page cache is written to the first storage unit, the page cache will directly enter the backup area, which becomes the The page cache in the backup area, and the target data in the page cache was not freed. In this solution, the target data can be backed up without being referenced or copied again, which greatly saves hardware computing resources while avoiding data loss after the second memory is reset.
  • the area ID can be used to uniquely identify whether the area is a backup area.
  • each page cache may include an area identifier, which is used to identify whether the page cache belongs to the backup area or the storage area.
  • the area corresponding to the storage address may be preset as the backup area according to the storage address.
  • one specific implementation of the backup area can be a separate storage area for data writing; the other can also be a backup queue or a backup linked list, etc., when one or After the multiple page caches are written into the second memory, the one or more page caches can directly enter the backup queue or the backup linked list, so that the data in the one or more page caches are kept in the first memory.
  • the step of not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1 to the current reference count of the storage area, and adding the The storage area is added to the backup area, and the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0, the The target data in the storage area.
  • the above-mentioned current reference count of the storage area can be understood as the current reference count of the smallest read/write unit (such as page cache) in the storage area that responds to the write command.
  • the method before generating the write instruction, further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate that the target data in the storage area is The number of references, wherein, when the number of references of the storage area is 0, release the target data in the storage area.
  • the number of references corresponding to all storage areas that can be used to store the target data in the first memory can be increased by 1, so that the target data in the storage area can be written by increasing the number of references to the target in the storage area after the write command is completed.
  • the number of data references ensures that the data in the storage area is not released, which means that the target data can be rewritten into the second memory after the second memory is reset.
  • the backup area management module 102 is configured to: release the earliest target data stored in the backup area when the size of the data stored in the backup area exceeds a storage threshold.
  • the storage threshold may be set in advance or by default, and may also be set according to relevant management instructions of the user.
  • the storage threshold such as the storage size of the first storage unit
  • the data stored in the backup area at the earliest has been written into the second storage unit by the first storage unit.
  • the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.
  • the backup area management module 102 may release the target storage area that entered the backup area earliest and the data in the target storage area.
  • the storage threshold such as the storage size of the first storage unit
  • the data stored in the storage area that was added to the backup area at the earliest has been written into the second storage unit by the first storage unit. storage unit, and since the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset.
  • the storage area that is, new data can be rewritten
  • the data in the storage area added to the backup area at the earliest in the current backup area can be released, which can alleviate the storage in the first memory.
  • Pressure guarantee storage space in the first memory.
  • FIG. 9 is a schematic diagram of a management backup area provided by the embodiment of the present application
  • FIG. 10 is a schematic diagram of another management backup area provided by the embodiment of the present application.
  • Figure 9 when the data size in the page cache 1-4 stored in the backup area exceeds the storage threshold, release the earliest target data stored in the backup area page cache 1 and page cache 1, and the original backup area The storage space is also reduced accordingly.
  • Figure 10 when the size of the data in the page cache 1-4 stored in the backup area exceeds the storage threshold, the target data stored in the page cache 1 of the backup area earliest is released, and the storage space of the original backup area is not enough. will get smaller.
  • the backup area management module 102 may release the target storage area entering the backup area and the data in the target storage area according to the corresponding release strategy.
  • the release strategy may be to release the target storage area and the data in the target storage area that entered the backup area before a preset time period from the current time point.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit.
  • the storage space is a space in which the backup area and the first storage unit can store data.
  • the storage space of the backup area in the first memory is not less than the storage space in the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the data in the backup area, Data loss is avoided.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit, when the data in the first storage unit has not been written to the second storage unit, the data corresponding to the backup area will not The phenomenon of being deleted.
  • an output instruction when receiving a notification that the storage space of the first memory is insufficient, an output instruction is generated, the output instruction is used to instruct writing all data in the first storage unit into the second storage unit ; After all the data in the first storage unit is written into the second storage unit, releasing all the storage areas in the backup area and the data in the all storage areas.
  • an output command can be issued to the second storage device to write all the data of the first storage unit in the second memory to the second storage device. unit. After all the data is written into the second storage unit, all the storage areas in the backup area and the data in all the storage areas can be released to relieve memory pressure.
  • a flush command can be issued to the second storage device to force the data in the first storage unit 1031 (buffer) to be flushed into the second storage device.
  • the second storage unit 1032 (NAND media), then releases all data and/or page cache in the backup area to mitigate the impact on the first storage.
  • the abnormal resending module 103 is configured to rewrite part or all of the data in the backup area 1022 to the first storage unit when the first storage unit 1031 in the second memory 103 is reset. That is, if the second storage has an abnormal problem (such as: unable to respond to a command), after resetting the second storage 103 , resend part or all of the data in the backup area 1022 to the second storage 103 .
  • the second storage has an abnormal problem (such as: unable to respond to a command)
  • FIG. 11 is a schematic diagram of rewriting target data into the second memory provided by the embodiment of the present application.
  • the abnormal retransmission module 103 retransmits some or all of the data in the backup area (one or more of the page caches 1-4) The data is sent to the first storage unit 1031, so that the data in the backup area is rewritten into the second storage.
  • the structure of the processing unit 101 or the second memory 103 in FIG. 4 is only some exemplary implementations provided by the embodiment of the present application, and the structure of the processing unit 101 or the second memory 103 in the embodiment of the present application includes But not limited to the above implementation.
  • Fig. 12 is a schematic flowchart of a data storage method provided by an embodiment of the present application, which can be applied to the system architecture described in Fig. 1 above, where the data storage device can be used to support and execute the Step S201-Step S205 of the method flow shown in 12. The following will describe from the processing unit side of the host 100 with reference to FIG. 12 .
  • the method may include the following steps S201-S205.
  • Step S201 Generate a write instruction.
  • the data storage device generates a write instruction, where the write instruction is used to instruct to write the target data in the first memory into the second memory.
  • the processing device when the processing device needs to save the data in the first memory to the second memory during operation, it can generate a write instruction to instruct to write the target data in the first memory to the second memory.
  • Step S202 After writing the target data into the first storage unit based on the write command, keep the target data in the backup area of the first storage.
  • the target data is retained in the backup area of the first memory.
  • the first storage unit is a volatile storage unit in the second memory, because, in order to prevent the data in the first storage unit from being lost after the second memory is reset, after the target data can be written into the first storage unit, The target data is retained in the backup area of the first memory.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the backup area of the first memory includes : saving the target data from the storage area to the backup area, and releasing the target data in the storage area.
  • the data storage device to retain the target data in the backup area of the first memory, one of which is to save the target data written in the second memory from the storage area to the backup area, and at the same time The target data in the original storage area is released (ie, erased), so that the original storage area can be rewritten with new data.
  • the storage space corresponding to the storage area in the first storage and the storage space corresponding to the backup area do not change at most the size of the data that can be stored.
  • the storage space corresponding to the storage area and the storage space corresponding to the backup area both store data with a maximum size of 100M.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the backup area of the first memory includes : Do not release the target data in the storage area, and add the storage area to the backup area.
  • the data storage device to retain the target data in the backup area of the first memory, and the other way is to add the storage area to the backup area without releasing the data in the storage area, that is, The original storage area is changed into a backup area, and the original storage area cannot be rewritten with new data.
  • this application does not limit how the storage area becomes the backup area.
  • the area identification of the storage area can be changed from the storage area to the backup area, and the area identification is used to uniquely identify whether the area is a backup area; the storage space corresponding to the storage area can be re-divided into the storage area corresponding to the backup area Therefore, the storage space where the storage area is located will decrease, and the storage space where the backup area is located will increase accordingly.
  • the step of not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1 to the current reference count of the storage area, and adding the The storage area is added to the backup area, and the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0, the The target data in the storage area.
  • the data storage device ensures that the data in the storage area is not released by increasing the number of references to the target data in the storage area after completing the write command, that is, the target data remains in the backup area of the first memory.
  • the number of references is used to indicate the number of times the target data in the storage area is referenced by related instructions (eg, write instructions).
  • the method further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate that the target data in the storage area is The number of references, wherein, when the number of references of the storage area is 0, release the target data in the storage area.
  • the data storage device does not increase the number of references of the storage area after completing the write command, before generating the write command, the number of references corresponding to all storage areas in the first memory that can be used to store the target data is increased by 1, so that in the storage area
  • the writing of the target data in the storage area ensures that the data in the storage area will not be released by increasing the number of references to the target data in the storage area after the completion of the write command, so that the target data can be rewritten after the second memory is reset. Second storage.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit.
  • the storage space of the backup area in the first memory is not less than the storage space in the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the data in the backup area, Data loss is avoided.
  • the storage threshold can be set in advance or by default, or when the size of the stored data in the backup area in the first memory set according to the relevant management instructions of the user exceeds the storage threshold (such as the storage size of the first storage unit), it will be stored at the earliest
  • the data to the backup area has been written into the second storage unit by the first storage unit, and since the second storage unit is a non-volatile storage unit, even when the second storage is reset, the data will not be lost. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.
  • the storage threshold when the size of the data stored in the backup area exceeds the storage threshold, release the target storage area that entered the backup area earliest and the data in the target storage area.
  • the storage threshold such as the storage size of the first storage unit
  • the data stored in the storage area that was added to the backup area at the earliest has been written into the second storage unit by the first storage unit.
  • the storage area that is, new data can be re-written
  • the data in the storage area that was added to the backup area in the current backup area at the earliest can be released, which can alleviate the storage in the first storage area.
  • Pressure guarantee storage space in the first memory.
  • Step S203 When the first storage unit in the second memory is reset, rewrite part or all of the data in the backup area to the first storage unit.
  • the data storage device rewrites part or all of the data in the backup area to the first storage unit.
  • the lost part of the data can be sent, and in the case of being unable to determine the lost data of the first storage unit, part or all of the data in the backup area can be sent to Avoid data loss.
  • the data storage device writes the data written into the first storage unit into the second storage unit.
  • the first storage unit in the second memory is a volatile storage unit
  • the second storage unit is a non-volatile storage unit.
  • the data in the first storage unit needs to be written into the second storage unit. middle.
  • Step S204 When receiving a notification that the storage space of the first memory is insufficient, generate an output instruction.
  • the data storage device when the data storage device receives the notification that the storage space of the first memory is insufficient, it generates an output instruction, and the output instruction is used to instruct to write all the data in the first storage unit into the second storage unit.
  • the output instruction may be a flush command delivered to the second storage device.
  • Step S205 After all data in the first storage unit is written into the second storage unit, release all storage areas in the backup area and data in all storage areas.
  • the data storage device releases all storage areas in the backup area and data in all storage areas.
  • all the storage areas in the backup area and the data in all the storage areas can be released.
  • the data storage device releases all storage areas in the backup area and data in all storage areas.
  • the data that needs to be erased is saved in the backup area of the first memory.
  • the volatile memory unit that is, the data in the first memory unit will be lost when reset
  • resend part or all of the data in the backup area to the second memory rewriting the data to the first storage unit
  • the resending of the data in the backup area can maintain the consistency of the metadata after the abnormal recovery, avoiding the loss of the user's actual file data.
  • the method does not need to restart the electronic device, which greatly improves user experience.
  • steps S201 to S205 in the data storage method described in the embodiment of the present application please refer to the relevant descriptions of each functional unit in the device embodiment described in FIG. 4 above, and will not be repeated here. .
  • FIG. 13 is a schematic structural diagram of a data storage device provided by an embodiment of the present application.
  • the data storage device 10 is applied to an electronic device, and the electronic device includes a first memory and a second memory.
  • the first The second storage unit includes a first storage unit and a second storage unit, the first storage unit is a volatile storage unit, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit ;
  • the data storage device 10 may include a generating unit 301, a backup unit 302, a first writing unit 303 and a second writing unit 304; may also include: a reference management unit 305, a first releasing unit 306, and a second releasing unit 307 , the output unit 308 and the third release unit 309 .
  • the detailed description of each unit is as follows.
  • a generating unit 301 configured to generate a write instruction, where the write instruction is used to instruct writing target data in the first memory into the second memory;
  • a backup unit 302 configured to retain the target data in a backup area of the first memory after the target data is written into the first storage unit based on the write instruction;
  • the first writing unit 303 is configured to rewrite part or all of the data in the backup area to the first storage unit when the first storage unit in the second memory is reset;
  • the second writing unit 304 is configured to write the data written in the first storage unit into the second storage unit.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit 302 is specifically configured to: store the target data saving from the storage area to the backup area, and releasing the target data in the storage area.
  • the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit 302 is specifically configured to: not release the storage the target data in the region and add the storage region to the backup region.
  • the backup unit 302 is specifically configured to: add 1 to the current reference count of the storage area, and add the storage area to the backup area, and the reference The count is used to indicate the number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.
  • the device further includes: a reference management unit 305, configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used for Indicates the number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.
  • a reference management unit 305 configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used for Indicates the number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.
  • the storage space of the backup area is greater than or equal to the storage space of the first storage unit.
  • the device further includes: a first release unit 306, configured to release the earliest target data stored in the backup area when the size of the data stored in the backup area exceeds a storage threshold .
  • the device further includes: a second release unit 307, configured to release the target storage area that entered the backup area the earliest when the size of the data stored in the backup area exceeds a storage threshold; data in the target storage area.
  • a second release unit 307 configured to release the target storage area that entered the backup area the earliest when the size of the data stored in the backup area exceeds a storage threshold; data in the target storage area.
  • the device further includes: an output unit 308, configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to indicate that the All data in the first storage unit is written into the second storage unit; a third releasing unit 309 is configured to release the All the storage areas in the backup area and the data in the all storage areas.
  • each unit corresponds to its own program code (or program instruction), and when the program code corresponding to each unit runs on a related hardware device, the unit executes a corresponding process to realize a corresponding function.
  • the functions of each unit can also be realized by related hardware.
  • each functional unit in the data storage device 10 described in the embodiment of the present application can refer to steps S201-step S205 in the method embodiment described in FIG. 12 and the above described in FIG. 4 The related description of each module in the device embodiment will not be repeated here.
  • the disclosed device can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the above units is only a logical function division.
  • there may be other division methods for example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical or other forms.
  • the units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
  • the above integrated units are realized in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium.
  • the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions to make a computer device (which may be a personal computer, server or network device, etc., specifically, a processor in the computer device) execute all or part of the steps of the above-mentioned methods in various embodiments of the present application.
  • the aforementioned storage medium may include: U disk, mobile hard disk, magnetic disk, optical disc, read-only memory (Read-Only Memory, abbreviated: ROM) or random access memory (Random Access Memory, abbreviated: RAM) and the like.
  • ROM Read-Only Memory
  • RAM Random Access Memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Embodiments of the present application disclose a data storage method and a related device. The data storage method is applied to an electronic device, the electronic device comprises a first memory and a second memory, the second memory comprises a first memory cell and a second memory cell, the first memory is a volatile memory, the first memory cell is a volatile memory cell, and the second memory cell is a non-volatile memory cell. The method comprises: generating a write instruction; after target data is written to the first memory cell on the basis of the write instruction, retaining the target data in a backup area of the first memory; when the first memory cell in the second memory is reset, re-writing some or all of data in the backup area to the first memory cell; and writing, into the second memory cell, the data written into the first memory cell. By implementing the embodiments of the present application, data loss after a volatile memory is reset can be avoided.

Description

一种数据存储方法及相关设备A data storage method and related equipment 技术领域technical field

本申请涉及信息技术领域,尤其涉及一种数据存储方法及相关设备。The present application relates to the field of information technology, in particular to a data storage method and related equipment.

背景技术Background technique

随着NAND flash等闪存颗粒的存储密度技术不断提升,一个存储单元(cell)可以存储越来越多的数据,也就是每单位数据的存储成本越来越低,但随之而来的则是与存储器件相对应的更多的存储器件存储异常,还有更加复杂的软件技术。With the continuous improvement of the storage density technology of flash memory particles such as NAND flash, a storage unit (cell) can store more and more data, that is, the storage cost per unit of data is getting lower and lower, but what follows is More storage devices corresponding to storage devices have storage exceptions, and more complex software technologies.

从现代存储器件内部的架构上看,为了提升存储器件的读写性能,一般在会在非易失性存储介质(如:NAND)前设置一个易失性存储介质(如:随机存取存储(Random Access Memory,RAM)缓冲器(buffer))。这样来自系统级芯片(System on Chip,SOC)的写请求能够先缓存在这个易失性存储介质中,然后再异步回写到非易失性存储介质中。当存储器件出现异常时候,最有效的手段就是对存储器件进行复位,然而由于这个buffer是易失性存储介质组成的,所以当存储器件因异常复位时,易失性存储介质中的数据就会丢失,造成用户的损失。From the perspective of the internal architecture of modern storage devices, in order to improve the read and write performance of storage devices, a volatile storage medium (such as random access storage ( Random Access Memory, RAM) buffer (buffer)). In this way, write requests from the System on Chip (SOC) can be cached in the volatile storage medium first, and then asynchronously written back to the non-volatile storage medium. When the storage device is abnormal, the most effective method is to reset the storage device. However, since this buffer is composed of volatile storage media, when the storage device is reset due to an abnormality, the data in the volatile storage medium will be lost. Lost, resulting in the loss of users.

因此,如何避免存储器件复位后的数据丢失,是本申请亟需解决的问题。Therefore, how to avoid data loss after the storage device is reset is an urgent problem to be solved in this application.

发明内容Contents of the invention

本申请实施例提供一种数据存储方法及相关设备,以避免存储器复位后的数据丢失。Embodiments of the present application provide a data storage method and related equipment, so as to avoid data loss after a memory is reset.

第一方面,本申请实施例提供了一种数据存储方法,其特征在于,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述方法可包括:In the first aspect, the embodiment of the present application provides a data storage method, which is characterized in that it is applied to an electronic device, and the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit, a second Two storage units, the first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the method may include:

生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中;基于所述写指令将所述目标数据写入至所述第一存储单元后,将所述目标数据保留在所述第一存储器的备份区域中;当所述第二存储器中的所述第一存储单元发生复位的情况下,将所述备份区域中部分或全部数据重新写入至所述第一存储单元;将写入至所述第一存储单元中的数据写入至所述第二存储单元中。generating a write instruction, where the write instruction is used to instruct writing target data in the first memory into the second memory; and writing the target data into the first storage unit based on the write instruction Afterwards, retain the target data in the backup area of the first memory; when the first storage unit in the second memory is reset, reset part or all of the data in the backup area writing into the first storage unit; writing the data written into the first storage unit into the second storage unit.

实施第一方面方法实施例,本申请在进行数据存储时,当数据写入第二存储器后,将原来需要被擦除的数据保存至第一存储器的备份区域中,可以在第二存储器发生复位的情况下(此时,第一存储单元中的数据在复位时会丢失),重新将备份区域中的部分或全部数据发送至第二存储器(将数据重新写入至第一存储单元),这样可以避免第二存储器复位后,第一存储单元中的数据丢失。而且,该重新发送备份区域的数据可以保持在异常恢复后的元数据的一致性,避免用户实际文件数据的丢失。另外,该方法不需要重新启动电子设备,大大提升了用户体验。因此,在写数据时将被写入的数据备份,可以保证数据发生丢失时能够被重新获取,最大限度的避免了用户数据损失。Implementing the method embodiment of the first aspect, when the application stores data, after the data is written into the second memory, the data that originally needs to be erased is saved in the backup area of the first memory, and reset can occur in the second memory In the case of (at this time, the data in the first storage unit will be lost when reset), resend part or all of the data in the backup area to the second storage (rewrite the data to the first storage unit), so that Data in the first storage unit can be prevented from being lost after the second memory is reset. Moreover, the resending of the data in the backup area can maintain the consistency of the metadata after the abnormal recovery, avoiding the loss of the user's actual file data. In addition, the method does not need to restart the electronic device, which greatly improves user experience. Therefore, backing up the written data when writing data can ensure that the data can be retrieved when data is lost, and avoid the loss of user data to the greatest extent.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储 区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。在本申请实施例中,第一存储器包括存储区域和备份区域,存储区域用于存储要写入第二存储器中的目标数据,备份区域用于存储该目标数据的备份数据。将被写入第二存储器中的目标数据由存储区域保存至备份区域,同时将原来存储区域中的目标数据释放(即,擦除),以使原来存储区域可以重新写入新的数据。在第二存储器发生复位的时,重新将备份区域中的部分或全部数据发送至第二存储器,这样可以避免第二存储器复位后数据丢失。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the storing the target data in the first memory The backup area includes: saving the target data from the storage area to the backup area, and releasing the target data in the storage area. In this embodiment of the present application, the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. The target data to be written in the second memory is saved from the storage area to the backup area, and at the same time, the target data in the original storage area is released (that is, erased), so that the original storage area can be rewritten with new data. When the second memory is reset, part or all of the data in the backup area is sent to the second memory again, so as to avoid data loss after the second memory is reset.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。在本申请实施例中,第一存储器包括存储区域和备份区域,存储区域用于存储要写入第二存储器中的目标数据,备份区域用于存储该目标数据的备份数据。在存储区域中的目标数据写入第二存储器后,并不释放该存储区域中的数据,而是将该存储区域加入至备份区域,即,原来的存储区域变为了备份区域,不能再被重新写入新的数据。在该方案中,目标数据不需要被再次引用或复制,即可完成备份,在避免第二存储器复位后数据丢失的同时,大大节省了硬件计算资源。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the storing the target data in the first memory In the backup area, including: not releasing the target data in the storage area, and adding the storage area to the backup area. In this embodiment of the present application, the first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. After the target data in the storage area is written into the second memory, the data in the storage area is not released, but the storage area is added to the backup area, that is, the original storage area becomes the backup area and cannot be recreated. Write new data. In this solution, the target data can be backed up without being referenced or copied again, which greatly saves hardware computing resources while avoiding data loss after the second memory is reset.

在一种可能实现的方式中,所述不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域包括:在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。在本申请实施例中,通过在完成写指令后增加对存储区域内目标数据的引用次数,确保存储区域内的数据不被释放,即可保证该目标数据可以在第二存储器复位后,重新写入第二存储器。In a possible implementation manner, the not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1, and add the storage area to the backup area, the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0 , releasing the target data in the storage area. In the embodiment of the present application, by increasing the number of references to the target data in the storage area after completing the write command, it is ensured that the data in the storage area is not released, which can ensure that the target data can be rewritten after the second memory is reset. into the second memory.

在一种可能实现的方式中,在生成所述写指令之前,所述方法还包括:在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。在本申请实施例中,在生成写指令之前,将第一存储器中可用于存储目标数据的所有存储区域对应的引用次数增加1,使得在存储区域中的目标数据写入通过在完成写指令后增加对存储区域内目标数据的引用次数,确保存储区域内的数据不被释放,即可保证该目标数据可以在第二存储器复位后,重新写入第二存储器。In a possible implementation manner, before generating the write instruction, the method further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate the The number of times the target data is referenced, wherein when the number of references of the storage area is 0, the target data in the storage area is released. In the embodiment of the present application, before generating the write command, the number of references corresponding to all storage areas that can be used to store the target data in the first memory is increased by 1, so that the target data in the storage area is written through after the write command is completed. Increasing the number of references to the target data in the storage area to ensure that the data in the storage area is not released can ensure that the target data can be rewritten into the second memory after the second memory is reset.

在一种可能实现的方式中,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。在本申请实施例中,第一存储器中备份区域的存储空间不小于第一存储单元中的存储空间,可以保证在第一存储单元复位后,第一存储单元中丢失的数据可以完全从备份区域内的数据中重新获取,避免了数据的丢失。In a possible implementation manner, the storage space of the backup area is greater than or equal to the storage space of the first storage unit. In the embodiment of the present application, the storage space of the backup area in the first memory is not smaller than the storage space of the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the backup area. Re-acquire the data in the file to avoid data loss.

在一种可能实现的方式中,所述方法还包括:在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。在本申请实施例中,第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早被存 储至备份区域的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早保留的目标数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。In a possible implementation manner, the method further includes: when the size of data stored in the backup area exceeds a storage threshold, releasing target data that is stored in the backup area earliest. In the embodiment of the present application, when the size of the stored data in the backup area in the first storage exceeds the storage threshold (such as the storage size of the first storage unit), the data that is stored in the backup area at the earliest has been written by the first storage unit. to the second storage unit, and because the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.

在一种可能实现的方式中,所述方法还包括:在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。在本申请实施例中,第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早添加至备份区域中的存储区域保存的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早添加至备份区域中的存储区域(即,可以重新写入新的数据),以及该存储区域中的数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。In a possible implementation manner, the method further includes: when the size of data stored in the backup area exceeds a storage threshold, releasing the target storage area that entered the backup area the earliest and the data in the target storage area . In this embodiment of the application, when the size of the stored data in the backup area in the first storage exceeds the storage threshold (such as the storage size of the first storage unit), the data stored in the storage area that was added to the backup area at the earliest has been saved by the first The storage unit is written into the second storage unit, and since the second storage unit is a non-volatile storage unit, data will not be lost even when the second memory is reset. Therefore, when the storage threshold is exceeded, the storage area (that is, new data can be re-written) and the data in the storage area that was added to the backup area in the current backup area at the earliest can be released, which can alleviate the storage in the first storage area. Pressure, guarantee storage space in the first memory.

在一种可能实现的方式中,所述方法还包括:在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元;在所述第一存储单元中全部数据写入至所述第二存储单元后,释放所述备份区域中全部存储区域以及所述全部存储区域中的数据。在本申请实施例中,当第一存储器的可存储空间不足(内存紧张)时,可以向第二存储器件下发输出指令(如:flush命令)以使第二存储器中第一存储单元的全部数据写入至第二存储单元。全部数据被写入第二存储单元后,即可释放备份区域中全部存储区域以及全部存储区域中的数据,以缓解内存压力。In a possible implementation manner, the method further includes: when receiving a notification that the storage space of the first storage unit is insufficient, generating an output instruction, the output instruction is used to instruct that the first storage unit Write all data in the second storage unit; after writing all data in the first storage unit to the second storage unit, release all storage areas in the backup area and all storage areas in the backup area data. In this embodiment of the application, when the storable space of the first memory is insufficient (memory is tight), an output command (such as a flush command) can be issued to the second storage device to make all the first storage units in the second memory Data is written into the second storage unit. After all the data is written into the second storage unit, all the storage areas in the backup area and the data in all the storage areas can be released to relieve memory pressure.

第二方面,本申请实施例提供了一种数据存储装置,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述装置包括:生成单元,用于生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中;备份单元,用于基于所述写指令将所述目标数据写入至所述第一存储单元后,将所述目标数据保留在所述第一存储器的备份区域中;第一写入单元,用于当所述第二存储器中的所述第一存储单元发生复位的情况下,将所述备份区域中部分或全部数据重新写入至所述第一存储单元;第二写入单元,用于将写入至所述第一存储单元中的数据写入至所述第二存储单元中。In a second aspect, an embodiment of the present application provides a data storage device, which is applied to an electronic device, where the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit and a second storage unit, The first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the device includes: a generating unit configured to generate a write an instruction, the write instruction is used to instruct to write the target data in the first memory into the second memory; a backup unit is used to write the target data into the second memory based on the write instruction After one storage unit, retaining the target data in the backup area of the first storage; the first writing unit is used for when the first storage unit in the second storage is reset, Rewrite part or all of the data in the backup area to the first storage unit; the second writing unit is used to write the data written in the first storage unit to the second storage in the unit.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元,具体用于:将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically configured to: save the target data from saving the storage area to the backup area, and releasing the target data in the storage area.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元,具体用于:不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically configured to: not release the storage area The target data in , and add the storage area to the backup area.

在一种可能实现的方式中,所述备份单元,具体用于:在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述 存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。In a possible implementation manner, the backup unit is specifically configured to: add 1 to the current reference count of the storage area, and add the storage area to the backup area, and the reference count It is used to indicate the number of references of the target data in the storage area, wherein when the reference count of the storage area is 0, the target data in the storage area is released.

在一种可能实现的方式中,所述装置还包括:引用管理单元,用于在生成所述写指令之前,在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。In a possible implementation manner, the device further includes: a reference management unit, configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used to indicate The number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.

在一种可能实现的方式中,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。In a possible implementation manner, the storage space of the backup area is greater than or equal to the storage space of the first storage unit.

在一种可能实现的方式中,所述装置装置还包括:第一释放单元,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。In a possible implementation manner, the apparatus further includes: a first releasing unit, configured to release target data stored in the backup area earliest when the size of data stored in the backup area exceeds a storage threshold.

在一种可能实现的方式中,所述装置还包括:第二释放单元,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。In a possible implementation manner, the device further includes: a second release unit, configured to release the target storage area that entered the backup area the earliest and all data in the target storage area.

在一种可能实现的方式中,所述装置还包括:输出单元,用于在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元;第三释放单元,用于在所述第一存储单元中全部数据写入至所述第二存储单元后,释放所述备份区域中全部存储区域以及所述全部存储区域中的数据。In a possible implementation manner, the device further includes: an output unit, configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to indicate that the writing all the data in the first storage unit into the second storage unit; a third release unit, configured to release the backup area after all the data in the first storage unit is written into the second storage unit All storage areas in and the data in all storage areas.

第三方面,本申请实施例提供一种数据存储装置,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述装置包括处理器,所述处理器被配置为支持该电子设备实现第一方面提供的数据存储方法中相应的功能。In a third aspect, an embodiment of the present application provides a data storage device, which is applied to an electronic device, and the electronic device includes a first memory and a second memory, and the second memory includes a first storage unit and a second storage unit, so The first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the device includes a processor, and the processor is configured To support the electronic device to realize the corresponding functions in the data storage method provided in the first aspect.

第四方面,本申请实施例提供一种电子设备,所述电子设备包括处理器、第一存储器和第二存储器,所述处理器与所述第一存储器和所述第二存储器耦合;所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;其中,所述第一存储器或与所述处理器耦合的存储器保存该电子设备必要的程序指令和数据,使得所述电子设备实现第一方面提供的数据存储方法中相应的功能。In a fourth aspect, an embodiment of the present application provides an electronic device, the electronic device includes a processor, a first memory, and a second memory, and the processor is coupled to the first memory and the second memory; the The second storage unit includes a first storage unit and a second storage unit, the first storage unit is a volatile storage unit, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit unit; wherein, the first memory or the memory coupled to the processor stores necessary program instructions and data of the electronic device, so that the electronic device realizes corresponding functions in the data storage method provided in the first aspect.

第五方面,本申请实施例提供了一种计算机程序,该计算机程序包括指令,当该计算机程序被计算机执行时,使得计算机可以执行上述第二方面中的数据存储装置所执行的流程。In a fifth aspect, an embodiment of the present application provides a computer program, the computer program includes instructions, and when the computer program is executed by a computer, the computer can execute the process performed by the data storage device in the second aspect above.

第六方面,本申请实施例提供一种计算机可读存储介质,用于储存为上述第二方面提供的一种数据存储装置所用的计算机软件指令,其包含用于执行上述方面所设计的程序。In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium for storing computer software instructions used for the data storage device provided in the second aspect above, which includes a program designed to execute the above aspect.

附图说明Description of drawings

为了更清楚地说明本申请实施例或背景技术中的技术方案,下面将对本申请实施例或背景技术中所需要使用的附图进行说明。In order to more clearly illustrate the technical solutions in the embodiment of the present application or the background art, the following will describe the drawings that need to be used in the embodiment of the present application or the background art.

图1是本申请实施例提供的几种存储单元的示意图。FIG. 1 is a schematic diagram of several storage units provided by an embodiment of the present application.

图2是本申请实施例提供的一种存储器件的结构示意图。FIG. 2 is a schematic structural diagram of a storage device provided by an embodiment of the present application.

图3是本申请实施例提供的一种数据存储系统架构示意图。FIG. 3 is a schematic diagram of a data storage system architecture provided by an embodiment of the present application.

图4是本申请实施例提供的一种数据存储装置的结构示意图。FIG. 4 is a schematic structural diagram of a data storage device provided by an embodiment of the present application.

图5是本申请实施例提供的一种将目标数据复制到第一存储中的示意图。FIG. 5 is a schematic diagram of copying target data to a first storage provided by an embodiment of the present application.

图6是本申请实施例提供的一种将目标数据由第一存储器回写至第二存储器中的示意图。FIG. 6 is a schematic diagram of writing back target data from a first memory to a second memory according to an embodiment of the present application.

图7是本申请实施例提供的一种保留数据在备份区域中的示意图。FIG. 7 is a schematic diagram of data reserved in a backup area provided by an embodiment of the present application.

图8是本申请实施例提供的一种现有技术中释放存储区域中目标数据的示意图。FIG. 8 is a schematic diagram of releasing target data in a storage area in a prior art provided by an embodiment of the present application.

图9是本申请实施例提供的一种管理备份区域的示意图。FIG. 9 is a schematic diagram of a management backup area provided by an embodiment of the present application.

图10是本申请实施例提供的另一种管理备份区域的示意图。FIG. 10 is a schematic diagram of another management backup area provided by the embodiment of the present application.

图11是本申请实施例提供的一种目标数据重新写入第二存储器中的示意图。FIG. 11 is a schematic diagram of rewriting target data into a second memory according to an embodiment of the present application.

图12是本申请实施例提供的一种数据存储方法的流程示意图。FIG. 12 is a schematic flowchart of a data storage method provided by an embodiment of the present application.

图13是本申请实施例提供的一种数据存储计装置的结构示意图。Fig. 13 is a schematic structural diagram of a data storage device provided by an embodiment of the present application.

具体实施方式detailed description

下面将结合本申请实施例中的附图,对本申请实施例进行描述。The embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.

本申请的说明书和权利要求书及所述附图中的术语“第一”和“第二”等是用于区别不同对象,而不是用于描述特定顺序。此外,术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first" and "second" in the description and claims of the present application and the drawings are used to distinguish different objects, rather than to describe a specific order. Furthermore, the terms "include" and "have", as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes unlisted steps or units, or optionally further includes For other steps or units inherent in these processes, methods, products or apparatuses.

应当理解,在本申请中,“至少一个(项)”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,用于描述关联对象的关联关系,表示可以存在三种关系,例如,“A和/或B”可以表示:只存在A,只存在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b或c中的至少一项(个),可以表示:a,b,c,“a和b”,“a和c”,“b和c”,或“a和b和c”,其中a,b,c可以是单个,也可以是多个。It should be understood that in this application, "at least one (item)" means one or more, and "multiple" means two or more. "And/or" is used to describe the association relationship of associated objects, indicating that there can be three types of relationships, for example, "A and/or B" can mean: only A exists, only B exists, and A and B exist at the same time , where A and B can be singular or plural. The character "/" generally indicates that the contextual objects are an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one item (piece) of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c ", where a, b, c can be single or multiple.

在本文中提及“实施例”意味着,结合实施例描述的特定特征、结构或特性可以包含在本申请的至少一个实施例中。在说明书中的各个位置出现该短语并不一定均是指相同的实施例,也不是与其它实施例互斥的独立的或备选的实施例。本领域技术人员显式地和隐式地理解的是,本文所描述的实施例可以与其它实施例相结合。Reference herein to an "embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present application. The occurrences of this phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is understood explicitly and implicitly by those skilled in the art that the embodiments described herein can be combined with other embodiments.

在本说明书中使用的术语“部件”、“模块”、“系统”等用于表示计算机相关的实体、硬件、 固件、硬件和软件的组合、软件、或执行中的软件。例如,部件可以是但不限于,在处理器上运行的进程、处理器、对象、可执行文件、执行线程、程序和/或计算机。通过图示,在计算设备上运行的应用和计算设备都可以是部件。一个或多个部件可驻留在进程和/或执行线程中,部件可位于一个计算机上和/或分布在2个或更多个计算机之间。此外,这些部件可从在上面存储有各种数据结构的各种计算机可读介质执行。部件可例如根据具有一个或多个数据分组(例如来自与本地系统、分布式系统和/或网络间的另一部件交互的二个部件的数据,例如,通过信号与其它系统交互的互联网)的信号通过本地和/或远程进程来通信。The terms "component", "module", "system" and the like are used in this specification to refer to a computer-related entity, hardware, firmware, a combination of hardware and software, software, or software in execution. For example, a component may be, but is not limited to being, a process running on a processor, a processor, an object, an executable, a thread of execution, a program, and/or a computer. By way of illustration, both an application running on a computing device and the computing device can be components. One or more components can reside within a process and/or thread of execution and a component can be localized on one computer and/or distributed between two or more computers. In addition, these components can execute from various computer readable media having various data structures stored thereon. A component may, for example, be based on a system having one or more packets of data (e.g., data from two components interacting with another component between a local system, a distributed system, and/or a network, such as the Internet interacting with other systems through signals). Signals are communicated through local and/or remote processes.

首先,对本申请中的部分用语进行解释说明,以便于本领域技术人员理解。First of all, some terms used in this application are explained to facilitate the understanding of those skilled in the art.

(1)NAND闪存(NAND Flash),是一种非失性存储技术。NAND Flash的存储单元划分有cell,die,block,page,cell等。cell是最小的记忆单元,多个cell组成一个page(页);多个page组成一个block(块);多个block组成一个die。NAND Flash除了具有断电后仍能保存数据的特性,还具有以下硬件特性:一个记忆单元经过写入(program),表示的数据可由逻辑1变成逻辑0,但无法再经由写入将此单元回复到逻辑1,需经过擦除(erase)才可回复逻辑1。一般快闪存储器中抹除的最小单位称为块(block)。(1) NAND Flash (NAND Flash) is a non-volatile storage technology. The storage unit of NAND Flash is divided into cell, die, block, page, cell, etc. Cell is the smallest memory unit, multiple cells form a page (page); multiple pages form a block (block); multiple blocks form a die. In addition to the feature that NAND Flash can still save data after power failure, it also has the following hardware features: After a memory unit is written (program), the data represented can change from logic 1 to logic 0, but this unit can no longer be written into. Return to logic 1, need to be erased (erase) before returning to logic 1. Generally, the smallest unit of erasing in a flash memory is called a block.

(2)固态驱动器(Solid State Drive,SSD),或称固态硬盘,是用固态电子存储芯片阵列而制成的硬盘。SSD由控制单元和存储单元(Flash芯片、DRAM芯片)组成,其芯片的工作温度范围很宽,应用领域广泛。固态硬盘的存储介质通常为两种,一种是采用闪存(Flash芯片)作为存储介质,另外一种是采用DRAM作为存储介质。它的外观可以被制作成多种模样,例如:笔记本硬盘、微硬盘、存储卡、U盘等样式。(2) Solid State Drive (SSD), or solid-state hard disk, is a hard disk made of an array of solid-state electronic memory chips. SSD is composed of a control unit and a storage unit (Flash chip, DRAM chip). The chip has a wide operating temperature range and a wide range of applications. There are generally two types of storage media for solid-state hard disks, one is to use flash memory (Flash chip) as a storage medium, and the other is to use DRAM as a storage medium. Its appearance can be made into various shapes, such as: notebook hard disk, micro hard disk, memory card, U disk and other styles.

(3)双倍速率DDR=Double Data Rate,双倍速率同步动态随机存储器=DDR SDRAM,通常被称为DDR,其中,SDRAM是(Synchronous Dynamic Random Access Memory)的缩写,即同步动态随机存取存储器,而DDR SDRAM是Double Data Rate SDRAM的缩写,是双倍速率同步动态随机存储器的意思。DDR内存是在SDRAM内存基础上发展而来的,仍然沿用SDRAM生产体系,因此对于内存厂商而言,只需对制造普通SDRAM的设备稍加改进,即可实现DDR内存的生产,可有效的降低成本。(3) Double rate DDR = Double Data Rate, double rate synchronous dynamic random access memory = DDR SDRAM, usually called DDR, where SDRAM is the abbreviation of (Synchronous Dynamic Random Access Memory), that is, synchronous dynamic random access memory , and DDR SDRAM is the abbreviation of Double Data Rate SDRAM, which means double-rate synchronous dynamic random access memory. DDR memory is developed on the basis of SDRAM memory and still uses the SDRAM production system. Therefore, for memory manufacturers, it is only necessary to slightly improve the equipment for manufacturing ordinary SDRAM to realize the production of DDR memory, which can effectively reduce cost.

目前,随着NAND flash等闪存颗粒的存储密度技术不断提升,一个存储单元(cell)可以存储越来越多的数据,也就是每单位数据的存储成本不断降低。例如:请参考附图1,图1是本申请实施例提供的几种存储单元的示意图。如图1所示,大多数存储器件的闪存颗粒可以分为单层存储单元(Single-Level Cell,SLC)、双层存储单元(Multi-Level Cell,MLC)、三层存储单元(Trinary-Level Cell,TLC)和四层存储单元(Quadruple-Level Cell,QLC),甚至还可能会出现多层存储单元;其中,STC每个存储单元可以保存1bit的数据,MTC每个存储单元可以保存2bit的数据,TTC每个存储单元可以保存3bit的数据,QTC每个存储单元可以保存4bit的数据。At present, with the continuous improvement of the storage density technology of flash memory particles such as NAND flash, a storage unit (cell) can store more and more data, that is, the storage cost per unit of data continues to decrease. For example: Please refer to the accompanying drawing 1, which is a schematic diagram of several storage units provided by the embodiment of the present application. As shown in Figure 1, the flash memory particles of most storage devices can be divided into single-level storage cells (Single-Level Cell, SLC), double-layer storage cells (Multi-Level Cell, MLC), triple-level storage cells (Trinary-Level Cell, Cell, TLC) and Quadruple-Level Cell (QLC), and even multi-layer storage units may appear; among them, each storage unit of STC can store 1 bit of data, and each storage unit of MTC can store 2 bits of data. For data, each storage unit of TTC can store 3 bits of data, and each storage unit of QTC can store 4 bits of data.

请参考附图2,图2是本申请实施例提供的一种存储器件的结构示意图。如图2所示,从目前存储器件内部的架构上看,为了提升存储器件的读写性能,一般在会在NAND介质 前设置一个随机存取存储(Random Access Memory,RAM)缓冲器(buffer)。这样来自系统级芯片(System on Chip,SOC)的写指令能够先缓存在这个buffer中,然后异步回写到NAND中。当存储器件出现异常时候,最有效的手段就是对存储器件进行复位。然而,由于这个buffer是易失的RAM组成,所以当存储器件因异常复位时,buffer中的数据就会丢失。Please refer to FIG. 2 , which is a schematic structural diagram of a storage device provided by an embodiment of the present application. As shown in Figure 2, from the perspective of the internal architecture of the current storage device, in order to improve the read and write performance of the storage device, a Random Access Memory (RAM) buffer (buffer) is generally set in front of the NAND medium . In this way, write instructions from the System on Chip (SOC) can be cached in this buffer first, and then written back to NAND asynchronously. When the storage device is abnormal, the most effective means is to reset the storage device. However, since this buffer is composed of volatile RAM, when the storage device is reset due to an abnormality, the data in the buffer will be lost.

现有技术中,为了避免数据丢失,一种方式是在存储器件复位前,让存储器件把buffer中的数据全部回写到NAND上,也就是发送一个flush命令给存储器件。但是存储器件发生异常的时候,有可能已经无法处理任何命令了,即,在存储器件异常时候,已经无法响应指令,把buffer中的数据回刷到NAND介质上,此时只有丢数据进行复位。另一种方式是,一旦发现存储器件无法响应任何命令了,直接对主机和存储器件同时复位。利用主机启动时,文件系统挂载时候的异常恢复保护元数据的一致性。这样做可以避免丢失的数据对文件系统挂载的影响,但是无法避免用户实际文件数据的丢失,而且会对使用体验产生明显影响。In the prior art, in order to avoid data loss, one way is to let the storage device write back all the data in the buffer to the NAND before the storage device is reset, that is, to send a flush command to the storage device. However, when the storage device is abnormal, it may not be able to process any commands, that is, when the storage device is abnormal, it has been unable to respond to the command, and the data in the buffer is flashed back to the NAND medium. At this time, only the data is lost to reset. Another way is to directly reset the host and the storage device at the same time once it is found that the storage device cannot respond to any command. When the host starts, the abnormal recovery when the file system is mounted protects the consistency of metadata. Doing so can avoid the impact of lost data on the file system mount, but it cannot avoid the loss of the user's actual file data, and it will have a significant impact on the user experience.

因此,本申请实施例可以提供一种避免存储器件复位时数据丢失的数据存储方法以及相关设备,而且该方法对用户影响小,提升了用户体验。Therefore, the embodiments of the present application can provide a data storage method and related equipment that avoid data loss when the storage device is reset, and the method has little impact on users and improves user experience.

下面先对本申请实施例所基于的其中一种系统架构进行描述。One of the system architectures on which the embodiment of the present application is based is firstly described below.

基于上述,本申请实施例提供一种包括主机和相关存储设备的数据存储系统架构。请参考附图3,图3是本申请实施例提供的一种数据存储系统架构示意图。如图3所示,数据存储系统架构包括主机(host)100和第二存储器103。该主机100可以为任何产生数据的计算设备,如服务器、个人计算机、平板电脑、手机、个人数字助理、智能穿戴设备等各类设备;其中,主机100中还包括处理单元101和第一存储器102。第二存储器103(相当于上述存储设备)可以是任何为主机100提供存储/读取数据功能的存储器。在本申请实施例中,可以是第二存储器103和主机100共同位于一个电子设备中,也可以是处于不同的电子设备中,本申请对此不做具体限定。主机100或第二存储器103具体可以是芯片或芯片组或搭载有芯片或者芯片组的电路板,该芯片或芯片组或搭载有芯片或芯片组的电路板可在必要的软件驱动下工作。具体地,Based on the foregoing, embodiments of the present application provide a data storage system architecture including a host and related storage devices. Please refer to accompanying drawing 3, which is a schematic diagram of a data storage system architecture provided by an embodiment of the present application. As shown in FIG. 3 , the data storage system architecture includes a host (host) 100 and a second storage 103 . The host 100 can be any computing device that generates data, such as servers, personal computers, tablet computers, mobile phones, personal digital assistants, smart wearable devices, and other devices; wherein, the host 100 also includes a processing unit 101 and a first memory 102 . The second memory 103 (equivalent to the above-mentioned storage device) may be any memory that provides the host 100 with the function of storing/reading data. In the embodiment of the present application, the second memory 103 and the host 100 may be co-located in one electronic device, or may be located in different electronic devices, which is not specifically limited in the present application. The host 100 or the second memory 103 may specifically be a chip or a chipset or a circuit board equipped with a chip or a chipset, and the chip or a chipset or a circuit board equipped with a chip or a chipset can work under the necessary software drive. specifically,

主机100,可包括处理单元(central processing unit,CPU)101和第一存储器102。可选的,还可以包括图3中未示出的电源、其他输入输出控制器和接口等应用处理侧的所有物理器件。其中,The host 100 may include a processing unit (central processing unit, CPU) 101 and a first memory 102. Optionally, all physical devices on the application processing side, such as power supplies not shown in FIG. 3 , other input and output controllers, and interfaces, may also be included. in,

处理单元101:可运行文件系统(如闪存文件系统F2FS)、操作系统或相关应用程序等,以控制连接到处理单元101的多个硬件或软件元件,并且可处理各种数据并执行操作。例如:处理单元101可以运行文件系统下发相关的读、写后擦除指令。Processing unit 101: can run a file system (such as a flash file system F2FS), an operating system or related application programs, etc., to control multiple hardware or software components connected to the processing unit 101, and can process various data and perform operations. For example: the processing unit 101 may run the file system to issue relevant read and write and erase instructions.

可选的,处理单元101可以包括中央处理单元(CPU)、应用处理单元(application processor,AP)、调制解调处理单元、图形处理单元(graphics processing unit,GPU)、图像信号处理单元(image signal processor,ISP)、视频编解码单元、数字信号处理单元(digital signal processor,DSP)、基带处理单元和神经网络处理单元(neural-network processing unit,NPU)等中的一个或多个。处理单元101可以包括一个或多个运算处理单元(也可称处理核), 其中,不同的运算处理单元可以是独立的器件,也可以集成在一个或多个器件中。可选的,处理单元101中还可以设置存储器,用于存储相关指令和数据。在一些实施例中,处理单元101中的存储器为高速缓冲存储器(Cache)。所述Cache可以保存处理单元101刚用过或循环使用的指令或数据。如果处理单元101需要再次使用该指令或数据,可从所述Cache中直接调用。避免了重复存取,减少了处理单元101的等待时间,因而提高了系统的效率。进一步地,处理单元101还可被实现为片上系统(System on Chip,SoC)。Optionally, the processing unit 101 may include a central processing unit (CPU), an application processing unit (application processor, AP), a modem processing unit, a graphics processing unit (graphics processing unit, GPU), an image signal processing unit (image signal processor, ISP), video codec unit, digital signal processing unit (digital signal processor, DSP), baseband processing unit and neural-network processing unit (neural-network processing unit, NPU), etc. one or more. The processing unit 101 may include one or more operation processing units (also referred to as processing cores), where different operation processing units may be independent devices, or may be integrated in one or more devices. Optionally, a memory may also be set in the processing unit 101 for storing related instructions and data. In some embodiments, the memory in the processing unit 101 is a cache memory (Cache). The Cache may store instructions or data that have just been used or are recycled by the processing unit 101 . If the processing unit 101 needs to use the instruction or data again, it can be called directly from the Cache. Repeated access is avoided, and the waiting time of the processing unit 101 is reduced, thereby improving the efficiency of the system. Further, the processing unit 101 may also be implemented as a system on chip (System on Chip, SoC).

另外,在本申请实施例中,处理单元101可以生成写指令,所述写指令用于指示将所述第一存储器102中的目标数据写入至所述第二存储器103中;基于所述写指令将所述目标数据写入至所述第一存储单元1031后,将所述目标数据保留在所述第一存储器102的备份区域1022中;当所述第二存储器103中的所述第一存储单元1031发生复位的情况下,将所述备份区域1022中部分或全部数据重新写入至所述第一存储单元1031;将写入至所述第一存储单元1031中的数据写入至所述第二存储单元1032中。其中,处理单元101可将第二存储器103中存储的指令或数据加载到第一存储器102中,并把需要运算的指令或数据调到处理单元101中进行运算,当运算完成后处理单元101再将结果临时存储在第一存储器102中,并将需要长期存储的指令或数据可以存储至第二存储器103中。另外,该方案的具体实施过程可以参考下述实施例的相关描述,本申请实施例在此暂不赘述。In addition, in the embodiment of the present application, the processing unit 101 may generate a write instruction, and the write instruction is used to instruct to write the target data in the first memory 102 into the second memory 103; based on the write After the instruction writes the target data into the first storage unit 1031, keep the target data in the backup area 1022 of the first memory 102; when the first memory in the second memory 103 When the storage unit 1031 is reset, rewrite part or all of the data in the backup area 1022 to the first storage unit 1031; write the data written into the first storage unit 1031 to the In the second storage unit 1032 mentioned above. Wherein, the processing unit 101 can load the instruction or data stored in the second memory 103 into the first memory 102, and transfer the instruction or data that needs to be calculated to the processing unit 101 to perform the operation. After the operation is completed, the processing unit 101 can then The results are temporarily stored in the first memory 102 , and instructions or data that need long-term storage can be stored in the second memory 103 . In addition, for the specific implementation process of this solution, reference may be made to the relevant description of the following embodiments, and the embodiments of the present application will not be repeated here.

第一存储器102,也可称为内存(Memory)或内存储器,为易失性存储器。本申请实施例中的第一存储器102包括可读可写的运行内存,可以用于暂时存放处理单元101中的运算数据,以及与第二存储器103或其他外部存储器交互数据,可作为如文件系统或其他正在运行中的程序的临时数据的存储媒介。例如,运行于处理单元101上的文件系统把需要运算的数据从第一存储器102调到处理单元101中进行运算,当运算完成后处理单元101再将结果传送出来。The first storage 102 , which can also be referred to as a memory (Memory) or an internal storage, is a volatile storage. The first memory 102 in the embodiment of the present application includes a readable and writable running memory, which can be used to temporarily store the calculation data in the processing unit 101, and exchange data with the second memory 103 or other external memory, and can be used as a file system or other temporary data storage media for running programs. For example, the file system running on the processing unit 101 transfers the data to be calculated from the first memory 102 to the processing unit 101 for calculation, and the processing unit 101 transmits the result after the calculation is completed.

可选的,第一存储器102包括存储区域1021和备份区域1022。该存储区域1021用于存储文件系统或其他正在运行中的程序的临时数据或指令程序。该备份区域1022用于存储从存储区域1021存储至第二存储器103中的数据。Optionally, the first storage 102 includes a storage area 1021 and a backup area 1022 . The storage area 1021 is used to store temporary data or instruction programs of a file system or other running programs. The backup area 1022 is used to store data stored in the second memory 103 from the storage area 1021 .

需要说明的是,第一存储器102可包括多个块(Block),每个Block包括多个页(page),而每个page中又包含一定数量的单元(cell),这些Block、page和cell均用于存储数据,其中,页缓存Page是最小的寻址单位,即读/写的最小单位。因此,所述第一存储器102中的存储区域1021包含有一个或多个页缓存以用于接收读/写指令,读取或存储数据。备份区域1022也包含有一个或多个页缓存以用于备份存储区域响应了写指令的数据。所以,第一存储器102中的存储区域1021和备份区域1022可以相当于单个页缓存,也可以相当于多个页缓存组成的块,还可以相当于多个块组成的存储数据的区域,本申请对存储区域1021和备份区域1022的组成形式,不作具体的限定。It should be noted that the first memory 102 may include a plurality of blocks (Block), each Block includes a plurality of pages (pages), and each page includes a certain number of cells (cells), and these Blocks, pages, and cells Both are used to store data, and the page cache Page is the smallest addressing unit, that is, the smallest unit of reading/writing. Therefore, the storage area 1021 in the first memory 102 includes one or more page caches for receiving read/write instructions, and reading or storing data. The backup area 1022 also includes one or more page caches for backing up data in response to write commands in the storage area. Therefore, the storage area 1021 and the backup area 1022 in the first memory 102 may be equivalent to a single page cache, or may be equivalent to a block composed of multiple page caches, or may be equivalent to a data storage area composed of multiple blocks. The composition form of the storage area 1021 and the backup area 1022 is not specifically limited.

还需要说明的是,当第一存储器所有Block中的所有page中的所有cell都为单层单元(SLC)时,第一存储器形成了SLC型的存储器。同理,当第一存储器所有Block中的所有page中的所有cell都为多层单元(MLC)或三层单元(TLC)时,因此该第一存储器形成了MLC/TLC型的存储器。It should also be noted that when all cells in all pages in all blocks of the first memory are single-level cells (SLC), the first memory forms an SLC type memory. Similarly, when all cells in all pages in all blocks of the first memory are multi-level cells (MLC) or triple-level cells (TLC), the first memory forms an MLC/TLC type memory.

另外,第一存储器102可以为动态随机存取存储器(DRAM)、静态随机存取存储器 (SRAM)、同步动态随机存取存储器(SDRAM)等中的一种或多种。其中,DRAM又包括双倍速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory,DDR SDRAM)简称DDR、二代双倍速率同步动态随机存储器(DDR2)、三代双倍速率同步动态随机存储器(DDR3)、四代低功耗双倍数据率同步动态随机存储器(Low Power Double Data Rate 4,LPDDR4)和五代低功耗双倍数据率同步动态随机存储器(Low Power Double Data Rate 5,LPDDR5)等,本申请实施例对此不作具体的限定。In addition, the first memory 102 may be one or more of dynamic random access memory (DRAM), static random access memory (SRAM), synchronous dynamic random access memory (SDRAM), and the like. Among them, DRAM includes double data rate synchronous dynamic random access memory (Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM) referred to as DDR, second generation double rate synchronous dynamic random access memory (DDR2), third generation double rate synchronous dynamic random access memory (DDR SDRAM) DDR3), four generations of low power double data rate synchronous DRAM (Low Power Double Data Rate 4, LPDDR4) and five generations of low power double data rate synchronous DRAM (Low Power Double Data Rate 5, LPDDR5), etc. , which is not specifically limited in this embodiment of the present application.

第二存储器103(例如:上述图2提及的存储器件)包括第一存储单元(例如:上述图2提及的缓冲器)、第二存储单元(例如:上述图2提及的闪存NAND),其中,第一存储单元为易失性存储单元,第二存储单元为非易失性存储单元;包括第一存储单元1031用于将接收到数据异步写入第二存储单元1032中;第二存储单元1032可用于长期存储主机100运行所涉及的指令和数据,如启动程序、操作系统、应用程序和数据等。The second memory 103 (for example: the storage device mentioned in FIG. 2 above) includes a first storage unit (for example: the buffer mentioned in FIG. 2 above), a second storage unit (for example: the flash memory NAND mentioned in FIG. 2 above) , wherein, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; including the first storage unit 1031 for asynchronously writing the received data in the second storage unit 1032; the second The storage unit 1032 can be used for long-term storage of instructions and data involved in the operation of the host 100, such as startup programs, operating systems, application programs and data, and so on.

可选的,第二存储器103,可以为Flash闪存(例如,NAND闪存、NOR闪存等)、通用闪存存储器(universal flash storage,UFS)、嵌入式多媒体卡eMMC、通用闪存存储多芯片封装uMCP存储器、嵌入式多媒体卡多芯片封装eMCP存储器、固态驱动器(SSD)等中的一个或多个等,本申请实施例对此不作具体的限定。Optionally, the second memory 103 can be Flash flash memory (such as NAND flash memory, NOR flash memory, etc.), universal flash memory (universal flash storage, UFS), embedded multimedia card eMMC, universal flash storage multi-chip package uMCP memory, The embedded multimedia card multi-chip packages one or more of eMCP memory, solid-state drive (SSD), etc., which is not specifically limited in this embodiment of the present application.

本申请在进行数据存储时,在数据写入第二存储器后,将原来需要被擦除的数据保存至第一存储器的备份区域中。在第二存储器发生复位的情况下(此时,易失性存储单元(即,第一存储单元)中的数据会在复位时丢失),重新将备份区域中的部分或全部数据发送至第二存储器(将数据重新写入至第一存储单元),这样可以避免第二存储器复位后,第一存储单元中的数据丢失。When storing data in the present application, after the data is written into the second memory, the data that needs to be erased is saved in the backup area of the first memory. In the case of a reset of the second memory (at this time, the data in the volatile memory unit (i.e., the first memory unit) will be lost at reset), resend part or all of the data in the backup area to the second memory storage (rewrite data to the first storage unit), so as to avoid data loss in the first storage unit after the second storage is reset.

可以理解的是,图3中的主机100或第二存储器103的结构只是本申请实施例提供的一些示例性的实施方式,本申请实施例中的主机100或第二存储器103的结构包括但不仅限于以上实现方式。It can be understood that the structure of the host 100 or the second storage 103 in FIG. 3 is only some exemplary implementations provided by the embodiment of the present application, and the structure of the host 100 or the second storage 103 in the embodiment of the present application includes but not only Limited to the above implementations.

还可以理解的是,处理单元101与第一存储器102、主机100与第二存储器103之间可以通过系统总线的方式相互通信,也可以通过其他连接方式进行通信,本申请实施例对此不作具体限定。本申请实施例示意的结构并不构成主机100或第二存储器103的具体限定。在本申请另一些实施例中,主机100或第二存储器103可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can also be understood that the processing unit 101 and the first memory 102, and the host 100 and the second memory 103 may communicate with each other through a system bus, or through other connection methods, which are not specifically described in this embodiment of the present application. limited. The structure shown in the embodiment of the present application does not constitute a specific limitation of the host 100 or the second storage 103 . In other embodiments of the present application, the host 100 or the second memory 103 may include more or fewer components than shown in the figure, or combine certain components, or separate certain components, or arrange different components. The illustrated components can be realized in hardware, software or a combination of software and hardware.

下面结合上述图3所述的主机100和第二存储器103的系统结构,以处理单元101执行文件系统下发的写指令为例,介绍本申请实施例提供的一种数据存储装置,请参考附图4,图4是本申请实施例提供的一种数据存储装置的结构示意图,该数据存储装置主要以主机100为主体,从处理单元101将数据写入第二存储器103的角度进行描述。本申请提出的数据存储方法可以应用于上述图3所示系统架构,避免存储器件复位时数据丢失。其中,所述处理单元101包括:文件系统,写数据备份模块101,备份区域管理模块102,异常重发模块103;所述第二存储器103包括:第一存储单元1031和第二存储单元1032。其中,Combining the system structure of the host 100 and the second memory 103 described above in FIG. 3 , and taking the processing unit 101 to execute the write command issued by the file system as an example, a data storage device provided by the embodiment of the present application is introduced. Please refer to the attached 4 and 4 are schematic structural diagrams of a data storage device provided by an embodiment of the present application. The data storage device mainly takes the host 100 as the main body, and is described from the perspective of the processing unit 101 writing data into the second memory 103 . The data storage method proposed in this application can be applied to the system architecture shown in FIG. 3 above to avoid data loss when the storage device is reset. Wherein, the processing unit 101 includes: a file system, a write data backup module 101 , a backup area management module 102 , and an abnormal retransmission module 103 ; the second memory 103 includes: a first storage unit 1031 and a second storage unit 1032 . in,

处理单元101被配置为生成写指令;基于写指令将目标数据写入至第一存储单元后, 将目标数据保留在第一存储器的备份区域中;当第二存储器中的第一存储单元发生复位的情况下,将备份区域中部分或全部数据重新写入至第一存储单元;将写入至第一存储单元中的数据写入至第二存储单元中。The processing unit 101 is configured to generate a write instruction; after the target data is written into the first storage unit based on the write instruction, the target data is retained in the backup area of the first memory; when the first storage unit in the second memory is reset In the case of , rewrite part or all of the data in the backup area to the first storage unit; write the data written in the first storage unit to the second storage unit.

其中,文件系统:用于生成写指令,该写指令用于指示将所述第一存储器102中的目标数据写入至所述第二存储器103中。例如:请参考附图5和图6,图5是本申请实施例提供的一种将目标数据复制到第一存储中的示意图,图6是本申请实施例提供的一种将目标数据由第一存储器回写至第二存储器中的示意图。如图5所示,首先响应于写指令,将目标数据(如:用户数据)复制到或分配至第一存储器102中存储区域的页缓存中。如图6所示,被写入至存储区域的页缓存中的目标数据将被回写至第二存储器103中,以完成该写指令。Wherein, the file system: is used to generate a write instruction, and the write instruction is used to instruct to write the target data in the first memory 102 into the second memory 103 . For example: Please refer to accompanying drawings 5 and 6, Fig. 5 is a schematic diagram of copying target data into the first storage provided by the embodiment of the present application, and Fig. 6 is a schematic diagram of copying the target data from the first storage provided by the embodiment of the present application A schematic diagram of writing back from a memory to a second memory. As shown in FIG. 5 , firstly, in response to a write command, target data (such as: user data) is copied or allocated to the page cache of the storage area in the first memory 102 . As shown in FIG. 6 , the target data written into the page cache of the storage area will be written back into the second memory 103 to complete the write command.

写数据备份模块101:用于在写指令完成后,即,将第一存储器102中的目标数据写入至所述第二存储器103中的第一存储单元1031后,将目标数据保留在第一存储器102的备份区域中,可以避免第一存储器102中的目标数据被释放。例如:请参考附图7和附图8,图7是本申请实施例提供的一种保留数据在备份区域中的示意图,图8是本申请实施例提供的一种现有技术中释放存储区域中目标数据的示意图。如图7所示,存储区域的页缓存中的数据写入至所述存储器件后,将存储区域的页缓存中的目标数据保留至第一存储器102的备份区域的页缓存中。现有技术中,如图8所示,将所述页缓存中的数据写入至所述第一存储单元1031后,需要将存储区域中页缓存中的目标数据释放。其中,需要说明的是,此时的页缓存数据被释放是指将该页缓存中的数据擦除,以使得该页缓存可以被写入新数据。在页缓存的数据被释放前,该页缓存是不能被写入新数据的。Write data backup module 101: for after the write command is completed, that is, after the target data in the first memory 102 is written to the first storage unit 1031 in the second memory 103, keep the target data in the first In the backup area of the memory 102, the target data in the first memory 102 can be prevented from being released. For example: Please refer to accompanying drawings 7 and 8, Fig. 7 is a schematic diagram of a reserved data in the backup area provided by the embodiment of the application, and Fig. 8 is a release storage area in the prior art provided by the embodiment of the application Schematic representation of the target data in . As shown in FIG. 7 , after the data in the page cache of the storage area is written into the storage device, the target data in the page cache of the storage area is saved to the page cache of the backup area of the first memory 102 . In the prior art, as shown in FIG. 8 , after writing the data in the page cache to the first storage unit 1031 , it is necessary to release the target data in the page cache in the storage area. Wherein, it should be noted that the release of the page cache data at this time refers to erasing the data in the page cache, so that the page cache can be written with new data. Before the data in the page cache is released, the page cache cannot be written with new data.

可选的,将所述目标数据保留在所述第一存储器的备份区域中,包括:将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。第一存储器包括存储区域和备份区域,存储区域用于存储要写入第二存储器中的目标数据,备份区域用于存储该目标数据的备份数据。将被写入第二存储器中的目标数据由存储区域保存至备份区域,同时将原来存储区域中的目标数据释放(即,擦除),以使原来存储区域可以重新写入新的数据。Optionally, storing the target data in the backup area of the first memory includes: saving the target data from the storage area to the backup area, and releasing the target data. The first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. The target data to be written in the second memory is saved from the storage area to the backup area, and at the same time, the target data in the original storage area is released (that is, erased), so that the original storage area can be rewritten with new data.

可选的,将所述目标数据保留在所述第一存储器的备份区域中,包括:不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。第一存储器包括存储区域和备份区域,存储区域用于存储要写入第二存储器中的目标数据,备份区域用于存储该目标数据的备份数据。在存储区域中的目标数据写入第二存储器后,并不释放该存储区域中的数据,而是将该存储区域加入至备份区域,即,原来的存储区域变为了备份区域,不能再被重新写入新的数据。例如:如图7所示,在存储区域保存有目标数据的页缓存,该页缓存中的目标数据在写入至第一存储单元后,该页缓存会直接进入至备份区域,即变为该备份区域中的页缓存,而且该页缓存中的目标数据没有被释放。在该方案中,目标数据不需要被再次引用或复制,即可完成备份,在避免第二存储器复位后数据丢失的同时,大大节省了硬件计算资源。Optionally, storing the target data in a backup area of the first memory includes: not releasing the target data in the storage area, and adding the storage area to the backup area. The first memory includes a storage area and a backup area, the storage area is used to store target data to be written into the second memory, and the backup area is used to store backup data of the target data. After the target data in the storage area is written into the second memory, the data in the storage area is not released, but the storage area is added to the backup area, that is, the original storage area becomes the backup area and cannot be recreated. Write new data. For example: as shown in Figure 7, the page cache of the target data is stored in the storage area. After the target data in the page cache is written to the first storage unit, the page cache will directly enter the backup area, which becomes the The page cache in the backup area, and the target data in the page cache was not freed. In this solution, the target data can be backed up without being referenced or copied again, which greatly saves hardware computing resources while avoiding data loss after the second memory is reset.

需要说明的是,区分备份区域和存储区域时可以根据区域标识,区域标识用于唯一识别该区域是否是备份区域。例如针对备份区域和存储区域包括的页缓存,每个页缓存均可 包括区域标识,用于识别该页缓存是属于备份区域还是存储区域。区分备份区域和存储区域时还可以根据存储地址,预设存储地址对应的区域为备份区域。对此,本申请实施例不做具体的限定。It should be noted that, when distinguishing the backup area from the storage area, the area ID can be used to uniquely identify whether the area is a backup area. For example, for the page cache included in the backup area and the storage area, each page cache may include an area identifier, which is used to identify whether the page cache belongs to the backup area or the storage area. When distinguishing the backup area from the storage area, the area corresponding to the storage address may be preset as the backup area according to the storage address. For this, the embodiments of the present application do not make specific limitations.

还需要说明的是,另外,备份区域的具体实现方式一种可以是单独的一块存储区域,以便数据的写入;另一种还可以是备份队列或备份链表等,当存储区域中的一个或多个页缓存会被写入第二存储器后,该一个或多个页缓存可以直接进入备份队列或备份链表中,使得该一个或多个页缓存中的数据被保留在第一存储器中。It should also be noted that, in addition, one specific implementation of the backup area can be a separate storage area for data writing; the other can also be a backup queue or a backup linked list, etc., when one or After the multiple page caches are written into the second memory, the one or more page caches can directly enter the backup queue or the backup linked list, so that the data in the one or more page caches are kept in the first memory.

可选的,所述不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域包括:在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。例如:在完成针对一个或多个页缓存的写指令后,增加对该一个或多个页缓存内的引用次数,确保该一个或多个页缓存内的目标数据不被释放,即可保证上述目标数据可以在第二存储器复位后,重新写入第二存储器。需要说明的是,上述提及的存储区域当前引用次数,可以理解为,存储区域中响应了写指令的读/写最小单位(如页缓存)的当前引用次数。Optionally, the step of not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1 to the current reference count of the storage area, and adding the The storage area is added to the backup area, and the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0, the The target data in the storage area. For example: After completing the write command for one or more page caches, increase the number of references to the one or more page caches to ensure that the target data in the one or more page caches is not released, which can ensure the above The target data can be rewritten into the second memory after the second memory is reset. It should be noted that the above-mentioned current reference count of the storage area can be understood as the current reference count of the smallest read/write unit (such as page cache) in the storage area that responds to the write command.

可选的,在生成所述写指令之前,所述方法还包括:在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。在生成写指令之前,可以将第一存储器中可用于存储目标数据的所有存储区域对应的引用次数增加1,使得在存储区域中的目标数据写入通过在完成写指令后增加对存储区域内目标数据的引用次数,确保存储区域内的数据不被释放,即可保证该目标数据可以在第二存储器复位后,重新写入第二存储器。例如:将存储区域内所有页缓存中的当前引用次数增加1,确保每一个执行了写指令的页缓存中的数据在写入第二存储器后不被释放。需要说明的是,上述提及的存储区域当前引用次数,可以理解为,存储区域中每个读/写最小单位(如页缓存)的引用次数。Optionally, before generating the write instruction, the method further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate that the target data in the storage area is The number of references, wherein, when the number of references of the storage area is 0, release the target data in the storage area. Before generating the write command, the number of references corresponding to all storage areas that can be used to store the target data in the first memory can be increased by 1, so that the target data in the storage area can be written by increasing the number of references to the target in the storage area after the write command is completed. The number of data references ensures that the data in the storage area is not released, which means that the target data can be rewritten into the second memory after the second memory is reset. For example: increase the current reference times in all page caches in the storage area by 1, to ensure that the data in each page cache that executes the write instruction is not released after being written into the second memory. It should be noted that the above-mentioned current reference count of the storage area can be understood as the reference count of each read/write minimum unit (such as page cache) in the storage area.

备份区域管理模块102用于:在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。其中,该存储阈值可以是预先或默认设置,还可以是根据用户的相关管理指令设置的。当第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早被存储至备份区域的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早保留的目标数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。The backup area management module 102 is configured to: release the earliest target data stored in the backup area when the size of the data stored in the backup area exceeds a storage threshold. Wherein, the storage threshold may be set in advance or by default, and may also be set according to relevant management instructions of the user. When the size of the stored data in the backup area in the first memory exceeds the storage threshold (such as the storage size of the first storage unit), the data stored in the backup area at the earliest has been written into the second storage unit by the first storage unit, Moreover, since the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.

可选的,在所述备份区域中存储数据的大小超过存储阈值时,备份区域管理模块102可释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早添加至备份区域中的存储区域保存的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早添加至备份区域中的存储区域(即, 可以重新写入新的数据),以及该存储区域中的数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。Optionally, when the size of the data stored in the backup area exceeds the storage threshold, the backup area management module 102 may release the target storage area that entered the backup area earliest and the data in the target storage area. When the size of the stored data in the backup area in the first storage exceeds the storage threshold (such as the storage size of the first storage unit), the data stored in the storage area that was added to the backup area at the earliest has been written into the second storage unit by the first storage unit. storage unit, and since the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the storage area (that is, new data can be rewritten) and the data in the storage area added to the backup area at the earliest in the current backup area can be released, which can alleviate the storage in the first memory. Pressure, guarantee storage space in the first memory.

例如:请参考附图9和图10,图9是本申请实施例提供的一种管理备份区域的示意图,图10是本申请实施例提供的另一种管理备份区域的示意图。如图9所示,当备份区域存储的页缓存1-4中的数据大小超过存储阈值时,释放最早存储至所述备份区域页缓存1以及页缓存1中的目标数据,原有的备份区域的存储空间也随之变小。如图10所示,当备份区域存储的页缓存1-4中的数据大小超过存储阈值时,释放最早存储至所述备份区域页缓存1中的目标数据,原有的备份区域的存储空间不会变小。For example: please refer to accompanying drawings 9 and 10, FIG. 9 is a schematic diagram of a management backup area provided by the embodiment of the present application, and FIG. 10 is a schematic diagram of another management backup area provided by the embodiment of the present application. As shown in Figure 9, when the data size in the page cache 1-4 stored in the backup area exceeds the storage threshold, release the earliest target data stored in the backup area page cache 1 and page cache 1, and the original backup area The storage space is also reduced accordingly. As shown in Figure 10, when the size of the data in the page cache 1-4 stored in the backup area exceeds the storage threshold, the target data stored in the page cache 1 of the backup area earliest is released, and the storage space of the original backup area is not enough. will get smaller.

可以理解的是,备份区域中存储数据的大小超过存储阈值也相当于备份区域中可存储空间不足。It can be understood that when the size of the data stored in the backup area exceeds the storage threshold, it also corresponds to insufficient storage space in the backup area.

还可以理解的是,所述备份区域中存储数据的大小超过存储阈值时,备份区域管理模块102可按照相对应的释放策略释放进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。例如,该释放策略可以是释放距当前时间点的预设时长前进入备份区域的目标存储区域以及所述目标存储区域中的数据。It can also be understood that when the size of the data stored in the backup area exceeds the storage threshold, the backup area management module 102 may release the target storage area entering the backup area and the data in the target storage area according to the corresponding release strategy. data. For example, the release strategy may be to release the target storage area and the data in the target storage area that entered the backup area before a preset time period from the current time point.

可选的,备份区域的存储空间大于或等于所述第一存储单元的存储空间。需要说明的是,该存储空间是备份区域和第一存储单元可以保存数据的空间。第一存储器中备份区域的存储空间不小于第一存储单元中的存储空间,可以保证在第一存储单元复位后,第一存储单元中丢失的数据可以完全从备份区域内的数据中重新获取,避免了数据的丢失。而且,在备份区域的存储空间大于或等于所述第一存储单元的存储空间时,不会出现第一存储单元内的数据还未写入至第二存储单元时,备份区域对应的该数据会被删除的现象。Optionally, the storage space of the backup area is greater than or equal to the storage space of the first storage unit. It should be noted that the storage space is a space in which the backup area and the first storage unit can store data. The storage space of the backup area in the first memory is not less than the storage space in the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the data in the backup area, Data loss is avoided. Moreover, when the storage space of the backup area is greater than or equal to the storage space of the first storage unit, when the data in the first storage unit has not been written to the second storage unit, the data corresponding to the backup area will not The phenomenon of being deleted.

可选的,在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元;在所述第一存储单元中全部数据写入至所述第二存储单元后,释放所述备份区域中全部存储区域以及所述全部存储区域中的数据。当第一存储器的可存储空间(相当于存储区域)不足(内存紧张)时,可以向第二存储器件下发输出指令以使第二存储器中第一存储单元的全部数据写入至第二存储单元。全部数据被写入第二存储单元后,即可释放备份区域中全部存储区域以及全部存储区域中的数据,以缓解内存压力。例如,当第一存储器的可存储空间(相当于存储区域)不足(内存紧张)时,可以向第二存储器件下发flush命令,强行让第一存储单元1031(buffer)中的数据刷入第二存储单元1032(NAND介质),然后释放备份区域中所有数据和/或页缓存,来减轻对第一存储器的影响。Optionally, when receiving a notification that the storage space of the first memory is insufficient, an output instruction is generated, the output instruction is used to instruct writing all data in the first storage unit into the second storage unit ; After all the data in the first storage unit is written into the second storage unit, releasing all the storage areas in the backup area and the data in the all storage areas. When the storable space (equivalent to the storage area) of the first memory is insufficient (memory is tight), an output command can be issued to the second storage device to write all the data of the first storage unit in the second memory to the second storage device. unit. After all the data is written into the second storage unit, all the storage areas in the backup area and the data in all the storage areas can be released to relieve memory pressure. For example, when the storable space (equivalent to the storage area) of the first storage device is insufficient (memory shortage), a flush command can be issued to the second storage device to force the data in the first storage unit 1031 (buffer) to be flushed into the second storage device. The second storage unit 1032 (NAND media), then releases all data and/or page cache in the backup area to mitigate the impact on the first storage.

异常重发模块103用于:在第二存储器103中的第一存储单元1031发生复位的情况下,将所述备份区域1022中部分或全部数据重新写入至所述第一存储单元。即,若第二存储器出现异常问题(如:无法响应命令),在对第二存储器103复位后,将备份区域1022中的部分或全部数据重新发给第二存储器103。例如:请参考附图11,图11是本申请实施例提供的一种目标数据重新写入第二存储器中的示意图。如图11所示,当第一存储单元1031在第二存储器复位丢失全部数据后,异常重发模块103将备份区域中的部分或全部数据(页缓存1-4中的一个或多个)重新发给第一存储单元1031,使得备份区域的数据重新写入第二存储器。The abnormal resending module 103 is configured to rewrite part or all of the data in the backup area 1022 to the first storage unit when the first storage unit 1031 in the second memory 103 is reset. That is, if the second storage has an abnormal problem (such as: unable to respond to a command), after resetting the second storage 103 , resend part or all of the data in the backup area 1022 to the second storage 103 . For example: Please refer to FIG. 11 , which is a schematic diagram of rewriting target data into the second memory provided by the embodiment of the present application. As shown in Figure 11, when the first storage unit 1031 loses all the data after the second memory reset, the abnormal retransmission module 103 retransmits some or all of the data in the backup area (one or more of the page caches 1-4) The data is sent to the first storage unit 1031, so that the data in the backup area is rewritten into the second storage.

可以理解的是,图4中的处理单元101或第二存储器103的结构只是本申请实施例提供的一些示例性的实施方式,本申请实施例中的处理单元101或第二存储器103的结构包括但不仅限于以上实现方式。It can be understood that the structure of the processing unit 101 or the second memory 103 in FIG. 4 is only some exemplary implementations provided by the embodiment of the present application, and the structure of the processing unit 101 or the second memory 103 in the embodiment of the present application includes But not limited to the above implementation.

基于图3提供的系统架构,以及图4提供的数据存储装置的结构,结合本申请中提供的数据存储方法,对本申请中提出的技术问题进行具体分析和解决。Based on the system architecture provided in FIG. 3 and the structure of the data storage device provided in FIG. 4 , combined with the data storage method provided in this application, the technical problems raised in this application are specifically analyzed and resolved.

参见图12,图12是本申请实施例提供的一种数据存储方法的流程示意图,该方法可应用于上述图1中所述的系统架构中,其中的数据存储装置可以用于支持并执行图12中所示的方法流程步骤S201-步骤S205。下面将结合附图12从主机100的处理单元侧进行描述。该方法可以包括以下步骤S201-步骤S205。Referring to Fig. 12, Fig. 12 is a schematic flowchart of a data storage method provided by an embodiment of the present application, which can be applied to the system architecture described in Fig. 1 above, where the data storage device can be used to support and execute the Step S201-Step S205 of the method flow shown in 12. The following will describe from the processing unit side of the host 100 with reference to FIG. 12 . The method may include the following steps S201-S205.

步骤S201:生成写指令。Step S201: Generate a write instruction.

具体地,数据存储装置生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中。在电子设备中的如文件系统,处理装置在运行过程中,若需要将第一存储器中的数据保存至第二存储器中时,可以生成写指令指示将所述第一存储器中的目标数据写入至所述第二存储器中。Specifically, the data storage device generates a write instruction, where the write instruction is used to instruct to write the target data in the first memory into the second memory. In an electronic device such as a file system, when the processing device needs to save the data in the first memory to the second memory during operation, it can generate a write instruction to instruct to write the target data in the first memory to the second memory.

步骤S202:基于写指令将目标数据写入至第一存储单元后,将目标数据保留在第一存储器的备份区域中。Step S202: After writing the target data into the first storage unit based on the write command, keep the target data in the backup area of the first storage.

具体地,数据存储装置基于写指令将目标数据写入至第一存储单元后,将目标数据保留在第一存储器的备份区域中。其中,第一存储单元为第二存储器中的易失性存储单元,因为,为了防止第二存储器复位后,第一存储单元中的数据丢失,可以将目标数据写入至第一存储单元后,将目标数据保留在第一存储器的备份区域中。Specifically, after the data storage device writes the target data into the first storage unit based on the write command, the target data is retained in the backup area of the first memory. Wherein, the first storage unit is a volatile storage unit in the second memory, because, in order to prevent the data in the first storage unit from being lost after the second memory is reset, after the target data can be written into the first storage unit, The target data is retained in the backup area of the first memory.

可选的,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。数据存储装置将所述目标数据保留在所述第一存储器的备份区域中有两种方案,其中一种方式是将被写入第二存储器中的目标数据由存储区域保存至备份区域,同时将原来存储区域中的目标数据释放(即,擦除),以使原来存储区域可以重新写入新的数据。即,将原来第一存储器中的一个区域A的数据转移到(例如:可以通过写入、复制等方式。)另一个区域B保存,转移后,原来区域A中的数据将会被删除。需要说明的是,在该方式中,第一存储器中存储区域所对应的存储空间与备份区域所对应的存储空间最多能存储数据的大小不会发生变化。例如:存储区域所对应的存储空间与备份区域所对应的存储空间均最多存储100M大小的数据。Optionally, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the backup area of the first memory includes : saving the target data from the storage area to the backup area, and releasing the target data in the storage area. There are two schemes for the data storage device to retain the target data in the backup area of the first memory, one of which is to save the target data written in the second memory from the storage area to the backup area, and at the same time The target data in the original storage area is released (ie, erased), so that the original storage area can be rewritten with new data. That is, transfer (for example: by writing, copying, etc.) the data of an area A in the original first storage to another area B for storage, after the transfer, the data in the original area A will be deleted. It should be noted that, in this manner, the storage space corresponding to the storage area in the first storage and the storage space corresponding to the backup area do not change at most the size of the data that can be stored. For example: the storage space corresponding to the storage area and the storage space corresponding to the backup area both store data with a maximum size of 100M.

可选的,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。数据存储装置将所述目标数据保留在所述第一存储器的备份区域中有两种方案,其中另一种方式是将该存储区域加入至备份区域,不释放该存储区域中的数据,即,将原来的存储区域变为了备份区域,该原来的存储区域也不能再被重新写入新的数据。另外,该存储区域变为备份区域的 方式本申请不做限制。例如:可以将存储区域的区域标识由存储区域改为备份区域,该区域标识用于唯一识别该区域是否是备份区域;可以将该存储区域所对应的存储空间重新划分为备份区域所对应的存储空间,存储区域所在的存储空间会因此减小,备份区域所在的存储空间会随之增大。Optionally, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the backup area of the first memory includes : Do not release the target data in the storage area, and add the storage area to the backup area. There are two schemes for the data storage device to retain the target data in the backup area of the first memory, and the other way is to add the storage area to the backup area without releasing the data in the storage area, that is, The original storage area is changed into a backup area, and the original storage area cannot be rewritten with new data. In addition, this application does not limit how the storage area becomes the backup area. For example: the area identification of the storage area can be changed from the storage area to the backup area, and the area identification is used to uniquely identify whether the area is a backup area; the storage space corresponding to the storage area can be re-divided into the storage area corresponding to the backup area Therefore, the storage space where the storage area is located will decrease, and the storage space where the backup area is located will increase accordingly.

可选的,所述不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域包括:在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。数据存储装置通过在完成写指令后增加对存储区域内目标数据的引用次数,确保存储区域内的数据不被释放,即可保证该目标数据保留在第一存储器的备份区域中。该引用次数用于指示所述存储区域中的所述目标数据被相关指令(如:写指令)引用的次数。Optionally, the step of not releasing the target data in the storage area, and adding the storage area to the backup area includes: adding 1 to the current reference count of the storage area, and adding the The storage area is added to the backup area, and the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0, the The target data in the storage area. The data storage device ensures that the data in the storage area is not released by increasing the number of references to the target data in the storage area after completing the write command, that is, the target data remains in the backup area of the first memory. The number of references is used to indicate the number of times the target data in the storage area is referenced by related instructions (eg, write instructions).

可选的,在生成所述写指令之前,所述方法还包括:在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。数据存储装置若在完成写指令之后不增加存储区域的引用次数,则可以在生成写指令之前,将第一存储器中可用于存储目标数据的所有存储区域对应的引用次数增加1,使得在存储区域中的目标数据写入通过在完成写指令后增加对存储区域内目标数据的引用次数,确保存储区域内的数据不被释放,即可保证该目标数据可以在第二存储器复位后,重新写入第二存储器。Optionally, before generating the write instruction, the method further includes: adding 1 to the current reference count of the storage area, where the reference count is used to indicate that the target data in the storage area is The number of references, wherein, when the number of references of the storage area is 0, release the target data in the storage area. If the data storage device does not increase the number of references of the storage area after completing the write command, before generating the write command, the number of references corresponding to all storage areas in the first memory that can be used to store the target data is increased by 1, so that in the storage area The writing of the target data in the storage area ensures that the data in the storage area will not be released by increasing the number of references to the target data in the storage area after the completion of the write command, so that the target data can be rewritten after the second memory is reset. Second storage.

可选的,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。第一存储器中备份区域的存储空间不小于第一存储单元中的存储空间,可以保证在第一存储单元复位后,第一存储单元中丢失的数据可以完全从备份区域内的数据中重新获取,避免了数据的丢失。Optionally, the storage space of the backup area is greater than or equal to the storage space of the first storage unit. The storage space of the backup area in the first memory is not less than the storage space in the first storage unit, which can ensure that after the first storage unit is reset, the lost data in the first storage unit can be completely retrieved from the data in the backup area, Data loss is avoided.

可选的,在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。其中,该存储阈值可以是预先或默认设置,还是根据用户的相关管理指令设置的第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早被存储至备份区域的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早保留的目标数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。Optionally, when the size of the data stored in the backup area exceeds a storage threshold, the earliest target data stored in the backup area is released. Wherein, the storage threshold can be set in advance or by default, or when the size of the stored data in the backup area in the first memory set according to the relevant management instructions of the user exceeds the storage threshold (such as the storage size of the first storage unit), it will be stored at the earliest The data to the backup area has been written into the second storage unit by the first storage unit, and since the second storage unit is a non-volatile storage unit, even when the second storage is reset, the data will not be lost. Therefore, when the storage threshold is exceeded, the earliest reserved target data in the current backup area can be released, which can alleviate the storage pressure in the first storage and ensure the storage space in the first storage.

可选的,在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。第一存储器中备份区域的存储数据的大小超过存储阈值(如第一存储单元的存储大小)时,最早添加至备份区域中的存储区域保存的数据,已经被第一存储单元写入至第二存储单元,而且由于第二存储单元为非易失性存储单元,即使在第二存储器发生复位时,也不会丢失数据。因此,在超过存储阈值时,释放当前备份区域中最早添加至备份区域中的存储区域(即,可以重新写入新的数据),以及该存储区域中的数据,可以缓解第一存储器中的存储压力,保证第一存储器中的存储空间。Optionally, when the size of the data stored in the backup area exceeds the storage threshold, release the target storage area that entered the backup area earliest and the data in the target storage area. When the size of the stored data in the backup area in the first storage exceeds the storage threshold (such as the storage size of the first storage unit), the data stored in the storage area that was added to the backup area at the earliest has been written into the second storage unit by the first storage unit. storage unit, and since the second storage unit is a non-volatile storage unit, data will not be lost even when the second storage unit is reset. Therefore, when the storage threshold is exceeded, the storage area (that is, new data can be re-written) and the data in the storage area that was added to the backup area in the current backup area at the earliest can be released, which can alleviate the storage in the first storage area. Pressure, guarantee storage space in the first memory.

步骤S203:当第二存储器中的第一存储单元发生复位的情况下,将备份区域中部分或全部数据重新写入至第一存储单元。Step S203: When the first storage unit in the second memory is reset, rewrite part or all of the data in the backup area to the first storage unit.

具体地,当所述第二存储器中的所述第一存储单元发生复位的情况下,数据存储装置将所述备份区域中部分或全部数据重新写入至所述第一存储单元。其中,在获取到第一存储单元丢失数据是哪些的情况下,可以发送丢失部分的数据,在不能确定第一存储单元丢失数据是哪些的情况下,可以发送备份区域中部分或全部数据,以避免数据丢失。Specifically, when the first storage unit in the second memory is reset, the data storage device rewrites part or all of the data in the backup area to the first storage unit. Wherein, in the case of obtaining the lost data of the first storage unit, the lost part of the data can be sent, and in the case of being unable to determine the lost data of the first storage unit, part or all of the data in the backup area can be sent to Avoid data loss.

可选的,数据存储装置将写入至所述第一存储单元中的数据写入至所述第二存储单元中。第二存储器中的第一存储单元为易失性存储单元,第二存储单元为非易失性存储单元,为了保存数据,需要将第一存储单元中的数据写入至所述第二存储单元中。Optionally, the data storage device writes the data written into the first storage unit into the second storage unit. The first storage unit in the second memory is a volatile storage unit, and the second storage unit is a non-volatile storage unit. In order to save data, the data in the first storage unit needs to be written into the second storage unit. middle.

步骤S204:在接收到第一存储器的可存储空间不足的通知时,生成输出指令。Step S204: When receiving a notification that the storage space of the first memory is insufficient, generate an output instruction.

具体地,数据存储装置在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元,例如,该输出指令可以是向第二存储器件下发的flush命令。Specifically, when the data storage device receives the notification that the storage space of the first memory is insufficient, it generates an output instruction, and the output instruction is used to instruct to write all the data in the first storage unit into the second storage unit. For the storage unit, for example, the output instruction may be a flush command delivered to the second storage device.

步骤S205:在第一存储单元中全部数据写入至所述第二存储单元后,释放备份区域中全部存储区域以及全部存储区域中的数据。Step S205: After all data in the first storage unit is written into the second storage unit, release all storage areas in the backup area and data in all storage areas.

具体地,数据存储装置在第一存储单元中全部数据写入至所述第二存储单元后,释放备份区域中全部存储区域以及全部存储区域中的数据。为了缓解电子设备中的存储压力,在数据全部被保存至非易失性存储单元中后,可以释放备份区域中全部存储区域以及全部存储区域中的数据。Specifically, after all data in the first storage unit is written into the second storage unit, the data storage device releases all storage areas in the backup area and data in all storage areas. In order to alleviate the storage pressure in the electronic device, after all the data is stored in the non-volatile storage unit, all the storage areas in the backup area and the data in all the storage areas can be released.

可选的,数据存储装置在第一存储单元中全部数据写入至所述第二存储单元后,释放备份区域中全部存储区域以及全部存储区域中的数据。Optionally, after all data in the first storage unit is written into the second storage unit, the data storage device releases all storage areas in the backup area and data in all storage areas.

本申请在进行数据存储时,在数据写入第二存储器后,将原来需要被擦除的数据保存至第一存储器的备份区域中。在第二存储器发生复位的情况下(此时,易失性存储单元,即,第一存储单元中的数据在复位时会丢失),重新将备份区域中的部分或全部数据发送至第二存储器(将数据重新写入至第一存储单元),这样可以避免第二存储器复位后,第一存储单元中的数据丢失。而且,该重新发送备份区域的数据可以保持在异常恢复后的元数据的一致性,避免用户实际文件数据的丢失。另外,该方法不需要重新启动电子设备,大大提升了用户体验。When storing data in the present application, after the data is written into the second memory, the data that needs to be erased is saved in the backup area of the first memory. In the case of a reset of the second memory (at this time, the volatile memory unit, that is, the data in the first memory unit will be lost when reset), resend part or all of the data in the backup area to the second memory (rewriting the data to the first storage unit), which can prevent the data in the first storage unit from being lost after the second memory is reset. Moreover, the resending of the data in the backup area can maintain the consistency of the metadata after the abnormal recovery, avoiding the loss of the user's actual file data. In addition, the method does not need to restart the electronic device, which greatly improves user experience.

需要说明的是,本申请实施例中所描述的数据存储方法中步骤S201-步骤S205的相关描述可参见上述图4中所述的装置实施例中各功能单元的相关描述,此处不再赘述。It should be noted that, for the relevant descriptions of steps S201 to S205 in the data storage method described in the embodiment of the present application, please refer to the relevant descriptions of each functional unit in the device embodiment described in FIG. 4 above, and will not be repeated here. .

上述详细阐述了本申请实施例的方法,下面提供了本申请实施例的相关设备。The method of the embodiment of the present application has been described in detail above, and the related equipment of the embodiment of the present application is provided below.

请参见图13,图13是本申请实施例提供的一种数据存储计装置的结构示意图,该数据存储装置10应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;该数据存储装置10可以包括生成单元301,备份单元302,第一写入单元303和第二写入单元304;还可以包括:引用管理单元305,第一释放单元306,第二释放单元307,输出单元308和第三释放单元 309。其中,各个单元的详细描述如下。Please refer to FIG. 13. FIG. 13 is a schematic structural diagram of a data storage device provided by an embodiment of the present application. The data storage device 10 is applied to an electronic device, and the electronic device includes a first memory and a second memory. The first The second storage unit includes a first storage unit and a second storage unit, the first storage unit is a volatile storage unit, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit ; The data storage device 10 may include a generating unit 301, a backup unit 302, a first writing unit 303 and a second writing unit 304; may also include: a reference management unit 305, a first releasing unit 306, and a second releasing unit 307 , the output unit 308 and the third release unit 309 . Wherein, the detailed description of each unit is as follows.

生成单元301,用于生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中;a generating unit 301, configured to generate a write instruction, where the write instruction is used to instruct writing target data in the first memory into the second memory;

备份单元302,用于基于所述写指令将所述目标数据写入至所述第一存储单元后,将所述目标数据保留在所述第一存储器的备份区域中;a backup unit 302, configured to retain the target data in a backup area of the first memory after the target data is written into the first storage unit based on the write instruction;

第一写入单元303,用于当所述第二存储器中的所述第一存储单元发生复位的情况下,将所述备份区域中部分或全部数据重新写入至所述第一存储单元;The first writing unit 303 is configured to rewrite part or all of the data in the backup area to the first storage unit when the first storage unit in the second memory is reset;

第二写入单元304,用于将写入至所述第一存储单元中的数据写入至所述第二存储单元中。The second writing unit 304 is configured to write the data written in the first storage unit into the second storage unit.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元302,具体用于:将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit 302 is specifically configured to: store the target data saving from the storage area to the backup area, and releasing the target data in the storage area.

在一种可能实现的方式中,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元302,具体用于:不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。In a possible implementation manner, the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit 302 is specifically configured to: not release the storage the target data in the region and add the storage region to the backup region.

在一种可能实现的方式中,所述备份单元302,具体用于:在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。In a possible implementation manner, the backup unit 302 is specifically configured to: add 1 to the current reference count of the storage area, and add the storage area to the backup area, and the reference The count is used to indicate the number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.

在一种可能实现的方式中,所述装置还包括:引用管理单元305,用于在生成所述写指令之前,在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。In a possible implementation manner, the device further includes: a reference management unit 305, configured to add 1 to the current reference count of the storage area before generating the write instruction, and the reference count is used for Indicates the number of times the target data in the storage area is referenced, wherein when the number of references in the storage area is 0, the target data in the storage area is released.

在一种可能实现的方式中,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。In a possible implementation manner, the storage space of the backup area is greater than or equal to the storage space of the first storage unit.

在一种可能实现的方式中,所述装置装置还包括:第一释放单元306,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。In a possible implementation manner, the device further includes: a first release unit 306, configured to release the earliest target data stored in the backup area when the size of the data stored in the backup area exceeds a storage threshold .

在一种可能实现的方式中,所述装置还包括:第二释放单元307,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。In a possible implementation manner, the device further includes: a second release unit 307, configured to release the target storage area that entered the backup area the earliest when the size of the data stored in the backup area exceeds a storage threshold; data in the target storage area.

在一种可能实现的方式中,所述装置还包括:输出单元308,用于在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元;第三释放单元309,用于在所述第一存储单元中全部数据写入至所述第二存储单元后,释放所述备份区域中全部存储区域以及所述全部存储区域中的数据。In a possible implementation manner, the device further includes: an output unit 308, configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to indicate that the All data in the first storage unit is written into the second storage unit; a third releasing unit 309 is configured to release the All the storage areas in the backup area and the data in the all storage areas.

需要说明的是,上述多个单元的划分仅是一种根据功能进行的逻辑划分,不作为对数据存储装置10具体的结构的限定。在具体实现中,其中部分功能模块可能被细分为更多细小的功能模块,部分功能模块也可能组合成一个功能模块,但无论这些功能模块是进行了 细分还是组合,装置10在对数据存储的过程中所执行的大致流程是相同的。通常,每个单元都对应有各自的程序代码(或者说程序指令),这些单元各自对应的程序代码在相关硬件装置上运行时,使得该单元执行相应的流程从而实现相应功能。另外,每个单元的功能还可以通过相关的硬件实现。It should be noted that the division of the above multiple units is only a logical division based on functions, and is not intended to limit the specific structure of the data storage device 10 . In a specific implementation, some of the functional modules may be subdivided into more smaller functional modules, and some of the functional modules may also be combined into one functional module, but no matter whether these functional modules are subdivided or combined, the device 10 is The general flow of execution in stored procedures is the same. Usually, each unit corresponds to its own program code (or program instruction), and when the program code corresponding to each unit runs on a related hardware device, the unit executes a corresponding process to realize a corresponding function. In addition, the functions of each unit can also be realized by related hardware.

还需要说明的是,本申请实施例中所描述的数据存储装置10中各功能单元的功能可参见上述图12中所述的方法实施例中步骤S201-步骤S205以及上述图4中所述的装置实施例中各个模块的相关描述,此处不再赘述。It should also be noted that, the functions of each functional unit in the data storage device 10 described in the embodiment of the present application can refer to steps S201-step S205 in the method embodiment described in FIG. 12 and the above described in FIG. 4 The related description of each module in the device embodiment will not be repeated here.

在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其他实施例的相关描述。In the foregoing embodiments, the descriptions of each embodiment have their own emphases, and for parts not described in detail in a certain embodiment, reference may be made to relevant descriptions of other embodiments.

需要说明的是,对于前述的各方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可能可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本申请所必须的。It should be noted that for the foregoing method embodiments, for the sake of simple description, they are expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited by the described action sequence. Depending on the application, certain steps may be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification belong to preferred embodiments, and the actions and modules involved are not necessarily required by this application.

在本申请所提供的几个实施例中,应该理解到,所揭露的装置,可通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如上述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the above units is only a logical function division. In actual implementation, there may be other division methods, for example, multiple units or components can be combined or integrated. to another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical or other forms.

上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

另外,在本申请各实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

上述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以为个人计算机、服务端或者网络设备等,具体可以是计算机设备中的处理器)执行本申请各个实施例上述方法的全部或部分步骤。其中,而前述的存储介质可包括:U盘、移动硬盘、磁碟、光盘、只读存储器(Read-Only Memory,缩写:ROM)或者随机存取存储器(Random Access Memory,缩写:RAM)等各种可以存储程序代码的介质。If the above integrated units are realized in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or part of the contribution to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions to make a computer device (which may be a personal computer, server or network device, etc., specifically, a processor in the computer device) execute all or part of the steps of the above-mentioned methods in various embodiments of the present application. Wherein, the aforementioned storage medium may include: U disk, mobile hard disk, magnetic disk, optical disc, read-only memory (Read-Only Memory, abbreviated: ROM) or random access memory (Random Access Memory, abbreviated: RAM) and the like. A medium that can store program code.

以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: it can still understand the foregoing The technical solutions recorded in each embodiment are modified, or some of the technical features are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the application.

Claims (22)

一种数据存储方法,其特征在于,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述方法包括:A data storage method, characterized in that it is applied to an electronic device, the electronic device includes a first memory and a second memory, the second memory includes a first storage unit and a second storage unit, and the first memory is Volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the method includes: 生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中;generating a write instruction, where the write instruction is used to instruct to write target data in the first memory into the second memory; 基于所述写指令将所述目标数据写入至所述第一存储单元后,将所述目标数据保留在所述第一存储器的备份区域中;after writing the target data into the first storage unit based on the write instruction, retaining the target data in a backup area of the first memory; 当所述第二存储器中的所述第一存储单元发生复位的情况下,将所述备份区域中部分或全部数据重新写入至所述第一存储单元;When the first storage unit in the second memory is reset, rewrite part or all of the data in the backup area to the first storage unit; 将写入至所述第一存储单元中的数据写入至所述第二存储单元中。writing the data written into the first storage unit into the second storage unit. 根据权利要求1所述方法,其特征在于,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:The method according to claim 1, wherein the first storage includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the second A backup area of a memory, including: 将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。saving the target data from the storage area to the backup area, and releasing the target data in the storage area. 根据权利要求1所述方法,其特征在于,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述将所述目标数据保留在所述第一存储器的备份区域中,包括:The method according to claim 1, wherein the first storage includes a storage area and the backup area, the storage area is used to store the target data; the keeping the target data in the second A backup area of a memory, including: 不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。The target data in the storage area is not released, and the storage area is added to the backup area. 根据权利要求3所述方法,其特征在于,所述不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域包括:The method according to claim 3, wherein the step of not releasing the target data in the storage area and adding the storage area to the backup area comprises: 在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。adding 1 to the current reference count of the storage area, and adding the storage area to the backup area, the reference count is used to indicate the number of times the target data in the storage area is referenced, Wherein, when the reference count of the storage area is 0, release the target data in the storage area. 根据权利要求3所述方法,其特征在于,在生成所述写指令之前,所述方法还包括:The method according to claim 3, wherein, before generating the write instruction, the method further comprises: 在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。Add 1 on the basis of the current reference count of the storage area, the reference count is used to indicate the number of times the target data in the storage area is referenced, wherein, when the reference count of the storage area is 0, releasing the target data in the storage area. 根据权利要求1-5所述任意一项方法,其特征在于,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。The method according to any one of claims 1-5, wherein the storage space of the backup area is greater than or equal to the storage space of the first storage unit. 根据权利要求2所述方法,其特征在于,所述方法还包括:The method according to claim 2, wherein the method further comprises: 在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。When the size of data stored in the backup area exceeds a storage threshold, release the earliest target data stored in the backup area. 根据权利要求3所述方法,其特征在于,所述方法还包括:The method according to claim 3, wherein the method further comprises: 在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。When the size of the data stored in the backup area exceeds the storage threshold, release the target storage area that first entered the backup area and the data in the target storage area. 根据权利要求1所述方法,其特征在于,所述方法还包括:The method according to claim 1, wherein the method further comprises: 在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元。When receiving the notification that the storable space of the first memory is insufficient, an output instruction is generated, where the output instruction is used to instruct to write all the data in the first storage unit into the second storage unit. 一种数据存储装置,其特征在于,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述装置包括:A data storage device, characterized in that it is applied to electronic equipment, the electronic equipment includes a first memory and a second memory, the second memory includes a first storage unit and a second storage unit, and the first memory is Volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the device includes: 生成单元,用于生成写指令,所述写指令用于指示将所述第一存储器中的目标数据写入至所述第二存储器中;a generating unit, configured to generate a write instruction, where the write instruction is used to instruct to write target data in the first memory into the second memory; 备份单元,用于基于所述写指令将所述目标数据写入至所述第一存储单元后,将所述目标数据保留在所述第一存储器的备份区域中;a backup unit, configured to retain the target data in a backup area of the first memory after the target data is written into the first storage unit based on the write instruction; 第一写入单元,用于当所述第二存储器中的所述第一存储单元发生复位的情况下,将所述备份区域中部分或全部数据重新写入至所述第一存储单元;a first writing unit, configured to rewrite part or all of the data in the backup area to the first storage unit when the first storage unit in the second memory is reset; 第二写入单元,用于将写入至所述第一存储单元中的数据写入至所述第二存储单元中。The second writing unit is used for writing the data written in the first storage unit into the second storage unit. 根据权利要求10所述装置,其特征在于,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元,具体用于:The device according to claim 10, wherein the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically used for: 将所述目标数据由所述存储区域保存至所述备份区域,并释放所述存储区域中的所述目标数据。saving the target data from the storage area to the backup area, and releasing the target data in the storage area. 根据权利要求10所述装置,其特征在于,所述第一存储器包括存储区域和所述备份区域,所述存储区域用于存储所述目标数据;所述备份单元,具体用于:The device according to claim 10, wherein the first memory includes a storage area and the backup area, the storage area is used to store the target data; the backup unit is specifically used for: 不释放所述存储区域中的所述目标数据,并将所述存储区域添加至所述备份区域。The target data in the storage area is not released, and the storage area is added to the backup area. 根据权利要求12所述装置,其特征在于,所述备份单元,具体用于:The device according to claim 12, wherein the backup unit is specifically used for: 在所述存储区域当前引用次数的基础上增加1,并将所述存储区域添加至所述备份区域中,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。adding 1 to the current reference count of the storage area, and adding the storage area to the backup area, the reference count is used to indicate the number of times the target data in the storage area is referenced, Wherein, when the reference count of the storage area is 0, release the target data in the storage area. 根据权利要求12所述装置,其特征在于,所述装置还包括:The device according to claim 12, wherein the device further comprises: 引用管理单元,用于在生成所述写指令之前,在所述存储区域当前引用次数的基础上增加1,所述引用计数用于指示所述存储区域中的所述目标数据被引用的次数,其中,当所述存储区域的引用次数为0时,释放所述存储区域中的所述目标数据。a reference management unit, configured to add 1 to the current reference count of the storage area before generating the write instruction, the reference count is used to indicate the number of times the target data in the storage area is referenced, Wherein, when the reference count of the storage area is 0, release the target data in the storage area. 根据权利要求10-14所述任意一项装置,其特征在于,所述备份区域的存储空间大于或等于所述第一存储单元的存储空间。The device according to any one of claims 10-14, wherein the storage space of the backup area is greater than or equal to the storage space of the first storage unit. 根据权利要求11所述装置,其特征在于,所述装置装置还包括:The device according to claim 11, wherein the device device further comprises: 第一释放单元,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早存储至所述备份区域的目标数据。The first release unit is configured to release the earliest target data stored in the backup area when the size of the data stored in the backup area exceeds a storage threshold. 根据权利要求12所述装置,其特征在于,所述装置还包括:The device according to claim 12, wherein the device further comprises: 第二释放单元,用于在所述备份区域中存储数据的大小超过存储阈值时,释放最早进入所述备份区域的目标存储区域以及所述目标存储区域中的数据。The second release unit is configured to release the target storage area that entered the backup area earliest and the data in the target storage area when the size of the data stored in the backup area exceeds a storage threshold. 根据权利要求10所述装置,其特征在于,所述装置还包括:The device according to claim 10, wherein the device further comprises: 输出单元,用于在接收到所述第一存储器的可存储空间不足的通知时,生成输出指令,所述输出指令用于指示将所述第一存储单元中全部数据写入所述第二存储单元;an output unit, configured to generate an output instruction when receiving a notification that the storage space of the first memory is insufficient, and the output instruction is used to instruct writing all data in the first storage unit into the second storage unit; 第三释放单元,用于在所述第一存储单元中全部数据写入至所述第二存储单元后,释放所述备份区域中全部存储区域以及所述全部存储区域中的数据。The third release unit is configured to release all the storage areas in the backup area and the data in the all storage areas after all the data in the first storage unit is written into the second storage unit. 一种数据存储装置,其特征在于,应用于电子设备,所述电子设备包括第一存储器和第二存储器,所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;所述装置包括处理器,所述处理器用于执行如权利要求1-9所述的任意一项方法。A data storage device, characterized in that it is applied to electronic equipment, the electronic equipment includes a first memory and a second memory, the second memory includes a first storage unit and a second storage unit, and the first memory is A volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; the device includes a processor, and the processor is used to perform the following claims 1- Any one of the methods described in 9. 一种电子设备,所述电子设备包括处理器、第一存储器和第二存储器,所述处理器与所述第一存储器和所述第二存储器耦合;所述第二存储器包括第一存储单元、第二存储单元,所述第一存储器为易失性存储器,所述第一存储单元为易失性存储单元,所述第二存储单元为非易失性存储单元;其中,所述处理器用于调用所述电子设备存储的程序代码使得所述电子设备执行如权利要求1-9所述的任意一项方法。An electronic device, the electronic device includes a processor, a first memory, and a second memory, the processor is coupled to the first memory and the second memory; the second memory includes a first storage unit, A second storage unit, the first memory is a volatile memory, the first storage unit is a volatile storage unit, and the second storage unit is a non-volatile storage unit; wherein the processor is used for Invoking the program code stored in the electronic device causes the electronic device to execute any one of the methods described in claims 1-9. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,该计算机程序被处理器执行时实现上述权利要求1-9任意一项所述的方法。A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of claims 1-9 above is implemented. 一种计算机程序,其特征在于,所述计算机程序包括指令,当所述计算机程序被计算机执行时,使得所述计算机执行如权利要求1-9中任意一项所述的方法。A computer program, characterized in that the computer program includes instructions, and when the computer program is executed by a computer, it causes the computer to perform the method according to any one of claims 1-9.
PCT/CN2021/100100 2021-06-15 2021-06-15 Data storage method and related device Ceased WO2022261823A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202180099157.2A CN117501247A (en) 2021-06-15 2021-06-15 A data storage method and related equipment
PCT/CN2021/100100 WO2022261823A1 (en) 2021-06-15 2021-06-15 Data storage method and related device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2021/100100 WO2022261823A1 (en) 2021-06-15 2021-06-15 Data storage method and related device

Publications (1)

Publication Number Publication Date
WO2022261823A1 true WO2022261823A1 (en) 2022-12-22

Family

ID=84526769

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/100100 Ceased WO2022261823A1 (en) 2021-06-15 2021-06-15 Data storage method and related device

Country Status (2)

Country Link
CN (1) CN117501247A (en)
WO (1) WO2022261823A1 (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1677571A (en) * 2004-03-12 2005-10-05 株式会社瑞萨科技 Nonvolatile memory apparatus
CN1783025A (en) * 2004-12-03 2006-06-07 华为技术有限公司 Embedded system data back-up device and method
CN101101533A (en) * 2006-07-06 2008-01-09 奇梦达北美公司 Method for accessing a non-volatile memory via a volatile memory interface
CN101216789A (en) * 2008-01-08 2008-07-09 福建星网锐捷网络有限公司 Data update method, device and system
US20100299513A1 (en) * 2009-05-22 2010-11-25 Samsung Electronics Co., Ltd. Memory apparatus and method therefor
CN102314321A (en) * 2010-07-07 2012-01-11 深圳市朗科科技股份有限公司 Storage system and method and device for accessing data by using same

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1677571A (en) * 2004-03-12 2005-10-05 株式会社瑞萨科技 Nonvolatile memory apparatus
CN1783025A (en) * 2004-12-03 2006-06-07 华为技术有限公司 Embedded system data back-up device and method
CN101101533A (en) * 2006-07-06 2008-01-09 奇梦达北美公司 Method for accessing a non-volatile memory via a volatile memory interface
CN101216789A (en) * 2008-01-08 2008-07-09 福建星网锐捷网络有限公司 Data update method, device and system
US20100299513A1 (en) * 2009-05-22 2010-11-25 Samsung Electronics Co., Ltd. Memory apparatus and method therefor
CN102314321A (en) * 2010-07-07 2012-01-11 深圳市朗科科技股份有限公司 Storage system and method and device for accessing data by using same

Also Published As

Publication number Publication date
CN117501247A (en) 2024-02-02

Similar Documents

Publication Publication Date Title
TWI385523B (en) Data backup method for a flash memory and controller and storage system using the same
US10956323B2 (en) NVDIMM emulation using a host memory buffer
US11210020B2 (en) Methods and systems for accessing a memory
US20140095555A1 (en) File management device and method for storage system
US20130013853A1 (en) Command executing method, memory controller and memory storage apparatus
TW201237624A (en) Two-level system main memory
US20190042460A1 (en) Method and apparatus to accelerate shutdown and startup of a solid-state drive
CN109885253B (en) Atomic cross-media writes on storage devices
CN112130749B (en) Data storage device and non-volatile memory control method
CN112286838A (en) Storage device configurable mapping granularity system
CN116888585A (en) Cache-based streaming for simple copy commands
CN114637694A (en) Logical-to-physical address indirection table in persistent memory in solid state drives
TWI454922B (en) Memory storage device and memory controller and data writing method thereof
CN111752858A (en) Controller, memory system and method of operation
CN107861884B (en) Method for improving cross-page memory address mapping efficiency in NAND flash memory
US10642531B2 (en) Atomic write method for multi-transaction
CN111459400B (en) Method and apparatus for pipeline-based access management in storage servers
US20210333996A1 (en) Data Parking for SSDs with Streams
US10606488B2 (en) Selective data flush in a storage device
US20230137039A1 (en) Reduce Command Latency Using Block Pre-Erase
WO2022261823A1 (en) Data storage method and related device
US12045506B2 (en) Combining operations during reset
CN117642716A (en) Lost recovery from HMB
CN109002265B (en) Data processing method and related device
KR101939361B1 (en) Method for logging using non-volatile memory

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21945416

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 202180099157.2

Country of ref document: CN

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21945416

Country of ref document: EP

Kind code of ref document: A1