A method, device, storage medium and product for dynamically allocating memory

By implementing dynamic memory allocation in the system firmware, the problem of iPXE failing memory allocation during the boot stage is solved, ensuring that the memory resource update of network card devices is updated, and memory leaks and operating system installation failures are avoided.

CN119003188BActive Publication Date: 2025-02-25INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411487409.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-23
Publication Date
2025-02-25
Estimated Expiration
2044-10-23

AI Technical Summary

Technical Problem

Under certain conditions, iPXE may experience memory allocation failure during the boot phase, resulting in the operating system installation failure.

Method used

The system firmware dynamically allocates memory, and in response to resource allocation instructions for network card devices, obtains the resource allocation pointer in the target data structure. If the pointer is empty, then the memory is applied and the pointer is written; if the pointer is not empty, the memory information in the pointer is read and its validity is judged. If the memory is invalid, clear and re-apply the memory.

Benefits of technology

Ensure that the network card device can correctly allocate memory during the boot stage, avoid the problem of memory allocation failure, improve the success rate of operating system installation, and prevent memory leakage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003188B_ABST
    Figure CN119003188B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention provides a method, device, storage medium and product for dynamic allocation of memory, which relates to the field of memory resource technology, including: in response to a resource allocation instruction for a first network card device, obtaining a target data structure corresponding to the first network card device through system firmware, and extracting a resource allocation pointer therefrom; if the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, and writing the first memory information into the resource allocation pointer; if it is not a null pointer, reading the second memory information in the resource allocation pointer, and obtaining the second memory corresponding to the second memory information; if the second memory is invalid memory, clearing the second memory information through the system firmware, applying for a first memory for the network card device according to the resource allocation instruction, and writing the first memory information into the resource allocation pointer. The present invention timely updates the memory resources of the network card device according to the resource allocation pointer to avoid memory allocation conflicts.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of memory resource technology, and in particular to a memory dynamic allocation method, device, storage medium and product. Background Art

[0002] PXE (Preboot Execution Environment) is a network boot technology that allows a computer to boot an operating system from a server over the network. iPXE (Intelligent Platform Management Interface Extensions) is an enhanced version of PXE that supports more efficient network booting, obtains the boot file address through DHCP requests, then downloads and executes the boot file to finally install the operating system.

[0003] IPXE is an open source PXE boot loader, which is widely used in diskless workstations, remote installation, or automatic deployment of operating systems. Currently, network boot and operating system installation mainly rely on PXE and iPXE. However, during the process of operating system installation through IPXE, installation failures may occur due to various factors, including but not limited to network problems, hard disk read and write errors, boot file corruption, incomplete operating system images, or compatibility issues. Among them, under certain conditions (such as using a specific version of RHEL and a specific hardware configuration), iPXE may fail to allocate memory during the boot phase, resulting in operating system installation failure. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a method, device, storage medium and product for dynamically allocating memory, so as to solve the problem that under certain conditions, memory allocation failure may occur in the boot phase of iPXE, resulting in system installation failure. The specific technical solution is as follows:

[0005] In a first aspect of an embodiment of the present invention, a method for dynamically allocating memory is first provided, which is applied to system firmware. The method includes:

[0006] In response to a resource allocation instruction for a first network card device, obtaining a target data structure corresponding to the first network card device through the system firmware, and extracting a resource allocation pointer from the target data structure;

[0007] If the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer;

[0008] If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware, and acquiring the second memory corresponding to the second memory information;

[0009] If the second memory is invalid memory, the second memory information is cleared by the system firmware, the first memory is applied for the network card device according to the resource allocation instruction, and the first memory information is written into the resource allocation pointer.

[0010] Optionally, the system firmware includes an initialization driver, and before the step of responding to the resource allocation instruction for the first network card device, acquiring the target data structure of the first network card device, and extracting the resource allocation pointer from the target data structure, the method further includes:

[0011] Searching, through the system firmware, from the driver code of the initialization driver, a target data structure corresponding to the first network card device, wherein the target data structure is used to initialize the expansion bridge;

[0012] Setting a resource allocation pointer in the target data structure, wherein the resource allocation pointer includes memory information of the first network card device;

[0013] The resource allocation pointer is initialized to a null pointer through the initialization driver.

[0014] Optionally, initializing the resource allocation pointer to a null pointer by the initialization driver includes:

[0015] Obtaining the initialization function of the expansion bridge through the initialization driver;

[0016] At the start position of the initialization function, a pointer initialization instruction for initializing the resource allocation pointer is set;

[0017] In response to the initialization of the expansion bridge, the pointer initialization instruction is executed by the initialization driver, so that the resource allocation pointer is initialized to a null pointer.

[0018] Optionally, before searching the target data structure corresponding to the first network card device from the driver code of the initialization driver through the system firmware, the method further includes:

[0019] Acquire all connected devices connected to the bus through the system firmware;

[0020] Taking any one of the connection devices as a target connection device, and identifying a device class code of the target connection device;

[0021] If the device class code matches the preset network card device code, confirming that the target connection device is a second network card device;

[0022] The target device link where the second network card device is located is obtained through the system firmware, and a corresponding resource allocation pointer is set for each network card device in the target device link.

[0023] Optionally, the acquiring, through the system firmware, a target device link where the second network card device is located, and setting a corresponding resource allocation pointer for each network card device in the target device link includes:

[0024] Acquire the configuration information of the second network card device through the system firmware;

[0025] Generate a device record of the second network card device and the configuration information, and extract a device address of a parent device of the second network card device from the configuration information;

[0026] Updating the second network card device to the parent device, and returning to the step of obtaining the configuration information of the second network card device until the address information of the root port is extracted from the configuration information;

[0027] A target device link where the second network card device is located is generated based on the plurality of second network card devices in the device record and the root port.

[0028] Optionally, the generating the device record of the second network card device and the configuration information, and extracting the device address of the parent device of the second network card device from the configuration information includes:

[0029] Generate the device record, where the device record is used to record the second network card device and configuration information;

[0030] If the configuration information includes the identifier of the root port, extracting the address information of the root port from the configuration information by the system firmware;

[0031] If the configuration information does not include the identifier of the root port, the device address of the parent device is extracted from the configuration information by the system firmware based on the configuration information and the bridge relationship.

[0032] Optionally, if the second memory is invalid memory, clearing the second memory information by the system firmware, applying for the first memory for the network card device according to the resource allocation instruction, and writing the first memory information into the resource allocation pointer, the method further includes:

[0033] Acquire a first network status of the first network card device through the system firmware;

[0034] If the first network status indicates that the first network card device is not connected, a third network card device is obtained and resources are allocated to the third network card device, where the third network card device is the next network card device of the first network card device.

[0035] Optionally, the acquiring, through the system firmware, the first network status of the first network card device includes:

[0036] Detecting the network cable connection status or network communication status of the first network card device;

[0037] If the network cable of the first network card device is not connected, or the network is not accessible, the first network state is characterized as the first network card device being not connected;

[0038] If the network cable of the first network card device is connected and the network is unobstructed, the first network status is characterized as the first network card device being connected.

[0039] Optionally, if the first network state indicates that the first network card device is not connected, then obtaining the third network card device and allocating resources to the third network card device, and the third network card device is the next network card device of the first network card device, the method further includes:

[0040] The first memory of the first network card device is released through the system firmware, and the first memory information in the resource allocation pointer corresponding to the first network card device is cleared.

[0041] Optionally, if the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer includes:

[0042] If the value of the resource allocation pointer is null, confirming that the resource allocation pointer is a null pointer;

[0043] extracting first memory information of the first memory from the resource allocation instruction by the system firmware, wherein the first memory information includes a memory type, a memory size, and a memory address;

[0044] The system firmware applies for the first memory for the first network card device according to the first memory information, and writes the first memory information into the resource allocation pointer.

[0045] Optionally, if the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware, and acquiring the second memory corresponding to the second memory information includes:

[0046] If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware;

[0047] Acquire a second memory corresponding to the second memory information, and use a memory detection tool to confirm whether the second memory is invalid;

[0048] If the second memory is invalid, confirming that the second memory is invalid memory;

[0049] If the second memory is not invalid, then the second memory is confirmed to be a valid memory.

[0050] Optionally, after reading the second memory information in the resource allocation pointer through the system firmware if the resource allocation pointer is not a null pointer and acquiring the second memory corresponding to the second memory information, the method further includes:

[0051] If the second memory is a valid memory, the first network card device is used as a target network card device, and the target network card device is used to boot and install an operating system.

[0052] In a second aspect of an embodiment of the present invention, a dynamic memory allocation device is provided, which is applied to system firmware, and the device includes:

[0053] an allocation pointer extraction module, configured to, in response to a resource allocation instruction for a first network card device, obtain a target data structure corresponding to the first network card device through the system firmware, and extract a resource allocation pointer from the target data structure;

[0054] a memory information allocation module, configured to apply for a first memory for the first network card device according to the resource allocation instruction through the system firmware if the resource allocation pointer is a null pointer, obtain first memory information of the first memory, and write the first memory information into the resource allocation pointer;

[0055] a memory information reading module, which reads the second memory information in the resource allocation pointer through the system firmware if the resource allocation pointer is not a null pointer, and obtains the second memory corresponding to the second memory information;

[0056] A memory information reallocation module is used to clear the second memory information through the system firmware if the second memory is invalid memory, apply for the first memory for the network card device according to the resource allocation instruction, and write the first memory information into the resource allocation pointer.

[0057] In the third aspect of the embodiments of the present invention, an electronic device is also provided, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute any of the above-mentioned dynamic memory allocation methods.

[0058] In a fourth aspect of an embodiment of the present invention, a non-volatile readable storage medium is further provided. When instructions in the non-volatile readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any of the above-mentioned dynamic memory allocation methods.

[0059] In a fifth aspect of an embodiment of the present invention, a computer program product is also provided, including a computer program / instruction, which implements any of the above-mentioned methods for dynamic allocation of memory when executed by a processor.

[0060] The dynamic memory allocation method provided by the embodiment of the present invention responds to a resource allocation instruction for a first network card device, obtains a target data structure corresponding to the first network card device through system firmware, and extracts a resource allocation pointer from the target data structure; if the resource allocation pointer is a null pointer, the system firmware applies for a first memory for the first network card device according to the resource allocation instruction, obtains first memory information of the first memory, and writes the first memory information into the resource allocation pointer; if the resource allocation pointer is not a null pointer, the system firmware reads the second memory information in the resource allocation pointer, and obtains the second memory corresponding to the second memory information; if the second memory is invalid memory, the system firmware clears the second memory information, applies for the first memory for the network card device according to the resource allocation instruction, and writes the first memory information into the resource allocation pointer. The present invention obtains a data structure corresponding to a network card device through system firmware, confirms a memory allocation state of the network card device according to a resource allocation pointer pre-set in the data structure, and further reads memory information in the network card device to judge the existing memory of the network card device, thereby deciding to apply for memory for the network card device or clear the memory and then apply again in the current polling process based on the memory allocation state of the network card device, thereby ensuring that the memory resources of the network card device are kept updated, and by improving the system firmware, optimizing the Polling mechanism, confirming the memory allocation state of the network card device, and checking the memory occupied by each network card device, the memory leakage problem caused by the continuous memory occupation by the network card device that cannot be connected can be effectively avoided.

[0061] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0063] Figure 1 It is a flowchart of the steps of a method for dynamic allocation of memory provided by an embodiment of the present invention;

[0064] Figure 2 is a schematic diagram of an example of a dynamic memory allocation method provided by an embodiment of the present invention;

[0065] Figure 3 It is a structural block diagram of a memory dynamic allocation device provided by an embodiment of the present invention;

[0066] Figure 4 It is a block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0067] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0068] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, some technical features involved in the embodiments of the present invention are explained and illustrated below:

[0069] BIOS (Basic Input / Output System) is the first software component loaded when the computer starts. It is mainly responsible for initializing the computer's hardware components. When the computer starts, it is responsible for initializing hardware devices, performing self-test (POST, Power-On Self-Test), loading the operating system and other key tasks, and loading the operating system's boot program.

[0070] PXE (Preboot eXecution Environment) is a network boot technology that allows a computer to download and boot an operating system or perform other tasks from a remote server over the network without having to boot from a local hard disk.

[0071] iPXE (Intel PXE Boot ROM open source version) is an open source network boot firmware, which is an enhanced version of PXE that allows users to boot operating systems, virtual machines, containers, etc. through the network. It provides more flexible and powerful functions than traditional PXE, including network boot, disk image deployment, script execution, etc.

[0072] PCI (Peripheral Component Interconnect) is a local bus standard used to connect computer motherboards and external devices (such as graphics cards, sound cards, network cards, etc.). The PCI bus standard allows high-speed data transmission between expansion slots on computer motherboards and peripherals through the bus.

[0073] PCIe (PCI Express) is a high-speed serial computer expansion bus standard used to connect computer internal devices such as graphics cards, network cards, storage devices, etc. PCIe has higher bandwidth and lower latency than the traditional PCI bus.

[0074] DHCP (Dynamic Host Configuration Protocol) is a network protocol used to automatically assign network configuration information such as IP address, subnet mask, gateway, and DNS server to client devices. When a device connects to the network, it sends a DHCP request to obtain this configuration information.

[0075] In computer systems, Bridge usually refers to a hardware device or software component used to connect two different networks or systems so that they can communicate with each other. In PCI / PCIE systems, Bridge plays an important role and is used to connect different PCI / PCIE devices and buses.

[0076] End Device, in PCI / PCIE system, refers to the terminal device connected to the PCI / PCIE bus. These devices are usually actual functional devices, such as network cards, graphics cards, storage controllers, etc. End Device is the final node in the PCI / PCIE system. They are connected to the system bus through the Bridge and communicate directly with the CPU and other devices.

[0077] Initrd (Initial RAM Disk, temporary file system) is usually used during the Linux system startup process. The main function of Initrd is to provide the necessary drivers and file system support when the kernel starts until the root file system is mounted.

[0078] Polling, in computer networks and hardware devices, refers to a polling mechanism used to periodically check the status of a device or interface. Specifically, Polling means that the system or driver periodically queries the status or data of a device to ensure that the device is working properly or to obtain the latest status information.

[0079] As an example, the network card on the network client host will start iPXE booting, and iPXE booting will send a DHCP request to the server. After receiving the DHCP request, the server will return the address of the iPXE boot file to the client. After receiving the address, the client will download the file from the server and execute it. In the IPXE booting process, IPXE will check each network interface in the system in turn to determine which interface can be used for network booting. The conditions for the network interface to be available are: the network interface has memory allocated and the network is connected. As a preparation condition, if the memory resource application of the network interface fails, it may cause the failure of system installation.

[0080] In this regard, in an embodiment of the present invention, in response to a resource allocation instruction for the first network card device, a target data structure corresponding to the first network card device is obtained through the system firmware, a resource allocation pointer is extracted from the target data structure, and the memory allocation status of the first network card device is judged according to the resource allocation pointer, and a decision is made to allocate memory or clear and reallocate memory for the current first network port device, thereby ensuring that the memory of the network port device is updated and effectively avoiding memory leakage problems.

[0081] Reference Figure 1 , shows a flowchart of a method for dynamic allocation of memory provided in an embodiment of the present invention, wherein the method for dynamic allocation of memory is applied to system firmware, and specifically may include the following steps:

[0082] Step 101: in response to a resource allocation instruction for a first network card device, a target data structure corresponding to the first network card device is obtained through system firmware, and a resource allocation pointer is extracted from the target data structure.

[0083] During the IPXE boot process, the client computer can poll the network card port through the DHCP protocol to obtain the IP address and other configuration information. Each different network port on the network card can be understood as a different network card logical device, that is, a network card device. After responding to the request, the DHCP server can provide the necessary configuration parameters, such as IP address, subnet mask, default gateway, and DNS server.

[0084] In the process of polling each network card device, it is necessary to first allocate memory for the network card device, and on the basis of preparing the memory for the network card device to start iPXE, further inquire about the network status of the network card device, which is not described in detail in the present invention. Among them, the resource allocation pointer is a memory space resource descriptor pointer pre-set in the data structure, which is usually used to indicate the allocation of memory, I / O port, interrupt and other resources for the device (such as the network card device). The resource allocation pointer contains a variety of necessary attribute information of the memory space resource, such as the type of memory resource, the starting address, the ending address, the size, etc. Optionally, the data structure can be obtained from the function implementation code of the BIOS.

[0085] When a resource allocation instruction for a first network card device is received, a target data structure corresponding to the network card device is obtained from the function implementation code through the system firmware. Further, a resource allocation pointer corresponding to the network card device is extracted from the target data structure, wherein each data structure is provided with a resource allocation pointer. After determining the target data structure corresponding to the first network card setting, the resource allocation pointer can be directly extracted from the target data structure without further screening. The first network card device can represent the current network card device in the polling process. Optionally, in an embodiment of the present invention, the system firmware can be BIOS firmware.

[0086] In a possible example, the system firmware further includes an initialization driver. Before obtaining the resource allocation pointer in response to the resource allocation instruction, the resource allocation pointer is set by the following method. Before step 101, the following method is further included:

[0087] Searching, through the system firmware, a target data structure corresponding to the first network card device from the driver code of the initialization driver, the target data structure being used to initialize the expansion bridge;

[0088] Setting a resource allocation pointer in the target data structure, where the resource allocation pointer includes memory information of the first network card device;

[0089] Initialize the resource allocation pointer to a null pointer by initializing the driver.

[0090] Optionally, the data structure is defined in the function implementation code of the BIOS. Usually, there is a special data structure in the function implementation code to describe the properties of the PCI / PCIE Root Bridge. The PCI / PCIE Root Bridge is responsible for managing the communication between the CPU and the PCI / PCIE device and is the entrance to the PCI / PCIE system. Exemplarily, during the initialization process of the system firmware, i.e., the BIOS, there will be an initialization driver (Driver) responsible for initializing the PCI / PCIE system topology and devices. This driver will identify each PCI / PCIE Root Bridge, intermediate Bridge, and EndDevice in the system, and perform corresponding register configuration, resource allocation, and driver loading. The initialization driver can also be used to perform actions such as initialization of PXE, memory allocation, and enumeration.

[0091] Among them, when initializing the PCI / PCIE Bridge, the PCI_ROOT_BRG_DATA data structure will be used. The variable X can be set in the data structure by initializing the driver to obtain the resource allocation pointer corresponding to the network card device. The variable X set in the data structure is a memory space resource descriptor pointer of type QWORD. QWORD is used to describe a data type, representing 64-bit data.

[0092] Preferably, corresponding to multiple network card devices, the initialization driver is provided with multiple data structures, wherein the data structures and the network card devices are in a one-to-one correspondence, that is, the number of data structures and network card devices is consistent, and a resource allocation pointer is provided in each data structure, so that each network card device corresponds to the data structure one-to-one, and then the network card device and the resource allocation pointer in the data structure also correspond one-to-one. By setting the variable X in the data structure, the resource allocation pointer of each network card device is obtained, so that the BIOS can more effectively manage the memory resources in the PCI / PCIE system, and avoid the problem of IPXE startup failure caused by insufficient memory resources.

[0093] After successfully setting the resource allocation pointer, the resource allocation pointer can be initialized to a null pointer through the initialization driver in order to receive subsequent memory resource allocation information. Specifically, initializing the resource allocation pointer to a null pointer can be achieved through the initialization instruction in the initialization function. In the driver code of the BIOS, you can find the initialization function corresponding to the expansion bridge (such as PCI / PCIEBridge), which is also called the driver entry function. This function is usually used to initialize the configuration and resource allocation of the expansion bridge. An initialization instruction can be set at the starting position of the initialization function to initialize the resource allocation pointer to a null pointer (NULL). In this way, whenever the initialization function of the expansion bridge is called and the expansion bridge is initialized, the pointer initialization instruction inserted in the initialization function is also executed. The resource allocation pointer is initialized to a null pointer by initializing the driver, thereby ensuring that the resource allocation pointer does not point to any memory address before resource allocation, avoiding potential problems in memory resource management.

[0094] In a possible implementation, since the present invention solves the problem of the network card port PXE installation system, the operation object is limited to the network card device. According to actual needs, the system firmware can filter and obtain the network card device from all PCI devices according to the device class code Class Code defined in the PCI / PCIE specification, and perform the setting of the resource allocation pointer for the network card device. Specifically, it can be performed through the following steps:

[0095] Get all the connected devices connected to the bus through the system firmware;

[0096] Taking any one of the connected devices as a target connected device, and identifying a device class code of the target connected device;

[0097] If the device class code matches the preset network card device code, then confirming that the target connection device is the second network card device;

[0098] The target device link where the second network card device is located is obtained through the system firmware, and a corresponding resource allocation pointer is set for each network card device in the target device link.

[0099] Optionally, the system firmware can scan all buses in the system and identify all PCI / PCIE devices connected to the bus. By reading the configuration space of each device, the device class code, bus number, device number, function number and other information of the device can be obtained.

[0100] In the PCI / PCIE system, the device class code (Class Code) is an important field used to identify the device type and function. Each PCI / PCIE device has a unique device class code that is used to describe the category, subcategory, and programming interface of the device. The device class code is usually stored in the configuration space of the device for use by the BIOS and operating system. Among them, the device class code is usually composed of three bytes, namely: Base Class Code: Identifies the basic category of the device, such as storage controller, network controller, multimedia device, etc., Subclass Code: Identifies the specific subcategory of the device, such as IDE controller, SCSI controller, Ethernet controller, etc., Programming Interface: Identifies the programming interface of the device, which is used to further refine the functions and characteristics of the device.

[0101] Table 1: Correspondence between base class code and device type description in device class code

[0102]

[0103] As shown in Table 1, when the base class code is 0x02, it can be determined that the device is an Ethernet controller, that is, a network card device. By matching the device class code with the system firmware, the network card device can be screened out from all PCI devices. Furthermore, starting from the screened second network card device, the target device link where the second network card device is located can be obtained, wherein the second network card device is the network card device obtained by matching the device class code.

[0104] In the PCI / PCIE system, the ownership relationship between devices and Bridges is described by bus numbers, device numbers, and function numbers. In order to obtain the network card terminal device and all levels of Bridges in its PCI / PCIE link, until the root port RootPort, to form a complete PCIE link, specifically, the configuration information of the second network card device can be obtained. The configuration information may include its bus number, device number, function number, etc. The device address of the parent device of the second network card device is extracted from the configuration information. For example, the device address of the parent device is usually stored in a specific register in the configuration space of the network card device. By reading the value of the specific register, the parent device of the second network card device can be obtained; at the same time, in order to keep records, the second network card device and the configuration information of the second network card device are recorded by the generated device record; after the record is generated, the second network card device is updated to the parent device. Device, and returns to the step of obtaining the configuration information of the second network card device, and iteratively executes the steps of obtaining the parent device, taking the parent device as the second network card device, and then obtaining the parent device, until the address information of the root port is extracted from the configuration information, indicating that the current second network card device is connected to the root port and there is no longer a parent device, that is, the starting point of the device link is obtained, and the loop ends; since a device record is generated for each obtained second network card device in advance, the "first second network card device" and multiple parent devices can be found by generating the record, therefore, based on the multiple second network card devices and the root port in the device record, the target device link where the second network card device is located can be generated in series, and the target device link includes the root port, the second network card device and the parent device of each level.

[0105] In most operating systems, you can use command-line tools in the system firmware (such as ifconfig, ip addr, ethtool, etc. in Linux, or ipconfig, netsh, etc. in Windows) to view the configuration information of the network card device. This information usually includes the IP address, subnet mask, gateway, etc. of the network card, and the address information of the parent device can be obtained based on the configuration information.

[0106] Optionally, in the process of iteratively acquiring the parent device, it is possible to determine whether the upper level of the second network card device is a parent device or a root port through an identifier in the configuration information. Specifically, a device record can be generated to record the second network card device and the configuration information corresponding to the second network card device. By extracting the configuration information, it is confirmed whether the configuration information contains the identifier of the root port. If the configuration information contains the identifier of the root port, indicating that the second network card device is connected to the root port and there is no upper-level parent device, the address information of the root port is extracted from the configuration information. If the configuration information does not contain the identifier of the root port, indicating that the second network card device is connected to the parent device, based on the configuration information and the bridging relationship, the device address of the parent device is extracted from the configuration information, and the parent device is further acquired based on the device address of the parent device, and the loop continues.

[0107] Step 102: if the resource allocation pointer is a null pointer, the system firmware applies for a first memory for the first network card device according to the resource allocation instruction, obtains first memory information of the first memory, and writes the first memory information into the resource allocation pointer.

[0108] Step 103: If the resource allocation pointer is not a null pointer, the second memory information in the resource allocation pointer is read through the system firmware, and the second memory corresponding to the second memory information is obtained.

[0109] In the process of polling the network card port, the network card device currently being queried needs to first allocate memory, make memory preparations, and then detect the network connection. If the memory allocation is successful and the network is connected, PXE is started by the current network port. If the memory allocation fails or the network is not connected, the PXE startup step is skipped and the next network card port is queried. Among them, the network card device can also be understood as the logical device of the network card port.

[0110] Exemplarily, in the process of allocating memory resources, by checking the value of the resource allocation pointer, the memory allocation status of the first network card device can be confirmed, and further whether it is necessary to apply for the first memory for the first network card device for memory preparation. Optionally, if the resource allocation pointer is a null pointer, it indicates that in the current resource allocation process, memory has not been allocated for the first network card device. For example, during the system startup or initialization process, the resource allocation pointer may be initialized to a null pointer, indicating that memory allocation has not been performed, or, in the previous memory allocation process, the memory allocation may fail due to some reasons (such as insufficient memory), so the resource allocation pointer is still a null pointer.

[0111] In this case, it is necessary to apply for memory for the first network card device according to the resource allocation instruction through the system firmware, and write the memory information into the resource allocation pointer. Specifically, the pointer status can be confirmed by the value of the resource allocation pointer. For example, when the resource allocation pointer is empty, it indicates that the resource allocation pointer is a null pointer (NULL). It is necessary to apply for memory for the first network card device, and the first memory information of the first memory can be extracted from the resource allocation instruction, wherein the first memory information can include a variety of necessary memory information such as memory type, memory size, and memory address. According to the extracted first memory information, the first memory is applied for the first network card device through the memory management function provided by the BIOS, and after applying for the memory, the memory information of the first memory is obtained, including the memory address, size, etc., and the first memory information is written into the resource allocation pointer to ensure that the resource allocation pointer is no longer a null pointer, indicating that the memory has been successfully allocated.

[0112] If the resource allocation pointer is not a null pointer, this usually means that the first network card device has allocated memory, and the resource allocation pointer stores the corresponding memory information. For example, in the previous resource allocation process, the system firmware has successfully allocated memory resources for the first network card device, and the memory information is written into the resource allocation pointer. In this case, it is necessary to obtain the existing memory of the first network card device and make further judgments on the existing memory to determine whether it is necessary to re-allocate memory resources for the first network card device.

[0113] Specifically, the existing memory of the first network card device can be further judged through the following steps:

[0114] If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware;

[0115] Obtaining a second memory corresponding to the second memory information, and using a memory detection tool to confirm whether the second memory is invalid;

[0116] If the second memory is invalid, confirming that the second memory is invalid memory;

[0117] If the second memory is not invalid, then the second memory is confirmed to be a valid memory.

[0118] In the driver code of the initialization driver, if the resource allocation pointer corresponding to the first network card device is not a null pointer, it indicates that the first network card device has been allocated memory resources. In order to determine the existing memory status of the first network card device, it is necessary to obtain the existing memory of the first network card device. Optionally, the second memory information can be read from the resource allocation pointer, including the memory address and size of the existing memory, and the second memory corresponding to the second memory information can be obtained to confirm the validity of the second memory. The validity of the second memory can be confirmed by the memory detection tool in the system firmware, or by running a stress test, checking the system log, etc. The validity of the second memory can be quickly confirmed by existing means, and the present invention will not be repeated again. The second memory is the existing memory of the first network card device.

[0119] By checking whether the resource allocation pointer is a null pointer, it can be determined whether it is necessary to apply for memory for the first network card device. If the pointer is null, a memory application is performed, and memory information of the memory is obtained, and then the information is written into the resource allocation pointer. If the pointer is not null, the memory information in the resource allocation pointer is read, and the corresponding memory is obtained. In this way, it can be ensured that memory resources can be correctly allocated and managed during the resource allocation process, and system problems caused by insufficient memory resources can be avoided.

[0120] Step 104: if the second memory is invalid memory, clear the second memory information through the system firmware, apply for the first memory for the network card device according to the resource allocation instruction, and write the first memory information into the resource allocation pointer.

[0121] When the second memory is confirmed as valid memory, it indicates that the second memory has at least no hardware failure, no data error, high stability and normal performance. In this case, the second memory can be directly used as the memory resource of the first network card device, and there is no need to apply for memory resources for the first network card device again. Optionally, based on confirming that the second memory is valid memory, it indicates that the memory preparation of the first network card device has been completed, and the first network card device can be used as the target network card device for booting and installing the operating system, that is, starting PXE through the first network card device to further detect the network status of the first network card device.

[0122] When the second memory is confirmed as invalid memory, it indicates that the second memory may have a hardware failure of the memory bar, such as damage or defects such as circuit damage, chip damage, poor contact, etc., and there may also be data errors, which cause errors in the second memory when reading and writing data, thereby failing to ensure data integrity, such as bit errors, block errors, and check errors. When the second memory is confirmed as invalid memory, the existing second memory needs to be cleared and new memory resources need to be allocated to the first network card device again. Optionally, the relevant information of the second memory can be cleared through the driver code of the BIOS to ensure that the first network card device no longer uses invalid memory, and the first memory information is extracted from the resource allocation instruction, and the first memory is re-applied for the network card device according to the first memory information to ensure that the system has sufficient memory resources. After the memory is successfully applied for again, the first memory information of the first memory can be written into the resource allocation pointer to ensure that the memory resources can be correctly allocated and managed.

[0123] In a possible implementation, after completing the memory application for the first network card device and implementing the memory preparation for the network card device, the network status of the network card device may be further detected. Specifically, this may be achieved through the following steps:

[0124] Acquire a first network status of a first network card device through system firmware;

[0125] If the first network status indicates that the first network card device is not connected, a third network card device is obtained and resources are allocated to the third network card device.

[0126] Optionally, a network status detection request can be sent through the first network card device, and whether the first network card device is connected can be determined based on the return result of the network status detection request, thereby obtaining the network status of the first network card device. Exemplarily, the network status of the first network card device can be determined by detecting the network cable connection status, or the network communication status. Specifically, whether the network cable is connected can be detected through the hardware signal of the first network card device, wherein whether the network cable is connected refers to the connection status between the network cable and the network card device at the physical level. If the network cable is connected, it means that a physical connection is established between the network cable plug and the network port of the network card device. Since the network cable connection is the basis of network communication, data cannot be transmitted without physical connection. Therefore, when the network cable of the first network card device is in a disconnected state, it can be confirmed that the first network state of the first network card device is disconnected. At this time, PXE cannot be started through the first network card device, and it is necessary to poll the next network card device, that is, poll the third network card device, where the third network card device is the next network card device of the current first network card device; when it is confirmed that the network cable of the first network card device is in a connected state, it is necessary to further detect the network communication state. If due to network configuration errors, such as IP address conflicts, gateway configuration errors, etc., the network communication still cannot proceed normally when the network cable is connected, it can be confirmed that the network communication state of the first network card device is network disconnected. At this time, data still cannot be transmitted. Therefore, when the network cable of the first network card device is in a connected state and the network communication state is network disconnected, it can still be confirmed that the first network state of the first network card device is disconnected.

[0127] Optionally, only when the network cable of the first network card device is connected and the network configuration is correct, that is, when the network is detected to be unobstructed, can the network communication be confirmed to be normal and the first network status is connected. In this case, the first network card device can be used as the target network card device to start PXE. Therefore, during the PXE startup process, if it is detected that the server is configured with multiple network card ports (network card devices), the polling mechanism will try to obtain DHCP services through each network port to find an available network connection. This will help to automatically switch to other network ports when the current network port connection fails, so as to improve the success rate of startup. Especially in the case of complex network environment or hardware failure, network port polling can increase the fault tolerance of system startup and avoid startup failure due to a single network port failure.

[0128] In one example, when a client uses iPXE to install RHEL 7.6, it is received that there is a probability of freezing during the boot phase, and a prompt "EFI stub: ERROR: Failed to alloc highmem for initrds" is received. After software version upgrade and log analysis, the cause of the freezing problem is located in the memory application phase. Through further analysis, it is found that when the driver of the network card device performs the Link Up action, each time the network card device status is polled, the memory applied for is not released after Polling, resulting in abnormal occupation of available memory; therefore, when the Polling time reaches the 14th second, all the available memory is occupied, resulting in IPXE being unable to apply for available memory for Initrd. Exemplarily, the driver of the network card device can be MLX Driver. The Link Up action refers to the process in which the network interface card (NIC) detects that the physical link connection status becomes available (that is, the link is connected) and starts data transmission.

[0129] To address the boot phase jamming issue caused by the above memory allocation, you can add a memory release mechanism in the MLX Driver to ensure that memory resources that are no longer in use are released after each Polling, to prevent the network card ports that cannot implement PXE startup from continuously occupying the requested memory, resulting in an increasing amount of memory occupied during the polling process, and less and less remaining memory available until all memory is occupied. When each network card port tries to establish a connection, it only occupies the memory resources required to start IPXE on the current port, and does not accumulate the demand for memory resources, effectively avoiding downtime and installation failures caused by memory occupation.

[0130] Specifically, in the Polling process, when it is confirmed that the first network state of the first network card device currently polled is not connected and the next network card device needs to be queried, the first memory of the first network card device can be released through the system firmware, and the first memory information in the resource allocation pointer corresponding to the first network card device can be cleared to ensure that the pointer no longer points to the released memory area, thereby updating the resource allocation pointer to make it empty. Exemplarily, when it is confirmed that the first network state is not connected, the first memory can be released immediately to avoid additional occupation of memory resources, or the first memory can be released after a period of time to avoid data errors caused by frequent memory operations, wherein the release of the first memory can be achieved by calling a memory release function, such as free() or a corresponding driver memory management function. By optimizing the Polling mechanism, the memory of the unconnected network card device is released in time, and the memory information in the resource allocation pointer is cleared, so that the memory leakage problem can be effectively avoided. Combined with the memory pool technology and the dynamic memory management strategy, the memory usage efficiency and system stability are further improved. The embodiment of the present invention adopts the implementation method of calling the BIOS when the BIOS modifies the Polling Link up state of the MLX Driver network card to solve the problem that the memory is not released by the MLX Driver, and the memory is only applied once and then reinitialized for use each time Polling.

[0131] Reference Figure 2, showing a schematic diagram of an example of a dynamic memory allocation method provided by an embodiment of the present invention, after setting the initialization instruction in the initialization function, as the system starts and the hot plug action is performed, the initialization instruction is executed while the expansion bridge is initialized, so that the resource allocation pointer is initialized to a null pointer, and after entering the polling process, for the first network card device currently polled, it is confirmed whether the resource allocation pointer of the first network card device is null. If the resource allocation pointer is null, it indicates that the first null device has not allocated memory, and the system firmware applies for the first memory for the first network card device according to the resource allocation instruction, and further obtains the first network status of the first network card device, and detects the network connection of the first network card device. If the resource allocation pointer is not null, it indicates that the first network card device has occupied memory resources, and the occupied memory of the first network card device needs to be further detected. The second memory information in the resource allocation pointer can be read by the system firmware, and the validity of the second memory is judged. If the second memory is valid memory, it indicates that the first network card device If the occupied memory of the first network card device can continue to be used, the network connection status of the first network card device can be continued to be detected. If the second memory is invalid memory, it indicates that the occupied memory of the first network card device cannot be continued to be used, and new memory resources need to be reallocated to the first network card device. The system firmware applies for the first memory for the first network card device according to the resource allocation instruction, so as to confirm the current memory occupation status of the first network card device by setting the resource allocation pointer of the first network card device, and keep the first memory updated; in the process of detecting the network connection status of the network card device, if the first network status of the current first network card device is not connected, it indicates that the network cable of the first network card device is not connected or the network is not accessible, and data transmission cannot be performed normally, and the next network card device needs to be inquired. The first memory of the first network card device is released through the system firmware, thereby effectively avoiding the invalid network port that cannot start iPXE from continuously occupying memory resources, resulting in the other network ports being unable to apply for the required memory resources, and finally causing the installation system to be interrupted due to the failure of memory application.

[0132] The present invention obtains a data structure corresponding to a network card device through system firmware, confirms a memory allocation state of the network card device according to a resource allocation pointer pre-set in the data structure, and further reads memory information in the network card device to judge the existing memory of the network card device, thereby deciding to apply for memory for the network card device or clear the memory and then apply again in the current polling process based on the memory allocation state of the network card device, thereby ensuring that the memory resources of the network card device are kept updated, and by optimizing the Polling mechanism in the firmware BIOS, confirming the memory allocation state of the network card device, and checking the memory occupied by each network card device, the memory leakage problem caused by the continuous memory occupation by the network card device that cannot be connected can be effectively avoided.

[0133] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0134] Reference Figure 3 , shows a structural block diagram of a memory dynamic allocation device provided by an embodiment of the present invention, wherein the memory dynamic allocation device is applied to system firmware and may specifically include the following modules:

[0135] The allocation pointer extraction module 301 is used to obtain a target data structure corresponding to the first network card device through the system firmware in response to a resource allocation instruction for the first network card device, and extract a resource allocation pointer from the target data structure;

[0136] The memory information allocation module 302 is used for applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware if the resource allocation pointer is a null pointer, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer;

[0137] The memory information reading module 303 reads the second memory information in the resource allocation pointer through the system firmware if the resource allocation pointer is not a null pointer, and obtains the second memory corresponding to the second memory information;

[0138] The memory information reallocation module 304 is used to clear the second memory information through the system firmware if the second memory is invalid memory, apply for the first memory for the network card device according to the resource allocation instruction, and write the first memory information into the resource allocation pointer.

[0139] Furthermore, the system firmware includes an initialization driver, and the dynamic memory allocation device also includes:

[0140] A target structure search module, used to search for a target data structure corresponding to the first network card device from the driver code of the initialization driver through the system firmware, and the target data structure is used to initialize the expansion bridge;

[0141] A resource pointer setting module, used for setting a resource allocation pointer in a target data structure, wherein the resource allocation pointer includes memory information of the first network card device;

[0142] The resource pointer initialization module is used to initialize the resource allocation pointer to a null pointer by initializing the driver.

[0143] Furthermore, the resource pointer initialization module also includes:

[0144] An initialization function acquisition module is used to acquire the initialization function of the expansion bridge through the initialization driver;

[0145] An initialization setting module, used for setting a pointer initialization instruction for initializing a resource allocation pointer at the start position of an initialization function;

[0146] The initialization instruction execution module is used for executing the pointer initialization instruction through the initialization driver in response to the initialization of the expansion bridge, so that the resource allocation pointer is initialized to a null pointer.

[0147] Furthermore, the dynamic memory allocation device also includes:

[0148] A bus device acquisition module is used to acquire all connected devices connected to the bus through the system firmware;

[0149] A device class identification module is used to take any device among the connected devices as a target connected device and identify a device class code of the target connected device;

[0150] A network card device matching module, used for confirming that the target connection device is a second network card device if the device class code matches the preset network card device code;

[0151] The device link acquisition module is used to acquire the target device link where the second network card device is located through the system firmware, and set a corresponding resource allocation pointer for each network card device in the target device link.

[0152] Furthermore, the device link acquisition module also includes:

[0153] A network card device configuration acquisition module, used to acquire configuration information of a second network card device through system firmware;

[0154] A parent device address extraction module, used to generate a device record of the second network card device and configuration information, and extract the device address of the parent device of the second network card device from the configuration information;

[0155] A parent device acquisition loop module, used for updating the second network card device to the parent device, and returning to the step of acquiring the configuration information of the second network card device until the address information of the root port is extracted from the configuration information;

[0156] The device link generation module is used to generate a target device link where the second network card device is located based on a plurality of second network card devices and a root port in the device record.

[0157] Furthermore, the parent device address extraction module also includes:

[0158] A device record generation module, used to generate a device record, the device record is used to record the second network card device and configuration information;

[0159] A root port address extraction module, used to extract the address information of the root port from the configuration information through the system firmware if the configuration information contains the identification of the root port;

[0160] The parent device address extraction submodule is used to extract the device address of the parent device from the configuration information based on the configuration information and the bridge relationship through the system firmware if the configuration information does not contain the identification of the root port.

[0161] Furthermore, the dynamic memory allocation device also includes:

[0162] A network status confirmation module, used for obtaining a first network status of a first network card device through system firmware;

[0163] The network card device polling module is used to obtain a third network card device and allocate resources to the third network card device if the first network status indicates that the first network card device is not connected. The third network card device is the next network card device of the first network card device.

[0164] Furthermore, the network status confirmation module also includes:

[0165] A network status detection module, used to detect the network cable connection status of the first network card device, or the network communication status;

[0166] A network disconnection confirmation module, used for, if the network cable of the first network card device is not connected, or the network is not accessible, then the first network state is characterized as the first network card device being disconnected;

[0167] The network connection confirmation module is used to indicate that if the network cable of the first network card device is connected and the network is unobstructed, then the first network state is characterized as the first network card device being connected.

[0168] Furthermore, the dynamic memory allocation device also includes:

[0169] The device memory release module is used to release the first memory of the first network card device through the system firmware and clear the first memory information in the resource allocation pointer corresponding to the first network card device.

[0170] Furthermore, the memory information allocation module 302 also includes:

[0171] A null pointer confirmation module, used for confirming that the resource allocation pointer is a null pointer if the value of the resource allocation pointer is null;

[0172] A memory information extraction module, used to extract first memory information of a first memory from a resource allocation instruction through a system firmware, wherein the first memory information includes a memory type, a memory size, and a memory address;

[0173] The first memory allocation module is used to apply for a first memory for the first network card device according to the first memory information through the system firmware, and write the first memory information into the resource allocation pointer.

[0174] Furthermore, the memory information reading module 303 also includes:

[0175] A second memory information reading module, configured to read the second memory information in the resource allocation pointer through the system firmware if the resource allocation pointer is not a null pointer;

[0176] A second memory detection module, used for obtaining a second memory corresponding to the second memory information, and using a memory detection tool to confirm whether the second memory is invalid;

[0177] An invalid memory confirmation module, used for confirming that the second memory is invalid memory if the second memory is invalid;

[0178] The valid memory confirmation module is used to confirm that the second memory is a valid memory if the second memory is not invalid.

[0179] Furthermore, the dynamic memory allocation device also includes:

[0180] The target network card device confirmation module is used to use the first network card device as the target network card device if the second memory is a valid memory, and the target network card device is used to boot and install the operating system.

[0181] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0182] refer to Figure 4 The embodiment of the present invention further provides an electronic device, including a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402 and the memory 403 communicate with each other through the communication bus 404.

[0183] Memory 403, used for storing computer programs;

[0184] The processor 401 is used to execute the program stored in the memory 403 to implement the following steps:

[0185] In response to a resource allocation instruction for the first network card device, obtaining a target data structure corresponding to the first network card device through the system firmware, and extracting a resource allocation pointer from the target data structure;

[0186] If the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer;

[0187] If the resource allocation pointer is not a null pointer, the second memory information in the resource allocation pointer is read through the system firmware, and the second memory corresponding to the second memory information is obtained;

[0188] If the second memory is invalid memory, the second memory information is cleared through the system firmware, the first memory is applied for the network card device according to the resource allocation instruction, and the first memory information is written into the resource allocation pointer.

[0189] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0190] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0191] The embodiment of the present invention also provides a non-volatile readable storage medium. When the instructions in the non-volatile readable storage medium are executed by the processor of the electronic device, the electronic device can execute the various processes of the above-mentioned dynamic memory allocation method embodiment and achieve the same technical effect. To avoid repetition, it is not repeated here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0192] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the dynamic memory allocation method described in any one of the above embodiments.

[0193] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0194] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0195] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0196] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in the embodiments of the present invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0197] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A method for dynamic memory allocation, characterized in that: Applied to system firmware, the system firmware includes an initialization driver, the method includes: Searching, through the system firmware, from the driver code of the initialization driver, a target data structure corresponding to the first network card device, wherein the target data structure is used to initialize the expansion bridge; Setting a resource allocation pointer in the target data structure, wherein the resource allocation pointer includes memory information of the first network card device; In response to a resource allocation instruction for the first network card device, obtaining a target data structure corresponding to the first network card device through the system firmware, and extracting the resource allocation pointer from the target data structure; If the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer; If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware, and acquiring the second memory corresponding to the second memory information; If the second memory is invalid memory, the second memory information is cleared by the system firmware, the first memory is applied for the network card device according to the resource allocation instruction, and the first memory information is written into the resource allocation pointer.

2. The method according to claim 1, characterized in that: Before the step of obtaining a target data structure of the first network card device in response to a resource allocation instruction for the first network card device and extracting a resource allocation pointer from the target data structure, the method further includes: The resource allocation pointer is initialized to a null pointer through the initialization driver.

3. The method according to claim 2, characterized in that Initializing the resource allocation pointer to a null pointer by the initialization driver includes: Obtaining the initialization function of the expansion bridge through the initialization driver; At the start position of the initialization function, a pointer initialization instruction for initializing the resource allocation pointer is set; In response to the initialization of the expansion bridge, the pointer initialization instruction is executed by the initialization driver, so that the resource allocation pointer is initialized to a null pointer.

4. The method according to claim 2, characterized in that: Before searching the target data structure corresponding to the first network card device from the driver code of the initialization driver through the system firmware, the method further includes: Acquire all connected devices connected to the bus through the system firmware; Taking any one of the connection devices as a target connection device, and identifying a device class code of the target connection device; If the device class code matches the preset network card device code, confirming that the target connection device is a second network card device; The target device link where the second network card device is located is obtained through the system firmware, and a corresponding resource allocation pointer is set for each network card device in the target device link.

5. The method according to claim 4, characterized in that The step of obtaining the target device link where the second network card device is located through the system firmware and setting a corresponding resource allocation pointer for each network card device in the target device link includes: Acquire the configuration information of the second network card device through the system firmware; Generate a device record of the second network card device and the configuration information, and extract a device address of a parent device of the second network card device from the configuration information; Updating the second network card device to the parent device, and returning to the step of obtaining the configuration information of the second network card device until the address information of the root port is extracted from the configuration information; A target device link where the second network card device is located is generated based on the plurality of second network card devices in the device record and the root port.

6. The method according to claim 5, characterized in that The step of generating a device record of the second network card device and the configuration information, and extracting a device address of a parent device of the second network card device from the configuration information includes: Generate the device record, where the device record is used to record the second network card device and configuration information; If the configuration information includes the identifier of the root port, extracting the address information of the root port from the configuration information by the system firmware; If the configuration information does not include the identifier of the root port, the device address of the parent device is extracted from the configuration information by the system firmware based on the configuration information and the bridge relationship.

7. The method according to claim 1, characterized in that If the second memory is invalid memory, clearing the second memory information by the system firmware, applying for the first memory for the network card device according to the resource allocation instruction, and writing the first memory information into the resource allocation pointer, the method further includes: Acquire a first network status of the first network card device through the system firmware; If the first network status indicates that the first network card device is not connected, a third network card device is obtained and resources are allocated to the third network card device, where the third network card device is the next network card device of the first network card device.

8. The method according to claim 7, characterized in that The obtaining the first network status of the first network card device through the system firmware includes: Detecting the network cable connection status or network communication status of the first network card device; If the network cable of the first network card device is not connected, or the network is not accessible, the first network state is characterized as the first network card device being not connected; If the network cable of the first network card device is connected and the network is unobstructed, the first network status is characterized as the first network card device being connected.

9. The method according to claim 7, characterized in that: After the step of acquiring the third network card device and allocating resources to the third network card device if the first network status indicates that the first network card device is not connected, and the third network card device is the next network card device of the first network card device, the method further includes: The first memory of the first network card device is released through the system firmware, and the first memory information in the resource allocation pointer corresponding to the first network card device is cleared.

10. The method according to claim 1, characterized in that If the resource allocation pointer is a null pointer, applying for a first memory for the first network card device according to the resource allocation instruction through the system firmware, obtaining first memory information of the first memory, and writing the first memory information into the resource allocation pointer, including: If the value of the resource allocation pointer is null, confirming that the resource allocation pointer is a null pointer; extracting first memory information of the first memory from the resource allocation instruction by the system firmware, wherein the first memory information includes a memory type, a memory size, and a memory address; The system firmware applies for the first memory for the first network card device according to the first memory information, and writes the first memory information into the resource allocation pointer.

11. The method according to claim 1, characterized in that: If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware, and acquiring the second memory corresponding to the second memory information, includes: If the resource allocation pointer is not a null pointer, reading the second memory information in the resource allocation pointer through the system firmware; Acquire a second memory corresponding to the second memory information, and use a memory detection tool to confirm whether the second memory is invalid; If the second memory is invalid, confirming that the second memory is invalid memory; If the second memory is not invalid, then the second memory is confirmed to be a valid memory.

12. The method according to claim 1, characterized in that After the step of reading the second memory information in the resource allocation pointer through the system firmware if the resource allocation pointer is not a null pointer and acquiring the second memory corresponding to the second memory information, the method further includes: If the second memory is a valid memory, the first network card device is used as a target network card device, and the target network card device is used to boot and install an operating system.

13. An electronic device comprising: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the dynamic memory allocation method described in any one of claims 1 to 12.

14. A non-volatile readable storage medium, when instructions in the non-volatile readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the dynamic memory allocation method as described in any one of claims 1 to 12.

15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method for dynamically allocating memory according to any one of claims 1 to 12 is implemented.

Citation Information

Patent Citations

  • Network card configuration method and resource management center

    CN105518620A

  • Equipment starting method and device and computer readable storage medium

    CN113204384A