WO2022237624A1 - Memory allocation method, apparatus and system - Google Patents

Memory allocation method, apparatus and system Download PDF

Info

Publication number
WO2022237624A1
WO2022237624A1 PCT/CN2022/091040 CN2022091040W WO2022237624A1 WO 2022237624 A1 WO2022237624 A1 WO 2022237624A1 CN 2022091040 W CN2022091040 W CN 2022091040W WO 2022237624 A1 WO2022237624 A1 WO 2022237624A1
Authority
WO
WIPO (PCT)
Prior art keywords
physical memory
memory space
user
request
kernel
Prior art date
Application number
PCT/CN2022/091040
Other languages
French (fr)
Chinese (zh)
Inventor
黄强
李�雨
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2022237624A1 publication Critical patent/WO2022237624A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/14Protection against unauthorised use of memory or access to memory
    • G06F12/1458Protection against unauthorised use of memory or access to memory by checking the subject access rights

Definitions

  • the present application relates to the field of computer technology, and more specifically, to a memory allocation method, device and system.
  • the processor When running the operating system, the processor can be divided into two operating modes, kernel mode and user mode, according to the function.
  • kernel mode When the processor is in the kernel mode, it mainly executes some key tasks of the operating system and controls the hardware resources of the computer.
  • the user mode Compared with the kernel mode, the user mode has lower execution authority.
  • the processor When the processor is in the user mode, it mainly executes the application-related processes.
  • the processor By dividing the user mode and the kernel mode, the processor can realize the isolation of system key data and application data and improve security. sex and reliability.
  • Memory management is an important function of the operating system. It is mainly used for the allocation and use of memory resources, such as allocating the memory space required for the process to run.
  • Memory management can be implemented by the processor in kernel mode or in user mode. When memory management is implemented in user mode, it can reduce the complexity of kernel mode, but the problem is that the memory required by the system service process also needs to apply to the user mode memory management process through inter-process communication (IPC). When the required memory is large, frequent IPC will bring a large overhead.
  • IPC inter-process communication
  • memory management is implemented in the kernel state, due to the complex data structures and algorithms used in memory management, it will make the formal verification of the kernel and pass high-level security certification very difficult, and increase the probability of being attacked.
  • the memory management method of the current operating system has yet to be optimized.
  • the present application provides a memory allocation method, device and system to improve the working efficiency of memory allocation.
  • a memory allocation method includes:
  • the first user state process receives the task request of the second user state process, and the task request is used to request memory space allocation; the first user state process allocates the first physical memory for the second user state process from the first physical memory space interval, wherein the first physical memory space is the physical memory space authorized by the kernel to the first user mode process.
  • the kernel can perform the first-level memory space management, that is, authorize part of the physical memory space for the first user-mode process, so that the user-mode process can allocate the authorized physical memory space according to the demand, that is, the second-level memory space management,
  • the kernel is responsible for completing a small amount of work, frequent communication between user-mode processes is reduced, energy consumption and memory allocation time overhead can be reduced, and memory allocation can be improved. s efficiency.
  • the method before the first user-mode process allocates the first physical memory range to the second user-mode process, the method further includes: when the first user-mode process When the size of the free memory space in the second physical memory space authorized by the process does not meet the size of the memory space required by the task request, the process in the first user state applies for physical memory space to the kernel; The process authorizes the third physical memory space, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
  • the first user state process can further apply for physical memory space from the kernel to obtain enough authorized physical memory space, avoiding the Insufficient physical memory space authorized by a user state process causes the second user state process to fail to request memory, which improves the flexibility of physical memory space management.
  • the method further includes: allocating a corresponding first virtual memory interval for the first physical memory interval in the first user mode process; The process sends a memory mapping request to the kernel, and the memory mapping request is used for requesting establishment of a mapping relationship between the first physical memory range and the first virtual memory range.
  • the first user mode process allocates the corresponding first virtual memory interval, and requests the kernel to perform memory mapping to complete the connection between the first physical memory interval and the first virtual memory interval. mapping.
  • the method further includes: the first user mode process authorizes a physical memory space allocation permission for the third user mode process.
  • the first user state process also has the function of authorizing physical memory space allocation permissions for other user processes (such as the third user state process), so that after the third user state process obtains the allocation authority, it can request the kernel for physical memory space , so that the third user state process can allocate the authorized physical memory space according to the demand, which can prevent the third user state process from requesting physical memory through inter-process communication, reduce the overhead caused by inter-process communication, and improve the efficiency of memory allocation .
  • other user processes such as the third user state process
  • the first user mode process may be a user mode main memory management process
  • the third user mode process may be a related process that provides system services.
  • the task request is a file mapping request
  • the first user state process is a file system process or a virtual file system process
  • the method further includes: the first user process In response to the file mapping request, the file requested by the file mapping request is mapped to the first physical memory range; the first user process sends the first physical memory range to the second user process.
  • the first user process after the first user process receives the task request for file mapping, it allocates the first physical memory interval for the file mapping task, maps the requested file to the first physical memory interval, and then notifies the second user mode process , the first physical memory range allocated by the first user mode process to the file mapping task.
  • This enables the first user state process to allocate a physical memory range for the file mapping task and complete the file mapping, avoiding requesting physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
  • the first user mode process may be a user mode virtual file system (VFS) process
  • the second user mode process may be a main service process.
  • the main service process obtains the first physical memory interval allocated by the VFS process for the file mapping task through the file mapping request, and then allocates the corresponding virtual address interval for the first physical memory interval, so as to request the kernel to complete the first physical memory interval and the virtual address interval mapping between.
  • VFS virtual file system
  • the task request is a file read/write request
  • the first user state process is a file system process or a virtual file system process
  • the method further includes: the first The user process executes the read/write operation requested by the file read/write request on the first physical memory range.
  • the first user process after receiving the file read/write task request, the first user process allocates a first physical memory range for the file read/write task, and will perform read and write operations on the first physical memory range.
  • This enables the first user-mode process to allocate physical memory ranges for file read/write tasks and complete file read/write, avoiding requesting physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
  • the method further includes: authorizing the physical memory space allocation authority for the first user-mode process in the second user-mode process.
  • the user state process also has the function of authorizing physical memory space allocation permissions for other user processes (such as the first user state process), which can avoid the need for the user state process to request physical memory through inter-process communication, and reduce the inter-process communication bandwidth. to improve the efficiency of memory allocation.
  • a memory allocation device including: a request unit, configured to send a task request to a first user-mode process in a second user-mode process;
  • the task requests to allocate a first physical memory range, and the first physical memory range belongs to a first physical memory space, and the first physical memory space is a physical memory space authorized by the kernel for the first user mode process.
  • the processing unit before the processing unit allocates the first physical memory range to the task request of the second user-mode process by the first user-mode process, the processing unit further uses It is determined that the size of the free memory space in the authorized physical memory space of the first user mode process does not meet the size of the memory space required by the task request; the request unit is also used to apply to the kernel for physical memory in the first user mode process. memory space; the processing unit is further configured to authorize the first physical memory space for the first user mode process in the kernel.
  • the processing unit is further configured to request allocation of a first virtual memory interval for the task in the first user state process;
  • a user mode process sends a memory mapping request to the kernel, and the memory mapping request is used to request establishment of a mapping relationship between the first physical memory range and the first virtual memory range.
  • the processing unit is further configured to authorize the physical memory space allocation permission for the third user-mode process in the first user-mode process.
  • the task request is a file mapping request
  • the first user state process is a file system process or a virtual file system process
  • the processing unit is further configured to The process responds to the file mapping request, and maps the file requested by the file mapping request to the first physical memory range
  • the device further includes: a transceiver unit, configured to send the second user to the second user in the first user process The process sends the first physical memory range.
  • the task request is a file read and write request
  • the first user mode process is a file system process or a virtual file system process
  • the processing unit is further configured to A user process executes the read and write operations requested by the file read and write request on the first physical memory range.
  • the processing unit is further configured to authorize the physical memory space allocation permission for the first user-mode process in the second user-mode process.
  • a communication device including a processor.
  • the processor may implement the first aspect and the method in any possible implementation manner of the first aspect.
  • the communication device further includes a memory
  • the processor is coupled to the memory, and can be used to execute instructions in the memory, so as to implement the above first aspect and the method in any possible implementation manner of the first aspect.
  • the communication device further includes a communication interface, and the processor is coupled to the communication interface.
  • the communication interface may be a transceiver, a pin, a circuit, a bus, a module or other types of communication interfaces, without limitation.
  • an operating system including computer programs and computer program codes.
  • the computer operating system executes the method in the first aspect and any possible implementation manner of the first aspect .
  • a processor including: an input circuit, an output circuit, and a processing circuit.
  • the processing circuit is configured to receive a signal through the input circuit and transmit a signal through the output circuit, so that the processor executes the method in the first aspect and any possible implementation manner of the first aspect.
  • the above-mentioned processor can be one or more chips
  • the input circuit can be an input pin
  • the output circuit can be an output pin
  • the processing circuit can be a transistor, a gate circuit, a flip-flop and various logic circuits, etc. .
  • the input signal received by the input circuit may be received and input by, for example but not limited to, the receiver
  • the output signal of the output circuit may be, for example but not limited to, output to the transmitter and transmitted by the transmitter
  • the circuit may be the same circuit, which is used as an input circuit and an output circuit respectively at different times.
  • the embodiment of the present application does not limit the specific implementation manners of the processor and various circuits.
  • a computer program product includes: a computer program (also referred to as code, or an instruction), when the computer program is executed, the computer executes the above-mentioned first aspect and the first aspect A method in any of the possible implementations.
  • a computer program also referred to as code, or an instruction
  • a computer-readable medium stores a computer program (also referred to as code, or an instruction) which, when running on a computer, causes the computer to execute the above-mentioned first aspect and the first A method in any one of the possible implementations of the aspect.
  • a computer program also referred to as code, or an instruction
  • FIG. 1 is a schematic diagram of an operating system architecture applicable to the present application
  • FIG. 2 is a schematic flowchart of a memory allocation method provided by an embodiment of the present application.
  • FIG. 3 is a schematic flowchart of Embodiment 1 of the memory allocation method provided by the present application.
  • FIG. 4 is a schematic flowchart of Embodiment 2 of the memory allocation method provided by the present application.
  • FIG. 5 is a schematic flowchart of Embodiment 3 of the memory allocation method provided by the present application.
  • FIG. 6 is a schematic flowchart of Embodiment 4 of the memory allocation method provided by the present application.
  • FIG. 7 is a schematic block diagram of an example of a communication device provided by the present application.
  • Fig. 8 is a schematic structural diagram of an example of a communication device provided by the present application.
  • the functions of the processor running the operating system are divided into the kernel state (in some contexts, it can also be referred to as the kernel for short) and the user state.
  • the kernel state is only responsible for some key business functions, and most of the operating system functions are released. In the user mode, this can ensure the "miniaturization" of the kernel mode.
  • different functional modules are managed separately and run in different processes. A problem with one module will not affect other modules, achieving better security and reliability.
  • Typical microkernel architecture operating systems include SeL4, QNX, MINIX, Fuchsia, etc.
  • the macro-kernel architecture In the macro-kernel architecture, all the functions of the processor running the operating system run in the kernel mode to realize a "grand" kernel, because all modules run in one address space and can directly access each other, the macro-kernel architecture can achieve very high efficiency performance, but there are also safety and reliability issues that a module failure will cause the entire kernel to crash.
  • a typical macro-kernel architecture operating system is Linux.
  • a system service process can be referred to as a system service or a service process for short.
  • a system service process is a process that performs specified system functions, and usually provides users with some system function services locally and through the network.
  • a system service process can include but is not limited to a file system process (file system, FS), client/server process, Web server process, etc.
  • the system service process generally runs in the background, and no program window or dialog box will appear to the user application process. You can find the started system service process in the task manager.
  • FIG. 1 is a schematic diagram of an operating system architecture applicable to this application.
  • the operating system can be divided into a kernel mode and a user mode according to functional rights.
  • the working mode of the processing device can include a kernel mode or a user mode.
  • the user state mode includes at least one user state process, such as the user state mode may include a system manager (system manager, SYSMGR) process, which is responsible for starting and managing system components and system services, and providing user application (user application, UAPP) requests.
  • the user mode can also include a virtual file system process (virtual file system, VFS), which is responsible for managing and storing file information.
  • VFS virtual file system
  • the user state mode may also include other system service processes, and the present application is not limited thereto.
  • the kernel-mode mode includes at least one kernel-mode process, which is responsible for key business functions. It should be understood that FIG. 1 is only a schematic diagram of a system architecture applicable to an operating system of the present application, but the present application is not limited thereto, and the solutions of the present application may also be applied to operating systems of other system architectures.
  • memory management in an embedded real-time operating system (quick unix, QNX) is completely implemented in user mode, and the kernel is responsible for filling the page table during address space mapping.
  • the specific process steps are as follows:
  • Step 1 UAPP sends a file read request to the FS process (hereinafter referred to as FS);
  • Step 2 FS judges whether the file has been read, and returns after reading, otherwise continue;
  • Step 3 FS applies for content as a cache memory (cache) to the memory management process
  • Step 4 FS reads the file and writes it into the cache
  • Step 5 FS copies the content in the cache to the address specified by UAPP;
  • Step 6 Go back to Step 2.
  • FS needs to apply for cache from the memory management process through inter-process communication (IPC).
  • IPC inter-process communication
  • the memory management in the Fuchsia operating system is completely implemented in the kernel mode.
  • the memory allocation operation of the user mode system service process can directly apply to the kernel through system calls.
  • the memory management module in the kernel mode It is relatively large, which makes Fuchsia's kernel larger and more complex than traditional microkernels, and the difficulty and workload of passing various security certifications will be greater.
  • this application proposes that the kernel can perform the first-level memory space management, authorize part of the physical memory space for the first user-mode process, and let the user-mode process perform the second-level memory space management , allocate authorized physical memory space according to task requirements, which can prevent user-mode processes from requesting physical memory space from other user-mode processes through inter-process communication (IPC) after receiving task requests, or requesting physical memory space from the kernel through system calls .
  • IPC inter-process communication
  • FIG. 2 is a schematic flowchart of the memory allocation method provided by the present application.
  • the memory allocation method may be executed by an operating system, or the memory allocation method may be executed when the processing device runs an operating system, and the operating system includes multiple user state process programs and kernel programs (which may be called kernels).
  • kernels which may be called kernels.
  • the following uses the memory allocation method of the operating system as an example for illustration, but the present application is not limited thereto.
  • the kernel authorizes the first physical memory space for the first user mode process.
  • the processing device runs an operating system whose kernel is used to manage the physical memory space of the operating system.
  • the kernel may be used to authorize part of the physical memory space in the physical memory space of the system for the first user state process, for example, the kernel authorizes the first physical memory space for the first user state process.
  • the first user mode process may allocate the authorized first physical memory space.
  • the first user mode process is a system service process.
  • the operation of the kernel or the operation of the user-mode process (such as execution, authorization, sending, receiving, determination, management, etc.) involved in this application can be understood as the process that the processing device runs into the operating system. What to do when the process is run, or when the operating system runs into the process.
  • the first user-mode process applies to the kernel for physical memory space.
  • the kernel allocates the first physical memory space for the first user process in response to the application of the first user state process.
  • the first user mode process can apply for physical memory space from the kernel.
  • the kernel allocates the first physical memory space for the first user process in response to the application of the first user process.
  • the first user mode process allocates the first physical memory range in the first physical memory space to the second user mode process.
  • the first user mode process receives a task request from the second user mode process.
  • the task request may be a file mapping request, a file read and write request, etc. from an application process.
  • the first user state process can determine the memory space size required by the task request, and determine the first physical memory address interval in the first physical memory space authorized by the first user state process, then allocate the first physical memory address interval for the task request A range of memory addresses.
  • the first user mode process judges whether the size of the physical memory space to be allocated in the authorized physical memory space of the first user mode process meets the required size of the task request based on the size of the memory space required by the task request. The size of the memory space. If satisfied, then in the physical memory space to be allocated, allocate a physical memory address interval for the task request; if not satisfied, the first user mode process applies for a physical memory space to the kernel, and the kernel is the authorized part of the first user process In the physical memory space, the first user state process requests to allocate the first physical memory range for the task in the authorized physical memory space.
  • the first user mode process may be the main service process of memory management in the user mode process, or may be called the main memory management process, and the main service process may authorize physical memory space allocation rights for other system service processes.
  • other system service processes may include a file system process.
  • the main service process authorizes the file system process to allocate physical memory space. After the file system process is authorized to allocate physical memory space, it can apply for physical memory space from the kernel. After the process authorizes part of the physical memory space, the file system process can allocate a physical memory range in the part of the physical memory space for task requests of other processes. But the present application is not limited thereto.
  • the kernel obtains the request of the user state process to apply for the physical memory space, based on the size of the physical memory space required by the request, it is determined whether the size of the physical memory space to be allocated in the physical memory space managed by the kernel satisfies the request The size of the required memory space. If it is satisfied, part of the physical memory space is authorized for the user-mode process. If it is not satisfied, the kernel can initiate physical memory space recovery, such as initiating a physical memory space request to a user-mode process with physical memory space allocation permissions, thereby reclaiming part of the physical memory space After that, the physical memory space is authorized for the user mode process.
  • the two-level physical memory space management method can reduce frequent communication between user mode processes when the kernel is responsible for completing a small amount of work, and can reduce system energy consumption and overhead.
  • FIG. 3 is a flow chart of Embodiment 1 of the memory allocation method provided by the present application.
  • FIG. 3 shows a schematic flow chart of memory allocation using the memory allocation method provided by the present application at the startup initialization stage of the operating system.
  • the process of initializing the processing device to start the operating system includes but is not limited to the following steps:
  • boot allocator boot allocator
  • the memory management main service process can be the system manager SYSMGR process
  • the main service process (i.e. an example of the first user mode process) may include a first physical memory management algorithm (physical memory management algorithm, PHYMGR), the kernel may include a global PHYMGR (global PHYMGR), and the main service process manages
  • PHYMGR physical memory management algorithm
  • the kernel may include a global PHYMGR (global PHYMGR)
  • the main service process manages
  • the algorithm applies for a physical memory space to the kernel, and the kernel responds to the application by authorizing part of the physical memory space (that is, an example of the first physical memory space) to the main service process through the global PHYMGR.
  • the main service process may authorize one or more system service processes to manage physical memory space.
  • a virtual file system (VFS) process has a higher allocation requirement for physical memory, and the main service process can authorize the physical memory management authority of the VFS process, but the application is not limited thereto.
  • Process physical memory management permissions for processes with high allocation requirements are not limited thereto.
  • step 9 the system service process (that is, another example of the first user mode process) authorized to manage the physical memory applies to the kernel for physical memory space.
  • the system service process authorized with the physical management authority completes the initialization of the metadata of the authorized physical memory space (that is, another example of the first physical memory space). System services that are granted physical management rights have allocation rights to the authorized physical memory space.
  • the kernel authorizes part of the physical memory space for the main service process, so that the main service process can allocate the authorized physical memory space according to the requirements during the running phase of the operating system.
  • the miniaturization of the kernel can be realized, the workload of the kernel can be reduced, and the security of the system can be improved.
  • FIG. 4 is a schematic flowchart of Embodiment 2 of the memory allocation method provided by the present application.
  • FIG. 4 shows a schematic flow of memory allocation in response to the anonymous memory mapping request of the UAPP after the processing device obtains the anonymous memory mapping request while running the main service process.
  • the VFS process can be, for example, as shown in FIG. 3 , authorized by the main service process to manage the physical memory space in the initialization phase, and authorized by the kernel, and the VFS process has a part of the physical memory space allocated with the authority, but the application is not limited thereto.
  • the process of the processing device responding to UAPP's anonymous memory mapping request includes but is not limited to the following steps:
  • Anonymous memory mapping means that the mapped area is not associated with a file.
  • the virtual memory range may be a virtual memory address range, or called a virtual memory address segment
  • the physical memory range may be a physical memory address range, or called a physical memory address segment.
  • the processing device first needs to determine whether the physical memory space to be allocated in the authorized physical memory space of the main service process can satisfy the size of the memory space required by the memory mapping request. If not satisfied, apply for physical memory space from the kernel in step 4; if satisfied, perform step 8 to allocate a physical memory range for the anonymous memory mapping request in the authorized physical memory space of the main service process;
  • the kernel judges whether the physical memory space to be allocated in the global physical memory space is enough
  • the processing device judges whether the size of the physical memory space to be allocated in the global physical memory space satisfies the size of the physical memory space applied by the main service process. If it is satisfied, the kernel authorizes part of the physical memory space for the main service process, and then returns to step 3; if not, initiates memory recovery in step 6.
  • the kernel initiates a memory reclamation request to reclaim part of the physical memory space
  • the kernel authorizes part of the physical memory space for the main service process, and performs metadata initialization on the authorized part of the physical memory space in the main service process, and returns to step 3;
  • the processing unit completes the rest of the process.
  • FIG. 5 is a schematic flowchart of Embodiment 3 of the memory allocation method provided by the present application.
  • FIG. 5 shows a schematic flow chart of executing a memory allocation process in response to the file mapping request after the processing device acquires a file mapping request from the UAPP while running the main service process.
  • the VFS process can be, for example, as shown in FIG. 3 , authorized by the main service process to manage the physical memory space in the initialization phase, and authorized by the kernel, and the VFS process has a part of the physical memory space with the assigned authority, but the application is not limited thereto.
  • the process of the processing device responding to the file mapping request of UAPP includes but not limited to the following steps:
  • the file mapping request may be that the mmap file mapping function carries a populated flag (with populated flag), but the application is not limited thereto.
  • the main service process requests the page cache (page cache) corresponding to the UAPP from the VFS process, and requests the VFS process to provide the physical memory (interval) of the file page corresponding to the UAPP;
  • step 4 Determine whether the VFS process has a page cache corresponding to the UAPP, if not, then perform step 5; if so, perform step 11, and return the page cache corresponding to the UAPP to the main service process;
  • the processing device first needs to judge whether the physical memory space to be allocated in the authorized physical memory space of the VFS process can satisfy the size of the memory space required by the file mapping request. If not satisfied, apply for physical memory space to the kernel in step 6; if satisfied, perform step 10, in the authorized physical memory space of the VFS process, allocate a physical memory interval as a page cache for the file mapping task.
  • the kernel judges whether the physical memory space to be allocated in the global physical memory space is enough
  • the kernel After the kernel obtains the application of the VFS process, it judges whether the size of the physical memory space to be allocated in the global physical memory space satisfies the size of the physical memory space applied by the VFS process. If not, initiate memory reclamation in step 8; if satisfied, return to step 5 after the kernel authorizes part of the physical memory space for the VFS process in step 9.
  • the kernel initiates a memory reclamation request to reclaim part of the physical memory space
  • the kernel authorizes part of the physical memory space for the VFS process, and performs metadata initialization on the authorized physical memory space in the VFS process, and returns to step 5;
  • a physical memory range is allocated for the file mapping task from authorized physical memory space through a physical memory management algorithm (phymgr) corresponding to the VFS process.
  • phymgr physical memory management algorithm
  • the VFS process returns the page cache corresponding to the UAPP to the VFS process
  • mapping request to the kernel in the main service process, that is, send the virtual memory interval and physical memory interval allocated for the file mapping request to the kernel to initiate a mapping request;
  • the processing unit completes the remaining process.
  • this application allocates and uses physical memory of system services (such as VFS processes, etc.) with clear authority management and operation boundaries, and the physical memory managed by system services is only used to meet its own functions and logic implementation. Needs (such as file mapping tasks, etc.), cannot be used to satisfy the physical memory allocation of the application, and the physical memory allocation of the application is still the responsibility of the main memory management process. This can reduce the frequent interaction between processes, and does not increase the overall memory management complexity. The access control of physical memory is still handled in the main memory management process.
  • system services such as VFS processes, etc.
  • the file reading and writing performance has obvious disadvantages compared with the macro-kernel operating system.
  • the file reading and writing performance can be equal to or surpass the typical macro-kernel operating system Linux.
  • the memory allocation method provided by the present application was compared with the read ability and write ability of the Linux operating system in the prior art. For files of the same size, when the same number of bytes is read each time, no matter in the way of sequential reading or random reading, the memory allocation method provided by this application can improve the processing efficiency by more than 35% compared with the Linux operating system .
  • the memory allocation method provided by this application can improve the processing efficiency by more than 15% compared with the Linux operating system .
  • the processing efficiency of the memory allocation method provided by the present application is significantly improved. For example, when 2 megabytes are written per second, the processing efficiency can be increased by 60%.
  • FIG. 6 is a schematic flowchart of Embodiment 4 of the memory allocation method provided by the present application.
  • FIG. 6 shows a schematic flow chart of executing a memory allocation process in response to the file mapping request after the processing device obtains a file read and write request from UAPP while running a VFS process, wherein the VFS process can be, for example, as shown in FIG.
  • the main service process is authorized to manage the physical memory space, and is authorized by the kernel, and the VFS process has a part of the physical memory space with the allocation authority, but the application is not limited thereto.
  • the process of the processing device responding to the file read and write request of UAPP includes but not limited to the following steps:
  • the file reading and writing request of UAPP is directly sent to the VFS process, and in response to the file reading and writing request in the VFS process, according to the file indicator fd, call the corresponding read (read) function or write (write) function to find the corresponding file location.
  • step 3 determines whether there is a page cache corresponding to the file; if it does not exist, the processing device executes step 3; if it exists, executes step 9, and performs the corresponding read and write operations of the UAPP request on the page cache;
  • the processing device judges whether the size of the physical memory space to be allocated in the authorized physical memory space satisfies the size of the page cache required by the read-write task. If it is not satisfied, execute step 4 to apply to the kernel for authorization of part of the physical memory space of the VFS process; if satisfied, execute step 8 to allocate a physical memory range for the read and write task as the page cache for the read and write task.
  • the kernel judges whether the global physical memory space is sufficient
  • the kernel judges whether the size of the physical memory space to be allocated in the global physical memory space can satisfy the memory space requested by the VFS process. If it is enough, then execute step 7.
  • the kernel authorizes part of the physical memory space for the VFS process; if not, execute step 6.
  • the kernel initiates the memory space space reclamation request;
  • the kernel initiates a memory space reclamation request to reclaim part of the physical memory space that has not been authorized by the VFS process;
  • the kernel authorizes part of the physical memory space for the VFS process, and performs metadata initialization on the authorized physical memory space in the VFS process, and returns to step 3;
  • the processing device When processing the file reading and writing task shown in Figure 6, the processing device receives the file reading and writing request in the VFS process, and if there is no corresponding page cache, it can read and write the file in the physical memory space authorized by the VFS process Allocate the corresponding page cache. With the permission to allocate physical memory space in the VFS process, it can reduce the inter-process communication overhead caused by the VFS process requesting the physical memory range from the memory management process, and improve the processing efficiency.
  • the memory allocation method provided by the present application has been described above with reference to FIG. 2 to FIG. 6 .
  • the communication device provided by the present application will be described below with reference to FIG. 7 .
  • FIG. 7 is a schematic structural diagram of a memory allocation device provided by the present application. As shown in FIG. 7 , the memory allocation device includes a request unit 710 and a processing unit 720 .
  • the request unit is used to send a task request to the first user mode process in the second user mode process, and the task request is used to request memory space allocation;
  • a processing unit configured to allocate a first physical memory range to the task request in the first user state process, the first physical memory range belongs to the first physical memory space, and the first physical memory space is the kernel for the first user The physical memory space authorized by the state process.
  • the processing unit before the processing unit requests allocation of the first physical memory range for the task of the second user-mode process by the first user-mode process, the processing unit is further configured to determine the authorized first user-mode process 2.
  • the size of the free memory space in the physical memory space does not meet the size of the memory space required by the task request;
  • the request unit is also used to apply for physical memory space from the kernel in the first user state process
  • the processing unit is further configured to authorize a third physical memory space for the first user mode process in the kernel, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
  • the processing unit is further configured to allocate a corresponding first virtual memory interval to the first physical memory interval in the first user mode process
  • the request unit is also used to send a memory mapping request to the kernel in the first user mode process, and the memory mapping request is used to request the kernel to establish a mapping relationship between the first physical memory interval and the first virtual memory interval .
  • the processing unit is further configured to authorize the allocation permission of the physical memory space for the third user-mode process in the first user-mode process.
  • the task request is a file mapping request
  • the first user mode process is a file system process or a virtual file system process
  • the processing unit is further configured to respond to the file mapping request in the first user process, and map the file requested by the file mapping request to the first physical memory interval; and, the device further includes:
  • a transceiver unit configured to send the first physical memory range to the second user process in the first user process.
  • the task request is a file read/write request
  • the first user mode process is a file system process or a virtual file system process
  • the processing unit is further configured to perform a process on the first physical memory range in the first user process. Performs the read/write operation requested by the file read/write request.
  • processing unit is further configured to authorize the physical memory space allocation permission for the first user-mode process in the second user-mode process.
  • FIG. 8 is a schematic structural diagram of a communication device 800 provided by an embodiment of the present application.
  • the communication device 800 may be configured with an operating system as shown in FIG. 1 .
  • the communication device 800 includes a bus 840 and a processor 810 connected to the bus 840 , and the communication device 800 may also include a communication interface 820 and a memory 830 .
  • the communication device 800 shown in FIG. 8 can implement each process of the memory allocation method in any method embodiment.
  • the operations and/or functions of the various modules in the communication device 800 are respectively for implementing the corresponding procedures in the foregoing method embodiments.
  • the communication device may be a terminal, and may also be called user equipment (user equipment, UE), and the communication device may be a mobile phone, a tablet computer, or a computer device.
  • user equipment user equipment
  • the embodiment of the present application also provides a computer operating system, including: computer program code, which causes the computer operating system to execute the method in any one of the above method embodiments when the computer program code is invoked.
  • the embodiment of the present application also provides a processing device, including a processor and an interface; the processor is configured to execute the method in any one of the above method embodiments.
  • the present application also provides a computer program product, the computer program product including: computer program code, when the computer program code is executed by one or more processors, the device including the processor executes any one of the above method embodiments Methods.
  • the present application also provides a computer-readable storage medium, the computer-readable storage medium stores program code, and when the program code is run by one or more processors, the device including the processor executes any one of the above methods. method in the example.
  • the various embodiments may refer to each other, for example, the methods and/or terms between the method embodiments may refer to each other, such as the functions and/or terms between the device embodiments Or terms may refer to each other, for example, functions and/or terms between the apparatus embodiment and the method embodiment may refer to each other.

Abstract

Provided in the present application are a memory allocation method, apparatus and system. By means of the method, a kernel can execute first-level memory space management to grant part of a physical memory space to a user state process, such that the user state process can allocate the granted physical memory space according to requirements, thereby realizing second-level memory space management. By using a two-level physical memory space management mode, when a kernel is responsible for completing a small amount of work, frequent communications between user state processes are reduced, and the energy consumption and memory allocation time overheads can be reduced, so as to improve the memory allocation efficiency.

Description

内存分配方法、装置和系统Memory allocation method, device and system
本申请要求于2021年05月14日提交中国国家知识产权局、申请号为202110527267.6、申请名称为“内存分配方法、装置和系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the State Intellectual Property Office of China on May 14, 2021, with application number 202110527267.6 and application title "memory allocation method, device and system", the entire contents of which are incorporated herein by reference Applying.
技术领域technical field
本申请涉及计算机技术领域,并且更具体地,涉及一种内存分配方法、装置和系统。The present application relates to the field of computer technology, and more specifically, to a memory allocation method, device and system.
背景技术Background technique
运行操作系统时处理器可以根据功能分为内核态和用户态两种运行模式,处理器处于内核态模式时主要执行操作系统的一些关键任务、控制计算机的硬件资源。用户态相较于内核态执行权限较低,处理器处于用户态模式时主要执行应用程序相关的进程,处理器通过划分用户态和内核态,能够实现系统关键数据与应用数据的隔离,提高安全性和可靠性。When running the operating system, the processor can be divided into two operating modes, kernel mode and user mode, according to the function. When the processor is in the kernel mode, it mainly executes some key tasks of the operating system and controls the hardware resources of the computer. Compared with the kernel mode, the user mode has lower execution authority. When the processor is in the user mode, it mainly executes the application-related processes. By dividing the user mode and the kernel mode, the processor can realize the isolation of system key data and application data and improve security. sex and reliability.
内存管理是操作系统的一个重要功能,主要用于内存资源的分配、使用,如为进程分配运行所需的内存空间等。内存管理可以由处理器处于内核态时实现或者处于用户态时实现。内存管理在用户态实现时,可以降低内核态的复杂度,但存在的问题是系统服务进程所需的内存也需要通过进程间通信(inter-process communication,IPC)向用户态内存管理进程申请,当所需内存较大时,频繁的IPC将带来较大的开销。内存管理在内核态实现时,由于内存管理使用的数据结构和算法复杂,将使得内核的形式化验证和通过高等级的安全认证变得非常困难,并且增加了被攻击的概率。目前操作系统的内存管理方式还有待优化。Memory management is an important function of the operating system. It is mainly used for the allocation and use of memory resources, such as allocating the memory space required for the process to run. Memory management can be implemented by the processor in kernel mode or in user mode. When memory management is implemented in user mode, it can reduce the complexity of kernel mode, but the problem is that the memory required by the system service process also needs to apply to the user mode memory management process through inter-process communication (IPC). When the required memory is large, frequent IPC will bring a large overhead. When memory management is implemented in the kernel state, due to the complex data structures and algorithms used in memory management, it will make the formal verification of the kernel and pass high-level security certification very difficult, and increase the probability of being attacked. The memory management method of the current operating system has yet to be optimized.
发明内容Contents of the invention
本申请提供了一种内存分配方法、装置和系统,以提高内存分配的工作效率。The present application provides a memory allocation method, device and system to improve the working efficiency of memory allocation.
第一方面,提供了一种内存分配方法,该方法包括:In the first aspect, a memory allocation method is provided, the method includes:
第一用户态进程接收第二用户态进程的任务请求,该任务请求用于请求分配内存空间;该第一用户态进程从第一物理内存空间中为该第二用户态进程分配第一物理内存区间,其中该第一物理内存空间是内核授权给该第一用户态进程的物理内存空间。The first user state process receives the task request of the second user state process, and the task request is used to request memory space allocation; the first user state process allocates the first physical memory for the second user state process from the first physical memory space interval, wherein the first physical memory space is the physical memory space authorized by the kernel to the first user mode process.
根据上述方案,内核可以执行第一级内存空间管理,即为第一用户态进程授权部分物理内存空间,使得用户态进程可以根据需求分配被授权的物理内存空间,即第二级内存空间管理,通过采用两级物理内存空间的管理方式,在内核负责完成少量的工作的情况下,减少了用户态进程之间频繁的通信,能够减小能耗以及减小内存分配的时间开销,提高内存分配的效率。According to the above scheme, the kernel can perform the first-level memory space management, that is, authorize part of the physical memory space for the first user-mode process, so that the user-mode process can allocate the authorized physical memory space according to the demand, that is, the second-level memory space management, By adopting a two-level physical memory space management method, when the kernel is responsible for completing a small amount of work, frequent communication between user-mode processes is reduced, energy consumption and memory allocation time overhead can be reduced, and memory allocation can be improved. s efficiency.
结合第一方面,在第一方面的某些实现方式中,该通过该第一用户态进程为第二用户态进程分配该第一物理内存区间之前,该方法还包括:当该第一用户态进程被授权的第二物理内存空间中空闲内存空间大小不满足该任务请求所需的内存空间大小时,该第一用户态进程中向该内核申请物理内存空间;该内核为该第一用户态进程授权该第三物理内存空间,其中,该第一物理内存空间包括该第二物理内存空间和该第三物理内存空间。With reference to the first aspect, in some implementation manners of the first aspect, before the first user-mode process allocates the first physical memory range to the second user-mode process, the method further includes: when the first user-mode process When the size of the free memory space in the second physical memory space authorized by the process does not meet the size of the memory space required by the task request, the process in the first user state applies for physical memory space to the kernel; The process authorizes the third physical memory space, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
根据上述方案,在第一用户态进程被授权的物理内存空间不满足需求的情况下,第一 用户态进程可以进一步向内核申请物理内存空间,以获取足够的被授权物理内存空间,避免因第一用户态进程被授权的物理内存空间不足造成第二用户态进程请求内存失败的情况,提高了物理内存空间管理的灵活性。According to the above solution, in the case that the authorized physical memory space of the first user state process does not meet the requirements, the first user state process can further apply for physical memory space from the kernel to obtain enough authorized physical memory space, avoiding the Insufficient physical memory space authorized by a user state process causes the second user state process to fail to request memory, which improves the flexibility of physical memory space management.
结合第一方面,在第一方面的某些实现方式中,该方法还包括:该第一用户态进程中为该第一物理内存区间分配相应的第一虚拟内存区间;在该第一用户态进程中向该内核发送内存映射请求,该内存映射请求用于请求建立该第一物理内存区间与该第一虚拟内存区间之间的映射关系。With reference to the first aspect, in some implementations of the first aspect, the method further includes: allocating a corresponding first virtual memory interval for the first physical memory interval in the first user mode process; The process sends a memory mapping request to the kernel, and the memory mapping request is used for requesting establishment of a mapping relationship between the first physical memory range and the first virtual memory range.
根据上述方案,第一用户态进程在分配第一物理内存区间后,再分配相应地第一虚拟内存区间,并请求内核进行内存映射,以完成第一物理内存区间与第一虚拟内存区间之间的映射。According to the above scheme, after allocating the first physical memory interval, the first user mode process allocates the corresponding first virtual memory interval, and requests the kernel to perform memory mapping to complete the connection between the first physical memory interval and the first virtual memory interval. mapping.
结合第一方面,在第一方面的某些实现方式中,该方法还包括:该第一用户态进程为第三用户态进程授权物理内存空间分配权限。With reference to the first aspect, in some implementation manners of the first aspect, the method further includes: the first user mode process authorizes a physical memory space allocation permission for the third user mode process.
根据上述方案,第一用户态进程还具有为其他用户进程(如第三用户态进程)授权物理内存空间分配权限的功能,使得第三用户态进程获取分配权限后,可以向内核请求物理内存空间,从而第三用户态进程可以根据需求按需分配被授权的物理内存空间,能够避免第三用户态进程通过进程间通信请求物理内存,减少了进程间通信带来的开销,提高内存分配的效率。According to the above scheme, the first user state process also has the function of authorizing physical memory space allocation permissions for other user processes (such as the third user state process), so that after the third user state process obtains the allocation authority, it can request the kernel for physical memory space , so that the third user state process can allocate the authorized physical memory space according to the demand, which can prevent the third user state process from requesting physical memory through inter-process communication, reduce the overhead caused by inter-process communication, and improve the efficiency of memory allocation .
示例性地,第一用户态进程可以是用户态主内存管理进程,第三用户态进程可以是提供系统服务的相关进程。Exemplarily, the first user mode process may be a user mode main memory management process, and the third user mode process may be a related process that provides system services.
结合第一方面,在第一方面的某些实现方式中,该任务请求为文件映射请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,该方法还包括:该第一用户进程响应该文件映射请求,将该文件映射请求所请求的文件映射至该第一物理内存区间;该第一用户进程中向该第二用户进程发送该第一物理内存区间。With reference to the first aspect, in some implementations of the first aspect, the task request is a file mapping request, the first user state process is a file system process or a virtual file system process, and the method further includes: the first user process In response to the file mapping request, the file requested by the file mapping request is mapped to the first physical memory range; the first user process sends the first physical memory range to the second user process.
根据上述方案,第一用户进程接收到文件映射的任务请求后,为该文件映射任务分配第一物理内存区间,并将其请求的文件映射至第一物理内存区间,再通知第二用户态进程,该第一用户态进程为该文件映射任务分配的第一物理内存区间。使得第一用户态进程可以为文件映射任务分配物理内存区间并完成文件映射,避免了通过进程间通信请求物理内存,减少了进程间通信带来的开销,提高内存分配的效率。According to the above scheme, after the first user process receives the task request for file mapping, it allocates the first physical memory interval for the file mapping task, maps the requested file to the first physical memory interval, and then notifies the second user mode process , the first physical memory range allocated by the first user mode process to the file mapping task. This enables the first user state process to allocate a physical memory range for the file mapping task and complete the file mapping, avoiding requesting physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
示例性地,第一用户态进程可以是用户态虚拟文件系统(VFS)进程,第二用户态进程可以是主服务进程。其中主服务进程通过文件映射请求获取到VFS进程为文件映射任务分配的第一物理内存区间后为第一物理内存区间分配相应的虚拟地址区间,以请求内核完成第一物理内存区间与虚拟地址区间之间的映射。Exemplarily, the first user mode process may be a user mode virtual file system (VFS) process, and the second user mode process may be a main service process. The main service process obtains the first physical memory interval allocated by the VFS process for the file mapping task through the file mapping request, and then allocates the corresponding virtual address interval for the first physical memory interval, so as to request the kernel to complete the first physical memory interval and the virtual address interval mapping between.
结合第一方面,在第一方面的某些实现方式中,该任务请求为文件读/写请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,该方法还包括:该第一用户进程中对该第一物理内存区间执行该文件读/写请求所请求的读/写操作。With reference to the first aspect, in some implementations of the first aspect, the task request is a file read/write request, the first user state process is a file system process or a virtual file system process, and the method further includes: the first The user process executes the read/write operation requested by the file read/write request on the first physical memory range.
根据上述方案,第一用户进程接收到文件读/写的任务请求后,为该文件读/写任务分配第一物理内存区间,并将对该第一物理内存区间执行读写操作。使得第一用户态进程可以为文件读/写任务分配物理内存区间并完成文件读/写,避免了通过进程间通信请求物理内存,减少了进程间通信带来的开销,提高内存分配的效率。According to the above scheme, after receiving the file read/write task request, the first user process allocates a first physical memory range for the file read/write task, and will perform read and write operations on the first physical memory range. This enables the first user-mode process to allocate physical memory ranges for file read/write tasks and complete file read/write, avoiding requesting physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
结合第一方面,在第一方面的某些实现方式中,该方法还包括:在该第二用户态进程 中为该第一用户态进程授权物理内存空间分配权限。With reference to the first aspect, in some implementations of the first aspect, the method further includes: authorizing the physical memory space allocation authority for the first user-mode process in the second user-mode process.
根据上述方案,用户态进程还具有为其他用户进程(如第一用户态进程)授权物理内存空间分配权限的功能,能够避免用户态进程需要通过进程间通信请求物理内存,减少了进程间通信带来的开销,提高内存分配的效率。According to the above scheme, the user state process also has the function of authorizing physical memory space allocation permissions for other user processes (such as the first user state process), which can avoid the need for the user state process to request physical memory through inter-process communication, and reduce the inter-process communication bandwidth. to improve the efficiency of memory allocation.
第二方面,提供了一种内存分配装置,包括:请求单元,用于在第二用户态进程向第一用户态进程发送任务请求;处理单元,用于在该第一用户态进程中为该任务请求分配第一物理内存区间,该第一物理内存区间属于第一物理内存空间,该第一物理内存空间是内核为该第一用户态进程授权的物理内存空间。In a second aspect, a memory allocation device is provided, including: a request unit, configured to send a task request to a first user-mode process in a second user-mode process; The task requests to allocate a first physical memory range, and the first physical memory range belongs to a first physical memory space, and the first physical memory space is a physical memory space authorized by the kernel for the first user mode process.
结合第二方面,在第二方面的某些实现方式中,在该处理单元在该第一用户态进程为第二用户态进程的任务请求分配该第一物理内存区间之前,该处理单元还用于确定该第一用户态进程被授权的物理内存空间中空闲内存空间大小不满足该任务请求所需的内存空间大小;该请求单元还用于在该第一用户态进程中向该内核申请物理内存空间;该处理单元还用于在该内核为该第一用户态进程授权该第一物理内存空间。With reference to the second aspect, in some implementation manners of the second aspect, before the processing unit allocates the first physical memory range to the task request of the second user-mode process by the first user-mode process, the processing unit further uses It is determined that the size of the free memory space in the authorized physical memory space of the first user mode process does not meet the size of the memory space required by the task request; the request unit is also used to apply to the kernel for physical memory in the first user mode process. memory space; the processing unit is further configured to authorize the first physical memory space for the first user mode process in the kernel.
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于在该第一用户态进程中为该任务请求分配第一虚拟内存区间;该请求单元还用于在该第一用户态进程中向该内核发送内存映射请求,该内存映射请求用于请求建立该第一物理内存区间与该第一虚拟内存区间之间的映射关系。With reference to the second aspect, in some implementation manners of the second aspect, the processing unit is further configured to request allocation of a first virtual memory interval for the task in the first user state process; A user mode process sends a memory mapping request to the kernel, and the memory mapping request is used to request establishment of a mapping relationship between the first physical memory range and the first virtual memory range.
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于在该第一用户态进程中为第三用户态进程授权物理内存空间分配权限。With reference to the second aspect, in some implementation manners of the second aspect, the processing unit is further configured to authorize the physical memory space allocation permission for the third user-mode process in the first user-mode process.
结合第二方面,在第二方面的某些实现方式中该任务请求为文件映射请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,该处理单元还用于在该第一用户进程中响应该文件映射请求,将该文件映射请求所请求的文件映射至该第一物理内存区间;以及,该装置还包括:收发单元,用于在该第一用户进程中向该第二用户进程发送该第一物理内存区间。With reference to the second aspect, in some implementations of the second aspect, the task request is a file mapping request, the first user state process is a file system process or a virtual file system process, and the processing unit is further configured to The process responds to the file mapping request, and maps the file requested by the file mapping request to the first physical memory range; and, the device further includes: a transceiver unit, configured to send the second user to the second user in the first user process The process sends the first physical memory range.
结合第二方面,在第二方面的某些实现方式中,该任务请求为文件读写请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,该处理单元还用于在该第一用户进程中对该第一物理内存区间执行该文件读写请求所请求的读写操作。With reference to the second aspect, in some implementations of the second aspect, the task request is a file read and write request, the first user mode process is a file system process or a virtual file system process, and the processing unit is further configured to A user process executes the read and write operations requested by the file read and write request on the first physical memory range.
结合第二方面,在第二方面的某些实现方式中,该处理单元还用于在该第二用户态进程中为该第一用户态进程授权物理内存空间分配权限。With reference to the second aspect, in some implementation manners of the second aspect, the processing unit is further configured to authorize the physical memory space allocation permission for the first user-mode process in the second user-mode process.
第三方面,提供了一种通信装置,包括处理器。该处理器可以实现上述第一方面以及第一方面中任一种可能实现方式中的方法。In a third aspect, a communication device is provided, including a processor. The processor may implement the first aspect and the method in any possible implementation manner of the first aspect.
可选地,该通信装置还包括存储器,该处理器与该存储器耦合,可用于执行存储器中的指令,以实现上述第一方面以及第一方面中任一种可能实现方式中的方法。Optionally, the communication device further includes a memory, and the processor is coupled to the memory, and can be used to execute instructions in the memory, so as to implement the above first aspect and the method in any possible implementation manner of the first aspect.
可选地,该通信装置还包括通信接口,处理器与通信接口耦合。Optionally, the communication device further includes a communication interface, and the processor is coupled to the communication interface.
本申请实施例中,通信接口可以是收发器、管脚、电路、总线、模块或其它类型的通信接口,不予限制。In this embodiment of the present application, the communication interface may be a transceiver, a pin, a circuit, a bus, a module or other types of communication interfaces, without limitation.
第四方面,提供了一种操作系统,包括计算机程序,计算机程序代码,当该计算机程序代码被调用时,使得计算机操作系统执行第一方面以及第一方面中任一种可能实现方式中的方法。In a fourth aspect, there is provided an operating system, including computer programs and computer program codes. When the computer program codes are invoked, the computer operating system executes the method in the first aspect and any possible implementation manner of the first aspect .
第五方面,提供了一种处理器,包括:输入电路、输出电路和处理电路。该处理电路 用于通过该输入电路接收信号,并通过该输出电路发射信号,使得该处理器执行第一方面以及第一方面中任一种可能实现方式中的方法。In a fifth aspect, a processor is provided, including: an input circuit, an output circuit, and a processing circuit. The processing circuit is configured to receive a signal through the input circuit and transmit a signal through the output circuit, so that the processor executes the method in the first aspect and any possible implementation manner of the first aspect.
在具体实现过程中,上述处理器可以为一个或多个芯片,输入电路可以为输入管脚,输出电路可以为输出管脚,处理电路可以为晶体管、门电路、触发器和各种逻辑电路等。输入电路所接收的输入的信号可以是由例如但不限于接收器接收并输入的,输出电路所输出的信号可以是例如但不限于输出给发射器并由发射器发射的,且输入电路和输出电路可以是同一电路,该电路在不同的时刻分别用作输入电路和输出电路。本申请实施例对处理器及各种电路的具体实现方式不做限定。In the specific implementation process, the above-mentioned processor can be one or more chips, the input circuit can be an input pin, the output circuit can be an output pin, and the processing circuit can be a transistor, a gate circuit, a flip-flop and various logic circuits, etc. . The input signal received by the input circuit may be received and input by, for example but not limited to, the receiver, the output signal of the output circuit may be, for example but not limited to, output to the transmitter and transmitted by the transmitter, and the input circuit and the output The circuit may be the same circuit, which is used as an input circuit and an output circuit respectively at different times. The embodiment of the present application does not limit the specific implementation manners of the processor and various circuits.
第六方面,提供了一种计算机程序产品,该计算机程序产品包括:计算机程序(也可以称为代码,或指令),当该计算机程序被运行时,使得计算机执行上述第一方面以及第一方面中任一种可能实现方式中的方法。In a sixth aspect, a computer program product is provided, and the computer program product includes: a computer program (also referred to as code, or an instruction), when the computer program is executed, the computer executes the above-mentioned first aspect and the first aspect A method in any of the possible implementations.
第七方面,提供了一种计算机可读介质,该计算机可读介质存储有计算机程序(也可以称为代码,或指令)当其在计算机上运行时,使得计算机执行上述第一方面以及第一方面中任一种可能实现方式中的方法。In a seventh aspect, a computer-readable medium is provided, and the computer-readable medium stores a computer program (also referred to as code, or an instruction) which, when running on a computer, causes the computer to execute the above-mentioned first aspect and the first A method in any one of the possible implementations of the aspect.
附图说明Description of drawings
图1为适用于本申请的操作系统架构的一个示意图;FIG. 1 is a schematic diagram of an operating system architecture applicable to the present application;
图2是本申请实施例提供的内存分配方法的一示意性流程图;FIG. 2 is a schematic flowchart of a memory allocation method provided by an embodiment of the present application;
图3是本申请提供的内存分配方法实施例一的一个示意性流程图;FIG. 3 is a schematic flowchart of Embodiment 1 of the memory allocation method provided by the present application;
图4是本申请提供的内存分配方法实施例二的一个示意性流程图;FIG. 4 is a schematic flowchart of Embodiment 2 of the memory allocation method provided by the present application;
图5是本申请提供的内存分配方法实施例三的一个示意性流程图;FIG. 5 is a schematic flowchart of Embodiment 3 of the memory allocation method provided by the present application;
图6是本申请提供的内存分配方法实施例四的一个示意性流程图;FIG. 6 is a schematic flowchart of Embodiment 4 of the memory allocation method provided by the present application;
图7是本申请提供的通信装置的一例的示意性框图;FIG. 7 is a schematic block diagram of an example of a communication device provided by the present application;
图8是本申请提供的通信设备的一例的示意性结构图。Fig. 8 is a schematic structural diagram of an example of a communication device provided by the present application.
具体实施方式Detailed ways
下面将结合附图,对本申请中的技术方案进行描述。The technical solution in this application will be described below with reference to the accompanying drawings.
为使本申请实施例的目的、技术方案和优点更加清楚,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments It is a part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the scope of protection of this application.
本申请实施例的说明书、权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例例如能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second" and the like in the description, claims, and above-mentioned drawings of the embodiments of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific sequence or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein, for example, can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed instead, may include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus.
首先,对本申请涉及到的相关技术和术语进行介绍。First, the relevant technologies and terms involved in this application are introduced.
1.微内核架构1. Microkernel architecture
在微内核架构中,运行操作系统的处理器的功能被分为内核态(某些语境下也可以简称为内核)和用户态,内核态只负责部分关键业务功能,大部分操作系统功能放在用户态,这样可以确保内核态的“微型”化,同时把不同功能模块分开管理,以不同的进程运行,一个模块的问题不会影响到其他模块,实现更好的安全性和可靠性。典型的微内核架构操作系统有SeL4,QNX,MINIX,Fuchsia等。In the microkernel architecture, the functions of the processor running the operating system are divided into the kernel state (in some contexts, it can also be referred to as the kernel for short) and the user state. The kernel state is only responsible for some key business functions, and most of the operating system functions are released. In the user mode, this can ensure the "miniaturization" of the kernel mode. At the same time, different functional modules are managed separately and run in different processes. A problem with one module will not affect other modules, achieving better security and reliability. Typical microkernel architecture operating systems include SeL4, QNX, MINIX, Fuchsia, etc.
2.宏内核架构2. Macro kernel architecture
在宏内核架构中,运行操作系统的处理器所有功能都运行在内核态,实现一个“宏大”的内核,因为所有模块都运行在一个地址空间,可以直接互相访问,宏内核架构可以实现非常高效的性能,但也存在一个模块出了问题会导致整个内核崩溃的安全和可靠性问题。典型的宏内核架构操作系统有Linux。In the macro-kernel architecture, all the functions of the processor running the operating system run in the kernel mode to realize a "grand" kernel, because all modules run in one address space and can directly access each other, the macro-kernel architecture can achieve very high efficiency performance, but there are also safety and reliability issues that a module failure will cause the entire kernel to crash. A typical macro-kernel architecture operating system is Linux.
需要说明的是,本申请提供的方案可以适用于微内核架构的操作系统也可以适用于宏内核架构的操作系统,本申请对此不做限定。It should be noted that the solutions provided in the present application may be applicable to operating systems with a microkernel architecture and also applicable to operating systems with a macrokernel architecture, which is not limited in this application.
3.系统服务(system service)进程3. System service (system service) process
系统服务进程可以简称为系统服务或服务进程,系统服务进程是执行指定系统功能的进程,通常本地和通过网络为用户提供一些系统功能的服务,例如,系统服务进程可以包括但不限于文件系统进程(file system,FS)、客户端/服务器进程、Web服务器进程等。A system service process can be referred to as a system service or a service process for short. A system service process is a process that performs specified system functions, and usually provides users with some system function services locally and through the network. For example, a system service process can include but is not limited to a file system process (file system, FS), client/server process, Web server process, etc.
系统服务进程一般在后台运行,不会向用户应用进程出现程序窗口或对话框,可以在任务管理器中查找到已启动的系统服务进程。The system service process generally runs in the background, and no program window or dialog box will appear to the user application process. You can find the started system service process in the task manager.
图1为适用于本申请的操作系统架构的一个示意图。FIG. 1 is a schematic diagram of an operating system architecture applicable to this application.
如图1所示,操作系统可以根据功能权限划分为内核态模式和用户态模式,或者说,当处理装置运行操作系统时,处理装置的工作模式可以包括内核态模式或用户态模式。其中,用户态模式包括至少一个用户态进程,如用户态模式可以包括系统管理者(system manager,SYSMGR)进程,负责启动并管理系统组件以及系统服务,为用户应用(user application,UAPP)请求提供相应的系统服务,用户态模式还可以包括虚拟文件系统进程(virtual file system,VFS),负责管理和存储文件信息。用户态模式还可以包括其他系统服务进程,本申请不限于此。内核态模式包括至少一个内核态进程,负责关键业务功能。应理解,图1仅为适用于本申请的操作系统的一个系统架构示意图,但本申请不限于此,本申请的方案还可以应用于其他系统架构的操作系统中。As shown in FIG. 1 , the operating system can be divided into a kernel mode and a user mode according to functional rights. In other words, when the processing device runs an operating system, the working mode of the processing device can include a kernel mode or a user mode. Wherein, the user state mode includes at least one user state process, such as the user state mode may include a system manager (system manager, SYSMGR) process, which is responsible for starting and managing system components and system services, and providing user application (user application, UAPP) requests. Corresponding system services, the user mode can also include a virtual file system process (virtual file system, VFS), which is responsible for managing and storing file information. The user state mode may also include other system service processes, and the present application is not limited thereto. The kernel-mode mode includes at least one kernel-mode process, which is responsible for key business functions. It should be understood that FIG. 1 is only a schematic diagram of a system architecture applicable to an operating system of the present application, but the present application is not limited thereto, and the solutions of the present application may also be applied to operating systems of other system architectures.
目前处理器运行操作系统时实现内存管理的方式主要包括两种:在用户态实现和在内核态实现。At present, there are mainly two ways to implement memory management when the processor runs an operating system: implementation in user mode and implementation in kernel mode.
例如,嵌入式实时操作系统(quick unix,QNX)中的内存管理完全放在用户态实现,内核负责地址空间映射时页表填充的部分。以读文件为例,具体流程步骤如下:For example, memory management in an embedded real-time operating system (quick unix, QNX) is completely implemented in user mode, and the kernel is responsible for filling the page table during address space mapping. Taking file reading as an example, the specific process steps are as follows:
步骤一:UAPP发送读文件请求给FS进程(以下简称FS);Step 1: UAPP sends a file read request to the FS process (hereinafter referred to as FS);
步骤二:FS判断文件是否读取完毕,读取完毕则结束返回,否则继续;Step 2: FS judges whether the file has been read, and returns after reading, otherwise continue;
步骤三:FS向内存管理进程申请内容作为高速缓冲存储器(cache);Step 3: FS applies for content as a cache memory (cache) to the memory management process;
步骤四:FS读取文件并写入cache;Step 4: FS reads the file and writes it into the cache;
步骤五:FS将cache中的内容拷贝至UAPP指定的地址;Step 5: FS copies the content in the cache to the address specified by UAPP;
步骤六:返回步骤二。Step 6: Go back to Step 2.
其中,上述步骤三中FS需要通过进程间通信(IPC)向内存管理进程申请cache,在读取的文件内容较大时,以页(page)为单位的cache分配将非常频繁,由于IPC耗时较 长,频繁的IPC将影响文件读写的性能。Among them, in the above step 3, FS needs to apply for cache from the memory management process through inter-process communication (IPC). When the content of the read file is large, the cache allocation in units of pages (page) will be very frequent. Longer and frequent IPCs will affect the performance of file read and write.
再例如,Fuchsia操作系统中的内存管理完全放在内核态实现,用户态系统服务进程的内存分配操作可以直接通过系统调用的方式向内核申请,虽然能够提高性能,但内核态中的内存管理模块较为庞大,这使得Fuchsia的内核相比传统微内核会更大更复杂,通过各种安全认证的难度和工作量都会更大。For another example, the memory management in the Fuchsia operating system is completely implemented in the kernel mode. The memory allocation operation of the user mode system service process can directly apply to the kernel through system calls. Although it can improve performance, the memory management module in the kernel mode It is relatively large, which makes Fuchsia's kernel larger and more complex than traditional microkernels, and the difficulty and workload of passing various security certifications will be greater.
针对目前操作系统中的内存管理方式存在的上述问题,本申请提出内核可以执行第一级内存空间管理,为第一用户态进程授权部分物理内存空间,由用户态进程执行第二级内存空间管理,根据任务需求分配被授权的物理内存空间,能够避免用户态进程在接收到任务请求后通过进程间通信(IPC)向其他用户态进程请求物理内存空间,或者通过系统调用向内核请求物理内存空间。通过采用两级物理内存空间的管理方式,在内核负责完成少量的工作量的情况下,减少用户态进程之间频繁的通信,能够减小系统能耗、开销,提高内存分配的工作效率。In view of the above-mentioned problems existing in the memory management methods in the current operating system, this application proposes that the kernel can perform the first-level memory space management, authorize part of the physical memory space for the first user-mode process, and let the user-mode process perform the second-level memory space management , allocate authorized physical memory space according to task requirements, which can prevent user-mode processes from requesting physical memory space from other user-mode processes through inter-process communication (IPC) after receiving task requests, or requesting physical memory space from the kernel through system calls . By adopting a two-level physical memory space management method, when the kernel is responsible for completing a small amount of work, frequent communication between user-mode processes can be reduced, system energy consumption and overhead can be reduced, and the work efficiency of memory allocation can be improved.
下面结合附图对本申请提供的内存分配方法进行说明。The memory allocation method provided by the present application will be described below with reference to the accompanying drawings.
图2是本申请提供的内存分配方法的一个示意性流程图。该内存分配方法可以由操作系统执行,或者可以是处理装置运行操作系统时执行该内存分配方法,操作系统包括多个用户态进程程序和内核程序(可以称为内核)。下面由操作系统该内存分配方法为例进行说明,但本申请不限于此。FIG. 2 is a schematic flowchart of the memory allocation method provided by the present application. The memory allocation method may be executed by an operating system, or the memory allocation method may be executed when the processing device runs an operating system, and the operating system includes multiple user state process programs and kernel programs (which may be called kernels). The following uses the memory allocation method of the operating system as an example for illustration, but the present application is not limited thereto.
S210,内核为第一用户态进程授权第一物理内存空间。S210. The kernel authorizes the first physical memory space for the first user mode process.
处理装置运行操作系统,该操作系统的内核用于管理该操作系统的物理内存空间。该内核可以用于为第一用户态进程授权系统的物理内存空间中的部分物理内存空间,如内核为第一用户态进程授权第一物理内存空间。该第一用户态进程可以对被授权的第一物理内存空间进行分配。The processing device runs an operating system whose kernel is used to manage the physical memory space of the operating system. The kernel may be used to authorize part of the physical memory space in the physical memory space of the system for the first user state process, for example, the kernel authorizes the first physical memory space for the first user state process. The first user mode process may allocate the authorized first physical memory space.
作为示例非限定,该第一用户态进程为系统服务进程。As an example without limitation, the first user mode process is a system service process.
需要说明的是,本申请中涉及到的内核的操作或用户态进程的操作(如执行、授权、发送、接收、确定、管理等操作)可以理解为是处理装置在运行到操作系统的该进程时执行的操作,或者操作系统运行到该进程时执行的操作。It should be noted that the operation of the kernel or the operation of the user-mode process (such as execution, authorization, sending, receiving, determination, management, etc.) involved in this application can be understood as the process that the processing device runs into the operating system. What to do when the process is run, or when the operating system runs into the process.
一种实施方式中,该操作系统创建该第一用户态进程后,由该第一用户态进程向内核申请物理内存空间。该内核响应第一用户态进程的申请,为该第一用户进程分配该第一物理内存空间。In one implementation manner, after the operating system creates the first user-mode process, the first user-mode process applies to the kernel for physical memory space. The kernel allocates the first physical memory space for the first user process in response to the application of the first user state process.
另一种实施方式中,第一用户态进程被授权的物理内存空间不足时,如第一用户态进程被授权的物理内存空间中,空闲物理内存(空闲物理内存也可以称为待分配的物理内存或待使用的物理内存)的大小不满足其他进程请求的物理内存大小时,第一用户态进程可以向内核申请物理内存空间。内核响应第一用户态进程的申请,为该第一用户进程分配该第一物理内存空间。In another embodiment, when the authorized physical memory space of the first user mode process is insufficient, as in the authorized physical memory space of the first user mode process, free physical memory (free physical memory can also be referred to as physical memory to be allocated) memory or physical memory to be used) does not meet the size of physical memory requested by other processes, the first user mode process can apply for physical memory space from the kernel. The kernel allocates the first physical memory space for the first user process in response to the application of the first user process.
S220,第一用户态进程为第二用户态进程分配第一物理内存空间中的第一物理内存区间。S220. The first user mode process allocates the first physical memory range in the first physical memory space to the second user mode process.
第一用户态进程接收第二用户态进程的任务请求,例如,该任务请求可以是来自应用进程的文件映射请求、文件读写请求等。第一用户态进程可以确定该任务请求所需的内存空间大小,并在该第一用户态进程被授权的第一物理内存空间中确定第一物理内存地址区间,则为该任务请求分配该第一内存地址区间。The first user mode process receives a task request from the second user mode process. For example, the task request may be a file mapping request, a file read and write request, etc. from an application process. The first user state process can determine the memory space size required by the task request, and determine the first physical memory address interval in the first physical memory space authorized by the first user state process, then allocate the first physical memory address interval for the task request A range of memory addresses.
具体地,该第一用户态进程基于该任务请求所需的内存空间大小,判断该第一用户态进程被授权的物理内存空间中待分配的物理内存空间的大小是否满足该任务请求所需的内存空间大小。若满足,则在该待分配的物理内存空间中为该任务请求分配物理内存地址区间;若不满足,则第一用户态进程向内核申请物理内存空间,该内核为该第一用户进程授权部分物理内存空间,第一用户态进程在被授权的物理内存空间内为该任务请求分配第一物理内存区间。Specifically, the first user mode process judges whether the size of the physical memory space to be allocated in the authorized physical memory space of the first user mode process meets the required size of the task request based on the size of the memory space required by the task request. The size of the memory space. If satisfied, then in the physical memory space to be allocated, allocate a physical memory address interval for the task request; if not satisfied, the first user mode process applies for a physical memory space to the kernel, and the kernel is the authorized part of the first user process In the physical memory space, the first user state process requests to allocate the first physical memory range for the task in the authorized physical memory space.
可选地,该第一用户态进程可以是用户态进程中的内存管理的主服务进程,或者可以称为主内存管理进程,该主服务进程可以为其他系统服务进程授权物理内存空间分配权限。Optionally, the first user mode process may be the main service process of memory management in the user mode process, or may be called the main memory management process, and the main service process may authorize physical memory space allocation rights for other system service processes.
例如,其他系统服务进程可以包括文件系统进程,该主服务进程授权文件系统进程物理内存空间分配权限,文件系统进程被授权物理内存空间分配权限后可以向内核申请物理内存空间,内核为该文件系统进程授权部分物理内存空间后,该文件系统进程可以为其他进程的任务请求分配该部分物理内存空间中的物理内存区间。但本申请不限于此。For example, other system service processes may include a file system process. The main service process authorizes the file system process to allocate physical memory space. After the file system process is authorized to allocate physical memory space, it can apply for physical memory space from the kernel. After the process authorizes part of the physical memory space, the file system process can allocate a physical memory range in the part of the physical memory space for task requests of other processes. But the present application is not limited thereto.
可选地,内核获取到用户态进程申请物理内存空间的请求后,基于该请求所需的物理内存空间的大小,确定内核管理的物理内存空间中待分配的物理内存空间的大小是否满足该请求所需的内存空间的大小。若满足,则为用户态进程授权部分物理内存空间,若不满足,内核可以发起物理内存空间回收,比如向具有物理内存空间分配权限的用户态进程发起物理内存空间请求,从而回收部分物理内存空间后,再为用户态进程授权物理内存空间。Optionally, after the kernel obtains the request of the user state process to apply for the physical memory space, based on the size of the physical memory space required by the request, it is determined whether the size of the physical memory space to be allocated in the physical memory space managed by the kernel satisfies the request The size of the required memory space. If it is satisfied, part of the physical memory space is authorized for the user-mode process. If it is not satisfied, the kernel can initiate physical memory space recovery, such as initiating a physical memory space request to a user-mode process with physical memory space allocation permissions, thereby reclaiming part of the physical memory space After that, the physical memory space is authorized for the user mode process.
根据本申请的上述方案,采用两级物理内存空间的管理方式,可以在内核负责完成少量的工作量的情况下,减少用户态进程的之间频繁通信,能够减小系统能耗、开销。According to the above solution of the present application, the two-level physical memory space management method can reduce frequent communication between user mode processes when the kernel is responsible for completing a small amount of work, and can reduce system energy consumption and overhead.
图3是本申请提供的内存分配方法的实施例一的流程图。图3示出了操作系统启动初始化阶段,采用本申请提供的内存分配方法分配内存的示意性流程图。FIG. 3 is a flow chart of Embodiment 1 of the memory allocation method provided by the present application. FIG. 3 shows a schematic flow chart of memory allocation using the memory allocation method provided by the present application at the startup initialization stage of the operating system.
处理装置启动操作系统的初始化阶段的流程包括但不限于如下步骤:The process of initializing the processing device to start the operating system includes but is not limited to the following steps:
1.启动内核;1. Start the kernel;
2.在内核启动过程中,首先创建并使用启动分配器(boot allocator),用于内核启动阶段对内存的使用需求,当内核启动过程中完成了对内存的使用后,结束boot allocator的生命周期;2. During the kernel startup process, first create and use a boot allocator (boot allocator) for the memory usage requirements during the kernel startup phase. When the memory usage is completed during the kernel startup process, the life cycle of the boot allocator is ended ;
3.在内核启动过程中对剩余物理内存空间完成元数据的初始化;3. Complete the initialization of metadata for the remaining physical memory space during the kernel startup process;
4.内核启动的初始化完毕后,创建用户态内存管理主服务进程,例如,该内存管理主服务进程可以是系统管理者SYSMGR进程;4. After the initialization of the kernel startup is completed, create a user mode memory management main service process, for example, the memory management main service process can be the system manager SYSMGR process;
5.主服务进程中向内核申请主服务进程的物理内存空间;5. In the main service process, apply to the kernel for the physical memory space of the main service process;
例如,主服务进程(即第一用户态进程的一个示例)可以包括第一物理内存管理算法(physical memory management algorithm,PHYMGR),内核可以包括全局PHYMGR(global PHYMGR),主服务进程通过物理内存管理算法向内核申请物理内存空间,内核响应该申请,通过该全局PHYMGR为主服务进程授权部分物理内存空间(即第一物理内存空间的一个示例)。For example, the main service process (i.e. an example of the first user mode process) may include a first physical memory management algorithm (physical memory management algorithm, PHYMGR), the kernel may include a global PHYMGR (global PHYMGR), and the main service process manages The algorithm applies for a physical memory space to the kernel, and the kernel responds to the application by authorizing part of the physical memory space (that is, an example of the first physical memory space) to the main service process through the global PHYMGR.
6.在主服务进程对该主服务进程被授权的物理内存空间完成元数据的初始化;6. Complete the initialization of metadata in the physical memory space authorized by the main service process to the main service process;
7.在主服务进程初始化完成后,创建初始化(initialization,INIT)进程;7. After the initialization of the main service process is completed, create an initialization (initialization, INIT) process;
8.在INIT进程中创建其他系统服务进程,例如,创建文件系统进程等;8. Create other system service processes in the INIT process, for example, create file system processes, etc.;
9.可选地,主服务进程可以授权一个或多个系统服务进程物理内存空间管理权限。9. Optionally, the main service process may authorize one or more system service processes to manage physical memory space.
例如,虚拟文件系统(VFS)进程对物理内存有较高的分配需求,主服务进程可以授 权VFS进程物理内存管理权限,但本申请不限于此,主服务进程还可以授权其他对物理内存有较高的分配需求的进程物理内存管理权限。For example, a virtual file system (VFS) process has a higher allocation requirement for physical memory, and the main service process can authorize the physical memory management authority of the VFS process, but the application is not limited thereto. Process physical memory management permissions for processes with high allocation requirements.
10.在步骤9中被授权物理内存管理权限的系统服务进程(即第一用户态进程的另一个示例)向内核申请物理内存空间。10. In step 9, the system service process (that is, another example of the first user mode process) authorized to manage the physical memory applies to the kernel for physical memory space.
11.被授权物理管理权限的系统服务进程完成被授权的物理内存空间(即第一物理内存空间的另一个示例)元数据的初始化。被授权物理管理权限的系统服务对被授权的物理内存空间具有分配权限。11. The system service process authorized with the physical management authority completes the initialization of the metadata of the authorized physical memory space (that is, another example of the first physical memory space). System services that are granted physical management rights have allocation rights to the authorized physical memory space.
12.执行其他剩余操作系统启动流程后,完成操作系统的启动。12. After performing other remaining operating system start-up processes, complete the start-up of the operating system.
在操作系统初始化阶段,内核为主服务进程授权部分物理内存空间,使得操作系统运行阶段,主服务进程可以根据需求分配被授权的物理内存空间。通过物理内存空间的两极化管理,能够实现内核的微型化,减少内核的工作量,提高系统的安全性。During the initialization phase of the operating system, the kernel authorizes part of the physical memory space for the main service process, so that the main service process can allocate the authorized physical memory space according to the requirements during the running phase of the operating system. Through the polarization management of the physical memory space, the miniaturization of the kernel can be realized, the workload of the kernel can be reduced, and the security of the system can be improved.
图4是本申请提供的内存分配方法的实施例二的一个示意性流程图。图4示出了处理装置在运行主服务进程时获取到UAPP的匿名内存映射请求后,响应该匿名内存映射请求进行内存分配的示意性流程。其中,VFS进程可以例如图3所示,在初始化阶段被主服务进程授权物理内存空间管理权限,并被内核授权、该VFS进程具有分配权限的部分物理内存空间,但本申请不限于此。FIG. 4 is a schematic flowchart of Embodiment 2 of the memory allocation method provided by the present application. FIG. 4 shows a schematic flow of memory allocation in response to the anonymous memory mapping request of the UAPP after the processing device obtains the anonymous memory mapping request while running the main service process. Wherein, the VFS process can be, for example, as shown in FIG. 3 , authorized by the main service process to manage the physical memory space in the initialization phase, and authorized by the kernel, and the VFS process has a part of the physical memory space allocated with the authority, but the application is not limited thereto.
该处理装置响应UAPP的匿名内存映射请求的流程,包括但不限于如下步骤:The process of the processing device responding to UAPP's anonymous memory mapping request includes but is not limited to the following steps:
1.在主服务进程中获取到UAPP的匿名内存映射(UAPP anon map with populate)请求;1. Obtain UAPP's anonymous memory mapping (UAPP anon map with populate) request in the main service process;
匿名内存映射是指映射区不与文件相关联。Anonymous memory mapping means that the mapped area is not associated with a file.
2.在主服务进程中为该匿名内存映射任务(或者说为发起该匿名内存映射请求的进程)分配相应的虚拟内存区间;2. Allocate the corresponding virtual memory interval for the anonymous memory mapping task (or the process that initiates the anonymous memory mapping request) in the main service process;
其中,虚拟内存区间可以是一个虚拟内存地址区间,或称为虚拟内存地址段,物理内存区间可以是一个物理内存地址区间,或称为物理内存地址段。Wherein, the virtual memory range may be a virtual memory address range, or called a virtual memory address segment, and the physical memory range may be a physical memory address range, or called a physical memory address segment.
3.判断主服务进程被授权的物理内存空间中待分配的物理内存空间是否足够;3. Determine whether the physical memory space to be allocated in the authorized physical memory space of the main service process is sufficient;
处理装置首先要判断该主服务进程被授权的物理内存空间中待分配的物理内存空间是否能够满足该内存映射请求所需的内存空间大小。若不满足,则在步骤4中向内核申请物理内存空间;若满足,执行步骤8,在主服务进程被授权的物理内存空间中,为该匿名内存映射请求分配物理内存区间;The processing device first needs to determine whether the physical memory space to be allocated in the authorized physical memory space of the main service process can satisfy the size of the memory space required by the memory mapping request. If not satisfied, apply for physical memory space from the kernel in step 4; if satisfied, perform step 8 to allocate a physical memory range for the anonymous memory mapping request in the authorized physical memory space of the main service process;
4.在主服务进程中向内核申请物理内存空间;4. Apply for physical memory space from the kernel in the main service process;
5.内核判断全局物理内存空间中待分配的物理内存空间是否够;5. The kernel judges whether the physical memory space to be allocated in the global physical memory space is enough;
处理装置在内核获取到该主服务进程的申请后,判断全局物理内存空间中待分配的物理内存空间大小是否满足主服务进程申请的物理内存空间大小。若满足,则内核为主服务进程授权部分物理内存空间后,返回步骤3;若不满足,则在步骤6中发起内存回收。After the kernel obtains the application of the main service process, the processing device judges whether the size of the physical memory space to be allocated in the global physical memory space satisfies the size of the physical memory space applied by the main service process. If it is satisfied, the kernel authorizes part of the physical memory space for the main service process, and then returns to step 3; if not, initiates memory recovery in step 6.
6.内核发起内存回收请求,以回收部分物理内存空间;6. The kernel initiates a memory reclamation request to reclaim part of the physical memory space;
7.在全局物理内存空间足够的情况下,内核为主服务进程授权部分物理内存空间,并在主服务进程对被授权的部分物理内存空间执行元数据初始化,返回步骤3;7. When the global physical memory space is sufficient, the kernel authorizes part of the physical memory space for the main service process, and performs metadata initialization on the authorized part of the physical memory space in the main service process, and returns to step 3;
8.在主服务进程中为该匿名内存映射任务分配主服务进程被授权的物理内存空间中的物理内存区间;8. In the main service process, allocate a physical memory interval in the authorized physical memory space of the main service process for the anonymous memory mapping task;
9.在主服务进程中向内核发起映射请求,即将为该匿名内存映射请求分配的虚拟内存 区间和物理内存区间发送给内核发起映射请求;9. Initiate a mapping request to the kernel in the main service process, and send the virtual memory interval and physical memory interval allocated for the anonymous memory mapping request to the kernel to initiate a mapping request;
10.处理装置完成剩余流程。10. The processing unit completes the rest of the process.
图5是本申请提供的内存分配方法的实施例三的一个示意性流程图。图5示出了处理装置在运行主服务进程时获取到UAPP的文件映射请求后,响应该文件映射请求时执行内存分配流程的示意性流程图。其中,VFS进程可以例如图3所示,在初始化阶段被主服务进程授权物理内存空间管理权限,并被内核授权、该VFS进程具有分配权限的部分物理内存空间,但本申请不限于此。FIG. 5 is a schematic flowchart of Embodiment 3 of the memory allocation method provided by the present application. FIG. 5 shows a schematic flow chart of executing a memory allocation process in response to the file mapping request after the processing device acquires a file mapping request from the UAPP while running the main service process. Wherein, the VFS process can be, for example, as shown in FIG. 3 , authorized by the main service process to manage the physical memory space in the initialization phase, and authorized by the kernel, and the VFS process has a part of the physical memory space with the assigned authority, but the application is not limited thereto.
该处理装置响应UAPP的文件映射请求的流程,包括但不限于如下步骤:The process of the processing device responding to the file mapping request of UAPP includes but not limited to the following steps:
1.在主服务进程中获取到UAPP的文件映射(UAPP file map with populate)请求;1. Obtain the UAPP file map (UAPP file map with populate) request in the main service process;
例如,该文件映射请求可以是mmap文件映射函数携带populated标志位(with populated flag),但本申请不限于此。For example, the file mapping request may be that the mmap file mapping function carries a populated flag (with populated flag), but the application is not limited thereto.
2.在主服务进程中为该文件映射任务(或者说为发起该文件映射任务的进程)分配相应的虚拟内存区间;2. Allocate a corresponding virtual memory interval for the file mapping task (or the process that initiates the file mapping task) in the main service process;
3.在主服务进程向VFS进程请求与该UAPP对应的页高速缓存器(page cache),请求VFS进程提供与该UAPP对应的文件页的物理内存(区间);3. The main service process requests the page cache (page cache) corresponding to the UAPP from the VFS process, and requests the VFS process to provide the physical memory (interval) of the file page corresponding to the UAPP;
4.判断VFS进程是否有与该UAPP对应的页高速缓存器,若没有,则执行步骤5;若有则执行步骤11,向主服务进程返回该UAPP对应的页高速缓存器;4. Determine whether the VFS process has a page cache corresponding to the UAPP, if not, then perform step 5; if so, perform step 11, and return the page cache corresponding to the UAPP to the main service process;
5.判断VFS被授权的物理内存空间是否足够;5. Determine whether the authorized physical memory space of the VFS is sufficient;
处理装置首先要判断该VFS进程被授权的物理内存空间中待分配的物理内存空间是否能够满足该文件映射请求所需的内存空间大小。若不满足,则在步骤6中向内核申请物理内存空间;若满足,执行步骤10,在VFS进程被授权的物理内存空间中,为该文件映射任务分配物理内存区间作为页高速缓存器。The processing device first needs to judge whether the physical memory space to be allocated in the authorized physical memory space of the VFS process can satisfy the size of the memory space required by the file mapping request. If not satisfied, apply for physical memory space to the kernel in step 6; if satisfied, perform step 10, in the authorized physical memory space of the VFS process, allocate a physical memory interval as a page cache for the file mapping task.
6.在VFS进程中向内核申请物理内存空间;6. Apply for physical memory space from the kernel in the VFS process;
7.内核判断全局物理内存空间中待分配的物理内存空间是否够;7. The kernel judges whether the physical memory space to be allocated in the global physical memory space is enough;
内核获取到该VFS进程的申请后,判断全局物理内存空间中待分配的物理内存空间大小是否满足VFS进程申请的物理内存空间大小。若不满足,则在步骤8中发起内存回收;若满足,则步骤9中内核为VFS进程授权部分物理内存空间后,返回步骤5。After the kernel obtains the application of the VFS process, it judges whether the size of the physical memory space to be allocated in the global physical memory space satisfies the size of the physical memory space applied by the VFS process. If not, initiate memory reclamation in step 8; if satisfied, return to step 5 after the kernel authorizes part of the physical memory space for the VFS process in step 9.
8.内核发起内存回收请求,以回收部分物理内存空间;8. The kernel initiates a memory reclamation request to reclaim part of the physical memory space;
9.在全局物理内存空间足够的情况下,内核为VFS进程授权部分物理内存空间,并在VFS进程对被授权的物理内存空间执行元数据初始化,返回步骤5;9. When the global physical memory space is sufficient, the kernel authorizes part of the physical memory space for the VFS process, and performs metadata initialization on the authorized physical memory space in the VFS process, and returns to step 5;
10.在VFS进程被授权的物理内存空间中为该文件映射任务分配VFS进程的物理内存区间作为页高速缓存器;10. Allocate the physical memory interval of the VFS process as the page cache for the file mapping task in the authorized physical memory space of the VFS process;
可选地,在VFS进程中通过该VFS进程相对应的物理内存管理算法(phymgr)从被授权的物理内存空间中为该文件映射任务分配物理内存区间。Optionally, in the VFS process, a physical memory range is allocated for the file mapping task from authorized physical memory space through a physical memory management algorithm (phymgr) corresponding to the VFS process.
11.在VFS进程将文件内容写入页高速缓存器;11. Write the file content to the page cache in the VFS process;
12.在VFS进程向VFS进程返回该UAPP对应的页高速缓存器;12. The VFS process returns the page cache corresponding to the UAPP to the VFS process;
13.在主服务进程中向内核发起映射请求,即将为该文件映射请求分配的虚拟内存区间和物理内存区间发送给内核发起映射请求;13. Initiate a mapping request to the kernel in the main service process, that is, send the virtual memory interval and physical memory interval allocated for the file mapping request to the kernel to initiate a mapping request;
14.处理装置完成剩余流程。14. The processing unit completes the remaining process.
应理解,根据上述处理流程可知,本申请对系统服务(如VFS进程等)的物理内存 分配和使用明确的权限管理和操作边界,系统服务管理的物理内存只用于满足自身功能和逻辑实现的需要(如文件映射任务等),不能用于满足应用程序的物理内存分配,应用程序的物理内存分配还是由主内存管理进程负责。由此可以减少进程间的频繁交互,也并未增加整体的内存管理复杂性,物理内存的访问控制还是统一在主内存管理进程中处理。It should be understood that, according to the above processing flow, this application allocates and uses physical memory of system services (such as VFS processes, etc.) with clear authority management and operation boundaries, and the physical memory managed by system services is only used to meet its own functions and logic implementation. Needs (such as file mapping tasks, etc.), cannot be used to satisfy the physical memory allocation of the application, and the physical memory allocation of the application is still the responsibility of the main memory management process. This can reduce the frequent interaction between processes, and does not increase the overall memory management complexity. The access control of physical memory is still handled in the main memory management process.
目前微内核操作系统中,文件读写性能相对宏内核操作系统会有明显的劣势,通过使用本申请提供的内存分配方法后,文件读写性能可以持平或超越典型的宏内核操作系统Linux。在测试实验中,对比了本申请提供的内存分配方法与现有技术中Linux操作系统的读能力和写能力。对于相同大小的文件在每次读取相同字节数时,无论是顺序读取的方式还是随机读取的方式,本申请提供的内存分配方法相较于Linux操作系统处理效率可以提高35%以上。对于相同大小的文件在每次写入相同字节数时,无论是顺序写入的方式还是随机写入的方式,本申请提供的内存分配方法相较于Linux操作系统处理效率可以提高15%以上。尤其对于每秒写入较大字节量时,本申请提供的内存分配方法的处理效率提高更为明显,例如每秒写入2兆字节时,处理效率可以提高60%。In the current micro-kernel operating system, the file reading and writing performance has obvious disadvantages compared with the macro-kernel operating system. After using the memory allocation method provided by this application, the file reading and writing performance can be equal to or surpass the typical macro-kernel operating system Linux. In the test experiment, the memory allocation method provided by the present application was compared with the read ability and write ability of the Linux operating system in the prior art. For files of the same size, when the same number of bytes is read each time, no matter in the way of sequential reading or random reading, the memory allocation method provided by this application can improve the processing efficiency by more than 35% compared with the Linux operating system . For files of the same size, when the same number of bytes is written each time, no matter in the way of sequential writing or random writing, the memory allocation method provided by this application can improve the processing efficiency by more than 15% compared with the Linux operating system . Especially when a large amount of bytes is written per second, the processing efficiency of the memory allocation method provided by the present application is significantly improved. For example, when 2 megabytes are written per second, the processing efficiency can be increased by 60%.
图6是本申请提供的内存分配方法的实施例四的一个示意性流程图。图6示出了处理装置在运行VFS进程时获取到UAPP的文件读写请求后,响应该文件映射请求时执行内存分配流程的示意性流程图,其中,VFS进程可以例如图3所示,在初始化阶段被主服务进程授权物理内存空间管理权限,并被内核授权、该VFS进程具有分配权限的部分物理内存空间,但本申请不限于此。FIG. 6 is a schematic flowchart of Embodiment 4 of the memory allocation method provided by the present application. FIG. 6 shows a schematic flow chart of executing a memory allocation process in response to the file mapping request after the processing device obtains a file read and write request from UAPP while running a VFS process, wherein the VFS process can be, for example, as shown in FIG. In the initial stage, the main service process is authorized to manage the physical memory space, and is authorized by the kernel, and the VFS process has a part of the physical memory space with the allocation authority, but the application is not limited thereto.
该处理装置响应UAPP的文件读写请求的流程,包括但不限于如下步骤:The process of the processing device responding to the file read and write request of UAPP includes but not limited to the following steps:
1.在VFS进程中获取到UAPP的文件读写请求;1. Obtain the file read and write request of UAPP in the VFS process;
UAPP的文件读写请求直接发送给VFS进程,在VFS进程中响应该文件读写请求根据文件指示符fd、调用相应的读(read)函数或写(write)函数,找到对应的文件位置。The file reading and writing request of UAPP is directly sent to the VFS process, and in response to the file reading and writing request in the VFS process, according to the file indicator fd, call the corresponding read (read) function or write (write) function to find the corresponding file location.
2.判断是否存在该文件对应的page cache;若不存在,处理装置执行步骤3;若存在,则执行步骤9,对该page cache执行UAPP请求相对应的读写操作;2. Determine whether there is a page cache corresponding to the file; if it does not exist, the processing device executes step 3; if it exists, executes step 9, and performs the corresponding read and write operations of the UAPP request on the page cache;
3.判断是VFS进程被授权的物理内存空间是否足够;3. Determine whether the authorized physical memory space of the VFS process is sufficient;
处理装置判断被授权的物理内存空间中待分配的物理内存空间大小是否满足该读写任务所需的page cache的大小。若不满足,则执行步骤4,向内核申请授权VFS进程部分物理内存空间;若满足,则执行步骤8,为该读写任务分配物理内存区间作为该读写任务的page cache。The processing device judges whether the size of the physical memory space to be allocated in the authorized physical memory space satisfies the size of the page cache required by the read-write task. If it is not satisfied, execute step 4 to apply to the kernel for authorization of part of the physical memory space of the VFS process; if satisfied, execute step 8 to allocate a physical memory range for the read and write task as the page cache for the read and write task.
4.在VFS进程向内核申请物理内存空间;4. Apply for physical memory space from the kernel in the VFS process;
5.内核判断全局物理内存空间是否足够;5. The kernel judges whether the global physical memory space is sufficient;
内核判断全局物理内存空间中待分配物理内存空间大小是否能够满足VFS进程申请的内存空间,若足够,则执行步骤7内核为VFS进程授权部分物理内存空间;若不足,则执行步骤6内核发起内存空间回收请求;The kernel judges whether the size of the physical memory space to be allocated in the global physical memory space can satisfy the memory space requested by the VFS process. If it is enough, then execute step 7. The kernel authorizes part of the physical memory space for the VFS process; if not, execute step 6. The kernel initiates the memory space space reclamation request;
6.内核发起内存空间回收请求,以回收部分物理内存空间后未VFS进程授权部分物理内存空间;6. The kernel initiates a memory space reclamation request to reclaim part of the physical memory space that has not been authorized by the VFS process;
7.内核为VFS进程授权部分物理内存空间,并在VFS进程对被授权的物理内存空间执行元数据初始化,返回步骤3;7. The kernel authorizes part of the physical memory space for the VFS process, and performs metadata initialization on the authorized physical memory space in the VFS process, and returns to step 3;
8.在VFS进程为该文件读写任务分配相应的物理内存区间作为page cache;8. In the VFS process, allocate the corresponding physical memory range as the page cache for the file reading and writing task;
9.在VFS进程对该文件相应的page cache执行读写操作;9. Perform read and write operations on the corresponding page cache of the file in the VFS process;
10.流程结束。10. The process ends.
在图6所示的处理文件读写任务时,处理装置在VFS进程接收到文件读写请求,在不存在相应的page cache,可以在VFS进程被授权的物理内存空间中为该文件读写任务分配相应的page cache。在VFS进程中具有物理内存空间分配权限,能够减少VFS进程向内存管理进程请求物理内存区间而带来的进程间通信开销,提高了处理效率。When processing the file reading and writing task shown in Figure 6, the processing device receives the file reading and writing request in the VFS process, and if there is no corresponding page cache, it can read and write the file in the physical memory space authorized by the VFS process Allocate the corresponding page cache. With the permission to allocate physical memory space in the VFS process, it can reduce the inter-process communication overhead caused by the VFS process requesting the physical memory range from the memory management process, and improve the processing efficiency.
以上结合图2至图6对本申请提供的内存分配方法进行了说明。下面结合图7对本申请提供的通信装置进行说明。The memory allocation method provided by the present application has been described above with reference to FIG. 2 to FIG. 6 . The communication device provided by the present application will be described below with reference to FIG. 7 .
图7为本申请提供的内存分配装置的示意性结构图。如图7所示,该内存分配装置包括请求单元710和处理单元720。FIG. 7 is a schematic structural diagram of a memory allocation device provided by the present application. As shown in FIG. 7 , the memory allocation device includes a request unit 710 and a processing unit 720 .
请求单元,用于在第二用户态进程向第一用户态进程发送任务请求,该任务请求用于请求分配内存空间;The request unit is used to send a task request to the first user mode process in the second user mode process, and the task request is used to request memory space allocation;
处理单元,用于在该第一用户态进程中为该任务请求分配第一物理内存区间,该第一物理内存区间属于第一物理内存空间,该第一物理内存空间是内核为该第一用户态进程授权的物理内存空间。A processing unit, configured to allocate a first physical memory range to the task request in the first user state process, the first physical memory range belongs to the first physical memory space, and the first physical memory space is the kernel for the first user The physical memory space authorized by the state process.
可选地,在该处理单元在该第一用户态进程为第二用户态进程的任务请求分配该第一物理内存区间之前,该处理单元还用于确定该第一用户态进程被授权的第二物理内存空间中空闲内存空间大小不满足该任务请求所需的内存空间大小;Optionally, before the processing unit requests allocation of the first physical memory range for the task of the second user-mode process by the first user-mode process, the processing unit is further configured to determine the authorized first user-mode process 2. The size of the free memory space in the physical memory space does not meet the size of the memory space required by the task request;
该请求单元还用于在该第一用户态进程中向该内核申请物理内存空间;The request unit is also used to apply for physical memory space from the kernel in the first user state process;
该处理单元还用于在该内核为该第一用户态进程中授权第三物理内存空间,其中,该第一物理内存空间包括该第二物理内存空间和该第三物理内存空间。The processing unit is further configured to authorize a third physical memory space for the first user mode process in the kernel, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
可选地,该处理单元还用于在该第一用户态进程中为该第一物理内存区间分配相应的第一虚拟内存区间;Optionally, the processing unit is further configured to allocate a corresponding first virtual memory interval to the first physical memory interval in the first user mode process;
该请求单元还用于在该第一用户态进程中向该内核发送内存映射请求,该内存映射请求用于请求该内核建立该第一物理内存区间与该第一虚拟内存区间之间的映射关系。The request unit is also used to send a memory mapping request to the kernel in the first user mode process, and the memory mapping request is used to request the kernel to establish a mapping relationship between the first physical memory interval and the first virtual memory interval .
可选地,该处理单元还用于在该第一用户态进程中为第三用户态进程授权物理内存空间的分配权限。Optionally, the processing unit is further configured to authorize the allocation permission of the physical memory space for the third user-mode process in the first user-mode process.
可选地,该任务请求为文件映射请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,Optionally, the task request is a file mapping request, and the first user mode process is a file system process or a virtual file system process,
该处理单元还用于在该第一用户进程中响应该文件映射请求,将该文件映射请求所请求的文件映射至该第一物理内存区间;以及,该装置还包括:The processing unit is further configured to respond to the file mapping request in the first user process, and map the file requested by the file mapping request to the first physical memory interval; and, the device further includes:
收发单元,用于在该第一用户进程中向该第二用户进程发送该第一物理内存区间。A transceiver unit, configured to send the first physical memory range to the second user process in the first user process.
可选地,该任务请求为文件读/写请求,该第一用户态进程为文件系统进程或虚拟文件系统进程,该处理单元还用于在该第一用户进程中对该第一物理内存区间执行该文件读/写请求所请求的读/写操作。Optionally, the task request is a file read/write request, the first user mode process is a file system process or a virtual file system process, and the processing unit is further configured to perform a process on the first physical memory range in the first user process. Performs the read/write operation requested by the file read/write request.
可选地,该处理单元还用于在该第二用户态进程中为该第一用户态进程授权物理内存空间分配权限。Optionally, the processing unit is further configured to authorize the physical memory space allocation permission for the first user-mode process in the second user-mode process.
图8是本申请实施例提供的通信设备800的结构示意图,该通信设备800可以配置有如图1所示的操作系统。该通信设备800包括总线840,以及与总线840相连的处理器810,该通信设备800还可以包括通信接口820和存储器830。FIG. 8 is a schematic structural diagram of a communication device 800 provided by an embodiment of the present application. The communication device 800 may be configured with an operating system as shown in FIG. 1 . The communication device 800 includes a bus 840 and a processor 810 connected to the bus 840 , and the communication device 800 may also include a communication interface 820 and a memory 830 .
应理解,图8所示的通信设备800能够实现任一方法实施例中的内存分配方法的各个 过程。通信设备800中的各个模块的操作和/或功能,分别为了实现上述方法实施例中的相应流程。具体可参见上述方法实施例中的描述,为避免重复,此处适当省略详细描述。It should be understood that the communication device 800 shown in FIG. 8 can implement each process of the memory allocation method in any method embodiment. The operations and/or functions of the various modules in the communication device 800 are respectively for implementing the corresponding procedures in the foregoing method embodiments. For details, reference may be made to the descriptions in the foregoing method embodiments, and detailed descriptions are appropriately omitted here to avoid repetition.
可选地,该通信设备可以是终端,也可以称为用户设备(user equipment,UE),该通信设备可以是手机、平板电脑或计算机设备等。Optionally, the communication device may be a terminal, and may also be called user equipment (user equipment, UE), and the communication device may be a mobile phone, a tablet computer, or a computer device.
本申请实施例还提供了一种计算机操作系统,包括:计算机程序代码,当该计算机程序代码被调用时,使得计算机操作系统执行上述任一方法实施例中的方法。The embodiment of the present application also provides a computer operating system, including: computer program code, which causes the computer operating system to execute the method in any one of the above method embodiments when the computer program code is invoked.
本申请实施例还提供了一种处理装置,包括处理器和接口;所述处理器用于执行上述任一方法实施例中的方法。The embodiment of the present application also provides a processing device, including a processor and an interface; the processor is configured to execute the method in any one of the above method embodiments.
本申请还提供一种计算机程序产品,该计算机程序产品包括:计算机程序代码,当该计算机程序代码由一个或多个处理器执行时,使得包括该处理器的装置执行上述任一方法实施例中的方法。The present application also provides a computer program product, the computer program product including: computer program code, when the computer program code is executed by one or more processors, the device including the processor executes any one of the above method embodiments Methods.
本申请还提供一种计算机可读存储介质,该计算机可读存储介质存储有程序代码,当该程序代码由一个或多个处理器运行时,使得包括该处理器的装置执行上述任一方法实施例中的方法。The present application also provides a computer-readable storage medium, the computer-readable storage medium stores program code, and when the program code is run by one or more processors, the device including the processor executes any one of the above methods. method in the example.
在本申请实施例中,在无逻辑矛盾的前提下,各实施例之间可以相互引用,例如方法实施例之间的方法和/或术语可以相互引用,例如装置实施例之间的功能和/或术语可以相互引用,例如装置实施例和方法实施例之间的功能和/或术语可以相互引用。In the embodiments of the present application, on the premise that there is no logical contradiction, the various embodiments may refer to each other, for example, the methods and/or terms between the method embodiments may refer to each other, such as the functions and/or terms between the device embodiments Or terms may refer to each other, for example, functions and/or terms between the apparatus embodiment and the method embodiment may refer to each other.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。The above is only a specific implementation of the application, but the scope of protection of the application is not limited thereto. Anyone familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the application. Should be covered within the protection scope of this application. Therefore, the protection scope of the present application should be determined by the protection scope of the claims.

Claims (18)

  1. 一种内存分配方法,其特征在于,包括:A memory allocation method, characterized in that, comprising:
    第一用户态进程接收第二用户态进程的任务请求,所述任务请求用于请求分配内存空间;The first user mode process receives the task request of the second user mode process, and the task request is used to request memory space allocation;
    所述第一用户态进程从第一物理内存空间中为所述第二用户态进程分配第一物理内存区间,其中所述第一物理内存空间是内核授权给所述第一用户态进程的物理内存空间。The first user-mode process allocates a first physical memory range to the second user-mode process from the first physical memory space, wherein the first physical memory space is a physical space authorized by the kernel to the first user-mode process. memory space.
  2. 根据权利要求1所述的方法,其特征在于,在所述第一用户态进程从第一物理内存空间中为所述第二用户态进程分配所述第一物理内存区间之前,所述方法还包括:The method according to claim 1, wherein, before the first user mode process allocates the first physical memory interval for the second user mode process from the first physical memory space, the method further comprises include:
    当所述第一用户态进程被授权的第二物理内存空间中空闲内存空间大小不满足所述任务请求所需的内存空间大小时,所述第一用户态进程向所述内核申请物理内存空间;When the size of the free memory space in the second physical memory space authorized by the first user mode process does not meet the size of the memory space required by the task request, the first user mode process applies to the kernel for physical memory space ;
    所述内核为所述第一用户态进程授权第三物理内存空间,其中,所述第一物理内存空间包括所述第二物理内存空间和所述第三物理内存空间。The kernel authorizes a third physical memory space for the first user mode process, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, characterized in that the method further comprises:
    所述第一用户态进程为所述第一物理内存区间分配相应的第一虚拟内存区间;The first user state process allocates a corresponding first virtual memory interval for the first physical memory interval;
    所述第一用户态进程向所述内核发送内存映射请求,所述内存映射请求用于请求所述内核建立所述第一物理内存区间与所述第一虚拟内存区间之间的映射关系。The first user state process sends a memory mapping request to the kernel, where the memory mapping request is used to request the kernel to establish a mapping relationship between the first physical memory interval and the first virtual memory interval.
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 3, wherein the method further comprises:
    所述第一用户态进程为第三用户态进程授权物理内存空间的分配权限。The first user mode process authorizes the allocation authority of the physical memory space for the third user mode process.
  5. 根据权利要求1或2所述的方法,其特征在于,所述任务请求为文件映射请求,所述第一用户态进程为文件系统进程或虚拟文件系统进程,所述方法还包括:The method according to claim 1 or 2, wherein the task request is a file mapping request, and the first user state process is a file system process or a virtual file system process, and the method further comprises:
    所述第一用户态进程响应所述文件映射请求,将所述文件映射请求所请求的文件映射至所述第一物理内存区间;The first user mode process responds to the file mapping request, and maps the file requested by the file mapping request to the first physical memory interval;
    所述第一用户态进程向所述第二用户进程发送所述第一物理内存区间。The first user mode process sends the first physical memory range to the second user process.
  6. 根据权利要求1或2所述的方法,其特征在于,所述任务请求为文件读/写请求,所述第一用户态进程为文件系统进程或虚拟文件系统进程,所述方法还包括:The method according to claim 1 or 2, wherein the task request is a file read/write request, and the first user mode process is a file system process or a virtual file system process, and the method further comprises:
    所述第一用户态进程对所述第一物理内存区间执行所述文件读/写请求所请求的读/写操作。The first user state process executes the read/write operation requested by the file read/write request on the first physical memory range.
  7. 根据权利要求1、2、5或6所述的方法,其特征在于,所述方法还包括:The method according to claim 1, 2, 5 or 6, wherein the method further comprises:
    所述第二用户态进程为所述第一用户态进程授权物理内存空间分配权限。The second user mode process authorizes the physical memory space allocation permission for the first user mode process.
  8. 一种内存分配装置,其特征在于,包括:A memory allocation device, characterized in that it comprises:
    请求单元,用于在第二用户态进程向第一用户态进程发送任务请求,所述任务请求用于请求分配内存空间;A request unit, configured to send a task request to the first user mode process in the second user mode process, and the task request is used to request memory space allocation;
    处理单元,用于在所述第一用户态进程中为所述任务请求分配第一物理内存区间,所述第一物理内存区间属于第一物理内存空间,所述第一物理内存空间是内核为所述第一用户态进程授权的物理内存空间。A processing unit, configured to allocate a first physical memory interval to the task request in the first user state process, the first physical memory interval belongs to a first physical memory space, and the first physical memory space is a kernel of The physical memory space authorized by the first user mode process.
  9. 根据权利要求8所述的装置,其特征在于,The device according to claim 8, characterized in that
    在所述处理单元在所述第一用户态进程为第二用户态进程的任务请求分配所述第一物理内存区间之前,所述处理单元还用于确定所述第一用户态进程被授权的第二物理内存空间中空闲内存空间大小不满足所述任务请求所需的内存空间大小;Before the processing unit requests allocation of the first physical memory range for the task request of the second user state process by the first user state process, the processing unit is further configured to determine the authorization of the first user state process The size of the free memory space in the second physical memory space does not meet the size of the memory space required by the task request;
    所述请求单元还用于在所述第一用户态进程中向所述内核申请物理内存空间;The request unit is further configured to apply for physical memory space from the kernel in the first user state process;
    所述处理单元还用于在所述内核为所述第一用户态进程中授权第三物理内存空间,其中,所述第一物理内存空间包括所述第二物理内存空间和所述第三物理内存空间。The processing unit is further configured to authorize a third physical memory space for the first user mode process in the kernel, wherein the first physical memory space includes the second physical memory space and the third physical memory space memory space.
  10. 根据权利要求8或9所述的装置,其特征在于,A device according to claim 8 or 9, characterized in that
    所述处理单元还用于在所述第一用户态进程中为所述第一物理内存区间分配相应的第一虚拟内存区间;The processing unit is further configured to allocate a corresponding first virtual memory interval to the first physical memory interval in the first user mode process;
    所述请求单元还用于在所述第一用户态进程中向所述内核发送内存映射请求,所述内存映射请求用于请求所述内核建立所述第一物理内存区间与所述第一虚拟内存区间之间的映射关系。The request unit is further configured to send a memory mapping request to the kernel in the first user state process, and the memory mapping request is used to request the kernel to establish the first physical memory interval and the first virtual The mapping relationship between memory ranges.
  11. 根据权利要求8至10中任一项所述的装置,其特征在于,所述处理单元还用于在所述第一用户态进程中为第三用户态进程授权物理内存空间的分配权限。The device according to any one of claims 8 to 10, wherein the processing unit is further configured to authorize, in the first user mode process, an allocation authority of physical memory space for a third user mode process.
  12. 根据权利要求8或9所述的装置,其特征在于,所述任务请求为文件映射请求,所述第一用户态进程为文件系统进程或虚拟文件系统进程,The device according to claim 8 or 9, wherein the task request is a file mapping request, and the first user state process is a file system process or a virtual file system process,
    所述处理单元还用于在所述第一用户进程中响应所述文件映射请求,将所述文件映射请求所请求的文件映射至所述第一物理内存区间;以及,所述装置还包括:The processing unit is further configured to respond to the file mapping request in the first user process, and map the file requested by the file mapping request to the first physical memory interval; and, the device further includes:
    收发单元,用于在所述第一用户进程中向所述第二用户进程发送所述第一物理内存区间。A transceiver unit, configured to send the first physical memory range to the second user process in the first user process.
  13. 根据权利要求8或9所述的装置,其特征在于,所述任务请求为文件读/写请求,所述第一用户态进程为文件系统进程或虚拟文件系统进程,The device according to claim 8 or 9, wherein the task request is a file read/write request, and the first user state process is a file system process or a virtual file system process,
    所述处理单元还用于在所述第一用户进程中对所述第一物理内存区间执行所述文件读/写请求所请求的读/写操作。The processing unit is further configured to perform the read/write operation requested by the file read/write request on the first physical memory range in the first user process.
  14. 根据权利要求8、9、12或13所述的装置,其特征在于,所述处理单元还用于在所述第二用户态进程中为所述第一用户态进程授权物理内存空间分配权限。The device according to claim 8, 9, 12 or 13, wherein the processing unit is further configured to authorize the physical memory space allocation permission for the first user state process in the second user state process.
  15. 一种内存分配装置,其特征在于,包括至少一个处理器,与存储器耦合;A memory allocation device, characterized in that it includes at least one processor coupled to the memory;
    所述存储器用于存储程序或指令;The memory is used to store programs or instructions;
    所述至少一个处理器用于执行所述程序或指令,以使所述装置实现如权利要求1至7中任一项所述的方法。The at least one processor is configured to execute the program or instructions, so that the device implements the method according to any one of claims 1-7.
  16. 一种计算机可读存储介质,包括计算机程序,当其由一个或多个处理器执行时,使得包括所述处理器的装置执行如权利要求1至7中任一项所述的方法。A computer-readable storage medium comprising a computer program which, when executed by one or more processors, causes an apparatus comprising said processors to perform the method as claimed in any one of claims 1 to 7.
  17. 一种计算机程序产品,其特征在于,包括所述计算机程序产品包括计算机指令,所述计算机指令指示计算设备执行权利要求1至7任一项所述的方法。A computer program product, characterized in that the computer program product includes computer instructions, and the computer instructions instruct a computing device to perform the method according to any one of claims 1 to 7.
  18. 一种芯片,其特征在于,包括至少一个处理器和通信接口;A chip, characterized in that it includes at least one processor and a communication interface;
    所述通信接口用于接收输入所述芯片的信号或从所述芯片输出的信号,所述处理器与所述通信接口通信且通过逻辑电路或执行代码指令用于实现如权利要求1至7中任一项所述的方法。The communication interface is used to receive a signal input to the chip or a signal output from the chip, and the processor communicates with the communication interface and executes a code instruction through a logic circuit or to implement the process described in claims 1 to 7. any one of the methods described.
PCT/CN2022/091040 2021-05-14 2022-05-05 Memory allocation method, apparatus and system WO2022237624A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110527267.6A CN115344507A (en) 2021-05-14 2021-05-14 Memory allocation method, device and system
CN202110527267.6 2021-05-14

Publications (1)

Publication Number Publication Date
WO2022237624A1 true WO2022237624A1 (en) 2022-11-17

Family

ID=83977947

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/091040 WO2022237624A1 (en) 2021-05-14 2022-05-05 Memory allocation method, apparatus and system

Country Status (2)

Country Link
CN (1) CN115344507A (en)
WO (1) WO2022237624A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104050101A (en) * 2014-05-29 2014-09-17 汉柏科技有限公司 Method for realizing user-state receiving and transmission of messages for ARM (Advanced RISC Machine) CPU (Central Processing Unit)
CN104796337A (en) * 2015-04-10 2015-07-22 京信通信系统(广州)有限公司 Method and device for forwarding message
CN104794069A (en) * 2015-04-01 2015-07-22 北京创毅视讯科技有限公司 User state allocation method and system for cache in CPU
US20160188251A1 (en) * 2014-07-15 2016-06-30 Nvidia Corporation Techniques for Creating a Notion of Privileged Data Access in a Unified Virtual Memory System
CN112711546A (en) * 2019-10-24 2021-04-27 华为技术有限公司 Memory configuration method and device and storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102819497B (en) * 2012-05-31 2015-09-30 华为技术有限公司 A kind of memory allocation method, Apparatus and system
US10140462B2 (en) * 2015-05-21 2018-11-27 Qualcomm Innovation Center, Inc. Stackable file system with user space policy management
CN110502335A (en) * 2019-06-12 2019-11-26 成都虚谷伟业科技有限公司 Distributed data base multilevel memory managing device
CN110659248B (en) * 2019-09-05 2022-11-11 上海交通大学 User mode file system design method and system based on nonvolatile memory

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104050101A (en) * 2014-05-29 2014-09-17 汉柏科技有限公司 Method for realizing user-state receiving and transmission of messages for ARM (Advanced RISC Machine) CPU (Central Processing Unit)
US20160188251A1 (en) * 2014-07-15 2016-06-30 Nvidia Corporation Techniques for Creating a Notion of Privileged Data Access in a Unified Virtual Memory System
CN104794069A (en) * 2015-04-01 2015-07-22 北京创毅视讯科技有限公司 User state allocation method and system for cache in CPU
CN104796337A (en) * 2015-04-10 2015-07-22 京信通信系统(广州)有限公司 Method and device for forwarding message
CN112711546A (en) * 2019-10-24 2021-04-27 华为技术有限公司 Memory configuration method and device and storage medium

Also Published As

Publication number Publication date
CN115344507A (en) 2022-11-15

Similar Documents

Publication Publication Date Title
US11392506B2 (en) Apparatus and method for secure memory access using trust domains
US11500689B2 (en) Communication method and apparatus
US10228737B2 (en) Affinity-aware parallel zeroing of memory for initialization of large pages in non-uniform memory access (NUMA) servers
US10255088B2 (en) Modification of write-protected memory using code patching
US20060265561A1 (en) System and method for out of user space block mode I/O directly between an application instance and an I/O adapter
CA3142633A1 (en) Method and apparatus for inter-process communication, and computer device
US20060265521A1 (en) System and method for creation/deletion of linear block address table entries for direct I/O
WO2012058917A1 (en) Method, system and physical host for virtual machine (vm) storage space management
CN111290827A (en) Data processing method and device and server
WO2015085826A1 (en) Method and apparatus for accessing shared resource
CN110609708B (en) Method, apparatus and computer readable medium for data processing
US20230168953A1 (en) Inter-process communication method and apparatus
WO2023016414A1 (en) Credential rotation method, computing device, and storage medium
US9684525B2 (en) Apparatus for configuring operating system and method therefor
WO2022237624A1 (en) Memory allocation method, apparatus and system
EP4293523A1 (en) Technologies for memory tagging
US20130246729A1 (en) Method for Managing a Memory of a Computer System, Memory Management Unit and Computer System
CN111666579B (en) Computer device, access control method thereof and computer readable medium
CN116028455A (en) Data processing method and device, storage medium and electronic equipment
WO2022222977A1 (en) Method and apparatus for managing memory of physical server for running cloud service instances
CN113791898B (en) TrustZone-based trusted microkernel operating system
WO2022199560A1 (en) Memory management method and device
US20240113875A1 (en) Method and apparatus for storing keys
CN117539627A (en) Dynamic allocation method and register of NVMe queue resources based on SR-IOV protocol
CN115756742A (en) Performance optimization design method, system, medium and device for direct I/O virtualization

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22806592

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE