Data writing method and device, equipment and storage medium

By dynamically adjusting cache resources and optimizing cache policies, the problem of improving host write and garbage collection write performance in storage devices is solved, and the overall write performance and cache resource efficiency of storage devices are improved without increasing hardware costs.

CN120335710APending Publication Date: 2025-07-18DAPUSTOR CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411944048.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

The data writing performance of existing storage devices is affected by the joint influence of host writes and garbage collection writes, making it difficult to improve overall performance without increasing hardware usage costs.

Method used

By dynamically adjusting the size and type of cache resources, using the preset cache resource adjustment strategy to optimize the host write and garbage collection writing process. First, cache the data into static or dynamic random access storage resources, then store the data into the flash controller cache, and release the cache resources after the programming operation is completed.

Benefits of technology

It improves the host write performance and the overall write performance of storage devices, improves the efficiency of cache resources, and avoids increasing hardware costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120335710A_ABST
    Figure CN120335710A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of storage equipment, and discloses a data writing method and device, equipment and a storage medium. The data writing method comprises the steps of receiving to-be-written first data of a host; based on a preset cache resource adjustment strategy, determining a first cache resource in which the first data is stored; taking the first data as first cache data and storing the first data into the first cache resource; reading the first cache data from the first cache resource and storing the first cache data into a cache of a flash memory controller; releasing the first cache data in the first cache resource; initiating a storage medium write programming operation so as to brush the first cache data in the cache of the flash memory controller to a storage medium; after the programming operation is completed, the management resources in the first cache resources are released. On the premise that the hardware use cost is not increased, the overall write-in performance of the storage device is indirectly improved by improving the write-in performance of the host.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of storage devices, and particularly to a data writing method, apparatus, device and storage medium. Background Art

[0002] A storage device is a component in a computer system or other electronic devices for permanently or temporarily storing data, such as a solid-state drive. Writing data to a non-volatile storage medium (such as NAND) by the storage device mainly includes two paths: the host writes data and the garbage collection writes data. Among them, garbage collection means that the storage device reads the valid data of the original physical space that has been stored and stores it in other physical spaces, and then the original physical space can be released for new data writing only by erasing the original physical space, and this process is the garbage collection of the storage device.

[0003] The data writing performance of existing storage devices is affected by both host writing and garbage collection writing. Although the overall data writing performance of the storage device can be improved by improving the host writing performance or the garbage collection writing performance, the host writing of valid data will occupy physical space, while the garbage collection writing will release physical space, and the two need to be balanced at all times. Therefore, to a certain extent, it limits the improvement of the writing performance of the storage device. In addition, although the OP (Over-Provisioning) size of the storage device can be increased or a higher-performance storage medium can be used, this method will correspondingly increase the hardware usage cost, so it is not a better solution. Summary of the Invention

[0004] The main purpose of the present invention is to provide a data writing method, apparatus, device and storage medium, aiming to solve the technical problem of how to improve the writing performance of a storage device without increasing the hardware usage cost.

[0005] In a first aspect of the present invention, a data writing method is provided, which is applied to a storage device. The data writing method includes:

[0006] Receiving first data to be written by a host;

[0007] Determining a first cache resource for storing the first data based on a preset cache resource adjustment policy;

[0008] Storing the first data as first cache data in the first cache resource;

[0009] Reading the first cache data from the first cache resource and storing it in a flash memory controller cache;

[0010] Releasing the first cache data in the first cache resource;

[0011] Initiate a storage medium write programming operation to flush the first cached data in the flash controller cache to the storage medium;

[0012] After the programming operation is completed, release the management resources in the first cache resource.

[0013] Optionally, in the first implementation manner of the first aspect of the present invention, the data writing method further includes:

[0014] Start garbage collection;

[0015] Scan the mapping table to find the second data in the storage medium to obtain a scan result;

[0016] According to the scan result, issue a read command for the second data;

[0017] Based on the read command, read the second data from the storage medium;

[0018] Based on the cache resource adjustment policy, determine the second cache resource for storing the second data;

[0019] Store the second data as the second cached data in the second cache resource;

[0020] Construct a write command for garbage collection and issue it to the flash controller;

[0021] Read the second cached data from the second cache resource and store it in the flash controller cache;

[0022] Release the second cached data in the second cache resource;

[0023] Initiate a storage medium write programming operation to flush the second cached data in the flash controller cache to the storage medium;

[0024] After the programming operation is completed, release the management resources in the second cache resource.

[0025] Optionally, in the second implementation manner of the first aspect of the present invention, the host write and the garbage collection write share the random access storage resources provided by the storage device, and the random access storage resources include static random access memory resources and dynamic random access memory resources.

[0026] Optionally, in the third implementation manner of the first aspect of the present invention, the first cache resource is static random access memory resources and / or dynamic random access memory resources, and the second cache resource is static random access memory resources and / or dynamic random access memory resources.

[0027] Optionally, in the fourth implementation of the first aspect of the present invention, determining the first cache resource for storing the first data based on the preset cache resource adjustment policy includes:

[0028] Receiving a first cache resource application initiated when the host writes data;

[0029] Determining whether garbage collection has been started currently;

[0030] If garbage collection has not been started currently, determining whether there is unused static random access memory resource;

[0031] If there is unused static random access memory resource currently, determining to store the first data using the static random access memory resource or using the static random access memory resource and the dynamic random access memory resource;

[0032] If there is no unused static random access memory resource currently, determining to store the first data using the dynamic random access memory resource.

[0033] Optionally, in the fifth implementation of the first aspect of the present invention, after determining whether garbage collection has been started currently, it further includes:

[0034] If garbage collection has been started currently, determining to store the first data using the dynamic random access memory resource.

[0035] Optionally, in the sixth implementation of the first aspect of the present invention, determining the second cache resource for storing the second data based on the cache resource adjustment policy includes:

[0036] Receiving a second cache resource application initiated when garbage collection writes data;

[0037] Determining whether there is unused static random access memory resource currently;

[0038] If there is unused static random access memory resource currently, determining to store the second data using the static random access memory resource or using the static random access memory resource and the dynamic random access memory resource;

[0039] If there is no unused static random access memory resource currently, determining to store the second data using the dynamic random access memory resource.

[0040] The second aspect of the present invention provides a data writing device, which is applied to a storage device. The data writing device includes:

[0041] A receiving module, configured to receive first data to be written by a host;

[0042] A determination module, configured to determine a first cache resource for storing the first data based on a preset cache resource adjustment policy;

[0043] A first storage module, configured to store the first data as first cache data in the first cache resource;

[0044] A second storage module, configured to read the first cache data from the first cache resource and store it in a flash controller cache;

[0045] A first release module, configured to release the first cache data in the first cache resource;

[0046] A write module, configured to initiate a storage medium write programming operation to flush the first cache data in the flash controller cache to the storage medium;

[0047] A second release module, configured to release the management resources in the first cache resource after the programming operation is completed.

[0048] Optionally, in the first implementation manner of the second aspect of the present invention, the data writing device further includes:

[0049] A start module, configured to start garbage collection;

[0050] A scan module, configured to scan a mapping table to find second data in a storage medium and obtain a scan result;

[0051] A distribution module, configured to issue a read command for the second data according to the scan result;

[0052] A read module, configured to read the second data from the storage medium based on the read command;

[0053] The determination module is further configured to: determine a second cache resource for storing the second data based on the cache resource adjustment policy;

[0054] The first storage module is further configured to: store the second data as second cache data in the second cache resource;

[0055] A construction module, configured to construct a write command for garbage collection and issue it to a flash controller;

[0056] The second storage module is further configured to: read the second cache data from the second cache resource and store it in a flash controller cache;

[0057] The first release module is further configured to: release the second cache data in the second cache resource;

[0058] The writing module is further configured to: initiate a storage medium write programming operation to flush the second cached data in the flash controller cache to the storage medium;

[0059] The second release module is further configured to: after the programming operation is completed, release the management resources in the second cache resource.

[0060] Optionally, in the second implementation manner of the second aspect of the present invention, the host write and the garbage collection write share the random access storage resources provided by the storage device, and the random access storage resources include static random access memory resources and dynamic random access memory resources.

[0061] Optionally, in the third implementation manner of the second aspect of the present invention, the first cache resource is static random access memory resources and / or dynamic random access memory resources, and the second cache resource is static random access memory resources and / or dynamic random access memory resources.

[0062] Optionally, in the fourth implementation manner of the second aspect of the present invention, the determining module is specifically configured to:

[0063] Initiate a first cache resource application when receiving host write data;

[0064] Determine whether garbage collection has been started currently;

[0065] If garbage collection has not been started currently, determine whether there are unused static random access memory resources;

[0066] If there are unused static random access memory resources currently, determine to use static random access memory resources or use static random access memory resources and dynamic random access memory resources to store the first data;

[0067] If there are no unused static random access memory resources currently, determine to use dynamic random access memory resources to store the first data.

[0068] Optionally, in the fifth implementation manner of the second aspect of the present invention, the determining module is further configured to:

[0069] If garbage collection has been started currently, determine to use dynamic random access memory resources to store the first data.

[0070] Optionally, in the sixth implementation manner of the second aspect of the present invention, the determining module is further configured to:

[0071] Initiate a second cache resource application when receiving garbage collection write data;

[0072] Determine whether there are unused static random access memory resources;

[0073] If there is unused static random access memory resource currently, determine to store the second data by using the static random access memory resource or by using both the static random access memory resource and the dynamic random access memory resource;

[0074] If there is no unused static random access memory resource currently, determine to store the second data by using the dynamic random access memory resource.

[0075] The third aspect of the present invention provides a computer device, including: a memory and at least one processor, wherein instructions are stored in the memory; the at least one processor invokes the instructions in the memory to enable the computer device to execute the above data writing method.

[0076] The fourth aspect of the present invention provides a computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, and when the instructions run on a computer, the computer is enabled to execute the above data writing method.

[0077] In the technical solution provided by the present invention, when the host writes data, first determine the cache resource for caching the data written by the host, and then store the data to be written into the cache resource. The cache resource specifically needs to be determined according to a pre-set cache resource adjustment strategy. The cache resource adjustment strategy is specifically used for dynamically adjusting the cache resource, including adjusting the size and type of the cache resource. The specific cache resource adjustment strategy adopted is related to the environment when the host writes data currently, including whether garbage collection is enabled for writing data and the size and type of the cache resource that can be used currently. The present invention dynamically adjusts the cache resource for caching the data written by the host, thereby achieving the improvement of the host writing performance, and further indirectly improving the overall writing performance of the storage device. In addition, after storing the data to be written by the host into the flash controller cache, the cached data stored in the cache resource is released in advance, thereby improving the use efficiency of the cache resource, and further indirectly improving the speed of the host writing data, and further realizing the double improvement of the host writing performance and the overall writing performance of the storage device. BRIEF DESCRIPTION OF THE DRAWINGS

[0078] Figure 1 It is a schematic diagram of the first embodiment of the data writing method in the embodiment of the present invention;

[0079] Figure 2 It is a schematic diagram of the second embodiment of the data writing method in the embodiment of the present invention;

[0080] Figure 3 It is a schematic diagram of an embodiment of the host writing data in the storage device in the embodiment of the present invention;

[0081] Figure 4Schematic diagram of an embodiment of writing data for garbage collection in the storage device in an embodiment of the present invention;

[0082] Figure 5 Schematic diagram of an embodiment of the data writing device in an embodiment of the present invention;

[0083] Figure 6 Schematic diagram of an embodiment of the computer device in an embodiment of the present invention. Detailed implementation manners

[0084] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the term "comprising" or "having" and any deformation thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0085] For ease of understanding, the specific processes of the embodiments of the present invention are described below. Please refer to Figure 1 The first embodiment of the data writing method in the embodiment of the present invention includes:

[0086] 101. Receive the first data to be written by the host;

[0087] In this embodiment, the host initiates a write request and sends the first data to be written to the storage medium through a communication interface (such as PCIe, USB, SATA, SAS, etc.). The first data can be various forms of data such as files, database records, and log information, and is encapsulated into a specific data packet or data frame for easy transmission.

[0088] When the host sends data packets, the storage device receives these data packets through the communication interface and performs data packet integrity verification during the receiving process to ensure that the data packets are not damaged or lost. The received data packets need to be cached for subsequent processing. The cache resources are usually dynamically allocated by the system to which the storage device belongs (hereinafter referred to as the system) to ensure that data packets of different sizes can be accommodated.

[0089] 102. Determine the first cache resource for storing the first data based on a preset cache resource adjustment strategy;

[0090] To improve the host write performance and thus correspondingly improve the overall performance of the storage device, in this embodiment, after receiving the data sent by the host and before caching, the cache resources for storing the host write data are first determined, specifically determined according to the preset cache resource adjustment policy.

[0091] The cache resource adjustment policy is specifically used to dynamically adjust the cache resources, including adjusting the size and type of the cache resources. Using cache resources of different sizes and different types can affect the host write performance, and thus can be used to improve the host write performance without increasing additional hardware costs.

[0092] The cache resource adjustment policy adopted in this embodiment is specifically related to the environment when the host writes data currently, including whether garbage collection is enabled for writing data and the size and type of the cache resources that can be used currently. In some alternative embodiments, the preset cache resource adjustment policy can also adjust the cache resources based on various factors such as the priority, size, read-write frequency, and idle status of the cache resources of the received data to be written. When receiving the host write data, the system will judge which cache resource the data should be stored in according to this set of policies.

[0093] In this embodiment, before receiving the data, the system loads the preset cache resource adjustment policy. The cache resource adjustment policy is usually stored in the form of a configuration file or a database table, and contains the configuration information and adjustment rules of various cache resources. In addition, to facilitate the better application of the cache resource adjustment policy, in one embodiment, the system also monitors the status of each cache resource in real time, including information such as free space, read-write speed, and access frequency, which can be obtained specifically by periodically querying the cache resource manager or reading the cache resource status register.

[0094] In an alternative embodiment, step 102 above further includes:

[0095] 1021. Receive the first cache resource application initiated when the host writes data;

[0096] When the host needs to write data, a cache resource application (i.e., the first cache resource application) is sent to the system to which the storage device belongs through the system interface. The first cache resource application contains the data to be written by the host, the target address, and possible other metadata. After receiving the cache resource application, the system first performs preliminary processing, including verifying the legality of the application, parsing the information in the application, and preparing for subsequent cache resource applications.

[0097] 1022. Judge whether garbage collection has been started currently;

[0098] Before determining the cache resources, the system needs to determine whether garbage collection is currently in progress. Garbage collection refers to the process in which the storage device reads the valid data in the original physical space that has been stored, stores it in other physical spaces, and then erases the original physical space to release the space for reuse in writing new data. This process is the garbage collection of the storage device. Garbage collection also occupies cache resources. If garbage collection is currently in progress, it will affect the available cache resources. For example, high-performance cache resources such as SRAM may be affected.

[0099] In this alternative embodiment, the system needs to maintain a garbage collection status flag to indicate whether garbage collection is currently in progress. This flag can be implemented through internal variables or a state machine. After receiving a write data request, the system will first check the garbage collection status flag to determine whether garbage collection has been started currently.

[0100] 1023. If garbage collection has not been started currently, then determine whether there is unused static random access memory resource;

[0101] In this alternative embodiment, if garbage collection has not been started currently, it means that the data written by the current host can use the static random access memory resource for caching. The system will further check whether there is unused SRAM resource currently. The system needs to maintain an SRAM resource pool to manage all available SRAM resources in the system. This resource pool can be implemented through data structures (such as linked lists, arrays, etc.).

[0102] After receiving a cache resource application, the system will check the resource situation in the SRAM resource pool, including checking whether there are free SRAM blocks, whether the size of each block meets the requirements of the request, etc. To maximize the use efficiency of SRAM resources, the storage system can design a resource allocation strategy. This resource allocation strategy can determine whether to allocate SRAM resources and how much SRAM resources to allocate according to factors such as the size and priority of the requested data.

[0103] 1024. If there is unused static random access memory resource currently, then determine to store the first data using the static random access memory resource or using the static random access memory resource and the dynamic random access memory resource;

[0104] In this alternative embodiment, if there is unused SRAM resource currently and these resources meet the requirements of the write data request, the system determines to use the SRAM resource to store the data. If the SRAM resource is insufficient, or for other considerations (such as load balancing, resource optimization, etc.), the system can consider using the DRAM resource to cooperate in caching the data written by the host at the same time.

[0105] In this alternative embodiment, the system will determine how much SRAM resource to allocate to the data to be written by the current host according to the result of resource check. If the SRAM resource is sufficient, the system will directly write the data into the SRAM; if the SRAM resource is insufficient, the system will calculate the amount of DRAM resource to be allocated and allocate both SRAM and DRAM resources to store the data. After allocating the resources, the system will store the data into the corresponding SRAM or DRAM according to the target address and data content in the request, and update the status of the SRAM and DRAM resource pools, marking the allocated resources as used, so as to prepare for subsequent data writing.

[0106] 1025. If there is no unused static random access memory resource currently, determine to store the first data using dynamic random access memory resource;

[0107] In this alternative embodiment, if there is no unused SRAM resource currently, or these resources cannot meet the requirement of caching data, the system determines to use DRAM resource to cache the data written by the host. Although the access speed of DRAM is slightly slower than that of SRAM, it has a larger capacity and lower cost.

[0108] Similar to the SRAM resource management, the system also needs to maintain a DRAM resource pool to manage all available DRAM resources in the system. After determining to use DRAM resource, the system will calculate the amount of DRAM resource to be allocated and allocate the corresponding resources from the DRAM resource pool to the current cache resource application. Similar to writing to SRAM, the system will write the data into the corresponding DRAM according to the target address and data content in the request, and update the status of the DRAM resource pool, marking the allocated resources as used.

[0109] 1026. If garbage collection has been started currently, determine to store the first data using dynamic random access memory resource.

[0110] In this alternative embodiment, if garbage collection has been started currently, the system uses DRAM resource to store the data written by the host, giving priority to allocating SRAM resource to the garbage collection writing to improve the garbage collection performance, and thus indirectly improving the host write data performance. The host writing valid data will occupy physical space, while the garbage collection writing will release physical space. The two can maintain the balance between the physical space occupied by the host writing valid data and the physical space released by the garbage collection through the balancing algorithm provided by the system. Therefore, through the balancing algorithm, while improving the garbage collection performance, the host writing performance can also be indirectly improved, so as to achieve the overall performance improvement of the storage device.

[0111] In this alternative embodiment, after receiving a write data request, the system first checks the garbage collection status flag. If the flag indicates that garbage collection is currently in progress, the system determines to use DRAM resources to store the host-written data. Similar to the above steps of using DRAM resources, the system calculates the amount of DRAM resources to be allocated, allocates the corresponding resources from the DRAM resource pool to the current cache resource application, then writes the data into the DRAM according to the target address and data content in the request, and updates the status of the DRAM resource pool.

[0112] 103. Store the first data as the first cache data in the first cache resource;

[0113] In this embodiment, after determining the cache resources for caching the host-written data, the first data written by the host can be stored as the first cache data in the first cache resource.

[0114] In an alternative embodiment, the first cache resource is preferably a static random access memory resource and / or a dynamic random access memory resource.

[0115] (1) Static random access memory resource

[0116] The static random access memory resource adopted in this alternative embodiment is specifically a Static Random-Access Memory (SRAM). SRAM is a type of random access memory, and its "static" characteristic means that as long as the power is maintained, the data stored in it can be constantly retained. The characteristics of SRAM are high-speed access, low power consumption, and high reliability, and it is a main component of the computer system memory.

[0117] (2) Dynamic random access memory resource

[0118] The dynamic random access memory resource adopted in this alternative embodiment is specifically a Dynamic Random Access Memory (DRAM), which is one of the most core and commonly used memory types in a computer system. DRAM is a semiconductor memory that uses the principle of capacitors storing charges to save data. The characteristics of DRAM are fast read and write speed, large capacity, and low cost, and it is a main component of the computer system memory.

[0119] In this alternative embodiment, the first cache resource for caching the host-written data can be SRAM, or DRAM, or a combination of SRAM and DRAM, which is specifically determined by the environment when the host writes data.

[0120] 104. Read the first cache data from the first cache resource and store it in the flash controller cache;

[0121] In this embodiment, before writing the data written by the host into the storage medium, it is necessary to first read the data from the cache resource and store it in the flash controller cache, so as to reduce the number of write operations of the storage medium and improve the efficiency of write operations. The system will determine when to read the data from the cache resource and store it in the flash controller cache according to the characteristics of the flash controller and the optimization strategy of write operations.

[0122] The flash controller cache refers to a buffer for temporarily storing data in a system that uses flash memory. It is usually located between the flash controller and the flash chip and is used to accelerate the data reading and writing processes, reduce the time for the processor to wait for data, and thus improve the overall performance of the system. Through the flash controller cache mechanism, the flash controller can access data faster, reduce the processor waiting time, reduce the latency of data access, and thus improve the overall performance of the system.

[0123] 105. Release the first cache data in the first cache resource;

[0124] In this embodiment, after the data written by the host is successfully written into the flash controller cache, the system can release the first cache data in the first cache resource, so that other data can use the released cache resource and improve the rotation efficiency of the cache resource.

[0125] In this embodiment, the system will send a resource release request to the first cache resource, and the request contains information such as the start address and length of the data to be released. The resource release request can be implemented by calling the resource release function or API provided by the system. The first cache resource will clear the data stored in the first cache data according to the resource release request. The system will update the management information of the cache resource to reflect the state that the first cache data has been released.

[0126] 106. Initiate a storage medium write programming operation to write down the first cache data in the flash controller cache to the storage medium;

[0127] When writing data to the Nand storage medium, the flash controller needs to construct a Program management structure and complete the Program operation. In the Nand Flash storage medium, the write operation is usually called "Program", that is, the programming operation. Flash storage media (such as EPRROM) are generally read-only. Once the data in them needs to be changed, new data needs to be rewritten, that is, Re-Program (re-programming). Therefore, the process of writing to Flash is called Program. In this embodiment, the system will initiate a write programming operation according to the characteristics of the storage medium and the optimization strategy of write operations to write the data (that is, the first cache data) in the flash controller cache to the storage medium.

[0128] 107. After the programming operation is completed, release the management resources in the first cache resource.

[0129] In this embodiment, after the data written by the host is successfully written into the storage medium, the system will release the management resources related to the first cache resource, including releasing the memory, data structures, threads, etc. used to manage the data writing process, thereby ensuring that the system can efficiently run other tasks and improving the utilization efficiency of the cache resource.

[0130] In this embodiment, when the host writes data, first determine the cache resource for caching the data written by the host, and then store the data to be written in this cache resource. The cache resource specifically needs to be determined according to the pre-set cache resource adjustment strategy. The cache resource adjustment strategy is specifically used to dynamically adjust the cache resource, including adjusting the size and type of the cache resource. The specific cache resource adjustment strategy adopted is related to the environment when the host writes data currently, including whether garbage collection is enabled for writing data and the size and type of the cache resource that can be used currently. By dynamically adjusting the cache resource for caching the data written by the host in this embodiment, the writing performance of the host is improved, and thus the overall writing performance of the storage device is indirectly improved. In addition, after storing the data to be written by the host in the flash controller cache, release the cached data in the cache resource in advance, thereby improving the utilization efficiency of the cache resource and further indirectly improving the speed of the host writing data, and thus realizing the double improvement of the host writing performance and the overall writing performance of the storage device.

[0131] Please refer to Figure 2 , Figure 2 This is the second embodiment of the data writing method in the embodiment of the present invention. Compared with the first embodiment, this embodiment illustrates the improvement of the garbage collection writing performance. The data written by the host and the data written by garbage collection are two paths of the storage device writing data. This embodiment can be executed before, after or at the same time as any step in the above first embodiment. In this embodiment, the data writing method further includes:

[0132] 201. Start garbage collection;

[0133] Garbage collection is that the storage device reads the valid data stored in the original physical space and stores it in other physical spaces, and then the original physical space can be released for rewriting only by erasing it. That is, it is necessary to first read the written data from the storage physical space and back it up to other storage spaces, and wait until all backups are completed before performing the erase operation on the physical space and reusing it for new data writing. And this process is the garbage collection of the storage device.

[0134] 202. Scan the mapping table to find the second data in the storage medium to obtain a scan result;

[0135] The mapping table is an important data structure in the storage device for recording the physical locations of data blocks on the storage medium. Performing garbage collection requires scanning the mapping table to identify which data blocks contain valid data and determine the locations of these valid data blocks.

[0136] 203. Issue a read command for the second data according to the scanning result;

[0137] The scanning result contains the locations of all valid data in the storage medium. It is necessary to read out the scanned valid data (i.e., the second data) and transfer it to other locations in the storage medium.

[0138] 204. Read the second data from the storage medium based on the read command;

[0139] 205. Determine the second cache resource for storing the second data based on the cache resource adjustment strategy;

[0140] In this embodiment, the read command contains the location of the data to be read in the storage medium. According to this location, the valid data to be recycled (i.e., the second data) can be read from the storage medium. Before writing the read second data to a new location, the system needs to cache the read valid data. To optimize the use of cache resources, the system needs to adopt a preset cache resource adjustment strategy to determine the best cache resource for storing these data.

[0141] To improve the garbage collection writing performance and thus correspondingly improve the overall performance of the storage device, in this embodiment, after receiving the data read during garbage collection and before caching, the cache resource for storing the data read during garbage collection is determined first, specifically according to the preset cache resource adjustment strategy. The cache resource adjustment strategy is specifically used to dynamically adjust cache resources, including adjusting the size and type of cache resources. Using cache resources of different sizes and types can affect the garbage collection writing performance, and thus can be used to improve the garbage collection writing performance without increasing additional hardware costs.

[0142] The cache resource adjustment strategy adopted in this embodiment is specifically related to the current environment when reading data during garbage collection, including the size and type of cache resources currently available. In some alternative embodiments, the preset cache resource adjustment strategy can also adjust cache resources based on multiple factors such as the priority, size, read / write frequency, and idle situation of the cache resources when reading data during garbage collection. After starting to read data during garbage collection, the system will use this set of strategies to determine which cache resource the data should be stored in.

[0143] In this embodiment, before data caching, the system will load a pre-set cache resource adjustment policy. The cache resource adjustment policy is usually stored in the form of a configuration file or a database table, and contains the configuration information and adjustment rules of various cache resources. In addition, to facilitate the better application of the cache resource adjustment policy, in one embodiment, the system also monitors the status of each cache resource in real time, including information such as free space, read / write speed, access frequency, etc., which can be obtained specifically by periodically querying the cache resource manager or reading the cache resource status register.

[0144] In this embodiment, since garbage collection involves two different processes of reading and rewriting valid data, the read valid data needs to be cached, and the rewritten valid data also needs to be cached before being written to the storage medium, that is, the second cache resource needs to be divided into a read cache resource and a write cache resource. The determination methods of the read cache resource and the write cache resource can both use the cache resource adjustment policy to determine, and the division method of the determined second cache resource is not limited. For example, the second cache resource can be divided proportionally, that is, the second cache resource is equally divided into a read cache resource and a write cache resource.

[0145] In an alternative embodiment, step 205 above further includes:

[0146] 2051. Receive a second cache resource application initiated when garbage collection write data is received;

[0147] When the storage device needs to garbage collect write data, it sends a cache resource application (that is, a second cache resource application) to the system to which the storage device belongs through the system interface. The second cache resource application contains the valid data to be recycled, the target address, and possibly other metadata. After receiving the cache resource application, the system first performs preliminary processing, including verifying the legality of the application, parsing the information in the application, and preparing for subsequent cache resource applications.

[0148] 2052. Determine whether there is unused static random access memory resource currently;

[0149] In this alternative embodiment, before the system determines the cache resource, it needs to check whether there is unused SRAM resource currently. The system needs to maintain an SRAM resource pool for managing all available SRAM resources in the system. This resource pool can be implemented through data structures (such as linked lists, arrays, etc.).

[0150] After receiving a cache resource request, the system checks the resource status in the SRAM resource pool, including checking whether there are free SRAM blocks and whether the size of each block meets the requirements of the request. To maximize the utilization efficiency of SRAM resources, the storage system can design a resource allocation strategy. This resource allocation strategy can determine whether to allocate SRAM resources and how much SRAM resources to allocate based on factors such as the size and priority of the requested data.

[0151] 2053. If there are unused static random access memory resources currently, determine to use static random access memory resources or use static random access memory resources and dynamic random access memory resources to store the second data.

[0152] In this alternative embodiment, if there are unused SRAM resources currently and these resources meet the requirements of caching data, the system determines to use SRAM resources to store data. If the SRAM resources are insufficient, or for other considerations (such as load balancing, resource optimization, etc.), the system can consider using DRAM resources to cooperate with the cache host to write data.

[0153] In this alternative embodiment, the system will determine how much SRAM resources to allocate to the data to be written for current garbage collection according to the result of resource checking. If the SRAM resources are sufficient, the system will directly write the data into the SRAM; if the SRAM resources are insufficient, the system will calculate the amount of DRAM resources to be allocated and allocate SRAM and DRAM resources simultaneously to store the data. After allocating the resources, the system will store the data into the corresponding SRAM or DRAM according to the target address and data content in the request, and update the status of the SRAM and DRAM resource pools, marking the allocated resources as used status to prepare for subsequent data writing.

[0154] 2054. If there are no unused static random access memory resources currently, determine to use dynamic random access memory resources to store the second data.

[0155] In this alternative embodiment, if there are no unused SRAM resources currently, or these resources cannot meet the requirements of caching data, the system determines to use DRAM resources to cache the written data of garbage collection. Although the access speed of DRAM is slightly slower than that of SRAM, it has a larger capacity and lower cost.

[0156] Similar to SRAM resource management, the system also needs to maintain a DRAM resource pool to manage all available DRAM resources in the system. After determining to use DRAM resources, the system calculates the amount of DRAM resources to be allocated and allocates the corresponding resources from the DRAM resource pool to the current cache resource application. Similar to writing to SRAM, the system writes the data into the corresponding DRAM according to the target address and data content in the request, and updates the status of the DRAM resource pool, marking the allocated resources as used.

[0157] 206. Store the second data as second cache data in the second cache resource;

[0158] In this embodiment, after determining the cache resource for caching garbage collection write data, the second data of garbage collection read and write can be stored as second cache data in the second cache resource (including read cache resource and write cache resource).

[0159] In an optional embodiment, the second cache resource is preferably a static random access memory resource and / or a dynamic random access memory resource. In this optional embodiment, the second cache resource for caching garbage collection read data and write data can be SRAM, or DRAM, or a combination of SRAM and DRAM, which is specifically determined by the environment when garbage collection reads data and writes data.

[0160] 207. Construct a write command for garbage collection and send it to the flash memory controller;

[0161] In this embodiment, garbage collection not only involves data reading, but also involves rewriting the read data. Therefore, after storing the valid read data in the second cache, the system needs to construct a write command to rewrite the valid read data to a new location in the storage medium.

[0162] 208. Read the second cache data from the second cache resource and store it in the flash memory controller cache;

[0163] In this embodiment, before rewriting the garbage collection read data to the storage medium, the data needs to be read from the cache resource (i.e., the write cache resource) and stored in the flash memory controller cache first, so as to reduce the number of write operations on the storage medium and improve the efficiency of write operations. The system will determine when to read the data from the cache resource and store it in the flash memory controller cache according to the characteristics of the flash memory controller and the optimization strategy of write operations. Through the flash memory controller cache mechanism, the flash memory controller can access data faster, reduce the processor waiting time, reduce the data access latency, and thus improve the overall performance of the system.

[0164] 209. Release the second cached data in the second cache resource;

[0165] In this embodiment, after the data read and rewritten by garbage collection is successfully written into the flash controller cache, the system can release the second cached data in the second cache resource, so that other data can use the released cache resource, improving the rotation efficiency of the cache resource.

[0166] In this embodiment, the system sends a resource release request to the second cache resource. The request contains information such as the start address and length of the data to be released. The resource release request can be implemented by calling a resource release function or API provided by the system. The second cache resource clears the data stored in the second cached data according to the resource release request. The system updates the management information of the cache resource to reflect the state that the second cached data has been released, such as updating the cache mapping table, marking the second cache resource as available. If the second cached data in the cache resource is no longer needed, it can be deleted from the cache to release space, and at the same time, the statistical information of the cache resource, such as the size of the free space, is updated.

[0167] 210. Initiate a storage medium write programming operation to flush the second cached data in the flash controller cache to the storage medium;

[0168] When writing data to the Nand storage medium, the flash controller needs to construct a Program management structure and complete the Program operation. In the Nand Flash storage medium, the write operation is usually called "Program", that is, the programming operation. Flash storage media (such as EPRROM) are generally read-only. Once the data in them needs to be changed, new data needs to be rewritten, that is, Re-Program (reprogramming). Therefore, the process of writing to Flash is called Program. In this embodiment, the system initiates a write programming operation according to the characteristics of the storage medium and the optimization strategy of the write operation to write the data (that is, the second cached data) in the flash controller cache to the storage medium.

[0169] 211. After the programming operation is completed, release the management resources in the second cache resource.

[0170] In this embodiment, after the data read by garbage collection is successfully rewritten to the storage medium, the system releases the management resources related to the second cache resource, including releasing the memory, data structures, threads, etc. used to manage the data writing process, so as to ensure that the system can efficiently run other tasks and improve the usage efficiency of the cache resource.

[0171] In an alternative embodiment, the host writes and the garbage collection writes share the random access storage resources provided by the storage device. The random access storage resources include static random access memory resources and dynamic random access memory resources. The first cache resource for caching the host write data preferably uses static random access memory resources and / or dynamic random access memory resources, and the second cache resource for caching the garbage collection read data and write data preferably uses static random access memory resources and / or dynamic random access memory resources.

[0172] In this embodiment, when using the cache resources to store data, Sram is used to replace all or part of Dram, thereby improving the host write performance and the garbage collection performance. The host writes and the garbage collection writes can use the Sram resources to cache the data to be written according to the cache resource adjustment strategy, while ensuring the balance between the host writes and the garbage collection writes, improving the performance of the host writes and the garbage collection writes, and thus improving the overall performance of the storage device. In addition, this embodiment further releases the cached data in advance after storing the cached data in the flash controller cache, thereby improving the rotation efficiency of Sram / Dram and ultimately improving the overall performance of the storage device.

[0173] Please refer to Figure 3 , the method flow of writing host data in the storage device SSD in the embodiment of the present invention includes:

[0174] Step 1: The SSD receives a write request from the host;

[0175] Step 2: Place the received write data in SRAM / DRAM, and preferentially store it in the idle SRAM cache to improve performance;

[0176] Step 3: Fetch the write data to the FLC (Flash controller / the aforementioned flash controller) cache data;

[0177] Step 4: After successfully storing the data in the FLC cache, release the cached data in SRAM / DRAM to improve the usage efficiency;

[0178] Step 5: The FLC initiates a write programming to the Nand to write the data down to the Nand;

[0179] Step 6: After the Nand completes the programming, release the relevant management resources.

[0180] The whole process is implemented by software to avoid waste of hardware resources.

[0181] Please refer to Figure 4 , the method flow of garbage collection writing in the storage device SSD in the embodiment of the present invention includes:

[0182] Step 1: After starting GC (Garbage Collection), start scanning the L2P table and P2L table in the mapping table to find valid data;

[0183] Step 2: Issue a valid data read command to Nand according to the scan result;

[0184] Step 3: The FLC (Flash Controller / the aforementioned flash controller) reads the valid data from Nand;

[0185] Step 4: Place the read valid data in the GC read cache;

[0186] Step 5: Move the read valid data to the GC write cache;

[0187] Step 6: Construct a GC write command and issue the write command to the FLC to cache the valid data in the FLC cache;

[0188] Step 7: After successfully storing in the FLC cache, release the valid data in the GC write cache to improve the usage efficiency;

[0189] Step 8: The FLC initiates a write programming to Nand to download the data to Nand;

[0190] Step 9: After Nand completes programming, release the relevant management resources.

[0191] In the above steps, when the programming fails, start re-reading; initiate a Nand read according to the re-read command and repeat the steps 3 - 9 above. The whole process is implemented by software to avoid wasting hardware resources.

[0192] The data writing method in the embodiment of the present invention is described above. Next, the data writing device in the embodiment of the present invention will be described. Please refer to Figure 5 , an embodiment of the data writing device in the embodiment of the present invention includes:

[0193] A receiving module 301, configured to receive first data to be written by a host;

[0194] A determining module 302, configured to determine a first cache resource for storing the first data based on a preset cache resource adjustment strategy;

[0195] A first storing module 303, configured to store the first data as first cache data in the first cache resource;

[0196] A second storing module 304, configured to read the first cache data from the first cache resource and store it in the flash controller cache;

[0197] A first releasing module 305, configured to release the first cache data in the first cache resource;

[0198] A write module 306, configured to initiate a write programming operation on a storage medium to flush the first cached data in the flash controller cache to the storage medium;

[0199] A second release module 307, configured to release the management resources in the first cache resource after the programming operation is completed.

[0200] Optionally, in one embodiment, the data writing device further includes:

[0201] A start module, configured to start garbage collection;

[0202] A scanning module, configured to scan a mapping table to find second data in the storage medium and obtain a scanning result;

[0203] A sending module, configured to send a read command for the second data according to the scanning result;

[0204] A reading module, configured to read the second data from the storage medium based on the read command;

[0205] The determining module is further configured to: determine a second cache resource for storing the second data based on the cache resource adjustment policy;

[0206] The first storing module is further configured to: store the second data as second cached data in the second cache resource;

[0207] A construction module, configured to construct a write command for garbage collection and send it to the flash controller;

[0208] The second storing module is further configured to: read the second cached data from the second cache resource and store it in the flash controller cache;

[0209] The first release module is further configured to: release the second cached data in the second cache resource;

[0210] The write module is further configured to: initiate a write programming operation on the storage medium to flush the second cached data in the flash controller cache to the storage medium;

[0211] The second release module is further configured to: release the management resources in the second cache resource after the programming operation is completed.

[0212] Optionally, in one embodiment, the host write and the garbage collection write share the random access storage resources provided by the storage device, and the random access storage resources include static random access storage resources and dynamic random access storage resources.

[0213] Optionally, in one embodiment, the first cache resource is a static random access memory resource and / or a dynamic random access memory resource, and the second cache resource is a static random access memory resource and / or a dynamic random access memory resource.

[0214] Optionally, in one embodiment, the determining module is specifically configured to:

[0215] Receive a first cache resource application initiated when the host writes data;

[0216] Determine whether garbage collection has been started currently;

[0217] If garbage collection has not been started currently, determine whether there is unused static random access memory resource currently;

[0218] If there is unused static random access memory resource currently, determine to store the first data using the static random access memory resource or using the static random access memory resource and the dynamic random access memory resource;

[0219] If there is no unused static random access memory resource currently, determine to store the first data using the dynamic random access memory resource.

[0220] Optionally, in one embodiment, the determining module is further configured to:

[0221] If garbage collection has been started currently, determine to store the first data using the dynamic random access memory resource.

[0222] Optionally, in one embodiment, the determining module is further configured to:

[0223] Receive a second cache resource application initiated when garbage collection writes data;

[0224] Determine whether there is unused static random access memory resource currently;

[0225] If there is unused static random access memory resource currently, determine to store the second data using the static random access memory resource or using the static random access memory resource and the dynamic random access memory resource;

[0226] If there is no unused static random access memory resource currently, determine to store the second data using the dynamic random access memory resource.

[0227] Since the embodiments of the device part correspond to the embodiments of the above method, the introduction of the data writing device provided by the present invention may refer to the above method embodiments, and the present invention will not be elaborated herein again, and it has the same beneficial effects as the above data writing method.

[0228] AboveFigure 5 The data writing device in the embodiment of the present invention is described in detail from the perspective of modular functional entities. Next, the computer device in the embodiment of the present invention is described in detail from the perspective of hardware processing.

[0229] Figure 6 FIG. is a schematic structural diagram of a computer device provided by an embodiment of the present invention. The computer device 500 may vary greatly due to different configurations or performances, and may include one or more central processing units (CPUs) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) for storing application programs 533 or data 532. Among them, the memory 520 and the storage media 530 may be transient storage or persistent storage. The program stored in the storage media 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the computer device 500. Further, the processor 510 may be configured to communicate with the storage media 530 and execute a series of instruction operations in the storage media 530 on the computer device 500.

[0230] The computer device 500 may further include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input / output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, FreeBSD, and so on. Those skilled in the art can understand that Figure 6 The shown computer device structure does not limit the computer device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0231] The present invention further provides a computer device, which includes a memory and a processor. When the computer-readable instructions stored in the memory are executed by the processor, the processor executes the steps of the data writing method in the above embodiments.

[0232] The present invention further provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions run on a computer, the computer executes the steps of the data writing method.

[0233] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.

[0234] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

[0235] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A data writing method, applied to a storage device, characterized in that The data writing method includes: Receiving first data to be written by a host; Determining a first cache resource for storing the first data based on a preset cache resource adjustment policy; Storing the first data as first cache data in the first cache resource; Reading the first cache data from the first cache resource and storing it in a flash controller cache; Releasing the first cache data in the first cache resource; Initiating a storage medium write programming operation to write down the first cache data in the flash controller cache to the storage medium; After the programming operation is completed, releasing the management resources in the first cache resource.

2. The data writing method according to claim 1, wherein, The data writing method further includes: Starting garbage collection; Scanning a mapping table to find second data in the storage medium to obtain a scanning result; Issuing a read command for the second data according to the scanning result; Reading the second data from the storage medium based on the read command; Determining a second cache resource for storing the second data based on the cache resource adjustment policy; Storing the second data as second cache data in the second cache resource; Constructing a write command for garbage collection and issuing it to the flash controller; Reading the second cache data from the second cache resource and storing it in the flash controller cache; Releasing the second cache data in the second cache resource; Initiating a storage medium write programming operation to write down the second cache data in the flash controller cache to the storage medium; After the programming operation is completed, releasing the management resources in the second cache resource.

3. The data writing method according to claim 2, wherein The host write and the garbage collection write share the random access storage resources provided by the storage device, and the random access storage resources include static random access memory resources and dynamic random access memory resources.

4. The data writing method according to claim 3, wherein The first cache resource is static random access memory resources and / or dynamic random access memory resources, and the second cache resource is static random access memory resources and / or dynamic random access memory resources.

5. The data writing method according to claim 4, wherein The determining the first cache resource for storing the first data based on the preset cache resource adjustment policy includes: Receiving a first cache resource application initiated when the host writes data; Judging whether garbage collection has been started currently; If garbage collection has not been started currently, judging whether there are unused static random access memory resources currently; If there are unused static random access memory resources currently, determining to store the first data using static random access memory resources or using static random access memory resources and dynamic random access memory resources; If there are no unused static random access memory resources currently, determining to store the first data using dynamic random access memory resources.

6. The data writing method according to claim 5, wherein After the judging whether garbage collection has been started currently, it further includes: If garbage collection has been started currently, determining to store the first data using dynamic random access memory resources.

7. The data writing method according to claim 4, wherein The determining the second cache resource for storing the second data based on the cache resource adjustment policy includes: Receiving a second cache resource application initiated when garbage collection writes data; Judging whether there are unused static random access memory resources currently; If there are unused static random access memory resources currently, determine to use the static random access memory resources or use both the static random access memory resources and the dynamic random access memory resources to store the second data; If there are no unused static random access memory resources currently, determine to use the dynamic random access memory resources to store the second data.

8. A data writing device, applied to a storage device, characterized in that The data writing device includes: a receiving module, configured to receive first data to be written by a host; a determining module, configured to determine a first cache resource for storing the first data based on a preset cache resource adjustment policy; a first storing module, configured to store the first data as first cache data in the first cache resource; a second storing module, configured to read the first cache data from the first cache resource and store it in a flash controller cache; a first releasing module, configured to release the first cache data in the first cache resource; a writing module, configured to initiate a storage medium write programming operation to flush the first cache data in the flash controller cache to the storage medium; a second releasing module, configured to release the management resources in the first cache resource after the programming operation is completed.

9. A computer device, characterized in that, The computer device includes: a memory and at least one processor, and instructions are stored in the memory; The at least one processor invokes the instructions in the memory so that the computer device executes the data writing method according to any one of claims 1-7.

10. A computer-readable storage medium, on which instructions are stored, characterized in that, When the instructions are executed by the processor, the data writing method according to any one of claims 1-7 is implemented.