Memory control method, computing device, storage medium and program product

By allocating large virtual memory pages to applications and ensuring start address alignment, the problems of page table entry bloat and cache misses caused by small page sizes are solved, improving system performance and memory access efficiency, and reducing memory fragmentation and resource waste.

CN121501706APending Publication Date: 2026-02-10ALIBABA CLOUD COMPUTING CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610036744.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-12
Publication Date
2026-02-10

AI Technical Summary

Technical Problem

In existing technologies, small-page memory pages cause page table entries to swell, frequent heap memory operations consume computational resources, reduce system performance, and may lead to cache misses, affecting memory access efficiency. At the same time, there is a memory fragmentation problem, resulting in limited improvement in system performance.

Method used

By allocating large-page virtual memory pages to applications, ensuring starting address alignment, and generating page table entries based on the mapping results, the number of page table entries is reduced, cache hit rate is improved, access latency is reduced, and the resource overhead of separate page consolidation and scanning processes is avoided.

Benefits of technology

Significantly reduces the number of page table entries, improves system performance, reduces access latency, enhances memory access efficiency, reduces memory fragmentation, avoids limited performance gains in cases where consolidation is not possible, and saves resource overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121501706A_ABST
    Figure CN121501706A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a memory control method, computing equipment, a storage medium and a program product. The method comprises the steps of obtaining a heap expansion request for a heap memory of an application program; in response to the heap expansion request, allocating a virtual memory page with a large page size for the application program based on the heap memory; wherein the initial address of the virtual memory page is aligned according to the size of the large page; the virtual memory page is used for mapping to a physical memory page corresponding to the large page size, and generating a page table item according to a mapping result. According to the technical scheme provided by the embodiment of the invention, the virtual memory page with the large page size is allocated, and the initial address of the virtual memory page is aligned according to the large page size, so that the system performance is effectively improved, and the memory access efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and particularly relate to a memory control method, a computing device, a storage medium and a program product. BACKGROUND

[0002] The heap memory is a memory region dynamically allocated by an application program at runtime. A traditional heap memory allocation mechanism is performed in units of virtual memory pages, usually relies on a standard small page size (usually 4KB), and then the virtual memory pages are mapped to physical memory pages of the same size, and the mapping relationship is saved as a page table entry (PTE) in a page table, that is, physical memory access can be achieved by searching the page table entry. The page table entry is an entry in the page table for recording the mapping relationship between the virtual memory page and the physical memory page and the like, and each page table entry corresponds to a virtual memory page. In actual applications, in order to improve the page table entry search efficiency, the page table entries are usually cached.

[0003] However, the small page size memory page will cause the page table entry to expand, and under the condition of frequent heap memory operations, not only the computing resources are consumed, but also cache misses may occur, thereby reducing the system performance and affecting the memory access efficiency. In order to improve the system performance, in the prior art, a scanning process in a specially set background is usually responsible for merging the virtual memory pages of the small page size that meet the conditions in the heap memory into large pages, but this way has condition restrictions, many virtual memory pages still cannot be integrated, and the system performance improvement is limited. SUMMARY

[0004] Embodiments of the present application provide a memory control method, a computing device, a storage medium and a program product, to solve the technical problems of system performance reduction and low memory access efficiency in the prior art.

[0005] In a first aspect, a memory control method is provided in embodiments of the present application, comprising: obtaining a heap expansion request for a heap memory of an application program; in response to the heap expansion request, allocating a virtual memory page with the large page size for the application program based on the heap memory; a start address of the virtual memory page is aligned according to the large page size; The virtual memory page is used to map to a physical memory page corresponding to the large page size, and a page table entry is generated according to the mapping result.

[0006] In a second aspect, a computing device is provided in embodiments of the present application, comprising a processing component and a storage component; The storage component stores a computer program; the computer program is used to be called and executed by the processing component, to implement the memory control method as described in the first aspect.

[0007] Thirdly, this application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processing component, implements the memory control method described in the first aspect above.

[0008] Fourthly, this application provides a computer program product, including a computer program or instructions, which, when executed by a processing component, implement the memory control method described in the first aspect above.

[0009] In this embodiment, a heap expansion request for the application's heap memory is obtained; in response to the heap expansion request, virtual memory pages with large page sizes are allocated to the application based on the heap memory; wherein, the starting address of the virtual memory page is aligned with the large page size; the virtual memory page is used to map to the physical memory page corresponding to the large page size, and page table entries are generated according to the mapping result.

[0010] By aligning the starting address of the virtual memory page to be allocated with the large page size, the alignment requirement is ensured from the starting address. This allows for the allocation of large-page virtual memory pages based on this starting address. Large-page memory pages significantly reduce the number of page table entries, thereby improving system performance, reducing access latency, and increasing memory access efficiency. Furthermore, a separate process for page compaction is not required, avoiding the limited performance improvement caused by non-compactment scenarios. The absence of a separate scanning process also avoids the resource overhead associated with scanning, further guaranteeing system performance.

[0011] These or other aspects of this application will become more apparent in the following description of the embodiments. Attached Figure Description

[0012] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 A flowchart of an embodiment of a memory control method provided in this application; Figure 2a This diagram illustrates a cache lookup of a small-page virtual memory page in a practical application. Figure 2b This diagram illustrates a cache lookup of a large-page-size virtual memory page in a practical application. Figure 3 This paper illustrates a memory allocation flowchart of an embodiment of the present application in a practical application; Figure 4This invention provides a schematic diagram of the structure of one embodiment of a memory control device. Figure 5 A schematic diagram of one embodiment of a computing device provided in this application is shown. Detailed Implementation

[0013] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0014] It should be noted that, in the cases involving user information in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse. In addition, the various models involved in this application (including but not limited to language models or large models) comply with relevant laws and standards.

[0015] As described in the background section, small page sizes lead to page table bloat. With frequent heap memory operations, this not only consumes computational resources but also, due to the limited number of cache entries, can cause cache misses, impacting memory access efficiency and thus reducing overall system performance. Furthermore, small page sizes result in fragmented memory space, wasting memory and impacting system performance. When a large amount of memory needs to be allocated, numerous small pages are required to store data, generating many page table entries and making the page table large. When the system has only allocated virtual memory pages but not yet allocated and mapped physical memory pages, the first access to a virtual memory page triggers a page fault. If the initial memory access is large, it will touch a large number of small virtual memory pages, triggering numerous page faults. Moreover, due to the large page table size, translating a virtual address requires multiple page table lookups to find the corresponding entry. Both multiple page faults and multiple page table lookups incur performance overhead.

[0016] The inventors discovered that in existing technologies, to address system performance issues, a dedicated background scanning process is typically used to merge virtual memory pages of the heap memory that meet certain criteria into larger pages. However, this method has limitations: only virtual memory pages of the smaller page size within memory regions where both the beginning and end addresses are aligned to the larger page size can be merged. Memory regions that do not meet this alignment requirement cannot be merged, resulting in limited performance improvements. Furthermore, the need to periodically scan memory to find suitable virtual memory pages of the smaller page size introduces additional performance overhead.

[0017] To effectively improve system performance, increase cache hit rate, reduce access latency, and effectively alleviate memory fragmentation issues, this application provides a solution. The basic idea is as follows: obtain a heap expansion request for the application's heap memory; respond to the heap expansion request, allocate virtual memory pages with large page sizes for the application based on the heap memory, with the starting address of the virtual memory pages aligned with the large page size; wherein, the virtual memory pages are used to map to the physical memory pages corresponding to the large page sizes, and page table entries are generated based on the mapping results.

[0018] By aligning the starting address of the virtual memory page to be allocated according to the large page size, it is ensured that the virtual memory page to be allocated meets the alignment requirements from the starting address. This allows for the allocation of large-page virtual memory pages based on this starting address. Large-page memory pages significantly reduce the number of page table entries, thereby improving system performance. Furthermore, the page table entries corresponding to large-page memory pages can cover a larger virtual address space. Caching page table entries can improve cache hit rate, reduce access latency, improve memory access efficiency, and effectively reduce memory fragmentation. Moreover, large-page alignment is performed during the allocation phase, eliminating the need for a separate process for page consolidation, thus avoiding the limited system performance improvement caused by unconsolidation. It also eliminates the need for a separate scanning process, avoiding the resource overhead of scanning processes, further guaranteeing system performance.

[0019] When the required virtual memory space for the heap is large, compared to the small-page mechanism, a smaller number of large-page virtual memory pages can be allocated. This reduces page table entries, lowers the page table hierarchy and structural complexity, and reduces the memory resources occupied by the page table. When translating a virtual address, the corresponding page table entry can be found without multiple page table lookups, speeding up the address translation process, reducing memory consumption, and improving memory access performance. Furthermore, compared to the small-page mechanism, a single page fault with a large-page virtual memory page can trigger the mapping of a larger contiguous virtual memory space, significantly reducing the number of page faults and page table update overhead required to process the same memory region, thus improving memory access efficiency and performance.

[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] The implementation details of the technical solutions in the embodiments of this application are described in detail below.

[0022] Figure 1 A flowchart illustrating an embodiment of a memory control method provided in this application. The technical solution of this embodiment can be executed by a memory allocator, which can run in kernel mode. The method may include the following steps: 101: Get a heap expansion request for the application's heap memory.

[0023] The application can run in user mode.

[0024] In practical applications, an application can correspond to one or more processes. The heap memory of an application can refer to the heap memory corresponding to any process of the application. One process can correspond to one heap memory, and the heap memory can correspond to one VMA (Virtual Memory Area).

[0025] A heap expansion request can refer to a situation where the application's heap memory is insufficient to meet allocation requirements. It can be triggered by the application or the memory allocator, etc., and this application does not limit this.

[0026] 102: In response to a heap expansion request, allocate virtual memory pages with large page sizes to the application based on heap memory.

[0027] The starting address of the virtual memory page is aligned with the big page size.

[0028] In the event of a page fault, virtual memory pages can be mapped to physical memory pages with a larger page size, and page table entries are generated based on the mapping result. When a virtual memory page is accessed for the first time, it is not yet mapped to a corresponding physical memory page. Therefore, the page table entry for the virtual memory page does not yet contain information about the physical memory page. If the page table lookup fails to find the corresponding physical memory page information, a page fault is triggered, thus mapping the virtual memory page to a physical memory page with a larger page size. The information of the mapped physical memory page is then filled into the page table entry corresponding to the virtual memory page.

[0029] This method allows the end address of the current heap memory to be aligned with the large page size, and the end address of the current heap memory to be used as the starting address of the large page size virtual memory page to be allocated. Thus, a large page size virtual memory page is allocated based on this starting address to expand the heap memory. After expansion, the end address of the heap memory is the boundary address of the allocated virtual memory page.

[0030] Virtual memory pages with large page sizes can refer to Transparent Huge Pages (THPs). These large page sizes are larger than traditional small page sizes, such as 4KB. For example, a large page size could be 2MB (Megabyte) or 1GB (Gigabyte), etc. The starting address of a large page aligned to a large page size can be an integer multiple of the large page size. For example, with a large page size of 2MB, the starting address of a large page aligned to a large page size, represented in hexadecimal, could be 0x200000 (2MB), 0x400000 (4MB), 0x600000 (6MB), or 0x800000 (8MB), etc.

[0031] The heap expansion request can be triggered by the application through a system call, such as by calling the brk function or sbrk library function. This application does not impose any restrictions on this.

[0032] In this embodiment, the starting address of the virtual memory page to be allocated is aligned with the large page size, ensuring that the virtual memory page to be allocated meets the alignment requirements from the starting address. This allows for the allocation of large-page virtual memory pages based on this starting address. Large-page memory pages significantly reduce the number of page table entries, thereby improving system performance. Furthermore, the page table entries corresponding to large-page memory pages can cover a larger virtual address space. Caching page table entries can improve cache hit rate, reduce access latency, improve memory access efficiency, and effectively reduce memory fragmentation, thus improving system performance. Moreover, large-page alignment is performed during the allocation phase, eliminating the need for a separate scanning process for page consolidation. This avoids the limited system performance improvement caused by unconsolidation and the resource overhead associated with scanning processes, further guaranteeing system performance.

[0033] When the required virtual memory space for the heap is large, compared to the small-page mechanism, a smaller number of large-page virtual memory pages can be allocated. This reduces page table entries, lowers the page table hierarchy and structural complexity, and reduces the memory resources occupied by the page table. When translating a virtual address, the corresponding page table entry can be found without multiple page table lookups, speeding up the address translation process, reducing memory consumption, and improving memory access performance. Furthermore, a single page fault with a large-page virtual memory page can trigger the mapping of the virtual memory page to a physical memory page, allowing for the mapping of a larger contiguous virtual memory space at once. Compared to the small-page mechanism, multiple small-granularity allocation mappings can be consolidated into a single operation, significantly reducing the number of page faults and page table update overhead, thus improving memory access efficiency and performance.

[0034] In some embodiments, before obtaining a heap expansion request for heap memory for an application, the method may further include: detecting application startup and determining, within the application's memory address space, heap memory with a starting address aligned to the big page size.

[0035] "Application startup detected" can refer to the detection of any process of the application starting up. When an application starts, the kernel can allocate a memory address space for the application. This memory address space can refer to a virtual address range. Within this memory address space, the kernel will arrange different memory segments according to a certain layout, such as code memory segment, data memory segment, heap memory segment, and stack memory segment, and determine the access permissions of different memory segments.

[0036] When an application starts, the initial layout of the heap memory can be achieved by determining the starting address of the heap memory in the memory address space.

[0037] When the starting address of the heap memory is aligned with the big page size, the memory allocator can allocate virtual inner pages starting from the starting address of the heap memory. Since each virtual inner page is a big page, the starting address of each virtual memory page is naturally aligned with the big page size.

[0038] In this embodiment, the starting address of the heap memory aligned with the large page size can be determined in the memory address space. This ensures that the heap memory meets the alignment requirements from the starting address, and that the heap memory can be managed at the large page granularity. This facilitates the allocation of large page-sized virtual memory pages based on the starting address of the heap memory, and avoids the potential waste of memory resources when allocating large page-sized virtual memory pages if the starting address of the heap memory is not aligned with the large page size.

[0039] In some embodiments, the heap memory expansion request may be generated by a memory allocator. As an optional implementation, the method may further include: in response to a memory allocation request triggered by an application, determining whether the current virtual memory page meets the allocation requirements based on the memory size in the memory allocation request; if yes, allocating a corresponding memory region from the current virtual memory page according to the memory size; if not, generating a heap expansion request.

[0040] In some embodiments, allocating virtual memory pages with large page sizes to the application based on the heap memory may include: allocating at least one virtual memory page with a large page size from the heap memory according to the memory size. The total memory size corresponding to the at least one virtual memory page is greater than or equal to the memory size; alternatively, the total memory size corresponding to the at least one virtual memory page and the remaining space of the current virtual memory page may also be greater than or equal to the memory size.

[0041] The method may also include: allocating a corresponding memory region based on at least one virtual memory page, according to the memory size.

[0042] Optionally, a corresponding memory region can be allocated from the remaining space of the current virtual memory page and from the at least one virtual memory page, according to the memory size, in order to avoid wasting memory resources.

[0043] Optionally, based on the memory size, remaining space, and large page size, the number of pages can be determined first, and then a number of virtual memory pages with large page sizes can be allocated from the heap memory. The product of the number of pages and the large page size must be greater than or equal to the difference between the memory size and the remaining space. Alternatively, the minimum number of pages can be calculated using the constraint that the product of the number of pages and the large page size is greater than or equal to the difference between the memory size and the remaining space.

[0044] Among them, the memory allocation request triggered by the application can refer to the memory allocation request triggered by any process corresponding to the application. It can be triggered by the user's explicit call to functions such as malloc or calloc, or it can be triggered dynamically during the process execution.

[0045] Whether the current virtual memory page meets the allocation requirements can be interpreted as whether the remaining space of the current virtual memory page is greater than or equal to the memory size. For example, if the large page size of the virtual memory page is 2MB, the starting address of the current heap memory is 0x200000 (2MB), and the virtual address space of the heap memory consists of two virtual memory pages, with the address range of the first virtual memory page being [0x200000, 0x400000] and the address range of the second virtual memory page being [0x400000, 0x600000], the end address of the heap memory is also the end address of the second virtual memory page, 0x600000. Assuming the actual used memory size in the heap is 3MB (i.e., the actual used range is [0x200000, 0x500000)), and the remaining space in the current virtual memory page is 1MB of remaining space in the second virtual memory page, and assuming the memory allocation request indicates a memory size of 4KB, and the remaining 1MB of space meets the requested memory size of 4KB, then 4KB can be allocated from the 1MB of remaining space in the second virtual memory page without needing to extend the virtual memory page further. The memory region allocated from the current virtual memory page according to the memory size is [0x500000, 0x600000). The virtual address of the memory region, such as the starting address 0x500000, can also be fed back to the application. The application can determine the range of the memory region based on this starting address and the requested memory size. If the requested memory size is 2MB, then the 1MB of remaining space is insufficient to meet the requested memory size of 2MB, and a heap extension request is generated. This allows for the response to heap expansion requests. Based on the memory size, at least one virtual memory page with a large page size is allocated from the heap memory. For example, if the memory size is 2MB, and the second virtual memory page has 1MB of remaining space, which does not meet the allocation requirements, a third virtual memory page of 2MB can be allocated. Then, from at least one virtual memory page, a corresponding memory region is allocated based on the memory size. This memory region can refer to the actual memory area used. For example, given a 2MB memory size, the second virtual memory page has 1MB of remaining space [0x500000, 0x600000), so only 1MB of space in the third virtual memory page ([0x600000, 0x700000)) needs to be allocated. This memory region covers the remaining space of the second virtual memory page ([0x500000, 0x600000)) and the space in the third virtual memory page ([0x600000, 0x700000), i.e., [0x500000, 0x700000]). In addition, the virtual address of the memory region, such as the starting address 0x500000, can be fed back to the application. The application can then determine the range of the memory region based on the starting address and the requested memory size.

[0046] As an alternative implementation, heap expansion requests can be generated by the application if it determines that the current virtual memory pages do not meet the allocation requirements based on the requested memory size.

[0047] The user can explicitly call functions such as malloc or calloc to trigger memory allocation requests, or the process can dynamically trigger memory allocation requests during execution. The application determines whether the current virtual memory page meets the allocation requirements based on the memory size requested in the memory allocation request. Specifically, it can determine whether the remaining space of the virtual memory page corresponding to the current heap memory meets the requested memory size. If it does, the allocation requirement is met; otherwise, the allocation requirement is not met, and a heap expansion request is generated.

[0048] In some embodiments, the method may further include: saving the starting address of the heap memory as the alignment address of the heap memory into alignment data. The alignment data may refer to the alignment field in a memory management structure.

[0049] In practical applications, the memory management structure can be, for example, `mm_struct`, which is a core data structure in the kernel used to describe memory management information. An alignment field can be added to the memory management structure to record the alignment address.

[0050] The above-mentioned allocation of virtual memory pages with large page sizes for applications based on heap memory may include: starting from the alignment address where the alignment data is stored, allocating virtual memory pages for applications based on heap memory according to the large page size.

[0051] This method may further include updating the alignment address in the alignment data based on the end address of the virtual memory page. That is, the alignment address is the latest end address of the heap memory. By recording the alignment address, it is convenient to use this alignment address as a reference for subsequent heap memory expansion.

[0052] In some embodiments, upon detecting application startup, determining the heap memory with its starting address aligned to the max page size within the application's memory address space may include: upon detecting application startup, determining whether the memory allocator has alignment enabled; if alignment is enabled, determining the heap memory with its starting address aligned to the max page size within the application's memory address space. If alignment is not enabled, the starting address of the heap memory can be randomly determined within the application's memory address space.

[0053] Accordingly, in some embodiments, allocating virtual memory pages with large page sizes to the application based on heap memory in response to a heap expansion request may include: determining whether the memory allocator has alignment enabled in response to the heap expansion request; if alignment is enabled, allocating virtual memory pages to the application based on heap memory according to the large page size. If alignment is not enabled, virtual memory pages may be allocated to the application based on heap memory according to the small page size in response to a heap expansion request for heap memory.

[0054] This alignment feature may refer to the THP (Big Page) alignment feature.

[0055] In this embodiment, for applications requiring intensive memory access, alignment can be enabled. This aligns the starting address of the heap memory to the big page size, allocating virtual memory pages to the application based on the heap memory. The big page mechanism reduces page faults and page table lookups, improving memory access efficiency. For applications not requiring intensive memory access, alignment can be disabled. The starting address of the heap memory is randomly determined, and virtual memory pages are allocated to the application based on the small page size. This allows for finer memory management and avoids wasting virtual address space. Flexible switching of alignment mechanisms helps adapt to different memory access needs, improving overall resource efficiency.

[0056] In some embodiments, the method may further include: determining a pre-set target user-space interface; enabling the alignment function in response to a startup command set based on the target user-space interface; and disabling the alignment function in response to a shutdown command set based on the target user-space interface.

[0057] The target user-space interface can be the sysctl user-space interface (a kernel runtime parameter that can be dynamically modified during kernel operation). Users can use this interface to dynamically control whether THP (Big Page) alignment is enabled or disabled. For example, using the sysctl user-space interface, users can enable THP alignment using a command like `echo 1 > / proc / sys / vm / enable_brk_thp_aligned` and disable it using a command like `echo 0 > / proc / sys / vm / enable_brk_thp_aligned`. Here, ` / proc / sys / vm / ` represents the directory used for dynamically configuring and monitoring kernel memory management parameters. In the ` / proc / sys / vm / ` directory, there is a parameter file named `enable_brk_thp_aligned`. Writing the value 1 to this file using `echo 1` enables the `enable_brk_thp_aligned` parameter, which refers to the big page (ThP) alignment function performed during heap expansion based on the `brk` system call. Writing the value 0 to the file using `echo 1` indicates that the alignment function of the parameter `enable_brk_thp_aligned` is disabled.

[0058] This embodiment provides a target user-space interface, allowing users to flexibly control whether to enable the alignment function. For example, users can enable the alignment function for applications that require intensive memory access, and disable it for applications that do not require intensive memory access. This target user-space interface helps users flexibly switch alignment mechanisms to adapt to different memory access needs and improve overall resource efficiency.

[0059] In some embodiments, the method may further include: shrinking the end address of the heap memory to the actual end address corresponding to the application when alignment is disabled. This actual end address is the address actually used by the application. For example, if the current start address of the heap memory is 0x200000 and the end address is 0x600000, and assuming the actual used memory size in the heap memory is 3MB (i.e., the actual used range is [0x200000, 0x500000)), then the actual end address is 0x500000, and the end address of the heap memory can be shrunk to 0x500000. This releases unused virtual address space, avoids wasting virtual memory resources, and improves memory utilization efficiency.

[0060] Furthermore, this actual end address can be used as the starting address for subsequent heap expansions, which can then allocate virtual memory pages based on this starting address and the page size.

[0061] In some embodiments, the method may further include: receiving a page fault request; allocating physical memory pages according to the large page size and establishing a mapping relationship between physical memory pages and virtual memory pages; generating page table entries based on the mapping relationship and updating the page table entries to the page table.

[0062] Page fault requests are generated by the processing component in response to the first memory access request for a virtual memory page. The cache can store page table entries, specifically those containing information about the physical memory pages mapped from the virtual memory pages. The cache can refer to mechanisms such as the TLB (Translation Lookaside Buffer).

[0063] The processing component, which can refer to the CPU (Central Processing Unit), accesses a virtual memory page for the first time. Since this virtual memory page is not yet mapped to a corresponding physical memory page, its page table entry does not yet contain information about the physical memory page. The processing component uses the virtual memory page's identifier as a key to search the page table entry in the cache. Because the cache only stores page table entries for mapped virtual memory pages, if the corresponding page table entry is not found in the cache, it searches the page table in memory. If the searched page table entry does not contain information about the physical memory page, a page fault request for that virtual memory page is triggered. Then, according to the page size, physical memory pages are allocated, and a mapping relationship between physical memory pages and virtual memory pages is established. Page table entries are generated based on this mapping relationship.

[0064] Furthermore, after generating a page table entry based on this mapping relationship, the method can also save the page table entry to the cache.

[0065] In traditional small-page mechanisms, the number of page table entries is large, while the cache capacity is limited, resulting in a limited number of page table entries that can be stored. Many page table entries cannot be cached, and the virtual address space covered by a small page's page table entry is limited, leading to a low cache hit rate. This embodiment uses large pages, which reduces the overall number of page table entries and the number of page table entries loaded into the cache. Furthermore, a single page table entry can cover a larger virtual address space, improving the cache hit rate and eliminating the need for multiple memory page table lookups, thus reducing performance overhead.

[0066] Figure 2a This diagram illustrates a cache lookup of small-page virtual memory pages in a practical application, for example, when accessing a 2MB virtual memory region. Figure 2aAs shown, this 2MB virtual memory region corresponds to 512 virtual memory pages of 4KB each, which is limited by space. Figure 2a The ellipsis represents 510 small-page virtual memory pages. Each 512 small-page virtual memory page corresponds to 512 page table entries. When accessing the 512 virtual memory pages corresponding to a 2MB virtual memory region, the TLB cache can be searched based on the identifiers of the 512 virtual memory pages to determine if the corresponding page table entry is stored. The physical address can then be determined based on the physical memory page information from the page table entry. However, the TLB cache has a limited capacity and can only store a limited number of page table entries. The TLB may not store some of the 512 page table entries; therefore, the page table entries for some virtual memory pages can be found in the TLB. Figure 2a The term "TLB hit" refers to a situation where the page table entries for some virtual memory pages cannot be found in the TLB. Figure 2a The "TLB missing" is mentioned.

[0067] Figure 2b This illustrates a cache lookup diagram for virtual memory pages with large page sizes in a practical application, such as... Figure 2b As shown, when accessing a 2MB virtual memory region, this 2MB virtual memory region can correspond to only one 2MB large page virtual memory page. One virtual memory page corresponds to one page table entry. When accessing this virtual memory page, only one lookup is needed to check if the corresponding page table entry is stored in the TLB cache based on the virtual memory page's identifier. Even though the number of page table entries that the TLB cache can store is limited, because using large pages reduces the overall number of page table entries compared to small pages, the proportion of page table entries that the TLB can store is larger, resulting in a higher TLB hit rate. Accessing this 2MB virtual memory region only requires querying the TLB for the page table entry of one virtual memory page; therefore, it is easier to find the entry in the TLB.

[0068] Furthermore, a single page fault in a large-page virtual memory page can trigger the mapping of the virtual memory page to a physical memory page, allowing for the mapping of a larger contiguous virtual memory space at once. Compared to the small-page mechanism, this consolidates multiple small-granularity allocation mappings into a single operation, thereby significantly reducing the number of page faults, page table update overhead, and improving memory access efficiency and performance.

[0069] In some embodiments, the method may further include: in response to a memory release request triggered by an application, determining a target virtual memory page corresponding to the memory region to be released; detecting whether other memory regions in the target virtual memory page besides the memory region to be released are free; if so, releasing the physical memory page corresponding to the target virtual memory page; if not, marking the memory region as free. Wherein, while releasing the physical memory page corresponding to the target virtual memory page, the information of the physical memory page in the page table entry corresponding to the target virtual memory page may be deleted.

[0070] In this embodiment, the kernel can respond to memory release requests, release the target virtual memory page, prevent the application's virtual memory space from expanding indefinitely, and ensure the overall stability of the system during long-term operation. Furthermore, it can reclaim the corresponding physical memory page to the global free pool for allocation by other applications or processes, thereby effectively preventing the risk of physical memory exhaustion caused by individual applications or processes continuously occupying memory that is no longer needed.

[0071] For ease of understanding, Figure 3 A flowchart illustrating the memory allocation process in a practical application according to an embodiment of this application is shown.

[0072] First, any process in the application starts (step 301). The memory allocator can allocate a memory address space for the process (step 302) and initialize the heap memory, that is, determine the starting address of the heap memory in the memory address space. This starting address can be randomly determined (step 303).

[0073] Then determine whether to enable the alignment function (step 304).

[0074] If the alignment function is not enabled, the starting address can still be the original randomly determined starting address.

[0075] With alignment enabled, the starting address of the heap memory in the process's memory address space is determined and aligned to the large page size (step 305). User-initiated calls to functions such as malloc or calloc can trigger memory allocation requests for heap memory (step 306), or these requests can be dynamically triggered during process execution (step 307). The kernel memory allocator can determine whether the current virtual memory page meets the allocation requirements based on the requested memory size. If not, a heap expansion request is generated. The memory allocator responds to this heap expansion request and determines whether alignment is enabled (step 308). With alignment enabled, virtual memory pages with large page sizes and starting addresses aligned to the large page size are allocated to the process based on the heap memory (step 309). Without alignment enabled, the ending address of the heap memory shrinks to the actual ending address corresponding to the application. This actual ending address can be used as the starting address for subsequent heap expansions, allocating virtual memory pages according to the small page size.

[0076] In this embodiment, the alignment function can be flexibly adjusted at any time to adapt memory management strategies to different load and performance requirements, thereby improving overall resource efficiency. When alignment is enabled during process startup and heap expansion, the starting address of the heap memory can be aligned according to the large page size. Virtual memory pages are then allocated to the application based on the large page size within the heap memory. This ensures that the heap memory meets alignment requirements from the start address, allowing for large-page granular management and facilitating the allocation of large-page virtual memory pages based on the heap memory's starting address. This avoids potential memory resource waste when allocating large-page virtual memory pages if the heap memory's starting address is not aligned with the large page size. Conversely, when alignment is not enabled during process startup and heap expansion, the starting address of the heap memory is randomly determined, and virtual memory pages are allocated to the application based on the small page size. This allows for finer memory management and avoids wasting virtual memory space. Furthermore, if alignment is enabled when the process starts but disabled during subsequent heap expansion, the end address of the heap memory can be shrunk to the actual end address of the application, thus avoiding waste of virtual memory resources.

[0077] Larger page sizes significantly reduce the number of page table entries, thus improving system performance. Furthermore, page table entries corresponding to larger page sizes can cover a larger virtual address space. Caching these page table entries can improve cache hit rate, reduce access latency, and increase memory access efficiency, while also effectively reducing memory fragmentation. Moreover, large page size alignment is performed during the allocation phase, eliminating the need for a separate process for page consolidation. This avoids the limited performance improvement caused by unconsolidation and eliminates the need for a separate scanning process, thus avoiding the resource overhead associated with scanning and further ensuring system performance.

[0078] When the required virtual memory space for the heap is large, compared to the small-page mechanism, a smaller number of large-page virtual memory pages can be allocated. This reduces page table entries, lowers the page table hierarchy and structural complexity, and reduces the memory resources occupied by the page table. When translating a virtual address, the corresponding page table entry can be found without multiple page table lookups, speeding up the address translation process, reducing memory consumption, and improving memory access performance. Furthermore, compared to the small-page mechanism, a single page fault with a large-page virtual memory page can trigger the mapping of a larger contiguous virtual memory space, significantly reducing the number of page faults and page table update overhead required to process the same memory region, thus improving memory access efficiency and performance.

[0079] It should be noted that some processes described in the above embodiments and accompanying drawings include multiple operations appearing in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear in this document, or they may be executed in parallel. The operation numbers, such as 101, 102, etc., are merely used to distinguish different operations and do not represent any execution order. Furthermore, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should also be noted that the descriptions such as "first" and "second" in this document are used to distinguish different messages, devices, modules, etc., and do not represent a sequential order, nor do they limit "first" and "second" to different types.

[0080] Figure 4 This is a schematic diagram of one embodiment of a memory control device provided in this application. In practical applications, this device can be implemented as a memory allocator, and the device may include: Module 401 is used to obtain heap expansion requests for the application's heap memory.

[0081] Allocation module 402 is used to allocate virtual memory pages with large page sizes to the application based on heap memory in response to a heap expansion request.

[0082] The starting address of the virtual memory page is aligned with the big page size; in the event of a page fault, the virtual memory page can be mapped to the physical memory page corresponding to the big page size, and page table entries are generated based on the mapping result.

[0083] In some embodiments, before the acquisition module acquires a heap expansion request for heap memory for an application, the apparatus may further include a detection module for detecting application startup and determining, within the application's memory address space, heap memory with a starting address aligned to the big page size.

[0084] In some embodiments, the heap memory expansion request may be generated by a memory allocator. As an alternative implementation, the apparatus may further include: The request generation module is used to respond to memory allocation requests triggered by the application. Based on the memory size in the memory allocation request, it determines whether the remaining space of the current virtual memory page is sufficient for the memory size. If so, it allocates the corresponding memory region from the current virtual memory page according to the memory size. If not, it generates a heap expansion request.

[0085] The allocation module, based on heap memory, can allocate virtual memory pages with large page sizes for applications by: allocating at least one virtual memory page with a large page size from the heap memory according to the memory size. The allocation module can also be used to: allocate a corresponding memory region from at least one virtual memory page according to the memory size.

[0086] As an alternative implementation, heap expansion requests can be generated by the application if the remaining space of the current virtual memory page is insufficient to meet the requested memory size.

[0087] In some embodiments, the device may further include: The save module is used to save the starting address of the heap memory as the alignment address of the heap memory into the alignment data.

[0088] The allocation module, based on the heap memory, allocates virtual memory pages with large page sizes to the application. This can include: starting from the alignment address stored in the alignment data, allocating virtual memory pages to the application based on the large page size and the heap memory. The storage module can also update the alignment address in the alignment data according to the end address corresponding to the virtual memory page. That is, the alignment address is the latest end address of the heap memory. By recording the alignment address, it is convenient to use this alignment address as a reference for subsequent heap memory expansion.

[0089] In some embodiments, the detection module detects that an application has started. Determining the heap memory with its starting address aligned to the big page size in the application's memory address space may include: detecting that the application has started, determining whether the device has enabled alignment functionality; if alignment functionality is enabled, determining the heap memory with its starting address aligned to the big page size in the application's memory address space. If alignment functionality is not enabled, the starting address of the heap memory can be randomly determined in the application's memory address space.

[0090] Accordingly, in some embodiments, the allocation module allocating virtual memory pages for the application based on heap memory according to the large page size may include: determining whether the device has alignment enabled; if alignment is enabled, allocating virtual memory pages for the application based on heap memory according to the large page size. If alignment is not enabled, virtual memory pages may be allocated for the application based on heap memory according to the small page size in response to a heap expansion request for heap memory.

[0091] In some embodiments, the device may further include: The interface response module is used to determine the pre-set target user-space interface; to enable the alignment function in response to the start command set based on the target user-space interface; and to disable the alignment function in response to the stop command set based on the target user-space interface.

[0092] In some embodiments, the device may further include: The address modification module is used to shrink the end address of the heap memory to the actual end address corresponding to the application when the alignment function is disabled.

[0093] In some embodiments, the device may further include: The mapping module is used to receive page fault requests; allocate physical memory pages according to the large page size and establish a mapping relationship between physical memory pages and virtual memory pages; based on the mapping relationship, generate page table entries and update the page table entries to the page table.

[0094] In some embodiments, the device may further include: The memory release module, in response to a memory release request triggered by an application, determines the target virtual memory page corresponding to the requested memory region; checks whether the remaining memory regions within the target virtual memory page are free; if so, it releases the physical memory page corresponding to the target virtual memory page; otherwise, it marks the memory region as free. Simultaneously with releasing the physical memory page corresponding to the target virtual memory page, the information about the physical memory page in the page table entry corresponding to the target virtual memory page can be deleted.

[0095] Figure 4 The memory control device can perform Figure 1 The implementation principle and technical effects of the memory control method described in the illustrated embodiments will not be repeated here. The specific methods by which each module and unit of the memory control device in the above embodiments performs its operations have been described in detail in the embodiments related to this method, and will not be elaborated upon here.

[0096] Figure 5 This is a schematic diagram of the structure of one embodiment of a computing device provided in this application. Figure 5 As shown, in practice, the computing device may include a storage component 501 and a processing component 502.

[0097] Storage component 501 is used to store computer programs and can be configured to store various other data to support operation on a computing device. Examples of this data include instructions for any application or method used to operate on the computing device, data structures, contact data, phone book data, messages, pictures, videos, etc.

[0098] Processing component 502, coupled to storage component 501, is used to execute computer programs in storage component 501 for implementing, etc. Figure 1 The memory control method described in the illustrated embodiment.

[0099] Furthermore, such as Figure 5 As shown, the computing device may also include other components such as a communication component 503, a display component 504, a power supply component 505, and an audio component 506. Figure 5 The diagram only shows some components and does not mean that the computing device includes only these components. Figure 5 The components shown. Additionally... Figure 5The components within the dashed box are optional, not mandatory, and their specific requirements depend on the product form of the computing device. The computing device in this embodiment can be a terminal device such as a desktop computer, laptop computer, smartphone, or IoT (Internet of Things) device, or a server-side device such as a conventional server, cloud server, or server array. If the computing device in this embodiment is implemented as a terminal device such as a desktop computer, laptop computer, or smartphone, it may include... Figure 5 The components within the dashed box; if the computing device in this embodiment is implemented as a conventional server, cloud server, or server array, etc., then it may not include... Figure 5 The component within the dashed box.

[0100] The processing component described above includes one or more processors to execute computer instructions to complete all or part of the steps in the method described above. Alternatively, the processing component may be implemented as 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 method described above.

[0101] The aforementioned storage components 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.

[0102] The aforementioned communication component is configured to facilitate wired or wireless communication between the device housing the communication component and other devices. The device housing the communication component can access wireless networks based on communication standards, such as mobile communication networks, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.

[0103] The aforementioned display components may include a screen, which may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can 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 can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.

[0104] The aforementioned power supply components provide power to various components within the device in which they reside. These power supply components may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to the device in which they reside.

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

[0106] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to implement the steps in the above-described method embodiments. The computer-readable storage medium includes volatile or non-volatile components, or a combination thereof, and can be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random-access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, CD-ROM, Digital Video Disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium. Accordingly, this application also provides a computer program product, which includes a computer program or instructions that, when executed by a processor, cause the processor to implement the steps in the above method embodiments. It should be understood that each step or combination of steps in the above method flow can be implemented by the computer program or instructions. Furthermore, these computer programs or instructions can be applied to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device, enabling the processor of the general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to function as an apparatus for implementing the corresponding functions in the above method embodiments.

[0107] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0108] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes that element.

[0109] Finally, it should be noted that the above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A memory control method, characterized in that, Applied to a memory allocator, the method includes: Retrieve heap expansion requests for the application's heap memory; In response to the heap expansion request, virtual memory pages with large page sizes are allocated to the application based on the heap memory; the starting address of the virtual memory page is aligned with the large page size. The virtual memory page is used to map to the physical memory page corresponding to the large page size, and page table entries are generated based on the mapping result.

2. The method according to claim 1, characterized in that, Before obtaining the heap expansion request for the application's heap memory, the process also includes: Upon detecting that the application has started, the heap memory with a starting address aligned to the large page size is determined within the application's memory address space.

3. The method according to claim 2, characterized in that, Also includes: In response to a memory allocation request triggered by the application, determine whether the remaining space of the current virtual memory page meets the memory size based on the memory size in the memory allocation request; If so, allocate the corresponding memory region from the current virtual memory page according to the stated memory size; If not, generate the heap expansion request.

4. The method according to any one of claims 1 to 3, characterized in that, The allocation of virtual memory pages with large page sizes to the application based on the heap memory includes: According to the memory size, allocate at least one virtual memory page with the large page size from the heap memory; the total memory size corresponding to the at least one virtual memory page is greater than or equal to the memory size; The method further includes: Based on the at least one virtual memory page, a corresponding memory region is allocated according to the memory size.

5. The method according to claim 2, characterized in that, Also includes: The starting address of the heap memory is used as the alignment address of the heap memory and saved in the alignment data; The allocation of virtual memory pages with large page sizes to the application based on the heap memory includes: Starting from the alignment address where the alignment data is stored, virtual memory pages are allocated for the application from the heap memory according to the large page size; The method further includes: Update the alignment address in the alignment data according to the end address corresponding to the virtual memory page.

6. The method according to claim 2, characterized in that, The step of detecting the application's startup and determining, within the application's memory address space, the heap memory with its starting address aligned to the large page size includes: Upon detecting that the application has started, determine whether the memory allocator has enabled the alignment function; With the alignment function enabled, the heap memory with a starting address aligned to the large page size is determined in the application's memory address space.

7. The method according to any one of claims 1 to 3, characterized in that, In response to the heap expansion request, allocating virtual memory pages with large page sizes to the application based on the heap memory includes: In response to the heap expansion request, determine whether the memory allocator has the alignment function enabled; With the alignment function enabled, virtual memory pages are allocated to the application based on the heap memory according to the large page size.

8. The method according to claim 6, characterized in that, Also includes: Determine the pre-defined target user-space interface; In response to a startup command set based on the target user-space interface, the alignment function is enabled; In response to a shutdown command set based on the target user-space interface, the alignment function is disabled.

9. The method according to claim 8, characterized in that, Also includes: When the alignment function is disabled, the end address of the heap memory is shrunk to the actual end address corresponding to the application.

10. The method according to any one of claims 1 to 3, characterized in that, Also includes: Receive a page fault request; the page fault request is generated by the processing component in response to the first memory access request for the virtual memory page; According to the large page size, allocate physical memory pages and establish a mapping relationship between the physical memory pages and the virtual memory pages; Based on the mapping relationship, the page table entry is generated and the page table entry is updated in the page table.

11. The method according to claim 1, characterized in that, Also includes: In response to a memory release request triggered by the application, determine the target virtual memory page corresponding to the memory region to be released; Detect whether the remaining memory regions in the target virtual memory page, excluding the memory region, are free; If so, release the physical memory page corresponding to the target virtual memory page; If not, mark the memory region as free.

12. A computing device, characterized in that, This includes processing components and storage components; The storage component stores a computer program; the computer program is invoked and executed by the processing component to implement the memory control method as described in any one of claims 1 to 11.

13. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processing component, implements the memory control method as described in any one of claims 1 to 11.

14. A computer program product, characterized in that, It includes a computer program or instructions that, when executed by a processing component, implement the memory control method as described in any one of claims 1 to 11.

Citation Information

Patent Citations

  • Giant page memory management method and system for hierarchical large memory architecture

    CN119512988A

  • Large page optimizations in a virtual machine environment

    US20070136506A1