











技术领域technical field
本申请涉及存储技术领域,更具体地,涉及一种数据存储方法、装置、电子设备和可读存储介质。The present application relates to the field of storage technologies, and more particularly, to a data storage method, apparatus, electronic device, and readable storage medium.
背景技术Background technique
在计算机系统中,文件系统用于控制数据如何被存储和被取回,即程序加载以及数据存取等都需要文件系统的支持,因而文件系统性能尤为重要。目前常见的文件系统包括磁盘文件系统、网络文件系统和专用文件系统等,每个文件系统可以具有不同的结构和逻辑、速度性质、灵活性、安全性以及大小等。如何在保证文件系统一致性和持久性的前提下,减少文件系统的使用延迟为本领域亟待解决的技术问题之一。In a computer system, the file system is used to control how data is stored and retrieved, that is, program loading and data access require the support of the file system, so the performance of the file system is particularly important. Currently common file systems include disk file systems, network file systems, and dedicated file systems. Each file system can have different structures and logics, speed properties, flexibility, security, and size. How to reduce the usage delay of the file system on the premise of ensuring the consistency and durability of the file system is one of the technical problems to be solved urgently in the field.
发明内容SUMMARY OF THE INVENTION
本申请提出了一种数据存储方法、装置、电子设备和可读存储介质,以改善上述缺陷。The present application proposes a data storage method, apparatus, electronic device and readable storage medium to improve the above-mentioned defects.
第一方面,本申请实施例提供了一种数据存储方法,应用于电子设备,所述电子设备包括缓冲器,包括:检测是否获取到刷新信息,所述刷新信息用于指示所述缓冲器被写入元数据或所述电子设备发生异常的至少一种;如果获取到刷新信息,则根据所述刷新信息将所述缓冲器上的数据写入至存储器上。In a first aspect, an embodiment of the present application provides a data storage method, which is applied to an electronic device, where the electronic device includes a buffer, including: detecting whether refresh information is acquired, the refresh information being used to indicate that the buffer is Write at least one of metadata or an abnormality in the electronic device; if refresh information is obtained, write the data on the buffer to the memory according to the refresh information.
第二方面,本申请实施例还提供了一种数据存储装置,应用于电子设备,所述电子设备包括缓冲器,所述装置包括:信息检测模块,用于检测是否获取到刷新信息,所述刷新信息用于指示所述缓冲器被写入元数据或所述电子设备发生异常的至少一种;数据存储模块,用于如果获取到刷新信息,则根据所述刷新信息将所述缓冲器上的数据写入至存储器上。In a second aspect, an embodiment of the present application further provides a data storage device, which is applied to an electronic device, where the electronic device includes a buffer, and the device includes: an information detection module for detecting whether refresh information is acquired, the The refresh information is used to indicate at least one of metadata being written to the buffer or the electronic device is abnormal; the data storage module is used to store the buffer on the buffer according to the refresh information if the refresh information is obtained. data is written to the memory.
第三方面,本申请实施例还提供了一种电子设备,包括一个或多个处理器;存储器;一个或多个应用程序,其中所述一个或多个应用程序被存储在所述存储器中并被配置为由所述一个或多个处理器执行,所述一个或多个程序配置用于执行上述方法。In a third aspect, embodiments of the present application further provide an electronic device, including one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and Configured to be executed by the one or more processors, the one or more programs are configured to perform the above-described method.
第四方面,本申请实施例还提供了一种计算机可读介质,所述计算机可读取存储介质中存储有程序代码,所述程序代码可被处理器调用执行上述方法。In a fourth aspect, an embodiment of the present application further provides a computer-readable medium, where a program code is stored in the computer-readable storage medium, and the program code can be invoked by a processor to execute the foregoing method.
本申请实施例提供的数据存储方法、装置、电子设备和可读存储介质,电子设备可以检测其是否获取到刷新信息,其中,刷新信息主要用于指示缓冲器被写入元数据或者电子设备发生异常的至少一种,如果电子设备获取到刷新信息,则根据所述刷新信息将缓冲器上的数据写入至存储器上。本申请通过检测是否获取到刷新信息,来确定是否将缓冲器上的数据写入到存储器上,其在保证电子设备文件系统稳定性的同时,可以提高电子设备使用的流畅度。With the data storage method, device, electronic device, and readable storage medium provided by the embodiments of the present application, the electronic device can detect whether it acquires refresh information, where the refresh information is mainly used to indicate that metadata is written into the buffer or the electronic device has In at least one of the exceptions, if the electronic device obtains refresh information, the electronic device writes the data in the buffer to the memory according to the refresh information. The present application determines whether to write the data in the buffer to the memory by detecting whether the refresh information is acquired, which can improve the smoothness of the use of the electronic device while ensuring the stability of the file system of the electronic device.
本申请实施例的其他特征和优点将在随后的说明书阐述,并且,部分地从说明书中变得显而易见,或者通过实施本申请实施例而了解。本申请实施例的目的和其他优点可通过在所写的说明书、权利要求书、以及附图中所特别指出的结构来实现和获得。Other features and advantages of the embodiments of the present application will be set forth in the description that follows, and in part will be apparent from the description, or learned by practice of the embodiments of the present application. The objectives and other advantages of the embodiments of the application may be realized and attained by the structure particularly pointed out in the written description, claims, and drawings.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings that are used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can also be obtained from these drawings without creative effort.
图1示出了本申请一个实施例提供的数据存储方法的方法流程图;FIG. 1 shows a method flowchart of a data storage method provided by an embodiment of the present application;
图2示出了本申请一个实施例提供的数据存储方法中元数据的示例图;FIG. 2 shows an example diagram of metadata in a data storage method provided by an embodiment of the present application;
图3示出了本申请另一个实施例提供的数据存储方法的方法流程图;FIG. 3 shows a method flowchart of a data storage method provided by another embodiment of the present application;
图4示出了本申请又一个实施例提供的数据存储方法的方法流程图;FIG. 4 shows a method flowchart of a data storage method provided by another embodiment of the present application;
图5示出了本申请再一个实施例提供的数据存储方法的方法流程图;FIG. 5 shows a method flowchart of a data storage method provided by still another embodiment of the present application;
图6示出了本申请另一个实施例提供的数据存储方法的方法流程图;FIG. 6 shows a method flowchart of a data storage method provided by another embodiment of the present application;
图7示出了本申请又一个实施例提供的数据存储方法的方法流程图;FIG. 7 shows a method flowchart of a data storage method provided by another embodiment of the present application;
图8示出了本申请实施例提供的数据存储装置的模块框图;FIG. 8 shows a block diagram of a module of a data storage device provided by an embodiment of the present application;
图9示出了本申请实施例提供的数据存储装置的模块框图中信息检测模块501的模块框图;FIG. 9 shows a block diagram of an information detection module 501 in the block diagram of a data storage device provided by an embodiment of the present application;
图10示出了本申请实施例提供的数据存储装置的模块框图中信息检测模块501的其他模块框图;FIG. 10 shows another block diagram of the information detection module 501 in the block diagram of the data storage device provided by the embodiment of the present application;
图11示出了本申请实施例提供的电子设备的结构框图;FIG. 11 shows a structural block diagram of an electronic device provided by an embodiment of the present application;
图12示出了本申请实施例提供的用于保存或者携带实现根据本申请实施例的数据存储方法的程序代码的存储单元。FIG. 12 shows a storage unit provided by an embodiment of the present application for storing or carrying a program code for implementing the data storage method according to the embodiment of the present application.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述。In order to make those skilled in the art better understand the solutions of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application.
应注意到:相似的标号和字母在下面的附图中表示类似项,因此,一旦某一项在一个附图中被定义,则在随后的附图中不需要对其进行进一步定义和解释。同时,在本申请的描述中,术语“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。It should be noted that like numerals and letters refer to like items in the following figures, so once an item is defined in one figure, it does not require further definition and explanation in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.
目前移动终端ext4(Fourth extended file system,第四代扩展文件系统)提供了一种提高存储性能的方法,ext4文件系统在写数据时(如direct IO,sqlite等),需要及时调用fsync函数来保证数据的落盘,然而器件的数据同步落盘操作是通过Barrier I/O实现。其中,Barrier I/O的实现方式是使其之前的I/O在其之前写入存储介质,而之后的I/O则需要等到其写入完成后才能得到执行,即写入数据后最多需要执行2次flush(刷新)操作。第一次flush是把barrier I/O之前的所有数据刷新写入至存储设备,当刷新成功,也就是这些数据被存储设备告知确实写入其介质后,提交Barrier I/O所在的请求。然后执行第二次刷新,第二次刷新的则是Barrier I/O所携带的数据。显然,现有的ext4文件系统在读写数据时会频繁的调用fsync下发大量的flush命令给缓冲器,而这种阻塞式的命令会很耗时,而大量的耗时操作必然会引起写性能的大幅下降,进而会影响IO的整体性能,最终影响用户体验。At present, the mobile terminal ext4 (Fourth extended file system, fourth-generation extended file system) provides a method to improve storage performance. When the ext4 file system writes data (such as direct IO, sqlite, etc.), it needs to call the fsync function in time to ensure that The data is placed on the disk, but the data synchronization of the device is realized through the Barrier I/O. Among them, the implementation of Barrier I/O is to make the previous I/O write to the storage medium before it, and the subsequent I/O needs to wait until its writing is completed before it can be executed, that is, after writing data, it takes at most Perform 2 flush (refresh) operations. The first flush is to flush and write all the data before the barrier I/O to the storage device. When the flush is successful, that is, after the storage device tells the data to be written to its medium, submit the request for the barrier I/O. Then perform a second refresh, and the second refresh is the data carried by the Barrier I/O. Obviously, the existing ext4 file system will frequently call fsync to issue a large number of flush commands to the buffer when reading and writing data, and such blocking commands will be time-consuming, and a large number of time-consuming operations will inevitably cause write The performance drops significantly, which in turn affects the overall performance of IO, and ultimately affects the user experience.
因此,为了解决上述问题,本申请实施例提供了一种数据存储方法。请参阅图1,示出了本申请一个施例提供的数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。在具体的实施例中,该数据存储方法包括:步骤S101至步骤S102。Therefore, in order to solve the above problem, an embodiment of the present application provides a data storage method. Referring to FIG. 1 , a data storage method provided by an embodiment of the present application is shown, and the method is applied to the electronic device of FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. In a specific embodiment, the data storage method includes steps S101 to S102.
步骤S101:检测是否获取到刷新信息,所述刷新信息用于指示所述缓冲器被写入元数据或所述电子设备发生异常的至少一种。Step S101: Detect whether refresh information is acquired, where the refresh information is used to indicate at least one of metadata being written to the buffer or an abnormality of the electronic device.
本申请实施例中,电子设备可以是手机、笔记本电脑、平板电脑(TabletPersonalComputer)、掌上电脑、膝上型电脑(LaptopComputer)、个人数字助理(personaldigitalaSSistant,简称PDA)、移动互联网设备(MobileInternetDevice,MID)或者可穿戴式设备(例如,智能手表(如iWatch)、智能手环或者计步器等)或其他可安装部署即时通讯应用客户端的电子设备。In the embodiment of the present application, the electronic device may be a mobile phone, a notebook computer, a tablet computer (TabletPersonalComputer), a palmtop computer, a laptop computer (LaptopComputer), a personal digital assistant (personal digital assistant (personal digital assistant, PDA for short), a mobile Internet device (Mobile Internet Device, MID) Or wearable devices (for example, smart watches (such as iWatch), smart bracelets or pedometers, etc.) or other electronic devices that can install and deploy instant messaging application clients.
Ext4文件系统是Linux系统下的日志文件系统,其在将存储块写入磁盘之前可以对存储块的分配方式进行大量的改进。在Linux系统中,对文件系统上文件的读写通常是通过页缓存(page cache)进行的(Direct IO除外)进行的,通过引入页缓存可以减少磁盘读写的次数,提升IO的性能,但是性能和可靠性在一定程度也上往往是矛盾的。虽然内核中设计有一个工作序列执行脏页回写同磁盘文件进行同步,但是在一些极端的情况下还是避免不了掉电数据丢失。因此,内核提供了sync、fsync、fdatasync和msync等系统调用用于数据的同步。其中,sync会同步整个系统下的所有文件系统以及块设备,而fsync和fdatasync只针对单独的文件进行同步,msync用于同步经过mmap的文件。使用这些系统API(Application Programming Interface,API),用户可以在写完一些重要文件之后,立即执行将新写入的数据回写到磁盘,尽可能的降低数据丢失的概率。The Ext4 file system is a journaling file system under Linux, which can make a lot of improvements to the allocation of storage blocks before writing them to disk. In the Linux system, the reading and writing of files on the file system is usually carried out through the page cache (except Direct IO). By introducing the page cache, the number of disk reads and writes can be reduced and the performance of IO can be improved, but Performance and reliability are also often contradictory to a certain extent. Although a work sequence is designed in the kernel to perform dirty page write-back to synchronize with disk files, in some extreme cases, power-down data loss cannot be avoided. Therefore, the kernel provides system calls such as sync, fsync, fdatasync and msync for data synchronization. Among them, sync will synchronize all file systems and block devices under the entire system, while fsync and fdatasync only synchronize individual files, and msync is used to synchronize mmap files. Using these system APIs (Application Programming Interface, API), users can write back the newly written data to the disk immediately after writing some important files, so as to reduce the probability of data loss as much as possible.
电子设备接收到用户写入的一个文件后可以先将该数据保存在页缓存中,并将对应的页设置为脏页,这些数据并不会立即写回磁盘中,同时内核中设计有等待队列和一些工作者队列,它们在对达到预设条件之后就会被唤醒执行脏页。其中,预设条件可以包括延迟时间到期、系统内存不足或者脏页超过阈值等,延迟时间可以为5s,文件中新写入的数据此时才能够回写至磁盘。虽然写操作和回写操作之间的窗口时间(ext4默认启用延迟分配的特性)较短,如果在这段时间设备掉电或者系统崩溃,则用户写入的数据将会丢失。因此,对于单个文件来说,如果需要提高可靠性,可以在写入数据之后调用fsync来实现文件或者数据的同步,而fsync调用会同步文件的所有数据,其中,数据包括元数据和普通数据。为了将写入的数据正真存储至磁盘上,通常需调用flush命令,其不仅可以充分利用器件的缓存,而且可以提升器件的性能,但是频繁的调用flush命令会大幅度降低写性能。After the electronic device receives a file written by the user, it can first save the data in the page cache and set the corresponding page as a dirty page. These data will not be written back to the disk immediately, and a waiting queue is designed in the kernel. And some worker queues, which are woken up to execute dirty pages after a preset condition is reached. The preset conditions may include expiration of the delay time, insufficient system memory, or dirty pages exceeding the threshold, etc. The delay time may be 5s, and the newly written data in the file can be written back to the disk only at this time. Although the window time between write operations and write-back operations (ext4 enables delayed allocation by default) is short, if the device loses power or the system crashes during this time, the data written by the user will be lost. Therefore, for a single file, if you need to improve reliability, you can call fsync after writing data to synchronize the file or data, and the fsync call will synchronize all data of the file, including metadata and ordinary data. In order to actually store the written data on the disk, the flush command is usually called, which can not only make full use of the cache of the device, but also improve the performance of the device, but frequently calling the flush command will greatly reduce the write performance.
在一种实施方式中,电子设备可以实时检测其是否获取到刷新信息,其中刷新信息用于指示电子设备的缓冲器中被写入元数据,即电子设备可以每隔预设时间段检测是否有元数据被写入,如果有元数据写入,则进入步骤S102,如果没有元数据写入,则持续进行检测。其中,元数据主要是用来描述一个文件的特征和系统数据,为了更清楚的理解元数据本申请给出了如图2所示的示例图,从图2可以看出文件的元数据可以包括File(文件名)、Size(文件大小)、Blocks(文件所占扇区个数)、IO Block(每个数据块的大小)、regularfile(文件的类型)、Inode(文件的索引号)、Links(硬链接次数)、AcceSS(权限)、Uid(属主id/属主名)、Gid(属组id/属组名)、AcceSS time(最近访问时间)、Modify time(数据改动时间)以及Change time(元数据改动时间)等。In one embodiment, the electronic device can detect in real time whether it acquires refresh information, where the refresh information is used to indicate that metadata is written into the buffer of the electronic device, that is, the electronic device can detect whether there is any Metadata is written, if there is metadata written, go to step S102, and if no metadata is written, continue to detect. Among them, metadata is mainly used to describe the characteristics and system data of a file. In order to understand the metadata more clearly, this application provides an example diagram as shown in Figure 2. It can be seen from Figure 2 that the metadata of a file can include: File (file name), Size (file size), Blocks (number of sectors occupied by the file), IO Block (size of each data block), regularfile (file type), Inode (file index number), Links (Number of hard links), AcceSS (authority), Uid (owner id/owner name), Gid (member group id/member group name), AcceSS time (last access time), Modify time (data modification time) and Change time (metadata change time), etc.
本申请实施例还中刷新信息还可以用于指示电子设备发生异常,而电子设备发生异常可以包括电子设备的电量过低、电子设备异常关机、电子设备异常重启等,当电子设备发生这些异常后,存储器上的数据就无法及时的存储于硬件设备上,进而会导致数据的丢失。为了防止因电子设备因异常而导致数据的丢失,本申请接收到关于设备异常的信号之后即可以执行数据冲刷操作,即将缓冲器上的数据写入至存储器。需要说明的是,刷新信息可以指示的是缓冲器被写入元数据,也可以指示的是电子设备发生异常,或者可以指示的是缓冲器被写入元数据以及电子设备发生异常,只要指示上述任意一种情况即可进入步骤S102。In the embodiment of the present application, the refresh information can also be used to indicate that the electronic device is abnormal, and the abnormality of the electronic device may include that the power of the electronic device is too low, the electronic device is shut down abnormally, and the electronic device is abnormally restarted. , the data on the memory cannot be stored on the hardware device in time, which will lead to data loss. In order to prevent data loss due to abnormality of the electronic device, the present application can perform a data flushing operation after receiving a signal about the abnormality of the device, that is, write the data on the buffer to the memory. It should be noted that the refresh information can indicate that metadata is written to the buffer, or that an abnormality occurs in the electronic device, or it can indicate that metadata is written to the buffer and an abnormality occurs in the electronic device. In any case, step S102 can be entered.
步骤S102:如果获取到刷新信息,则根据所述刷新信息将所述缓冲器上的数据写入至存储器上。Step S102: If the refresh information is obtained, write the data on the buffer to the memory according to the refresh information.
在一种实施方式中,存储器主要作用是永久地存储文件数据,存储器可以由任何种类的非易失性存储器实现,该非易失性存储器可以包括但不限于各种只读存储器(ROM)。例如,可编程ROM(PROM)、电可改写ROM(EAROM)、可擦可编程ROM(EPROM)和电可擦可编程ROM(EEPROM)、闪速存储器(Flash Memory)、磁盘等等。其中,闪速存储器是一类非易失性存储器(Non-Volatile Memory,NVM),即使在供电电源关闭后其仍能保持片内信息,闪速存储器不仅具有较快的速度,而且更新数据方便、成本低以及密度大等特点。闪速存储器根据单元的连接方式可分为NAND(Not And,与非)、NOR、DINOR(Divided bit Line NOR)及AND几类。NAND存储器使用复杂的I/O接口来串行的存储数据,因为NAND存储器读和写操作均采用512字节的块,故基于NAND的存储器可以取代硬盘或其他设备。本申请实施例可以根据刷新信息将缓冲器上的数据写入至NAND存储器上。In one embodiment, the main function of the memory is to store file data permanently, and the memory may be implemented by any kind of non-volatile memory, which may include, but is not limited to, various read-only memories (ROMs). For example, programmable ROM (PROM), electrically rewritable ROM (EAROM), erasable programmable ROM (EPROM) and electrically erasable programmable ROM (EEPROM), flash memory (Flash Memory), magnetic disks, and the like. Among them, flash memory is a type of non-volatile memory (Non-Volatile Memory, NVM), which can keep on-chip information even after the power supply is turned off. Flash memory not only has faster speed, but also facilitates updating data. , low cost and high density. Flash memory can be divided into NAND (Not And, NAND), NOR, DINOR (Divided bit Line NOR) and AND according to the connection method of the unit. NAND memory uses a complex I/O interface to store data serially, and because NAND memory read and write operations use 512-byte blocks, NAND-based memory can replace hard drives or other devices. In this embodiment of the present application, the data in the buffer can be written to the NAND memory according to the refresh information.
在另一种实施方式中,电子设备判定其获取到刷新信息之后,则可以根据该刷新信息执行相应的数据写入动作,即根据刷新信息将缓冲器上的部分数据或者全部数据写入至NAND存储器上。具体的,当电子设备确定其缓冲器上输入元数据,则将缓冲器上的元数据写入至NAND存储器;当检测到电子设备发生异常,则将缓冲器上的数据写入至NAND存储器。In another embodiment, after the electronic device determines that it has acquired the refresh information, it can perform a corresponding data writing action according to the refresh information, that is, write part or all of the data on the buffer to the NAND according to the refresh information on the memory. Specifically, when the electronic device determines that metadata is input in its buffer, the metadata in the buffer is written to the NAND memory; when an abnormality is detected in the electronic device, the data in the buffer is written to the NAND memory.
需要说明的是,如果检测到缓冲器上被写入元数据,同时检测到电子设备发生异常,则可以根据数据的重要程度确定数据写入存储器的先后顺序。换句话说,本申请实施例在检测到缓冲器上有元数据写入并且此时电子设备发生异常,则可以先将缓冲器上的元数据写入至存储器,而后再将缓冲器上的其他数据写入至存储器,因为元数据是描述数据的数据,其与普通数据相比更重要。电子设备发生异常后,如果有部分数据丢失,则可以根据存储的元数据对丢失的数据进行恢复。因此,当缓冲器被写入元数据同时电子设备发生异常时可以先将元数据写入至存储器上,如此可以保证数据存储的安全性。It should be noted that, if it is detected that metadata is written to the buffer and an abnormality of the electronic device is detected at the same time, the sequence in which the data is written into the memory can be determined according to the importance of the data. In other words, when the embodiment of the present application detects that metadata is written to the buffer and the electronic device is abnormal at this time, the metadata on the buffer may be written to the memory first, and then the other Data is written to memory because metadata is data that describes the data, which is more important than normal data. After an abnormality occurs in the electronic device, if some data is lost, the lost data can be recovered according to the stored metadata. Therefore, when metadata is written into the buffer and an abnormality occurs in the electronic device, the metadata can be written to the memory first, thus ensuring the security of data storage.
本申请实施例提出的一种数据存储方法在检测到其获取到刷新信息后,可以根据该刷新信息执行相应的写入操作,如此不仅可以保证文件系统的稳定性而且在一定程度上可以提高电子设备使用的流畅度,即本申请通过对写入数据的判定可以针对性的对缓冲器上存储的部分数据进行刷新,同时当电子设备发生异常时,本申请也可以及时对缓冲器上存储的所有数据进行刷新避免了因为异常而导致的数据丢失,通过本申请实施例电子设备可以避免大量耗时操作的出现,其在保证写性能的同时也不会影响IO的整体性能。After detecting that the data storage method proposed in the embodiment of the present application has acquired refresh information, a corresponding write operation can be performed according to the refresh information, which can not only ensure the stability of the file system but also improve the electronic performance to a certain extent. The fluency of equipment use, that is, the application can refresh part of the data stored in the buffer in a targeted manner by judging the written data. At the same time, when an abnormality occurs in the electronic equipment, the application can also timely Refreshing all data avoids data loss caused by abnormality, and the electronic device in the embodiment of the present application can avoid the occurrence of a large number of time-consuming operations, which will not affect the overall performance of IO while ensuring the write performance.
本申请另一实施例提供了一种数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。请参阅图3,该数据存储方法可以包括步骤S301至步骤S304。Another embodiment of the present application provides a data storage method, and the method is applied to the electronic device shown in FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. Referring to FIG. 3, the data storage method may include steps S301 to S304.
步骤S301:获取缓冲器被写入的数据。Step S301: Acquire the data written in the buffer.
步骤S302:判断被写入的数据是否为元数据。Step S302: Determine whether the written data is metadata.
通过上述介绍可以知道,元数据主要是用来描述一个文件的特征的系统数据,诸如访问权限、文件拥有者以及文件数据块的分布信息(inode)等。因此,对元数据的保护尤为重要,本申请可以通过对元数据io标识的判断来确定传输至缓冲器上的数据是否为元数据。文件系统的元数据具有特殊的io标识,本申请可以根据所述io标识区分文件系统的元数据和其他数据。因此,在linux系统中当缓冲器被写入数据时,电子设备可以根据文件系统的数据的io标识确定文件系统的数据是否为元数据,如果文件系统的数据的io标识为元数据对应的io标识,则可以确定文件系统的数据是元数据。具体的,电子设备检测到缓冲器上有数据写入后可以先获取该数据对应的所有标识符,并判其获取的标识符与预设标识符是否匹配,如果获取的标识符与预设标识符匹配则确定该标识符对应的数据为元数据。例如,电子设备检测到缓冲器上有数据A写入后,获取其包括的标识符,得到标识符a和标识符b,其中,标识符a的值为FC4E2BA9,而标识符b的值为201883441,预设标识符为FC4E2BA9,显然,标识符a的值FC4E2BA9和预设标识符FC4E2BA9匹配,此时则可以确定标识符a对应的数据即为元数据。It can be known from the above introduction that metadata is mainly system data used to describe the characteristics of a file, such as access rights, file owners, and distribution information (inode) of file data blocks. Therefore, the protection of metadata is particularly important, and the present application can determine whether the data transmitted to the buffer is metadata by judging the io identifier of the metadata. The metadata of the file system has a special io identifier, and the present application can distinguish the metadata of the file system from other data according to the io identifier. Therefore, in the Linux system, when data is written into the buffer, the electronic device can determine whether the data of the file system is metadata according to the io identifier of the data in the file system, if the io identifier of the data in the file system is the io corresponding to the metadata If the identifier is identified, it can be determined that the data of the file system is metadata. Specifically, after detecting that data is written into the buffer, the electronic device can first obtain all the identifiers corresponding to the data, and determine whether the obtained identifier matches the preset identifier. If the obtained identifier matches the preset identifier If the identifier matches, the data corresponding to the identifier is determined as metadata. For example, after detecting that data A is written in the buffer, the electronic device obtains the identifiers included in it, and obtains identifiers a and b, wherein the value of identifier a is FC4E2BA9, and the value of identifier b is 201883441 , the preset identifier is FC4E2BA9. Obviously, the value FC4E2BA9 of the identifier a matches the preset identifier FC4E2BA9. In this case, it can be determined that the data corresponding to the identifier a is metadata.
在另一种实施方式中,每个写入的数据可以包括与其对应的设备接口标识,电子设备检测到缓冲器有数据写入后,可以先获取该数据对应的设备接口标识,并判断该设备接口标识是否对应预设的设备接口。其中,预设的设备接口用于传递元数据,如果设备接口标识对应预设的设备接口,则判定缓冲器上写入的数据为元数据,此时则判定获取到所述刷新信息,即进入步骤S303。例如,存储器上写入数据B后,电子设备可以先获取该数据B对应的设备接口标识,得到数据B对应的设备接口标识为bx345,而预设的设备接口标识也为bx345,显然,此时数据B的设备接口标识与设备的设备接口对应,故数据B为元数据。如果缓冲区上写入的数据不是元数据则重新获取缓冲器被写入的数据,即进入步骤S301。In another embodiment, each written data may include its corresponding device interface identifier. After the electronic device detects that data is written into the buffer, it can first obtain the device interface identifier corresponding to the data, and determine the device interface. Whether the interface identifier corresponds to the preset device interface. The preset device interface is used to transmit metadata. If the device interface identifier corresponds to the preset device interface, it is determined that the data written in the buffer is metadata. At this time, it is determined that the refresh information is obtained, that is, the entry Step S303. For example, after writing data B into the memory, the electronic device can first obtain the device interface identifier corresponding to the data B, and obtain the device interface identifier corresponding to data B as bx345, and the preset device interface identifier is also bx345. Obviously, at this time The device interface identifier of data B corresponds to the device interface of the device, so data B is metadata. If the data written in the buffer is not metadata, the data written in the buffer is re-acquired, that is, step S301 is entered.
另外,本申请实施例也可以获取被写入数据的属性信息,所述属性信息可以包括所述数据的大小,如果被写入的数据的大小小于指定数值,则确定被写入的数据内包含元数据。本申请实施例也可以根据被写入数据的地址来确定被写入的数据是否为元数据,即如果被写入的数据的地址为专门存储元数据的地址,则该数据即为元数据,具体如何判断缓冲器上的数据为元数据这里不进行明确限制,可以根据实际情况进行判断。In addition, in this embodiment of the present application, attribute information of the written data may also be obtained, and the attribute information may include the size of the data. If the size of the written data is smaller than a specified value, it is determined that the written data contains metadata. In this embodiment of the present application, it is also possible to determine whether the written data is metadata according to the address of the written data, that is, if the address of the written data is an address dedicated to storing metadata, then the data is metadata, How to judge that the data on the buffer is metadata is not specifically limited here, and can be judged according to the actual situation.
步骤S303:判定获取到所述刷新信息。Step S303: It is determined that the refresh information is acquired.
通过上述介绍可以知道,当检测到缓冲器上有数据写入时,电子设备可以先判断该数据是不是元数据,或者判断该数据中是否包含有元数据,如果缓冲器上写入的数据中包含有元数据,或者写入的数据即为元数据,则表示电子设备获取到了刷新信息,此时则可以根据该刷新信息将缓冲器上的元数据写入至存储器,即进入步骤S304。It can be known from the above introduction that when it is detected that data is written to the buffer, the electronic device can first determine whether the data is metadata, or whether the data contains metadata, if the data written in the buffer contains metadata If metadata is included, or the written data is metadata, it means that the electronic device has obtained the refresh information, and the metadata on the buffer can be written to the memory according to the refresh information, that is, step S304 is entered.
步骤S304:根据所述刷新信息将所述缓冲器上的元数据写入至存储器上。Step S304: Write the metadata on the buffer to the memory according to the refresh information.
在一种实施方式中,当确定获取到所述刷新信息后,电子设备可以根据该刷新信息将缓冲器上的元数据写入至存储器,当电子设备检测到缓冲器上写入的数据包括元数据,或者检测到缓冲器上写入的数据为元数据时,电子设备可以将缓冲器上的元数据写入至存储器。需要说明的是,当电子设备确定缓冲器上有元数据写入后,电子设备仅需将缓冲器上的元数据写入至存储器上即可,而缓冲器上的其他数据(普通数据)则不需要和元数据一起写入至存储器,主要原因是元数据是描述普通数据的数据,即使电子设备发生异常导致普通数据丢失,也可以通过已经存储的元数据来进行恢复。因此,对元数据的保护更为重要,而普通数据则可以按照缓冲器正常的队列顺序写入至存储器。In one embodiment, after determining that the refresh information is acquired, the electronic device can write the metadata on the buffer to the memory according to the refresh information, and when the electronic device detects that the data written in the buffer includes metadata data, or when detecting that the data written on the buffer is metadata, the electronic device can write the metadata on the buffer to the memory. It should be noted that after the electronic device determines that metadata is written in the buffer, the electronic device only needs to write the metadata in the buffer to the memory, and other data (ordinary data) in the buffer is It does not need to be written to the storage together with the metadata. The main reason is that the metadata is the data that describes the ordinary data. Even if the ordinary data is lost due to an abnormality of the electronic device, it can be recovered through the stored metadata. Therefore, the protection of metadata is more important, while ordinary data can be written to memory in the normal queue order of the buffer.
本申请实施例提出的一种数据存储方法中电子设备在检测到缓冲器中被写入数据后,可以先判断该数据是否为元数据或者该数据中是否包括元数据,如果写入缓冲器上的数据为元数据或者写入的数据中包括元数据,则可以将缓冲器上的元数据写入至存储器,通过对元数据针对性的保护可以确保写入缓冲器的数据能够完整的落盘,即保证日志文件系统的完整性和一致性,即通过对元数据的保护可以保证电子设备即使发生异常或者发生故障后也可以进行必要的文件系统的修复,与此同时可以充分利用缓冲器的缓存能力提升数据的写性能。In the data storage method proposed by the embodiment of the present application, after detecting that data is written in the buffer, the electronic device can first determine whether the data is metadata or whether the data includes metadata. If the data is metadata or the written data includes metadata, the metadata on the buffer can be written to the memory, and the targeted protection of the metadata can ensure that the data written to the buffer can be completely placed on the disk , that is, to ensure the integrity and consistency of the log file system, that is, through the protection of metadata, it can be ensured that the electronic device can perform necessary file system repairs even after an abnormality or failure occurs, and at the same time, the buffer can be fully utilized. Cache capability improves data write performance.
本申请又一实施例提供了一种数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。请参阅图4,该数据存储方法可以包括步骤S401至步骤S404。Yet another embodiment of the present application provides a data storage method, and the method is applied to the electronic device shown in FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. Referring to FIG. 4 , the data storage method may include steps S401 to S404.
步骤S401:获取所述电子设备的使用状态信息。Step S401: Acquire usage status information of the electronic device.
在一种实施方式中,电子设备的使用状态信息可以包括电量信息和设备状态信息,其中,电量信息指的是电子设备当前剩余的电量值,而设备状态信息指的是电子设备当前是否正常运行。本申请实施例中,电子设备的使用状态可以包括正常使用状态和异常状态,异常状态指的是电子设备无法正常运行,电子设备的异常状态可以包括第一异常状态和第二异常状态。其中,第一异常状态主要是因为电源故障而致使电子设备无法运行的状态,在该状态下电子设备会发生异常关机、异常重启或者无法开机等现象。本申请实施例中第一异常状态可以包括异常关机和异常重启,第二异常状态则是除电源故障外的其他异常状态,在该异常状态下触发电子设备的电源开关后可以检测到电流,但是无按键背光、显示屏背光、振动器或者铃声等,第二异常状态也包括电子设备部分功能发生故障,如按键失效、显示不正常(讯息显示错误、LCD全黑、全白或者字形错误等)以及部分功能失效等。In one embodiment, the usage status information of the electronic device may include power information and device status information, wherein the power information refers to the current remaining power value of the electronic device, and the device status information refers to whether the electronic device is currently running normally . In the embodiment of the present application, the use state of the electronic device may include a normal use state and an abnormal state, the abnormal state means that the electronic device cannot operate normally, and the abnormal state of the electronic device may include a first abnormal state and a second abnormal state. The first abnormal state is mainly a state in which the electronic device cannot be operated due to a power failure. In this state, the electronic device may be abnormally shut down, abnormally restarted, or cannot be turned on. In the embodiment of the present application, the first abnormal state may include abnormal shutdown and abnormal restart, and the second abnormal state is other abnormal state except power failure. In this abnormal state, after the power switch of the electronic device is triggered, current can be detected, but There is no key backlight, display backlight, vibrator or ringtone, etc. The second abnormal state also includes failure of some functions of the electronic equipment, such as key failure, abnormal display (message display error, LCD all black, all white or wrong font, etc.) and some functional failures.
步骤S402:判断所述使用状态信息是否满足指定条件。Step S402: Determine whether the use state information satisfies a specified condition.
本申请实施例中,电子设备的使用状态可以包括电量信息,电子设备判断该使用状态信息是否满足指定条件,包括:判断所述电子设备的电量信息是否小于预设阈值,如果所述电量信息小于预设阈值,则判定所述使用状态信息满足指定条件。In this embodiment of the present application, the use state of the electronic device may include power information, and the electronic device determines whether the use state information satisfies a specified condition, including: judging whether the power information of the electronic device is less than a preset threshold, if the power information is less than If the preset threshold is set, it is determined that the usage status information satisfies the specified condition.
另外,根据刷新信息将所述缓冲器上的数据写入至存储器之前,本申请实施例可以先获取所述电子设备的接线情况,即根据该接线情况确定所述电子设备是否处于未充电状态。如果所述电子设备未处于充电状态,则表明所述电子设备的电量会不断降低,随时会有关机的情况发生,即判定电子设备的所述使用状态信息满足指定条件,此时则需要将缓冲器上的数据写入至存储器上,以防止因为关机而导致缓存器上的数据丢失。In addition, before writing the data on the buffer to the memory according to the refresh information, the embodiment of the present application may first obtain the connection condition of the electronic device, that is, determine whether the electronic device is in an uncharged state according to the connection condition. If the electronic device is not in the charging state, it means that the power of the electronic device will continue to decrease, and there will be a shutdown situation at any time. The data on the memory is written to the memory to prevent the data on the memory from being lost due to shutdown.
在另一种实施方式中,如果电子设备处于充电状态,则可以不将缓冲器上的数据写入至电子设备,因为电子设备处于充电状态其电量会不断升高,不会发生因为电量低而导致电子设备关机的情况。但是,为了保证数据的安全性,在这种情况下可以将缓冲器上的元数据写入至存储器。具体的,当判定电子设备的电量信息小于预设阈值,同时确定电子设备处于充电状态可以将缓冲器上的元数据写入至存储器。In another embodiment, if the electronic device is in a charging state, the data on the buffer may not be written to the electronic device, because the electronic device is in a charging state, and its power will continue to rise, and it will not occur due to low power. Conditions that cause electronic equipment to shut down. However, to ensure data security, metadata on the buffer can be written to memory in this case. Specifically, when it is determined that the power information of the electronic device is less than the preset threshold, and it is determined that the electronic device is in a charging state, the metadata on the buffer can be written to the memory.
在另一种实施方式中,电子设备的使用状态信息可以包括设备状态信息,判断所述使用状态信息是否满足指定条件可以包括:判断所述设备状态信息是否为电子设备异常关机或者异常重启,如果所述设备状态信息是电子设备异常关机或者异常重启,则判定所述电子设备的使用状态信息满足指定条件,此时则可进入步骤S403。如果使用状态信息不满足指定条件则重新获取所述电子设备的使用状态信息,即进入步骤S401。In another implementation manner, the use state information of the electronic device may include device state information, and judging whether the use state information satisfies a specified condition may include: judging whether the device state information is abnormal shutdown or abnormal restart of the electronic device, if If the device state information is the abnormal shutdown or abnormal restart of the electronic device, it is determined that the use state information of the electronic device satisfies the specified condition, and in this case, step S403 may be entered. If the use state information does not meet the specified condition, the use state information of the electronic device is re-acquired, that is, step S401 is entered.
步骤S403:若所述使用状态信息满足指定条件,则判定获取到刷新信息。Step S403: If the use state information satisfies the specified condition, it is determined that refresh information is obtained.
步骤S404:根据所述刷新信息将所述缓冲器上的数据写入至存储器上。Step S404: Write the data in the buffer to the memory according to the refresh information.
通过上述介绍可以知道,电子设备获取到电量信息之后可以判断该电量信息是否小于预设阈值,如果小于预设阈值,则判定所述使用状态信息满足指定条件,此时则可以根据所述电量信息将缓冲器上的数据写入至存储器上。It can be known from the above introduction that after the electronic device obtains the power information, it can determine whether the power information is less than a preset threshold. Write the data in the buffer to the memory.
在一种实施方式中,如果获取到电子设备的电量信息大于第一电量预设阈值并且小于第二电量预设阈值,则可以将缓冲器上的元数据写入至存储器,而普通数据则不写入存储器。例如,获取到电子设备的电量信息为10%,第一电量预设阈值为5%、第二电量预设阈值为15%,可以看出电子设备的电量信息10%大于第一电量预设阈值5%并且小于第二电量预设阈值15%,此时则可以将缓冲器上的元数据写入至存储器,而缓冲器上的其他数据则不同元数据一起写入至存储器。In one embodiment, if the acquired power information of the electronic device is greater than the first power preset threshold and less than the second power preset threshold, the metadata on the buffer can be written to the memory, while the common data is not Write to memory. For example, if the obtained power information of the electronic device is 10%, the first power preset threshold is 5%, and the second power preset threshold is 15%, it can be seen that 10% of the power information of the electronic device is greater than the first power preset threshold 5% and less than 15% of the second power preset threshold, at this time, the metadata on the buffer can be written to the memory, while other data on the buffer is written to the memory together with the metadata.
在另一种实施方式中,如果获取到电子设备的电量信息小于第一电量预设阈值,则可以将缓冲器上的数据写入至存储器,即电子设备的电量信息小于第一电量预设阈值时可以将缓冲器上的元数据和普通数据一起写入至存储器。例如,获取到电子设备的电量信息为4%,第一电量预设阈值为5%,显然,电子设备的电量信息4%小于第一电量预设阈值5%,此时则可以将缓冲器上的元数据和普通数据写入至存储器。为了避免数据的丢失,本申请实施例可以在电子设备的电量信息小于第一电量预设阈值时,先将元数据写入至存储器,然后再将普通数据写入至存储器上。如此,即时普通数据丢失也可以根据元数据进行恢复。In another embodiment, if the obtained power information of the electronic device is less than the first power preset threshold, the data in the buffer can be written to the memory, that is, the power information of the electronic device is less than the first power preset threshold Metadata on the buffer can be written to memory along with normal data. For example, the obtained power information of the electronic device is 4%, and the first preset power threshold is 5%. Obviously, the power information of the electronic device is 4% less than the first power preset threshold of 5%. Metadata and general data are written to memory. In order to avoid data loss, in this embodiment of the present application, when the power information of the electronic device is less than the first power preset threshold, metadata is first written to the memory, and then ordinary data is written to the memory. In this way, even if ordinary data is lost, it can be recovered according to the metadata.
在一种实施方式中,电子设备的使用状态信息可以包括设备状态信息,当电子设备状态信息是电子设备异常关机或者异常重启,则确定使用状态信息满足指定条件,此时可以判定电子设备获取到刷新信息,即可以根据该刷新信息将缓冲器上的数据写入至存储器。通过上述介绍可以知道设备状态信息包括第一异常状态和第二异常状态,而第一异常状态包括异常关机和异常重启,即当电子设备处于第一异常状态下时可以将缓冲器上的元数据和普通数据写入至存储器;当电子设备处于第二异常状态时,可以将缓冲器上的元数据写入至存储器,因为电子设备处于第二异常状态时电子设备的供电是正常的,因此在该状态下只需要将元数据写入至存储器即可,其他数据则可以按照正常的队列写入至存储器。In one embodiment, the use state information of the electronic device may include device state information. When the electronic device state information is abnormal shutdown or abnormal restart of the electronic device, it is determined that the use state information satisfies a specified condition, and at this time, it can be determined that the electronic device obtains Refresh information, that is, the data on the buffer can be written to the memory according to the refresh information. From the above description, it can be known that the device state information includes the first abnormal state and the second abnormal state, and the first abnormal state includes abnormal shutdown and abnormal restart, that is, when the electronic device is in the first abnormal state, the metadata on the buffer can be stored. and ordinary data are written to the memory; when the electronic device is in the second abnormal state, the metadata on the buffer can be written to the memory, because the power supply of the electronic device is normal when the electronic device is in the second abnormal state, so when the electronic device is in the second abnormal state In this state, only metadata needs to be written to the memory, and other data can be written to the memory according to the normal queue.
在另一种实施方式中,当确定设备状态信息是电子设备异常关机或者异常重启时,为了保证电子设备有足够的时间将缓冲器上的数据写入至存储器,本申请实施例可以利用电子设备的电容为其供电,并将缓冲器上的数据写入至存储器。在该过程中,可以先将缓冲器上的元数据写入至存储器,然后再将其他数据写入至存储器,如此可以保证数据写入的安全性,即避免因为电容供电不足而致使缓冲器上数据丢失的现象,只要元数据被成功写入存储器即使其他数据丢失,也可以通过元数据进行恢复。本申请实施例利用电容供电的主要原因是电子设备电容的掉电速度比电子设备电池的掉电速度慢,当电子设备异常关机或者异常重启时,电子设备的电池不足以支持缓冲器上数据的写入,此时为了延迟关机为缓冲器数据的写入保留足够长的时间可以利用电子设备的电容供电。In another implementation manner, when it is determined that the device state information is the abnormal shutdown or abnormal restart of the electronic device, in order to ensure that the electronic device has enough time to write the data in the buffer to the memory, the embodiment of the present application may use the electronic device The capacitor powers it and writes the data on the buffer to the memory. In this process, the metadata on the buffer can be written to the memory first, and then other data can be written to the memory, so as to ensure the safety of data writing, that is, to avoid the buffer on the buffer due to insufficient power supply of the capacitor. The phenomenon of data loss, as long as the metadata is successfully written into the storage, even if other data is lost, it can be recovered through the metadata. The main reason why the capacitors are used for power supply in this embodiment of the present application is that the power-down speed of the capacitor of the electronic device is slower than that of the battery of the electronic device. When the electronic device is abnormally shut down or restarted abnormally, the battery of the electronic device is not enough to support the data on the buffer. Write, at this time, in order to delay the shutdown for a long enough time for the writing of the buffer data, the capacitor of the electronic device can be used to supply power.
本申请实施例提出的一种数据存储方法检测到电子设备发生异常时可以先判断该异常为哪种异常,然后根据异常的不同执行相应的数据写入操作,具体的,当电子设备的电量信息小于预设阈值时可以将缓冲器上的数据写入至存储器,或者当电子设备异常关机或异常重启时也可以将缓冲器上的数据写入至存储器,即本申请实施例通过对不同异常的判断可以更加安全有效的对缓冲器上的数据进行存储,不仅可以减少电子设备使用时的卡顿现象,而且可以提高电子设备使用的流畅度,同时也不会影响写性能和IO的整体性能。When a data storage method proposed in the embodiment of the present application detects that an abnormality occurs in an electronic device, it can first determine what kind of abnormality the abnormality is, and then perform a corresponding data writing operation according to the difference of the abnormality. Specifically, when the power information of the electronic device is When it is less than the preset threshold, the data on the buffer can be written to the memory, or when the electronic device is abnormally shut down or restarted abnormally, the data on the buffer can also be written to the memory, that is, the embodiment of the present application Judging can store the data on the buffer more safely and effectively, which can not only reduce the jam phenomenon when the electronic device is used, but also improve the fluency of the electronic device, without affecting the writing performance and the overall performance of the IO.
本申请再一实施例提供了一种数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。请参阅图5,该数据存储方法可以包括步骤S501至步骤S505。Yet another embodiment of the present application provides a data storage method, and the method is applied to the electronic device shown in FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. Referring to FIG. 5, the data storage method may include steps S501 to S505.
步骤S501:获取电子设备的使用状态信息。Step S501: Acquire usage status information of the electronic device.
步骤S502:判断所述使用状态信息是否满足指定条件。Step S502: Determine whether the use state information satisfies a specified condition.
在一种实施方式中,当电子设备判断其使用状态满足指定条件则判定获取到刷新信息,即进入步骤S503,当电子设备的使用状态不满足指定条件则判定获取到刷新信息,并将缓冲器上的元数据写入至存储器,即进入步骤S505。In one embodiment, when the electronic device determines that its use state satisfies the specified condition, it determines that the refresh information is obtained, that is, it goes to step S503, and when the use state of the electronic device does not meet the specified condition, it determines that the refresh information is obtained, and the buffer The metadata on the device is written to the memory, that is, it goes to step S505.
步骤S503:判定获取到刷新信息。Step S503: It is determined that the refresh information is acquired.
步骤S504:根据所述刷新信息将所述缓冲器上的数据写入至存储器。Step S504: Write the data on the buffer to the memory according to the refresh information.
步骤S505:将所述缓冲器上的元数据写入至存储器。Step S505: Write the metadata on the buffer to the memory.
本申请实施例提出的一种数据存储方法可以结合使用状态信息和元数据来确定是否将缓冲区上的元数据写入至存储器,即本申请实施例通过对电子设备不同情况的考虑可以更加安全有效的对缓冲器上的数据进行存储,不仅可以减少电子设备使用时的卡顿现象,而且可以提高电子设备使用的流畅度,同时也不会影响写性能和IO的整体性能。A data storage method proposed by the embodiments of the present application may combine state information and metadata to determine whether to write the metadata on the buffer to the memory, that is, the embodiments of the present application can be more secure by considering different situations of electronic devices Effectively storing the data on the buffer can not only reduce the jam phenomenon when the electronic device is used, but also improve the smoothness of the use of the electronic device without affecting the writing performance and the overall performance of the IO.
本申请另一实施例提供了一种数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。请参阅图6,该数据存储方法可以包括步骤S601至步骤S604。Another embodiment of the present application provides a data storage method, and the method is applied to the electronic device shown in FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. Referring to FIG. 6, the data storage method may include steps S601 to S604.
步骤S601:获取电子设备的使用状态信息。Step S601: Acquire usage status information of the electronic device.
步骤S602:判断所述使用状态信息是否满足指定条件。Step S602: Determine whether the use state information satisfies a specified condition.
在一种实施方式中,当电子设备判断其使用状态满足指定条件则判定获取到刷新信息,即进入步骤S603,当使用状态不满足指定条件则重新获取电子设备的使用状态信息,即进入步骤S601。In one embodiment, when the electronic device determines that its use state satisfies the specified condition, it determines that the refresh information is obtained, that is, it goes to step S603; .
步骤S603:判定获取到刷新信息。Step S603: It is determined that the refresh information is acquired.
步骤S604:将所述缓冲器上的元数据写入至存储器。Step S604: Write the metadata on the buffer to the memory.
本申请实施例提出的一种数据存储方法可以结合使用状态信息和元数据来确定是否将缓冲区上的元数据写入至存储器,即本申请实施例通过对电子设备不同情况的考虑可以更加安全有效的对缓冲器上的数据进行存储,不仅可以减少电子设备使用时的卡顿现象,而且可以提高电子设备使用的流畅度,同时也不会影响写性能和IO的整体性能。A data storage method proposed by the embodiments of the present application may combine state information and metadata to determine whether to write the metadata on the buffer to the memory, that is, the embodiments of the present application can be more secure by considering different situations of electronic devices Effectively storing the data on the buffer can not only reduce the jam phenomenon when the electronic device is used, but also improve the smoothness of the use of the electronic device without affecting the writing performance and the overall performance of the IO.
本申请又一实施例提供了一种数据存储方法,该方法应用于图11和图12的电子设备。该数据存储方法应用于电子设备,所述电子设备包括缓冲器。请参阅图7,该数据存储方法可以包括步骤S701至步骤S705。Yet another embodiment of the present application provides a data storage method, and the method is applied to the electronic device shown in FIG. 11 and FIG. 12 . The data storage method is applied to an electronic device including a buffer. Referring to FIG. 7 , the data storage method may include steps S701 to S705.
步骤S701:获取所述缓冲器被写入的数据。Step S701: Acquire the data written in the buffer.
步骤S702:判断被写入的数据是否为元数据。Step S702: Determine whether the written data is metadata.
在一种实施方式中,电子设备确定其缓冲器被写入的数据是元数据是则获取电子设备的使用状态信息,即进入步骤S703,而当缓冲器被写入的数据不是元数据则获取所述缓冲器被写入的数据,即进入步骤S701。In one embodiment, when the electronic device determines that the data written in the buffer is metadata, it acquires the usage status information of the electronic device, that is, it goes to step S703, and when the data written in the buffer is not metadata, it acquires The data written in the buffer goes to step S701.
步骤S703:获取电子设备的使用状态信息。Step S703: Obtain the use status information of the electronic device.
步骤S704:判断所述使用状态信息是否满足指定条件。Step S704: Determine whether the use state information satisfies a specified condition.
在一种实施方式中,电子设备判定使用状态信息满足预设条件则根据所述刷新信息将所述缓冲器上的数据写入至存储器,即进入步骤S705,否则获取电子设备的使用状态信息,即进入步骤S703。In one embodiment, the electronic device determines that the use state information satisfies a preset condition, and writes the data on the buffer to the memory according to the refresh information, that is, enters step S705, otherwise obtains the use state information of the electronic device, That is, it goes to step S703.
步骤S705:根据所述刷新信息将所述缓冲器上的数据写入至存储器。Step S705: Write the data on the buffer to the memory according to the refresh information.
本申请实施例提出的一种数据存储方法可以结合使用状态信息和元数据来确定是否将缓冲区上的元数据写入至存储器,即本申请实施例通过对电子设备不同情况的考虑可以更加安全有效的对缓冲器上的数据进行存储,不仅可以减少电子设备使用时的卡顿现象,而且可以提高电子设备使用的流畅度,同时也不会影响写性能和IO的整体性能。A data storage method proposed by the embodiments of the present application may combine state information and metadata to determine whether to write the metadata on the buffer to the memory, that is, the embodiments of the present application can be more secure by considering different situations of electronic devices Effectively storing the data on the buffer can not only reduce the jam phenomenon when the electronic device is used, but also improve the smoothness of the use of the electronic device without affecting the writing performance and the overall performance of the IO.
请参阅图8,本申请实施例提出了一种数据存储装置800。在具体的实施例中,该数据存储装置800包括:信息检测模块801和数据存储模块802。Referring to FIG. 8 , an embodiment of the present application provides a
信息检测模块801,用于检测是否获取到刷新信息,所述刷新信息用于指示所述缓冲器被写入元数据或所述电子设备发生异常的至少一种。The
如图9所示,信息检测模块801可以包括元数据判断单元8011、信息判定单元8012和元数据存储单元8013。As shown in FIG. 9 , the
元数据判断单元8011,用于在检测到所述缓冲器被写入数据时,判断被写入的数据是否为元数据。The
信息判定单元8012,用于若为元数据,则判定获取到所述刷新信息。The
元数据存储单元8013,用于根据所述刷新信息将所述缓冲器上的元数据写入至存储器上。A
如图10所示,信息检测模块801还可以包括状态信息获取单元8014、状态信息判断单元8015和刷新信息判定单元8016。As shown in FIG. 10 , the
状态信息获取单元8014,用于获取所述电子设备的使用状态信息。A state
状态信息判断单元8015,用于判断所述使用状态信息是否满足指定条件。The state
进一步的,状态信息判断单元8015还用于判断所述电子设备的电量信息是否小于预设阈值,如果所述电量信息小于预设阈值,则判定所述使用状态信息满足指定条件。Further, the status
进一步的,状态信息判断单元8015还用于判断所述设备状态信息是否为电子设备异常关机或者异常重启,如果所述设备状态信息是电子设备异常关机或者异常重启,则判定所述使用状态信息满足指定条件。Further, the state
刷新信息判定单元8016,用于若所述使用状态信息满足指定条件,则判定获取到刷新信息。The refresh
进一步的,刷新信息判定单元8016还用于确定所述电子设备是否处于未充电状态,如果所述电子设备处于未充电状态,则判定所述使用状态信息满足指定条件。Further, the refresh
数据存储模块802,用于如果获取到刷新信息,则根据所述刷新信息将所述缓冲器上的数据写入至存储器上。The
进一步的,数据存储模块802还用于利用电容为所述电子设备供电,并将缓冲器上的数据写入存储器。Further, the
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, for the specific working process of the above-described devices and units, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
在本申请所提供的几个实施例中,模块相互之间的耦合可以是电性,机械或其它形式的耦合。In several embodiments provided in this application, the coupling between the modules may be electrical, mechanical or other forms of coupling.
另外,在本申请各个实施例中的各功能模块可以集成在一个处理模块中,也可以是各个模块单独物理存在,也可以两个或两个以上模块集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist physically alone, or two or more modules may be integrated into one module. The above-mentioned integrated modules can be implemented in the form of hardware, and can also be implemented in the form of software function modules.
请参阅图11,其示出了本申请实施例提供的一种电子设备1000的结构框图。该电子设备1000可以是智能手机、平板电脑、电子书等能够运行应用程序的电子设备。本申请中的电子设备1000可以包括一个或多个如下部件:处理器1010、存储器1020、以及一个或多个应用程序,其中一个或多个应用程序可以被存储在存储器1020中并被配置为由一个或多个处理器1010执行,一个或多个程序配置用于执行如前述方法实施例所描述的方法。Please refer to FIG. 11 , which shows a structural block diagram of an electronic device 1000 provided by an embodiment of the present application. The electronic device 1000 may be an electronic device capable of running an application program, such as a smart phone, a tablet computer, an electronic book, or the like. The electronic device 1000 in the present application may include one or more of the following components: a processor 1010, a memory 1020, and one or more application programs, wherein the one or more application programs may be stored in the memory 1020 and configured by One or more processors 1010 execute, and one or more programs are configured to perform the methods described in the foregoing method embodiments.
处理器1010可以包括一个或者多个处理核。处理器1010利用各种接口和线路连接整个电子设备1000内的各个部分,通过运行或执行存储在存储器1020内的指令、程序、代码集或指令集,以及调用存储在存储器1020内的数据,执行电子设备1000的各种功能和处理数据。可选地,处理器1010可以采用数字信号处理(Digital Signal ProceSSing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器1010可集成中央处理器(Central ProceSSing Unit,CPU)、图像处理器(Graphics ProceSSing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器1010中,单独通过一块通信芯片进行实现。Processor 1010 may include one or more processing cores. The processor 1010 uses various interfaces and lines to connect various parts of the entire electronic device 1000, and executes by running or executing the instructions, programs, code sets or instruction sets stored in the memory 1020, and calling the data stored in the memory 1020. Various functions of the electronic device 1000 and processing data. Optionally, the processor 1010 may use at least one of a digital signal processing (Digital Signal ProceSSing, DSP), a Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), and a Programmable Logic Array (Programmable Logic Array, PLA). A hardware form is implemented. The processor 1010 may integrate one or a combination of a central processing unit (Central ProceSSing Unit, CPU), a graphics processor (Graphics ProceSSing Unit, GPU), a modem, and the like. Among them, the CPU mainly handles the operating system, user interface and application programs, etc.; the GPU is used for rendering and drawing of the display content; the modem is used to handle wireless communication. It can be understood that, the above-mentioned modem may not be integrated into the processor 1010, and is implemented by a communication chip alone.
存储器1020可以包括随机存储器(Random AcceSS Memory,RAM),也可以包括只读存储器(Read-Only Memory)。存储器1020可用于存储指令、程序、代码、代码集或指令集。存储器1020可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现下述各个方法实施例的指令等。存储数据区还可以存储电子设备1000在使用中所创建的数据(比如电话本、音视频数据、聊天记录数据)等。The memory 1020 may include random access memory (Random Access Memory, RAM), or may include read-only memory (Read-Only Memory). Memory 1020 may be used to store instructions, programs, codes, sets of codes, or sets of instructions. The memory 1020 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.) , instructions for implementing the following method embodiments, and the like. The storage data area may also store data (such as phone book, audio and video data, chat record data) created by the electronic device 1000 during use.
在一些实施方式中,电子设备1000还包括信息检测模块,所述信息检测模块用于检测是否获取到刷新信息,所述刷新信息用于指示所述缓冲器被写入元数据或所述电子设备发生异常的至少一种。In some embodiments, the electronic device 1000 further includes an information detection module, and the information detection module is configured to detect whether refresh information is acquired, and the refresh information is used to indicate that metadata is written into the buffer or the electronic device. At least one of the exceptions occurred.
在一些实施方式中,电子设备1000还包括数据存储模块,所述数据存储模块用于如果获取到刷新信息,则根据所述刷新信息将所述缓冲器上的数据写入至存储器上。In some embodiments, the electronic device 1000 further includes a data storage module, and the data storage module is configured to write the data in the buffer to the memory according to the refresh information if the refresh information is obtained.
请参阅图12,其示出了本申请实施例提供的一种计算机可读存储介质2000的结构框图。该计算机可读存储介质2000中存储有程序代码,所述程序代码可被处理器调用执行上述方法实施例中所描述的方法。Please refer to FIG. 12 , which shows a structural block diagram of a computer-readable storage medium 2000 provided by an embodiment of the present application. Program codes are stored in the computer-readable storage medium 2000, and the program codes can be invoked by the processor to execute the methods described in the above method embodiments.
计算机可读存储介质2000可以是诸如闪存、EEPROM(电可擦除可编程只读存储器)、EPROM、硬盘或者ROM之类的电子存储器。可选地,计算机可读存储介质2000包括非易失性计算机可读介质(non-transitory computer-readable storage medium)。计算机可读存储介质2000具有执行上述方法中的任何方法步骤的程序代码2010的存储空间。这些程序代码可以从一个或者多个计算机程序产品中读出或者写入到这一个或者多个计算机程序产品中。程序代码2010可以例如以适当形式进行压缩。The computer-readable storage medium 2000 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 2000 includes a non-transitory computer-readable storage medium. Computer readable storage medium 2000 has storage space for program code 2010 to perform any of the method steps in the above-described methods. The program codes can be read from or written to one or more computer program products. Program code 2010 may be compressed, for example, in a suitable form.
最后应说明的是:以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不驱使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, but not 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: it can still be Modifications are made to the technical solutions described in the foregoing embodiments, or some technical features thereof are equivalently replaced; and these modifications or replacements do not drive the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010251756.9ACN111488315A (en) | 2020-04-01 | 2020-04-01 | Data storage method and device, electronic equipment and readable storage medium |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010251756.9ACN111488315A (en) | 2020-04-01 | 2020-04-01 | Data storage method and device, electronic equipment and readable storage medium |
| Publication Number | Publication Date |
|---|---|
| CN111488315Atrue CN111488315A (en) | 2020-08-04 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010251756.9APendingCN111488315A (en) | 2020-04-01 | 2020-04-01 | Data storage method and device, electronic equipment and readable storage medium |
| Country | Link |
|---|---|
| CN (1) | CN111488315A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113064681A (en)* | 2021-03-09 | 2021-07-02 | 青岛海尔科技有限公司 | System and apparatus, method, and device for refreshing user interface |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101183801A (en)* | 2007-12-07 | 2008-05-21 | 杭州华三通信技术有限公司 | A power failure protection method, system and device |
| CN102929805A (en)* | 2012-10-19 | 2013-02-13 | 浪潮电子信息产业股份有限公司 | Power-down protection method for cache data in memory system |
| CN106933706A (en)* | 2017-03-10 | 2017-07-07 | 联想(北京)有限公司 | The power-off protection method and device of Nonvolatile memory |
| CN109471596A (en)* | 2018-10-31 | 2019-03-15 | 北京小米移动软件有限公司 | Data writing method, apparatus, device and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101183801A (en)* | 2007-12-07 | 2008-05-21 | 杭州华三通信技术有限公司 | A power failure protection method, system and device |
| CN102929805A (en)* | 2012-10-19 | 2013-02-13 | 浪潮电子信息产业股份有限公司 | Power-down protection method for cache data in memory system |
| CN106933706A (en)* | 2017-03-10 | 2017-07-07 | 联想(北京)有限公司 | The power-off protection method and device of Nonvolatile memory |
| CN109471596A (en)* | 2018-10-31 | 2019-03-15 | 北京小米移动软件有限公司 | Data writing method, apparatus, device and storage medium |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113064681A (en)* | 2021-03-09 | 2021-07-02 | 青岛海尔科技有限公司 | System and apparatus, method, and device for refreshing user interface |
| Publication | Publication Date | Title |
|---|---|---|
| US11822805B2 (en) | Method and terminal for reclaiming memory after freezing program | |
| US8392649B2 (en) | Memory storage device, controller, and method for responding to host write commands triggering data movement | |
| JPH04362717A (en) | System restarting device | |
| CN108491058A (en) | A kind of the powered-off fault data guard method and device of Nonvolatile memory | |
| CN111158910A (en) | Memory management method, device, storage medium and electronic device | |
| CN113868023B (en) | Snapshot method and device of storage system, electronic equipment and readable storage medium | |
| CN114579055B (en) | Disk storage method, device, equipment and medium | |
| US7107487B2 (en) | Fault tolerant sleep mode of operation | |
| CN106708960A (en) | Restoration method for file system of NAS device and NAS device | |
| CN111290836A (en) | Virtual machine snapshot creating method and device, storage medium and computer equipment | |
| TW201933091A (en) | A system and a method for testing a data storage device | |
| CN115639971B (en) | Data writing method, data writing device, electronic device, storage medium, and program product | |
| JP5166211B2 (en) | Device using non-volatile memory as main memory | |
| CN111488315A (en) | Data storage method and device, electronic equipment and readable storage medium | |
| US20170160961A1 (en) | Memory management method, memory control circuit unit, and memory storage apparatus | |
| US20130166852A1 (en) | Method for hibernation mechanism and computer system therefor | |
| EP3291092B1 (en) | Data recovery method, device and terminal | |
| CN113345500A (en) | Method and apparatus for recovery management | |
| CN102402464A (en) | Method for erasing and writing data of memory in smart card and smart card | |
| CN114217750B (en) | SSD low power consumption optimization method, SSD low power consumption optimization device, computer equipment and storage medium | |
| CN113687784A (en) | A method, device and electronic device for dual-control switching storage | |
| CN113094294B (en) | SSD abnormal power failure processing method, SSD abnormal power failure processing device, computer equipment and storage medium | |
| TWI891111B (en) | Storage device management method and storage device | |
| US20250036308A1 (en) | Memory management method, memory storage device, and memory control circuit unit | |
| CN119576635A (en) | A method, device, equipment and medium for processing fault information of solid state hard disk |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication | Application publication date:20200804 | |
| RJ01 | Rejection of invention patent application after publication |