User mode file read-write method, system and equipment based on shared memory

By introducing shared memory and coroutine mechanisms into the user-state file system, the performance overhead problems caused by multiple data copying and thread switching during data reading and writing of the user-state file system is solved, and more efficient data read and write performance and lower IO latency are achieved.

CN119781694AActive Publication Date: 2025-04-08CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411986111.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-04-08
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

When reading and writing data, the existing user-state file system has high performance overhead due to multiple data copies from user-state to kernel state, kernel-state to user-state, and thread switching, especially in the case of high IO pressure.

Method used

Using the user-state file reading and writing method based on shared memory, create shared memory through fuse user-state processes, and listen to read or write requests in shared memory, reduce data copying and thread switching, and introduce coroutine mechanisms to optimize thread scheduling.

Benefits of technology

It reduces the overhead of data copying and thread switching, improves data read and write performance, reduces IO link delay, and reduces the overhead of resource application and release.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781694A_ABST
    Figure CN119781694A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of user mode file reading and writing, and provides a user mode file reading and writing method, system and equipment based on a shared memory, and the method comprises the steps: when a user program reads data of a file in a mounting directory, triggering a fuse kernel mode thread to create a memory for storing read data and a read request in the shared memory, after the fuse user mode process monitors a read request of the shared memory, reading data from the back-end memory, storing the data into the shared memory, and sending corresponding read reply and data to a user program through a fuse kernel mode thread; when a user program writes data into a file in a mounting directory, a fuse kernel mode thread is triggered to create a memory used for storing written data and a write request in a shared memory, after a fuse user mode process monitors the write request of the shared memory, the written data is stored in a back end, and a corresponding write reply is obtained from the shared memory through the fuse kernel mode thread and sent to the user program. According to the method, the data read-write performance can be improved, and the thread switching and resource application overhead can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of user-mode file reading and writing, and in particular to a user-mode file reading and writing method, system and device based on shared memory. Background Art

[0002] The file system in userspace (hereinafter referred to as fuse) provides an interface to developers through the support of the fuse kernel module. Developers only need to perform file operations according to the interface provided by fuse to implement a file system. Although the file system in userspace simplifies the implementation of the file system and provides convenience for developers, the performance overhead caused by the additional kernel mode / user mode switching has become a constraint on its application in actual scenarios.

[0003] In actual applications, when reading and writing data, two data copies will occur: from user state to kernel state and from kernel state to user state. For example, copying 1M of data will incur a cost of at least 60us. In addition, the thread model of fuse user state determines that many temporary threads will be generated and destroyed. When the IO pressure is high, many temporary IO threads will be generated, and a lot of additional cost will be incurred in thread switching.

[0004] Therefore, how to provide a user-mode file reading and writing method to reduce thread switching overhead and improve reading and writing efficiency and resource consumption has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] In view of this, in order to overcome the deficiencies of the prior art, the present application aims to provide a user-mode file reading and writing method, system and device based on shared memory.

[0006] According to a first aspect of the present application, a method for reading and writing user-mode files based on shared memory is provided, the method comprising: Start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files; Create shared memory through the running fuse user-mode process, and create a listening thread to listen to the read or write requests in the shared memory; When the user program reads the data of the file in the mounted directory, the fuse kernel thread is triggered to create a memory and a read request in the shared memory for storing the read data. After the fuse user process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel thread; When the user program writes data to a file in the mounted directory, the fuse kernel-state thread is triggered to create memory and a write request in the shared memory to store the written data. After the fuse user-state process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-state thread, and sends it to the user program.

[0007] Optionally, in the shared memory-based user-mode file reading and writing method of the present application, shared memory is created by running a fuse user-mode process, including: when the fuse user-mode process is running, shared memory is created by registering through an mmap function, and the shared memory includes a data area and a control area.

[0008] Optionally, in the shared memory-based user-mode file reading and writing method of the present application, the shared memory created by the running fuse user-mode process can be accessed by both user mode and kernel mode.

[0009] Optionally, in the user-state file reading and writing method based on shared memory of the present application, a listening thread is created to listen to read or write requests in the shared memory, including: when the fuse user-state process is running, a fixed number of threads are created, a coroutine task is set for each thread, and the thread with the coroutine task continuously monitors whether there is a read or write request in the control area of ​​the shared memory.

[0010] Optionally, in the user-mode file reading and writing method based on shared memory of the present application, when the user program reads the data of the file in the mounted directory, the fuse kernel-mode thread is triggered to create memory and a read request in the shared memory for storing the read data, including: the user program calls the read interface of the libc library to read the data of the file in the mounted directory generated by the fuse user-mode process, triggering the fuse kernel-mode thread to create memory in the data area of ​​the shared memory for storing the read data, creating a read request and placing the created read request into the control area of ​​the shared memory, and the fuse kernel-mode thread enters a blocked state and waits for a reply to wake up.

[0011] Optionally, in the shared memory-based user-mode file reading and writing method of the present application, after the fuse user-mode process monitors the shared memory read request, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel-mode thread, including: The thread of the fuse user-state process listens to the read request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area to the user-state address, creates the corresponding read coroutine task, reads data from the backend storage by executing the read coroutine task, stores the read data in the memory of the data area of ​​the shared memory, writes the read reply corresponding to the read request to the control area of ​​the shared memory, and wakes up the fuse kernel-state thread; The awakened fuse kernel-mode thread obtains the corresponding read reply and data from the shared memory, and sends the corresponding read reply and data to the user program.

[0012] Optionally, in the user-mode file reading and writing method based on shared memory of the present application, when a user program writes data to a file in a mounted directory, the fuse kernel-mode thread is triggered to create memory and a write request in the shared memory for storing the written data, including: the user program calls the write interface of the libc library to write data to the file in the mounted directory generated by the fuse user-mode process, triggering the fuse kernel-mode thread to create memory in the data area of ​​the shared memory for storing the written data, creating a write request and placing the created write request in the control area of ​​the shared memory, and the fuse kernel-mode thread enters a blocked state and waits for a reply to wake up.

[0013] Optionally, in the shared memory-based user-mode file reading and writing method of the present application, after the fuse user-mode process listens to the write request of the shared memory, it writes data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-mode thread, and sends it to the user program, including: The thread of the fuse user-state process listens to the write request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area into the user-state address, creates the corresponding write coroutine task, writes data to the backend storage by executing the write coroutine task, writes the write reply corresponding to the write request into the control area of ​​the shared memory, and wakes up the fuse kernel-state thread; The awakened fuse kernel-mode thread obtains the corresponding write reply from the shared memory and sends it to the user program.

[0014] According to a second aspect of the present application, a user-mode file reading and writing system based on shared memory is provided, the system comprising a reading and writing server, the reading and writing server comprising: The fuse user state process startup module is used to start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files; The shared memory creation module is used to create shared memory through the running fuse user-mode process and create a listening thread to listen to the read or write requests in the shared memory; The user-mode file reading module is used to trigger the fuse kernel-mode thread to create a memory and a read request in the shared memory to store the read data when the user program reads the data of the file in the mounted directory. After the fuse user-mode process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel-mode thread; The user-mode file writing module is used to trigger the fuse kernel-mode thread to create memory and write requests in the shared memory to store the written data when the user program writes data to the file in the mounted directory. After the fuse user-mode process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-mode thread, and sends it to the user program.

[0015] According to a third aspect of the present application, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect of the present application when executing the program.

[0016] The user-mode file reading and writing method and system based on shared memory in this application have the following beneficial technical effects: 1. To address the data copy overhead caused by switching between user mode and kernel mode, a shared memory mechanism is introduced in the fuse file system to reduce data copying, improve data read and write performance, and reduce IO link latency. 2. In view of the generation and destruction of temporary threads in the fuse thread model when IO is busy, as well as the overhead caused by thread switching, a coroutine mechanism is introduced in the fuse file system to reduce the overhead in thread scheduling switching and resource application. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0018] Figure 1 This is an example diagram of the architecture of a user-mode file reading and writing system based on shared memory according to an embodiment of the present application; Figure 2This is an example diagram of the architecture of a read-write server of a user-mode file read-write system based on shared memory according to an embodiment of the present application; Figure 3 This is a first example diagram of executing the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Figure 4 A second example diagram of executing the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Figure 5 A third execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Figure 6 This is a fourth execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Figure 7 A fifth execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Figure 8 This is a sixth execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Fig. 9 FIG. 7 is a seventh execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Fig.10 This is an eighth execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Fig.11 This is a ninth execution example diagram of the shared memory-based user-mode file reading and writing method according to an embodiment of the present application; Fig.12 A schematic diagram of the structure of the device provided in this application. DETAILED DESCRIPTION

[0019] The embodiments of the present application are described in detail below with reference to the accompanying drawings.

[0020] It should be noted that the following embodiments and features in the embodiments may be combined with each other in the absence of conflict; and, based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making any creative work are within the scope of protection of the present disclosure.

[0021] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.

[0022] Figure 1 FIG. 1 is an example diagram of the architecture of a user-mode file reading and writing system based on shared memory according to an embodiment of the present application. Figure 1 As shown, the system may include a read / write server 101, a communication network 102 and / or one or more read / write clients 103. Figure 1 The example shown is a plurality of read-write clients 103 .

[0023] The read-write server 101 can be any suitable server for storing information, data, programs and / or any other suitable type of content. In some embodiments, the read-write server 101 can perform appropriate functions. For example, in some embodiments, the read-write server 101 can be used to read and write user-mode files based on shared memory. As an optional example, in some embodiments, the read-write server 101 can be used to: start the fuse user-state process by loading the fuse user-state program, and generate a mount directory for accessing read and write files; create shared memory through the running fuse user-state process, and create a listening thread to listen to read or write requests in the shared memory; when the user program reads data of a file in the mounted directory, the fuse kernel-state thread is triggered to create a memory and a read request in the shared memory for storing the read data. After the fuse user-state process listens to the read request of the shared memory, the data is read from the back-end storage and stored in the shared memory, and the corresponding read reply and data are sent to the user program through the fuse kernel-state thread; when the user program writes data to a file in the mounted directory, the fuse kernel-state thread is triggered to create a memory and a write request in the shared memory for storing the written data. After the fuse user-state process listens to the write request of the shared memory, the data is written to the back-end storage, and the corresponding write reply is obtained from the shared memory through the fuse kernel-state thread and sent to the user program.

[0024] Figure 2 FIG. 1 is an example diagram of the architecture of a read-write server of a user-mode file read-write system based on shared memory according to an embodiment of the present application, such as Figure 2 As shown, in this embodiment, the read-write server includes: The fuse user state process startup module is used to start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files; The shared memory creation module is used to create shared memory through the running fuse user-mode process and create a listening thread to listen to the read or write request in the shared memory; The user-mode file reading module is used to trigger the fuse kernel-mode thread to create a memory and a read request in the shared memory to store the read data when the user program reads the data of the file in the mounted directory. After the fuse user-mode process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel-mode thread; The user-mode file writing module is used to trigger the fuse kernel-mode thread to create memory and write requests in the shared memory to store the written data when the user program writes data to the file in the mounted directory. After the fuse user-mode process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-mode thread, and sends it to the user program.

[0025] As another example, in some embodiments, the read / write server 101 may send a shared memory-based user-mode file read / write method to the read / write client 103 for user use based on a request of the read / write client 103 .

[0026] As an optional example, in some embodiments, the read-write client 103 is used to provide a visual read-write interface, which is used to receive a user's selection input operation for reading and writing user-state files based on shared memory, and to respond to the selection input operation, obtain the read-write interface corresponding to the option selected by the selection input operation from the read-write server 101 and display the read-write interface, wherein the read-write interface at least displays information on reading and writing user-state files based on shared memory and operation options for reading and writing information on reading and writing user-state files based on shared memory.

[0027] In some embodiments, the communication network 102 can be any suitable combination of one or more wired and / or wireless networks. For example, the communication network 102 can include any one or more of the following: the Internet, an intranet, a wide area network (WAN), a local area network (LAN), a wireless network, a digital subscriber line (DSL) network, a frame relay network, an asynchronous transfer mode (ATM) network, a virtual private network (VPN) and / or any other suitable communication network. The read-write client 103 can be connected to the communication network 102 via one or more communication links (e.g., communication link 104), and the communication network 102 can be linked to the read-write service end 101 via one or more communication links (e.g., communication link 105). The communication link can be any communication link suitable for transmitting data between the read-write client 103 and the read-write service end 101, such as a network link, a dial-up link, a wireless link, a hard-wired link, any other suitable communication link or any suitable combination of such links.

[0028] The read-write client 103 may include any one or more clients that present an interface related to reading and writing user state files based on shared memory through appropriate forms for use and operation by the user. In some embodiments, the read-write client 103 may include the device of any suitable type. For example, in some embodiments, the read-write client 103 may include a mobile device, a tablet computer, a laptop computer, a desktop computer and / or any other suitable type of client device.

[0029] Although the read-write server 101 is illustrated as one device, in some embodiments, any suitable number of devices may be used to perform the functions performed by the read-write server 101. For example, in some embodiments, multiple devices may be used to implement the functions performed by the read-write server 101. Alternatively, the functions of the read-write server 101 may be implemented using a cloud service.

[0030] Based on the above system, an embodiment of the present application provides a user-mode file reading and writing method based on shared memory, which is illustrated by the following embodiments.

[0031] The shared memory-based user-mode file reading and writing method of this embodiment can be executed on the reading and writing server. The shared memory-based user-mode file reading and writing method includes the following steps: First, in an embodiment of the present application, a fuse user state process is started by loading a fuse user state program to generate a mount directory for accessing read and write files.

[0032] Secondly, in the embodiment of the present application, a shared memory is created by running a fuse user-mode process, and a listening thread is created to listen to read or write requests in the shared memory.

[0033] Figure 3 FIG. 1 is a first example diagram of an execution of a user-mode file reading and writing method based on shared memory according to an embodiment of the present application, such as Figure 3 As shown, in this embodiment, when the fuse user state process is running, the mmap function is used to register and create a shared memory, which includes a data area and a control area. It should be noted that in this embodiment, the shared memory created by the running fuse user state process can be accessed by the user state and the kernel state. When the fuse user state process is running, a fixed number of threads are created, and a coroutine task is set for each thread. The thread with the coroutine task continuously monitors whether there is a read or write request in the control area of ​​the shared memory. The mmap function is a system call function used in Unix and Unix-like operating systems. It allows a program to map a file or other object to the address space of a process to achieve file mapping in memory. In this way, modifications to this memory area will be directly reflected in the file, and data can also be read directly from the file into the memory.

[0034] In actual applications, when a user program reads data from a file in a mounted directory, the fuse kernel-state thread is triggered to create memory and a read request in the shared memory to store the read data. After the fuse user-state process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel-state thread.

[0035] Figure 4 FIG. 2 is a second example diagram of the user mode file reading and writing method based on shared memory according to an embodiment of the present application, such as Figure 4 As shown, in this embodiment, the user program calls the read interface of the libc library to read the data of the file in the mount directory generated by the fuse user state process, triggering the fuse kernel state thread to create a memory for storing the read data in the data area of ​​the shared memory, create a read request and put the created read request into the control area of ​​the shared memory, and the fuse kernel state thread enters a state of blocking and waiting for a reply wake-up. The libc library is a common abbreviation for the C Standard Library, which is the implementation of the C language standard library in most Unix and Unix-like operating systems. The libc library provides a series of standard functions that are used to perform basic tasks, such as file operations, string processing, mathematical calculations, memory allocation, etc.

[0036] Figure 5 FIG. 3 is a third execution example diagram of the user mode file reading and writing method based on shared memory according to an embodiment of the present application, such as Figure 5As shown, in this embodiment, the thread of the fuse user-state process listens to the read request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area into a user-state address, creates a corresponding read coroutine task, and reads data from the backend storage by executing the read coroutine task.

[0037] Figure 6 FIG. 4 is a fourth execution example diagram of the method for reading and writing user-mode files based on shared memory according to an embodiment of the present application, such as Figure 6 As shown, in this embodiment, after reading data from the back-end storage, this embodiment stores the read data in the memory of the data area of ​​the shared memory, writes the read reply corresponding to the read request into the control area of ​​the shared memory, and wakes up the fuse kernel state thread.

[0038] Figure 7 FIG. 5 is a fifth execution example diagram of the method for reading and writing user-mode files based on shared memory according to an embodiment of the present application, such as Figure 7 As shown, in this embodiment, the awakened fuse kernel state thread obtains the corresponding read reply and data from the shared memory, obtains the corresponding read reply and data and sends them to the user program.

[0039] In actual applications, when a user program writes data to a file in a mounted directory, the fuse kernel-state thread is triggered to create memory and a write request in the shared memory to store the written data. After the fuse user-state process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-state thread, and sends it to the user program.

[0040] Figure 8 FIG. 6 is a sixth execution example diagram of the shared memory-based user mode file reading and writing method according to an embodiment of the present application, such as Figure 8 As shown, in this embodiment, the user program calls the write interface of the libc library to write data to the file in the mount directory generated by the fuse user-state process, triggering the fuse kernel-state thread to create a memory for storing the write data in the data area of ​​the shared memory, create a write request and put the created write request into the control area of ​​the shared memory, and the fuse kernel-state thread enters a blocked state and waits for a reply to wake up.

[0041] Fig. 9 FIG. 7 is a seventh execution example diagram of the method for reading and writing user-mode files based on shared memory according to an embodiment of the present application, as shown in FIG. Fig. 9As shown, in this embodiment, the thread of the fuse user-state process listens to the write request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area into a user-state address, creates a corresponding write coroutine task, and writes data to the backend storage by executing the write coroutine task.

[0042] Fig.10 FIG. 8 is an eighth execution example diagram of the method for reading and writing user-mode files based on shared memory according to an embodiment of the present application, as shown in FIG. Fig.10 As shown, in this embodiment, the write reply corresponding to the write request is written into the control area of ​​the shared memory to wake up the fuse kernel state thread.

[0043] Fig.11 FIG. 9 is a ninth execution example diagram of the method for reading and writing user-mode files based on shared memory according to an embodiment of the present application, as shown in FIG. Fig.11 As shown, the awakened fuse kernel-mode thread obtains the corresponding write reply from the shared memory and sends it to the user program.

[0044] The user-mode file reading and writing method and system based on shared memory of this embodiment have the following beneficial technical effects: 1. To address the data copy overhead caused by switching between user mode and kernel mode, a shared memory mechanism is introduced in the fuse file system to reduce data copying, improve data read and write performance, and reduce IO (input and output) link latency; 2. In view of the generation and destruction of temporary threads in the fuse thread model when IO is busy, as well as the overhead caused by thread switching, a coroutine mechanism is introduced in the fuse file system to reduce the overhead in thread scheduling switching and resource application.

[0045] like Fig.12 As shown, the present application also provides a device, including a processor 310, a communication interface 320, a memory 330 for storing a processor executable computer program, and a communication bus 340. The processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 implements the above-mentioned user-mode file reading and writing method based on shared memory by running the executable computer program.

[0046] Among them, the computer program in the memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0047] The system embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected based on actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.

[0048] Through the description of the above implementation modes, those skilled in the art can clearly understand that each implementation mode can be implemented by means of software plus a necessary general hardware platform, or of course by hardware. Based on such an understanding, the above technical solution can essentially or in other words be embodied in the form of a software product that contributes to the prior art. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.

[0049] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A user-mode file reading and writing method based on shared memory, characterized in that: The method comprises: Start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files; Create shared memory through the running fuse user-mode process, and create a listening thread to listen to the read or write requests in the shared memory; When the user program reads the data of the file in the mounted directory, the fuse kernel thread is triggered to create a memory and a read request in the shared memory for storing the read data. After the fuse user process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel thread; When the user program writes data to a file in the mounted directory, the fuse kernel-state thread is triggered to create memory and a write request in the shared memory to store the written data. After the fuse user-state process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-state thread, and sends it to the user program.

2. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: The shared memory is created by the running fuse user state process, including: when the fuse user state process is running, the shared memory is created by registering through the mmap function, and the shared memory includes a data area and a control area.

3. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: The shared memory created by the running fuse user-mode process can be accessed by both user-mode and kernel-mode.

4. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: Create a listening thread to listen to the read or write request in the shared memory, including: when the fuse user state process is running, create a fixed number of threads, set a coroutine task for each thread, and use the thread with the coroutine task to continuously monitor whether there is a read or write request in the control area of ​​the shared memory.

5. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: When the user program reads the data of the file in the mounted directory, the fuse kernel state thread is triggered to create memory and a read request in the shared memory for storing the read data, including: the user program calls the read interface of the libc library to read the data of the file in the mounted directory generated by the fuse user state process, triggering the fuse kernel state thread to create memory in the data area of ​​the shared memory for storing the read data, creating a read request and putting the created read request into the control area of ​​the shared memory, and the fuse kernel state thread enters a blocked state and waits for a reply to wake up.

6. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: After the fuse user-state process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory. The corresponding read reply and data are sent to the user program through the fuse kernel-state thread, including: The thread of the fuse user-state process listens to the read request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area to the user-state address, creates the corresponding read coroutine task, reads data from the backend storage by executing the read coroutine task, stores the read data in the memory of the data area of ​​the shared memory, writes the read reply corresponding to the read request to the control area of ​​the shared memory, and wakes up the fuse kernel-state thread; The awakened fuse kernel-mode thread obtains the corresponding read reply and data from the shared memory, and sends the corresponding read reply and data to the user program.

7. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: When the user program writes data to a file in the mounted directory, the fuse kernel-state thread is triggered to create memory and a write request in the shared memory for storing the written data, including: the user program calls the write interface of the libc library to write data to the file in the mounted directory generated by the fuse user-state process, triggering the fuse kernel-state thread to create memory in the data area of ​​the shared memory for storing the written data, creating a write request and putting the created write request into the control area of ​​the shared memory, and the fuse kernel-state thread enters a blocked state and waits for a reply to wake up.

8. The method for reading and writing user-mode files based on shared memory according to claim 1, characterized in that: After the fuse user-state process listens to the write request of the shared memory, it writes data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-state thread, and sends it to the user program, including: The thread of the fuse user-state process listens to the write request of the control area of ​​the shared memory through the coroutine task, converts the address of the data area into the user-state address, creates the corresponding write coroutine task, writes data to the backend storage by executing the write coroutine task, writes the write reply corresponding to the write request into the control area of ​​the shared memory, and wakes up the fuse kernel-state thread; The awakened fuse kernel-mode thread obtains the corresponding write reply from the shared memory and sends it to the user program.

9. A user-mode file reading and writing system based on shared memory, characterized in that: It is characterized in that The system includes a read-write server, and the read-write server includes: The fuse user state process startup module is used to start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files; The shared memory creation module is used to create shared memory through the running fuse user-mode process and create a listening thread to listen to the read or write requests in the shared memory; The user-mode file reading module is used to trigger the fuse kernel-mode thread to create a memory and a read request in the shared memory to store the read data when the user program reads the data of the file in the mounted directory. After the fuse user-mode process listens to the read request of the shared memory, it reads the data from the backend storage and stores it in the shared memory, and sends the corresponding read reply and data to the user program through the fuse kernel-mode thread; The user-mode file writing module is used to trigger the fuse kernel-mode thread to create memory and write requests in the shared memory to store the written data when the user program writes data to the file in the mounted directory. After the fuse user-mode process listens to the write request of the shared memory, it writes the data to the backend storage, obtains the corresponding write reply from the shared memory through the fuse kernel-mode thread, and sends it to the user program.

10. A computer device, characterized in that: The computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method according to any one of claims 1 to 8 when executing the program.

Citation Information

Patent Citations

  • File movement method by FUSE on Linux platform

    CN105740413A

  • File operation method of user space file system and user space file system

    CN114398318A

  • Data interaction method, device and equipment

    CN117193941A

  • Method for optimizing user mode file system framework FUSE

    CN118939279A

  • Autonomous deployment of multiple database file systems

    US20220164320A1