CN107729159B - Address mapping method and device for shared memory - Google Patents

Address mapping method and device for shared memory Download PDF

Info

Publication number
CN107729159B
CN107729159B CN201710909286.9A CN201710909286A CN107729159B CN 107729159 B CN107729159 B CN 107729159B CN 201710909286 A CN201710909286 A CN 201710909286A CN 107729159 B CN107729159 B CN 107729159B
Authority
CN
China
Prior art keywords
virtual address
kernel
controller
state
user
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710909286.9A
Other languages
Chinese (zh)
Other versions
CN107729159A (en
Inventor
赵冬梅
邓晓阳
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Huawei Technology Co Ltd
Original Assignee
Huawei Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201710909286.9A priority Critical patent/CN107729159B/en
Publication of CN107729159A publication Critical patent/CN107729159A/en
Application granted granted Critical
Publication of CN107729159B publication Critical patent/CN107729159B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Abstract

The application provides an address mapping method and device of a shared memory, relates to the technical field of data storage, and is used for improving the conversion efficiency between addresses of the shared memory. The method comprises the following steps: when a first controller receives a shared memory mapping request triggered by a first user mode process, the first controller acquires a first user mode virtual address from an appointed virtual address interval; the first controller determines a first kernel-state virtual address corresponding to the first user-state virtual address according to the designated virtual address interval, the first user-state virtual address and a first linear relation, wherein the first linear relation is used for indicating the relation between the user-state virtual address and the kernel-state virtual address; and determining a first physical address of a shared memory according to the first kernel-state virtual address and a second linear relationship, wherein the shared memory is a memory shared by the user-state process and the kernel-state process, and the second linear relationship is used for indicating the relationship between the kernel-state virtual address and the physical address.

Description

Address mapping method and device for shared memory
Technical Field
The embodiment of the application relates to the technical field of data storage, in particular to an address mapping method and device for a shared memory.
Background
At present, memory deployment is gradually switched from a kernel mode to a user mode, most of services are already deployed in the user mode, and the memory deployed in the user mode needs to be accessed by using a user mode virtual address. A small part of services (for example, drivers, etc.) are still deployed in the kernel mode, and are mainly used for Direct Memory Access (DMA) and Remote Direct Memory Access (RDMA) operations. In order to reduce data copy between user mode processes and between the user mode processes and kernel mode processes, the method can be realized in a memory sharing mode. Shared memory refers to a logical memory that allows multiple processes to share, and shared memory is the fastest method for sharing data among processes. When multiple processes in a user mode and a kernel mode access the same shared memory, the addresses of the shared memory need to be mapped into the address spaces of the multiple processes at the same time.
In the existing Linux system, a common shared memory mapping mechanism for a user mode and a kernel mode is provided, and the shared memory mapping mechanism comprises the following steps: and in the user mode, the system automatically allocates an idle user mode virtual address through a system call function. And distributing a section of memory through a memory distribution function in the kernel mode to obtain the virtual address of the section of memory. And converting the virtual address of the memory segment into a page frame through a system function, and converting the page frame into a physical address of a corresponding page through the page frame and a physical address conversion function. And finally, establishing a mapping relation between the physical address and the user mode virtual address, thereby realizing the mapping between the user mode and the kernel mode process in the shared memory. However, the user-state virtual addresses automatically allocated by the system are relatively random, so that the conversion between the user-state virtual addresses and the virtual addresses of the memory is irregular. Meanwhile, the translation between the virtual address and the physical address of the memory requires two calls of the system kernel function, so the address translation efficiency in the mapping mechanism is low.
Disclosure of Invention
Embodiments of the present invention provide a method and an apparatus for mapping addresses of a shared memory, which solve the problem in the prior art that the conversion efficiency between the addresses of the shared memory is low.
In order to achieve the above purpose, the embodiment of the invention adopts the following technical scheme:
in a first aspect, a method for mapping addresses of a shared memory is provided, where the method includes: when a first controller receives a shared memory mapping request triggered by a first user mode process, the first controller acquires a first user mode virtual address from an appointed virtual address interval; the first controller determines a first kernel-state virtual address corresponding to the first user-state virtual address according to the designated virtual address interval, the first user-state virtual address and a first linear relation, wherein the first linear relation is used for indicating the relation between the user-state virtual address and the kernel-state virtual address; and determining a first physical address of a shared memory according to the first kernel-state virtual address and a second linear relationship, wherein the shared memory is a memory shared by the user-state process and the kernel-state process, and the second linear relationship is used for indicating the relationship between the kernel-state virtual address and the physical address. In the above technical solution, the first controller may implement linear conversion between the user-state virtual address and the kernel-state virtual address by specifying the user-state virtual address interval and the first linear relationship, and implement linear conversion between the kernel-state virtual address and the physical address of the shared memory by using the second linear relationship, so that conversion efficiency between the addresses may be improved, and then access efficiency of data in the shared memory may be improved.
In a possible implementation manner of the first aspect, when the starting address of the specified virtual address interval is a0, the first user-state virtual address is a1, and the first kernel-state virtual address is a2, the first linear relationship includes formula (1), where m is a constant:
A2=A1-A0+m (1)。
in one possible implementation manner of the first aspect, when the first kernel-state virtual address is a2 and the first physical address is A3, the second linear relationship includes formula (2), where m is a constant:
A3=A2-m (2)。
in the two possible implementation manners, a relationship for linear translation between the user-state virtual address and the kernel-state virtual address and a relationship for linear translation between the kernel-state virtual address and the physical address are provided.
In a possible implementation manner of the first aspect, when the second user-mode process shares the shared memory, the method further includes: the first controller configures one or more of the following information for the second user mode process: the designated virtual address space, the physical address interval of the shared space, the first linear relationship and the second linear relationship. In the possible implementation manner, the first user mode process and the second user mode process may share the same shared memory, so that the first user mode process may access the second user mode process to write data in the shared memory, and the second user mode process may also access the first user mode process to write data in the shared memory, thereby avoiding copying of data between the user mode processes, and improving the access efficiency of data
In a possible implementation manner of the first aspect, when the third kernel-state process shares the shared memory, the method further includes: the first controller configures one or more of the following information for the third kernel-state process: a physical address range of the shared space, a second linear relationship. In the possible implementation manner, the first user mode process and the third kernel mode process may share the same shared memory, so that the first user mode process may access the third kernel mode process to write data in the shared memory, and the third kernel mode process may also access the first user mode process to write data in the shared memory, thereby avoiding copying of data between the user mode process and the kernel mode process, and improving the access efficiency of data.
In a possible implementation manner of the first aspect, the method further includes: the first controller sends a data access request to the second controller, the data access request is used for accessing data of the memory in the second controller, and a kernel-state virtual address of the memory in the second controller and a physical address of the memory meet a second linear relation. In the possible implementation manner, data forwarding and accessing can be directly performed between the first controller and the second controller, so that data access across controllers is realized, and the performance of the storage system can be improved.
In a second aspect, there is provided a controller as a first controller, including: the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a first user state virtual address from a specified virtual address interval when receiving a shared memory mapping request triggered by a first user state process; a determining unit, configured to determine, by the first controller, a first kernel-state virtual address corresponding to the first user-state virtual address according to the specified virtual address interval, the first user-state virtual address, and a first linear relationship, where the first linear relationship is used to indicate a relationship between the user-state virtual address and the kernel-state virtual address; the determining unit is further configured to determine a first physical address of a shared memory according to the first kernel-state virtual address and a second linear relationship, where the shared memory is a memory shared by the user-state process and the kernel-state process, and the second linear relationship is used to indicate a relationship between the kernel-state virtual address and the physical address.
In a possible implementation manner of the second aspect, when the starting address of the specified virtual address interval is a0, the first user-state virtual address is a1, and the first kernel-state virtual address is a2, the first linear relationship includes formula (3), where m is a constant:
A2=A1-A0+m (3)。
in one possible implementation manner of the second aspect, when the first kernel-state virtual address is a2 and the first physical address is A3, the second linear relationship includes formula (4), where m is a constant:
A3=A2-m (4)。
in a possible implementation manner of the second aspect, when the second user-mode process shares the shared memory, the controller further includes: a configuration unit, configured to configure one or more of the following information for the second user mode process: the designated virtual address space, the physical address interval of the shared space, the first linear relationship and the second linear relationship.
In a possible implementation manner of the second aspect, when the third kernel-state process shares the shared memory, the first controller further includes: a configuration unit, configured to configure one or more of the following information for the third kernel-state process: a physical address range of the shared space, a second linear relationship.
In one possible implementation manner of the second aspect, the first controller further includes: and the sending unit is used for sending a data access request to the second controller, wherein the data access request is used for accessing data in the memory in the second controller, and the kernel-state virtual address of the memory in the second controller and the physical address of the memory meet a second linear relationship.
In a third aspect, a controller is provided, where the controller includes a processor, a storage, a bus, and a communication interface, the storage stores codes and data, the processor is connected to the storage through the bus, and the processor runs the codes in the storage, so that the controller executes the address mapping method for the shared memory provided in the first aspect or any possible implementation manner of the first aspect.
In yet another aspect of the present application, a readable storage medium is provided, where instructions are stored in the readable storage medium, and when the readable storage medium is executed on a device, the readable storage medium causes the device to perform the method for mapping addresses of a shared memory provided in the first aspect or any possible implementation manner of the first aspect.
In a further aspect of the present application, a computer program product is provided, which when run on a computer, causes the computer to execute the method for mapping addresses of a shared memory provided in the first aspect or any one of the possible implementations of the first aspect.
It can be understood that the apparatus, the computer storage medium, or the computer program product of any of the above-mentioned methods for mapping addresses of shared memories is used to execute the corresponding method provided above, and therefore, the beneficial effects achieved by the method can refer to the beneficial effects in the corresponding method provided above, and are not described herein again.
Drawings
Fig. 1 is a schematic diagram of a shared memory according to an embodiment of the present invention;
fig. 2 is a flowchart of address mapping of a shared memory provided in the prior art;
fig. 3 is a schematic flowchart of an address mapping method for a shared memory according to an embodiment of the present invention;
fig. 4 is a schematic diagram illustrating a distribution of a system memory according to an embodiment of the present invention;
fig. 5 is a flowchart of address mapping of a shared memory according to an embodiment of the present invention;
fig. 6 is a flowchart illustrating another method for mapping addresses of a shared memory according to an embodiment of the present invention;
fig. 7 is a flowchart illustrating a further method for mapping addresses of a shared memory according to an embodiment of the present invention;
FIG. 8 is a diagram illustrating data access between controllers according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of a controller according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of another controller according to an embodiment of the present invention.
Detailed Description
At present, the deployment of the memory in the controller is gradually switched from the kernel mode to the user mode, most of the services are already deployed in the user mode, and a small part of the services (such as a driver and the like) are still deployed in the kernel mode. The memory deployed in the user mode needs to be accessed by using the user mode virtual address, and the memory deployed in the kernel mode needs to be accessed by using the kernel mode virtual address. The user mode and the kernel mode are two operation levels of the operating system, and the Intel CPU provides three operation modes of Ring0-Ring 3. Ring0 grade was highest and Ring3 lowest.
User mode: when a process executes user code, the process is said to be in a user running state, which may also be referred to as a user state for short, and at this time, the processor runs in the user code with the lowest privilege level (level 3). Kernel mode: when a task (process) executes a system call and falls into kernel code for execution, the process is said to be in a kernel running state or simply kernel state, and at this time, the processor is in the kernel code of 0 level with the highest privilege level for execution. When a process is in kernel mode, the kernel stack of the current process is used by the executing kernel code. A process may refer to a process of running a program on a data set, which is an independent unit of resource allocation and scheduling by the system.
In order to reduce data copy between user mode processes and between the user mode processes and kernel mode processes, sharing of data in the same memory by different processes can be achieved in a memory sharing mode. Shared memory refers to a logical memory that allows multiple processes to share or access, and shared memory is the fastest method for sharing data among processes. For example, as shown in fig. 1, a process a, a process B, and a process C in a controller share the same shared memory, where the process a and the process B are processes in a user state, and the process C is a process in a kernel state. Process a, process B, and process C may be unrelated processes.
In the prior art, a Linux operating system provides a mapping mechanism mmap for sharing a memory between a user mode and a kernel mode. And the mmap () system calls to realize memory sharing among the processes by mapping the same common file. After the ordinary file is mapped to the process address space, the process can access the file just like accessing the ordinary memory without calling read (), write (), and other operations. The specific mapping process is shown in fig. 2, and step 1: calling the user-state map function, and then by the system calling the mmap function, the system automatically assigns a free user-state virtual address (assumed to be a 1). Step 2: distributing a section of memory in a kernel mode through vmalloc to obtain a virtual address of the section of memory (namely, the kernel mode virtual address, which is assumed to be A2); and step 3: the virtual address a2 of the segment memory is converted into a page frame by the system function vmalloc _ to _ page, and the page frame is converted into a physical address of the corresponding page by the page _ to _ phys (assumed to be A3). And 4, step 4: the mapping relationship between the physical address A3 and the user-state virtual address A1 is established by vm _ insert _ page.
However, in the above method, the user-state virtual addresses automatically allocated by the system are relatively random, which results in irregular and traceable conversion efficiency between the user-state virtual addresses and the virtual addresses of the memory, and further results in low conversion efficiency between the user-state virtual addresses and the kernel-state virtual addresses. Meanwhile, the conversion between the virtual address and the physical address of the memory requires two calls of the kernel functions vmalloc _ to _ page and page _ to _ phys of the system, so the conversion efficiency between the virtual address and the physical address of the memory is also low. In addition, the above conversion method only supports the conversion between the addresses of the user mode and the kernel mode in the same controller, that is, the two kernel functions can only convert the memory address within the range of the controller, but not support the memory addresses between different controllers.
Based on this, embodiments of the present application provide a method and an apparatus for supporting linear translation between addresses in a shared memory, so that translation efficiency between the addresses in the shared memory can be improved, and performance of a storage system is improved.
Fig. 3 is a flowchart illustrating an address mapping method for a shared memory according to an embodiment of the present disclosure, and referring to fig. 3, the method includes the following steps.
Step 301: when the first controller receives a shared memory mapping request triggered by the first user mode process, the first controller acquires a first user mode virtual address from the specified virtual address interval.
The first controller may have a plurality of programs installed therein, and the first controller may run one or more of the plurality of programs. The first controller may provide different services to the user by running different programs. When the first controller runs a program, the program can create a corresponding process, and meanwhile, a certain memory is allocated to the process. In the embodiment of the present application, when a process executes a user code, the process may be referred to as a user mode process. A process may be referred to as a kernel-mode process when it traps execution of a system call in kernel code.
In addition, the first user-mode process may refer to any one of a plurality of processes in a user mode in the first controller. The first user mode process may share the same shared memory with other processes in the user mode and processes in the kernel mode, that is, the shared memory is a memory shared by the user mode process and the kernel mode process, and both the first user mode process and other processes sharing the shared memory may access the shared memory.
The first user mode virtual address refers to a virtual address used by the first user mode process to access the shared memory. The designated virtual address interval refers to a continuous range of virtual addresses, which may also be referred to as a virtual address space range. The designated virtual address interval may be set or planned in advance, and the first user-mode virtual address may be a virtual address in the designated virtual address interval.
Specifically, when a first user mode process in the first controller shares the same memory with other processes, the first controller triggers a shared memory mapping request when creating the first user mode process, where the shared memory mapping request is used to map the shared memory in an address space of the first user mode process. When the first controller receives a shared memory mapping request triggered by the first user mode process, the first controller may obtain the first user mode virtual address in an idle state from the designated virtual address interval.
Step 302: the first controller determines a first kernel-state virtual address corresponding to the first user-state virtual address according to the designated virtual address interval, the first user-state virtual address and a first linear relation, wherein the first linear relation is used for indicating the relation between the user-state virtual address and the kernel-state virtual address.
The designated virtual address interval may be represented as [ USR _ START, USR _ END ], USR _ START may refer to a START address of the user-state virtual address of the shared memory, and USR _ END may refer to an END address of the user-state virtual address of the shared memory. The designated virtual address interval is set in relation to a physical address interval of the shared memory.
In addition, the first kernel-mode virtual address refers to a virtual address, corresponding to the first user-mode virtual address in the kernel mode, for accessing the shared memory when the first user-mode process traverses the kernel mode to access the shared memory. The first linear relationship is used for indicating the relationship between the user-state virtual address and the kernel-state virtual address, that is, the relationship for mutual conversion between the user-state virtual address and the kernel-state virtual address, and is a linear conversion relationship. The conversion between the user-state virtual address and the kernel-state virtual address is performed through the first linear relation, so that the conversion process can be simplified, and the conversion efficiency can be improved.
Specifically, when the start address of the specified virtual address interval is represented as a0, the first user-state virtual address obtained from the specified virtual address interval is represented as a1, and the first kernel-state virtual address is represented as a2, the first linear relationship may be represented by the following formula (1), where m is a constant.
A2=A1-A0+m (1)
Optionally, the start address of the specified virtual address interval may also be represented according to the interval length of the specified virtual address interval and the end address of the virtual address interval. Assuming that the interval length is L and the end address is An, a0 can be expressed as An-L, and the corresponding equation (1) can be expressed as the following equation (1-1).
A2=A1-A0+m=An-L+m (1-1)
For example, in the kernel state, a1 is obtained by redefining the operation function (pseudo code is shown below) of the shared memory mapped file and allocating an unused virtual address from the specified virtual address interval [ USR _ START, USR _ END ] through the get _ shm _ umapped _ area () function. Then, the first kernel-state virtual address a2 is obtained by formula (1).
Figure BDA0001424625630000051
Further, after the first controller determines the first kernel-state virtual address a2, the first controller may allocate a specified size of memory (i.e., shared memory) from the memory space, and may use the first kernel-state virtual address a2 as a virtual start address for accessing the shared memory.
The memory space in the first controller may be as shown in fig. 4. When the system of the first controller is started, in the kernel mode, except for a part of the memory reserved for the operating system (i.e., the operating system memory), the remaining part of the memory may be managed by the memory management module, including the mapping relationship of the remaining part of the memory, and the remaining part of the memory is used for all memory allocation requests in the whole system operation process. The mapping relationship of the remaining memory may be a linear mapping.
It should be noted that the memory management module may be located in a kernel mode, and may be implemented by software. The memory management module may establish a mapping relationship between the kernel-mode virtual address and a physical address of the memory, where the mapping relationship may be implemented by performing fixed addition and subtraction offset on the physical address.
Step 303: and determining a first physical address of the shared memory according to the first kernel-state virtual address and a second linear relation, wherein the second linear relation is used for indicating the relation between the kernel-state virtual address and the physical address.
The first physical address refers to a physical address of the shared memory corresponding to the first kernel-state virtual address. The second linear relationship is used for indicating the relationship between the kernel-state virtual address and the physical address, namely the relationship for mutual conversion between the kernel-state virtual address and the physical address, and is a linear conversion relationship. The conversion between the kernel-state virtual address and the user-state virtual address is carried out through the second linear relation, so that the conversion process can be simplified, and the conversion efficiency can be improved.
Specifically, when the first kernel-state virtual address is a2 and the first physical address is A3, the second linear relationship may be shown in the following formula (2), where m is a constant and has the same value as m in the formula (1).
A3=A2-m (2)
It should be noted that the second linear relationship shown in the formula (2) may be a mapping relationship allocated between a kernel-mode virtual address and a physical address allocated to the shared memory when the memory management module allocates the shared memory to the first user-mode process. That is, the memory management module obtains the corresponding kernel-state virtual address by performing fixed addition and subtraction offset (for example, m) on the physical address. Therefore, when the first controller obtains the first kernel-state virtual address a2, the first physical address A3 corresponding to the first kernel-state virtual address a2 can be determined according to the first kernel-state virtual address a2 and the second linear relationship shown in formula (2).
For example, as shown in fig. 5, the address mapping process of the shared memory may specifically be: calling a user mode map function in a user mode, and calling through a mmap system to obtain a user mode virtual address A1 from a specified virtual address interval; obtaining a kernel-state virtual address A2 corresponding to A1 through first linear relation conversion; allocating a section of memory from the linear line mapping memory area, wherein the initial address is A2; translating the kernel-state virtual address A2 to a physical address A3 by a public-second linear relationship; a mapping between the physical address A3 and the user-state virtual address A1 is established.
In practical applications, a user runs a program, a process created by the program is started to run in a user mode, and if operations such as file operation or network data transmission are to be performed, system calls such as write or send must be passed, and the system calls complete the operations by using codes in a kernel. At this time, the process must be switched to the kernel mode, and then enter the kernel address space in the shared address interval to execute the code completion operations, and then switch back to the user mode after completion. Therefore, when a process applies for a shared space in a user mode and writes data, if the process passes through a kernel mode, a kernel-mode virtual address can be rapidly acquired according to the first linear relation, and the written data can be accessed through the kernel-mode virtual address. Similarly, when a process applies for a shared space in a kernel mode and writes data, if the process passes through a user mode, a user mode virtual address can be quickly obtained according to the first linear relation, and the written data is accessed through the user mode virtual address, so that data copying between the user mode and the kernel mode is avoided, and the data access efficiency is improved.
In the embodiment of the application, the first controller can realize linear conversion between the user-state virtual address and the kernel-state virtual address by specifying the user-state virtual address interval and the first linear relationship, and realize linear conversion between the kernel-state virtual address and the physical address of the shared memory by the second linear relationship, so that the conversion efficiency between the addresses can be improved, and the access efficiency of data in the shared memory can be improved.
Further, when the second user mode process of the first controller shares the shared memory established by the first user mode process with the first user mode process, as shown in fig. 6, the method may further include: step 304.
Step 304: the first controller configures one or more of the following information for the second user mode process: the designated virtual address space, the physical address interval of the shared space, the first linear relationship and the second linear relationship.
When a second user mode process in the first controller shares the shared memory established by the first user mode process, the first controller may configure one or more of the designated virtual address space, the physical address interval of the shared space, the first linear relationship, and the second linear relationship to the second user mode process. When configuring part of the information in the plurality of information, the rest of the information that is not configured may be agreed or set in advance, which is not specifically limited in this embodiment of the application.
Therefore, when the second user mode process implements the shared memory mapping, the shared memory mapping can be implemented by a method similar to that of the first user mode process according to the designated virtual address space, the physical address interval of the shared space, the first linear relationship, and the second linear relationship, that is, the shared memory is mapped in the address space of the second user mode process according to the above steps 301 to 303, so that both the first user mode process and the second user mode process can access the memory sharing.
In the embodiment of the application, the first user mode process and the second user mode process can share the same shared memory, so that the first user mode process can access the second user mode process to write data in the shared memory, and meanwhile, the second user mode process can also access the first user mode process to write data in the shared memory, thereby avoiding copying of data between the user mode processes and improving the data access efficiency.
Further, when the third kernel-state process of the first controller shares the shared memory established by the first user-state process with the first user-state process, as shown in fig. 7, the method may further include: step 305.
Step 305: the first controller configures one or more of the following information for the third kernel-state process: physical address intervals, a second linear relationship of the shared space.
When the third kernel-state process in the first controller shares the shared memory established by the first user-state process, the first controller may configure one or more of the specified virtual address space and the second linear relationship to the third kernel-state process. When only one of the two pieces of information is configured, the information that is not configured may be agreed or set in advance, which is not specifically limited in the embodiment of the present application.
Therefore, when the third kernel-state process performs the shared memory mapping, the mapping between the kernel-state virtual address and the physical address can be implemented according to the physical address interval of the shared space and the second linear relationship, that is, the shared memory is mapped in the address space of the third kernel-state process according to the step 303, so that both the first user-state process and the third kernel-state process can access the memory sharing.
Further, if the shared memory is established by the third kernel-state process, the first controller may configure the second linear relationship and the physical address interval of the shared memory for the first user-state process, so that the first user-state process may map the shared memory into the address space of the first user-state process according to the specified virtual address interval, the physical address interval, the first linear relationship, and the second linear relationship.
In the embodiment of the application, the first user mode process and the third kernel mode process can share the same shared memory, so that the first user mode process can access the third kernel mode process to write data in the shared memory, and meanwhile, the third kernel mode process can also access the first user mode process to write data in the shared memory, thereby avoiding the copying of data between the user mode process and the kernel mode process, and improving the data access efficiency.
Further, the method further comprises: the first controller sends a data access request to the second controller, the data access request is used for accessing data of the memory in the second controller, and a kernel-state virtual address of the memory in the second controller and a physical address of the memory meet a second linear relation.
The second controller may perform linear translation between the kernel-state virtual address and the physical address of the memory through the second linear relationship, as with the first controller, so as to ensure that the first controller and the second controller have the same address translation relationship. Therefore, the first controller can directly send a data access request to the second controller, and when the second controller receives the data access request, the second controller can directly access the memory in the second controller according to the kernel-state virtual address in the data access request, so that a process of direct data access between the first controller and the second controller is realized.
Illustratively, as shown in fig. 8, the first controller is denoted as a-control, the second controller is denoted as B-control, and it is assumed that the user mode of the a-control includes a process a and a process B, and the user mode of the B-control includes a process C and a process D. The kernel states of the control A and the control B respectively comprise a driver and a chip for data processing, the driver can create a corresponding process in the kernel states during the operation, and the process created by the driver during the operation can also be called as a thread because the kernel states are large processes. The translation relationship between the kernel-state virtual addresses and the physical addresses in both the A-control and the B-control satisfy a second linear relationship, so that the driver in the A-control can perform data forwarding and remote direct data access RDMA with the driver in the B-control.
In the embodiment of the application, the first controller and the second controller can both realize linear conversion between kernel-state virtual addresses and physical addresses through the second linear relationship, and the first controller and the second controller are ensured to have the same address conversion relationship, so that data can be directly forwarded and accessed between the first controller and the second controller, data access between cross-controllers is realized, and the performance of the storage system can be improved.
The above description mainly introduces the solutions provided in the embodiments of the present application from the perspective of each network element. It is to be understood that each network element, for example, the first controller, the second controller, etc., for implementing the above functions, includes corresponding hardware structures and/or software modules for performing the respective functions. Those of skill in the art would readily appreciate that the present application is capable of being implemented as hardware or a combination of hardware and computer software for performing the exemplary network elements and algorithm steps described in connection with the embodiments disclosed herein. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiment of the present application, the first controller may be divided into the functional modules according to the above method example, for example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. It should be noted that, in the embodiment of the present application, the division of the module is schematic, and is only one logic function division, and there may be another division manner in actual implementation.
In the case of dividing each functional module by corresponding functions, fig. 9 shows a possible structural diagram of the first controller according to the above embodiment, where the first controller includes: an acquisition unit 901 and a determination unit 902. Wherein the obtaining unit 901 is configured to support the first controller to execute step 301 in fig. 3, fig. 6, or fig. 7; the determining unit 902 is configured to support the first controller to perform step 302 and step 303 in fig. 3, fig. 6, or fig. 7. Further, the first controller may further include: a configuration unit 903 and a transmission unit 904; wherein the configuration unit 903 is configured to support the first controller to execute step 304 in fig. 6, or step 304 and step 305 in fig. 7; the sending unit 904 is used for the step of the first controller sending a data access request to the second controller.
In a hardware implementation, the determining unit 902 and the configuring unit 903 may be processors; the obtaining unit 901 may be a receiver, the sending unit 904 may be a sender, and the receiver and the sender may constitute a communication interface.
Fig. 10 is a schematic diagram of a possible logical structure of the first controller according to the above embodiments, which is provided for an embodiment of the present application. The first controller includes: a processor 1002, a communication interface 1003, a memory 1001, and a bus 1004. The processor 1002, the communication interface 1003, and the memory 1001 are connected to each other by a bus 1004. In an embodiment of the application, the processor 1002 is configured to control and manage the actions of the first controller, for example, the processor 1002 is configured to support the first controller to perform steps 302-303 of fig. 3, steps 302-304 of fig. 6, steps 302-305 of fig. 7, and/or other processes for the techniques described herein. The communication interface 1003 is used to support the first controller for communication. A memory 1001 for storing program codes and data of the first controller.
The processor 1002 may be, among other things, a central processing unit, a general purpose processor, a digital signal processor, an application specific integrated circuit, a field programmable gate array or other programmable logic device, transistor logic, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor may also be a combination of computing functions, e.g., comprising one or more microprocessors, a digital signal processor and a microprocessor, or the like. The bus 1004 may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown in FIG. 10, but this is not intended to represent only one bus or type of bus.
In another embodiment of the present application, a readable storage medium is further provided, where the readable storage medium stores computer-executable instructions, and when a device (which may be a single chip, a chip, or the like) or a processor executes the method for mapping addresses of the shared memory provided in fig. 3, fig. 6, or fig. 7. The aforementioned readable storage medium may include: u disk, removable hard disk, read only memory, random access memory, magnetic or optical disk, etc. for storing program codes.
In another embodiment of the present application, there is also provided a computer program product comprising computer executable instructions stored in a computer readable storage medium; the computer executable instructions may be read by at least one processor of the device from a computer readable storage medium, and execution of the computer executable instructions by the at least one processor causes the device to perform the method of shared memory address mapping provided in fig. 3, 6 or 7.
In the embodiment of the application, the first controller can realize linear conversion between the user-state virtual address and the kernel-state virtual address by specifying the user-state virtual address interval and the first linear relationship, and realize linear conversion between the kernel-state virtual address and the physical address of the shared memory by the second linear relationship, so that the conversion efficiency between the addresses can be improved, and the access efficiency of data in the shared memory can be improved.
Finally, it should be noted that: the above description is only an embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (14)

1. A method for mapping addresses of a shared memory, the method comprising:
when a first controller receives a shared memory mapping request triggered by a first user mode process, the first controller acquires a first user mode virtual address from a specified virtual address interval;
the first controller determines a first kernel-state virtual address corresponding to the first user-state virtual address according to the designated virtual address interval, the first user-state virtual address and a first linear relationship, wherein the first linear relationship is used for indicating the relationship between the user-state virtual address and the kernel-state virtual address;
and determining a first physical address of a shared memory according to the first kernel-state virtual address and a second linear relationship, wherein the shared memory is a memory shared by a user-state process and a kernel-state process, and the second linear relationship is used for indicating the relationship between the kernel-state virtual address and the physical address.
2. The method of claim 1, wherein when the starting address of the designated virtual address interval is A0, the first user-state virtual address is A1, and the first kernel-state virtual address is A2, the first linear relationship comprises equation (1), where m is a constant:
A2=A1-A0+m (1)。
3. the method of claim 1 or 2, wherein when the first kernel-state virtual address is A2 and the first physical address is A3, the second linear relationship comprises equation (2), where m is a constant:
A3=A2-m (2)。
4. the method of claim 3, wherein when a second user-mode process shares the shared memory, the method further comprises:
the first controller configures one or more of the following information for the second user-mode process: the designated virtual address space, a physical address interval of a shared space, the first linear relationship, and the second linear relationship.
5. The method of claim 4, wherein when a third kernel-state process shares the shared memory, the method further comprises:
the first controller configures one or more of the following information for the third kernel-state process: a physical address interval of the shared space, the second linear relationship.
6. The method of claim 5, further comprising:
the first controller sends a data access request to a second controller, the data access request is used for accessing data of a memory in the second controller, and a kernel-state virtual address of the memory in the second controller and a physical address of the memory meet the second linear relation.
7. A controller characterized in that the controller, as a first controller, comprises:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a first user state virtual address from a specified virtual address interval when receiving a shared memory mapping request triggered by a first user state process;
a determining unit, configured to determine, by a first controller, a first kernel-state virtual address corresponding to the first user-state virtual address according to the specified virtual address interval, the first user-state virtual address, and a first linear relationship, where the first linear relationship is used to indicate a relationship between the user-state virtual address and the kernel-state virtual address;
the determining unit is further configured to determine a first physical address of a shared memory according to the first kernel-state virtual address and a second linear relationship, where the shared memory is a memory shared by the user-state process and the kernel-state process, and the second linear relationship is used to indicate a relationship between the kernel-state virtual address and the physical address.
8. The controller of claim 7, wherein when the starting address of the designated virtual address interval is A0, the first user-state virtual address is A1, and the first kernel-state virtual address is A2, the first linear relationship comprises equation (3), wherein m is a constant:
A2=A1-A0+m (3)。
9. the controller of claim 7 or 8, wherein when the first kernel-state virtual address is A2 and the first physical address is A3, the second linear relationship comprises equation (4), where m is a constant:
A3=A2-m (4)。
10. the controller according to claim 9, wherein when a second user-mode process shares the shared memory, the controller further comprises:
a configuration unit, configured to configure one or more of the following information for the second user mode process: the designated virtual address space, a physical address interval of a shared space, the first linear relationship, and the second linear relationship.
11. The controller according to claim 10, wherein when a third kernel-state process shares the shared memory, the controller further comprises:
a configuration unit, configured to configure one or more of the following information for the third kernel-state process: a physical address interval of the shared space, the second linear relationship.
12. The controller of claim 11, further comprising:
a sending unit, configured to send a data access request to a second controller, where the data access request is used to access data in a memory in the second controller, and a kernel-state virtual address of the memory in the second controller and a physical address of the memory satisfy the second linear relationship.
13. A controller, characterized in that the controller comprises a processor, a memory, a bus and a communication interface, the memory stores code and data, the processor is connected with the memory through the bus, the processor runs the code in the memory, so that the controller executes the address mapping method of the shared memory according to any one of claims 1-6.
14. A readable storage medium having stored therein instructions that, when run on a device, cause the device to perform the method of shared memory address mapping of any of claims 1-6.
CN201710909286.9A 2017-09-29 2017-09-29 Address mapping method and device for shared memory Active CN107729159B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710909286.9A CN107729159B (en) 2017-09-29 2017-09-29 Address mapping method and device for shared memory

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710909286.9A CN107729159B (en) 2017-09-29 2017-09-29 Address mapping method and device for shared memory

Publications (2)

Publication Number Publication Date
CN107729159A CN107729159A (en) 2018-02-23
CN107729159B true CN107729159B (en) 2021-01-15

Family

ID=61209174

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710909286.9A Active CN107729159B (en) 2017-09-29 2017-09-29 Address mapping method and device for shared memory

Country Status (1)

Country Link
CN (1) CN107729159B (en)

Families Citing this family (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019161557A1 (en) * 2018-02-24 2019-08-29 华为技术有限公司 Communication method and apparatus
CN110231988B (en) * 2018-03-05 2021-08-03 龙芯中科技术股份有限公司 Video memory access method and device and storage medium
CN109408226A (en) * 2018-09-19 2019-03-01 深圳传音通讯有限公司 Data processing method, device and terminal device
CN109445685B (en) * 2018-09-26 2020-06-30 华中科技大学 User mode file system processing method
CN109857677B (en) * 2018-12-28 2023-03-31 晶晨半导体(上海)股份有限公司 Distribution method and device of kernel stack
CN111444113B (en) * 2019-01-16 2023-06-13 阿里巴巴集团控股有限公司 Nonvolatile storage medium sharing method and device, electronic equipment and storage equipment
EP3900308A4 (en) 2019-01-30 2022-02-23 Huawei Technologies Co., Ltd. Input/output processing in a distributed storage node with rdma
CN110456994B (en) * 2019-07-19 2023-03-10 南京芯驰半导体科技有限公司 Remote display system and method
CN111143072B (en) * 2019-12-29 2023-09-08 浪潮(北京)电子信息产业有限公司 User mode program memory allocation method, system and related components
CN114090273A (en) * 2020-07-30 2022-02-25 华为技术有限公司 Method and device for interprocess communication and computer storage medium
CN112513817B (en) * 2020-08-14 2021-10-01 华为技术有限公司 Data interaction method of main CPU and NPU and computing equipment
CN112532585A (en) * 2020-11-02 2021-03-19 杭州迪普科技股份有限公司 Method, device and medium for inter-process message transmission
CN112395220B (en) * 2020-11-18 2023-02-28 海光信息技术股份有限公司 Processing method, device and system of shared storage controller and storage controller
CN112612623B (en) * 2020-12-25 2022-08-09 苏州浪潮智能科技有限公司 Method and equipment for managing shared memory
CN112650603B (en) * 2020-12-28 2024-02-06 北京天融信网络安全技术有限公司 Memory management method, device, electronic equipment and storage medium
CN112804223B (en) * 2021-01-06 2024-04-16 腾讯科技(深圳)有限公司 Message processing method and device
CN112769716B (en) * 2021-01-12 2022-03-18 烽火通信科技股份有限公司 Data forwarding method and device of virtual switch based on hybrid virtual network bridge
CN114879962A (en) * 2021-02-05 2022-08-09 华为技术有限公司 Method and device for realizing batch system call
CN114003520B (en) * 2021-09-28 2023-06-20 苏州浪潮智能科技有限公司 Data transmission method, device, system and medium between host and equipment
CN114048502B (en) * 2021-10-15 2023-08-15 中国科学院信息工程研究所 Lightweight trusted channel and communication control method thereof
CN116418848A (en) * 2021-12-31 2023-07-11 华为技术有限公司 Method and device for processing configuration and access requests of network nodes
CN114610660A (en) * 2022-03-01 2022-06-10 Oppo广东移动通信有限公司 Method, device and system for controlling interface data

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5960190A (en) * 1997-02-12 1999-09-28 Zilog, Inc. In-circuit emulation system with minimal impact on target environment
US9081501B2 (en) * 2010-01-08 2015-07-14 International Business Machines Corporation Multi-petascale highly efficient parallel supercomputer
CN103257936B (en) * 2012-02-17 2016-03-02 联想(北京)有限公司 EMS memory mappings method and memory-mapped module
CN103034544B (en) * 2012-12-04 2015-08-05 杭州迪普科技有限公司 The management method of a kind of User space and kernel state shared drive and device
CN104572313B (en) * 2013-10-22 2018-03-13 华为技术有限公司 Communication means and device between a kind of process
CN105677597A (en) * 2014-11-20 2016-06-15 中兴通讯股份有限公司 Data writing method and device
CN104809183B (en) * 2015-04-17 2018-06-22 北京奇艺世纪科技有限公司 A kind of digital independent and the method and apparatus of write-in

Also Published As

Publication number Publication date
CN107729159A (en) 2018-02-23

Similar Documents

Publication Publication Date Title
CN107729159B (en) Address mapping method and device for shared memory
US11194626B2 (en) Dynamic resource allocation based on data transferring to a tiered storage
CN112099941B (en) Method, equipment and system for realizing hardware acceleration processing
KR101952795B1 (en) Resource processing method, operating system, and device
EP1805629B1 (en) System and method for virtualization of processor resources
US10191759B2 (en) Apparatus and method for scheduling graphics processing unit workloads from virtual machines
US9135079B2 (en) Dynamically assigning a portion of physical computing resource to logical partitions based on characteristics of executing logical partitions
US10013264B2 (en) Affinity of virtual processor dispatching
US10579416B2 (en) Thread interrupt offload re-prioritization
US10310759B2 (en) Use efficiency of platform memory resources through firmware managed I/O translation table paging
KR20050076702A (en) Method for transferring data in a multiprocessor system, multiprocessor system and processor carrying out this method
US10534739B2 (en) Indicating a privilege level
US20140164659A1 (en) Regulating access to slave devices
US9088569B2 (en) Managing access to a shared resource using client access credentials
US11853798B2 (en) Disaggregated memory pool assignment
US10891056B2 (en) Virtualization of memory compute functionality
CN108228496B (en) Direct memory access memory management method and device and master control equipment
CN114281516A (en) Resource allocation method and device based on NUMA attribute
JP2003248620A (en) Dynamic memory managing method and dynamic memory management information processing device
KR20220135134A (en) Task scheduling method, computing device and application processor using the same
KR20230086548A (en) System-on-chip for managing control authorization to share physical resources by heterogeneous multi cpu and method thereof
CN116069451A (en) Virtualization method, device, equipment, medium, accelerator and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20220908

Address after: No. 1899 Xiyuan Avenue, high tech Zone (West District), Chengdu, Sichuan 610041

Patentee after: Chengdu Huawei Technologies Co.,Ltd.

Address before: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Patentee before: HUAWEI TECHNOLOGIES Co.,Ltd.

TR01 Transfer of patent right