Memory management method and system based on Linux system, electronic equipment and readable storage medium
By using VFS and MMFS to manage memory in Linux systems, the problem that existing memory management methods are difficult to meet the complex memory configuration requirements is solved, and more efficient and flexible memory management is achieved.
Patent Information
- Application Number
- CN202411555483.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-02-11
AI Technical Summary
Existing memory management methods are difficult to meet complex memory configuration requirements, especially in hierarchical memory and asynchronous operations such as hot tracking and page migration.
By introducing virtual file system (VFS) and memory management file system (MMFS) into Linux systems, memory management and allocation are realized. The specific steps include obtaining the calling instructions of the target process, creating and deleting the MMFS corresponding to the process, and performing memory allocation and page troubleshooting.
It improves the scalability of kernel memory management, supports complex memory configuration and asynchronous operations, and enhances the flexibility and efficiency of memory management.
Smart Images

Figure CN119415260A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and specifically relates to a memory management method, system, electronic device and readable storage medium based on a Linux system. Background Art
[0002] In modern operating systems, with the introduction of Compute Express Link (CXL), there are richer physical memory configurations, and the memory hierarchy is becoming more and more complex, such as hierarchical memory or decentralized memory and multiple memory types. The existing method of registering callback functions on memory management events is not sufficient to describe many memory configurations, such as hierarchical memory, and cannot be used for asynchronous operations, such as heat tracking and page migration. It can be seen that the existing memory management method is difficult to meet the needs. Summary of the invention
[0003] The embodiments of the present application provide a memory management method, system, electronic device and readable storage medium based on a Linux system, which can solve the problem that existing memory management methods are difficult to meet the needs.
[0004] In a first aspect, a memory management method based on a Linux system is provided, comprising:
[0005] The routing function obtains a first call instruction of a first target process;
[0006] The routing function calls the virtual file system VFS to create a first MMFS corresponding to the first target process in the default memory management file system MMFS directory;
[0007] The routing function routes the first target process to the first MMFS;
[0008] The first MMFS performs memory allocation for the first target process;
[0009] The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
[0010] In an optional embodiment, the method further includes:
[0011] The routing function obtains a second call instruction of the first target process;
[0012] The routing function calls the VFS and deletes the first MMFS;
[0013] The second calling instruction is an instruction for unmapping memory.
[0014] In an optional implementation, after the routing function routes the first target process to the first MMFS, the method further includes:
[0015] The routing function saves a mapping tree between the first target process and the first MMFS;
[0016] The routing function calls the VFS to delete the first MMFS, including:
[0017] The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
[0018] In an optional embodiment, the method further includes:
[0019] When a page fault occurs in the first target process, calling the VFS to notify the first MMFS;
[0020] The first MMFS performs processing of the page fault.
[0021] In an optional embodiment, the method further includes:
[0022] The first MMFS calls the Linux memory management code to perform asynchronous startup page migration processing.
[0023] In an optional embodiment, the method further includes:
[0024] In case that the first call instruction of the second target process is obtained, creating a second MMFS corresponding to the second target process through the VFS;
[0025] The second MMFS performs memory allocation for the second target process;
[0026] When the second call instruction of the second target process is obtained, deleting the second MMFS through a close system call;
[0027] The second calling instruction is an instruction for unmapping memory.
[0028] In a second aspect, a memory management system based on a Linux system is provided, including: a routing function, a VFS and an MMFS, and also including:
[0029] A first acquisition module, used for the routing function to acquire a first call instruction of a first target process;
[0030] A first calling module, used for the routing function to call the virtual file system VFS, and create a first MMFS corresponding to the first target process in the default memory management file system MMFS directory;
[0031] A routing module, used for the routing function to route the first target process to the first MMFS;
[0032] A first execution module, configured for the first MMFS to execute memory allocation for the first target process;
[0033] The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
[0034] In an optional embodiment, the system further includes:
[0035] A second acquisition module, used for the routing function to acquire a second call instruction of the first target process;
[0036] A second calling module, configured for the routing function to call the VFS and delete the first MMFS;
[0037] The second calling instruction is an instruction for unmapping memory.
[0038] In an optional embodiment, the system further includes:
[0039] a saving module, configured to save, by the routing function, a mapping tree between the first target process and the first MMFS after the routing function routes the first target process to the first MMFS;
[0040] The second calling module is specifically used for:
[0041] The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
[0042] In an optional embodiment, the system further includes:
[0043] A third calling module is used to call the VFS to notify the first MMFS when a page fault occurs in the first target process;
[0044] The second execution module is used for the first MMFS to execute processing on the page fault.
[0045] In an optional embodiment, the system further includes:
[0046] The third execution module is used for the first MMFS to call the Linux memory management code to perform asynchronous startup page migration processing.
[0047] In an optional embodiment, the system further includes:
[0048] a fourth calling module, configured to, when obtaining the first calling instruction of the second target process, call the VFS to create a second MMFS corresponding to the second target process;
[0049] A fourth execution module, configured for the second MMFS to execute memory allocation for the second target process;
[0050] a deletion module, configured to delete the second MMFS by calling a close system when a second calling instruction of the second target process is obtained;
[0051] The second calling instruction is an instruction for unmapping memory.
[0052] According to a third aspect, an electronic device is provided, comprising a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and wherein the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0053] In a fourth aspect, a readable storage medium is provided, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0054] In a fifth aspect, a chip is provided, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the steps of the method described in the first aspect.
[0055] In a sixth aspect, a computer program / program product is provided, wherein the computer program / program product is stored in a storage medium and is executed by at least one processor to implement the steps of the method described in the first aspect.
[0056] In the embodiment of the present application, an MMFS corresponding to the target process is created through VFS, and memory allocation to the target process is performed using MMFS. When an application requests memory, it does not use a general kernel allocator to allocate memory, but can create and map files through VFS to provide access to memory, thereby using VFS as a memory management solution for the file system, allowing applications to request memory through file operations, and improving the scalability of kernel memory management. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a flowchart of a memory management method based on a Linux system provided in an embodiment of the present application;
[0058] Figure 2 It is a schematic diagram of the system architecture provided by the embodiment of the present application;
[0059] Figure 3 It is a schematic diagram of the structure of a memory management system based on a Linux system provided in an embodiment of the present application;
[0060] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0061] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of this application.
[0062] The terms "first", "second", etc. of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first" and "second" are generally of one type, and the number of objects is not limited, for example, the first object can be one or more. In addition, "or" in the present application represents at least one of the connected objects. For example, the protection scope of "A or B" covers at least three schemes, that is, scheme one: including A and excluding B; scheme two: including B and excluding A; scheme three: including both A and B. In addition, the terms "A and / or B", "at least one of A and B", and "at least one of A or B" also cover at least the above three schemes respectively. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0063] The following is a detailed description of the Linux system-based memory management method provided by the embodiment of the present application through some embodiments and their application scenarios in conjunction with the accompanying drawings.
[0064] See also Figure 1, the embodiment of the present application provides a memory management method based on the Linux system. In the embodiment of the present application, the memory management system using the present method is called a file-based memory management (Base file Mem Manage, BFM) system. BFM consists of a routing function (which can be recorded as BFM route) and one or more memory management file systems (Mem Manage file system, MMFS) that provide different memory management mechanisms and strategies. Each process is assigned an MMFS as its default memory manager (for example, through an environment variable), and can also explicitly use any loaded MMFS.
[0065] The BFM system combines the Virtual Filesystem Switch (VFS) in Linux as an extensible interface for the file system, supporting a variety of file systems for different media and different purposes. Importantly, it has an interface for memory management operations, such as controlling virtual-to-physical mapping and handling page faults. Instead of using a general kernel allocator to allocate memory, the memory management system can be designed as a file system that uses VFS. Processes can create and map files through VFS to provide access to memory. Applications choose which memory manager to use by choosing where to create files. Therefore, the memory of the process consists of files that have been memory-mapped into the process. This introduces extensibility to kernel memory management. This idea is called file-based memory management (BFM).
[0066] Methods include:
[0067] Step 101: The routing function obtains a first call instruction of a first target process;
[0068] Step 102: The routing function calls the VFS to create a first MMFS corresponding to the first target process in the default MMFS directory;
[0069] Step 103: The routing function routes the first target process to the first MMFS;
[0070] Step 104: The first MMFS performs memory allocation for the first target process;
[0071] The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
[0072] In the embodiment of the present application, an MMFS corresponding to the target process is created through VFS, and memory allocation to the target process is performed using MMFS. When an application requests memory, it does not use a general kernel allocator to allocate memory, but can create and map files through VFS to provide access to memory, thereby using VFS as a memory management solution for the file system, allowing applications to request memory through file operations, and improving the scalability of kernel memory management.
[0073] The first calling instruction described above may use instructions for mapping anonymous virtual memory in the same manner as now, such as calling mmap or brk with the MAP_ANON flag.
[0074] In an optional embodiment, the method further includes:
[0075] (1) The routing function obtains the second call instruction of the first target process;
[0076] (2) The routing function calls VFS and deletes the first MMFS;
[0077] The second calling instruction is an instruction for canceling the memory mapping.
[0078] The second calling instruction may use the same method as now for unmapping the anonymous virtual memory, for example, calling munmap.
[0079] In the above method steps, when the application (i.e., the target process) maps anonymous virtual memory in the same way as it does now, by calling mmap or brk with the MAP_ANON flag, or unmaps the anonymous memory through munmap. BFMroute intercepts these calls and creates in the application's default MMFS when mapping the memory, and then maps it to a file, or deletes the file associated with the memory range when unmapping the memory (i.e., calling VFS to create or delete MMFS). We call this kind of file (i.e., MMFS created by VFS) a memory file. The creation / deletion of the file calls the VFS layer to forward the operation to the relevant MMFS (1C). Finally, the MMFS updates its own metadata as needed and allocates or releases physical memory for the created / deleted file.
[0080] Applications can use the default memory manager without modifying the code, which is implemented through the BFM route interface design. For example, through environment variables, any loaded MMFS can be explicitly used, so that BFMroute can route the memory management system calls to the file operations in the default MMFS of the application, providing transparency for the application.
[0081] In an optional implementation, after the routing function routes the first target process to the first MMFS, the method further includes:
[0082] The routing function saves a mapping tree between the first target process and the first MMFS;
[0083] The routing function calls VFS to delete the first MMFS, including:
[0084] The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
[0085] In an embodiment of the present application, when a process calls brk or mmap with the MAP_ANON flag, BFMroute creates an unnamed temporary file in the mount directory of the MMFS allocated by the process and maps the file to the address space of the creating process. BFM route also saves references to the file in a per-process tree, indexed by the virtual address range it maps. When a process terminates or calls munmap, BFM route searches the tree of the process's mapped files and deletes the files in the area to be unmapped. This triggers the removal process of the MMFS, thereby freeing up physical memory.
[0086] In an optional embodiment, the method further includes:
[0087] (1) When a page fault occurs in the first target process, calling VFS to notify the first MMFS;
[0088] (2) The first MMFS performs processing for page faults.
[0089] In an embodiment of the present application, when a page fault occurs, the VFS is directly called, and using information about the faulty memory file, the VFS notifies the MMFS that owns the file containing the fault. The MMFS then handles the page fault in a manner it deems appropriate, such as allocating physical memory for the fault.
[0090] In an optional embodiment, the method further includes:
[0091] First, MMFS calls the Linux memory management code to perform asynchronous startup page migration processing.
[0092] In the embodiment of the present application, the MMFS can also execute MM events asynchronously. For example, a MMFS of a hierarchical memory can asynchronously start page migration without any external prompt.
[0093] In an optional embodiment, the method further includes:
[0094] (1) when the first call instruction of the second target process is obtained, a second MMFS corresponding to the second target process is created through the VFS;
[0095] (2) The second MMFS performs memory allocation for the second target process;
[0096] (3) when the second call instruction of the second target process is obtained, the second MMFS is deleted through the close system call;
[0097] The second calling instruction is an instruction for canceling the memory mapping.
[0098] In the embodiment of the present application, some advanced applications may want a specific memory area to have a different behavior from the default setting. This can be achieved by manually creating (for example, manually calling VFS between users to create) a memory file with the required behavior and mapping it to its address space. Complex applications can use multiple MMFS on different data structures at the same time. The memory of the process consists of files under the MMFS that have been memory-mapped to the process. It should be noted that when a memory file is manually created, it will not be tracked by the BFM route. Therefore, when munmap is called, its memory will not be automatically released, and the file can be manually closed through the close system call.
[0099] The solution of this application is described below in combination with the system design architecture:
[0100] BFM consists of BFM routes and one or more memory management file systems MMFS that provide different memory management mechanisms and policies. Each process is assigned an MMFS as its default memory manager (for example, through environment variables), and can also explicitly use any loaded MMFS. The entire extensible memory management design framework is as follows Figure 2 shown.
[0101] 1. BFM scalable implementation design
[0102] In Linux, VFS is an extensible interface for file systems that supports a variety of file systems for different media and purposes. Importantly, it has an interface for memory management operations, such as controlling virtual-to-physical mapping and handling page faults. Instead of using a general kernel allocator to allocate memory, a memory management system can be designed as a file system that uses VFS. Processes can create and map files through VFS to provide access to memory. Applications choose which memory manager to use by choosing where to create files. Therefore, the memory of a process consists of files that have been memory-mapped into the process. This introduces extensibility to kernel memory management. This idea is called file-based memory management BFM. The following interactive processes are designed around VFS in BFM.
[0103] (1) BFM application process for releasing memory (corresponding to Figure 2 1A->1B->1C->1D);
[0104] In BFM, applications map anonymous virtual memory in the same way as they do today (1A), by calling mmap or brk with the MAP_ANON flag, or unmap anonymous memory via munmap. The BFM route intercepts these calls and creates and then maps a file to the application's default MMFS when the memory is mapped, or deletes the file associated with the memory range when the memory is unmapped (1B). We call such a file a memory file. The creation / deletion of the file calls the VFS layer, which forwards the operation to the relevant MMFS (1C). Finally, the MMFS updates its own metadata as needed and allocates or releases physical memory for the created / deleted file (1D).
[0105] (2) BFM page fault handling process (corresponding to Figure 2 2A-2B->2C);
[0106] When a page fault occurs, the page fault handler calls the VFS directly, using information about the faulting memory file (2A). As before, the VFS then notifies the MMFS that owns the file containing the fault (2B). The MMFS then handles the page fault as it sees fit, such as allocating physical memory for the fault (2C).
[0107] (3) Asynchronous execution of MM event flow in MMFS (corresponding to Figure 2 3A->3B);
[0108] An MMFS can also perform MM events asynchronously. For example, a hierarchical memory MMFS can start page migration asynchronously without any external prompt (3A). In addition, the MMFS can call existing Linux memory management code. For example, the MMFS uses the relevant page table traversal and update functions to update the physical address of the migrated page (3B). To allocate physical memory, the MMFS can statically allocate memory at boot time, or it can call get_free_pages to dynamically allocate physical memory.
[0109] 2. BFM transparency implementation design
[0110] Applications can use the default memory manager without modifying their code, which is implemented by the BFM route interface design. Through environment variables, any loaded MMFS can also be used explicitly, so that BFM route can route memory management system calls to file operations in the application's default MMFS to provide transparency to applications. When a process calls brk or mmap with the MAP_ANON flag, BFM route creates an unnamed temporary file in the mount directory of the process's allocated MMFS and maps the file to the address space of the creating process. BFMroute also saves references to files in a per-process tree, indexed according to the virtual address range it maps. When a process terminates or calls munmap, BFM route searches the tree of process-mapped files and deletes files in the area to be unmapped. This triggers the removal process of the MMFS, freeing up physical memory.
[0111] The existing Linux memory manager is slightly modified to support BFM, and BFM route is designed as an additional feature of the Linux memory manager. It exposes interfaces to the Linux memory manager to build its per-process memory file tree and redirect anonymous memory operations to the appropriate MMFS. BFM route exposes four main functions to the rest of Linux:
[0112] BFM_create_new_file: Creates a new unnamed temporary file and returns a handle to the file to the caller.
[0113] BFM_register_new_file: Adds a newly mapped file to the per-process in-memory file tree, indexed by the virtual address it is mapped to.
[0114] BFM_munmap: Called when a process calls munmap to delete or truncate a memory file.
[0115] BFM_exiting_proc: Called when a process exits, deletes any remaining files associated with the process.
[0116] When the mmap system call is called with the MAP_ANON flag, it creates a file via BFM_create_new_file and then maps the file. Then after the new file is mapped, BFM_register_new_file is called to keep track of the new file. Similarly the brk system call is modified. The munmap and exit system calls call BFM_munmap and BFM_exiting_proc respectively to do the cleanup.
[0117] 3. BFM controllability implementation design
[0118] Complex applications can use multiple memory managers on different data structures at the same time, which is achieved through the BFMMMFS interface design. This allows applications to manage their memory requirements more flexibly. A subset of the callback functions defined by the VFS layer is sufficient to define an MMFS. The main callback functions that define MMFS are listed in Table 1 below.
[0119] Table 1
[0120]
[0121] In the BFM application process for releasing memory (1A->1B->1C->1D), when the general application layer mmap interface is called in 1A, the BFM route intercepts these calls, and creates and maps a file in the default MMFS of the application to control when the kernel memory is allocated when mapping memory. The kernel state implementation of the mmap callback function provided by vfs is implemented in mmfs. The implementation logic is that the user space requests the kernel to map a file or device to its address space through the mmap system call. The kernel will allocate an address space for the mapping, and then map the file or device content to this address space, so that the access to this address space is actually the access to the file or device.
[0122] In 1D, MMFS will update its metadata based on the files created in 1B. At this time, the mmfs kernel state implementation of the fallocate callback function provided by vfs will be used to control the physical memory that needs to be allocated. The fallocate implementation logic is that the kernel will give priority to the physical memory reserved at startup and update the corresponding metadata in the file system. This helps to avoid problems such as physical memory application failure and cache inconsistency. Ultimately, the actual allocation of physical memory will be controlled through the fault interface implemented by mmfs in 1D. The fault implementation logic is that when the program accesses the mapped memory but the memory has not been loaded, a page fault will be triggered. The kernel loads the corresponding page into the memory through the page fault handling mechanism to meet the program's access requirements to the memory. The free_inode release interface implemented by mmfs has a similar processing logic and is called in 1D when released.
[0123] Advanced applications may want specific memory regions to behave differently from the default settings. For example, an application
[0124] It may be desirable to keep DMA buffers pinned in memory, while the rest of the memory can be movable. Applications can control when kernel memory is allocated. This can be achieved by manually creating a memory file with the desired behavior in an MMFS and mapping it into its address space. Complex applications can use multiple MMFS on different data structures at the same time. The memory of a process consists of files under the MMFS that have been memory mapped into the process. It is important to note that when a memory file is created manually, it is not tracked by the BFM route. Therefore, its memory is not automatically released when munmap is called. The file can be closed manually with the close system call.
[0125] 4. BFM usage design
[0126] MMFS is available for use when it is mounted. All files created under its mount point use MMFS to allocate memory. When a process starts, the parent process or the system administrator can specify a directory that represents the MMFS for anonymous memory management. If no directory is specified, the system default is used.
[0127] See also Figure 3 The embodiment of the present application provides a memory management system 300 based on a Linux system, including: a routing function, a VFS and an MMFS, and also including:
[0128] A first acquisition module 301 is used for a routing function to acquire a first call instruction of a first target process;
[0129] The first calling module 302 is used for calling the virtual file system VFS through a routing function, and creating a first MMFS corresponding to the first target process in the default memory management file system MMFS directory;
[0130] A routing module 303, configured to route the first target process to the first MMFS by a routing function;
[0131] A first execution module 304, used for the first MMFS to execute memory allocation for the first target process;
[0132] The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
[0133] In an optional embodiment, the system further includes:
[0134] A second acquisition module, used for the routing function to acquire the second calling instruction of the first target process;
[0135] The second calling module is used for the routing function to call the VFS and delete the first MMFS;
[0136] The second calling instruction is an instruction for canceling the memory mapping.
[0137] In an optional embodiment, the system further includes:
[0138] a saving module, configured to save, after the routing function routes the first target process to the first MMFS, a mapping tree between the first target process and the first MMFS;
[0139] The second calling module is specifically used for:
[0140] The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
[0141] In an optional embodiment, the system further includes:
[0142] A third calling module is used to call the VFS to notify the first MMFS when a page fault occurs in the first target process;
[0143] The second execution module is used for the first MMFS to execute processing on the page fault.
[0144] In an optional embodiment, the system further includes:
[0145] The third execution module is used for the first MMFS to call the Linux memory management code to perform asynchronous startup page migration processing.
[0146] In an optional embodiment, the system further includes:
[0147] A fourth calling module is used to call the VFS to create a second MMFS corresponding to the second target process when the first calling instruction of the second target process is obtained;
[0148] A fourth execution module, used for the second MMFS to execute memory allocation for the second target process;
[0149] A deletion module, configured to delete the second MMFS by a close system call when a second call instruction of the second target process is obtained;
[0150] The second calling instruction is an instruction for canceling the memory mapping.
[0151] See also Figure 4 The embodiment of the present invention provides an electronic device 400, including: at least one processor 401, a memory 402, a user interface 403 and at least one network interface 404. The components in the electronic device 400 are coupled together via a bus system 405.
[0152] It is understood that the bus system 405 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 405 also includes a power bus, a control bus, and a status signal bus. Figure 4 Various buses are labeled as bus system 405 .
[0153] The user interface 403 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen, etc.).
[0154] It is understood that the memory 402 in the embodiment of the present invention may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DRRAM). The memory 402 described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memory.
[0155] In some implementations, the memory 402 stores the following elements, executable modules or data structures, or a subset thereof, or an extended set thereof: an operating system 4021 and an application 4022 .
[0156] The operating system 4021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 4022 includes various application programs, such as a media player, a browser, etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present invention can be included in the application 4022.
[0157] In the embodiment of the present invention, the electronic device 400 may further include: a program stored in the memory 402 and executable on the processor 401, which implements the steps of the method provided in the embodiment of the present invention when executed by the processor 401.
[0158] The method disclosed in the above embodiment of the present invention can be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 401 or the instruction in the form of software. The above processor 401 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor to execute, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a computer-readable storage medium mature in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The computer-readable storage medium is located in the memory 402, and the processor 401 reads the information in the memory 402 and completes the steps of the above method in combination with its hardware. Specifically, a computer program is stored on the computer-readable storage medium.
[0159] It is to be understood that the embodiments described in the embodiments of the present invention may be implemented by hardware, software, firmware, middleware, microcode or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more ASICs, DSPs, digital signal processing devices (DSP Device, DSPD), programmable logic devices (Programmable Logic Device, PLD), FPGAs, general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application or a combination thereof.
[0160] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0161] The processor is the processor in the terminal described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk. In some examples, the readable storage medium may be a non-transient readable storage medium.
[0162] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0163] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0164] The embodiments of the present application further provide a computer program / program product, which is stored in a storage medium and is executed by at least one processor to implement the various processes of the above-mentioned method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described here.
[0165] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises one..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the method and device in the embodiment of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0166] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of a computer software product plus a necessary general hardware platform, and of course, can also be implemented by hardware. The computer software product is stored in a storage medium (such as ROM, RAM, disk, CD, etc.), including several instructions to enable a terminal or a network-side device to execute the methods described in each embodiment of the present application.
[0167] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms of implementation methods without departing from the purpose of the present application and the scope of protection of the claims, and these implementation methods are all within the protection of the present application.
Claims
1. A memory management method based on Linux system, characterized in that: include: The routing function obtains a first call instruction of a first target process; The routing function calls the virtual file system VFS to create a first MMFS corresponding to the first target process in the default memory management file system MMFS directory; The routing function routes the first target process to the first MMFS; The first MMFS performs memory allocation for the first target process; The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
2. The method according to claim 1, characterized in that The method further comprises: The routing function obtains a second call instruction of the first target process; The routing function calls the VFS and deletes the first MMFS; The second calling instruction is an instruction for unmapping memory.
3. The method according to claim 2, characterized in that After the routing function routes the first target process to the first MMFS, the method further includes: The routing function saves a mapping tree between the first target process and the first MMFS; The routing function calls the VFS to delete the first MMFS, including: The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
4. The method according to claim 1, characterized in that: The method further comprises: When a page fault occurs in the first target process, calling the VFS to notify the first MMFS; The first MMFS performs processing of the page fault.
5. The method according to claim 1, characterized in that The method further comprises: The first MMFS calls the Linux memory management code to perform asynchronous startup page migration processing.
6. The method according to claim 1, characterized in that The method further comprises: In case that the first call instruction of the second target process is obtained, creating a second MMFS corresponding to the second target process through the VFS; The second MMFS performs memory allocation for the second target process; When the second call instruction of the second target process is obtained, deleting the second MMFS through a close system call; The second calling instruction is an instruction for unmapping memory.
7. A memory management system based on Linux system, characterized in that: include: Routing functions, VFS and MMFS, and also include: A first acquisition module, used for the routing function to acquire a first call instruction of a first target process; A first calling module, used for the routing function to call the virtual file system VFS, and create a first MMFS corresponding to the first target process in the default memory management file system MMFS directory; A routing module, used for the routing function to route the first target process to the first MMFS; A first execution module, configured for the first MMFS to execute memory allocation for the first target process; The first calling instruction is an instruction for mapping memory, and different MMFSs map different memory managers respectively.
8. The system according to claim 7, characterized in that The system further comprises: A second acquisition module, used for the routing function to acquire a second call instruction of the first target process; A second calling module, configured for the routing function to call the VFS and delete the first MMFS; The second calling instruction is an instruction for unmapping memory.
9. The system according to claim 8, characterized in that The system further comprises: a saving module, configured to save, by the routing function, a mapping tree between the first target process and the first MMFS after the routing function routes the first target process to the first MMFS; The second calling module is specifically used for: The routing function searches for the first MMFS according to the mapping tree, and calls the VFS to delete the first MMFS.
10. The system according to claim 7, characterized in that The system further comprises: A third calling module is used to call the VFS to notify the first MMFS when a page fault occurs in the first target process; The second execution module is used for the first MMFS to execute processing on the page fault.
11. The system according to claim 7, characterized in that The system further comprises: The third execution module is used for the first MMFS to call the Linux memory management code to perform asynchronous startup page migration processing.
12. The system according to claim 7, characterized in that The system further comprises: a fourth calling module, configured to, when obtaining the first calling instruction of the second target process, call the VFS to create a second MMFS corresponding to the second target process; A fourth execution module, configured for the second MMFS to execute memory allocation for the second target process; a deletion module, configured to delete the second MMFS by a close system call when a second call instruction of the second target process is obtained; The second calling instruction is an instruction for unmapping memory.
13. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the memory management method based on the Linux system as described in any one of claims 1 to 7 are implemented.
14. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the memory management method based on the Linux system as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Dynamic library mapping loading method and device, electronic equipment and storage medium
CN121658098A