Data processing method, apparatus, and vehicle
Patent Information
- Application Number
- PCT/CN2025/089891
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-04-18
- Publication Date
- 2026-10-22
Smart Images

Figure CN2025089891_22102026_PF_FP_ABST
Abstract
Description
Data processing methods, devices and vehicles Technical Field
[0001] This application relates to the field of intelligent vehicles, and more specifically, to a data processing method, apparatus, and vehicle. Background Technology
[0002] The flash electrically erasable programmable read-only memory (EEPROM) emulation module in the AUTOSAR (Automotive Open System Architecture) storage stack is used to simulate EEPROM and directly determine the storage location of user data. The Fee specification divides a flash memory space into two memory banks, for example, bank0 and bank1. When upper-layer applications write a data block, encountering the same block ID does not erase the existing block; instead, the writing continues, only invalidating the existing block. When bank0 is full, valid blocks in bank0 can be migrated to bank1, and then written to the header of bank1, switching the effective bank to bank1. Then, bank0 is completely erased. This process is repeated, allowing users to repeatedly write data; this process is called garbage collection (GC). During garbage collection (GC), considering the possibility of new read / write requests, space is reserved in bank0 to respond to these new requests, which is equivalent to reducing the data storage space in bank0. Summary of the Invention
[0003] This application provides a data processing method, apparatus, and vehicle that enables data writing during garbage collection without reserving space in the memory block to be migrated.
[0004] In a first aspect, a data processing method is provided, comprising: during the execution of a garbage collection operation through a first memory block and a second memory block, obtaining a first read / write request, the first read / write request being used to request the writing of first data, the first memory block being a memory block to be migrated out, the second memory block being a memory block to be migrated in, the first memory block including at least one sector, and the second memory block including at least one sector; in response to the first read / write request, stopping the execution of the garbage collection operation and writing the first data into a first data block in the second memory block.
[0005] Based on the above technical solution, when a new read / write request appears, garbage collection can be stopped and the new data can be written to the memory block where data is to be migrated. This allows data writing during garbage collection to be performed without reserving space in the memory block where data is to be migrated.
[0006] In some possible implementations, the number of sectors in the first memory block is the same as the number of sectors in the second memory block.
[0007] In conjunction with the first aspect, in some implementations of the first aspect, when garbage collection is performed on the first memory block and the second memory block, obtaining the first read / write request includes: when garbage collection is performed on the first memory block and the second memory block and a preset number of data blocks in the first memory block are migrated to the second memory block, reading the first read / write request.
[0008] Based on the above technical solution, after migrating a preset number of data blocks, the system can proactively check for new read / write requests. If a new read / write request exists, the data block migration operation can be stopped, and the operation corresponding to that read / write request can be executed. In this way, a "small steps, quick runs" approach can be adopted during the garbage collection migration phase, continuously checking for new read / write requests. When a new read / write request is received, the garbage collection operation can be paused, the new data written to a new memory block, and then the garbage collection operation can be resumed, without reserving space in the memory block where data is to be migrated.
[0009] In conjunction with the first aspect, in some implementations of the first aspect, when garbage collection is performed on the first memory block and the second memory block, obtaining the first read / write request includes: when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased, reading the first read / write request.
[0010] Based on the above technical solution, after erasing a preset number of sectors, the system can actively check for new read / write requests. If a new read / write request exists, the sector erasure operation can be stopped, and the operation corresponding to that read / write request can be executed. In this way, the erase phase of garbage collection can adopt a "small steps, fast execution" approach, continuously checking for new read / write requests. When a new read / write request is received, the garbage collection operation can be paused, the new data written to a new memory block, and then the garbage collection operation can be resumed, without reserving space in the memory block where data is to be migrated.
[0011] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: stopping the acquisition of read / write requests when the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be moved out in the first memory block.
[0012] Based on the above technical solution, by comparing the remaining space in the second memory block with the sum of the space occupied by the data blocks to be migrated out in the first memory block, it is possible to avoid the situation where too much new data occupies the storage space of the second memory block, which would prevent the garbage collection operation from being completed.
[0013] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: stopping the acquisition of read / write requests when the remaining space in the second memory block is less than or equal to the preset storage space.
[0014] Based on the above technical solution, by comparing the remaining space in the second memory block with the preset storage space, it is possible to avoid the situation where too much new data occupies the storage space of the second memory block, which would prevent the garbage collection operation from being completed.
[0015] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: if a second data block in the first memory block is a data block to be migrated to the second memory block and the first data block and the second data block have the same identifier, in response to resuming garbage collection, performing the migration of other data blocks in the first memory block except for the second data block; or, if a third data block in the first memory block is a data block that has been migrated to the second memory block and the first data block and the third data block have the same identifier, in response to resuming garbage collection, performing the migration of other data blocks in the first memory block except for the third data block.
[0016] Based on the above technical solution, when new data is written to the first data block in the second memory block and the identifier of the second data block to be migrated in the first memory block is the same as the identifier of the first data block, the migration of other data blocks in the first memory block except for the second data block can be performed after the garbage collection operation is resumed. This avoids duplicate and invalid migrations during the garbage collection process.
[0017] In conjunction with the first aspect, in some implementations of the first aspect, before writing the first data into the first data block in the second memory block or moving the data block of the first memory block into the second memory block, the method further includes: writing header information of the second memory block, the header information indicating that the second memory block is valid.
[0018] Based on the above technical solution, before writing the first data into the first data block of the second memory block or before moving the data block of the first memory block into the second memory block, the header information of the second memory block can be written first. This avoids situations where, during garbage collection, power-down and subsequent power-on result in the data in the second memory block being completely erased, or the data in the second memory block being treated as dirty data. This prevents the repeated moving of data blocks already moved out of the first memory block into the second memory block, thus improving the efficiency of garbage collection and reducing the time required for garbage collection.
[0019] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block; and migrating the data blocks to be moved out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0020] Based on the above technical solution, by indicating the validity of the second memory block through the header information, it can be determined that the first memory block is moving data blocks into the second memory block when power is off. By traversing the information of data blocks in the first and second memory blocks, information on data blocks that have already been moved from the first memory block into the second memory block can be obtained, thereby enabling the first memory block to continue moving data that has not yet been moved out into the second memory block.
[0021] In some possible implementations, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of a first memory block, wherein, when the header information of a second memory block indicates that the second memory block is valid, obtaining information about data blocks in the first memory block and information about data blocks in the second memory block, including: when the header information of the first memory block indicates that the first memory block is valid and the header information of the second memory block indicates that the second memory block is valid, obtaining information about data blocks in the first memory block and information about data blocks in the second memory block.
[0022] In some possible implementations, the header information of the first memory block includes a first serial number, and the header information of the second memory block includes a second serial number. Before migrating the data block to be migrated out of the first memory block to the second memory block based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the method further includes: determining, based on the first serial number and the second serial number, that the first memory block is a data block to be migrated out and / or the second memory block is a memory block to be migrated in.
[0023] The header information of the second memory block indicates that the second memory block is valid, which can also be understood as the existence of data blocks in the second memory block (the data blocks can be data blocks moved out from the first memory block, or data blocks newly written during garbage collection). Alternatively, the header information of the second memory block indicating that the second memory block is valid can also be understood as the data in the second memory block not being treated as dirty data.
[0024] In conjunction with the first aspect, in some implementations of the first aspect, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erasable state among the multiple sectors of the first memory block; and performing an erasure operation on the sectors in the non-erasable state.
[0025] Based on the above technical solution, by indicating the failure of the first memory block through the header information, it can be determined that an erase operation was being performed on the sectors of the first memory block when power was off. By obtaining information on the sectors in the non-erased state among multiple sectors of the first memory block, the erase operation on the unerased sectors of the first memory block can continue after power is restored.
[0026] In some possible implementations, the method further includes: obtaining the header information of the second memory block when a power-down and power-on occurs during garbage collection; and obtaining information on the non-erased sectors among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid, including: obtaining information on the non-erased sectors among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid and the header information of the second memory block indicates that the second memory block is valid.
[0027] In some possible implementations, the header information of the first memory block indicates that the first memory block is invalid, which can also be understood as the header information of the first memory block being missing, or the header information of the first memory block being erased.
[0028] In conjunction with the first aspect, in some implementations of the first aspect, before obtaining information about sectors in a non-erased state among multiple sectors of the first memory block, the method further includes: determining that the first memory block includes erase tags and migration tags, or determining that the first memory block does not include erase tags and does not include migration tags, or determining that the first memory block only includes migration tags; wherein, the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0029] Based on the above technical solution, if the first memory block contains both erase and migration tags, or only migration tags, or neither erase nor migration tags, it can be determined that the first memory block is an incompletely erased memory block. Thus, after power-on, information on sectors in the first memory block that are not in an erased state can be searched, allowing for continued erase operations on those sectors.
[0030] In some possible implementations, the method further includes: obtaining the header information of the first memory block when a power-down and power-on occurs during garbage collection; and determining that the garbage collection operation has been completed if only an erase tag exists in the first memory block.
[0031] Based on the above technical solution, if only the erase tag exists, after power-on, there is no need to search for sectors in the non-erased state in the first memory block again. Instead, the first memory block can be directly identified as a memory block that has been erased, which helps to improve the efficiency of garbage collection and also helps to reduce the time required for garbage collection.
[0032] In some possible implementations, the erase tag and migration tag are located at the end of the first memory block.
[0033] Secondly, this application provides a data processing method, which includes: during the garbage collection operation performed through a first memory block and a second memory block, obtaining information about one or more data blocks to be migrated out in the first memory block, wherein the first memory block is the memory block to be migrated out and the second memory block is the memory block to be migrated into, the first memory block includes at least one sector and the second memory block includes at least one sector; after writing the header information of the second memory block, migrating one or more data blocks from the first memory block into the second memory block, wherein the header information indicates that the second memory block is valid.
[0034] Based on the above technical solution, the header information of the second memory block can be written before moving the data blocks from the first memory block into the second memory block. This avoids situations where, during garbage collection, power-down and subsequent power-on result in the data in the second memory block being completely erased, or the data in the second memory block being treated as dirty data. This prevents the repeated moving of data blocks already moved out of the first memory block into the second memory block, thus improving garbage collection efficiency and reducing the time required for garbage collection.
[0035] In some possible implementations, the number of sectors in the first memory block is the same as the number of sectors in the second memory block.
[0036] In conjunction with the second aspect, in some implementations of the second aspect, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block; and migrating the data blocks to be moved out from one or more data blocks to the second memory block based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0037] Based on the above technical solution, by indicating the validity of the second memory block through the header information, it can be determined that the first memory block is moving data blocks into the second memory block when power-down occurs. By traversing the information of data blocks in the first and second memory blocks, information on data blocks that have already been moved from the first memory block to the second memory block can be obtained, thereby enabling the first memory block to continue moving data that has not yet been moved out into the second memory block.
[0038] In some possible implementations, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of a first memory block, wherein, when the header information of a second memory block indicates that the second memory block is valid, obtaining information about data blocks in the first memory block and information about data blocks in the second memory block, including: when the header information of the first memory block indicates that the first memory block is valid and the header information of the second memory block indicates that the second memory block is valid, obtaining information about data blocks in the first memory block and information about data blocks in the second memory block.
[0039] In some possible implementations, the header information of the first memory block includes a first serial number, and the header information of the second memory block includes a second serial number. Before migrating the data block to be migrated out of the first memory block to the second memory block based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the method further includes: determining, based on the first serial number and the second serial number, that the first memory block is a data block to be migrated out and / or the second memory block is a memory block to be migrated in.
[0040] The header information of the second memory block indicates that the second memory block is valid, which can also be understood as the existence of data blocks in the second memory block (the data blocks can be data blocks moved out from the first memory block, or data blocks newly written during garbage collection). Alternatively, the header information of the second memory block indicating that the second memory block is valid can also be understood as the data in the second memory block not being treated as dirty data.
[0041] In conjunction with the second aspect, in some implementations of the second aspect, the method further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erasable state among the multiple sectors of the first memory block; and performing an erasure operation on the sectors in the non-erasable state.
[0042] Based on the above technical solution, by indicating the failure of the first memory block through the header information, it can be determined that an erase operation was being performed on the sectors of the first memory block when power-down occurred. By obtaining information on the sectors in the non-erased state among multiple sectors of the first memory block, the erase operation on the unerased sectors of the first memory block can continue after power-on.
[0043] In some possible implementations, the method further includes: obtaining the header information of the second memory block when a power-down and power-on occurs during garbage collection; and obtaining information on the non-erased sectors among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid, including: obtaining information on the non-erased sectors among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid and the header information of the second memory block indicates that the second memory block is valid.
[0044] In some possible implementations, the header information of the first memory block indicates that the first memory block is invalid, which can also be understood as the header information of the first memory block being missing, or the header information of the first memory block being erased.
[0045] In conjunction with the second aspect, in some implementations of the second aspect, before obtaining information about sectors in a non-erased state among multiple sectors of the first memory block, the method further includes: determining that the first memory block includes erase tags and migration tags, or determining that the first memory block does not include erase tags and does not include migration tags, or determining that the first memory block only includes migration tags; wherein, the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0046] Based on the above technical solution, if the first memory block contains both erase and migration tags, or only migration tags, or neither erase nor migration tags, it can be determined that the first memory block is an incompletely erased memory block. Thus, after power-on, information on sectors in the first memory block that are not in an erased state can be searched, allowing for continued erase operations on those sectors.
[0047] In some possible implementations, the method further includes: obtaining the header information of the first memory block when a power-down and power-on occurs during garbage collection; and determining that the garbage collection operation has been completed if only an erase tag exists in the first memory block.
[0048] Based on the above technical solution, if only the erase tag exists, after power-on, there is no need to search for sectors in the non-erased state in the first memory block again. Instead, the first memory block can be directly identified as a memory block that has been erased, which helps to improve the efficiency of garbage collection and also helps to reduce the time required for garbage collection.
[0049] In some possible implementations, the erase tag and migration tag are located at the end of the first memory block.
[0050] Thirdly, this application provides a data processing apparatus, comprising: an acquisition unit, configured to acquire a first read / write request during a garbage collection operation performed through a first memory block and a second memory block, the first read / write request being used to request the writing of first data, the first memory block being a memory block to be migrated out, the second memory block being a memory block to be migrated in, the first memory block including at least one sector, and the second memory block including at least one sector; and a data processing unit, configured to, in response to the first read / write request, stop performing the garbage collection operation and write the first data into a first data block in the second memory block.
[0051] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is used to: read the first read / write request when garbage collection is performed on the first memory block and the second memory block and a preset number of data blocks in the first memory block are migrated to the second memory block.
[0052] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is used to: read the first read / write request when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased.
[0053] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is also used to: stop acquiring read / write requests when the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be moved out in the first memory block.
[0054] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is also used to: stop acquiring read / write requests when the remaining space in the second memory block is less than or equal to the preset storage space.
[0055] In conjunction with the third aspect, in some implementations of the third aspect, the data processing unit is configured to, in response to resuming garbage collection, perform the migration of other data blocks in the first memory block except for the second data block when the second data block in the first memory block is a data block to be migrated to the second memory block and the identifiers of the first data block and the second data block are the same; or, in response to resuming garbage collection, the data processing unit is configured to perform the migration of other data blocks in the first memory block except for the third data block when the third data block in the first memory block is a data block that has been migrated to the second memory block and the identifiers of the first data block and the third data block are the same.
[0056] In conjunction with the third aspect, in some implementations of the third aspect, the data processing unit is further configured to: write header information of the second memory block before writing the first data into the first data block of the second memory block or before moving the data block of the first memory block into the second memory block, wherein the header information indicates that the second memory block is valid.
[0057] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is further configured to acquire the header information of the second memory block when a power-down and power-on occurs during the garbage collection process; the acquisition unit is further configured to acquire the information of the data blocks in the first memory block and the information of the data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; the data processing unit is further configured to migrate the data blocks to be moved out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0058] In conjunction with the third aspect, in some implementations of the third aspect, the acquisition unit is further configured to acquire the header information of the first memory block when a power-down and power-on occurs during the garbage collection process; the acquisition unit is further configured to acquire information on the sectors in the non-erased state among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid; the data processing unit is further configured to perform an erasure operation on the sectors in the non-erased state.
[0059] In conjunction with the third aspect, in some implementations of the third aspect, a determining unit is used to determine, before the obtaining unit obtains information about sectors in a non-erased state, whether the first memory block includes an erase tag and a migration tag, or whether the first memory block does not include an erase tag and does not include a migration tag, or whether the first memory block only includes a migration tag; wherein, the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0060] Fourthly, this application provides a data processing apparatus, comprising: an acquisition unit, configured to acquire information about one or more data blocks to be migrated out in the first memory block during a garbage collection operation performed through a first memory block and a second memory block, wherein the first memory block is a memory block to be migrated out and the second memory block is a memory block to be migrated in, the first memory block including at least one sector and the second memory block including at least one sector; and a data processing unit, configured to migrate one or more data blocks from the first memory block to the second memory block after writing header information of the second memory block, wherein the header information indicates that the second memory block is valid.
[0061] In conjunction with the fourth aspect, in some implementations of the fourth aspect, the acquisition unit is further configured to acquire the header information of the second memory block when a power-down and power-on occurs during garbage collection; the acquisition unit is further configured to acquire the information of the data blocks in the first memory block and the information of the data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; the data processing unit is further configured to migrate the data blocks to be moved out from one or more data blocks to the second memory block based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0062] In conjunction with the fourth aspect, in some implementations of the fourth aspect, the acquisition unit is further configured to acquire the header information of the first memory block when a power-down and power-on occurs during the garbage collection process; the acquisition unit is further configured to acquire information on the sectors in the non-erased state among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid; the data processing unit is further configured to perform an erasure operation on the sectors in the non-erased state.
[0063] In conjunction with the fourth aspect, in some implementations of the fourth aspect, the apparatus further includes: a determining unit, configured to determine, before the acquiring unit acquires information about sectors in a non-erased state, that the first memory block includes an erase tag and a migration tag, or that the first memory block does not include an erase tag and does not include a migration tag, or that the first memory block only includes a migration tag; wherein the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0064] Fifthly, this application provides a data processing apparatus, which includes a processor and a memory, wherein the memory is used to store instructions, and the processor executes the instructions stored in the memory to cause the apparatus to perform any one of the possible methods in the first aspect or the second aspect.
[0065] Sixthly, this application provides a vehicle that includes any of the possible devices described in the third to fifth aspects above.
[0066] In a seventh aspect, this application provides a computer program product comprising: computer program code, which, when executed on a computer, causes the computer to perform any one of the possible methods described in the first or second aspect above.
[0067] It should be noted that the above-mentioned computer program code can be stored in whole or in part on the first storage medium, wherein the first storage medium can be packaged together with the processor or packaged separately from the processor. This application embodiment does not specifically limit this.
[0068] Eighthly, this application provides a computer-readable storage medium storing program code that, when executed on a computer, causes the computer to perform any of the possible methods described in the first or second aspect above.
[0069] Ninthly, this application provides a chip system including circuitry for performing any of the possible methods described in the first or second aspect above. Attached Figure Description
[0070] Figure 1 is a functional block diagram of the vehicle provided in an embodiment of this application.
[0071] Figure 2 is a schematic diagram of the garbage collection (GC) process.
[0072] Figure 3 is a schematic flowchart of the data processing method provided in the embodiments of this application.
[0073] Figure 4 is a schematic diagram of the waste recycling operation performed by bank0 and bank1 according to an embodiment of this application.
[0074] Figure 5 is another schematic diagram of the waste recycling operation performed by bank0 and bank1 according to an embodiment of this application.
[0075] Figure 6 is a schematic diagram of bank0 before bank0 and bank1 perform the garbage collection operation in an embodiment of this application.
[0076] Figure 7 is a schematic diagram of the state changes of the block for each state provided in the application embodiment.
[0077] Figure 8 is a schematic diagram of the migration process before optimization.
[0078] Figure 9 is an optimized migration diagram provided in an embodiment of this application.
[0079] Figure 10 is a schematic diagram of data block migration provided in an embodiment of this application.
[0080] Figure 11 is another schematic diagram of data block migration provided in an embodiment of this application.
[0081] Figure 12 is a schematic diagram of identifying data blocks in bank1 according to an embodiment of this application.
[0082] Figure 13 is a schematic diagram of finding a successor point provided in an embodiment of this application.
[0083] Figure 14 is a schematic diagram of finding the continuing erase point provided in an embodiment of this application.
[0084] Figure 15 is another schematic flowchart of the data processing method provided in the embodiments of this application.
[0085] Figure 16 is a schematic diagram of the AUTOSAR-based software architecture provided in an embodiment of this application.
[0086] Figure 17 is another schematic flowchart of the data processing method provided in the embodiments of this application.
[0087] Figure 18 is another schematic flowchart of the data processing method provided in the embodiments of this application.
[0088] Figure 19 is a schematic diagram of setting a waterline in a new bank according to an embodiment of this application.
[0089] Figure 20 is a schematic diagram of the dual-bank activation mechanism in a multi-bank scenario provided in the embodiments of this application.
[0090] Figure 21 is a schematic block diagram of a data processing apparatus provided in an embodiment of this application.
[0091] Figure 22 is another schematic block diagram of the data processing apparatus provided in the embodiments of this application. Detailed Implementation
[0092] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this document is merely a description of the association relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. "At least one" refers to one or more. For example, "at least one of A and B," similar to "A and / or B," describes the association relationship between related objects, indicating that three relationships can exist. For example, at least one of A and B can represent: A existing alone, A and B existing simultaneously, and B existing alone.
[0093] The prefixes such as "first" and "second" used in this application embodiment are merely for distinguishing different descriptive objects and do not limit the position, order, priority, quantity, or content of the described objects. The use of ordinal numbers and other prefixes used to distinguish descriptive objects in this application embodiment does not constitute a limitation on the described objects. The description of the described objects is given in the claims or the context of the embodiments, and should not constitute unnecessary restrictions due to the use of such prefixes. Furthermore, in the description of this embodiment, unless otherwise stated, "multiple" means two or more.
[0094] Figure 1 is a functional block diagram of a vehicle 100 provided in an embodiment of this application.
[0095] As shown in Figure 1, the vehicle 100 may include a perception system 110 and a computing platform 120. The perception system 110 may include one or more sensors for sensing information about the environment surrounding the vehicle 100. For example, the perception system 110 may include a positioning system, which may be a Global Positioning System (GPS), a BeiDou Navigation Satellite System, or another positioning system. Alternatively, the perception system 110 may include one or more of the following: an inertial measurement unit (IMU), an accelerometer, a lidar, millimeter-wave radar, ultrasonic radar, and a camera device. Furthermore, the perception system 110 may include one or more collision sensors.
[0096] Some or all of the functions of vehicle 100 can be controlled by computing platform 120. Computing platform 120 may include one or more processors, such as processors 121 to 12n (n being a positive integer). A processor is a circuit with signal processing capabilities. In one implementation, the processor can be a circuit with instruction read and execute capabilities, such as a central processing unit (CPU), microprocessor, graphics processing unit (GPU) (which can be understood as a type of microprocessor), or digital signal processor (DSP). In another implementation, the processor can implement certain functions through the logical relationships of hardware circuits. These logical relationships are fixed or reconfigurable. For example, the processor may be a hardware circuit implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD), such as a field-programmable gate array (FPGA). In reconfigurable hardware circuits, the process of the processor loading a configuration document and configuring the hardware circuit can be understood as the process of the processor loading instructions to implement some or all of the functions of the aforementioned units. Furthermore, the processor can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as a neural network processing unit (NPU), tensor processing unit (TPU), deep learning processing unit (DPU), etc. In addition, the computing platform 120 may also include a memory for storing instructions. Some or all of the processors 121 to 12n can call the instructions in the memory to implement the corresponding functions.
[0097] Optionally, the structure of the vehicle 100 described above is merely illustrative. In actual applications, various components of the vehicle 100 may be added or removed as needed.
[0098] The vehicle 100 in this application may include: road vehicles, water vehicles, air vehicles, industrial equipment, agricultural equipment, or entertainment equipment, etc. For example, vehicle 100 may be a means of transportation (such as commercial vehicles, passenger cars, motorcycles, flying cars, trains, etc.), industrial vehicles (such as forklifts, trailers, tractors, etc.), engineering vehicles (such as excavators, bulldozers, cranes, etc.), agricultural equipment (such as lawnmowers, harvesters, etc.), amusement equipment, toy vehicles, etc. The embodiments of this application do not specifically limit the type of vehicle.
[0099] This application's embodiments may relate to the non-volatile memory domain of the AUTOSAR classic platform (AUTOSAR CP). AUTOSAR is an open industry standard established by OEMs, Tier 1 automotive suppliers, semiconductor manufacturers, software vendors, and tool vendors for automotive software architecture. This architecture covers functions such as real-time scheduling, communication, diagnostics, memory management, functional safety, and information security required for building automotive controllers. AUTOSAR CP is AUTOSAR's solution for high real-time and high-security embedded systems and is currently widely used in traditional embedded microcontroller units (MCUs). CP provides a hierarchical non-volatile memory management method for managing user data stored in Flash memory.
[0100] The current AUTOSAR non-volatile storage management system includes the AUTOSAR software component (SWC), runtime environment (RTE), AUTOSAR storage stack, and hardware device (Flash). The SWC initiates data storage requests, the RTE passes these requests to the AUTOSAR storage stack, which encapsulates the requested data and writes it to the hardware device. The data to be stored is encapsulated into blocks and stored in one or more pages; a page is the smallest unit of writing to Flash. The smallest unit of erasing Flash is a sector, and a sector can contain multiple pages.
[0101] As mentioned earlier, the Fee module in the AUTOSAR storage stack is used to simulate EEPROM and directly determines the storage location of user data. The Fee specification divides a Flash space into two banks, for example, bank0 and bank1. When upper-layer applications write a block, encountering the same block ID does not erase the existing block; instead, it continues writing downwards, only invalidating the existing block. Figure 2 illustrates the GC process. As shown in Figure 2, when bank0 is full, valid blocks in bank0 are migrated to bank1 and written to the header of bank1, switching the effective bank to bank1. Then, bank0 is completely erased, and this process is repeated, allowing users to repeatedly write data. During GC, considering new read / write requests, space is reserved in bank0 to handle these requests, effectively reducing the data storage space in bank0.
[0102] This application provides a data processing method, apparatus, and vehicle. During garbage collection (GC), if there are read / write requests, GC can be paused, new data can be directly written to a new memory block, and then GC can be resumed. This allows for responding to user read / write requests during GC. Simultaneously, there is no need to reserve space in the old memory block for new data. The "new memory block" can refer to the memory block where data is to be migrated in, and the "old memory block" can refer to the memory block where data is to be migrated out.
[0103] Figure 3 shows a schematic flowchart of a data processing method 300 provided in an embodiment of this application. This method 300 can be executed by the vehicle 100; or by the computing platform 120; or by a processor, circuit, or chip in the computing platform 120; or by the Fee module. The method 300 includes:
[0104] S310, during the garbage collection operation performed through the first memory block and the second memory block, a first read / write request is obtained. The first read / write request is used to request the writing of first data. The first memory block is a memory block for which data is to be migrated out, and the second memory block is a memory block for which data is to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector.
[0105] Optionally, the number of sectors in the first memory block is the same as the number of sectors in the second memory block.
[0106] For example, the first data is the vehicle's mileage data.
[0107] For example, the first data is information about the vehicle's remaining battery power.
[0108] S320, in response to the first read / write request, stops performing garbage collection and writes the first data into the first data block in the second memory block.
[0109] For example, Figure 4 illustrates a schematic diagram of garbage collection operations performed on bank0 and bank1 according to an embodiment of this application. As shown in Figure 4, bank0 is a memory block to be migrated out, and bank1 is a memory block to be migrated in. Blocks 1, 2, and 3 in bank0 are data blocks to be migrated to bank1. When block 1 in bank0 is migrated into bank1, the Fee module receives a first read / write request, which requests the writing of first data. In response to the first read / write request, the Fee module can stop performing garbage collection operations and write the first data to block 4 in bank1.
[0110] The scenario shown in Figure 4 above represents the Fee receiving a new read / write request during the migration phase of garbage collection. The migration phase can refer to the stage of migrating data blocks from bank0 to bank1.
[0111] Optionally, the method 300 further includes: resuming garbage collection operations after writing the first data to the second memory block. For example, as shown in Figure 4, after writing the first data to block 4 in bank1, the Fee module can continue performing migration operations for blocks 2 and 3 in bank0.
[0112] In this embodiment, when a new read / write request is received, the garbage collection operation can be stopped and the new data can be written to the memory block where data is to be migrated. This eliminates the need to reserve space in the memory block where data is to be migrated, and allows data writing during the garbage collection process to proceed.
[0113] Optionally, when garbage collection is performed on the first memory block and the second memory block, obtaining the first read / write request includes: when garbage collection is performed on the first memory block and the second memory block and a preset number of data blocks in the first memory block are migrated to the second memory block, reading the first read / write request.
[0114] Optionally, the preset quantity is 1.
[0115] For example, as shown in Figure 4, when block 1 from bank0 is moved to bank1, the Fee module can proactively obtain read / write requests from the non-volatile random access memory manager (NvM) module. If a new read / write request exists, garbage collection can be stopped and the data corresponding to the new read / write request can be written to bank4. If no new read / write request exists, then block 2 from bank0 can continue to be moved to bank1. When block 2 from bank0 is moved to bank1, the Fee module can proactively obtain read / write requests from the NvM.
[0116] In this embodiment, after migrating a preset number of data blocks, the system can actively check for new read / write requests. If a new read / write request exists, the data block migration operation can be stopped, and the operation corresponding to that read / write request can be executed. This allows for a "small steps, quick runs" approach during the garbage collection migration phase, continuously detecting new read / write requests. When a new read / write request is received, the garbage collection operation can be paused, the new data written to a new memory block, and then the garbage collection operation can be resumed, eliminating the need to reserve space in the memory block where data is to be migrated.
[0117] Optionally, when garbage collection is performed on the first memory block and the second memory block, obtaining the first read / write request includes: reading the first read / write request when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased.
[0118] For example, Figure 5 illustrates a schematic diagram of garbage collection operations performed on bank0 and bank1 according to an embodiment of this application. As shown in Figure 5, after all data in bank0 has been migrated to bank1, the Fee module can begin erasing sectors in bank0. For example, bank0 includes sector 1 and sector 2. The Fee module has migrated blocks 1-3 in bank0 to bank1 and started performing the erasure operation on bank0. After completing the erasure operation on sector 1, the Fee module can actively obtain read / write requests from the NvM. If a new read / write request exists, garbage collection can be stopped and the data corresponding to the new read / write request can be written to bank1. If no new read / write request exists, the erasure of sector 2 in bank0 can continue.
[0119] The scenario shown in Figure 5 above represents the Fee module receiving a new read / write request during the erase phase of garbage collection. The erase phase refers to the phase in which sectors in bank0 are erased.
[0120] In this embodiment, after erasing a preset number of sectors, the system can actively check for new read / write requests. If a new read / write request exists, the sector erasure operation can be stopped, and the operation corresponding to that read / write request can be executed. This allows for a "small steps, quick execution" approach during the garbage collection erasure phase, continuously detecting new read / write requests. When a new read / write request is received, the garbage collection operation can be paused, the new data written to a new memory block, and then the garbage collection operation can be resumed, eliminating the need to reserve space in the memory block where data is to be migrated.
[0121] Optionally, the method 300 further includes: stopping the acquisition of read / write requests if the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be moved out in the first memory block.
[0122] For example, during the process of migrating data from bank0 to bank1, the Fee module may receive new read / write requests. After writing the new data to the block in bank1, the Fee module can check the remaining space in bank1. If the remaining space is detected to be less than or equal to the sum of the spaces occupied by the data blocks to be migrated out in bank0, the module can stop receiving read / write requests and force the garbage collection operation to complete.
[0123] In this embodiment of the application, by comparing the remaining space in the second memory block with the sum of the space occupied by the data blocks to be migrated out in the first memory block, it is possible to avoid the situation where too much new data occupies the storage space of the second memory block, which would prevent the garbage collection operation from being completed.
[0124] Optionally, the method 300 further includes: stopping the acquisition of read / write requests when the remaining space in the second memory block is less than or equal to the preset storage space.
[0125] For example, during the migration of data from bank0 to bank1, the Fee module may receive new read / write requests. After writing the new data to the block in bank1, the Fee module can check the remaining space in bank1. If the remaining space is detected to be less than or equal to the preset storage space, it can stop receiving read / write requests and force the garbage collection operation to complete.
[0126] In this embodiment of the application, by comparing the remaining space in the second memory block with the preset storage space, it is possible to avoid the situation where excessive new data occupies the storage space of the second memory block, which would prevent the garbage collection operation from being completed.
[0127] Optionally, the method 300 further includes: if the second data block in the first memory block is a data block to be migrated to the second memory block and the identifiers of the first data block and the second data block are the same, in response to resuming garbage collection, performing the migration of other data blocks in the first memory block except for the second data block; or, if the third data block in the first memory block is a data block that has been migrated to the second memory block and the identifiers of the first data block and the third data block are the same, in response to resuming garbage collection, performing the migration of other data blocks in the first memory block except for the third data block.
[0128] In this embodiment, the Fee module can maintain the state changes of each block in real time during garbage collection, minimizing invalid migrations. For example, Figure 6 shows a schematic diagram of bank0 before garbage collection in this embodiment. It can be seen that the valid blocks in bank0 are blocks 1-6. The states of each block in bank0 that the Fee module can maintain before garbage collection can be found in Table 1.
[0129] Table 1
[0130] The block number above can be understood as the identification information of a block.
[0131] During garbage collection, if the Fee module moves block1 from bank0 to bank1, it will update the state of each block in bank0. For example, the updated state of each block can be seen in Table 2.
[0132] Table 2
[0133] In this embodiment of the application, when initiating migration, the state of each block in bank0 can be classified. There are four possible states for a block:
[0134] (1) The block to be migrated;
[0135] (2) Blocks that have never been written to;
[0136] (3) The migrated block;
[0137] (4) Blocks newly written during GC.
[0138] Of the four states above, only the block to be migrated needs to be migrated; the other states do not require migration.
[0139] For example, Figure 7 illustrates a schematic diagram of the state changes of a block for each state provided in the embodiments of this application. A block to be migrated becomes a migrated block after the migration is completed.
[0140] For example, the block to be migrated was written in real time during GC, and its state changed to the newly written block during GC. The comparison before and after optimization is illustrated in Figures 8 and 9 below. Figure 8 shows a migration diagram before optimization. As shown in Figure 8, assuming bank0 has a total of 6 blocks (e.g., blocks 1-6), during GC, due to read / write requests, 3 new blocks (e.g., blocks 4-6) were written to the reserved space of bank0. The effect before optimization is shown in Figure 8. At the start of migration, there are a total of 6 blocks, namely blocks 1-6. During the migration process, blocks 4-6 were written in real time, which could only be written to the reserved space of bank0 before optimization. After blocks 1-6 in the non-reserved space are migrated, the Fee module will also migrate blocks 4-6 in the reserved space to bank1. In the entire process, the Fee module migrates a total of 9 blocks.
[0141] Figure 9 shows an optimized migration diagram provided in an embodiment of this application. As shown in Figure 9, there are a total of 6 blocks when migration starts, namely blocks 1-6. After blocks 1-3 in bank0 have migrated, the status of each block in bank0 can be updated. The updated status is shown in Table 3:
[0142] Table 3
[0143] After migrating blocks 1-3 from bank0 to bank1, the Fee module receives new read / write requests. Based on these new requests, the Fee module can pause garbage collection and write the new data to blocks 4-6 in bank1. At this point, the Fee module can update the state of each block in bank0. The updated state is shown in Table 4.
[0144] Table 4
[0145] For example, block 4 in bank0 stores the vehicle's remaining mileage at time T1, while the newly written block 4 in bank1 stores the vehicle's remaining mileage at time T2, which is later than time T1.
[0146] For example, block 5 in bank0 stores the vehicle's remaining battery power at time T3, while the newly written block 5 in bank1 stores the vehicle's remaining battery power at time T4, which is later than time T3.
[0147] For example, block 6 in bank0 stores the vehicle's remaining fuel level at time T5, while the newly written block 6 in bank1 stores the vehicle's remaining fuel level at time T6, which is later than time T5.
[0148] Thus, after writing new data to blocks 4-6 in bank1, the state of blocks 4-6 in the state table is updated from a block awaiting migration to the block newly written during GC. Therefore, after garbage collection resumes, since the state of blocks 4-6 has been updated to the block newly written during GC, the Fee module no longer needs to migrate blocks 4-6 in bank0. In this process, a total of 3 blocks are migrated, a reduction of 6 blocks compared to Figure 8, thereby reducing the number of invalid migrations.
[0149] Taking bank0 as the first memory block and bank1 as the second memory block as the second example, the first data can be the data written to blocks 4-6 in bank1. Since the identifier of block 4, which is newly written to bank1, is the same as that of block 4 in bank0, the identifier of block 5, which is newly written to bank1, is the same as that of block 5 in bank0, and the identifier of block 6, which is newly written to bank1, is the same as that of block 6 in bank0, after resuming the garbage collection operation, the Fee module can determine that there are no more blocks that need to be migrated to bank1 based on the status of each block shown in Table 4 above, and thus can start the erase operation for bank0.
[0150] For example, a migrated block is written in real time during GC, and its state changes to a newly written block during GC.
[0151] For example, Figure 10 shows a schematic diagram of data block migration provided in an embodiment of this application. As shown in Figure 10, when migration is started, there are a total of 6 blocks, namely blocks1-6. After blocks1-3 in bank0 are migrated, the status of each block in bank0 can be updated. The updated status is shown in Table 3. After migrating blocks1-3 in bank0 to bank1, the Fee module obtains new read / write requests. The Fee module can pause garbage collection based on the new read / write requests and write the new data to block1 in bank1. At this time, the Fee module can update the status of each block in bank0. The updated status is shown in Table 5.
[0152] Table 5
[0153] In this way, after garbage collection is restored, the Fee module can determine that the state of blocks 4-6 is a block to be migrated, so that blocks 4-6 in bank0 can continue to be migrated to bank1.
[0154] For example, a block that was not written to is written to in real time during GC, and its state changes to a block newly written during GC.
[0155] For example, Figure 11 shows a schematic diagram of data block migration provided in an embodiment of this application. As shown in Figure 11, there are a total of 6 blocks when migration starts, namely blocks1-6. After blocks1-3 in bank0 are migrated, the state of each block in bank0 can be updated. The updated state is shown in Table 3 (block7 is not included in bank0, as it is a block that has not been written). After migrating blocks1-3 in bank0 to bank1, the Fee module obtains new read / write requests. The Fee module can pause garbage collection based on the new read / write requests and write the new data to block7 in bank1. At this time, the Fee module can update the state of each block in bank0 (the state of block7 is updated from a block that has not been written to a block that was newly written during GC). The updated state is shown in Table 6.
[0156] Table 6
[0157] In this way, after garbage collection is restored, the Fee module can determine that the state of blocks 4-6 is a block to be migrated, so that blocks 4-6 in bank0 can continue to be migrated to bank1.
[0158] In this embodiment, if new data is written to the first data block in the second memory block and the identifier of the second data block to be migrated in the first memory block is the same as the identifier of the first data block, the migration of other data blocks in the first memory block except for the second data block can be performed after the garbage collection operation is resumed. This avoids duplicate and invalid migrations during garbage collection.
[0159] Optionally, before writing the first data into the first data block of the second memory block or moving the data block of the first memory block into the second memory block, the method 300 further includes: writing header information of the second memory block, wherein the header information indicates that the second memory block is valid.
[0160] For example, the header information includes serial number information.
[0161] The above header information indicates that the second memory block is valid. This can be understood as the header information indicating that there is already a data block in the second memory block, or that the data in the second memory block will not be treated as dirty data.
[0162] In this embodiment, before writing the first data into the first data block of the second memory block or moving the data block from the first memory block into the second memory block, the header information of the second memory block can be written first. This avoids situations where, during garbage collection, power-down and subsequent power-on result in the data in the second memory block being completely erased, or the data in the second memory block being treated as dirty data. This prevents the repeated moving of data blocks already moved out of the first memory block into the second memory block, thus improving the efficiency of garbage collection and reducing its duration.
[0163] Optionally, the method 300 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block; and migrating the data blocks to be moved out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0164] For example, consider a first memory block as bank0 and a second memory block as bank1. Upon power-down and power-back, the header information of bank1 confirms that the data to be migrated to bank1 is valid. The Fee module can then iterate through the data blocks in bank0 and bank1. For instance, by first iterating through the data blocks in bank1, it can determine the information of data blocks that have already been migrated from bank0 to bank1. Then, by iterating through the data blocks in bank0, it can determine the data blocks in bank0 that need to be migrated out. The Fee module can then continue migrating the data blocks to be migrated out from bank0 to bank1.
[0165] For example, Figure 12 shows a schematic diagram of identifying data blocks in bank1 according to an embodiment of this application. At the start of garbage collection, header information is written to bank1. If a power outage occurs during garbage collection, the Fee module can determine that both bank0 and bank1 are active after power is restored, since both have header information. By traversing both bank0 and bank1, the Fee module can find the transition point and the erase point, ensuring that garbage collection is recoverable after an abnormal power outage. First, normal blocks and abnormal blocks caused by power outages can be identified. When writing data to a data block, the Fee module adds a header area at the beginning of the data block and a tail area at the end. The header and tail areas include the block's identification information (e.g., block number), block data length, and a special devil number. For normal blocks, the header and tail area verification passes; however, for abnormal blocks, the header and tail area verification fails due to tail incompleteness.
[0166] For example, bank0 includes blocks 1-6. When the Fee module migrates blocks 1-3 and part of block 4 from bank0 to bank1, a power-down occurs. After power-down and power-on, the Fee module can determine that bank1 is the memory block to be migrated based on the header information of bank1. At this time, the Fee module can traverse the data blocks in bank0 and bank1, determining that bank0 includes blocks 1-6 and bank1 includes blocks 1-4. The Fee module can determine through the above verification method that the header and tail information of block 4 in bank1 fails the verification (or the tail area of bank4 is missing). After power-on, it will erase block 4 in bank1. In this way, the Fee module can determine that the continuation point is block 4 in bank0, and thus can continue to perform the migration operation of blocks 4-6 in bank0.
[0167] In this embodiment, the header information of the second memory block indicates that the second memory block is valid, which determines that the first memory block is moving data blocks into the second memory block when power-down occurs. By traversing the information of data blocks in the first and second memory blocks, information on data blocks that have already been moved from the first memory block to the second memory block can be obtained, thereby enabling data blocks that have not been moved out of the first memory block to continue moving into the second memory block.
[0168] Optionally, the method 300 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block, wherein when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block includes: when the header information of the first memory block indicates that the first memory block is valid and the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0169] Since the erasure phase of garbage collection is performed sequentially from the head to the tail of bank0, if both bank0 and bank1 contain header information after power-down and power-back, the Fee module can determine that the garbage collection migration phase had been executed when power was down.
[0170] Optionally, the header information of the first memory block includes a first serial number, and the header information of the second memory block includes a second serial number. Before migrating the data block to be migrated out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the method 300 further includes: determining, according to the first serial number and the second serial number, that the first memory block is a data block to be migrated out and / or the second memory block is a memory block to be migrated in.
[0171] For example, Figure 13 illustrates a schematic diagram of finding a successor point provided in an embodiment of this application. As shown in Figure 13, after a power outage and subsequent power-on, the Fee module can first obtain the header information of bank0 and bank1. After determining that both bank0 and bank1 include header information, it can be determined that both bank0 and bank1 are valid. The Fee module uses the sequence number in the header information of bank0 and the sequence number in the header information of bank1 to determine that bank1 is the bank to be migrated and that the migration stage in garbage collection was executed when the power outage occurred. The Fee module can traverse bank0 and bank1, detecting that bank0 has block1 and block2 and bank1 has block1. In this way, the Fee module can regenerate the status table of the blocks in bank0, with block1 in the migrated state and block2 in the pending migration state, thus confirming that the successor point is block2. In this way, the migration action before the power outage will continue.
[0172] The header information of the second memory block indicates that the second memory block is valid, which can also be understood as the existence of data blocks in the second memory block (the data blocks can be data blocks moved out from the first memory block, or data blocks newly written during garbage collection). Alternatively, the header information of the second memory block indicating that the second memory block is valid can also be understood as the data in the second memory block not being treated as dirty data.
[0173] Optionally, the method 300 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erasable state among the multiple sectors of the first memory block; and performing an erasure operation on the sectors in the non-erasable state.
[0174] For example, after a power-down and power-back, the Fee module can determine if there are any banks with missing header information (or whose header information has been erased). If a bank with missing header information exists (e.g., bank0), it can be determined that the erase operation for that bank during garbage collection needs to be resumed. The Fee module can traverse each sector in bank0 to find the first sector in a non-erased state. The Fee module can then continue the erase operation from this non-erased sector.
[0175] For example, after a power-down and power-up, the Fee module can iterate through the header information of the two banks. If it is determined that the header information of one of the banks is missing, it can be determined that the bank is the one where data is to be migrated out and that the erase phase of garbage collection was executed when the power-down occurred.
[0176] In this embodiment, by indicating the failure of the first memory block through the header information, it can be determined that an erase operation was being performed on the sectors of the first memory block when power-down occurred. By obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block, the erase operation on the unerased sectors of the first memory block can continue after power-on.
[0177] Optionally, the method 300 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block, including: when the header information of the first memory block indicates that the first memory block is invalid and the header information of the second memory block indicates that the second memory block is valid, obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block.
[0178] For example, after a power-down and power-up, the Fee module can obtain the header information of two banks. If the header information of one bank is missing while the header information of the other bank is present, then the bank with the missing header information can be identified as the bank to be migrated out, and the bank with the present header information is the bank to be migrated in, and the erase phase of garbage collection was executed when the power-down occurred. The Fee module can determine that the erase operation for that bank (e.g., bank0) needs to be resumed during garbage collection. The Fee module can traverse each sector in bank0 to find the first sector in a non-erased state. The Fee module can then continue the erase operation from this non-erased sector.
[0179] Optionally, the header information of the first memory block indicates that the first memory block is invalid, which can also be understood as the header information of the first memory block being missing, or the header information of the first memory block being erased.
[0180] Optionally, before obtaining information about sectors in a non-erased state among multiple sectors of the first memory block, the method 300 further includes: determining that the first memory block includes erase tags and migration tags, or determining that the first memory block does not include erase tags and does not include migration tags, or determining that the first memory block only includes migration tags; wherein, the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0181] For example, Figure 14 illustrates a schematic diagram of finding a continuation erase point provided in an embodiment of this application. If a power outage and subsequent power-on occur during the erasure of bank0, the Fee module can find the continuation erase point by traversing the two banks. As shown in Figure 14, after power-on, the Fee module checks the header information of bank0 and bank1. If the header information of one bank is missing while the header information of the other bank is present, it can be determined that the bank with missing header information is the bank to be migrated out (e.g., bank0), and the bank with present header information is the bank to be migrated in (e.g., bank1), and the erasure phase of garbage collection was already executed when the power outage occurred. The next step for the Fee module is to confirm whether bank0 has been completely erased.
[0182] In this embodiment, an erase flag and a migration flag are designed to determine the erase status of bank0. For example, when bank0, where data is to be migrated, is completely erased, an erase flag is written to it. For example, before bank2 (or bank1) prepares to migrate data to bank0 (at this time, bank0 is the bank where data is to be migrated in, and bank2 (or bank1) is the bank where data is to be migrated out), a migration flag is written to bank0. Thus, there are four possible combinations of flags in bank0:
[0183] (1) If neither the erase flag nor the migration flag exists, treat it as dirty data;
[0184] (2) If only the erase flag exists, process it as if the erasure is complete;
[0185] (3) The presence of both erase flag and migration flag indicates that GC erasure is incomplete;
[0186] (4) Only the migration flag exists. This is an abnormal scenario and should be treated as dirty data.
[0187] For example, after power-on, if the Fee module determines that the combination mode of the Flag in bank0 is combination mode (2), then the Fee module can determine that the sectors in bank0 have been erased when power-off occurs.
[0188] For example, after power-on, if the Fee module determines that the combination of Flags in bank0 is combination mode (3), then the Fee module can determine that the sectors in bank0 were not completely erased when power-down occurred. The Fee module can check whether each sector is in an erasure state from top to bottom through the driver interface Fls_BlankCheck, until it finds the first sector in a non-erasure state, thus finding the continuation erase point. Then the erasure process continues, and after all sectors are erased, an erasure mark is written to complete garbage collection.
[0189] For example, after power-on, if the Fee module determines that the combination of Flags in bank0 is combination (1) and (4), then the Fee module can treat the data in bank0 as dirty data.
[0190] In this embodiment, if the first memory block contains both an erase tag and a migration tag, or only a migration tag, or neither an erase tag nor a migration tag, it can be determined that the first memory block is an incompletely erased memory block. Thus, after power-on, information about sectors in the first memory block that are not in an erased state can be searched, allowing the erasure operation on these sectors to continue.
[0191] Optionally, the method 300 further includes: in the event of a power outage and power-on during garbage collection, obtaining the header information of the first memory block; and determining that the garbage collection operation has been completed if only erase tags exist in the first memory block; wherein the erase tags are tags added to the first memory block after the data in the first memory block has been erased.
[0192] In this embodiment, if only the erase tag exists, after power-on, there is no need to search for sectors in the non-erased state in the first memory block again. Instead, the first memory block can be directly determined as a memory block that has been erased, which helps to improve the efficiency of garbage collection and also helps to reduce the time required for garbage collection.
[0193] Optionally, the erase tag and migration tag are located at the end of the first memory block.
[0194] Figure 15 shows a schematic flowchart of a data processing method 1500 provided in an embodiment of this application. This method 1500 can be executed by the vehicle 100; or by the computing platform 120; or by a processor, circuit, or chip in the computing platform 120; or by the Fee module. The method 1500 includes:
[0195] S1510, during the garbage collection operation performed through the first memory block and the second memory block, information about one or more data blocks to be migrated out in the first memory block is obtained. The first memory block is the memory block to be migrated out, and the second memory block is the memory block to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector.
[0196] Optionally, the number of sectors in the first memory block is the same as the number of sectors in the second memory block.
[0197] S1520: After writing the header information of the second memory block, one or more data blocks are moved from the first memory block to the second memory block, and the header information indicates that the second memory block is valid.
[0198] In this embodiment, the header information of the second memory block can be written before moving the data blocks from the first memory block to the second memory block. This avoids situations where, during garbage collection, power-down and subsequent power-on result in the data in the second memory block being completely erased, or the data in the second memory block being treated as dirty data. This prevents the repeated moving of data blocks already moved out of the first memory block into the second memory block, thus improving garbage collection efficiency and reducing the time required for garbage collection.
[0199] Optionally, the method 400 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block; and migrating the data blocks to be moved out from one or more data blocks to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0200] In this embodiment, the header information of the second memory block indicates that the second memory block is valid, which determines that the first memory block is moving data blocks into the second memory block when power-down occurs. By traversing the information of data blocks in the first and second memory blocks, information on data blocks that have already been moved from the first memory block to the second memory block can be obtained, thereby enabling data that has not been moved out of the first memory block to continue moving into the second memory block.
[0201] Optionally, the method 1500 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block, wherein when the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block includes: when the header information of the first memory block indicates that the first memory block is valid and the header information of the second memory block indicates that the second memory block is valid, obtaining the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0202] Optionally, the header information of the first memory block includes a first serial number, and the header information of the second memory block includes a second serial number. Before migrating the data block to be migrated out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the method 1500 further includes: determining, according to the first serial number and the second serial number, that the first memory block is a data block to be migrated out and / or the second memory block is a memory block to be migrated in.
[0203] The header information of the second memory block indicates that the second memory block is valid, which can also be understood as the existence of data blocks in the second memory block (the data blocks can be data blocks moved out from the first memory block, or data blocks newly written during garbage collection). Alternatively, the header information of the second memory block indicating that the second memory block is valid can also be understood as the data in the second memory block not being treated as dirty data.
[0204] Optionally, the method 1500 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the first memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erasable state among the multiple sectors of the first memory block; and performing an erasure operation on the sectors in the non-erasable state.
[0205] In this embodiment, by indicating the failure of the first memory block through the header information, it can be determined that an erase operation was being performed on the sectors of the first memory block when power-down occurred. By obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block, the erase operation on the unerased sectors of the first memory block can continue after power-on.
[0206] Optionally, the method 1500 further includes: when a power-down and power-on occurs during garbage collection, obtaining the header information of the second memory block; when the header information of the first memory block indicates that the first memory block is invalid, obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block, including: when the header information of the first memory block indicates that the first memory block is invalid and the header information of the second memory block indicates that the second memory block is valid, obtaining information on the sectors in the non-erased state among the multiple sectors of the first memory block.
[0207] Optionally, the header information of the first memory block indicates that the first memory block is invalid, which can also be understood as the header information of the first memory block being missing, or the header information of the first memory block being erased.
[0208] Optionally, before obtaining information about sectors in a non-erased state among multiple sectors of the first memory block, the method 1500 further includes: determining that the first memory block includes erase tags and migration tags, or determining that the first memory block does not include erase tags and does not include migration tags, or determining that the first memory block only includes migration tags; wherein, the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0209] In this embodiment, if the first memory block contains both an erase tag and a migration tag, or only a migration tag, or neither an erase tag nor a migration tag, it can be determined that the first memory block is an incompletely erased memory block. Thus, after power-on, information about sectors in the first memory block that are not in an erased state can be searched, allowing the erasure operation on these sectors to continue.
[0210] Optionally, the method 1500 further includes: in the event of a power-down and power-on during garbage collection, obtaining the header information of the first memory block; and in the event that the header information of the first memory block is missing and only an erase tag exists in the first memory block, determining that the garbage collection operation has been completed.
[0211] In this embodiment, if only the erase tag exists, after power-on, there is no need to search for sectors in the non-erased state in the first memory block again. Instead, the first memory block can be directly determined as a memory block that has been erased, which helps to improve the efficiency of garbage collection and also helps to reduce the time required for garbage collection.
[0212] Optionally, the erase tag and migration tag are located at the end of the first memory block.
[0213] Figure 16 illustrates a schematic diagram of the AUTOSAR-based software architecture provided in an embodiment of this application. This AUTOSAR software architecture enables seamless garbage collection and can be applied to the non-volatile memory management of vehicle controllers. Specifically, SWC initiates data storage and retrieval requests; RTE transmits these requests to NvM; during data storage, NvM adds headers and trailers to the data to be stored and encapsulates it into an NvM block; during data retrieval, it parses the stored data from the NvM block; the Fee module is a flash EEPROM emulation, used during data storage to add headers and trailers to the NvM block to be stored and encapsulate it into a Fee block; during data retrieval, it parses the stored NvM block from the Fee block; the Fls module is a Flash driver used to operate the hardware Flash device for storing and retrieving data; Flash is a hardware storage device used to store data.
[0214] The Fee module can include a dual-bank mechanism module and a block state management module. The dual-bank mechanism module can control both banks to be active simultaneously during abnormal power loss in GC, querying the renewal point and the erase point. The block state management module can identify blocks written in real time during GC to avoid unnecessary migrations.
[0215] Figure 17 shows a schematic flowchart of a data processing method 1700 provided in an embodiment of this application. This method 1700 can be implemented through interaction between NvM and Fee modules. As shown in Figure 17, the method 1700 includes:
[0216] S1701, NvM sends read / write requests to the Fee module by calling Fee Write.
[0217] S1702, during GC, the Fee module calls NvM CheckNewJob to check if there are any new read / write requests.
[0218] The seamless GC described in this application uses a small-step, fast-run approach to respond to user read and write requests in real time, triggering migration or erase interruptions to write new data into a new bank.
[0219] Figure 18 shows a schematic flowchart of a data processing method 1800 provided in an embodiment of this application. This method 1800 can be implemented interactively by a Fee module. The method 1800 includes:
[0220] S1801, when the Fee module detects that the remaining space in the current bank cannot be used to write the data to be stored, it triggers GC.
[0221] S1802, the Fee module writes the header information of the new bank.
[0222] In this embodiment, the Fee module can write the header information of the new bank before performing block migration during garbage collection (GC). This ensures that both the new and old banks are in a valid state. Even if a power outage occurs during GC, both the new and old banks will be in a valid state after power is restored, preventing the data in the new bank from being invalidated and treated as dirty data.
[0223] S1803, the Fee module migrates the preset quantity from the old bank to the new bank.
[0224] For example, the preset quantity is 1.
[0225] For example, as shown in Figure 4, the old bank can be bank0, and the new bank can be bank1. After garbage collection begins, the Fee module can migrate block1 from bank0 to bank1.
[0226] S1804. After completing the migration of a preset number of blocks, the Fee module uses NvM CheckNewJob to check for new read / write requests.
[0227] Optionally, a preset number of block migrations can be completed, including completing the migration of one block. For example, if the old bank is bank0 and the new bank is bank1, after migrating a block from bank0 to bank1, the Fee module can use NvM CheckNewJob to query for new read / write requests.
[0228] For example, if there are no new read / write requests, S1805 can be executed. If there are new read / write requests, S1806-S1808 can be executed.
[0229] S1805, if there are no new read / write requests, the migration of the preset number of blocks in the old bank can continue.
[0230] S1806 If there is a new read / write request, record the currently migrated block and the write address of the new bank, and switch the state of the Fee module to the idle state.
[0231] For example, by recording the currently migrated block, migration of unmigrated blocks can continue during GC recovery. By recording the write address of the new bank, new data can be written to a different address in the new bank when the next read / write request is executed. By switching the state of the Fee module to the idle state, NvM can clearly indicate that the Fee module is currently available to perform new data writes.
[0232] S1807, the Fee module receives a new read / write request.
[0233] For example, NvM sends a read / write request to the Fee module by calling Fee Write.
[0234] For example, step S1807 can be triggered by the SWC issuing a storage data request. After receiving the storage data request sent by the SWC, the NvM issues a read / write request to the Fee module.
[0235] S1808, the Fee module processes new read / write requests and writes the latest address in the new bank.
[0236] If the Fee module detects a new read / write request via NvM's CheckNewJob, it can pause GC and switch its state to idle. This allows NvM to determine that the Fee module is currently capable of handling new read / write requests, and thus send new read / write requests to the Fee module. Upon receiving a new read / write request, the Fee module processes it, writing the new data to a new bank. After completing the user's read / write request, it checks again for new read / write requests; if so, it processes them; otherwise, it continues the migration of a preset number of blocks.
[0237] Optionally, when the remaining space in the new bank is less than or equal to the sum of the spaces occupied by the unmigrated blocks in the old bank, the Fee module may stop responding to user read and write requests and force the GC to complete.
[0238] S1809, after all blocks have been migrated, the Fee module initiates the process of erasing the old bank, which erases a preset number of sectors in the old bank.
[0239] Similarly, the Fee module can adopt a small-step, fast-running approach during the process of initiating the erasure of the old bank, responding to new read and write requests in real time.
[0240] S1810, after completing the erasure of a preset number of sectors, the Fee module uses NvM CheckNewJob to check for new read / write requests.
[0241] Optionally, a preset number of sector migrations can be completed, including completing the migration of one sector. For example, if the old bank is bank0 and the new bank is bank1, after erasing one sector in bank0, the Fee module can use NvM CheckNewJob to query for new read / write requests.
[0242] For example, if there are no new read / write requests, S1811 can be executed. If there are new read / write requests, S1812-S1814 can be executed.
[0243] S1811, If there are no new read / write requests, the erasure of the preset number of sectors in the old bank can continue.
[0244] S1812, if there is a new read / write request, record the current erase position.
[0245] For example, by recording the current erasure position, erasure of unerased sectors can continue when GC restarts.
[0246] S1813, the Fee module receives new read / write requests.
[0247] S1814, the Fee module processes new read / write requests and writes the latest address in the new bank.
[0248] In this embodiment of the application, a new GC management mechanism is designed. During GC, a small step and fast run approach is adopted to continuously detect whether there are new read and write requests. When there is a write request, GC is paused, and the new data is directly written to the new bank before GC continues, without reserving space for new data.
[0249] The introduction of the dual-bank mechanism also comes at a cost, primarily increased initialization time. Since both banks are active, initialization requires traversing both banks, whereas previously only one bank needed to be traversed. To mitigate this cost, a waterline can be set. The system will only respond to user requests in real-time when the new bank is within a certain range; otherwise, garbage collection (GC) will be forced if the waterline is exceeded.
[0250] For example, Figure 19 shows a schematic diagram of setting a waterline in a new bank according to an embodiment of this application. As shown in Figure 19, after the migration of block 1 is completed, three writes to block 2 occur in real time. When the waterline is exceeded, the seamless GC stops, and block 3 is forcibly migrated to complete the migration of all data.
[0251] In multi-bank scenarios, dual-bank functionality can also be enabled. A single flash memory can be divided into multiple banks (more than two banks), but only two banks are active at any given time.
[0252] For example, Figure 20 illustrates a schematic diagram of the dual-bank activation mechanism in a multi-bank scenario provided by an embodiment of this application. As shown in Figure 20, the Flash area is divided into three banks. In the current scenario, bank1 is migrating to bank2, while bank0 is in an erased state. The multi-bank scenario is applicable to any of the above embodiments.
[0253] Figure 21 shows a schematic block diagram of a data processing apparatus 2100 provided in an embodiment of this application. The apparatus 2100 includes: an acquisition unit 2110, configured to acquire a first read / write request during a garbage collection operation performed through a first memory block and a second memory block, the first read / write request requesting the writing of first data, the first memory block being a memory block to be migrated out, the second memory block being a memory block to be migrated in, the first memory block including at least one sector, and the second memory block including at least one sector; and a data processing unit 2120, configured to, in response to the first read / write request, stop performing the garbage collection operation and write the first data into a first data block within the second memory block.
[0254] Optionally, the acquisition unit 2110 is configured to: read the first read / write request when garbage collection is performed on the first memory block and the second memory block and a preset number of data blocks in the first memory block are migrated to the second memory block.
[0255] Optionally, the acquisition unit 2110 is configured to: read a first read / write request when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased.
[0256] Optionally, the acquisition unit 2110 is further configured to: stop acquiring read / write requests when the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be moved out in the first memory block.
[0257] Optionally, the acquisition unit 2110 is further configured to: stop acquiring read / write requests when the remaining space in the second memory block is less than or equal to the preset storage space.
[0258] Optionally, the data processing unit 2120 is configured to, in response to resuming garbage collection, perform migration of other data blocks in the first memory block except for the second data block when the second data block in the first memory block is a data block to be migrated to the second memory block and the identifiers of the first data block and the second data block are the same; or, in response to resuming garbage collection, perform migration of other data blocks in the first memory block except for the third data block when the third data block in the first memory block is a data block that has been migrated to the second memory block and the identifiers of the first data block and the third data block are the same.
[0259] Optionally, the data processing unit 2120 is further configured to: write header information of the second memory block before writing the first data into the first data block of the second memory block or before moving the data block of the first memory block into the second memory block, wherein the header information indicates that the second memory block is valid.
[0260] Optionally, the acquisition unit 2110 is further configured to acquire the header information of the second memory block when a power-down and power-on occurs during garbage collection; the acquisition unit 2110 is further configured to acquire the information of the data blocks in the first memory block and the information of the data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; the data processing unit 2120 is further configured to migrate the data blocks to be moved out of the first memory block to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0261] Optionally, the acquisition unit 2110 is further configured to acquire the header information of the first memory block when a power-down and power-on occurs during garbage collection; the acquisition unit 2110 is further configured to acquire information of the sectors in the non-erasable state among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid; the data processing unit 2120 is further configured to perform an erasure operation on the sectors in the non-erasable state.
[0262] Optionally, the device 2100 further includes: a determining unit, configured to determine, before the acquiring unit acquires information about sectors in a non-erased state, that the first memory block includes an erase tag and a migration tag, or that the first memory block does not include an erase tag and does not include a migration tag, or that the first memory block only includes a migration tag; wherein the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0263] Figure 22 shows a schematic block diagram of a data processing apparatus 2200 provided in an embodiment of this application. The apparatus 2200 includes: an acquisition unit 2210, configured to acquire information about one or more data blocks to be migrated out of the first memory block during a garbage collection operation performed through a first memory block and a second memory block, wherein the first memory block is the memory block to be migrated out, and the second memory block is the memory block to be migrated in, the first memory block including at least one sector, and the second memory block including at least one sector; and a data processing unit 2220, configured to migrate one or more data blocks from the first memory block to the second memory block after writing header information of the second memory block, wherein the header information indicates that the second memory block is valid.
[0264] Optionally, the acquisition unit 2210 is further configured to acquire the header information of the second memory block when a power-down and power-on occurs during garbage collection; the acquisition unit is further configured to acquire the information of the data blocks in the first memory block and the information of the data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; the data processing unit 2220 is further configured to migrate the data blocks to be moved out from one or more data blocks to the second memory block according to the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
[0265] Optionally, the acquisition unit 2210 is further configured to acquire the header information of the first memory block when a power-down and power-on occurs during garbage collection; the acquisition unit 2210 is further configured to acquire information of the sectors in the non-erasable state among the multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block is invalid; the data processing unit 2220 is further configured to perform an erasure operation on the sectors in the non-erasable state.
[0266] Optionally, the device 2200 further includes: a determining unit, configured to determine, before the acquiring unit acquires information about sectors in a non-erased state, that the first memory block includes an erase tag and a migration tag, or that the first memory block does not include an erase tag and does not include a migration tag, or that the first memory block only includes a migration tag; wherein the erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
[0267] It should be understood that the division of units in the above device is only a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, the units in the device can be implemented by a processor calling software; for example, the device includes a processor connected to memory, which stores instructions. The processor calls the instructions stored in memory to implement any of the above methods or to implement the functions of each unit in the device. The processor can be, for example, a general-purpose processor, such as a CPU or microprocessor, and the memory can be internal or external to the device. Alternatively, the units in the device can be implemented as hardware circuits. The functions of some or all units can be implemented through the design of the hardware circuits, which can be understood as one or more processors. For example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all units are implemented through the design of the logical relationships between the components within the circuit. In another implementation, the hardware circuit can be implemented using a PLD, such as an FPGA, which can include a large number of logic gates. The connection relationships between the logic gates are configured through configuration files, thereby implementing the functions of some or all units. All units of the above device can be implemented entirely through processor calling software, or entirely through hardware circuits, or partially through processor calling software and the remaining parts through hardware circuits.
[0268] In this application embodiment, a processor is a circuit with signal processing capabilities. In one implementation, the processor can be a circuit with instruction reading and execution capabilities, such as a CPU, microprocessor, GPU, or DSP. In another implementation, the processor can implement certain functions through the logical relationships of hardware circuits. These logical relationships are fixed or reconfigurable. For example, the processor may be a hardware circuit implemented as an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document and configuring the hardware circuit can be understood as the processor loading instructions to implement the functions of some or all of the above units. Furthermore, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, or DPU.
[0269] As can be seen, each unit in the above device can be one or more processors (or processing circuits) configured to implement the above methods, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.
[0270] Furthermore, the units in the above devices can be integrated in whole or in part, or they can be implemented independently. In one implementation, these units are integrated together as a System-on-a-Chip (SoC). The SoC may include at least one processor for implementing any of the above methods or implementing the functions of the units in the device. The at least one processor may be of different types, such as CPU and FPGA, CPU and AI processor, CPU and GPU, etc.
[0271] This application also provides a data processing apparatus, which includes a processing unit and a storage unit. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to cause the apparatus to perform the methods or steps described in the above embodiments.
[0272] Alternatively, if the data processing device is located in a vehicle, the processing unit may be the processor 121-12n shown in FIG1.
[0273] This application also provides a vehicle that may include the data processing device 2100 or the data processing device 2200 described above.
[0274] This application also provides a computer program product, which includes computer program code that, when run on a computer, causes the computer to perform the methods described in the above embodiments.
[0275] This application also provides a computer-readable medium storing program code that, when run on a computer, causes the computer to perform the methods described in the above embodiments.
[0276] This application also provides a chip, which includes a circuit for performing the methods described in the above embodiments.
[0277] In implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software. The method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or by a combination of hardware and software modules within the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, power-on erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, detailed descriptions are omitted here.
[0278] It should be understood that in the embodiments of this application, the memory may include read-only memory and random access memory, and provides instructions and data to the processor.
[0279] It should also be understood that, in the various embodiments of this application, the order of the above-mentioned processes does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0280] Those skilled in the art will recognize that the units and algorithm steps of the various examples 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 implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art 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.
[0281] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0282] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and 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. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0283] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0284] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0285] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0286] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data processing method, characterized in that, include: During the garbage collection operation performed through the first memory block and the second memory block, a first read / write request is obtained. The first read / write request is used to request the writing of first data. The first memory block is a memory block to be migrated out, and the second memory block is a memory block to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector. In response to the first read / write request, the garbage collection operation is stopped and the first data is written into the first data block in the second memory block.
2. The method according to claim 1, characterized in that, When performing garbage collection operations on the first memory block and the second memory block, obtaining the first read / write request includes: When garbage collection is performed on the first memory block and the second memory block, and a preset number of data blocks in the first memory block are migrated to the second memory block, the first read / write request is read.
3. The method according to claim 1 or 2, characterized in that, When performing garbage collection operations on the first memory block and the second memory block, obtaining the first read / write request includes: The first read / write request is read when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: If the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be migrated out in the first memory block, the read / write request will be stopped.
5. The method according to any one of claims 1 to 3, characterized in that, The method further includes: If the remaining space in the second memory block is less than or equal to the preset storage space, stop acquiring read and write requests.
6. The method according to any one of claims 1 to 5, characterized in that, The method further includes: If the second data block in the first memory block is the data block to be migrated to the second memory block, and the first data block and the second data block have the same identifier, in response to resuming garbage collection, the migration of other data blocks in the first memory block except for the second data block is performed; or, If the third data block in the first memory block is a data block that has been migrated to the second memory block and the first data block and the third data block have the same identifier, in response to resuming garbage collection, the migration of other data blocks in the first memory block except for the third data block is performed.
7. The method according to any one of claims 1 to 6, characterized in that, Before writing the first data into the first data block of the second memory block or moving the data block of the first memory block into the second memory block, the method further includes: Write header information to the second memory block, the header information indicating that the second memory block is valid.
8. The method according to claim 7, characterized in that, The method further includes: If a power outage and subsequent power-on occur during garbage collection, the header information of the second memory block is obtained. If the header information of the second memory block indicates that the second memory block is valid, obtain the information of the data block in the first memory block and the information of the data block in the second memory block; Based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the data blocks to be migrated out of the first memory block are migrated to the second memory block.
9. The method according to claim 7 or 8, characterized in that, The method further includes: If a power outage and subsequent power-on occur during garbage collection, the header information of the first memory block is obtained. If the header information of the first memory block indicates that the first memory block is invalid, obtain information about the sectors in the non-erased state among the multiple sectors of the first memory block; Perform an erase operation on the sector that is in the non-erasing state.
10. The method according to claim 9, characterized in that, Before obtaining information about the sectors in the non-erased state among the multiple sectors of the first memory block, the method further includes: The first memory block is determined to include an erase tag and a migration tag, or the first memory block is determined to not include the erase tag and not include the migration tag, or the first memory block is determined to include only the migration tag; The erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
11. A data processing method, characterized in that, include: During the garbage collection operation performed through the first memory block and the second memory block, information about one or more data blocks to be migrated out in the first memory block is obtained. The first memory block is the memory block to be migrated out, and the second memory block is the memory block to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector. After writing the header information of the second memory block, one or more data blocks are moved from the first memory block to the second memory block, and the header information indicates that the second memory block is valid.
12. The method according to claim 11, characterized in that, The method further includes: If a power outage and subsequent power-on occur during garbage collection, the header information of the second memory block is obtained. If the header information of the second memory block indicates that the second memory block is valid, obtain the information of the data block in the first memory block and the information of the data block in the second memory block; Based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block, the data blocks to be migrated out from one or more data blocks are migrated to the second memory block.
13. The method according to claim 11 or 12, characterized in that, The method further includes: If a power outage and subsequent power-on occur during garbage collection, the header information of the first memory block is obtained. If the header information of the first memory block indicates that the first memory block is invalid, obtain information about the sectors in the non-erased state among the multiple sectors of the first memory block; Perform an erase operation on the sector that is in the non-erasing state.
14. The method according to claim 13, characterized in that, Before obtaining information about the sectors in the non-erased state among the multiple sectors of the first memory block, the method further includes: The first memory block is determined to include an erase tag and a migration tag, or the first memory block is determined to not include the erase tag and not include the migration tag, or the first memory block is determined to include only the migration tag; The erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
15. A data processing apparatus, characterized in that, include: The acquisition unit is used to acquire a first read / write request during the garbage collection operation performed through the first memory block and the second memory block. The first read / write request is used to request the writing of first data. The first memory block is a memory block to be migrated out, and the second memory block is a memory block to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector. The data processing unit is configured to, in response to the first read / write request, stop performing garbage collection operations and write the first data into the first data block in the second memory block.
16. The apparatus according to claim 15, characterized in that, The acquisition unit is used for: When garbage collection is performed on the first memory block and the second memory block, and a preset number of data blocks in the first memory block are migrated to the second memory block, the first read / write request is read.
17. The apparatus according to claim 15 or 16, characterized in that, The acquisition unit is used for: The first read / write request is read when garbage collection is performed on the first memory block and the second memory block and data in a preset number of sectors in the first memory block is erased.
18. The apparatus according to any one of claims 15 to 17, characterized in that, The acquisition unit is further configured to: If the remaining space in the second memory block is less than or equal to the sum of the spaces occupied by the data blocks to be migrated out in the first memory block, the read / write request will be stopped.
19. The apparatus according to any one of claims 15 to 17, characterized in that, The acquisition unit is further configured to: If the remaining space in the second memory block is less than or equal to the preset storage space, stop acquiring read and write requests.
20. The apparatus according to any one of claims 15 to 19, characterized in that, The data processing unit is used for If the second data block in the first memory block is a data block to be migrated to the second memory block and the first data block and the second data block have the same identifier, in response to resuming garbage collection, the migration of other data blocks in the first memory block except for the second data block is performed; or, If the third data block in the first memory block is a data block that has been migrated to the second memory block and the first data block and the third data block have the same identifier, in response to resuming garbage collection, the migration of other data blocks in the first memory block except for the third data block is performed.
21. The apparatus according to any one of claims 15 to 20, characterized in that, The data processing unit is further configured to: Before writing the first data into the first data block in the second memory block, header information of the second memory block is written, the header information indicating that the second memory block is valid.
22. The apparatus according to claim 21, characterized in that, The acquisition unit is also used to acquire the header information of the second memory block when a power outage and power-on occurs during garbage collection. The acquisition unit is further configured to acquire information about data blocks in the first memory block and information about data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; The data processing unit is further configured to migrate the data block to be migrated out of the first memory block to the second memory block based on the information of the data block in the first memory block and the information of the data block in the second memory block.
23. The apparatus according to claim 21 or 22, characterized in that, The acquisition unit is also used to acquire the header information of the first memory block when a power outage and power-on occurs during garbage collection. The acquisition unit is further configured to acquire information about sectors in a non-erased state among multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block has failed. The data processing unit is also used to perform an erasure operation on the sectors that are in the non-erasure state.
24. The apparatus according to claim 23, characterized in that, The device further includes: The determining unit is configured to, before the obtaining unit obtains information about the sector in the non-erased state, determine that the first memory block includes an erase tag and a migration tag, or determine that the first memory block does not include the erase tag and does not include the migration tag, or determine that the first memory block only includes the migration tag; The erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
25. A data processing apparatus, characterized in that, include: The acquisition unit is used to acquire information about one or more data blocks to be migrated out in the first memory block during the garbage collection operation performed through the first memory block and the second memory block. The first memory block is the memory block to be migrated out, and the second memory block is the memory block to be migrated in. The first memory block includes at least one sector, and the second memory block includes at least one sector. A data processing unit is configured to, after writing the header information of the second memory block, move one or more data blocks from the first memory block into the second memory block, wherein the header information indicates that the second memory block is valid.
26. The apparatus according to claim 25, characterized in that, The acquisition unit is also used to acquire the header information of the second memory block when a power outage and power-on occurs during garbage collection. The acquisition unit is further configured to acquire information about data blocks in the first memory block and information about data blocks in the second memory block when the header information of the second memory block indicates that the second memory block is valid; The data processing unit is further configured to migrate the data blocks to be migrated out from one or more data blocks to the second memory block based on the information of the data blocks in the first memory block and the information of the data blocks in the second memory block.
27. The apparatus according to claim 25 or 26, characterized in that, The acquisition unit is also used to acquire the header information of the first memory block when a power outage and power-on occurs during garbage collection. The acquisition unit is further configured to acquire information about sectors in a non-erased state among multiple sectors of the first memory block when the header information of the first memory block indicates that the first memory block has failed. The data processing unit is also used to perform an erasure operation on the sectors that are in the non-erasure state.
28. The apparatus according to claim 27, characterized in that, The device further includes: The determining unit is configured to, before the obtaining unit obtains information about the sector in the non-erased state, determine that the first memory block includes an erase tag and a migration tag, or determine that the first memory block does not include the erase tag and does not include the migration tag, or determine that the first memory block only includes the migration tag; The erase tag is a tag added to the first memory block after the data in the first memory block has been erased, and the migration tag is a tag added to the first memory block when the third memory block migrates data to the first memory block.
29. A data processing apparatus, characterized in that, include: Memory, used to store computer programs; A processor for executing a computer program stored in the memory to cause the apparatus to perform the method as described in any one of claims 1 to 14.
30. A vehicle, characterized in that, Includes the apparatus as described in any one of claims 15 to 29.
31. A computer-readable storage medium, characterized in that, It stores instructions that, when executed by a processor, cause the processor to implement the method as described in any one of claims 1 to 14.
32. A computer program product, characterized in that, The computer program product includes computer program code that, when run on a computer, causes the computer to perform the method as described in any one of claims 1 to 14.
33. A chip, characterized in that, The chip includes circuitry for performing the method as described in any one of claims 1 to 14.