Memory allocation method, device and system
Through two-level physical memory space management, the kernel is responsible for part of the work, and the user-mode process allocates and manages authorized physical memory space, which solves the memory management complexity and security problems in the existing technology, and improves memory allocation efficiency and system security.
Patent Information
- Application Number
- CN202110527267.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-14
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-05-14
AI Technical Summary
The memory management method of existing operating systems causes frequent inter-process communication to increase overhead when implemented in user mode, while the complexity of data structures and algorithms increases the difficulty of security authentication and attack risks when implemented in kernel mode, and is difficult to optimize.
A two-level physical memory space management method is adopted. The kernel is responsible for part of the work. User-mode processes reduce communication between user-mode processes and the workload of the kernel through authorized physical memory space allocation and virtual memory space management, and improve memory allocation efficiency.
It reduces system energy consumption and memory allocation time overhead, improves memory allocation efficiency, reduces inter-process communication overhead, and improves system security.
Smart Images

Figure CN115344507B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a memory allocation method, device and system. Background Art
[0002] When running an operating system, the processor can be divided into two operating modes according to its functions: kernel mode and user mode. When the processor is in kernel mode, it mainly executes some key tasks of the operating system and controls the hardware resources of the computer. User mode has lower execution permissions than kernel mode. When the processor is in user mode, it mainly executes application-related processes. By dividing the processor into user mode and kernel mode, it can achieve isolation of system key data and application data, thereby improving security and reliability.
[0003] Memory management is an important function of the operating system, which is mainly used for the allocation and use of memory resources, such as allocating memory space required for the process to run. Memory management can be implemented when the processor is in kernel state or in user state. When memory management is implemented in user state, the complexity of kernel state can be reduced, but the problem is that the memory required by the system service process also needs to be applied to the user state memory management process through inter-process communication (IPC). When the required memory is large, frequent IPC will bring large overhead. When memory management is implemented in kernel state, due to the complex data structure and algorithm used by memory management, it will make the formal verification of the kernel and pass the high-level security certification very difficult, and increase the probability of being attacked. The current memory management method of the operating system needs to be optimized. Summary of the invention
[0004] The present application provides a memory allocation method, device and system to improve the working efficiency of memory allocation.
[0005] In a first aspect, a memory allocation method is provided, the method comprising:
[0006] A first user state process receives a task request from a second user state process, where the task request is used to request allocation of memory space; the first user state process allocates a first physical memory interval to the second user state process from a first physical memory space, where the first physical memory space is the physical memory space authorized by the kernel to the first user state process.
[0007] According to the above scheme, the kernel can perform the first-level memory space management, that is, authorizing part of the physical memory space for the first user-state process, so that the user-state process can allocate the authorized physical memory space according to demand, that is, the second-level memory space management. By adopting a two-level physical memory space management method, while the kernel is responsible for completing a small amount of work, the frequent communication between user-state processes is reduced, which can reduce energy consumption and reduce the time overhead of memory allocation, thereby improving the efficiency of memory allocation.
[0008] In combination with the first aspect, in certain implementations of the first aspect, before allocating the first physical memory interval to the second user state process through the first user state process, the method also includes: when the size of the free memory space in the second physical memory space authorized by the first user state process does not meet the memory space size required by the task request, the first user state process applies for physical memory space from the kernel; the kernel authorizes the third physical memory space to the first user state process, wherein the first physical memory space includes the second physical memory space and the third physical memory space.
[0009] According to the above scheme, when the physical memory space authorized by the first user state process does not meet the demand, the first user state process can further apply for physical memory space from the kernel to obtain sufficient authorized physical memory space, thereby avoiding the situation where the second user state process fails to request memory due to insufficient physical memory space authorized by the first user state process, thereby improving the flexibility of physical memory space management.
[0010] In combination with the first aspect, in certain implementations of the first aspect, the method also includes: allocating a corresponding first virtual memory interval to the first physical memory interval in the first user state process; and sending a memory mapping request to the kernel in the first user state process, wherein the memory mapping request is used to request establishment of a mapping relationship between the first physical memory interval and the first virtual memory interval.
[0011] According to the above solution, after allocating the first physical memory interval, the first user state process allocates the corresponding first virtual memory interval and requests the kernel to perform memory mapping to complete the mapping between the first physical memory interval and the first virtual memory interval.
[0012] In combination with the first aspect, in some implementations of the first aspect, the method further includes: the first user state process authorizing physical memory space allocation authority to the third user state process.
[0013] 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 permission, it can request physical memory space from the kernel, so that the third user state process can allocate the authorized physical memory space on demand according to demand, which can avoid the third user state process requesting physical memory through inter-process communication, reduce the overhead caused by inter-process communication, and improve the efficiency of memory allocation.
[0014] Exemplarily, the first user state process may be a user state main memory management process, and the third user state process may be a related process providing system services.
[0015] In combination with the first aspect, in certain 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 responds to the file mapping request, maps the file requested by the file mapping request to the first physical memory interval; and the first user process sends the first physical memory interval to the second user process.
[0016] 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 state process of the first physical memory interval allocated by the first user state process for the file mapping task. This allows the first user state process to allocate a physical memory interval for the file mapping task and complete the file mapping, avoiding the request for physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
[0017] Exemplarily, the first user state process may be a user state virtual file system (VFS) process, and the second user state 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 a file mapping request, and then allocates a corresponding virtual address interval to the first physical memory interval, so as to request the kernel to complete the mapping between the first physical memory interval and the virtual address interval.
[0018] In combination with the first aspect, in certain 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: executing the read / write operation requested by the file read / write request on the first physical memory interval in the first user process.
[0019] According to the above scheme, after the first user process receives the task request for file reading / writing, it allocates the first physical memory interval for the file reading / writing task and performs the reading / writing operation on the first physical memory interval. This allows the first user state process to allocate the physical memory interval for the file reading / writing task and complete the file reading / writing, avoiding the request for physical memory through inter-process communication, reducing the overhead caused by inter-process communication, and improving the efficiency of memory allocation.
[0020] In combination with the first aspect, in some implementations of the first aspect, the method further includes: authorizing physical memory space allocation permissions for the first user state process in the second user state process.
[0021] 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 user state processes to request physical memory through inter-process communication, reduce the overhead caused by inter-process communication, and improve the efficiency of memory allocation.
[0022] In a second aspect, a memory allocation device is provided, including: a request unit, used to send a task request to a first user state process in a second user state process; a processing unit, used to allocate a first physical memory interval for 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 the physical memory space authorized by the kernel for the first user state process.
[0023] In combination with the second aspect, in certain implementations of the second aspect, before the processing unit allocates the first physical memory interval to the task request of the second user state process in the first user state process, the processing unit is also used to determine that the size of the free memory space in the physical memory space authorized for the first user state process 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; and the processing unit is also used to authorize the first physical memory space for the first user state process in the kernel.
[0024] In combination with the second aspect, in certain implementations of the second aspect, the processing unit is also used to allocate a first virtual memory interval for the task request in the first user state process; the request unit is also used to send a memory mapping request to the kernel in the first user state process, and the memory mapping request is used to request to establish a mapping relationship between the first physical memory interval and the first virtual memory interval.
[0025] In combination with the second aspect, in some implementations of the second aspect, the processing unit is further used to authorize physical memory space allocation permissions for a third user state process in the first user state process.
[0026] In combination with 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 also used 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 also includes: a transceiver unit, used to send the first physical memory interval to the second user process in the first user process.
[0027] In combination with the second aspect, in certain implementations of the second aspect, the task request is a file read and write request, the first user state process is a file system process or a virtual file system process, and the processing unit is also used to perform the read and write operations requested by the file read and write request on the first physical memory interval in the first user process.
[0028] In combination with the second aspect, in some implementations of the second aspect, the processing unit is further used to authorize physical memory space allocation permissions for the first user state process in the second user state process.
[0029] In a third aspect, a communication device is provided, including a processor. The processor can implement the method in the first aspect and any possible implementation manner of the first aspect.
[0030] 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 to implement the method in the above-mentioned first aspect and any possible implementation manner of the first aspect.
[0031] Optionally, the communication device further includes a communication interface, and the processor is coupled to the communication interface.
[0032] In the embodiments 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.
[0033] In a fourth aspect, an operating system is provided, including a computer program and a computer program code, which, when called, enables the computer operating system to execute the method in the first aspect and any possible implementation of the first aspect.
[0034] In a fifth aspect, a processor is provided, comprising: an input circuit, an output circuit, and a processing circuit. The processing circuit is used 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 of the first aspect.
[0035] In the specific implementation process, the 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 trigger, and various logic circuits. The input signal received by the input circuit can be, for example, but not limited to, received and input by a receiver, and the signal output by the output circuit can be, for example, but not limited to, output to a transmitter and transmitted by the transmitter, and the input circuit and the output circuit can be the same circuit, which is used as an input circuit and an output circuit at different times. The embodiments of the present application do not limit the specific implementation methods of the processor and various circuits.
[0036] In a sixth aspect, a computer program product is provided, which includes: a computer program (also referred to as code, or instruction), which, when executed, enables a computer to execute the method in the above-mentioned first aspect and any possible implementation manner of the first aspect.
[0037] In the seventh aspect, a computer-readable medium is provided, which stores a computer program (also referred to as code, or instruction) which, when executed on a computer, enables the computer to execute the method in the above-mentioned first aspect and any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of an operating system architecture applicable to the present application;
[0039] Figure 2 is a schematic flow chart of a memory allocation method provided in an embodiment of the present application;
[0040] Figure 3 is a schematic flow chart of a first embodiment of a memory allocation method provided by the present application;
[0041] Figure 4 is a schematic flow chart of Embodiment 2 of the memory allocation method provided by the present application;
[0042] Figure 5 is a schematic flow chart of Embodiment 3 of the memory allocation method provided by the present application;
[0043] Figure 6 is a schematic flow chart of a fourth embodiment of the memory allocation method provided by the present application;
[0044] Figure 7 is a schematic block diagram of an example of a communication device provided by the present application;
[0045] Figure 8 It is a schematic structural diagram of an example of a communication device provided in the present application. DETAILED DESCRIPTION
[0046] The technical solution in this application will be described below in conjunction with the accompanying drawings.
[0047] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution 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 are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0048] The terms "first", "second", etc. in the specification, 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 order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0049] First, the relevant technologies and terms involved in this application are introduced.
[0050] 1. Microkernel architecture
[0051] In the microkernel architecture, the functions of the processor running the operating system are divided into kernel state (also referred to as kernel in some contexts) and user state. Kernel state is only responsible for some key business functions, and most operating system functions are placed in user state. This ensures the "miniaturization" of kernel state. At the same time, different functional modules are managed separately and run in different processes. Problems in one module will not affect other modules, achieving better security and reliability. Typical microkernel architecture operating systems include SeL4, QNX, MINIX, Fuchsia, etc.
[0052] 2. Macro kernel architecture
[0053] In the macro kernel architecture, all functions of the processor running the operating system run in kernel state, realizing a "grand" kernel. Because all modules run in the same address space and can directly access each other, the macro kernel architecture can achieve very efficient performance, but there are also security and reliability issues that a problem with a module can cause the entire kernel to crash. A typical macro kernel architecture operating system is Linux.
[0054] It should be noted that the solution provided in this application can be applicable to operating systems with a microkernel architecture as well as operating systems with a macrokernel architecture, and this application does not limit this.
[0055] 3. System service process
[0056] System service processes can be referred to as system services or service processes for short. System service processes are processes that execute specified system functions. They usually provide users with some system function services locally and through the network. For example, system service processes may include but are not limited to file system processes (file system, FS), client / server processes, Web server processes, etc.
[0057] System service processes generally run in the background and no program windows or dialog boxes appear to user application processes. The started system service processes can be found in the Task Manager.
[0058] Figure 1 A schematic diagram of an operating system architecture suitable for this application.
[0059] like Figure 1 As shown, the operating system can be divided into kernel mode and user mode according to functional permissions, or in other words, when the processing device runs the operating system, the working mode of the processing device may include kernel mode or user mode. Among them, the user mode includes at least one user mode process, such as the user mode may include a system manager (system manager, SYSMGR) process, which is responsible for starting and managing system components and system services, and providing corresponding system services for user application (user application, UAPP) requests. The user mode may also include a virtual file system process (virtual file system, VFS), which is responsible for managing and storing file information. The user mode may also include other system service processes, but the present application is not limited to this. The kernel mode includes at least one kernel mode process, which is responsible for key business functions. It should be understood that Figure 1 This is only a schematic diagram of a system architecture applicable to the operating system of the present application, but the present application is not limited to this, and the solution of the present application can also be applied to operating systems of other system architectures.
[0060] Currently, there are two main ways to implement memory management when the processor runs an operating system: in user mode and in kernel mode.
[0061] For example, the memory management in the embedded real-time operating system (Quick Unix, QNX) is completely implemented in user mode, and the kernel is responsible for filling the page table when the address space is mapped. Taking reading a file as an example, the specific process steps are as follows:
[0062] Step 1: UAPP sends a file read request to the FS process (hereinafter referred to as FS);
[0063] Step 2: FS determines whether the file has been read. If it has been read, it will end and return, otherwise it will continue;
[0064] Step 3: FS requests content from the memory management process as cache;
[0065] Step 4: FS reads the file and writes it to cache;
[0066] Step 5: FS copies the contents in the cache to the address specified by UAPP;
[0067] Step 6: Return to step 2.
[0068] 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 file to be read is large, cache allocation in pages will be very frequent. Since IPC takes a long time, frequent IPC will affect the performance of file reading and writing.
[0069] For another example, the memory management in the Fuchsia operating system is completely implemented in kernel state. The memory allocation operations of the user-state system service process can be directly applied to the kernel through system calls. Although this can improve performance, the memory management module in kernel state 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.
[0070] In view of the above problems existing in the memory management method in the current operating system, the present 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 the user-mode process can perform the second-level memory space management, and allocate the authorized physical memory space according to the task requirements, which can avoid the user-mode process from requesting physical memory space from other user-mode processes through inter-process communication (IPC) after receiving the task request, 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, the frequent communication between user-mode processes is reduced, which can reduce the system energy consumption and overhead, and improve the work efficiency of memory allocation.
[0071] The memory allocation method provided by the present application is described below with reference to the accompanying drawings.
[0072] Figure 2: is a schematic flow chart of the memory allocation method provided by the present application. The memory allocation method can be executed by the operating system, or the memory allocation method can be executed by the processing device when running the operating system, and the operating system includes multiple user state process programs and kernel programs (which can be called kernels). The memory allocation method of the operating system is used as an example for explanation below, but the present application is not limited to this.
[0073] S210, the kernel authorizes a first physical memory space for a first user mode process.
[0074] The processing device runs an operating system, and the kernel of the operating system is used to manage the physical memory space of the operating system. The kernel can be used to authorize a portion of the physical memory space of the system to a first user state process, such as the kernel authorizing a first physical memory space to the first user state process. The first user state process can allocate the authorized first physical memory space.
[0075] As an example and not limitation, the first user mode process is a system service process.
[0076] It should be noted that the kernel operations or user-mode process operations involved in this application (such as execution, authorization, sending, receiving, determination, management, etc.) can be understood as the operations performed by the processing device when running the process of the operating system, or the operations performed when the operating system runs the process.
[0077] In one implementation, after the operating system creates the first user state process, the first user state process applies to the kernel for physical memory space. The kernel responds to the application of the first user state process and allocates the first physical memory space to the first user process.
[0078] In another implementation, when the physical memory space authorized to the first user state process is insufficient, such as when the size of the free physical memory (free physical memory may also be referred to as physical memory to be allocated or physical memory to be used) in the physical memory space authorized to the first user state process does not meet the size of the physical memory requested by other processes, the first user state process may apply to the kernel for physical memory space. The kernel responds to the application of the first user state process and allocates the first physical memory space to the first user process.
[0079] S220: The first user state process allocates a first physical memory interval in a first physical memory space to the second user state process.
[0080] The first user state process receives a task request from the second user state process, for example, the task request may be a file mapping request, a file read / write request, etc. from an application process. The first user state process may determine the size of the memory space required for the task request, and determine a first physical memory address interval in a first physical memory space authorized by the first user state process, and then allocate the first memory address interval to the task request.
[0081] Specifically, the first user state process determines whether the size of the physical memory space to be allocated in the physical memory space authorized by the first user state process meets the size of the memory space required by the task request based on the size of the memory space required by the task request. If it meets, a physical memory address interval is allocated for the task request in the physical memory space to be allocated; if it does not meet, the first user state process applies for physical memory space from the kernel, the kernel authorizes part of the physical memory space for the first user process, and the first user state process allocates a first physical memory interval for the task request in the authorized physical memory space.
[0082] Optionally, the first user state process may be a main service process for memory management in the user state process, or may be referred to as a main memory management process, and the main service process may authorize physical memory space allocation authority for other system service processes.
[0083] For example, other system service processes may include file system processes. 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 to the kernel for physical memory space. After the kernel authorizes part of the physical memory space for the file system process, the file system process can allocate physical memory intervals in the part of the physical memory space for tasks of other processes. However, the present application is not limited thereto.
[0084] Optionally, after the kernel obtains the request for physical memory space from the user-mode process, it determines whether the size of the physical memory space to be allocated in the physical memory space managed by the kernel meets the size of the memory space required by the request based on the size of the physical memory space required by the request. If it meets the size, part of the physical memory space is authorized for the user-mode process. If it does not meet the size, the kernel can initiate physical memory space recovery, such as initiating a physical memory space request to the user-mode process with the permission to allocate physical memory space, thereby recovering part of the physical memory space and then authorizing the physical memory space for the user-mode process.
[0085] According to the above scheme of the present application, a two-level physical memory space management method is adopted, which can reduce the frequent communication between user-mode processes while the kernel is responsible for completing a small amount of work, thereby reducing system energy consumption and overhead.
[0086] Figure 3It is a flowchart of Example 1 of the memory allocation method provided by the present application. Figure 3 A schematic flowchart of memory allocation using the memory allocation method provided in the present application during the initialization phase of operating system startup is shown.
[0087] The process of the initialization phase of the processing device starting the operating system includes but is not limited to the following steps:
[0088] 1. Start the kernel;
[0089] 2. During the kernel startup process, the boot allocator is first created and used to meet 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 bootallocator ends;
[0090] 3. Initialize metadata for the remaining physical memory space during kernel startup;
[0091] 4. After the initialization of the kernel startup is completed, a user-mode memory management main service process is created. For example, the memory management main service process may be a system manager SYSMGR process;
[0092] 5. The main service process applies to the kernel for the physical memory space of the main service process;
[0093] For example, the main service process (i.e., an example of the first user-mode process) may include a first physical memory management algorithm (PHYMGR), the kernel may include a global PHYMGR (globalPHYMGR), the main service process applies for physical memory space from the kernel through the physical memory management algorithm, the kernel responds to the application, and authorizes part of the physical memory space (i.e., an example of the first physical memory space) to the main service process through the global PHYMGR.
[0094] 6. The main service process completes the initialization of metadata for the physical memory space authorized by the main service process;
[0095] 7. After the main service process is initialized, create an initialization (INIT) process;
[0096] 8. Create other system service processes in the INIT process, for example, create a file system process, etc.;
[0097] 9. Optionally, the main service process can authorize one or more system service processes to manage physical memory space.
[0098] For example, the virtual file system (VFS) process has a higher allocation requirement for physical memory, and the main service process can authorize the VFS process to have physical memory management permissions, but the present application is not limited to this. The main service process can also authorize other processes that have a higher allocation requirement for physical memory to have physical memory management permissions.
[0099] 10. The system service process (ie, another example of the first user mode process) that is authorized with the physical memory management permission in step 9 applies to the kernel for physical memory space.
[0100] 11. The system service process authorized with physical management rights completes the initialization of metadata of the authorized physical memory space (ie, another example of the first physical memory space). The system service authorized with physical management rights has allocation rights to the authorized physical memory space.
[0101] 12. After executing other remaining operating system startup processes, the operating system startup is completed.
[0102] During the initialization phase of the operating system, the kernel authorizes part of the physical memory space for the main service process, so that during the operating system operation phase, the main service process can allocate the authorized physical memory space according to demand. Through the polarized management of physical memory space, the kernel can be miniaturized, the kernel workload can be reduced, and the system security can be improved.
[0103] Figure 4 It is a schematic flowchart of Example 2 of the memory allocation method provided in this application. Figure 4 The schematic flow chart shows the schematic flow of memory allocation in response to the anonymous memory mapping request of UAPP after the processing device obtains the anonymous memory mapping request of UAPP when running the main service process. Figure 3 As shown, in the initialization phase, the main service process is authorized with physical memory space management rights, and the kernel authorizes the VFS process to have allocation rights to some physical memory space, but the present application is not limited to this.
[0104] The process of the processing device responding to the anonymous memory mapping request of the UAPP includes but is not limited to the following steps:
[0105] 1. Get the anonymous memory mapping (UAPP anon map with populate) request of UAPP in the main service process;
[0106] Anonymous memory mapping means that the mapping area is not associated with a file.
[0107] 2. Allocate a 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;
[0108] The virtual memory interval may be a virtual memory address interval, or referred to as a virtual memory address segment, and the physical memory interval may be a physical memory address interval, or referred to as a physical memory address segment.
[0109] 3. Determine whether the physical memory space to be allocated in the physical memory space authorized by the main service process is sufficient;
[0110] The processing device first determines whether the physical memory space to be allocated in the physical memory space authorized by the main service process can meet the memory space size required by the memory mapping request. If not, it applies for physical memory space from the kernel in step 4; if it is satisfied, it executes step 8 to allocate a physical memory interval for the anonymous memory mapping request in the physical memory space authorized by the main service process;
[0111] 4. Apply for physical memory space from the kernel in the main service process;
[0112] 5. The kernel determines whether there is enough physical memory space to be allocated in the global physical memory space;
[0113] After the kernel obtains the application of the main service process, the processing device determines whether the size of the physical memory space to be allocated in the global physical memory space meets the size of the physical memory space applied by the main service process. If it meets, the kernel authorizes part of the physical memory space for the main service process and returns to step 3; if it does not meet, memory recycling is initiated in step 6.
[0114] 6. The kernel initiates a memory reclaim request to reclaim part of the physical memory space;
[0115] 7. If 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;
[0116] 8. In the main service process, a physical memory interval in the physical memory space authorized by the main service process is allocated to the anonymous memory mapping task;
[0117] 9. 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 anonymous memory mapping request to the kernel to initiate the mapping request;
[0118] 10. The processing device completes the remaining process.
[0119] Figure 5 It is a schematic flowchart of Example 3 of the memory allocation method provided in this application. Figure 5The schematic flow chart shows a memory allocation process executed by the processing device in response to a file mapping request from UAPP after the processing device obtains the file mapping request from UAPP when running the main service process. Figure 3 As shown, in the initialization phase, the main service process is authorized with physical memory space management rights, and the kernel authorizes the VFS process to have allocation rights to some physical memory space, but the present application is not limited to this.
[0120] The process of the processing device responding to the file mapping request of the UAPP includes but is not limited to the following steps:
[0121] 1. Get the UAPP file mapping (UAPP file map with populate) request in the main service process;
[0122] For example, the file mapping request may be an mmap file mapping function carrying a populated flag (with populated flag), but the present application is not limited thereto.
[0123] 2. Allocate a corresponding virtual memory interval for the file mapping task (or for the process that initiates the file mapping task) in the main service process;
[0124] 3. The main service process requests the VFS process for the page cache corresponding to the UAPP, and requests the VFS process to provide the physical memory (interval) of the file page corresponding to the UAPP;
[0125] 4. Determine whether the VFS process has a page cache corresponding to the UAPP. If not, execute step 5; if yes, execute step 11 to return the page cache corresponding to the UAPP to the main service process;
[0126] 5. Determine whether the physical memory space authorized by VFS is sufficient;
[0127] The processing device first determines whether the physical memory space to be allocated in the physical memory space authorized by the VFS process can meet the memory space size required by the file mapping request. If not, it applies for physical memory space from the kernel in step 6; if it is satisfied, it executes step 10 to allocate a physical memory interval as a page cache for the file mapping task in the physical memory space authorized by the VFS process.
[0128] 6. Apply for physical memory space from the kernel in the VFS process;
[0129] 7. The kernel determines whether there is enough physical memory space to be allocated in the global physical memory space;
[0130] After the kernel obtains the application of the VFS process, it determines whether the size of the physical memory space to be allocated in the global physical memory space meets the size of the physical memory space applied by the VFS process. If not, memory recycling is initiated in step 8; if it is satisfied, the kernel authorizes part of the physical memory space for the VFS process in step 9 and returns to step 5.
[0131] 8. The kernel initiates a memory reclaim request to reclaim part of the physical memory space;
[0132] 9. If 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;
[0133] 10. Allocate the physical memory interval of the VFS process as a page cache for the file mapping task in the physical memory space authorized by the VFS process;
[0134] Optionally, in the VFS process, a physical memory interval is allocated to the file mapping task from the authorized physical memory space through a physical memory management algorithm (phymgr) corresponding to the VFS process.
[0135] 11. The VFS process writes the file content to the page cache;
[0136] 12. The VFS process returns the page cache corresponding to the UAPP to the VFS process;
[0137] 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 the mapping request;
[0138] 14. The processing device completes the remaining process.
[0139] It should be understood that according to the above processing flow, this application has clear permission management and operation boundaries for the physical memory allocation and use of system services (such as VFS processes, etc.). The physical memory managed by the system service is only used to meet the needs of its own functions and logical implementation (such as file mapping tasks, etc.), and cannot be used to meet the physical memory allocation of the application. The physical memory allocation of the application is still the responsibility of the main memory management process. This can reduce the frequent interactions between processes and does not increase the overall complexity of memory management. The access control of physical memory is still uniformly handled in the main memory management process.
[0140] In the current microkernel operating system, the file read and write performance has a significant disadvantage relative to the macrokernel operating system. After using the memory allocation method provided by this application, the file read and write performance can be equal to or exceed the typical macrokernel operating system Linux. In the test experiment, the memory allocation method provided by this application was compared with the reading and writing capabilities of the Linux operating system in the prior art. For files of the same size, when the same number of bytes are read each time, whether it is a sequential read method or a random read method, the memory allocation method provided by this application can improve the processing efficiency by more than 35% compared to the Linux operating system. For files of the same size, when the same number of bytes are written each time, whether it is a sequential write method or a random write method, the memory allocation method provided by this application can improve the processing efficiency by more than 15% compared to the Linux operating system. Especially for writing a large amount of bytes per second, the processing efficiency of the memory allocation method provided by this application is more significantly improved, for example, when writing 2 megabytes per second, the processing efficiency can be improved by 60%.
[0141] Figure 6 It is a schematic flowchart of Example 4 of the memory allocation method provided in this application. Figure 6 A schematic flow chart showing a memory allocation process executed by a processing device in response to a file mapping request after obtaining a file read / write request from a UAPP when running a VFS process, wherein the VFS process may be, for example, Figure 3 As shown, in the initialization phase, the main service process is authorized with physical memory space management rights, and the kernel authorizes the VFS process to have allocation rights to some physical memory space, but the present application is not limited to this.
[0142] The process of the processing device responding to the file read and write request of the UAPP includes but is not limited to the following steps:
[0143] 1. Obtain the file read and write request of UAPP in the VFS process;
[0144] The file read and write request of UAPP is directly sent to the VFS process. In the VFS process, the file read and write request is responded to according to the file indicator fd, the corresponding read function or write function is called to find the corresponding file location.
[0145] 2. Determine whether there is a page cache corresponding to the file; if not, the processing device executes step 3; if so, execute step 9 to perform read and write operations corresponding to the UAPP request on the page cache;
[0146] 3. Determine whether the physical memory space authorized by the VFS process is sufficient;
[0147] The processing device determines whether the size of the physical memory space to be allocated in the authorized physical memory space meets the size of the page cache required by the read / write task. If not, step 4 is executed to apply to the kernel for authorization of part of the physical memory space of the VFS process; if satisfied, step 8 is executed to allocate a physical memory interval for the read / write task as the page cache of the read / write task.
[0148] 4. The VFS process applies for physical memory space from the kernel;
[0149] 5. The kernel determines whether the global physical memory space is sufficient;
[0150] The kernel determines 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 sufficient, the kernel executes step 7 to authorize part of the physical memory space for the VFS process. If it is insufficient, the kernel executes step 6 to initiate a memory space recovery request.
[0151] 6. The kernel initiates a memory space recovery request to recover part of the physical memory space and then authorizes part of the physical memory space to the VFS process;
[0152] 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;
[0153] 8. In the VFS process, the corresponding physical memory interval is allocated as the page cache for the file reading and writing tasks;
[0154] 9. The VFS process performs read and write operations on the page cache corresponding to the file;
[0155] 10. The process ends.
[0156] exist Figure 6 When processing file read and write tasks, the processing device receives a file read and write request from the VFS process. If there is no corresponding page cache, the processing device can allocate the corresponding page cache for the file read and write task in the physical memory space authorized by the VFS process. Having the physical memory space allocation authority in the VFS process can reduce the inter-process communication overhead caused by the VFS process requesting the physical memory interval from the memory management process, thereby improving the processing efficiency.
[0157] Combination of the above Figures 2 to 6 The memory allocation method provided by this application is described. Figure 7 The communication device provided in this application is described.
[0158] Figure 7This is a schematic structural diagram of the memory allocation device provided in this application. Figure 7 As shown, the memory allocation device includes a request unit 710 and a processing unit 720.
[0159] The request unit is used to send a task request from the second user state process to the first user state process;
[0160] The processing unit is used to allocate a first physical memory interval for the task request in the first user state process, where the first physical memory interval 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 state process.
[0161] Optionally, before the processing unit allocates the first physical memory interval to the task request of the second user state process in the first user state process,
[0162] The processing unit is further used to determine that the size of the memory space to be allocated in the physical memory space authorized by the first user state process does not meet the size of the memory space required by the task request;
[0163] The request unit is also used to apply for physical memory space from the kernel in the first user mode process;
[0164] The processing unit is also used to authorize the first physical memory space for the first user mode process in the kernel.
[0165] Optionally, the processing unit is further configured to allocate a first virtual memory interval for the task request in the first user state process;
[0166] The request unit is further used to send a memory mapping request to the kernel in the first user mode process, where the memory mapping request is used to request to establish a mapping relationship between the first physical memory interval and the first virtual memory interval.
[0167] Optionally, the processing unit is further configured to authorize physical memory space allocation authority for a third user state process in the first user state process.
[0168] Optionally, the task request is a file mapping request, the first user state process is a file system process or a virtual file system process,
[0169] 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:
[0170] The transceiver unit is used to send the first physical memory interval to the second user process in the first user process.
[0171] Optionally, 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.
[0172] The processing unit is also used to perform the read and write operations requested by the file read and write request on the first physical memory interval in the first user process.
[0173] Optionally, the processing unit is further configured to authorize physical memory space allocation authority for the first user state process in the second user state process.
[0174] Figure 8 is a schematic diagram of the structure of a communication device 800 provided in an embodiment of the present application. The communication device 800 may be configured as follows Figure 1 The communication device 800 includes a bus 840 and a processor 810 connected to the bus 840 . The communication device 800 may also include a communication interface 820 and a memory 830 .
[0175] It should be understood that Figure 8 The communication device 800 shown can implement each process of the memory allocation method in any method embodiment. The operations and / or functions of each module in the communication device 800 are respectively to implement the corresponding processes in the above method embodiments. For details, please refer to the description in the above method embodiments. To avoid repetition, the detailed description is appropriately omitted here.
[0176] Optionally, the communication device may be a terminal, also referred to as user equipment (UE), and the communication device may be a mobile phone, a tablet computer, a computer device, or the like.
[0177] An embodiment of the present application further provides a computer operating system, including: a computer program code, which, when called, enables the computer operating system to execute a method in any of the above method embodiments.
[0178] An embodiment of the present application also provides a processing device, including a processor and an interface; the processor is used to execute the method in any of the above method embodiments.
[0179] The present application also provides a computer program product, which includes: computer program code, when the computer program code is executed by one or more processors, it enables a device including the processor to execute a method in any of the above method embodiments.
[0180] The present application also provides a computer-readable storage medium storing program code. When the program code is executed by one or more processors, a device including the processor executes a method in any of the above method embodiments.
[0181] In the embodiments of the present application, under the premise of no logical contradiction, the embodiments may reference each other, for example, the methods and / or terms between method embodiments may reference each other, for example, the functions and / or terms between device embodiments may reference each other, for example, the functions and / or terms between device embodiments and method embodiments may reference each other.
[0182] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A memory allocation method, characterized in that: include: The first user state process receives a task request from the second user state process, where the task request is used to request allocation of memory space; The first user state process allocates a first physical memory interval from a first physical memory space to the second user state process, wherein the first physical memory space is a physical memory space authorized by the kernel to the first user state process; The method also includes: the first user state process authorizing physical memory space allocation authority to the second user state process.
2. The method according to claim 1, characterized in that Before the first user state process allocates the first physical memory interval from the first physical memory space to the second user state process, the method further includes: When the size of the free memory space in the second physical memory space authorized by the first user state process does not meet the size of the memory space required by the task request, the first user state process applies for physical memory space from the kernel; 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. 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 to 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. The method according to claim 1 or 2, characterized in that: The method further comprises: The first user state process authorizes the third user state process to allocate permission for the physical memory space.
5. The method according to claim 1 or 2, characterized in that: 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 state 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 state process sends the first physical memory interval to the second user state process.
6. The method according to claim 1 or 2, characterized in that: 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 user mode process performs the read / write operation requested by the file read / write request on the first physical memory interval.
7. A memory allocation device, characterized in that: comprising at least one processor coupled to the memory; The memory is used to store programs or instructions; The at least one processor is configured to execute the program or instruction so that the apparatus implements the method according to any one of claims 1 to 6.
8. A computer-readable storage medium comprising a computer program, which, when executed by one or more processors, causes a device comprising the processor to perform the method according to any one of claims 1 to 6.
9. A computer program product, characterized in that The computer program product comprises computer instructions, wherein the computer instructions instruct a computing device to execute the method according to any one of claims 1 to 6.
10. A chip, characterized in that: comprising at least one processor and a communication interface; 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 is used to implement the method according to any one of claims 1 to 6 through a logic circuit or executing code instructions.
