Control method of electronic equipment, electronic equipment and storage medium
By obtaining the reserved storage capacity of the super block and updating the storage capacity when the newly opened segment instruction, the storage capacity mismatch caused by bad blocks is solved, extending the service life of the storage device and improving performance.
Patent Information
- Application Number
- CN202311615067.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-29
- Publication Date
- 2025-05-30
AI Technical Summary
Bad blocks cause the storage capacity that the file system can use does not match the storage capacity provided by the storage device, affecting the service life and performance of the storage device.
By actively obtaining the reserved storage capacity of the super block when the newly opened section instruction, the processor actively obtains the reserved storage capacity of the super block and updates the actual storage capacity of its segment, ensuring that the actual storage capacity provided by the super block is consistent with the storage capacity that the ZNS file system can use.
It extends the service life of the storage device, avoids the risk of storage device failure caused by the number of bad blocks exceeding the maximum threshold, and improves the garbage collection efficiency and utilization of storage capacity of the storage device.
Smart Images

Figure CN120066379A_ABST
Abstract
Description
Technical Field
[0001] 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
[0002] The zoned name spaces (ZNS) file system is a new type of file system. In the ZNS file system, a storage device is divided into different zones, and each zone includes a fixed number of logical blocks. The ZNS file system allows data to be sequentially written within each zone without addressing or erasing the entire block, thereby reducing the write amplification effect, increasing the lifespan of the storage device, and providing higher write performance. However, bad blocks may occur during the production process and use process of the storage device, resulting in a mismatch between the storage capacity available for the ZNS file system and the storage capacity provided by the storage device. Summary of the Invention
[0003] The embodiments of the present application provide a control method for an electronic device, an electronic device, and a storage medium, which are used to improve the problem that the storage capacity available for the file system does not match the storage capacity provided by the storage device due to bad blocks.
[0004] To achieve the above object, the embodiments of the present application adopt the following technical solutions:
[0005] In a first aspect, a control method for an electronic device is provided. The electronic device includes a processor and a storage device, the processor and the storage device are coupled, and a zoned name space (ZNS) file system is deployed on the processor. The method includes: the processor sends a new zone instruction to the storage device, where the new zone instruction includes data read / write pressure, and the data read / write pressure refers to the workload size that the ZNS file system bears when processing input and output operations. The storage device determines a first superblock according to the data read / write pressure, and sends the reserved area storage capacity of the first superblock to the processor. The reserved area storage capacity refers to a part of the storage capacity that the storage device cannot provide for the ZNS file system due to factors such as bad blocks. A superblock is composed of storage blocks at the same physical location of different flash chips of the storage device, and the superblock contains K bad blocks, where K is an integer greater than zero. The processor updates the default storage capacity of the newly opened zone of the ZNS file system to the actual storage capacity of the first superblock, and the actual storage capacity is the difference between the default storage capacity and the reserved area storage capacity of the first superblock.
[0006] The control method of the electronic device provided by this application, when a new section instruction is received, the processor actively obtains the reserved area storage capacity of the super block to update the actually usable storage capacity of its section, thereby ensuring that the storage capacity actually provided by the super block is always consistent with the storage capacity that the ZNS file system can use. 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 cause the bad blocks in the super block to not be replaced, and the service life of the super block will directly expire, resulting in a gradual decrease in the number of available super blocks, and further increasing the failure risk of the storage device. The solution provided by the embodiments of this application no longer requires available good blocks to replace the super block 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 gradually expires 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, even if the number of bad blocks exceeds the maximum threshold requirement of the storage device, the storage device can still be used normally.
[0007] In a possible implementation manner, determining the 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, then determining the super block with the number of bad blocks less than or equal to the number threshold and in the idle state as the first super block; if the data read / write pressure is less than the pressure threshold, then determining the super block with the number of bad blocks greater than the number threshold and in the idle state as the first super block.
[0008] The control method of the electronic device provided by this application, when a new section is opened, uses the data read / write pressure faced by the file system as a judgment condition for screening the first super block, so that the storage device can flexibly select super blocks containing different numbers of bad blocks according to the data read / write pressure, thereby meeting the performance requirements of the file system under different conditions.
[0009] In a possible implementation manner, updating the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity includes:
[0010] According to the reserved area storage capacity, move the pointing position of the write pointer of the newly opened section from the pointing position of the default storage capacity to the pointing position of the actual storage capacity.
[0011] In a possible implementation manner, the method further includes: the processor sends a query instruction to the storage device in response to the power-on of the storage device, and the storage device sends the reserved area storage capacity of each super block to the processor in response to the query instruction.
[0012] In a possible implementation, after sending the reserved area storage capacity of each superblock to the processor, the method further includes: The processor determines a source superblock and a target superblock according to the reserved area storage capacity of each superblock, and the processor sends a garbage collection instruction including the identification information of the source superblock and the target superblock to the storage device. In response to the garbage collection instruction, the storage device moves the data stored in the source superblock to the target superblock.
[0013] In a possible implementation, determining the source superblock and the target superblock includes: The processor determines the proportion of valid data of each non-idle superblock according to the reserved area storage capacity and the valid data storage capacity, and determines the source superblock from the non-idle superblocks according to the proportion of valid data. The processor determines the actual storage capacity of each idle superblock according to the reserved area storage capacity, and determines the target superblock from the idle superblocks according to the size relationship between the actual storage capacity of the idle superblock and the valid data storage capacity of the source superblock.
[0014] The control method of the electronic device provided by this application uses the reserved area storage capacity as a judgment condition for screening the source superblock and the target superblock during garbage collection operations, thereby reducing the probability of using a superblock with a relatively small actual storage capacity as the source superblock, and thus improving the garbage collection efficiency of the storage device and the utilization rate of the storage capacity.
[0015] In a second aspect, this application provides an electronic device, including a processor and a storage device. The processor is coupled to the storage device. A ZNS file system is deployed in the processor. The processor is configured to: send a new section opening instruction to the storage device, where the new section opening instruction includes the data read / write pressure determined by the processor, and update the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity, and 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 superblock according to the data read / write pressure, and send the reserved area storage capacity of the first superblock to the processor; where a superblock is composed of storage blocks at the same physical location of different flash chips of the storage device, and the superblock includes K bad blocks, and K is an integer greater than zero.
[0016] In a possible implementation, the storage device is specifically configured to: if the data read / write pressure is greater than or equal to the pressure threshold, determine a superblock with a bad block number less than or equal to the number threshold and in an idle state as the first superblock; if the data read / write pressure is less than the pressure threshold, determine a superblock with a bad block number greater than the number threshold and in an idle state as the first superblock.
[0017] In a possible implementation, the processor is specifically configured to: move the pointing position of the write pointer of the newly opened section from the pointing position of the default storage capacity to the pointing position of the actual storage capacity according to the reserved area storage capacity.
[0018] In a possible implementation, the processor is further configured to: in response to the power-on of the storage device, send a query instruction to the storage device, and the storage device is further configured to: in response to the query instruction, send the reserved area storage capacity of each superblock to the processor.
[0019] In a possible implementation, the processor is further configured to: determine a source superblock and a target superblock according to the reserved area storage capacity of each superblock, and send a garbage collection instruction including the identification information of the source superblock and the target superblock to the storage device; the storage device is further configured to: in response to the garbage collection instruction, move the data stored in the source superblock to the target superblock.
[0020] In a possible implementation, the processor is specifically configured to: determine the proportion of valid data of each superblock in a non-idle state according to the reserved area storage capacity and the valid data storage capacity, and determine the source superblock from the superblocks in a non-idle state according to the proportion of valid data, determine the actual storage capacity of each superblock in an idle state according to the reserved area storage capacity, and determine the target superblock from the superblocks in an idle state according to the size relationship between the actual storage capacity of the superblock in an idle state and the valid data storage capacity of the source superblock.
[0021] In a third aspect, a computer-readable storage medium is provided, and the computer-readable storage medium stores computer-executable instructions; after the computer-executable instructions are executed, any method in the first aspect above can be implemented.
[0022] It can be understood that the technical effects of the second aspect to the third aspect can refer to the technical effects of the first aspect and any of its implementation manners, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application;
[0024] Figure 2 It is a schematic diagram of the correspondence between a ZNS file system and a storage device provided by an embodiment of the present application;
[0025] Figure 3 It is a schematic structural diagram of a storage device provided by an embodiment of the present application;
[0026] Figure 4 It is a schematic diagram of the process of bad block replacement provided by an embodiment of the present application;
[0027] Figure 5 Another schematic diagram of the bad block replacement process provided for the embodiments of the present application;
[0028] Figure 6 Schematic flow diagram of the control method of the electronic device provided for the embodiments of the present application;
[0029] Figure 7 Schematic flow diagram of updating the storage capacity of the newly opened section provided for the embodiments of the present application;
[0030] Figure 8 Schematic flow diagram of another control method of the electronic device provided for the embodiments of the present application. Detailed implementation manners
[0031] 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 forms "a", "an", "", "the above", "the" and "this" are also intended to include the forms 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" and "one or more" mean one or more than two (including two). The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0032] The reference to "one embodiment" or "some embodiments" etc. described in this specification means that a specific feature, structure or characteristic described in combination with the embodiment is included in one or more embodiments of the present application. Thus, the statements "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments" etc. that appear in different places in this specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "comprise", "include", "have" and their variants all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise stated.
[0033] Hereinafter, the terms "first" and "second" are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features.
[0034] In the embodiments of this application, words such as "exemplarily" or "for example" are used to represent examples, illustrations, or explanations. Any embodiment or design solution described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Rather, the use of words such as "exemplarily" or "for example" is intended to present relevant concepts in a specific manner.
[0035] The file system is an important part of the operating system of electronic devices such as terminal devices, servers, or 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 can provide a standard system call interface for the application programs installed on the electronic device. By calling the standard system call interface provided by the file system, the application programs can implement operations such as creating, deleting, reading, and writing data in the storage device.
[0036] In one implementation, the electronic device can be a terminal device, a server, a virtual machine (VM), etc. The terminal device can 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, as well as devices such as a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) / virtual reality (VR) device, etc. The embodiments of this application do not impose special restrictions on the specific form of the electronic device.
[0037] Exemplarily, Figure 1 is a schematic structural diagram of the electronic device provided in the embodiments of this application. As Figure 1 shown, 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, a headphone interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0038] It can be understood thatFigure 1 The structure shown does not constitute a specific limitation on the electronic device of the embodiments of the present application. In other embodiments, the electronic device may also include more or fewer components than Figure 1 shown, or combine certain components, or split certain components, or have different component arrangements. Figure 1 The components shown 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.
[0039] In a possible implementation, the file system may be a ZNS file system that is flash-friendly (F2F). In the ZNS file system, a partition is divided into storage zones (Zones), sections (Sections), and segments (Segments) according to the size of the partition storage capacity. The partition storage capacity refers to all the storage space that the storage device can provide. A storage zone may include at least one section, and a section may include at least one segment.
[0040] Exemplarily, the correspondence between the ZNS file system and the storage device can be referred to Figure 2 . In the ZNS file system, a storage zone includes N sections, and each section includes M segments. The storage device 121 includes N superblocks. The superblocks are composed of storage blocks at the same physical location of different flash chips of the storage device. The number of superblocks matches the number of sections. And the superblock is the smallest operation unit for the storage device to perform operations such as data writing, data overwriting, and garbage collection. Among them, M and N are positive integers.
[0041] In a possible implementation, referring to Figure 3 , the storage device 121 includes a storage controller 1211 and a memory 1212. The memory 1212 may contain M flash chips (Dies). Each Die is an independent concurrent unit, and each flash chip may contain N storage blocks. To improve performance, usually one storage block is taken from each flash chip to form a superblock. For example, Figure 3 superblock 1 and superblock N in, all the storage blocks that make up a superblock can be concurrent, and the superblock is used as the smallest operation unit on the memory side. During subsequent operation, the size of the superblock remains unchanged.
[0042] In the ZNS file system, the ZNS file system requires that the storage capacity of each superblock of the storage device be the same, that is, each superblock includes the same number of storage blocks. The sections of the ZNS file system correspond to the superblocks of the storage device. Therefore, it is also necessary to ensure that the storage capacity that each section can use is the same as the storage capacity provided by the superblocks of the storage device.
[0043] Exemplarily, in the ZNS file system, there are N segments numbered from 1 to N, and in the storage device, there are N superblocks numbered from 1 to N. The storage capacity of the segment numbered 1 is the same as that of the superblock numbered 1, both being P. Moreover, the storage capacity of any other numbered superblock also needs to be the same as that of the superblock numbered 1, which also needs to be P.
[0044] Since there may be bad blocks in the storage device, a bad block refers to a storage area in the storage device where write and erase operations cannot be performed. The occurrence of bad blocks will cause the storage capacity actually provided by the superblock for the file system to decrease, making the storage capacity that the segments on the file system side can actually use different from the storage capacity provided by the superblocks on the storage device side.
[0045] There are two types of bad blocks that appear in the storage device. One is the storage block that is already damaged at the factory stage, that is, the factory bad block (FBB), and the other is the storage block that is damaged due to reaching the service life during the use of the storage device, that is, the grown bad block (GBB).
[0046] The storage capacities of different superblocks need to be kept consistent. In some feasible implementation manners, the remap method can be used to ensure that the storage capacity sizes of each superblock are the same. The processing process of remap is as follows: when a bad block appears on a superblock, 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.
[0047] Exemplarily, refer to Figure 4 , when the storage block located in Die5 of the flash chip in superblock 1 becomes a bad block, first select a spare block from the free resource pool on the flash chip Die5. The free resource pool contains all the available good blocks in the idle state on the flash chip Die5, and any good block can be used as a spare block. Replace the bad block with the spare block, and then store the mapping relationship between the spare block and the bad block it replaces through the mapping relationship entry, so that superblock 1 is logically a complete superblock.
[0048] When the free resource pool has a sufficient number of available good blocks in the idle state to complete the replacement of the bad block, the superblock can be guaranteed to have the ability to handle bad blocks. However, when the free resource pool does not have a sufficient number of available good blocks in the idle state, the bad block in the superblock cannot be replaced, making the size of this superblock inconsistent with that of other superblocks, and further causing this superblock to fail.
[0049] Exemplarily, refer to Figure 5, when the replacement of the storage blocks located in Flash Die5 of Super Block 1 is completed and the storage blocks located in Flash Die3 of Super Block 1 become bad blocks, first select a spare block from the free resource pool on Flash Die3. However, since there are no available good blocks in the free state on Flash Die3 for replacing bad blocks, the free resource pool is empty. And because the storage capacity between each super block needs to be consistent, Super Block 1 can no longer be used. Then mark the entire Super Block 1 as a bad block and store the other available good blocks in Super Block 1 as free good blocks in the free resource pool.
[0050] The remapping method can ensure that the size of each super block is the same, thereby ensuring that the storage capacity actually available to the sections on the ZNS file system side is the same as the storage capacity provided by the super blocks on the storage device side. However, there are the following disadvantages:
[0051] First: The number of super blocks in the storage device is limited by the Flash Die with the least number of available good blocks in the free state in the storage device. When there are many available good blocks in the free state on other Flash Dies that can be used, while the number of available good blocks in the free state on a certain Flash Die is small or zero, the number of super blocks will continue to decrease because bad blocks can no longer be replaced, which will lead to the entire storage device not being able to meet the normal usage conditions due to the small number of available super blocks.
[0052] Exemplarily, continue to refer to Figure 5 , the number of available good blocks that can be in the free state on Flash Die3 is 0, while there are still many available good blocks in the free state on Flash Die1, Flash Die2, Flash Die4, and Flash Die6 that can be used. Since Flash Die3 no longer has the ability to replace bad blocks, for any super block, once the storage block located in Flash Die3 becomes a bad block, then this super block fails. Therefore, using the remapping method, the storage capacity actually provided by the super block has always been a fixed value P, and when bad blocks can no longer be replaced, the storage capacity actually provided by this super block becomes 0.
[0053] Second: As the storage capacity of consumer storage devices continues to increase, the number of Dies and the number of storage blocks also continue to increase. Therefore, the probability that the storage blocks at the same position on different Dies are good blocks at the same time is greatly reduced. As a result, the workload of remapping continues to increase, which will lead to the remap entries of the mapping relationship between the storage spare blocks and the bad blocks they replace occupying more space. Furthermore, it will lead to insufficient resources in the static random-access memory (SRAM) inside the controller.
[0054] 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, more time is required to complete the data reading, so the latency of data reading becomes higher.
[0055] The embodiment of the present application provides a control method for an electronic device. When a new section instruction is issued, the ZNS file system actively obtains the reserved area storage capacity of the superblock. The reserved area storage capacity refers to a part of the storage capacity that the storage device cannot provide for the ZNS file system to use due to factors such as bad blocks, and updates the actually available storage capacity of the new section according to the reserved area storage capacity, ensuring that the storage capacity actually provided by the superblock is always consistent with the storage capacity that the ZNS file system can use.
[0056] The control method of the electronic device of the present application will be described in detail below.
[0057] Refer to Figure 6 , the process of this control method is as follows:
[0058] S601: The processor sends a new section instruction to the storage device. The new section instruction includes the data read-write pressure.
[0059] When the currently available section can no longer meet the storage requirements of newly written data, a new section instruction will be triggered. After the new section instruction is triggered, the ZNS file system needs to prepare a new section for data storage. First, the ZNS file system can detect the current data read-write pressure in real time through a detection tool. The data read-write pressure refers to the workload size that the ZNS file system bears when processing input and output operations. For example, the data read-write pressure can be measured by the number of I / O requests processed by the ZNS file system per unit time. The more the number of I / O requests, the greater the data read-write pressure. Then, the data read-write pressure is inserted as a parameter into the new section instruction sent by the processor to the storage device. The data read-write pressure will be used as a basis for screening the superblock that matches the new section, so as to ensure that the storage device can meet the current performance requirements of the ZNS file system.
[0060] S602: The storage device determines the first superblock according to the data read-write pressure and sends the reserved area storage capacity of the first superblock to the processor.
[0061] After receiving the new section instruction, the storage device first parses it to obtain the data read-write pressure faced by the ZNS file system at this time. Then, the storage device needs to select a first superblock that matches the current data read-write pressure from multiple available superblocks based on the data read-write pressure as the screening basis.
[0062] It can be understood that super blocks with different numbers of bad blocks are matched to different data read / write pressures. The specific matching criteria need to be determined according to the comparison result between the data read / write pressure and the pressure threshold.
[0063] In a possible implementation, the specific steps for determining the first super block according to the data read / write pressure include:
[0064] S6021: If the data read / write pressure is greater than or equal to the pressure threshold, then determine the super blocks with the number of bad blocks less than or equal to the number threshold and in the idle state as the first super blocks.
[0065] S6022: If the data read / write pressure is less than the pressure threshold, then determine the super blocks with the number of bad blocks greater than the number threshold and in the idle state as the first super blocks.
[0066] When the data read / write pressure faced by the ZNS file system is very high, reaching or exceeding the pressure threshold, it indicates that the ZNS file system has a relatively high requirement for the performance stability of the storage device at this time. For example, in the scenario of stress testing the storage device or processing a large amount of sequential write data. And in the above scenarios, the storage device is required to have a relatively large bandwidth and high bandwidth stability to ensure that the system can efficiently handle data read / write requests. Therefore, super blocks with relatively few bad blocks or super blocks without bad blocks can be selected as the first super blocks.
[0067] On the contrary, when the data read / write pressure is lower than the pressure threshold, it indicates that the ZNS file system has a low requirement for performance stability at this time. Therefore, there is no high requirement for the bandwidth size and bandwidth stability of the storage device. Therefore, super blocks with relatively more bad blocks can be selected as the first super blocks.
[0068] Exemplarily, the number of bad blocks of super block A can be 1, the number of bad blocks of super block B can be 3, the number of bad blocks of super block C can be 5, the number of bad blocks of super block D can be 10, the first threshold can be 0.5, and the number threshold can be 4. If the 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 can be selected as the first super block to match the newly opened section; 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 can be selected as the first super block to match the newly opened section.
[0069] After determining the first superblock that matches the newly opened section, the storage device needs to obtain the reserved area storage capacity of the first superblock. The reserved area storage capacity refers to the storage capacity occupied by the storage device itself and cannot be provided for use by the ZNS file system. Due to the existence of the reserved area storage capacity, the storage device cannot provide all of its storage capacity for use by the ZNS file system, resulting in a discrepancy between the actual storage capacity provided by the superblock and the storage capacity that the ZNS file system can use.
[0070] The reserved area storage capacity can consist of multiple parts. Exemplarily, 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 storage capacity occupied by bad blocks refers to the total storage capacity that cannot be used for normal data writing due to the occurrence of bad blocks. The second part is the storage capacity occupied by parity data. The storage capacity occupied by parity data can be redundant arrays of independent disks (RAID) parity data. RAID parity data is a type of redundant information used to detect and correct data errors. The third part is the storage capacity occupied by table entries. The storage capacity occupied by table entries refers to the storage capacity occupied by the table entries that store the mapping relationship between the ZNS file system and the storage device.
[0071] Exemplarily, the relationship between the reserved area storage capacity and the occupied capacity of each part can be characterized by Formula 1.
[0072] C N =C a +C b +C c (1)
[0073] In the formula, C N is the reserved area storage capacity, C a is the storage capacity occupied by bad blocks, C b is the storage capacity occupied by parity data, and C c is the storage capacity occupied by table entries.
[0074] S603: The processor updates the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity.
[0075] After the ZNS file system receives the reserved area storage capacity feedback from the storage device, it needs to update the storage capacity of the newly opened section based on the reserved area storage capacity, so that the amount of data that can be written in the newly opened section of the ZNS file system is consistent with the amount of data that can actually be written in the first superblock that matches on the storage device side. The actual storage capacity of the newly opened section is the difference between the default storage capacity of the superblock and the reserved area storage capacity of the superblock.
[0076] In a possible implementation, updating the storage capacity of a newly opened segment is achieved by moving the write pointer (WP) of the newly opened segment, that is, moving the pointing position of the write pointer of the newly opened segment from the default storage capacity to the actual storage capacity. The ways of moving the write pointer can include two ways: direct movement and Dummy Write.
[0077] For example, refer to Figure 7 , when the reserved area storage capacity of superblock N feedback by the storage device is zero, there is no need to move the write pointer of segment N, and the pointing position of the write pointer is the pointing position of the default storage capacity; while when the reserved area storage capacity of superblock 1 feedback by the storage device is not zero, it is necessary to directly move the write pointer of segment 1, and the pointing position of the write pointer needs to be moved from the pointing position of the default storage capacity to the position matching the reserved area storage capacity.
[0078] For the control method of the electronic device provided in this application, the processor actively obtains the reserved area storage capacity of the superblock to update the actually usable storage capacity of its segment, so as to ensure that the storage capacity actually provided by the superblock is always consistent with the storage capacity that the ZNS file system can use. Since there is no need to replace a bad block with an available good block when a bad block appears, the number of superblocks is no longer limited by the number of available good blocks in the resource pool, and the lifespan of the superblock gradually expires as the number of bad blocks increases, delaying the decreasing trend of the number of superblocks and extending the service life of the storage device. And since the number of bad blocks no longer affects the number of superblocks, the storage device can still be used normally even if the number of bad blocks exceeds the maximum threshold requirement of the storage device.
[0079] 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 lifespan, when the number of available superblocks is less than a certain threshold, it is necessary to perform garbage collection on the data in the storage device. Garbage collection refers to moving the valid data in the source superblock to the target superblock and resetting the source superblock. For the screening process of the source superblock and the target superblock, refer to Figure 8 , which specifically includes the following steps:
[0080] S801: In response to the power-on of the storage device, the processor sends a query instruction to the storage device.
[0081] 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 superblocks in the storage device, and based on the reserved area storage capacity, select the source superblock and the target superblock in the garbage collection operation, that is, the storage device does not actively perform the garbage collection operation, but the processor performs the garbage collection operation.
[0082] S802: The storage device sends the reserved area storage capacity of each superblock to the processor in response to the query instruction.
[0083] After receiving the query instruction, the storage device obtains the storage capacities of all available superblocks in the storage device and sends the storage capacities of each superblock to the processor.
[0084] S803: The processor determines the source superblock and the target superblock according to the reserved area storage capacity of each superblock.
[0085] In the embodiments of the present application, it can be ensured that the amount of data that can be written in the newly opened segment of the ZNS file system is consistent with the amount of data that can actually be written in the first superblock that matches the storage device side. However, since there may be bad blocks in each superblock, the displayed storage capacities of the segments corresponding to each superblock can also be different.
[0086] In Figure 4 or Figure 5 In the example shown, when the storage device performs the garbage collection operation, the selection of the source superblock is based on the size of the valid data storage capacity, where the valid data storage capacity refers to the storage capacity occupied by the valid data. If the size of the storage capacity occupied by the valid data continues to be used as the screening condition for the source superblock, the actually available storage capacity of the superblock after garbage collection will be less.
[0087] Exemplarily, the default value of the storage capacity that superblock 1 can provide is 100 MB. Since there are no bad blocks in superblock 1, the actual storage capacity it can provide is 100 MB, and the storage capacity occupied by the valid data is 20 MB. The default value of the storage capacity that superblock 2 can provide is 100 MB. Since there are bad blocks in superblock 2, the actual storage capacity it can provide is less than 100 MB, for example, it can be 90 MB, and the storage capacity occupied by the valid data is 15 MB.
[0088] If the source superblock is selected according to the size of the storage capacity occupied by the valid data, superblock 2 with less storage capacity occupied by the valid data will be selected as the source superblock. However, after the garbage collection is completed, the actually available storage capacity of superblock 1 is 100 MB, and the actually available storage capacity of superblock 2 is 90 MB, that is, the storage capacity that superblock 1 can provide is greater than the storage capacity that superblock 2 can provide. Therefore, in order to avoid the actually available storage capacity in the available superblocks after garbage collection being too small, the size of the storage capacity occupied by the valid data can no longer be used as the screening condition for the source superblock.
[0089] The steps of screening the source superblock and the target superblock according to the reserved area storage capacity may include:
[0090] S8031: The processor determines the proportion of valid data of each superblock in a non-idle state based on the reserved area storage capacity and the valid data storage capacity, and determines the source superblock from the superblocks in a non-idle state according to the proportion of valid data.
[0091] After obtaining the reserved area storage capacity of each superblock, the proportion of valid data of each superblock can be calculated based on the reserved area storage capacity and the valid data storage capacity. The valid data storage capacity is used as the numerator, and the difference between the default storage capacity of each superblock and the reserved area storage capacity is used as the denominator, so as to obtain the proportion of valid data of each superblock in a non-idle state, and determine the source superblock according to the proportion of valid data.
[0092] Exemplarily, continuing with the above embodiment, since there are no bad blocks in superblock 1, and the storage capacity occupied by its check data and the storage capacity occupied by the table entries are also zero, its reserved area storage capacity is 0MB, and the actual storage capacity it can provide is 100MB, among which the valid data storage capacity is 20MB. Therefore, the proportion of valid data of superblock 1 is 0.2. Since there are bad blocks in superblock 2, its reserved area storage capacity can be 40MB, the actual storage capacity it can provide is 60MB, and the valid data storage capacity is 15MB. Therefore, the proportion of valid data of superblock 2 is 0.25. Then, superblock 1 with a smaller proportion of valid data is determined as the source superblock.
[0093] It can be understood that it is a feasible way to complete the selection of the source superblock according to the relative size relationship of the proportion of valid data between superblocks. However, the way to complete the selection of the source superblock according to the proportion of valid data may also include other methods, which are not limited in this application.
[0094] S8032: The processor determines the actual storage capacity of each superblock in an idle state based on the reserved area storage capacity, and determines the target superblock from the superblocks in an idle state according to the size relationship between the actual storage capacity of the superblock in an idle state and the valid data storage capacity of the source superblock.
[0095] When screening the target superblock, the screening condition is that the candidate superblock needs to have enough storage space to store the data transferred from the source superblock. Therefore, after obtaining the reserved area storage capacity of each superblock in an idle state, it is necessary to determine the actual storage capacity of each superblock in an idle state according to the difference between the default storage capacity and the reserved area storage capacity, and then complete the screening of the target superblock according to the size relationship between the actual storage capacity of the candidate superblock and the valid data storage capacity of the source superblock.
[0096] Exemplarily, taking superblock 3 and superblock 4 as examples, the default storage capacity that superblock 3 can provide is 100 MB. However, there are bad blocks in superblock 3, and the storage capacity of its reserved area can be 30 MB. Therefore, the actual storage capacity of superblock 3 is 70 MB. The default storage capacity that superblock 4 can provide is 100 MB. However, there are also bad blocks in superblock 4, and the storage capacity of its reserved area can be 40 MB. Therefore, the actual storage capacity of superblock 4 is 60 MB. The effective data storage capacity in the source superblock is 65 MB. Therefore, superblock 3 has enough storage space to store the data transferred from the source superblock, while superblock 4 does not have enough storage space to store the data transferred from the source superblock. So, superblock 3 is determined as the target superblock.
[0097] S804: The processor sends a garbage collection instruction containing the source superblock and target superblock identification information to the storage device.
[0098] After filtering out the source superblock and target superblock according to the reserved area storage capacity, the ZNS file system sends a garbage collection instruction carrying the source superblock and target superblock identification information to the storage device.
[0099] S805: In response to the garbage collection instruction, the storage device transfers the data stored in the source superblock to the target superblock.
[0100] After receiving the garbage collection instruction, the storage controller in the storage device transfers the valid data of the source superblock to the target superblock according to 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 superblock to the target superblock. By performing garbage collection by transferring the valid data from the source superblock to the target superblock, the probability that a superblock with a lower usage frequency is selected as the first superblock can be made greater than that of a superblock with a higher usage frequency, thereby balancing the usage frequencies of different superblocks on the storage device and increasing the service life of the storage device. When transferring data, it is necessary to ensure the consistency and integrity of the data, that is, the data should not be lost or damaged during the copying or moving process, and after the transfer is completed, the source superblock needs to be reset and its status needs to be configured as the idle state. Since the source superblock already stores data, its status needs to be configured as the non-idle state.
[0101] The control method of the electronic device provided in this application can ensure that the superblock can continue to be used normally even when there are bad blocks in the superblock. Therefore, it is not necessary to detect and filter the bad blocks in the storage device, thus saving the cost brought by the filtering. And when there are bad blocks in the superblock, there is no need for replacement, so there is no need for a mapping relationship table entry to store the mapping relationship between the spare block and the bad block it replaces, reducing the data read latency and the consumption of SRAM memory resources.
[0102] Embodiments of the present disclosure further provide an electronic device, which includes a processor and the aforementioned storage system. The processor is connected to the storage system and is configured to store data in the storage system or read data read from the storage system. Exemplarily, the electronic device may be the electronic device shown in the foregoing examples Figure 1 of the electronic device.
[0103] In several embodiments provided in the present application, 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 certain module is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0104] Those of ordinary skill in the art can realize that the modules and algorithm steps of each example described in combination with the embodiments disclosed in this document can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. A professional technician may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0105] The above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed in the present application should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A control method for 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 partitioned namespace ZNS file system is deployed on the processor. The method includes: The processor sends a new section opening instruction to the storage device, where the new section opening instruction includes the data read / write pressure determined by the processor; The storage device determines a first superblock according to the data read / write pressure and sends the reserved area storage capacity of the first superblock to the processor; The superblock is composed of storage blocks at the same physical position of different flash chips of the storage device, and the superblock contains K bad blocks, where K is an integer greater than zero; The processor updates the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity, and 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, The determining the superblock according to the data read / write pressure includes: If the data read / write pressure is greater than or equal to the pressure threshold, the superblock with the number of bad blocks less than or equal to the number threshold and in the idle state is determined as the first superblock; If the data read / write pressure is less than the pressure threshold, the superblock with the number of bad blocks greater than the number threshold and in the idle state is determined as the first superblock.
3. The method according to claim 1, characterized in that, The updating the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity includes: According to the reserved area storage capacity, the pointing position of the write pointer of the newly opened section 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-3, characterized in that, The method further includes: The processor sends a query instruction to the storage device in response to the power-on of the storage device; The storage device sends the reserved area storage capacity of each superblock 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 superblock to the processor, the method further includes: The processor determines a source superblock and a target superblock according to the reserved area storage capacity of each superblock; The processor sends a garbage collection instruction including the identification information of the source superblock and the target superblock to the storage device; The storage device transports the data stored in the source superblock to the target superblock in response to the garbage collection instruction.
6. The method according to claim 5, characterized in that, The determining the source superblock and the target superblock includes: The processor determines the effective data ratio of each non-idle superblock according to the reserved area storage capacity and the effective data storage capacity, and determines the source superblock from the non-idle superblocks according to the effective data ratio; The processor determines the actual storage capacity of each superblock in the idle state according to the reserved area storage capacity, and determines the target superblock from the superblocks in the idle state according to the size relationship between the actual storage capacity of the superblock in the idle state and the effective data storage capacity of the source superblock.
7. An electronic device, characterized in that, it includes a processor and a storage device, the processor is coupled to the storage device, a ZNS file system is deployed in the processor, and the processor is configured to: send a new section opening instruction to the storage device, where the new section opening instruction includes the data read-write pressure determined by the processor; update the default storage capacity of the newly opened section of the ZNS file system to the actual storage capacity, and 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 superblock according to the data read-write pressure, and send the reserved area storage capacity of the first superblock to the processor; wherein, the superblock is composed of storage blocks at the same physical position of different flash chips of the storage device, and the superblock contains K bad blocks, and K is an integer greater than zero.
8. The electronic device according to claim 7, characterized in that, the storage device is specifically configured to: if the data read-write pressure is greater than or equal to the pressure threshold, determine the superblock with the number of bad blocks less than or equal to the number threshold and in the idle state as the first superblock; if the data read-write pressure is less than the pressure threshold, determine the superblock with the number of bad blocks greater than the number threshold and in the idle state as the first superblock.
9. The electronic device according to claim 7, characterized in that, the processor is specifically configured to: move the pointing position of the write pointer of the newly opened section from the pointing position of the default storage capacity to the pointing position of the actual storage capacity according to the reserved area storage capacity.
10. The electronic device according to any one of claims 7-9, characterized in that, the processor is further configured to: send a query instruction to the storage device in response to the power-on of the storage device; the storage device is further configured to: send the reserved area storage capacity of each superblock to the processor in response to the query instruction.
11. The electronic device according to claim 10, characterized in that, the processor is further configured to: determine a source superblock and a target superblock according to the reserved area storage capacity of each superblock; send a garbage collection instruction including the identification information of the source superblock and the target superblock to the storage device; the storage device is further configured to: move the data stored in the source superblock to the target superblock in response to the garbage collection instruction.
12. The electronic device according to claim 11, characterized in that, the processor is specifically configured to: determine the effective data ratio of each superblock in the non-idle state according to the reserved area storage capacity and the effective data storage capacity, and determine the source superblock from the superblocks in the non-idle state according to the effective data ratio. Determine the actual storage capacity of each superblock in the idle state according to the reserved area storage capacity, and determine the target superblock from the superblocks in the idle state according to the size relationship between the actual storage capacity of the superblocks in the idle state and the effective data storage capacity of the source superblock.
13. A readable storage medium, characterized in that, the readable storage medium includes a stored program, wherein when the program runs, it controls the device where the readable storage medium is located to execute the method according to any one of claims 1 to 6.