A memory allocation method, device, equipment and readable storage medium
By reserving and mapping contiguous large pages of memory in the host operating system, the problem of low network card memory allocation efficiency is solved, achieving contiguous and efficient addressing of network card memory and improving network card I/O performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-30
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, network interface cards (NICs) suffer from inefficiency and memory allocation failures when allocating memory resources, especially when addressing non-contiguous physical pages, which requires frequent interaction with the host and leads to a decline in NIC I/O performance.
In the host operating system, a contiguous large page of memory is reserved and mapped to the user process address space through a kernel-mode driver. After being converted into a DMA address, it is sent to the network card to ensure that the memory used by the network card is contiguous and to avoid frequent interaction with the host.
This effectively avoids the problem of the network card being unable to allocate memory, ensures the continuity of memory usage by the network card, and improves the addressing efficiency and performance of the network card.
Smart Images

Figure CN115543618B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of network communication, in particular to a memory allocation method and device, equipment and a readable storage medium. BACKGROUND
[0002] Before using RDMA communication at both ends of communication, QP needs to be created, CQ needs to be created, and MR needs to be registered. These object resources have a context for managing object information. The memory occupied by the context of these objects is allocated by the host side OS and maintained by the network card.
[0003] At present, in a kind of scheme, according to the number of QP, CQ, MR supported by network card device, the total memory required is calculated in advance when initializing, then multiple segments (such as 2MB size) physical memory are applied to OS, and the start DMA address of these memory segments is sent to network card. When user creates QP, CQ, MR, the context information of these objects is written into the specified position of the memory segment by network card. In this kind of scheme, network card needs to frequently interact with HOST when addressing to the end of a memory segment and finding the next memory segment, which is low in efficiency, and memory application failure may occur, leading to network card initialization failure and unavailability.
[0004] In another kind of scheme, network card pre-applys a certain number of 4KB size physical pages to OS when initializing, which is maintained by network card, and subsequently, as the number of QP, CQ, MR created by user increases, these physical pages will be exhausted, at which time network card will actively continue to apply more 4KB size physical pages to OS. In this kind of scheme, although the probability of memory application failure is reduced, when addressing in network card, if non-continuous physical pages need to be addressed, HOST also needs to be interacted multiple times to find the next available physical page, leading to low efficiency of network card addressing and reducing the IO performance of network card.
[0005] In summary, how to effectively solve the problem of allocating memory resources to network card is a technical problem that needs to be solved by the technical personnel in the field at present. SUMMARY
[0006] The purpose of the present application is to provide a memory allocation method, device, equipment and readable storage medium, by reserving continuous large page memory and allocating the continuous large page memory to network card in advance, it can avoid that network card cannot apply memory, and can guarantee that the memory used by network card is continuous, can avoid multiple interactions with host in addressing process, and can effectively guarantee the performance of network card.
[0007] To solve the above technical problems, the present application provides the following technical solutions:
[0008] A memory allocation method, comprising:
[0009] Reserving a continuous large page memory in an operating system of a host;
[0010] Mapping the large page memory to a user process address space to obtain a large page memory virtual address;
[0011] Converting the large page memory virtual address into a large page memory DMA address by using a kernel mode driver;
[0012] Sending the large page memory DMA address to a network card.
[0013] Preferably, the reserving a continuous large page memory in an operating system of a host comprises:
[0014] Obtaining a large page memory reserving parameter;
[0015] Reserving the large page memory by using the large page memory reserving parameter;
[0016] Mounting the large page memory to a target directory.
[0017] Preferably, the obtaining a large page memory reserving parameter comprises:
[0018] Obtaining performance information of the network card;
[0019] Determining a memory size required by the network card by using the performance information;
[0020] Determining a number of the large page memories by using the memory size.
[0021] Preferably, the determining a number of the large page memories by using the memory size comprises:
[0022] Obtaining a current CPU architecture type;
[0023] Determining a page size of each of the large page memories by using the CPU architecture type;
[0024] Determining the number by using the memory size and the page size.
[0025] Preferably, the determining the number by using the memory size and the page size comprises:
[0026] If the page sizes correspond to different scales, selecting a largest page size from the page sizes;
[0027] Determining the number by using the largest page size and the memory size.
[0028] Preferably, before the converting the large page memory virtual address into a large page memory DMA address by using a kernel mode driver, the method further comprises:
[0029] determining whether the huge page memory is initialized;
[0030] If yes, ending the flow;
[0031] If no, performing the step of converting the huge page memory virtual address into the huge page memory DMA address by using the kernel mode driver.
[0032] Preferably, the mapping the huge page memory into the memory to obtain the huge page memory virtual address further comprises:
[0033] loading the kernel mode RDMA driver, and setting whether to enable the huge page memory flag;
[0034] when the user mode RDMA driver opens the ibv_device, querying the kernel mode RDMA driver whether to enable the huge page memory;
[0035] If yes, performing the step of mapping the huge page memory into the memory to obtain the huge page memory virtual address.
[0036] A memory allocation apparatus, comprising:
[0037] a memory reserving module, configured to reserve the continuous huge page memory in an operating system of a host;
[0038] a memory mapping module, configured to map the huge page memory into a user process address space to obtain a huge page memory virtual address;
[0039] an address converting module, configured to convert the huge page memory virtual address into a huge page memory DMA address by using a kernel mode driver;
[0040] a memory allocation module, configured to send the huge page memory DMA address to a network card.
[0041] An electronic device, comprising:
[0042] a memory, configured to store a computer program;
[0043] a processor, configured to implement the steps of the above memory allocation method when executing the computer program.
[0044] A readable storage medium, having a computer program stored thereon, the computer program being configured to implement the steps of the above memory allocation method when executed by a processor.
[0045] By using the method provided in the embodiments of the present application, the continuous huge page memory is reserved in the operating system of the host; the huge page memory is mapped into the user process address space to obtain the huge page memory virtual address; the huge page memory virtual address is converted into the huge page memory DMA address by using the kernel mode driver; and the huge page memory DMA address is sent to the network card.
[0046] In the present application, first, a continuous large page memory is reserved in the operating system of the host, and then the large page memory is mapped, so as to obtain a large page memory virtual address. The large page memory virtual address is converted into a large page memory DMA address by a kernel mode driver, and finally the large page memory DMA address is sent to the network card. In this way, the network card can be allocated continuous large page memory by reserving continuous large page memory. That is, the network card will not appear unable to apply for memory, and the allocated memory is continuous large page memory, so that addressing can be completed without repeated interaction with the host. It can be seen that the present application can avoid the network card from being unable to apply for memory, and can guarantee that the memory used by the network card is continuous, can avoid multiple interactions with the host in the addressing process, and can effectively guarantee the performance of the network card.
[0047] Correspondingly, the embodiments of the present application also provide a memory allocation device, equipment and readable storage medium corresponding to the above memory allocation method, which have the above technical effects, and details are not described here. BRIEF DESCRIPTION OF DRAWINGS
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the drawings needed to be used in the embodiments or the related art description will be briefly introduced. Obviously, the drawings in the following description only some embodiments of the present application, and for those skilled in the art, other drawings can be obtained without creative labor on the basis of these drawings.
[0049] Figure 1 An implementation flowchart of a memory allocation method in the embodiments of the present application;
[0050] Figure 2 A memory model schematic diagram in the embodiments of the present application;
[0051] Figure 3 A memory model schematic diagram;
[0052] Figure 4 A network card memory usage schematic diagram in the embodiments of the present application;
[0053] Figure 5 A network card memory application schematic diagram;
[0054] Figure 6 A detailed implementation flowchart of a memory allocation method in the embodiments of the present application;
[0055] Figure 7 A structure schematic diagram of a memory allocation device in the embodiments of the present application;
[0056] Figure 8 A structure schematic diagram of an electronic device in the embodiments of the present application;
[0057] Figure 9 Figure 1 is a schematic diagram of a specific structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0058] In order to make the personnel in the technical field better understand the present application, the present application will be further described in detail below in combination with the drawings and specific embodiments. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative labor, belong to the scope of protection of the present application.
[0059] For the convenience of understanding, the related terms involved in the present application will be explained as follows:
[0060] QP, Queue Pair, queue;
[0061] CQ, Completion Queue, completion queue;
[0062] MR, Memory Region, memory region;
[0063] QPC, Queue Pair Context, queue pair context;
[0064] CQC, Completion Queue Context, completion queue context;
[0065] MRTE, Memory Region Table Entry, memory region table entry;
[0066] PBLE, Physical Buffer List Entry, physical memory buffer list entry;
[0067] RDMA, Remote Direct Memory Access, remote direct memory access;
[0068] RNIC, RDMA NIC, RDMA-capable network interface card;
[0069] SD, Segment Descriptor, segment descriptor;
[0070] PD, Page Descriptor, page descriptor;
[0071] VF, Virtual Function, PCIe virtual function;
[0072] FPM, Function Private Memory, Function internal dedicated memory
[0073] pinned DMA buf, Pinned direct memory access buffer, DMA operation for a certain user process Lock the physical memory;
[0074] page pa, page physical address, physical memory page physical address
[0075] Please refer to Figure 1 , Figure 1 A flowchart of a memory allocation method in an embodiment of the present application, the method comprising the following steps:
[0076] S101, reserving continuous large page memory in the operating system of the host.
[0077] Among them, the large page memory (HugePages) is to reduce the page table by increasing the size of the operating system page, so as to avoid the fast table missing.
[0078] The large page memory allocates physical memory, which will not be swapped out to the disk by the memory management of the operating system, so there will be no page fault interrupt, and it is not easy to introduce the time delay of accessing the disk. The large page memory is continuous in physical, and the access to the large page memory can also have an acceleration effect.
[0079] In an embodiment of the present application, a conventional large page memory reservation method can be used to reserve continuous large page memory in the operating system of the host. Of course, the total reserved large page memory needs to be sufficient for the use of the network card.
[0080] In a specific embodiment of the present application, step S101 reserves continuous large page memory in the operating system of the host, comprising:
[0081] Step one, get the reserved large page memory parameters;
[0082] Step two, reserve large page memory using the reserved large page memory parameters;
[0083] Step three, mount the large page memory to the target directory.
[0084] For ease of description, the above three steps will be described together.
[0085] Specifically, the reserved large page memory parameters can be obtained by reading a readable storage medium, receiving external input, or through calculation, etc. The reserved large page memory parameters can specifically include the page size, the number of pages, and other information of the large page memory.
[0086] With the reserved huge page memory parameter, the huge page memory reservation can be realized. Specifically, the huge page memory reservation instruction or code, etc. can be used to realize it.
[0087] For example, 2 1G huge page memories can be reserved by the following instruction:
[0088] echo 2 > / sys / devices / system / node / node0 / hugepages / hugepages-1048576kB / nr_hugepages;
[0089] 1024 2MB huge page memories can be reserved by the following instruction:
[0090] echo 1024 > / sys / devices / system / node / node0 / hugepages / hugepages-2048kB / nr_hugepages.
[0091] After reserving enough continuous huge page memories, they can be mounted to the target directory. For example, the huge page memories can be mounted to a directory, such as / mnt (Linux reserved mounting directory) or / dev / hugepages (the directory name of the directory under dev is hugepages), in actual application, they can also be mounted to other directories.
[0092] In one specific embodiment of the present application, the step one of obtaining the reserved huge page memory parameter comprises:
[0093] Step 1, obtaining the performance information of the network card;
[0094] Step 2, determining the required memory size of the network card by using the performance information;
[0095] Step 3, determining the number of huge page memories by using the memory size.
[0096] The performance information of the network card includes the number of QPC, CQC, MRTE and PBLE supported respectively.
[0097] The number of QPC, CQC, MRTE and PBLE supported by the network card in the performance information can determine the required memory size of the network card.
[0098] Example 1: Assuming that the QPC size is 1024 bytes, the CQC size is 128 bytes, the MRTE size is 64 bytes, the PBLE size is 8 bytes, and the network card supports 256k QPCs, 512k CQCs, 16M MRTEs, and 256M PBLEs, the total memory size required is calculated as follows:
[0099] 1024 byte * 256k + 128 byte * 512k + 64 byte * 16M + 8 byte * 256M = 3392 Mbyte.
[0100] Example 2: Assuming that the QPC size is 1024 bytes, the CQC size is 128 bytes, the MRTE size is 64 bytes, the PBLE size is 8 bytes, and the network card supports 128k QPCs, 256k CQCs, 8M MRTEs, and 128M PBLEs, the total memory size required is calculated as follows:
[0101] 1024 byte * 128k + 128 byte * 256k + 64 byte * 8M + 8 byte * 128M = 1696 Mbyte.
[0102] Considering that the page size of the large page memory supported by CPUs of different architectures will be different, step 3 above uses the memory size to determine the number of large page memories, which can specifically include:
[0103] Step 1, obtain the current CPU architecture type;
[0104] Step 2, determine the page size of each large page memory using the CPU architecture type;
[0105] Step 3, determine the number using the memory size and the page size.
[0106] That is, the size of the large page memory used by CPUs of different architectures is different, such as ARM and X86_64 supporting 2MB and 1GB large page memories. In the implementation process of the embodiment, the size of the large page memory is dynamically adjusted according to the specific CPU architecture. Then, after determining the page size of the large page memory corresponding to the current CPU architecture, the number of large page memories required to be reserved is determined in combination with the memory size and the page size.
[0107] Example 1: If the memory size required by the network card is 3392M byte, the number of specific large page memories is determined according to different page sizes after reserving the large page memory according to the page size, which can include but is not limited to the following cases:
[0108] Case 1: Assuming that the page size is 1GB, 4 pages need to be reserved;
[0109] Case 2: if the page size is 2MB, 1696 pages need to be reserved.
[0110] Example 2: if the memory size required by the network card is 1696M byte, the memory is reserved according to the page size of the large page memory, and the number of the large page memory is determined according to different page sizes, which can include but is not limited to the following cases:
[0111] Case 1: if the page size is 1GB, 2 pages need to be reserved;
[0112] Case 2: if the page size is 2MB, 848 pages need to be reserved.
[0113] That is, as the QPC / CQC / MRTE / PBLE specifications and sizes supported by the network card change, the number of the reserved large page memory also changes.
[0114] In a specific embodiment of the present application, when determining the number of the large page memory, the larger page size can be preferentially selected for the number determination. That is, the number is determined by using the memory size and the page size, including: if the page sizes correspond to different scales, the largest page size is selected from the page sizes; and the number is determined by using the largest page size and the memory size.
[0115] For example, if the page sizes of the large page memory supported by the current CPU architecture include 2M and 1G, 1G is preferentially selected as the page size of the large page memory.
[0116] S102, map the large page memory to the user process address space to obtain a large page memory virtual address.
[0117] After reserving enough and continuous large page memory, mmap can be performed to obtain the large page memory virtual address.
[0118] Wherein, mmap refers to mapping a file or other object into memory.
[0119] S103, convert the large page memory virtual address into a large page memory DMA address by using the kernel mode driver.
[0120] Specifically, the large page memory virtual address can be sent to the kernel mode driver, and then the kernel mode driver is used to convert the large page memory virtual address into a DMA address, so that the large page memory DMA address is obtained.
[0121] S104, send the large page memory DMA address to the network card.
[0122] Specifically, the kernel mode driver can be used to send the large page memory DMA address to the network card.
[0123] The memory model of the network card for storing RDMA objects QP, CQ and MR in large page memory is shown in Figure 2 Specifically, the network card can maintain the address of the allocated large page memory by using 32 KB SRAM, and support allocation to multiple PFs / VFs. According to the number of QPs, CQs and MRs supported by each PF / VF, the physical memory required by each PF / VF is calculated, and the number of SDs required is calculated. The network card records the start index and number of SDs used by each PF / VF. When the user creates a QP, CQ or MR object in a PF / VF, the network card stores the object information in the physical memory pointed to by the specified SD in sequence. Figure 3 Compared with the memory model shown in Figure 3 , in the present application, when running IO data after creating QP, CQ and MR objects, the network card can quickly locate the specified SD according to QPN, thereby loading the specified object information and performing IO data operation, improving the IO performance of the network card.
[0124] For example, after using the memory allocation method provided in the embodiments of the present application, the memory application situation is as shown in Figure 4 , the size of the applied memory is 2M large page memory, and the large page memory is continuous; the memory model is as shown in Figure 3 , the memory application situation is as shown in Figure 5 , the size of the applied memory page is fixed at 4KB and is discontinuous.
[0125] By using the method provided in the embodiments of the present application, continuous large page memory is reserved in the operating system of the host; the large page memory is mapped to the memory to obtain a large page memory virtual address; the large page memory virtual address is converted into a large page memory DMA address by using a kernel mode driver; and the large page memory DMA address is sent to the network card.
[0126] In the present application, first, continuous large page memory is reserved in the operating system of the host, and then the large page memory is mmaped to obtain a large page memory virtual address. The large page memory virtual address is converted into a large page memory DMA address by using a kernel mode driver, and finally the large page memory DMA address is sent to the network card. In this way, continuous large page memory can be allocated to the network card by reserving continuous large page memory. That is, the network card will not be unable to apply for memory, and the allocated memory is continuous large page memory, so that addressing can be completed without repeated interaction with the host. It can be seen that the present application can avoid the network card being unable to apply for memory, and can ensure that the memory used by the network card is continuous, can avoid multiple interactions with the host in the addressing process, and can effectively protect the performance of the network card.
[0127] It should be noted that based on the above embodiment, the application embodiment also provides a corresponding improvement scheme. The preferred / improved embodiment involves the same steps or corresponding steps between the above embodiments, which can be mutually referred to, and the corresponding benefits can also be mutually referred to. In the preferred / improved embodiment herein, it will not be described one by one.
[0128] In a specific embodiment in the present application, before converting the large page memory virtual address into the large page memory DMA address by using the kernel mode driver, the following steps can also be performed:
[0129] Step one, judge whether the large page memory has been initialized;
[0130] Step two, if yes, end the process;
[0131] Step three, if no, perform the step of converting the large page memory virtual address into the large page memory DMA address by using the kernel mode driver.
[0132] To avoid repeated operations, before performing the address conversion, it can also be judged whether the large page memory has been initialized. If yes, directly end the process; if not initialized, perform the step of converting the large page memory virtual address into the large page memory DMA address by using the kernel mode driver.
[0133] In a specific embodiment in the present application, after mapping the large page memory into the memory to obtain the large page memory virtual address, the following steps can also be performed:
[0134] Step one, load the kernel mode RDMA driver, and set whether to enable the large page memory flag;
[0135] Step two, when the user mode RDMA driver opens the ibv_device, query the kernel mode RDMA driver whether to enable the large page memory;
[0136] Step three, if yes, perform the step of mapping the large page memory into the memory to obtain the large page memory virtual address.
[0137] For ease of description, the above three steps will be described in combination.
[0138] That is, the large page memory can be determined whether to be started by setting the large page memory flag. Specifically, the kernel mode RDMA driver can be loaded, and whether to enable the large page memory flag is set. In this way, when the user mode RDMA driver opens the ibv_device, the kernel mode RDMA driver can be queried whether to enable the large page memory. If it is determined to enable the large page memory, the step of mapping the large page memory into the memory to obtain the large page memory virtual address is performed; otherwise, the large page memory is not started, that is, the scheme of using the non-reserved large page memory for the network card is continued. This type of scheme will not be described one by one.
[0139] To make the person skilled in the art better understand the memory allocation method provided by the embodiments of the application, the memory allocation method will be described in detail below with reference to a specific application scenario as an example.
[0140] Please refer to Figure 6 , Figure 6 The detailed implementation flowchart of the memory allocation method in the embodiments of the application is as follows.
[0141] Step 1. Set the reserved large page memory parameter of the HOST side OS;
[0142] Step 2. Mount the large page memory to a certain directory, such as / mnt or / dev / hugepages;
[0143] Step 3. Load the kernel state RDMA driver and set whether to enable the large page memory flag;
[0144] Step 4. When the user state RDMA driver opens the ibv_device, query whether to enable the large page memory from the kernel state RDMA driver. If it is queried that the large page memory is enabled and the large page memory initialization has not been performed, the user state driver performs mmap on the large page memory at this time to obtain the large page memory virtual address;
[0145] Step 5. If it is queried that the large page memory is enabled and the large page memory initialization has been completed, directly skip steps 7 and 8 and end the flow directly;
[0146] Step 6. If it is queried that the large page memory is not enabled, directly go to the normal memory application flowchart by skipping steps 7 and 8;
[0147] Step 7. Send the large page memory virtual address to the kernel state driver to convert it into a DMA address;
[0148] Step 8. The kernel state RDMA driver issues the large page memory DMA address to the network card maintenance.
[0149] By using the memory allocation method provided by the embodiments of the application, the large page memory can be used for maintaining the QP, CQ, MR and other object information of the network card, the problem of memory application failure in the network card running process is avoided, meanwhile, multiple large page memories maintain the physical address continuity, the problem of network card cross-discontinuous physical page addressing is reduced, and the network card IO performance is improved.
[0150] Corresponding to the above method embodiments, the embodiments of the application also provide a memory allocation device, and the memory allocation device described below can be mutually corresponding and referred to the memory allocation method described above.
[0151] Referring to Figure 7 , the device includes the following modules:
[0152] The memory reservation module 101 is used to reserve contiguous large pages of memory in the host operating system;
[0153] The memory mapping module 102 is used to map large page memory to the user process address space to obtain the virtual address of the large page memory;
[0154] Address translation module 103 is used to convert the virtual address of massive page memory into the address of massive page memory DMA using kernel-mode drivers;
[0155] The memory allocation module 104 is used to send the large page memory DMA address to the network card.
[0156] Using the apparatus provided in the embodiments of this application, a contiguous large page memory is reserved in the host operating system; the large page memory is mapped to the user process address space to obtain a large page memory virtual address; the large page memory virtual address is converted into a large page memory DMA address using a kernel-mode driver; and the large page memory DMA address is sent to the network card.
[0157] In this application, contiguous large pages of memory are first reserved in the host operating system. Then, mmap is performed on the large pages to obtain their virtual addresses. A kernel-mode driver translates these virtual addresses into large page DMA addresses, which are then sent to the network interface card (NIC). This allows for the allocation of contiguous large pages to the NIC by reserving them. Consequently, the NIC avoids memory allocation failures, and the allocated memory is contiguous large pages. Therefore, addressing can be completed without repeated interactions with the host. This application effectively prevents the NIC from being unable to allocate memory, ensures that the memory used by the NIC is contiguous, and avoids multiple interactions with the host during addressing, thus effectively guaranteeing NIC performance.
[0158] In one specific embodiment of this application, the memory reservation module 101 is specifically used to obtain reserved large page memory parameters;
[0159] Reserve large page memory using the parameter;
[0160] Mount the large page memory to the target directory.
[0161] In one specific embodiment of this application, the memory reservation module 101 is specifically used to obtain the performance information of the network card;
[0162] Use performance information to determine the amount of memory required by the network card;
[0163] Use the memory size to determine the number of large pages.
[0164] In one specific embodiment of this application, the memory reservation module 101 is specifically used to obtain the current CPU architecture type;
[0165] Determine the page size of each massive memory segment based on the CPU architecture type;
[0166] The quantity is determined using the memory size and page size.
[0167] In one specific embodiment of this application, the memory reservation module 101 is specifically used to select the largest page size from the page sizes if the page sizes correspond to different scales;
[0168] Determine the quantity using the maximum page size and memory size.
[0169] In one specific embodiment of this application, it further includes:
[0170] The initialization judgment module, used before the kernel-mode driver translates the virtual address of massive page memory into a massive page memory DMA address, also includes:
[0171] Determine if the large page memory has been initialized;
[0172] If so, the process ends;
[0173] If not, then execute the step of using the kernel-mode driver to translate the virtual address of massive page memory into a massive page memory DMA address.
[0174] In one specific embodiment of this application, an enabling judgment module is used to obtain the virtual address of the large page memory by mapping the large page memory to memory, and the module further includes:
[0175] Load the kernel-mode RDMA driver and configure whether to enable massive page memory marking;
[0176] When the user-space RDMA driver opens ibv_device, it queries the kernel-space RDMA driver to see if large page memory is enabled;
[0177] If so, then execute the step of mapping the large page memory into memory to obtain the virtual address of the large page memory.
[0178] Corresponding to the above method embodiments, this application also provides an electronic device. The electronic device described below and the memory allocation method described above can be referred to in correspondence.
[0179] See Figure 8 As shown, the electronic device includes:
[0180] Memory 332 is used to store computer programs;
[0181] The processor 322 is used to implement the steps of the memory allocation method in the above method embodiments when executing a computer program.
[0182] For details, please refer to Figure 9 , Figure 9 This is a schematic diagram of a specific structure of an electronic device provided in this embodiment. The electronic device can vary significantly due to differences in configuration or performance. It may include one or more central processing units (CPUs) 322 (e.g., one or more processors) and a memory 332. The memory 332 stores one or more computer application programs 342 or data 344. The memory 332 can be temporary or persistent storage. The program stored in the memory 332 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the data processing device. Furthermore, the central processing unit 322 may be configured to communicate with the memory 332 and execute the series of instruction operations stored in the memory 332 on the electronic device 301.
[0183] Electronic device 301 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input / output interfaces 358, and / or one or more operating systems 341.
[0184] The steps in the memory allocation method described above can be implemented by the structure of the electronic device.
[0185] Corresponding to the above method embodiments, this application also provides a readable storage medium. The readable storage medium described below corresponds to the memory allocation method described above.
[0186] A readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the memory allocation method described in the above method embodiments.
[0187] Specifically, the readable storage medium can be a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, or any other readable storage medium capable of storing program code.
[0188] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0189] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0190] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0191] Finally, it should be noted that in this document, the terms include, encompass, or any other variations 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 process, method, article, or apparatus.
[0192] This document uses specific examples to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A memory allocation method, characterized in that, include: Reserve contiguous large pages of memory in the host operating system; The massive page memory is mapped to the user process address space to obtain the massive page memory virtual address; The kernel-mode driver is used to translate the virtual address of the massive page memory into a massive page memory DMA address; Send the large page memory DMA address to the network card; The provision of reserving contiguous large pages of memory in the host operating system includes: Get the reserved large page memory parameters; The reserved large page memory is reserved using the reserved large page memory parameters; Mount the large page memory to the target directory; The step of obtaining the reserved large page memory parameters includes: Obtain the performance information of the network card; The required memory size for the network card is determined using the performance information. The number of large pages is determined using the memory size.
2. The memory allocation method according to claim 1, characterized in that, Using the memory size, determine the number of large pages, including: Get the current CPU architecture type; Using the CPU architecture type, determine the page size of each of the large page memories; The quantity is determined using the memory size and the page size.
3. The memory allocation method according to claim 2, characterized in that, Determining the quantity using the memory size and the page size includes: If the page sizes correspond to different scales, then the largest page size is selected from the page sizes; The quantity is determined using the maximum page size and the memory size.
4. The memory allocation method according to claim 1, characterized in that, Before the step of using a kernel-mode driver to translate the massive page memory virtual address into a massive page memory DMA address, the method further includes: Determine whether the large page memory has been initialized; If so, the process ends; If not, then perform the step of using the kernel-mode driver to translate the large page memory virtual address into a large page memory DMA address.
5. The memory allocation method according to any one of claims 1 to 4, characterized in that, The process of mapping the large page memory into memory to obtain the virtual address of the large page memory also includes: Load the kernel-mode RDMA driver and configure whether to enable massive page memory marking; When the user-mode RDMA driver opens ibv_device, it queries the kernel-mode RDMA driver to see if large page memory is enabled; If so, then execute the step of mapping the large page memory into memory to obtain the virtual address of the large page memory.
6. A memory allocation device, characterized in that, include: A memory reservation module is used to reserve contiguous large page memory in the host's operating system, including: obtaining large page memory reservation parameters; reserving the large page memory using the large page memory reservation parameters; and mounting the large page memory to a target directory; wherein, obtaining the large page memory reservation parameters includes: obtaining network card performance information; determining the memory size required by the network card using the performance information; and determining the number of large page memory units using the memory size. The memory mapping module is used to map the massive page memory to the user process address space to obtain the virtual address of the massive page memory; The address translation module is used to convert the virtual address of the large page memory into a large page memory DMA address using the kernel-mode driver; The memory allocation module is used to send the large page memory DMA address to the network card.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for implementing the steps of the memory allocation method as described in any one of claims 1 to 5 when executing the computer program.
8. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the memory allocation method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Memory resource allocation method and device, electronic device and readable storage medium
CN108829523A
Memory resource management method and device of cloud firewall, computer equipment and medium
CN114443280A