Memory access method, device, electronic device and storage medium

By setting reserved space in TLB and writing page table entries to the target program, the frequent page missing exceptions caused by page table entries limitations in TLB in Linux operating system are solved, and the memory access efficiency of real-time programs is improved.

CN114546897BActive Publication Date: 2024-12-24LOONGSON TECH CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011355548.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-26
Publication Date
2024-12-24
Estimated Expiration
2040-11-26

AI Technical Summary

Technical Problem

In Linux operating system, the limitation of page table entries in TLB causes programs with high real-time requirements to frequently trigger page-missing exceptions, resulting in delayed memory access time and affecting program operation efficiency.

Method used

Set a reserved space in TLB to save the page table entries of the target program and not be replaced during the operation of the target program. By querying the page table, you can obtain the page table entries to be accessed and write them to the reserved space to reduce Page missing exception occurs.

Benefits of technology

The time for target programs to access memory is optimized, the number of times they look up page table entries in the memory page table is reduced, the efficiency of memory access is improved, and the program required for real-time can respond in a timely manner.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114546897B_ABST
    Figure CN114546897B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a memory access method and device, which is applied to an electronic device running a Linux operating system, and the method includes: initializing a TLB, and setting a reserved space in the TLB, the reserved space is used to store page table entries of a target program, and the page table entries stored in the reserved space are not replaced during the operation of the target program; when the current program triggers a page fault exception, the target page table entry to be accessed by the current program is obtained by querying the page table, and the target page table entry contains the mapping relationship between the physical address and the virtual address of the memory to be accessed by the current program; if the current program is the target program, the target page table entry is written into the reserved space in the TLB. The embodiment of the present invention can optimize the time required for the target program to access the memory and improve the response speed of the target program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a memory access method, a memory access device, an electronic device and a storage medium. Background Art

[0002] With the development of the computer market, the Linux operating system has been widely used. The Linux operating system has evolved from a relatively mature Unix operating system and is an integrated kernel system. The kernel refers to a system software that provides hardware abstraction layer, disk and file system control, multitasking and other functions. Among them, the Linux operating system kernel uses paged memory management. When designing memory management, the MMU (Memory Management Unit) mechanism and TLB (Translation Lookaside Buffer) are used. The MMU is used to complete the conversion of virtual addresses to physical addresses. The TLB is a cache inside the MMU, which caches the page table entries corresponding to the recently searched virtual addresses, and is used to improve the conversion speed of virtual addresses to physical addresses.

[0003] Normally, the memory address given by the application is a virtual address. The virtual address is sent to the MMU, and the MMU first accesses the TLB. If the page table entry for converting the virtual address is found in the TLB, the physical address corresponding to the virtual address can be directly obtained. When the page table entry for converting the virtual address is not found in the TLB, the MMU will trigger a TLB Miss exception (page missing exception). At this time, it is necessary to search the page table in the physical memory multiple times until the page table entry corresponding to the virtual address is found in the page table, and the page table entry is updated to the TLB table entry.

[0004] However, since the number of page table entries that can be cached in the TLB is limited, when a large number of programs are running, the MMU will replace the page table entries of the running programs in the TLB with the page table entries of the newly running programs, causing the MMU to frequently trigger page fault exceptions. It is necessary to frequently search the memory page table for the missing page table entries in the TLB, which in turn causes the time delay for the program to access the memory to increase, especially for some programs with high real-time requirements in the Linux operating system. As a result, these programs with high real-time requirements cannot respond in time, affecting the running efficiency of the program. Summary of the invention

[0005] In view of the above problems, an embodiment of the present invention is proposed to provide a memory access method that overcomes the above problems or at least partially solves the above problems, so as to optimize the time for a target program with high real-time requirements to access memory, thereby improving the operating efficiency of the target program.

[0006] Correspondingly, an embodiment of the present invention further provides a memory access device, an electronic device and a storage medium to ensure the implementation and application of the above method.

[0007] In order to solve the above problem, an embodiment of the present invention discloses a memory access method, which is applied to an electronic device running a Linux operating system. The method includes:

[0008] Initializing a translation lookaside buffer TLB, and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program;

[0009] In the case where the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program;

[0010] If the current program is the target program, the target page table entry is written into the reserved space in the TLB.

[0011] The embodiment of the present invention further discloses a memory access device, which is applied to an electronic device running a Linux operating system, comprising:

[0012] An initialization module, used for initializing a translation lookaside buffer TLB and setting a reserved space in the TLB, wherein the reserved space is used for storing page table entries of a target program, and the page table entries stored in the reserved space are not replaced during the running of the target program;

[0013] A page table entry query module, used to obtain a target page table entry to be accessed by the current program by querying the page table when the current program triggers a page fault exception, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program;

[0014] The page table entry writing module is used to write the target page table entry into the reserved space in the TLB if the current program is the target program.

[0015] The embodiment of the present invention further discloses an electronic device, wherein the electronic device runs a Linux operating system, and the electronic device includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, wherein the one or more programs include instructions for performing the following operations:

[0016] Initializing a translation lookaside buffer TLB, and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program;

[0017] In the case where the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program;

[0018] If the current program is the target program, the target page table entry is written into the reserved space in the TLB.

[0019] An embodiment of the present invention further discloses a readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device can execute one or more memory access methods described in the embodiment of the present invention.

[0020] The embodiments of the present invention include the following advantages:

[0021] The embodiment of the present invention sets a reserved space in the TLB, and the reserved space is used to store the page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the operation of the target program. In the prior art, during the operation of the target program, the page table entries in its TLB may still be replaced by the page table entries of the newly running program, resulting in a longer time delay for the target program to access the memory, especially for the target program with high real-time requirements, which will seriously affect the operation efficiency of the target program. The embodiment of the present invention sets a reserved space for the target program in the TLB, so that after the target program triggers a page fault exception for the first time, the target page table entry to be accessed by the target program will be written into the reserved space in the TLB, and during the operation of the target program, the target page table entry to be accessed will not be replaced out of the TLB, which can reduce the occurrence of page fault exceptions in the target program as much as possible, reduce the process of the target program again or repeatedly searching for page table entries in the memory page table, and improve the speed of the target program to obtain the target page table entry, so as to optimize the time required for the target program to access the memory and improve the operation efficiency of memory access. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1is a flow chart of steps of an embodiment of a memory access method of the present invention;

[0023] Figure 2 is a flowchart of another memory access method embodiment of the present invention;

[0024] Figure 3 is a structural block diagram of an embodiment of a memory access device of the present invention;

[0025] Figure 4 The invention is a structural block diagram of an electronic device for memory access according to an exemplary embodiment. DETAILED DESCRIPTION

[0026] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0027] Method Example 1

[0028] Reference Figure 1 , shows a flowchart of a memory access method embodiment of the present invention, which is applied to an electronic device running a Linux operating system. The method may specifically include the following steps:

[0029] Step 101, initialize TLB, and set reserved space in the TLB, the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program.

[0030] The embodiments of the present invention can be used in electronic devices running Linux operating systems, including but not limited to servers, smart phones, voice recorders, tablet computers, e-book readers, MP3 (Moving Picture Experts Group Audio Layer III) players, MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, car computers, desktop computers, set-top boxes, smart TVs, wearable devices, and the like.

[0031] In an example of an embodiment of the present invention, the electronic device may be a Loongson platform equipped with a Loongson processor. Preferably, the processor may be a Loongson series processor, such as Loongson 1, Loongson 2 or Loongson 3, etc. The embodiment of the present invention does not limit the type of the processor.

[0032] In the Linux operating system, when the processor executes a program, it accesses the memory allocated for the program. However, the processor does not directly access the physical memory address (physical address), but indirectly accesses the physical address through the virtual space address (virtual address). The virtual address is a logical address assigned by the Linux operating system to each program being executed. The Linux operating system establishes a mapping relationship between the virtual address and the physical address, so that the processor can indirectly access the physical address through the mapping relationship.

[0033] Usually, the virtual address is in units of 512Byte to 8K, which is called a page. Each page is numbered in sequence starting from 0. This size is usually called a page. The physical address is taken as a unit of the same size. A page in the physical address is usually called a page frame or block, and the number of a page frame is also corresponding to a page frame in sequence starting from 0. The page of the virtual address and the page frame of the physical address are recorded in a page table. Each program has its own page table. Each item in the page table stores the mapping between a logical page and a page frame. The item is called a page table item. The page table item can represent the mapping relationship between the virtual address and the physical address. The page table is stored in the memory.

[0034] The memory is used for address mapping (mapping of virtual addresses and physical addresses), page table maintenance, page frame allocation, free memory management, page table replacement (swapping the page table from the main memory to the auxiliary memory), out-of-bounds checking and protection checking, etc.

[0035] The Linux operating system can be a multi-process multi-user operating system. Therefore, the MMU mechanism and TLB are used in the Linux operating system for memory access. The MMU is called a memory management unit, which is a control route used by the processor to manage virtual memory and physical memory. It is also responsible for mapping virtual addresses to physical addresses and providing memory access authorization. The MMU can determine which physical address a virtual address should be mapped to by looking up the page table for memory access. TLB is a storage space that stores the mapping relationship between virtual addresses and physical addresses according to a certain structure. The TLB is called a translation check buffer. It is a memory management unit and a cache used to improve the speed of virtual address to physical address conversion. Each row in the TLB stores a block consisting of a single page table entry.

[0036] In the Linux operating system, the specific process of using the MMU mechanism for memory access may include: when a program needs to access memory, it will send a memory access request to the MMU, the memory access request carries the program's identifier, and the MMU will search the TLB for the page table entry corresponding to the program's virtual address according to the identifier. If there is no page table entry corresponding to the virtual address in the TLB, the MMU will trigger a page fault exception. In response to the page fault exception, the memory (Memory) will allocate a corresponding page table entry for the virtual address and fill this page table entry into the page table for the MMU to search. The MMU will write the found page table entry into the TLB, so that the program can perform memory access according to the mapping relationship between the virtual address and the physical address in the page table entry.

[0037] However, since the number of page table entries that can be cached in the TLB is limited, when a large number of programs are running, the page table entries of the newly running programs will replace the page table entries of the already running programs in the TLB. That is, the page table entries corresponding to the already running programs (including those that have been run or are being run) will be replaced out of the TLB. For programs with high real-time requirements, this will cause frequent page fault exceptions and require repeated searches for page table entries in the memory page table, which will greatly affect the running efficiency of the program.

[0038] In order to ensure that these programs with high real-time requirements can get timely responses, the embodiment of the present invention initializes the TLB before the Linux operating system starts running (Linux operating system initialization stage), that is, clears the page table entries stored in the TLB, and sets a reserved space in the TLB, the reserved space is used to store the page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the operation of the target program. The target program can be a specific program with high real-time requirements in the Linux operating system that is pre-set. Among them, the initialization of the TLB can be achieved by initializing the wired registers inside the processor.

[0039] The embodiment of the present invention reserves storage space in the TLB for the target program, thereby minimizing the situation where the target program frequently searches for missing page table entries in the memory page table and causing response delays, thereby giving priority to ensuring that the target program can respond in a timely manner during operation. In one example of the present invention, the target program may include: an emergency response program responsible for control management functions, a real-time monitoring program for testing functions, etc.

[0040] In an embodiment of the present invention, the TLB may include reserved space and non-reserved space. The reserved space may be exclusively used by the target program to cache the page table entries of the target program. By setting a certain proportion of the reserved space, the memory access requirements of the target program can be prioritized. The non-reserved space is shared by all programs.

[0041] The size of the reserved space in the TLB can be set by those skilled in the art according to specific circumstances, and the embodiment of the present invention does not limit this.

[0042] Step 102, when the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program.

[0043] When the current program performs memory access and queries the target page table entry to be accessed in the TLB through the MMU, if the target page table entry is not found in the TLB, the MMU triggers a page fault exception. The current program may be a program started for the first time or a program that has been started.

[0044] In an application example of the present invention, the TLB is first initialized, that is, the page table entries stored in the TLB are cleared, and a reserved space is set in the TLB. Assume that the programs running in the current Linux operating system include program A and program B, wherein program A is a target program and program B is a non-target program. In actual applications, assuming that program A and program B access the memory for the first time, both program A and program B will trigger a page fault exception. In response to the page fault exception, the processor can start a kernel page fault exception handler, and the kernel page fault exception handler can obtain the target page table entry to be accessed by program A and the target page table entry to be accessed by program B in the page table of the memory, respectively.

[0045] Step 103: If the current program is a target program, the target page table entry is written into the reserved space in the TLB.

[0046] The embodiment of the present invention can pre-set the target program and record the identification of the target program. When the current program triggers a page fault exception, it can be determined whether the current program is the preset target program based on the identification of the current program. For example, in the above example, when program A accesses the memory, a memory access request is sent to the MMU, and the memory access request carries the identification of program A. When the MMU triggers a page fault exception response, the kernel page fault exception handler is started. The kernel page fault exception handler obtains the target page table entry to be accessed by the current program in the page table corresponding to program A in the memory based on the identification of program A and the virtual address corresponding to program A. The kernel page fault exception handler can query whether program A is the target program based on the identification of program A. Assuming that program A is found to be the target program based on the identification of program A, the target page table entry to be accessed by program A is written into the reserved space in the TLB.

[0047] In an optional embodiment of the present invention, the method further includes:

[0048] If the current program is not the target program, the target page table entry to be accessed by the current program is written into the non-reserved space in the TLB.

[0049] In the above example, when program B accesses the memory, a memory access request is sent to the MMU, and the memory access request carries the identifier of program B. When the MMU triggers a page fault exception response, the kernel page fault exception handler is started. The kernel page fault exception handler obtains the target page table entry to be accessed by the current program in the page table corresponding to program B in the memory according to the identifier of program B and the virtual address corresponding to program B. The kernel page fault exception handler can query whether program B is the target program according to the identifier of program B. Assuming that program B is not the target program according to the identifier of program B, the target page table entry to be accessed by program B is written into the non-reserved space in the TLB.

[0050] It should be noted that the embodiment of the present invention does not limit the number of target programs, and one or more target programs may be set. Generally, the number of target programs is usually much smaller than the number of non-target programs to give priority to ensuring that the memory access request of the target program can be responded to in a timely manner.

[0051] Optionally, after the target page table entry of the target program is written into the reserved space of the TLB, the target page table entry of the target program may reside in the TLB to ensure that each time the target program accesses the memory, the physical address corresponding to the virtual address of the target program can be directly found in the TLB, so as to quickly access the memory according to the physical address and optimize the time for the target program to access the memory.

[0052] In addition, the preset reserved space of a certain size can only cache the page table entries corresponding to the target program, and the target program does not need to occupy the storage space of the TLB in turn with a large number of other non-target programs. Therefore, the present invention can give priority to ensuring the stable cache of the page table entries corresponding to the target program, thereby improving the TLB hit rate of the target program in each subsequent memory access process. The TLB hit refers to the ability to directly find the corresponding page table entry data in the TLB.

[0053] Furthermore, since the reserved space of the TLB is limited, in order to avoid wasting resources of the TLB reserved space, after the current target program is finished running, the reserved space of the TLB occupied by it can be released for use by other target programs.

[0054] In summary, the embodiment of the present invention sets a reserved space for the target program in the TLB, so that after the target program triggers a page fault exception for the first time, the target page table entry to be accessed by the target program will be written into the reserved space in the TLB, and during the running of the target program, the target page table entry to be accessed will not be replaced out of the TLB, which can minimize the occurrence of page fault exceptions in the target program, reduce the process of the target program again or repeatedly searching for page table entries in the memory page table, and improve the speed of the target program acquiring the target page table entry, so as to optimize the time required for the target program to access the memory and improve the operating efficiency of memory access.

[0055] Method Example 2

[0056] Reference Figure 2 , shows a flowchart of another memory access method embodiment of the present invention, which is applied to an electronic device running a Linux operating system. The method may specifically include the following steps:

[0057] Step 201, initialize TLB, and set reserved space in the TLB, the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program.

[0058] Optionally, the setting of the reserved space in the TLB may include:

[0059] Step 211, determining the reserved ratio according to the number and type of preset target programs;

[0060] Step 2012: Set the storage space of the reserved ratio in the TLB as the reserved space.

[0061] In an embodiment of the present invention, the TLB may include reserved space and non-reserved space. The reserved space may be exclusively used by the target program to cache the page table entries of the target program. By setting a certain proportion of the reserved space, the memory access requirements of the target program can be prioritized. The non-reserved space is shared by all programs.

[0062] Among them, the size of the reserved space in the TLB is set by those skilled in the art according to specific circumstances. For example, the reserved ratio can be determined according to the number and type of preset target programs, and the size of the reserved space can be determined according to the reserved ratio. In an example, the capacity of the TLB is 64KB, which can store 16 page table entries. Assuming that the target program includes a jump program, since the memory access requirement of the jump program is large, a reserved space with a reserved ratio of 1 / 8 is set in the TLB, that is, the reserved space in the TLB is set to 8KB, and the reserved space of 8KB can store the target page table entries of 2 target programs. Furthermore, in an embodiment of the present invention, the reserved space with a reserved ratio set in the TLB can be set in the register of the processor.

[0063] Step 202, when the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program.

[0064] In the system memory, each entry of the page table is used to store the mapping between a page and a page frame. The entry is called a page table entry, which represents the mapping relationship between the virtual address and the physical address. By querying the page table, the target page table entry to be accessed by the current program can be obtained. Therefore, by querying the page table, the target page table entry to be accessed by the current program can be obtained, and the target page table entry contains the mapping relationship between the physical address and the virtual address of the memory to be accessed by the current program.

[0065] When the MMU does not find the target page table entry corresponding to the current program in the TLB, the MMU triggers a page fault exception. In response to the page fault exception, the processor starts the kernel page fault exception handler and queries the page table in the memory to obtain the target page table entry to be accessed by the current program from the page table. The current program can be a program started for the first time or a program that has been started.

[0066] Optionally, in step 202, when the current program is a target program, before obtaining the target page table entry to be accessed by the current program by querying the page table, the method further includes:

[0067] Step A1, receiving a memory access request of the target program based on a huge page mechanism;

[0068] It should be noted that, usually, the page table in the memory is stored in a multi-level page table, such as dividing the page table into multiple parts and storing them separately. When the memory is large, there will be a lot of page tables, which will affect the efficiency of searching for page table entries. In order to reduce the number of page tables, huge pages are needed. The huge page refers to simulating multiple continuous page tables into a whole, which can save the amount of memory occupied by the page table and improve memory access performance.

[0069] When the target program accesses memory and triggers a page fault exception, the target program applies for memory access through a huge page mechanism, which can increase the speed of querying the target page table entry in the multi-level page table, thereby increasing the speed of the program accessing memory.

[0070] In the Linux operating system, for each program, the kernel maintains a table (page table) that maps virtual addresses to physical addresses. For each page operation, the kernel needs to load the mapping relationship between virtual addresses and physical addresses. Usually, the minimum page size or standard page size is 4KB. Due to the small page size, the kernel needs to load a large number of pages, resulting in the kernel needing to load a large number of mapping relationships, which in turn affects the performance of the system.

[0071] The size of a huge page is larger than the size of the minimum page or the standard page. For example, a huge page can be any size between 4k and 1G, such as 8KB, 64KB, 256KB, 1MB, 2MB, 4MB, 16MB, 256MB, 512MB or 1GB, or any size therebetween. For example, a huge page can be an integer multiple n of 4KB, i.e. n*4KB.

[0072] In an embodiment of the present invention, the target program can apply for access to the memory through the huge page mechanism, that is, when the kernel page size is certain, multiple page frames with continuous physical addresses can be allocated to the target program, thereby simulating a large page for the target program to access, thereby reducing the number of page table entries required by the kernel to load the target program, thereby reducing the number of page fault exceptions of the target program, improving the operating efficiency of the target program, and improving system performance.

[0073] Step A2, in response to the memory access request of the target program, allocating page frames with continuous physical addresses and virtual addresses corresponding to the page frames to the target program, and writing the correspondence between the page frames and the virtual addresses as page table entries into the page table corresponding to the target program.

[0074] The step of obtaining a target page table entry to be accessed by the current program by querying the page table includes:

[0075] By querying the page table corresponding to the target program, a target page table entry including the corresponding relationship between the page frame and the virtual address is obtained.

[0076] In an embodiment of the present invention, the target program can apply for access to the memory through the huge page mechanism. When the target program triggers a page fault exception and the target program accesses the memory for the first time, there is no page table entry for the target program in the memory page table. Therefore, the memory will allocate a page frame with a continuous physical address and a virtual address corresponding to the page frame to the target program, and write the correspondence between the page frame and the virtual address as a page table entry in the page table corresponding to the target program.

[0077] Optionally, the target program may include preset parameters, and the preset parameters are used to instruct the target program to call a preset kernel function of the Linux operating system when it is started, and the preset kernel function is used to keep the page table corresponding to the target program resident in the memory during the running of the target program.

[0078] Each program is allocated a unique page table in the memory. When the system memory is insufficient, the page tables corresponding to some programs will be swapped from the memory to the auxiliary memory. This process is called swapping out. When a program's page table is swapped out, when the program accesses the memory again and searches for its target page table entry, since the page table storing the program's target page table entry no longer exists in the memory, the target page table entry needs to be reassigned to the program. This process takes a lot of time.

[0079] In order to further reduce the time for the target program to access the memory, the embodiment of the present invention calls a preset kernel function so that the page table corresponding to the target program can be resident in the memory and not swapped out during the operation of the target program, that is, it is ensured that each time the target program accesses the memory, the target page table entry of the target program can be directly found in the page table of the memory. Specifically, before starting the target program, preset parameters can be set in the target program, and the preset parameters are used to call the preset kernel function of the Linux operating system when the target program is started, such as the mprotect() function, so as to realize the page table corresponding to the target program to be resident in the memory by calling the mprotect() function. It can be understood that the embodiment of the present invention does not limit the specific type of the preset parameters. For example, the preset parameter can be a preset identification information. When the system starts the target program, if the identification information is detected, it is determined that the mprotect() function needs to be called to make the page table corresponding to the target program resident in the memory.

[0080] The mprotect() function can be used to modify the page table entry attributes. In the Linux operating system, the format of the page table entry includes 32 bits, of which the upper 20 bits from the 31st to the 12th are the base address, which is used to locate the physical address. The lower 12 bits from the 11th to the 0th are the page table entry attribute information. Among them, the 0th bit is the Present flag, which is used to indicate whether the page table is in the memory. The Present flag is 1, indicating that the page table is in the memory, and the Present flag is 0, indicating that the page table is not in the memory. The embodiment of the present invention modifies the page table entry attributes of the target program by calling the mprotect() function, and sets the Present flag to 1, so that the page table corresponding to the target program resides in the memory and will not be swapped from the memory to the auxiliary storage, thereby further reducing the memory access time of the target program, and giving priority to ensuring that the target program can be responded to in a timely manner.

[0081] Step 203: if the current program is the target program, the target page table entry is written into the reserved space in the TLB; if the current program is not the target program, the target page table entry to be accessed by the current program is written into the non-reserved space in the TLB.

[0082] Optionally, if the current program is a target program, writing the target page table entry into a reserved space in the TLB includes:

[0083] Step B1: If the current program is a target program, query whether there is free storage space in the reserved space of the TLB;

[0084] Step B2: If there is free storage space in the reserved space of the TLB, write the target page table entry to be accessed by the target program into the reserved space.

[0085] When the kernel page fault exception handler determines that the current program is the target program, the target page table entry to be accessed by the target program will be preferentially written into the reserved space in the TLB. However, the reserved space in the TLB is limited. Therefore, when it is determined that the current program is the target program, it is queried whether there is free storage space in the reserved space of the TLB. If there is free storage space in the reserved space of the TLB, the target page table entry to be accessed by the target program will be written into the reserved space.

[0086] Optionally, after querying whether there is free storage space in the reserved space of the TLB, the method may further include:

[0087] If there is no free storage space in the reserved space of the TLB, the target page table entry to be accessed by the target program is written into the non-reserved space in the TLB.

[0088] Furthermore, when there are a large number of preset target programs, different priorities can be set for different types of target programs. When there is free storage space in the reserved space of the TLB, the programs can be sorted according to the priority, and the target page table entries corresponding to the target programs with higher priorities can be written into the reserved space first. Alternatively, when there is no free storage space in the reserved space of the TLB, the target page table entries corresponding to the target programs with lower priorities in the reserved space of the TLB can be replaced with the target page table entries corresponding to the target programs with higher priorities.

[0089] In summary, the embodiments of the present invention improve memory access performance by receiving a memory access request of the target program based on a huge page mechanism, and keep the page table corresponding to the target program resident in the memory to reduce the time for memory reallocation of page table entries. In addition, the embodiment of the present invention can also prioritize the stable caching of page table entries corresponding to the target program by pre-setting reserved space for the target program in the TLB, thereby improving the TLB hit rate of the target program in each subsequent memory access process, reducing the occurrence of page fault exceptions in the target program, reducing the process of the target program again or repeatedly searching for page table entries in the memory page table, and improving the speed at which the target program obtains the target page table entries, so as to further optimize the time required for the target program to access the memory and improve the operating efficiency of memory access.

[0090] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0091] Device Embodiment

[0092] Reference Figure 3 , shows a structural block diagram of an embodiment of a memory access device of the present invention, which is applied to an electronic device running a Linux operating system. The device may specifically include the following modules:

[0093] The initialization module 301 is used to initialize the translation lookaside buffer TLB and set a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program.

[0094] The page table entry query module 302 is used to obtain the target page table entry to be accessed by the current program by querying the page table when the current program triggers a page fault exception. The target page table entry contains the mapping relationship between the physical address and the virtual address of the memory to be accessed by the current program.

[0095] The page table entry writing module 303 is used to write the target page table entry into the reserved space in the TLB if the current program is the target program.

[0096] Optionally, the initialization module includes:

[0097] The ratio determination submodule is used to determine the reserved ratio according to the number and type of preset target programs;

[0098] The space setting submodule is used to set the storage space of the reserved ratio in the TLB as the reserved space.

[0099] Optionally, the page table entry writing module is further used to write the target page table entry to be accessed by the current program into the non-reserved space in the TLB if the current program is not the target program.

[0100] Optionally, the device further comprises:

[0101] A request receiving module, used for receiving a memory access request of the target program based on a huge page mechanism;

[0102] a request response module, configured to respond to a memory access request of the target program, allocate page frames with continuous physical addresses and virtual addresses corresponding to the page frames to the target program, and write the correspondence between the page frames and the virtual addresses into a page table corresponding to the target program as a page table entry;

[0103] The page table entry query module is specifically used to obtain a target page table entry including a correspondence between the page frame and the virtual address by querying a page table corresponding to the target program.

[0104] Optionally, the page table entry writing module includes:

[0105] A space query submodule, for querying whether there is free storage space in the reserved space of the TLB if the current program is a target program;

[0106] The page table entry writing submodule writes the target page table entry to be accessed by the target program into the reserved space if there is free storage space in the reserved space of the TLB.

[0107] Optionally, the page table entry writing submodule is further used to write the target page table entry to be accessed by the target program into the non-reserved space in the TLB if there is no free storage space in the reserved space of the TLB.

[0108] Optionally, the target program includes preset parameters, and the preset parameters are used to instruct the target program to call a preset kernel function of the Linux operating system when it is started. The preset kernel function is used to keep the page table corresponding to the target program resident in the memory during the running of the target program.

[0109] In summary, the embodiment of the present invention sets a reserved space for the target program in the TLB, so that after the target program triggers a page fault exception for the first time, the target page table entry to be accessed by the target program will be written into the reserved space in the TLB, and during the running of the target program, the target page table entry to be accessed will not be replaced out of the TLB, which can minimize the occurrence of page fault exceptions in the target program, reduce the process of the target program again or repeatedly searching for page table entries in the memory page table, and improve the speed of the target program acquiring the target page table entry, so as to optimize the time required for the target program to access the memory and improve the operating efficiency of memory access.

[0110] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0111] An embodiment of the present invention provides an electronic device, which runs a Linux operating system. The electronic device includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors. The one or more programs include instructions for performing the following operations: initializing a translation lookaside buffer TLB and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of a target program, and the page table entries stored in the reserved space are not replaced during the operation of the target program; when a current program triggers a page fault exception, obtaining a target page table entry to be accessed by the current program by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program; and if the current program is the target program, writing the target page table entry into the reserved space in the TLB.

[0112] Figure 4 4 is a block diagram of an electronic device 400 for memory access according to an exemplary embodiment. For example, the electronic device 400 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0113] Reference Figure 4 , the electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power component 406 , a multimedia component 408 , an audio component 410 , an input / output (I / O) interface 412 , a sensor component 414 , and a communication component 416 .

[0114] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.

[0115] The memory 404 is configured to store various types of data to support operations on the device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, videos, etc. The memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

[0116] The power component 404 provides power to the various components of the electronic device 400. The power component 404 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 400.

[0117] The multimedia component 408 includes a screen that provides an output interface between the electronic device 400 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

[0118] The audio component 410 is configured to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.

[0119] I / O interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

[0120] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the device 400, the relative positioning of components, such as the display and keypad of the electronic device 400, and the sensor assembly 414 can also detect the position change of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and the temperature change of the electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0121] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 414 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 414 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

[0122] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.

[0123] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the instructions can be executed by a processor 420 of an electronic device 400 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0124] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a terminal, enables the terminal to perform a memory access method, the method comprising:

[0125] Initializing a translation lookaside buffer TLB, and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program;

[0126] In the case where the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying a page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program;

[0127] If the current program is the target program, the target page table entry is written into the reserved space in the TLB.

[0128] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0129] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0130] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0131] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing terminal device to operate in a predictable manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0133] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.

[0134] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal 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 terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.

[0135] The above is a detailed introduction to a memory access method and device, an electronic device and a storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a general technician in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A memory access method, characterized in that: Applied to an electronic device running a Linux operating system, the method comprises: Initializing a translation lookaside buffer TLB, and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program; In the case where the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying the page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of the memory to be accessed by the current program; If the current program is a target program, writing the target page table entry into the reserved space in the TLB; If the current program is a target program, the target page table entry is written into the reserved space in the TLB, including: if there is at least one target program, different priorities are set for target programs of different types; if there is free storage space in the reserved space of the TLB, the target page table entry corresponding to the target program with a high priority is sorted according to the priority, and the target page table entry corresponding to the target program with a high priority is preferentially written into the reserved space; if there is no free storage space in the reserved space of the TLB, the target page table entry corresponding to the target program with a low priority in the reserved space of the TLB is replaced with the target page table entry corresponding to the target program with a high priority; The initializing TLB includes: during the initialization phase of the Linux operating system, clearing the page table entries stored in the TLB by initializing a designated register inside the processor.

2. The method according to claim 1, characterized in that The step of setting a reserved space in the TLB includes: Determine the reserved ratio according to the number and type of preset target programs; The storage space of the reserved ratio in the TLB is set as the reserved space.

3. The method according to claim 2, characterized in that The method further comprises: If the current program is not the target program, the target page table entry to be accessed by the current program is written into the non-reserved space in the TLB.

4. The method according to any one of claims 1 to 3, characterized in that: In the case where the current program is a target program, before obtaining the target page table entry to be accessed by the current program by querying the page table, the method further includes: Receiving a memory access request of the target program based on a huge page mechanism; In response to a memory access request of the target program, allocating page frames with continuous physical addresses and virtual addresses corresponding to the page frames to the target program, and writing the correspondence between the page frames and the virtual addresses as page table entries into a page table corresponding to the target program; The step of obtaining a target page table entry to be accessed by the current program by querying the page table includes: By querying the page table corresponding to the target program, a target page table entry including the corresponding relationship between the page frame and the virtual address is obtained.

5. The method according to claim 1, characterized in that If the current program is a target program, writing the target page table entry into the reserved space in the TLB includes: If the current program is the target program, query whether there is free storage space in the reserved space of the TLB; If there is free storage space in the reserved space of the TLB, the target page table entry to be accessed by the target program is written into the reserved space.

6. The method according to claim 5, characterized in that After querying whether there is free storage space in the reserved space of the TLB, the method further includes: If there is no free storage space in the reserved space of the TLB, the target page table entry to be accessed by the target program is written into the non-reserved space in the TLB.

7. The method according to claim 4, characterized in that The target program includes preset parameters, and the preset parameters are used to instruct the target program to call a preset kernel function of the Linux operating system when it is started. The preset kernel function is used to keep the page table corresponding to the target program resident in the memory during the operation of the target program.

8. The method according to any one of claims 1-3, 5-6, characterized in that: The target program includes preset parameters, and the preset parameters are used to instruct the target program to call a preset kernel function of the Linux operating system when it is started. The preset kernel function is used to keep the page table corresponding to the target program resident in the memory during the operation of the target program.

9. A memory access device, characterized in that: Applicable to an electronic device running a Linux operating system, the device comprises: An initialization module, used for initializing a translation lookaside buffer TLB and setting a reserved space in the TLB, wherein the reserved space is used for storing page table entries of a target program, and the page table entries stored in the reserved space are not replaced during the running of the target program; A page table entry query module, used to obtain a target page table entry to be accessed by the current program by querying the page table when the current program triggers a page fault exception, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of a memory to be accessed by the current program; A page table entry writing module, used for writing the target page table entry into the reserved space in the TLB if the current program is a target program; The page table entry writing module is specifically used to: if there is at least one target program, set different priorities for different types of target programs; if there is free storage space in the reserved space of the TLB, sort them according to the priority, and preferentially write the target page table entry corresponding to the target program with a high priority into the reserved space; if there is no free storage space in the reserved space of the TLB, replace the target page table entry corresponding to the target program with a low priority in the reserved space of the TLB with the target page table entry corresponding to the target program with a high priority; The initialization module is specifically used to: during the initialization phase of the Linux operating system, clear the page table entries stored in the TLB by initializing the specified registers inside the processor.

10. An electronic device, characterized in that: The electronic device runs a Linux operating system, and includes a memory and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by one or more processors, and the one or more programs include instructions for performing the following operations: Initializing a translation lookaside buffer TLB, and setting a reserved space in the TLB, wherein the reserved space is used to store page table entries of the target program, and the page table entries stored in the reserved space are not replaced during the running of the target program; In the case where the current program triggers a page fault exception, a target page table entry to be accessed by the current program is obtained by querying the page table, wherein the target page table entry includes a mapping relationship between a physical address and a virtual address of the memory to be accessed by the current program; If the current program is a target program, writing the target page table entry into the reserved space in the TLB; If the current program is a target program, the target page table entry is written into the reserved space in the TLB, including: if there is at least one target program, different priorities are set for target programs of different types; if there is free storage space in the reserved space of the TLB, the target page table entry corresponding to the target program with a high priority is sorted according to the priority, and the target page table entry corresponding to the target program with a high priority is preferentially written into the reserved space; if there is no free storage space in the reserved space of the TLB, the target page table entry corresponding to the target program with a low priority in the reserved space of the TLB is replaced with the target page table entry corresponding to the target program with a high priority; The initializing TLB includes: during the initialization phase of the Linux operating system, clearing the page table entries stored in the TLB by initializing a designated register inside the processor.

11. A readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the memory access method as described in one or more of method claims 1-8.