Request processing method, related device and storage medium
By using ring buffers in the kernel state to handle multiple read and write requests of user-state programs, the competition and waiting between threads are reduced, and the concurrency performance of storage devices and the input/output operands per second are improved.
Patent Information
- Application Number
- CN202411336571.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-09-24
AI Technical Summary
When a user-state program issues a large number of data read and write requests to the storage device driver through multiple threads, the data read and write requests are queued in the storage device driver, limiting the input/output operands per second of the storage device.
The kernel-state ring buffer is used to store multiple read and write requests of the user-state program in the first ring buffer, and the target read and write request pointed to by the head pointer is sent to the controller for data read and write operations, and obtains After the response, it is stored in the second ring buffer, and the third ring buffer is used to store context information and pass it to the user-state program, clearing the pointer to reduce inter-thread competition and waiting.
Reduces competition and waiting time between multiple threads, improves the kernel-state concurrency performance in the host of the storage device, thereby improving the input/output operand per second.
Smart Images

Figure CN119248192A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure belongs to the field of storage technology, and in particular relates to a request processing method, a related device and a storage medium. Background Art
[0002] A storage system usually includes a computer device and a storage device, and the storage device can expand the storage space of the computer device. The operating system of the computer device includes a user state and a kernel state with different execution state levels. The user state program can send data read and write requests to the storage device driver in the kernel state in a multi-threaded manner to implement data read and write operations on the storage device. However, when the user state program sends a large number of data read and write requests to the storage device driver through multiple threads, a large number of data read and write requests will be queued in the storage device driver waiting to be executed. Obviously, this limits the number of input / output operations per second of the storage device. Summary of the invention
[0003] In view of the above problems, the present disclosure provides a request processing method, related devices and storage media, aiming to reduce the competition and waiting time between multiple threads, improve the concurrency performance of the kernel state in the host of the storage device, and thereby increase the input / output operations per second of the storage device.
[0004] According to a first aspect of the present disclosure, a request processing method is provided, which is applied in kernel mode and includes:
[0005] storing multiple read and write requests of a user-mode program to a storage device in a first ring buffer, wherein the storage device includes a controller and a memory;
[0006] Execute the loop step: send the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement the data read / write operation on the memory and obtain the target read / write response of the target read / write request;
[0007] storing the target read / write response in a second ring buffer, wherein context information of the target read / write request and the target read / write response is stored in a third ring buffer;
[0008] Based on the context information of the target read / write request and the target read / write response, sending the target read / write response to a corresponding user state program;
[0009] The head pointer is moved down by one position, and the context information of the target read / write request and the target read / write response stored in the third ring buffer is cleared.
[0010] Optionally, before storing the multiple read and write requests of the user mode program to the storage device in the first ring buffer, the request processing method further includes:
[0011] Instantiate the first ring buffer, the second ring buffer and the third ring buffer respectively;
[0012] Pre-allocate storage space for the third ring buffer.
[0013] Optionally, storing the multiple read and write requests of the user-mode program to the storage device in the first ring buffer includes:
[0014] Receiving the multiple read and write requests through a system call interface channel between a user state and a kernel state;
[0015] storing the plurality of read and write requests in the first ring buffer;
[0016] The context information of the plurality of read and write requests is stored in the third ring buffer.
[0017] Optionally, the context information of the read / write request includes: a mapping of the logical address of the read / write request to a physical address,
[0018] The step of sending the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement the data read / write operation on the memory, and obtaining the target read / write response to the target read / write request includes:
[0019] constructing a storage interface channel request based on the target read / write request and a mapping of the logical address of the target read / write request to the physical address, and sending the storage interface channel request to the controller;
[0020] The controller performs data read and write operations on the memory according to the storage interface channel request to obtain a target read and write response to the target read and write request.
[0021] Optionally, storing the target read / write response in a second ring buffer comprises:
[0022] Receiving a tracking command for tracking the execution status of the target read / write request through a system call interface channel between a user state and a kernel state;
[0023] storing the target read and write responses in the second ring buffer based on the tracking command;
[0024] The context information of the target read / write response is stored in the third ring buffer.
[0025] Optionally, the sending the target read / write response to the corresponding user state program based on the context information of the target read / write request and the target read / write response includes:
[0026] Receiving a retrieval command for retrieving the target read / write response through a system call interface channel between a user state and a kernel state;
[0027] Based on the context information of the target read / write request, restore the original context in the user state, and store the target read / write response in the user state;
[0028] Based on the context information of the target read / write response, the original context of the kernel state is restored, and the loop steps are executed again.
[0029] Optionally, before storing the multiple read and write requests of the user mode program to the storage device in the first ring buffer, the request processing method further includes:
[0030] Initialize the storage device as a miscellaneous device structure dev device, and register the storage device.
[0031] According to a second aspect of the present disclosure, a request processing device is provided, which is applied in kernel mode and includes:
[0032] A read / write request storage unit, used for storing a plurality of read / write requests of a user-mode program to a storage device in a first ring buffer, wherein the storage device includes a controller and a memory;
[0033] a target read / write request execution unit, configured to execute a loop step: sending the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement a data read / write operation on the memory, and obtaining a target read / write response to the target read / write request;
[0034] storing the target read / write response in a second ring buffer, wherein context information of the target read / write request and the target read / write response is stored in a third ring buffer;
[0035] Based on the context information of the target read / write request and the target read / write response, sending the target read / write response to a corresponding user state program;
[0036] The head pointer is moved down by one position, and the context information of the target read / write request and the target read / write response stored in the third ring buffer is cleared.
[0037] According to a third aspect of the present disclosure, there is provided a storage system, including:
[0038] Storage devices, including controllers and memory;
[0039] A computer device includes a request processing device running in kernel mode as described above, which is used to store multiple read and write requests of a user mode program to the storage device in a first ring buffer, and send the target read and write request pointed to by the head pointer in the first ring buffer to the controller to implement data read and write operations on the memory, and obtain a target read and write response to the target read and write request.
[0040] According to a fourth aspect of the present disclosure, a storage medium is provided, on which a computer program or instruction is stored, and the computer program or instruction implements the steps of the method described above when executed by a processor.
[0041] The present disclosure brings the following beneficial effects:
[0042] The request processing method provided by the present invention is applied to kernel mode, and the storage device includes a controller and a memory. Multiple read and write requests of a user mode program to the storage device are stored in a first ring buffer. Then, a loop step is executed: the target read and write request pointed to by the head pointer in the first ring buffer is sent to the controller to implement data read and write operations on the memory, and a target read and write response of the target read and write request is obtained, and the target read and write response is stored in a second ring buffer, wherein context information of the target read and write request and the target read and write response is stored in a third ring buffer, and based on the context information of the target read and write request and the target read and write response, the target read and write response is sent to a corresponding user mode program, the head pointer is moved down by one position, and the context information of the target read and write request and the target read and write response stored in the third ring buffer is cleared, so that the pointer operation of the kernel mode ring buffer is used to realize the transmission and processing of multiple read and write requests of the user mode program to the storage device, thereby reducing the competition and waiting time between multiple threads, improving the concurrency performance of the kernel mode in the host of the storage device, and thereby improving the number of input / output operations per second of the storage device.
[0043] Other features and advantages of the present disclosure will be described in the following description, and partly become apparent from the description, or understood by practicing the present disclosure. The purpose and other advantages of the present disclosure are realized and obtained by the structures particularly pointed out in the description and the drawings.
[0044] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0046] Figure 1A schematic diagram of the structure of a storage system provided according to an embodiment of the present disclosure;
[0047] Figure 2 A schematic diagram of the structure of software for a computer device provided according to an embodiment of the present disclosure;
[0048] Figure 3 A flowchart of a request processing method provided according to an embodiment of the present disclosure;
[0049] Figure 4 A flowchart of a request processing method provided according to an embodiment of the present disclosure;
[0050] Figure 5 A schematic diagram of the structure of a request processing device provided according to an embodiment of the present disclosure;
[0051] Figure 6 The present invention is a schematic diagram of the structure of an electronic device provided according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0052] Various embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. In each of the accompanying drawings, the same elements are represented by the same or similar reference numerals. For the sake of clarity, the various parts in the accompanying drawings are not drawn to scale.
[0053] The following terms are used in this article:
[0054] Input / output (I / O) operations per second (IOPS) is a common performance metric for storage devices such as solid-state drives (SSDs). IOPS refers to the total number of I / O operations that a storage device can perform per second. A higher number of IOPS means better performance and lower latency for storage device operations (such as read and write operations).
[0055] A ring buffer is a data structure, also known as a pointer ring, which is usually used to store data in a fixed-size buffer in a loop. The ring buffer consists of a fixed-size array and two pointers. The head pointer points to the start of the buffer and the tail pointer points to the current position of the buffer. When data is written to the ring buffer, the tail pointer moves forward. If the tail pointer reaches the end of the buffer, it returns to the start of the buffer to achieve circular storage of data. When data is read, the head pointer also moves forward to ensure that the data read is the latest.
[0056] User mode, User mode and kernel mode are two different operating modes in the operating system, used to distinguish code running at different privilege levels. In user mode, programs run at a lower privilege level and can only access limited resources and perform restricted operations. Code in user mode is usually an application or user process, such as a text editor, browser, etc. In user mode, programs cannot directly access underlying hardware devices or execute privileged instructions. If a user mode program needs to perform privileged operations or access restricted resources, it must request support from kernel mode through system calls.
[0057] Kernel state is a high privilege level of the operating system. Only the operating system kernel can run in kernel state. In kernel state, the operating system has full control over all system resources and privileged instructions. Kernel state can execute privileged instructions, directly access hardware devices, and manage system resources. When a user program requests to perform a privileged operation, the processor switches to kernel state and transfers the request to the operating system kernel. Kernel state code is usually part of the operating system kernel and is used for core functions such as managing system resources, scheduling tasks, and handling interrupts.
[0058] Context is a static description of a certain moment in the dynamic process of process / thread running. Process / thread running is a dynamic process. If it is suspended, the context is the CPU state related to the process / thread at this moment. Generally, the CPU state related to the process / thread includes the value of the general register and the value of the status register. When the context is restored, the CPU can continue to execute from where it was suspended, and the process / thread can continue to run.
[0059] Context switch: During the running of user-mode programs, if a system call, exception, or interrupt occurs, the kernel mode needs to be used for processing. At this time, the system will sink to the kernel mode, which will save the current context of the user mode and restore the original context of the kernel mode. This process is a case of context switching.
[0060] It is understandable that the user-mode program can perform data read and write operations on the storage device. The user-mode program can establish a data read and write process (worker), which includes multiple threads, and each thread executes different data read and write tasks in parallel. The user-mode program can issue data read and write requests to the storage device driver in the kernel state through multiple threads, and the storage device driver forwards the data read and write requests to the storage device in sequence to implement the data read and write operations on the storage device, and the storage device driver returns the data read and write operation results to the user-mode program. Table 1 shows the verification results of the number of input / output operations per second of the storage device when the user-mode program uses a multi-threaded method to process data read and write requests for the storage device. As shown in Table 1, the user-mode program creates 2-32 processes, each process creates 1 thread, and each thread executes a maximum of 2000-8000 data read and write requests. From the verification results, when the number of processes is 16 and each thread issues 4000 data read and write requests, the number of input / output operations per second of the storage device reaches a peak of 45,000. As the number of processes and the number of data read and write requests issued by each thread continue to increase, the number of input / output operations per second of the storage device decreases. Obviously, when the user-mode program issues a large number of data read and write requests to the storage device driver through multiple threads, a large number of data read and write requests will be queued in the storage device driver waiting to be executed, which limits the number of input / output operations per second of the storage device.
[0061] Based on this, an embodiment of the present disclosure provides a request processing method to reduce competition and waiting time among multiple threads, improve the concurrency performance of the kernel state in the host of the storage device, and thereby increase the number of input / output operations per second of the storage device.
[0062] Table 1
[0063] Number of workers Number of threads per worker Number of requests per thread Read IOPS 2 1 2000 30880 2 1 4000 30651 2 1 8000 30323 4 1 2000 34213 4 1 4000 34277 4 1 8000 35580 8 1 2000 44567 8 1 4000 45079 8 1 8000 45118 16 1 2000 45496 16 1 4000 45796 16 1 8000 45575 32 1 2000 37559 32 1 4000 35457 32 1 8000 33000
[0064] Figure 1 FIG. 2 shows a schematic diagram of the structure of a storage system provided according to an embodiment of the present disclosure. Figure 1As shown, the storage system 100 provided in the embodiment of the present disclosure includes: a computer device 110 and a storage device 120, wherein the storage device 120 can be understood as an external storage device of the computer device 110. In some embodiments, the storage device 120 can be a solid state drive (SSD), a hard disk drive (HDD), a universal flash storage (UFS), an embedded multimedia card (EMMC), and other types of memory. In some embodiments, the computer device 110 can be a mobile phone, a tablet computer, a PC, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), and other devices with the storage device 120. The embodiment of the present disclosure does not impose any restrictions on the specific type of the computer device 110.
[0065] In some embodiments, the storage device 120 may include a controller 121 and a memory (e.g., F1ash) 122. The controller 121 includes a data buffer 123 and firmware (FirmWare, referred to as FW) 124. In some embodiments, the memory 122 in the storage device 120 includes multiple storage chips (e.g., UFS memory cards). The working rate of a storage chip is often insufficient to meet performance requirements, so the storage device 120 often packages multiple storage chips (e.g., 32 UFS memory cards) together, so that multiple storage chips can be controlled in parallel to work together to improve performance. In some embodiments, an operating system may be running on the computer device 110, and the operating system may be understood as a host 111 of the storage device 120. The host 111 may send instructions (including read / write commands, Trim commands, and commands for FW-related tasks) to the firmware 124 through a storage interface (e.g., Small Computer System Interface (SCSI)) channel between the computer device 110 and the storage device 120. When the host 111 sends a write command to the firmware 124, the firmware 124 can write data to the memory 122 according to the write command. When the host 111 sends a read command to the firmware 124, the firmware 124 can read data from the memory 122 according to the read command and return the read data to the host 111. It should be noted that for the convenience of description, Figure 1 In the example, the components of the computer device 110 do not include the storage device 120. Alternatively, the storage device 120 may also be a part of the computer device 110.
[0066] Figure 2 FIG. 1 is a schematic diagram of the structure of software of a computer device provided according to an embodiment of the present disclosure. Figure 2 As shown, the software architecture of the operating system running on the computer device 110 (which can also be understood as the host 111 of the storage device 120) can adopt a layered architecture. The embodiment of the present disclosure takes the Android system with a layered architecture as an example to illustrate the software structure of the host 111.
[0067] The layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer 210, the application framework layer 220, the Android runtime and system library 230, and the kernel layer 240. The application layer 210 may include a series of application packages. Figure 2 As shown, the application package may include user-mode programs such as camera, call, music, video, navigation, etc. The application framework layer 220 provides an application programming interface (API) and a programming framework for the user-mode programs of the application layer 210. Figure 2As shown, the application framework layer 220 may include a window manager, a content provider, a resource manager, etc. The application layer 210 and the application framework layer 220 run in a virtual machine. The system library may include multiple functional modules. For example: media libraries, image processing libraries, etc. The kernel layer 240 is a layer between hardware and software. The kernel layer 240 at least includes a driver module 241 and a file system management module 242, etc. The driver module 241 may include a display driver 244, a camera driver 245, a sensor driver 246, a storage device driver 243, etc. In some embodiments, the application layer 210 runs in user mode, and the kernel layer 240 runs in kernel mode. There is a system call interface between the user mode and the kernel mode. For example, an input / output control (ioctl) interface is used to communicate between the driver module 241 and the application layer 210. In some embodiments, the kernel layer 240 also includes a first ring buffer 251, a second ring buffer 252, and a first ring buffer 253. In some embodiments, the storage device driver 243 receives multiple read and write requests from the user state program to the storage device 120 through the system call interface channel between the user state and the kernel state, and stores them in the first ring buffer 251, sends the target read and write request pointed to by the head pointer in the first ring buffer 251 to the controller 121 (for example, the firmware 124) and stores the target read and write request in the data buffer 123 to implement data read and write operations on the memory 122 and obtain a target read and write response to the target read and write request.
[0068] Since the process of using the request processing method in the embodiment of the present disclosure to process multiple read and write requests of the user mode program to the storage device 120 will be described in detail below, it will not be repeated here.
[0069] Figure 3 The flowchart of the request processing method provided according to an embodiment of the present disclosure is shown in FIG. The request processing method of the embodiment of the present disclosure is applied to the kernel state. The request processing method of the embodiment of the present disclosure can be executed by the request processing device (not shown in the figure) in the software of the computer device 110. Figure 3 , the request processing method includes steps S310 to S320.
[0070] In step S310, multiple read and write requests from a user-mode program to a storage device are stored in a first ring buffer, where the storage device includes a controller and a memory.
[0071] In some embodiments, before storing multiple read and write requests of the user-mode program to the storage device 120 in the first ring buffer 251, the storage device driver 243 respectively instantiates the first ring buffer 251, the second ring buffer 252 and the third ring buffer 253, and pre-allocates storage space for the third ring buffer 253. In one example, the memory 122 in the storage device 120 includes 32 UFS slots, and the storage device driver 243 instantiates 3 structure arrays of lock-free pointer rings for the 32 UFS slots, namely the first ring buffer 251, the second ring buffer 252 and the third ring buffer 253, and the size of each array is, for example, 8192. The first ring buffer 251 is used to store multiple read and write requests (requests) of the user-mode program to the storage device 122. The second ring buffer 252 is used to store the read and write responses (responses) of the multiple read and write requests. The third ring buffer 253 is used to store the context information of the multiple read and write requests and the context information of the read and write responses of the multiple read and write requests. In one example, memory is allocated to the third ring buffer 253 by a function (e.g., kmalloc function) in the Linux kernel for dynamically allocating memory. In some embodiments, before storing multiple read and write requests of the user-mode program to the storage device 120 in the first ring buffer 251, the storage device driver 243 initializes the storage device 120 as a miscdevice structure dev device in the kernel mode, and registers the storage device 120 so that it can be accessed and operated when performing read and write operations in the operating system.
[0072] In some embodiments, the user state program sends multiple read and write requests for the storage device 120 to the storage device driver 243 through the system call interface channel (e.g., ioctl interface channel) between the user state and the kernel state. In some embodiments, in the user state, the user state program configures the attributes of the read and write requests for the storage device 120, wherein the attributes include information such as startoffset, data length, dpo, fua, block size, and data buffer. The corresponding system call interface channel read and write request command (e.g., ioctl read and write request command) is constructed using configuration information such as lun, request information, read / write type, data transmission direction, and initialization of some fields of the UPIU structure. The corresponding system call interface channel read and write request command is sent to the storage device driver 243. If the sending is successful, the number of successful read and write requests is recorded. If the sending fails, the relevant information is recorded. In one example, the user state program can send (e.g., 32*8192) read and write requests for the storage device 120 to the storage device driver 243 through the system call interface channel (e.g., ioctl interface channel) between the user state and the kernel state. In some embodiments, the storage device driver 243 stores multiple read and write requests from the user mode program to the storage device 120 in the first ring buffer 251 .
[0073] In some embodiments, the storage device driver 243 receives multiple read and write requests through a system call interface channel (e.g., an ioctl interface channel) between the user state and the kernel state, stores the multiple read and write requests in the first ring buffer 251, and stores the context information of the multiple read and write requests in the third ring buffer 253. In one example, ptr_ring_peek() can be called to read the pointer data of the consumer head position in the third ring buffer 253 to ensure the correctness of the data. In one example, ptr_ring_discard_one() can be called to update the status of the third ring buffer 253.
[0074] In step S320, a loop step is executed: the target read / write request pointed to by the head pointer in the first ring buffer is sent to the controller to implement data read / write operations on the memory and obtain a target read / write response to the target read / write request; the target read / write response is stored in the second ring buffer, wherein context information of the target read / write request and the target read / write response is stored in the third ring buffer; based on the context information of the target read / write request and the target read / write response, the target read / write response is sent to a corresponding user state program; the head pointer is moved down one position to clear the context information of the target read / write request and the target read / write response stored in the third ring buffer.
[0075] In some embodiments, the context information of the user-mode program's read and write request to the storage device 120 includes: a mapping of the logical address of the read and write request to the physical address. In some embodiments, the storage device driver 243 constructs a storage interface (e.g., SCSI interface) channel request according to the target read and write request pointed to by the head pointer in the first ring buffer 251 and the mapping of the logical address of the target read and write request to the physical address, and sends the storage interface channel request to the controller 121. In one example, ptr_ring_produce() can be called to process production data for the first ring buffer 251, and after obtaining the memory 122 of the storage device 120, the storage interface channel request information is filled and the storage interface channel request is constructed using a spin lock protection method, and then the storage interface channel request is sent to the controller 121, and the firmware 124 stores the storage interface channel request in the data buffer 123, so that the firmware 124 performs data read and write operations on the memory 122 according to the storage interface channel request, and obtains the target read and write response of the target read and write request.
[0076] In some embodiments, the user state program sends a tracking command for tracking the execution status of the target read and write request to the storage device driver 243 through the system call interface channel (e.g., ioctl interface channel) between the user state and the kernel state. In some embodiments, the storage device driver 243 receives the tracking command for tracking the execution status of the target read and write request through the system call interface channel between the user state and the kernel state, stores the target read and write response in the second ring buffer 252 based on the tracking command, and stores the context information of the target read and write response in the third ring buffer 253.
[0077] In some embodiments, the user state program sends the retrieval command for retrieving the target read / write response to the storage device driver 243 through the system call interface channel (e.g., ioctl interface channel) between the user state and the kernel state. In some embodiments, the storage device driver 243 receives the retrieval command for retrieving the target read / write response through the system call interface channel between the user state and the kernel state, restores the original context of the user state based on the context information of the target read / write request, stores the target read / write response in the user state, restores the original context of the kernel state based on the context information of the target read / write response, and returns to the execution loop step, that is, returns to the execution to shift the head pointer in the first ring buffer 251 by one position, and clears the context information of the target read / write request and the target read / write response stored in the third ring buffer 253. In one example, ptr_ring_consume_batched() is called to send the target read / write response stored in the second ring buffer 252 to the corresponding user state program.
[0078] It is easy to understand that the pointer is directly passed from the first ring buffer to the third ring buffer, and there is no need to copy the data itself, which avoids frequent copying of data between different threads, reduces memory copies during data transmission, reduces the number of times data is moved in memory, and reduces system overhead. By sharing the first ring buffer to the third ring buffer in kernel state, user-state programs are prevented from frequently creating and destroying threads, and each thread in the multi-threaded model needs to occupy certain resources, saving system resources. The pointer operation of the kernel-state ring buffer is used to realize the transmission and processing of multiple read and write requests of the user-state program to the storage device, reducing the competition and waiting time between multiple threads, improving the concurrency performance of the kernel state in the host of the storage device, and thereby increasing the number of input / output operations per second of the storage device.
[0079] It is easy to understand that the user-mode program sends multiple read and write requests for the storage device to the storage device driver through the system call interface channel between the user mode and the kernel mode. By sending requests with the same attributes, the storage device cache hit rate can be improved, and more adjacent data blocks in the storage device can be accessed.
[0080] It is easy to understand that storing multiple read and write requests of the user mode program to the storage device in a one-time circular manner in the first ring buffer 251 can reduce the communication overhead of cyclic writing-executing 1 command, and can improve the concurrency performance of the kernel mode in the host of the storage device.
[0081] Figure 4 The following is a flowchart of a request processing method provided according to an embodiment of the present disclosure. The request processing method of the embodiment of the present disclosure is applied to the kernel state. Figure 4 , the request processing method includes steps S401 to S411.
[0082] In step S401 , the storage device driver 243 instantiates the first ring buffer 251 , the second ring buffer 252 , and the third ring buffer 253 , respectively, and pre-allocates storage space for the third ring buffer 253 .
[0083] In step S402, the storage device driver 243 initializes the storage device 120 as a miscdevice structure dev device in kernel mode, and registers the storage device 120 so as to access and operate it when performing read and write operations in the operating system.
[0084] In step S403 , the user state program sends multiple read and write requests for the storage device 120 to the storage device driver 243 through the system call interface channel (eg, ioctl interface channel) between the user state and the kernel state.
[0085] In step S404 , the storage device driver 243 receives multiple read and write requests through the system call interface channel between the user state and the kernel state, stores the multiple read and write requests in the first ring buffer 251 , and stores the context information of the multiple read and write requests in the third ring buffer 253 .
[0086] In step S405 , the storage device driver 243 constructs a storage interface (eg, SCSI interface) channel request based on the target read / write request pointed to by the head pointer in the first ring buffer 251 and the mapping of the logical address of the target read / write request to the physical address, and sends the storage interface channel request to the controller 121 .
[0087] In step S406 , the firmware 124 performs data read and write operations on the memory 122 according to the storage interface channel request, and obtains a target read and write response to the target read and write request.
[0088] In step S407 , the user state program sends a tracking command for tracking the execution status of the target read / write request to the storage device driver 243 through the system call interface channel between the user state and the kernel state.
[0089] In step S408, the storage device driver 243 receives a tracking command for tracking the execution status of the target read and write request through the system call interface channel between the user state and the kernel state, stores the target read and write response in the second ring buffer 252 based on the tracking command, and stores the context information of the target read and write response in the third ring buffer 253.
[0090] In step S409 , the user state program sends a retrieval command for retrieving the target read / write response to the storage device driver 243 through the system call interface channel between the user state and the kernel state.
[0091] In step S410, the storage device driver 243 receives a retrieval command for retrieving a target read / write response through a system call interface channel between the user state and the kernel state, restores the original context of the user state based on the context information of the target read / write request, and stores the target read / write response in the user state.
[0092] In step S411, the original context in kernel mode is restored based on the context information of the target read / write response.
[0093] In step S412, the head pointer in the first ring buffer 251 is moved down by one position, and the context information of the target read / write request and the target read / write response stored in the third ring buffer 253 is cleared. The process returns to step S405.
[0094] Figure 5 FIG. 1 is a schematic diagram of a request processing device according to an embodiment of the present disclosure. Figure 5As shown, the request processing device 500 includes a read / write request storage unit 510 and a target read / write request execution unit 520 .
[0095] The read / write request storage unit 510 is used to store multiple read / write requests of a user-mode program to a storage device in a first ring buffer, wherein the storage device includes a controller and a memory.
[0096] The target read / write request execution unit 520 is used to execute the following loop steps: sending the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement data read / write operations on the memory and obtain a target read / write response to the target read / write request; storing the target read / write response in the second ring buffer, wherein the context information of the target read / write request and the target read / write response is stored in the third ring buffer; based on the context information of the target read / write request and the target read / write response, sending the target read / write response to the corresponding user state program; moving the head pointer down by one position and clearing the context information of the target read / write request and the target read / write response stored in the third ring buffer.
[0097] Since the process of using the request processing method in the embodiment of the present disclosure to process multiple read and write requests of the user mode program to the storage device 120 has been described in detail above, it will not be repeated here.
[0098] The present disclosure also provides an electronic device, such as Figure 6 As shown, it includes a memory 620, a processor 610, and a program stored in the memory 620 and executable on the processor 610. When the program is executed by the processor 610, each process of each embodiment of the above-mentioned request processing method can be implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0099] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, the embodiments of the present disclosure also provide a storage medium, on which a computer program or instruction is stored, and when the computer program or instruction is executed by the processor, each process in each embodiment of the above request processing method can be implemented.
[0100] Since the instructions stored in the storage medium can execute the steps in the request processing method provided in the embodiment of the present disclosure, the beneficial effects that can be achieved by the request processing method provided in the embodiment of the present disclosure can be achieved. For details, please refer to the previous embodiment, which will not be repeated here. The specific implementation of each of the above operations can be referred to the previous embodiment, which will not be repeated here.
[0101] In summary, according to an embodiment of the present disclosure, applied to kernel mode, the storage device includes a controller and a memory, and multiple read and write requests of the user mode program to the storage device are stored in a first ring buffer. Then, a loop step is executed: the target read and write request pointed to by the head pointer in the first ring buffer is sent to the controller to implement data read and write operations on the memory, and a target read and write response of the target read and write request is obtained, and the target read and write response is stored in a second ring buffer, wherein context information of the target read and write request and the target read and write response is stored in a third ring buffer, and based on the context information of the target read and write request and the target read and write response, the target read and write response is sent to the corresponding user mode program, the head pointer is moved down by one position, and the context information of the target read and write request and the target read and write response stored in the third ring buffer is cleared, so that the pointer operation of the kernel mode ring buffer is used to realize the transmission and processing of multiple read and write requests of the user mode program to the storage device, thereby reducing the competition and waiting time between multiple threads, improving the concurrency performance of the kernel mode in the host of the storage device, and thereby improving the number of input / output operations per second of the storage device.
[0102] Finally, it should be noted that: Obviously, the above embodiments are only examples for clearly illustrating the present disclosure, and are not intended to limit the implementation methods. For ordinary technicians in the relevant field, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from this are still within the scope of protection of the present disclosure.
Claims
1. A request processing method, applied in kernel mode, comprising: storing multiple read and write requests of a user-mode program to a storage device in a first ring buffer, wherein the storage device includes a controller and a memory; Execute the loop step: send the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement the data read / write operation on the memory and obtain the target read / write response of the target read / write request; storing the target read / write response in a second ring buffer, wherein context information of the target read / write request and the target read / write response is stored in a third ring buffer; Based on the context information of the target read / write request and the target read / write response, sending the target read / write response to a corresponding user state program; The head pointer is moved down by one position, and the context information of the target read / write request and the target read / write response stored in the third ring buffer is cleared.
2. The request processing method according to claim 1, wherein: Before storing the plurality of read and write requests of the user mode program to the storage device in the first ring buffer, the request processing method further comprises: Instantiate the first ring buffer, the second ring buffer and the third ring buffer respectively; Pre-allocate storage space for the third ring buffer.
3. The request processing method according to claim 1, wherein: The storing of multiple read and write requests of the user mode program to the storage device in the first ring buffer comprises: Receiving the multiple read and write requests through a system call interface channel between a user state and a kernel state; storing the plurality of read and write requests in the first ring buffer; The context information of the plurality of read and write requests is stored in the third ring buffer.
4. The request processing method according to claim 3, wherein: The context information of the read / write request includes: a mapping of the logical address of the read / write request to a physical address, The step of sending the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement the data read / write operation on the memory, and obtaining the target read / write response to the target read / write request includes: constructing a storage interface channel request based on the target read / write request and a mapping of the logical address of the target read / write request to the physical address, and sending the storage interface channel request to the controller; The controller performs data read and write operations on the memory according to the storage interface channel request to obtain a target read and write response to the target read and write request.
5. The request processing method according to claim 3, wherein: The storing the target read / write response in the second ring buffer comprises: Receiving a tracking command for tracking the execution status of the target read / write request through a system call interface channel between a user state and a kernel state; storing the target read and write responses in the second ring buffer based on the tracking command; The context information of the target read / write response is stored in the third ring buffer.
6. The request processing method according to claim 5, wherein: The sending the target read / write response to the corresponding user state program based on the context information of the target read / write request and the target read / write response includes: Receiving a retrieval command for retrieving the target read / write response through a system call interface channel between a user state and a kernel state; Based on the context information of the target read / write request, restore the original context in the user state, and store the target read / write response in the user state; Based on the context information of the target read / write response, the original context of the kernel state is restored, and the loop steps are executed again.
7. The request processing method according to claim 1, wherein: Before storing the plurality of read and write requests of the user mode program to the storage device in the first ring buffer, the request processing method further comprises: The storage device is initialized as a miscellaneous device structure device, and the storage device is registered.
8. A request processing device, applied in kernel mode, comprising: A read / write request storage unit, used for storing a plurality of read / write requests of a user-mode program to a storage device in a first ring buffer, wherein the storage device includes a controller and a memory; a target read / write request execution unit, configured to execute a loop step: sending the target read / write request pointed to by the head pointer in the first ring buffer to the controller to implement a data read / write operation on the memory, and obtaining a target read / write response to the target read / write request; storing the target read / write response in a second ring buffer, wherein context information of the target read / write request and the target read / write response is stored in a third ring buffer; Based on the context information of the target read / write request and the target read / write response, sending the target read / write response to a corresponding user state program; The head pointer is moved down by one position, and the context information of the target read / write request and the target read / write response stored in the third ring buffer is cleared.
9. A storage system comprising: Storage devices, including controllers and memory; A computer device, comprising a request processing device running in kernel mode as described in claim 8, which is used to store multiple read and write requests of a user mode program to the storage device in a first ring buffer, and send the target read and write request pointed to by the head pointer in the first ring buffer to the controller to implement data read and write operations on the memory, and obtain a target read and write response to the target read and write request.
10. A storage medium having a computer program or instruction stored thereon, wherein the computer program or instruction, when executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Local storage IO protocol stack data interaction method and device
CN111209123A
DMA data transmission system and method
CN114416613A
Content data distribution system, content data distribution method, connection management device, terminal device, and its program
JP2007265172A
Reproducer and reproduction method
JP2009130376A
Lock-free sharing of live-recorded circular buffer resources
US20210109857A1
Cited By
Lock-free annular real-time streaming system applied to electroencephalogram
CN119587047A
