[go: up one dir, main page]

CN116049021A - Storage space management method, electronic device, and computer-readable storage medium - Google Patents

Storage space management method, electronic device, and computer-readable storage medium Download PDF

Info

Publication number
CN116049021A
CN116049021A CN202211067942.2A CN202211067942A CN116049021A CN 116049021 A CN116049021 A CN 116049021A CN 202211067942 A CN202211067942 A CN 202211067942A CN 116049021 A CN116049021 A CN 116049021A
Authority
CN
China
Prior art keywords
storage space
sorting
space
fragmentation rate
writable
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN202211067942.2A
Other languages
Chinese (zh)
Other versions
CN116049021B (en
Inventor
周小航
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
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 Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202211067942.2A priority Critical patent/CN116049021B/en
Publication of CN116049021A publication Critical patent/CN116049021A/en
Application granted granted Critical
Publication of CN116049021B publication Critical patent/CN116049021B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

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)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请提供一种存储空间管理方法、电子设备及计算机可读存储介质。存储空间管理方法包括:在满足对存储空间进行GC整理的条件下,确定存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,碎片化率用于表示片段中可写空间的不连续程度;按照碎片化率从大到小的顺序,依次对待进行GC整理的各片段进行GC整理。通过先整理碎片化率最大的片段,可以快速降低存储空间整体的碎片化率,即使GC整理被中断,也可以最大程度提高存储空间中可写空间的连续程度,进而提高电子设备的性能。

Figure 202211067942

The present application provides a storage space management method, an electronic device, and a computer-readable storage medium. The storage space management method includes: under the condition of satisfying the GC sorting of the storage space, determining the size relationship between the fragmentation rates of the segments to be GC sorted in the storage space, and the fragmentation rate is used to represent the writable space in the segment The degree of discontinuity; according to the order of fragmentation rate from large to small, GC sorts the fragments to be sorted by GC in turn. By sorting the fragments with the highest fragmentation rate first, the overall fragmentation rate of the storage space can be quickly reduced. Even if the GC is interrupted, the continuity of the writable space in the storage space can be maximized, thereby improving the performance of electronic devices.

Figure 202211067942

Description

存储空间管理方法、电子设备及计算机可读存储介质Storage space management method, electronic device, and computer-readable storage medium

技术领域technical field

本申请涉及存储空间管理技术的领域,尤其涉及一种存储空间管理方法、电子设备及计算机可读存储介质。The present application relates to the field of storage space management technologies, and in particular to a storage space management method, electronic equipment, and a computer-readable storage medium.

背景技术Background technique

在电子设备使用一段时间后,电子设备会对存储空间进行垃圾回收(GarbageCollection,GC)整理,以降低存储空间中可写空间的不连续程度,使得新写入存储空间的数据尽可能连续,提高电子设备写入数据和读取数据的速度,进而提高电子设备的性能。After the electronic device has been used for a period of time, the electronic device will perform garbage collection (GarbageCollection, GC) on the storage space to reduce the discontinuity of the writable space in the storage space, so that the data newly written into the storage space is as continuous as possible, improving The speed at which an electronic device can write data and read data, thereby improving the performance of the electronic device.

然而,电子设备在对存储空间进行GC整理时会占用电子设备的资源,因此一般在电子设备空闲时才进行GC整理,但当电子设备从空闲状态切换为非空闲状态时,GC整理的过程很容易被中断。在GC整理中断后,若电子设备未能及时再次进行GC整理,会导致可写空间的不连续程度增长较快,进而影响电子设备的性能。However, when the electronic device GCs the storage space, it will occupy the resources of the electronic device, so the GC is generally performed when the electronic device is idle, but when the electronic device switches from the idle state to the non-idle state, the process of GC is very slow easily interrupted. After the GC is interrupted, if the electronic device fails to perform GC again in time, the discontinuity of the writable space will increase rapidly, thereby affecting the performance of the electronic device.

发明内容Contents of the invention

本申请提供一种存储空间管理方法、电子设备及计算机可读存储介质,以解决现有的技术中通过GC整理不能有效降低存储空间的不连续程度的问题。The present application provides a storage space management method, an electronic device and a computer-readable storage medium to solve the problem in the prior art that GC sorting cannot effectively reduce the degree of discontinuity of the storage space.

为达到上述目的,本申请采用如下技术方案:In order to achieve the above object, the application adopts the following technical solutions:

第一方面,提供一种存储空间管理方法,包括:在满足对存储空间进行GC整理的条件下,确定存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,碎片化率用于表示片段中可写空间的不连续程度;按照碎片化率从大到小的顺序,依次对待进行GC整理的各片段进行GC整理。由于碎片化率最大的片段中可写空间的不连续程度最高,通过先整理碎片化率最大的片段,可以快速降低存储空间整体的碎片化率,即使GC整理被中断,也可以最大程度提高存储空间中可写空间的连续程度,进而提高电子设备的性能。In the first aspect, a storage space management method is provided, including: under the condition that the storage space is GC sorted, determine the size relationship between the fragmentation rates of the fragments to be GC sorted in the storage space, the fragmentation rate It is used to indicate the degree of discontinuity of the writable space in the segment; according to the order of fragmentation rate from large to small, each segment to be GC sorted will be GC sorted in turn. Since the discontinuity of the writable space is the highest in the segment with the highest fragmentation rate, the overall fragmentation rate of the storage space can be quickly reduced by sorting out the segment with the highest fragmentation rate first, and the storage space can be maximized even if the GC is interrupted. The degree of continuity of the writable space in the space, thereby improving the performance of electronic devices.

在一实施例中,所述按照所述碎片化率从大到小的顺序,依次对所述待进行GC整理的各片段进行GC整理,包括:In one embodiment, according to the order of the fragmentation rate from large to small, GC sorting is performed on the fragments to be sorted by GC in sequence, including:

根据所述存储空间的碎片化率以及所述存储空间中可写空间的大小,确定GC整理的整理模式,所述存储空间的碎片化率由所述存储空间中的所有片段的数量以及每个片段的碎片化率确定,所述整理模式用于确定GC整理的频率;根据所述整理模式,按照所述碎片化率从大到小的顺序依次对所述待进行GC整理的各片段进行GC整理。According to the fragmentation rate of the storage space and the size of the writable space in the storage space, determine the sorting mode of GC sorting, the fragmentation rate of the storage space is determined by the number of all fragments in the storage space and each The fragment fragmentation rate is determined, and the sorting mode is used to determine the frequency of GC sorting; according to the sorting mode, the fragments to be GC sorted are sequentially GCed in order of the fragmentation rate from large to small tidy.

上述实施例中,根据存储空间的碎片化率和存储空间中可写空间的大小确定对应频率的GC整理模式,使得GC整理的频率与存储空间的存储情况相适配,进而提高电子设备的性能。In the above embodiment, the GC sorting mode corresponding to the frequency is determined according to the fragmentation rate of the storage space and the size of the writable space in the storage space, so that the frequency of GC sorting is adapted to the storage conditions of the storage space, thereby improving the performance of the electronic device .

在一实施例中,所述存储空间中可写空间的大小由所述存储空间中未写入数据的片段的数量或未写入数据的数据块的数量确定,所述片段包括预设数量的数据块。In one embodiment, the size of the writable space in the storage space is determined by the number of fragments or data blocks without data written in the storage space, and the fragments include a preset number of data block.

在一实施例中,所述根据所述存储空间的碎片化率以及所述存储空间中可写空间的大小,确定GC整理的整理模式,包括:In one embodiment, the determining the sorting mode of GC sorting according to the fragmentation rate of the storage space and the size of the writable space in the storage space includes:

若所述存储空间的碎片化率大于第一预设值,所述存储空间中可写空间的大小小于第二预设值,则确定所述整理模式从第一整理模式切换为第二整理模式,所述第二整理模式的GC整理频率大于所述第一整理模式的GC整理频率。If the fragmentation rate of the storage space is greater than a first preset value and the size of the writable space in the storage space is smaller than a second preset value, it is determined that the sorting mode is switched from the first sorting mode to the second sorting mode , the GC sorting frequency of the second sorting mode is greater than the GC sorting frequency of the first sorting mode.

若所述存储空间的碎片化率小于第三预设值,所述存储空间中可写空间的大小大于第四预设值,则确定所述整理模式从所述第二整理模式切换为所述第一整理模式,所述第三预设值小于或等于所述第一预设值,所述第四预设值大于或等于所述第二预设值。If the fragmentation rate of the storage space is less than a third preset value and the size of the writable space in the storage space is greater than a fourth preset value, it is determined that the sorting mode is switched from the second sorting mode to the In the first sorting mode, the third preset value is less than or equal to the first preset value, and the fourth preset value is greater than or equal to the second preset value.

上述实施例中,在存储空间的碎片化率较大、存储空间中可写空间较小的情况下,采用较快的GC整理频率,以快速降低存储空间的碎片化率,使得待写入数据尽可能写入连续程度更高的存储空间,提高了数据写入速度以及后续数据读取速度。在存储空间的碎片化率较小、存储空间中可写空间较大的情况下,采用较慢的GC整理频率,以降低GC整理过程对电子设备的响应速度的影响程度。In the above embodiment, when the fragmentation rate of the storage space is high and the writable space in the storage space is small, a faster GC sorting frequency is used to quickly reduce the fragmentation rate of the storage space, so that the data to be written Write in a storage space with a higher degree of continuity as much as possible, which improves the data writing speed and subsequent data reading speed. When the fragmentation rate of the storage space is small and the writable space in the storage space is large, a slower GC sorting frequency is used to reduce the impact of the GC sorting process on the response speed of the electronic device.

在一实施例中,在所述第一整理模式下,按照第一检测频率检测所述存储空间的碎片化率以及所述存储空间中可写空间的大小,在所述第二整理模式下,按照第二检测频率检测所述存储空间的碎片化率以及所述存储空间中可写空间的大小,所述第二检测频率大于所述第一检测频率。即在第二整理模式下,检测存储空间的碎片化率以及存储空间中可写空间的大小的检测频率更高,从而可以在检测到满足第一整理模式的情况下尽快切换至第一整理模式,即尽快降低GC整理频率,以避免频繁进行GC整理对电子设备的响应速度的影响。In an embodiment, in the first sorting mode, the fragmentation rate of the storage space and the size of the writable space in the storage space are detected according to the first detection frequency; in the second sorting mode, The fragmentation rate of the storage space and the size of the writable space in the storage space are detected according to a second detection frequency, and the second detection frequency is greater than the first detection frequency. That is, in the second sorting mode, the detection frequency of detecting the fragmentation rate of the storage space and the size of the writable space in the storage space is higher, so that it can switch to the first sorting mode as soon as possible when it is detected that the first sorting mode is satisfied , that is, reduce the frequency of GC sorting as soon as possible to avoid the impact of frequent GC sorting on the response speed of electronic equipment.

在一实施例中,所述满足对存储空间进行GC整理的条件包括所述电子设备的内核层未检测到IO指令下发到所述存储空间。在未检测到IO指令下发到所述存储空间的情况下即可进行GC整理,从而可以尽量增加GC整理的次数,避免电子设备长时间处于碎片化率较高的场景。In an embodiment, the satisfying the condition for GC sorting the storage space includes that the kernel layer of the electronic device does not detect that an IO instruction is sent to the storage space. GC sorting can be performed when no IO command is detected to be sent to the storage space, so that the number of GC sorting can be increased as much as possible, and the electronic device is prevented from being in a scene with a high fragmentation rate for a long time.

在一实施例中,所述方法还包括:In one embodiment, the method also includes:

在所述存储空间中不存在未写入数据的片段的情况下,若检测到存在待写入数据,根据所述存储空间中各片段的碎片化率,按照所述碎片化率从小到大的顺序,将所述待写入数据依次写入对应的片段,即将待写入数据优先写入连续程度更高的空间,从而提高数据的写入速度以及后续读取数据的速度。In the case that there is no piece of unwritten data in the storage space, if it is detected that there is data to be written, according to the fragmentation rate of each piece in the storage space, according to the fragmentation rate from small to large Sequentially, the data to be written is written into the corresponding segments sequentially, that is, the data to be written is preferentially written into a space with a higher degree of continuity, so as to increase the speed of writing data and the speed of subsequent reading of data.

第二方面,提供一种存储空间管理装置,包括:In a second aspect, a storage space management device is provided, including:

存储模块,用于在满足对存储空间进行GC整理的条件下,确定所述存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,所述碎片化率用于表示所述片段中可写空间的不连续程度;The storage module is used to determine the size relationship between the fragmentation rates of the fragments to be GC sorted in the storage space under the condition that the GC sorting of the storage space is satisfied, and the fragmentation rate is used to represent the the degree of discontinuity of writable space in the fragment;

处理模块,用于按照所述碎片化率从大到小的顺序,依次对所述待进行GC整理的各片段进行GC整理。The processing module is configured to sequentially perform GC sorting on the fragments to be sorted by GC in descending order of the fragmentation rate.

在一实施例中,所述处理模块具体用于:In one embodiment, the processing module is specifically used for:

根据所述存储空间的碎片化率以及所述存储空间中可写空间的大小,确定GC整理的整理模式,所述存储空间的碎片化率由所述存储空间中的所有片段的数量以及每个片段的碎片化率确定,所述整理模式用于确定GC整理的频率;According to the fragmentation rate of the storage space and the size of the writable space in the storage space, determine the sorting mode of GC sorting, the fragmentation rate of the storage space is determined by the number of all fragments in the storage space and each The fragmentation rate of the fragment is determined, and the sorting mode is used to determine the frequency of GC sorting;

根据所述整理模式,按照所述碎片化率从大到小的顺序依次对所述待进行GC整理的各片段进行GC整理。According to the sorting mode, the fragments to be sorted by GC are sequentially sorted by GC according to the order of the fragmentation rate from the largest to the smallest.

在一实施例中,所述存储空间中可写空间的大小由所述存储空间中未写入数据的片段的数量或未写入数据的数据块的数量确定,所述片段包括预设数量的数据块。In one embodiment, the size of the writable space in the storage space is determined by the number of fragments or data blocks without data written in the storage space, and the fragments include a preset number of data block.

在一实施例中,所述处理模块具体用于:In one embodiment, the processing module is specifically used for:

若所述存储空间的碎片化率大于第一预设值,所述存储空间中可写空间的大小小于第二预设值,则确定所述整理模式从第一整理模式切换为第二整理模式,所述第二整理模式的GC整理频率大于所述第一整理模式的GC整理频率。If the fragmentation rate of the storage space is greater than a first preset value and the size of the writable space in the storage space is smaller than a second preset value, it is determined that the sorting mode is switched from the first sorting mode to the second sorting mode , the GC sorting frequency of the second sorting mode is greater than the GC sorting frequency of the first sorting mode.

在一实施例中,所述处理模块具体用于:In one embodiment, the processing module is specifically used for:

若所述存储空间的碎片化率小于第三预设值,所述存储空间中可写空间的大小大于第四预设值,则确定所述整理模式从所述第二整理模式切换为所述第一整理模式,所述第三预设值小于或等于所述第一预设值,所述第四预设值大于或等于所述第二预设值。If the fragmentation rate of the storage space is less than a third preset value and the size of the writable space in the storage space is greater than a fourth preset value, it is determined that the sorting mode is switched from the second sorting mode to the In the first sorting mode, the third preset value is less than or equal to the first preset value, and the fourth preset value is greater than or equal to the second preset value.

在一实施例中,在所述第一整理模式下,按照第一检测频率检测所述存储空间的碎片化率以及所述存储空间中可写空间的大小,在所述第二整理模式下,按照第二检测频率检测所述存储空间的碎片化率以及所述存储空间中可写空间的大小,所述第二检测频率大于所述第一检测频率。In an embodiment, in the first sorting mode, the fragmentation rate of the storage space and the size of the writable space in the storage space are detected according to the first detection frequency; in the second sorting mode, The fragmentation rate of the storage space and the size of the writable space in the storage space are detected according to a second detection frequency, and the second detection frequency is greater than the first detection frequency.

在一实施例中,所述满足对存储空间进行GC整理的条件包括所述电子设备的内核层未检测到IO指令下发到所述存储空间。In an embodiment, the satisfying the condition for GC sorting the storage space includes that the kernel layer of the electronic device does not detect that an IO instruction is sent to the storage space.

在一实施例中,所述处理模块还用于:In one embodiment, the processing module is also used for:

在所述存储空间中不存在未写入数据的片段的情况下,若检测到存在待写入数据,根据所述存储空间中各片段的碎片化率,按照所述碎片化率从小到大的顺序,将所述待写入数据依次写入对应的片段。In the case that there is no piece of unwritten data in the storage space, if it is detected that there is data to be written, according to the fragmentation rate of each piece in the storage space, according to the fragmentation rate from small to large In order, the data to be written is sequentially written into corresponding segments.

第三方面,提供一种电子设备,包括处理器,所述处理器用于执行存储在存储器中的计算机程序,以实现如上述第一方面所述的存储空间管理方法。In a third aspect, an electronic device is provided, including a processor, the processor is configured to execute a computer program stored in a memory, so as to implement the method for managing storage space as described in the first aspect above.

第四方面,提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如上述第一方面所述的存储空间管理方法。In a fourth aspect, a computer-readable storage medium is provided, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the storage space management method as described in the above-mentioned first aspect is implemented.

第五方面,提供一种芯片,所述芯片包括处理器,所述处理器和存储器耦合,所述处理器执行所述存储器中存储的计算机程序或指令,以实现如上述第一方面所述的存储空间管理方法。In a fifth aspect, there is provided a chip, the chip includes a processor, the processor is coupled to a memory, and the processor executes computer programs or instructions stored in the memory, so as to implement the above-mentioned first aspect Storage space management method.

第六方面,提供一种计算机程序产品,当计算机程序产品在电子设备上运行时,使得电子设备执行上述第一方面所述的存储空间管理方法。According to a sixth aspect, a computer program product is provided. When the computer program product is run on an electronic device, the electronic device is made to execute the storage space management method described in the first aspect above.

可以理解的是,上述第二方面至第六方面的有益效果可以参见上述第一方面中的相关描述,在此不再赘述。It can be understood that, for the beneficial effects of the above-mentioned second aspect to the sixth aspect, reference can be made to the related description in the above-mentioned first aspect, which will not be repeated here.

附图说明Description of drawings

图1为本申请实施例提供的存储空间的示意图;FIG. 1 is a schematic diagram of a storage space provided by an embodiment of the present application;

图2为本申请实施例提供的GC整理前后的存储空间的示意图;FIG. 2 is a schematic diagram of the storage space before and after GC sorting provided by the embodiment of the present application;

图3为本申请实施例提供的电子设备的软件结构框图;FIG. 3 is a block diagram of the software structure of the electronic device provided by the embodiment of the present application;

图4是本申请实施例提供的第一整理模式和第二整理模式切换的场景图;Fig. 4 is a scene diagram of switching between the first sorting mode and the second sorting mode provided by the embodiment of the present application;

图5是本申请一实施例提供的存储空间管理方法的流程图;Fig. 5 is a flowchart of a storage space management method provided by an embodiment of the present application;

图6是本申请实施例提供的内核层的结构图;FIG. 6 is a structural diagram of a kernel layer provided by an embodiment of the present application;

图7是本申请实施例提供的电子设备的结构示意图。FIG. 7 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.

具体实施方式Detailed ways

以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。In the following description, specific details such as specific system structures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.

应当理解,当在本申请说明书和所附权利要求书中使用时,术语“包括”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and/or components, but does not exclude one or more other Presence or addition of features, wholes, steps, operations, elements, components and/or collections thereof.

还应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。It should also be understood that the term "and/or" used in the description of the present application and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

如在本申请说明书和所附权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。类似地,短语“如果确定”或“如果检测到[所描述条件或事件]”可以依据上下文被解释为意指“一旦确定”或“响应于确定”或“一旦检测到[所描述条件或事件]”或“响应于检测到[所描述条件或事件]”。As used in this specification and the appended claims, the term "if" may be construed, depending on the context, as "when" or "once" or "in response to determining" or "in response to detecting ". Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be construed, depending on the context, to mean "once determined" or "in response to the determination" or "once detected [the described condition or event] ]” or “in response to detection of [described condition or event]”.

另外,在本申请的描述中,术语“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。In addition, in the description of the present application, the terms "first", "second" and the like are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance.

在本申请说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。术语“包括”、“包含”、“具有”及它们的变形都意味着“包括但不限于”,除非是以其他方式另外特别强调。Reference to "one embodiment" or "some embodiments" or the like in the specification of the present application means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in other embodiments," etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean "one or more but not all embodiments" unless specifically stated otherwise. The terms "including", "comprising", "having" and variations thereof mean "including but not limited to", unless specifically stated otherwise.

为更好地理解本申请实施例,以下对实施例中可能涉及的术语或概念进行介绍。In order to better understand the embodiments of the present application, terms or concepts that may be involved in the embodiments are introduced below.

1.文件系统(file system)1. File system

文件系统的基本数据单位是文件,是操作系统中用于明确磁盘或分区等存储空间上的文件的方法和数据结构,用于对对应的磁盘或分区上的文件进行组织和管理。The basic data unit of the file system is a file, which is a method and data structure used in the operating system to specify files on storage spaces such as disks or partitions, and is used to organize and manage files on the corresponding disks or partitions.

2.F2FS(Flash Friendly File System)文件系统2. F2FS (Flash Friendly File System) file system

F2FS文件系统是专门为基于NAND的存储设备设计的新型开源flash文件系统,flash支持Linux操作系统。F2FS文件系统在保存文件的数据时,不保证在逻辑上联系的数据在存储空间上也连续。The F2FS file system is a new open source flash file system specially designed for NAND-based storage devices. Flash supports the Linux operating system. When the F2FS file system saves file data, it does not guarantee that logically linked data is also continuous in storage space.

3.片段(segment)3. Fragment (segment)

如图1所示,F2FS文件系统将存储空间划分为固定大小的片段11,片段11是存储空间分配、整理和回收的基本单位。每个片段11包括512个数据块(block)。数据块111是F2FS文件系统数据存储的基本单位,每个数据块111的存储空间是4096字节。存储空间中的每个数据块可以是可读、可写、可擦除三种状态中的一种。实际使用过程中,数据的写入和删除操作频繁交错,因此,存在可写的数据块在存储空间上不连续的片段,即存在可写空间不连续的片段。例如,如图2所示,片段21中,黑色数据块表示写入数据的数据块,白色数据块表示未写入数据的数据块,则片段21为可写空间不连续的片段。As shown in FIG. 1 , the F2FS file system divides the storage space into segments 11 of fixed size, and the segment 11 is the basic unit of storage space allocation, organization and recovery. Each segment 11 includes 512 data blocks (block). The data block 111 is the basic unit of data storage in the F2FS file system, and the storage space of each data block 111 is 4096 bytes. Each data block in the storage space can be in one of three states: readable, writable, and erasable. In actual use, data writing and deletion operations are frequently interleaved, so there are fragments of writable data blocks that are discontinuous in storage space, that is, there are fragments of discontinuous writable space. For example, as shown in FIG. 2 , in the segment 21 , the black data blocks represent the data blocks with written data, and the white data blocks represent the data blocks with no data written, then the segment 21 is a segment with discontinuous writable space.

4.GC整理4. GC finishing

如图2所示,GC整理用于根据一定的算法将可写空间不连续的片段21中的有效数据转移到其他存储空间,转移后删除无效数据即可得到可写空间连续的片段22。As shown in FIG. 2 , GC sorting is used to transfer valid data in fragments 21 with discontinuous writable space to other storage spaces according to a certain algorithm, and delete invalid data after transfer to obtain fragments 22 with continuous writable spaces.

现有技术中,一般在电子设备空闲时才进行GC整理,因此GC整理的过程很容易被中断。在GC整理中断后,若电子设备未能及时再次进行GC整理,会导致可写空间的不连续程度增长较快,进而影响电子设备的性能。In the prior art, GC sorting is generally performed when the electronic device is idle, so the GC sorting process is easily interrupted. After the GC is interrupted, if the electronic device fails to perform GC again in time, the discontinuity of the writable space will increase rapidly, thereby affecting the performance of the electronic device.

为此,本申请提供一种存储空间管理方法,在满足对存储空间进行GC整理的条件下,确定存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,按照碎片化率从大到小的顺序,依次对待进行GC整理的各片段进行GC整理。其中,碎片化率最大的片段中可写空间的不连续程度最高,通过先整理碎片化率最大的片段,可以快速降低存储空间整体的碎片化率,即使GC整理被中断,也可以最大程度提高存储空间中可写空间的连续程度,进而提高电子设备的性能。To this end, the present application provides a storage space management method. Under the condition that the storage space is GC-organized, the size relationship between the fragmentation rates of the fragments to be GC-organized in the storage space is determined. According to the fragmentation rate In order from large to small, GC sorts the fragments to be sorted by GC in turn. Among them, the segment with the largest fragmentation rate has the highest discontinuity in the writable space. By sorting the segment with the highest fragmentation rate first, the overall fragmentation rate of the storage space can be quickly reduced. Even if the GC is interrupted, it can also be maximized. The continuous degree of writable space in the storage space, thereby improving the performance of electronic devices.

下面对本申请实施例提供的存储空间管理方法进行示例性说明。The storage space management method provided by the embodiment of the present application is described below as an example.

本申请实施例提供的存储空间管理方法应用于电子设备。示例性的,本申请实施例中所述的电子设备可以是手机、平板电脑、手持计算机、个人数字助理(personaldigital assistant,PDA)、增强现实(augmented reality,AR)\虚拟现实(virtualreality,VR)设备、媒体播放器、穿戴设备等可单手握持/操作的设备,本申请实施例对该电子设备的具体形态/类型不作特殊限制。上述电子设备包括但不限于搭载

Figure BDA0003823230820000051
鸿蒙系统(Harmony OS)或者其他操作系统的设备。The storage space management method provided in the embodiment of the present application is applied to an electronic device. Exemplarily, the electronic device described in the embodiment of the present application may be a mobile phone, a tablet computer, a handheld computer, a personal digital assistant (personaldigital assistant, PDA), an augmented reality (augmented reality, AR)\virtual reality (virtual reality, VR) Devices, media players, wearable devices, and other devices that can be held/operated with one hand, the embodiment of the present application does not specifically limit the specific form/type of the electronic device. The above-mentioned electronic equipment includes but is not limited to carrying
Figure BDA0003823230820000051
Devices with Harmony OS or other operating systems.

电子设备的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本发明实施例以分层架构的Android系统为例,示例性说明电子设备的软件结构。The software system of the electronic device may adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present invention, the Android system with layered architecture is taken as an example to illustrate the software structure of the electronic device.

图3是本发明实施例的电子设备的软件结构框图。Fig. 3 is a block diagram of the software structure of the electronic device according to the embodiment of the present invention.

分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,将Android系统分为四层,从上至下分别为应用程序层,应用程序框架层,安卓运行时(Android runtime)和系统库,以及内核层。The layered architecture divides the software into several layers, and each layer has a clear role and division of labor. Layers communicate through software interfaces. In some embodiments, the Android system is divided into four layers, which are respectively the application program layer, the application program framework layer, the Android runtime (Android runtime) and the system library, and the kernel layer from top to bottom.

应用程序层可以包括一系列应用程序包。The application layer can consist of a series of application packages.

如图3所示,应用程序包可以包括相机,图库,日历,通话,地图,导航,WLAN,蓝牙,音乐,视频,短信息等应用程序。As shown in FIG. 3, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and short message.

应用程序框架层为应用程序层的应用程序提供应用编程接口(applicationprogramming interface,API)和编程框架。应用程序框架层包括一些预先定义的函数。The application framework layer provides an application programming interface (application programming interface, API) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.

如图3所示,应用程序框架层可以包括窗口管理器,内容提供器,视图系统,电话管理器,资源管理器,通知管理器等。As shown in Figure 3, the application framework layer can include window manager, content provider, view system, phone manager, resource manager, notification manager, etc.

窗口管理器用于管理窗口程序。窗口管理器可以获取显示屏大小,判断是否有状态栏,锁定屏幕,截取屏幕等。A window manager is used to manage window programs. The window manager can get the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc.

内容提供器用来存放和获取数据,并使这些数据可以被应用程序访问。所述数据可以包括视频,图像,音频,拨打和接听的电话,浏览历史和书签,电话簿等。Content providers are used to store and retrieve data and make it accessible to applications. Said data may include video, images, audio, calls made and received, browsing history and bookmarks, phonebook, etc.

视图系统包括可视控件,例如显示文字的控件,显示图片的控件等。视图系统可用于构建应用程序。显示界面可以由一个或多个视图组成的。例如,包括短信通知图标的显示界面,可以包括显示文字的视图以及显示图片的视图。The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, and so on. The view system can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.

电话管理器用于提供电子设备的通信功能。例如通话状态的管理(包括接通,挂断等)。The phone manager is used to provide communication functions of electronic devices. For example, the management of call status (including connected, hung up, etc.).

资源管理器为应用程序提供各种资源,比如本地化字符串,图标,图片,布局文件,视频文件等等。The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and so on.

通知管理器使应用程序可以在状态栏中显示通知信息,可以用于传达告知类型的消息,可以短暂停留后自动消失,无需用户交互。比如通知管理器被用于告知下载完成,消息提醒等。通知管理器还可以是以图表或者滚动条文本形式出现在系统顶部状态栏的通知,例如后台运行的应用程序的通知,还可以是以对话窗口形式出现在屏幕上的通知。例如在状态栏提示文本信息,发出提示音,电子设备振动,指示灯闪烁等。The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages, and can automatically disappear after a short stay without user interaction. For example, the notification manager is used to notify the download completion, message reminder, etc. The notification manager can also be a notification that appears on the top status bar of the system in the form of a chart or scroll bar text, such as a notification of an application running in the background, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, issuing a prompt sound, vibrating the electronic device, and flashing the indicator light, etc.

Android Runtime包括核心库和虚拟机。Android runtime负责安卓系统的调度和管理。Android Runtime includes core library and virtual machine. The Android runtime is responsible for the scheduling and management of the Android system.

核心库包含两部分:一部分是java语言需要调用的功能函数,另一部分是安卓的核心库。The core library consists of two parts: one part is the function function that the java language needs to call, and the other part is the core library of Android.

应用程序层和应用程序框架层运行在虚拟机中。虚拟机将应用程序层和应用程序框架层的java文件执行为二进制文件。虚拟机用于执行对象生命周期的管理,堆栈管理,线程管理,安全和异常的管理,以及垃圾回收等功能。The application layer and the application framework layer run in virtual machines. The virtual machine executes the java files of the application program layer and the application program framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

系统库可以包括多个功能模块。例如:表面管理器(surface manager),媒体库(Media Libraries),三维图形处理库(例如:OpenGL ES),2D图形引擎(例如:SGL)等。A system library can include multiple function modules. For example: surface manager (surface manager), media library (Media Libraries), 3D graphics processing library (eg: OpenGL ES), 2D graphics engine (eg: SGL), etc.

表面管理器用于对显示子系统进行管理,并且为多个应用程序提供了2D和3D图层的融合。The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications.

媒体库支持多种常用的音频,视频格式回放和录制,以及静态图像文件等。媒体库可以支持多种音视频编码格式,例如:MPEG4,H.264,MP3,AAC,AMR,JPG,PNG等。The media library supports playback and recording of various commonly used audio and video formats, as well as still image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

三维图形处理库用于实现三维图形绘图,图像渲染,合成,和图层处理等。The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing, etc.

2D图形引擎是2D绘图的绘图引擎。2D graphics engine is a drawing engine for 2D drawing.

内核层是硬件和软件之间的层。内核层至少包含显示驱动,摄像头驱动,音频驱动,传感器驱动。The kernel layer is the layer between hardware and software. The kernel layer includes at least a display driver, a camera driver, an audio driver, and a sensor driver.

在一实施例中,本申请实施例提供的存储空间管理方法可以在电子设备的内核层执行。由于文件系统(例如F2FS文件系统)运行于内核层,因此在内核层可以通过文件系统的接口获取文件系统所管理的存储空间更详细的存储信息,从而便于更合理的评估存储空间的碎片化率,进而可以通过存储空间的碎片化率更合理地决策GC整理的整理模式以及存储空间中各片段的整理顺序,使得通过GC整理可以快速的降低存储空间中可写空间的不连续程度。In an embodiment, the storage space management method provided in the embodiment of the present application may be executed at a kernel layer of an electronic device. Since the file system (such as the F2FS file system) runs at the kernel layer, more detailed storage information of the storage space managed by the file system can be obtained at the kernel layer through the interface of the file system, so as to facilitate a more reasonable evaluation of the fragmentation rate of the storage space , and then the fragmentation rate of the storage space can be used to more reasonably decide the sorting mode of GC sorting and the sorting order of each fragment in the storage space, so that the degree of discontinuity of the writable space in the storage space can be quickly reduced through GC sorting.

下面对本申请实施例提供的存储空间管理方法进行详细说明。The storage space management method provided by the embodiment of the present application will be described in detail below.

首先根据电子设备的使用状态确定是否满足对存储空间进行GC整理的条件。Firstly, it is determined according to the use state of the electronic device whether the condition for GC sorting the storage space is met.

在一实施例中,可以在电子设备处于预设状态时确定满足对存储空间进行GC整理的条件,预设状态可以是空闲、灭屏、正在充电或电量大于预设值中的任意一项或多项。也可以在电子设备处于预设状态且当前处于预设时段(例如凌晨3点到5点之间)时,确定满足对存储空间进行GC整理的条件。具体地,在电子设备处于预设状态或者电子设备处于预设状态且当前处于预设时段时,应用程序框架层生成满足对存储空间进行GC整理的条件的信息,该信息经过系统库发送至内核层,内核层根据该信息确定满足对存储空间进行GC整理的条件。In an embodiment, it may be determined that the condition for GC finishing the storage space is met when the electronic device is in a preset state, and the preset state may be any one of idle, screen off, charging, or power greater than a preset value or multiple. It may also be determined that the condition for GC finishing the storage space is met when the electronic device is in a preset state and is currently in a preset time period (for example, between 3:00 am and 5:00 am). Specifically, when the electronic device is in a preset state or the electronic device is in a preset state and is currently in a preset period of time, the application framework layer generates information that satisfies the conditions for GC sorting the storage space, and the information is sent to the kernel through the system library Layer, the kernel layer determines that the conditions for GC sorting the storage space are met according to the information.

在另一实施例中,可以在内核层未检测到输入输出(Input/Output,IO)指令下发到存储空间,即在内核层未检测到在存储空间读取数据或写入数据的指令的情况下,满足对存储空间进行GC整理的条件。由于电子设备处于没有IO指令下发到存储空间的状态,相对于上层确定的电子设备处于预设状态的情况更多,因此,在未检测到IO指令下发到存储空间的情况下,确定满足对存储空间进行GC整理的条件,进而对存储空间进行GC整理,可以在电子设备被使用的频率较高的情况下尽可能多的提高GC整理的次数,进而提高电子设备的性能。同时,由于GC整理在内核层执行,通过内核层检测IO指令确定是否满足GC整理的条件,相对于通过上层确定是否满足GC整理的条件再发送至内核层,可以提高GC整理的决策效率,且可以降低GC整理的决策过程所占用的计算资源。In another embodiment, it is possible to issue an I/O (Input/Output, IO) instruction to the storage space at the kernel layer, that is, an instruction to read data or write data in the storage space is not detected at the kernel layer In this case, the conditions for GC finishing the storage space are met. Since the electronic device is in a state where no IO command is sent to the storage space, there are more situations in which the electronic device is in the preset state determined by the upper layer. Therefore, when no IO command is detected and sent to the storage space, it is determined that the Conditions for GC sorting the storage space, and then performing GC sorting on the storage space, can increase the number of GC sorting as much as possible when the frequency of electronic equipment is used is high, thereby improving the performance of the electronic equipment. At the same time, since GC sorting is executed at the kernel layer, the decision-making efficiency of GC sorting can be improved by checking the IO instructions at the kernel layer to determine whether the conditions for GC sorting are met. The computing resources occupied by the decision-making process of GC sorting can be reduced.

由于用户可能在GC整理的过程中使用电子设备,使得GC整理中断,在中断GC整理后响应用户操作,可能会造成电子设备响应速度较慢的情况。因此,可以在内核层未检测到IO指令下发到存储空间,且距离上一次结束GC整理的时间间隔大于预设时长时,确定满足对存储空间进行GC整理的条件,从而可以避免频繁进行GC整理对电子设备性能的影响。Because the user may use the electronic device during the GC sorting process, the GC sorting is interrupted, and responding to user operations after the GC sorting is interrupted may cause the electronic device to respond slowly. Therefore, when the kernel layer does not detect that the IO command is issued to the storage space, and the time interval from the last GC finishing is greater than the preset time, it can be determined that the conditions for GC finishing the storage space are met, thereby avoiding frequent GC The impact of finishing on the performance of electronic devices.

在确定满足对存储空间进行GC整理的条件的情况下,首先确定GC整理模式,整理模式用于确定GC整理的频率,即不同的整理模式对应不同的GC整理的频率。When it is determined that the conditions for GC sorting of the storage space are met, the GC sorting mode is first determined, and the sorting mode is used to determine the frequency of GC sorting, that is, different sorting modes correspond to different frequencies of GC sorting.

在一实施例中,根据存储空间的碎片化率以及所述存储空间中可写空间的大小确定GC整理的模式。其中,存储空间的碎片化率由存储空间中的所有片段的数量以及每个片段的碎片化率确定。片段的碎片化率越高,片段中可写空间的不连续程度越高,当将数据写入该片段时,会导致写入的数据在存储空间上不连续,即会导致逻辑上连续的数据在物理空间上不连续。存储空间的碎片化率越高,存储空间的不连续程度越高。In one embodiment, the GC sorting mode is determined according to the fragmentation rate of the storage space and the size of the writable space in the storage space. Wherein, the fragmentation rate of the storage space is determined by the number of all fragments in the storage space and the fragmentation rate of each fragment. The higher the fragmentation rate of a segment, the higher the degree of discontinuity of the writable space in the segment. When data is written to the segment, the written data will be discontinuous in storage space, which will result in logically continuous data. Not continuous in physical space. The higher the fragmentation rate of the storage space, the higher the discontinuity of the storage space.

具体地,若存储空间的碎片化率大于第一预设值,存储空间中可写空间的大小小于第二预设值,则确定整理模式从第一整理模式切换为第二整理模式,若存储空间的碎片化率小于第三预设值,存储空间中可写空间的大小大于第四预设值,则确定整理模式从第二整理模式切换为第一整理模式。其中,第二整理模式的GC整理频率大于第一整理模式的GC整理频率,例如,第一整理模式下内核层每隔30秒进行一次GC整理,第二整理模式下内核层每隔5秒进行一次GC整理;第三预设值小于或等于第一预设值;第四预设值大于或等于第二预设值。即当存储空间的碎片化率较大、存储空间中可写空间较小时,增大GC整理的频率,从而可以快速降低存储空间的碎片化程度,使得写入片段的数据尽可能连续,提高电子设备的性能。当存储空间的碎片化率较小、存储空间中可写空间较大时,降低GC整理的频率,以避免GC整理的过程占用电子设备的资源,进而避免GC整理的过程影响电子设备的运行速度,提高用户体验。Specifically, if the fragmentation rate of the storage space is greater than the first preset value and the size of the writable space in the storage space is smaller than the second preset value, then it is determined that the sorting mode is switched from the first sorting mode to the second sorting mode, if the storage If the fragmentation rate of the space is less than the third preset value and the size of the writable space in the storage space is greater than the fourth preset value, then it is determined that the sorting mode is switched from the second sorting mode to the first sorting mode. Wherein, the GC sorting frequency of the second sorting mode is greater than the GC sorting frequency of the first sorting mode. For example, in the first sorting mode, the kernel layer performs GC sorting every 30 seconds, and in the second sorting mode, the kernel layer performs GC every 5 seconds. One GC arrangement; the third preset value is less than or equal to the first preset value; the fourth preset value is greater than or equal to the second preset value. That is, when the fragmentation rate of the storage space is high and the writable space in the storage space is small, increase the frequency of GC sorting, so as to quickly reduce the fragmentation degree of the storage space, make the data written into the fragments as continuous as possible, and improve electronic device performance. When the fragmentation rate of the storage space is small and the writable space in the storage space is large, reduce the frequency of GC sorting, so as to avoid the process of GC sorting from occupying the resources of electronic devices, thereby avoiding the process of GC sorting from affecting the running speed of electronic devices , improve user experience.

其中,第一整理模式下的GC整理对应第一GC整理函数,每进行一次GC整理即调用一次第一GC整理函数。第二整理模式下的GC整理对应第二GC整理函数,每进行一次GC整理即调用一次第二GC整理函数。第一GC整理函数和第二GC整理函数可以相同,也可以不同。示例性地,第二GC整理函数的运行时长可以小于第一GC整理函数的运行时长,即第二GC整理模式相对于第一GC整理模式的整理频率增大,且每次整理的时间较短,即第二GC整理模式可以是多次整理、且每次整理空间小的整理模式。Wherein, the GC sorting in the first sorting mode corresponds to the first GC sorting function, and the first GC sorting function is called once every time the GC sorting is performed. The GC sorting in the second sorting mode corresponds to the second GC sorting function, and the second GC sorting function is called every time the GC sorting is performed. The first GC sorting function and the second GC sorting function may be the same or different. Exemplarily, the running time of the second GC sorting function may be shorter than the running time of the first GC sorting function, that is, the sorting frequency of the second GC sorting mode is higher than that of the first GC sorting mode, and the time for each sorting is shorter , that is, the second GC sorting mode can be a sorting mode with multiple sorting times and a small space for each sorting.

示例性地,如图4所示,横坐标表示时间,单位为秒,纵坐标表示碎片化率,A>B,在满足GC整理的条件的情况下,采用第一整理模式进行GC整理。在t1时刻,存储空间的碎片化率为A%,且存储空间中可写空间的大小小于第二预设值,则从第一整理模式切换为第二整理模式,根据第二整理模式进行GC整理。在t2时刻,存储空间的碎片化率为B%,且存储空间中可写空间的大小大于第四预设值,仍然满足GC整理的条件,则退出第二整理模式,进入第一整理模式,从而可以在存储空间的碎片化率较高的情况下,增加GC整理的频率,以快速降低存储空间的碎片化率。Exemplarily, as shown in FIG. 4 , the abscissa represents time in seconds, and the ordinate represents the fragmentation rate, A>B. If the conditions for GC sorting are met, the first sorting mode is used for GC sorting. At time t1, the fragmentation rate of the storage space is A%, and the size of the writable space in the storage space is smaller than the second preset value, switch from the first sorting mode to the second sorting mode, and perform GC according to the second sorting mode tidy. At time t2, the fragmentation rate of the storage space is B%, and the size of the writable space in the storage space is greater than the fourth preset value, and still meets the condition of GC sorting, then exit the second sorting mode and enter the first sorting mode, Therefore, when the fragmentation rate of the storage space is high, the frequency of GC sorting can be increased to quickly reduce the fragmentation rate of the storage space.

在一实施例中,存储空间中可写空间的大小由存储空间中未写入数据的片段的数量确定,在存储空间的碎片化率大于第一预设值,未写入数据的片段的数量小于第二预设值时,进入第二整理模式,以提高GC整理的频率。在存储空间的碎片化率小于第三预设值,未写入数据的片段的数量大于第四预设值时,进入第一整理模式,以降低GC整理的频率。In one embodiment, the size of the writable space in the storage space is determined by the number of unwritten data fragments in the storage space, the fragmentation rate of the storage space is greater than the first preset value, and the number of unwritten data fragments When it is less than the second preset value, enter the second sorting mode to increase the frequency of GC sorting. When the fragmentation rate of the storage space is less than the third preset value and the number of unwritten data fragments is greater than the fourth preset value, enter the first sorting mode to reduce the frequency of GC sorting.

例如,用Free_segment表示存储空间中未写入数据的片段的数量,GC_FRAG_SCORE_RATE表示存储空间的碎片化率。第一预设值设为45%,第二预设值设为2*OVP,第三预设值设为40%,第四预设值设为3*OVP。For example, use Free_segment to indicate the number of unwritten data segments in the storage space, and GC_FRAG_SCORE_RATE to indicate the fragmentation rate of the storage space. The first preset value is set to 45%, the second preset value is set to 2*OVP, the third preset value is set to 40%, and the fourth preset value is set to 3*OVP.

在Free_segment<=2*OVP,且GC_FRAG_SCORE_RATE>45%时,进入第二整理模式;在Free_segment>=3*OVP,GC_FRAG_SCORE_RATE<40%时,进入第一整理模式。其中,OVP表示预设片段数量的预留值,在存储空间中未写入数据的片段的数量较多(例如未写入数据的片段的数量大于2*OVP)时,一般选择用可写空间连续的片段依次存储待写入数据。在存储空间中未写入数据的片段的数量小于2*OVP时,说明存储空间的可用空间较小,选择用可写空间不连续的片段(即已经写入数据但未写满的片段)存储待写入数据。用可写空间不连续的片段存储待写入数据会影响数据写入速度以及后续数据的读取速度。因此,在存储空间中未写入数据的片段的数量小于2*OVP时,加快GC整理的频率,可以尽快得到更多可写空间连续的片段,使得待写入数据可以写入可写空间连续的片段。When Free_segment<=2*OVP, and GC_FRAG_SCORE_RATE>45%, enter the second sorting mode; when Free_segment>=3*OVP, GC_FRAG_SCORE_RATE<40%, enter the first sorting mode. Among them, OVP represents the reserved value of the preset number of fragments. When the number of fragments without data written in the storage space is large (for example, the number of fragments without data written is greater than 2*OVP), generally choose to use writable space Contiguous segments sequentially store data to be written. When the number of fragments with no data written in the storage space is less than 2*OVP, it means that the available space of the storage space is small, and choose to use fragments with discontinuous writable space (that is, fragments that have written data but are not full) to store Data to be written. Using discontinuous pieces of writable space to store the data to be written will affect the data writing speed and the reading speed of subsequent data. Therefore, when the number of unwritten fragments in the storage space is less than 2*OVP, the frequency of GC sorting can be accelerated, and more fragments with continuous writable space can be obtained as soon as possible, so that the data to be written can be written into the continuous writable space fragments.

在另一实施例中,存储空间中可写空间的大小也可以由存储空间中未写入数据的数据块的数量确定,在存储空间的碎片化率大于第一预设值,未写入数据的数据块的数量小于第二预设值时,进入第二整理模式,以提高GC整理的频率。在存储空间的碎片化率小于第三预设值,未写入数据的数据块的数量大于第四预设值时,进入第一整理模式,以降低GC整理的频率。In another embodiment, the size of the writable space in the storage space can also be determined by the number of data blocks in the storage space that have not written data. When the fragmentation rate of the storage space is greater than the first preset value, no data has been written. When the number of data blocks is less than the second preset value, enter the second sorting mode to increase the frequency of GC sorting. When the fragmentation rate of the storage space is less than the third preset value and the number of data blocks without written data is greater than the fourth preset value, enter the first sorting mode to reduce the frequency of GC sorting.

例如,用Free_blocks表示未写入数据的数据块的数量,space表示文件系统所管理的存储空间的总容量。第一预设值设为55%,第二预设值设为5%*space,第三预设值设为45%,第四预设值设为10%*space。For example, Free_blocks represents the number of data blocks that have not been written into, and space represents the total capacity of the storage space managed by the file system. The first preset value is set to 55%, the second preset value is set to 5%*space, the third preset value is set to 45%, and the fourth preset value is set to 10%*space.

在Free_blocks<=5%*space,GC_FRAG_SCORE_RATE>55%时,进入第二整理模式;在Free_blocks>=10%*space,GC_FRAG_SCORE_RATE<45%时,进入第一整理模式。When Free_blocks<=5%*space, GC_FRAG_SCORE_RATE>55%, enter the second sorting mode; when Free_blocks>=10%*space, GC_FRAG_SCORE_RATE<45%, enter the first sorting mode.

在一实施例中,每个片段的碎片化率用对应片段的碎片化得分表示。In one embodiment, the fragmentation rate of each segment is represented by the fragmentation score of the corresponding segment.

其中,片段的碎片化得分的计算公式为:Among them, the calculation formula of the fragmentation score of the fragment is:

Figure BDA0003823230820000081
Figure BDA0003823230820000081

其中,score表示片段的碎片化得分,X表示片段中不可写的数据块的数量,weigh表示权重,block(i)表示片段中第i个数据块的得分,第i个数据块的得分与第i个数据块、第i-1个数据块、第i+1个数据块的可写状态是否一致有关。例如,若第i个数据块、第i-1个数据块、第i+1个数据块可写状态一致,即均为可写或均为不可写,则第i个数据块的得分为0;若第i个数据块与第i-1个数据块的可写状态一致,且与第i+1个数据块可写状态不一致,则第i个数据块的得分为1;若第i个数据块与第i-1个数据块的可写状态不一致,且与第i+1个数据块可写状态一致,则第i个数据块的得分为1;若第i个数据块与第i-1个数据块的可写状态不一致,且与第i+1个数据块可写状态不一致,则第i个数据块的得分为2。Among them, score represents the fragmentation score of the fragment, X represents the number of unwritable data blocks in the fragment, weight represents the weight, block(i) represents the score of the i-th data block in the fragment, and the score of the i-th data block is related to the score of the i-th data block Whether the writable status of the i data block, the i-1th data block, and the i+1th data block are consistent is related. For example, if the i-th data block, the i-1th data block, and the i+1th data block have the same writable status, that is, they are all writable or unwritable, then the score of the i-th data block is 0 ; If the writable state of the i-th data block is consistent with that of the i-1th data block, and inconsistent with the writable state of the i+1th data block, the score of the i-th data block is 1; if the i-th data block If the writable status of the data block is inconsistent with that of the i-1th data block, and is consistent with the writable status of the i+1th data block, the score of the i-th data block is 1; if the i-th data block is consistent with the i-th data block If the writable status of -1 data block is inconsistent and inconsistent with the writable status of the i+1th data block, then the score of the i-th data block is 2.

Figure BDA0003823230820000082
表示一个片段中所有数据块的得分的总和,可以用于表示片段内部的碎片化得分。在数据写入片段的过程中,当一个片段中可写的数据块越少,会在越短的时间内为待写入数据分配下一个片段,进而导致逻辑上连续的数据存储于不同的片段,导致存储空间的IO性能下降,因此,X表示片段中不可写的数据块的数量,也可以用于表示跨片段的碎片化得分,即片段外部的碎片化得分。通过对片段内部的碎片化得分和片段外部的碎片化进行加权求和得到片段的碎片化得分,可以更好的评价存储空间的碎片化程度。
Figure BDA0003823230820000082
Represents the sum of the scores of all data blocks in a fragment, which can be used to represent the fragmentation score within the fragment. In the process of writing data to a segment, when there are fewer writable data blocks in a segment, the next segment will be allocated for the data to be written in a shorter time, resulting in logically continuous data stored in different segments , leading to a decrease in the IO performance of the storage space. Therefore, X represents the number of unwritable data blocks in the segment, and can also be used to represent the fragmentation score across segments, that is, the fragmentation score outside the segment. By weighting and summing the fragmentation score inside the fragment and the fragmentation outside the fragment to obtain the fragmentation score of the fragment, the degree of fragmentation of the storage space can be better evaluated.

在确定每个片段的碎片化得分后,可以根据每个片段的碎片化得分以及存储空间中的所有片段的数量进一步确定存储空间的碎片化率。具体地,存储空间的碎片化率的计算公式为:After the fragmentation score of each fragment is determined, the fragmentation rate of the storage space can be further determined according to the fragmentation score of each fragment and the number of all fragments in the storage space. Specifically, the formula for calculating the fragmentation rate of storage space is:

Figure BDA0003823230820000091
Figure BDA0003823230820000091

其中,score_all表示存储空间中所有片段的碎片化得分的和,all_segment表示存储空间中片段的总数量,N是一个片段可以达到的碎片化得分的最大值,例如weigh为2时,N为1534。Among them, score_all represents the sum of the fragmentation scores of all fragments in the storage space, all_segment represents the total number of fragments in the storage space, and N is the maximum fragmentation score that a fragment can achieve. For example, when the weight is 2, N is 1534.

可以理解,也可以采用其他可以表征可写空间不连续程度的计算方法确定片段的碎片化率或者存储空间的碎片化率。It can be understood that other calculation methods that can characterize the degree of discontinuity of the writable space can also be used to determine the fragmentation rate of the fragment or the fragmentation rate of the storage space.

在确定整理模式后,内核层确定存储空间中待进行GC整理的各片段,对待进行GC整理的各片段进行GC整理,直到满足GC整理结束条件。After determining the sorting mode, the kernel layer determines the fragments to be sorted by GC in the storage space, and performs GC sorting on each segment to be sorted by GC until the end condition of GC is satisfied.

其中,待进行GC整理的片段可以是存储空间中所有可写空间不连续的片段,也可以是碎片化率大于设定阈值的片段。Wherein, the fragments to be sorted by GC may be fragments with discontinuous writable space in the storage space, or fragments with a fragmentation rate greater than a set threshold.

GC整理结束条件为存储空间的碎片化率达到第一设定值、存储空间中可写空间的大小达到第二设定值、整理时长达到设定时长、整理数量达到设定数量中的任意一项或多项。The GC finishing condition is that the fragmentation rate of the storage space reaches the first set value, the size of the writable space in the storage space reaches the second set value, the finishing time reaches the set duration, and the number of finishing reaches any one of the set numbers. item or items.

在一实施例中,在内核层检测到存在IO指令下发到存储空间的情况下,内核层中断GC整理。在另一实施例中,在电子设备处于预设状态或者电子设备处于预设状态且当前处于预设时段时,应用程序框架层生成不满足对存储空间进行GC整理的条件的信息,该信息经过系统库发送至内核层,内核层根据该信息中断GC整理。In one embodiment, when the kernel layer detects that there is an IO instruction issued to the storage space, the kernel layer interrupts the GC sorting. In another embodiment, when the electronic device is in a preset state or the electronic device is in a preset state and is currently in a preset period of time, the application framework layer generates information that does not meet the conditions for GC sorting the storage space, and the information passes through The system library is sent to the kernel layer, and the kernel layer interrupts GC sorting according to the information.

在GC整理中断或停止后,若再次检测到满足对存储空间进行GC整理的条件,则再次确定GC整理的模式对存储空间进行GC整理。After the GC sorting is interrupted or stopped, if it is detected again that the condition for GC sorting the storage space is met, the GC sorting mode is determined again to perform GC sorting on the storage space.

可以理解,在满足对存储空间进行GC整理的条件的情况下,GC整理的过程包括但不限于以下几种场景:It can be understood that when the conditions for GC finishing the storage space are met, the GC finishing process includes but is not limited to the following scenarios:

1.当前存储空间的碎片化率大于第一预设值,存储空间中可写空间的大小小于第二预设值,则采用第二整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第二整理模式进行GC整理一段时间后,若检测到存储空间的碎片化率小于第三预设值,存储空间中可写空间的大小大于第四预设值,即检测到存储空间变大,碎片化率降低,则采用第一整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第一整理模式整理一段时间后,若确定满足GC整理结束条件,结束GC整理。其中,在采用第一整理模式进行GC整理和采用第二整理模式进行GC整理的过程中,GC整理的过程可以被中断。1. If the fragmentation rate of the current storage space is greater than the first preset value, and the size of the writable space in the storage space is smaller than the second preset value, the second sorting mode will be used to treat GC in the order of fragmentation rate from large to small The sorted fragments are sorted by GC. After using the second sorting mode for GC sorting for a period of time, if it is detected that the fragmentation rate of the storage space is less than the third preset value, and the size of the writable space in the storage space is greater than the fourth preset value, it is detected that the storage space has changed If the fragmentation rate is large and the fragmentation rate decreases, the first sorting mode is used to perform GC sorting on the fragments to be sorted by GC in order of fragmentation rate from large to small. After adopting the first sorting mode for a period of time, if it is determined that the GC sorting end condition is satisfied, the GC sorting ends. Wherein, during the process of performing GC sorting in the first sorting mode and in the process of performing GC sorting in the second sorting mode, the process of GC sorting may be interrupted.

2.当前存储空间的碎片化率小于第三预设值,存储空间中可写空间的大小大于第四预设值,则采用第一整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第一整理模式整理一段时间后,若确定满足GC整理结束条件,结束GC整理。2. If the fragmentation rate of the current storage space is less than the third preset value, and the size of the writable space in the storage space is greater than the fourth preset value, the first sorting mode will be used for GC in order of fragmentation rate from large to small The sorted fragments are sorted by GC. After adopting the first sorting mode for a period of time, if it is determined that the GC sorting end condition is satisfied, the GC sorting ends.

3.当前存储空间的碎片化率小于第三预设值,存储空间中可写空间的大小大于第四预设值,则采用第一整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第一整理模式整理一段时间后,GC整理被中断。在再次满足对存储空间进行GC整理的条件下,检测到存储空间的碎片化率大于第一预设值,存储空间中可写空间的大小小于第二预设值,则采用第二整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第二整理模式进行GC整理一段时间后,若检测到存储空间的碎片化率小于第三预设值,存储空间中可写空间的大小大于第四预设值,则采用第一整理模式按照碎片化率从大到小的顺序对待进行GC整理的各片段进行GC整理。在采用第一整理模式整理一段时间后,若确定满足GC整理结束条件,结束GC整理。3. If the fragmentation rate of the current storage space is less than the third preset value, and the size of the writable space in the storage space is greater than the fourth preset value, the first sorting mode will be used for GC in order of fragmentation rate from large to small The sorted fragments are sorted by GC. After using the first sorting mode for a period of time, GC sorting is interrupted. Under the condition of GC sorting the storage space again, it is detected that the fragmentation rate of the storage space is greater than the first preset value, and the size of the writable space in the storage space is smaller than the second preset value, then the second sorting mode is adopted according to GC sorts the fragments to be GC sorted in descending order of fragmentation rate. After using the second sorting mode for GC sorting for a period of time, if it is detected that the fragmentation rate of the storage space is less than the third preset value and the size of the writable space in the storage space is greater than the fourth preset value, then the first sorting mode is adopted Perform GC sorting for each fragment to be sorted by GC in order of fragmentation rate from large to small. After adopting the first sorting mode for a period of time, if it is determined that the GC sorting end condition is satisfied, the GC sorting ends.

在一实施例中,在第一整理模式下,按照第一检测频率检测存储空间的碎片化率以及存储空间中可写空间的大小,在第二整理模式下,按照第二检测频率检测存储空间的碎片化率以及存储空间中可写空间的大小,第二检测频率大于第一检测频率。即第二整理模式下的GC整理的频率大于第一整理模式下的GC整理频率,同时第二整理模式下的检测频率大于第一整理模式下的检测频率。按照第一检测频率或第二检测频率检测存储空间的碎片化率以及存储空间中可写空间的大小,用于确定GC整理的模式以及GC整理的顺序,其中,GC整理的顺序在后文进行详细说明。在第二整理模式下,存储空间的碎片化率较高,存储空间中可写空间的大小较小,采用更快的检测频率,可以在检测到不满足第二整理模式的情况下快速切换到第一整理模式,避免长期采用第二整理模式进行GC整理所造成的降低电子设备的响应速度的情况,也可以在碎片化率较高的情况下及时调整GC整理的顺序,提高存储空间中可写空间的连续程度。In one embodiment, in the first sorting mode, the fragmentation rate of the storage space and the size of the writable space in the storage space are detected according to the first detection frequency, and in the second sorting mode, the storage space is detected according to the second detection frequency The fragmentation rate of the storage space and the size of the writable space in the storage space, the second detection frequency is greater than the first detection frequency. That is, the frequency of GC sorting in the second sorting mode is greater than that in the first sorting mode, and the detection frequency in the second sorting mode is higher than that in the first sorting mode. Detect the fragmentation rate of the storage space and the size of the writable space in the storage space according to the first detection frequency or the second detection frequency, to determine the GC sorting mode and the order of the GC sorting, where the order of the GC sorting is performed later Detailed description. In the second sorting mode, the fragmentation rate of the storage space is high, the size of the writable space in the storage space is small, and a faster detection frequency is adopted, which can quickly switch to The first sorting mode can avoid the situation of reducing the response speed of electronic equipment caused by long-term use of the second sorting mode for GC sorting. It can also adjust the order of GC sorting in time when the fragmentation rate is high, and improve the storage space. The degree of continuity of the write space.

上述实施例中,在存储空间的碎片化率较高、存储空间中可写空间较小的情况下,采用较快的GC整理频率进行GC整理,从而可以快速降低存储空间的碎片化程度,使得写入片段的数据尽可能连续,提高电子设备的性能。在存储空间的碎片化率较低、存储空间中可写空间较小的情况下,采用较慢的GC整理频率进行GC整理,可以避免GC整理的过程占用电子设备的资源,进而避免GC整理的过程影响电子设备的运行速度,提高用户体验。同时,待写入数据是否可以连续存储于存储空间与存储空间的碎片化率的关联程度更高,通过存储空间的碎片化率来确定GC整理的频率,可以使得GC整理的时机与存储空间的存储状态相适配,以确保GC整理的及时性,避免在剩余存储空间较大,但是可写空间连续性较差的情况下写入数据,提高电子设备的性能。In the above embodiment, when the fragmentation rate of the storage space is high and the writable space in the storage space is small, a faster GC sorting frequency is used for GC sorting, so that the degree of fragmentation of the storage space can be quickly reduced, so that The data written to the segment is as contiguous as possible, improving the performance of the electronic device. When the fragmentation rate of the storage space is low and the writable space in the storage space is small, using a slower GC sorting frequency for GC sorting can prevent the GC sorting process from occupying the resources of electronic devices, thereby avoiding the waste of GC sorting The process affects the operating speed of electronic devices and improves user experience. At the same time, whether the data to be written can be continuously stored in the storage space has a higher degree of correlation with the fragmentation rate of the storage space. The frequency of GC sorting can be determined by the fragmentation rate of the storage space, which can make the timing of GC sorting and the storage space The storage status is adapted to ensure the timeliness of GC sorting, avoid writing data when the remaining storage space is large but the continuity of the writable space is poor, and improve the performance of electronic devices.

在一实施例中,内核层在对待进行GC整理的各片段进行GC整理时,按照设定顺序对待进行GC整理的各片段进行GC整理。In one embodiment, when the kernel layer performs GC sorting on the segments to be sorted by GC, it performs GC sorting on the segments to be sorted by GC according to a set order.

本申请一实施例提供的存储空间管理方法包括:The storage space management method provided by an embodiment of the present application includes:

S501:在满足对存储空间进行GC整理的条件下,确定所述存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,所述碎片化率用于表示所述片段中可写空间的不连续程度。S501: Under the condition that the GC sorting of the storage space is satisfied, determine the size relationship between the fragmentation rates of the segments to be GC sorted in the storage space, the fragmentation rate is used to indicate that the fragments can The degree of discontinuity of the write space.

具体地,根据上述片段的碎片化得分的计算公式确定的待进行GC整理的各片段的碎片化得分,即为各片段的碎片化率。待进行GC整理的片段可以是存储空间中所有可写空间不连续的片段,也可以是碎片化率大于设定阈值的片段。在确定各片段的碎片化率后,按照碎片化率从大到小的顺序对待进行GC整理的各片段进行排序。Specifically, the fragmentation score of each fragment to be sorted by GC determined according to the above calculation formula of the fragmentation score is the fragmentation rate of each fragment. The fragments to be sorted by GC may be fragments with discontinuous writable space in the storage space, or fragments with a fragmentation rate greater than a set threshold. After the fragmentation rate of each segment is determined, the segments to be sorted by GC are sorted in descending order of fragmentation rate.

S502:按照所述碎片化率从大到小的顺序,依次对所述待进行GC整理的各片段进行GC整理。S502: Perform GC sorting on the fragments to be sorted by GC sequentially in descending order of the fragmentation ratio.

具体地,在内核层确定待进行GC整理的各片段的碎片化率的大小关系后,开始进行GC整理。若GC整理的过程未被中断,则一直按照碎片化率从大到小的顺序进行GC整理,即每次在对上一个片段结束GC整理后,先整理碎片化率最高的片段,直到GC整理被中断或者GC整理结束。若GC整理被中断或GC整理结束,则更新待进行GC整理的各片段的碎片化率。在下一次进行GC整理时,根据更新后的碎片化率,重新按照碎片化率从大到小的顺序,依次对所述待进行GC整理的各片段进行GC整理。Specifically, after the kernel layer determines the magnitude relationship of the fragmentation rates of the fragments to be sorted by GC, the sorting by GC is started. If the GC sorting process is not interrupted, the GC sorting will always be performed in descending order of the fragmentation rate, that is, after finishing the GC sorting of the previous segment, the segment with the highest fragmentation rate will be sorted out first, until the GC sorting Interrupted or GC finishing. If the GC sorting is interrupted or the GC sorting ends, the fragmentation rate of each segment to be GC sorted is updated. When GC sorting is performed next time, according to the updated fragmentation rate, the fragments to be sorted by GC are sequentially GC sorted in order of fragmentation rate from large to small.

在一实施例中,先确定GC整理的整理模式,若整理模式是第一整理模式,则按照第一整理模式对应的GC整理频率对待进行GC整理的片段进行GC整理,且在整理过程中,按照碎片化率从大到小的顺序进行GC整理。若整理模式是第二整理模式,则按照第二整理模式对应的整理频率对待进行GC整理的片段进行GC整理,且在整理过程中,按照碎片化率从大到小的顺序进行GC整理。In one embodiment, first determine the sorting mode of GC sorting, if the sorting mode is the first sorting mode, then perform GC sorting on the fragments to be sorted by GC according to the GC sorting frequency corresponding to the first sorting mode, and during the sorting process, GC sorting is performed in descending order of fragmentation rate. If the sorting mode is the second sorting mode, GC sorting is performed on the fragments to be GC sorted according to the sorting frequency corresponding to the second sorting mode, and during the sorting process, GC sorting is performed in descending order of fragmentation rate.

上述实施例中,在满足对存储空间进行GC整理的条件下,确定存储空间中待进行GC整理的各片段的碎片化率之间的大小关系,碎片化率用于表示片段中可写空间的不连续程度;按照碎片化率从大到小的顺序,依次对待进行GC整理的各片段进行GC整理。由于碎片化率最大的片段中可写空间的不连续程度最高,通过先整理碎片化率最大的片段,可以快速降低存储空间整体的碎片化率,即使GC整理被中断,也可以最大程度提高存储空间中可写空间的连续程度。相对于在GC整理时先整理可写空间小的片段或随机整理任意片段,通过先整理碎片化率最大的片段,可用更好地提高电子设备的性能。In the above embodiment, under the condition that the storage space is GC sorted, the size relationship between the fragmentation rates of the segments to be GC sorted in the storage space is determined, and the fragmentation rate is used to represent the writable space in the segment. Degree of discontinuity: According to the order of fragmentation rate from large to small, GC sorts the fragments to be sorted by GC in turn. Since the discontinuity of the writable space is the highest in the segment with the highest fragmentation rate, the overall fragmentation rate of the storage space can be quickly reduced by sorting out the segment with the highest fragmentation rate first, and the storage space can be maximized even if the GC is interrupted. The degree of contiguousness of writable space in the space. Compared with sorting out fragments with small writable space first or randomly sorting arbitrary fragments during GC sorting, by sorting out the fragments with the largest fragmentation rate first, the performance of electronic devices can be better improved.

在一实施例中,在GC整理被中断或者GC整理结束时,若内核层检测到存在待写入数据,且存储空间中不存在未写入数据的片段,则根据存储空间中各片段的碎片化率,按照碎片化率从小到大的顺序,将待写入数据依次写入对应的片段,即将数据优先写入可写空间的连续程度最高的片段。现有技术中一般是将待写入数据优先写入可写空间多的片段,或者需要结合片段中的可写空间以及已经写入数据的写入时间确定优先写入的片段。但是可写空间多的片段中的可写空间的连续程度不一定高,不能保证待写入数据在存储空间上尽可能连续。确定可写空间以及已经写入数据的写入时间需要占用较高的计算资源。而将数据优先写入可写空间的连续程度最高的片段,可用使得待写入数据在存储空间内尽可能连续,以提高数据的写入速度和后续数据的读取速度,且根据碎片化率确定优先写入的片段的计算过程简单,占用的计算资源较少,从而可以提高电子设备的性能。In one embodiment, when GC sorting is interrupted or GC sorting ends, if the kernel layer detects that there is data to be written, and there is no segment with unwritten data in the storage space, then according to the fragmentation of each segment in the storage space Fragmentation rate, according to the order of fragmentation rate from small to large, the data to be written is written to the corresponding segment in turn, that is, the data is first written to the segment with the highest continuous degree in the writable space. In the prior art, the data to be written is generally written in priority to the segment with more writable space, or the segment to be written in priority needs to be determined in combination with the writable space in the segment and the writing time of the data already written. However, the continuity of the writable space in the segment with a large amount of writable space is not necessarily high, and it cannot be guaranteed that the data to be written is as continuous as possible in the storage space. Determining the writable space and the writing time of the written data requires relatively high computing resources. The data is first written to the segment with the highest degree of continuity in the writable space, which can make the data to be written as continuous as possible in the storage space, so as to improve the writing speed of data and the reading speed of subsequent data, and according to the fragmentation rate The calculation process for determining the segment to be written in priority is simple, and less calculation resources are occupied, so that the performance of the electronic device can be improved.

在一实施例中,若内核层检测到存在待读取数据,且待读取数据存储于多个片段,则按照碎片化率从小到大的顺序,依次读取对应的片段,从而可以优先读取存储连续程度更高的数据,即可以先快速读取一部分数据,以提高电子设备的响应速度。In one embodiment, if the kernel layer detects that there is data to be read, and the data to be read is stored in multiple fragments, the corresponding fragments are read sequentially according to the order of fragmentation rate from small to large, so that the data can be read preferentially. To fetch and store data with a higher degree of continuity, that is, a part of the data can be quickly read first to improve the response speed of electronic equipment.

如图6所示,内核层包括文件系统层、block层和存储驱动,本申请实施例提供的存储空间管理方法执行于内核层的文件系统层。具体地,文件系统层中的文件系统(例如F2FS文件系统)用于接收用户读取数据或者写入数据的请求,根据读取数据或者写入数据的请求确定需要读取或者写入的数据在存储空间中的地址信息,将地址信息发送至block层。block层用于对需要读取的数据对应的地址信息或者需要写入的数据对应的地址信息进行处理,得到存储驱动可以处理的任务单元,将任务单元发送至存储驱动。存储驱动在接收的任务单元后,根据设定的顺序在对应地址的存储空间读取或写入数据,例如,将数据写入通用闪存存储(Universal Flash Storage,UFS)、小型计算机系统接口(Small ComputerSystem Interface,scsi)硬盘中。在数据读取或写入成功后,存储驱动将读取或写入成功的信息通过block层发送至文件系统。文件系统层调用GC整理决策模块,GC整理决策模块根据读取数据或者写入数据的请求以及数据读取或写入成功的信息确定存储空间的存储情况,根据存储情况进一步确定存储空间的碎片化率以及存储空间中可写空间的大小,进而根据存储空间的碎片化率以及存储空间中可写空间的大小确定GC整理策略。GC整理策略包括GC整理模式、GC整理顺序、数据读取顺序、数据写入顺序等。之后,根据GC整理策略在存储空间进行GC整理以及数据读写,可以使得待写入和待读取的数据在存储空间上尽可能连续,提高电子设备的性能,进而提高用户体验。As shown in FIG. 6 , the kernel layer includes a file system layer, a block layer, and a storage driver, and the storage space management method provided by the embodiment of the present application is executed on the file system layer of the kernel layer. Specifically, the file system (such as the F2FS file system) in the file system layer is used to receive the user's request for reading data or writing data, and according to the request for reading data or writing data, it is determined that the data that needs to be read or written is in the Address information in the storage space, and send the address information to the block layer. The block layer is used to process the address information corresponding to the data to be read or the address information corresponding to the data to be written to obtain task units that can be processed by the storage driver, and send the task units to the storage driver. After the storage driver receives the task unit, it reads or writes data in the storage space of the corresponding address according to the set order, for example, writes the data into Universal Flash Storage (UFS), Small Computer System Interface (Small ComputerSystem Interface, scsi) hard disk. After the data is read or written successfully, the storage driver sends the read or write successful information to the file system through the block layer. The file system layer calls the GC sorting decision module, and the GC sorting decision module determines the storage status of the storage space according to the request for reading or writing data and the information of successful data reading or writing, and further determines the fragmentation of the storage space according to the storage status rate and the size of the writable space in the storage space, and then determine the GC finishing strategy according to the fragmentation rate of the storage space and the size of the writable space in the storage space. GC collation strategies include GC collation mode, GC collation order, data read order, data write order, etc. After that, GC sorting and data reading and writing are performed in the storage space according to the GC sorting strategy, which can make the data to be written and read as continuous as possible in the storage space, improve the performance of electronic devices, and further improve user experience.

在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。In the above-mentioned embodiments, the descriptions of each embodiment have their own emphases, and for parts that are not detailed or recorded in a certain embodiment, refer to the relevant descriptions of other embodiments.

应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the sequence numbers of the steps in the above embodiments do not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiment of the present application.

图7示出了电子设备100的结构示意图。FIG. 7 shows a schematic structural diagram of the electronic device 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,以及用户标识模块(subscriber identification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L,骨传导传感器180M等。The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, and an antenna 2 , mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, and A subscriber identification module (subscriber identification module, SIM) card interface 195 and the like. The sensor module 180 may include a pressure sensor 180A, a gyroscope 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, an ambient light sensor 180L, bone conduction sensor 180M, etc.

可以理解的是,本发明实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。It can be understood that, the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 100 . In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine certain components, or separate certain components, or arrange different components. The illustrated components can be realized in hardware, software or a combination of software and hardware.

处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processingunit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (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. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.

控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。The controller can generate an operation control signal according to the instruction opcode and timing signal, and complete the control of fetching and executing the instruction.

处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be called directly from the memory. Repeated access is avoided, and the waiting time of the processor 110 is reduced, thereby improving the efficiency of the system.

在一些实施例中,处理器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)接口等。In some embodiments, processor 110 may include one or more interfaces. The interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuitsound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver) /transmitter, UART) interface, mobile industry processor interface (mobile industry processor interface, MIPI), general-purpose input and output (general-purpose input/output, GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, and/or Universal serial bus (universal serial bus, USB) interface, etc.

可以理解的是,本发明实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备100的结构限定。在本申请另一些实施例中,电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。It can be understood that the interface connection relationship between the modules shown in the embodiment of the present invention is only a schematic illustration, and does not constitute a structural limitation of the electronic device 100 . In other embodiments of the present application, the electronic device 100 may also adopt different interface connection manners in the foregoing embodiments, or a combination of multiple interface connection manners.

电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,显示屏194,摄像头193,和无线通信模块160等供电。电源管理模块141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。在其他一些实施例中,电源管理模块141也可以设置于处理器110中。在另一些实施例中,电源管理模块141和充电管理模块140也可以设置于同一个器件中。The power management module 141 is used for connecting the battery 142 , the charging management module 140 and the processor 110 . The power management module 141 receives the input from the battery 142 and/or the charging management module 140 to provide power for the processor 110 , the internal memory 121 , the display screen 194 , the camera 193 , and the wireless communication module 160 . The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle times, and battery health status (leakage, impedance). In some other embodiments, the power management module 141 may also be disposed in the processor 110 . In some other embodiments, the power management module 141 and the charging management module 140 may also be set in the same device.

外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, so as to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. Such as saving music, video and other files in the external memory card.

内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储电子设备100使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行电子设备100的各种功能应用以及数据处理。The internal memory 121 may be used to store computer-executable program codes including instructions. The internal memory 121 may include an area for storing programs and an area for storing data. Wherein, the stored program area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.) and the like. The storage data area can store data created during the use of the electronic device 100 (such as audio data, phonebook, etc.) and the like. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like. The processor 110 executes various functional applications and data processing of the electronic device 100 by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.

需要说明的是,上述装置/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参见方法实施例部分,此处不再赘述。It should be noted that the information interaction and execution process between the above-mentioned devices/units are based on the same concept as the method embodiment of the present application, and its specific functions and technical effects can be found in the method embodiment section. I won't repeat them here.

所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used for illustration. In practical applications, the above-mentioned functions can be assigned to different functional units, Completion of modules means that the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment may be integrated into one processing unit, or each unit may exist separately physically, or two or more units may be integrated into one unit, and the above-mentioned integrated units may adopt hardware It can also be implemented in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the present application. For the specific working processes of the units and modules in the above system, reference may be made to the corresponding processes in the aforementioned method embodiments, and details will not be repeated here.

所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质至少可以包括:能够将计算机程序代码携带到拍照装置/电子设备的任何实体或装置、记录介质、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,RandomAccess Memory)、电载波信号、电信信号以及软件分发介质。例如U盘、移动硬盘、磁碟或者光盘等。If the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the procedures in the method of the above-mentioned embodiments in the present application can be completed by instructing related hardware through a computer program. The computer program can be stored in a computer-readable storage medium. The computer program When executed by a processor, the steps in the above-mentioned various method embodiments can be realized. Wherein, the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device capable of carrying computer program codes to the photographing device/electronic device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium. Such as U disk, mobile hard disk, magnetic disk or optical disk, etc.

所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

在本申请所提供的实施例中,应该理解到,所揭露的装置/网络设备和方法,可以通过其它的方式实现。例如,以上所描述的装置/网络设备实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,装置或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。In the embodiments provided in this application, it should be understood that the disclosed device/network device and method may be implemented in other ways. For example, the device/network device embodiments described above are only illustrative. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units Or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.

本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those skilled in the art can appreciate that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed by hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the present application.

最后应说明的是:以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。Finally, it should be noted that: the above is only a specific implementation of the application, but the scope of protection of the application is not limited thereto, and any changes or replacements within the technical scope disclosed in the application shall be covered by this application. within the scope of the application. Therefore, the protection scope of the present application should be determined by the protection scope of the claims.

Claims (10)

1. A storage space management method, comprising:
determining the size relation between fragmentation rates of all fragments to be subjected to GC finishing in a storage space under the condition that the GC finishing is satisfied, wherein the fragmentation rates are used for representing the discontinuity degree of writable space in the fragments;
and sequentially carrying out GC finishing on the fragments to be subjected to GC finishing according to the sequence of the fragmentation rate from large to small.
2. The method according to claim 1, wherein the GC-sorting of the fragments to be GC-sorted sequentially in the order of the fragmentation rate from the higher to the lower, comprises:
determining a sorting mode of GC sorting according to the fragmentation rate of the storage space and the size of the writable space in the storage space, wherein the fragmentation rate of the storage space is determined by the number of all fragments in the storage space and the fragmentation rate of each fragment, and the sorting mode is used for determining the frequency of GC sorting;
And according to the sorting mode, sequentially sorting the fragments to be subjected to GC sorting according to the sequence from the large fragmentation rate to the small fragmentation rate.
3. The method of claim 2, wherein the size of the writable space in the storage space is determined by a number of segments of unwritten data or a number of data blocks of unwritten data in the storage space, the segments comprising a preset number of data blocks.
4. A method according to claim 2 or 3, wherein said determining a sort pattern of GC sort according to a fragmentation rate of the storage space and a size of writable space in the storage space comprises:
if the fragmentation rate of the storage space is larger than a first preset value, and the size of the writable space in the storage space is smaller than a second preset value, determining that the sorting mode is switched from a first sorting mode to a second sorting mode, and the GC sorting frequency of the second sorting mode is larger than the GC sorting frequency of the first sorting mode.
5. The method of claim 4, wherein determining the sorting pattern of GC sorting according to the fragmentation rate of the memory space and the size of writable space in the memory space comprises:
If the fragmentation rate of the storage space is smaller than a third preset value, and the size of the writable space in the storage space is larger than a fourth preset value, determining that the sorting mode is switched from the second sorting mode to the first sorting mode, wherein the third preset value is smaller than or equal to the first preset value, and the fourth preset value is larger than or equal to the second preset value.
6. The method according to claim 4 or 5, wherein in the first sort mode the fragmentation rate of the storage space and the size of the writable space in the storage space are detected at a first detection frequency, and in the second sort mode the fragmentation rate of the storage space and the size of the writable space in the storage space are detected at a second detection frequency, the second detection frequency being larger than the first detection frequency.
7. The method according to any one of claims 1 to 6, wherein the meeting a condition for GC-sorting of a storage space includes a kernel layer of an electronic device not detecting an IO instruction issued to the storage space.
8. The method according to any one of claims 1 to 7, further comprising:
And if the existence of the data to be written is detected under the condition that the fragments of the unwritten data do not exist in the storage space, the data to be written are sequentially written into the corresponding fragments according to the fragmentation rate of each fragment in the storage space and the sequence from the small fragmentation rate to the large fragmentation rate.
9. An electronic device comprising a processor for executing a computer program stored in a memory to implement the method of any one of claims 1-8.
10. A computer readable storage medium storing a computer program, which when executed by a processor implements the method according to any one of claims 1-8.
CN202211067942.2A 2022-08-29 2022-08-29 Storage space management method, electronic device, and computer-readable storage medium Active CN116049021B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211067942.2A CN116049021B (en) 2022-08-29 2022-08-29 Storage space management method, electronic device, and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211067942.2A CN116049021B (en) 2022-08-29 2022-08-29 Storage space management method, electronic device, and computer-readable storage medium

Publications (2)

Publication Number Publication Date
CN116049021A true CN116049021A (en) 2023-05-02
CN116049021B CN116049021B (en) 2023-10-20

Family

ID=86112228

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211067942.2A Active CN116049021B (en) 2022-08-29 2022-08-29 Storage space management method, electronic device, and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN116049021B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020133683A1 (en) * 2000-12-22 2002-09-19 Robert Jochemsen Method and system for reducing fragmentation
CN103778064A (en) * 2012-10-23 2014-05-07 阿里巴巴集团控股有限公司 Data management method and device
CN105589812A (en) * 2015-12-16 2016-05-18 成都华为技术有限公司 Disk defragmentation method, disk defragmentation device and host
CN108536609A (en) * 2017-03-02 2018-09-14 迈普通信技术股份有限公司 Memory fragmentation manages system and method
CN110928852A (en) * 2019-12-09 2020-03-27 Oppo广东移动通信有限公司 A garbage collection method, device and computer-readable storage medium
CN110945486A (en) * 2018-06-30 2020-03-31 华为技术有限公司 A storage fragment management method and terminal
CN112131140A (en) * 2020-09-24 2020-12-25 北京计算机技术及应用研究所 A key-value separation storage method supporting efficient storage space management based on SSD
WO2022001215A1 (en) * 2020-06-30 2022-01-06 华为技术有限公司 Data writing method and device
CN113961517A (en) * 2020-07-21 2022-01-21 中兴通讯股份有限公司 File system management method, electronic device and storage medium
CN114691535A (en) * 2020-12-28 2022-07-01 三星电子株式会社 Memory device, method of operating the same, and method of operating memory controller

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020133683A1 (en) * 2000-12-22 2002-09-19 Robert Jochemsen Method and system for reducing fragmentation
CN1529843A (en) * 2000-12-22 2004-09-15 �ʼҷ����ֵ������޹�˾ Method and system for reducing fragmentation
CN103778064A (en) * 2012-10-23 2014-05-07 阿里巴巴集团控股有限公司 Data management method and device
CN105589812A (en) * 2015-12-16 2016-05-18 成都华为技术有限公司 Disk defragmentation method, disk defragmentation device and host
CN108536609A (en) * 2017-03-02 2018-09-14 迈普通信技术股份有限公司 Memory fragmentation manages system and method
CN110945486A (en) * 2018-06-30 2020-03-31 华为技术有限公司 A storage fragment management method and terminal
CN110928852A (en) * 2019-12-09 2020-03-27 Oppo广东移动通信有限公司 A garbage collection method, device and computer-readable storage medium
WO2022001215A1 (en) * 2020-06-30 2022-01-06 华为技术有限公司 Data writing method and device
CN113961517A (en) * 2020-07-21 2022-01-21 中兴通讯股份有限公司 File system management method, electronic device and storage medium
CN112131140A (en) * 2020-09-24 2020-12-25 北京计算机技术及应用研究所 A key-value separation storage method supporting efficient storage space management based on SSD
CN114691535A (en) * 2020-12-28 2022-07-01 三星电子株式会社 Memory device, method of operating the same, and method of operating memory controller

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
YONGSEOK OH等: "Optimizations of LFS with slack space recycling and lazy indirect block update", 《ACM》, pages 1 - 9 *
钱佳兴: "闪存存储系统的碎片管理优化研究", 中国优秀硕士论文电子期刊网 信息科技辑》, no. 5, pages 137 - 100 *

Also Published As

Publication number Publication date
CN116049021B (en) 2023-10-20

Similar Documents

Publication Publication Date Title
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
CN111274039B (en) Memory recycling method and device, storage medium and electronic equipment
CN114185494B (en) Memory anonymous page processing method, electronic device and readable storage medium
CN114840450B (en) Method for organizing storage space and electronic device
CN118276722A (en) Window display method and electronic device
CN117707639B (en) Application start acceleration method, electronic device and storage medium
CN116541180B (en) Memory allocation method, electronic equipment and storage medium
CN111475299A (en) Memory allocation method, device, storage medium and electronic device
CN116737350A (en) A method and device for managing objects
CN116049021B (en) Storage space management method, electronic device, and computer-readable storage medium
TW200820266A (en) Method for reading and writing data in a flash memory in an embedded system
CN116049113B (en) File system organization method, electronic device and computer-readable storage medium
WO2024087724A1 (en) Garbage collection method, page storage method, and electronic device
CN113032290B (en) Flash memory configuration method, flash memory configuration device, electronic equipment and storage medium
CN117707716A (en) Thread scheduling method, electronic device and computer-readable storage medium
CN116701298A (en) File system management method and electronic device
CN116257346A (en) A method and device for inputting and outputting IO requests
CN116225632A (en) Thread scheduling method, device and related device
CN116662222B (en) Cache management method and related equipment
CN115934302A (en) Memory leak processing method and electronic equipment
CN118626218A (en) Resource scheduling method and electronic equipment
CN116719752A (en) Memory allocation method, electronic equipment and storage medium
CN119576583B (en) Memory management method, electronic device and computer readable storage medium
CN114741205B (en) Anonymous page recycling method and electronic device
CN117130767B (en) Method for recycling memory, electronic device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: Unit 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong 518040

Patentee after: Honor Terminal Co.,Ltd.

Country or region after: China

Address before: 3401, unit a, building 6, Shenye Zhongcheng, No. 8089, Hongli West Road, Donghai community, Xiangmihu street, Futian District, Shenzhen, Guangdong

Patentee before: Honor Device Co.,Ltd.

Country or region before: China

CP03 Change of name, title or address