Memory allocation method and device and electronic equipment

By dynamically adapting memory allocation to large page sizes at the virtual memory fragment level, the problem of wasted physical memory resources in traditional memory management is solved, achieving more efficient memory utilization and system reliability.

CN121833242APending Publication Date: 2026-04-10VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
VIVO MOBILE COMM CO LTD
Filing Date
2025-12-17
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Traditional operating systems' physical memory management based on 4KiB basic pages suffers from performance bottlenecks when handling large-scale physical memory accesses, leading to frequent page faults and cache misses. Furthermore, multi-size transparent big page schemes result in big page sizes that do not match the actual needs of applications, causing a waste of physical memory resources.

Method used

By refining the control granularity of memory big page allocation to the virtual memory segment level, a memory big page allocation prompt is introduced. The most suitable big page size is dynamically adapted according to the specific access characteristics of the virtual memory segment, thereby achieving differentiated physical memory allocation.

Benefits of technology

It improves the utilization of physical memory large pages, reduces the waste of physical memory resources, and enhances memory access efficiency and system robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833242A_ABST
    Figure CN121833242A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and device and electronic equipment, and is applied to the technical field of electronic equipment. The method comprises the steps that a memory large page allocation prompt of a first virtual memory fragment of a first application program is acquired; wherein the first virtual memory fragment is a continuous virtual memory which is divided according to the memory access permission and / or mapping object type of the first application program; the memory large page allocation prompt is used for indicating a large page size decision rule when a physical memory is allocated to the first virtual memory fragment; determining a target memory large page size corresponding to the first virtual memory fragment according to the type of the memory large page allocation prompt; and allocating a physical memory to the first virtual memory fragment based on the target memory large page size.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of electronic equipment technology, specifically relating to a memory allocation method, apparatus, and electronic equipment. Background Technology

[0002] With the continuous growth of physical memory capacity in electronic devices and the increasing demand for physical memory from applications, the traditional physical memory management method based on 4KiB basic pages in operating systems faces significant performance bottlenecks when handling large-scale physical memory accesses. Specifically, this manifests as frequent page faults and Translation Lookaside Buffer (TLB) misses.

[0003] To improve physical memory access efficiency, Transparent Huge Pages (THP) technology emerged, which reduces address translation overhead by allocating larger physical memory pages, such as 2MiB. Subsequently, to further optimize physical memory usage, the industry proposed a multi-size Transparent Huge Pages (mTHP) scheme to provide more flexible allocation granularity.

[0004] However, the multi-size transparent big page scheme in related technologies adopts a uniform allocation strategy for memory big page allocation control mechanism, which results in the allocated big page size being seriously inconsistent with the actual access needs of the application. This causes a large amount of allocated big page memory to be underutilized, leading to a waste of physical memory resources. Summary of the Invention

[0005] The purpose of this application is to provide a memory allocation method, apparatus, and electronic device that can improve the utilization rate of physical memory large pages, thereby reducing the waste of physical memory resources.

[0006] In a first aspect, embodiments of this application provide a memory allocation method, the method comprising: Obtain the memory big page allocation prompt for the first virtual memory segment of the first application; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; The target memory page size corresponding to the first virtual memory segment is determined based on the type of the memory page allocation prompt. Based on the target memory page size, allocate physical memory for the first virtual memory segment.

[0007] Secondly, embodiments of this application provide a memory allocation apparatus, the apparatus comprising: The acquisition module is used to acquire the memory big page allocation prompt of the first virtual memory segment of the first application; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; The determining module is used to determine the target memory page size corresponding to the first virtual memory segment based on the type of the memory page allocation prompt; The allocation module is used to allocate physical memory to the first virtual memory segment based on the target memory page size.

[0008] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the memory allocation method as described in the first aspect.

[0009] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the memory allocation method as described in the first aspect.

[0010] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the memory allocation method as described in the first aspect.

[0011] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the memory allocation method as described in the first aspect.

[0012] In this embodiment, a memory big page allocation prompt for a first virtual memory segment of a first application is obtained; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rule when allocating physical memory for the first virtual memory segment; the target memory big page size corresponding to the first virtual memory segment is determined according to the type of the memory big page allocation prompt; and physical memory is allocated for the first virtual memory segment based on the target memory big page size.

[0013] As can be seen, in this embodiment of the application, by refining the control granularity of memory big page allocation to the virtual memory segment level and introducing a memory big page allocation prompt, the most suitable big page size can be dynamically adapted according to the specific access characteristics of each virtual memory segment, thereby improving the utilization rate of physical memory big pages and reducing the waste of physical memory resources caused by size mismatch. Attached Figure Description

[0014] Figure 1 This is a flowchart of a memory allocation method provided in an embodiment of this application; Figure 2 This is a structural block diagram of a memory allocation device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application; Figure 4 This is a schematic diagram of the hardware structure of an electronic device that implements the various embodiments of this application. Detailed Implementation

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

[0016] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0017] To facilitate understanding, some relevant concepts and application scenarios involved in the embodiments of this application will be introduced first.

[0018] I. Related Concepts Physical memory, as the core storage hardware of a computer system, typically refers to random access memory (RAM). It provides physical storage space for the operating system and applications during runtime, directly storing executable code, program data, and related system status information. This storage medium is volatile; its contents are completely lost when the system is powered off. In this embodiment, physical memory is the direct resource carrier for implementing large page allocation, mapping, and management operations.

[0019] A basic page is the smallest fixed unit for physical memory allocation and management by the operating system. Its size is determined by both the hardware architecture and the operating system, and is typically 4KiB or 16KiB in scenarios such as mobile terminals. Basic pages are the cornerstone of the virtual memory system. The virtual address space of a process is divided into contiguous basic page units, which are mapped to corresponding page frames in physical memory through page tables.

[0020] Huge pages are memory pages that are significantly larger than the base page, such as 2 MiB or 1 GiB. Using huge pages can greatly reduce the number of page table entries required by a process, thereby reducing the miss rate of the address transfer bypass cache and improving the efficiency of physical memory access.

[0021] Transparent Huge Pages (THP) is a memory management feature automatically implemented by the operating system kernel, its core being transparency to applications. This system can merge multiple consecutive base pages into a single large page (e.g., 2MiB) in the background without requiring any modifications or explicit requests from the application, thus lowering the barrier to entry.

[0022] Multi-sized Transparent Huge Pages (mTHP) are an evolution of transparent huge page technology, supporting the allocation of various intermediate-sized pages that are larger than the base page but smaller than the traditional 2MiB huge page, such as 64KiB, 128KiB, and 256KiB. This technology provides more flexible allocation granularity, improving upon the high allocation failure rate and severe internal fragmentation issues caused by the fixed large size of traditional THP, achieving a better balance between physical memory access performance and physical memory utilization.

[0023] The Virtual Memory Area (VMA) is a core data structure in the Linux kernel that describes the address space of a process. Each VMA corresponds to a range of virtual addresses with contiguous addresses and the same access permissions and mapping attributes.

[0024] A Virtual Memory Map Entry (VM Map Entry) is a similar data structure in the XNU kernel used to define a contiguous and consistent memory region in a process's virtual address space.

[0025] In summary, a basic page is the smallest unit of physical memory management by the system; a large page generally refers to a memory page larger than a basic page; a transparent large page is a technology in which the system automatically merges and manages large pages; and a multi-size transparent large page further supports various intermediate sizes, enabling more precise control over physical memory allocation.

[0026] This application provides a memory allocation method, apparatus, and electronic device that can allocate appropriately sized large pages to different virtual memory segments based on memory large page allocation prompts, thereby improving the utilization rate of physical memory large pages and reducing the waste of physical memory resources.

[0027] The memory allocation method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.

[0028] It should be noted that the memory allocation method provided in this application is applicable to electronic devices. In practical applications, the electronic device may include mobile terminals such as smartphones, tablets, smartwatches, and personal digital assistants. This application does not limit this.

[0029] Figure 1 This is a flowchart of a memory allocation method provided in an embodiment of this application, such as... Figure 1 As shown, the method may include the following steps: step 101, step 102 and step 103.

[0030] In step 101, a memory big page allocation prompt for the first virtual memory segment of the first application is obtained; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment.

[0031] In this embodiment of the application, the first application refers to any application that is currently performing physical memory allocation processing during the execution of the memory allocation method of this embodiment of the application.

[0032] For example, this could be for video players, web browsers, or game applications running on electronic devices. When physical memory allocation is required for a segment of virtual memory belonging to an application, that application becomes the primary application.

[0033] In this embodiment, the first virtual memory segment refers to a basic management unit within the virtual address space of the first application process. This segment corresponds to a continuous range of virtual addresses within the process, and it has unified memory access permissions (such as read, write, and execute) and unified mapping object types (such as mapping to anonymous physical memory, file, or device memory). It is the basic logical unit for memory management by the operating system kernel.

[0034] In this embodiment of the application, a virtual memory technology framework is used, which is implemented by the operating system kernel. This framework provides each process with an independent, contiguous virtual address space that is typically larger than the physical memory capacity, thereby separating the logical addresses used by the process from the physical addresses of the hardware.

[0035] Within the framework of virtual memory technology, a virtual memory segment is the basic management unit into which a process's virtual address space is divided. The operating system kernel divides a process's entire virtual address space (including code segments, data segments, heap, stack, shared libraries, memory-mapped files, etc.) into multiple such virtual memory segments based on a combination of access permissions and mapped object types.

[0036] In this embodiment of the application, the memory big page allocation prompt is a kind of metadata (or tag) associated with a specific virtual memory segment, used to define the decision rules regarding the size of big pages to be used when allocating physical memory to that virtual memory segment (i.e., establishing a mapping from virtual address to physical address).

[0037] For example, taking a video player as an example, the typical virtual memory segments and their attributes contained in its process are shown in Table 1 below.

[0038] Taking Table 1 as an example, when physical memory needs to be allocated for the code segment of the video player, the virtual address range corresponding to that code segment becomes the first virtual memory segment; if physical memory needs to be allocated subsequently for the video player's video frame buffer (part of the heap memory), then the virtual address range corresponding to that buffer becomes the new first virtual memory segment. The other virtual memory segments of the video player are similar and will not be elaborated upon here.

[0039]

[0040] Table 1 In this embodiment, the partitioning of virtual memory segments provides an architectural foundation for fine-grained memory management. The operating system first divides the address space into multiple independent virtual memory segments based on access permissions and mapping types, achieving logical isolation and attribute classification of different functional code and data. By configuring an independent memory large page allocation prompt for each virtual memory segment, the control granularity of physical memory allocation is further refined from the application level to the level of its internal functional units. This allows the system to intelligently allocate appropriately sized memory large pages to different virtual memory segments based on their actual access characteristics (such as sequential execution of the code segment and random access to the data segment), thereby achieving precise allocation and efficient utilization of large page resources. This effectively solves the problem of low physical memory utilization caused by uniform allocation in related technologies.

[0041] In some embodiments, the type of memory massive page allocation prompt includes a static prompt and a dynamic prompt.

[0042] In this embodiment, a static prompt is used to instruct the allocation of a fixed-size memory page for its associated virtual memory segment. This fixed size is used directly during allocation, eliminating the need for additional decision calculations. For example, for a virtual memory segment corresponding to a high-performance computing library code segment, a static prompt can be configured and fixed at 64 KiB to ensure maximum performance for instruction retrieval. For a virtual memory segment corresponding to an audio rendering buffer in an audio processing application, a static prompt can be configured and fixed at 16 KiB to meet real-time requirements. The static prompt provides stable performance guarantees for performance-sensitive or deterministic tasks, avoiding performance fluctuations that may arise from dynamic strategies.

[0043] In this embodiment, the dynamic prompt is used to associate a set of memory big page size selection strategies with its associated virtual memory segment. The strategy dynamically determines the target memory big page size based on one or more runtime environment state parameters.

[0044] In this embodiment of the application, the environmental state parameters may include at least one of the following: the physical memory access characteristics of the first virtual memory segment; the physical memory resource pressure state of the electronic device; and the degree of physical memory fragmentation of the electronic device.

[0045] In this embodiment, the physical memory access characteristics of the first virtual memory segment include memory large page access utilization, which is defined as the proportion of the physical memory capacity actually accessed by the processor within the allocated memory large pages in the virtual memory segment to the total physical capacity of the allocated memory large pages in that segment. The target memory large page size is positively correlated with the memory large page access utilization.

[0046] As one implementation method, multiple incremental utilization thresholds are predefined; when the memory large page access utilization reaches the highest utilization threshold, the largest size memory large page is selected; when the memory large page access utilization is in the middle utilization threshold range, the medium size memory large page is selected; when the memory large page access utilization is in the lowest utilization threshold range, the smaller size memory large page is selected; when the memory large page access utilization is lower than the lowest utilization threshold, the basic memory page is used.

[0047] For example, three incremental utilization thresholds are predefined: the first utilization threshold (lowest) is 30%, the second utilization threshold (middle) is 60%, and the third utilization threshold (highest) is 85%. The allocatable large page sizes are 64KiB, 32KiB, and 16KiB, respectively, with a base page size of 4KiB.

[0048] If the memory page access utilization of a virtual memory segment is detected to be 90%, since 90% is higher than the third utilization threshold (85%), the largest size 64KiB memory page is selected for this virtual memory segment. If the memory page access utilization of this virtual memory segment drops to 70%, which is between the second and third utilization thresholds (60%), a medium-sized 32KiB memory page will be selected. If the memory page access utilization of this virtual memory segment further drops to 45%, which is between the first and second utilization thresholds (30%), a smaller size 16KiB memory page will be selected. If the memory page access utilization of this virtual memory segment is only 15%, which is lower than the first utilization threshold (30%), the use of large pages will be abandoned, and a 4KiB basic memory page will be used instead.

[0049] In this embodiment, the physical memory resource pressure state of an electronic device characterizes the degree of physical memory scarcity, which can be quantified by the physical memory scarcity rate, defined as: (Total physical memory - Available physical memory) / Total physical memory. The higher this value, the greater the physical memory resource pressure on the electronic device. The target large page size is negatively correlated with the physical memory resource pressure state of the electronic device; that is, the more scarce the physical memory resources of the electronic device, the smaller the large page size should be selected.

[0050] As one implementation method, multiple incremental physical memory scarcity rate thresholds are predefined to classify different levels of physical memory resource pressure. When the physical memory scarcity rate is below the minimum scarcity rate threshold, it indicates that physical memory resources are sufficient, and the largest size memory page is selected. When the physical memory scarcity rate is in the middle scarcity rate threshold range, the medium size memory page is selected. When the physical memory scarcity rate is in the higher scarcity rate threshold range, the smaller size memory page is selected. When the physical memory scarcity rate is above the highest scarcity rate threshold, it indicates that physical memory is extremely strained, and the basic memory page is used.

[0051] For example, assume a total physical memory of 8 GiB and predefined three increasing physical memory scarcity thresholds: a first scarcity threshold (lowest) of 20%, a second scarcity threshold (middle) of 40%, and a third scarcity threshold (highest) of 60%. Allocatable large page sizes are 64 KiB, 32 KiB, and 16 KiB, with a base page size of 4 KiB.

[0052] If the current available physical memory is 6.4 GiB, then the physical memory shortage rate is (8-6.4) / 8 = 20%. Since the physical memory shortage rate equals the first shortage rate threshold (20%), meaning physical memory is sufficient, the largest size 64KiB memory page is chosen. If the available physical memory drops to 5.0 GiB, then the physical memory shortage rate is (8-5) / 8 = 37.5%. At this point, the physical memory shortage rate is between the first shortage rate threshold (20%) and the second shortage rate threshold (40%), meaning physical memory is slightly strained. Therefore, the medium size 32KiB memory page is chosen. If the available physical memory drops to 3.0 GiB, then the physical memory shortage rate is (8-3) / 8 = 40%. At this point, the physical memory shortage rate is between the second shortage rate threshold (40%) and the third shortage rate threshold (60%), meaning physical memory is moderately strained. Therefore, the smaller size 16KiB memory page is chosen. If only 1.0 GiB of physical memory remains, the physical memory shortage rate is (8-1) / 8 = 87.5%. Since the physical memory shortage rate is higher than the third shortage rate threshold (60%), meaning that physical memory is extremely scarce, we will abandon the use of large pages and use 4 KiB basic pages to maximize the utilization of fragmented physical memory.

[0053] In this embodiment, the degree of physical memory fragmentation of an electronic device characterizes the scarcity of contiguous free pages in the physical memory of the electronic device. It can be quantified by the physical memory fragmentation rate, defined as: non-migratable pages / total available pages. A higher value indicates more severe physical memory fragmentation, while a lower value indicates more complete physical memory. The target large page size is negatively correlated with the degree of physical memory fragmentation of the electronic device; that is, the higher the physical memory fragmentation rate of the electronic device, the smaller the large page size should be selected.

[0054] As one implementation method, multiple decreasing fragmentation rate thresholds are predefined; when the physical memory fragmentation rate is lower than the lowest fragmentation rate threshold, the largest memory page is selected; when the physical memory fragmentation rate is in the middle fragmentation rate threshold range, the medium-sized memory page is selected; when the physical memory fragmentation rate is in the higher fragmentation rate threshold range, the smaller memory page is selected; otherwise, the basic memory page is used.

[0055] For example, three decreasing fragmentation thresholds are predefined: the first fragmentation threshold (highest) is 50% (severe fragmentation), the second fragmentation threshold (middle) is 30% (moderate fragmentation), and the third fragmentation threshold (lowest) is 15% (very light fragmentation). Allocable large page sizes are 64KiB, 32KiB, and 16KiB, with a base page size of 4KiB. If the current physical memory fragmentation rate is calculated to be 10%, since 10% is below or equal to the third fragmentation threshold (15%), it indicates that the physical memory is very contiguous, and the success rate of allocating large pages is high. Therefore, the largest size 64 KiB memory page is selected. If, after running for a period of time, the physical memory fragmentation rate rises to 25%, it falls between the second fragmentation threshold (30%) and the third fragmentation threshold (15%). To balance success rate and performance, a medium-sized 32 KiB memory page is selected. If the physical memory fragmentation rate further rises to 40%, it falls between the first fragmentation threshold (50%) and the second fragmentation threshold (30%). Allocating contiguous large blocks of memory becomes very difficult, so a smaller size 16 KiB memory page is selected. If the memory is extremely fragmented, with the physical memory fragmentation rate reaching 60%, since 60% is above the first fragmentation threshold (50%), it is almost impossible to allocate any size contiguous large page. Therefore, the use of large pages is abandoned, and a 4 KiB base memory page is used directly.

[0056] In this embodiment, the above-mentioned environmental state parameters can be used individually or in combination. For example, for the virtual memory segment corresponding to the file mapping area of ​​the document reader, the utilization rate of memory big pages and the physical memory resource pressure can be considered comprehensively: when physical memory is sufficient, a 256KiB big page can be selected, and when physical memory is tight, a 64KiB or smaller size can be selected.

[0057] It should be noted that, in order to clearly illustrate the principle of the strategy, the above exemplary values ​​should not be construed as limiting the scope of protection of this application.

[0058] In this embodiment, a dynamic prompt mechanism enables adaptive and intelligent physical memory management. It automatically adjusts the bigpage allocation strategy based on the application's running status and the system's global resource availability, achieving precise on-demand allocation. This mechanism effectively solves the problem of wasted physical memory resources caused by traditional uniform allocation. By dynamically adjusting the bigpage size or timely rollback to basic page allocation, it effectively improves the efficiency of physical memory resource utilization. By refining the control granularity from the application level to the internal virtual memory segment level, it provides a technical foundation for implementing differentiated physical memory allocation strategies.

[0059] In some embodiments, the aforementioned virtual memory segments are specifically implemented in mainstream operating system kernels: in the Linux kernel, they correspond to Virtual Memory Areas (VMAs) and are described by the `vm_area_struct` structure; in the XNU kernel, they correspond to Virtual Memory Map Entry (VM Map Entry) and are implemented by the `vm_map_entry` structure. Both of these data structures are core metadata used by the operating system kernel to manage the process address space. A process's complete virtual address space layout (including code segments, data segments, heap, stack, shared library mappings, memory-mapped files, etc.) is composed of multiple such virtual memory segments.

[0060] In this embodiment, extending the mature kernel mechanisms such as the Linux kernel and XNU kernel has the following advantages: By directly reusing the existing memory management framework, there is no need to change the basic architecture of the process address space. This method can be implemented by enhancing the kernel module, effectively reducing the complexity of system integration; This design makes this method naturally compatible with the two major kernel systems of Linux and XNU, and the protection scope covers various electronic devices based on these kernels; Since VMA and VM Map Entry are the natural granularity of memory management, by associating the memory big page allocation prompt with these structures, the allocation strategy and the life cycle of the memory region can be synchronized, ensuring that fine-grained memory allocation control can be seamlessly embedded into core memory management processes such as page fault handling.

[0061] In step 102, the target memory page size corresponding to the first virtual memory segment is determined based on the type of the memory page allocation prompt.

[0062] In this embodiment, by identifying the specific type of the memory large page allocation prompt, the most suitable memory allocation strategy can be matched for different virtual memory segments. This mechanism can both ensure deterministic low-latency access to performance-sensitive virtual memory segments through static prompts and achieve adaptive resource allocation based on the real-time status of the electronic device through dynamic prompts, thereby achieving the goal of precise allocation and efficient utilization of physical memory resources.

[0063] In some embodiments, the type of memory big page allocation prompt includes a static prompt and a dynamic prompt; accordingly, step 102 above may specifically include the following steps: step 1021 and step 1022.

[0064] In step 1021, if the memory page allocation prompt is a static prompt, the fixed size indicated by the memory page allocation prompt is determined as the target memory page size corresponding to the first virtual memory segment.

[0065] In this embodiment of the application, when the memory big page allocation prompt of the first virtual memory segment is identified as a static prompt, all complex decision-making logic is bypassed, and the fixed size (such as 64KiB) embedded in the prompt is directly read and used as the target memory big page size. This process is efficient, has no overhead, and the result is predictable.

[0066] In step 1022, when the memory big page allocation prompt is a dynamic prompt, the target memory big page size corresponding to the first virtual memory segment is determined according to the memory big page size selection strategy; wherein, the memory big page size selection strategy is used to dynamically select a big page size based on one or more environmental state parameters associated with the memory allocation decision.

[0067] In this embodiment of the application, when the memory page allocation prompt of the first virtual memory segment is identified as a dynamic prompt, the system will calculate the most suitable memory page size at the current moment based on at least one current environmental state parameter (such as memory page utilization, physical memory pressure state, etc.) using built-in algorithms and rules, and use it as the target memory page size. This process is adaptive and intelligent.

[0068] In this embodiment, for virtual memory segments with high performance requirements (such as the virtual memory segment corresponding to the audio rendering buffer), static prompts can be associated to ensure performance stability and low latency. For general or complex virtual memory segments (such as the virtual memory segment corresponding to the application heap), dynamic prompts can be associated to achieve adaptive resource adjustment. This ensures both the experience of critical services and maximizes the utilization efficiency of physical memory resources.

[0069] As can be seen, in this embodiment of the application, by supporting both static and dynamic strategies, it not only meets the deterministic requirements in specific scenarios, but also achieves adaptive optimization for most scenarios, thus exhibiting high flexibility.

[0070] In step 103, physical memory is allocated for the first virtual memory segment based on the target memory page size.

[0071] In this embodiment of the application, "allocating physical memory" means first obtaining consecutive physical page frames from physical memory, and then establishing a correspondence between the virtual address of the first virtual memory segment and the obtained physical page frames for the processor to access.

[0072] In some embodiments, step 103 may specifically include the following steps: step 1031, step 1032 and step 1033.

[0073] In step 1031, physical memory is allocated in units of the target memory page size.

[0074] In this embodiment of the application, a contiguous block of large page memory of the same size is requested from the physical memory manager according to the target large page size.

[0075] In step 1032, if the allocation is successful, the allocated physical memory is mapped to the first virtual memory segment.

[0076] In this embodiment of the application, if the allocation of the large page memory of the target memory large page size is successful, the mapping relationship between the virtual address of the first virtual memory segment and the allocated large page memory is established by manipulating the page table, so that the application can access the large page memory through the virtual address.

[0077] In step 1033, if the allocation fails, the post-processing strategy for memory large page allocation failure is executed.

[0078] In this embodiment, if the allocation of a large page of the target memory size fails, a post-processing strategy for large page allocation failure is executed. This post-processing strategy is a fault-tolerance mechanism for physical memory allocation failures. This mechanism effectively addresses allocation anomalies caused by physical memory fragmentation or resource pressure, preventing interruptions to the processing flow due to a single allocation failure. It ensures the continuous execution capability of the physical memory allocation process under non-ideal resource conditions, thereby enhancing overall robustness and reliability.

[0079] For example, if the target memory page size is 64KiB, the operating system kernel will attempt to find a contiguous 64KiB block of physical memory. If successful, the page table mapping for the entire 64KiB range will be established at once; if it fails, the handling strategy after allocation failure will be triggered (such as downgrading to attempting to allocate 32KiB).

[0080] In some embodiments, the above-described post-processing strategy for memory massive page allocation failure may include: Based on predefined degradation rules, obtain a candidate target memory page size that is smaller; then allocate physical memory in units of the candidate target memory page size.

[0081] In this embodiment, the processing strategy defines a standardized degradation process: when the initial large page size allocation fails, the process is not terminated directly, but a smaller candidate size is selected according to predetermined rules and the allocation is re-initiated. This mechanism transforms a single allocation process into an iterative trial process, adapting to the real-time physical memory status of the electronic device through size degradation.

[0082] As can be seen, in this embodiment of the application, by establishing an automatic degradation path, allocation failures caused by physical memory fragmentation or resource pressure can be effectively addressed, improving allocation robustness and significantly increasing the success rate of physical memory allocation operations. Furthermore, the degradation mechanism enables electronic devices to dynamically adjust expected values ​​based on the current availability of physical memory, thereby improving the utilization efficiency of physical memory resources while ensuring basic functionality.

[0083] In some embodiments, predefined degradation rules may include at least one of the following: Halve the size of the failed target memory page. Select the next largest page size from a set of predefined large page sizes, which is the largest page size that was used when the current allocation failed.

[0084] For example, an initial target memory page size of 64KiB is selected. If allocation fails, iterative degradation is performed according to predefined rules: first, a 32KiB page is attempted; if successful, allocation is completed; if it fails, degradation continues to 16KiB; if still unsuccessful, degradation further downgrades to 8KiB. When all page sizes fail to allocate successfully, a 4KiB base memory page is finally used to complete memory allocation. That is, iterative degradation follows the order "64KiB→32KiB→16KiB→8KiB" until allocation is successful or a 4KiB base page is finally used. This degradation process adapts to the real-time physical memory state of electronic devices by continuously reducing the allocation granularity, ensuring reliable physical memory allocation even under resource-constrained conditions.

[0085] For example, the predefined descending sequence of large page sizes is: 64KiB, 32KiB, 16KiB. When allocation failure occurs, a degradation operation is performed according to this sequence: if the 64KiB allocation fails, the next largest size in the sequence, 32KiB, is automatically selected for retry; if the 32KiB allocation fails, the 16KiB size is selected for retry; if the 16KiB allocation also fails, the process falls back to the 4KiB base page to complete the final allocation. That is, the process attempts sequentially according to the predefined sequence "64KiB → 32KiB → 16KiB," and if all attempts fail, it falls back to the 4KiB base page. This mechanism achieves controllable degradation through the predefined size sequence, maintaining the determinism of the allocation process while ensuring that physical memory allocation can still be completed when physical memory resources are limited.

[0086] In this embodiment, the two degradation methods described above correspond to arithmetic degradation and sequential degradation, respectively. They complement each other and together constitute a systematic solution for handling physical memory allocation failures. Arithmetic degradation quickly locates the allocatable size based on the binary convergence principle; sequential degradation ensures the controllability and performance continuity of the degradation process through a pre-defined sequence. Both adhere to the principle of "maintaining the largest possible size," continuously optimizing physical memory access performance during the degradation process.

[0087] In some embodiments, the post-processing strategy for memory massive page allocation failure may further include: If allocation based on the candidate target memory large page size fails again, the degradation rules are executed iteratively until allocation is successful or the size is reduced to the base page size; if the size is reduced to the base page size, physical memory is allocated in units of the base page size.

[0088] In this embodiment, the degradation processing strategy has been significantly extended, and a complete iterative termination mechanism has been established. This mechanism transforms a single degradation attempt into a complete search process: by continuously iterating the application of degradation rules, it can actively find the maximum allocatable size under the constraints of available resources, and ultimately ensure successful base page allocation as a backup plan.

[0089] As can be seen, in this embodiment, by setting the base page as the final degradation target, a reliable allocation guarantee mechanism is established, ensuring that memory allocation requests can be successfully executed under any resource conditions, thereby effectively improving system reliability. The iterative degradation process ensures that the system continuously explores the maximum allocatable size under the current physical memory state, achieving continuous optimization of physical memory resource utilization. Clear termination conditions set clear boundaries for the process, preventing infinite loops and ensuring predictable and maintainable system behavior. This degradation and retry process is completed in the background by the operating system kernel, which is imperceptible to the application, thus ensuring that the entire degradation mechanism is completely transparent to upper-layer applications, providing a consistent memory service experience for applications, and effectively ensuring the smoothness of user operations.

[0090] In summary, this embodiment of the application constructs a complete physical memory allocation closed loop through a three-level processing mechanism of "attempted allocation → successful mapping → failure handling". This process not only ensures allocation efficiency under ideal conditions, but also ensures system resilience when resources are limited through degradation strategies, thereby realizing a complete technical closed loop from decision-making to execution and improving the overall reliability of the system in complex environments.

[0091] In some embodiments, step 103 above may be triggered in any of the following scenarios: When the first virtual memory segment is created; When a page fault occurs in the first virtual memory segment.

[0092] In this embodiment, two core triggering events for physical memory allocation are clearly defined: the first trigger occurs during the virtual memory segment creation phase, completing the initial allocation of the virtual memory space and reducing the frequency of subsequent page faults; the second trigger occurs during runtime page fault handling, realizing the actual filling of the created virtual memory segment and ensuring optimal performance of runtime memory access. These two events correspond to different stages of the virtual memory segment lifecycle, together constituting a complete physical memory allocation triggering system.

[0093] As can be seen from the above embodiments, in this embodiment, a memory big page allocation prompt for a first virtual memory segment of a first application is obtained; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; the target memory big page size corresponding to the first virtual memory segment is determined according to the type of the memory big page allocation prompt; and physical memory is allocated for the first virtual memory segment based on the target memory big page size. It is evident that in this embodiment, by refining the control granularity of memory big page allocation to the virtual memory segment level and introducing a memory big page allocation prompt, the most suitable big page size can be dynamically adapted according to the specific access characteristics of each virtual memory segment, thereby improving the utilization rate of physical memory big pages and reducing the waste of physical memory resources caused by size mismatch.

[0094] The memory allocation method provided in this application can be executed by a memory allocation device. This application uses the execution of the memory allocation method by a memory allocation device as an example to illustrate the memory allocation device provided in this application.

[0095] Figure 2 This is a structural block diagram of a memory allocation device provided in an embodiment of this application, such as... Figure 2 As shown, the memory allocation device 200 may include: an acquisition module 201, a determination module 202, and an allocation module 203; The acquisition module 201 is used to acquire the memory big page allocation prompt of the first virtual memory segment of the first application; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; The determining module 202 is used to determine the target memory page size corresponding to the first virtual memory segment based on the type of the memory page allocation prompt. The allocation module 203 is used to allocate physical memory to the first virtual memory segment based on the target memory page size.

[0096] As can be seen from the above embodiments, in this embodiment, a memory big page allocation prompt for a first virtual memory segment of a first application is obtained; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rule when allocating physical memory for the first virtual memory segment; the target memory big page size corresponding to the first virtual memory segment is determined according to the type of the memory big page allocation prompt; and physical memory is allocated for the first virtual memory segment based on the target memory big page size.

[0097] As can be seen, in this embodiment of the application, by refining the control granularity of memory big page allocation to the virtual memory segment level and introducing a memory big page allocation prompt, the most suitable big page size can be dynamically adapted according to the specific access characteristics of each virtual memory segment, thereby improving the utilization rate of physical memory big pages and reducing the waste of physical memory resources caused by size mismatch.

[0098] Optionally, as an embodiment, the type of the memory massive page allocation prompt includes: a static prompt and a dynamic prompt; The determining module 202 is specifically used to determine the fixed size indicated by the memory page allocation prompt as the target memory page size corresponding to the first virtual memory segment when the memory page allocation prompt is a static prompt. When the memory big page allocation prompt is a dynamic prompt, the target memory big page size corresponding to the first virtual memory segment is determined according to the memory big page size selection strategy; wherein, the memory big page size selection strategy is used to dynamically select a big page size based on one or more environmental state parameters associated with the memory allocation decision.

[0099] Optionally, as an embodiment, the environmental state parameters include at least one of the following: The physical memory access characteristics of the first virtual memory segment; The physical memory resource pressure status of electronic devices; The degree of fragmentation of physical memory in electronic devices; The target memory page size is negatively correlated with the physical memory resource pressure state, and the target memory page size is negatively correlated with the physical memory fragmentation degree.

[0100] Optionally, as an embodiment, the allocation module 203 is specifically used to allocate physical memory in units of the target memory page size; if the allocation is successful, the allocated physical memory is mapped to the first virtual memory segment; if the allocation fails, a memory page allocation failure post-processing strategy is executed. The post-malfunction handling strategy for memory large page allocation failure includes: obtaining a candidate target memory large page size with a smaller size according to predefined degradation rules; and performing physical memory allocation in units of the candidate target memory large page size.

[0101] Optionally, as an example, the predefined degradation rules include at least one of the following: Halve the size of the failed target memory page. Select the next largest page size from a set of predefined large page sizes, which is the largest page size that was used when the current allocation failed.

[0102] The memory allocation device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the specific device.

[0103] The memory allocation device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit this. The memory allocation device provided in this application embodiment can implement the various processes implemented in the above method embodiments; to avoid repetition, these will not be described again here.

[0104] Optionally, such as Figure 3As shown, this application embodiment also provides an electronic device 300, including a processor 301 and a memory 302. The memory 302 stores a program or instructions that can run on the processor 301. When the program or instructions are executed by the processor 301, they implement the various steps of the above memory allocation method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0105] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0106] Figure 4 This is a schematic diagram of the hardware structure of an electronic device that implements the various embodiments of this application.

[0107] The electronic device 400 includes, but is not limited to, components such as: radio frequency unit 401, network module 402, audio output unit 403, input unit 404, sensor 405, display unit 406, user input unit 407, interface unit 408, memory 409, and processor 410.

[0108] Those skilled in the art will understand that the electronic device 400 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 410 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0109] Processor 410 is configured to obtain a memory big page allocation prompt for a first virtual memory segment of a first application; wherein the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rule when allocating physical memory for the first virtual memory segment; determine the target memory big page size corresponding to the first virtual memory segment according to the type of the memory big page allocation prompt; and allocate physical memory for the first virtual memory segment based on the target memory big page size.

[0110] As can be seen, in this embodiment of the application, by refining the control granularity of memory big page allocation to the virtual memory segment level and introducing a memory big page allocation prompt, the most suitable big page size can be dynamically adapted according to the specific access characteristics of each virtual memory segment, thereby improving the utilization rate of physical memory big pages and reducing the waste of physical memory resources caused by size mismatch.

[0111] Optionally, as an embodiment, the type of the memory massive page allocation prompt includes: a static prompt and a dynamic prompt; The processor 410 is specifically configured to, when the memory page allocation prompt is a static prompt, determine the fixed size indicated by the memory page allocation prompt as the target memory page size corresponding to the first virtual memory segment; When the memory big page allocation prompt is a dynamic prompt, the target memory big page size corresponding to the first virtual memory segment is determined according to the memory big page size selection strategy; wherein, the memory big page size selection strategy is used to dynamically select a big page size based on one or more environmental state parameters associated with the memory allocation decision.

[0112] Optionally, as an embodiment, the environmental state parameters include at least one of the following: The physical memory access characteristics of the first virtual memory segment; The physical memory resource pressure status of electronic devices; The degree of fragmentation of physical memory in electronic devices; The target memory page size is negatively correlated with the physical memory resource pressure state, and the target memory page size is negatively correlated with the physical memory fragmentation degree.

[0113] Optionally, as an embodiment, the processor 410 is specifically configured to allocate physical memory in units of the target memory page size; if the allocation is successful, the allocated physical memory is mapped to the first virtual memory segment; if the allocation fails, a memory page allocation failure post-processing strategy is executed. The post-malfunction handling strategy for memory large page allocation failure includes: obtaining a candidate target memory large page size with a smaller size according to predefined degradation rules; and performing physical memory allocation in units of the candidate target memory large page size.

[0114] Optionally, as an example, the predefined degradation rules include at least one of the following: Halve the size of the failed target memory page. Select the next largest page size from a set of predefined large page sizes, which is the largest page size that was used when the current allocation failed.

[0115] It should be understood that, in this embodiment, the input unit 404 may include a graphics processing unit (GPU) 4041 and a microphone 4042. The GPU 4041 processes image data of still images or videos acquired by an image acquisition device (such as a camera) in video acquisition mode or image acquisition mode. The display unit 406 may include a display panel 4061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 407 includes at least one of a touch panel 4071 and other input devices 4072. The touch panel 4071 is also called a touch screen. The touch panel 4071 may include a touch detection device and a touch controller. Other input devices 4072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.

[0116] The memory 409 can be used to store software programs and various data. The memory 409 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 409 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (Synchlink DRAM, SLDRAM), and direct memory bus RAM (DRRAM). The memory 409 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.

[0117] Processor 410 may include one or more processing units; optionally, processor 410 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 410.

[0118] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described memory allocation method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0119] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0120] This application also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described memory allocation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0121] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0122] This application also provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the memory allocation method embodiments described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0123] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, 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, article, 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, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0124] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (e.g., ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (e.g., a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0125] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A memory allocation method, characterized in that, The method includes: Obtain the memory big page allocation prompt for the first virtual memory segment of the first application; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; The target memory page size corresponding to the first virtual memory segment is determined based on the type of the memory page allocation prompt. Based on the target memory page size, allocate physical memory for the first virtual memory segment.

2. The method according to claim 1, characterized in that, The types of memory massive page allocation prompts include: static prompts and dynamic prompts; Determining the target memory page size corresponding to the first virtual memory segment based on the type of the memory page allocation prompt includes: When the memory page allocation prompt is a static prompt, the fixed size indicated by the memory page allocation prompt is determined as the target memory page size corresponding to the first virtual memory segment; When the memory big page allocation prompt is a dynamic prompt, the target memory big page size corresponding to the first virtual memory segment is determined according to the memory big page size selection strategy; wherein, the memory big page size selection strategy is used to dynamically select a big page size based on one or more environmental state parameters associated with the memory allocation decision.

3. The method according to claim 2, characterized in that, The environmental state parameters include at least one of the following: The physical memory access characteristics of the first virtual memory segment; The physical memory resource pressure status of electronic devices; The degree of fragmentation of physical memory in electronic devices; The target memory page size is negatively correlated with the physical memory resource pressure state, and the target memory page size is negatively correlated with the physical memory fragmentation degree.

4. The method according to claim 1, characterized in that, The step of allocating physical memory to the first virtual memory segment based on the target memory page size includes: Physical memory allocation is performed in units of the target memory page size; If the allocation is successful, the allocated physical memory will be mapped to the first virtual memory segment; If allocation fails, the post-mallocation strategy for large page allocation failure will be executed. The post-malfunction handling strategy for memory large page allocation failure includes: obtaining a candidate target memory large page size with a smaller size according to predefined degradation rules; and performing physical memory allocation in units of the candidate target memory large page size.

5. The method according to claim 4, characterized in that, The predefined degradation rules include at least one of the following: Halve the size of the failed target memory page. Select the next largest page size from a set of predefined large page sizes, which is the largest page size that was used when the current allocation failed.

6. A memory allocation device, characterized in that, The device includes: The acquisition module is used to acquire the memory big page allocation prompt of the first virtual memory segment of the first application; wherein, the first virtual memory segment is a contiguous virtual memory segment divided according to the memory access permissions and / or mapping object type of the first application; the memory big page allocation prompt is used to indicate the big page size decision rules when allocating physical memory for the first virtual memory segment; The determining module is used to determine the target memory page size corresponding to the first virtual memory segment based on the type of the memory page allocation prompt; The allocation module is used to allocate physical memory to the first virtual memory segment based on the target memory page size.

7. The apparatus according to claim 6, characterized in that, The types of memory massive page allocation prompts include: static prompts and dynamic prompts; The determining module is specifically used to determine the fixed size indicated by the memory page allocation prompt as the target memory page size corresponding to the first virtual memory segment when the memory page allocation prompt is a static prompt; When the memory big page allocation prompt is a dynamic prompt, the target memory big page size corresponding to the first virtual memory segment is determined according to the memory big page size selection strategy; wherein, the memory big page size selection strategy is used to dynamically select a big page size based on one or more environmental state parameters associated with the memory allocation decision.

8. The apparatus according to claim 7, characterized in that, The environmental state parameters include at least one of the following: The physical memory access characteristics of the first virtual memory segment; The physical memory resource pressure status of electronic devices; The degree of fragmentation of physical memory in electronic devices; The target memory page size is negatively correlated with the physical memory resource pressure state, and the target memory page size is negatively correlated with the physical memory fragmentation degree.

9. The apparatus according to claim 6, characterized in that, The allocation module is specifically used to allocate physical memory in units of the target memory page size; if the allocation is successful, the allocated physical memory is mapped to the first virtual memory segment. If allocation fails, the post-mallocation strategy for large page allocation failure will be executed. The post-malfunction handling strategy for memory large page allocation failure includes: obtaining a candidate target memory large page size with a smaller size according to predefined degradation rules; and performing physical memory allocation in units of the candidate target memory large page size.

10. The apparatus according to claim 9, characterized in that, The predefined degradation rules include at least one of the following: Halve the size of the failed target memory page. Select the next largest page size from a set of predefined large page sizes, which is the largest page size that was used when the current allocation failed.

11. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing programs or instructions that can run on the processor, the programs or instructions being executed by the processor to implement the steps of the memory allocation method as described in any one of claims 1-5.