A user-mode file reading and writing method, system and device based on shared memory

By introducing shared memory and coroutine mechanisms into the user-mode file system, the performance issues caused by switching from user mode to kernel mode are resolved, efficient data reading and writing is achieved, and IO link latency and thread switching overhead are reduced.

CN119781694BActive Publication Date: 2025-09-23CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing user-mode file systems incur performance overhead and thread switching overhead caused by switching from user mode to kernel mode and vice versa during data reading and writing, resulting in low reading and writing efficiency.

Method used

Adopting the shared memory mechanism and coroutine mechanism, the shared memory is created through the fuse user-state process and thread requests are monitored, which reduces data copying and thread switching and realizes efficient data transmission between user state and kernel state.

Benefits of technology

It reduces the data copy overhead and thread switching overhead from user state to kernel state, improves data reading and writing performance and IO link latency, and improves reading and writing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781694B_ABST
    Figure CN119781694B_ABST
Patent Text Reader

Abstract

The present application relates to the field of user-mode file reading and writing technology, and provides a user-mode file reading and writing method, system, and device based on shared memory, including: when a user program reads data from a file in a mounted directory, a fuse kernel-mode thread is triggered to create memory and a read request in the shared memory for storing the read data; after the fuse user-mode process listens to the read request from 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-mode thread; when the user program writes data to a file in the mounted directory, a fuse kernel-mode thread is triggered to create memory and a write request in the shared memory for storing the written data; after the fuse user-mode process listens to the write request from 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-mode thread and sent to the user program. The present application can improve data reading and writing performance and reduce thread switching and resource application overhead.
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 method, system, and device for user-mode file reading and writing based on shared memory. Background Art

[0002] The userspace file system (FUSE) provides an interface to developers through the FUSE kernel module. Developers can implement a file system simply by performing file operations based on the FUSE interface. While userspace file systems simplify file system implementation and provide convenience for developers, the performance overhead of additional kernel-mode / user-mode switching limits their practical application.

[0003] In actual applications, data reading and writing requires two data copies: from user state to kernel state and then from kernel state to user state. For example, copying 1MB of data incurs a minimum overhead of approximately 60µs. Furthermore, the fuse user-state thread model dictates the creation and destruction of many temporary threads. When I / O pressure is high, many temporary I / O threads are generated, incurring significant additional overhead 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:

[0007] Start the fuse user state process by loading the fuse user state program and generate a mount directory for accessing read and write files;

[0008] Create shared memory through the running fuse user-mode process and create a listening thread to listen for read or write requests in the shared memory;

[0009] When a user program reads data from a file in the mounted directory, it triggers the fuse kernel thread to create memory in the shared memory to store the read data and a read request. After the fuse user process listens to the shared memory read request, 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 thread.

[0010] When a 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 to 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.

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

[0012] 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.

[0013] Optionally, in the user-mode 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-mode 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.

[0014] 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 for storing the read data and a read request in the shared memory, 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 for storing the read data in the data area of ​​the shared memory, 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.

[0015] 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:

[0016] 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;

[0017] 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.

[0018] Optionally, in the user-mode file reading and writing method based on shared memory of the present application, when the 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 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.

[0019] 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 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:

[0020] 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 to the user-state address, creates the corresponding write coroutine task, writes the data to the backend storage by executing the write coroutine task, writes the write reply corresponding to the write request to the control area of ​​the shared memory, and wakes up the fuse kernel-state thread;

[0021] The awakened fuse kernel-mode thread obtains the corresponding write reply from the shared memory and sends it to the user program.

[0022] 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 including a reading and writing server, the reading and writing server including:

[0023] 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;

[0024] 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 for read or write requests in the shared memory;

[0025] The user-mode file reading module is used to trigger the FUSE kernel-mode thread to create memory and read requests 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. The corresponding read reply and data are sent to the user program through the FUSE kernel-mode thread.

[0026] The user-mode file write 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.

[0027] 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.

[0028] The present application provides a user-mode file reading and writing method and system based on shared memory, which has the following beneficial technical effects:

[0029] 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 I / O link latency.

[0030] 2. To address the overhead of creating and destroying temporary threads in the fuse thread model and switching threads during busy IO operations, a coroutine mechanism is introduced in the fuse file system to reduce the overhead of thread scheduling, switching, and resource application. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. 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 any creative work.

[0032] 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;

[0033] Figure 2 This 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;

[0034] Figure 3 This is a first example diagram of an execution of a shared memory-based user-mode file reading and writing method according to an embodiment of the present application;

[0035] Figure 4 This is 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;

[0036] Figure 5 FIG3 is a third example diagram of executing the shared memory-based user-mode file reading and writing method according to an embodiment of the present application;

[0037] Figure 6 FIG4 is a fourth example diagram of executing the method for reading and writing user-mode files in a shared memory according to an embodiment of the present application;

[0038] Figure 7 FIG5 is 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;

[0039] Figure 8 FIG6 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;

[0040] Figure 9 FIG7 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;

[0041] Figure 10 FIG8 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;

[0042] Figure 11 FIG9 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;

[0043] Figure 12 A schematic diagram of the structure of the device provided in this application. DETAILED DESCRIPTION

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

[0045] It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments may be combined with each other; and, based on the embodiments in this disclosure, all other embodiments obtained by persons of ordinary skill in the art without creative work are within the scope of protection of this disclosure.

[0046] 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 can be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on this disclosure, it should be understood by those skilled in the art that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects described herein can be used to implement an apparatus and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this apparatus and / or practice this method.

[0047] 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 in FIG. 1 is a plurality of read-write clients 103 .

[0048] 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 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 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.

[0049] Figure 2 This is an example diagram of the architecture of the read-write server of the user-mode file read-write system based on shared memory according to an embodiment of the present application, as shown in FIG. Figure 2 As shown, in this embodiment, the read-write server includes:

[0050] 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;

[0051] 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 for read or write requests in the shared memory;

[0052] The user-mode file reading module is used to trigger the FUSE kernel-mode thread to create memory and read requests 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. The corresponding read reply and data are sent to the user program through the FUSE kernel-mode thread.

[0053] The user-mode file write 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.

[0054] 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 from the read / write client 103 .

[0055] 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 user-state files based on shared memory.

[0056] In some embodiments, the communication network 102 can be any appropriate 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 server 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 server 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.

[0057] 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 in an appropriate form for use and operation by the user. In some embodiments, the read-write client 103 may include a 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.

[0058] Although the read-write server 101 is illustrated as a single 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.

[0059] 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 described below through the following embodiments.

[0060] The shared memory-based user-mode file reading and writing method of this embodiment can be executed on a read-write server. The shared memory-based user-mode file reading and writing method includes the following steps:

[0061] First, in an embodiment of the present application, a fuse user-mode process is started by loading a fuse user-mode program to generate a mount directory for accessing read and write files.

[0062] Secondly, in an 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 for read or write requests in the shared memory.

[0063] Figure 3 FIG. 1 is a first example diagram of an execution of a shared memory-based user-mode file reading and writing method according to an embodiment of the present application. Figure 3As shown, in this embodiment, when the fuse user-state process is running, it registers and creates shared memory through the mmap function, and the shared memory 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 both user state and kernel state. When the fuse user-state process is running, it creates a fixed number of threads, sets a coroutine task for each thread, and continuously monitors whether there is a read or write request in the control area of ​​the shared memory through the thread with the coroutine task. 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, thereby realizing the mapping of the file in the 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.

[0064] 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 from 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.

[0065] 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. Figure 4 As shown, in this embodiment, the user program calls the libc library's read interface to read data from a file in a mounted directory generated by a fuse user-mode process. This triggers the fuse kernel-mode thread to create memory in the shared memory data area to store the read data, create a read request, and place the created read request in the shared memory control area. The fuse kernel-mode thread then enters a blocked state, awaiting a response. libc, a commonly used abbreviation for the C Standard Library, 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 for performing basic tasks such as file operations, string processing, mathematical calculations, and memory allocation.

[0066] Figure 5 FIG3 is a third example diagram of an execution of a shared memory-based user-mode file reading and writing method according to an embodiment of the present application, as shown in FIG3. 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 back-end storage by executing the read coroutine task.

[0067] Figure 6 FIG4 is a fourth example diagram of the user mode file reading and writing method based on shared memory according to an embodiment of the present application, as shown in FIG4. 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.

[0068] Figure 7 FIG5 is a fifth example diagram of the user mode file reading and writing method based on shared memory according to an embodiment of the present application, as shown in FIG5 . 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.

[0069] 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 to 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.

[0070] Figure 8 FIG6 is a sixth example diagram of the user-mode file reading and writing method based on shared memory according to an embodiment of the present application, as shown in FIG6 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 written 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.

[0071] Figure 9 FIG7 is a seventh example diagram of the user-mode file reading and writing method based on shared memory according to an embodiment of the present application, as shown in FIG. Figure 9As shown, in this embodiment, the thread of the fuse user-mode 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-mode address, creates a corresponding write coroutine task, and writes data to the back-end storage by executing the write coroutine task.

[0072] Figure 10 FIG8 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, as shown in FIG. Figure 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.

[0073] Figure 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. Figure 11 As shown in the figure, the awakened fuse kernel-mode thread obtains the corresponding write reply from the shared memory and sends it to the user program.

[0074] The shared memory-based user-mode file reading and writing method and system of this embodiment have the following beneficial technical effects:

[0075] 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. This reduces the number of data copies, improves data read and write performance, and reduces I / O (input and output) link latency.

[0076] 2. To address the overhead of creating and destroying temporary threads in the fuse thread model and switching threads during busy IO operations, a coroutine mechanism is introduced in the fuse file system to reduce the overhead of thread scheduling, switching, and resource application.

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

[0078] 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, or the part that contributes to the existing technology, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or 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 code.

[0079] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.

[0080] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods of each embodiment or certain portions of the embodiments.

[0081] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection 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 for read or write requests in the shared memory; When a user program reads data from a file in the mounted directory, it triggers the fuse kernel thread to create memory in the shared memory to store the read data and a read request. After the fuse user process listens to the shared memory read request, 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 thread. When a 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 to 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, wherein: 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 registered and created 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, wherein: 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, wherein: Create a listening thread to listen for read or write requests 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, wherein: 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 placing the created read request in 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, wherein: After the fuse user-state process listens to the shared memory read request, it reads the data from the backend storage and stores it in the shared memory. It then sends the corresponding read reply and data 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, wherein: When a 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, 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 to store the written data, 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.

8. The method for reading and writing user-mode files based on shared memory according to claim 1, wherein: After the fuse user-state process listens to the write request to 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 to the user-state address, creates the corresponding write coroutine task, writes the data to the backend storage by executing the write coroutine task, writes the write reply corresponding to the write 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 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 by: The system includes a read-write server, which 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 for 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 memory and read requests 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. The corresponding read reply and data are sent to the user program through the FUSE kernel-mode thread. The user-mode file write 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 includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method according to any one of claims 1 to 8 are implemented.

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