CN115344537A - Storage space allocation method and device, file system and storage medium - Google Patents

Storage space allocation method and device, file system and storage medium Download PDF

Info

Publication number
CN115344537A
CN115344537A CN202210752014.3A CN202210752014A CN115344537A CN 115344537 A CN115344537 A CN 115344537A CN 202210752014 A CN202210752014 A CN 202210752014A CN 115344537 A CN115344537 A CN 115344537A
Authority
CN
China
Prior art keywords
storage
file
data
page
termination
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.)
Pending
Application number
CN202210752014.3A
Other languages
Chinese (zh)
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.)
Midea Group Co Ltd
Guangdong Midea White Goods Technology Innovation Center Co Ltd
Original Assignee
Midea Group Co Ltd
Guangdong Midea White Goods Technology Innovation Center 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 Midea Group Co Ltd, Guangdong Midea White Goods Technology Innovation Center Co Ltd filed Critical Midea Group Co Ltd
Priority to CN202210752014.3A priority Critical patent/CN115344537A/en
Publication of CN115344537A publication Critical patent/CN115344537A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1727Details of free space management performed by the file system

Abstract

The application discloses a storage space allocation method, a storage space allocation device, a file system and a storage medium, and belongs to the technical field of file systems. The method comprises the following steps: a data write request corresponding to a first file is received. Determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file; determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space meets the condition of low residual capacity, and selecting at least one storage file to be fused which meets the condition of low utilization rate of storage pages; and selecting at least one idle storage page as a storage page to be used, and writing data stored in a termination storage page corresponding to the first file, data to be written in the first file and data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used. By the adoption of the method and the device, the utilization rate of the storage space can be improved.

Description

Storage space allocation method and device, file system and storage medium
Technical Field
The present application relates to the field of file system technologies, and in particular, to a method and an apparatus for allocating storage space, a file system, and a storage medium.
Background
Lightweight file systems are widely used in the fields of smart homes, smart cars, and the like. The storage space of the storage medium of the lightweight file system is usually small, and is mostly used for storing configuration files, user setting parameters and the like. The storage medium is divided into a plurality of storage pages, and one file is stored in at least one storage page. When new data of a certain file needs to be written, if the data volume of the written file is larger than the storage space of the storage page occupied by the current file, a new storage space needs to be allocated to the file.
At present, when allocating a new storage space to a file, a free storage page is usually selected to be allocated to the file for use as a termination storage page corresponding to the file.
Under the current storage space allocation mode, if a storage page can only be occupied by one file, even if the storage page is occupied by one file, the storage page can not be allocated to other files for use if a large storage space is left. Thus, the problems of wasted storage space and low utilization rate may be caused.
Disclosure of Invention
The embodiment of the application provides a method and a device for allocating storage space, a file system and a storage medium, which can solve the problem of low utilization rate of the storage space in the related art. The technical scheme is as follows:
in a first aspect, a method for allocating storage space is provided, where the method includes:
receiving a data writing request corresponding to a first file, wherein the data writing request carries the data volume to be written of the first file;
determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file;
determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium meets the condition of low residual capacity, and selecting at least one to-be-fused storage file meeting the condition of low utilization rate of storage pages from the files stored in the storage medium except the first file;
and selecting at least one storage page from the idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
In one possible implementation, the method further includes:
determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium does not meet the condition of low residual capacity, selecting at least one storage page from idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing data stored in a termination storage page corresponding to the first file and data to be written in the first file into the storage page to be used.
In one possible implementation manner, the determining that the storage space of the storage medium satisfies the low remaining capacity condition includes:
calculating the occupancy rate of the storage space of the storage medium after the data to be written is written;
and if the occupancy rate of the storage space is greater than a preset threshold value, determining that the storage space of the storage medium meets a low residual capacity condition.
In one possible implementation manner, the determining that the storage space of the storage medium satisfies the low remaining capacity condition includes:
calculating the residual capacity of the storage space of the storage medium after the data to be written is written;
calculating a first number of average occupied storage pages of files stored in the storage medium;
calculating a first product of the capacity of a single storage page and the first quantity, and dividing the product by the first quantity to obtain a first numerical value;
acquiring a second number of storage pages occupied by a third file, and calculating a second product of the second number and the capacity of a single storage page;
adding the first value and the second product to obtain a second value;
and if the residual capacity of the storage space is smaller than the second value, determining that the storage space of the storage medium meets a low residual capacity condition.
In a possible implementation manner, the selecting, from the files other than the first file stored in the storage medium, at least one to-be-fused storage file that satisfies a low-usage-rate condition of a storage page includes:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is less than one half of the capacity of a single storage page, selecting one to-be-fused storage file from the files stored in the storage medium except the first file, wherein the data volume of a termination storage page corresponding to the to-be-fused storage file is less than one half of the capacity of the single storage page, and only the data of the to-be-fused storage file is stored in the termination storage page corresponding to the to-be-fused storage file.
In a possible implementation manner, the selecting, according to the amount of data to be newly added, at least one storage page from free storage pages of the storage medium as a storage page to be used, and writing data stored in a termination storage page corresponding to the first file, data to be written in the first file, and data stored in a termination storage page corresponding to the storage file to be fused into the storage page to be used includes:
dividing the sum of the newly added data amount and the data amount stored in the terminated storage page corresponding to the first file by the capacity of a single storage page, and rounding up the division result to obtain a third number of storage pages to be used;
selecting the third number of storage pages from free storage pages of the storage medium as storage pages to be used;
and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the third number of storage pages to be used.
In a possible implementation manner, the selecting, from the files other than the first file stored in the storage medium, at least one to-be-fused storage file that satisfies a low-usage-rate condition of a storage page includes:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is larger than one half of the capacity of a single storage page, selecting two storage files to be fused from the files stored in the storage medium except the first file, wherein for each storage file to be fused, the data volume of a termination storage page corresponding to the storage file to be fused is smaller than one half of the capacity of the single storage page, and only the data of the storage file to be fused is stored in the termination storage page corresponding to the storage file to be fused.
In a possible implementation manner, according to the amount of the data to be newly added, at least one storage page is selected from idle storage pages of the storage medium as a storage page to be used, and data stored in a termination storage page corresponding to the first file, data to be written in the first file, and data stored in a termination storage page corresponding to the storage file to be fused are written into the storage page to be used, including;
dividing the sum of the newly added data amount and the data amount stored in the storage page which is terminated and corresponds to the first file by the capacity of a single storage page, rounding up the division result, and adding one to the rounding result to obtain a fourth number of the storage pages to be used;
selecting the fourth number of storage pages from free storage pages of the storage medium as storage pages to be used;
writing the data stored in the storage page to be used corresponding to the storage file to be fused into the storage page to be used;
and writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into the unoccupied storage pages to be used in the fourth number of storage pages to be used.
In a second aspect, an apparatus for storage space allocation is provided, the apparatus comprising:
the device comprises a receiving module and a sending module, wherein the receiving module is used for receiving a data writing request corresponding to a first file, and the data writing request carries the data volume to be written of the first file;
the determining module is used for determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file;
the selection module is used for determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium meets the condition of low residual capacity, and selecting at least one to-be-fused storage file meeting the condition of low utilization rate of storage pages from files stored in the storage medium except the first file;
and the storage module is used for selecting at least one storage page from idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
In a possible implementation manner, the selection module further includes:
determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium does not meet the condition of low residual capacity, selecting at least one storage page from idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing data stored in a termination storage page corresponding to the first file and data to be written in the first file into the storage page to be used.
In one possible implementation manner, the selection module is configured to:
calculating the occupancy rate of the storage space of the storage medium after the data to be written is written;
and if the storage space occupancy rate is greater than a preset threshold value, determining that the storage space of the storage medium meets a low residual capacity condition.
In one possible implementation manner, the selection module is configured to:
calculating the residual capacity of the storage space of the storage medium after the data to be written is written;
calculating a first number of average occupied storage pages of files stored in the storage medium;
calculating a first product of the capacity of a single memory page and the first number, and dividing the product by the first number to obtain a first numerical value;
acquiring a second number of storage pages occupied by a third file, and calculating a second product of the second number and the capacity of a single storage page;
adding the first value and the second product to obtain a second value;
and if the storage space residual capacity is smaller than the second value, determining that the storage space of the storage medium meets a low residual capacity condition.
In one possible implementation manner, the selection module is configured to:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is less than one half of the capacity of a single storage page, selecting one to-be-fused storage file from the files stored in the storage medium except the first file, wherein the data volume of a termination storage page corresponding to the to-be-fused storage file is less than one half of the capacity of the single storage page, and only the data of the to-be-fused storage file is stored in the termination storage page corresponding to the to-be-fused storage file.
In one possible implementation manner, the storage module is configured to:
dividing the sum of the newly added data amount and the data amount stored in the terminated storage page corresponding to the first file by the capacity of a single storage page, and rounding up the division result to obtain a third number of storage pages to be used;
selecting the third number of storage pages from free storage pages of the storage medium as storage pages to be used;
and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the third number of storage pages to be used.
In one possible implementation manner, the selection module is configured to:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is larger than one half of the capacity of a single storage page, selecting two storage files to be fused from the files stored in the storage medium except the first file, wherein for each storage file to be fused, the data volume of a termination storage page corresponding to the storage file to be fused is smaller than one half of the capacity of the single storage page, and only the data of the storage file to be fused is stored in the termination storage page corresponding to the storage file to be fused.
In a possible implementation manner, the storage module is configured to store the information;
dividing the sum of the newly added data amount and the data amount stored in the terminated storage page corresponding to the first file by the capacity of a single storage page, rounding up the division result, and adding one to the rounding result to obtain a fourth number of storage pages to be used;
selecting the fourth number of storage pages from free storage pages of the storage medium as storage pages to be used;
writing the data stored in the termination storage page corresponding to the storage file to be fused into a storage page to be used;
and writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into the unoccupied storage pages to be used in the fourth number of storage pages to be used.
In a third aspect, a file system is provided, and the computer device includes a storage controller and a storage medium, where at least one instruction is stored in the storage medium, and the instruction is loaded and executed by the storage controller to implement the operations performed by the method for allocating storage space according to the first aspect.
In a fourth aspect, a computer-readable storage medium is provided, in which at least one instruction is stored, and the instruction is loaded and executed by a processor to implement the operations performed by the method for allocating memory space according to the first aspect.
In a fifth aspect, a computer program product is provided, wherein at least one instruction is stored, and the instruction is loaded and executed by a processor to implement the operations performed by the method for allocating memory space according to the first aspect.
The technical scheme provided by the embodiment of the application has the following beneficial effects:
when the storage space needs to be newly allocated to the first file, if the residual capacity in the current storage medium is judged to be small, at least one storage file to be fused meeting the condition of low utilization rate of storage pages can be selected. And determining at least one storage page to be used, and writing the data stored in the termination storage page corresponding to the storage file to be fused, the data stored in the termination storage page of the target file and the data to be written in the target file into the newly determined at least one storage page to be used. If the method is processed according to the related art, because the file to be merged is two files, the two files cannot be stored in the same storage page, but by the method, the two files can be merged and stored, that is, the two files can be stored in the same storage page, so that the utilization rate of the storage page can be higher.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a schematic diagram of a file system provided by an embodiment of the present application;
FIG. 2 is a flowchart of a method for allocating memory according to an embodiment of the present application;
FIG. 3 is a schematic diagram of an operation pointer provided by an example of the present application;
FIG. 4 is a graph comparing the effects provided by the examples of the present application;
FIG. 5 is a schematic structural diagram of an apparatus for allocating storage space according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a terminal device provided in an embodiment of the present application;
fig. 7 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
In order to facilitate understanding of the embodiments of the present application, the following description explains terms related to the embodiments of the present application.
1. Integrated management page pool
The integrated management page pool is used for recording the number of files stored in a storage medium of the file system and the number of free storage pages in the storage medium. Wherein the free memory page is a memory page in which data is not stored. A file may also be referred to as a node.
2. File description pool
The file description pool is used for recording the relevant information of each file. The related information of the file includes: the data volume of the termination storage page corresponding to the file, the priority of the file, the data storage characteristics of the termination storage page corresponding to the file, the number of storage pages occupied by the file, the data volume of the file and the operation pointer of the file.
3. Terminating a memory page
The last memory page occupied by the file. For example, if the data size of a file is 5KB and the capacity of a single memory page is 2KB, the data sizes of the first two memory pages of the three memory pages occupied by the file are 2KB, and the data size of the last memory page is 1KB, and the memory page with the data size of 1KB is the terminating memory page.
The data size of the termination storage page corresponding to any file indicates the data size of the file stored in the termination storage page. For example, if a storage page is both an end storage page corresponding to file a and an end storage page corresponding to file B, then the "data amount of the end storage page corresponding to file a" indicates the data amount of file a stored in the storage page, and the "data amount of the end storage page corresponding to file B" indicates the data amount of file B stored in the storage page.
4. Priority of files
The priority of a file is related to how often the file is accessed, and if a file is accessed frequently, the priority of the file is lower, whereas if a file is accessed frequently, the priority of the file is higher.
5. Terminating data storage features of a memory page
In the embodiment of the present application, the data storage characteristics may be classified into three types. The method is characterized in that: only the upper half page is stored; the second characteristic: only the lower half page is stored; the characteristics are three: and storing the whole page.
For the terminating storage page corresponding to any file, the first characteristic indicates that the upper half page of the terminating storage page is used for storing the data of the file, the second characteristic indicates that the lower half page of the terminating storage page is used for storing the data of the file, and the third characteristic indicates that the whole page of the terminating storage page is used for storing the data of the file.
6. Operation of a file system
The operation on the file in the file system mainly comprises the following steps: create, delete, write, read, etc. The embodiment of the application mainly aims at the writing situation.
The method for allocating the storage space can be applied to a file system. For example, lightweight file systems on smart homes, smart cars, and the like. Referring to fig. 1, a file system 100 may include a storage controller 110 and a storage medium 120. The storage controller 110 may be a processor (CPU), and the storage medium 120 may be a Flash Memory (Flash Memory).
After the storage controller 110 obtains the operation request for the file, the corresponding operation is performed on the file in the storage medium 120 according to the operation request. In the case that the operation is a write operation, the method for allocating the storage space provided by the embodiment of the present application may be used to allocate the storage space to the data to be written.
Fig. 2 is a flowchart of a method for allocating a storage space according to an embodiment of the present application. Referring to fig. 2, the process flow of the method may include the following steps:
step 201, receiving a data write request corresponding to a first file.
And the data writing request carries the data volume to be written of the first file.
In implementation, when receiving an operation request for a first file, a storage controller first obtains an operation attribute carried in the operation request. And if the operation attribute is determined to be writing, acquiring the data volume to be written carried in the operation request. Here, when the operation attribute is a write operation, the operation request may also be referred to as a data write request.
Step 202, determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file.
In an implementation, the storage controller may first obtain a current data size of the first file and a current operation pointer of the first file, and specifically, may obtain the current data size and the current operation pointer of the first file in the foregoing node description. And then, determining the data volume to be newly added of the first file according to the current data volume of the first file, the current operation pointer of the first file and the data volume to be written.
The calculation formula of the data amount to be newly added of the first file may be as follows:
len=p+n-l
wherein len is the data size to be newly added of the first file, p is the data size of the first file from the first byte to the operation pointer, n is the data size to be written, and l is the current data size of the first file.
For ease of understanding, referring to fig. 3, the relationship between the amount of data to be newly added to the first file, the current operation pointer, the amount of data to be written, and the current amount of data of the first file before is shown.
Step 203, determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of the storage medium meets the condition of low residual capacity, and selecting at least one to-be-fused storage file meeting the condition of low utilization rate of storage pages from the files stored in the storage medium except the first file.
In implementation, the storage controller determines whether the data amount to be newly added of the first file is greater than 0, and if the data amount to be newly added of the first file is not greater than 0, it is determined that the data amount to be newly added does not meet the newly allocated storage space condition. And if the data volume to be newly added of the first file is larger than 0, determining that the data volume to be newly added meets the condition of newly allocated storage space. Two cases are explained below:
situation one, the data volume to be newly added does not meet the condition of newly allocated storage space
In this case, there is no need to newly allocate a storage space for the first file. Also in this case, the priority of the first file in the node description pool, the current operation pointer, may be updated. The specific updating method comprises the following steps:
updating the priority:
the priority of the first file is reduced, assuming that the priority of the first file is a 1 If the priority of the updated first file is: 1/(1/a) 1 +1)。
Updating the operation pointer:
assuming that the current operation pointer of the first file is p, the updated operation pointer is p + n, and n is the data volume to be written.
Second, the data volume to be newly added meets the condition of newly allocated storage space
In this case, it is explained that a storage space needs to be newly allocated to the first file. Next, it is determined whether the storage space of the storage medium satisfies a low remaining capacity condition. There are various judgment methods, and two of them will be described below.
Method one, static threshold method
The storage space occupancy rate of the storage medium in the case of writing the data to be written is calculated, and if the storage space occupancy rate is greater than a preset threshold, it may be determined whether the storage space of the storage medium satisfies a low remaining capacity condition. The above calculation formula of the storage space occupancy rate may be as follows:
Figure BDA0003718576030000101
wherein r is the occupancy rate of the storage space, len is the data volume to be newly added of the first file, N is the number of storage pages in the storage medium, x is the number of idle storage pages, and k is the capacity of a single storage page.
Method II, dynamic threshold value method
The remaining capacity of the storage space of the storage medium in the case of writing data to be written is calculated. The calculation formula of the remaining capacity of the storage space is as follows:
s = x × k-len, where s is the remaining capacity of the storage space, len is the data amount to be newly added to the first file, x is the number of free storage pages, and k is the capacity of a single storage page.
Then, a storage space reference threshold is calculated, and a calculation formula of the storage space reference threshold may be as follows:
Figure BDA0003718576030000111
wherein c is a reference threshold of the storage space, N is the number of storage pages in the storage medium, x is the number of free storage pages, k is the capacity of a single storage page, y is the number of files stored in the storage medium, and g is the number of storage pages occupied by the file occupying the most storage pages in the storage medium.
Then, whether the storage space residual capacity is smaller than a storage space reference threshold is judged, and if the storage space residual capacity is smaller than the storage space reference threshold, the storage space of the storage medium is determined to meet the low residual capacity condition. Determining that the storage space of the storage medium does not satisfy the low remaining capacity condition if the storage space remaining capacity is not less than the storage space reference threshold. The case where the low residual capacity condition is satisfied and the case where the low residual capacity condition is not satisfied will be described below.
Case one, the storage space of the storage medium does not satisfy the low remaining capacity condition
In this case, a storage page to be used is selected among free storage pages of the storage medium according to the amount of data to be newly added. And then writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into the storage page to be used.
The following describes "selecting a storage page to be used from free storage pages of a storage medium according to the amount of data to be newly added".
And calculating the number of the required storage pages to be used according to the data volume to be newly increased and the data volume of the terminated storage pages of the first file. The calculation formula may be as follows:
Figure BDA0003718576030000112
wherein z is the number of required storage pages to be used, ceil () is an upward rounding operation, len is the data volume b to be newly added of the first file a K is the data amount of the terminating memory page of the first file, and k is the capacity of a single memory page.
In addition, in this case, the data size of the terminating storage page corresponding to the first file in the node description pool, the priority of the first file, the storage characteristics of the terminating storage page corresponding to the first file, the number of storage pages occupied by the first file, the data size of the first file, and the current operation pointer of the first file may also be updated. The number of free memory pages in the integrated management page pool may also be updated. The specific updating method comprises the following steps:
updating the data volume of the termination storage page corresponding to the first file:
suppose the data amount of the terminating storage page corresponding to the first file is a 2 If the updated first file corresponds to the termination storage page, the data size of the termination storage page is: (len + a) 2 ) % k, wherein len is the data volume to be newly added of the first file,% is the remainder operation, and k is the capacity of a single storage page.
Updating the priority of the first file:
the priority of the first file is lowered, assuming that the priority of the first file is a 1 If the priority of the updated first file is: 1/(1/a) 1 +1)。
Updating the storage characteristics of the termination storage page corresponding to the first file:
and updating the storage characteristics of the termination storage page corresponding to the first file to be the third characteristics.
Updating the number of memory pages occupied by the first file:
suppose that the number of memory pages occupied by the first file is a 3 And then the number of the storage pages occupied by the updated first file is:
Figure BDA0003718576030000121
updating the data volume of the first file:
assume that the data size of the first file is a 4 If the updated data volume of the first file is: a is 4 +len。
Updating the current operation pointer of the first file:
assuming that the current operation pointer of the first file is p, the updated operation pointer is p + n, and n is the data volume to be written.
Updating the number of free memory pages:
assuming that the number of free memory pages is x, the updated number of free memory pages is:
Figure BDA0003718576030000122
second, the storage space of the storage medium satisfies the low residual capacity condition
In this case, the following processing may be performed:
and determining the expected data volume of the termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file. The expected data volume is: (len + a) 2 ) % k, wherein,% is the residue operation, k is the capacity of a single storage page, len is the data volume to be newly added of the first file, a 2 And storing the current data size of the page for the termination corresponding to the first file.
Then, it is determined whether the predicted data amount of the terminating memory page is less than one-half of the capacity of the single memory page, and if the predicted data amount of the terminating memory page is less than one-half of the capacity of the single memory page, single-page fusion storage is performed. If the predicted amount of data of the terminating memory page is not less than one-half of the capacity of a single memory page, multi-page fused memory is performed. The following describes the single-page fused memory and the multi-page fused memory separately:
1. single page fused storage
Firstly, traversing a file description pool, sequentially judging files according to the sequence of the priority levels from low to high, judging whether the files can be used as the storage files to be fused or not, and stopping judging the files until one storage file to be fused is determined. The file judgment method comprises the following steps:
and judging whether the data volume of the termination storage page corresponding to the file is less than one half of the capacity of a single storage page or not, wherein the storage characteristic of the corresponding termination storage page is a characteristic three. And if the data volume of the termination storage page corresponding to the file is less than one half of the capacity of the single storage page and the storage characteristic of the corresponding termination storage page is the third characteristic, taking the file as the to-be-fused storage file.
After determining the storage files to be fused, the fusion storage may be performed, and the specific processing is described in the following step 204.
2. Multi-page fused storage
Firstly, traversing a file description pool, sequentially judging files according to the sequence of the priority levels from low to high, judging whether the files can be used as storage files to be fused or not, and stopping judging the files until two storage files to be fused are determined. The file judgment method comprises the following steps:
and judging whether the data volume of the termination storage page corresponding to the file is less than one half of the capacity of a single storage page or not, wherein the storage characteristic of the corresponding termination storage page is a characteristic three. And if the data volume of the termination storage page corresponding to the file is less than one half of the capacity of a single storage page and the storage characteristic of the corresponding termination storage page is a characteristic three, taking the file as the storage file to be fused.
After determining the two storage files to be merged, the merged storage may be executed, and the specific processing is described in the following step 204.
And 204, selecting at least one storage page from the idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
In the implementation, the processing of step 204 is different for the single-page fused storage and the multi-page fused storage, and the processing of step 204 when the single-page fused storage and the multi-page fused storage are respectively explained as follows:
1. single page fused storage
First, according to the target number of memory pages to be used which is required for calculation:
Figure BDA0003718576030000131
then, according to a wear leveling algorithm, a target number of memory pages are selected from the free memory pages as memory pages to be used. And writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
For example, if the target number is 1, the data stored in the termination storage page corresponding to the first file and the data to be written in the first file may be written into the first half page of the storage page to be used, and the data stored in the termination storage page corresponding to the storage file to be merged may be written into the second half page of the storage page to be used.
In addition, the data volume of the termination storage page corresponding to the first file in the node description pool, the priority of the first file, the storage characteristics of the termination storage page corresponding to the first file, the number of storage pages occupied by the first file, the data volume of the first file, and the current operation pointer of the first file may be updated. And updating the storage characteristics of the termination storage page corresponding to the storage file to be fused. The number of free memory pages in the integrated management page pool may also be updated. The specific updating method comprises the following steps:
updating the data volume of the termination storage page corresponding to the first file:
suppose that the data amount of the terminating memory page corresponding to the first file is a 2 If the data amount of the termination storage page corresponding to the updated first file is: (len + a) 2 ) % k, wherein len is the data volume to be newly added of the first file,% is the remainder operation, and k is the capacity of a single storage page.
Priority update for the first file:
the priority of the first file is reduced, assuming that the priority of the first file is a 1 If the priority of the updated first file is: 1/(1/a) 1 +1)。
Updating the storage characteristics of the termination storage page corresponding to the first file:
and updating the storage characteristics of the termination storage page corresponding to the first file into the first characteristic (or the second characteristic). Specifically, if the first half page of the termination storage page corresponding to the first file is used for storing the data of the first file after the fused storage is completed, the first feature is updated, and if the second half page of the termination storage page corresponding to the first file is used for storing the data of the first file after the fused storage is completed, the second feature is updated.
Updating the number of memory pages occupied by the first file:
suppose that the first file occupies a number of memory pages of a 3 And then the number of the storage pages occupied by the updated first file is:
Figure BDA0003718576030000141
where floor () represents a floor operation.
Updating the data volume of the first file:
assume that the data size of the first file is a 4 And if so, the data volume of the updated first file is as follows: a is 4 +len。
Updating the current operation pointer of the first file:
assuming that the current operation pointer of the first file is p, the updated operation pointer is p + n, and n is the data volume to be written.
Updating the storage characteristics of the termination storage page corresponding to the storage file to be fused:
and updating the storage characteristics of the termination storage page corresponding to the storage file to be fused into the first characteristics (or the second characteristics). Specifically, if the merged storing is completed, the first half page of the terminating storage page corresponding to the to-be-merged storing file is used for storing the data of the to-be-merged storing file, the first feature is updated, and if the merged storing is completed, the second half page of the terminating storage page corresponding to the to-be-merged storing file is used for storing the data of the to-be-merged storing file, the second feature is updated.
Updating the number of free memory pages:
assuming that the number of free memory pages is x, the updated number of free memory pages is:
Figure BDA0003718576030000151
2. multi-page fused storage
First, according to the target number of memory pages to be used which is required for calculation:
Figure BDA0003718576030000152
then, according to a wear leveling algorithm, a target number of memory pages are selected from the free memory pages as memory pages to be used. And writing the data stored in the termination storage pages corresponding to the two storage files to be fused into one storage page to be used. And writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into the unoccupied storage pages to be used in the target number of storage pages to be used.
For example, the target number is 2, and the storage files to be merged are a storage file to be merged a and a storage file to be merged B, respectively. Then, one storage page to be used may be selected first, and the data stored in the termination storage page corresponding to the storage file a to be fused is written into the upper half page of the storage page to be used, and the data stored in the termination storage page corresponding to the storage file B to be fused is written into the lower half page of the storage page to be used. And writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into another storage page to be used.
In addition, the data volume of the termination storage page corresponding to the first file in the node description pool, the priority of the first file, the storage characteristics of the termination storage page corresponding to the first file, the number of storage pages occupied by the first file, the data volume of the first file, and the current operation pointer of the first file may also be updated. And updating the storage characteristics of the termination storage pages corresponding to the two storage files to be fused. The number of free memory pages in the integrated management page pool may also be updated. The specific updating method is the same as that in the single-page fusion storage, and is not described herein again.
In the scheme shown in the embodiment of the application, when a storage space needs to be newly allocated to a first file, if it is determined that the remaining capacity in the current storage medium is small, at least one to-be-fused storage file meeting a low-usage-rate condition of a storage page may be selected. And determining at least one storage page to be used, and writing the data stored in the termination storage page corresponding to the storage file to be fused, the data stored in the termination storage page of the target file and the data to be written in the target file into the newly determined at least one storage page to be used. If the method is processed according to the related art, because the file to be merged is two files, the two files cannot be stored in the same storage page, but by the method, the two files can be merged and stored, that is, the two files can be stored in the same storage page, so that the utilization rate of the storage page can be higher.
Referring to fig. 4, a relationship between the number of storage files and the storage space occupied when the storage space allocation method provided by the embodiment of the present application is adopted is shown. For the purpose of comparison, fig. 4 also shows the relationship between the number of storage files and the storage space occupied when the storage space allocation method in the related art is adopted. Compared with the prior art, the method for allocating the storage space has the advantages that under the condition that the storage space is the same, more files can be stored by the method for allocating the storage space, namely, the utilization rate of the storage space is higher.
All the above optional technical solutions may be combined arbitrarily to form the optional embodiments of the present disclosure, and are not described herein again.
Based on the same technical concept, an embodiment of the present application further provides an apparatus for allocating storage space, as shown in fig. 5, the apparatus includes: a receiving module 410, a determining module 420, a selecting module 430, and a storing module 440, wherein:
a receiving module 410, configured to receive a data writing request corresponding to a first file, where the data writing request carries a data amount to be written of the first file; the receiving function in step 201 shown in fig. 2 may be specifically implemented.
A determining module 420, configured to determine, according to the data amount to be written, the current data amount of the first file, and the current operation pointer of the first file, a data amount to be newly added to the first file; the determination function in step 202 shown in fig. 2 may be specifically implemented.
A selecting module 430, configured to determine that the amount of data to be newly added meets a newly allocated storage space condition, determine that a storage space of a storage medium meets a low remaining capacity condition, and select, from files stored in the storage medium other than the first file, at least one to-be-fused storage file that meets a low-usage-rate condition of a storage page; the selection function in step 203 shown in fig. 2 may be specifically implemented.
The storage module 440 is configured to select at least one storage page from the idle storage pages of the storage medium as a storage page to be used according to the amount of the data to be newly added, and write the data stored in the termination storage page corresponding to the first file, the data to be written in the first file, and the data stored in the termination storage page corresponding to the storage file to be merged into the storage page to be used. The writing function in step 204 shown in fig. 2 may be specifically implemented.
When the storage space needs to be newly allocated to the first file, if the residual capacity in the current storage medium is judged to be small, at least one storage file to be fused meeting the condition of low utilization rate of storage pages can be selected. And determining at least one storage page to be used, and writing the data stored in the termination storage page corresponding to the storage file to be fused, the data stored in the termination storage page of the target file and the data to be written in the target file into the newly determined at least one storage page to be used. If the method is processed according to the related art, because the file to be merged is two files, the two files cannot be stored in the same storage page, but by the method, the two files can be merged and stored, that is, the two files can be stored in the same storage page, so that the utilization rate of the storage page can be higher.
It should be noted that: in the memory space allocation apparatus provided in the foregoing embodiment, only the division of each functional module is illustrated, and in practical applications, the above function allocation may be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules, so as to complete all or part of the above described functions. In addition, the apparatus for allocating storage space and the method for allocating storage space provided by the foregoing embodiments belong to the same concept, and specific implementation processes thereof are detailed in the method embodiments and will not be described herein again.
Fig. 6 shows a block diagram of an electronic device 500 according to an exemplary embodiment of the present application. The electronic device 500 may be a portable mobile terminal, such as: a smart phone, a tablet computer, an MP3 player (Moving Picture Experts Group Audio Layer III, motion Picture Experts compression standard Audio Layer 3), an MP4 player (Moving Picture Experts Group Audio Layer IV, motion Picture Experts compression standard Audio Layer 4), a notebook computer, or a desktop computer. The electronic device 500 may also be referred to by other names such as user equipment, portable terminal, laptop terminal, desktop terminal, and so on.
In general, the electronic device 500 includes: a processor 501 and a memory 502. The processor 510 corresponds to the memory controller in fig. 1, and the memory 502 corresponds to the storage medium in fig. 1.
The processor 501 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and so on. The processor 501 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), PLA (Programmable Logic Array). The processor 501 may also include a main processor and a coprocessor, where the main processor is a processor for Processing data in an awake state, and is also called a Central Processing Unit (CPU); a coprocessor is a low power processor for processing data in a standby state. In some embodiments, the processor 501 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed by the display screen. In some embodiments, processor 501 may also include an AI (Artificial Intelligence) processor for processing computational operations related to machine learning.
Memory 502 may include one or more computer-readable storage media, which may be non-transitory. Memory 502 may also include high-speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In some embodiments, a non-transitory computer readable storage medium in memory 502 is used to store at least one instruction for execution by processor 501 to implement the method of memory allocation provided by the method embodiments herein.
In some embodiments, the electronic device 500 may further optionally include: a peripheral interface 503 and at least one peripheral. The processor 501, memory 502, and peripheral interface 503 may be connected by buses or signal lines. Various peripheral devices may be connected to the peripheral interface 503 via a bus, signal line, or circuit board. Specifically, the peripheral device includes: at least one of radio frequency circuitry 504, display screen 505, camera assembly 506, audio circuitry 507, positioning assembly 508, and power supply 509.
The peripheral interface 503 may be used to connect at least one peripheral related to I/O (Input/Output) to the processor 501 and the memory 502. In some embodiments, the processor 501, memory 502, and peripheral interface 503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 501, the memory 502, and the peripheral interface 503 may be implemented on separate chips or circuit boards, which is not limited by the present embodiment.
The Radio Frequency circuit 504 is used for receiving and transmitting RF (Radio Frequency) signals, also called electromagnetic signals. The radio frequency circuitry 504 communicates with communication networks and other communication devices via electromagnetic signals. The rf circuit 504 converts an electrical signal into an electromagnetic signal to transmit, or converts a received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a subscriber identity module card, and so forth. The radio frequency circuitry 504 may communicate with other terminals via at least one wireless communication protocol. The wireless communication protocols include, but are not limited to: the world wide web, metropolitan area networks, intranets, generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and/or WiFi (Wireless Fidelity) networks. In some embodiments, the rf circuit 504 may further include NFC (Near Field Communication) related circuits, which are not limited in this application.
The display screen 505 is used to display a UI (User Interface). The UI may include graphics, text, icons, video, and any combination thereof. When the display screen 505 is a touch display screen, the display screen 505 also has the ability to capture touch signals on or over the surface of the display screen 505. The touch signal may be input to the processor 501 as a control signal for processing. At this point, the display screen 505 may also be used to provide virtual buttons and/or a virtual keyboard, also referred to as soft buttons and/or a soft keyboard. In some embodiments, the display screen 505 may be one, disposed on the front panel of the electronic device 500; in other embodiments, the display screens 505 may be at least two, respectively disposed on different surfaces of the electronic device 500 or in a folded design; in other embodiments, the display 505 may be a flexible display disposed on a curved surface or on a folded surface of the electronic device 500. Even more, the display screen 505 can be arranged in a non-rectangular irregular figure, i.e. a shaped screen. The Display screen 505 may be made of LCD (Liquid Crystal Display), OLED (Organic Light-Emitting Diode), and other materials.
The camera assembly 506 is used to capture images or video. Optionally, camera assembly 506 includes a front camera and a rear camera. Generally, a front camera is disposed at a front panel of the terminal, and a rear camera is disposed at a rear surface of the terminal. In some embodiments, the number of the rear cameras is at least two, and each rear camera is any one of a main camera, a depth-of-field camera, a wide-angle camera and a telephoto camera, so that the main camera and the depth-of-field camera are fused to realize a background blurring function, and the main camera and the wide-angle camera are fused to realize panoramic shooting and VR (Virtual Reality) shooting functions or other fusion shooting functions. In some embodiments, camera assembly 506 may also include a flash. The flash lamp can be a monochrome temperature flash lamp or a bicolor temperature flash lamp. The double-color-temperature flash lamp is a combination of a warm-light flash lamp and a cold-light flash lamp, and can be used for light compensation at different color temperatures.
The audio circuitry 507 may include a microphone and a speaker. The microphone is used for collecting sound waves of a user and the environment, converting the sound waves into electric signals, and inputting the electric signals to the processor 501 for processing, or inputting the electric signals to the radio frequency circuit 504 to realize voice communication. For stereo capture or noise reduction purposes, the microphones may be multiple and disposed at different locations of the electronic device 500. The microphone may also be an array microphone or an omni-directional pick-up microphone. The speaker is used to convert electrical signals from the processor 501 or the radio frequency circuit 504 into sound waves. The loudspeaker can be a traditional film loudspeaker and can also be a piezoelectric ceramic loudspeaker. When the speaker is a piezoelectric ceramic speaker, the speaker can be used for purposes such as converting an electric signal into a sound wave audible to a human being, or converting an electric signal into a sound wave inaudible to a human being to measure a distance. In some embodiments, audio circuitry 507 may also include a headphone jack.
The positioning component 508 is used to locate the current geographic Location of the electronic device 500 for navigation or LBS (Location Based Service). The Positioning component 508 may be a Positioning component based on the Global Positioning System (GPS) in the united states, the beidou System in china, or the galileo System in russia.
The power supply 509 is used to power the various components in the electronic device 500. The power source 509 may be alternating current, direct current, disposable or rechargeable. When power supply 509 includes a rechargeable battery, the rechargeable battery may be a wired rechargeable battery or a wireless rechargeable battery. The wired rechargeable battery is a battery charged through a wired line, and the wireless rechargeable battery is a battery charged through a wireless coil. The rechargeable battery may also be used to support fast charge technology.
In some embodiments, the electronic device 500 also includes one or more sensors 510. The one or more sensors 510 include, but are not limited to: acceleration sensor 511, gyro sensor 512, pressure sensor 513, fingerprint sensor 514, optical sensor 515, and proximity sensor 516.
The acceleration sensor 511 may detect the magnitude of acceleration on three coordinate axes of a coordinate system established with the electronic device 500. For example, the acceleration sensor 511 may be used to detect components of the gravitational acceleration in three coordinate axes. The processor 501 may control the display screen 505 to display the user interface in a landscape view or a portrait view according to the gravitational acceleration signal collected by the acceleration sensor 511. The acceleration sensor 511 may also be used for acquisition of motion data of a game or a user.
The gyro sensor 512 may detect a body direction and a rotation angle of the electronic device 500, and the gyro sensor 512 may cooperate with the acceleration sensor 511 to acquire a 3D motion of the user on the electronic device 500. The processor 501 may implement the following functions according to the data collected by the gyro sensor 512: motion sensing (such as changing the UI according to a user's tilting operation), image stabilization at the time of photographing, game control, and inertial navigation.
The pressure sensor 513 may be disposed on a side bezel of the electronic device 500 and/or underneath the display screen 505. When the pressure sensor 513 is disposed on the side frame of the electronic device 500, the holding signal of the user to the electronic device 500 can be detected, and the processor 501 performs left-right hand recognition or shortcut operation according to the holding signal collected by the pressure sensor 513. When the pressure sensor 513 is disposed at the lower layer of the display screen 505, the processor 501 controls the operability control on the UI interface according to the pressure operation of the user on the display screen 505. The operability control comprises at least one of a button control, a scroll bar control, an icon control, and a menu control.
The fingerprint sensor 514 is used for collecting a fingerprint of the user, and the processor 501 identifies the identity of the user according to the fingerprint collected by the fingerprint sensor 514, or the fingerprint sensor 514 identifies the identity of the user according to the collected fingerprint. Upon recognizing that the user's identity is a trusted identity, the processor 501 authorizes the user to perform relevant sensitive operations including unlocking the screen, viewing encrypted information, downloading software, paying, and changing settings, etc. The fingerprint sensor 514 may be disposed on the front, back, or side of the electronic device 500. When a physical button or vendor Logo is provided on the electronic device 500, the fingerprint sensor 514 may be integrated with the physical button or vendor Logo.
The optical sensor 515 is used to collect the ambient light intensity. In one embodiment, the processor 501 may control the display brightness of the display screen 505 based on the ambient light intensity collected by the optical sensor 515. Specifically, when the ambient light intensity is high, the display brightness of the display screen 505 is increased; when the ambient light intensity is low, the display brightness of the display screen 505 is adjusted to be low. In another embodiment, processor 501 may also dynamically adjust the shooting parameters of camera head assembly 506 based on the ambient light intensity collected by optical sensor 515.
A proximity sensor 516, also referred to as a distance sensor, is typically disposed on the front panel of the electronic device 500. The proximity sensor 516 is used to capture the distance between the user and the front of the electronic device 500. In one embodiment, when the proximity sensor 516 detects that the distance between the user and the front surface of the electronic device 500 gradually decreases, the processor 501 controls the display screen 505 to switch from the bright screen state to the dark screen state; when the proximity sensor 516 detects that the distance between the user and the front surface of the electronic device 500 becomes gradually larger, the processor 501 controls the display screen 505 to switch from the breath screen state to the bright screen state.
Those skilled in the art will appreciate that the configuration shown in fig. 6 is not intended to be limiting of the electronic device 500 and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components may be used.
Fig. 7 is a schematic structural diagram of a computer device according to an embodiment of the present application, where the computer device 600 may have a relatively large difference due to different configurations or performances, and may include one or more processors 601 and one or more memories 602, where the memory 602 stores at least one instruction, and the at least one instruction is loaded and executed by the processors 601 to implement the methods provided by the above method embodiments. Certainly, the server may further have components such as a wired or wireless network interface, a keyboard, and an input/output interface, so as to perform input and output, and the computer device may further include other components for implementing the functions of the device, which is not described herein again.
In an exemplary embodiment, a computer-readable storage medium, such as a memory, including instructions executable by a processor in a terminal to perform the method of memory space allocation in the above embodiments is also provided. The computer readable storage medium may be non-transitory. For example, the computer-readable storage medium may be a ROM (Read-Only Memory), a RAM (Random Access Memory), a CD-ROM (Compact Disc Read-Only Memory), a magnetic tape, a floppy disk, an optical data storage device, and the like.
It should be noted that information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.), and signals (including but not limited to signals transmitted between a user terminal and other equipment, etc.) referred to in the present application are authorized by a user or are sufficiently authorized by various parties, and the collection, use, and processing of the relevant data need to comply with relevant laws and regulations and standards in relevant countries and regions. For example, documents referred to in this application are obtained with sufficient authorization.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk.
The above description is only exemplary of the present application and should not be taken as limiting, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the protection scope of the present application.

Claims (11)

1. A method of memory space allocation, the method comprising:
receiving a data writing request corresponding to a first file, wherein the data writing request carries the data volume to be written of the first file;
determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file;
determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium meets the condition of low residual capacity, and selecting at least one to-be-fused storage file meeting the condition of low utilization rate of storage pages from the files stored in the storage medium except the first file;
and selecting at least one storage page from the idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
2. The method of claim 1, further comprising:
determining that the data volume to be newly added meets a newly allocated storage space condition and the storage space of a storage medium does not meet a low residual capacity condition, selecting at least one storage page from idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing data stored in a termination storage page corresponding to the first file and data to be written in the first file into the storage page to be used.
3. The method of claim 1, wherein determining that the storage space of the storage medium satisfies the low remaining capacity condition comprises:
calculating the occupancy rate of the storage space of the storage medium after the data to be written is written;
and if the occupancy rate of the storage space is greater than a preset threshold value, determining that the storage space of the storage medium meets a low residual capacity condition.
4. The method of claim 1, wherein determining that the storage space of the storage medium satisfies the low remaining capacity condition comprises:
calculating the residual capacity of the storage space of the storage medium after the data to be written is written;
calculating a first number of average occupied storage pages of files stored in the storage medium;
calculating a first product of the capacity of a single memory page and the first number, and dividing the product by the first number to obtain a first numerical value;
acquiring a second number of storage pages occupied by a third file, and calculating a second product of the second number and the capacity of a single storage page;
adding the first value and the second product to obtain a second value;
and if the storage space residual capacity is smaller than the second value, determining that the storage space of the storage medium meets a low residual capacity condition.
5. The method according to any one of claims 1 to 4, wherein the selecting at least one to-be-fused storage file satisfying a storage page low usage condition from among the files stored in the storage medium other than the first file comprises:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is less than one half of the capacity of a single storage page, selecting a to-be-fused storage file from the files stored in the storage medium except the first file, wherein the data volume of a termination storage page corresponding to the to-be-fused storage file is less than one half of the capacity of the single storage page, and only the data of the to-be-fused storage file is stored in the termination storage page corresponding to the to-be-fused storage file.
6. The method according to claim 5, wherein the selecting at least one storage page as a to-be-used storage page from free storage pages of the storage medium according to the amount of the to-be-added data, and writing data stored in a termination storage page corresponding to the first file, data to be written in the first file, and data stored in a termination storage page corresponding to the to-be-merged storage file into the to-be-used storage page, includes:
dividing the sum of the newly added data amount and the data amount stored in the terminated storage page corresponding to the first file by the capacity of a single storage page, and rounding up the division result to obtain a third number of storage pages to be used;
selecting the third number of storage pages from free storage pages of the storage medium as storage pages to be used;
and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the third number of storage pages to be used.
7. The method according to any one of claims 1 to 4, wherein the selecting at least one to-be-fused storage file satisfying a storage page low usage condition from among the files stored in the storage medium other than the first file comprises:
determining the expected data volume of a termination storage page corresponding to the first file under the condition that the data to be written is written into the termination storage page corresponding to the first file;
and if the predicted data volume is larger than one half of the capacity of a single storage page, selecting two storage files to be fused from the files stored in the storage medium except the first file, wherein for each storage file to be fused, the data volume of a termination storage page corresponding to the storage file to be fused is smaller than one half of the capacity of the single storage page, and only the data of the storage file to be fused is stored in the termination storage page corresponding to the storage file to be fused.
8. The method according to claim 7, wherein the amount of data to be newly added selects at least one storage page from free storage pages of the storage medium as a storage page to be used, and writes data stored in a termination storage page corresponding to the first file, data to be written in the first file, and data stored in a termination storage page corresponding to the storage file to be fused into the storage page to be used, including;
dividing the sum of the newly added data amount and the data amount stored in the terminated storage page corresponding to the first file by the capacity of a single storage page, rounding up the division result, and adding one to the rounding result to obtain a fourth number of storage pages to be used;
selecting the fourth number of storage pages from free storage pages of the storage medium as storage pages to be used;
writing the data stored in the storage page to be used corresponding to the storage file to be fused into the storage page to be used;
and writing the data stored in the termination storage page corresponding to the first file and the data to be written in the first file into the unoccupied storage pages to be used in the fourth number of storage pages to be used.
9. An apparatus for storage space allocation, the apparatus comprising:
the device comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving a data writing request corresponding to a first file, and the data writing request carries the data volume to be written of the first file;
the determining module is used for determining the data volume to be newly added of the first file according to the data volume to be written, the current data volume of the first file and the current operation pointer of the first file;
the selection module is used for determining that the data volume to be newly added meets the condition of newly allocated storage space, determining that the storage space of a storage medium meets the condition of low residual capacity, and selecting at least one to-be-fused storage file meeting the condition of low utilization rate of storage pages from files stored in the storage medium except the first file;
and the storage module is used for selecting at least one storage page from idle storage pages of the storage medium as a storage page to be used according to the data volume to be newly added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written in the first file and the data stored in the termination storage page corresponding to the storage file to be fused into the storage page to be used.
10. A file system, wherein the computer device comprises a storage controller and a storage medium, wherein the storage medium has stored therein at least one instruction, which is loaded and executed by the storage controller to implement the operations performed by the method for storage space allocation according to any one of claims 1 to 8.
11. A computer-readable storage medium having stored therein at least one instruction which is loaded and executed by a processor to perform operations performed by a method of memory allocation according to any one of claims 1 to 8.
CN202210752014.3A 2022-06-28 2022-06-28 Storage space allocation method and device, file system and storage medium Pending CN115344537A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210752014.3A CN115344537A (en) 2022-06-28 2022-06-28 Storage space allocation method and device, file system and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210752014.3A CN115344537A (en) 2022-06-28 2022-06-28 Storage space allocation method and device, file system and storage medium

Publications (1)

Publication Number Publication Date
CN115344537A true CN115344537A (en) 2022-11-15

Family

ID=83947511

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210752014.3A Pending CN115344537A (en) 2022-06-28 2022-06-28 Storage space allocation method and device, file system and storage medium

Country Status (1)

Country Link
CN (1) CN115344537A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543970A (en) * 2022-11-29 2022-12-30 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543970A (en) * 2022-11-29 2022-12-30 本原数据(北京)信息技术有限公司 Data page processing method, data page processing device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108304265B (en) Memory management method, device and storage medium
CN108132790B (en) Method, apparatus and computer storage medium for detecting a garbage code
CN110288689B (en) Method and device for rendering electronic map
CN110673944B (en) Method and device for executing task
CN108845777B (en) Method and device for playing frame animation
CN111813322B (en) Storage pool creation method, device, equipment and storage medium
CN115766490A (en) Calibration data acquisition method, calibration data storage method, device and equipment
CN111459410B (en) Memory space allocation method and device, electronic equipment and storage medium
CN115344537A (en) Storage space allocation method and device, file system and storage medium
CN111711841B (en) Image frame playing method, device, terminal and storage medium
CN113301422B (en) Method, terminal and storage medium for acquiring video cover
CN111694521B (en) Method, device and system for storing file
CN110032421B (en) Method and device for managing atlas in memory, terminal and storage medium
CN114594885A (en) Application icon management method, device and equipment and computer readable storage medium
CN109189525B (en) Method, device and equipment for loading sub-page and computer readable storage medium
CN108877845B (en) Song playing method and device
CN110471613B (en) Data storage method, data reading method, device and system
CN111222124B (en) Method, device, equipment and storage medium for using authority distribution
CN111163262B (en) Method, device and system for controlling mobile terminal
CN110533666B (en) Method for obtaining data block size, method and device for processing data
CN113052408B (en) Method and device for community aggregation
CN115379274B (en) Picture-based interaction method and device, electronic equipment and storage medium
CN112329355B (en) Method and device for determining single-well control area, computer equipment and storage medium
CN111246147B (en) Video caching method, device, terminal and storage medium
CN111400544B (en) Video data storage method, device, equipment 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