Method and system for integrating io_uring mechanism with Pebble

By introducing the io_uring mechanism into the Pebble storage engine, it replaces synchronous I/O, optimizes file operation functions and task queue processing, solves the problem of synchronous I/O limiting performance, and achieves more efficient I/O operations and performance improvement.

CN114721750BActive Publication Date: 2024-10-01上海沄熹科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210480432.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-05
Publication Date
2024-10-01
Estimated Expiration
2042-05-05

AI Technical Summary

Technical Problem

The synchronous I/O mechanism used in the Pebble storage engine limits the I/O performance of storage devices and cannot fully utilize the high performance of modern storage devices, especially in I/O-intensive applications, resulting in limited performance improvement.

Method used

Introduce the io_uring mechanism into Pebble, replace the traditional synchronous I/O mechanism by adding a virtual file system object, customize the virtual file system interface, and rewrite the file operation functions, such as Create, Open, ReuseForWrite, Read, Write and Sync, using The io_uring task queue and waitgroup mechanism optimize file read and write operations.

Benefits of technology

It achieves more efficient I/O operations, reduces CPU consumption and latency, and significantly improves the read and write performance of the Pebble storage engine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114721750B_ABST
    Figure CN114721750B_ABST
Patent Text Reader

Abstract

The present invention particularly relates to a method and system for integrating an io_uring mechanism with Pebble. The method and system for integrating an io_uring mechanism with Pebble customizes the implementation of a virtual file system interface in Pebble by adding a virtual file system object to a Pebble storage engine, using the latest io_uring to replace the traditional synchronous I / O mechanism as the underlying I / O model of Pebble. The method and system for integrating an io_uring mechanism with Pebble replaces the underlying synchronous I / O technology of the Pebble storage engine with the io_uring mechanism based on a method for adding a virtual file system object to Pebble, so that Pebble, as an I / O intensive application, can make full use of the advantages of the io_uring mechanism, improve I / O efficiency, reduce CPU consumption, and thereby achieve an improvement in read and write performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database development, and in particular to a method and system for integrating an io_uring mechanism with Pebble. Background Art

[0002] Pebble is a high-performance KV storage engine developed by Cockroach in Go language with reference to RocksDB. As an important part of the database, the storage engine lays the foundation for the performance and stability of the database. In storage scenarios, there are usually very high requirements for performance. Therefore, when selecting the I / O technology at the bottom of the storage engine, we always hope to get a better solution. Pebble uses a synchronous I / O mechanism. Ideally, the program will maximize the computing power of the CPU and the I / O capabilities of the storage device to achieve the best performance. In recent years, the I / O performance of storage devices has improved rapidly, and the synchronous I / O mode will limit the performance of storage devices. If asynchronous I / O is used, the performance of I / O-intensive applications such as Pebble can be significantly accelerated.

[0003] In 2019, Linux 5.1 was officially released, introducing a new syscall interface - io_uring, to support asynchronous I / O. It allows users to submit one or more I / O requests, which are processed asynchronously and do not block the calling process. There is a shared ring buffer between user space and kernel space. This arrangement allows efficient I / O while avoiding the overhead of copying buffers between them as much as possible. By sharing memory, the I / O process no longer needs to make a system call. This native kernel approach and the PolledIO mechanism enable io_uring to achieve high IOPS.

[0004] In order to improve the performance of the Pebble storage engine, we can consider changing the I / O model and using io_uring to replace the original synchronous I / O mechanism. The main file types and operations involved in Pebble's disk I / O include: reading and writing WAL files, reading and writing SST files during flush and compaction, and reading and writing MANIFEST files. By adding a virtual file system class to Pebble and customizing the interface implementation of the virtual file system, we can take advantage of io_uring to achieve the goal of improving performance, reducing latency, and saving CPU resources.

[0005] Based on this, the present invention proposes a method and system for integrating the io_uring mechanism of Pebble. Summary of the invention

[0006] In order to overcome the defects of the prior art, the present invention provides a simple and efficient method and system for integrating the io_uring mechanism of Pebble.

[0007] The present invention is achieved through the following technical solutions:

[0008] A method and system for integrating io_uring mechanism in Pebble, characterized by: adding a virtual file system object in the Pebble storage engine, using the latest io_uring to replace the traditional synchronous I / O mechanism as the underlying I / O model of Pebble, and customizing the virtual file system interface in Pebble;

[0009] The following steps are involved:

[0010] S1. File system implementation class using io_uring mechanism;

[0011] Based on Pebble's vfs.defaultFS, the Create, Open and ReuseForWrite functions are rewritten, that is, the three operations of creating files, opening files and reusing and rewriting files;

[0012] S2, file operation implementation class using io_uring mechanism;

[0013] This is achieved by encapsulating Pebble's original vfs.File class, modifying the structure of the file operation class, and modifying the functions involved in read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions;

[0014] S3, the implementation class for submitting io_uring tasks. The basic idea is to implement an io_uring encapsulation class:

[0015] Use the singleton pattern to create a unique object, through which all io_uring read and write requests for files are submitted to the kernel; the implementation method is to define a queue, which is responsible for receiving io_uring tasks sent from multiple threads;

[0016] The only object created using the singleton pattern starts a coroutine during initialization. During the life cycle of Pebble, it continuously loops to obtain the io_uring task from the head of the queue and submits it to the kernel. At the same time, it continuously loops to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calls the waitgroup.Done command to wake up the waiting thread to continue processing, and notifies the function that initiated the request that the I / O operation has been completed.

[0017] In step S1, when rewriting Create, Open and ReuseForWrite functions, the following contents are included:

[0018] 1) Use direct_io mode when calling os.OpenFile to open the file;

[0019] 2) The File object returned by the function is specifically a file operation implementation class implemented using the io_uring mechanism.

[0020] In step S2, the structure of the file operation class is modified, including the following contents:

[0021] 1) Add two array objects, one for saving the written content of the file, and the other for implementing cache processing of less than 512 bytes during read and write operations, with a size of 512 bytes;

[0022] 2) Add an integer object to record the offset of reading, writing and disk flushing;

[0023] 3) Add a waitgroup object to ensure that all io_uring write tasks have been processed and completed each time the file is synchronized.

[0024] In step S2, the Read function of the file operation class is modified, including the following contents:

[0025] 1) The starting offset of file reading must be an integer multiple of 512 bytes. When the recorded file reading offset does not meet this condition, the starting offset is moved forward to the largest position that meets the integer multiple of 512 bytes;

[0026] 2) According to the length of the passed array and the file size, move the end position of the read file to the smallest position that satisfies an integer multiple of 512 bytes;

[0027] 3) After determining the file reading position, submit the io_uring read task and create a corresponding waitgroup (synchronous wait group) to wait for the read operation to complete;

[0028] 4) When the read operation is completed, the read content is intercepted and the read content that is actually needed is returned.

[0029] The difference between the ReadAt function and the Read function is that the ReadAt function is responsible for passing in parameters to specify the starting offset of the read file. In the step S2, when the ReadAt function of the file operation class is modified, the modification idea is the same as that of the Read function.

[0030] In step S2, the Write function of the file operation class is modified, including the following contents:

[0031] 1) Since the file is opened in direct_io mode, that is, the file reading and writing will not go through the operating system cache, the write operation first writes the content to the memory, that is, the array object defined in the file operation class. When the written content reaches a certain amount, an io_uring write task is submitted to write the file content to the disk to achieve the purpose of reducing the number of I / O times;

[0032] 2) When submitting an io_uring write task, the waitgroup object in the file operation class is passed in. However, unlike the read operation, the write operation does not need to wait for the task to be processed. It can return directly after submitting the task.

[0033] In step S2, the Sync function of the file operation class is modified, including the following contents:

[0034] 1) According to the recorded disk offset, the file content that is not written to the disk in the current memory is submitted to the io_uring write task, and passed to the waitgroup object in the file operation class to wait for the I / O task to complete;

[0035] 2) Perform special processing on data less than 512 bytes: write this part of the file content into an array object of 512 bytes in the file operation class, fill the part less than 512 bytes with 0, create a corresponding waitgroup, submit this part of the file content to the io_uring write task again, and wait for the task to complete;

[0036] When data less than 512 bytes is submitted, the current disk offset is not updated. This part of the file content is written to the disk again along with the subsequent written content. Therefore, the starting position of the disk is always an integer multiple of 512 bytes and no special processing is required when using it.

[0037] A system for integrating Pebble with an io_uring mechanism, characterized in that: a method for implementing the above-mentioned Pebble integrated with the io_uring mechanism comprises a file system implementation module using the io_uring mechanism, a file operation implementation module using the io_uring mechanism, and an implementation module for submitting io_uring tasks;

[0038] The file system implementation module using the io_uring mechanism is implemented based on Pebble's vfs.defaultFS and is responsible for rewriting the three functions Create, Open and ReuseForWrite, i.e., creating files, opening files and reusing and rewriting files.

[0039] The file operation implementation module using the io_uring mechanism is implemented by encapsulating Pebble's original vfs.File class, and is responsible for transforming the structure of the file operation class and transforming the functions involved in the read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions;

[0040] The basic idea of ​​the implementation module for submitting io_uring tasks is to implement an io_uring encapsulation class, which is responsible for creating a unique object using the singleton mode, and all io_uring read and write requests of files are submitted to the kernel through this object; at the same time, a queue is defined to receive io_uring tasks sent from multiple threads;

[0041] The only object created using the singleton pattern starts a coroutine during initialization. It is responsible for continuously looping to obtain the io_uring task from the head of the queue and submitting it to the kernel during the life cycle of Pebble. It is also responsible for continuously looping to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calling the waitgroup.Done command to wake up the waiting thread to continue processing, and notifying the function that initiated the request that the I / O operation has been completed.

[0042] The beneficial effects of the present invention are as follows: the method and system for integrating the io_uring mechanism with Pebble replaces the underlying synchronous I / O technology of the Pebble storage engine with the io_uring mechanism based on a method of adding a virtual file system object in Pebble, so that Pebble, as an I / O intensive application, can fully utilize the advantages of the io_uring mechanism, improve I / O efficiency, reduce CPU consumption, and thus achieve improved read and write performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0044] Attached Figure 1 Schematic diagram of the method of integrating the io_uring mechanism into Pebble of the present invention. DETAILED DESCRIPTION

[0045] In order to enable those skilled in the art to better understand the technical solutions in the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0046] In Pebble's original virtual file system, the file system class opens files by calling the os interface, and the file operation class implements file read, write, synchronize, close, and other operations by calling the io interface, using a synchronous I / O mechanism. In order to integrate the io_uring mechanism into Pebble, it is necessary to add a new virtual file system class, rewrite the file system class and file operation class, and encapsulate io_uring to handle the read and write tasks generated by each file.

[0047] The method of integrating the io_uring mechanism in Pebble is to add a virtual file system object in the Pebble storage engine, use the latest io_uring to replace the traditional synchronous I / O mechanism as the underlying I / O model of Pebble, and customize the virtual file system interface in Pebble.

[0048] The following steps are involved:

[0049] S1. File system implementation class using io_uring mechanism;

[0050] Based on Pebble's vfs.defaultFS, the Create, Open and ReuseForWrite functions are rewritten, that is, the three operations of creating files, opening files and reusing and rewriting files;

[0051] S2, file operation implementation class using io_uring mechanism;

[0052] This is achieved by encapsulating Pebble's original vfs.File class. Since the file is opened in direct_io mode, it only supports read and write operations of integer multiples of 512 bytes. Therefore, it is necessary to modify the structure of the file operation class and the functions involved in the read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions;

[0053] S3, the implementation class for submitting io_uring tasks. The basic idea is to implement an io_uring encapsulation class:

[0054] Use the singleton pattern to create a unique object, through which all io_uring read and write requests for files are submitted to the kernel; the implementation method is to define a queue, which is responsible for receiving io_uring tasks sent from multiple threads;

[0055] The only object created using the singleton pattern starts a coroutine during initialization. During the life cycle of Pebble, it continuously loops to obtain the io_uring task from the head of the queue and submits it to the kernel. At the same time, it continuously loops to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calls the waitgroup.Done command to wake up the waiting thread to continue processing, and notifies the function that initiated the request that the I / O operation has been completed.

[0056] In step S1, when rewriting Create, Open and ReuseForWrite functions, the following contents are included:

[0057] 1) Use direct_io mode when calling os.OpenFile to open the file;

[0058] 2) The File object returned by the function is specifically a file operation implementation class implemented using the io_uring mechanism.

[0059] In step S2, the structure of the file operation class is modified, including the following contents:

[0060] 1) Add two array objects, one for saving the written content of the file, and the other for implementing cache processing of less than 512 bytes during read and write operations, with a size of 512 bytes;

[0061] 2) Add an integer object to record the offset of reading, writing and disk flushing;

[0062] 3) Add a waitgroup object to ensure that all io_uring write tasks have been processed and completed each time the file is synchronized.

[0063] The original logic of the Read function is: record the offset of the file to be read, and read the file from the saved offset as the starting position each time the Read function is called, until the end of the file or the array passed in to save the file read content has been read full. Since direct_io only supports reading of 512 bytes, some special processing is required for the starting and ending positions of the read file.

[0064] In step S2, the Read function of the file operation class is modified, including the following contents:

[0065] 1) The starting offset of file reading must be an integer multiple of 512 bytes. When the recorded file reading offset does not meet this condition, the starting offset is moved forward to the largest position that meets the integer multiple of 512 bytes;

[0066] 2) According to the length of the passed array and the file size, move the end position of the read file to the smallest position that satisfies an integer multiple of 512 bytes;

[0067] 3) After determining the file reading position, submit the io_uring read task and create a corresponding waitgroup (synchronous wait group) to wait for the read operation to complete;

[0068] 4) When the read operation is completed, the read content is intercepted, which can be understood as "cutting off the head and tail", and finally the read content that is really needed is returned.

[0069] The difference between the ReadAt function and the Read function is that the ReadAt function is responsible for passing in parameters to specify the starting offset of the read file. In the step S2, when the ReadAt function of the file operation class is modified, the modification idea is the same as that of the Read function.

[0070] In step S2, the Write function of the file operation class is modified, including the following contents:

[0071] 1) Since the file is opened in direct_io mode, that is, the file reading and writing will not go through the operating system cache, the write operation first writes the content to the memory, that is, the array object defined in the file operation class. When the written content reaches a certain amount, an io_uring write task is submitted to write the file content to the disk to achieve the purpose of reducing the number of I / O times;

[0072] 2) When submitting an io_uring write task, the waitgroup object in the file operation class is passed in. However, unlike the read operation, the write operation does not need to wait for the task to be processed. It can return directly after submitting the task.

[0073] In step S2, the Sync function of the file operation class is modified, including the following contents:

[0074] 1) According to the recorded disk offset, the file content that is not written to the disk in the current memory is submitted to the io_uring write task, and passed to the waitgroup object in the file operation class to wait for the I / O task to complete;

[0075] 2) Perform special processing on data less than 512 bytes: write this part of the file content into an array object of 512 bytes in the file operation class, fill the part less than 512 bytes with 0, create a corresponding waitgroup, submit this part of the file content to the io_uring write task again, and wait for the task to complete;

[0076] When data less than 512 bytes is submitted, the current disk offset is not updated. This part of the file content is written to the disk again along with the subsequent written content. Therefore, the starting position of the disk is always an integer multiple of 512 bytes and no special processing is required when using it.

[0077] The Pebble integrated io_uring mechanism system is used to implement the Pebble integrated io_uring mechanism method, including a file system implementation module using the io_uring mechanism, a file operation implementation module using the io_uring mechanism, and an implementation module for submitting io_uring tasks;

[0078] The file system implementation module using the io_uring mechanism is implemented based on Pebble's vfs.defaultFS and is responsible for rewriting the three functions Create, Open and ReuseForWrite, i.e., creating files, opening files and reusing and rewriting files.

[0079] The file operation implementation module using the io_uring mechanism is implemented by encapsulating Pebble's original vfs.File class, and is responsible for transforming the structure of the file operation class and transforming the functions involved in the read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions;

[0080] The basic idea of ​​the implementation module for submitting io_uring tasks is to implement an io_uring encapsulation class, which is responsible for creating a unique object using the singleton mode, and all io_uring read and write requests of files are submitted to the kernel through this object; at the same time, a queue is defined to receive io_uring tasks sent from multiple threads;

[0081] The only object created using the singleton pattern starts a coroutine during initialization. It is responsible for continuously looping to obtain the io_uring task from the head of the queue and submitting it to the kernel during the life cycle of Pebble. It is also responsible for continuously looping to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calling the waitgroup.Done command to wake up the waiting thread to continue processing, and notifying the function that initiated the request that the I / O operation has been completed.

[0082] The embodiment described above is only one specific implementation of the present invention. Common changes and substitutions made by those skilled in the art within the scope of the technical solution of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for integrating io_uring mechanism into Pebble, Features: The following steps are involved: By adding a virtual file system object to the Pebble storage engine, using the latest io_uring to replace the traditional synchronous I / O mechanism as the underlying I / O model of Pebble, the virtual file system interface in Pebble is customized. The following steps are involved: S1. File system implementation class using io_uring mechanism; Based on Pebble's vfs.defaultFS, the Create, Open and ReuseForWrite functions are rewritten, that is, the three operations of creating files, opening files and reusing and rewriting files; S2, file operation implementation class using io_uring mechanism; This is achieved by encapsulating Pebble's original vfs.File class, modifying the structure of the file operation class, and modifying the functions involved in read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions; S3, the implementation class for submitting io_uring tasks. The basic idea is to implement an io_uring encapsulation class: Use the singleton pattern to create a unique object, through which all io_uring read and write requests for files are submitted to the kernel; the implementation method is to define a queue, which is responsible for receiving io_uring tasks sent from multiple threads; The only object created using the singleton pattern starts a coroutine during initialization. During the life cycle of Pebble, it continuously loops to obtain the io_uring task from the head of the queue and submits it to the kernel. At the same time, it continuously loops to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calls the waitgroup.Done command to wake up the waiting thread to continue processing, and notifies the function that initiated the request that the I / O operation has been completed.

2. The method for integrating io_uring mechanism with Pebble according to claim 1, Features: In the step S1, when rewriting the Create, Open and ReuseForWrite functions, the following contents are included: 1) Use direct_io mode when calling os.OpenFile to open the file; 2) The File object returned by the function is specifically a file operation implementation class implemented using the io_uring mechanism.

3. The method for integrating io_uring mechanism with Pebble according to claim 1, Features: In step S2, the structure of the file operation class is modified, including the following contents: 1) Add two array objects, one for saving the written content of the file, and the other for implementing cache processing of less than 512 bytes during read and write operations, with a size of 512 bytes; 2) Add an integer object to record the offset of reading, writing and disk flushing; 3) Add a waitgroup object to ensure that all io_uring write tasks have been processed and completed each time the file is synchronized.

4. The method for integrating io_uring mechanism with Pebble according to claim 1, Features: In step S2, the Read function of the file operation class is modified, including the following contents: 1) The starting offset of file reading must be an integer multiple of 512 bytes. When the recorded file reading offset does not meet this condition, the starting offset is moved forward to the largest position that meets the integer multiple of 512 bytes; 2) According to the length of the passed array and the file size, move the end position of the read file to the smallest position that satisfies an integer multiple of 512 bytes; 3) After determining the file reading position, submit the io_uring read task and create a corresponding synchronous wait group waitgroup to wait for the read operation to complete; 4) When the read operation is completed, the read content is intercepted and the read content that is actually needed is returned.

5. The method for integrating io_uring mechanism with Pebble according to claim 4, Features: The difference between the ReadAt function and the Read function is that the ReadAt function is responsible for passing in parameters to specify the starting offset of the read file. In the step S2, when the ReadAt function of the file operation class is modified, the modification idea is the same as that of the Read function.

6. The method for integrating io_uring mechanism with Pebble according to claim 1, Features: In step S2, the Write function of the file operation class is modified, including the following contents: 1) Since the file is opened in direct_io mode, that is, the file reading and writing will not go through the operating system cache, the write operation first writes the content to the memory, that is, the array object defined in the file operation class. When the written content reaches a certain amount, an io_uring write task is submitted to write the file content to the disk to achieve the purpose of reducing the number of I / O times; 2) When submitting an io_uring write task, the waitgroup object in the file operation class is passed in. However, unlike the read operation, the write operation does not need to wait for the task to be processed. It can return directly after submitting the task.

7. The method for integrating io_uring mechanism with Pebble according to claim 1, Features: In step S2, the Sync function of the file operation class is modified, including the following contents: 1) According to the recorded disk offset, the file content that is not written to the disk in the current memory is submitted to the io_uring write task, and passed to the waitgroup object in the file operation class to wait for the I / O task to complete; 2) Perform special processing on data less than 512 bytes: write this part of the file content into an array object of 512 bytes in the file operation class, fill the part less than 512 bytes with 0, create a corresponding waitgroup, submit this part of the file content to the io_uring write task again, and wait for the task to complete; When data less than 512 bytes is submitted, the current disk offset is not updated. This part of the file content is written to the disk again along with the subsequent written content. Therefore, the starting position of the disk is always an integer multiple of 512 bytes and no special processing is required when using it.

8. A Pebble system integrating io_uring mechanism, Features: A method for implementing the Pebble integrated io_uring mechanism as described in any one of claims 1 to 7, comprising a file system implementation module using the io_uring mechanism, a file operation implementation module using the io_uring mechanism, and an implementation module for submitting io_uring tasks; The file system implementation module using the io_uring mechanism is implemented based on Pebble's vfs.defaultFS and is responsible for rewriting the three functions Create, Open and ReuseForWrite, i.e., creating files, opening files and reusing and rewriting files. The file operation implementation module using the io_uring mechanism is implemented by encapsulating Pebble's original vfs.File class, and is responsible for transforming the structure of the file operation class and transforming the functions involved in the read and write operations in the file operation class, including but not limited to Read, ReadAt, Write, and Sync functions; The basic idea of ​​the implementation module for submitting io_uring tasks is to implement an io_uring encapsulation class, which is responsible for creating a unique object using the singleton mode, and all io_uring read and write requests of files are submitted to the kernel through this object; at the same time, a queue is defined to receive io_uring tasks sent from multiple threads; The only object created using the singleton pattern starts a coroutine during initialization. It is responsible for continuously looping to obtain the io_uring task from the head of the queue and submitting it to the kernel during the life cycle of Pebble. It is also responsible for continuously looping to obtain the io_uring task that has been written to the disk from the CE queue of the io_uring task, calling the waitgroup.Done command to wake up the waiting thread to continue processing, and notifying the function that initiated the request that the I / O operation has been completed.