Method and medium for storing massive fragmented files in super large files using memory mapping

By using memory mapped file technology and bitmap algorithms in the traffic management business management platform, the problems of too many INODEs and frequent disk IO in traditional operating systems are solved, enabling efficient storage and rapid deletion of massive image data, improving storage performance and reducing cost.

CN114564442BActive Publication Date: 2024-10-15ANHUI BAICHENG HUITONG TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111679208.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-31
Publication Date
2024-10-15
Estimated Expiration
2041-12-31

AI Technical Summary

Technical Problem

In the traffic management business management platform, when the traditional operating system is used to store a large amount of picture data, it results in an excessive number of INODEs, wasting space, and frequent deletion operations, which leads to a decrease in disk performance and lifespan.

Method used

Adopt a method based on memory mapping, use bitmap algorithm to record the usage status of data blocks, use memory mapped file technology to quickly save and read image data, reduce the number of INODE, and delete it through marking method when the file life cycle reaches, reducing disk consumption IO operations.

Benefits of technology

It effectively reduces the number of INODEs, improves file saving and reading efficiency, reduces disk IO operations, extends disk life, and solves storage cost and performance bottlenecks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114564442B_ABST
    Figure CN114564442B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and medium for storing massive fragmented files in a super-large file based on memory mapping, and the method includes S1 creating and initializing a data volume; S2 when image data needs to be stored, a bitmap algorithm is used to find an idle data block, and the memory mapping file technology is used to quickly write the image information into the data block; S3 when a file needs to be read, the data block index stored in the file is parsed according to the requested path, and the data block position is found in the data block index; at the same time, the memory mapping file technology is used to map the data block content to the memory, and the program reads the memory file data and sends it to the client; S4 according to the life cycle of the file in different businesses, when the life cycle arrives, only the use status of the data block is modified. The present invention can be used to reduce the number of INODE description files for each image in the original operating system, and when the life cycle of the image arrives, the image is quickly deleted, and the high-concurrency disk IO is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of operating system file processing, and in particular to a method and a medium for storing massive fragmented files in an ultra-large file based on memory mapping. Background Art

[0002] In the traffic management platform, it is necessary to connect to the vehicle violation data generated by the front-end equipment (electric police, checkpoints, etc.). Each piece of data needs to save the current vehicle passing and illegal picture data. The size of such pictures is about (500kb to 2M). In the traditional practice, Windows or Linux operating system is used to mount IPSAN network hardware, and the directory file management mechanism of the operating system is used to achieve a large number of picture storage. In actual operation, due to the large number of pictures and too many files, the operating system needs to establish INODE data information for each file, which requires a large number of INODEs, resulting in too much waste of space. In addition, due to the particularity of the traffic police industry, there is a certain storage period for vehicle passing and illegal data. For picture data that reaches the storage period, due to the large number of files, a large number of deletion operations will inevitably cause high IO operations on the disk, thereby affecting the disk performance and life. Therefore, how to efficiently store pictures in traffic police business, improve performance bottlenecks, and reduce storage costs has become an urgent problem to be solved in the traffic police industry. Summary of the invention

[0003] The present invention provides a method and medium for storing a large number of fragmented files in a super-large file based on memory mapping, which can at least solve one of the technical problems in the background technology.

[0004] To achieve the above object, the present invention adopts the following technical solutions:

[0005] A method for storing a large number of fragmented files in a super-large file based on memory mapping, wherein a computer device performs the following steps:

[0006] S1. Create and initialize the data volume. This part saves the specific file content in the form of data blocks and uses a bitmap algorithm to record the usage status of each data block.

[0007] S2. Data preservation: When image data needs to be saved, the bitmap algorithm is used to quickly find free data blocks, and the memory-mapped file technology is used to quickly write the image information into the data block. Because the solution uses memory-mapped file technology, the operation data is equivalent to the operation memory, which greatly improves the file storage efficiency and realizes zero copy of file data.

[0008] S3, file reading. When a file needs to be read, the solution quickly parses the data block index saved in the file according to the requested path, and finds the data block location in the data block index. At the same time, the memory-mapped file technology is used to map the data block content to the memory, and the program reads the memory file data and sends it to the client. In this module, the memory-mapped file technology is also used, and the data operation is like operating the memory, which improves the file download speed.

[0009] S4. File deletion. Due to the limitation of business scenarios (traffic police business), the system does not provide manual data deletion function. File deletion will be based on the life cycle of files in different businesses. When the life cycle is reached, the system will not operate the specific file data, but only modify the usage status of the data block, thereby reducing a large amount of disk IO. Improve file deletion and disk performance.

[0010] S1 is the basis, and S2 to S4 are different business triggers.

[0011] On the other hand, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the above method.

[0012] On the other hand, the present invention further discloses a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above method.

[0013] It can be seen from the above technical scheme that the method of the present invention for saving massive fragmented files in a super-large file based on memory mapping can solve how to reduce the number of INODE description files for each picture in the original operating system, and how to quickly delete the picture when the life cycle (expiration) of the picture is reached, while reducing high-concurrency disk IO; specifically, the system of the present invention uses super-large files to store pictures, and each picture will be recorded in a super-large starting position and offset when it is saved, thereby reducing the INODE of the file system; for the disk IO caused by the deletion of a large number of picture files, a marking method is used in the scheme to mark the picture deletion operation, thereby solving the concurrent deletion operation of the disk. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 It is a flowchart of the present invention;

[0015] Figure 2 is a schematic diagram of mapping a bitmap and a volume data block according to an embodiment of the present invention;

[0016] Figure 3 It is a schematic diagram of the volume data block structure of an embodiment of the present invention. DETAILED DESCRIPTION

[0017] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.

[0018] like Figure 1 As shown, the method for saving a large number of fragmented files in a super-large file based on memory mapping described in this embodiment includes the following steps:

[0019] S1. Create and initialize the data volume. This part saves the specific file content in the form of data blocks and uses a bitmap algorithm to record the usage status of each data block.

[0020] S2. Data preservation: When image data needs to be saved, the bitmap algorithm is used to quickly find free data blocks, and the memory-mapped file technology is used to quickly write the image information into the data block. Because the solution uses memory-mapped file technology, the operation data is equivalent to the operation memory, which greatly improves the file storage efficiency and realizes zero copy of file data.

[0021] S3, file reading. When a file needs to be read, the solution quickly parses the data block index saved in the file according to the requested path, and finds the data block location in the data block index. At the same time, the memory-mapped file technology is used to map the data block content to the memory, and the program reads the memory file data and sends it to the client. In this module, the memory-mapped file technology is also used, and the data operation is like operating the memory, which improves the file download speed.

[0022] S4. File deletion. Due to the limitation of business scenarios (traffic police business), the system does not provide manual data deletion function. File deletion will be based on the life cycle of files in different businesses. When the life cycle is reached, the system will not operate the specific file data, but only modify the usage status of the data block, thereby reducing a large amount of disk IO. Improve file deletion and disk performance.

[0023] S1 is the basis, and S2 to S4 are different business triggers.

[0024] The entire specific operation process of the embodiment of the present invention includes the following steps:

[0025] S1. Initialization and volume creation

[0026] a) The initialization operation needs to specify the system disk, data disk (multiple), data block size (BLOCK_SIZE), data volume (VOLUME), and data volume data expiration time (EXP_TIME);

[0027] b) Create a metadata bitmap (INODE_BITMAP) and a data volume based on the entered parameter information. One data volume corresponds to one metadata bitmap. The bitmap data is saved in the system disk. The bitmap size is the volume size / block size. The data block size is the same in the same volume.

[0028] c) Volume will be formatted, and the formatting will eventually generate the corresponding INODE_BITMAP information according to the data block size, such as Figure 2 shown.

[0029] S2. Data preservation

[0030] like Figure 3 As shown, the metadata area stores data-related attributes, such as file name, storage time, expiration time, file size offset in the data block, and the size of the entire metadata area (64 bytes). The structure is as follows:

[0031] type illustrate size fid File name, UUID 32byte stime File storage time, timestamp 8byte offset End of file offset 8byte null Reserve a spot 16byte

[0032] a) When the system receives the image data to be saved, it first obtains the volume that matches the saved data and the volume corresponding to it according to the current image size;

[0033] b) Find the bit index I_INDEX with a data bit of 0 in the INODE_BITMAP corresponding to the Volume, calculate the data block index B_INDEX (B_INDEX=B_INDEX) that needs to be saved for the current image data, and at the same time obtain the starting offset B_OFFSET=BLOCK_SIZE*B_INDEX for saving the image in the Volume.

[0034] c) Fill in the value of the DATA_BLOCK data item and the specific data of the picture;

[0035] d) Use memory mapping (MMAP) technology to map the volume's B_OFFSET to B_OFFSET+BLOCK_SIZE file memory to the memory area M_AREA;

[0036] e) Write the image data to the mapped memory through the system interface (MEMCPY);

[0037] f) After successfully writing into the memory M_AREA, modify the corresponding index position in INODE_BITMAP to 1; return the path where the file is saved this time. The path rule is: relative path / volume number / data block index / file number.PNG

[0038] g) If writing into memory M_AREA fails, the corresponding error message is returned and the process ends.

[0039] S3. Data viewing

[0040] a) The requester carries a specific file relative path R_PATH to request specific data. The service parses the relative path to obtain the specific information stored in the file: volume (Volume), data block index (B_INDEX), and file number (FID);

[0041] b) Find the corresponding BIT bit I_INDEX of INODE_BITMAP according to B_INDEX;

[0042] c) If the value of I_INDEX is 0, the file does not exist and the result is returned;

[0043] d) If the value of I_INDEX is 1, the data block location is found according to B_INDEX, and the metadata content of the data block is mapped to the memory space B_META;

[0044] e) Parse the B_META content, extract fid, stime, offset, and determine whether the file number in B_MATE is equal to the request parameter FID;

[0045] f) If the file number in B_META is not equal to the parameter FID, it returns that the file does not exist;

[0046] g) If stime+EXP_TIME < current timestamp, return that the file has expired;

[0047] h) If the file number in B_META is equal to the parameter, the content of the area [(B_INDEX*BLOCK_SIZE)+64, B_INDEX*BLOCK_SIZE)+64+offset] is mapped out and the actual file data is returned.

[0048] S4. Data deletion

[0049] The system automatically maintains a mapping record S_V_OPTIME of the start and end time of daily volume operations.

[0050] The specific structure is shown in the following table:

[0051] Property name illustrate volume_id Volume Number day Data storage date, accurate to the day s_offset Start offset e_offset End Offset

[0052] Due to the particularity of business data, manual deletion is not allowed in principle. The system will automatically perform deletion operations only after the file expires. The minimum granularity of the system file expiration time is day (Day). The operation steps for automatic deletion by the system are as follows:

[0053] a) Obtain the record of the earliest day S_V_OPTIME of DAY

[0054] b) Take out the EXP_TIME of the current Volume, calculate S_V_OPTIME.day + EXP_TIME, and record it on the v1 variable.

[0055] c) If v1 >= now(); then end

[0056] d) If v1 < now(), then calculate the data blocks within the range according to S_V_OPTIME.s_offset, S_V_OPTIME.e_offset, and BLOCK_SIZE, and index bit_index_array in the INODE_BITMAP area;

[0057] e) Set all the values of the bits specified by bit_index_array to 0.

[0058] The effects before and after the traffic management picture storage system adopts this solution are as follows:

[0059] 1. When the number of pictures is too large (in the hundreds of millions), there are often problems where the file INODE of the operating system does not match the actual disk space, resulting in the failure to save files even though there is still a large amount of disk space. After adopting this solution, the operation greatly reduces the number of INODEs in the system. The number of INODEs is equal to the volume (Volume), solving the problem of too many INODEs in the system.

[0060] 2. When the pictures reach the expiration date, the system will perform deletion operations on the picture files in the disk. When a large number of pictures are deleted, a large number of disk I / O operations will be generated, greatly affecting the disk performance and also reducing the disk life. After adopting this solution, only the pictures that need to be deleted are marked, rather than real deletion operations, thus solving the problem of reduced disk performance due to a large number of I / O operations.

[0061] 3. For traditional I / O operation files, data needs to be copied multiple times. For example, when reading a file, the data needs to go through disk -> memory buffer -> user area. During this process, the data needs to be copied 2 times. In this solution, because memory-mapped files are adopted, users can directly operate on the memory, achieving zero-copy of data. This greatly improves the data writing and reading performance.

[0062] On the other hand, the present invention further discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the above method.

[0063] On the other hand, the present invention further discloses a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the above method.

[0064] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the methods for saving a large number of fragmented files in a super-large file based on memory mapping in the above embodiments.

[0065] It is understandable that the system provided by the embodiment of the present invention corresponds to the method provided by the embodiment of the present invention, and the explanation, examples and beneficial effects of the relevant contents can refer to the corresponding parts in the above method.

[0066] The embodiment of the present application also provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus.

[0067] Memory, used to store computer programs;

[0068] The processor is used to implement the above-mentioned method of saving a large number of fragmented files in a very large file based on memory mapping when executing the program stored in the memory;

[0069] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc.

[0070] The communication interface is used for communication between the above electronic device and other devices.

[0071] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0072] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components.

[0073] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0074] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0075] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0076] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for storing a large number of fragmented files in a super-large file based on memory mapping, characterized in that: The following steps are included: S1. Create and initialize data volumes; S2, data preservation, when there is image data that needs to be saved, the bitmap algorithm is used to find the free data block, and the memory mapping file technology is used to quickly write the image information into the data block; S3, file reading, when there is a file to be read, the data block index saved in this file is parsed according to the requested path, and the data block location is found in the data block index; at the same time, the memory mapping file technology is used to map the data block content to the memory, and the program reads the memory file data and sends it to the client; S4, file deletion. According to the life cycle of files in different businesses, when the life cycle is reached, the system will not operate the specific file data, but only modify the usage status of the data block; The step S2 specifically includes: 2a) When the system receives the image data to be saved, it first obtains the volume that matches the saved data and the volume corresponding to it according to the current image size; 2b) Find the bit index I_INDEX with a data bit of 0 in the INODE_BITMAP corresponding to the Volume, calculate the data block index B_INDEX that needs to be saved for the current image data, B_INDEX=B_INDEX, and at the same time obtain the saving start offset of the image in the Volume B_OFFSET=BLOCK_SIZE*B_INDEX; 2c) Fill in the value of the DATA_BLOCK data item and the specific data of the picture; 2d) Use memory mapping technology to map the volume's B_OFFSET to B_OFFSET+BLOCK_SIZE file memory to the memory area M_AREA; 2e) Write the image data into the mapped memory through the system interface; 2f) After successfully writing into memory M_AREA, modify the corresponding index position in INODE_BITMAP to 1; Returns the path where the file is saved. The path rule is: relative path / volume number / data block index / file number.PNG; 2g) If writing into memory M_AREA fails, the corresponding error message is returned and the process ends.

2. The method for storing a large number of fragmented files in a super-large file based on memory mapping according to claim 1, characterized in that: In step S1, the specific file content is saved in the form of data blocks, and a bitmap algorithm is used to record the usage status of each data block.

3. The method for storing a large number of fragmented files in a super-large file based on memory mapping according to claim 1, characterized in that: Step S1 specifically includes: 1a) The initialization operation requires specifying the system disk, data disk, data block size, data volume, and data volume data expiration time; 1b) Create metadata bitmaps and data volumes according to the entered parameter information. One data volume corresponds to one metadata bitmap. The bitmap data is stored in the system disk. The bitmap size is the volume size / block size. The data blocks in the same volume have the same size. 1c) The data volume will be formatted, and the formatting will eventually generate corresponding metadata bitmap information based on the data block size.

4. The method for storing a large number of fragmented files in a super-large file based on memory mapping according to claim 1, characterized in that: The step S3 comprises: 3a) The requester carries the specific file relative path R_PATH to request specific data. The service parses the relative path to obtain the specific information stored in the file: volume, data block index, and file number; 3b) Find the corresponding BIT bit I_INDEX of INODE_BITMAP according to B_INDEX; 3c) If the value of I_INDEX is 0, return that the file does not exist and end; 3d) If the value of I_INDEX is 1, then find the data block position according to B_INDEX, and map the data block metadata content to the memory space B_META; 3e) Parse the content of B_META, extract fid, stime, and offset, and determine whether the file number in B_MATE is equal to the request parameter FID; stime represents the file storage time; 3f) If the file number in B_META is not equal to the parameter FID, return that the file does not exist; 3g) If stime + EXP_TIME < the current timestamp, return that the file has expired; 3h) If the file number in B_META is equal to the parameter, then Extract the content of the area [(B_INDEX * BLOCK_SIZE) + 64, (B_INDEX * BLOCK_SIZE) + 64 + offset] and return the real file data.

5. The method for storing a large number of fragmented files in a super-large file based on memory mapping according to claim 1, characterized in that: The specific steps of S4 include: 4a) Obtain the earliest S_V_OPTIME record of the DAY; 4b) Extract the EXP_TIME of the current Volume, calculate S_V_OPTIME.day + EXP_TIME, and record it on the v1 variable; 4c) If v1 >= now(); then end; 4d) If v1 < now(), then calculate the data block index bit_index_array in the INODE_BITMAP area within the range according to S_V_OPTIME.s_offset, S_V_OPTIME.e_offset, and BLOCK_SIZE; 4e) Set all the values of the bits specified by bit_index_array to 0.

6. A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor is caused to execute the steps of the method according to any one of claims 1 to 5.

7. A computer device includes a memory and a processor. The memory stores a computer program. When the computer program is executed by the processor, the processor is caused to execute the steps of the method according to any one of claims 1 to 5.