WO2024007678A1 - 一种存储空间整理方法及电子设备 - Google Patents

一种存储空间整理方法及电子设备 Download PDF

Info

Publication number
WO2024007678A1
WO2024007678A1 PCT/CN2023/089219 CN2023089219W WO2024007678A1 WO 2024007678 A1 WO2024007678 A1 WO 2024007678A1 CN 2023089219 W CN2023089219 W CN 2023089219W WO 2024007678 A1 WO2024007678 A1 WO 2024007678A1
Authority
WO
WIPO (PCT)
Prior art keywords
electronic device
file system
device layer
block device
block
Prior art date
Application number
PCT/CN2023/089219
Other languages
English (en)
French (fr)
Inventor
金大臣
党健
Original Assignee
荣耀终端有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 荣耀终端有限公司 filed Critical 荣耀终端有限公司
Priority to EP23761410.2A priority Critical patent/EP4328705A1/en
Publication of WO2024007678A1 publication Critical patent/WO2024007678A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/061Improving I/O performance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1727Details of free space management performed by the file system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/064Management of blocks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0643Management of files
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1016Performance improvement
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/72Details relating to flash memory management
    • G06F2212/7205Cleaning, compaction, garbage collection, erase control

Definitions

  • the present application relates to the field of terminal technology, and in particular, to a storage space organizing method and electronic equipment.
  • garbage collection processing In order to improve the continuity of the storage space of electronic devices and delay the lag of electronic devices, garbage collection processing needs to be performed on the storage space. Garbage collection processing often needs to be performed through the file system that manages the storage device. In the process of using an electronic device, the user is likely to use the file system of the electronic device. However, the processing resources and interfaces of the file system are limited. The file system's garbage collection process may conflict with the user's use, causing garbage collection and users to compete for resources, causing users to freeze.
  • Embodiments of the present application disclose a storage space organization method and electronic equipment, which can avoid missing the GC window, ensure the success rate of garbage collection processing, improve the continuity of storage space, and delay the jamming of electronic equipment.
  • the present application provides a method for organizing storage space.
  • the method is applied to an electronic device.
  • the kernel of the electronic device includes a file system and a block device layer.
  • the method includes: the electronic device passes the block device layer.
  • the device layer monitors the input and output port IO. When IO is released, the block device layer determines whether all IOs have been released; when all IOs have been released, the electronic device passes through the block device layer.
  • the status of the file system is updated to an idle state, triggering the electronic device to perform a first garbage collection process through the file system.
  • the status of the file system includes an idle state and a busy state.
  • the first garbage collection process is a garbage collection process performed by the file system based on logical addresses.
  • the block device layer monitors the IO occupancy. When all IOs are released, it actively changes the status of the file system to the idle state, and actively triggers the first GC detection and turns on the first GC.
  • the process can better grasp the idle opportunities of electronic devices, thereby reducing the number of missed GC windows due to conflicts in the block device layer IO ports occupied by the first GC detection and user operations, and improving the success rate of the GC process of electronic devices.
  • the GC detection determines that the probability of performing GC processing increases, and the number of times storage devices such as disks of electronic equipment are sorted increases, which can delay the jamming of electronic equipment and increase the service life of electronic equipment.
  • the electronic device updates the status of the file system to an idle state through the block device layer, triggering the electronic device to perform a first garbage collection process through the file system, specifically including: : The electronic device updates the status of the file system to an idle state through the block device layer. After the first period of time, the file system triggers garbage collection detection and determines whether the garbage collection conditions are met.
  • the garbage collection The condition is that the status of the file system is idle and all IOs of the block device layer have been released; when the garbage collection condition is met, the electronic device performs the first garbage collection process through the file system.
  • the method further includes: after a second period of time since the file system triggers garbage collection detection, the electronic device passes the file The system triggers garbage collection detection again and determines whether the garbage collection conditions are met; if the garbage collection conditions are met, the electronic device once again performs the first garbage collection process through the file system.
  • the electronic device can start the periodic detection timing immediately after the garbage collection detection, and the garbage collection detection is not actively triggered during the second period of time (active triggering is the triggering process after the above-mentioned file system status is updated to the idle state).
  • garbage collection detection can be performed periodically to ensure the frequency of garbage collection, which can further improve the continuity of storage space and delay the jamming of electronic equipment.
  • the second duration is the duration for periodic garbage collection detection. For details, refer to the relevant description in Figure 7 .
  • the electronic device further includes a storage device, and after the electronic device updates the status of the file system to an idle state through the block device layer, the method further includes: the electronic device The device triggers the storage device to perform a second garbage collection process through the block device layer. In this way, when the second garbage collection is performed, the second garbage collection process can also be triggered to ensure that the physical storage addresses will also be sorted to improve the continuity of the storage space.
  • the second garbage collection process is a garbage collection process performed by the storage device based on the physical address.
  • the electronic device monitors IO through the block device layer, which specifically includes: the electronic device monitors whether a task instruction is received through the block device layer, and the task instruction is the file When the system obtains the first task, it sends a notification indicating execution of the first task to the block device layer; when the block device layer receives the task instruction, the electronic device passes the The block device layer determines that there is IO occupation; the electronic device monitors whether a task end notification is received through the block device layer, and the task end notification is when the storage device of the electronic device completes the execution of the first task. , a notification sent to the block device layer; when the block device layer receives the task end notification, the electronic device determines that there is an IO release through the block device layer.
  • the block device layer can monitor the IO situation through the execution of the task. That is, the block device layer can count the IO through the IO counting module.
  • the occupied IO is increased by one, and when a task is completed, the occupied IO is decreased. one. This ensures that when the occupied IO decreases, the trigger detects whether the occupied IO is 0, so as to trigger the garbage collection process. Therefore, triggering accuracy can avoid GC window conflicts, thereby ensuring the success rate of garbage collection processing, improving the orderliness of storage space, and delaying the jamming of electronic equipment.
  • the first task may be that the file system receives a task from the user space to process the file.
  • the file system issues a task instruction (which may include one or more task instructions) to the block device layer.
  • the storage device may send a task end notification to the block device layer.
  • the electronic device further includes a memory and a processor.
  • the method further includes: the electronic device passes the block The device layer controls the memory to increase the first operating frequency; the electronic device controls the processor to increase the second operating frequency through the block device layer.
  • the first working frequency is the working frequency of the memory; the second working frequency is the working frequency of the processor.
  • the process of increasing the working frequency can refer to S604-S607 in Figure 6.
  • the electronic device further includes a memory and a processor.
  • the method It also includes: the electronic device controls the memory to reduce the first operating frequency through the block device layer; the electronic device controls the processor to reduce the second operating frequency through the block device layer. In this way, when the electronic device can complete the task processing and does not need to use processing resources, it can reduce the working frequency of the memory and processor and reduce the waste of processing resources and energy.
  • the first working frequency is the working frequency of the memory; the second working frequency is the working frequency of the processor.
  • the process of reducing the working frequency can refer to S619-S622 in Figure 6.
  • the preset state is that the electronic device is in a screen-off state and the status of the file system is updated to an idle state. In this way, when the user turns off the screen and the file system status is determined to be updated (all IOs have been released), the working frequency is reduced. Under this condition, the user is less likely to use electronic devices, and the task has been completed. Time-frequency reduction can take into account the energy consumption of user use and electronic equipment.
  • the screen-off state in this application means that the screen of the electronic device is off.
  • this application provides an electronic device, including: one or more processors and one or more memories.
  • the core of the electronic device includes a file system and a block device layer.
  • the one or more memories are used for For storing computer program code, the computer program code includes computer instructions that, when executed by the one or more processors, cause the electronic device to perform:
  • the block device layer monitors the input and output port IO, and in the case of IO release, the block device layer determines whether all IOs have been released;
  • the status of the file system is updated to an idle state through the block device layer, triggering the electronic device to perform first garbage collection processing through the file system.
  • Status includes idle status and busy status.
  • the first garbage collection process is a garbage collection process performed by the file system based on logical addresses.
  • the block device layer monitors the IO occupancy. When all IOs are released, it actively changes the status of the file system to the idle state, and actively triggers the first GC detection and turns on the first GC.
  • the process can better grasp the idle opportunities of electronic devices, thereby reducing the number of missed GC windows due to conflicts in the block device layer IO ports occupied by the first GC detection and user operations, and improving the success rate of the GC process of electronic devices.
  • the GC detection determines that the probability of performing GC processing increases, and the number of times storage devices such as disks of electronic equipment are sorted increases, which can delay the jamming of electronic equipment and increase the service life of electronic equipment.
  • the electronic device updates the status of the file system to an idle state through the block device layer, triggering the electronic device to perform first garbage collection processing through the file system.
  • the status of the file system is updated to the idle state through the block device layer.
  • the file system triggers garbage collection detection and determines whether the garbage collection condition is met.
  • the garbage collection condition is the The status of the file system is an idle state and all IOs of the block device layer have been released; when the garbage collection conditions are met, the first garbage collection process is performed through the file system.
  • the electronic device triggers the update command of the file status after the first period of time to ensure that there is no task command to process the file within a period of time and to ensure the IO resources of the block device layer.
  • GC processing is performed when the source is idle, thereby avoiding IO conflicts with user operations, ensuring user experience and increasing the possibility of successful GC processing.
  • the electronic device after the file system triggers the garbage collection detection, the electronic device also performs: after a second period of time since the file system triggers the garbage collection detection, the file system triggers the garbage collection detection again. Trigger garbage collection detection, and determine whether the garbage collection condition is met; if the garbage collection condition is met, the first garbage collection process is performed again through the file system. In this way, the electronic device can start the periodic detection timing immediately after the garbage collection detection, and the garbage collection detection is not actively triggered during the second period of time (active triggering is the triggering process after the above-mentioned file system status is updated to the idle state). At this time, garbage collection detection can be performed periodically to ensure the frequency of garbage collection, which can further improve the continuity of storage space and delay the jamming of electronic equipment.
  • the second duration is the duration for periodic garbage collection detection. For details, refer to the relevant description in Figure 7 .
  • the electronic device further includes a storage device, and after the electronic device updates the status of the file system to an idle state through the block device layer, the electronic device also executes:
  • the block device layer triggers the storage device to perform a second garbage collection process. In this way, when the second garbage collection is performed, the second garbage collection process can also be triggered to ensure that the physical storage addresses will also be sorted to improve the continuity of the storage space.
  • the second garbage collection process is a garbage collection process performed by the storage device based on the physical address.
  • the electronic device monitors IO through the block device layer. Specifically, the electronic device monitors whether a task instruction is received through the block device layer.
  • the task instruction is the first step obtained by the file system.
  • a notification indicating execution of the first task is sent to the block device layer; when the block device layer receives the task instruction, it is determined through the block device layer that there is IO occupation; Monitor whether a task end notification is received through the block device layer.
  • the task end notification is a notification sent to the block device layer by the storage device of the electronic device after completing the execution of the first task; in When the block device layer receives the task end notification, the block device layer determines that IO is released.
  • the block device layer can monitor the IO situation through the execution of the task. That is, the block device layer can count the IO through the IO counting module.
  • the occupied IO is increased by one, and when a task is completed, the occupied IO is decreased. one. This ensures that when the occupied IO decreases, the trigger detects whether the occupied IO is 0, so as to trigger the garbage collection process. Therefore, triggering accuracy can avoid GC window conflicts, thereby ensuring the success rate of garbage collection processing, improving the continuity of storage space, and delaying the lag of electronic equipment.
  • the first task may be that the file system receives a task from the user space to process the file.
  • the file system issues a task instruction (which may include one or more task instructions) to the block device layer.
  • the storage device may send a task end notification to the block device layer.
  • the electronic device further includes a memory and a processor.
  • the electronic device executes: controlling through the block device layer The memory increases the first operating frequency; and the processor is controlled through the block device layer to increase the second operating frequency.
  • the first working frequency is the working frequency of the memory; the second working frequency is the working frequency of the processor.
  • the process of increasing the working frequency can refer to S604-S607 in Figure 6.
  • the electronic device further includes a memory and a processor, and the block device layer receives When the task end notification is received and the electronic device is in a preset state, the electronic device also performs: controlling the memory through the block device layer to reduce the first operating frequency; controlling through the block device layer The processor reduces the second operating frequency. In this way, when the electronic device can complete the task processing and does not need to use processing resources, it can reduce the working frequency of the memory and processor and reduce the waste of processing resources and energy.
  • the first working frequency is the working frequency of the memory; the second working frequency is the working frequency of the processor.
  • the process of reducing the working frequency can refer to S619-S622 in Figure 6.
  • the preset state is that the electronic device is in a screen-off state and the status of the file system is updated to an idle state. In this way, when the user turns off the screen and the file system status is determined to be updated (all IOs have been released), the working frequency is reduced. Under this condition, the user is less likely to use electronic devices, and the task has been completed. Time-frequency reduction can take into account the energy consumption of user use and electronic equipment.
  • the screen-off state in this application means that the screen of the electronic device is off.
  • the present application provides an electronic device, including one or more processors and one or more memories.
  • the one or more processors are coupled to one or more memories, and the one or more memories are used to store computer program code.
  • the computer program code includes computer instructions that, when executed by the one or more processors, cause the electronic device to perform A method of organizing storage space in a possible implementation of any of the above aspects.
  • this application provides an electronic device, including: one or more functional modules.
  • One or more functional modules are used to execute the storage space arrangement method in any possible implementation of any of the above aspects.
  • embodiments of the present application provide a computer storage medium, including computer instructions.
  • the computer instructions When the computer instructions are run on an electronic device, the electronic device causes the electronic device to perform the storage space arrangement in any of the possible implementations of any of the above aspects. method.
  • embodiments of the present application provide a computer program product.
  • the computer program product When the computer program product is run on a computer, it causes the computer to execute the storage space arrangement method in any of the possible implementations of any of the above aspects.
  • Figure 1 is a schematic diagram of the hierarchical structure of the kernel of an operating system provided by an embodiment of the present application
  • FIG. 2 is a schematic diagram of the storage space structure of F2FS provided by an embodiment of the present application.
  • Figure 3 is a schematic structural diagram of a storage space provided by an embodiment of the present application.
  • Figure 4 is a schematic diagram of the hierarchical structure of the kernel of an operating system provided by an embodiment of the present application.
  • Figure 5 is a schematic diagram of a GC detection process provided by an embodiment of the present application.
  • Figure 6 is a schematic diagram of the process of a file garbage collection method provided by an embodiment of the present application.
  • Figure 7 is a schematic diagram of the flow of another file garbage collection method provided by an embodiment of the present application.
  • Figure 8 is a schematic diagram of another GC detection process provided by the embodiment of the present application.
  • FIG. 9 is a schematic diagram of the hardware structure of an electronic device 100 provided by an embodiment of the present application.
  • words such as “first” and “second” are used to distinguish identical or similar items with basically the same functions and effects.
  • the first chip and the second chip are only used to distinguish different chips and do not differentiate between them.
  • the order is limited.
  • words such as “first” and “second” do not limit the number and execution order, and words such as “first” and “second” do not limit the number and execution order.
  • At least one refers to one or more, and “multiple” refers to two or more.
  • “And/or” describes the association of associated objects, indicating that there can be three relationships, for example, A and/or B, which can mean: A exists alone, A and B exist simultaneously, and B exists alone, where A, B can be singular or plural.
  • the character “/” generally indicates that the related objects are in an “or” relationship.
  • “At least one of the following” or similar expressions thereof refers to any combination of these items, including any combination of a single item (items) or a plurality of items (items).
  • At least one of a, b, or c can mean: a, b, c, a-b, a--c, b-c, or a-b-c, where a, b, c can be single, or It's multiple.
  • the kernel is a first-layer software extension based on hardware that provides the most basic functions of the operating system.
  • the kernel has functions such as managing system processes, memory, device drivers, and file systems.
  • Figure 1 is a schematic diagram of the hierarchical structure of the kernel of an operating system disclosed in an embodiment of the present application (schematic diagram of the IO stack structure).
  • the file system belongs to the kernel layer (kernel) of the operating system, that is, all modules of the file system run in the kernel state.
  • the kernel can include virtual file system (virtual file system switch, VFS), different file systems, block device layer (Block layer) and device driver (device driver), etc.
  • VFS virtual file system switch
  • Block layer block device layer
  • device driver device driver
  • the virtual file system VFS defines the interface layer and adaptation layer of a universal file system. On the one hand, it provides users with a unified set of unified methods for accessing files, directories and other objects. On the other hand, it has to work with different underlying layers. File system adaptation. Specifically, VFS can abstract things that are common to all file systems, such as files, index nodes, inodes, directory entries, and other structures, and provide a common application programming interface (application programming interface) abstracted from these structures. API), and then the specific file system needs to be delivered according to the corresponding interface. That is, VFS provides users with a unified interface and introduces an intermediate layer at the user layer and file system layer.
  • API application programming interface
  • the basic data unit of the file system is a file. Its purpose is to organize and manage the files on the disk. Different organization methods will form different file systems. According to different storage locations, file systems can be divided into three categories: disk file systems, virtual file systems and network file systems. Among them, the function of the disk file system is to store data on storage devices such as disks, and when receiving requests, it can perform operations such as opening, reading, and writing. For example, the second/third/fourth generation extended file system (extended file system, EXT) 2/3/4, F2FS, XFS, file allocation table (File Allocation Table, FAT) file system, etc.
  • extended file system extended file system
  • FAT File Allocation Table
  • the block device layer is a software logic layer that enables requests to block devices to be completed efficiently and reasonably through organizational management. As shown in Figure 1, the block device layer is located on the upper layer of driver devices and hardware and the lower layer of the file system, that is, The block device layer is an abstract layer on the real hardware, shielding different hardware drivers, and used for the implementation and optimization of IO scheduling strategies.
  • the driver device can be an abstraction of the hardware device, including UFS driver, eMMC driver, etc., without limitation.
  • IO goes from user mode to system scheduling and enters the kernel.
  • the path of the kernel is VFS, file system, block device layer and device driver layer.
  • VFS virtual file system
  • block device layer a type of memory
  • device driver layer a type of driver
  • Flash Friendly File System F2FS file system.
  • This file system is a file system compiled based on the Linux kernel. It is a new open source flash file system specially designed for NAND-based storage devices. It is especially designed to be friendly to NAND flash storage media. Among them, NAND flash memory is a better storage device than hard drive.
  • FIG. 2 is a schematic diagram of the storage space structure of F2FS disclosed in the embodiment of the present application.
  • the entire storage space is divided into fixed-size segments. Segments are the basic unit of F2FS space management and also determine the initial layout of the file system metadata. A certain number of consecutive segments form a section, and a certain number of consecutive sections form a zone. Among them, section (or segment) and zone are important units for F2FS log writing and cleaning. By configuring the appropriate section (or segment) size, the overhead of garbage collection at the flash translation layer (FTL) level can be greatly reduced.
  • the storage space can be written in two ways: random writing and sequential writing.
  • the entire storage space of F2FS is divided into 6 areas, namely super block (SB), check point (CP), segment information table (segment information table, SIT), and index node address table (node address table, NAT) , segment summary area (SSA) and main area (main area).
  • SB super block
  • CP check point
  • SIT segment information table
  • NAT index node address table
  • SSA segment summary area
  • main area main area
  • F2FS Since in the file system, the storage, reading, writing and deletion processes of the file system tend to divide the storage space into finer and finer parts, the degree of fragmentation of the file system will increase with the increase of usage time, and This fragmentation of storage space is irreversible. Therefore, as the usage time of the computing device increases, the fragmentation of the device storage space increases, and the computing device takes longer to perform operations such as reading and writing the storage space, and the user's use of the computing device becomes laggy. Therefore, in order to delay the increase in fragmentation as much as possible, F2FS has a GC solution to organize the storage space.
  • the F2FS file system will release the address space of the corresponding storage space, and these address spaces may be distributed on each segment of the storage space, resulting in The address space where the storage space is free (no data is stored) may be scattered in various locations in the storage space. Therefore, The file system uses F2FS garbage collection to move the data on the segment with less valid data to the currently used segment, thereby freeing up the space of a complete segment.
  • the process of performing GC operations on a file system can be divided into three steps.
  • the relocation target needs to be determined first.
  • the file system can determine the target to move based on the valid blocks of the file on the segment, as well as the update interval or age of the segment.
  • files on segments with the fewest valid blocks and which have not been updated or changed for a long time are selected for migration.
  • the file system can identify valid blocks and move them.
  • the file system releases the storage space after the move.
  • the segment with the fewest valid blocks refers to the segment with the smallest proportion of valid data in the entire segment space in each segment.
  • FIG. 3 is a schematic structural diagram of a storage space disclosed in the embodiment of the present application.
  • the storage space includes more than N segments, and each segment is 2MB in size. Among them, N is a positive integer.
  • the storage space there are 3MB files stored in the 1st and 2nd segments, a 4MB file stored in the 3rd and 4th segments, and a 4KB file stored in the Nth segment. .
  • the file system can determine that the migration target is a 4KB file stored on the Nth segment, that is, the file with the least valid blocks on this segment. This segment can be determined as the migration target. After that, the file system can store this 4KB file.
  • the file is moved to the segment storage space immediately after the 3MB file.
  • the original 4KB file is released, and the corresponding storage space of a segment can be released entirely.
  • the GC process of the file system it is based on the above-mentioned logical addresses, and the storage space itself also needs to be sorted. At this time, the sorting process is often based on physical addresses.
  • the storage device referred to in this application may be a NAND flash memory chip.
  • NAND flash memory chip is an electronically erasable programmable read-only memory. It is characterized by a simple structure and can achieve a considerable amount of data storage per unit area of a semiconductor. The side effect of this structure is that erasing and writing cannot be performed in units of bits, but can only be performed in large-scale operations in units of physical blocks.
  • the physical block is the storage area of the flash memory chip.
  • Each flash memory chip contains several physical blocks. Each physical block contains a constant number of physical pages. The physical block is also the basic unit of the erase operation.
  • mapping table between the logical page address (logical address) and the free physical page (physical address), which is a data structure that stores the one-to-one correspondence between the logical page address and the physical page address.
  • Logical page address is a general mechanism that describes the block where data is located on a computer storage device. It refers to the address of a certain data block or the data block pointed to by an address. The physical address can be obtained by converting the flash memory translation layer. Free physical page. When the physical page in the solid-state storage device has not been used, that is, when it has no data, the physical page is a free physical page and can be used for allocation of write requests and garbage collection operations.
  • the process of garbage collection in a storage device generally involves first transferring the valid data in the selected physical block to other physical blocks, and then performing an erasure operation on it to recycle the physical pages by erasing the physical blocks with more invalid data.
  • Block device layer (block layer)
  • the block device layer connects the file system layer and the device driver layer.
  • bio enters the block device layer.
  • the block device layer will receive the IO ports and transfer these IO ports.
  • the processing of these bios is abstracted into request management by the block layer.
  • these requests leave the block device layer and enter the device driver layer.
  • the soft interrupt of the block device layer is responsible for processing the work after the IO is completed. During this process, the block device layer will occupy IO and release IO.
  • the function used by the user When the user uses electronic equipment, if the function used by the user reads and writes to the disk, it will also occupy the IO port of the block device layer. For example, users view mobile photo albums, documents, etc.
  • the storage device completes storage according to the storage protocol.
  • the storage protocols involved in this application may include: embedded multi media card (eMMC) and universal flash storage (UFS).
  • eMMC embedded multi media card
  • UFS universal flash storage
  • eMMC is a flash memory card standard, which defines the physical architecture, access interface and protocol of a storage system based on an embedded multimedia card. eMMC can work synchronously, and the working mode is half-duplex. Each channel allows read and write transmission, but it can only read/write at the same time.
  • UFS universal flash storage
  • eMMC embedded MultiMediaCard
  • UFS protocol storage devices is much faster than that of eMMC protocol storage devices.
  • Double data rate is a memory name, which means double-rate synchronous dynamic random access memory, and is one type of memory. Among them, DDR has its own operating frequency. The higher the operating frequency, the higher the performance of DDR, but of course this is also accompanied by greater power consumption.
  • CPU Central processing unit
  • the CPU is the final execution unit for information processing and program execution.
  • the CPU is the core component responsible for reading instructions, decoding them, and executing them.
  • the CPU can control and allocate all hardware resources (such as memory, etc.) in the electronic device.
  • Each CPU has one or more operating frequencies.
  • FIG. 4 is a schematic diagram of the hierarchical structure of the kernel of an operating system disclosed in an embodiment of the present application.
  • the kernel hierarchical structure can include three parts: user space, kernel space and hardware.
  • the operating system can be divided into two parts.
  • One part is the core software, also called the kernel space, which runs at a higher privilege level and has all permissions to access hardware devices.
  • the other part is called user space.
  • Ordinary applications run in user space. Ordinary applications cannot directly access kernel space and hardware devices.
  • User space can include applications.
  • the application can be a gallery, reading, mobile game, camera, etc. application, which is not limited in this application.
  • the kernel space can include the system call layer (system call interface), file system and block device layer, etc.
  • the system call layer is the bridge between user space and kernel space.
  • Applications access the hardware resources in the system through the unified entrance of the system call layer. Through this interface, all resource access is executed under the control of the kernel to avoid causing Unauthorized access to system resources by user programs, thus ensuring the security and stability of the system.
  • system call The interface is an interface used to receive file processing tasks from the user layer.
  • a file system is a method and data structure used by the operating system to identify files on a disk or partition, that is, a method of organizing data on a disk.
  • the file system can reasonably plan the hard disk to ensure the normal use needs of users. Specific users create files for users, save, read, modify, transfer files, etc.
  • the file system can be diverse, such as F2FS, EXT4, FAT, etc., which is not limited by this application.
  • the block device layer may include an IO counting module, which is used to count the number of occupied IOs (or the number of idle IOs).
  • an IO counting module which is used to count the number of occupied IOs (or the number of idle IOs).
  • the relevant content of the IO counting module please refer to the description in Figure 6 and will not be repeated.
  • Hardware can include storage devices, memory (modules), processors, etc.
  • Storage devices can be used to store files or data, such as hard drives, disks, etc.
  • the protocol type of the storage device can be UFS or eMMC. For details, please refer to the above description.
  • Memory is used to temporarily store the calculation data of the processor and the data exchanged by storage devices such as hard disks. All programs in electronic devices run in memory, and the performance of the memory affects the overall performance of the computer.
  • the memory version can be DDR.
  • the processor may be a CPU of the electronic device.
  • the processor may be a CPU of the electronic device.
  • the file system can determine whether the disk status of the computing device is idle. If it is in the idle status, the file system can send a GC detection notification to the block layer, and the block layer determines the current After the IO port results are obtained, the IO port status results can be sent to the file system. The file system can determine whether to perform GC processing based on the IO port status results.
  • the number of IOs in the Block layer is limited. Common file operation behaviors in user mode and the delivery of file system IO logs will cause the occupation of Block layer IO. For example, the user operates a computing device to open a file, or the file system performs IO pre-reading, dirty pages are written, etc. That is, the Block layer will call (or occupy) the IO port when it receives the task. When the file system of the computing device performs GC processing, it will also call the IO port. If the user operation process and GC processing are performed at the same time, the IO resources of the Block layer will be preempted, and the computing device needs to be processed in order to perform user operations. The tasks that need to be processed for user operations may be delayed, thus affecting the user experience.
  • F2FS Before F2FS performs GC processing, it needs to determine whether the GC process can be started.
  • the status of F2FS includes two statuses: busy and idle. Busy indicates that the current F2FS file system is working (there are processes being processed); idle status indicates that the F2FS file system is not working (no processes need to be processed). Since the GC process needs to occupy the F2FS process and the IO port of the Block layer, F2FS will choose to perform GC processing when it is idle and there is free IO in the Block layer.
  • the computing device can periodically perform GC detection through the file system and ask whether it is in the idle state and whether the Block layer currently has an IO port to call.
  • the file system performs GC processing, that is, the GC process is started. Otherwise, GC processing will not be enabled.
  • the above-mentioned GC detection process is triggered periodically according to a specific length of time. That is to say, the determination of whether to start the GC process is only based on the result of judging the FS status and the result of the Block layer IO port at a certain time point of the same length of time. Hence, if there happens to be a user operating the file system at this point in time, the FS system will not be opened. GC processing process.
  • FIG. 5 is a schematic diagram of a GC detection process disclosed in the embodiment of the present application.
  • the file system can perform GC checks periodically. For example, at time T1, the first GC detection is triggered. After judgment, it is found that the FS (file system) status is idle and the Block layer IO is "none", that is, the IO is not occupied (all IO has been released). Therefore the file system can start the GC process. After one GC cycle, at time T2, the second GC detection is triggered. Since the FS is busy during the detection process, the file system ends the second GC cycle and waits for the next GC cycle. At time T3, the third GC detection is triggered.
  • Block layer IO is "active" (IO is occupied, that is, there is still IO not released)
  • GC processing cannot be started, and the third GC cycle is missed.
  • T4 the GC process cannot be started for the same reason as the second GC cycle.
  • the electronic device can monitor the IO of the Block layer. In the case of releasing IO, determine whether any IO is currently occupied. If no IO is occupied, the file system can determine the status of the file system as idle, trigger GC detection, and perform the first GC process. At the same time, the block device layer can notify the storage device to perform the second GC process. In this way, the block device layer monitors the IO occupancy. When all IO is released, it actively changes the status of the file system to the idle state, actively triggers GC detection, and starts the GC process, which can better grasp the electronic equipment.
  • the GC detection determines that the probability of performing GC processing increases, and the number of times storage devices such as disks of electronic equipment are sorted increases, which can delay the jamming of electronic equipment and increase the service life of electronic equipment.
  • Figure 6 is a schematic diagram of the flow of a file garbage collection method disclosed in the embodiment of the present application. As shown in Figure 6, the electronic device may include but is not limited to the following steps:
  • the electronic device can include five parts: file system (for example, F2FS, EXT4, FAT, etc.), block device layer (Block layer), storage device (UFS/eMMC), memory (DDR), and processor (CPU).
  • file system for example, F2FS, EXT4, FAT, etc.
  • Block layer block device layer
  • UFS/eMMC storage device
  • DDR memory
  • processor CPU
  • the file system acquires the first task.
  • the first task refers to a task that requests a file to read and/or write a certain file stored in the storage device.
  • the electronic device can send a task request to the file system.
  • the file system can obtain other modules ( Or some applications) task request, that is, the file system obtains the first task based on the task request.
  • the first application of the electronic device can obtain the user operation for opening the first file.
  • the first application can issue (read and read) the first file to the file system. /or write) task request.
  • the file system can generate the first task according to the first task request. Among them, the first task It is a task for the first file.
  • the user clicks the gallery control on the desktop of the electronic device, and in response to the above user operation, the gallery application (first application) sends a task request to the file system to open the image database (first file).
  • the file system creates or generates the first task based on the task request of the image database.
  • the first task may be to read and write (for example, view or edit, etc.) the picture database.
  • the process of the first application issuing a task request for the first file (reading and/or writing, etc.) to the file system can refer to the process of the above-mentioned application accessing the file system through the system call layer, and the relevant description of Figure 4 can be referred to. No need to go into details.
  • the file system sends a task instruction to the block device layer.
  • the file system When the file system obtains the first task, it may send a task instruction to the block device layer.
  • the block device layer receives task instructions from the file system.
  • the task instruction instructs the block device layer to process the first task.
  • the block device layer calls IO based on task instructions.
  • the block device layer After the block device layer receives the task instruction from the file system, it can call an idle IO port based on the task instruction. At this time, the number of free IO ports is reduced by one, that is, the number of occupied IO ports is increased by one. It can be determined that the existing tasks of the current block device layer need to be processed.
  • the block device layer may include an IO counting module.
  • the current number of IO occupied by the IO counting module (it can also be the number of idle IOs).
  • the IO counting module can determine that the current occupied number increases by one (the IO idle number decreases by one).
  • the number of IO occupied is the number of IO ports called by the block layer
  • the number of IO idle is the number of IO ports not called by the block layer.
  • a task instruction corresponds to a change in the number of IO occupied (or idle).
  • the block device layer of the electronic device can immediately trigger the file system after receiving the task instruction.
  • Status updates That is, when the electronic device monitors that the number of idle IOs changes from 0 to 1, it can trigger the status of the file system to be updated to the busy status.
  • the IO counting module of the block device layer monitors that the IO changes from a fully released state to an IO occupied state, the block device layer sends a busy status notification to the file system. After the file system receives the busy status notification, it updates the status of the file system to the busy status based on the busy status notification.
  • the block device layer sends the first upscaling instruction to the memory.
  • the block device layer After the block device layer determines that the file system task occupies the IO port, it can send the first upscaling instruction to the memory.
  • the memory may receive the first upscaling instruction from the block device layer.
  • the frequency command may include an up-frequency command and a frequency-down command.
  • the first up-frequency instruction is an instruction for instructing the memory to increase the current operating frequency.
  • the first upconversion instruction may include frequency information 1.
  • frequency information 1 may indicate that the operating frequency of the memory is changed to frequency information 1.
  • the current working frequency of the memory is lower than the frequency of frequency information 1.
  • the first upconversion instruction may include an upconversion signal, for example, 1 indicates upconversion and 0 indicates downconversion.
  • the first upconverting instruction may include "1" to refer to upconverting.
  • the block device layer can first determine whether the current memory is working at a low frequency (at least it has not reached the highest frequency working state and needs to be further improved). If the latest time before S604, the block device layer The frequency change command sent to the memory is a frequency downcommand (for details, please refer to the description of S619 and will not be repeated), then the block device The layer can determine that the current operating frequency of the memory still needs to be increased and can be increased. At this time, the block device layer can send a first frequency increase instruction to the memory.
  • the block device layer does not need to determine whether the current memory is operating at a low frequency, and can directly send the first upclocking instruction to the memory. At this time, the memory determines whether to increase the frequency based on the first up-frequency instruction.
  • the working frequency of the memory in this application can have different gears, including high frequency and low frequency gears, or high frequency, intermediate frequency and low frequency gears, etc., which is not limited by this application.
  • the memory may be DDR or other memory, which is not limited.
  • the memory increases the first working frequency based on the first up-frequency instruction.
  • the memory After the memory obtains the first upclocking instruction, it can increase its (first) working frequency based on the first upclocking instruction.
  • the current working frequency of the memory is in a low-frequency state
  • the received first upclocking instruction includes frequency information 1.
  • the memory can adjust the current working frequency to the frequency corresponding to the frequency information 1.
  • the current working frequency of the memory is in a low-frequency state
  • the first up-converting instruction received includes an up-converting signal.
  • the memory can increase the current working frequency to the frequency of an adjacent higher gear, or to the highest gear. Frequency is not limited.
  • the memory increases the first operating frequency based on the first up-clocking instruction.
  • the first operating frequency after the increase only needs to be higher than the first operating frequency before the increase. There is no limit to how much the increase is.
  • the block device layer sends the second upscaling instruction to the processor.
  • the block device layer After the block device layer determines that the task of the file system occupies the IO port, it can send a second upscaling instruction to the processor.
  • the processor may receive the second upscaling instruction from the block device layer.
  • the second up-frequency instruction is an instruction for instructing the processor to increase the current working frequency.
  • the first upconversion instruction may include frequency information 2.
  • frequency information 2 may indicate that the operating frequency of the processor is changed to frequency information 2.
  • the current operating frequency of the processor is lower than the frequency of frequency information 2.
  • the second upconversion instruction may include an upconversion signal.
  • the block device layer can first determine whether the current processor is working at a low frequency (at least it has not reached the highest frequency working state and needs to be further improved). If the latest time before S604, the block device The frequency change instruction sent by the layer to the processor is a frequency reduction instruction (for details, please refer to the description of S621, which will not be described in detail), then the block device layer can determine that the current working frequency of the memory needs to be increased. At this time, the block device layer can send a frequency reduction instruction to the processor. The second upscaling command.
  • the operating frequency of the processor in this application can have different gears, including high frequency and low frequency gears, or high frequency, intermediate frequency and low frequency gears, etc., which is not limited by this application.
  • the block device layer can use the IO counting module to determine whether the current number of occupied IOs is greater than (or equal to) the first number. If it is greater than (or equal to) the first number, S604 can be executed. and S606.
  • the first quantity may be 5, 10, 15, 20, etc., without limitation. In this way, the electronic device can increase the frequency when IO is occupied to a certain extent, ensuring the necessity of increasing the frequency, thereby fully adapting to the needs of the electronic device for processing file tasks, ensuring efficient execution while taking into account energy consumption.
  • the processor increases the second working frequency based on the second up-frequency instruction.
  • the processor After the processor obtains the second upconversion instruction, it can increase its (second) operating frequency based on the second upconversion instruction.
  • the processor increases the working frequency based on the second upclocking instruction.
  • the working frequency after the increase only needs to be higher than the working frequency before the increase. There is no limit to how much the increase can be.
  • For the specific upgrade process please refer to the description of S605 above and will not be described in detail.
  • the working frequency can be increased based on the occupancy of the IO port and dynamically adapted to the intensity of the current task, ensuring that when the user is using it or when the task is heavy, the processing speed can meet the task requirements and avoid Solve the problem of time process and poor user experience.
  • the block device layer sends a task processing notification to the storage device.
  • the block device layer After the block device layer determines that the file system task occupies the IO port, it can send a task processing notification to the storage device.
  • the storage device may receive task processing notifications from the block device layer.
  • the task processing notification is used to instruct the storage device to process the first task.
  • the block device layer can send a task processing notification to the storage device.
  • the number of task notifications sent can be one or multiple, depending on the specific details of the block device layer. Division and processing are not limited by this application.
  • the storage device included in the electronic device may be of UFS or eMMC type.
  • steps S604, S606 and S608 is not limited.
  • the block device layer may send a third upconversion instruction to the storage device, and correspondingly, the storage device may receive the third upconversion instruction from the block device layer. After receiving the third upconversion instruction, the storage device may increase the third operating frequency based on the third upconversion instruction.
  • the third operating frequency is the operating frequency of the storage device.
  • the storage device executes the task based on the task processing notification.
  • the storage device After the storage device receives the task processing notification from the block device layer, it can execute the task based on the task processing notification. That is, the storage device needs to process the first task, determine the location of the data based on the task processing notification, and perform operations such as reading and/or writing.
  • the storage device sends a task end notification to the block device layer.
  • a task end notification may be sent to the block device layer.
  • the block device layer can receive a task end notification from the storage device.
  • the task end notification indicates that the current first task has been processed.
  • the block device layer releases IO based on the task end notification.
  • the block device layer can receive the task end notification from the storage device, it can release IO based on the task end notification.
  • the current number of free IO ports increases by one, that is, the number of occupied IO ports decreases by one.
  • the block device layer may include an IO counting module.
  • the number of currently occupied IO ports of the IO counting module (it can also be the number of idle IOs).
  • the IO counting module can determine that the current number of IO occupations is reduced by one (or the number of idle IOs is increased by one).
  • a task end instruction corresponds to a change in the number of IO occupied (or idle).
  • the block device layer determines whether all IO has been released.
  • the block device layer can determine the number of occupied IOs or the number of idle IOs, and determine whether any IOs are currently occupied. That is, the block device layer can determine whether the number of occupied IOs is 0 (or whether the number of idle IOs is the total number of IOs).
  • the block device layer when IO is released (that is, when the number of IO occupancy is reduced), the block device layer (the IO counting module) determines the number of IO occupancy and determines whether the current number of IO occupancy is 0. When the number of IO occupied is 0 (that is, no IO is occupied), the block device layer can execute S613; otherwise (there is IO occupied), Continue to monitor the number of IO occupations and do not execute S613.
  • the block device layer when the block device layer (the IO counting module) determines that the number of idle IOs increases, it is determined whether the current number of idle IOs is the total number of IOs. When the number of idle IOs is the total number of IOs (no IO ports are occupied), the block device layer can execute S613; otherwise (there are IOs occupied), continue to monitor the number of idle IOs and do not execute S613.
  • the block device layer triggers the file system status update after the first period of time.
  • the block device layer can trigger a file system status update after the first period of time when all IO has been released (it is determined that no IO is occupied). That is, the block device layer can trigger the execution of steps S614 and S615.
  • the first duration may be 1ms, 1s, 5min, etc. In this application, the first duration may range from 1ms to 10min, etc., and the duration is not limited.
  • the update command of the file status is triggered. Try to ensure that there is no task command to process the file within a period of time, and ensure that GC processing is performed when the IO resources of the block layer are idle, thus avoiding IO conflicts with user operations. , while ensuring user experience and increasing the possibility of successful GC processing.
  • the first duration can avoid switching to the idle state too frequently and reduce the consumption of processing resources and energy.
  • the block device layer sends an idle status notification to the file system.
  • the block device layer When the block device layer is not occupied by IO, after the first period of time, the block device layer can send an idle status notification to the file system.
  • the file system can receive idle status notifications from the block device layer.
  • the idle state notification may be an instruction instructing the file system to switch the state to the idle state.
  • the status of the file system includes idle and busy. The idle status indicates that there are currently no tasks to be processed.
  • the file system updates the status of the file system to the idle status based on the idle status notification.
  • the status of the file system can be updated to the idle status based on the idle status notification. That is, when all IOs have been released, the electronic device updates the status of the file system to the idle state through the block device layer.
  • the status of the file system before updating can be idle or busy, and is not limited. After the update, it is in idle state.
  • the block device layer by monitoring the IO window, when the block device layer releases an idle IO port, it can be determined whether there are still IO ports currently occupied. If no IO port is occupied, it can be Switch the file system's status to idle. The status of the file system is updated to idle to facilitate subsequent GC processing and improve the probability of completion of GC processing.
  • the file system triggers GC detection and performs the first GC process.
  • the file system can trigger GC detection and perform the first GC process. That is, the file system can enable GC detection and determine GC.
  • the file system can trigger GC detection, and the file system can perform GC processing when the file system status is idle and there is idle IO in the Block layer.
  • the first GC process refers to the GC operation performed by the file system.
  • the first GC process is the garbage collection mechanism performed by the file system according to the logical address.
  • the block device layer sends a device GC command to the storage device.
  • the block device layer can send device GC instructions to the storage device.
  • the storage device may receive device GC instructions from the block device layer.
  • the device GC instruction refers to the IO generated by GC at the block device layer.
  • the device GC instruction can be obtained from the file system. Obtained, instructs the storage device to perform the second GC process.
  • the storage device performs the second GC process based on the device GC instruction.
  • the storage device may perform the second GC process based on the device GC instruction.
  • the second GC process may be a garbage collection mechanism performed by the storage device according to the physical address.
  • the second GC process may be a garbage collection mechanism performed by the storage device according to the physical address.
  • the block device layer sends the first downclocking instruction to the memory.
  • the first downclocking instruction can be sent to the memory.
  • the memory may receive the first downclocking instruction from the block device layer.
  • the first frequency reduction instruction is an instruction used to instruct the memory to reduce the current operating frequency.
  • the first upconversion instruction may include frequency information 1.
  • frequency information 1 may indicate that the operating frequency of the memory is changed to frequency information 1.
  • the current working frequency of the memory is higher than the frequency of frequency information 1.
  • the first frequency down instruction may include a frequency down signal, for example, 1 represents up frequency and 0 represents down frequency.
  • the first down-clocking instruction may include "0" to refer to down-clocking.
  • the block device layer can first determine whether the current memory is working at high frequency (at least it has not reached the lowest frequency working state, and the frequency needs to be further reduced). If the latest time before S619, the block device The frequency change command sent by the layer to the memory is an up-frequency command (for details, please refer to the description of S604 and will not be repeated), then the block device layer can determine that the current working frequency of the memory still needs to be reduced and can be reduced. At this time, the block device layer can Send the first downclocking command to the memory.
  • the block device layer does not need to determine whether the current memory is operating at a high frequency, and can directly send the first frequency reduction instruction to the memory. At this time, the memory determines whether to reduce the frequency based on the first frequency reduction instruction.
  • the block device layer after the block device layer triggers the file system status update, it can be determined whether the electronic device is in the screen-off state. If it is in the screen-off state, the block device layer sends the first downclocking instruction to the memory. ; Otherwise, the block device layer cannot send the first downclocking instruction. In this way, since users often do not use the electronic device when the screen of the electronic device is turned off, the memory of the electronic device is more likely to be idle. At this time, the working frequency is reduced and the processing speed of the memory is reduced, which can ensure the user experience. At the same time, reduce power consumption.
  • the memory reduces the first working frequency based on the first frequency reduction instruction.
  • the memory After the memory obtains the first frequency reduction instruction, it can reduce its own operating frequency based on the first frequency reduction instruction.
  • the current working frequency of the memory is in a low-frequency state
  • the received first frequency reduction instruction includes frequency information 1.
  • the memory can adjust the current working frequency to the frequency corresponding to the frequency information 1.
  • the current working frequency of the memory is in a low-frequency state
  • the first frequency reduction command received includes a frequency reduction signal.
  • the memory can reduce the current working frequency to the frequency of an adjacent lower gear, or to the lowest gear. Frequency is not limited.
  • the memory reduces the operating frequency based on the first frequency reduction instruction.
  • the reduced operating frequency only needs to be lower than the operating frequency before the reduction. There is no limit to how much the reduction is.
  • the block device layer sends a second downclocking instruction to the processor.
  • a second downclocking instruction can be sent to the processor.
  • the processor may receive a second downclocking instruction from the block device layer.
  • the second frequency reduction instruction includes an instruction for instructing the processor to reduce the current operating frequency.
  • the second The frequency down instruction may include frequency information 2.
  • frequency information 2 may indicate that the operating frequency of the processor is changed to frequency information 2.
  • the current operating frequency of the processor is higher than the frequency of frequency information 2.
  • the second frequency reduction instruction may include a frequency reduction signal.
  • the block device layer after the block device layer triggers the file system status update, it can be determined whether the electronic device is in the screen-off state. If it is in the screen-off state, the block device layer sends a second down-frequency signal to the processor. command; otherwise, the block device layer cannot send the second downclocking command. In this way, since users often do not use the electronic device when the screen of the electronic device is turned off, the probability of the processor of the electronic device being idle is greater. At this time, the working frequency is reduced, and the computing speed of the processor is reduced, which can ensure User experience while reducing power consumption. This process may be the same process as that of S619.
  • S621 also includes other processes for determining whether to send the second frequency reduction instruction to the processor. For details, please refer to the relevant description of S619, which will not be described again.
  • steps S614, S617, S619 and S621 are not distinguished.
  • the processor reduces the second operating frequency based on the second frequency reduction instruction.
  • the processor After the processor obtains the second frequency reduction instruction, it may reduce the operating frequency of the processor itself based on the second frequency reduction instruction.
  • the processor reduces the operating frequency based on the second frequency reduction instruction.
  • the reduced operating frequency only needs to be lower than the operating frequency before the reduction. There is no limit to how much the reduction is.
  • For the specific reduction process please refer to the description of S621 and S620 above, and will not be described again.
  • steps S619 to S622 since the operating frequency can be reduced based on the idle status of the IO port and dynamically adapted to the intensity of the current task, reducing the frequency can also reduce power consumption while ensuring user use.
  • the block device layer may send a third frequency reduction instruction to the storage device, and correspondingly, the storage device may receive the third frequency reduction instruction from the block device layer. After receiving the third frequency reduction instruction, the storage device may reduce the current third operating frequency based on the third frequency reduction instruction.
  • the third operating frequency is the operating frequency of the storage device.
  • Figure 7 is a schematic diagram of the flow of another file garbage collection method disclosed in an embodiment of the present application.
  • the electronic device may include but is not limited to the following steps:
  • the second duration may be 2ms, 1s, 5s, 5min, etc., without limitation.
  • the last GC detection can be a GC detection that is triggered periodically like this time, or it can be a GC detection that is triggered when the Block layer detects that all IOs are released and the file system is updated to the idle state in Figure 6 above. , without limitation. That is to say, it can be understood that after each GC detection, the timing starts, and when the duration reaches the second duration, the GC detection is restarted. If the Block layer detects that all IOs are released and the GC detection is triggered when the file system is updated to the idle state, the GC detection has already occurred before the second period of time has elapsed, and the time can be re-timed.
  • the file system status and block layer IO need to be judged.
  • the first GC processing is performed; otherwise, the GC processing is not performed.
  • the file system sends the device GC command 1 to the block device layer.
  • the file system can send device GC command 1 to the block device layer.
  • the block device layer may receive device GC instructions 1 from the software system.
  • Device GC instruction 1 may be an instruction for the storage device to perform GC operations.
  • the block device layer sends device GC command 2 to the storage device.
  • the block device layer after the block device layer receives device GC command 1 from the software system, it can send device GC command 2 to the storage device.
  • the device GC command 2 and the device GC command 1 may have the same meaning and contain the same information, and both are instructions for the storage device to perform GC operations.
  • S703 and S704 can refer to the description of S617 and S618 above, and will not be described again.
  • the electronic device processing can detect the GC detection triggered when all IOs are released at the Block layer and the file system is updated to the idle state. It can also perform GC detection periodically to ensure the intensity and frequency of GC detection. GC The detection can trigger GC processing, thereby ensuring the frequency of GC processing, ensuring that storage devices frequently perform garbage collection and other sorting operations, delaying the process of storage space fragmentation, thereby extending the service life of electronic devices as much as possible and improving user experience.
  • the second duration ranges from 5ms to 60min, for example, it can be 30ms, 1s, 10min, 30min, etc., which is not limited by this application.
  • the first duration and the second duration may be a fixed duration or a variable duration, which may be related to the degree of dirtiness of the storage space and is not limited by this application.
  • the triggering method of GC detection is to detect the IO status at the block layer and trigger.
  • the file system also performs GC detection periodically according to the second duration.
  • the file system executes step S616, that is, after triggering the GC detection, it starts timing, and after the second period of time, it can start to perform the GC detection again.
  • the GC detection starts, it is determined whether there is idle IO and whether the file system is in the idle state.
  • the electronic device can start GC processing. Otherwise, GC processing is performed. This process is the same as that in Figure 4 and will not be described again.
  • FIG. 8 is a schematic diagram of another GC detection process disclosed in the embodiment of the present application.
  • the file system of the electronic device obtains the idle state (idle) notification of the Block layer, it can start timing.
  • the GC detection is triggered. Since it satisfies In the idle state, if there is no IO occupation in the Block layer, GC processing will be performed, and the memory and processor will be down-clocked.
  • the timing of the GC detection cycle starts.
  • the GC detection can be started. At this time, the GC processing conditions are met and the GC process is executed.
  • the file system receives a notification from the Block layer that the file status is busy, and the electronic device can increase the frequency of the memory and processor.
  • the GC test will be performed again after t2 has passed since the last GC test. Since IO is occupied, GC will not be performed.
  • the file system of the electronic device obtains the idle status (idle) notification of the Block layer, it can start timing. After the first duration (t1), GC detection is triggered. Since the idle status is satisfied, the Block layer If there is no IO occupation, GC processing will be performed, and the memory and processor will Reduce frequency.
  • the processing process is based on consistency.
  • the time interval between the GC detection after t1 at time T7 and the last GC detection is t3, and t3 is less than the duration of t2.
  • triggering GC detection increases the probability of successful GC detection, which can reduce the number of missed GC windows due to conflicts between GC detection and user operations occupying the Block layer IO port, and improve the probability of successful GC processing.
  • the GC detection determines that the probability of performing GC processing increases, and the number of times storage devices such as disks of electronic equipment are sorted increases, which can delay the jamming of electronic equipment and increase the service life of electronic equipment.
  • the electronic device may include a hardware layer, an operating system layer running on the hardware layer, and an application layer running on the operating system layer.
  • This hardware layer includes hardware such as central processing unit (CPU), memory management unit (MMU) and memory (also called main memory).
  • the operating system can be any one or more computer operating systems that implement business processing through processes, such as Linux operating system, Unix operating system, Android operating system, iOS operating system or windows operating system, etc.
  • This application layer includes applications such as browsers, address books, word processing software, and instant messaging software.
  • FIG. 9 shows a schematic diagram of the hardware structure of the electronic device 100.
  • the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2 , mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone interface 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and Subscriber identification module (subscriberidentification module, SIM) card interface 195, etc.
  • SIM Subscriber identification module
  • the sensor module 180 may include a pressure sensor 180A, a gyro sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, and ambient light. Sensor 180L, bone conduction sensor 180M, etc.
  • the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100 .
  • the electronic device 100 may include more or fewer components than shown in the figures, or some components may be combined, some components may be separated, or some components may be arranged differently.
  • the components illustrated may be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (GPU), an image signal processor ( image signal processor (ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU), etc.
  • application processor application processor, AP
  • modem processor graphics processing unit
  • GPU graphics processing unit
  • ISP image signal processor
  • controller video codec
  • digital signal processor digital signal processor
  • DSP digital signal processor
  • baseband processor baseband processor
  • neural network processor neural-network processing unit
  • the controller can generate operation control signals based on the instruction operation code and timing signals to complete instruction fetching and execution. control.
  • the processor 110 may also be provided with a memory for storing instructions and data.
  • the memory in processor 110 is cache memory. This memory may hold instructions or data that have been recently used or recycled by processor 110 . If the processor 110 needs to use the instructions or data again, it can be recalled from memory. Repeated access is avoided and the waiting time of the processor 110 is reduced, thus improving the efficiency of the system.
  • processor 110 may include one or more interfaces.
  • Interfaces may include integrated circuit (inter-integrated circuit, I2C) interface, integrated circuit built-in audio (inter-integrated circuitsound, I2S) interface, pulse code modulation (pulse code modulation, PCM) interface, universal asynchronous receiver (universal asynchronous receiver) /transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, and/or Universal serial bus (USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous receiver
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM subscriber identity module
  • USB Universal serial bus
  • the interface connection relationships between the modules illustrated in the embodiments of the present application are schematic illustrations and do not constitute a structural limitation on the electronic device 100 .
  • the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
  • the charging management module 140 is used to receive charging input from the charger.
  • the charger can be a wireless charger or a wired charger.
  • the charging management module 140 may receive charging input from the wired charger through the USB interface 130 .
  • the charging management module 140 may receive wireless charging input through the wireless charging coil of the electronic device 100 . While the charging management module 140 charges the battery 142, it can also provide power to the electronic device through the power management module 141.
  • the power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110.
  • the power management module 141 receives input from the battery 142 and/or the charging management module 140, and supplies power to the processor 110, the internal memory 121, the display screen 194, the camera 193, the wireless communication module 160, and the like.
  • the power management module 141 can also be used to monitor battery capacity, battery cycle times, battery health status (leakage, impedance) and other parameters.
  • the power management module 141 may also be provided in the processor 110 .
  • the power management module 141 and the charging management module 140 may also be provided in the same device.
  • the wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
  • the electronic device 100 implements display functions through a GPU, a display screen 194, an application processor, and the like.
  • the GPU is an image processing microprocessor and is connected to the display screen 194 and the application processor. GPUs are used to perform mathematical and geometric calculations for graphics rendering.
  • Processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • the display screen 194 is used to display images, videos, etc.
  • Display 194 includes a display panel.
  • the display panel can use a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light emitting diode or an active matrix organic light emitting diode (active-matrix organic light emitting diode).
  • LCD liquid crystal display
  • OLED organic light-emitting diode
  • active-matrix organic light emitting diode active-matrix organic light emitting diode
  • AMOLED organic light-emitting diodes
  • FLED flexible light-emitting diodes
  • Miniled MicroLed, Micro-oLed, quantum dot light-emitting diodes (QLED), etc.
  • the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
  • the electronic device 100 can communicate with the ISP, camera 193, video codec, GPU, display screen 194, and application
  • the processor implements the shooting function.
  • the electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor. Such as music playback, recording, etc.
  • the audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. Audio module 170 may also be used to encode and decode audio signals. In some embodiments, the audio module 170 may be provided in the processor 110 , or some functional modules of the audio module 170 may be provided in the processor 110 .
  • the SIM card interface 195 is used to connect a SIM card.
  • the SIM card can be connected to or separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195 .
  • the electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1.
  • SIM card interface 195 can support Nano SIM card, Micro SIM card, SIM card, etc. Multiple cards can be inserted into the same SIM card interface 195 at the same time. Multiple cards can be of the same type or different types.
  • the SIM card interface 195 is also compatible with different types of SIM cards.
  • the SIM card interface 195 is also compatible with external memory cards.
  • the electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications.
  • the electronic device 100 uses an eSIM, that is, an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100 .
  • the display status of the display screen may include two statuses: screen on and screen off.
  • the Block layer or file system of the electronic device in Figure 4 can obtain the status of the display screen.
  • the electronic device may include a display driver, the display driver may determine the display status of the current display screen, and the block layer or file system may obtain its display status from the display driver.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
  • the computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another, for example, the computer instructions may be transmitted from a website, computer, server, or data center Transmission to another website, computer, server or data center through wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) means.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains one or more available media integrated therein.
  • the usable media may be magnetic media (eg, floppy disk, hard disk, tape), optical media (eg, DVD), or semiconductor media (eg, solid state drive), etc.
  • the program can be stored in a computer-readable storage medium.
  • the aforementioned storage media include: ROM, random access memory (RAM), magnetic disks, optical disks and other media that can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

一种存储空间整理方法及电子设备,电子设备的内核包括文件系统和块设备层,该方法包括:电子设备通过块设备层监听输入输出口IO,在有IO释放的情况下,块设备层判断是否所有IO都已释放;在所有IO都已释放的情况下,电子设备通过块设备层将文件系统的状态更新为空闲状态,触发电子设备通过文件系统进行第一垃圾回收处理,文件系统的状态包括空闲状态和忙碌状态。上述方法可以避免错过GC窗口,保证垃圾回收处理的成功率,以提高存储空间的连续性,延缓电子设备卡顿。

Description

一种存储空间整理方法及电子设备
本申请要求于2022年07月04日提交中国专利局、申请号为202210776818.7、申请名称为“一种存储空间整理方法及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及终端技术领域,尤其涉及一种存储空间整理方法及电子设备。
背景技术
为了提高在电子设备存储空间的连续度以及延缓电子设备的卡顿,需要针对存储空间进行垃圾回收处理,垃圾回收处理往往是需要通过管理存储设备的文件系统进行执行的。在用户使用电子设备的过程中,很有可能使用到电子设备的文件系统。然而,文件系统的处理资源和接口等都是有限的,文件系统进行垃圾回收的处理的过程中与用户的使用可能产生冲突,会导致垃圾回收与用户争抢资源,导致用户卡顿。
发明内容
本申请实施例公开了一种存储空间整理方法及电子设备,可以避免错过GC窗口,保证垃圾回收处理的成功率,以提高存储空间的连续性,延缓电子设备卡顿。
第一方面,本申请提供了一种存储空间整理方法,所述方法应用于电子设备,所述电子设备的内核包括文件系统和块设备层,所述方法包括:所述电子设备通过所述块设备层监听输入输出口IO,在有IO释放的情况下,所述块设备层判断是否所有IO都已释放;在所有IO都已释放的情况下,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,所述文件系统的状态包括空闲状态和忙碌状态。
其中,第一垃圾回收处理是文件系统基于逻辑地址进行的垃圾回收处理。
在本申请实施例中,块设备层对IO占用情况进行监控,在IO全部释放的情况下,主动的变更文件系统的状态为空闲状态,以及主动的触发第一GC检测,开启第一GC的流程,能够更好的把握电子设备的空闲时机,从而能够减少由于第一GC检测与用户操作均占用块设备层IO口冲突造成错过GC窗口的次数,提高电子设备的GC过程的成功率。GC检测确定执行GC处理的概率提高,电子设备的磁盘等存储设备被整理的次数也就变多了,从而可以延缓电子设备的卡顿,提高电子设备的使用寿命。
在一种可能的实现方式中,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,具体包括:所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,在第一时长之后,所述文件系统触发垃圾回收检测,并判断是否满足垃圾回收条件,所述垃圾回收条件为所述文件系统的状态为空闲状态且所述块设备层所有IO都已释放;在满足所述垃圾回收条件的情况下,所述电子设备通过所述文件系统进行第一垃圾回收处理。这样,电子设备在第 一时长之后,再触发文件状态的更新指令,尽可能保证一段时间内没有处理文件的任务指令,保证块设备层的IO资源是空闲的时候进行GC处理,从而可以避免与用户操作的IO冲突,保证用户体验的同时,增加GC处理成功进行的可能性。
在一种可能的实现方式中,在所述文件系统触发垃圾回收检测之后,所述方法还包括:在距所述文件系统触发垃圾回收检测的第二时长之后,所述电子设备通过所述文件系统再一次触发垃圾回收检测,并判断是否满足所述垃圾回收条件;在满足所述垃圾回收条件的情况下,所述电子设备通过所述文件系统再一次进行所述第一垃圾回收处理。这样,电子设备可以在垃圾回收检测之后立即开始周期性检测的计时,满足第二时长度中间没有被主动触发垃圾回收检测(主动触发即上述的文件系统状态更新为空闲状态之后的触发过程)的时候,便可以周期性的进行垃圾回收检测,保证垃圾回收的频率,从而可以进一步提高存储空间的连续性,延缓电子设备的卡顿。
其中,第二时长为周期性进行垃圾回收检测的时长,具体参考图7的相关描述。
在一种可能的实现方式中,所述电子设备还包括存储设备,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态之后,所述方法还包括:所述电子设备通过所述块设备层触发所述存储设备进行第二垃圾回收处理。这样,在进行第二垃圾回收的时候,也可以触发第二垃圾回收的过程,保障物理存储地址也会进行整理,以提高存储空间的连续性。
其中,第二垃圾回收处理是存储设备基于物理地址进行的垃圾回收处理。
在一种可能的实现方式中,所述电子设备通过所述块设备层监听IO,具体包括:所述电子设备通过所述块设备层监听是否接收到任务指令,所述任务指令是所述文件系统获取第一任务的情况下,向所述块设备层发送的指示执行所述第一任务的通知;在所述块设备层接收到所述任务指令的情况下,所述电子设备通过所述块设备层确定有IO占用;所述电子设备通过所述块设备层监听是否接收到任务结束通知,所述任务结束通知是所述电子设备的存储设备在执行完毕所述第一任务的情况下,向所述块设备层发送的通知;在所述块设备层接收到所述任务结束通知的情况下,所述电子设备通过所述块设备层确定有IO释放。这样,块设备层能够通过任务的执行情况监控IO的情况,即块设备层可以通过IO计数模块对IO进行计数,在收到一个任务,占用IO加一,在结束一个任务,占用IO就减一。从而可以保证在有占用IO减少时,触发检测是否占用IO为0,以便触发垃圾回收的过程。从而触发准确性可以避免GC窗口冲突的情况,从而可以保证垃圾回收处理的成功率,以提高存储空间的有序程度,延缓电子设备卡顿。
其中,第一任务可以是文件系统接收到来自用户空间的对文件进行处理的任务。在获取到第一任务的情况下,文件系统向块设备层下发任务指令(可以包括一个或多个任务指令)。在第一任务结束的情况下,存储设备可以向块设备层发送任务结束通知。
在一种可能的实现方式中,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务指令的情况下,所述方法还包括:所述电子设备通过所述块设备层控制所述内存提升第一工作频率;所述电子设备通过所述块设备层控制所述处理器提升第二工作频率。这样,在用户使用的时候,或者文件系统忙碌的情况下,提高工作频率,加快任务的处理,提高处理效率,从而可以减少处理时间,提高用户体验。
其中,第一工作频率是内存的工作频率;第二工作频率是处理器的工作频率,提升工作频率的过程可以参考图6中S604-S607。
在一种可能的实现方式中,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务结束通知,且所述电子设备处于预设状态的情况下,所述方法还包括:所述电子设备通过所述块设备层控制所述内存降低第一工作频率;所述电子设备通过所述块设备层控制所述处理器降低第二工作频率。这样,电子设备能够任务处理完成的情况下,不需要使用到处理资源的时候,降低内存和处理器的工作频率,减少处理资源和能源的浪费。
其中,第一工作频率是内存的工作频率;第二工作频率是处理器的工作频率,降低工作频率的过程可以参考图6中S619-S622。
在一种可能的实现方式中,所述预设状态为电子设备处于灭屏状态且所述文件系统的状态更新为空闲状态。这样,在用户灭屏且文件系统状态确定更新(所有IO均已释放)的时候,来降低工作频率,这种条件下,用户使用电子设备的可能性较低,且任务也已经处理完成,此时降频,能够兼顾用户使用和电子设备的能耗。
其中,本申请中灭屏状态即电子设备的屏幕处于熄灭状态。
第二方面,本申请提供了一种电子设备,包括:一个或多个处理器和一个或多个存储器,所述电子设备的内核包括文件系统和块设备层,所述一个或多个存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当所述一个或多个处理器执行所述计算机指令时,以使得所述电子设备执行:
通过所述块设备层监听输入输出口IO,在有IO释放的情况下,所述块设备层判断是否所有IO都已释放;
在所有IO都已释放的情况下,通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,所述文件系统的状态包括空闲状态和忙碌状态。
其中,第一垃圾回收处理是文件系统基于逻辑地址进行的垃圾回收处理。
在本申请实施例中,块设备层对IO占用情况进行监控,在IO全部释放的情况下,主动的变更文件系统的状态为空闲状态,以及主动的触发第一GC检测,开启第一GC的流程,能够更好的把握电子设备的空闲时机,从而能够减少由于第一GC检测与用户操作均占用块设备层IO口冲突造成错过GC窗口的次数,提高电子设备的GC过程的成功率。GC检测确定执行GC处理的概率提高,电子设备的磁盘等存储设备被整理的次数也就变多了,从而可以延缓电子设备的卡顿,提高电子设备的使用寿命。
在一种可能的实现方式中,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,具体执行:通过所述块设备层将所述文件系统的状态更新为空闲状态,在第一时长之后,所述文件系统触发垃圾回收检测,并判断是否满足垃圾回收条件,所述垃圾回收条件为所述文件系统的状态为空闲状态且所述块设备层所有IO都已释放;在满足所述垃圾回收条件的情况下,通过所述文件系统进行第一垃圾回收处理。这样,电子设备在第一时长之后,再触发文件状态的更新指令,尽可能保证一段时间内没有处理文件的任务指令,保证块设备层的IO资 源是空闲的时候进行GC处理,从而可以避免与用户操作的IO冲突,保证用户体验的同时,增加GC处理成功进行的可能性。
在一种可能的实现方式中,在所述文件系统触发垃圾回收检测之后,所述电子设备还执行:在距所述文件系统触发垃圾回收检测的第二时长之后,通过所述文件系统再一次触发垃圾回收检测,并判断是否满足所述垃圾回收条件;在满足所述垃圾回收条件的情况下,通过所述文件系统再一次进行所述第一垃圾回收处理。这样,电子设备可以在垃圾回收检测之后立即开始周期性检测的计时,满足第二时长度中间没有被主动触发垃圾回收检测(主动触发即上述的文件系统状态更新为空闲状态之后的触发过程)的时候,便可以周期性的进行垃圾回收检测,保证垃圾回收的频率,从而可以进一步提高存储空间的连续性,延缓电子设备的卡顿。
其中,第二时长为周期性进行垃圾回收检测的时长,具体参考图7的相关描述。
在一种可能的实现方式中,所述电子设备还包括存储设备,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态之后,所述电子设备还执行:通过所述块设备层触发所述存储设备进行第二垃圾回收处理。这样,在进行第二垃圾回收的时候,也可以触发第二垃圾回收的过程,保障物理存储地址也会进行整理,以提高存储空间的连续性。
其中,第二垃圾回收处理是存储设备基于物理地址进行的垃圾回收处理。
在一种可能的实现方式中,所述电子设备通过所述块设备层监听IO,具体执行:通过所述块设备层监听是否接收到任务指令,所述任务指令是所述文件系统获取第一任务的情况下,向所述块设备层发送的指示执行所述第一任务的通知;在所述块设备层接收到所述任务指令的情况下,通过所述块设备层确定有IO占用;通过所述块设备层监听是否接收到任务结束通知,所述任务结束通知是所述电子设备的存储设备在执行完毕所述第一任务的情况下,向所述块设备层发送的通知;在所述块设备层接收到所述任务结束通知的情况下,通过所述块设备层确定有IO释放。这样,块设备层能够通过任务的执行情况监控IO的情况,即块设备层可以通过IO计数模块对IO进行计数,在收到一个任务,占用IO加一,在结束一个任务,占用IO就减一。从而可以保证在有占用IO减少时,触发检测是否占用IO为0,以便触发垃圾回收的过程。从而触发准确性可以避免GC窗口冲突的情况,从而可以保证垃圾回收处理的成功率,以提高存储空间的连续性,延缓电子设备卡顿。
其中,第一任务可以是文件系统接收到来自用户空间的对文件进行处理的任务。在获取到第一任务的情况下,文件系统向块设备层下发任务指令(可以包括一个或多个任务指令)。在第一任务结束的情况下,存储设备可以向块设备层发送任务结束通知。
在一种可能的实现方式中,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务指令的情况下,所述电子设备还执行:通过所述块设备层控制所述内存提升第一工作频率;通过所述块设备层控制所述处理器提升第二工作频率。这样,在用户使用的时候,或者文件系统忙碌的情况下,提高工作频率,加快任务的处理,提高处理效率,从而可以减少处理时间,提高用户体验。
其中,第一工作频率是内存的工作频率;第二工作频率是处理器的工作频率,提升工作频率的过程可以参考图6中S604-S607。
在一种可能的实现方式中,所述电子设备还包括内存和处理器,在所述块设备层接收 到所述任务结束通知,且所述电子设备处于预设状态的情况下,所述电子设备还执行:通过所述块设备层控制所述内存降低第一工作频率;通过所述块设备层控制所述处理器降低第二工作频率。这样,电子设备能够任务处理完成的情况下,不需要使用到处理资源的时候,降低内存和处理器的工作频率,减少处理资源和能源的浪费。
其中,第一工作频率是内存的工作频率;第二工作频率是处理器的工作频率,降低工作频率的过程可以参考图6中S619-S622。
在一种可能的实现方式中,所述预设状态为电子设备处于灭屏状态且所述文件系统的状态更新为空闲状态。这样,在用户灭屏且文件系统状态确定更新(所有IO均已释放)的时候,来降低工作频率,这种条件下,用户使用电子设备的可能性较低,且任务也已经处理完成,此时降频,能够兼顾用户使用和电子设备的能耗。
其中,本申请中灭屏状态即电子设备的屏幕处于熄灭状态。
第三方面,本申请提供了一种电子设备,包括一个或多个处理器和一个或多个存储器。该一个或多个处理器与一个或多个存储器耦合,一个或多个存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当一个或多个处理器执行计算机指令时,使得电子设备执行上述任一方面任一项可能的实现方式中的存储空间整理方法。
第四方面,本申请提供了一种电子设备,包括:一个或多个功能模块。一个或多个功能模块用于执行上述任一方面任一项可能的实现方式中的存储空间整理方法。
第五方面,本申请实施例提供了一种计算机存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行上述任一方面任一项可能的实现方式中的存储空间整理方法。
第六方面,本申请实施例提供了一种计算机程序产品,当计算机程序产品在计算机上运行时,使得计算机执行上述任一方面任一项可能的实现方式中的存储空间整理方法。
附图说明
图1是本申请实施例提供的一种操作系统的内核的分层结构示意图;
图2是本申请实施例提供的一种F2FS的存储空间结构的示意图;
图3是本申请实施例提供的一种存储空间的结构示意图;
图4是本申请实施例提供的一种操作系统的内核的分层结构示意图;
图5是本申请实施例提供一种GC检测流程的示意图;
图6是本申请实施例提供一种文件垃圾回收方法流程的示意图;
图7是本申请实施例提供另一种文件垃圾回收方法流程的示意图;
图8是本申请实施例提供的另一种GC检测流程的示意图;
图9是本申请实施例提供的一种电子设备100的硬件结构示意图。
具体实施方式
在本申请的实施例中,采用了“第一”、“第二”等字样对功能和作用基本相同的相同项或相似项进行区分。例如,第一芯片和第二芯片仅仅是为了区分不同的芯片,并不对其 先后顺序进行限定。本领域技术人员可以理解“第一”、“第二”等字样并不对数量和执行次序进行限定,并且“第一”、“第二”等字样也并不限定一定不同。
需要说明的是,本申请实施例中,“示例性的”或者“例如”等词用于表示例子、例证或说明。本申请中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其他实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。
本申请实施例中,“至少一个”是指一个或者多个,“多个”是指两个或两个以上。“和/或”,描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B的情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是指的这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b,或c中的至少一项(个),可以表示:a,b,c,a-b,a--c,b-c,或a-b-c,其中a,b,c可以是单个,也可以是多个。
为了便于清楚描述本申请实施例的技术方案,以下,对本申请实施例中所涉及的部分术语和技术进行简单介绍:
(1)文件在内核层的处理过程
内核是作为基于硬件的第一层软件扩充,提供操作系统的最基本的功能,内核具有管理系统进程、内存、设备驱动程序和文件系统等功能。图1是本申请实施例公开的一种操作系统的内核的分层结构示意图(IO栈结构示意图)。如图1所示,文件系统属于操作系统的内核层(kernel),即文件系统的所有模块均运行在内核态。其中,是内核可以包括虚拟文件系统(virtual filesystem switch,VFS)、不同的文件系统,块设备层(Block layer)和设备驱动(device driver)等。
虚拟文件系统VFS是定义了一个通用文件系统的接口层和适配层,一方面为用户提供了一组统一的访问文件,目录和其他对象的统一放法,另一方面又要和不同的底层文件系统进行适配。具体地,VFS可以将所有的文件系统的共性的东西抽象出来,例如,文件file、索引节点inode、目录项dentry等结构体,针对这些结构体抽象出来的通用的应用程序接口(application programming interface,API),然后具体的文件系统则需要按照相应接口下发即可。即VFS为用户提供了统一的接口,在用户层和文件系统层引入了中间层。
文件系统(file system)的基本数据单位是文件,它的目的是对磁盘上的文件进行组织化管理,组织的方式不同,就会形成不同的文件系统。根据存储位置的不同,可以将文件系统分为3类:磁盘文件系统、虚拟文件系统和网络文件系统。其中,磁盘文件系统的功能是将数据存储在磁盘等存储设备上,并在收到请求的时候,能够进行打开、读、写等操作。例如,第二/三/四代扩展文件系统(extended filesystem,EXT)2/3/4、F2FS、XFS、文件分配表(File Allocation Table,FAT)文件系统等等。
块设备层,就是通过组织管理,使得向块设备下发的请求能够高效合理的完成的一种软件逻辑层。如图1所示,块设备层处于驱动设备和硬件的上层以及文件系统的下层,即 了块设备层是在真实的硬件上抽象的一层,屏蔽不同的硬件驱动,用来IO调度策略的实现和优化。
驱动设备(SCSI层)可以是硬件设备的抽象,包括UFS驱动、eMMC驱动等等,不加限定。
经过上述的描述可以看出,IO从用户态到系统调度进到内核,内核的路径为,VFS,文件系统、块设备层和设备驱动层。示例性地,用户发起读写操作时,并不是直接操作存储设备,而是需要经过较长的IO栈才能完成数据的读写。读写操作大体上需依次经过虚拟文件系统vfs、(磁盘)文件系统、block层、驱动设备层,最后到达存储器件,器件处理完成后发送中断通知驱动程序。
(2)F2FS文件系统
(Flash Friendly File System,F2FS)文件系统。该文件系统是基于Linux内核编译的一款文件系统,专门为基于NAND的存储设备设计的新型开源flash文件系统,特别针对NAND闪存存储介质做了友好设计。其中,NAND闪存(flash memory)是一种比硬盘驱动器更好的存储设备。
图2是本申请实施例公开的一种F2FS的存储空间结构的示意图。如图2所示,整个存储空间被划分为固定大小的段segment,segment是F2FS空间管理的基本单元,也确定了文件系统元数据的初始布局。一定数量连续的segment组成节section,一定数量连续的section组成域zone。其中,section(或segment)和zone是F2FS日志写入和清理的重要单元,通过配置合适的section(或segment)大小可以极大地减少闪存转换层(flash translation layer,FTL)层面垃圾回收的开销。此外,存储空间可以为了随机写入和顺序写入两种方式写入的空间。
F2FS整个存储空间被划分成6个区域,分别为超级块(SB)、检查点(check point,CP)、段信息表(segment information table,SIT)、索引节点地址表(node address table,NAT)、段摘要区(segment summary area,SSA)和主区域(main area)。
上述存储空间的划分可以看出,在F2FS系统中,为了能够在一个连续大的磁盘空间(存储设备)快速写入数据,划分出多个segments,写入存储空间的数据可以零散的分布在存储空间中的。进一步,多个segments便于碎片化的存储空间进行整合,对于存储空间的整合功能可以通过垃圾回收(GC)机制完成的。
(3)垃圾回收(garbage collection,GC)
第一、文件系统的GC处理过程。
由于在文件系统中,由于文件系统的存储,读写和删除等过程往往会让存储空间分割的越来越细,因此文件系统的碎片化程度会随着使用时间的增大而增大,且这种存储空间的碎片化是不可逆的。因此,随着计算设备使用时间的增加,设备存储空间碎片化程度的增加,计算设备对存储空间进行读写等操作的时间变长,用户使用计算设备就会变得卡顿。因此,为了尽可能的延缓碎片化程度的增加F2FS对应有GC方案对存储空间进行整理。
由于计算设备对存储空间中的文件进行写、读和删等的操作,F2FS文件系统就会释放相应的存储空间的地址空间出来,而这些地址空间可能分布在存储空间的每个segment上,造成存储空间空闲(没有存储数据)的地址空间可能分散在存储空间的各个位置。因此, 文件系统通过F2FS的垃圾回收将有效数据较少的segment上的数据搬移到当前在用的segment上,从而能够释放出一个完整的segment的空间出来。
具体地,文件系统执行GC操作的过程可以分为3步,第一,先需要确定搬移目标。例如,文件系统可以基于文件在segment上的有效块,以及segmen的更新之间或年龄确定需要搬移目标。一般选择有效块最少,长时间不更新或变化的segment上的文件进行搬移。第二,文件系统可以识别有效块并进行搬移。第三,文件系统对搬移之后的存储空间进行释放。其中,有效块最少segment是指各个segment中有效数据占segment整个空间比重最少的segment。
示例性的,图3是本申请实施例中公开的一种存储空间的结构示意图。如图3中的(A)所示,存储空间包括有N个以上的segment,且每个segment均为2MB的大小。其中,N为正整数。在存储空间中,在第1个和第2个segment存储有3MB的文件,在第3个和第4个segment上存储有一个4MB的文件,以及在第N个segment上存储有一个4KB的文件。文件系统基于GC可以确定搬移目标为在第N个segment上存储有一个4KB的文件,即在这个segment上有效块最少的文件,即可确定这个segment为搬移目标,之后,文件系统可以将这个4KB的文件搬移到3MB的文件之后紧挨的segment存储空间上。如图3中的(B)所示,文件系统在搬移后,将原来4KB的文件进行释放,其对应的一个segment的存储空间便可以全部释放出来。
在文件系统进行GC的过程中,是基于上述的逻辑地址进行的,而对于存储空间本身也需要对空间进行整理,此时整理的过程往往是基于物理地址进行的。
第二、存储设备的GC处理过程。
本申请所指的存储设备可以是NAND闪存芯片。NAND闪存芯片是一种电子式可清除程序化只读存储器,它的特点是结构简,单位面积的半导体内能实现相当多的数据存储量。这种结构带来的副作用是擦写时不能以比特为单位,而只能以物理块为单位进行大范围的操作。其中,物理块,闪存芯片的存储区域,每个闪存芯片中包含若干个物理块,每个物理块中包含恒定数量的物理页,物理块也是擦除操作的基本单位。
其中,逻辑页地址(逻辑地址)与空闲物理页(物理地址)之间存在映射表,是保存逻辑页地址与物理页地址之间一一对应关系的数据结构。逻辑页地址,描述计算机存储设备上数据所在区块的通用机制,指某个数据区块的地址或某个地址所指向的数据区块,可由闪存转换层转换得到物理地址。空闲物理页,固态存储设备中物理页还没有使用,即其没有数据时,该物理页为空闲物理页,可以用于写请求和垃圾回收操作的分配。
在存储设备垃圾回收的过程一般是先将选中的物理块中的有效数据转移到其它物理块中,然后对其实施擦除操作,通过擦除具有较多无效数据的物理块来回收物理页。
(4)块设备层(block layer)
如图1所示,块设备层连接着文件系统层和设备驱动层,从块设备层接收到任务开始,bio就进入了块设备层,块设备层会接收到IO口,并将这些IO口进行处理这些bio被block层抽象成请求request管理,在适当的时候这些request离开块设备层进入设备驱动层。输入输出接口IO请求完成后,块设备层的软中断负责处理IO完成后的工作。在这个过程中,块设备层会占用IO以及释放IO。
在用户使用电子设备的时候,若用户使用的功能会对磁盘进行读写,那么同样也会占用块设备层的IO口。例如,用户查看手机相册、文档等。
例如,在上述的F2FS文件系统进行IO处理的时候,也会需要占用块设备层IO口,并对磁盘数据进行读写。
(5)存储协议
存储设备是按照存储协议完成存储的,本申请涉及到的存储协议可以包括:嵌入式多媒体卡(embedded multi media card,eMMC)和通用闪存存储(universal flash storage,UFS)。
首先、eMMC是一种闪存卡的标准,它定义了基于嵌入式多媒体卡的存储系统的物理架构和访问接口以及协议。eMMC可以同步工作,工作模式为半双工,每个通道允许读写传输,但是同一时间只能读/写。
其次、UFS就是通用闪存存储,是一种设计用于数码相机、智能电话等消费电子产品使用的闪存存储规范。它的设计目标是发展一套统一的快闪存储卡格式,在提供高数据传输速度和稳定性的同时,也可以减少消费者对于市面上各种存储卡格式的混淆和不同存储卡转接器的使用。UFS采用串行数据传输技术,只有两个数据通道但速率超越eMMC,工作模式为全双工模式,同一条通道允许读写通道,而且读写能够同时进行,传输效率提高。UFS协议的存储设备的速度是比eMMC协议的存储设备要快很多。
(6)内存
内存又叫做主存,是CPU能够直接寻址的存储空间。双倍数据流(double data rate,DDR)是一个内存名称,意思即双倍速率同步动态随机存储器,是内存的其中一种。其中,DDR有自身的工作频率。工作频率越高,DDR的性能越高,当然这也伴随着更大的功耗。
(7)中央处理器(central processing unit,CPU)
CPU作为计算机系统的运算和控制核心,是信息处理、程序运行的最终执行单元。在电子设备中CPU是负责读取指令,对指令译码并执行指令的核心部件。
此外,由于CPU的能够对电子设备中所有的硬件资源(例如存储器等)进行控制调配。
每一个CPU具有一个或多个工作频率,工作频率越高,CPU的性能越高,当然这也伴随着更大的功耗。
基于上述的描述,图4是本申请实施例公开的一种操作系统的内核的分层结构示意图。如图4所示,内核分层结构可以包括用户空间(user space)、内核空间(kernel space)和硬件三个部分。操作系统可以分为两部分,一部分是核心软件,也叫内核空间,运行在较高的特权级别上,拥有访问硬件设备的所有权限。另一部分称为用户空间,普通应用程序在用户空间中运行,普通应用程序不能直接访问内核空间和硬件设备。
用户空间可以包括应用程序。应用程序可以为图库、阅读、**游戏、相机等应用程序,本申请不限定。
内核空间可以包括系统调用层(system call interface)、文件系统和块设备层等。
其中,系统调用层是用户空间和内核空间的桥梁,应用程序通过系统调用层这个统一入口来访问系统中的硬件资源,通过此接口,所有的资源访问都是在内核的控制下执行,以免导致对用户程序对系统资源的越权访问,从而保障了系统的安全和稳定。即系统调用 接口是用来接收用户层的文件处理任务的接口。
文件系统是操作系统用于明确磁盘或分区上的文件的方法和数据结构,即在磁盘上的数据的组织方法。文件系统能够合理规划硬盘,保证用户正常的使用需求。具体用户为用户建立文件,存入、读出、修改、转存文件等。文件系统可以是多种多样的,例如F2FS、EXT4、FAT等等,本申请不加限定。
块设备层(Block层)的描述可以参考上述的描述。在本申请实施例中,块设备层可以包括IO计数模块,用于对IO占用数量(或者IO空闲数量)进行统计等。IO计数模块的相关内容可以参考图6中的描述,不赘述。
硬件可以包括存储设备、内存(模块)和处理器等。
存储设备可以用于存储文件或数据等,例如硬盘、磁盘等。存储设备的协议类型可以为UFS或eMMC,具体可以参考上述描述。
内存用于暂时存放处理器的运算数据,以及硬盘等存储设备交换的数据。电子设备中所有程序的运行都在内存中进行,内存性能的强弱影响计算机整体发挥的水平。本申请中,内存的版本可以是DDR。
处理器即可以是电子设备的CPU。具体介绍可以参考上述的描述,不赘述。
在本申请实施例中,文件系统进行GC检测之后,文件系统可以确定计算设备的磁盘状态是否为idle,在为idle状态的情况下,文件系统可以向block层发送GC检测通知,block层确定当前的IO口结果之后,可以向文件系统发送IO口状态结果。文件系统可以基于IO口状态结果判断是否进行GC处理。
对于计算设备来说,Block层的IO数量是有限的。用户态常用文件操作行为和文件系统IO日志的下发,会导致Block层IO的占用。例如,用户操作计算设备打开了一个文件,或者文件系统IO预读、脏页会写等行为。即Block层接收到任务便会调用(或占用)IO口,计算设备的文件系统进行GC处理的时候,也会调用IO口,如果在用户操作过程与GC处理同时进行的话,Block层的IO资源会被抢占,计算设备执行用户操作需要按照先后顺序进行处理,用户操作所需要处理的任务可能会延迟,从而会影响用户使用体验。
F2FS进行GC处理之前,需要确定是否能够开启GC进程。F2FS的状态包括忙碌busy和空闲idle两种状态,busy表示当前F2FS文件系统正在工作(有进程正在处理);idle状态表示F2FS文件系统没有工作(没有进程需要处理)。由于GC处理的过程中需要占用F2FS的进程和Block层的IO口,因此,F2FS会选择自身处于空闲状态且Block层还有空闲的IO的时候进行GC处理。
为了防止上述的GC处理过程抢占用户使用过程中的IO带宽和F2FS的进程,计算设备可以通过文件系统周期性地进行GC检测,询问自身是否处于idle状态且Block层当前是否有IO口进行调用。在确定文件系统处于idle状态且Block层有IO口的情况下,文件系统进行GC处理,即开启GC进程。否则,不开启GC处理。
上述的GC检测过程是按照特定时长周期性地进行触发的,也就是说确定是否开启GC进程,仅仅基于在同样时间长度的某一时间点上确定判断FS状态的结果以及Block层IO口的结果定的,若这个时间点正好有用户的操作正在使用文件系统,FS系统便不会开启 GC的处理过程。
示例性地,图5为本申请实施例公开的一种GC检测流程的示意图。如图5所示,文件系统可以周期性的进行GC检测。例如,在T1时刻,触发第一次GC检测,经过判断发现FS(文件系统)状态处于idle,Block层IO为“无”,即IO没有被占用(所有IO均已释放)。因此文件系统可以开启GC进程。经过一个GC周期的时间长度之后,在T2时刻,触发第二次GC检测,由于检测过程中FS处于busy,文件系统便结束第二个GC周期,等待下一个GC周期。在T3时刻,触发第三次GC检测,由于Block层IO为“有”(IO被占用,即尚有IO没释放),不能开启GC处理,错过了第三个GC周期。等到T4时刻,由于与第二个GC周期基于相同的理由无法开启GC进程。
上述过程中,由于触发GC进程是周期性的进行判断的,导致文件系统的busy和idle状态判断的不够准确,加之用户操作占用IO与GC过程占用IO发生冲突,加剧了文件系统错过开启GC周期的情况。而GC处理的频率越高,磁盘空间会被整理的越有调序;越长时间没有执行GC进程,也就意味着磁盘空间被占用的越乱,文件系统读取磁盘的过程也就越长,电子设备的卡顿情况也就会越早的出现。
在本申请实施例中,电子设备可以监控Block层的IO。在释放IO的情况下,确定当前是否有IO被占用。若没有IO被占用,文件系统可以便将文件系统的状态确定为idle状态,并触发GC检测,进行第一GC处理。同时块设备层可以通知存储设备进行第二GC处理。这样,块设备层对IO占用情况进行监控,在IO全部释放的情况下,主动的变更文件系统的状态为空闲状态,以及主动的触发GC检测,开启GC的流程,能够更好的把握电子设备的空闲时机,从而能够减少由于GC检测与用户操作均占用Block层IO口冲突造成错过GC窗口的次数,提高电子设备的GC过程的成功率。GC检测确定执行GC处理的概率提高,电子设备的磁盘等存储设备被整理的次数也就变多了,从而可以延缓电子设备的卡顿,提高电子设备的使用寿命。
图6是本申请实施例公开的一种文件垃圾回收方法流程的示意图。如图6所示,电子设备可以包括但不限于以下步骤:
其中,电子设备可以包括文件系统(例如,F2FS、EXT4、FAT等)、块设备层(Block层)、存储设备(UFS/eMMC)、内存(DDR)和处理器(CPU)这5个部分。各个部分的说明可以参考上述图5中的相关描述,不加赘述。
S601、文件系统获取第一任务。
其中,第一任务是指针对于文件请求对存储设备存储的某一文件进行读和/或写的操作的任务。
在处理各种任务进程的时候,有需要对其本地存储的文件进行读和/或写的操作的情况下,电子设备可以向文件系统发送的任务请求,此时文件系统可以获取到其他模块(或一些应用)的任务请求,即文件系统基于任务请求获取到第一任务。
一种可能的实施方式中,电子设备的第一应用可以获取用于打开第一文件的用户操作,响应于上述用户操作,第一应用可以向文件系统下发针对于第一文件的(读和/或写)任务请求。文件系统接收到任务请求之后,可以第一任务请求生成第一任务。其中,第一任务 是针对于第一文件的任务。
示例性地,用户点击电子设备桌面的图库控件,响应于上述的用户操作,图库应用(第一应用)便向文件系统发送开启图片数据库(第一文件)的任务请求。文件系统基于图片数据库的任务请求建立或生成第一任务。第一任务可以是对图片数据库进行读写(例如,查看或编辑等)。
其中,第一应用向文件系统下发针对于第一文件的(读和/或写等)任务请求的过程可以参考上述应用程序通过系统调用层访问文件系统的过程,可以参考图4相关描述,不赘述。
需要说明的是,文件系统获取第一任务的方式还有其他的可能,本申请不做限定。
S602、文件系统向块设备层发送任务指令。
在文件系统获取到第一任务的情况下,可以向块设备层发送任务指令。对应地,块设备层接收来自文件系统的任务指令。其中,任务指令指示块设备层对第一任务进行处理。
S603、块设备层基于任务指令调用IO。
块设备层接收到来自文件系统的任务指令之后,可以基于任务指令调用一个空闲的IO口。此时,空闲IO口的数量减少一个,即占用IO数量加一,可以确定,当前块设备层的存在任务需要处理。
一种实施方式下,块设备层可以包括一个IO计数模块。IO计数模块当前IO占用数量(也可以是IO空闲数量)。在从文件系统获取到任务指令的情况下,IO计数模块可以确定当前的占用数量增加一个(IO空闲数量减少一个)。其中,IO占用数量是block层调用IO口的数量,IO空闲数量是block层没有调用的IO口的数量。
需要说明的是,一个任务指令对应一个IO占用(或空闲)数量的变化。
可选地,若在块设备层接收到任务指令之前,块设备层的IO全部被释放,此时文件系统处于idle状态,电子设备的块设备层接收到任务指令之后,可以立即触发文件系统的状态更新。即电子设备监控空闲IO的数量从0变为1的情况下,可以触发文件系统的状态更新为busy状态。具体地,在块设备层的IO计数模块监控到IO从全部释放的状态变为有IO占用的情况下,块设备层向文件系统发送忙碌状态通知。文件系统接收到忙碌状态通知之后,基于忙碌状态通知将文件系统的状态更新为忙碌状态。
S604、块设备层向内存发送第一升频指令。
块设备层确定文件系统的任务占用IO口之后,可以向内存发送第一升频指令。对应地,其中,内存可以接收来自块设备层的第一升频指令。
本申请实施例中,频率指令可以包括升频指令和降频指令两种。其中,第一升频指令是用于指示内存提高当前工作频率的指示。可选地,第一升频指令可以包括频率信息1。其中,频率信息1可以指示内存的工作频率变更为频率信息1。当前内存的工作频率是低于频率信息1的频率的。可选地,第一升频指令可以包括升频信号,例如,1表示升频,0表示降频。第一升频指令可以包括“1”用于是指升频。
一种可能的实施方式中,块设备层可以先确定当前内存是否处于低频工作(至少还未达到最高频工作的状态,还需要进一步提升)的情况,若在S604之前最近一次,块设备层向内存发送的频率变更指令为降频指令(具体可以参考S619的描述,不赘述),则块设备 层可以确定当前内存的工作频率为还需要提升且能够提升,此时,块设备层可以向内存发送第一升频指令。
另一种可能的实施方式中,块设备层无需确定当前内存是否处于低频工作,可以直接向内存发送第一升频指令。此时,内存基于第一升频指令判断是否提升频率。
需要说明的是,本申请中内存的工作频率可以有不同档位,可以有高频和低频档位,也可以有高频,中频和低频档位等,本申请不限定。
本申请实施例中,内存可以是DDR,还可以是其它,不限定。
S605、内存基于第一升频指令提升第一工作频率。
内存获取到第一升频指令之后,可以基于第一升频指令提升自身的(第一)工作频率。
示例性地,内存当前的工作频率为低频状态,接收到的第一升频指令包括频率信息1,内存可以将当前的工作频率调整为频率信息1对应频率。
示例性地,内存当前的工作频率为低频状态,接收到的第一升频指令包括升频信号,内存可以将当前的工作频率提升相邻更高档位的频率,也可以提高为最高档位的频率,不限定。
在本申请实施例中,内存基于第一升频指令提升第一工作频率,提升后的第一工作频率比提升前的第一工作频率高即可,不限定提升多少。
S606、块设备层向处理器发送第二升频指令。
块设备层确定文件系统的任务占用IO口之后,可以向处理器发送第二升频指令。对应地,处理器可以接收来自块设备层的第二升频指令。
其中,第二升频指令是用于指示处理器提高当前工作频率的指示。可选地,第一升频指令可以包括频率信息2。其中,频率信息2可以指示处理器的工作频率变更为频率信息2。当前处理器的工作频率是低于频率信息2的频率的。可选地,第二升频指令可以包括升频信号,具体可以参考S604的相关描述,不赘述。
一种可能的实施方式中,块设备层可以先确定当前处理器是否处于低频工作(至少还未达到最高频工作的状态,还需要进一步提升)的情况,若在S604之前最近一次,块设备层向处理器发送的频率变更指令为降频指令(具体可以参考S621的描述,不赘述),则块设备层可以确定当前内存的工作频率需要提升,此时,块设备层可以向处理器发送第二升频指令。
需要说明的是,本申请中处理器的工作频率可以有不同档位,可以有高频和低频档位,也可以有高频,中频和低频档位等,本申请不限定。
可选地,块设备层在执行S604和S606之前可以通过IO计数模块判断当前的占用IO数量是否大于(或等于)第一数量,在大于第一数量(或等于)的情况下,可以执行S604和S606。第一数量可以是5、10、15、20等,不限定。这样,电子设备能够在IO占用一定程度下,在提高频率,保证提高频率的必要性,从而可以充分适配电子设备处理文件任务的需要,保证高效执行的同时,兼顾能耗。
S607、处理器基于第二升频指令提升第二工作频率。
处理器获取到第二升频指令之后,可以基于第二升频指令提升自身的(第二)工作频率。
在本申请实施例中,处理器基于第二升频指令提升工作频率,提升后的工作频率比提升前的工作频率高即可,不限定提升多少。提升的过程具体可以参考上述S605的描述,不赘述。
步骤S604~S607的过程中,由于能够基于IO口的占用情况提升工作频率,动态适应当前任务的强度,保证用户使用的时候,或者处理任务较重的时候,处理速度是能够满足任务需求,避免处理时间过程,用户体验差的问题。
S608、块设备层向存储设备发送任务处理通知。
块设备层确定文件系统的任务占用IO口之后,可以向存储设备发送任务处理通知。对应地,存储设备可以接收来自块设备层的任务处理通知。
其中,任务处理通知用于指示存储设备处理第一任务。
需要说明的是,在块设备层接收到文件系统的指令任务之后,可以向存储设备发送任务处理通知,所发送的任务通知的数量可以是一条也可以是多条,需要看块设备层具体的划分和处理,本申请不限定。在本申请中,电子设备的包括的存储设备可以是UFS或者eMMC类型的。
其中,步骤S604,S606和S608的执行先后顺序不加限定。
可选地,块设备层可以向存储设备发送第三升频指令,对应地,存储设备可以接收来自块设备层的第三升频指令。存储设备接收到第三升频指令之后,可以基于第三升频指令提升第三工作频率。第三工作频率是存储设备的工作频率。
S609、存储设备基于任务处理通知执行任务。
存储设备接收到来自块设备层的任务处理通知之后,可以基于任务处理通知执行任务。即存储设备需要处理第一任务,基于任务处理通知确定数据的位置并进读和/或写等操作。
S610、存储设备向块设备层发送任务结束通知。
在存储设备基于任务处理通知执行任务结束之后,可以向块设备层发送任务结束通知。对应地,块设备层可以接收来自存储设备的任务结束通知。
其中,任务结束通知表明当前的第一任务已经处理完成。
S611、块设备层基于任务结束通知释放IO。
块设备层可以接收到来自存储设备的任务结束通知之后,可以基于任务结束通知释放IO。当前的空闲IO口的数量加一,即占用IO数量减一。
一种实施方式下,块设备层可以包括一个IO计数模块。IO计数模块当前IO口的占用数量(也可以是IO空闲数量)。在从存储设备获取到任务结束通知的情况下,IO计数模块可以确定当前的IO占用数量减少一个(或者,IO空闲数量增加一个)。
需要说明的是,一个任务结束指令对应一个IO占用(或空闲)数量的变化。
S612、在释放IO的情况下,块设备层确定是否所有IO都已释放。
块设备层可以确定IO占用数量或者IO空闲数量,并判断当前是否有IO被占用。即块设备层可以判断IO占用数量是否为0(或者IO空闲数量是否为IO总数)。
一种可能的实施方式中,在释放IO的情况下(即在IO占用数量减少的情况下),块设备层(的IO计数模块)确定IO占用数量,判断当前的IO占用数量是否为0。在IO占用数量为0的情况下(即没有IO被占用),块设备层可以执行S613;否则(有IO被占用), 继续监控IO占用数量,且不执行S613。
另一种可能的实施方式中,在块设备层(的IO计数模块)确定空闲IO数量增加的情况下,确定当前IO空闲数量是否为IO总数。在IO空闲数量为IO总数的情况下(没有IO口被占用),块设备层可以执行S613;否则(有IO被占用),继续监控IO空闲数量,且不执行S613。
S613、在所有IO都已释放的情况下,块设备层经过第一时长后触发文件系统状态更新。
块设备层在所有IO都已释放(确定没有IO被占用)的情况下,可以在第一时长后触发文件系统状态更新。即块设备层可以触发步骤S614和S615的执行过程。
其中,第一时长可以是1ms、1s、5min等,在本申请中,第一时长的范围可以是1ms-10min等,时间长度不加限定。在第一时长之后,再触发文件状态的更新指令,尽可能保证一段时间内没有处理文件的任务指令,保证block层的IO资源是空闲的时候进行GC处理,从而可以避免与用户操作的IO冲突,保证用户体验的同时,增加GC处理成功进行的可能性。另外一方面,第一时长可以避免切换为idle状态太过频繁,减少处理资源和能源的消耗。
S614、块设备层向文件系统发送空闲状态通知。
块设备层在没有IO被占用的情况下,块设备层经过第一时长后,可以向文件系统发送空闲状态通知。对应地,文件系统可以接收来自块设备层的空闲状态通知。
其中,空闲状态通知可以是指示文件系统将状态切换为idle状态的指令。文件系统的状态包括idle和busy两种,idle状态表示当前没有任务需要处理。
S615、文件系统基于空闲状态通知将文件系统的状态更新为空闲状态。
在文件系统接收到来自块设备层的空闲状态通知之后,可以基于空闲状态通知将文件系统的状态更新为空闲状态。即,在所有IO都已释放的情况下,电子设备通过块设备层将文件系统的状态更新为空闲状态。其中,文件系统的状态在更新前可以是idle(空闲)或busy(忙碌)状态,不限定。在更新后,为idle状态。
本申请实施例中,通过对IO窗口的监测,在块设备层释放出一个空闲的IO口出来的情况下,可以确定一次是否当前还有IO口被占用,若没有IO口被占用,便可以将文件系统的状态切换为idle。文件系统的状态更新为idle方便后续GC处理的过程,提高GC处理完成的概率。
S616、文件系统触发GC检测,并进行第一GC处理。
在将文件系统的状态更新为空闲状态,文件系统可以触发GC检测,并进行第一GC处理。即文件系统可以开启GC检测,并确定GC。
文件系统可以触发GC检测,文件系统可以在文件系统的状态处于idle且Block层存在空闲IO的情况下,进行GC处理。
其中,第一GC处理是指文件系统进行的GC操作,第一GC处理是文件系统按照逻辑地址进行的垃圾回收机制,具体可以参考上述文件系统的GC过程,不赘述。
S617、块设备层向存储设备发送设备GC指令。
块设备层在触发文件系统状态更新之后,可以向存储设备发送设备GC指令。对应地,存储设备可以接收来自块设备层的设备GC指令。
其中,设备GC指令是指GC在块设备层产生的IO,设备GC指令可以是从文件系统 获取到的,指示存储设备进行第二GC处理。
S618、存储设备基于设备GC指令执行第二GC处理。
存储设备接收到来自块设备层的设备GC指令之后,可以基于设备GC指令执行第二GC处理。
其中,第二GC处理可以是存储设备按照物理地址进行的垃圾回收机制,具体可以参考上述存储设备中的GC过程,不赘述。
S619、块设备层向内存发送第一降频指令。
块设备层触发文件系统状态更新之后,可以向内存发送第一降频指令。对应地,其中,内存可以接收来自块设备层的第一降频指令。
其中,第一降频指令是用于指示内存降低当前工作频率的指示。可选地,第一升频指令可以包括频率信息1。其中,频率信息1可以指示内存的工作频率变更为频率信息1。当前内存的工作频率是高于频率信息1的频率的。可选地,第一降频指令可以包括降频信号,例如,1表示升频,0表示降频。第一降频指令可以包括“0”用于是指降频。
一种可能的实施方式中,块设备层可以先确定当前内存是否处于高频工作(至少还未达到最低频工作的状态,还需要进一步降低频率)的情况,若在S619之前最近一次,块设备层向内存发送的频率变更指令为升频指令(具体可以参考S604的描述,不赘述),则块设备层可以确定当前内存的工作频率为还需要降低且能够降低,此时,块设备层可以向内存发送第一降频指令。
另一种可能的实施方式中,块设备层无需确定当前内存是否处于高频工作,可以直接向内存发送第一降频指令。此时,内存基于第一降频指令判断是否降低频率。
一种可能的实施方式中,在块设备层触发文件系统状态更新之后,可以判断电子设备的是否处于灭屏状态,在处于灭屏状态的情况下,块设备层向内存发送第一降频指令;否则,块设备层不能发送第一降频指令。这样,由于电子设备的屏幕熄灭的状态下,用户往往是不会使用电子设备的,电子设备的内存处于空闲情况的概率更大,这个时候降低工作频率,内存的处理速度降低,能够保证用户体验的同时,降低功耗。
S620、内存基于第一降频指令降低第一工作频率。
内存获取到第一降频指令之后,可以基于第一降频指令降低自身的工作频率。
示例性地,内存当前的工作频率为低频状态,接收到的第一降频指令包括频率信息1,内存可以将当前的工作频率调整为频率信息1对应频率。
示例性地,内存当前的工作频率为低频状态,接收到的第一降频指令包括降频信号,内存可以将当前的工作频率降低相邻更低档位的频率,也可以降低为最低档位的频率,不限定。
在本申请实施例中,内存基于第一降频指令降低工作频率,降低后的工作频率比降低前的工作频率低即可,不限定降低多少。
S621、块设备层向处理器发送第二降频指令。
块设备层触发文件系统状态更新之后,可以向处理器发送第二降频指令。对应地,处理器可以接收来自块设备层的第二降频指令。
其中,第二降频指令包括是用于指示处理器降低当前工作频率的指示。可选地,第二 降频指令可以包括频率信息2。其中,频率信息2可以指示处理器的工作频率变更为频率信息2。当前处理器的工作频率是高于频率信息2的频率的。可选地,第二降频指令可以包括降频信号,具体可以参考S619的相关描述,不赘述。
一种可能的实施方式中,在块设备层触发文件系统状态更新之后,可以判断电子设备的是否处于灭屏状态,在处于灭屏状态的情况下,块设备层向处理器发送第二降频指令;否则,块设备层不能发送第二降频指令。这样,由于电子设备的屏幕熄灭的状态下,用户往往是不会使用电子设备的,电子设备的处理器处于空闲情况的概率更大,这个时候降低工作频率,处理器的运算速度降低,能够保证用户体验的同时,降低功耗。这一处理过程可以与S619的处理过程是同一处理过程。
此外,S621还存在其他的判断是否向处理器发送第二降频指令的过程,具体可以参考S619的相关描述,不赘述。
其中,步骤S614、S617、S619和S621的执行不区分先后顺序。
S622、处理器基于第二降频指令降低第二工作频率。
处理器获取到第二降频指令之后,可以基于第二降频指令降低处理器自身的工作频率。
在本申请实施例中,处理器基于第二降频指令降低工作频率,降低后的工作频率比降低前的工作频率低即可,不限定降低多少。降低的过程具体可以参考上述S621和S620的描述,不赘述。
步骤S619~S622的过程中,由于能够基于IO口的空闲情况降低工作频率,动态适应当前任务的强度,保证用户使用的同时,减少频率也可以降低功耗。
可选地,块设备层可以向存储设备发送第三降频指令,对应地,存储设备可以接收来自块设备层的第三降频指令。存储设备接收到第三降频指令之后,可以基于第三降频指令降低当前第三工作频率。第三工作频率是存储设备的工作频率。
需要说明的是,S604~S607,以及S619~S622的过程不能够割裂的看待,都是基于IO使用状况调整工作频率的过程,能够保证任务强度,用户体验的同时,降低功耗。
基于上述图6的描述,图7是本申请实施例公开的另一种文件垃圾回收方法流程的示意图。如图7所示,电子设备可以包括但不限于以下步骤:
S701、在距上一次GC检测达到第二时长的情况下,触发GC检测,若满足文件系统处于idle状态,且Block层无IO占用的条件下,进行第一GC处理。
其中,第二时长可以是2ms、1s、5s、5min等,不加限定。
其中,上一次的GC检测,可以是如本次一样周期性触发的GC检测,也可以是上述图6中,由于Block层检测到IO全部释放,且文件系统更新为idle状态时触发的GC检测,不加限定。即可以理解为,每一次GC检测之后,均开始计时,在时长达到第二时长,重新开始GC检测。若由于Block层检测到IO全部释放,且文件系统更新为idle状态时触发的GC检测,在尚未到第二时长便已经GC检测,便重新计时即可。
在触发GC检测之后,需要进行文件系统状态和block层IO的判断,当若满足文件系统处于idle状态,且Block层无IO占用的条件下,进行第一GC处理;否则,不进行GC处理。具体可以参考上述图6中S616的描述,以及图5相关的描述,不赘述。
S702、文件系统向块设备层发送设备GC指令1。
可选地,在触发GC检测的情况下,文件系统可以向块设备层发送设备GC指令1。对应地,块设备层可以接收来自件系统的设备GC指令1。设备GC指令1可以是存储设备进行GC操作的指令。
S703、块设备层向存储设备发送设备GC指令2。
可选地,块设备层接收到来自件系统的设备GC指令1之后,可以向存储设备发送设备GC指令2。其中,设备GC指令2与设备GC指令1的含义和包含的信息可以相同,均是存储设备进行GC操作的指令。
S704、基于设备GC指令2执行第二GC处理。
其中,S703和S704可以参考上述S617和S618的描述,不赘述。
上述的实施例中,电子设备处理能够在Block层检测到IO全部释放,且文件系统更新为idle状态时触发的GC检测,还能够周期性地进行GC检测,保证GC检测的强度和频次,GC检测能够触发GC处理,从而可以保证GC处理的频率,保证存储设备的经常进行垃圾回收等整理操作,延缓存储空间碎片化的过程,从而尽可能延长电子设备使用寿命,以及提高用户体验。
在本申请实施例中,第二时长的范围为5ms-60min,例如,可以为30ms、1s、10min、30min等等,本申请不限定。其中,第一时长和第二时长可以是固定的时长,也可以是变化的时长,这可能于存储空间脏的程度有关系,本申请不限定。
在上述的两种实施方式中,仅仅是说明了GC检测的触发方式为block层检测IO状况进行触发的情况,在上述的基础上,文件系统同时也按照第二时长周期性地进行GC检测。
示例性的,文件系统执行步骤S616,即触发GC检测之后,便开启进行计时,经过第二时长,便可以开始重新进行GC检测。GC检测开始之后,判断是否有空闲的IO,以及文件系统是否处于idle状态,在满足上述条件的情况下,电子设备可以开始进行GC处理。否则进行GC处理。这个过程与图4的过程相同,不赘述。
需要说明的是,在没有图6中IO口全部释放,主动触发GC的情况时,GC检测均是按照周期进行的,图6中的主动进行GC检测,会打破GC检测的周期。
为了能够进一步说明本申请实施例的GC处理过程,基于图6和图7的描述,进一步说明。图8是本申请实施例公开的另一种GC检测流程的示意图。如图8所示,在T5时刻,电子设备的文件系统获取到Block层的空闲状态(idle)通知的情况下,可以开始计时,经过第一时长(t1)之后,触发进行GC检测,由于满足idle状态确Block层无IO占用,则进行GC处理,且内存和处理器进行降频。此外,在触发GC检测时,开始进行GC检测周期的计时,计时达到第二时长(t2)的情况下,可以开始进行GC检测,此时满足GC处理条件,执行GC过程。在T6时刻,文件系统接收到来自Block层文件状态处于busy通知,电子设备可以将内存和处理器的频率提升。上一次GC检测再经过t2时长之后再次GC检测,由于有IO被占用,因此,不进行GC。在T6时刻,电子设备的文件系统又获取到Block层的空闲状态(idle)通知的情况下,可以开始计时,经过第一时长(t1)之后,触发进行GC检测,由于满足idle状态确Block层无IO占用,则进行GC处理,且内存和处理器进 行降频。在T5时刻和在T7时刻之后,处理的过程基于一致,其中,在T7时刻经过t1之后的GC检测,与上一次的GC检测时间间隔为t3,t3是小于t2的时长的。具体过程可以结合图6和图7进行理解,不赘述。
上述的过程中,由于触发GC过程打破了原来的周期性的触发过程,触发条件为Block层的IO口没有被占用的情况下,很大概率此时用户没有使用电子设备,即Block层的IO口均是空闲出来的,通常文件系统也处于空闲状态。这种情况下触发GC检测,能够成功进行GC检测的概率变大,能够减少由于GC检测与用户操作均占用Block层IO口冲突造成错过GC窗口的次数,提高GC处理执行成功的概率。GC检测确定执行GC处理的概率提高,电子设备的磁盘等存储设备被整理的次数也就变多了,从而可以延缓电子设备的卡顿,提高电子设备的使用寿命。
在本申请实施例中,电子设备可以包括硬件层、运行在硬件层之上的操作系统层,以及运行在操作系统层上的应用层。该硬件层包括中央处理器(central processing unit,CPU)、内存管理单元(memory management unit,MMU)和内存(也称为主存)等硬件。该操作系统可以是任意一种或多种通过进程(process)实现业务处理的计算机操作系统,例如,Linux操作系统、Unix操作系统、Android操作系统、iOS操作系统或windows操作系统等。该应用层包含浏览器、通讯录、文字处理软件、即时通信软件等应用。
为了能够更好地理解本申请实施例,下面对本申请实施例的电子设备的结构进行介绍:
图9示出了电子设备100的硬件结构示意图。电子设备100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriberidentification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L,骨传导传感器180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processingunit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令 的控制。
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从存储器中调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuitsound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purposeinput/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,是示意性说明,并不构成对电子设备100的结构限定。在本申请另一些实施例中,电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块140可以通过USB接口130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块140可以通过电子设备100的无线充电线圈接收无线充电输入。充电管理模块140为电池142充电的同时,还可以通过电源管理模块141为电子设备供电。
电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,显示屏194,摄像头193,和无线通信模块160等供电。电源管理模块141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块141也可以设置于处理器110中。在另一些实施例中,电源管理模块141和充电管理模块140也可以设置于同一个器件中。
电子设备100的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。
电子设备100通过GPU,显示屏194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏194用于显示图像,视频等。显示屏194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emittingdiode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrixorganic light emitting diode的,AMOLED),柔性发光二极管(flex light-emittingdiode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot lightemitting diodes,QLED)等。在一些实施例中,电子设备100可以包括1个或N个显示屏194,N为大于1的正整数。
电子设备100可以通过ISP,摄像头193,视频编解码器,GPU,显示屏194以及应用 处理器等实现拍摄功能。
电子设备100可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块170还可以用于对音频信号编码和解码。在一些实施例中,音频模块170可以设置于处理器110中,或将音频模块170的部分功能模块设置于处理器110中。
SIM卡接口195用于连接SIM卡。SIM卡可以通过插入SIM卡接口195,或从SIM卡接口195拔出,实现和电子设备100的接触和分离。电子设备100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口195可以同时插入多张卡。多张卡的类型可以相同,也可以不同。SIM卡接口195也可以兼容不同类型的SIM卡。SIM卡接口195也可以兼容外部存储卡。电子设备100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备100中,不能和电子设备100分离。
本申请实施例中,显示屏的显示状态可以包括亮屏和灭屏两种状态,图4中电子设备的Block层或者文件系统可以获取显示屏的状态。具体地,电子设备可以包括显示驱动,显示驱动可以确定当前显示屏的显示状态,Block层或者文件系统可以从显示驱动获取其显示状态。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指示。在计算机上加载和执行所述计算机程序指示时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指示可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指示可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如DVD)、或者半导体介质(例如固态硬盘)等。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,该流程可以由计算机程序来指示相关的硬件完成,该程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法实施例的流程。而前述的存储介质包括:ROM或随机存储记忆体RAM、磁碟或者光盘等各种可存储程序代码的介质。

Claims (16)

  1. 一种存储空间整理方法,其特征在于,所述方法应用于电子设备,所述电子设备的内核包括文件系统和块设备层,所述方法包括:
    所述电子设备通过所述块设备层监听输入输出口IO,在有IO释放的情况下,所述块设备层判断是否所有IO都已释放;
    在所有IO都已释放的情况下,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,所述文件系统的状态包括空闲状态和忙碌状态。
  2. 根据权利要求1所述的方法,其特征在于,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,具体包括:
    所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,在第一时长之后,所述文件系统触发垃圾回收检测,并判断是否满足垃圾回收条件,所述垃圾回收条件为所述文件系统的状态为空闲状态且所述块设备层所有IO都已释放;
    在满足所述垃圾回收条件的情况下,所述电子设备通过所述文件系统进行第一垃圾回收处理。
  3. 根据权利要求2所述的方法,其特征在于,在所述文件系统触发垃圾回收检测之后,所述方法还包括:
    在距所述文件系统触发垃圾回收检测的第二时长之后,所述电子设备通过所述文件系统再一次触发垃圾回收检测,并判断是否满足所述垃圾回收条件;
    在满足所述垃圾回收条件的情况下,所述电子设备通过所述文件系统再一次进行所述第一垃圾回收处理。
  4. 根据权利要求1所述的方法,其特征在于,所述电子设备还包括存储设备,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态之后,所述方法还包括:
    所述电子设备通过所述块设备层触发所述存储设备进行第二垃圾回收处理。
  5. 根据权利要求1-4任一项所述的方法,其特征在于,所述电子设备通过所述块设备层监听IO,具体包括:
    所述电子设备通过所述块设备层监听是否接收到任务指令,所述任务指令是所述文件系统获取第一任务的情况下,向所述块设备层发送的指示执行所述第一任务的通知;
    在所述块设备层接收到所述任务指令的情况下,所述电子设备通过所述块设备层确定有IO占用;
    所述电子设备通过所述块设备层监听是否接收到任务结束通知,所述任务结束通知是所述电子设备的存储设备在执行完毕所述第一任务的情况下,向所述块设备层发送的通知;
    在所述块设备层接收到所述任务结束通知的情况下,所述电子设备通过所述块设备层确定有IO释放。
  6. 根据权利要求5所述的方法,其特征在于,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务指令的情况下,所述方法还包括:
    所述电子设备通过所述块设备层控制所述内存提升第一工作频率;
    所述电子设备通过所述块设备层控制所述处理器提升第二工作频率。
  7. 根据权利要求5所述的方法,其特征在于,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务结束通知,且所述电子设备处于预设状态的情况下,所述方法还包括:
    所述电子设备通过所述块设备层控制所述内存降低第一工作频率;
    所述电子设备通过所述块设备层控制所述处理器降低第二工作频率。
  8. 根据权利要求7所述的方法,其特征在于,所述预设状态为电子设备处于灭屏状态且所述文件系统的状态更新为空闲状态。
  9. 一种电子设备,其特征在于,包括:一个或多个处理器和一个或多个存储器;所述一个或多个处理器与所述一个或多个存储器耦合,所述一个或多个存储器用于存储计算机程序代码,计算机程序代码包括计算机指令,当所述一个或多个处理器执行所述计算机指令时,使得所述电子设备执行如权利要求1-8任一项所述的方法。
  10. 一种计算机可读存储介质,包括指令,其特征在于,当所述指令在电子设备上运行时,使得所述电子设备执行如权利要求1-8中任一项所述的方法。
  11. 一种存储空间整理方法,其特征在于,所述方法应用于电子设备,所述电子设备的内核包括文件系统和块设备层,所述方法包括:
    所述电子设备通过所述块设备层监听输入输出口IO,在有IO释放的情况下,所述块设备层判断是否所有IO都已释放;其中,在所有IO都已释放的情况下,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,触发所述电子设备通过所述文件系统进行第一垃圾回收处理,所述文件系统的状态包括空闲状态和忙碌状态;
    在距上一次垃圾回收检测达到第二时长的情况下,所述电子设备通过所述文件系统触发垃圾回收检测,并判断是否满足垃圾回收条件;在满足所述垃圾回收条件的情况下,所述电子设备通过所述文件系统进行所述第一垃圾回收处理;所述垃圾回收条件为所述文件系统的状态为空闲状态且所述块设备层所有IO都已释放;
    所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态,在第一时长之后,所述文件系统触发垃圾回收检测,并判断是否满足所述垃圾回收条件,所述垃圾回收条件为所述文件系统的状态为空闲状态且所述块设备层所有IO都已释放;在满足所述垃 圾回收条件的情况下,所述电子设备通过所述文件系统进行第一垃圾回收处理;
    其中,在所述第一时长之后,所述文件系统触发垃圾回收检测距上一次垃圾回收检测的时长小于所述第二时长。
  12. 根据权利要求11所述的方法,其特征在于,所述电子设备还包括存储设备,所述电子设备通过所述块设备层将所述文件系统的状态更新为空闲状态之后,所述方法还包括:
    所述电子设备通过所述块设备层触发所述存储设备进行第二垃圾回收处理。
  13. 根据权利要求11或12所述的方法,其特征在于,所述电子设备通过所述块设备层监听IO,具体包括:
    所述电子设备通过所述块设备层监听是否接收到任务指令,所述任务指令是所述文件系统获取第一任务的情况下,向所述块设备层发送的指示执行所述第一任务的通知;
    在所述块设备层接收到所述任务指令的情况下,所述电子设备通过所述块设备层确定有IO占用;
    所述电子设备通过所述块设备层监听是否接收到任务结束通知,所述任务结束通知是所述电子设备的存储设备在执行完毕所述第一任务的情况下,向所述块设备层发送的通知;
    在所述块设备层接收到所述任务结束通知的情况下,所述电子设备通过所述块设备层确定有IO释放。
  14. 根据权利要求13所述的方法,其特征在于,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务指令的情况下,所述方法还包括:
    所述电子设备通过所述块设备层控制所述内存提升第一工作频率;
    所述电子设备通过所述块设备层控制所述处理器提升第二工作频率。
  15. 根据权利要求13所述的方法,其特征在于,所述电子设备还包括内存和处理器,在所述块设备层接收到所述任务结束通知,且所述电子设备处于预设状态的情况下,所述方法还包括:
    所述电子设备通过所述块设备层控制所述内存降低第一工作频率;
    所述电子设备通过所述块设备层控制所述处理器降低第二工作频率。
  16. 根据权利要求15所述的方法,其特征在于,所述预设状态为电子设备处于灭屏状态且所述文件系统的状态更新为空闲状态。
PCT/CN2023/089219 2022-07-04 2023-04-19 一种存储空间整理方法及电子设备 WO2024007678A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
EP23761410.2A EP4328705A1 (en) 2022-07-04 2023-04-19 Storage space arrangement method and electronic device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210776818.7 2022-07-04
CN202210776818.7A CN114840450B (zh) 2022-07-04 2022-07-04 一种存储空间整理方法及电子设备

Publications (1)

Publication Number Publication Date
WO2024007678A1 true WO2024007678A1 (zh) 2024-01-11

Family

ID=82574861

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/089219 WO2024007678A1 (zh) 2022-07-04 2023-04-19 一种存储空间整理方法及电子设备

Country Status (3)

Country Link
EP (1) EP4328705A1 (zh)
CN (1) CN114840450B (zh)
WO (1) WO2024007678A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114840450B (zh) * 2022-07-04 2022-11-18 荣耀终端有限公司 一种存储空间整理方法及电子设备
CN116701244B (zh) * 2022-09-20 2024-05-24 荣耀终端有限公司 一种内存转储方法、装置和电子设备
CN116578392B (zh) * 2023-07-11 2023-09-26 天津卓朗昆仑云软件技术有限公司 虚拟机数据交互方法、系统及电子设备

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1776568A (zh) * 2005-11-28 2006-05-24 北京中星微电子有限公司 基于任务的动态调节cpu工作频率的方法及系统
CN101281458A (zh) * 2008-05-14 2008-10-08 华为技术有限公司 一种垃圾回收的装置、系统及方法
CN109240941A (zh) * 2018-09-21 2019-01-18 郑州云海信息技术有限公司 一种存储系统的垃圾回收方法及相关装置
CN109726137A (zh) * 2017-10-27 2019-05-07 华为技术有限公司 固态硬盘垃圾回收任务的管理方法、控制器和固态硬盘
WO2021162388A1 (ko) * 2020-02-10 2021-08-19 삼성전자 주식회사 스토리지를 포함하는 전자 장치 및 이를 이용한 스토리지로 파일 시스템의 디스카드 커맨드 전달 방법
CN114442932A (zh) * 2017-10-09 2022-05-06 华为技术有限公司 一种垃圾数据清理方法及设备
CN114840450A (zh) * 2022-07-04 2022-08-02 荣耀终端有限公司 一种存储空间整理方法及电子设备

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100501868C (zh) * 2006-03-02 2009-06-17 浙江大学 基于NAND Flash存储器文件系统的实现方法
CN202120349U (zh) * 2011-06-20 2012-01-18 辽宁嘉联科技有限公司 基于多界面智能卡的手持设备支付安全装置
US9448924B2 (en) * 2014-01-08 2016-09-20 Netapp, Inc. Flash optimized, log-structured layer of a file system
US11093453B1 (en) * 2017-08-31 2021-08-17 EMC IP Holding Company LLC System and method for asynchronous cleaning of data objects on cloud partition in a file system with deduplication
CN108874683A (zh) * 2018-05-30 2018-11-23 郑州云海信息技术有限公司 固态存储设备的垃圾回收的方法以及计算机设备
CN113296880A (zh) * 2020-10-30 2021-08-24 阿里巴巴集团控股有限公司 基于容器的应用管理方法和装置

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1776568A (zh) * 2005-11-28 2006-05-24 北京中星微电子有限公司 基于任务的动态调节cpu工作频率的方法及系统
CN101281458A (zh) * 2008-05-14 2008-10-08 华为技术有限公司 一种垃圾回收的装置、系统及方法
CN114442932A (zh) * 2017-10-09 2022-05-06 华为技术有限公司 一种垃圾数据清理方法及设备
CN109726137A (zh) * 2017-10-27 2019-05-07 华为技术有限公司 固态硬盘垃圾回收任务的管理方法、控制器和固态硬盘
CN109240941A (zh) * 2018-09-21 2019-01-18 郑州云海信息技术有限公司 一种存储系统的垃圾回收方法及相关装置
WO2021162388A1 (ko) * 2020-02-10 2021-08-19 삼성전자 주식회사 스토리지를 포함하는 전자 장치 및 이를 이용한 스토리지로 파일 시스템의 디스카드 커맨드 전달 방법
CN114840450A (zh) * 2022-07-04 2022-08-02 荣耀终端有限公司 一种存储空间整理方法及电子设备

Also Published As

Publication number Publication date
CN114840450B (zh) 2022-11-18
EP4328705A1 (en) 2024-02-28
CN114840450A (zh) 2022-08-02

Similar Documents

Publication Publication Date Title
WO2024007678A1 (zh) 一种存储空间整理方法及电子设备
US11669277B2 (en) Latency-based scheduling of command processing in data storage devices
US10866905B2 (en) Access parameter based multi-stream storage device access
US10324832B2 (en) Address based multi-stream storage device access
US10970003B2 (en) Scalable low-latency storage interface
CN110633048B (zh) 闪存存储装置的命名空间操作方法
WO2018082570A1 (zh) I/o请求的调度方法及装置
US8533420B2 (en) Thin provisioned space allocation
US20160253093A1 (en) A new USB protocol based computer acceleration device using multi I/O channel SLC NAND and DRAM cache
US10572379B2 (en) Data accessing method and data accessing apparatus
KR20210038313A (ko) 레이턴시에 중점을 둔 판독 동작과 대역폭에 중점을 둔 판독 동작 사이의 동적 변경
CN111240601B (zh) 一种分区空间的超级块确定方法、装置、设备及存储介质
TWI710905B (zh) 資料儲存裝置及邏輯至物理位址映射表之載入方法
WO2018000300A1 (zh) 一种电子设备的数据操作方法及电子设备
JP2023045456A (ja) コンピュテーショナルストレージドライブ
CN113590501A (zh) 一种数据存储方法及相关设备
CN113468083B (zh) 一种双端口NVMe控制器及控制方法
KR20220006454A (ko) 스토리지 장치에서 네임 스페이스들을 관리하는 방법 및 그 방법을 사용하는 스토리지 장치
WO2024078012A1 (zh) 固态硬盘配置方法、垃圾回收方法以及相关设备
WO2018102226A1 (en) File system streams support and usage
CN113806238A (zh) 内存分配方法、装置、存储介质及电子设备
WO2024088150A1 (zh) 基于开放通道固态盘的数据存储方法、装置、设备、介质及产品
CN115934000B (zh) 一种存储系统的定时方法及相关装置
EP4318247A1 (en) Storage control method and apparatus, storage method and apparatus, electronic device, and medium
WO2023198103A1 (zh) 进程间通信方法和电子设备

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 2023761410

Country of ref document: EP

Effective date: 20230905