Search

CN-122019185-A - Method for managing memory and computing device

CN122019185ACN 122019185 ACN122019185 ACN 122019185ACN-122019185-A

Abstract

A method for managing memory includes obtaining memory allocation request sent by target application, including at least the first identification corresponding to target instance waiting for memory allocation, matching the first identification with the current multiple active identifications, corresponding to multiple virtual memory pages being distributed, obtaining new virtual memory page if there is no active identification matched with the first identification, transmitting memory address in new virtual memory page to target application, realizing memory space isolation of each instance in application program at level of virtual memory page, and avoiding problem of batch instance crash caused by write overflow of single instance.

Inventors

  • YANG FAN
  • ZHANG WANGUO

Assignees

  • 支付宝(杭州)数字服务技术有限公司

Dates

Publication Date
20260512
Application Date
20260211

Claims (10)

  1. 1. A method of managing memory, the method involving a heap memory manager, the method comprising: Acquiring a memory allocation request sent by a target application, wherein the memory allocation request at least comprises a first identifier, and the first identifier corresponds to a target instance waiting for memory allocation; Matching the first identifier with a plurality of current active identifiers, wherein each active identifier corresponds to a plurality of allocated virtual memory pages, and the virtual memory pages corresponding to the plurality of active identifiers are different from each other; And if the active identification is not matched with the first identification, acquiring a new virtual memory page, and transmitting a memory address in the new virtual memory page to the target application.
  2. 2. The method of claim 1, matching the first identifier with a plurality of active identifiers at present, specifically comprising: determining whether an active identifier is matched with the first identifier or not in a corresponding relation table, wherein the corresponding relation table comprises a plurality of active identifiers, each active identifier corresponds to an in-operation instance which is allocated to a memory address and is not subjected to memory release, and the corresponding relation table also comprises a plurality of virtual memory pages which are allocated to the in-operation instance and correspond to each active identifier.
  3. 3. The method of claim 2, wherein the memory allocation request further comprises an applied memory length; transmitting the memory address in the newly added virtual memory page to the target application, specifically including: and transmitting the memory address of the virtual memory block which is in the newly added virtual memory page and is suitable for the memory length to the target application.
  4. 4. The method of claim 3, further comprising, after matching the first identification with a current number of active identifications: If the active identification is matched with the first identification, taking the virtual memory page corresponding to the matched active identification as a target memory page, and determining the address of the virtual memory block which is suitable for the memory length in the target memory page to transmit to the target application.
  5. 5. The method of claim 4, further comprising: And if the virtual memory block which is suitable for the memory length of the application does not exist in the target memory page, acquiring a newly added virtual memory page, and transmitting the memory address in the newly added virtual memory page to the target application.
  6. 6. The method of claim 5, after fetching the new virtual memory page, the method further comprising: And taking the first identifier as an active identifier, and updating the corresponding relation table according to the newly added virtual memory page.
  7. 7. The method of claim 2, further comprising: Acquiring a memory release request sent by a target application, wherein the memory release request at least comprises a second identifier, and the second identifier corresponds to an in-operation instance waiting for memory release; And matching the second identifier with the current active identifiers, and setting the virtual memory page corresponding to the matched active identifier to be in an unassigned state.
  8. 8. The method of claim 7, further comprising: Checking the data format of each virtual memory page corresponding to each running instance, and if any virtual memory page fails to be checked, determining the running instance corresponding to the virtual memory page as a problem instance; Transmitting a third identification to the target application, the third identification corresponding to the problem instance.
  9. 9. The method of claim 7, after setting the virtual memory page corresponding to the matched active identifier to an unassigned state, further comprising: and deleting the matched active identification from the corresponding relation table.
  10. 10. A computing device comprising a memory having executable code stored therein and a processor, which when executing the executable code, implements the method of any of claims 1-9.

Description

Method for managing memory and computing device Technical Field The embodiment of the specification belongs to the technical field of data processing, and particularly relates to a memory management method and computing equipment. Background In the running process of the server application, the general transaction processing flow is that a client request is received, an instance corresponding to the client request is newly built, the client request is processed, and a processing result is returned to the client. In the process of processing the client request, the server application needs to continuously apply memory for the same instance to store the intermediate data generated in the process. For example, multiple data queries and data aggregations may be involved in processing the same client request, each of which generates corresponding intermediate data, and each of which requires a corresponding memory space for storage. Heap memory is a dynamic memory area in a computer system that is distinguished from stack, global data, and code areas, allowing applications to apply for memory space of a specific size as needed at runtime. In the above-described process of processing an instance, the server application applies for memory for each instance through the heap memory allocator. Specifically, fig. 1 shows a process schematic of heap memory allocation, in which, to ensure the utilization efficiency of the memory, the underlying operating system may partition the physical memory into blocks in advance and provide a virtual memory map—virtual memory page corresponding to each physical memory block, the heap memory allocator may further partition each virtual memory page into a plurality of virtual memory blocks (the virtual memory blocks are not usually partitioned in advance before allocation, but only preset lengths for the virtual memory blocks are preset), and further, after receiving a memory allocation request sent by an application program, the heap memory allocator allocates an un-called virtual memory block for the memory allocation request (i.e., constructs a virtual memory block with a length that can cover the requirement of the memory allocation request according to the memory allocation request and the preset length, and returns the address of the constructed virtual memory block to the application program sending the memory allocation request). Thus, the application program has corresponding memory space for storing intermediate data in the process of processing each instance. It should be noted that, the server application often needs to receive client requests from multiple different clients at the same time, and thus often needs to process multiple instances concurrently (under certain conditions, different instances may also need to be established correspondingly for multiple client requests from the same client corresponding to different functional modules). If any instance of the above problems of write overflow occur (for example, for a certain memory allocation request, the heap memory allocator allocates a virtual memory block of 12 bytes (Byte), but the server application actually writes 16 bytes of intermediate data), the whole virtual memory page corresponding to the instance will not pass the verification at the heap memory allocator, and each instance of storing the intermediate data on the virtual memory page will terminate. Therefore, the present disclosure provides a technical solution for managing a memory, so as to at least partially solve the above-mentioned problems. Disclosure of Invention Embodiments of the present disclosure are directed to a method for managing memory and a computing device, including: A first aspect of the present specification provides a method of managing memory, the method involving a heap memory manager, the method comprising: Acquiring a memory allocation request sent by a target application, wherein the memory allocation request at least comprises a first identifier, and the first identifier corresponds to a target instance waiting for memory allocation; Matching the first identifier with a plurality of current active identifiers, wherein each active identifier corresponds to a plurality of allocated virtual memory pages, and the virtual memory pages corresponding to the plurality of active identifiers are different from each other; And if the active identification is not matched with the first identification, acquiring a new virtual memory page, and transmitting a memory address in the new virtual memory page to the target application. A second aspect of the present description provides a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method according to the first aspect. A third aspect of the present description provides a computing device comprising a memory having executable code stored therein and a processor, which when executing the execut