Method, apparatus, file system and storage medium for storage space allocation

By merging multiple files into the same storage page in a lightweight file system, the problem of low storage space utilization is solved, achieving more efficient storage space utilization.

CN115344537BActive Publication Date: 2026-07-14GUANGDONG MIDEA WHITE HOME APPLIANCE TECH INNOVATION CENT CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210752014.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-28
Publication Date
2026-07-14
Estimated Expiration
2042-06-28

AI Technical Summary

Technical Problem

In existing technologies, the storage space allocation method of lightweight file systems results in low storage space utilization and an inability to effectively utilize the remaining storage space.

Method used

By selecting storage files that meet the low utilization criteria, the data from multiple files is merged and stored in the same storage page, optimizing the storage space allocation method and improving the utilization of storage pages.

Benefits of technology

It improves the utilization rate of storage space, reduces storage space waste, and increases the capacity to store a number of files within the same space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115344537B_ABST
    Figure CN115344537B_ABST
Patent Text Reader

Abstract

The application discloses a method, device, file system and storage medium for storage space allocation, and belongs to the technical field of file systems. The method comprises the following steps: receiving a data write request corresponding to a first file; determining a to-be-added data amount of the first file according to a to-be-written data amount, a current data amount of the first file and a current operation pointer of the first file; determining that the to-be-added data amount meets a new storage space allocation condition, and determining that a storage space meets a low residual capacity condition; selecting at least one to-be-fused storage file meeting a low usage condition of a storage page; selecting at least one idle storage page as a to-be-used storage page; and writing data stored in a terminal storage page corresponding to the first file, to-be-written data of the first file and data stored in a terminal storage page corresponding to the to-be-fused storage file into the to-be-used storage page. The application can provide storage space utilization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of file system technology, and in particular to a method, apparatus, file system, and storage medium for allocating storage space. Background Technology

[0002] Lightweight file systems are widely used in smart homes, smart cars, and other fields. The storage media of a lightweight file system typically has a small storage space and is often used to store configuration files, user settings, etc. The storage media is divided into multiple storage pages, and a file is stored in at least one storage page. When new data needs to be written to a file, if the amount of data in the file after the write exceeds the storage space currently occupied by the file's storage page, new storage space needs to be allocated for the file.

[0003] Currently, when allocating new storage space for a file, a free storage page is typically selected and allocated to that file as its terminating storage page.

[0004] Under the current storage space allocation method, if a storage page can only be occupied by one file, even if a large amount of storage space remains after the page is occupied by one file, it cannot be allocated to other files. This can lead to wasted storage space and low utilization. Summary of the Invention

[0005] This application provides a method, apparatus, file system, and storage medium for storage space allocation, which can solve the problem of low storage space utilization in related technologies. The technical solution is as follows:

[0006] Firstly, a method for allocating storage space is provided, the method comprising:

[0007] Receive a data write request for a corresponding first file, wherein the data write request carries the amount of data to be written to the first file;

[0008] The amount of data to be added to the first file is determined based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file.

[0009] It is determined that the amount of data to be added meets the conditions for newly allocated storage space, and it is determined that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, at least one storage file that meets the condition for low storage page utilization is selected for merging.

[0010] Based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium. 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 are written into the storage page to be used.

[0011] In one possible implementation, the method further includes:

[0012] If it is determined that the amount of data to be added meets the conditions for newly allocated storage space, and it is determined that the storage space of the storage medium does not meet the condition for low remaining capacity, then, based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium, and the data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the storage page to be used.

[0013] In one possible implementation, determining that the storage space of the storage medium satisfies the low remaining capacity condition includes:

[0014] Calculate the storage space occupancy rate of the storage medium after writing the data to be written;

[0015] If the storage space occupancy rate is greater than a preset threshold, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

[0016] In one possible implementation, determining that the storage space of the storage medium satisfies the low remaining capacity condition includes:

[0017] Calculate the remaining storage capacity of the storage medium after writing the data to be written;

[0018] Calculate the first number of storage pages occupied on average by the files stored in the storage medium;

[0019] Calculate the first product of the capacity of a single storage page and the first quantity, and divide the product by the first quantity to obtain a first value;

[0020] Obtain the second number of storage pages occupied by the third file, and calculate the second product of the second number and the capacity of a single storage page;

[0021] Add the first value and the second product to obtain the second value;

[0022] If the remaining capacity of the storage space is less than the second value, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

[0023] In one possible implementation, selecting at least one storage file to be merged from the files other than the first file stored in the storage medium that satisfies the low storage page utilization condition includes:

[0024] Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file;

[0025] If the expected data volume is less than half the capacity of a single storage page, then a storage file to be merged is selected from the files other than the first file stored in the storage medium, wherein the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

[0026] In one possible implementation, the step of selecting at least one storage page as a storage page to be used from the free storage pages of the storage medium based on the amount of data to be added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written to 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, includes:

[0027] The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page, and the result of the division is rounded up to obtain the third number of storage pages to be used.

[0028] Select the third number of storage pages from the free storage pages of the storage medium as storage pages to be used;

[0029] 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 are written into the third number of storage pages to be used.

[0030] In one possible implementation, selecting at least one storage file to be merged from the files other than the first file stored in the storage medium that satisfies the low storage page utilization condition includes:

[0031] Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file;

[0032] If the expected data volume is greater than half the capacity of a single storage page, then two storage files to be merged are selected from the files other than the first file stored in the storage medium. For each storage file to be merged, the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

[0033] In one possible implementation, based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium, and the data stored in the termination storage page corresponding to the first file, the data to be written to the first file, and the data stored in the termination storage page corresponding to the storage file to be merged are written to the storage page to be used, including;

[0034] The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page. The result of the division is rounded up, and then one is added to the rounded result to obtain the fourth number of storage pages to be used.

[0035] Select the fourth number of storage pages from the free storage pages of the storage medium as storage pages to be used;

[0036] Write the data stored in the termination storage page corresponding to the storage file to be merged into a storage page to be used;

[0037] The data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the unoccupied unused storage pages in the fourth number of unused storage pages.

[0038] Secondly, a storage space allocation apparatus is provided, the apparatus comprising:

[0039] A receiving module is configured to receive a data write request for a corresponding first file, wherein the data write request carries the amount of data to be written in the first file;

[0040] The determining module is used to determine the amount of new data to be added to the first file based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file;

[0041] The selection module is used to determine that the amount of data to be added meets the conditions for newly allocated storage space and to determine that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, at least one storage file to be merged meets the condition for low storage page utilization.

[0042] The storage module is configured to select at least one storage page as a storage page to be used from the free storage pages of the storage medium according to the amount of data to be added, and write the data stored in the termination storage page corresponding to the first file, the data to be written to the first file, and the data stored in the termination storage page corresponding to the storage file to be merged into the storage page.

[0043] In one possible implementation, the selection module further includes:

[0044] If it is determined that the amount of data to be added meets the conditions for newly allocated storage space, and it is determined that the storage space of the storage medium does not meet the condition for low remaining capacity, then, based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium, and the data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the storage page to be used.

[0045] In one possible implementation, the selection module is configured to:

[0046] Calculate the storage space occupancy rate of the storage medium after writing the data to be written;

[0047] If the storage space occupancy rate is greater than a preset threshold, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

[0048] In one possible implementation, the selection module is configured to:

[0049] Calculate the remaining storage capacity of the storage medium after writing the data to be written;

[0050] Calculate the first number of storage pages occupied on average by the files stored in the storage medium;

[0051] Calculate the first product of the capacity of a single storage page and the first quantity, and divide the product by the first quantity to obtain a first value;

[0052] Obtain the second number of storage pages occupied by the third file, and calculate the second product of the second number and the capacity of a single storage page;

[0053] Add the first value and the second product to obtain the second value;

[0054] If the remaining capacity of the storage space is less than the second value, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

[0055] In one possible implementation, the selection module is configured to:

[0056] Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file;

[0057] If the expected data volume is less than half the capacity of a single storage page, then a storage file to be merged is selected from the files other than the first file stored in the storage medium, wherein the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

[0058] In one possible implementation, the storage module is used for:

[0059] The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page, and the result of the division is rounded up to obtain the third number of storage pages to be used.

[0060] Select the third number of storage pages from the free storage pages of the storage medium as storage pages to be used;

[0061] 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 are written into the third number of storage pages to be used.

[0062] In one possible implementation, the selection module is configured to:

[0063] Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file;

[0064] If the expected data volume is greater than half the capacity of a single storage page, then two storage files to be merged are selected from the files other than the first file stored in the storage medium. For each storage file to be merged, the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

[0065] In one possible implementation, the storage module is used for;

[0066] The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page. The result of the division is rounded up, and then one is added to the rounded result to obtain the fourth number of storage pages to be used.

[0067] Select the fourth number of storage pages from the free storage pages of the storage medium as storage pages to be used;

[0068] Write the data stored in the termination storage page corresponding to the storage file to be merged into a storage page to be used;

[0069] The data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the unoccupied unused storage pages in the fourth number of unused storage pages.

[0070] Thirdly, a file system is provided, the computer device including a storage controller and a storage medium, the storage medium storing at least one instruction, the instruction being loaded and executed by the storage controller to perform the operations performed by the storage space allocation method described in the first aspect above.

[0071] Fourthly, a computer-readable storage medium is provided, the storage medium storing at least one instruction, the instruction being loaded and executed by a processor to perform the operations performed by the storage space allocation method described in the first aspect above.

[0072] Fifthly, a computer program product is provided, the computer program product storing at least one instruction, the instruction being loaded and executed by a processor to perform the operation performed by the storage space allocation method described in the first aspect above.

[0073] The beneficial effects of the technical solutions provided in this application are:

[0074] When new storage space needs to be allocated for the first file, if it is determined that the remaining capacity in the current storage medium is small, at least one storage file that meets the condition of low storage page utilization can be selected for merging. At least one storage page to be used is then determined, and the data stored on the termination page corresponding to the storage file to be merged, the data stored on the termination page of the target file, and the data to be written from the target file are all written together to the newly determined at least one storage page to be used. According to related technologies, since the storage files to be merged are two files, these two files cannot be stored in the same storage page. However, through the above method, the two files can be merged, meaning they may be stored in the same storage page, thus improving the utilization rate of storage pages. Attached Figure Description

[0075] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0076] Figure 1 This is a schematic diagram of the file system provided in an embodiment of this application;

[0077] Figure 2 This is a flowchart of a storage space allocation method provided in an embodiment of this application;

[0078] Figure 3 This is a schematic diagram of the operation pointer provided in this application example;

[0079] Figure 4 These are effect comparison diagrams provided in the embodiments of this application;

[0080] Figure 5 This is a schematic diagram of the storage space allocation device provided in the embodiments of this application;

[0081] Figure 6 This is a schematic diagram of the terminal device structure provided in the embodiments of this application;

[0082] Figure 7 This is a schematic diagram of the computer device structure provided in the embodiments of this application. Detailed Implementation

[0083] To facilitate understanding of the embodiments of this application, the terms involved in the embodiments of this application will be explained below.

[0084] I. Comprehensive Management Page Pool

[0085] The comprehensive management page pool records the number of files stored on the file system's storage medium, as well as the number of free storage pages. Free storage pages are those that do not contain data. Files can also be called nodes.

[0086] II. File Description Pool

[0087] The file description pool is used to record relevant information for each file. This information includes: the amount of data in the file's terminating storage page, the file's priority, the data storage characteristics of the terminating storage page, the number of storage pages occupied by the file, the file's data size, and the file's operation pointers.

[0088] III. Termination of Storage Page

[0089] This refers to the last storage page occupied by the file. For example, if a file has 5KB of data and each storage page has a capacity of 2KB, then the first two storage pages occupied by the file each have a data size of 2KB, while the last storage page has a data size of 1KB. This 1KB storage page is the terminating storage page.

[0090] The data size of the terminating page corresponding to any file represents the amount of data of that file stored in that terminating page. For example, if a page is both the terminating page for file A and the terminating page for file B, then "the data size of the terminating page for file A" represents the amount of data of file A stored in that page, and "the data size of the terminating page for file B" represents the amount of data of file B stored in that page.

[0091] IV. File Priority

[0092] File priority is related to how frequently a file is accessed. If a file is accessed frequently, its priority is low; conversely, if a file is accessed infrequently, its priority is high.

[0093] V. Data storage characteristics of terminating storage pages

[0094] In the embodiments of this application, data storage characteristics can be divided into three types. Characteristic 1: only the top half of the page is stored; Characteristic 2: only the bottom half of the page is stored; Characteristic 3: the entire page is stored.

[0095] For any file's corresponding terminating storage page, feature one indicates that the top half of the terminating storage page is used to store the file's data, feature two indicates that the bottom half of the terminating storage page is used to store the file's data, and feature three indicates that the entire terminating storage page is used to store the file's data.

[0096] VI. File System Operations

[0097] File operations in a file system mainly include creation, deletion, writing, and reading. This application's embodiments primarily focus on the writing operation.

[0098] The storage space allocation method provided in this application can be applied to file systems, such as lightweight file systems in smart home devices and smart car devices. See also... Figure 1 The file system 100 may include a storage controller 110 and a storage medium 120. The storage controller 110 may be a processor (central processing unit, CPU), and the storage medium 120 may be flash memory.

[0099] After receiving an operation request for a file, the storage controller 110 performs corresponding operations on the file in the storage medium 120 according to the operation request. In the case of a write operation, the storage space allocation method provided in this embodiment can be used to allocate storage space for the data to be written.

[0100] Figure 2 This is a flowchart illustrating a method for allocating storage space according to an embodiment of this application. See also... Figure 2 The processing flow of this method may include the following steps:

[0101] Step 201: Receive the data write request for the corresponding first file.

[0102] The data write request carries the amount of data to be written to the first file.

[0103] In implementation, when the storage controller receives an operation request for the first file, it first obtains the operation attributes carried in the operation request. If the operation attribute is determined to be a write operation, then the amount of data to be written carried in the operation request is obtained. Here, when the operation attribute is a write operation, the operation request can also be referred to as a data write request.

[0104] Step 202: Determine the amount of data to be added to the first file based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file.

[0105] In implementation, the storage controller can first obtain the current data volume and the current operation pointer of the first file, which can be specifically obtained in the aforementioned node description. Then, based on the current data volume, the current operation pointer, and the amount of data to be written, the amount of data to be added to the first file is determined.

[0106] The formula for calculating the amount of new data to be added to the first file can be as follows:

[0107] len = p + nl

[0108] Where len is the amount of data to be added to the first file, p is the amount of data in the first file from the first byte to the point before the operation pointer, n is the amount of data to be written, and l is the current amount of data in the first file.

[0109] For ease of understanding, see Figure 3 This shows the relationship between the amount of data to be added to the first file, the current operation pointer, the amount of data to be written, and the current amount of data in the first file.

[0110] Step 203: Determine that the amount of data to be added meets the conditions for newly allocated storage space, and determine that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, select at least one storage file that meets the condition for low storage page utilization.

[0111] In implementation, the storage controller determines whether the amount of data to be added to the first file is greater than 0. If the amount of data to be added to the first file is not greater than 0, it is determined that the amount of data to be added does not meet the conditions for allocating new storage space. If the amount of data to be added to the first file is greater than 0, it is determined that the amount of data to be added meets the conditions for allocating new storage space. The two cases are explained below:

[0112] Scenario 1: The amount of data to be added does not meet the conditions for allocating new storage space.

[0113] In this case, there is no need to allocate new storage space for the first file. Furthermore, the priority and current operation pointer of the first file in the node description pool can be updated. The specific update method is as follows:

[0114] Priority update:

[0115] Lower the priority of the first file. Assuming the priority of the first file is a1, the priority of the first file after the update is: 1 / (1 / a1+1).

[0116] Update the operation pointer:

[0117] Assuming the current operation pointer of the first file is p, the updated operation pointer will be p+n, where n is the amount of data to be written.

[0118] Scenario 2: The amount of new data to be added meets the conditions for newly allocated storage space.

[0119] In this case, it indicates that new storage space needs to be allocated for the first file. Next, it is determined whether the storage space on the storage medium meets the low remaining capacity condition. There are several methods for determining this; two are described below.

[0120] Method 1: Static Threshold Method

[0121] The storage space utilization rate of the storage medium is calculated when data is being written. If this utilization rate exceeds a preset threshold, it can be determined whether the storage medium meets the low remaining capacity condition. The formula for calculating the storage space utilization rate is as follows:

[0122]

[0123] Where r is the storage space occupancy rate, len is the amount of new data to be added to the first file, N is the number of storage pages in the storage medium, x is the number of free storage pages, and k is the capacity of a single storage page.

[0124] Method 2: Dynamic Threshold Method

[0125] Calculate the remaining storage capacity of the storage medium after writing the data to be written. The formula for calculating the remaining storage capacity is as follows:

[0126] s = x * k - len, where s is the remaining storage space, len is the amount of data to be added to the first file, x is the number of free storage pages, and k is the capacity of a single storage page.

[0127] Next, the storage space reference threshold is calculated. The formula for calculating the storage space reference threshold can be as follows:

[0128]

[0129] Where c is the storage space reference threshold, 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 that occupies the most storage pages in the storage medium.

[0130] Next, it is determined whether the remaining storage space capacity is less than the storage space reference threshold. If the remaining storage space capacity is less than the storage space reference threshold, then the storage medium's storage space is determined to meet the low remaining capacity condition. If the remaining storage space capacity is not less than the storage space reference threshold, then the storage medium's storage space is determined not to meet the low remaining capacity condition. The following sections explain the cases where the low remaining capacity condition is met and those where it is not met.

[0131] Scenario 1: The storage space of the storage medium does not meet the low remaining capacity condition.

[0132] In this case, based on the amount of data to be added, a storage page to be used is selected from the free storage pages of the storage medium. Then, the data stored in the termination storage page corresponding to the first file and the data to be written to the first file are written to the storage page to be used.

[0133] The following explains "selecting storage pages to be used from the free storage pages of the storage medium based on the amount of data to be added".

[0134] Calculate the required number of storage pages to be used based on the amount of data to be added and the amount of data in the final storage page of the first file. The calculation formula can be as follows:

[0135]

[0136] Where z is the number of storage pages needed, ceil() is the rounding up operation, and len is the amount of new data to be added to the first file, b. a is the data size of the final storage page of the first file, and k is the capacity of a single storage page.

[0137] Furthermore, in this case, the following can also be updated in the node description pool: the data size of the terminating storage page corresponding to the first file, 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. The number of free storage pages in the comprehensive management page pool can also be updated. The specific update method is as follows:

[0138] Update the data size of the terminating storage page corresponding to the first file:

[0139] Assuming the data size of the terminating storage page corresponding to the first file is a2, then the data size of the terminating storage page corresponding to the first file after the update is: (len+a2)%k, where len is the amount of data to be added to the first file, % is the modulo operation, and k is the capacity of a single storage page.

[0140] Priority update for the first file:

[0141] Lower the priority of the first file. Assuming the priority of the first file is a1, the priority of the first file after the update is: 1 / (1 / a1+1).

[0142] Update the storage characteristics of the terminating storage page corresponding to the first file:

[0143] Update the storage characteristics of the termination storage page corresponding to the first file to the aforementioned characteristic three.

[0144] Update the number of storage pages occupied by the first file:

[0145] Assuming the first file occupies a3 memory pages, then the number of memory pages occupied by the first file after the update is:

[0146] Update the data volume of the first file:

[0147] Assuming the data size of the first file is a4, then the data size of the updated first file is: a4 + len.

[0148] Update the current operation pointer for the first file:

[0149] Assuming the current operation pointer of the first file is p, the updated operation pointer will be p+n, where n is the amount of data to be written.

[0150] Update the number of free storage pages:

[0151] Assuming the number of free storage pages is x, then the updated number of free storage pages is:

[0152] Scenario 2: The storage space of the storage medium meets the condition of low remaining capacity.

[0153] In this case, the following steps can be taken:

[0154] Determine the estimated data volume of the termination page corresponding to the first file when the data to be written is written to it. The estimated data volume is: (len + a2) % k, where % is the modulo operation, k is the capacity of a single storage page, len is the amount of data to be added to the first file, and a2 is the current data volume of the termination page corresponding to the first file.

[0155] Then, it is determined whether the expected data size of the terminating storage page is less than half the capacity of a single storage page. If the expected data size of the terminating storage page is less than half the capacity of a single storage page, single-page merging is executed. If the expected data size of the terminating storage page is not less than half the capacity of a single storage page, multi-page merging is executed. The following sections explain single-page merging and multi-page merging separately:

[0156] I. Single-page converged storage

[0157] First, the file description pool is traversed, and files are evaluated sequentially according to their priority from low to high. The evaluation is continued until a suitable file for fusion is identified, at which point the evaluation process stops. The file evaluation method is as follows:

[0158] Determine if the data size of the terminating storage page corresponding to the file is less than half the capacity of a single storage page, and if the storage characteristic of the corresponding terminating storage page is characteristic three. If the data size of the terminating storage page corresponding to the file is less than half the capacity of a single storage page, and the storage characteristic of the corresponding terminating storage page is characteristic three, then the file is selected as the storage file to be merged.

[0159] Once the files to be merged and stored are identified, the merging and storage can be performed. The specific process is explained in step 204 below.

[0160] II. Multi-page converged storage

[0161] First, the file description pool is traversed, and files are evaluated sequentially according to their priority from low to high. The evaluation is continued until two files are identified as potential storage files for fusion, at which point the evaluation stops. The file evaluation method is as follows:

[0162] Determine if the data size of the terminating storage page corresponding to the file is less than half the capacity of a single storage page, and if the storage characteristic of the corresponding terminating storage page is characteristic three. If the data size of the terminating storage page corresponding to the file is less than half the capacity of a single storage page, and the storage characteristic of the corresponding terminating storage page is characteristic three, then the file is selected as the storage file to be merged.

[0163] Once the two files to be merged are identified, the merging process can be performed. The specific steps are explained in step 204 below.

[0164] Step 204: Based on the amount of data to be added, select at least one storage page from the free storage pages of the storage medium as the storage page to be used, 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.

[0165] In implementation, the processing of step 204 differs for single-page converged storage and multi-page converged storage. The following explains the processing of step 204 for single-page converged storage and multi-page converged storage respectively:

[0166] I. Single-page converged storage

[0167] First, based on the target number of memory pages to be used, the calculation is performed:

[0168] Then, based on the wear leveling algorithm, a target number of storage pages are selected from the free storage pages as the storage pages to be used. The data stored in the terminating storage page corresponding to the first file, the data to be written to the first file, and the data stored in the terminating storage page corresponding to the storage file to be merged are written to the storage pages to be used.

[0169] For example, if the target quantity 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 can be written to the upper half of the storage page to be used, and the data stored in the termination storage page corresponding to the storage file to be merged can be written to the lower half of the storage page to be used.

[0170] In addition, the following can be updated in the node description pool: the data volume of the terminating storage page corresponding to the first file, 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 volume of the first file, and the current operation pointer of the first file. The storage characteristics of the terminating storage page corresponding to the storage file to be merged can also be updated. The number of free storage pages in the comprehensive management page pool can also be updated. The specific update methods are as follows:

[0171] Update the data size of the terminating storage page corresponding to the first file:

[0172] Assuming the data size of the terminating storage page corresponding to the first file is a2, then the data size of the terminating storage page corresponding to the first file after the update is: (len+a2)%k, where len is the amount of data to be added to the first file, % is the modulo operation, and k is the capacity of a single storage page.

[0173] Priority update for the first file:

[0174] Lower the priority of the first file. Assuming the priority of the first file is a1, the priority of the first file after the update is: 1 / (1 / a1+1).

[0175] Update the storage characteristics of the terminating storage page corresponding to the first file:

[0176] Update the storage characteristics of the terminating storage page corresponding to the first file to the aforementioned characteristic one (or characteristic two). Specifically, if, after the fused storage is completed, the upper half of the terminating storage page corresponding to the first file is used to store the data of the first file, then this section is updated to characteristic one; if, after the fused storage is completed, the lower half of the terminating storage page corresponding to the first file is used to store the data of the first file, then this section is updated to characteristic two.

[0177] Update the number of storage pages occupied by the first file:

[0178] Assuming the first file occupies a3 memory pages, then the number of memory pages occupied by the first file after the update is: Floor() represents the floor function.

[0179] Update the data volume of the first file:

[0180] Assuming the data size of the first file is a4, then the data size of the updated first file is: a4 + len.

[0181] Update the current operation pointer for the first file:

[0182] Assuming the current operation pointer of the first file is p, the updated operation pointer will be p+n, where n is the amount of data to be written.

[0183] Update the storage characteristics of the terminating storage page corresponding to the file to be merged:

[0184] Update the storage characteristics of the terminating storage page corresponding to the storage file to be merged to the aforementioned characteristic one (or characteristic two). Specifically, if the upper half of the terminating storage page corresponding to the storage file to be merged is used to store the data of the storage file to be merged after the storage merge is completed, then update to characteristic one here; if the lower half of the terminating storage page corresponding to the storage file to be merged is used to store the data of the storage file to be merged after the storage merge is completed, then update to characteristic two here.

[0185] Update the number of free storage pages:

[0186] Assuming the number of free storage pages is x, then the updated number of free storage pages is:

[0187] II. Multi-page converged storage

[0188] First, based on the target number of memory pages to be used, the calculation is performed:

[0189] Then, according to the wear leveling algorithm, a target number of storage pages are selected from the free storage pages as the storage pages to be used. The data stored in the termination storage pages corresponding to the two storage files to be merged are written to a single storage page to be used. The data stored in the termination storage page corresponding to the first file and the data to be written from the first file are written to an unoccupied storage page within the target number of storage pages to be used.

[0190] For example, if the target quantity is 2, and the storage files to be merged are storage file A and storage file B, then we can first select a storage page to be used. The data stored on the termination page corresponding to storage file A is written to the top half of this selected storage page, and the data stored on the termination page corresponding to storage file B is written to the bottom half of this selected storage page. Then, the data stored on the termination page corresponding to the first file and the data to be written to the first file are written to the other storage page to be used.

[0191] In addition, updates can be made to the data volume 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 volume of the first file, and the current operation pointer of the first file. The storage characteristics of the terminating storage pages corresponding to the two storage files to be merged can also be updated. The number of free storage pages in the integrated management page pool can also be updated. The specific update method is the same as the update method in single-page merged storage, and will not be elaborated here.

[0192] In the scheme shown in the embodiments of this application, when new storage space needs to be allocated for the first file, if it is determined that the remaining capacity in the current storage medium is small, at least one storage file that meets the condition of low storage page utilization can be selected for merging. At least one storage page to be used is determined, and the data stored in the termination storage page corresponding to the storage file to be merged, the data stored in the termination storage page of the target file, and the data to be written from the target file are written together into the newly determined at least one storage page to be used. If processed according to related technologies, since the storage files to be merged are two files, these two files cannot be stored in the same storage page. However, through the above method, the two files can be merged for storage, meaning the two files may be stored in the same storage page, thus improving the utilization rate of the storage page.

[0193] See Figure 4 This illustrates the relationship between the number of stored files and the storage space occupied when the storage space allocation method provided in the embodiments of this application is used. For the purpose of comparison, Figure 4 The document also illustrates the relationship between the number of stored files and storage space usage when using storage space allocation methods in related technologies. A comparison clearly shows that, with the same storage space, the storage space allocation method provided in this application can store more files, meaning higher storage space utilization.

[0194] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.

[0195] Based on the same technical concept, embodiments of this application also provide a storage space allocation device, such as... Figure 5 As shown, the device includes: a receiving module 410, a determining module 420, a selecting module 430, and a storage module 440, wherein:

[0196] The receiving module 410 is configured to receive a data write request for a corresponding first file, wherein the data write request carries the amount of data to be written to the first file; specifically, it can implement... Figure 2 The receiving function in step 201 shown.

[0197] The determining module 420 is used to determine the amount of new data to be added to the first file based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file; specifically, it can implement... Figure 2 The "determine" function in step 202 shown.

[0198] Selection module 430 is used to determine that the amount of data to be added meets the conditions for newly allocated storage space, and to determine that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, at least one file that meets the condition for low storage page utilization is selected for merging. Specifically, this can be implemented as follows: Figure 2 The selection function in step 203 shown.

[0199] Storage module 440 is configured to select at least one storage page as a storage page to be used from the free storage pages of the storage medium according to the amount of data to be added, and write the data stored in the termination storage page corresponding to the first file, the data to be written to 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. Specifically, this can be implemented as follows: Figure 2 The write function in step 204 shown.

[0200] When new storage space needs to be allocated for the first file, if it is determined that the remaining capacity in the current storage medium is small, at least one storage file that meets the condition of low storage page utilization can be selected for merging. At least one storage page to be used is then determined, and the data stored on the termination page corresponding to the storage file to be merged, the data stored on the termination page of the target file, and the data to be written from the target file are all written together to the newly determined at least one storage page to be used. According to related technologies, since the storage files to be merged are two files, these two files cannot be stored in the same storage page. However, through the above method, the two files can be merged, meaning they may be stored in the same storage page, thus improving the utilization rate of storage pages.

[0201] It should be noted that the storage space allocation device provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functional allocation can be completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the storage space allocation device and the storage space allocation method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.

[0202] Figure 6This illustration shows a structural block diagram of an electronic device 500 provided in an exemplary embodiment of this application. The electronic device 500 may be a portable mobile terminal, such as a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. The electronic device 500 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.

[0203] Typically, electronic device 500 includes a processor 501 and a memory 502. The processor 510 is equivalent to... Figure 1 The memory controller in the memory 502 is equivalent to Figure 1 The storage medium in the middle.

[0204] Processor 501 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 501 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 501 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 501 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 501 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0205] 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 and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in memory 502 is used to store at least one instruction, which is executed by processor 501 to implement the storage space allocation method provided in the method embodiments of this application.

[0206] In some embodiments, the electronic device 500 may optionally include a peripheral device interface 503 and at least one peripheral device. The processor 501, memory 502, and peripheral device interface 503 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 503 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of the following: a radio frequency circuit 504, a display screen 505, a camera assembly 506, an audio circuit 507, a positioning assembly 508, and a power supply 509.

[0207] Peripheral device interface 503 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 501 and memory 502. In some embodiments, processor 501, memory 502 and peripheral device interface 503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 501, memory 502 and peripheral device interface 503 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.

[0208] The radio frequency (RF) circuit 504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 504 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 504 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF 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 user identity module card, etc. The RF circuit 504 can communicate with other terminals through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: the World Wide Web, metropolitan area networks, intranets, various 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 also include circuitry related to NFC (Near Field Communication), which is not limited in this application.

[0209] Display screen 505 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 505 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 501 for processing. In this case, display screen 505 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 505, disposed on the front panel of electronic device 500; in other embodiments, there may be at least two display screens, disposed on different surfaces of electronic device 500 or in a folded design; in still other embodiments, display screen 505 may be a flexible display screen, disposed on a curved or folded surface of electronic device 500. Furthermore, display screen 505 may be configured as a non-rectangular irregular shape, i.e., a non-rectangular screen. Display screen 505 may be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).

[0210] The camera assembly 506 is used to acquire images or videos. Optionally, the camera assembly 506 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 506 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm-light flash and a cool-light flash, which can be used for light compensation at different color temperatures.

[0211] The audio circuit 507 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting them into electrical signals that are input to the processor 501 for processing, or to the radio frequency circuit 504 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each located in a different part of the electronic device 500. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 501 or the radio frequency circuit 504 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 507 may also include a headphone jack.

[0212] Positioning component 508 is used to locate the current geographic location of electronic device 500 for navigation or LBS (Location Based Service). Positioning component 508 can be a positioning component based on the US GPS (Global Positioning System), China's BeiDou system, or Russia's Galileo system.

[0213] Power supply 509 is used to supply power to various components in electronic device 500. Power supply 509 can be AC ​​power, DC power, a disposable battery, or a rechargeable battery. When power supply 509 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, and a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.

[0214] In some embodiments, the electronic device 500 further includes one or more sensors 510. The one or more sensors 510 include, but are not limited to: an accelerometer 511, a gyroscope 512, a pressure sensor 513, a fingerprint sensor 514, an optical sensor 515, and a proximity sensor 516.

[0215] Accelerometer 511 can detect the magnitude of acceleration on the three coordinate axes of a coordinate system established by electronic device 500. For example, accelerometer 511 can be used to detect the components of gravitational acceleration on the three coordinate axes. Processor 501 can control display screen 505 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 511. Accelerometer 511 can also be used for games or for acquiring user motion data.

[0216] The gyroscope sensor 512 can detect the orientation and rotation angle of the electronic device 500. The gyroscope sensor 512, in conjunction with the accelerometer sensor 511, can collect 3D motion data from the user on the electronic device 500. Based on the data collected by the gyroscope sensor 512, the processor 501 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.

[0217] The pressure sensor 513 can be disposed on the side bezel of the electronic device 500 and / or the lower layer of the display screen 505. When the pressure sensor 513 is disposed on the side bezel of the electronic device 500, it can detect the user's grip signal on the electronic device 500, and the processor 501 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 513. When the pressure sensor 513 is disposed on the lower layer of the display screen 505, the processor 501 can control the operable controls on the UI interface based on the user's pressure operation on the display screen 505. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.

[0218] The fingerprint sensor 514 is used to collect a user's fingerprint. The processor 501 identifies the user based on the fingerprint collected by the fingerprint sensor 514, or vice versa. When the user's identity is verified as trusted, the processor 501 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 514 can be located on the front, back, or side of the electronic device 500. When the electronic device 500 has a physical button or manufacturer logo, the fingerprint sensor 514 can be integrated with the physical button or manufacturer logo.

[0219] An optical sensor 515 is used to collect ambient light intensity. In one embodiment, the processor 501 can 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 decreased. In another embodiment, the processor 501 can also dynamically adjust the shooting parameters of the camera assembly 506 based on the ambient light intensity collected by the optical sensor 515.

[0220] A proximity sensor 516, also known as a distance sensor, is typically mounted on the front panel of an electronic device 500. The proximity sensor 516 is used to detect 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 of the electronic device 500 is gradually decreasing, the processor 501 controls the display screen 505 to switch from a screen-on state to a screen-off state; when the proximity sensor 516 detects that the distance between the user and the front of the electronic device 500 is gradually increasing, the processor 501 controls the display screen 505 to switch from a screen-off state to a screen-on state.

[0221] Those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the electronic device 500, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0222] Figure 7 This is a schematic diagram of the structure of a computer device 600 provided in an embodiment of this application. The computer device 600 can vary significantly due to differences in configuration or performance, and may include one or more processors 601 and one or more memories 602. The memory 602 stores at least one instruction, which is loaded and executed by the processor 601 to implement the methods provided in the above-described method embodiments. Of course, the server may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The computer device may also include other components for implementing device functions, which will not be elaborated upon here.

[0223] In an exemplary embodiment, a computer-readable storage medium is also provided, such as a memory including instructions that can be executed by a processor in a terminal to perform the storage space allocation method described above. This computer-readable storage medium may be non-transitory. For example, the computer-readable storage medium may be ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (CompactDisc Read-Only Memory), magnetic tape, floppy disk, and optical data storage devices, etc.

[0224] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals (including but not limited to signals transmitted between user terminals and other devices) involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the documents involved in this application were all obtained under full authorization.

[0225] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0226] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for allocating storage space, characterized in that, The method includes: Receive a data write request for a corresponding first file, wherein the data write request carries the amount of data to be written to the first file; The amount of data to be added to the first file is determined based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file. It is determined that the amount of data to be added meets the conditions for newly allocated storage space, and it is determined that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, at least one storage file that meets the condition for low storage page utilization is selected for merging. Based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium. 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 are written into the storage page to be used.

2. The method according to claim 1, characterized in that, The method further includes: If it is determined that the amount of data to be added meets the conditions for newly allocated storage space, and it is determined that the storage space of the storage medium does not meet the condition for low remaining capacity, then, based on the amount of data to be added, at least one storage page is selected as the storage page to be used from the free storage pages of the storage medium, and the data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the storage page to be used.

3. The method according to claim 1, characterized in that, The determination that the storage space of the storage medium satisfies the low remaining capacity condition includes: Calculate the storage space occupancy rate of the storage medium after writing the data to be written; If the storage space occupancy rate is greater than a preset threshold, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

4. The method according to claim 1, characterized in that, The determination that the storage space of the storage medium satisfies the low remaining capacity condition includes: Calculate the remaining storage capacity of the storage medium after writing the data to be written; Calculate the first number of storage pages occupied on average by the files stored in the storage medium; Calculate the first product of the capacity of a single storage page and the first number; Obtain the second number of storage pages occupied by the third file, and calculate the second product of the second number and the capacity of a single storage page; Add the first product and the second product to obtain the second value; If the remaining capacity of the storage space is less than the second value, then the storage space of the storage medium is determined to meet the low remaining capacity condition.

5. The method according to any one of claims 1-4, characterized in that, Among the files stored in the storage medium other than the first file, at least one storage file that meets the low storage page utilization condition is selected for fusion, including: Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file; If the expected data volume is less than half the capacity of a single storage page, then a storage file to be merged is selected from the files other than the first file stored in the storage medium, wherein the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

6. The method according to claim 5, characterized in that, The step of selecting at least one storage page as a storage page to be used from the free storage pages of the storage medium according to the amount of data to be added, and writing the data stored in the termination storage page corresponding to the first file, the data to be written to 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 includes: The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page, and the result of the division is rounded up to obtain the third number of storage pages to be used. Select the third number of storage pages from the free storage pages of the storage medium as storage pages to be used; 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 are written into the third number of storage pages to be used.

7. The method according to any one of claims 1-4, characterized in that, Among the files stored in the storage medium other than the first file, at least one storage file that meets the low storage page utilization condition is selected for fusion, including: Determine the expected data volume of the termination storage page corresponding to the first file when the data to be written is written to the termination storage page corresponding to the first file; If the expected data volume is greater than half the capacity of a single storage page, then two storage files to be merged are selected from the files other than the first file stored in the storage medium. For each storage file to be merged, the data volume of the terminating storage page corresponding to the storage file to be merged is less than half the capacity of a single storage page, and the terminating storage page corresponding to the storage file to be merged only stores the data of the storage file to be merged.

8. The method according to claim 7, characterized in that, The amount of data to be added is determined by selecting at least one storage page from the free storage pages of the storage medium as the storage page 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 merged into the storage page to be used. The sum of the newly added data and the data stored in the termination storage page corresponding to the first file is divided by the capacity of a single storage page. The result of the division is rounded up, and then one is added to the rounded result to obtain the fourth number of storage pages to be used. Select the fourth number of storage pages from the free storage pages of the storage medium as storage pages to be used; Write the data stored in the termination storage page corresponding to the storage file to be merged into a storage page to be used; The data stored in the termination storage page corresponding to the first file and the data to be written in the first file are written to the unoccupied unused storage pages in the fourth number of unused storage pages.

9. A storage space allocation device, characterized in that, The device includes: A receiving module is configured to receive a data write request for a corresponding first file, wherein the data write request carries the amount of data to be written in the first file; The determining module is used to determine the amount of new data to be added to the first file based on the amount of data to be written, the current amount of data in the first file, and the current operation pointer of the first file; The selection module is used to determine that the amount of data to be added meets the conditions for newly allocated storage space and to determine that the storage space of the storage medium meets the condition for low remaining capacity. Among the files stored in the storage medium other than the first file, at least one storage file to be merged meets the condition for low storage page utilization. The storage module is configured to select at least one storage page as a storage page to be used from the free storage pages of the storage medium according to the amount of data to be added, and write the data stored in the termination storage page corresponding to the first file, the data to be written to the first file, and the data stored in the termination storage page corresponding to the storage file to be merged into the storage page.

10. A file system, characterized in that, The file system includes a storage controller and a storage medium, wherein the storage medium stores at least one instruction, which is loaded and executed by the storage controller to perform the operation performed by the storage space allocation method as described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, which is loaded and executed by a processor to perform the operation performed by the storage space allocation method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • File storage method and device

    CN106294603A

  • NandFlash-based sequential storage method, electronic equipment and storage medium

    CN113625964A