Control method for electronic device, electronic device, and storage medium
By updating the actual storage capacity of the super block when the newly opened segment instruction, the storage capacity mismatch caused by bad blocks in the ZNS file system is solved, extending the device life and improving performance and efficiency.
Patent Information
- Application Number
- PCT/CN2024/100210
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-11-29
- Filing Date
- 2024-06-19
- Publication Date
- 2025-08-14
AI Technical Summary
In the ZNS file system, due to bad blocks of storage devices, the storage capacity that the file system can use does not match the storage capacity provided by the storage device, which affects the device life and performance.
By actively obtaining the reserved storage capacity of the super block when the newly opened section instruction is in, the processor actively obtains the reserved storage capacity of the super block, and updates the actual storage capacity of the newly opened section of the ZNS file system, ensuring that the actual storage capacity provided by the super block is consistent with the storage capacity that the file system can use, and avoiding the solution of replacing bad blocks with good blocks.
It extends the service life of storage devices, improves the performance and efficiency of storage devices, and reduces data reading delay and SRAM resource consumption.
Smart Images

Figure CN2024100210_14082025_PF_FP_ABST
Abstract
Description
Electronic device control method, electronic device, and storage medium
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on November 29, 2023, with application number 202311615067.1 and application name “Control method of electronic device, electronic device and storage medium”, all contents of which are incorporated by reference into this application. Technical Field
[0002] The embodiments of the present application relate to the field of storage technology, and in particular to a control method for an electronic device, an electronic device, and a storage medium. Background Art
[0003] The zoned namespace (ZNS) file system is a new type of file system. In a ZNS file system, storage devices are divided into zones, each containing a fixed number of logical blocks. The ZNS file system allows data to be written sequentially within each zone without addressing or erasing entire blocks, thereby reducing write amplification, extending the lifespan of storage devices, and providing higher write performance. However, bad blocks may occur during the production and use of storage devices, resulting in a mismatch between the storage capacity available to the ZNS file system and the storage capacity provided by the storage device.
[0004] Summary of the Invention
[0005] Embodiments of the present application provide a control method for an electronic device, an electronic device, and a storage medium, for improving the problem of mismatch between the storage capacity available to a file system and the storage capacity provided by a storage device due to bad blocks.
[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, a control method for an electronic device is provided, the electronic device including a processor and a storage device, the processor and the storage device being coupled, a partition namespace ZNS file system being deployed on the processor, the method comprising: the processor sending a new segment opening instruction to the storage device, wherein the new segment opening instruction includes data read and write pressure, the data read and write pressure referring to the workload borne by the ZNS file system when processing input and output operations, the storage device determining a first super block based on the data read and write pressure, and sending a reserved area storage capacity of the first super block to the processor, the reserved area storage capacity referring to a portion of the storage capacity that the storage device cannot provide to the ZNS file system due to factors such as bad blocks; wherein the super block is composed of storage blocks at the same physical position of different flash memory chips of the storage device, the super block contains K bad blocks, K being an integer greater than zero, and the processor updating the default storage capacity of the newly opened segment of the ZNS file system to the actual storage capacity of the first super block, the actual storage capacity being the difference between the default storage capacity and the reserved area storage capacity of the first super block.
[0008] The control method of the electronic device provided by the present application updates the storage capacity that can be actually used by its segment by actively obtaining the reserved area storage capacity of the super block by the processor when a new segment instruction is issued, thereby ensuring that the storage capacity actually provided by the super block is always consistent with the storage capacity that can be used by the ZNS file system. Compared with the solution of selecting available good blocks from the resource pool to replace the bad blocks in the super block when bad blocks appear in the super block, this solution is limited by the number of available good blocks in the resource pool. When the number of available good blocks in the resource pool is small or there are no available good blocks, it will result in the inability to replace the bad blocks in the super block, and the service life of the super block will be directly exhausted, resulting in a gradual decrease in the number of available super blocks, thereby increasing the risk of failure of the storage device. The solution provided by the embodiment of the present application no longer needs to be replaced by available good blocks when bad blocks appear in the super block. Therefore, the number of super blocks is no longer limited by the number of available good blocks in the resource pool, and the life of the super block is gradually exhausted as the number of bad blocks increases, delaying the decreasing trend of the number of super blocks and extending the service life of the storage device. And because the number of bad blocks no longer affects the number of super blocks, the storage device can still be used normally even if the number of bad blocks exceeds the maximum threshold requirement of the storage device.
[0009] In one possible embodiment, determining a super block based on data read and write pressure includes: if the data read and write pressure is greater than or equal to a pressure threshold, determining a super block whose number of bad blocks is less than or equal to the number threshold and is in an idle state as the first super block; if the data read and write pressure is less than the pressure threshold, determining a super block whose number of bad blocks is greater than the number threshold and is in an idle state as the first super block.
[0010] The control method of the electronic device provided in the present application uses the data read and write pressure faced by the file system as the judgment condition for screening the first super block when a new segment is opened, so that the storage device can flexibly select super blocks containing different numbers of bad blocks according to the data read and write pressure, thereby meeting the performance requirements of the file system under different conditions.
[0011] In one possible implementation, updating the default storage capacity of a newly created section of the ZNS file system to the actual storage capacity includes:
[0012] According to the storage capacity of the reserved area, the pointing position of the write pointer of the newly opened segment is moved from the pointing position of the default storage capacity to the pointing position of the actual storage capacity.
[0013] In a possible implementation, the method further includes: the processor sending a query instruction to the storage device in response to power-on of the storage device, and the storage device sending the reserved area storage capacity of each super block to the processor in response to the query instruction.
[0014] In one possible embodiment, after sending the reserved area storage capacity of each super block to the processor, the method further includes: the processor determines the source super block and the target super block based on the reserved area storage capacity of each super block, the processor sends a garbage collection instruction containing the identification information of the source super block and the target super block to the storage device, and the storage device responds to the garbage collection instruction and moves the data stored in the source super block to the target super block.
[0015] In one possible implementation, determining the source super block and the target super block includes: the processor determines the effective data ratio of each super block in a non-idle state based on the reserved area storage capacity and the effective data storage capacity, and determines the source super block from the super blocks in the non-idle state based on the effective data ratio; the processor determines the actual storage capacity of each super block in an idle state based on the reserved area storage capacity, and determines the target super block from the super blocks in the idle state based on the size relationship between the actual storage capacity of the super block in the idle state and the effective data storage capacity of the source super block.
[0016] The control method of the electronic device provided in the present application uses the storage capacity of the reserved area as a judgment condition for screening the source super block and the target super block when performing the garbage collection operation, thereby reducing the probability of using a super block with a smaller actual storage capacity as the source super block, thereby improving the garbage collection efficiency of the storage device and the utilization rate of the storage capacity.
[0017] In a second aspect, the present application provides an electronic device comprising a processor and a storage device, the processor being coupled to the storage device, a ZNS file system being deployed in the processor, and the processor being configured to: send a new segment opening instruction to the storage device, wherein the new segment opening instruction includes data read / write pressure determined by the processor, and update the default storage capacity of the newly opened segment of the ZNS file system to the actual storage capacity, where the actual storage capacity is the difference between the default storage capacity and the reserved area storage capacity. The storage device is configured to: determine a first super block based on the data read / write pressure, and send the reserved area storage capacity of the first super block to the processor; wherein the super block is composed of storage blocks in the same physical location of different flash memory chips of the storage device, and the super block contains K bad blocks, where K is an integer greater than zero.
[0018] In one possible embodiment, the storage device is specifically configured as follows: if the data read and write pressure is greater than or equal to the pressure threshold, a super block with a number of bad blocks less than or equal to the number threshold and in an idle state is determined as the first super block; if the data read and write pressure is less than the pressure threshold, a super block with a number of bad blocks greater than the number threshold and in an idle state is determined as the first super block.
[0019] In a possible implementation, the processor is specifically configured to: move the position pointed to by the write pointer of the newly opened segment from the position pointed to by the default storage capacity to the position pointed to by the actual storage capacity according to the storage capacity of the reserved area.
[0020] In one possible implementation, the processor is further configured to send a query instruction to the storage device in response to the storage device being powered on, and the storage device is further configured to send the reserved area storage capacity of each super block to the processor in response to the query instruction.
[0021] In one possible embodiment, the processor is further configured to: determine the source super block and the target super block based on the reserved area storage capacity of each super block, and send a garbage collection instruction containing identification information of the source super block and the target super block to the storage device; the storage device is further configured to: move the data stored in the source super block to the target super block in response to the garbage collection instruction.
[0022] In one possible embodiment, the processor is specifically configured to: determine the effective data ratio of each super block in a non-idle state based on the reserved area storage capacity and the effective data storage capacity, and determine the source super block from the super block in the non-idle state based on the effective data ratio; determine the actual storage capacity of each super block in the idle state based on the reserved area storage capacity; and determine the target super block from the super block in the idle state based on the size relationship between the actual storage capacity of the super block in the idle state and the effective data storage capacity of the source super block.
[0023] In a third aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer-executable instructions; after the computer-executable instructions are executed, any one of the methods in the first aspect above can be implemented.
[0024] It can be understood that the technical effects of the second to third aspects can refer to the technical effects of the first aspect and any of its embodiments, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] FIG1 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;
[0026] FIG2 is a schematic diagram of the correspondence between the ZNS file system and the storage device provided in an embodiment of the present application;
[0027] FIG3 is a schematic diagram of the structure of a storage device provided in an embodiment of the present application;
[0028] FIG4 is a schematic diagram of a bad block replacement process according to an embodiment of the present application;
[0029] FIG5 is a schematic diagram of another bad block replacement process provided by an embodiment of the present application;
[0030] FIG6 is a flow chart of a method for controlling an electronic device according to an embodiment of the present application;
[0031] FIG7 is a schematic diagram of a process for updating the storage capacity of a newly opened segment according to an embodiment of the present application;
[0032] FIG8 is a flow chart of another method for controlling an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and claims of the present application, the singular expressions "a", "a", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two). The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0034] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized. The term "connected" includes direct and indirect connections, unless otherwise stated.
[0035] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the quantity of the technical features indicated. Therefore, a feature specified as "first" or "second" may explicitly or implicitly include one or more of the features.
[0036] In the embodiments of this application, words such as "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplarily" or "for example" is intended to present the relevant concepts in a concrete manner.
[0037] The file system is a crucial component of the operating system of electronic devices, such as terminals, servers, and virtual machines (VMs). It is a set of abstract data types that implement operations such as data storage, hierarchical organization, access, and retrieval. The file system provides a standard system call interface for applications installed on electronic devices. By invoking this standard system call interface, applications can perform operations such as creating, deleting, reading, and writing data on storage devices.
[0038] In one implementation, the electronic device may be a terminal device, a server, or a virtual machine (VM). The terminal device may be a mobile phone, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook computer, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) or virtual reality (VR) device, etc. The embodiments of the present application do not impose any particular restrictions on the specific form of the electronic device.
[0039] For example, Figure 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. As shown in Figure 1, the electronic device may include: a processor 110, an external memory interface 120, a storage device 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195, etc.
[0040] It is understood that the structure shown in FIG1 does not constitute a specific limitation on the electronic device of the embodiments of the present application. In other embodiments, the electronic device may include more or fewer components than those shown in FIG1, or combine or separate certain components, or arrange the components differently. The components shown in FIG1 may be implemented in hardware, software, or a combination of software and hardware. The embodiments of the present application do not limit the specific structure of the electronic device.
[0041] In one possible implementation, the file system can be a flash-friendly (F2F) ZNS file system. In a ZNS file system, partitions are divided into zones, sections, and segments based on their storage capacity. A zone's storage capacity refers to the total storage space available on a storage device. A zone can include at least one section, and a section can include at least one segment.
[0042] For an example, the correspondence between the ZNS file system and storage devices can be seen in Figure 2. In the ZNS file system, a storage area includes N sectors, each of which includes M segments. Storage device 121 includes N superblocks. A superblock is composed of storage blocks in the same physical location on different flash memory chips in the storage device. The number of superblocks matches the number of sectors. Furthermore, a superblock is the smallest unit of operation for performing operations such as data writing, data overwriting, and garbage collection on the storage device. M and N are positive integers.
[0043] In one possible implementation, referring to FIG3 , storage device 121 includes a storage controller 1211 and memory 1212. Memory 1212 may include M flash memory chips (dies), each die being an independent concurrent unit, and each flash memory chip may include N memory blocks (blocks). To improve performance, a memory block is typically taken from each flash memory chip to form a superblock, such as superblock 1 and superblock N in FIG3 . All memory blocks that make up a superblock can operate concurrently, and the superblock serves as the minimum operation unit on the memory side. The superblock size remains unchanged during subsequent operations.
[0044] The ZNS file system requires that each superblock on a storage device have the same storage capacity, meaning that each superblock contains the same number of storage blocks. Since ZNS file system extents correspond to storage device superblocks, it is also necessary to ensure that the available storage capacity of each extent is equal to the storage capacity provided by the storage device's superblock.
[0045] For example, the ZNS file system contains N segments, which are numbered 1-N, and the storage device contains N superblocks, which are numbered 1-N. The storage capacity of the segment numbered 1 and the superblock numbered 1 are the same, both P. The storage capacity of any other numbered superblock must also be the same as the storage capacity of the superblock numbered 1, which is also P.
[0046] Since bad blocks may appear in the storage device, a bad block refers to a storage area in the storage device that cannot be erased or written. The appearance of bad blocks will cause the storage capacity actually provided by the super block to the file system to be reduced, making the storage capacity that can be actually used by the segment on the file system side different from the storage capacity provided by the super block on the storage device side.
[0047] There are two types of bad blocks in storage devices: one is a storage block that is damaged at the factory stage, namely a factory bad block (FBB); the other is a storage block that is damaged during the use of the storage device due to reaching the end of its service life, namely a grown bad block (GBB).
[0048] The storage capacity of different super blocks needs to be consistent. In some feasible implementations, remapping can be used to ensure that the storage capacity of each super block is consistent. The remapping process is: when a bad block appears on a super block, the logical address of the bad block is mapped to the physical address of a spare block, so that the ZNS file system can still read and write data normally.
[0049] For example, referring to Figure 4, when a storage block on flash chip Die5 in Super Block 1 becomes a bad block, a spare block is first selected from the free resource pool on flash chip Die5. The free resource pool contains all available good blocks on flash chip Die5 that are in an idle state. Any good block can be used as a spare block. The spare block is used to replace the bad block, and a mapping table entry is used to store the mapping relationship between the spare block and the bad block it replaces, thus making Super Block 1 logically a complete Super Block.
[0050] When the free resource pool has a sufficient number of free good blocks to complete the replacement of bad blocks, the super block can be guaranteed to have the ability to handle bad blocks. However, when the free resource pool does not have a sufficient number of free good blocks, the bad blocks in the super block cannot be replaced, causing the size of the super block to be inconsistent with other super blocks, and thus causing the super block to fail.
[0051] For example, referring to FIG5 , when the replacement of the storage block located in flash chip Die5 in Super Block 1 is completed and the storage block located in flash chip Die3 in Super Block 1 becomes a bad block, a spare block is first selected from the free resource pool on flash chip Die3. However, since there are no free good blocks available on flash chip Die3 to replace the bad block, the free resource pool is empty. Since the storage capacity of each Super Block must be consistent, Super Block 1 can no longer be used. The entire Super Block 1 is then marked as a bad block, and the other available good blocks in Super Block 1 are stored as free good blocks in the free resource pool.
[0052] Remapping can ensure that the size of each superblock is consistent, thereby ensuring that the actual storage capacity of the segments on the ZNS file system side is the same as the storage capacity provided by the superblock on the storage device side. However, there are several disadvantages:
[0053] First, the number of Super Blocks in a storage device is limited by the Flash Die with the fewest free good blocks. If other Flash Dies have many free good blocks, but a particular Flash Die has fewer or zero free good blocks, the number of Super Blocks will continue to decrease because it can no longer replace bad blocks. Consequently, the entire storage device will be unable to meet normal usage requirements due to the low number of available Super Blocks.
[0054] For example, referring to Figure 5, the number of good blocks available in an idle state on flash memory chip Die3 is 0, while there are still many good blocks available in an idle state on flash memory chip Die1, flash memory chip Die2, flash memory chip Die4, and flash memory chip Die6. Since flash memory chip Die3 no longer has the ability to replace bad blocks, for any super block, once its storage block located in flash memory chip Die3 becomes a bad block, the super block becomes invalid. Therefore, using the remapping method, the actual storage capacity provided by the super block is always a fixed value P. When the bad block can no longer be replaced, the actual storage capacity provided by the super block becomes 0.
[0055] Second: As the storage capacity of consumer-grade storage devices continues to increase, the number of dies and storage blocks also continues to increase. Therefore, the probability that storage blocks at the same position in different dies are good blocks at the same time is greatly reduced. As a result, the workload of remapping continues to increase, which in turn causes the remap table entries that store the mapping relationship between spare blocks and the bad blocks they replace to occupy more space, thereby leading to insufficient static random-access memory (SRAM) resources inside the controller.
[0056] Third: When reading data, since the mapping relationship between the spare block and the bad block it replaces needs to be determined through the mapping relationship table entry, it takes more time to complete the data reading, so the data reading latency becomes higher.
[0057] An embodiment of the present application provides a control method for an electronic device, in which, when a new segment is instructed to be opened, the ZNS file system actively obtains the reserved area storage capacity of the super block, where the reserved area storage capacity refers to a portion of the storage capacity that the storage device cannot provide to the ZNS file system due to factors such as bad blocks, and updates the storage capacity that can be actually used for the newly opened segment based on the reserved area storage capacity, thereby ensuring that the storage capacity actually provided by the super block is always consistent with the storage capacity that can be used by the ZNS file system.
[0058] The control method of the electronic device of the present application will be described in detail below.
[0059] Referring to FIG6 , the flow of the control method is as follows:
[0060] S601: The processor sends a new segment opening instruction to the storage device, where the new segment opening instruction includes data read and write pressure.
[0061] When the currently available segments can no longer meet the storage requirements for newly written data, a new segment creation instruction is triggered. After the new segment creation instruction is triggered, the ZNS file system needs to prepare a new segment for data storage. First, the ZNS file system can use detection tools to monitor the current data read / write pressure in real time. Data read / write pressure refers to the workload the ZNS file system bears when processing input and output operations. For example, data read / write pressure can be measured by the number of I / O requests processed by the ZNS file system per unit time. The greater the number of I / O requests, the greater the data read / write pressure. The data read / write pressure is then inserted as a parameter into the new segment creation instruction sent by the processor to the storage device. The data read / write pressure serves as the basis for selecting superblocks that match the newly created segment, thereby ensuring that the storage device can meet the current performance requirements of the ZNS file system.
[0062] S602: The storage device determines a first super block according to data read and write pressure, and sends a reserved area storage capacity of the first super block to the processor.
[0063] After receiving the new segment opening instruction, the storage device first parses it to obtain the data read and write pressure faced by the ZNS file system at this time. Then the storage device needs to use the data read and write pressure as the screening basis and select the first super block that matches the current data read and write pressure from multiple available super blocks.
[0064] It is understandable that different data read / write pressures match superblocks with different numbers of bad blocks, and the specific matching criteria need to be determined based on the comparison result of the data read / write pressure and the pressure threshold.
[0065] In a possible implementation, the specific steps of determining the first super block according to data read / write pressure include:
[0066] S6021: If the data read / write pressure is greater than or equal to the pressure threshold, a super block in which the number of bad blocks is less than or equal to the number threshold and is in an idle state is determined as the first super block.
[0067] S6022: If the data read / write pressure is less than the pressure threshold, a super block having a number of bad blocks greater than the number threshold and in an idle state is determined as a first super block.
[0068] When the ZNS file system faces extremely high data read and write pressure, reaching or exceeding the pressure threshold, the ZNS file system requires high stability for the performance of the storage device. For example, when stress testing the storage device or processing large amounts of sequential data writes, the storage device must have a large bandwidth and high bandwidth stability to ensure that the system can efficiently handle data read and write requests. Therefore, Super Blocks with relatively few bad blocks or no bad blocks can be selected as the first Super Block.
[0069] On the contrary, when the data read and write pressure is lower than the pressure threshold, it means that the ZNS file system does not have high requirements for performance stability, and therefore does not have high requirements for the bandwidth size and bandwidth stability of the storage device. Therefore, a super block with a relatively large number of bad blocks can be selected as the first super block.
[0070] For example, the number of bad blocks in Super Block A may be 1, the number of bad blocks in Super Block B may be 3, the number of bad blocks in Super Block C may be 5, and the number of bad blocks in Super Block D may be 10. The first threshold may be 0.5, and the number threshold may be 4. If the storage data read / write pressure faced by the ZNS file system is greater than or equal to 0.5, then any one of Super Block A and Super Block B may be selected as the first Super Block to match the newly opened segment. If the data read / write pressure faced by the ZNS file system is less than 0.5, then any one of Super Block C and Super Block D may be selected as the first Super Block to match the newly opened segment.
[0071] After determining the first Super Block that matches the newly opened segment, the storage device needs to obtain the reserved storage capacity of the first Super Block. The reserved storage capacity refers to the storage capacity occupied by the storage device itself and cannot be provided to the ZNS file system. Due to the existence of the reserved storage capacity, the storage device cannot provide its full storage capacity to the ZNS file system, resulting in a discrepancy between the actual storage capacity provided by the Super Block and the storage capacity available to the ZNS file system.
[0072] The reserved area storage capacity can be composed of multiple parts. For example, the reserved area storage capacity can include but is not limited to three parts. The first part is the storage capacity occupied by bad blocks. The bad block storage capacity refers to the total storage capacity occupied by bad blocks that prevent normal data writing. The second part is the storage capacity occupied by parity data. The parity data storage capacity can be redundant arrays of independent disks (RAID) parity data. RAID parity data is redundant information used to detect and correct data errors. The third part is the storage capacity occupied by table entries. The table entry storage capacity refers to the storage capacity occupied by the table entries that store the mapping relationship between the ZNS file system and the storage device.
[0073] For example, the relationship between the storage capacity of the reserved area and the occupied capacity of each part can be expressed as Formula 1. N =C a +C b +C c (1)
[0074] Where C N is the storage capacity of the reserved area, C a The storage capacity occupied by bad blocks, C b The storage capacity occupied by the verification data, C c The storage capacity occupied by the table entries.
[0075] S603: The processor updates the default storage capacity of the newly opened segment of the ZNS file system to the actual storage capacity.
[0076] After receiving the reserved area storage capacity feedback from the storage device, the ZNS file system needs to update the storage capacity of the newly opened segment based on the reserved area storage capacity, so that the amount of data that can be written to the newly opened segment in the ZNS file system is consistent with the actual amount of data that can be written to the first super block matched on the storage device side, and the actual storage capacity of the newly opened segment is the difference between the default storage capacity of the super block and the reserved area storage capacity of the super block.
[0077] In one possible implementation, updating the storage capacity of a newly opened segment is accomplished by moving the write pointer (WP) of the newly opened segment, i.e., moving the write pointer of the newly opened segment from the default storage capacity to the actual storage capacity. The write pointer can be moved in two ways: direct move and dummy write.
[0078] For example, referring to Figure 7, when the reserved area storage capacity of the super block N fed back by the storage device is zero, there is no need to move the write pointer of segment N, and the position pointed by the write pointer is the position pointed by the default storage capacity; when the reserved area storage capacity of the super block 1 fed back by the storage device is not zero, it is necessary to directly move the write pointer of segment 1, and the position pointed by the write pointer needs to be moved from the position pointed by the default storage capacity to a position that matches the reserved area storage capacity.
[0079] In the control method for an electronic device provided in this application, the processor proactively obtains the reserved area storage capacity of a superblock to update the actual usable storage capacity of its segments, thereby ensuring that the storage capacity actually provided by the superblock is always consistent with the storage capacity available to the ZNS file system. Since bad blocks no longer need to be replaced with available good blocks when they appear, the number of superblocks is no longer limited by the number of available good blocks in the resource pool. Furthermore, the lifespan of a superblock gradually decreases as the number of bad blocks increases, slowing the decreasing trend in the number of superblocks and extending the service life of the storage device. Furthermore, since the number of bad blocks no longer affects the number of superblocks, the storage device can still function normally even if the number of bad blocks exceeds the maximum threshold requirement of the storage device.
[0080] As the number of segments continues to increase, in order to maintain data consistency in the storage device, improve storage efficiency, and extend the device life, when the number of available Super Blocks falls below a certain threshold, garbage collection of the data in the storage device is required. Garbage collection refers to moving valid data from the source Super Block to the target Super Block and resetting the source Super Block. The selection process of the source Super Block and the target Super Block, as shown in Figure 8, specifically includes the following steps:
[0081] S801: In response to the storage device being powered on, the processor sends a query instruction to the storage device.
[0082] After the storage device is powered on, the processor will send a query instruction to the storage device to obtain the reserved area storage capacity of all super blocks in the storage device, and select the source super block and target super block in the garbage collection operation based on the reserved area storage capacity. That is, the storage device does not actively perform the garbage collection operation, and the processor performs the garbage collection operation.
[0083] S802: The storage device sends the reserved area storage capacity of each super block to the processor in response to the query instruction.
[0084] After receiving the query instruction, the storage device obtains the storage capacity of all available super blocks in the storage device and sends the storage capacity of each super block to the processor.
[0085] S803: The processor determines a source super block and a target super block according to the reserved area storage capacity of each super block.
[0086] In an embodiment of the present application, the amount of data that can be written to a newly opened segment in the ZNS file system can be consistent with the amount of data that can actually be written to the first super block that matches the storage device side. However, since bad blocks can exist in each super block, the displayed storage capacity of the segment corresponding to each super block can also be different.
[0087] In the examples shown in Figures 4 and 5 , when performing garbage collection, the storage device selects a source Super Block based on the size of its effective data storage capacity, which refers to the storage capacity occupied by valid data. If the size of the storage capacity occupied by valid data continues to be used as a screening criterion for selecting a source Super Block, the actual available storage capacity of the Super Block after garbage collection will be less.
[0088] For example, the default value of the storage capacity that Super Block 1 can provide is 100 MB. Since Super Block 1 has no bad blocks, the actual storage capacity it can provide is 100 MB, of which 20 MB is occupied by valid data. The default value of the storage capacity that Super Block 2 can provide is 100 MB. Since Super Block 2 has bad blocks, the actual storage capacity it can provide is less than 100 MB, for example, 90 MB, of which 15 MB is occupied by valid data.
[0089] If the source Super Block is selected based on the amount of storage capacity occupied by valid data, Super Block 2, which has less storage capacity occupied by valid data, will be selected as the source Super Block. However, after garbage collection, the actual storage capacity available in Super Block 1 is 100MB, while that available in Super Block 2 is 90MB. This means that Super Block 1 has a larger storage capacity than Super Block 2. Therefore, to avoid the actual storage capacity of the available Super Blocks after garbage collection being too small, the storage capacity occupied by valid data can no longer be used as a filter for source Super Blocks.
[0090] The steps of screening the source super block and the target super block according to the reserved area storage capacity may include:
[0091] S8031: The processor determines the valid data ratio of each super block in a non-idle state according to the reserved area storage capacity and the valid data storage capacity, and determines the source super block from the super blocks in a non-idle state according to the valid data ratio.
[0092] After obtaining the reserved area storage capacity of each super block, the effective data ratio of each super block can be calculated based on the reserved area storage capacity and the effective data storage capacity. The effective data storage capacity is used as the numerator and the difference between the default storage capacity of each super block and the reserved area storage capacity is used as the denominator. The effective data ratio of each super block in a non-idle state is obtained, and the source super block is determined based on the effective data ratio.
[0093] For example, continuing with the above embodiment, since there are no bad blocks in super block 1, and the storage capacity occupied by its verification data and the storage capacity occupied by its table entries are also zero, its reserved area storage capacity is 0MB, and the actual storage capacity it can provide is 100MB, of which the effective data storage capacity is 20MB, so the effective data ratio of super block 1 is 0.2; since there are bad blocks in super block 2, its reserved area storage capacity can be 40MB, and the actual storage capacity it can provide is 60MB, of which the effective data storage capacity is 15MB, so the effective data ratio of super block 2 is 0.25, and then super block 1 with a smaller effective data ratio is determined as the source super block.
[0094] It is understandable that selecting the source super block based on the relative size relationship of the effective data ratio between super blocks is a feasible way, but selecting the source super block based on the effective data ratio can also include other ways, which are not limited in this application.
[0095] S8032: The processor determines the actual storage capacity of each super block in the idle state based on the storage capacity of the reserved area, and determines the target super block from the super blocks in the idle state based on the relationship between the actual storage capacity of the super block in the idle state and the effective data storage capacity of the source super block.
[0096] When filtering the target super block, the filtering condition is that the super block to be selected needs to have enough storage space to store the data moved from the source super block. Therefore, after obtaining the storage capacity of the reserved area of each idle super block, it is necessary to determine the actual storage capacity of each idle super block based on the difference between the default storage capacity and the reserved area storage capacity, and then complete the screening of the target super block based on the relationship between the actual storage capacity of the selected super block and the effective data storage capacity of the source super block.
[0097] For example, taking Super Block 3 and Super Block 4 as examples, the default value of the storage capacity that Super Block 3 can provide is 100MB, but there are bad blocks in Super Block 3, and the storage capacity of its reserved area can be 30MB, so the actual storage capacity of Super Block 3 is 70MB. The default value of the storage capacity that Super Block 4 can provide is 100MB, but there are also bad blocks in Super Block 4, and the storage capacity of its reserved area can be 40MB, so the actual storage capacity of Super Block 4 is 60MB, and the effective data storage capacity in the source Super Block is 65MB. Therefore, Super Block 3 has enough storage space to store the data moved from the source Super Block, but Super Block 4 does not have enough storage space to store the data moved from the source Super Block, so Super Block 3 is determined as the target Super Block.
[0098] S804: The processor sends a garbage collection instruction containing identification information of the source super block and the target super block to the storage device.
[0099] After selecting the source super block and the target super block according to the storage capacity of the reserved area, the ZNS file system sends a garbage collection instruction carrying the identification information of the source super block and the target super block to the storage device.
[0100] S805: The storage device moves the data stored in the source super block to the target super block in response to the garbage collection instruction.
[0101] After receiving a garbage collection instruction, the storage controller in the storage device moves the valid data of the source super block to the target super block based on the identification information contained in the garbage collection instruction. Data transfer refers to the process of copying and transferring the stored data of the source super block to the target super block. By transferring the valid data from the source super block to the target super block for garbage collection, the probability of selecting a less frequently used super block as the first super block can be made higher than that of a more frequently used super block, thereby balancing the usage frequency of different super blocks on the storage device and improving the service life of the storage device. During data transfer, the consistency and integrity of the data must be ensured, that is, the data should not be lost or damaged during the copying or moving process. After the transfer is completed, the source super block needs to be reset and its status configured as idle. Since data is already stored in the source super block, its status needs to be configured as non-idle.
[0102] The electronic device control method provided in this application can ensure that the superblock continues to function normally even when a bad block appears in the superblock. Therefore, there is no need to detect and screen bad blocks in the storage device, thus saving the cost of screening. Furthermore, when a bad block appears in the superblock, it no longer needs to be replaced, eliminating the need for a mapping table entry to store the mapping between the spare block and the bad block it replaces. This reduces data read latency and SRAM memory resource consumption.
[0103] The present disclosure also provides an electronic device including a processor and the aforementioned storage system, wherein the processor is connected to the storage system and configured to store data in the storage system or read data from the storage system.
[0104] In the several embodiments provided herein, it should be understood that the control and memory of the provided electronic device may be implemented in other ways. For example, the division of a module is merely a logical functional division, and in actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another system, or ignoring or not implementing certain features.
[0105] Those skilled in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0106] The above are only specific embodiments of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A method for controlling an electronic device, characterized in that: Applied to an electronic device, the electronic device includes a processor and a storage device, the processor and the storage device are coupled, and a partition namespace ZNS file system is deployed on the processor. The method includes: The processor sends a new section opening instruction to the storage device, wherein the new section opening instruction includes the data read / write pressure determined by the processor; The storage device determines a first super block according to the data read / write pressure, and sends a reserved area storage capacity of the first super block to the processor; the super block is composed of storage blocks at the same physical location of different flash memory chips of the storage device, and the super block includes K bad blocks, where K is an integer greater than zero; The processor updates the default storage capacity of the newly opened segment of the ZNS file system to the actual storage capacity, where the actual storage capacity is the difference between the default storage capacity and the reserved area storage capacity.
2. The method according to claim 1, characterized in that Determining a super block according to the data read / write pressure includes: If the data read / write pressure is greater than or equal to the pressure threshold, determining a super block in which the number of bad blocks is less than or equal to the number threshold and is in an idle state as the first super block; If the data reading and writing pressure is less than the pressure threshold, a super block having a number of bad blocks greater than the number threshold and in an idle state is determined as the first super block.
3. The method according to claim 1, characterized in that The updating of the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity includes: According to the storage capacity of the reserved area, the pointing position of the write pointer of the newly opened segment is moved from the pointing position of the default storage capacity to the pointing position of the actual storage capacity.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: The processor sends a query instruction to the storage device in response to powering on the storage device; The storage device sends the reserved area storage capacity of each super block to the processor in response to the query instruction.
5. The method according to claim 4, characterized in that After sending the reserved area storage capacity of each super block to the processor, the method further includes: The processor determines a source super block and a target super block according to a reserved area storage capacity of each super block; The processor sends a garbage collection instruction containing identification information of the source super block and the target super block to the storage device; The storage device moves the data stored in the source super block to the target super block in response to the garbage collection instruction.
6. The method according to claim 5, characterized in that Determining the source super block and the target super block includes: The processor determines, based on the reserved area storage capacity and the valid data storage capacity, a valid data ratio of each super block in a non-idle state, and determines, based on the valid data ratio, the source super block from the super blocks in the non-idle state; The processor determines the actual storage capacity of each super block in an idle state based on the storage capacity of the reserved area, and determines the target super block from the super blocks in the idle state based on the size relationship between the actual storage capacity of the super block in the idle state and the effective data storage capacity of the source super block.
7. An electronic device, characterized in that: The system comprises a processor and a storage device, wherein the processor is coupled to the storage device, a ZNS file system is deployed in the processor, and the processor is configured to: Sending a new section opening instruction to a storage device, wherein the new section opening instruction includes the data read / write pressure determined by the processor; Updating the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity, where the actual storage capacity is the difference between the default storage capacity and the storage capacity of the reserved area; The storage device is configured as follows: Based on the data read and write pressure, a first super block is determined, and the reserved area storage capacity of the first super block is sent to the processor; wherein the super block is composed of storage blocks at the same physical position of different flash memory chips of the storage device, and the super block contains K bad blocks, where K is an integer greater than zero.
8. The electronic device according to claim 7, wherein: The storage device is specifically configured as follows: If the data read / write pressure is greater than or equal to the pressure threshold, determining a super block in which the number of bad blocks is less than or equal to the number threshold and is in an idle state as the first super block; If the data reading and writing pressure is less than the pressure threshold, a super block having a number of bad blocks greater than the number threshold and in an idle state is determined as the first super block.
9. The electronic device according to claim 7, wherein: The processor is specifically configured to: According to the storage capacity of the reserved area, the position pointed to by the write pointer of the newly opened segment is moved from the position pointed to by the default storage capacity to the position pointed to by the actual storage capacity.
10. The electronic device according to any one of claims 7 to 9, characterized in that: The processor is further configured to: In response to powering on the storage device, sending a query instruction to the storage device; The storage device is further configured to: In response to the query instruction, the reserved area storage capacity of each super block is sent to the processor.
11. The electronic device according to claim 10, wherein: The processor is further configured to: Determining a source super block and a target super block according to a reserved area storage capacity of each super block; Sending a garbage collection instruction containing identification information of the source super block and the target super block to the storage device; The storage device is further configured to: In response to the garbage collection instruction, the data stored in the source super block is moved to the target super block.
12. The electronic device according to claim 11, wherein: The processor is specifically configured to: Determining a valid data ratio of each super block in a non-idle state according to the reserved area storage capacity and the valid data storage capacity, and determining the source super block from the super blocks in the non-idle state according to the valid data ratio; The actual storage capacity of each super block in an idle state is determined based on the storage capacity of the reserved area, and the target super block is determined from the super blocks in an idle state based on the relationship between the actual storage capacity of the super block in an idle state and the effective data storage capacity of the source super block.
13. A readable storage medium, characterized in that: The readable storage medium includes a stored program, wherein when the program is executed, the device where the readable storage medium is located is controlled to execute the method according to any one of claims 1 to 6.