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; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • 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

Abstract

The application provides a storage space management method, electronic equipment and a computer readable storage medium. The storage space management method comprises the following steps: determining the size relation between the fragmentation rates of all fragments to be subjected to GC finishing in the storage space under the condition that the GC finishing is carried out on the storage space is met, wherein the fragmentation rates are used for representing the discontinuity degree of writable space in the fragments; and sequentially carrying out GC finishing on each fragment to be subjected to GC finishing according to the sequence of the fragmentation rate from large to small. By firstly sorting the fragments with the largest fragmentation rate, the fragmentation rate of the whole storage space can be reduced rapidly, and even if GC sorting is interrupted, the continuity degree of the writable space in the storage space can be improved to the greatest extent, so that the performance of the electronic equipment is improved.

Description

Storage space management method, electronic device, and computer-readable storage medium
Technical Field
The present disclosure relates to the field of storage space management technologies, and in particular, to a storage space management method, an electronic device, and a computer readable storage medium.
Background
After the electronic equipment is used for a period of time, the electronic equipment can carry out garbage collection (Garbage Collection, GC) arrangement on the storage space so as to reduce the discontinuity degree of the writable space in the storage space, enable the data newly written into the storage space to be continuous as much as possible, improve the speed of writing data and reading data of the electronic equipment, and further improve the performance of the electronic equipment.
However, the electronic device occupies the resources of the electronic device when performing GC arrangement on the storage space, so the GC arrangement is generally performed when the electronic device is idle, but when the electronic device is switched from the idle state to the non-idle state, the GC arrangement process is easily interrupted. After GC finishing is interrupted, if the electronic equipment fails to timely perform GC finishing again, the discontinuous degree of the writable space can be increased rapidly, and the performance of the electronic equipment is further affected.
Disclosure of Invention
The application provides a storage space management method, electronic equipment and a computer readable storage medium, which are used for solving the problem that the discontinuity degree of a storage space cannot be effectively reduced through GC arrangement in the prior art.
In order to achieve the above purpose, the present application adopts the following technical scheme:
in a first aspect, a storage space management method is provided, including: determining the size relation between the fragmentation rates of all fragments to be subjected to GC finishing in the storage space under the condition that the GC finishing is carried out on the storage space is met, wherein the fragmentation rates are used for representing the discontinuity degree of writable space in the fragments; and sequentially carrying out GC finishing on each fragment to be subjected to GC finishing according to the sequence of the fragmentation rate from large to small. The maximum fragment rate can be used for rapidly reducing the overall fragment rate of the storage space by firstly arranging the fragment with the maximum fragment rate, and even if GC arrangement is interrupted, the continuous degree of the writable space in the storage space can be improved to the greatest extent, so that the performance of the electronic equipment is improved.
In an embodiment, the performing GC-sorting on the segments to be GC-sorted sequentially in the order from the higher fragmentation rate includes:
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.
In the above embodiment, the GC arrangement mode of the corresponding 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 GC arrangement frequency is adapted to the storage condition of the storage space, and further, the performance of the electronic device is improved.
In an embodiment, the size of the writable space in the storage space is determined by the number of fragments of unwritten data or the number of data blocks of unwritten data in the storage space, the fragments comprising a preset number of data blocks.
In an 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:
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.
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.
In the above embodiment, under the condition that the fragmentation rate of the storage space is larger and the writable space in the storage space is smaller, the fast GC arrangement frequency is adopted to quickly reduce the fragmentation rate of the storage space, so that the data to be written is written into the storage space with higher continuous degree as much as possible, and the data writing speed and the subsequent data reading speed are improved. Under the conditions that the fragmentation rate of the storage space is smaller and the writable space in the storage space is larger, the slower GC arrangement frequency is adopted, so that the influence degree of the GC arrangement process on the response speed of the electronic equipment is reduced.
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 at a first detection frequency, and 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 at a second detection frequency, the second detection frequency being larger than the first detection frequency. In the second sorting mode, the fragmentation rate of the storage space and the detection frequency of the size of the writable space in the storage space are higher, so that the switching to the first sorting mode can be performed as soon as possible under the condition that the first sorting mode is detected to be satisfied, that is, the GC sorting frequency is reduced as soon as possible, and the influence of frequent GC sorting on the response speed of the electronic equipment is avoided.
In an embodiment, the meeting the condition of GC arrangement of the storage space includes that the kernel layer of the electronic device does not detect the IO instruction to issue to the storage space. GC arrangement can be performed under the condition that the IO instruction is not detected to be issued to the storage space, so that the times of GC arrangement can be increased as much as possible, and the situation that the electronic equipment is in a scene with high fragmentation rate for a long time is avoided.
In an embodiment, the method further comprises:
and if the existence of the data to be written is detected under the condition that the fragments of the data which are not written exist in the storage space, the data to be written are sequentially written into the corresponding fragments according to the sequence from the small fragmentation rate to the large fragmentation rate according to the fragmentation rate of each fragment in the storage space, namely, the data to be written is preferentially written into a space with higher continuous degree, so that the writing speed of the data and the subsequent reading speed of the data are improved.
In a second aspect, there is provided a storage space management apparatus comprising:
the storage module is used for determining the size relation between the fragmentation rates of all fragments to be subjected to GC finishing in the storage space under the condition that the GC finishing is carried out on the storage space, wherein the fragmentation rates are used for representing the discontinuity degree of writable space in the fragments;
and the processing module is used for sequentially carrying out GC arrangement on the fragments to be subjected to the GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate.
In one embodiment, the processing module is specifically configured to:
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.
In an embodiment, the size of the writable space in the storage space is determined by the number of fragments of unwritten data or the number of data blocks of unwritten data in the storage space, the fragments comprising a preset number of data blocks.
In one embodiment, the processing module is specifically configured to:
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.
In one embodiment, the processing module is specifically configured to:
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.
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 at a first detection frequency, and 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 at a second detection frequency, the second detection frequency being larger than the first detection frequency.
In an embodiment, the meeting the condition of GC arrangement of the storage space includes that the kernel layer of the electronic device does not detect the IO instruction to issue to the storage space.
In an embodiment, the processing module is further configured to:
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.
In a third aspect, an electronic device is provided, comprising a processor for executing a computer program stored in a memory for implementing a storage space management method as described in the first aspect above.
In a fourth aspect, there is provided a computer readable storage medium storing a computer program which, when executed by a processor, implements the storage space management method according to the first aspect described above.
In a fifth aspect, a chip is provided, the chip comprising a processor, the processor being coupled to a memory, the processor executing a computer program or instructions stored in the memory to implement the storage space management method as described in the first aspect above.
In a sixth aspect, a computer program product is provided which, when run on an electronic device, causes the electronic device to perform the storage space management method of the first aspect described above.
It will be appreciated that the advantages of the second to sixth aspects may be found in the relevant description of the first aspect, and are not described here again.
Drawings
FIG. 1 is a schematic diagram of a storage space according to an embodiment of the present disclosure;
fig. 2 is a schematic diagram of storage spaces before and after GC arrangement according to an embodiment of the present application;
fig. 3 is a software structural block diagram of an electronic device according to an embodiment of the present application;
FIG. 4 is a scene graph of a first collation mode and a second collation mode switch provided by an embodiment of the application;
FIG. 5 is a flowchart of a method for managing storage space according to an embodiment of the present application;
FIG. 6 is a block diagram of a kernel layer provided by an embodiment of the present application;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system configurations, techniques, etc. in order to provide a thorough understanding of 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 that depart from 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 the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
As used in this specification and the appended claims, the term "if" may be interpreted as "when..once" or "in response to a determination" or "in response to detection" depending on the context. Similarly, the phrase "if a determination" or "if a [ described condition or event ] is detected" may be interpreted in the context of meaning "upon determination" or "in response to determination" or "upon detection of a [ described condition or event ]" or "in response to detection of a [ described condition or event ]".
In addition, in the description of the present application, the terms "first," "second," and the like are used merely to distinguish between descriptions and are not to be construed as indicating or implying relative importance.
Reference in the specification to "one embodiment" or "some embodiments" or the like means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," and the like in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments" unless expressly specified otherwise. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless expressly specified otherwise.
For a better understanding of embodiments of the present application, terms or concepts that may be referred to in the embodiments are described below.
1. File system (file system)
The basic data unit of the file system is a file, and is a method and a data structure for defining the file on a storage space such as a disk or a partition in an operating system, and the method and the data structure are used for organizing and managing the file on the corresponding disk or partition.
F2FS (Flash Friendly File System) File System
The F2FS file system is a novel open source flash file system specially designed for NAND-based storage equipment, and the flash supports a Linux operating system. The F2FS file system does not guarantee that logically linked data is also contiguous in storage space when saving the data of a file.
3. Segment (segment)
As shown in FIG. 1, the F2FS file system divides storage space into fixed-size segments 11, the segments 11 being the basic units of storage space allocation, organization, and reclamation. Each segment 11 comprises 512 data blocks (blocks). The data blocks 111 are the basic unit of F2FS file system data storage, and the storage space of each data block 111 is 4096 bytes. Each data block in the memory space may be in one of three states, readable, writable, and erasable. In practical use, the writing and deleting operations of data are frequently staggered, so that there are segments of writable data blocks that are discontinuous in storage space, i.e., segments that are discontinuous in writable space. For example, as shown in fig. 2, in the segment 21, a black data block indicates a data block to which data is written, and a white data block indicates a data block to which data is not written, the segment 21 is a segment in which writable spaces are discontinuous.
GC finishing
As shown in fig. 2, GC-sorting is used to transfer valid data in segments 21 with discontinuous writable space to other storage spaces according to a certain algorithm, and delete invalid data after transfer to obtain segments 22 with continuous writable space.
In the prior art, GC arrangement is generally performed when the electronic device is idle, so that the GC arrangement process is easily interrupted. After GC finishing is interrupted, if the electronic equipment fails to timely perform GC finishing again, the discontinuous degree of the writable space can be increased rapidly, and the performance of the electronic equipment is further affected.
Therefore, the method for managing the storage space determines the size relation between the fragmentation rates of all fragments to be subjected to GC arrangement in the storage space under the condition that the GC arrangement is carried out on the storage space, and sequentially carries out the GC arrangement on all fragments to be subjected to the GC arrangement according to the sequence of the fragmentation rates from large to small. The fragment with the largest fragmentation rate can be firstly arranged, so that the whole fragmentation rate of the storage space can be quickly reduced, and even if GC arrangement is interrupted, the continuity degree of the writable space in the storage space can be furthest improved, and the performance of the electronic equipment is further improved.
The following describes an exemplary storage space management method provided in the embodiment of the present application.
The storage space management method provided by the embodiment of the application is applied to the electronic equipment. For example, the electronic device described in the embodiments of the present application may be a device that may be held/operated by one hand, such as a mobile phone, a tablet computer, a handheld computer, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR), a Virtual Reality (VR) device, a media player, and a wearable device, and the specific form/type of the electronic device is not particularly limited in the embodiments of the present application. The electronic device includes but is not limited to a mounted device
Figure BDA0003823230820000051
Hong Mongolian System (Harmony OS) or other operating system devices.
The software system of the electronic device may employ a layered architecture, an event driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. In the embodiment of the invention, an Android system with a layered architecture is taken as an example, and the software structure of the electronic equipment is illustrated.
Fig. 3 is a software configuration block diagram of an electronic device according to an embodiment of the present invention.
The layered architecture divides the software into several layers, each with distinct roles and branches. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, from top to bottom, an application layer, an application framework layer, an Zhuoyun row (Android run) and system libraries, and a kernel layer, respectively.
The application layer may include a series of application packages.
As shown in fig. 3, the application package may include applications for cameras, gallery, calendar, phone calls, maps, navigation, WLAN, bluetooth, music, video, short messages, etc.
The application framework layer provides an application programming interface (application programming interface, API) and programming framework for application programs of the application layer. The application framework layer includes a number of predefined functions.
As shown in FIG. 3, the application framework layer may include a window manager, a content provider, a view system, a telephony manager, a resource manager, a notification manager, and the like.
The window manager is used for managing window programs. The window manager can acquire the size of the display screen, judge whether a status bar exists, lock the screen, intercept the screen and the like.
The content provider is used to store and retrieve data and make such data accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phonebooks, etc.
The view system includes visual controls, such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, a display interface including a text message notification icon may include a view displaying text and a view displaying a picture.
The telephony manager is for providing communication functions of the electronic device. Such as the management of call status (including on, hung-up, etc.).
The resource manager provides various resources for the application program, such as localization strings, icons, pictures, layout files, video files, and the like.
The notification manager allows the application to display notification information in a status bar, can be used to communicate notification type messages, can automatically disappear after a short dwell, and does not require user interaction. Such as notification manager is used to inform that the download is complete, message alerts, etc. The notification manager may also be a notification in the form of a chart or scroll bar text that appears on the system top status bar, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, a text message is prompted in a status bar, a prompt tone is emitted, the electronic device vibrates, and an indicator light blinks, etc.
Android run time includes a core library and virtual machines. Android run time is responsible for scheduling and management of the Android system.
The core library consists of two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. The virtual machine executes java files of the application program layer and the application program framework layer as binary files. The virtual machine is used for executing the functions of object life cycle management, stack management, thread management, security and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: surface manager (surface manager), media Libraries (Media Libraries), three-dimensional graphics processing Libraries (e.g., openGL ES), 2D graphics engines (e.g., SGL), etc.
The surface manager is used to manage the display subsystem and provides a fusion of 2D and 3D layers for multiple applications.
Media libraries support a variety of commonly used audio, video format playback and recording, still image files, and the like. The media library may support a variety of audio and video encoding formats, such as MPEG4, h.264, MP3, AAC, AMR, JPG, PNG, etc.
The three-dimensional graphic processing library is used for realizing three-dimensional graphic drawing, image rendering, synthesis, layer processing and the like.
The 2D graphics engine is a drawing engine for 2D drawing.
The kernel layer is a layer between hardware and software. The inner core layer at least comprises a display driver, a camera driver, an audio driver and a sensor driver.
In an embodiment, the storage space management method provided in the embodiment of the present application may be executed in a kernel layer of the electronic device. Because the file system (such as F2FS file system) operates in the kernel layer, more detailed storage information of the storage space managed by the file system can be acquired through an interface of the file system in the kernel layer, so that the fragmentation rate of the storage space can be evaluated more reasonably, the sorting mode of GC sorting and the sorting sequence of all fragments in the storage space can be decided more reasonably through the fragmentation rate of the storage space, and the discontinuity degree of writable space in the storage space can be reduced rapidly through GC sorting.
The following describes a storage space management method provided in the embodiment of the present application in detail.
Firstly, determining whether conditions for GC arrangement of the storage space are met or not according to the use state of the electronic equipment.
In an embodiment, the condition for GC arrangement of the storage space may be determined to be satisfied when the electronic device is in a preset state, where the preset state may be any one or more of idle, off-screen, charging, or an amount of electricity being charged is greater than a preset value. The condition of meeting GC arrangement of the storage space may also be determined when the electronic device is in a preset state and is currently in a preset period (e.g., between 3 and 5 a.m.). 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, the application program framework layer generates information meeting the conditions for GC arrangement of the storage space, the information is sent to the kernel layer through the system library, and the kernel layer determines that the conditions for GC arrangement of the storage space are met according to the information.
In another embodiment, the condition of GC-sorting of the storage space may be satisfied when the Input/Output (IO) instruction is not detected by the kernel layer to the storage space, i.e., when the instruction for reading data from or writing data to the storage space is not detected by the kernel layer. Because the electronic equipment is in a state that no IO instruction is issued to the storage space, the situation that the electronic equipment is in a preset state is more than the situation that the electronic equipment determined by the upper layer is in the preset state, under the situation that the IO instruction is not issued to the storage space, the condition that GC arrangement is performed on the storage space is determined to be met, and then the storage space is subjected to GC arrangement, the GC arrangement times can be increased as much as possible under the situation that the frequency of the electronic equipment is higher, and the performance of the electronic equipment is further improved. Meanwhile, since GC arrangement is executed in the kernel layer, whether the conditions of GC arrangement are met or not is determined by detecting IO instructions through the kernel layer, compared with the case that whether the conditions of GC arrangement are met or not is determined through the upper layer and then sent to the kernel layer, the decision efficiency of GC arrangement can be improved, and the computational resources occupied by the decision process of GC arrangement can be reduced.
Because the user may use the electronic device in the GC arrangement process, the GC arrangement is interrupted, and after the GC arrangement is interrupted, the response to the user operation may cause a situation that the response speed of the electronic device is slower. Therefore, when the IO instruction is not detected by the kernel layer and the time interval from last finishing of GC arrangement is longer than the preset duration, the condition that the GC arrangement is carried out on the memory space is determined to be met, and accordingly the influence of frequent GC arrangement on the performance of the electronic equipment can be avoided.
In the case where it is determined that the condition for GC-sorting of the storage space is satisfied, a 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.
In one embodiment, the pattern of GC ordering is determined based on the fragmentation rate of a memory space and the size of writable space in the memory 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 discontinuity of writable space in the segment, which when writing data to the segment results in written data being discontinuous in storage space, i.e. logically continuous data being discontinuous in physical space. The higher the fragmentation rate of the storage space, the higher the degree of discontinuity of the storage space.
Specifically, if the fragmentation rate of the storage space is greater than a first preset value, the size of the writable space in the storage space is smaller than a second preset value, the arrangement mode is determined to be switched from the first arrangement mode to the second arrangement mode, and if the fragmentation rate of the storage space is smaller than a third preset value, the size of the writable space in the storage space is greater than a fourth preset value, the arrangement mode is determined to be switched from the second arrangement mode to the first arrangement mode. The GC finishing frequency of the second finishing mode is greater than that of the first finishing mode, for example, the core layer performs GC finishing every 30 seconds in the first finishing mode, and the core layer performs GC finishing every 5 seconds in the second finishing mode; the third preset value is smaller than or equal to the first preset value; the fourth preset value is greater than or equal to the second preset value. Namely, when the fragmentation rate of the storage space is larger and the writable space in the storage space is smaller, the frequency of GC arrangement is increased, so that the fragmentation degree of the storage space can be quickly reduced, the data written into the fragments are continuous as much as possible, and the performance of the electronic equipment is improved. When the fragmentation rate of the storage space is smaller and the writable space in the storage space is larger, the frequency of GC arrangement is reduced, so that the process of GC arrangement is prevented from occupying the resources of the electronic equipment, the running speed of the electronic equipment is prevented from being influenced by the process of GC arrangement, and the user experience is improved.
The GC arrangement in the first arrangement mode corresponds to a first GC arrangement function, and the first GC arrangement function is called once after each GC arrangement. GC arrangement in the second arrangement mode corresponds to the second GC arrangement function, and the second GC arrangement function is called once for each GC arrangement. The first GC-sorting function and the second GC-sorting function may be the same or different. For example, the operation duration of the second GC finishing function may be smaller than that of the first GC finishing function, that is, the finishing frequency of the second GC finishing mode is increased relative to that of the first GC finishing mode, and the time per finishing is shorter, that is, the second GC finishing mode may be a finishing mode in which a plurality of finishing is performed and the finishing space per finishing is small.
Illustratively, as shown in fig. 4, the abscissa represents time in seconds, the ordinate represents the fragmentation rate, and a > B, in the case where the condition of GC arrangement is satisfied, GC arrangement is performed in the first arrangement mode. 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 a second preset value, switching from the first sorting mode to the second sorting mode, and performing GC sorting according to the second sorting mode. At time t2, the fragmentation rate of the storage space is B%, the size of the writable space in the storage space is larger than the fourth preset value, the condition of GC arrangement is still satisfied, the second arrangement mode is exited, and the first arrangement mode is entered, so that the frequency of GC arrangement can be increased under the condition that the fragmentation rate of the storage space is higher, and the fragmentation rate of the storage space is rapidly reduced.
In an embodiment, the size of the writable space in the storage space is determined by the number of fragments of unwritten data in the storage space, and when the fragmentation rate of the storage space is greater than a first preset value and the number of fragments of unwritten data is less than a second preset value, the method enters a second sorting mode to increase the frequency of GC sorting. And when the fragmentation rate of the storage space is smaller than a third preset value and the number of fragments of unwritten data is larger than a fourth preset value, entering a first sorting mode to reduce the frequency of GC sorting.
For example, the number of fragments in the storage space where data is not written is represented by free_segment, and the fragmentation RATE of the storage space is represented by gc_frag_stream_rate. The first preset value is set to 45%, the second preset value is set to 2 x ovp, the third preset value is set to 40%, and the fourth preset value is set to 3 x ovp.
Entering a second sort mode when free_segment < = 2 x ovp and gc_frag_sector_rate > 45%; when free_segment > =3×ovp, gc_frag_sector_rate <40%, the first sort mode is entered. Wherein, OVP represents a reserved value of a preset number of segments, and when the number of segments in which data is not written in the storage space is large (for example, the number of segments in which data is not written is greater than 2×ovp), the segments that are continuous in writable space are generally selected to sequentially store the data to be written. When the number of fragments in the storage space where data is not written is smaller than 2 ovps, it is indicated that the available space in the storage space is smaller, and the data to be written is stored by using fragments with discontinuous writable space (i.e. fragments where data has been written but not fully written). Storing the data to be written in spatially discontinuous segments affects the data writing speed and the reading speed of the subsequent data. Therefore, when the number of fragments in which data is not written in the storage space is smaller than 2×ovp, the GC arrangement frequency is quickened, so that more fragments with continuous writable space can be obtained as soon as possible, and the data to be written can be written into the fragments with continuous writable space.
In another embodiment, the size of the writable space in the storage space may also be determined by the number of data blocks in the storage space where data is not written, and when the fragmentation rate of the storage space is greater than the first preset value and the number of data blocks where data is not written is less than the second preset value, the method enters the second sorting mode to increase the frequency of GC sorting. And when the fragmentation rate of the storage space is smaller than a third preset value and the number of data blocks without data writing is larger than a fourth preset value, entering a first sorting mode to reduce the frequency of GC sorting.
For example, the number of data blocks to which data is not written is represented by free_blocks, and space represents the total capacity of 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.
Entering a second sort mode when free_blocks < = 5% space, gc_frag_stream_rate > 55%; when free_blocks > =10% space, gc_frag_score_rate <45%, the first sort mode is entered.
In one embodiment, the fragmentation rate of each fragment is represented by a fragmentation score for the corresponding fragment.
Wherein, the calculation formula of the fragmentation score of the fragment is as follows:
Figure BDA0003823230820000081
Wherein score represents a fragmentation score of a fragment, X represents the number of non-writable data blocks in the fragment, weight represents a weight, and block (i) represents a score of an i-th data block in the fragment, the score of the i-th data block being related to whether the writable states of the i-th data block, the i-1-th data block, and the i+1-th data block are consistent. For example, if the writable states of the ith data block, the i-1 th data block and the (i+1) th data block are consistent, that is, the data blocks are writable or are non-writable, the score of the ith data block is 0; if the i-th data block is consistent with the writable state of the i-1-th data block and is inconsistent with the (i+1) -th data block writable state, the score of the i-th data block is 1; if the writable state of the ith data block is inconsistent with the writable state of the (i-1) th data block and is consistent with the writable state of the (i+1) th data block, the score of the ith data block is 1; if the i-th data block is inconsistent with the writable state of the i-1-th data block and inconsistent with the (i+1) -th data block writable state, the score of the i-th data block is 2.
Figure BDA0003823230820000082
The sum of the scores representing all the data blocks in a segment can be used to represent the fragmentation score inside the segment. In the process of writing data into fragments, when the number of writable data blocks in one fragment is smaller, the next fragment is allocated to the data to be written in a shorter time, so that logically continuous data is stored in different fragments, and the IO performance of the storage space is reduced, therefore, X represents the number of non-writable data blocks in the fragment and can also be used for representing fragmentation scores of fragments, namely fragmentation scores outside the fragment. The fragmentation degree of the storage space can be better evaluated by weighting and summing the fragmentation score of the inner part of the fragment and the fragmentation of the outer part of the fragment to obtain the fragmentation score of the fragment.
After determining the fragmentation score for each fragment, the fragmentation rate for the storage space may be further determined based on the fragmentation score for each fragment and the number of all fragments in the storage space. Specifically, the calculation formula of the fragmentation rate of the storage space is:
Figure BDA0003823230820000091
where 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 value of the fragmentation score that can be achieved by one fragment, for example, N is 1534 when weight is 2.
It will be appreciated that other calculation methods that characterize the degree of writable space discontinuity may be used to determine the fragmentation rate of a fragment or the fragmentation rate of a storage space.
After the finishing mode is determined, the kernel layer determines all fragments to be subjected to GC finishing in the storage space, and performs GC finishing on all fragments to be subjected to GC finishing until the GC finishing end condition is met.
The fragments to be subjected to GC arrangement may be fragments in which all writable spaces in the storage space are discontinuous, or fragments in which the fragmentation rate is greater than a set threshold.
The GC finishing condition is any one or more of the fact that the fragmentation rate of the storage space reaches a first set value, the size of the writable space in the storage space reaches a second set value, the finishing duration reaches a set duration, and the finishing quantity reaches a set quantity.
In one embodiment, the kernel layer interrupts GC ordering if it detects that there is an IO instruction issued to memory space. 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, the application framework layer generates information which does not meet the condition of GC arrangement of the storage space, the information is sent to the kernel layer through the system library, and the kernel layer interrupts GC arrangement according to the information.
After the GC arrangement is interrupted or stopped, if the condition that the GC arrangement is satisfied is detected again, determining a GC arrangement mode again to carry out the GC arrangement on the storage space.
It can be appreciated that in the case where the condition for GC finishing of the storage space is satisfied, the process of GC finishing includes, but is not limited to, the following scenarios:
1. and if the fragmentation rate of the current storage space is larger than a first preset value and the size of a writable space in the storage space is smaller than a second preset value, performing GC arrangement on all fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate by adopting a second arrangement mode. After GC arrangement is performed for a period of time by adopting the second arrangement mode, if the fragmentation rate of the storage space is detected to be smaller than the third preset value, the size of the writable space in the storage space is detected to be larger than the fourth preset value, namely, the storage space is detected to be larger, and the fragmentation rate is reduced, the GC arrangement is performed on all fragments to be subjected to the GC arrangement according to the sequence from the larger fragmentation rate to the smaller fragmentation rate by adopting the first arrangement mode. After finishing for a period of time by adopting the first finishing mode, if the condition for finishing the GC finishing is confirmed to be met, finishing the GC finishing. Wherein, in the process of GC finishing using the first finishing mode and GC finishing using the second finishing mode, the process of GC finishing may be interrupted.
2. And if the fragmentation rate of the current 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, performing GC arrangement on all fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate by adopting a first arrangement mode. After finishing for a period of time by adopting the first finishing mode, if the condition for finishing the GC finishing is confirmed to be met, finishing the GC finishing.
3. And if the fragmentation rate of the current 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, performing GC arrangement on all fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate by adopting a first arrangement mode. After a period of time of the sort using the first sort mode, GC sort is discontinued. And under the condition that GC arrangement is performed on the storage space again, detecting that the fragmentation rate of the storage space is larger than a first preset value and the size of a writable space in the storage space is smaller than a second preset value, and performing GC arrangement on all fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate by adopting a second arrangement mode. After GC arrangement is performed for a period of time by adopting the second arrangement mode, if the fragmentation rate of the storage space is detected to be smaller than a third preset value and the size of the writable space in the storage space is larger than a fourth preset value, performing GC arrangement on all fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate by adopting the first arrangement mode. After finishing for a period of time by adopting the first finishing mode, if the condition for finishing the GC finishing is confirmed to be met, finishing the GC finishing.
In an embodiment, in a 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 a 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 greater than the first detection frequency. That is, the GC-finish frequency in the second finish mode is greater than the GC-finish frequency in the first finish mode, while the detection frequency in the second finish mode is greater than the detection frequency in the first finish 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 or the second detection frequency, and the mode of GC arrangement and the order of GC arrangement are determined, wherein the order of GC arrangement is described in detail later. Under the second arrangement mode, the fragmentation rate of the storage space is higher, the size of the writable space in the storage space is smaller, the faster detection frequency is adopted, the electronic equipment can be quickly switched to the first arrangement mode under the condition that the second arrangement mode is not satisfied, the condition that the response speed of the electronic equipment is reduced due to the fact that the second arrangement mode is adopted for GC arrangement for a long time is avoided, the GC arrangement sequence can be timely adjusted under the condition that the fragmentation rate is higher, and the continuity degree of the writable space in the storage space is improved.
In the above embodiment, under the conditions that the fragmentation rate of the storage space is higher and the writable space in the storage space is smaller, GC arrangement is performed by adopting the faster GC arrangement frequency, so that the fragmentation degree of the storage space can be rapidly reduced, the data written into the fragments is continuous as much as possible, and the performance of the electronic device is improved. Under the conditions that the fragmentation rate of the storage space is low and the writable space in the storage space is small, the GC arrangement is performed by adopting the slow GC arrangement frequency, so that the process of GC arrangement can be prevented from occupying the resources of the electronic equipment, the running speed of the electronic equipment is prevented from being influenced by the process of GC arrangement, and the user experience is improved. Meanwhile, whether the data to be written can be continuously stored in the storage space and the association degree of the fragmentation rate of the storage space is higher, the frequency of GC arrangement is determined through the fragmentation rate of the storage space, the timing of GC arrangement can be matched with the storage state of the storage space, timeliness of GC arrangement is ensured, writing of the data under the condition that the residual storage space is larger but the writable space is poor in continuity is avoided, and the performance of the electronic equipment is improved.
In an embodiment, when the kernel layer performs GC finishing on each segment to be subjected to GC finishing, the kernel layer performs GC finishing on each segment to be subjected to GC finishing according to a set sequence.
The storage space management method provided by the embodiment of the application comprises the following steps:
s501: and under the condition that GC arrangement is carried out on the storage space, determining the size relation between the fragmentation rates of all fragments to be subjected to the GC arrangement in the storage space, wherein the fragmentation rates are used for representing the discontinuity degree of writable space in the fragments.
Specifically, the fragmentation score of each fragment to be subjected to GC arrangement determined according to the calculation formula of the fragmentation score of the fragment is the fragmentation rate of each fragment. The fragments to be subjected to GC-sorting may be fragments in which all writable spaces in the storage space are discontinuous, or fragments in which the fragmentation rate is greater than a set threshold. After determining the fragmentation rate of each fragment, sorting the fragments to be subjected to GC arrangement according to the sequence from the large fragmentation rate to the small fragmentation rate.
S502: 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.
Specifically, after the kernel layer determines the size relationship of the fragmentation rate of each fragment to be subjected to GC-trimming, GC-trimming is started. If the GC finishing process is not interrupted, the GC finishing is always carried out according to the sequence from the large to the small of the fragmentation rate, namely, after finishing the GC finishing of the last fragment each time, the fragment with the highest fragmentation rate is firstly finished until the GC finishing is interrupted or the GC finishing is finished. If the GC finishing is interrupted or the GC finishing is finished, updating the fragmentation rate of each fragment to be subjected to the GC finishing. And when GC finishing is performed next time, according to the updated fragmentation rate, sequentially performing GC finishing on the fragments to be subjected to GC finishing again according to the sequence from the large fragmentation rate to the small fragmentation rate.
In an embodiment, a GC-trimming mode is determined first, and if the trimming mode is a first trimming mode, GC-trimming is performed on the segments to be GC-trimmed according to the GC-trimming frequency corresponding to the first trimming mode, and in the trimming process, GC-trimming is performed in order of from a higher fragmentation rate to a lower fragmentation rate. If the sorting mode is the second sorting mode, GC sorting is carried out on the fragments to be subjected to GC sorting according to the sorting frequency corresponding to the second sorting mode, and in the sorting process, the GC sorting is carried out according to the sequence from the high fragmentation rate to the low fragmentation rate.
In the above embodiment, under the condition that GC arrangement is performed on the storage space, the size relationship between the fragmentation rates of the segments to be GC-arranged in the storage space, where the fragmentation rates are used to represent the discontinuity degree of the writable space in the segments, is determined; and sequentially carrying out GC finishing on each fragment to be subjected to GC finishing according to the sequence of the fragmentation rate from large to small. The maximum fragment rate can be used for rapidly reducing the fragmentation rate of the whole storage space by firstly arranging the fragment with the maximum fragment rate, and the continuous degree of the writable space in the storage space can be improved to the greatest extent even if GC arrangement is interrupted. Compared with the prior arrangement of the segments with small writable space or the random arrangement of any segments during GC arrangement, the performance of the electronic equipment can be better improved by the prior arrangement of the segments with the largest defragmentation rate.
In an embodiment, when the GC arrangement is interrupted or the GC arrangement is finished, if the kernel layer detects that there is data to be written and there is no segment of unwritten data in the storage space, the data to be written is written into the corresponding segment in sequence according to the sequence from the small to the large of the fragmentation rate of each segment in the storage space, that is, the data is preferentially written into the segment with the highest continuity degree of the writable space. In the prior art, data to be written is generally written into a segment with more writable space preferentially, or the segment to be written preferentially needs to be determined by combining the writable space in the segment and the writing time of the written data. However, the extent of the continuity of the writable space in the segment with more writable space is not necessarily high, and it cannot be guaranteed that the data to be written is as continuous as possible over the storage space. Determining the writable space and the write time for already written data requires a high computational resource. The data to be written can be enabled to be continuous as far as possible in the storage space, so that the writing speed of the data and the reading speed of the subsequent data are improved, the calculation process of determining the segment to be written preferentially according to the fragmentation rate is simple, the occupied calculation resources are less, and the performance of the electronic equipment can be improved.
In an embodiment, if the kernel layer detects that there is data to be read, and the data to be read is stored in a plurality of segments, the corresponding segments are sequentially read according to the sequence from small to large of the fragmentation rate, so that the data with higher storage continuity degree can be preferentially read, that is, a part of the data can be quickly read first, so that the response speed of the electronic device is improved.
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 in the embodiment of the present application is executed in the file system layer of the kernel layer. Specifically, a file system (for example, an F2FS file system) in the file system layer is configured to receive a request from a user to read data or write data, determine address information of data to be read or written in a storage space according to the request to read data or write data, and send the address information to the block layer. The block layer is used for processing address information corresponding to data to be read or address information corresponding to data to be written to obtain task units which can be processed by the storage drive, and sending the task units to the storage drive. After the storage drive receives the task units, the storage drive reads or writes data in the storage space of the corresponding address according to the set order, for example, writes the data in a general flash storage (Universal Flash Storage, UFS) or a small computer system interface (Small Computer System Interface, scsi) hard disk. After the data is successfully read or written, the storage drive sends the information of the successful read or write to the file system through the block layer. The file system layer calls a GC arrangement decision module, and the GC arrangement decision module determines the storage condition of the storage space according to the request of reading data or writing data and the information of successful reading or writing of the data, further determines the fragmentation rate of the storage space and the size of the writable space in the storage space according to the storage condition, and further determines the GC arrangement strategy according to the fragmentation rate of the storage space and the size of the writable space in the storage space. The GC arrangement policy includes GC arrangement mode, GC arrangement order, data reading order, data writing order, and the like. And then, GC arrangement and data reading and writing are carried out in the storage space according to a GC arrangement strategy, so that the data to be written and read are continuous as much as possible in the storage space, the performance of the electronic equipment is improved, and further the user experience is improved.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference is made to the related descriptions of other embodiments.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic of each process, and should not limit the implementation process of the embodiment of the present application in any way.
Fig. 7 shows a schematic structural diagram of the electronic device 100.
The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charge management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, keys 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identity module (subscriber identification module, SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyro sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.
It should be understood that the illustrated structure of the embodiment of the present invention does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, electronic device 100 may include more or fewer components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the 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 reuse the instruction or data, it can be called directly from the memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
It should be understood that the interfacing relationship between the modules illustrated in the embodiments of the present invention is only illustrative, and is not meant to limit the structure of the electronic device 100. In other embodiments of the present application, the electronic device 100 may also use different interfacing manners, or a combination of multiple interfacing manners in the foregoing embodiments.
The power management module 141 is used for connecting the battery 142, and the charge management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140 to power the processor 110, the internal memory 121, the display 194, the camera 193, the wireless communication module 160, and the like. The power management module 141 may also be configured to monitor battery capacity, battery cycle number, battery health (leakage, impedance) and other parameters. In other embodiments, the power management module 141 may also be provided in the processor 110. In other embodiments, the power management module 141 and the charge management module 140 may be disposed in the same device.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to enable expansion of the memory capabilities of the electronic device 100. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. For example, files such as music, video, etc. are stored in an external memory card.
The internal memory 121 may be used to store computer executable program code including instructions. The internal memory 121 may include a storage program area and a storage data area. The storage program area may store an application program (such as a sound playing function, an image playing function, etc.) required for at least one function of the operating system, etc. The storage data area may store data created during use of the electronic device 100 (e.g., audio data, phonebook, etc.), and so on. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like. The processor 110 performs various functional applications of the electronic device 100 and data processing 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, because the content of information interaction and execution process between the above devices/units is based on the same concept as the method embodiment of the present application, specific functions and technical effects thereof may be referred to in the method embodiment section, and will not be described herein again.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions. The functional units and modules in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working process of the units and modules in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the present application implements all or part of the flow of the method of the above embodiments, and may be implemented by a computer program to instruct related hardware, where the computer program may be stored in a computer readable storage medium, where the computer program, when executed by a processor, may implement the steps of each of the method embodiments described above. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code to a camera device/electronic apparatus, a recording medium, a computer Memory, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), an electrical carrier signal, a telecommunications signal, and a software distribution medium. Such as a U-disk, removable hard disk, magnetic or optical disk, etc.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/network device and method may be implemented in other manners. For example, the apparatus/network device embodiments described above are merely illustrative, e.g., the division of the modules or units is merely a logical functional division, and there may be additional divisions in actual implementation, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection via interfaces, devices or units, which may be in electrical, mechanical or other forms.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
Finally, it should be noted that: the foregoing is merely a specific embodiment of the present application, but the protection scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to 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广东移动通信有限公司 Garbage recycling method and device and computer readable storage medium
CN110945486A (en) * 2018-06-30 2020-03-31 华为技术有限公司 Storage fragment management method and terminal
CN112131140A (en) * 2020-09-24 2020-12-25 北京计算机技术及应用研究所 SSD-based key value separation storage method supporting efficient storage space management
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 华为技术有限公司 Storage fragment management method and terminal
CN110928852A (en) * 2019-12-09 2020-03-27 Oppo广东移动通信有限公司 Garbage recycling method and 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 北京计算机技术及应用研究所 SSD-based key value separation storage method supporting efficient storage space management
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
EP4109230A1 (en) Storage system, file storage and reading method, and terminal device
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
CN110554999B (en) Cold and hot attribute identification and separation method and device based on log file system and flash memory device and related products
CN114185494B (en) Memory anonymous page processing method, electronic device and readable storage medium
CN114840450B (en) Storage space arrangement method and electronic equipment
CN115292199B (en) Video memory leakage processing method and related device
WO2023202429A1 (en) Garbage recycling method and electronic device
CN115879097A (en) Method for safely starting verification and electronic equipment
CN116049021B (en) Storage space management method, electronic device, and computer-readable storage medium
CN111008079B (en) Process management method, device, storage medium and electronic equipment
WO2024037068A1 (en) Task scheduling method, electronic device and computer-readable storage medium
CN116701298A (en) File system management method and electronic equipment
CN116049113B (en) File system arrangement method, electronic device and computer readable storage medium
CN111475299A (en) Memory allocation method and device, storage medium and electronic equipment
CN112783418B (en) Method for storing application program data and mobile terminal
CN114253737A (en) Electronic device, memory recovery method thereof and medium
CN113032290A (en) Flash memory configuration method and device, electronic equipment and storage medium
CN116719752A (en) Memory allocation method, electronic equipment and storage medium
WO2024087724A1 (en) Garbage collection method, page storage method, and electronic device
CN111459462A (en) Decentralized relock demotion
CN115168298B (en) File system fragmentation evaluation method and electronic equipment
CN116126744B (en) Memory recycling method and device and terminal equipment
CN114741205B (en) Anonymous page recovery method and electronic device
WO2023198103A1 (en) Inter-process communication method and electronic device
CN116662222A (en) Cache management method and related equipment

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