Large page allocation method and device, equipment, storage medium and program product
By dynamically matching the virtual memory region size with the preset large page size, large pages are flexibly allocated, solving the problems of memory waste and high page fault rates in the Linux kernel and improving the application performance of electronic devices.
Patent Information
- Application Number
- CN202410925327.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2026-01-13
AI Technical Summary
In existing technologies, the Linux kernel of electronic devices uses a fixed large page size for memory management, which leads to memory waste or high page fault and TLB miss rates, affecting application performance.
By responding to page faults, the size of the virtual memory region corresponding to the virtual address is dynamically matched with different preset large page sizes, and the target large page is flexibly allocated, avoiding fixed size limitations and improving memory resource utilization.
It effectively reduces page fault rate and TLB miss rate, improves application performance, reduces memory resource consumption, and improves data transfer efficiency.
Smart Images

Figure CN121326541A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of terminal technology, and in particular to a large page allocation method, apparatus, device, storage medium, and program product. Background Technology
[0002] Currently, the Linux kernel for mobile phones and other electronic devices uses 4KB pages by default to manage the system's physical memory. However, as the amount of physical memory and application memory used by electronic devices increases, the page fault rate and Translation After Buffer (TLB) miss rate during application memory access also increase, affecting application performance.
[0003] To address the aforementioned issues, memory management can be improved by allocating large pages (i.e., pages larger than 4KB) to the application's process, thereby increasing data transfer efficiency and enhancing application performance.
[0004] However, related technologies typically allocate large pages according to a fixed page size, which sometimes leads to wasted memory and sometimes fails to effectively solve the problems of high page fault rates and high TLB misses. Summary of the Invention
[0005] To overcome the problems existing in the related technologies, this disclosure provides a large page allocation method, apparatus, device, storage medium, and program product to solve the defects in the related technologies.
[0006] According to a first aspect of the present disclosure, a large page allocation method is provided, the method comprising:
[0007] In response to a memory-triggered page fault detected during application execution, the virtual address required by the current process of the application is obtained;
[0008] The size of the virtual memory region corresponding to the virtual address is matched with different preset large page sizes to obtain the target large page size;
[0009] Allocate large pages for the current process of the application according to the target large page size.
[0010] In some embodiments, the method further includes:
[0011] In response to the virtual address supporting big page management, the operation of matching the size of the virtual memory region corresponding to the virtual address with different preset big page sizes is performed.
[0012] In some embodiments, the method further includes:
[0013] The virtual address is located within the valid virtual address range that allows the use of large pages;
[0014] In response to finding the virtual address, detect the physical pages allocated to the virtual memory region;
[0015] In response to the absence of the physical page, it is determined that the virtual address supports large page management.
[0016] In some embodiments, the method further includes:
[0017] In response to the virtual memory region not disabling the use of large pages, the operation of searching for the virtual address within the valid virtual address range that allows the use of large pages is performed.
[0018] In some embodiments, matching the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain the target large page size includes:
[0019] Arrange the preset different page sizes in descending order to obtain the different page sizes after arrangement;
[0020] The range of the virtual memory region is sequentially matched with each of the different large page sizes in the arrangement until the target large page size is obtained.
[0021] In some embodiments, matching the range of the virtual memory region sequentially with each of the arranged different large page sizes until the target large page size is obtained includes:
[0022] In response to the virtual memory region being less than or equal to the first largest page size among the different arranged large page sizes, and greater than the second largest page size among the different arranged large page sizes, the first largest page size is determined as the target large page size, and the second largest page size is the large page size among the different arranged large page sizes that is adjacent to the first large page size and located after the first large page size.
[0023] In some embodiments, the method further includes:
[0024] Identify the application type of the application;
[0025] Based on a pre-built correspondence, multiple different large page sizes corresponding to the program type are determined and used as the preset different large page sizes.
[0026] In some embodiments, the method further includes:
[0027] The detection system currently supports different page sizes, which are then used as the preset page sizes.
[0028] In some embodiments, the method further includes:
[0029] In response to allocating the large page to the current process of the application, a reverse mapping is established for the large page, and a page table is created for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
[0030] In some embodiments, the method further includes:
[0031] In response to allocating the large page to the current process of the application, update the reference count of the large page.
[0032] In some embodiments, the method further includes:
[0033] In response to allocating the large page to the current process of the application, the large page is added to the Least Recently Used (LRU) reclamation list.
[0034] According to a second aspect of the present disclosure, a large page allocation apparatus is provided, the apparatus comprising:
[0035] The address acquisition module is used to acquire the virtual address that the current process of the application needs to access in response to a memory-triggered page fault detected during the operation of the application.
[0036] The size acquisition module is used to match the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain the target large page size;
[0037] The large page allocation module is used to allocate large pages to the current process of the application according to the target large page size.
[0038] In some embodiments, the size acquisition module is further configured to, in response to the virtual address supporting big page management, perform the operation of matching the size of the virtual memory region corresponding to the virtual address with preset different big page sizes.
[0039] In some embodiments, the apparatus further includes a management determination module;
[0040] The management determination module includes:
[0041] The address lookup unit is used to look up the virtual address within the range of valid virtual addresses that allow the use of large pages;
[0042] A page detection unit is used to detect physical pages allocated to the virtual memory region in response to finding the virtual address;
[0043] A management determination unit is configured to determine, in response to the absence of a detected physical page, that the virtual address supports big page management.
[0044] In some embodiments, the address lookup unit is further configured to perform the operation of looking up the virtual address within the valid virtual address range that allows the use of large pages in response to the virtual memory region not disabling the use of large pages.
[0045] In some embodiments, the size acquisition module includes:
[0046] The size arrangement unit is used to arrange the preset different large page sizes in descending order to obtain the different large page sizes after arrangement;
[0047] The size matching unit is used to match the range of the virtual memory region sequentially with each of the different large page sizes in the arrangement until the target large page size is obtained.
[0048] In some embodiments, the size matching unit is further configured to determine the first large page size as the target large page size in response to the virtual memory region being less than or equal to the first large page size among the arranged different large page sizes and greater than the second large page size among the arranged different large page sizes, wherein the second large page size is the large page size among the arranged different large page sizes that is adjacent to the first large page size and located after the first large page size.
[0049] In some embodiments, the apparatus further includes a first size determination module;
[0050] The first size determination module includes:
[0051] A program type identification unit is used to identify the program type of the application.
[0052] The first size determination unit is used to determine multiple different large page sizes corresponding to the program type based on a pre-built correspondence, and to use these as the preset different large page sizes.
[0053] In some embodiments, the apparatus further includes:
[0054] The second size determination module is used to detect the different large page sizes currently supported by the system and use them as the preset different large page sizes.
[0055] In some embodiments, the apparatus further includes:
[0056] A mapping list establishment module is configured to, in response to the current process of allocating the large page to the application, establish a reverse mapping for the large page and establish a page table for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
[0057] In some embodiments, the apparatus further includes:
[0058] A reference count update module is used to update the reference count of the large page in response to the current process of the application allocating the large page.
[0059] In some embodiments, the apparatus further includes:
[0060] A recycling list addition module is used to add the large page to the least recently used (LRU) recycling list in response to allocating the large page to the current process of the application.
[0061] According to a third aspect of the present disclosure, an electronic device is provided, the device comprising:
[0062] Processor and memory used to store computer programs;
[0063] The processor is configured to implement the large page allocation method described in any one of the first aspects when executing the computer program.
[0064] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the large page allocation method described in any one of the first aspects above.
[0065] According to a fifth aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the big page allocation method described in any one of the first aspects.
[0066] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:
[0067] This disclosure, in response to a memory-triggered page fault detected during application execution, obtains the virtual address required by the current process of the application, matches the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain a target large page size, and then allocates large pages to the current process of the application according to the target large page size. Since there is no fixed large page size restriction, large pages of appropriate size can be flexibly allocated according to the size of the virtual memory region, thereby avoiding excessive memory resource consumption, improving memory resource utilization, and effectively solving the problems of increased page fault rate and TLB miss, thus improving application performance.
[0068] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0069] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0070] Figure 1A This is a schematic diagram illustrating the principle of big page memory management according to an exemplary embodiment of the present disclosure;
[0071] Figure 1B This is a flowchart illustrating a large page allocation method according to an exemplary embodiment of the present disclosure;
[0072] Figure 2 This is a flowchart illustrating how to determine if the virtual address supports big page management, according to an exemplary embodiment of this disclosure;
[0073] Figure 3 This is a flowchart illustrating, according to an exemplary embodiment of the present disclosure, how to match the size of the virtual memory region corresponding to the virtual address with preset different large page sizes;
[0074] Figure 4 This is a flowchart illustrating how to determine the preset different large page sizes according to an exemplary embodiment of this disclosure;
[0075] Figure 5 This is a flowchart illustrating a large page allocation method according to another exemplary embodiment of the present disclosure;
[0076] Figure 6 This is a block diagram illustrating a large page allocation device according to an exemplary embodiment of the present disclosure;
[0077] Figure 7 This is a block diagram illustrating yet another large page allocation device according to an exemplary embodiment of the present disclosure;
[0078] Figure 8 This is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure. Detailed Implementation
[0079] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0080] Memory management technology refers to the techniques used by operating systems to manage and optimize computer memory, including virtual memory management, memory allocation, memory protection, memory sharing, and memory reclamation. As an open-source operating system, Linux's memory management technology has wide application and research value in the operating system field.
[0081] Currently, the Linux kernel for mobile phones and other electronic devices uses 4KB pages by default to manage the system's physical memory. However, as the amount of physical memory and application memory used by electronic devices increases, the page fault rate and Translation After Buffer (TLB) miss rate during application memory access also increase, affecting application performance.
[0082] For example, such as Figure 1A As shown, when using 4KB pages for management, a single page fault allocates one 4KB page and establishes a 4KB memory mapping. For 64KB of contiguous memory access, the system generates 16 page faults and establishes 16 memory mappings.
[0083] To address the aforementioned issues, memory management can be improved by allocating large pages (i.e., pages larger than 4KB) to the application's process, thereby increasing data transfer efficiency and enhancing application performance.
[0084] For example, Figure 1A This is a schematic diagram illustrating the principle of large page memory management according to an exemplary embodiment of this disclosure; as shown below. Figure 1AAs shown, when using standard 4KB pages for memory management, a single page fault allocates a 4KB page and establishes a 4KB memory mapping. Therefore, for a contiguous 64KB memory access, the system would generate 16 page faults and require 16 memory mappings. However, if large 64KB pages are used for memory management, for the same contiguous 64KB memory access, the system only needs to generate one page fault to allocate 64KB of physical memory. This improves data transfer efficiency, reduces the page fault rate and TLB miss rate, and ultimately enhances application performance.
[0085] However, related technologies typically allocate large pages according to a fixed page size, such as 2MB. This approach leads to wasted system memory when the fixed page size exceeds the application's requirements; conversely, when the fixed size is less than the application's requirements, it still results in increased page fault rates and TLB misses, thus impacting application performance and leading to higher system power consumption.
[0086] In view of this, the present disclosure provides the following large page allocation methods, apparatus, devices, storage media, and program products to solve the aforementioned drawbacks in the related art.
[0087] Figure 1B This is a flowchart illustrating a massive page allocation method according to an exemplary embodiment. The method of this embodiment can be executed by a massive page allocation device, which can be configured in an electronic device (such as a mobile phone, tablet computer, etc.) with an Android operating system (hereinafter referred to as the "system"), which is built based on the Linux kernel. Figure 1B As shown, the method includes the following steps S101-S103:
[0088] In step S101, in response to a memory-triggered page fault detected during application execution, the virtual address required by the current process of the application is obtained.
[0089] In this embodiment, when a memory-triggered page fault is detected during the operation of an application, the electronic device can obtain the virtual address (i.e., the page fault address) that the current process of the application needs to access.
[0090] For example, when the current process of an application attempts to access an address in its virtual address space, if the physical page corresponding to that address is not in random access memory (RAM) (for example, it may have been swapped out to the swap space on the disk), the memory will generate a page fault. The operating system kernel of the electronic device will then catch the page fault and look up the virtual address that caused the page fault.
[0091] In step S102, the size of the virtual memory region corresponding to the virtual address is matched with preset different large page sizes to obtain the target large page size.
[0092] In this embodiment, after obtaining the virtual address that the current process of the application needs to access, the virtual memory area (VMA) corresponding to the virtual address can be determined, and then the size of the virtual memory area can be matched with different preset large page sizes to obtain the target large page size.
[0093] The preset page sizes mentioned above are all or part of 2MB, 1MB, 512KB, 256KB, 128KB, 64KB, 32KB and 16KB, and this embodiment does not limit them.
[0094] In some embodiments, when an electronic device detects a memory-triggered page fault during application execution, it can detect the different large page sizes currently supported by the system and use them as the preset different large page sizes. It is understood that the supported different large page sizes will change depending on the system's memory usage status.
[0095] For example, if the system currently supports different page sizes of 64KB, 32KB, and 16KB, then these three page sizes can be used as the preset different page sizes mentioned above; or, if the system currently supports different page sizes of 2MB, 1MB, 512KB, 256KB, 128KB, 64KB, 32KB, and 16KB, then these eight page sizes can be used as the preset different page sizes mentioned above.
[0096] The target large page size can be slightly larger than the size of the virtual memory region mentioned above, or equal to the size of the virtual memory region among the preset large page sizes. In this way, while implementing memory management based on large page technology, excessive memory resources can be avoided by allocating large pages.
[0097] In other embodiments, the method of matching the size of the virtual memory region corresponding to the virtual address with preset different large page sizes can be found in the following: Figure 3 The embodiments shown will not be described in detail here.
[0098] In step S103, a large page is allocated to the current process of the application according to the target large page size.
[0099] In this embodiment, after matching the size of the virtual memory region corresponding to the virtual address with preset large page sizes to obtain the target large page size, large pages can be allocated to the current process of the application according to the target large page size. This allows the current process of the application to utilize the allocated large pages for memory management, thereby improving application performance (e.g., reducing frame drops during application startup, reducing application startup time, etc.). Therefore, this embodiment can allocate large pages of different sizes to applications of different sizes (including applications that require access to different sizes of virtual memory regions). Compared to the related technologies that allocate fixed-size large pages to various applications, this embodiment improves the flexibility of large page allocation. It is understood that large pages can reduce the size of the page table, thereby reducing TLB misses. This can accelerate the translation process from virtual address to physical address. Reducing the number of page table entries means that when accessing contiguous large blocks of memory, the CPU cache and TLB will have a higher hit rate, reducing the cache and TLB refresh frequency, thereby improving memory access speed.
[0100] For example, if the target large page size is 64KB, then a large page of 64KB can be allocated to the current process of the application, that is, a large page of 64KB size can be allocated to the current process of the application.
[0101] It is worth noting that, based on determining the target big page size, the method for allocating big pages to the current process of the application can refer to the big page allocation methods in related technologies, and this embodiment does not limit this.
[0102] In other embodiments, after allocating large pages to the current process of the application according to the target large page size, subsequent large page allocation processes can be executed, such as establishing page tables and reverse mappings for the allocated large pages. This exemplary content can be found in [reference needed]. Figure 5 The embodiments shown will not be described in detail here.
[0103] As described above, the method of this embodiment, in response to a memory-triggered page fault detected during application execution, obtains the virtual address required by the current process of the application, matches the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain a target large page size, and then allocates large pages to the current process of the application according to the target large page size. Since there is no fixed large page size restriction, large pages of appropriate size can be flexibly allocated according to the size of the virtual memory region, thereby avoiding excessive memory resource occupation, improving memory resource utilization, and effectively solving the problems of increased page fault rate and TLB miss, thus improving application performance.
[0104] In some embodiments, before matching the size of the virtual memory region corresponding to the virtual address with preset different huge page sizes, in order to ensure the implementation of the scheme, it can be determined whether the virtual address supports huge page management. Then, in response to the virtual address supporting huge page management, the operation of matching the size of the virtual memory region corresponding to the virtual address with preset different huge page sizes described in step S102 can be executed.
[0105] For example, Figure 2 This is a flowchart illustrating how to determine if a virtual address supports huge page management, according to an exemplary embodiment of this disclosure; this embodiment provides an illustrative example of how to determine if a virtual address supports huge page management, based on the above embodiment. Figure 2 As shown, the big page allocation method in this embodiment may further include determining, based on the following steps S201-S206, that the virtual address supports big page management:
[0106] In step S201, the virtual address is searched within the range of valid virtual addresses that allow the use of large pages.
[0107] In this embodiment, a range of valid virtual addresses that are allowed to use large pages can be preset. Then, when it is determined whether the above virtual address supports large page management, the virtual address can be searched within the preset range of valid virtual addresses.
[0108] In step S202, is the virtual address found? If yes, proceed to step S203; if no, proceed to step S206.
[0109] In this embodiment, if the virtual address is found within the valid virtual address range, step S203 can be continued; otherwise, the current process ends.
[0110] In step S203, the physical pages allocated to the virtual memory region are detected.
[0111] In this embodiment, after the virtual address is found within the valid virtual address range, the physical pages allocated to the virtual memory region can be detected. The purpose of this operation is to determine whether the virtual memory region has not been allocated physical pages.
[0112] In step S204, is the physical page detected? If not, proceed to step S205; if yes, proceed to step S206.
[0113] In step S205, it is determined that the virtual address supports big page management.
[0114] In step S206, the process ends.
[0115] In this embodiment, when no physical pages are detected allocated for the virtual memory region, it can be determined whether the virtual memory region has not been allocated physical pages, and thus it can be determined that the virtual address supports big page management.
[0116] In other embodiments, the operation of searching for the virtual address within the valid virtual address range that allows the use of large pages, as described in step S201 above, can also be performed in response to the detection that the virtual memory region does not disable the use of large pages.
[0117] In other words, as an exemplary embodiment, if a virtual address meets the following conditions, it can be determined that the virtual address supports big page management:
[0118] (1) The virtual memory region corresponding to the virtual address does not disable the use of large pages;
[0119] (2) The virtual address can be found within the valid virtual address range that allows the use of large pages;
[0120] (3) No physical pages have been allocated to the virtual memory region corresponding to the virtual address.
[0121] As described above, this embodiment, in response to the virtual memory region not disabling the use of big pages, searches for the virtual address within the valid virtual address range that allows the use of big pages. Then, in response to finding the virtual address, it detects the physical page allocated to the virtual memory region. Furthermore, in response to not detecting the physical page, it determines that the virtual address supports big page management. This allows for accurate determination of whether a virtual address supports big page management. Consequently, if the virtual address is determined to support big page management, the subsequent big page allocation process can be implemented, improving the feasibility of the solution.
[0122] Figure 3This is a flowchart illustrating how to match the size of the virtual memory region corresponding to the virtual address with preset different page sizes, according to an exemplary embodiment of this disclosure. This embodiment is based on the above embodiment and uses the example of how to match the size of the virtual memory region corresponding to the virtual address with preset different page sizes for illustrative purposes.
[0123] like Figure 3 As shown, the step S102 above, which involves matching the size of the virtual memory region corresponding to the virtual address with preset different large page sizes, may include the following steps S301-S302:
[0124] In step S301, the preset different page sizes are arranged in descending order to obtain the different page sizes after arrangement.
[0125] In this embodiment, when matching the size of the virtual memory region corresponding to the virtual address with preset different page sizes, the preset different page sizes can be arranged in descending order to obtain the arranged different page sizes.
[0126] For example, if the preset different page sizes are 32KB, 16KB and 64KB, then these three page sizes can be arranged in descending order to obtain the different page sizes after arrangement, namely 64KB, 32KB and 16KB.
[0127] In step S302, the range of the virtual memory region is sequentially matched with each of the different large page sizes in the arrangement until the target large page size is obtained.
[0128] In this embodiment, after obtaining the different page sizes after arrangement, the range of the virtual memory region can be matched sequentially with each page size in the different page sizes after arrangement until the target page size is obtained.
[0129] In some embodiments, the first large page size may be determined as the target large page size in response to the fact that the range of the virtual memory region is less than or equal to the first large page size among the different large page sizes after arrangement, and greater than the second large page size among the different large page sizes after arrangement.
[0130] The second largest page size can be the largest page size that is adjacent to and follows the first largest page size among the different page sizes after the arrangement.
[0131] Taking the different page sizes after arrangement as 64KB, 32KB, and 16KB as an example, assuming the range of the virtual memory region is 56KB, we can match this 56KB with each of the sizes 64KB, 32KB, and 16KB in turn: after matching 56KB with 64KB, since 56KB is less than 64KB, we continue to match 56KB with 32KB; since 56KB is greater than 32KB, and 32KB is the page size adjacent to 64KB, we can determine 64KB as the target page size.
[0132] It is understood that the above-mentioned different large page sizes of 64KB, 32KB, and 16KB, and the virtual memory region range of 56KB, are for illustrative purposes only and are not intended to limit the scope of this disclosure.
[0133] For example, different types of huge pages can be enabled or disabled separately using the sys node: / sys / kernel / mm / transparent_hugepages / hugepages-Xkb / enabled. The values of the enabled attribute and their meanings are shown in Table 1 below:
[0134] Table 1
[0135]
[0136] As shown in Table 1 above, when a page fault occurs, the supported big page types can be obtained based on the current sys node settings, and then big pages can be allocated in descending order of big page size.
[0137] As described above, this embodiment arranges the preset different large page sizes in descending order to obtain the arranged different large page sizes. The range of the virtual memory region is then matched sequentially with each of the arranged different large page sizes until the target large page size is obtained. This allows for the reasonable determination of the target large page size by matching the size of the virtual memory region corresponding to the virtual address with the preset different large page sizes. Consequently, large pages can be allocated to the current process of the application according to the target large page size, avoiding excessive memory resource consumption, improving memory resource utilization, and effectively solving the problems of increased page fault rates and TLB misses, thereby improving application performance.
[0138] Figure 4 This is a flowchart illustrating how to determine the preset different large page sizes according to an exemplary embodiment of the present disclosure; this embodiment is based on the above embodiment and takes how to determine the preset different large page sizes as an example for illustrative explanation.
[0139] like Figure 4 As shown, the large page allocation method in this embodiment may further include determining the preset different large page sizes based on the following steps S401-S402:
[0140] In step S401, the application type of the application is identified.
[0141] For example, various applications on an electronic device (including applications that can be installed or are already installed) can be pre-classified. Applications with an expected memory usage exceeding a preset threshold (such as at least one of a game, browser, or multimedia editing application) can be classified as "high-memory applications," while applications with an expected memory usage below the preset threshold can be classified as "low-memory applications." Based on this, when a memory-triggered page fault is detected during application execution, the application's category can be identified.
[0142] In step S402, based on the pre-built correspondence, multiple different large page sizes corresponding to the program type are determined and used as the preset different large page sizes.
[0143] In this embodiment, after the application type is identified, multiple different large page sizes corresponding to the application type can be determined based on a pre-built correspondence, and these can be used as the preset different large page sizes.
[0144] In other words, after pre-classifying the types of various applications in the electronic device, this embodiment can construct a correspondence between each type and multiple different large page sizes. Then, when the application type is identified, multiple different large page sizes corresponding to that application type can be determined based on this correspondence, serving as the preset different large page sizes to match the size of the virtual memory region corresponding to the virtual address. For example, the above correspondence can be shown in Table 2 below:
[0145] Table 2
[0146]
[0147]
[0148] As shown in Table 1 above, the range of different large page sizes corresponding to high-memory applications is 16KB to 2MB, while the range of different large page sizes corresponding to low-memory applications is 16KB to 64KB. This means the range of different large page sizes for high-memory applications is larger than that for low-memory applications. Therefore, when an application is subsequently determined to be a low-memory application, its corresponding preset different large page sizes can be determined to be "64KB, 32KB, 16KB". Compared to preset different large page sizes of "2MB, 1MB, 512KB, 256KB, 128KB, 64KB, 32KB, 16KB", this improves the efficiency of matching the size of the virtual memory region corresponding to the virtual address with the preset different large page sizes, and is also beneficial for allocating a reasonable large page size for the current process of the application.
[0149] As described above, this embodiment identifies the application's program type and determines multiple different large page sizes corresponding to the program type based on a pre-built correspondence. These large page sizes are then used as preset different large page sizes. This allows for a more accurate and reasonable determination of the preset different large page sizes based on the application's program type. This improves the efficiency of matching the size of the virtual memory region corresponding to the virtual address with the preset different large page sizes. It facilitates the efficient allocation of reasonably sized large pages to the current process of the application, thereby improving memory resource utilization. Furthermore, it effectively solves the problems of increased page fault rates and TLB misses, ultimately enhancing application performance.
[0150] Figure 5 This is a flowchart illustrating a large page allocation method according to another exemplary embodiment of the present disclosure; the method of this embodiment can be executed by a large page allocation device, which can be configured in an electronic device (such as a mobile phone, tablet computer, etc.) with an Android operating system, which is built based on the Linux kernel. Figure 5 As shown, the method includes the following steps S501-S506:
[0151] In step S501, in response to a memory-triggered page fault detected during application execution, the virtual address required by the current process of the application is obtained.
[0152] In step S502, the size of the virtual memory region corresponding to the virtual address is matched with preset different large page sizes to obtain the target large page size.
[0153] In step S503, a large page is allocated to the current process of the application according to the target large page size.
[0154] For example, large page (e.g., anonymous large pages) allocation can be performed based on the kernel function alloc_anon_folio. This function can be used to allocate physical memory from the large page pool according to the target large page size.
[0155] The explanations and descriptions of steps S501 to S503 can be found above. Figure 1B Steps S101-S103 in the illustrated embodiment will not be described in detail here.
[0156] In step S504, in response to allocating the large page to the current process of the application, a reverse mapping is established for the large page, and a page table is established for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
[0157] In this embodiment, after the large page is allocated to the current process of the application, a reverse mapping can be established for the large page.
[0158] For example, when the aforementioned large page is allocated to the current process of the application, the operating system records the physical address of this large page and its location in the process's virtual address space, storing this information in a data structure. This data structure can be a hash table, linked list, or other form of data structure for fast subsequent lookups. Furthermore, when the large page needs to be reclaimed or reallocated, the operating system can quickly find all virtual addresses referencing the large page by querying the aforementioned reverse mapping data structure and update or delete the corresponding page table entries.
[0159] For example, a preset kernel function, such as folio_add_new_anon_rmap, can be used to establish the reverse mapping, but this embodiment does not limit this.
[0160] Furthermore, after allocating the large page to the current process of the application, a page table can be created for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
[0161] For example, the page table created for the aforementioned large page can include a special page table entry (PTE) that contains the large page's physical address and attribute information, such as read / write, executable, and caching policies. In some embodiments, the page table structure can be modified to support large pages. For instance, when using multi-level page tables, entries pointing to the aforementioned large page can be added to the higher-level page table.
[0162] For example, a preset kernel function, such as set_ptea(nr_pages), can be used to create page tables for large pages. For instance, page tables can be created in 4KB sizes, but this embodiment does not limit this.
[0163] In step S505, in response to allocating the large page to the current process of the application, the reference count of the large page is updated.
[0164] In the Linux kernel, once a large page is allocated, its reference count can be incremented to track how many virtual address spaces are using this physical page. This ensures that the physical page is not mistakenly reclaimed or reallocated before all references are released.
[0165] In some embodiments, increasing the number of large page references can be achieved through a predefined kernel function, such as folio_ref_add(nr_pages).
[0166] In step S506, in response to allocating the large page to the current process of the application, the large page is added to the least recently used (LRU) reclamation list.
[0167] Understandably, in operating system memory management, the Least Recently Used (LRU) linked list is a data structure used in page replacement algorithms. It helps the operating system decide which pages should be evicted under memory pressure. When physical memory is insufficient, the operating system needs to select some pages from memory to swap out to disk to make room for new pages. The LRU linked list sorts pages according to their usage frequency and most recent usage time, ensuring that the least recently used page is at the end of the list, becoming the most likely candidate to be swapped out. For large pages, because they occupy more physical memory space, how effectively the lifecycle and reclamation strategy of large pages are managed is crucial to system performance.
[0168] In some embodiments, adding a large page to the LRU reclamation list means:
[0169] Whenever a large page is accessed, its position in the LRU list is updated to reflect its most recent usage. Specifically, the newly accessed large page is moved to the head of the list, indicating it was recently used. Therefore, when a large page hasn't been accessed for a long time, it gradually moves to the tail of the LRU list. Consequently, when the system needs to reclaim memory, the large page at the tail of the list will be swapped out first, as it is considered the least recently used.
[0170] For example, a pre-defined kernel function, such as folio_add_lru_vma(), can be used to add large pages to the LRU list.
[0171] As described above, this embodiment, in response to allocating the large page to the current process of the application, establishes a reverse mapping for the large page and a page table for the large page. This enables the mapping of contiguous segments in the virtual memory region to the physical address of the large page. Furthermore, by updating the reference count of the large page and adding it to the Least Recently Used (LRU) reclamation list, it is beneficial to reclaim the memory resources occupied by the large page when the system needs to reclaim memory, thereby improving the system's memory resource utilization.
[0172] Figure 6 This is a block diagram illustrating a large page allocation apparatus according to an exemplary embodiment of the present disclosure; the apparatus of this embodiment can be configured in an electronic device (such as a mobile phone, tablet computer, etc.) with an Android operating system, which is built based on the Linux kernel. Figure 6 As shown, the device may include: an address acquisition module 110, a size acquisition module 120, and a large page allocation module 130, wherein:
[0173] Address acquisition module 110 is used to acquire the virtual address that the current process of the application needs to access in response to a memory-triggered page fault detected during the operation of the application.
[0174] The size acquisition module 120 is used to match the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain the target large page size;
[0175] The large page allocation module 130 is used to allocate large pages to the current process of the application according to the target large page size.
[0176] As described above, the device in this embodiment, in response to a memory-triggered page fault detected during application execution, obtains the virtual address required by the current process of the application, matches the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain a target large page size, and then allocates large pages to the current process of the application according to the target large page size. Since there is no fixed large page size restriction, large pages of appropriate size can be flexibly allocated according to the size of the virtual memory region, thereby avoiding excessive memory resource occupation, improving memory resource utilization, and effectively solving the problems of increased page fault rate and TLB miss, thus improving application performance.
[0177] Figure 7This is a block diagram illustrating a big page allocation device according to an exemplary embodiment of the present disclosure. The device of this embodiment can be configured in an electronic device (such as a mobile phone, tablet computer, etc.) with an Android operating system, which is built based on the Linux kernel. The address acquisition module 210, size acquisition module 220, and big page allocation module 230 are as described above. Figure 6 The address acquisition module 110, size acquisition module 120 and big page allocation module 130 in the illustrated embodiment have the same function, and will not be described in detail here.
[0178] like Figure 7 As shown, the size acquisition module 220 can also be used to perform the operation of matching the size of the virtual memory region corresponding to the virtual address with different preset big page sizes in response to the virtual address supporting big page management.
[0179] In some embodiments, the above-described apparatus may further include a management determination module 240;
[0180] The management determination module 240 may include:
[0181] Address lookup unit 241 is used to look up the virtual address within the range of valid virtual addresses that allow the use of large pages;
[0182] Page detection unit 242 is used to detect physical pages allocated to the virtual memory region in response to finding the virtual address;
[0183] The management determination unit 243 is configured to determine, in response to the absence of the physical page, that the virtual address supports big page management.
[0184] In some embodiments, the address lookup unit 241 described above can also be used to perform the operation of looking up the virtual address within the valid virtual address range that allows the use of large pages in response to the virtual memory region not disabling the use of large pages.
[0185] In some embodiments, the size acquisition module 220 described above may include:
[0186] Size arrangement unit 221 is used to arrange the preset different large page sizes in descending order to obtain the different large page sizes after arrangement;
[0187] Size matching unit 222 is used to match the range of the virtual memory region sequentially with each of the different page sizes in the arrangement until the target page size is obtained.
[0188] In some embodiments, the size matching unit 222 may also be used to determine the first large page size as the target large page size in response to the range of the virtual memory region being less than or equal to the first large page size among the different large page sizes after arrangement, and greater than the second large page size among the different large page sizes after arrangement, wherein the second large page size is the large page size among the different large page sizes after arrangement that is adjacent to the first large page size and located after the first large page size.
[0189] In some embodiments, the above-described apparatus may further include a first size determination module 250;
[0190] The first size determination module 250 may include:
[0191] The program type identification unit 251 is used to identify the program type of the application.
[0192] The first size determination unit 252 is used to determine multiple different large page sizes corresponding to the program type based on a pre-built correspondence, and to use these as the preset different large page sizes.
[0193] In some embodiments, the above-described apparatus may further include:
[0194] The second size determination module 260 is used to detect the different large page sizes currently supported by the system and use them as the preset different large page sizes.
[0195] In some embodiments, the above-described apparatus may further include:
[0196] The mapping list establishment module 270 is configured to, in response to allocating the large page to the current process of the application, establish a reverse mapping for the large page and establish a page table for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
[0197] In some embodiments, the above-described apparatus may further include:
[0198] The reference count update module 280 is used to update the reference count of the large page in response to allocating the large page to the current process of the application.
[0199] In some embodiments, the above-described apparatus may further include:
[0200] The recycling list addition module 290 is configured to add the large page to the least recently used (LRU) recycling list in response to allocating the large page to the current process of the application.
[0201] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0202] Figure 8 This is a block diagram illustrating an electronic device according to an exemplary embodiment. For example, device 900 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness device, personal digital assistant, etc.
[0203] Reference Figure 8 The device 900 may include one or more of the following components: a processing component 902, a memory 904, a power supply component 906, a multimedia component 908, an audio component 910, an input / output (I / O) interface 912, a sensor component 914, and a communication component 916.
[0204] Processing component 902 typically controls the overall operation of device 900, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 902 may include one or more processors 920 to execute instructions to complete all or part of the steps of the large page allocation method described above. Furthermore, processing component 902 may include one or more modules to facilitate interaction between processing component 902 and other components. For example, processing component 902 may include a multimedia module to facilitate interaction between multimedia component 908 and processing component 902.
[0205] Memory 904 is configured to store various types of data to support the operation of device 900. Examples of this data include instructions for any application or method operating on device 900, contact data, phonebook data, messages, pictures, videos, etc. Memory 904 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 storage, flash memory, magnetic disk, or optical disk.
[0206] Power supply component 906 provides power to various components of device 900. Power supply component 906 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to device 900.
[0207] Multimedia component 908 includes a screen that provides an output interface between the device 900 and the user. In some embodiments, the screen may include a liquid crystal display panel and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 908 includes a front-facing camera and / or a rear-facing camera. When the device 900 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0208] Audio component 910 is configured to output and / or input audio signals. For example, audio component 910 includes a microphone (MIC) configured to receive external audio signals when device 900 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 904 or transmitted via communication component 916. In some embodiments, audio component 910 also includes a speaker for outputting audio signals.
[0209] I / O interface 912 provides an interface between processing component 902 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0210] Sensor assembly 914 includes one or more sensors for providing status assessments of various aspects of device 900. For example, sensor assembly 914 can detect the on / off state of device 900, the relative positioning of components such as the display panel and keypad of device 900, changes in the position of device 900 or a component of device 900, the presence or absence of user contact with device 900, the orientation or acceleration / deceleration of device 900, and temperature changes of device 900. Sensor assembly 914 may also include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 914 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 914 may also include an accelerometer, a gyroscope, a magnetometer, a pressure sensor, or a temperature sensor.
[0211] Communication component 916 is configured to facilitate wired or wireless communication between device 900 and other devices. Device 900 can access wireless networks based on communication standards, such as WiFi, 2G or 3G, 4G or 5G, or combinations thereof. In one exemplary embodiment, communication component 916 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 916 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0212] In an exemplary embodiment, device 900 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 large page allocation method described above.
[0213] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 904 including instructions, which can be executed by a processor 920 of device 900 to complete the above-described large page allocation method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0214] In an exemplary embodiment, a computer program product including instructions is also provided, which can be executed by the processor 920 of the device 900 to perform the above-described big page allocation method.
[0215] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the foregoing claims.
[0216] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A large page allocation method, characterized in that, The method includes: In response to a memory-triggered page fault detected during application execution, the virtual address required by the current process of the application is obtained; The size of the virtual memory region corresponding to the virtual address is matched with different preset large page sizes to obtain the target large page size; Allocate large pages for the current process of the application according to the target large page size.
2. The method according to claim 1, characterized in that, The method further includes: In response to the virtual address supporting big page management, the operation of matching the size of the virtual memory region corresponding to the virtual address with different preset big page sizes is performed.
3. The method according to claim 2, characterized in that, The method further includes: The virtual address is located within the valid virtual address range that allows the use of large pages; In response to finding the virtual address, detect the physical pages allocated to the virtual memory region; In response to the absence of the physical page, it is determined that the virtual address supports large page management.
4. The method according to claim 3, characterized in that, The method further includes: In response to the virtual memory region not disabling the use of large pages, the operation of searching for the virtual address within the valid virtual address range that allows the use of large pages is performed.
5. The method according to claim 1, characterized in that, The step of matching the size of the virtual memory region corresponding to the virtual address with preset large page sizes to obtain the target large page size includes: Arrange the preset different page sizes in descending order to obtain the different page sizes after arrangement; The range of the virtual memory region is sequentially matched with each of the different large page sizes in the arrangement until the target large page size is obtained.
6. The method according to claim 5, characterized in that, The step of sequentially matching the range of the virtual memory region with each of the arranged different large page sizes until the target large page size is obtained includes: In response to the virtual memory region being less than or equal to the first largest page size among the different arranged large page sizes, and greater than the second largest page size among the different arranged large page sizes, the first largest page size is determined as the target large page size, and the second largest page size is the large page size among the different arranged large page sizes that is adjacent to the first large page size and located after the first large page size.
7. The method according to claim 1, characterized in that, The method further includes: Identify the application type of the application; Based on a pre-built correspondence, multiple different large page sizes corresponding to the program type are determined and used as the preset different large page sizes.
8. The method according to claim 1, characterized in that, The method further includes: The detection system currently supports different page sizes, which are then used as the preset page sizes.
9. The method according to claim 1, characterized in that, The method further includes: In response to allocating the large page to the current process of the application, a reverse mapping is established for the large page, and a page table is created for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
10. The method according to claim 1, characterized in that, The method further includes: In response to allocating the large page to the current process of the application, update the reference count of the large page.
11. The method according to claim 1, characterized in that, The method further includes: In response to allocating the large page to the current process of the application, the large page is added to the Least Recently Used (LRU) reclamation list.
12. A large page dispensing device, characterized in that, The device includes: The address acquisition module is used to acquire the virtual address that the current process of the application needs to access in response to a memory-triggered page fault detected during the operation of the application. The size acquisition module is used to match the size of the virtual memory region corresponding to the virtual address with preset different large page sizes to obtain the target large page size; The large page allocation module is used to allocate large pages to the current process of the application according to the target large page size.
13. The apparatus according to claim 12, characterized in that, The size acquisition module is also used to perform the operation of matching the size of the virtual memory region corresponding to the virtual address with different preset big page sizes in response to the virtual address supporting big page management.
14. The apparatus according to claim 13, characterized in that, The device also includes a management and determination module; The management determination module includes: The address lookup unit is used to look up the virtual address within the range of valid virtual addresses that allow the use of large pages; A page detection unit is used to detect physical pages allocated to the virtual memory region in response to finding the virtual address; A management determination unit is configured to determine, in response to the absence of a detected physical page, that the virtual address supports big page management.
15. The apparatus according to claim 14, characterized in that, The address lookup unit is also configured to, in response to the virtual memory region not disabling the use of large pages, perform the operation of looking up the virtual address within the valid virtual address range that allows the use of large pages.
16. The apparatus according to claim 12, characterized in that, The size acquisition module includes: The size arrangement unit is used to arrange the preset different large page sizes in descending order to obtain the different large page sizes after arrangement; The size matching unit is used to match the range of the virtual memory region sequentially with each of the different large page sizes in the arrangement until the target large page size is obtained.
17. The apparatus according to claim 16, characterized in that, The size matching unit is further configured to, in response to the virtual memory region being less than or equal to the first largest page size among the arranged different large page sizes and greater than the second largest page size among the arranged different large page sizes, determine the first large page size as the target large page size, wherein the second large page size is the large page size among the arranged different large page sizes that is adjacent to the first large page size and located after the first large page size.
18. The apparatus according to claim 12, characterized in that, The device also includes a first size determination module; The first size determination module includes: A program type identification unit is used to identify the program type of the application. The first size determination unit is used to determine multiple different large page sizes corresponding to the program type based on a pre-built correspondence, and to use these as the preset different large page sizes.
19. The apparatus according to claim 12, characterized in that, The device further includes: The second size determination module is used to detect the different large page sizes currently supported by the system and use them as the preset different large page sizes.
20. The apparatus according to claim 12, characterized in that, The device further includes: A mapping list establishment module is configured to, in response to the current process of allocating the large page to the application, establish a reverse mapping for the large page and establish a page table for the large page to map contiguous segments in the virtual memory region to the physical address of the large page.
21. The apparatus according to claim 12, characterized in that, The device further includes: A reference count update module is used to update the reference count of the large page in response to the current process of the application allocating the large page.
22. The apparatus according to claim 12, characterized in that, The device further includes: A recycling list addition module is used to add the large page to the least recently used (LRU) recycling list in response to allocating the large page to the current process of the application.
23. An electronic device, characterized in that, The device includes: Processor and memory used to store computer programs; The processor is configured to implement the large page allocation method according to any one of claims 1 to 11 when executing the computer program.
24. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the large page allocation method as described in any one of claims 1 to 11.
25. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the large page allocation method as described in any one of claims 1 to 11.