Data writing method and device, electronic equipment and readable storage medium
By distinguishing data types and selecting appropriate storage space, traditional UFS and Zone UFS have solved the problem of low data writing efficiency in traditional UFS and Zone UFS, and efficient data writing operations and storage space management are achieved.
Patent Information
- Application Number
- CN202510070488.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-05-02
AI Technical Summary
Traditional UFS and Zone UFS have performance issues in file system operation and storage management, resulting in inefficient data writing.
By receiving write instructions, the data type (hot data, warm data or cold data) is determined and written to the corresponding storage space. Hot data writing supports the first type of storage space covered by writing, and warm data writing supports the second type of storage space sequentially written.
It improves the writing efficiency of hot data, reduces the fragmentation of storage space, optimizes the storage efficiency of warm data and cold data, and reduces unnecessary write operations.
Smart Images

Figure CN119917025A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of electronic equipment, and specifically relates to a data writing method, device, electronic equipment and readable storage medium. Background Art
[0002] Universal Flash Storage (UFS) is the flash storage specification currently used by mobile phones. Traditional UFS is a black box for the file system, and the file system cannot control the internal operations of UFS, especially the execution time of garbage collection. This leads to performance problems if UFS happens to perform garbage collection when the upper layer is preparing to write data, affecting the overall performance and response speed of the system.
[0003] Zone UFS came into being. Zone UFS is a new UFS firmware specification that moves firmware-side functions to the system side to achieve autonomous control of the storage. However, on the one hand, Zone UFS only allows sequential writes within a single zone, and does not allow random writes. This limitation makes the file system face greater challenges when handling random write operations, which may lead to performance degradation. On the other hand, Zone UFS is not compatible with the overwrite write behavior of traditional UFS, but requires additional space application. This will cause a significant decline in the performance of Zone UFS when there is insufficient space.
[0004] Therefore, traditional UFS and Zone UFS have many problems in file system operation and storage management, which affect the data writing efficiency. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a data writing method, device, electronic device and readable storage medium, which can solve the problem of low data writing efficiency in the prior art.
[0006] In a first aspect, an embodiment of the present application provides a data writing method, the method comprising:
[0007] receiving a write instruction for first data;
[0008] Determine, according to the write instruction, a data type of the first data, where the data type of the first data is used to indicate a modification frequency of the first data;
[0009] When the data type of the first data is hot data, writing the first data into a first type storage space of a file system, wherein the first type storage space supports overwriting data at a write address of already written data;
[0010] When the data type of the first data is warm data or cold data, the first data is written into a second type of storage space of the file system, and the second type of storage space supports writing data at a write address where no data is written.
[0011] In a second aspect, an embodiment of the present application provides a data writing device, the method comprising:
[0012] A receiving module, used for receiving a write instruction for first data;
[0013] a determination module, configured to determine a data type of the first data according to the write instruction, wherein the data type of the first data is used to indicate a modification frequency of the first data;
[0014] a first writing module, configured to write the first data into a first type of storage space of a file system when the data type of the first data is hot data, wherein the first type of storage space supports overwriting the written data at a write address of the written data;
[0015] The second writing module is used to write the first data into a second type of storage space of the file system when the data type of the first data is warm data or cold data, and the second type of storage space supports writing data at a write address where no data is written.
[0016] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.
[0017] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0018] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.
[0019] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the first aspect.
[0020] In an embodiment of the present application, a write instruction for first data is received; according to the write instruction, the data type of the first data is determined, and the data type of the first data is used to indicate the modification frequency of the first data; when the data type of the first data is hot data, the first data is written into the first type of storage space of the file system, and the first type of storage space supports overwriting the written data at the write address of the written data; the first type of storage space is suitable for frequently modified data, because it can directly overwrite the existing data address without moving or reallocating the storage space, thereby improving the writing efficiency of hot data and reducing the fragmentation of the storage space. When the data type of the first data is warm data or cold data, the first data is written into the second type of storage space of the file system, and the second type of storage space supports writing data at the write address of the unwritten data. The second type of storage space is suitable for data with low access frequency, because it is not necessary to frequently overwrite the existing data, so it can optimize the storage efficiency of warm data and cold data and reduce unnecessary write operations. Therefore, by distinguishing the data type and selecting the appropriate storage space, the write operation can be optimized according to the modification frequency of the data, thereby improving the data writing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a schematic diagram of a current data writing process provided by an embodiment of the present application;
[0022] Figure 2 is a flow chart of a data writing method provided by an embodiment of the present application;
[0023] Figure 3 is a schematic diagram of another data writing method provided in an embodiment of the present application;
[0024] Figure 4 is a structural diagram of a data writing device provided in an embodiment of the present application;
[0025] Figure 5 It is one of the hardware structure diagrams of the electronic device according to the embodiment of the present application;
[0026] Figure 6 This is the second schematic diagram of the hardware structure of the electronic device according to the embodiment of the present application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings of the embodiments of the present application to clearly describe the technical solutions of the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present application belong to the scope of protection of this application.
[0028] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0029] The technical terms involved in the embodiments of the present application are explained below:
[0030] Universal Flash Storage (UFS) is the flash storage specification currently used mainly in mobile phones.
[0031] Zone UFS: A new UFS firmware specification that moves firmware-side functions to the system side, allowing the system to control the storage autonomously. In terms of implementation, it is divided into two areas: CUFS and ZUFS. CUFS is the traditional UFS, which supports random writes and IPU; ZUFS is Zone UFS, which only supports sequential writes.
[0032] Cluster Unified File System (CUFS), a cluster refers to a cluster system consisting of multiple computing nodes or servers. Unified means that the file system provides consistent file access and management on all nodes in the cluster. File system: responsible for the storage, management and access of files. Cluster Unified File System is usually used in large-scale distributed computing environments to provide high availability, high performance and data consistency.
[0033] Zone-based Unified File System (ZUFS) refers to a file system that divides storage space into multiple zones, each of which can be managed independently. Zone-based unified file systems are usually used in scenarios that require flexible storage management and efficient resource utilization, and each zone can independently manage and optimize data.
[0034] Random write: If the logical block address at which a write operation starts is adjacent to the logical block address at which the previous write operation ends, then this operation is a sequential write;
[0035] Sequential write: If the logical block address at the start of a write operation is not immediately adjacent to the logical block address at the end of the previous write operation, that is, if the logical block addresses are discrete, it is a random write.
[0036] Meta data: Metadata refers to the area that stores file system attributes and maintains file system-related data structures.
[0037] Segment: The basic unit of traditional UFS operations, with a size of 2M.
[0038] Zone: It is the basic unit of Zone UFS operation. Its size depends on the manufacturer's implementation and is generally hundreds of times the size of a segment.
[0039] Garbage Collection (GC) refers to the act of recycling dirty data in the storage system.
[0040] In-place Update (IPU) means that when writing data, no additional space is requested, but the data is overwritten on the old data.
[0041] Outplace Update (OPU) means that when writing data, additional space needs to be applied for, the data is written in the applied space, and the old data is made dirty.
[0042] The data writing method provided in the embodiment of the present application can be applied to at least the following application scenarios, which are described below.
[0043] Traditional UFS is a storage technology widely used in mobile devices and embedded systems, providing high-speed data reading and writing capabilities. However, traditional UFS is similar to a black box for the file system. The file system cannot directly control the internal operations of UFS, especially the execution timing of garbage collection (GC). This opacity causes performance problems if UFS happens to perform GC operations when the file system is preparing to write data at the upper layer, affecting the overall performance and response speed of the system.
[0044] In order to solve the performance problem of traditional UFS, Zone UFS technology came into being. Zone UFS moves the internal operations of the firmware to the system side, remains transparent to the file system, and enables the file system to better control storage operations. Zone UFS has the advantages of controllable latency, excellent random read and write performance, and large available space.
[0045] However, Zone UFS only allows sequential writing within a single zone, not random writing, which places high demands on the order of IO delivery. In addition, Zone UFS is not compatible with the IPU (In-Place Update) behavior of traditional UFS, which directly overwrites dirty data and requires additional space application, which will cause a significant decline in the performance of Zone UFS when there is insufficient space.
[0046] The smallest storage unit of Zone UFS is a zone, which is hundreds of times larger than the smallest unit of traditional UFS, segment. This larger storage unit will lead to lower efficiency of garbage collection (GC) when there is insufficient space. Since GC operations need to move a large amount of data, a larger storage unit means that each GC operation involves a larger amount of data, which increases GC time and system overhead, further affecting system performance.
[0047] like Figure 1 As shown, the current data writing process first needs to determine whether the data can be written in place. If it cannot be written in place, the garbage collection program will be entered. If it can be written in place, but Zone UFS does not support in-place writing, SSR mode cannot be performed.
[0048] In response to the problems arising in the related art, the embodiments of the present application provide a data writing method, device, electronic device and storage medium, which can solve the problem of low data writing efficiency in the related art.
[0049] The data writing method provided in the embodiment of the present application is described in detail below through specific embodiments and application scenarios in conjunction with the accompanying drawings.
[0050] Figure 2 A flowchart of a data writing method provided in an embodiment of the present application.
[0051] like Figure 2 As shown, the data writing method may include steps 210 to 240, and the method is applied to a data writing device, as shown below:
[0052] Step 210, receiving a write instruction for first data;
[0053] A write instruction is received, which indicates that first data needs to be written into the file system.
[0054] Step 220: determining a data type of the first data according to the write instruction, where the data type of the first data is used to indicate a modification frequency of the first data;
[0055] According to the information in the write instruction or other context information, it is determined whether the first data is hot data, warm data or cold data. The determination of the data type is usually based on the access frequency and modification frequency of the data. A suitable storage strategy can be selected according to the data type.
[0056] Step 230: When the data type of the first data is hot data, write the first data into a first type of storage space of the file system, wherein the first type of storage space supports overwriting the written data at the write address of the written data;
[0057] Hot data refers to data that is frequently accessed and modified. It is usually the most active part of the system and needs to be read and written quickly. It is characterized by high access frequency and high modification frequency.
[0058] The file system is the structure and method used by the operating system to manage files and directories on storage devices. It is responsible for the storage, retrieval, update and deletion of files, and provides a mechanism for organizing, storing and accessing data.
[0059] The first type of storage space refers to the area in the file system that is specifically used to store hot data. The first type of storage space usually supports efficient overwrite operations and supports direct overwrite of the address of written data, which is suitable for frequently modified data.
[0060] If the first data is hot data, the system writes it to the first type of storage space that supports overwrite writing. This type of storage space is suitable for frequently modified data because it can be directly overwritten on the existing data address without moving or reallocating storage space. This improves the writing efficiency of hot data and reduces the fragmentation of storage space.
[0061] Step 240: When the data type of the first data is warm data or cold data, write the first data into a second type of storage space of the file system, wherein the second type of storage space supports writing data at a write address where no data is written.
[0062] Warm data refers to data that is accessed less frequently but still needs to maintain a certain level of activity. This data may be accessed or modified occasionally, but not as frequently as hot data. It is characterized by medium access frequency and medium modification frequency.
[0063] Cold data refers to data that is accessed very infrequently. This data may not be accessed or modified for a long time and is usually archived or backed up. It is characterized by low access frequency and low modification frequency.
[0064] The second type of storage space refers to the area in the file system used to store warm and cold data. These areas usually support sequential write operations. They support sequential writes on addresses where no data has been written, and are suitable for data with low access frequency.
[0065] If the first data is warm data or cold data, it is written to the second type of storage space that supports sequential writing. This type of storage space is suitable for data with low access frequency because new data can be written sequentially without frequently overwriting existing data. It can optimize the storage efficiency of warm data and cold data and reduce unnecessary write operations.
[0066] Therefore, by distinguishing data types and selecting appropriate storage space, write operations can be optimized according to the access and modification frequency of data, thereby improving the overall write efficiency. Hot data uses the first type of storage space that supports overwrite writes, which can reduce the fragmentation of storage space and maintain efficient use of storage space. Warm data and cold data use the second type of storage space that supports sequential writes, which can optimize the allocation of storage resources, avoid frequent overwrite write operations, and extend the service life of storage devices. Through reasonable data storage strategies, it is possible to better cope with the access and modification requirements of different types of data, thereby improving the overall system performance and response speed. By storing cold data in storage space with a lower access frequency, the frequent access and write operations of storage devices can be reduced, thereby reducing storage costs.
[0067] In summary, by intelligently selecting the appropriate storage strategy based on the data type, the storage efficiency is optimized, the storage resources are reasonably allocated, and the system performance is improved.
[0068] like Figure 3 As shown, in a possible embodiment, step 240 includes:
[0069] Step 310: When the data type of the first data is warm data or cold data, determine the storage space occupied by the first data and the remaining storage capacity of the file system;
[0070] Step 320, when the remaining storage capacity of the file system is greater than or equal to the storage space occupied by the first data, determine a first write address in the second type storage space where no data is written;
[0071] Step 330: write the first data into a first write address of the second type storage space.
[0072] In addition, step 320 may also be: when the remaining storage capacity of the file system is greater than the storage space occupied by the first data, determining a first write address in the second type storage space where no data is written.
[0073] The storage space occupancy refers to the size of the physical space occupied by the first data on the storage device. It is usually measured in bytes and reflects the actual occupancy of the data on the storage device.
[0074] Remaining storage capacity refers to the size of the storage space that has not been occupied in the file system. It indicates the available space in the file system that can be used to store new data. It reflects the storage resource availability of the file system.
[0075] First, it is determined whether the data type of the first data is warm data or cold data. If so, the system further calculates the size of the space occupied by the first data on the storage device, that is, the storage space occupancy, and checks the remaining available storage space in the file system, that is, the remaining storage capacity. The storage space required for the first data and the available storage resources of the file system can be understood to prepare for subsequent write operations.
[0076] The first write address refers to the starting address for writing the first data in the second type of storage space. This address is usually the first available address of the unoccupied storage space. Ensure that data can be written in sequence to avoid overwriting existing data.
[0077] Check whether the remaining storage capacity of the file system is sufficient to accommodate the first data. If sufficient, search for unoccupied storage space in the second type of storage space and determine the first available write address, that is, the first write address. Ensure that the file system has sufficient space to store the first data and find a suitable write location to avoid overwriting existing data.
[0078] The first data is sequentially written to the first write address of the second type of storage space. Since the second type of storage space supports sequential writing, the system can directly write the data to the unoccupied address found without complicated address management. The first data can be efficiently written to the file system to ensure the integrity of the data and the rational use of the storage space.
[0079] By calculating the storage space occupied by the first data and the remaining storage capacity of the file system, the system can ensure that the write operation is performed when there is enough space, avoiding write failures due to insufficient space. Writing data in sequence in the second type of storage space avoids complex address management and data overwriting operations, and improves writing efficiency. By determining the first write address of unwritten data, the system ensures that new data will not overwrite existing data, maintaining data integrity and consistency.
[0080] Sequential write operations help reduce storage space fragmentation, maintain efficient use of storage space, and extend the life of storage devices. Through reasonable storage space management and write strategies, the system can better cope with the storage needs of different types of data and improve system reliability and stability.
[0081] Therefore, by accurately calculating the storage space occupancy and remaining storage capacity and writing data in sequence, optimal utilization of storage space, improved writing efficiency and enhanced system reliability are achieved.
[0082] In a possible embodiment, after step 310, the following steps may also be included:
[0083] Step 340, when the remaining storage capacity of the file system is less than the storage space occupied by the first data, determine the storage space occupied by the invalid data stored in the file system;
[0084] Step 350, determining the occupancy ratio of the invalid data according to the storage space occupied by the invalid data and the total capacity of the file system;
[0085] Step 360: Determine the write address of the first data in the second type of storage space according to the storage space occupation ratio of the invalid data.
[0086] When data needs to be updated, the new data is written to a new location in the memory. The old data is not deleted immediately, but marked as dirty data. This means that the dirty data has been replaced by the new data, but still exists in the memory. The dirty data is not deleted immediately, but waits for garbage collection (GC) to clear it. GC will reclaim the storage space occupied by the dirty data at the appropriate time.
[0087] Dirty data usually refers to old, useless data generated during the data update process. Dirty data has been replaced by new data and therefore no longer has practical use value. Dirty data is useless in the current system and is no longer needed by the system or application. Therefore, dirty data can also be called invalid data.
[0088] The occupancy ratio refers to the ratio of invalid data to the total capacity of the file system. It reflects the occupancy of invalid data on the file system storage resources. It is used to evaluate the impact of invalid data on the file system storage resources.
[0089] The write address refers to a specific address in the second type of storage space for writing the first data. This address is usually determined based on the proportion of invalid data occupied. This ensures that data can be written as needed to avoid overwriting existing data.
[0090] Step 340: If the remaining storage capacity of the file system is insufficient to accommodate the first data, the system further checks the storage space occupied by invalid data in the file system. Invalid data is usually data that has not yet completed persistent storage and may still be in the cache or being written. It is possible to understand the occupancy of the file system storage resources by invalid data, providing a basis for determining the subsequent write address.
[0091] Involving step 350: calculating the proportion of invalid data in the total capacity of the file system. This proportion reflects the degree of occupancy of the file system storage resources by invalid data. It can evaluate the impact of invalid data on the file system storage resources and provide a reference for the subsequent determination of the write address.
[0092] Involving step 360: determining the write address of the first data in the second type of storage space according to the occupancy ratio of the invalid data. This address is usually dynamically determined according to the occupancy ratio of the invalid data to ensure that the data can be written on demand and avoid overwriting the existing data. The storage space can be reasonably allocated to ensure that the first data can be written smoothly while avoiding overwriting the invalid data.
[0093] By calculating the storage space occupied by invalid data and its proportion, the system can allocate storage space more reasonably, ensuring that the first data can be written smoothly while avoiding overwriting invalid data. The write address is dynamically determined according to the proportion of invalid data occupied, avoiding complex address management and data overwriting operations, and improving writing efficiency.
[0094] By properly allocating write addresses, new data will not overwrite invalid data, maintaining data integrity and consistency. Dynamically allocating write addresses helps reduce storage space fragmentation, maintain efficient use of storage space, and extend the life of storage devices. Through reasonable storage space management and write strategies, the system can better cope with the storage needs of different types of data and improve system reliability and stability.
[0095] Therefore, by calculating the storage space occupied and the occupied ratio of invalid data and dynamically determining the write address, the storage space is optimally allocated, the write efficiency is improved, and the system reliability is enhanced.
[0096] In a possible embodiment, step 360 includes:
[0097] When the proportion of storage space occupied by the invalid data is less than a preset proportion, determining a first write address where no data is written in the second type of storage space;
[0098] The first write address is determined as a write address of the first data in the second type storage space.
[0099] In addition, step 360 may also include: when the proportion of storage space occupied by the invalid data is less than or equal to a preset proportion, determining a first write address of unwritten data in the second type of storage space; and determining the first write address as the write address of the first data in the second type of storage space.
[0100] The preset ratio refers to the maximum allowable ratio of invalid data in the total capacity of the file system, which is preset by the system. This ratio is used to determine whether invalid data has caused excessive occupation of file system storage resources. It is used to control the occupation of file system storage resources by invalid data to ensure the normal operation of the system.
[0101] First, check whether the storage space occupied by invalid data is less than the preset ratio. If it is less than the preset ratio, it means that the invalid data occupies an acceptable range of the file system storage resources. The system can search for unoccupied storage space in the second type of storage space and determine the first available write address, i.e., the first write address. This ensures that the invalid data occupies a controllable range of the file system storage resources, avoiding storage resource shortages caused by excessive invalid data.
[0102] If the storage space occupied by invalid data is less than the preset ratio, the system determines the first write address found as the write address of the first data in the second type of storage space. This address is usually the first available address of the unoccupied storage space. This ensures that the first data can be written in order to avoid overwriting existing data and improve writing efficiency.
[0103] By checking the storage space occupied by invalid data, the system can ensure that the invalid data occupies a controllable range of the file system storage resources, thereby optimizing the allocation of storage space. When the storage space occupied by invalid data is less than the preset ratio, the system can directly determine the first write address and write the first data to the address, avoiding complex address management and data overwriting operations and improving writing efficiency. By reasonably allocating write addresses, the system ensures that new data will not overwrite invalid data, maintaining data integrity and consistency.
[0104] Dynamically allocating write addresses helps reduce storage space fragmentation, maintain efficient use of storage space, and extend the life of storage devices. Through reasonable storage space management and write strategies, the system can better cope with the storage needs of different types of data and improve system reliability and stability.
[0105] Therefore, by checking the storage space occupied by invalid data and dynamically determining the write address, the storage space is optimally allocated, the write efficiency is improved, and the system reliability is enhanced.
[0106] In another possible embodiment, step 360 includes:
[0107] When the proportion of storage space occupied by the invalid data is greater than a preset proportion, determining a second write address in the second type of storage space;
[0108] clearing invalid data in the second write address;
[0109] The first data is written into a second write address of the second type storage space.
[0110] The second write address refers to a specific address in the second type of storage space for writing the first data. This address is usually determined based on the storage space occupied by invalid data, and may need to be cleared before use. Ensure that data can be written on demand to avoid overwriting existing data.
[0111] First, check whether the storage space occupied by invalid data is greater than the preset ratio. If it is greater than the preset ratio, it means that the invalid data has occupied more than the acceptable range of the file system storage resources, and the system needs to find a suitable address in the second type of storage space, that is, the second write address, for writing the first data. Ensure that the invalid data's occupation of the file system storage resources is within a controllable range to avoid storage resource shortages caused by excessive invalid data.
[0112] After determining the second write address, the system needs to clear the invalid data in the address. Invalid data is usually data that has not yet completed persistent storage. It may still be in the cache or in the process of being written, but has not yet completed the final persistent storage. Being able to clear invalid data and free up storage space ensures that the first data can be written smoothly.
[0113] After clearing the invalid data in the second write address, the system writes the first data to the address. This address is usually the first available address of the unoccupied storage space. Ensure that the first data can be written in sequence to avoid overwriting existing data and improve writing efficiency.
[0114] By checking the storage space occupied by invalid data, the system can ensure that the invalid data's occupation of the file system's storage resources is within a controllable range, thereby optimizing the allocation of storage space. If the storage space occupied by invalid data is greater than the preset ratio, the system can clear the invalid data and determine the second write address, and write the first data to the address, thus avoiding complex address management and data overwriting operations and improving write efficiency.
[0115] By properly allocating write addresses, the system ensures that new data will not overwrite invalid data, maintaining data integrity and consistency. Dynamically allocating write addresses helps reduce storage space fragmentation, maintain efficient use of storage space, and extend the life of storage devices. Through reasonable storage space management and write strategies, the system can better cope with the storage needs of different types of data and improve system reliability and stability.
[0116] Therefore, by checking the storage space occupation ratio of invalid data and dynamically determining the write address, the storage space is optimally allocated, the write efficiency is improved, and the system reliability is enhanced.
[0117] In an embodiment of the present application, a write instruction for first data is received; according to the write instruction, the data type of the first data is determined, and the data type of the first data is used to indicate the modification frequency of the first data; when the data type of the first data is hot data, the first data is written into the first type of storage space of the file system, and the first type of storage space supports overwriting the written data at the write address of the written data; the first type of storage space is suitable for frequently modified data, because it can directly overwrite the existing data address without moving or reallocating the storage space, thereby improving the writing efficiency of hot data and reducing the fragmentation of the storage space. When the data type of the first data is warm data or cold data, the first data is written into the second type of storage space of the file system, and the second type of storage space supports writing data at the write address of the unwritten data. The second type of storage space is suitable for data with low access frequency, because it is not necessary to frequently overwrite the existing data, so it can optimize the storage efficiency of warm data and cold data and reduce unnecessary write operations. Therefore, by distinguishing the data type and selecting the appropriate storage space, the write operation can be optimized according to the modification frequency of the data, thereby improving the data writing efficiency.
[0118] The data writing method provided in the embodiment of the present application can be executed by a data writing device. In the embodiment of the present application, the data writing device provided in the embodiment of the present application is described by taking the data writing method executed by the data writing device as an example.
[0119] Figure 4 4 is a block diagram of a data writing device provided in an embodiment of the present application, the device 400 includes:
[0120] The receiving module 410 is used to receive a write instruction for the first data;
[0121] A determination module 420, configured to determine a data type of the first data according to the write instruction, where the data type of the first data is used to indicate a modification frequency of the first data;
[0122] A first writing module 430, configured to write the first data into a first type of storage space of a file system when the data type of the first data is hot data, wherein the first type of storage space supports overwriting the written data at a write address of the written data;
[0123] The second writing module 440 is used to write the first data into a second type of storage space of the file system when the data type of the first data is warm data or cold data, and the second type of storage space supports writing data at a write address where no data is written.
[0124] In a possible embodiment, the second writing module 440 is specifically configured to:
[0125] In a case where the data type of the first data is warm data or cold data, determining a storage space occupied by the first data and a remaining storage capacity of the file system;
[0126] When the remaining storage capacity of the file system is greater than or equal to the storage space occupied by the first data, determining a first write address in the second-type storage space where no data is written;
[0127] The first data is written into a first write address of the second type storage space.
[0128] In a possible embodiment, the determination module 420 is further configured to determine the storage space occupied by the invalid data stored in the file system when the remaining storage capacity of the file system is less than the storage space occupied by the first data;
[0129] The determination module 420 is further used to determine the occupancy ratio of the invalid data according to the storage space occupied by the invalid data and the total capacity of the file system;
[0130] The determination module 420 is further configured to determine a write address of the first data in the second type of storage space according to the storage space occupation ratio of the invalid data.
[0131] In a possible embodiment, the determination module 420 is specifically configured to:
[0132] When the proportion of storage space occupied by the invalid data is less than a preset proportion, determining a first write address where no data is written in the second type of storage space;
[0133] The first write address is determined as a write address of the first data in the second type storage space.
[0134] In a possible embodiment, the determination module 420 is specifically configured to:
[0135] When the proportion of storage space occupied by the invalid data is greater than a preset proportion, determining a second write address in the second type of storage space;
[0136] clearing invalid data in the second write address;
[0137] The first data is written into a second write address of the second type storage space.
[0138] In an embodiment of the present application, a write instruction for first data is received; according to the write instruction, the data type of the first data is determined, and the data type of the first data is used to indicate the modification frequency of the first data; when the data type of the first data is hot data, the first data is written into the first type of storage space of the file system, and the first type of storage space supports overwriting the written data at the write address of the written data; the first type of storage space is suitable for frequently modified data, because it can directly overwrite the existing data address without moving or reallocating the storage space, thereby improving the writing efficiency of hot data and reducing the fragmentation of the storage space. When the data type of the first data is warm data or cold data, the first data is written into the second type of storage space of the file system, and the second type of storage space supports writing data at the write address of the unwritten data. The second type of storage space is suitable for data with low access frequency, because it is not necessary to frequently overwrite the existing data, so it can optimize the storage efficiency of warm data and cold data and reduce unnecessary write operations. Therefore, by distinguishing the data type and selecting the appropriate storage space, the write operation can be optimized according to the modification frequency of the data, thereby improving the data writing efficiency.
[0139] The data writing device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., and the embodiment of the present application is not specifically limited.
[0140] The data writing device of the embodiment of the present application may be a device having an action system. The action system may be an Android action system, an iOS action system, or other possible action systems, which are not specifically limited in the embodiment of the present application.
[0141] The data writing device provided in the embodiment of the present application can implement each process implemented in the above method embodiment, and will not be described again here to avoid repetition.
[0142] Alternatively, if Figure 5 As shown, an embodiment of the present application also provides an electronic device 510, including a processor 511, a memory 512, and a program or instruction stored in the memory 512 and executable on the processor 511. When the program or instruction is executed by the processor 511, each step of any of the above-mentioned data writing method embodiments is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0143] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
[0144] Figure 6 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0145] The electronic device 600 includes but is not limited to: a radio frequency unit 601, a network module 602, an audio output unit 603, an input unit 604, a sensor 605, a display unit 606, a user input unit 607, an interface unit 608, a memory 609, and a processor 610.
[0146] Those skilled in the art will appreciate that the electronic device 600 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 610 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0147] The processor 610 is configured to receive a write instruction for the first data;
[0148] The processor 610 is further configured to determine a data type of the first data according to the write instruction, where the data type of the first data is used to indicate a modification frequency of the first data;
[0149] A memory 609, configured to write the first data into a first type of storage space of a file system when the data type of the first data is hot data, wherein the first type of storage space supports overwriting the written data at a write address of the written data;
[0150] The memory 609 is further configured to write the first data into a second type of storage space of the file system when the data type of the first data is warm data or cold data, wherein the second type of storage space supports writing data at a write address where no data has been written.
[0151] Optionally, the processor 610 is further configured to determine a storage space occupied by the first data and a remaining storage capacity of the file system when the data type of the first data is warm data or cold data;
[0152] The processor 610 is further configured to determine a first write address of unwritten data in the second-type storage space when the remaining storage capacity of the file system is greater than or equal to the storage space occupied by the first data;
[0153] The memory 609 is further configured to write the first data into a first write address of the second type storage space.
[0154] Optionally, the processor 610 is further configured to determine the storage space occupied by the invalid data stored in the file system when the remaining storage capacity of the file system is less than the storage space occupied by the first data;
[0155] The processor 610 is further configured to determine an occupation ratio of the invalid data according to an occupation amount of the storage space of the invalid data and a total capacity of the file system;
[0156] The processor 610 is further configured to determine a write address of the first data in the second type of storage space according to a storage space occupation ratio of the invalid data.
[0157] Optionally, the processor 610 is further configured to determine a first write address of unwritten data in the second type storage space when the proportion of storage space occupied by the invalid data is less than a preset proportion;
[0158] The processor 610 is further configured to determine the first write address as a write address of the first data in the second type storage space.
[0159] Optionally, the processor 610 is further configured to determine a second write address in the second type of storage space when the proportion of storage space occupied by the invalid data is greater than a preset proportion;
[0160] The processor 610 is further configured to clear invalid data in the second write address;
[0161] The memory 609 is further configured to write the first data into a second write address of the second type storage space.
[0162] In an embodiment of the present application, a write instruction for first data is received; according to the write instruction, the data type of the first data is determined, and the data type of the first data is used to indicate the modification frequency of the first data; when the data type of the first data is hot data, the first data is written into the first type of storage space of the file system, and the first type of storage space supports overwriting the written data at the write address of the written data; the first type of storage space is suitable for frequently modified data, because it can directly overwrite the existing data address without moving or reallocating the storage space, thereby improving the writing efficiency of hot data and reducing the fragmentation of the storage space. When the data type of the first data is warm data or cold data, the first data is written into the second type of storage space of the file system, and the second type of storage space supports writing data at the write address of the unwritten data. The second type of storage space is suitable for data with low access frequency, because it is not necessary to frequently overwrite the existing data, so it can optimize the storage efficiency of warm data and cold data and reduce unnecessary write operations. Therefore, by distinguishing the data type and selecting the appropriate storage space, the write operation can be optimized according to the modification frequency of the data, thereby improving the data writing efficiency.
[0163] It should be understood that in the embodiment of the present application, the input unit 604 may include a graphics processor (Graphics Processing Unit, GPU) 6041 and a microphone 6042, and the graphics processor 6041 processes the image data of the static picture or video image obtained by the image capture device (such as a camera) in the video image capture mode or the image capture mode. The display unit 606 may include a display panel 6061, and the display panel 6061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 607 includes at least one of a touch panel 6071 and other input devices 6072. The touch panel 6071 is also called a touch screen. The touch panel 6071 may include two parts: a touch detection device and a touch controller. Other input devices 6072 may include, but are not limited to, a physical keyboard, a function key (such as a volume control button, a switch button, etc.), a trackball, a mouse, and an action rod, which will not be repeated here. The memory 609 can be used to store software programs and various data, including but not limited to applications and action systems. The processor 610 may integrate an application processor and a modem processor, wherein the application processor mainly processes the action system, user pages and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor 610.
[0164] The memory 609 can be used to store software programs and various data. The memory 609 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 609 may include a volatile memory or a non-volatile memory, or the memory x09 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 609 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0165] The processor 610 may include one or more processing units; optionally, the processor 610 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 610.
[0166] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned data writing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0167] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0168] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned data writing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0169] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0170] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned data writing method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0171] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0172] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0173] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A data writing method, characterized in that: The method comprises: receiving a write instruction for first data; Determine, according to the write instruction, a data type of the first data, where the data type of the first data is used to indicate a modification frequency of the first data; When the data type of the first data is hot data, writing the first data into a first type storage space of a file system, wherein the first type storage space supports overwriting data at a write address of already written data; When the data type of the first data is warm data or cold data, the first data is written into a second type of storage space of the file system, and the second type of storage space supports writing data at a write address where no data is written.
2. The method according to claim 1, characterized in that When the data type of the first data is warm data or cold data, writing the first data into the second type storage space of the file system includes: In a case where the data type of the first data is warm data or cold data, determining a storage space occupied by the first data and a remaining storage capacity of the file system; When the remaining storage capacity of the file system is greater than or equal to the storage space occupied by the first data, determining a first write address in the second-type storage space where no data is written; The first data is written into a first write address of the second type storage space.
3. The method according to claim 2, characterized in that The method further comprises: In a case where the remaining storage capacity of the file system is less than the storage space occupied by the first data, determining the storage space occupied by the invalid data stored in the file system; Determining the occupancy ratio of the invalid data according to the storage space occupied by the invalid data and the total capacity of the file system; The write address of the first data in the second type of storage space is determined according to the storage space occupation ratio of the invalid data.
4. The method according to claim 3, characterized in that The determining, according to the storage space occupation ratio of the invalid data, the write address of the first data in the second type of storage space includes: When the proportion of storage space occupied by the invalid data is less than a preset proportion, determining a first write address where no data is written in the second type of storage space; The first write address is determined as a write address of the first data in the second type storage space.
5. The method according to claim 3, characterized in that: The determining, according to the storage space occupation ratio of the invalid data, the write address of the first data in the second type of storage space includes: When the proportion of storage space occupied by the invalid data is greater than a preset proportion, determining a second write address in the second type of storage space; clearing invalid data in the second write address; The first data is written into a second write address of the second type storage space.
6. A data writing device, characterized in that: The device comprises: A receiving module, used for receiving a write instruction for first data; a determination module, configured to determine a data type of the first data according to the write instruction, wherein the data type of the first data is used to indicate a modification frequency of the first data; a first writing module, configured to write the first data into a first type of storage space of a file system when the data type of the first data is hot data, wherein the first type of storage space supports overwriting the written data at a write address of the written data; The second writing module is used to write the first data into a second type of storage space of the file system when the data type of the first data is warm data or cold data, and the second type of storage space supports writing data at a write address where no data is written.
7. The device according to claim 6, characterized in that The second writing module is specifically used for: In a case where the data type of the first data is warm data or cold data, determining a storage space occupied by the first data and a remaining storage capacity of the file system; When the remaining storage capacity of the file system is greater than or equal to the storage space occupied by the first data, determining a first write address in the second-type storage space where no data is written; The first data is written into a first write address of the second type storage space.
8. The device according to claim 7, characterized in that The determining module is further configured to determine the storage space occupied by the invalid data stored in the file system when the remaining storage capacity of the file system is less than the storage space occupied by the first data; The determination module is further used to determine the occupancy ratio of the invalid data according to the storage space occupied by the invalid data and the total capacity of the file system; The determination module is further configured to determine a write address of the first data in the second type of storage space according to a storage space occupation ratio of the invalid data.
9. The device according to claim 8, characterized in that The determining module is specifically used for: When the proportion of storage space occupied by the invalid data is less than a preset proportion, determining a first write address where no data is written in the second type of storage space; The first write address is determined as a write address of the first data in the second type storage space.
10. The device according to claim 8, characterized in that The determining module is specifically used for: When the proportion of storage space occupied by the invalid data is greater than a preset proportion, determining a second write address in the second type of storage space; clearing invalid data in the second write address; The first data is written into a second write address of the second type storage space.
11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the method according to any one of claims 1 to 5 are implemented.
12. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.