Memory early mapping method and device, equipment and storage medium
By dynamically adjusting the L2 page table mapping in the Jailhouse system, the problem of insufficient space mapping in multi-CPU scenarios is solved, ensuring the system starts normally, and the scope of application of Jailhouse is expanded.
Patent Information
- Application Number
- CN202510742215.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2045-06-05
AI Technical Summary
In the Jailhouse system, due to insufficient space mapping caused by the large number of processors, the system cannot start normally, especially in multiple CPU scenarios such as servers, which leads to the failure of Jailhouse startup.
By determining the maximum number of supported CPUs corresponding to the memory space of the L2 page table map initialized by the Jailhouse virtual machine monitor, obtain the size of the percpu variable copy data structure, determine whether the currently configured CPU number exceeds the maximum number of supported numbers, and when it exceeds, determine the additional memory space required based on the currently configured CPU number, the maximum number of supported CPUs, and the size of the percpu variable copy data structure, convert it into the number of new page table entries, and add the corresponding page table entries to the original L2 page table as the newly added mapping area.
It realizes normal passage when the CPU is initialized in Jailhouse in the early stage, avoids initialization failure due to lack of mapping, and does not cause additional mapping waste, which expands the scope of application of Jailhouse.
Smart Images

Figure CN120256336A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Jailhouse, and in particular to a method, device, equipment and storage medium for early memory mapping. Background Art
[0002] Jailhouse is a partitioned virtual machine manager based on Linux, which configures the virtualization characteristics of hardware such as CPUs in a way called cell. A cell is a description of system hardware resources and is described using C language syntax. Cells are divided into root cells and non-root cells. The root cell takes over system hardware resources and there is only one; there can be multiple non-root cells, and they obtain system resources from the root cell. CPU or memory resources can be allocated to non-root cells, and each cell can run its own application programs or services, and they are highly isolated from each other.
[0003] Jailhouse establishes isolation domains and can directly access physical resources without emulation or para-virtualization, achieving high performance. It not only retains the generality of the Linux operating system but also makes it easy to implement secure and real-time workloads running in isolation domains by leveraging its own simplicity.
[0004] In the early stage of Jailhouse startup, each CPU needs to be initialized. When initializing in EL2, a temporary page table needs to be established to prepare for enabling the MMU in EL2. After enabling the MMU, the CPU will access using virtual addresses, set the final exception vector table, and initialize the stack and other data of the CPU.
[0005] In the process of implementing the present invention, the inventors found the following problem: The 2MB space mapped in scenarios with a large number of CPUs such as servers cannot meet the requirements, and there will be a situation of being stretched. Eventually, due to the unmapped space at the back, the access to the subsequent percpu data fails, which in turn leads to the failure of Jailhouse startup. Summary of the Invention
[0006] Embodiments of the present invention provide a method, device, equipment and storage medium for early memory mapping to solve the technical problem in the prior art that the Jailhouse system cannot start normally due to the influence of a large number of processors on space mapping.
[0007] In a first aspect, embodiments of the present invention provide a method for early memory mapping, including: Determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed by the initialization of the Jailhouse virtual machine monitor; Obtain the size of the data structure of the percpu variable copy; Obtain the number of CPUs currently configured by the Jailhouse virtual machine monitor, and determine whether the number of currently configured CPUs exceeds the maximum supported number of CPUs; When it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum supported number of CPUs, and the size of the data structure of the percpu variable copy; Convert the required memory space into the number of newly added page table entries; Add corresponding page table entries to the original L2 page table as the newly added mapping area according to the number of newly added page table entries.
[0008] In a second aspect, an embodiment of the present invention further provides a memory early mapping device, including: A determination module, configured to determine the maximum supported number of CPUs corresponding to the memory space mapped by the L2 page table formed by the initialization of the Jailhouse virtual machine monitor; An acquisition module, configured to obtain the size of the data structure of the percpu variable copy; A judgment module, configured to obtain the number of CPUs currently configured by the Jailhouse virtual machine monitor, and judge whether the number of currently configured CPUs exceeds the maximum supported number of CPUs; An additional memory space determination module, configured to, when it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum supported number of CPUs, and the size of the data structure of the percpu variable copy; A conversion module, configured to convert the required memory space into the number of newly added page table entries; An addition module, configured to add corresponding page table entries to the original L2 page table as the newly added mapping area according to the number of newly added page table entries.
[0009] In a third aspect, an embodiment of the present invention provides a device, including: Multiple processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the multiple processors, the multiple processors implement any one of the memory early mapping methods provided in the above embodiments.
[0010] In a fourth aspect, an embodiment of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the memory early mapping method provided in the above embodiments when executed by a computer processor.
[0011] The memory early mapping method, device, equipment and storage medium provided by the embodiments of the present invention determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed by initializing the Jailhouse virtual machine monitor; obtain the size of the percpu variable copy data structure; obtain the number of currently configured CPUs of the Jailhouse virtual machine monitor, and determine whether the number of currently configured CPUs exceeds the maximum number of supported CPUs; when it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum number of supported CPUs and the size of the percpu variable copy data structure; convert the required memory space into the number of newly added page table entries; add corresponding page table entries to the original L2 page table according to the number of newly added page table entries as a newly added mapping area. Determine the maximum number of currently supported CPUs through the memory space mapped by the L2 page table formed by initialization, and based on the difference between the number of currently configured CPUs and the maximum number of currently supported CPUs, cooperate with the percpu variable copy data structure required by each CPU during initialization to calculate the additional required memory space, convert the required space into the number of newly added page table entries, and use it as a newly added mapping area to accommodate the corresponding and percpu variable copy data structures of the extra CPUs. Ensure that all spaces that need to be accessed are mapped early. Enable the Jailhouse to pass the CPU early initialization normally, and at the same time, it will neither fail the initialization due to lack of mapping nor cause waste due to additional mapping, achieving on-demand mapping and increasing the applicable range of Jailhouse. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Other features, objects and advantages of the present invention will become more apparent by reading the detailed description of the non-limiting embodiments with reference to the following drawings: Figure 1 is a flowchart of the memory early mapping method provided by Embodiment 1 of the present invention; Figure 2 is a flowchart of the memory early mapping method provided by Embodiment 2 of the present invention; Figure 3 is a structural diagram of the memory early mapping device provided by Embodiment 3 of the present invention; Figure 4 is a structural diagram of the equipment provided by Embodiment 4 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0013] The present invention will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. In addition, it should be noted that, for the sake of description, only parts related to the present invention are shown in the drawings rather than all the structures.
[0014] Embodiment 1 Figure 1 It is a flowchart of the memory early mapping method provided by Embodiment 1 of the present invention. This embodiment is applicable to the case where Jailhouse initializes to establish a corresponding mapped memory space for the CPU. This method can be executed by a memory early mapping device, and specifically includes the following steps: Step 110: Determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed during the initialization of the Jailhouse virtual machine monitor.
[0015] Memory Address Mapping generally refers to the correspondence between virtual addresses and physical addresses, mainly used to manage and optimize the allocation and use of system memory. It is usually used during the system startup process or before a module is used. After establishing the mapping and enabling the MMU, the CPU will use virtual addresses for access, without directly operating on physical memory, which improves memory usage efficiency, simplifies memory management, and enhances security.
[0016] During the early startup process, Jailhouse will establish a simple page table for temporary initialization use. A total of three-level page tables are created for the hypervisor, trampoline, and uart. A global directory Level0 (L0) is created and shared, two L1 tables are created, and one L2 page table is created. The uart and hypervisor share one L2 page table. Each page table occupies 1 page of memory, each page table entry occupies 8 bytes, each page table can store 512 entries, and each page table entry maps a 2MB-sized memory block. Jailhouse only stores one page table entry in the L2 page table for the hypervisor to use, mapping a 2MB space, and the mapping size is fixed. In general usage scenarios, the temporarily mapped 2MB memory space can meet the requirements, and the CPU can access complete data. However, in scenarios with more CPUs such as servers, the mapped 2MB space cannot meet the requirements, resulting in a stretched situation. Eventually, due to the unmapped space at the back, the access to the subsequent percpu data fails, leading to the failure of Jailhouse to start.
[0017] Therefore, in this embodiment, first determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed during the initialization of the Jailhouse virtual machine monitor.
[0018] Since the initial mapped memory space size of the L2 page table in Jailhouse is not a fixed value, it usually needs to be dynamically determined in combination with page granularity configuration (4KB / 2MB), hardware architecture (32 / 64-bit), and system requirements. Calculate the maximum number of CPUs that the memory space corresponding to the L2 page table mapping can support based on the mapped memory space of the currently initialized L2 page table.
[0019] Step 120, obtain the size of the percpu variable copy data structure.
[0020] Since the Jailhouse virtual machine monitor's definition and allocation of data structures for CPU initialization is a static scenario and is affected by the consistency of alignment constraints, for the hardware system corresponding to the Jailhouse virtual machine monitor, the size of the percpu variable copy data structure corresponding to each CPU is the same and fixed.
[0021] Exemplarily, it may include: finding the start address and end address of the percpu data in the assembly macro definition related to the CPU variable; calculating the size of the percpu variable copy data structure based on the end address and start address.
[0022] For example: The assembly macro definition related to the CPU variable is usually generated by the linker script, and its total size of the segment is marked by it: ldCopy Code .data..percpu : { __per_cpu_start =.; *(.data..percpu) __per_cpu_end =.; } Therefore, the calculation method for calculating the size of the percpu variable copy data structure can be per_cpu_end - per_cpu_star.
[0023] Step 130, obtain the number of CPUs currently configured by the Jailhouse virtual machine monitor, and determine whether the number of currently configured CPUs exceeds the maximum supported number of CPUs.
[0024] Exemplarily, the Jailhouse command-line tool can be used to view the current system CPU topology and the number of CPUs allocated to each cell, or the number of currently used CPUs can be determined by parsing the cell configuration file.
[0025] After obtaining the number of CPUs currently configured by the Jailhouse virtual machine monitor, it can be compared with the maximum supported number of CPUs obtained in the previous step.
[0026] Step 140, when it exceeds, determine the additional required memory space according to the number of CPUs in the current configuration, the maximum supported number of CPUs, and the size of the percpu variable copy data structure.
[0027] If the number of CPUs in the current configuration exceeds the maximum supported number of CPUs in the comparison result, it is necessary to determine the additional required memory space according to the number of CPUs in the current configuration, the maximum supported number of CPUs, and the size of the percpu variable copy data structure. Exemplarily, it can be calculated and determined in the following way: MEM = ((N - NUM) * PERCPU_SIZE) / 1024 / 1024, in units of MB; Where MEM is the additional required memory space, N is the number of CPUs in the current configuration, NUM is the maximum supported number of CPUs, and PERCPU_SIZE is the size of the percpu variable copy data structure.
[0028] Using the above method, the memory space required for the unmapped CPUs can be determined.
[0029] Step 150, convert the required memory space into the number of new page table entries.
[0030] Since Jailhouse initializes the mapping of the memory space using the L2 page table, the above required memory space can be converted into the number of new page table entries.
[0031] Exemplarily, it can be implemented in the following way: calculate the number of page table entries PAGE_NUM that need to be added for mapping according to the size of the exceeded space, PAGE_NUM = MEM / 2 + 1.
[0032] Since the initial mapping of the memory space by the L2 page table of Jailhouse is usually 2M in combination with the page granularity configuration in a general architecture, the required memory space can be divided by 2 and added with the base number to obtain the number of page table entries PAGE_NUM for adding mapping.
[0033] Step 160, add corresponding page table entries as a new mapping area in the original L2 page table according to the number of new page table entries.
[0034] Exemplarily, it may include: adding a virtual address and a physical address corresponding to the page table entry based on the newly added page table entry; obtaining the index of the virtual address in the page table entry; and adding a new page table entry to the corresponding physical address in the L2 page table according to the index as the newly added mapping area.
[0035] Since it is a newly added page table entry, it is slightly different from the normal initialization allocation. Exemplarily, first, it is necessary to re-determine the virtual address that needs to be memory-mapped according to the memory range corresponding to the newly added page table entry and the base address in the L1 table. It is not determined by the last virtual address allocated originally. After determining the virtual address, the corresponding physical address is determined. A corresponding index is re-established in the page table entry, and a new page table entry is added to the corresponding physical address in the L2 page table according to the index as the newly added mapping area. By using the above method, it is possible to dynamically add L2 page table entries in the Jailhouse virtual machine monitor. Furthermore, it is possible to dynamically and flexibly adjust the L2 page table entries according to the actual number of CPUs, realizing on-demand mapping.
[0036] In this embodiment, by determining the maximum number of CPUs supported by the memory space corresponding to the L2 page table mapping formed during the initialization of the Jailhouse virtual machine monitor; obtaining the size of the percpu variable copy data structure; obtaining the number of CPUs currently configured in the Jailhouse virtual machine monitor, and determining whether the number of currently configured CPUs exceeds the maximum number of supported CPUs; when it exceeds, determining the additional required memory space according to the number of currently configured CPUs, the maximum number of supported CPUs, and the size of the percpu variable copy data structure; converting the required memory space into the number of newly added page table entries; and adding corresponding page table entries to the original L2 page table according to the number of newly added page table entries as the newly added mapping area. By determining the maximum number of CPUs that can be supported currently by the memory space corresponding to the L2 page table mapping formed during initialization, and based on the difference between the number of currently configured CPUs and the maximum number of CPUs that can be supported currently, and in cooperation with the percpu variable copy data structure required for each CPU during initialization, calculating the additional required memory space, converting the required space into the number of newly added page table entries, and using it as the newly added mapping area to accommodate the corresponding and percpu variable copy data structures of the extra CPUs. Ensure that all spaces that need to be accessed are mapped early during startup. Enable the Jailhouse to pass the CPU initialization normally in the early stage, and at the same time, it will neither fail the initialization due to lack of mapping nor cause waste due to additional mapping, achieving on-demand mapping and increasing the applicable range of Jailhouse.
[0037] In a preferred implementation manner of this embodiment, the method may further include the following steps: When not exceeding, keep the original L2 page table mapping table. By using the above method, when normal initialization is not affected, initialization can still be performed according to the original L2 page table mapping table. Implement on-demand allocation.
[0038] Embodiment 2 Figure 2 FIG. 6 is a flowchart of the memory early mapping method provided in Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment. The maximum number of supported CPUs corresponding to the memory space formed by initializing the Jailhouse virtual machine monitor can be specifically optimized as follows: Determine the estimated number of supported CPUs. Determine the embedding point according to the estimated number, and embed the normal return code at the embedding point in the Jailhouse entry code; When the return point can return normally, adjust the position of the embedding point to the middle position between the embedding point and the end of the entry code; Otherwise, adjust the position of the embedding point to the position from the entry code to the embedding point; Return to the step of adjusting the position of the embedding point to the middle position between the embedding point and the end of the entry code, until the distance between the previous embedding point and the current embedding point is less than the preset distance; Determine the maximum number of supported CPUs according to the position of the previous embedding point.
[0039] See Figure 2 For the memory early mapping method, it includes: Step 210, determine the estimated number of supported CPUs, determine the embedding point according to the estimated number, and embed the normal return code at the embedding point in the Jailhouse entry code.
[0040] In this embodiment, since the size of the initial mapping memory space of the L2 page table of Jailhouse is not a fixed value. Therefore, only the maximum number of supported CPUs can be estimated according to the common memory space size of the initial mapping of the L2 page table. And the accurate maximum number of supported CPUs cannot be obtained.
[0041] Since the startup failure occurs in the assembly program stage, usually the specific cause and location of the crash cannot be specifically determined, which brings difficulties for developers to find problems. Therefore, in this embodiment, a method of determining the maximum number of supported CPUs according to a special debug program is adopted. Exemplarily, a maximum support number can be estimated first according to the common L2 page table initial mapping memory space.
[0042] Determine the embedding point according to the estimated quantity. Exemplarily, when the Jailhouse virtual machine monitor is initialized, each CPU needs to enter the arch_entry assembly code. A embedding point can be set in the arch_entry assembly code of CPU N corresponding to the maximum supported quantity, where N is the corresponding CPU code, which can be obtained by adding 2 to the maximum supported quantity. That is, set the embedding point in the CPU after the last possible supported CPU, and embed the normal return code. The normal return code can be a return statement, that is, when the assembly code can run normally, return a value to determine that the code runs normally; otherwise, do not return any value.
[0043] Using this method, it can be determined whether the memory space mapped by the current L2 page table can support the maximum CPU, which is the CPU number corresponding to the embedding point.
[0044] Step 220, when the return point can return normally, adjust the position of the embedding point to the middle position from the embedding point to the end of the entry code; otherwise, adjust the position of the embedding point to the position from the entry code to the embedding point.
[0045] If the return point can return normally, it means that the CPU corresponding to the embedding point can be supported by the memory space mapped by the L2 page table. Therefore, it is necessary to readjust the embedding point and adjust the position of the embedding point to the middle position from the embedding point to the end of the entry code. In order to gradually narrow the corresponding search range. Since the assembly language does not support multiple embedding points, the inventor adopts the above method of gradually narrowing the range to quickly determine the maximum supported CPU quantity corresponding to the memory space mapped by the L2 page table formed by the initialization of the Jailhouse virtual machine monitor. If it cannot return normally, it means that a crash has occurred in the previous section. Therefore, the search area is limited to the middle position from the startup entry to the current embedding point.
[0046] Step 230, return to the step of adjusting the position of the embedding point to the middle position from the embedding point to the end of the entry code until the distance between the previous embedding point and the current embedding point is less than the preset distance.
[0047] Repeat the above steps to gradually narrow the search range until the distance between the previous embedding point and the current embedding point is less than the preset distance. The preset distance can be the code distance between two adjacent CPUs entering the arch_entry assembly code. Using the above method, the last CPU that can be normally started and initialized can be determined.
[0048] Step 240, determine the maximum supported CPU quantity according to the position of the previous embedding point.
[0049] Exemplarily, the CPU number corresponding to the previous embedding point can be determined as the maximum supported CPU quantity.
[0050] Step 250, obtain the size of the percpu variable copy data structure.
[0051] Step 260, obtain the number of CPUs currently configured by the Jailhouse virtual machine monitor, and determine whether the number of currently configured CPUs exceeds the maximum supported number of CPUs.
[0052] Step 270, when it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum supported number of CPUs, and the size of the percpu variable copy data structure.
[0053] Step 280, convert the required memory space into the number of newly added page table entries, and add corresponding page table entries to the original L2 page table according to the number of newly added page table entries as the newly added mapping area.
[0054] In this embodiment, by specifically optimizing the maximum supported number of CPUs corresponding to the memory space mapped by the L2 page table formed by initializing the Jailhouse virtual machine monitor: determine the estimated number of the maximum supported CPUs, determine the embedding point according to the estimated number, and embed the normal return code at the embedding point in the Jailhouse entry code; when it can return normally at the return point, adjust the position of the embedding point to the middle position between the embedding point and the end of the entry code; otherwise, adjust the position of the embedding point to the position from the entry code to the embedding point; return to the step of adjusting the position of the embedding point to the middle position between the embedding point and the end of the entry code until the distance between the previous embedding point and the current embedding point is less than the preset distance; determine the maximum supported number of CPUs according to the position of the previous embedding point. It can accurately determine the maximum supported number of CPUs through a specific debug program according to the actual situation. At the same time, it avoids the startup failure occurring in the assembly program stage, and developers cannot obtain the specific reason for the startup failure due to unmapping. It not only improves the determination efficiency but also can effectively eliminate the reason for the startup failure.
[0055] Embodiment III Figure 3 It is a schematic structural diagram of the memory early mapping device provided by Embodiment III of the present invention. Refer to Figure 3 The memory early mapping device includes: A determination module 310, configured to determine the maximum supported number of CPUs corresponding to the memory space mapped by the L2 page table formed by initializing the Jailhouse virtual machine monitor; An acquisition module 320, configured to acquire the size of the percpu variable copy data structure; A judgment module 330, configured to obtain the number of CPUs currently configured by the Jailhouse virtual machine monitor, and judge whether the number of currently configured CPUs exceeds the maximum supported number of CPUs; An additional memory space determination module 340, configured to, when the number of CPUs exceeds the maximum supported number, determine the additional required memory space according to the number of currently configured CPUs, the maximum supported number of CPUs, and the size of the percpu variable copy data structure; A conversion module 350, configured to convert the required memory space into the number of newly added page table entries; An addition module 360, configured to add corresponding page table entries to the original L2 page table as a newly added mapping area according to the number of newly added page table entries.
[0056] The memory early mapping device provided in this embodiment determines the maximum supported number of CPUs corresponding to the memory space mapped by the L2 page table formed by initializing the Jailhouse virtual machine monitor; obtains the size of the percpu variable copy data structure; obtains the number of CPUs currently configured by the Jailhouse virtual machine monitor, and judges whether the number of currently configured CPUs exceeds the maximum supported number of CPUs; when the number exceeds, determines the additional required memory space according to the number of currently configured CPUs, the maximum supported number of CPUs, and the size of the percpu variable copy data structure; converts the required memory space into the number of newly added page table entries; adds corresponding page table entries to the original L2 page table as a newly added mapping area according to the number of newly added page table entries. The maximum number of CPUs currently supported is determined through the memory space mapped by the initialized L2 page table, and based on the difference between the currently configured number of CPUs and the maximum number of CPUs currently supported, the additional required memory space is calculated in cooperation with the percpu variable copy data structure required for each CPU during initialization, and the required space is converted into the number of newly added page table entries, which is used as a newly added mapping area to accommodate the corresponding percpu variable copy data structure for the extra CPUs. Ensure that all spaces that need to be accessed during early mapping are started. This enables the Jailhouse to initialize the CPU normally during early startup. At the same time, it will neither fail to initialize due to lack of mapping nor cause waste due to additional mapping, achieving on-demand mapping and increasing the applicable range of Jailhouse.
[0057] Based on the above embodiments, the addition module includes: An addition unit, configured to add a virtual address and a physical address corresponding to the page table entry based on the newly added page table entry; An acquisition unit, configured to acquire the index of the virtual address in the page table entry; An addition unit, configured to add a new page table entry to the corresponding physical address in the L2 page table as a newly added mapping area according to the index.
[0058] Based on the above embodiments, the apparatus further includes: A holding module, configured to hold the original L2 page table mapping table when not exceeded.
[0059] Based on the above embodiments, the determining module includes: An estimated quantity determining unit, configured to determine the estimated quantity of the maximum supported CPUs An embedding unit, configured to determine an embedding point according to the estimated quantity, and embed a normal return code at the embedding point in the Jailhouse entry code; An adjustment unit, configured to adjust the position of the embedding point to the middle position from the embedding point to the end of the entry code when the return point can return normally; Otherwise, adjust the position of the embedding point to the position from the entry code to the embedding point; A return unit, configured to return to the step of adjusting the position of the embedding point to the middle position from the embedding point to the end of the entry code until the distance between the previous embedding point and the current embedding point is less than a preset distance; A determining unit, configured to determine the quantity of the maximum supported CPUs according to the position of the previous embedding point.
[0060] Based on the above embodiments, the obtaining module includes: A searching unit, configured to search for the start address and end address of the percpu data in the assembly macro definition related to the CPU variable; A calculating unit, configured to calculate the size of the percpu variable copy data structure according to the end address and the start address.
[0061] Based on the above embodiments, the additional memory space determining module is implemented in the following manner: MEM = ((N - NUM) * PERCPU_SIZE) / 1024 / 1024, with the unit of MB; Wherein, MEM is the additional required memory space, N is the quantity of the currently configured CPUs, NUM is the quantity of the maximum supported CPUs, and PERCPU_SIZE is the size of the percpu variable copy data structure.
[0062] Based on the above embodiments, the conversion module is implemented in the following manner: Calculate the number of page table entries PAGE_NUM that need to be added according to the exceeded space size, PAGE_NUM = MEM / 2 + 1.
[0063] The memory early mapping device provided by the embodiments of the present invention can execute the memory early mapping method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method.
[0064] Embodiment 4 Figure 4 FIG. 6 is a schematic structural diagram of a device provided for Embodiment 4 of the present invention. Figure 4 FIG. 7 shows a block diagram of an exemplary device 12 suitable for implementing the embodiments of the present invention. Figure 4 The shown device 12 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0065] As Figure 4 shown, the device 12 is presented in the form of a general-purpose computing device. The components of the device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0066] The bus 18 represents one or more of several types of bus structures, including a memory bus or a memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the multiple bus structures. By way of example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0067] The device 12 typically includes a variety of computer system-readable media. These media can be any available media accessible by the device 12, including volatile and non-volatile media, removable and non-removable media.
[0068] The system memory 28 may include computer system-readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, a storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 4 not shown, typically referred to as a "hard disk drive"). Although Figure 4Not shown in the figure, a disk drive for reading and writing a removable non-volatile disk (such as a "floppy disk") and an optical disk drive for reading and writing a removable non-volatile optical disk (such as a CD-ROM, DVD-ROM or other optical medium) can be provided. In these cases, each drive can be connected to the bus 18 through one or more data medium interfaces. The memory 28 may include at least one program product having a set (such as at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0069] A program / utility 40 having a set (at least one) of program modules 42 can be stored, for example, in the memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment. The program modules 42 generally perform the functions and / or methods in the embodiments described in the present invention.
[0070] The device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), and can also communicate with one or more terminals that enable a user to interact with the device 12, and / or communicate with any device (such as a network card, a modem, etc.) that enables the device 12 to communicate with one or more other computing terminals. Such communication can be carried out through the input / output (I / O) interface 22. In addition, the device 12 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through the network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the device 12 through the bus 18. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0071] The processing unit 16 executes various functional applications and data processing by running the programs stored in the system memory 28, such as implementing the display adjustment method based on a modal window provided by the embodiments of the present invention.
[0072] Embodiment Five Embodiment Five of the present invention also provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute any one of the memory early mapping methods provided by the above embodiments when executed by a computer processor.
[0073] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable media may be computer-readable signal media or computer-readable storage media. The computer-readable storage media may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage media may be any tangible medium that contains or stores a program, which can be used by or in combination with an instruction execution system, apparatus, or device.
[0074] The computer-readable signal media may include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal media may also be any computer-readable media other than the computer-readable storage media, which can send, propagate, or transmit a program for use by or in combination with an instruction execution system, apparatus, or device.
[0075] The program code contained on the computer-readable media may be transmitted by any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0076] The computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., by using an Internet service provider to connect through the Internet).
[0077] Note that the above is only a preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments can be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for early mapping of memory, characterized in that including: Determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed during the initialization of the Jailhouse virtual machine monitor; Obtain the size of the data structure of the percpu variable copy; Obtain the number of currently configured CPUs of the Jailhouse virtual machine monitor, and determine whether the number of currently configured CPUs exceeds the maximum number of supported CPUs; When it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum number of supported CPUs, and the size of the percpu variable copy data structure; Convert the required memory space into the number of newly added page table entries; Add corresponding page table entries to the original L2 page table according to the number of newly added page table entries as a newly added mapping area.
2. The method according to claim 1, wherein The adding corresponding page table entries to the original L2 page table according to the number of newly added page table entries as a newly added mapping area includes: Based on the newly added page table entries, increase the virtual address and physical address corresponding to the page table entries; Obtain the index of the virtual address in the page table entry; Add a new page table entry to the corresponding physical address in the L2 page table according to the index as a newly added mapping area.
3. The method according to claim 1, wherein The method further includes: When it does not exceed, keep the original L2 page table mapping table.
4. The method according to claim 1, wherein The determining the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed during the initialization of the Jailhouse virtual machine monitor includes: Determine the estimated number of supported CPUs; Determine the embedding point according to the estimated number, and embed the normal return code at the embedding point in the Jailhouse entry code; When the return point can return normally, adjust the position of the embedding point to the middle position from the embedding point to the end of the entry code; Otherwise, adjust the position of the embedding point to the position from the entry code to the embedding point; Return to the step of adjusting the position of the embedding point to the middle position from the embedding point to the end of the entry code until the distance between the previous embedding point and the current embedding point is less than the preset distance; Determine the maximum number of supported CPUs according to the position of the previous embedding point.
5. The method according to claim 1, wherein The obtaining the size of the percpu variable copy data structure includes: Find the start address and end address of the percpu data in the assembly macro definition related to the CPU variable; Calculate the size of the percpu variable copy data structure according to the end address and the start address.
6. The method according to claim 1, characterized in that The determining the additional required memory space according to the number of currently configured CPUs, the maximum number of supported CPUs, and the size of the percpu variable copy data structure is implemented in the following way: MEM = ((N - NUM) * PERCPU_SIZE) / 1024 / 1024, in MB; where MEM is the additional required memory space, N is the number of currently configured CPUs, NUM is the maximum number of supported CPUs, and PERCPU_SIZE is the size of the percpu variable copy data structure.
7. The method according to claim 6, wherein The converting the required memory space into the number of newly added page table entries is implemented in the following way: Calculate the number of page table entries PAGE_NUM that need to add mappings according to the exceeded space size, PAGE_NUM = MEM / 2 + 1.
8. An early memory mapping device, characterized in that including: A determination module, configured to determine the maximum number of supported CPUs corresponding to the memory space mapped by the L2 page table formed by initializing the Jailhouse virtual machine monitor; An acquisition module, configured to acquire the size of the data structure of the percpu variable copy; A judgment module, configured to acquire the number of CPUs currently configured by the Jailhouse virtual machine monitor, and judge whether the number of currently configured CPUs exceeds the maximum number of supported CPUs; An additional memory space determination module, configured to, when it exceeds, determine the additional required memory space according to the number of currently configured CPUs, the maximum number of supported CPUs, and the size of the data structure of the percpu variable copy; A conversion module, configured to convert the required memory space into the number of newly added page table entries; An acting module, configured to add corresponding page table entries to the original L2 page table as a newly added mapping area according to the number of newly added page table entries.
9. A device, characterized in that, Comprising: A plurality of processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the plurality of processors, the plurality of processors implement the memory early mapping method according to any one of claims 1-7.
10. A storage medium containing computer-executable instructions, characterized in that, The computer executable instructions are used to execute the memory early mapping method according to any one of claims 1-7 when executed by a computer processor.
Citation Information
Patent Citations
Method and device for expanding memory of virtual machine
CN107562520A
Memory management method and device of virtual machine and electronic equipment
CN114880074A
Memory virtualization method and device and medium
CN116225619A
System management memory allocation method, program running method, system and product
CN119003189A
Memory management method and device, equipment, storage medium, program product and chip
CN119473926A
Cited By
System startup memory detection method and device, equipment and storage medium
CN120523747A