A method, apparatus and electronic device for allocating a virtual memory address space

By setting priority regions and priority blocks in the virtual memory address space, memory blocks are allocated according to the requested space size, thus solving the memory fragmentation problem and improving memory utilization and allocation efficiency.

CN115437774BActive Publication Date: 2026-02-03GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110614194.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-02
Publication Date
2026-02-03
Estimated Expiration
2041-06-02

AI Technical Summary

Technical Problem

In existing technologies, the allocation of virtual memory address space is prone to memory fragmentation, resulting in low memory utilization.

Method used

By pre-setting priority regions, which include several priority blocks, and each block containing multiple memory blocks of the same size, memory blocks are allocated according to the size of the virtual memory request, and virtual address space is allocated in non-priority regions to satisfy the request.

Benefits of technology

It improves the utilization of the virtual memory address space, reduces memory fragmentation, and improves the efficiency of memory allocation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437774B_ABST
    Figure CN115437774B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of memory processing, and discloses a virtual memory address space allocation method, a virtual memory address space allocation device and electronic equipment. On one hand, the virtual memory address space allocation method sets a priority area, the priority area comprises a plurality of priority blocks, each priority block comprises a plurality of memory blocks with the same size, which is conducive to matching corresponding memory blocks for a virtual memory allocation request. On the other hand, the virtual memory allocation request is obtained, the space size of the virtual memory request space is determined, the priority block corresponding to the virtual memory request space is matched, and the idle memory block in the corresponding priority block is determined to be allocated to the virtual memory allocation request. The application can improve the utilization rate of the virtual memory address space.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of memory processing, and in particular to a virtual memory address space allocation method and device and electronic equipment. BACKGROUND

[0002] Virtual memory address space, also known as virtual address space, is a virtual address mode, which includes virtual memory address (VMA), also known as virtual address (VA), and is divided into occupied state and free state according to whether the virtual address is used.

[0003] In an operating system, a dynamic memory management mechanism is usually used, and the kernel allocates virtual memory to threads with memory requirements, and after the threads are executed, the memory is released to continue to allocate memory to other threads with memory requirements.

[0004] At present, in the virtual address space, when a continuous free virtual address that can be allocated is found, it is allocated to a memory request. Since the size of each virtual address allocation and release fluctuates greatly, when the continuous free virtual address left after the release of a small memory is distributed in various discontinuous areas of the memory space, memory fragmentation is easily caused. SUMMARY

[0005] Embodiments of the present application provide a virtual memory address space allocation method, device and electronic equipment, which can solve the technical problem of memory fragmentation in current virtual memory allocation and improve the utilization rate of virtual memory address space.

[0006] In a first aspect, embodiments of the present application provide a virtual memory address space allocation method applied to an electronic device, the electronic device including a virtual memory address space, and the method includes:

[0007] Pre-setting a priority area, wherein the priority area is located in the virtual memory address space, and the priority area includes a plurality of priority blocks, and each priority block includes a plurality of memory blocks of the same size;

[0008] Obtaining a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space;

[0009] According to the size of the virtual memory request space, matching the priority block corresponding to the virtual memory request space, and determining the free memory block in the corresponding priority block to allocate to the virtual memory allocation request.

[0010] In some embodiments, the method further includes:

[0011] establishing a mapping relationship between each priority block in the priority region and a memory block identifier, wherein each priority block corresponds to a memory block identifier, and wherein the memory block identifier is used to identify a size of a memory block included in the priority block.

[0012] In some embodiments, the matching the priority block corresponding to the virtual memory request space according to the size of the virtual memory request space comprises:

[0013] If the size of the virtual memory request space is within a preset range of the size of a memory block, the priority block corresponding to the virtual memory request space is determined to be the priority block in which the memory block is located.

[0014] In some embodiments, the preset range of the size of the memory block is [half of the size of the memory block, the size of the memory block].

[0015] In some embodiments, the method further comprises:

[0016] When all memory blocks in any one priority block are occupied, a backup priority block is divided from the virtual memory address space.

[0017] In some embodiments, the virtual memory address space is divided into a priority region and a non-priority region, and the dividing the backup priority block from the virtual memory address space comprises:

[0018] The backup priority block is divided from the non-priority region, wherein the backup priority block includes a plurality of memory blocks, and each memory block in the backup priority block has the same size as a memory block in the priority block.

[0019] In some embodiments, the method further comprises:

[0020] When the size of the virtual memory request space corresponding to the obtained virtual memory allocation request does not match the corresponding priority block, a virtual address space is allocated from the non-priority region to satisfy the virtual memory allocation request.

[0021] In some embodiments, the method further comprises:

[0022] If the idle virtual address space in the non-priority region is insufficient to satisfy the virtual memory allocation request, a virtual address space is allocated from the priority region to satisfy the virtual memory allocation request.

[0023] In some embodiments, the electronic device includes a first processor and a second processor, and the first processor and the second processor share the virtual memory address space.

[0024] In some embodiments, the first processor comprises a central processing unit, and the second processor comprises a graphics processing unit.

[0025] In a second aspect, an embodiment of the present application provides a virtual memory address space allocation apparatus, applied to an electronic device, the electronic device comprising a virtual memory address space, and the apparatus comprising:

[0026] a priority region setting unit, configured to set a priority region in advance, wherein the priority region is located in the virtual memory address space, and the priority region comprises a plurality of priority blocks, and each priority block comprises a plurality of memory blocks of the same size;

[0027] a memory request obtaining unit, configured to obtain a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space;

[0028] a virtual memory allocation unit, configured to match a priority block corresponding to the virtual memory request space according to a space size of the virtual memory request space, and determine an idle memory block in the corresponding priority block to allocate to the virtual memory allocation request.

[0029] In a third aspect, an embodiment of the present application provides an electronic device, comprising:

[0030] at least one processor; and

[0031] a memory in communication connection with the at least one processor; wherein

[0032] the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the virtual memory address space allocation method of the first aspect.

[0033] In a fourth aspect, an embodiment of the present application provides a non-volatile computer readable storage medium, the non-volatile computer readable storage medium storing computer executable instructions, and the computer executable instructions are used to enable an electronic device to execute the virtual memory address space allocation method of the first aspect.

[0034] In a fifth aspect, an embodiment of the present application provides a computer program, the computer program comprising program instructions, and when the program instructions are executed by one or more processors in an electronic device, the electronic device executes the virtual memory address space allocation method of the first aspect.

[0035] The beneficial effects of this application's embodiments are as follows: Unlike existing technologies, this application provides a method for allocating virtual memory address space, applied to an electronic device. The electronic device includes a virtual memory address space. The method includes: pre-setting a priority region, wherein the priority region is located within the virtual memory address space, and the priority region includes several priority blocks, each priority block including multiple memory blocks of the same size; obtaining a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space; matching the priority blocks corresponding to the virtual memory request space according to the size of the virtual memory request space, and determining free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation request. On one hand, by setting a priority region, which includes several priority blocks, each priority block including multiple memory blocks of the same size, it is beneficial to match corresponding memory blocks for virtual memory allocation requests. On the other hand, by obtaining virtual memory allocation requests, determining the size of the virtual memory request space, matching the priority blocks corresponding to the virtual memory request space, and determining free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation request, this application can improve the utilization rate of the virtual memory address space. Attached Figure Description

[0036] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0037] Figure 1 This is a schematic diagram of a virtual memory address space provided in an embodiment of this application;

[0038] Figure 2 This is a flowchart illustrating a method for allocating virtual memory address space according to an embodiment of this application;

[0039] Figure 3 This is a schematic diagram illustrating the process of allocating a virtual memory address space according to an embodiment of this application;

[0040] Figure 4 This is a schematic diagram of the overall process of another virtual memory address space allocation method provided in the embodiments of this application;

[0041] Figure 5 This is a schematic diagram of a partitioned maximum memory block provided in an embodiment of this application;

[0042] Figure 6 This is a flowchart illustrating another method for allocating virtual memory address space provided in an embodiment of this application;

[0043] Figure 7 This is a schematic diagram of another virtual memory address space provided in an embodiment of this application;

[0044] Figure 8 yes Figure 7 A schematic diagram of the priority region in the diagram;

[0045] Figure 9 This is a schematic diagram of the overall process of another virtual memory address space allocation method provided in the embodiments of this application;

[0046] Figure 10 This is a schematic diagram of the process of dividing a backup priority block according to an embodiment of this application;

[0047] Figure 11 This is a schematic diagram of the structure of a virtual memory address space allocation device provided in an embodiment of this application;

[0048] Figure 12 This is a schematic diagram of another virtual memory address space allocation device provided in an embodiment of this application;

[0049] Figure 13 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0050] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0051] It should be noted that, unless there is a conflict, the various features in the embodiments of this application can be combined with each other, all of which are within the protection scope of this application. Furthermore, although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than the module division in the device or the order in the flowchart. Moreover, the terms "first," "second," and "third" used in this application do not limit the data or execution order, but only distinguish identical or similar items with essentially the same function and effect.

[0052] Before providing a detailed description of this application, the nouns and terms used in the embodiments of this application will be explained, and the nouns and terms used in the embodiments of this application shall be interpreted as follows.

[0053] (1) Virtual memory address space refers to a portion of hard disk space used as memory by the operating system. This portion is called virtual memory address space. Virtual address space is used to solve the problem of scarce physical memory. The available range of virtual memory address space varies depending on whether the address bus is 32-bit or 64-bit. For example, if it is a 32-bit address bus, the virtual address space contains virtual memory addresses from 0 to 0xFFFFFFFF (4G), which is 4GB of address space. By default, all addresses in the virtual address space are initially in a free state. For example, the system allocates 4GB of virtual address space to each process (32-bit system) to store the virtual address of the process, and then the memory management unit maps the virtual address to the physical memory address.

[0054] (2) Memory unit refers to the smallest space allocated by virtual memory. In this application embodiment, the size of the memory unit can be set according to specific needs, for example, the size of a memory unit can be set to 1KB, 2KB or 4KB.

[0055] Currently, in the virtual address space, when a contiguous free virtual address is found that can be allocated, it is allocated to the memory request. When the thread finishes execution, the memory is released immediately. Since the size of each virtual address allocation and release varies greatly, when the contiguous free virtual addresses left after the small memory is released are distributed in various non-contiguous areas of the memory space, it is easy to cause memory fragmentation.

[0056] Based on this, this application provides a method for allocating virtual memory address space to solve the technical problem of memory fragmentation in current virtual memory allocation and improve the utilization rate of virtual memory address space.

[0057] Please see Figure 1 , Figure 1 This is a schematic diagram of a virtual memory address space provided in an embodiment of this application;

[0058] like Figure 1 As shown, this virtual memory address space corresponds to a 32-bit address bus. This virtual memory address space contains virtual memory addresses from 0 to 0xFFFFFFFF (4G), which is 4GB of address space.

[0059] It is understood that the virtual memory address space in this application embodiment can also be a 64-bit address bus. The following description takes a virtual memory address space corresponding to a 32-bit address bus as an example.

[0060] Please see Figure 2 , Figure 2 This is a flowchart illustrating a method for allocating virtual memory address space according to an embodiment of this application;

[0061] The virtual memory address space allocation method is applied to an electronic device, such as a mobile terminal, wherein the electronic device includes a virtual memory address space, and specifically, the virtual memory address space allocation method is applied to one or more processors of the electronic device.

[0062] like Figure 2 As shown, the method for allocating the virtual memory address space includes:

[0063] Step S201: Receive a first virtual memory allocation request, wherein the first virtual memory allocation request corresponds to a first virtual memory space;

[0064] Specifically, an application can correspond to a process / thread. When the application starts, the process / thread also starts. When the process / thread starts, the electronic device can allocate virtual memory space for the process / thread through the kernel for the application to use. When the application starts, the processor of the electronic device receives the first virtual memory allocation request sent by the process / thread. The first virtual memory allocation request corresponds to a first virtual memory space, which is the amount of memory required by the first virtual memory allocation request.

[0065] Step S202: Allocate a preset maximum memory block and divide the maximum memory block into two first memory blocks of the same size;

[0066] Specifically, when the processor receives a first virtual memory allocation request, it allocates a preset maximum memory block from the virtual memory address space of the electronic device, and divides the maximum memory block into two first memory blocks of the same size. The location of the preset maximum memory block is determined by the addressing direction; for example, the preset maximum memory block is located in the first virtual memory space along the addressing direction whose size satisfies the size of the maximum memory block.

[0067] It is understandable that, upon initial use, all addresses in the virtual memory address space are in a free state by default.

[0068] Step S203: Allocate one of the first memory blocks to the first virtual memory allocation request, and use the other first memory block as an idle first memory block, wherein the size of the first virtual memory space is not greater than the size of the first memory block.

[0069] Specifically, the first virtual memory allocation request corresponds to a first virtual memory space, and the size of the first virtual memory space is no greater than the size of the first memory block. Therefore, the first memory block can satisfy the first virtual memory allocation request. When the other first memory block is an idle first memory block, the idle first memory block is not released directly, but only when the entire largest memory block is in an idle state is the entire largest memory block released.

[0070] By allocating one of the first memory blocks to the first virtual memory allocation request and designating the other first memory block as an idle first memory block to wait for the next first virtual memory allocation request, this application can reduce fragmentation.

[0071] For details, please refer to [link / reference]. Figure 3 , Figure 3 This is a schematic diagram illustrating the process of allocating a virtual memory address space according to an embodiment of this application;

[0072] like Figure 3 As shown, the overall process of this virtual memory address space allocation method includes:

[0073] Step S301: Receive the first virtual memory allocation request;

[0074] Specifically, an application can correspond to a process / thread. When the application starts, the process / thread also starts. When the process / thread starts, the electronic device can allocate virtual memory space for the process / thread through the kernel for the application to use. When the application starts, the processor of the electronic device receives the first virtual memory allocation request sent by the process / thread. The first virtual memory allocation request corresponds to a first virtual memory space, which is the amount of memory required by the first virtual memory allocation request.

[0075] Step S302: Determine the first virtual memory space corresponding to the first virtual memory allocation request;

[0076] Specifically, the first virtual memory allocation request corresponds to the first virtual memory space, and after receiving the first virtual memory allocation request, the processor determines the first virtual memory space corresponding to the first virtual memory allocation request.

[0077] Step S303: Allocate a preset maximum memory block;

[0078] Specifically, when the processor receives the first virtual memory allocation request, it allocates a preset maximum memory block from the virtual memory address space of the electronic device. The size of the maximum memory block is preset, for example, the size of the maximum memory block is set to 1M, 2M or 4M. Preferably, in this embodiment of the application, the size of the maximum memory block is set to 1M.

[0079] Step S304: Based on the size of the first virtual memory space, divide the largest memory block into two first memory blocks of the same size;

[0080] Specifically, the size of the first virtual memory space is not greater than the size of the first memory block. Therefore, the largest memory block is divided into two first memory blocks of the same size, so that one of the first memory blocks is allocated to the first virtual memory allocation request. For example, if the size of the largest memory block is 1M, the largest memory block is divided into two first memory blocks, and the size of each memory block is 512KB.

[0081] Step S305: Allocate one of the first memory blocks to the first virtual memory allocation request, and use the other first memory block as a free first memory block;

[0082] Specifically, the first virtual memory allocation request corresponds to a first virtual memory space, and the size of the first virtual memory space is no larger than the size of the first memory block. Therefore, the first memory block can satisfy the first virtual memory allocation request. For example, if the size of the first memory block is 512KB and the size of the first virtual memory space corresponding to the first virtual memory allocation request is also 512KB, then one of the first memory blocks will be allocated to the first virtual memory allocation request, and the other first memory block will be designated as an idle first memory block. It is understood that the processor can determine which first memory block to allocate to the first virtual memory allocation request based on the addressing order; for example, the first memory block addressed first will be allocated to the first virtual memory allocation request.

[0083] Step S306: The next time the first virtual memory allocation request is received;

[0084] Specifically, when another application starts, the process / thread begins to start. When the process / thread starts, the electronic device can allocate virtual memory space for the process / thread through the kernel for the application to use. The process / thread sends a first virtual memory allocation request to the processor. The first virtual memory allocation request corresponds to a first virtual memory space. It can be understood that the size of the first virtual memory space corresponding to the previously received first virtual memory allocation request and the next received first virtual memory request can be the same or different. However, the size of the first virtual memory space corresponding to the previously received first virtual memory allocation request and the next received first virtual memory request is not greater than the size of the first memory block.

[0085] Step S307: Determine whether there is a free first memory block in the virtual memory address space;

[0086] Specifically, determine whether there is a free first memory block in the virtual memory address space. If yes, proceed to step S308: allocate the free first memory block to the first virtual memory allocation request; otherwise, return to step S303: allocate a preset maximum memory block.

[0087] Specifically, when there is a free first memory block in the virtual memory address space, the free first memory block is allocated to the first virtual memory allocation request; when there is no free first memory block in the virtual memory address space, a preset maximum memory block is reallocated and allocated to the first virtual memory allocation request.

[0088] Specifically, the step of reallocating a preset maximum memory block to allocate to the first virtual memory allocation request includes:

[0089] The reassigned maximum memory block is divided into two first memory blocks of the same size. One of the first memory blocks is allocated to the first virtual memory allocation request, and the other first memory block is left as an idle first memory block. This is equivalent to repeating the first step of dividing the maximum memory block, that is: allocating a preset maximum memory block, dividing the maximum memory block into two first memory blocks of the same size according to the size of the first virtual memory space, allocating one of the first memory blocks to the first virtual memory allocation request, and leaving the other first memory block as an idle first memory block.

[0090] Step S308: Allocate the free first memory block to the first virtual memory allocation request;

[0091] In this embodiment, by dividing the preset maximum memory block into two first memory blocks of the same size, and reserving the other first memory block after allocating one first memory block to wait for the next first virtual memory allocation request, this application can avoid the fragmentation problem caused by the process / thread releasing the virtual memory directly after use, and improve the utilization rate of the virtual memory address space.

[0092] Please refer to the following: Figure 4 , Figure 4 This is a schematic diagram of the overall process of another virtual memory address space allocation method provided in the embodiments of this application;

[0093] like Figure 4 As shown, the overall process of this virtual memory address space allocation method includes:

[0094] Step S401: Receive the Nth virtual memory allocation request;

[0095] Specifically, the Nth virtual memory allocation request corresponds to the Nth virtual memory space, where N is a positive integer and N≥1.

[0096] Step S402: Determine the Nth virtual memory space corresponding to the Nth virtual memory allocation request;

[0097] Specifically, the Nth virtual memory allocation request corresponds to the Nth virtual memory space. For example, the second virtual memory allocation request corresponds to the second virtual memory space, and the size of the second virtual memory space is 256KB.

[0098] Step S403: Determine whether there is a free Nth memory block in the virtual memory address space;

[0099] Specifically, it is determined whether there is a free Nth memory block in the virtual memory address space. The Nth memory block is used to satisfy the Nth virtual memory allocation request. If there is a free Nth memory block in the virtual memory address space, then proceed to step S404: allocate the free Nth memory block to the Nth virtual memory allocation request; if there is no free Nth memory block in the virtual memory address space, then proceed to step S405: determine whether there is a free (N-1)th memory block in the virtual memory address space.

[0100] Step S404: Allocate the free Nth memory block to the Nth virtual memory allocation request;

[0101] Specifically, if the virtual memory address space includes a free Nth memory block, it means that a certain (N-1)th memory block was previously allocated, and there is an unallocated Nth memory block. In this case, the free Nth memory block is allocated to the Nth virtual memory allocation request.

[0102] Step S405: Determine whether there is a free (N-1)th memory block in the virtual memory address space;

[0103] Specifically, the (N-1)th memory block is the parent memory block of the Nth memory block, and the size of the (N-1)th memory block is twice the size of the Nth memory block. For example, the size of the first memory block is twice the size of the second memory block.

[0104] If there is a free (N-1)th memory block in the virtual memory address space, proceed to step S406: divide the free (N-1)th memory block into two Nth memory blocks of the same size;

[0105] If there is a free N-1th memory block in the virtual memory address space, proceed to step S408: further determine whether there is a free upper-level memory block in the virtual memory address space, until it is determined that there is no first memory block in the virtual memory space;

[0106] Step S406: Divide the free (N-1)th memory block into two Nth memory blocks of the same size;

[0107] Specifically, if the Nth virtual memory allocation request is the third virtual memory allocation request, then the smallest memory block that satisfies the third virtual memory allocation request is the third memory block, then the Nth memory block is the third memory block, then the (N-1)th memory block is the second memory block, and at this time the second memory block is divided into two third memory blocks of the same size;

[0108] Step S407: Allocate one of the Nth memory blocks to the Nth virtual memory allocation request, and leave the other Nth memory block as a free Nth memory block;

[0109] Specifically, if the Nth memory block is the third memory block, and the (N-1)th memory block is the second memory block, then the second memory block is divided into two third memory blocks of the same size, and one of the third memory blocks is allocated to the third virtual memory allocation request, while the other third memory block is used as an idle third memory block.

[0110] Step S408: Further determine whether there is a free upper-level memory block in the virtual memory address space, until it is determined that there is no first memory block in the virtual memory space;

[0111] Specifically, the smallest memory block that satisfies the Nth virtual memory allocation request is the Nth memory block, where N is a positive integer. If there is no free Nth memory block in the virtual memory address space, it is determined whether there is a parent memory block of the Nth memory block, that is, whether there is a (N-1)th memory block, a (N-2)th memory block, a (N-3)th memory block, ..., a first memory block. If there is no first memory block, a maximum memory block is allocated.

[0112] In this embodiment of the application, the method further includes:

[0113] If there is a free upper-level memory block, the upper-level memory block is divided into two lower-level memory blocks of the same size. Then, one of the lower-level memory blocks is divided into two even lower-level memory blocks of the same size, and so on, until the Nth memory block is allocated, that is, the smallest memory block that satisfies the Nth virtual memory allocation request.

[0114] Step S409: Allocate a maximum memory block;

[0115] For details, please refer to [link / reference]. Figure 5 , Figure 5 This is a schematic diagram of a partitioned maximum memory block provided in an embodiment of this application;

[0116] like Figure 5 As shown, after allocating a maximum memory block, the maximum memory block is divided into two first memory blocks of the same size. Then, one of the first memory blocks is divided into two second memory blocks of the same size. Then, one of the second memory blocks is divided into two third memory blocks of the same size, and so on, until the Nth memory block is allocated, that is, the smallest memory block that satisfies the Nth virtual memory allocation request.

[0117] By searching for a parent memory block, after finding a free parent memory block, the free parent memory block is divided until the Nth memory block is reached. This is the smallest memory block required to satisfy the Nth virtual memory allocation request, thus enabling the creation of multiple memory block combinations. For example, if the free parent memory block is the first memory block and the smallest memory block required to satisfy the Nth virtual memory allocation request is the fourth memory block, then a second memory block, a third memory block, and two fourth memory blocks are created. One of the fourth memory blocks is then allocated to the Nth virtual memory allocation request. At this point, the virtual memory space still retains free second, third, and fourth memory blocks, which can better satisfy other virtual memory allocation requests and improve the utilization rate of the virtual memory space.

[0118] In this embodiment, the size of the Nth virtual memory space is not less than the size of a memory unit. The size of the memory unit can be set according to specific needs, for example, the size of a memory unit can be set to 1KB, 2KB, or 4KB. Preferably, in this embodiment, the size of a memory unit is 4KB.

[0119] In this embodiment, when the space of the largest memory block is partially occupied, the free space within the largest memory block is not released; when the space of the largest memory block is entirely free, the largest memory block is released. By reserving a portion of the free space within the largest memory block to await the next virtual memory allocation request, the memory fragmentation problem caused by immediately releasing memory after thread execution can be avoided.

[0120] It is understandable that when the size of the virtual memory space corresponding to the received virtual memory allocation request is greater than the size of the first memory block, but not greater than the size of the largest memory block, a largest memory block is allocated to the virtual memory allocation request.

[0121] When the size of the virtual memory space corresponding to the received virtual memory allocation request is greater than the size of the maximum memory block, a contiguous memory address space is searched in the virtual memory address space to allocate to the current virtual memory allocation request.

[0122] In this embodiment of the application, a method for allocating a virtual memory address space is provided and applied to an electronic device. The electronic device includes a virtual memory address space. The method includes: receiving a first virtual memory allocation request, wherein the first virtual memory allocation request corresponds to a first virtual memory space; allocating a preset maximum memory block and dividing the maximum memory block into two first memory blocks of the same size; allocating one of the first memory blocks to the first virtual memory allocation request, and the other first memory block as an idle first memory block, wherein the size of the first virtual memory space is not greater than the size of the first memory block.

[0123] In this embodiment of the application, in order to further solve the technical problem of memory fragmentation in the current virtual memory allocation and improve the utilization of virtual memory address space, this embodiment of the application provides another method for allocating virtual memory address space by pre-setting priority regions.

[0124] Please see Figure 6 , Figure 6 This is a flowchart illustrating another method for allocating virtual memory address space provided in an embodiment of this application;

[0125] This virtual memory address space allocation method is applied to electronic devices, such as mobile terminals. The electronic device includes a virtual memory address space, and comprises a first processor and a second processor that share the virtual memory address space. For example, the first processor includes a Central Processing Unit (CPU), and the second processor includes a Graphics Processing Unit (GPU). Specifically, this virtual memory address space allocation method is applied to one or more processors of the electronic device.

[0126] like Figure 6 As shown, the method for allocating the virtual memory address space includes:

[0127] Step S601: Pre-set a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes a number of priority blocks, each priority block including multiple memory blocks of the same size;

[0128] For details, please refer to [link / reference]. Figure 7 , Figure 7 This is a schematic diagram of another virtual memory address space provided in an embodiment of this application;

[0129] like Figure 7 As shown, the virtual memory address space is divided into priority regions and non-priority regions. The priority regions are used to satisfy virtual memory allocation requests with specific needs, such as virtual memory allocation requests with a space size within a certain range. The non-priority regions are used to satisfy virtual memory allocation requests without specific needs.

[0130] Please refer to the following: Figure 8 , Figure 8 yes Figure 7 A schematic diagram of the priority region in the diagram;

[0131] like Figure 8 As shown, the priority region includes several priority blocks, each of which corresponds to a memory block identifier. The memory block identifier is used to identify the size of the memory blocks included in the priority block, such as 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, or 1MB. Each priority block includes multiple memory blocks of the same size, each corresponding to a memory size. For example, all memory blocks within a certain priority block have a size of 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, or 1MB.

[0132] Specifically, by dividing the virtual memory address space into priority regions and non-priority regions, and setting the priority regions to include several priority blocks, for example, the priority regions include 9 priority blocks, and each priority block includes multiple memory blocks of the same size to satisfy virtual memory allocation requests of a specific size, this application can better handle virtual memory allocation requests of different virtual memory spaces, improve the utilization rate of the virtual memory address space, and improve the efficiency of virtual memory allocation by pre-setting priority blocks corresponding to the size of the virtual memory request space.

[0133] Step S602: Obtain a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space;

[0134] Specifically, an application can correspond to a process / thread. When the application starts, the process / thread also starts. When the process / thread starts, the electronic device can allocate virtual memory space for the process / thread through the kernel for the application to use. When the application starts, the processor of the electronic device receives a virtual memory allocation request sent by the process / thread, where the virtual memory allocation request corresponds to a virtual memory space, and the virtual memory space is the amount of memory required by the virtual memory allocation request.

[0135] Step S603: Based on the size of the virtual memory request space, match the priority block corresponding to the virtual memory request space, and determine the free memory block from the corresponding priority block to allocate to the virtual memory allocation request.

[0136] Specifically, matching the priority block corresponding to the virtual memory request space based on the space size includes:

[0137] If the size of the virtual memory request space is within a preset range of the size of a memory block, then the priority block corresponding to the virtual memory request space is determined to be the priority block where the memory block is located. For example, the preset range of the size of the memory block is (half the size of the memory block, the size of the memory block).

[0138] For details, please refer to [link / reference]. Figure 9 , Figure 9 This is a schematic diagram of the overall process of another virtual memory address space allocation method provided in the embodiments of this application;

[0139] like Figure 9 As shown, the overall process of this virtual memory address space allocation method includes:

[0140] Step S901: Pre-set priority area;

[0141] Specifically, the virtual memory address space is divided into priority regions and non-priority regions.

[0142] Step S902: Establish a mapping relationship between each priority block in the priority region and a memory block identifier, wherein each priority block corresponds to a memory block identifier;

[0143] Specifically, a mapping table is established, which stores the mapping relationship between each priority block in the priority region and the memory block identifier. By querying the mapping table, the memory block identifier corresponding to the priority block can be determined, wherein the memory block identifier includes the space size of each memory block included in the priority block.

[0144] Step S903: Obtain a virtual memory allocation request;

[0145] Specifically, the virtual memory allocation request is sent by a process / thread, the virtual memory allocation request corresponds to a virtual memory space, and the virtual memory space is the amount of memory required by the virtual memory allocation request.

[0146] Step S904: Determine the size of the virtual memory request space corresponding to the virtual memory allocation request;

[0147] Specifically, the size of the virtual memory request space corresponding to the virtual memory allocation request is the amount of memory required by the virtual memory allocation request. For example, if the memory requirement corresponding to a certain virtual memory allocation request is 512KB, then the size of the virtual memory request space is 512KB.

[0148] Step S905: Determine whether the size of the virtual memory request space is within the preset range of the size of a certain memory block;

[0149] Specifically, determine whether the size of the virtual memory request space corresponding to the virtual memory allocation request is within a preset range of the size of a certain memory block. If so, proceed to step S906: determine the priority block corresponding to the virtual memory allocation request.

[0150] If not, proceed to step S908: allocate virtual address space from the non-priority region to the virtual memory allocation request;

[0151] In this embodiment, the preset range of the memory block size is (half the memory block size, memory block size). For example, if the size of a memory block is 512KB, then the preset range of the memory block size is (256KB, 512KB). If the size of the virtual memory request space corresponding to a virtual memory allocation request is 500KB, then the size of the virtual memory request space is determined to be within the preset range of the memory block with a size of 512KB. At this time, the priority block corresponding to the virtual memory allocation request is determined to be the priority block with the memory block identifier of 512KB. Assuming that the memory block size of the priority blocks in the priority region is set to 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB and 1MB, if the size of the virtual memory request space corresponding to a virtual memory allocation request is 2MB, then the virtual memory request space corresponding to the virtual memory allocation request is not within the preset range of the memory block size. At this time, virtual address space is allocated to the virtual memory allocation request from the non-priority region.

[0152] Step S906: Determine the priority block corresponding to the virtual memory allocation request;

[0153] Specifically, the priority block corresponding to the virtual memory allocation request is determined based on the size of the virtual memory request space corresponding to the virtual memory allocation request.

[0154] Step S907: Determine a free memory block from the priority block and allocate it to the virtual memory allocation request;

[0155] Specifically, after determining the priority block corresponding to the virtual memory allocation request, a free memory block is determined from the priority block and allocated to the virtual memory allocation request. For example, the free memory block that is addressed fastest is allocated to the virtual memory allocation request.

[0156] Step S908: Allocate virtual address space from a non-priority region to the virtual memory allocation request;

[0157] Specifically, when the virtual memory request space corresponding to a virtual memory allocation request is not within the preset range of the size of a certain memory block, a virtual address space is allocated to the virtual memory allocation request from a non-priority region. Specifically, the virtual address space that satisfies the virtual memory allocation request is addressed from the non-priority region. For example, if the virtual memory request space corresponding to a certain virtual memory allocation request is 2M, then a 2M virtual address space is allocated to the virtual memory allocation request from the non-priority region.

[0158] In this embodiment, virtual memory allocation requests corresponding to virtual memory request spaces whose size is within a preset range of the size of a certain memory block are satisfied through the memory block. This embodiment can better allocate virtual memory to prevent memory fragmentation.

[0159] In this embodiment of the application, the method further includes:

[0160] Establish a mapping relationship between each priority block in the priority region and a memory block identifier, wherein each priority block corresponds to a memory block identifier, and the memory block identifier is used to identify the space size of the memory blocks included in the priority block.

[0161] Specifically, each priority block corresponds to a memory block identifier, meaning that all memory blocks within that priority block have a specific size. For example, all memory blocks within a given priority block may have sizes of 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, or 1MB. By establishing a mapping between each priority block and a memory block identifier within a priority region, where each priority block corresponds to a memory block identifier, and the memory block identifier identifies the size of the memory blocks within that priority block, this application can better determine the size of memory blocks within a priority region through memory block identifiers, thereby improving memory allocation.

[0162] It is understood that the size of the memory block in each priority block in this application embodiment can be set according to specific needs. For example, the size of the memory block can be set to 4KB, 8KB, 12KB, 16KB, 20KB, 24KB, etc., and is not limited here.

[0163] In this embodiment, the space size of each priority block can be the same or different. For example, the space size of the priority region is 90MB, and the priority region includes 9 priority blocks, each with a space size of 10MB. It is understood that because the space size of the memory blocks in each priority block is different, the number of memory blocks contained in each priority block is also different. For example, the number of memory blocks in a priority block identified as 4KB is twice the number of memory blocks in a priority block identified as 8KB, the number of memory blocks in a priority block identified as 8KB is twice the number of memory blocks in a priority block identified as 16KB, and so on. Similarly, the number of memory blocks in a priority block identified as 512KB is twice the number of memory blocks in a priority block identified as 1MB.

[0164] In the embodiments of this application, the number of memory blocks contained in each priority block can be the same or different. It is understood that since the space size of the memory blocks contained in each priority block is different, if the number of memory blocks contained in each priority block is the same, then the space size of each priority block is different. For example, the space size of a priority block identified as 8KB is twice the space size of a priority block identified as 4KB, the space size of a priority block identified as 16KB is twice the space size of a priority block identified as 8KB, and so on; the space size of a priority block identified as 1MB is twice the space size of a priority block identified as 512KB.

[0165] In this embodiment of the application, the method further includes:

[0166] When all memory blocks in any priority block are occupied, a spare priority block is allocated from the virtual memory address space.

[0167] Specifically, the virtual memory address space is divided into priority regions and non-priority regions, and the process of allocating spare priority blocks from the virtual memory address space includes:

[0168] The non-priority region is divided into a backup priority block, wherein the backup priority block includes multiple memory blocks, and the space size of each memory block in the backup priority block is the same as the space size of the memory blocks in the priority block.

[0169] Please refer to the following: Figure 10 , Figure 10 This is a schematic diagram of the process of dividing a backup priority block according to an embodiment of this application;

[0170] like Figure 10 As shown, the process of dividing the backup priority block includes:

[0171] Step S101: Determine the priority block corresponding to the virtual memory allocation request;

[0172] Specifically, the priority block corresponding to the virtual memory allocation request is determined based on the virtual memory request space corresponding to the virtual memory allocation request.

[0173] Step S102: Determine whether all memory blocks in the priority block are occupied;

[0174] Specifically, it is determined whether all memory blocks in the priority block are occupied. If so, proceed to step S103: divide the non-priority area into a spare priority block, wherein the spare priority block includes multiple memory blocks; if not, proceed to step S105: determine the free memory blocks in the priority block and allocate them to the virtual memory request.

[0175] It is understandable that when all memory blocks in the priority block are occupied, it means that there are no free memory blocks in the priority block. At this time, the virtual memory allocation request cannot be satisfied. Therefore, it is necessary to seek other virtual memory addresses to satisfy the virtual memory allocation request.

[0176] Step S103: Divide the non-priority area into a spare priority block, wherein the spare priority block includes multiple memory blocks;

[0177] Specifically, a backup priority block is allocated from the non-priority region, that is, a backup priority block is allocated from the non-priority region to the priority region. The backup priority block includes multiple memory blocks, and the space size of each memory block in the backup priority block is the same as the space size of the memory block in the priority block. It is equivalent to the backup priority block being a copy of the priority block corresponding to the virtual memory request. That is, a priority block that is exactly the same as the priority block corresponding to the virtual memory request is allocated from the non-priority region to satisfy the virtual memory request.

[0178] Step S104: Determine a free memory block from the spare priority block and allocate it to the virtual memory allocation request;

[0179] Specifically, free memory blocks are determined from the spare priority blocks and allocated to the virtual memory allocation request.

[0180] Understandably, if multiple spare priority blocks are divided from the non-priority area, the space size of the non-priority area may be reduced, making it unable to meet other virtual memory allocation requests, such as large virtual memory allocation requests. Therefore, this application also avoids the problem of overuse of spare priority blocks by reclaiming spare priority blocks.

[0181] Specifically, the method further includes:

[0182] When all memory blocks in the backup priority block are released, and there is at least one free memory block in the original priority block corresponding to the backup priority block, the backup priority block is assigned to the non-priority region. Here, the original priority block refers to the priority block in the priority region, and each original priority block corresponds to a memory block identifier.

[0183] Step S105: Determine a free memory block from the priority block and allocate it to the virtual memory request;

[0184] Specifically, when not all memory blocks in the priority block are occupied, it indicates that there are free memory blocks in the priority block. At this time, the free memory blocks in the priority block are determined and allocated to the virtual memory allocation request.

[0185] In this embodiment, a method for allocating virtual memory address space is provided and applied to an electronic device. The electronic device includes a virtual memory address space. The method includes: pre-setting a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes several priority blocks, each priority block including multiple memory blocks of the same size; obtaining a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space; matching the priority blocks corresponding to the virtual memory request space according to the size of the virtual memory request space, and determining free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation request. On the one hand, this method for allocating virtual memory address space, by setting a priority region including several priority blocks, each priority block including multiple memory blocks of the same size, facilitates matching corresponding memory blocks to virtual memory allocation requests. On the other hand, by obtaining virtual memory allocation requests, determining the size of virtual memory request spaces, matching priority blocks corresponding to virtual memory request spaces, and determining free memory blocks from the corresponding priority blocks to allocate to virtual memory allocation requests, this application can improve the utilization rate of virtual memory address space.

[0186] Please refer to the following: Figure 11 , Figure 11 This is a schematic diagram of the structure of a virtual memory address space allocation device provided in an embodiment of this application;

[0187] The virtual memory address space allocation device 110 is applied to an electronic device, specifically to one or more processors of the electronic device.

[0188] like Figure 11 As shown, the virtual memory address space allocation device 110 includes:

[0189] The memory allocation request unit 111 is used to receive a first virtual memory allocation request, wherein the first virtual memory allocation request corresponds to a first virtual memory space;

[0190] The memory partitioning unit 112 is used to allocate a preset maximum memory block and divide the maximum memory block into two first memory blocks of the same size.

[0191] The virtual memory allocation unit 113 is used to allocate one of the first memory blocks to the first virtual memory allocation request, and the other first memory block is used as an idle first memory block, wherein the size of the first virtual memory space is not greater than the size of the first memory block.

[0192] It should be noted that the above-described apparatus can execute the virtual memory address space allocation method provided in the embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the method. Technical details not described in detail in the apparatus embodiments can be found in the virtual memory address space allocation method provided in the embodiments of this application.

[0193] In this embodiment, a virtual memory address space allocation device is provided for use in an electronic device. The device includes: a memory allocation request unit for receiving a first virtual memory allocation request, wherein the first virtual memory allocation request corresponds to a first virtual memory space; a memory partitioning unit for allocating a preset maximum memory block and dividing the maximum memory block into two first memory blocks of equal size; and a virtual memory allocation unit for allocating one of the first memory blocks to the first virtual memory allocation request, and designating the other first memory block as an idle first memory block, wherein the size of the first virtual memory space is not greater than the size of the first memory block. By allocating one first memory block to the first virtual memory allocation request and designating the other first memory block as an idle first memory block to await the next first virtual memory allocation request, this application can solve the technical problem of memory fragmentation in current virtual memory allocation and improve the utilization rate of the virtual memory address space.

[0194] Please refer to the following: Figure 12 , Figure 12 This is a schematic diagram of another virtual memory address space allocation device provided in an embodiment of this application;

[0195] The virtual memory address space allocation device 120 is applied to an electronic device, specifically to one or more processors of the electronic device.

[0196] like Figure 12 As shown, the virtual memory address space allocation device 120 includes:

[0197] The priority region setting unit 121 is used to pre-set a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes a plurality of priority blocks, each priority block including a plurality of memory blocks of the same size.

[0198] The memory request acquisition unit 122 is used to acquire virtual memory allocation requests, wherein the virtual memory allocation requests correspond to virtual memory request space;

[0199] The virtual memory allocation unit 123 is used to match the priority block corresponding to the virtual memory request space according to the size of the virtual memory request space, and determine the free memory block from the corresponding priority block to allocate to the virtual memory allocation request.

[0200] It should be noted that the above-described apparatus can execute the virtual memory address space allocation method provided in the embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the method. Technical details not described in detail in the apparatus embodiments can be found in the virtual memory address space allocation method provided in the embodiments of this application.

[0201] In this embodiment, a virtual memory address space allocation device is provided and applied to an electronic device. The electronic device includes a virtual memory address space. The device includes: a priority region setting unit, used to pre-set a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes a plurality of priority blocks, each priority block including a plurality of memory blocks of the same size; a memory request acquisition unit, used to acquire a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space; and a virtual memory allocation unit, used to match the priority blocks corresponding to the virtual memory request space according to the size of the virtual memory request space, and determine free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation request. On the one hand, the virtual memory address space allocation method sets a priority region, which includes several priority blocks. Each priority block includes multiple memory blocks of the same size, which is beneficial for matching the corresponding memory blocks to the virtual memory allocation request. On the other hand, by obtaining the virtual memory allocation request, determining the size of the virtual memory request space, matching the priority block corresponding to the virtual memory request space, and determining the free memory block from the corresponding priority block to allocate to the virtual memory allocation request, this application can improve the utilization rate of the virtual memory address space.

[0202] Please see Figure 13 , Figure 13 This is a schematic diagram of the hardware structure of an electronic device according to various embodiments of this application;

[0203] like Figure 13 As shown, the electronic device 130 includes, but is not limited to, components such as: a radio frequency unit 131, a network module 132, an audio output unit 133, an input unit 134, a sensor 135, a display unit 136, a user input unit 137, an interface unit 138, a memory 139, a processor 1310, and a power supply 1311. The electronic device 130 also includes a camera. Those skilled in the art will understand that... Figure 13 The structure of the electronic device shown is not intended to limit the electronic device. An electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements. In the embodiments of this application, the electronic device includes, but is not limited to, televisions, mobile phones, tablet computers, laptops, PDAs, in-vehicle terminals, wearable devices, and pedometers.

[0204] The processor 1310 is configured to receive a first virtual memory allocation request, wherein the first virtual memory allocation request corresponds to a first virtual memory space; allocate a preset maximum memory block and divide the maximum memory block into two first memory blocks of the same size; allocate one of the first memory blocks to the first virtual memory allocation request, and the other first memory block as an idle first memory block, wherein the size of the first virtual memory space is not greater than the size of the first memory block.

[0205] In this embodiment of the application, by dividing the largest memory block into two first memory blocks of the same size when a first virtual memory allocation request is received, allocating one of the first memory blocks to the first virtual memory allocation request, and keeping the other first memory block as an idle first memory block to wait for the next first virtual memory allocation request, this application can solve the technical problem of memory fragmentation in current virtual memory allocation and improve the utilization rate of virtual memory address space.

[0206] Alternatively, the processor 1310 is configured to pre-set a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes a plurality of priority blocks, each priority block including a plurality of memory blocks of the same size; acquire a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space; match the priority block corresponding to the virtual memory request space according to the size of the virtual memory request space, and determine free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation request.

[0207] In this application embodiment, on the one hand, by setting a priority region, which includes several priority blocks, and each priority block includes multiple memory blocks of the same size, it is beneficial to match the corresponding memory blocks for virtual memory allocation requests. On the other hand, by obtaining virtual memory allocation requests, determining the size of the virtual memory request space, matching the priority blocks corresponding to the virtual memory request space, and determining free memory blocks from the corresponding priority blocks to allocate to the virtual memory allocation requests, this application can improve the utilization rate of the virtual memory address space.

[0208] It should be understood that, in this embodiment, the radio frequency unit 131 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink data from the base station and processes it with the processor 1310; additionally, it transmits uplink data to the base station. Typically, the radio frequency unit 131 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier, a duplexer, etc. Furthermore, the radio frequency unit 131 can also communicate with networks and other devices through a wireless communication system.

[0209] Electronic device 130 provides users with wireless broadband internet access through network module 132, such as helping users send and receive emails, browse web pages, and access streaming media.

[0210] The audio output unit 133 can convert audio data received by the radio frequency unit 131 or the network module 132 or stored in the memory 139 into audio signals and output them as sound. Furthermore, the audio output unit 133 can also provide audio output related to specific functions performed by the electronic device 130 (e.g., call signal reception sound, message reception sound, etc.). The audio output unit 133 includes a speaker, a buzzer, and a receiver, etc.

[0211] Input unit 134 is used to receive audio or video signals. Input unit 134 may include a graphics processing unit (GPU) 1341 and a microphone 1342. The GPU 1341 processes target images of still pictures or videos acquired by an image capture device (such as a camera) in video capture mode or image capture mode. The processed image frames can be displayed on display unit 136. The image frames processed by GPU 1341 can be stored in memory 139 (or other storage media) or transmitted via radio frequency unit 131 or network module 132. Microphone 1342 can receive sound and process such sound into audio data. The processed audio data can be converted into a format that can be transmitted to a mobile communication base station via radio frequency unit 131 in telephone call mode.

[0212] The electronic device 130 also includes at least one sensor 135, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 1361 according to the ambient light level, and the proximity sensor can turn off the display panel 1361 and / or backlight when the electronic device 130 is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used to identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc. The sensor 135 may also include a fingerprint sensor, pressure sensor, iris sensor, molecular sensor, gyroscope, barometer, hygrometer, thermometer, infrared sensor, etc., which will not be described in detail here.

[0213] The display unit 136 is used to display information input by the user or information provided to the user. The display unit 136 may include a display panel 1361, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.

[0214] User input unit 137 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of electronic devices. Specifically, user input unit 137 includes a touch panel 1371 and other input devices 1372. Touch panel 1371, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near touch panel 1371). Touch panel 1371 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 1310, which receives and executes commands from the processor 1310. In addition, touch panel 1371 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to touch panel 1371, user input unit 1377 may also include other input devices 1372. Specifically, other input devices 1372 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, joysticks, etc., which will not be described in detail here.

[0215] Furthermore, the touch panel 1371 can cover the display panel 1361. When the touch panel 1371 detects a touch operation on or near it, it transmits the information to the processor 1310 to determine the type of touch event. Subsequently, the processor 1310 provides corresponding visual output on the display panel 1361 based on the type of touch event. Although in Figure 13 In this embodiment, the touch panel 1371 and the display panel 1361 are two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 1371 and the display panel 1361 can be integrated to realize the input and output functions of the electronic device. The specific implementation is not limited here.

[0216] Interface unit 138 serves as an interface for connecting external devices to electronic device 130. For example, external devices may include a wired or wireless headphone port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, and so on. Interface unit 138 may be used to receive input from external devices (e.g., data, power, etc.) and transmit the received input to one or more components within electronic device 130, or it may be used to transmit data between electronic device 130 and external devices.

[0217] The memory 139 can be used to store software programs and various data. The memory 139 may mainly include a program storage area and a data storage area. The program storage area may store at least one application program 1391 required for a function (such as sound playback function, image playback function, etc.) and an operating system 1392, etc.; the data storage area may store data created based on the use of the mobile phone (such as audio data, phonebook, etc.). Furthermore, the memory 139 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0218] Processor 1310 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in memory 139, and by calling data stored in memory 139, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Processor 1310 may include one or more processing units; preferably, processor 1310 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into processor 1310.

[0219] The electronic device 130 may also include a power supply 1311 (such as a battery) for supplying power to various components. Preferably, the power supply 1311 can be logically connected to the processor 1310 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system.

[0220] In addition, the electronic device 130 includes some functional modules not shown, which will not be described in detail here.

[0221] Preferably, this application embodiment also provides an electronic device, including a processor 1310, a memory 139, and a computer program stored in the memory 139 and executable on the processor 1310. When the computer program is executed by the processor 1310, it implements the various processes of the above-described virtual memory address space allocation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0222] This application also provides a computer-readable storage medium storing a computer program. When executed by one or more processors, this computer program implements the various processes of the above-described virtual memory address space allocation method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0223] 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. Unless otherwise specified, 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.

[0224] The device or equipment embodiments described above are merely illustrative. The unit modules described as separate components may or may not be physically separate. The components shown as module units may or may not be physical units; that is, they may be located in one place or distributed across multiple network module units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0225] 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 software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile terminal, personal computer, server, or network device, etc.) to execute the methods described in various embodiments or some parts of the embodiments of this application.

[0226] Finally, it should be noted that the embodiments described above in conjunction with the accompanying drawings are only used to illustrate the technical solutions of this application. This application is not limited to the specific embodiments described above, which are merely illustrative and not restrictive. Under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of this application as described above. For the sake of brevity, they are not provided in detail. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A method for allocating virtual memory address space, applied to electronic devices, characterized in that, The electronic device includes a virtual memory address space, and the method includes: A priority region is pre-defined, wherein the priority region is located in the virtual memory address space, and the priority region includes several priority blocks, each priority block including multiple memory blocks of the same size, wherein in every two adjacent priority blocks, the size of a memory block included in the upper priority block is the sum of the size of the multiple memory blocks included in the lower priority block; Obtain a virtual memory allocation request, wherein the virtual memory allocation request corresponds to a virtual memory request space; Based on the size of the virtual memory request space, a priority block corresponding to the virtual memory request space is matched, and a free memory block is determined from the corresponding priority block and allocated to the virtual memory allocation request, wherein the free memory block that is addressed fastest is allocated to the virtual memory allocation request. Determine whether all memory blocks in the priority block are occupied; If so, a spare priority block is divided from the non-priority area, wherein the spare priority block includes multiple memory blocks; A free memory block is determined from the spare priority block and allocated to the virtual memory allocation request; When all memory blocks in the backup priority block are released, and there is at least one free memory block in the original priority block corresponding to the backup priority block, the backup priority block is assigned to the non-priority region. Here, the original priority block refers to the priority block in the priority region, and each original priority block corresponds to a memory block identifier.

2. The method according to claim 1, characterized in that, The method further includes: Establish a mapping relationship between each priority block in the priority region and a memory block identifier, wherein each priority block corresponds to a memory block identifier, and the memory block identifier is used to identify the space size of the memory blocks included in the priority block.

3. The method according to claim 1 or 2, characterized in that, The step of matching the priority block corresponding to the virtual memory request space based on the space size of the virtual memory request space includes: If the size of the virtual memory request space is within a preset range of the size of a memory block, then the priority block corresponding to the virtual memory request space is determined to be the priority block where the memory block is located.

4. The method according to claim 3, characterized in that, The preset range for the size of the memory block is (half the size of the memory block, the size of the memory block).

5. The method according to claim 1 or 2, characterized in that, The method further includes: When all memory blocks in any priority block are occupied, a spare priority block is allocated from the virtual memory address space.

6. The method according to claim 5, characterized in that, The virtual memory address space is divided into priority regions and non-priority regions. The step of allocating spare priority blocks from the virtual memory address space includes: The non-priority region is divided into a backup priority block, wherein the backup priority block includes multiple memory blocks, and the space size of each memory block in the backup priority block is the same as the space size of the memory blocks in the priority block.

7. The method according to claim 6, characterized in that, The method further includes: If the size of the virtual memory request space corresponding to the obtained virtual memory allocation request does not match the corresponding priority block, then virtual address space is allocated from the non-priority area to satisfy the virtual memory allocation request.

8. The method according to claim 7, characterized in that, The method further includes: If the free virtual address space in the non-priority region is insufficient to satisfy the virtual memory allocation request, then virtual address space is allocated from the priority region to satisfy the virtual memory allocation request.

9. The method according to any one of claims 1 or 2, or 6-8, characterized in that, The electronic device includes a first processor and a second processor, which share the virtual memory address space.

10. The method according to claim 9, characterized in that, The first processor includes a central processing unit, and the second processor includes a graphics processing unit.

11. A virtual memory address space allocation device, applied to electronic devices, characterized in that, The electronic device includes a virtual memory address space, and the device includes: A priority region setting unit is used to pre-set a priority region, wherein the priority region is located in the virtual memory address space, and the priority region includes a number of priority blocks, each priority block including multiple memory blocks of the same size, wherein in every two adjacent priority blocks, the size of a memory block included in the upper priority block is the sum of the multiple memory blocks included in the lower priority block; A memory request acquisition unit is used to acquire virtual memory allocation requests, wherein the virtual memory allocation requests correspond to virtual memory request spaces; A virtual memory allocation unit is configured to: match a priority block corresponding to the virtual memory request space based on the space size of the virtual memory request space; determine free memory blocks from the corresponding priority blocks and allocate them to the virtual memory allocation request, wherein the free memory block that is addressed fastest is allocated to the virtual memory allocation request; determine whether all memory blocks in the priority blocks are occupied; if so, divide a spare priority block from the non-priority region, wherein the spare priority block includes multiple memory blocks; determine free memory blocks from the spare priority blocks and allocate them to the virtual memory allocation request; when all memory blocks in the spare priority block are released, and at least one free memory block exists in the original priority block corresponding to the spare priority block, then divide the spare priority block into the non-priority region, wherein the original priority block refers to a priority block in the priority region, and each original priority block corresponds to a memory block identifier.

12. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform the virtual memory address space allocation method as described in any one of claims 1-10.

Citation Information

Patent Citations

  • Embedded system memory management method and device

    CN109857678A

  • Memory management method and device

    CN112650577A